aboutsummaryrefslogtreecommitdiff
path: root/net/tap-linux.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2012-11-12 09:13:04 +0200
committerMichael S. Tsirkin <mst@redhat.com>2012-12-12 23:36:20 +0200
commit89e6d68ef3c45b2c4e3199c3397b5525b752698d (patch)
tree09fea63c634f84ff4e9ec730d282bb0483952d27 /net/tap-linux.c
parent6f918e40e6b7f4e3dcf89c3e3f1001e965a683a1 (diff)
tap: reset vnet header size on open
For tap, we currently assume the vnet header size is 10 (the default value) but that might not be the case if tap is persistent and has been used by qemu previously. To fix, set vnet header size correctly on open. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'net/tap-linux.c')
-rw-r--r--net/tap-linux.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/tap-linux.c b/net/tap-linux.c
index c6521bec34..3eaedc40ad 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -39,6 +39,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
{
struct ifreq ifr;
int fd, ret;
+ int len = sizeof(struct virtio_net_hdr);
TFR(fd = open(PATH_NET_TUN, O_RDWR));
if (fd < 0) {
@@ -65,6 +66,13 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
close(fd);
return -1;
}
+ /*
+ * Make sure vnet header size has the default value: for a persistent
+ * tap it might have been modified e.g. by another instance of qemu.
+ * Ignore errors since old kernels do not support this ioctl: in this
+ * case the header size implicitly has the correct value.
+ */
+ ioctl(fd, TUNSETVNETHDRSZ, &len);
}
if (ifname[0] != '\0')