From nobody Sat Apr 20 12:23:26 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1673615363; cv=none; d=zohomail.com; s=zohoarc; b=nSRtaSzNROr1AY+UVXhlLole9zJXQbGWHUAvvmsXP88VW1SbudCD40MWcXLdeNj4heVQg3vzBKYuDqy0NTWxE/aim8WvdaDkbOwz/hCxojx9w+KypFfeoOvd3rp0UES6bmQAmPeIAhoO4Ifw2FAtyNKr8nZvHARLP3XKQXjCf5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673615363; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject; bh=D92loE1N2VhhDiTz7D9NWwgy6yEPkhdyyjdk3wETMj4=; b=LPInOWUa+zcaDSXdAFPFwQtL17tnoIXUU3svEkDkslIQ3KX5HsfSfyq1aMxDBhZ6s6JRx9Es1Ts35eWhXDEwOw220Mmr3bnSI6JmUWYeFAvbG9dEf4cZaPtUEgH7LtrCmzWbjOrnr0Yo1Hkzf3+BPpyprb/GJSZ6/1pRbZiU4ek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1673615363639339.3255394239426; Fri, 13 Jan 2023 05:09:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGJnl-0004RM-9Y; Fri, 13 Jan 2023 08:08:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGJnj-0004R0-F6 for qemu-devel@nongnu.org; Fri, 13 Jan 2023 08:08:55 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pGJnh-0005BY-2S for qemu-devel@nongnu.org; Fri, 13 Jan 2023 08:08:55 -0500 Received: by mail-pj1-x102f.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so24328598pjj.4 for ; Fri, 13 Jan 2023 05:08:51 -0800 (PST) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id f5-20020a170902ce8500b001870dc3b4c0sm14160671plg.74.2023.01.13.05.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 05:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=D92loE1N2VhhDiTz7D9NWwgy6yEPkhdyyjdk3wETMj4=; b=cKTV5g/ELRRnZDy0Wd5cRxC+h6kvOzugTGVZl9Fm4Fh9yg0gwqRMNvQMcJK6CPhJbi UCb5WpFgf252IJh70PfMPWeRiOnrtd3WQwdXuJRxuSXWLWay+GWj4UBtUjHHEVtn+gPO z1BrkYhrACxehxVM13AT7E4MQC/h2qMNU1fB8JZgws8OZoVmG+OmtwjarrSiqnUktXv3 lYG/ucC5VsBkpiKXOmO5KjFz5aPwIJjPGcz6wZL807gDeBkhefZ801oYSxTIUjNX4P0k WofrGktEdTwIuSJMNDSh1nI5PJcO8PzZL8nI2CEl78MU815fFMkASSi2pzGxbKQvNLQk yk4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D92loE1N2VhhDiTz7D9NWwgy6yEPkhdyyjdk3wETMj4=; b=Zij8TVyBWvJYqHZrPFjpXEcSDPlcl7l6rkGicnH8cDfByG9s50IoPG7nji3bDaINiU CL6WSu1T0VawBvzCEC7FAujy0IV074NEgH6WqK5JoQ0JbMIvrpdYbd+Q69485rjGRTJW Nqx6di/wPnJgRRlEgpyWyyEYD8C9u7OSOqG1iPQ6znJ063cEAvMGzC/4RhMJ/kEbO0AE rQWk3w412Qwz3zIaMI25gmDk9yFrX3lG07o51wEZBsFLLIOe/tUaqy3+Jppm2eLOFUfi vQiOHr9JqTr5+Sbp529IyIOeN12ftspd6hk513mLLEvsbvwQClSpzUVsK7GEnOLem6Ce JyFA== X-Gm-Message-State: AFqh2kolQHXkWdOVKALgJypyV6z3X/Rx58A1Fjm9eVDSaL0dcdc8nb1i IuzEsLX+TItl7jHdflilFZ92ww== X-Google-Smtp-Source: AMrXdXtUabcAFdbA69tIsuYs6p4ITo/URToe547EeDszV/Ywp2XULDCXh4+bjHrZv15KCnzt8ZVTNQ== X-Received: by 2002:a17:902:9687:b0:189:ed86:178b with SMTP id n7-20020a170902968700b00189ed86178bmr10614422plp.64.1673615330646; Fri, 13 Jan 2023 05:08:50 -0800 (PST) From: Akihiko Odaki To: Cc: Jason Wang , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , qemu-devel@nongnu.org, Akihiko Odaki Subject: [PATCH] net: Strip virtio-net header when dumping Date: Fri, 13 Jan 2023 22:08:33 +0900 Message-Id: <20230113130833.81458-1-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::102f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1673615365951100003 Content-Type: text/plain; charset="utf-8" filter-dump specifiees Ethernet as PCAP LinkType, which does not expect virtio-net header. Having virtio-net header in such PCAP file breaks PCAP unconsumable. Unfortunately currently there is no LinkType for virtio-net so for now strip virtio-net header to convert the output to Ethernet. Signed-off-by: Akihiko Odaki --- include/net/net.h | 6 ++++++ net/dump.c | 11 +++++++---- net/net.c | 18 ++++++++++++++++++ net/netmap.c | 1 + net/tap.c | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index dc20b31e9f..4b2d72b3fc 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -56,8 +56,10 @@ typedef RxFilterInfo *(QueryRxFilter)(NetClientState *); typedef bool (HasUfo)(NetClientState *); typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdrLen)(NetClientState *, int); +typedef bool (GetUsingVnetHdr)(NetClientState *); typedef void (UsingVnetHdr)(NetClientState *, bool); typedef void (SetOffload)(NetClientState *, int, int, int, int, int); +typedef int (GetVnetHdrLen)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); @@ -84,8 +86,10 @@ typedef struct NetClientInfo { HasUfo *has_ufo; HasVnetHdr *has_vnet_hdr; HasVnetHdrLen *has_vnet_hdr_len; + GetUsingVnetHdr *get_using_vnet_hdr; UsingVnetHdr *using_vnet_hdr; SetOffload *set_offload; + GetVnetHdrLen *get_vnet_hdr_len; SetVnetHdrLen *set_vnet_hdr_len; SetVnetLE *set_vnet_le; SetVnetBE *set_vnet_be; @@ -183,9 +187,11 @@ void qemu_format_nic_info_str(NetClientState *nc, uint= 8_t macaddr[6]); bool qemu_has_ufo(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc); bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); +bool qemu_get_using_vnet_hdr(NetClientState *nc); void qemu_using_vnet_hdr(NetClientState *nc, bool enable); void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo); +int qemu_get_vnet_hdr_len(NetClientState *nc); void qemu_set_vnet_hdr_len(NetClientState *nc, int len); int qemu_set_vnet_le(NetClientState *nc, bool is_le); int qemu_set_vnet_be(NetClientState *nc, bool is_be); diff --git a/net/dump.c b/net/dump.c index 6a63b15359..7d05f16ca7 100644 --- a/net/dump.c +++ b/net/dump.c @@ -61,12 +61,13 @@ struct pcap_sf_pkthdr { uint32_t len; }; =20 -static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int= cnt) +static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int= cnt, + int offset) { struct pcap_sf_pkthdr hdr; int64_t ts; int caplen; - size_t size =3D iov_size(iov, cnt); + size_t size =3D iov_size(iov, cnt) - offset; struct iovec dumpiov[cnt + 1]; =20 /* Early return in case of previous error. */ @@ -84,7 +85,7 @@ static ssize_t dump_receive_iov(DumpState *s, const struc= t iovec *iov, int cnt) =20 dumpiov[0].iov_base =3D &hdr; dumpiov[0].iov_len =3D sizeof(hdr); - cnt =3D iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen); + cnt =3D iov_copy(&dumpiov[1], cnt, iov, cnt, offset, caplen); =20 if (writev(s->fd, dumpiov, cnt + 1) !=3D sizeof(hdr) + caplen) { error_report("network dump write error - stopping dump"); @@ -153,8 +154,10 @@ static ssize_t filter_dump_receive_iov(NetFilterState = *nf, NetClientState *sndr, int iovcnt, NetPacketSent *sent_cb) { NetFilterDumpState *nfds =3D FILTER_DUMP(nf); + int offset =3D qemu_get_using_vnet_hdr(nf->netdev) ? + qemu_get_vnet_hdr_len(nf->netdev) : 0; =20 - dump_receive_iov(&nfds->ds, iov, iovcnt); + dump_receive_iov(&nfds->ds, iov, iovcnt, offset); return 0; } =20 diff --git a/net/net.c b/net/net.c index 2d01472998..3a95c3ba6a 100644 --- a/net/net.c +++ b/net/net.c @@ -513,6 +513,15 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int len) return nc->info->has_vnet_hdr_len(nc, len); } =20 +bool qemu_get_using_vnet_hdr(NetClientState *nc) +{ + if (!nc || !nc->info->get_using_vnet_hdr) { + return false; + } + + return nc->info->get_using_vnet_hdr(nc); +} + void qemu_using_vnet_hdr(NetClientState *nc, bool enable) { if (!nc || !nc->info->using_vnet_hdr) { @@ -532,6 +541,15 @@ void qemu_set_offload(NetClientState *nc, int csum, in= t tso4, int tso6, nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo); } =20 +int qemu_get_vnet_hdr_len(NetClientState *nc) +{ + if (!nc || !nc->info->get_vnet_hdr_len) { + return -ENOSYS; + } + + return nc->info->get_vnet_hdr_len(nc); +} + void qemu_set_vnet_hdr_len(NetClientState *nc, int len) { if (!nc || !nc->info->set_vnet_hdr_len) { diff --git a/net/netmap.c b/net/netmap.c index 9e0cec58d3..ed9c7ec948 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -393,6 +393,7 @@ static NetClientInfo net_netmap_info =3D { .has_ufo =3D netmap_has_vnet_hdr, .has_vnet_hdr =3D netmap_has_vnet_hdr, .has_vnet_hdr_len =3D netmap_has_vnet_hdr_len, + .get_using_vnet_hdr =3D netmap_get_using_vnet_hdr, .using_vnet_hdr =3D netmap_using_vnet_hdr, .set_offload =3D netmap_set_offload, .set_vnet_hdr_len =3D netmap_set_vnet_hdr_len, diff --git a/net/tap.c b/net/tap.c index e28ceb078f..daa7e0a042 100644 --- a/net/tap.c +++ b/net/tap.c @@ -257,6 +257,13 @@ static bool tap_has_vnet_hdr_len(NetClientState *nc, i= nt len) return !!tap_probe_vnet_hdr_len(s->fd, len); } =20 +static int tap_get_vnet_hdr_len(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->host_vnet_hdr_len; +} + static void tap_set_vnet_hdr_len(NetClientState *nc, int len) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -270,6 +277,13 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, i= nt len) s->host_vnet_hdr_len =3D len; } =20 +static bool tap_get_using_vnet_hdr(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->using_vnet_hdr; +} + static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -374,8 +388,10 @@ static NetClientInfo net_tap_info =3D { .has_ufo =3D tap_has_ufo, .has_vnet_hdr =3D tap_has_vnet_hdr, .has_vnet_hdr_len =3D tap_has_vnet_hdr_len, + .get_using_vnet_hdr =3D tap_get_using_vnet_hdr, .using_vnet_hdr =3D tap_using_vnet_hdr, .set_offload =3D tap_set_offload, + .get_vnet_hdr_len =3D tap_get_vnet_hdr_len, .set_vnet_hdr_len =3D tap_set_vnet_hdr_len, .set_vnet_le =3D tap_set_vnet_le, .set_vnet_be =3D tap_set_vnet_be, --=20 2.39.0