From 1eb6bf3bfa43344dde8ce5bedd56638bcddbe682 Mon Sep 17 00:00:00 2001
From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Tue, 13 Nov 2012 12:23:23 +0200
Subject: tap: reset vnet header size on open
Bug-Debian: http://bugs.debian.org/696057

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 host header size in tap device on open.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 58ddcd50f30cb5c020bd4f9f36b01ee160a27cac)

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 net/tap.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/tap.c b/net/tap.c
index f240028..08be84f 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -339,6 +339,13 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     s->using_vnet_hdr = 0;
     s->has_ufo = tap_probe_has_ufo(s->fd);
     tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
+    /*
+     * Make sure host header length is set correctly in tap:
+     * it might have been modified by another instance of qemu.
+     */
+    if (tap_probe_vnet_hdr_len(s->fd, s->host_vnet_hdr_len)) {
+        tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len);
+    }
     tap_read_poll(s, 1);
     s->vhost_net = NULL;
     return s;
-- 
1.7.10.4

