From nobody Wed Feb 11 08:39:56 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1682223743; cv=none; d=zohomail.com; s=zohoarc; b=Ryo4Xa3TDieyk/h3gzKeRg799Cq4DIM3FX0nfQJ4LxNMh1k5VOqUediLUN99QyMuhQPgtZh/9/2Sbz0Mdw39Gks4IlRuGn/jTHl1eJmIB4L2GIXG/a+iyOL94sNcot+FGo2jkeEECuQV0h/2RZWfAQLKY2nDhPQojWOzeYLMUGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682223743; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=WfMEYJ9MsNl1NEs1qpCe7w36MfTu1Ir4rIbITGTkOa8=; b=g/kRMg84OdaNxXAYF3GWW8gTAUNoyiT4k1fzTJzJ2giZTkwx7Y4DgryD7INYrGAtozzokJn9S6j6B7loRf9dJoIQnbHjmWaBFQioLRjVyljQpQJ3EX9uZFZaMDYP2wQjV8BI4S6UG/OjznWyzKFOtpAFJgdCTYBJYUQ9qBQTnJM= 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+importer=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 1682223743607791.1216373464675; Sat, 22 Apr 2023 21:22:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqRDS-0004vs-Tj; Sun, 23 Apr 2023 00:20:47 -0400 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 1pqRDD-0004j8-BF for qemu-devel@nongnu.org; Sun, 23 Apr 2023 00:20:32 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pqRDB-00018p-Nn for qemu-devel@nongnu.org; Sun, 23 Apr 2023 00:20:31 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1a920d4842bso27036575ad.2 for ; Sat, 22 Apr 2023 21:20:28 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id f1-20020a170902ff0100b001a5059861adsm4596996plj.224.2023.04.22.21.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 21:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1682223628; x=1684815628; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WfMEYJ9MsNl1NEs1qpCe7w36MfTu1Ir4rIbITGTkOa8=; b=1C5tivw8xhyua/X1Rqk3kCkSyip5aCOg+VS0o8Av+qElEwWqPBUPg0SX6Sf/jUZBKN YBDmLukZ4UTZS5gicChPIgt+LtWcbjcGI7P1ALNJwt/X3JPAHS6Kap+kegaMX76OUPVa 011xqIZFUyX6O8r3meecOIdIOS9X106n3AggBFCunWeN1LM+a2ESYzbFnr1z0e2x5arT IWPJNLEAABGQbZwINoef7e0gbyOVTfU7w2acsOB2LooR+hIUf05R29GydVFkt2MHnktn TuOrt5inkh0hUBG1xfNx0J1Hy104qp6u2QPedkA6zC0opoGHuc3jub7q7bPowDrPQ+Dg nVbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682223628; x=1684815628; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WfMEYJ9MsNl1NEs1qpCe7w36MfTu1Ir4rIbITGTkOa8=; b=CfI8fa2xZ22hzCULQpPowbYnne4YuHoBRbPmoB5ikQFkx8bedU92g0nrUXgt5SEf4I xpwloz0rfba0q6bZNUKGIDVZNazgLrxkSjEOev703o05J+IJ1KGfI6r21lNX387XpFfD 9cwm5LBHVXYql6jG+EXZb3+NIqldtJ3WhaTQcc6PiLWN+wCjL9z4G1l9OyRDPptnJkO0 KAyasG+SkAF7qa2o5cpJYBDaxj5gRpWby8c8W6yAvEh9odbua4kk/ERR+RpiCsodSoVA 0BCdnbfo1VEz2Wk8K/LUX99Kvog9PgnA44W5qBd10u8f1zpm66sGsVXounBWT00o135t Db/Q== X-Gm-Message-State: AAQBX9dEccspGj7cFZL5RsvEh7LdFot8yefectgilbNlJrbnoaLVJY5l acN9GXW8cwvjb/LhYtTvLem3FA== X-Google-Smtp-Source: AKy350baN9cYlnYtuLRMD1rvfkdMsQaKd7mucyJ3k9VHFXG3MyGGwGvTns+q4P661KbYO2X2QyeXoA== X-Received: by 2002:a17:902:ecd1:b0:1a5:2e19:bc40 with SMTP id a17-20020a170902ecd100b001a52e19bc40mr13167425plh.26.1682223628394; Sat, 22 Apr 2023 21:20:28 -0700 (PDT) From: Akihiko Odaki To: Cc: Sriram Yagnaraman , Jason Wang , Dmitry Fleytman , "Michael S . Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Beraldo Leal , Cleber Rosa , Laurent Vivier , Paolo Bonzini , qemu-devel@nongnu.org, Tomasz Dzieciol , Akihiko Odaki Subject: [PATCH v3 31/47] net/eth: Always add VLAN tag Date: Sun, 23 Apr 2023 13:18:17 +0900 Message-Id: <20230423041833.5302-32-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423041833.5302-1-akihiko.odaki@daynix.com> References: <20230423041833.5302-1-akihiko.odaki@daynix.com> 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1682223744493100003 Content-Type: text/plain; charset="utf-8" It is possible to have another VLAN tag even if the packet is already tagged. Signed-off-by: Akihiko Odaki --- include/net/eth.h | 4 ++-- hw/net/net_tx_pkt.c | 16 +++++++--------- net/eth.c | 22 ++++++---------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/include/net/eth.h b/include/net/eth.h index 95ff24d6b8..048e434685 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -353,8 +353,8 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, = size_t iovoff, uint16_t eth_get_l3_proto(const struct iovec *l2hdr_iov, int iovcnt, size_t l2hdr_l= en); =20 -void eth_setup_vlan_headers(struct eth_header *ehdr, uint16_t vlan_tag, - uint16_t vlan_ethtype, bool *is_new); +void eth_setup_vlan_headers(struct eth_header *ehdr, size_t *ehdr_size, + uint16_t vlan_tag, uint16_t vlan_ethtype); =20 =20 uint8_t eth_get_gso_type(uint16_t l3_proto, uint8_t *l3_hdr, uint8_t l4pro= to); diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index ce6b102391..af8f77a3f0 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -40,7 +40,10 @@ struct NetTxPkt { =20 struct iovec *vec; =20 - uint8_t l2_hdr[ETH_MAX_L2_HDR_LEN]; + struct { + struct eth_header eth; + struct vlan_header vlan[3]; + } l2_hdr; union { struct ip_header ip; struct ip6_header ip6; @@ -365,18 +368,13 @@ bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, b= ool tso_enable, void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt, uint16_t vlan, uint16_t vlan_ethtype) { - bool is_new; assert(pkt); =20 eth_setup_vlan_headers(pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_base, - vlan, vlan_ethtype, &is_new); + &pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_len, + vlan, vlan_ethtype); =20 - /* update l2hdrlen */ - if (is_new) { - pkt->hdr_len +=3D sizeof(struct vlan_header); - pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_len +=3D - sizeof(struct vlan_header); - } + pkt->hdr_len +=3D sizeof(struct vlan_header); } =20 bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, void *base, size_t = len) diff --git a/net/eth.c b/net/eth.c index f7ffbda600..5307978486 100644 --- a/net/eth.c +++ b/net/eth.c @@ -21,26 +21,16 @@ #include "net/checksum.h" #include "net/tap.h" =20 -void eth_setup_vlan_headers(struct eth_header *ehdr, uint16_t vlan_tag, - uint16_t vlan_ethtype, bool *is_new) +void eth_setup_vlan_headers(struct eth_header *ehdr, size_t *ehdr_size, + uint16_t vlan_tag, uint16_t vlan_ethtype) { struct vlan_header *vhdr =3D PKT_GET_VLAN_HDR(ehdr); =20 - switch (be16_to_cpu(ehdr->h_proto)) { - case ETH_P_VLAN: - case ETH_P_DVLAN: - /* vlan hdr exists */ - *is_new =3D false; - break; - - default: - /* No VLAN header, put a new one */ - vhdr->h_proto =3D ehdr->h_proto; - ehdr->h_proto =3D cpu_to_be16(vlan_ethtype); - *is_new =3D true; - break; - } + memmove(vhdr + 1, vhdr, *ehdr_size - ETH_HLEN); vhdr->h_tci =3D cpu_to_be16(vlan_tag); + vhdr->h_proto =3D ehdr->h_proto; + ehdr->h_proto =3D cpu_to_be16(vlan_ethtype); + *ehdr_size +=3D sizeof(*vhdr); } =20 uint8_t --=20 2.40.0