[PATCH 2/2] net/dump: Correctly compute Ethernet packet offset

Laurent Vivier posted 2 patches 2 weeks, 5 days ago
[PATCH 2/2] net/dump: Correctly compute Ethernet packet offset
Posted by Laurent Vivier 2 weeks, 5 days ago
When a packet is sent with QEMU_NET_PACKET_FLAG_RAW by QEMU it
never includes virtio-net header even if qemu_get_vnet_hdr_len()
is not 0, and filter-dump is not managing this case.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self,
we can show the problem using it and tcpddump:

- QEMU parameters:

  .. -monitor stdio \
     -netdev bridge,id=netdev0,br=virbr0 \
     -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \
     -object filter-dump,netdev=netdev0,file=log.pcap,id=pcap0

- HMP command:

  (qemu) announce_self

- TCP dump:

  $ tcpdump -nxr log.pcap

  without the fix:

    08:00:06:04:00:03 > 2e:2f:80:35:00:01, ethertype Unknown (0x9a2b), length 50:
         0x0000:  2c2d 2e2f 0000 0000 9a2b 2c2d 2e2f 0000
         0x0010:  0000 0000 0000 0000 0000 0000 0000 0000
         0x0020:  0000 0000

  with the fix:

    ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
         0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
         0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
         0x0020:  0000 0000 0000 0000 0000 0000 0000

Fixes: 481c52320a26 ("net: Strip virtio-net header when dumping")
Cc: akihiko.odaki@daynix.com
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 net/dump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/dump.c b/net/dump.c
index d7dd2ce461de..140215aa1054 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -155,7 +155,8 @@ static ssize_t filter_dump_receive_iov(NetFilterState *nf, NetClientState *sndr,
 {
     NetFilterDumpState *nfds = FILTER_DUMP(nf);
 
-    dump_receive_iov(&nfds->ds, iov, iovcnt, qemu_get_vnet_hdr_len(nf->netdev));
+    dump_receive_iov(&nfds->ds, iov, iovcnt, flags & QEMU_NET_PACKET_FLAG_RAW ?
+                     0 : qemu_get_vnet_hdr_len(nf->netdev));
     return 0;
 }
 
-- 
2.47.1
Re: [PATCH 2/2] net/dump: Correctly compute Ethernet packet offset
Posted by Jason Wang 2 weeks, 2 days ago
On Fri, Jan 17, 2025 at 7:17 PM Laurent Vivier <lvivier@redhat.com> wrote:
>
> When a packet is sent with QEMU_NET_PACKET_FLAG_RAW by QEMU it
> never includes virtio-net header even if qemu_get_vnet_hdr_len()
> is not 0, and filter-dump is not managing this case.
>
> The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self,
> we can show the problem using it and tcpddump:
>
> - QEMU parameters:
>
>   .. -monitor stdio \
>      -netdev bridge,id=netdev0,br=virbr0 \
>      -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \
>      -object filter-dump,netdev=netdev0,file=log.pcap,id=pcap0
>
> - HMP command:
>
>   (qemu) announce_self
>
> - TCP dump:
>
>   $ tcpdump -nxr log.pcap
>
>   without the fix:
>
>     08:00:06:04:00:03 > 2e:2f:80:35:00:01, ethertype Unknown (0x9a2b), length 50:
>          0x0000:  2c2d 2e2f 0000 0000 9a2b 2c2d 2e2f 0000
>          0x0010:  0000 0000 0000 0000 0000 0000 0000 0000
>          0x0020:  0000 0000
>
>   with the fix:
>
>     ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
>          0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
>          0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
>          0x0020:  0000 0000 0000 0000 0000 0000 0000
>
> Fixes: 481c52320a26 ("net: Strip virtio-net header when dumping")
> Cc: akihiko.odaki@daynix.com
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks
Re: [PATCH 2/2] net/dump: Correctly compute Ethernet packet offset
Posted by Akihiko Odaki 2 weeks, 4 days ago
On 2025/01/17 20:17, Laurent Vivier wrote:
> When a packet is sent with QEMU_NET_PACKET_FLAG_RAW by QEMU it
> never includes virtio-net header even if qemu_get_vnet_hdr_len()
> is not 0, and filter-dump is not managing this case.
> 
> The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self,
> we can show the problem using it and tcpddump:
> 
> - QEMU parameters:
> 
>    .. -monitor stdio \
>       -netdev bridge,id=netdev0,br=virbr0 \
>       -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \
>       -object filter-dump,netdev=netdev0,file=log.pcap,id=pcap0
> 
> - HMP command:
> 
>    (qemu) announce_self
> 
> - TCP dump:
> 
>    $ tcpdump -nxr log.pcap
> 
>    without the fix:
> 
>      08:00:06:04:00:03 > 2e:2f:80:35:00:01, ethertype Unknown (0x9a2b), length 50:
>           0x0000:  2c2d 2e2f 0000 0000 9a2b 2c2d 2e2f 0000
>           0x0010:  0000 0000 0000 0000 0000 0000 0000 0000
>           0x0020:  0000 0000
> 
>    with the fix:
> 
>      ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
>           0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
>           0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
>           0x0020:  0000 0000 0000 0000 0000 0000 0000
> 
> Fixes: 481c52320a26 ("net: Strip virtio-net header when dumping")
> Cc: akihiko.odaki@daynix.com
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>