Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp156871lqs; Thu, 13 Jun 2024 06:48:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVI1gTk/0TWzuyOU9kKkz0hslKkjsbRk2OBGvNmAKishq0ExhUE9u8cW5CUZeot1RB8hEQN3Rx09UrKDlPcnZRPSYPhPgxIFZwxLCyew== X-Google-Smtp-Source: AGHT+IFs3v6r93sjQNSpldysmZQaKkbVqQKJNXeO7LUAMXblzFpTPaWc+RggVDJ+Ptwpq2F6u8rU X-Received: by 2002:aa7:c613:0:b0:57c:7123:f91c with SMTP id 4fb4d7f45d1cf-57caaabf924mr3181283a12.31.1718286497962; Thu, 13 Jun 2024 06:48:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718286497; cv=pass; d=google.com; s=arc-20160816; b=pFh7lNPNU6fbt7a3UttZ9TQ4jdVCa6nBob89jBSzndgm1imO63nSbytW/N4Eh3YWKE 4xvN7ca3mnEtYnkzHQmpyrw9iJqvePGHeGN4V39F88VBGOyDlW0n6FMob1wrgcCEWevR MfEJ3Ta0HaH1aE9woM4dT4VTEnsA9GzD1DXu7xElXpDb4w2JCdz5H8+ZDcdA4NDyv7ty W1ao1++lLVWvVZn1F4NOtxOxqANyrBJ9Ifr/a1M6jeXv3hLm+IUSopWDNtPMyPRH1v2r 3WKOF9bg2IeN3ruwNXNScJLU+QKNK4fvQ9UwRkp9T6Vtx8ecKxkIKNhTeXOAJWsdZYy+ G3bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=MFqPztQitJYDktXqBkZ6NLUwtPUevbzJdNjmzYUffpg=; fh=i/I7AskunchA/+NXKdRdussEYwx6WmQrrqzpWN92+mo=; b=mKVlUBQOpwy58TF+0GgWDTdK8XI+xbCopAFsj+I/uap1KHk/ErU9q5MnkSzFyEMLJn mVaNjWm/+H1BEgn8rbQ7S0WFvdb0w6XcSGctK/c+8Pi1Xd9g2sqfAsyrpwKtqwv5j+Rk MCiCe1QE64o9Wf2NJWSy3wAehGV8srRMxp5CEaVIOWdFu/rZG52mXgl71dWmLRj/UBIc DYhv+lCRAt7wyrEE12r97a7DJd5UeRoYisAx2D5MCbF1rIns4iD9CX9yLV0mVQfqZ4Ki rtdJRpruEZaGY3ySP0D02whks4ELGnt32OFPeTbU6qBKb1QQ1Sa9y+mThjHON9FWdcHH rxXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="jFSc/htR"; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-213364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213364-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb745f885si719950a12.520.2024.06.13.06.48.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:48:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="jFSc/htR"; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-213364-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213364-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6A3D91F21E2E for ; Thu, 13 Jun 2024 13:48:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04E5D144D16; Thu, 13 Jun 2024 13:48:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="jFSc/htR" Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F143143895 for ; Thu, 13 Jun 2024 13:48:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286482; cv=none; b=l4B1WjaLRtgKye/6UdunnycL4bLdkgxVOmogf+eobuFGgpHC4B3SHxyCYUe5GIKZeDXJViexqgCm3Rj75txpuOpODmtck2N/4r1mduCQn93Zp9Z3/YuanDp/AKzDBdjeZTRxggPifN/AT23Hlfz0DxeJ8kRCwRkb6PVFWi3H2CE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286482; c=relaxed/simple; bh=/dQrRNNz2mPVszGNmHGCjfVyHSU68crTSQrnsrESOs0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=bTu5Xj7S2z2p1NqvUBf8PiqdshA36Rj3N59XcxE14GPLBSbE2lnW5ux9z1an5G8dNk5uPIaxhy1GcgDA6o09ZaaYbCYpl18Kyqcf+OX8Af2aQsPAszZ8TLi5HCLW/yHaDRH/NSVzXh4dDjxD4NGCK21ZP1W1EPmpbryed5fkzCA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=jFSc/htR; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 3E4203F2D4 for ; Thu, 13 Jun 2024 13:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1718286473; bh=MFqPztQitJYDktXqBkZ6NLUwtPUevbzJdNjmzYUffpg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jFSc/htREI/jOxDnpEPnaAtzd/BnNFwdRVTPxItva8fT7xvJuPol3DtrD90jGVaLy oNRhqECFsP3YUicRxvUBiSlJWpJSrrxyoPiNkchutKzjOA3S8NP1DMYFxFoDex3zO8 FiFIkLsiU7poJ3sNA+pPKy8jryZTba91ThW/+X0P47ehOeD6LmIvhSztjqpeCNBU+v uKfq1JKoM54lfvGFPeV27OVlMKSmt4QknbkxtuWMgZeMVqS1I8oGV7xP32xybdyM/G rN4AcjSr6/tJW5vd0mUeh7wGAx/XXUz+lZRVdoxp27SnaDFi32WQ9Baj40h8XCD2j3 zLtFXtwaRHqKg== Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a6ef7afd90aso51844366b.2 for ; Thu, 13 Jun 2024 06:47:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718286472; x=1718891272; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MFqPztQitJYDktXqBkZ6NLUwtPUevbzJdNjmzYUffpg=; b=ESkoFshuOhHbR/OubSkYzK8IoxQ3HUaPEZpZnw72F2taIgGQ/sb1turR4SFB1zH8Ba dgZox85vyceqb+e3AICnpYqKJ2v8WB0TRCJ4I30bQnj4LXJex4ZBCua3/GyKjbpy2J9x KRwHCox/9AH5aeQJPYyh5FBphnru2aLbwezb+ws5xWnscc1gxo3HkZjaAZAtohMEXtaj 5qXlF+kCdh2bk4l5AojtqWcLL5UV5eaIsFQ2tgYJZ3+99dinxoNSnAudyW60naBUSQRc NX0KyvZF+y0Z2HnAOo1C2TsImXDPFY/pEvl3AGJbYV0RZdxh+YLNaAvEe/2/fFTUnN8o TEJA== X-Forwarded-Encrypted: i=1; AJvYcCWbrMgdFF0BPDB+iE/yUehcibFOE23QAOmBUHP7nYx3lg/9BMX2PTXowdwZUuHYUhK5GfimnpPP7WDKN0xnxEoQ3HN9p66TLidcFAkx X-Gm-Message-State: AOJu0YySH4ZY2jj/wP9p0nSft12Da4RziFIctY3TbTjqgALvi0hPqR9g +J+s3/tIq+XTgBrKuEV9S1y0aNkV8NBbaPFnwrNThLKrjE64Gazk6evPe8DiAB+a5F1+H6h9UYi 7uQiVfVe3+nvI0ijAqPmMZ5lJk0tsc/oECt/fayIJ2KwNs0hYgDGo7lyvKmDly5UoMXlA52f8Vz IqycdChcD7rYDMisBwh7Tzk4r7ZM3Ugz8Q16VYptSOlOyiwcbCUuAq X-Received: by 2002:a17:907:6d08:b0:a6f:489b:ff50 with SMTP id a640c23a62f3a-a6f489c0235mr351318666b.52.1718286472674; Thu, 13 Jun 2024 06:47:52 -0700 (PDT) X-Received: by 2002:a17:907:6d08:b0:a6f:489b:ff50 with SMTP id a640c23a62f3a-a6f489c0235mr351316366b.52.1718286472251; Thu, 13 Jun 2024 06:47:52 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240608025347.90680-1-chengen.du@canonical.com> <66660e3cd5636_8dbbb294c@willemb.c.googlers.com.notmuch> <666789d3d9d2a_bf52c294e9@willemb.c.googlers.com.notmuch> <6669abb1ea6da_125bdf29449@willemb.c.googlers.com.notmuch> In-Reply-To: <6669abb1ea6da_125bdf29449@willemb.c.googlers.com.notmuch> From: Chengen Du Date: Thu, 13 Jun 2024 21:47:41 +0800 Message-ID: Subject: Re: [PATCH v6] af_packet: Handle outgoing VLAN packets without hardware offloading To: Willem de Bruijn Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kaber@trash.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Willem, Thank you for the suggestion. I have conducted further tests and found that the results are not as we expected. I would like to explain my findings based on the following tests: ip link add link ens18 ens18.24 type vlan proto 802.1ad id 24 ip link add link ens18.24 ens18.24.25 type vlan proto 802.1Q id 25 ifconfig ens18.24 1.0.24.1/24 ifconfig ens18.24.25 1.0.25.1/24 ping -n 1.0.25.3 > /dev/null 2>&1 & tcpdump -nn -i any -y LINUX_SLL -Q out not tcp and not udp I have added more logs and found the following results: af_packet: tpacket_rcv: dev->name [ens18.24.25] af_packet: tpacket_rcv: dev->name [ens18.24] af_packet: vlan_get_tci: dev->name [ens18.24], min_header_len [14], hard_header_len [18] af_packet: prb_fill_vlan_info: ppd->hv1.tp_vlan_tci [0], ppd->hv1.tp_vlan_tpid [8100] af_packet: prb_fill_vlan_info: currect vlan_tci [19], tp_vlan_tpid [810= 0] af_packet: tpacket_rcv: dev->name [ens18] af_packet: vlan_get_tci: dev->name [ens18], min_header_len [14], hard_header_len [14] af_packet: prb_fill_vlan_info: ppd->hv1.tp_vlan_tci [18], ppd->hv1.tp_vlan_tpid [88a8] af_packet: prb_fill_vlan_info: currect vlan_tci [18], tp_vlan_tpid [88a= 8] It seems that the min_header_len has been set even though the device is ens18.24. I will continue investigating this issue. Thank you for your ongoing assistance. Best regards, Chengen Du On Wed, Jun 12, 2024 at 10:07=E2=80=AFPM Willem de Bruijn wrote: > > Chengen Du wrote: > > Hi Willem, > > > > On Tue, Jun 11, 2024 at 7:18=E2=80=AFAM Willem de Bruijn > > wrote: > > > > > > Chengen Du wrote: > > > > Hi Willem, > > > > > > > > I'm sorry, but I would like to confirm the issue further. > > > > > > > > On Mon, Jun 10, 2024 at 4:19=E2=80=AFAM Willem de Bruijn > > > > wrote: > > > > > > > > > > Chengen Du wrote: > > > > > > The issue initially stems from libpcap. The ethertype will be o= verwritten > > > > > > as the VLAN TPID if the network interface lacks hardware VLAN o= ffloading. > > > > > > In the outbound packet path, if hardware VLAN offloading is una= vailable, > > > > > > the VLAN tag is inserted into the payload but then cleared from= the sk_buff > > > > > > struct. Consequently, this can lead to a false negative when ch= ecking for > > > > > > the presence of a VLAN tag, causing the packet sniffing outcome= to lack > > > > > > VLAN tag information (i.e., TCI-TPID). As a result, the packet = capturing > > > > > > tool may be unable to parse packets as expected. > > > > > > > > > > > > The TCI-TPID is missing because the prb_fill_vlan_info() functi= on does not > > > > > > modify the tp_vlan_tci/tp_vlan_tpid values, as the information = is in the > > > > > > payload and not in the sk_buff struct. The skb_vlan_tag_present= () function > > > > > > only checks vlan_all in the sk_buff struct. In cooked mode, the= L2 header > > > > > > is stripped, preventing the packet capturing tool from determin= ing the > > > > > > correct TCI-TPID value. Additionally, the protocol in SLL is in= correct, > > > > > > which means the packet capturing tool cannot parse the L3 heade= r correctly. > > > > > > > > > > > > Link: https://github.com/the-tcpdump-group/libpcap/issues/1105 > > > > > > Link: https://lore.kernel.org/netdev/20240520070348.26725-1-che= ngen.du@canonical.com/T/#u > > > > > > Fixes: 393e52e33c6c ("packet: deliver VLAN TCI to userspace") > > > > > > Cc: stable@vger.kernel.org > > > > > > Signed-off-by: Chengen Du > > > > > > > > > > Overall, solid. > > > > > > > > > > > --- > > > > > > net/packet/af_packet.c | 57 ++++++++++++++++++++++++++++++++++= ++++++-- > > > > > > 1 file changed, 55 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c > > > > > > index ea3ebc160e25..8cffbe1f912d 100644 > > > > > > --- a/net/packet/af_packet.c > > > > > > +++ b/net/packet/af_packet.c > > > > > > @@ -538,6 +538,43 @@ static void *packet_current_frame(struct p= acket_sock *po, > > > > > > return packet_lookup_frame(po, rb, rb->head, status); > > > > > > } > > > > > > > > > > > > +static u16 vlan_get_tci(struct sk_buff *skb) > > > > > > +{ > > > > > > + struct vlan_hdr vhdr, *vh; > > > > > > + u8 *skb_orig_data =3D skb->data; > > > > > > + int skb_orig_len =3D skb->len; > > > > > > + > > > > > > + skb_push(skb, skb->data - skb_mac_header(skb)); > > > > > > + vh =3D skb_header_pointer(skb, ETH_HLEN, sizeof(vhdr), &v= hdr); > > > > > > > > > > Don't harcode Ethernet. > > > > > > > > > > According to documentation VLANs are used with other link layers. > > > > > > > > > > More importantly, in practice PF_PACKET allows inserting this > > > > > skb->protocol on any device. > > > > > > > > > > We don't use link layer specific constants anywhere in the packet > > > > > socket code for this reason. But instead dev->hard_header_len. > > > > > > > > > > One caveat there is variable length link layer headers, where > > > > > dev->min_header_len !=3D dev->hard_header_len. Will just have to = fail > > > > > on those. > > > > > > > > Thank you for pointing out this error. I would like to confirm if I > > > > need to use dev->hard_header_len to get the correct header length a= nd > > > > return zero if dev->min_header_len !=3D dev->hard_header_len to han= dle > > > > variable-length link layer headers. Is there something I > > > > misunderstand, or are there other aspects I need to consider furthe= r? > > > > > > That's right. > > > > > > The min_header_len !=3D hard_header_len check is annoying and may see= m > > > pedantic. But it's the only way to trust that the next header starts > > > at hard_header_len. > > > > Thank you for your advice. > > I have implemented the modification, but I found that the > > (min_header_len !=3D hard_header_len) check results in unexpected > > behavior in the following test scenario: > > ip link add link ens18 ens18.24 type vlan proto 802.1ad id 24 > > ip link add link ens18.24 ens18.24.25 type vlan proto 802.1Q id 25 > > ifconfig ens18.24 1.0.24.1/24 > > ifconfig ens18.24.25 1.0.25.1/24 > > ping -n 1.0.25.3 > /dev/null 2>&1 & > > tcpdump -nn -i any -y LINUX_SLL -Q out not tcp and not udp > > > > While receiving a packet from ens18.24.25 (802.1Q), the min_header_len > > and hard_header_len are 14 and 18, respectively. > > This check results in the TCI being 0 instead of 25. > > Should we skip this check to display the correct value, or is there > > another check that can achieve the same purpose? > > Interesting. Glad you found this. > > Makes sense, as VLAN devices have > > vlandev->hard_header_len =3D dev->hard_header_len + VLAN_HLEN; > > Does > > if (min_header_len && min_header_len !=3D hard_header_len) > > resolve it? > > Few devices actually set min_header_len. Initially, only Ethernet in > ether_setup() and loopback. It was introduced for validation in > dev_validate_header, and a min_header_len of 0 just skips some basic > validation. > > As long as VLAN devices do not initialize min_header_len (e.g., by > inheriting it from the physical device and incorrectly setting it to > ETH_HLEN), then this should be fine. >