Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2837702lqo; Mon, 20 May 2024 20:32:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYclEt3Ql8iYFcszVDw/wjaugtjKvEbrRA+Ky9uPUI2Bofugwc2X8EjlQqPsDeTsKlfA55l9MAKPfd62rXlclcKL9rgDdL3zMrKI8wiA== X-Google-Smtp-Source: AGHT+IE7Gc/htqNY/f/US6UeWskeWmGcFfZnaR3WCqQSByTyQY46UDaJ6l6KEw7iQCf7p7GIF0DC X-Received: by 2002:a05:6a21:6da1:b0:1a9:5e1f:8485 with SMTP id adf61e73a8af0-1afde1180a2mr30192534637.31.1716262345277; Mon, 20 May 2024 20:32:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716262345; cv=pass; d=google.com; s=arc-20160816; b=ZdNo1Mh00Fsj28kXGQjT9HUcCqm5WkEnjMIQrABQdn56guE6hQptaJ4gUqy2kLSJtY hXkR1uMZOAh5HF/cJvHzE2tA+8Z6sb5fCTKONRFjcmAFommWwspNh33iKdu4bVJ3kM5R 5c/XzCgox7Fch0FXS76ducvbSBb9rW8lzn5XE2ew6/tWI2ipveUIf3pl0CB01JQGGhqD eo+SARRPncKhyWvA3VgqdSZsdN/hCafGT5UHdkUkxUcgA2fJhRWjbz3ldEGEvW+sWc9m pQb1iClKzFi0kM1Xwv4tyEZ/cEC/vF4FtO1mv0nUjQlASvMuwbtLLWiIWjKxmQzhi8Bb +/xA== 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=oRT4EC1vFVwwe/RwAMWjDpt+UAEk61rLUizH+FeKckE=; fh=TjOZmDzRTn5pVf5Czr17UECjS+oVNVqwf+Gyu2LYPNk=; b=NrPNYSB66WhBD8ZqRSXt+BWuFYhRnu5qZDi5PrWe4MCgx45hOW+yrF1NnA2MAu8iX0 cPEI1vwB09npfZxnrzl9ccwcge9sPKb83o+O50iOoroWmmWEJdDj61PcdpN+RIKcxEsW zn/QTX8ciBVK7YGxXADJFAlUOPnitsaCzwi/lzinZHtsb6J0lLhvIhYitPrwxcDro5/Q v+hocz6TB2WE7yzp0ElUmxPLodSlA9GTYlbFHCnl2ryqkCdtC/tAy1wcVzxD+FgP6F5f vxNLbACtCmJ6n5kFwa7Gm7dTrg7JguMb3ESOBS/oG+ZLG6jPMMXnlQRzC3h0S1kuBX8H 4pFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="dVZY/b1w"; 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-184464-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184464-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b628869477si9205146a91.15.2024.05.20.20.32.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 20:32:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184464-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="dVZY/b1w"; 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-184464-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184464-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A6ED2828F9 for ; Tue, 21 May 2024 03:32:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50A1C1B299; Tue, 21 May 2024 03:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="dVZY/b1w" 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 AA297210FB for ; Tue, 21 May 2024 03:31:55 +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=1716262318; cv=none; b=SvxL4qYpFoxo2wEfrqTkIsJAaFIOldhluSw/a1pqxRuQAfo5EBHSdArf8e3doNef98EjdGAa56hzIR51WWB9i8jTyDRZ/oCB0m5LEtjXuFGj8vffSd0mg0r7vbfmj9u/dCLrKhBYyYS/DQOOWTrBRgLCL8UbgpzuNTIE+uyFVi4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716262318; c=relaxed/simple; bh=MFCU+pjB3KCKhjmKoPu7wpzHpc58NnIFXFSypYZ2ds4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=nFiKkwRDarmAPxCxPCY8g1f9e655IqKI4xS0fFslsPLoTXoNg4r/IhkUYLVtF9eYCuDqp8+10UXrE8OktGLPhSKyi/t/6Iz/bCKJOwBscx26IafLpC6BMQY476jv8QrhrjJ0ah3svmkJDLkVc/FFUQTVF1ytzeI60DaQlm7qGK4= 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=dVZY/b1w; 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-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (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 A20763F331 for ; Tue, 21 May 2024 03:31:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1716262313; bh=oRT4EC1vFVwwe/RwAMWjDpt+UAEk61rLUizH+FeKckE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=dVZY/b1wgbSp1oD1d6pAxFCX6N/oFTO9SFqa74hRmKu0YIaPS/0DgHKQ83RDXpCnn LxlmB00qb7Qzmr1nvPoaMCgKUPNLHP9zYV8dhWHgTISsH2bXkWJmlP2jryKldkJF+k Wppy1wf2c4TpUBpCi3tlwftGzosyplpaJTGMHCbxoRpKVAo6h/+Hv0t63/F0Y+JsT6 G9XnhFMc5xU+Rve7C525juoO56tDZ95TvgUk6Fjlz0lvpPyKgpfb/nAZo0pdcurEWX cmwcK9UKcfUPpdjrNyecsWZr/IRd3222VtesOVtfPWsGx3PTsyQVkyQ5glvqJCXVEE PFHo8l0ExVAAQ== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a59a63a1f78so707596766b.0 for ; Mon, 20 May 2024 20:31:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716262313; x=1716867113; 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=oRT4EC1vFVwwe/RwAMWjDpt+UAEk61rLUizH+FeKckE=; b=a3LnLFd2pUtlkSpv1jWTxzgymn1X/BIO0smsQiwfo8FZHBgRgb4cydzWxREu50/t3x dGN/yDjjJDiCZ0Ex2ZiEFiy1v7C1TQLX+YKqL/rMn+go3Lw1pi4Sb9WHjaCYOfAD8ivb LkKUPAFZO49iTiBUiLNOaykJP+3A7OmOME+TWfWAy1tY7nU22jtD2uIthSV4QKda+kA0 WE0hcKs/+HhI+RtzXOck0RKJK4z1rzBI4EKTo8qmogrwIXi8zBrAM2JYy7gX2HFks2Mw Gidw7hWb5ylG9JitGab7cxkbmxqijGQoQvjBjqypmmftFblxmYNjdr2DkAiwGf9ioDrM q3NA== X-Forwarded-Encrypted: i=1; AJvYcCUv/4HMrf939qsopeEC74kbMPO8BKIu0hzLrewMnKhKPKvrS83tnzMhHDy8obH29QHUakzm/KqcylirqPcT2e5xZkFpmVkxR4Dx8e5y X-Gm-Message-State: AOJu0YyfXjCt6tUsQHg87tqpj2hltRKRlUsOkxOJbz8L5ERiqDUS0GGH hNs1gtsw/SUPc1OQTrtk1BVCszH+hwx/MCgD4AQzG+3ERHFz2buIcha42bTASyFt3P7jzwYAavM WhKYSoBogd2iHQbWzpSKDYudcMpJvGQc1+lorurVuYDMxF1SuDkvOC85IOIYZNcej4PiPrEPGFv mvfB+cxjp3oitwFV9kDwMzcm+3ycyDyCGQvW97iXhoO0dYWlIQ/BVL X-Received: by 2002:a17:906:c452:b0:a59:ee81:fd68 with SMTP id a640c23a62f3a-a5a2d68089bmr1950750366b.71.1716262313284; Mon, 20 May 2024 20:31:53 -0700 (PDT) X-Received: by 2002:a17:906:c452:b0:a59:ee81:fd68 with SMTP id a640c23a62f3a-a5a2d68089bmr1950749466b.71.1716262312944; Mon, 20 May 2024 20:31:52 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240520070348.26725-1-chengen.du@canonical.com> <664b97e8abe7a_12b4762946f@willemb.c.googlers.com.notmuch> In-Reply-To: <664b97e8abe7a_12b4762946f@willemb.c.googlers.com.notmuch> From: Chengen Du Date: Tue, 21 May 2024 11:31:42 +0800 Message-ID: Subject: Re: [PATCH] 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, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Willem, Thank you for your response. I would appreciate any suggestions you could offer, as I am not as familiar with this area as you are. I encountered an issue while capturing packets using tcpdump, which leverages the libpcap library for sniffing functionalities. Specifically, when I use "tcpdump -i any" to capture packets and hardware VLAN offloading is unavailable, some bogus packets appear. In this scenario, Linux uses cooked-mode capture (SLL) for the "any" device, reading from a PF_PACKET/SOCK_DGRAM socket instead of the usual PF_PACKET/SOCK_RAW socket. Using SOCK_DGRAM instead of SOCK_RAW means that the Linux socket code does not supply the packet's link-layer header. Based on the code in af_packet.c, SOCK_DGRAM strips L2 headers from the original packets and provides SLL for some L2 information. From the receiver's perspective, the VLAN information can only be parsed from SLL, which causes issues if the kernel stores VLAN information in the payload. As you mentioned, this modification affects existing PF_PACKET receivers. For example, libpcap needs to change how it parses VLAN packets with the PF_PACKET/SOCK_RAW socket. The lack of VLAN information in SLL may prevent the receiver from properly decoding the L3 frame in cooked mode. I am new to this area and would appreciate it if you could kindly correct any misunderstandings I might have about the mechanism. I would also be grateful for any insights you could share on this issue. Additionally, I am passionate about contributing to resolving this issue and am willing to work on patches based on your suggestions. Thank you for your time and assistance. Best regards, Chengen Du On Tue, May 21, 2024 at 2:35=E2=80=AFAM Willem de Bruijn wrote: > > Chengen Du wrote: > > In the outbound packet path, if hardware VLAN offloading is unavailable= , > > the VLAN tag is inserted into the payload but then cleared from the > > metadata. Consequently, this could lead to a false negative result when > > checking for the presence of a VLAN tag using skb_vlan_tag_present(), > > causing the packet sniffing outcome to lack VLAN tag information. As a > > result, the packet capturing tool may be unable to parse packets as > > expected. > > > > Signed-off-by: Chengen Du > > This is changing established behavior, which itself may confuse > existing PF_PACKET receivers. > > The contract is that the VLAN tag can be observed in the payload or > as tp_vlan_* fields if it is offloaded. > > > @@ -2457,7 +2464,8 @@ static int tpacket_rcv(struct sk_buff *skb, struc= t net_device *dev, > > sll->sll_halen =3D dev_parse_header(skb, sll->sll_addr); > > sll->sll_family =3D AF_PACKET; > > sll->sll_hatype =3D dev->type; > > - sll->sll_protocol =3D skb->protocol; > > + sll->sll_protocol =3D eth_type_vlan(skb->protocol) ? > > + vlan_eth_hdr(skb)->h_vlan_encapsulated_proto : skb->proto= col; > > This is a particularly subtle change of behavior. > > > if (skb_vlan_tag_present(skb)) { > > aux.tp_vlan_tci =3D skb_vlan_tag_get(skb); > > aux.tp_vlan_tpid =3D ntohs(skb->vlan_proto); > > - aux.tp_status |=3D TP_STATUS_VLAN_VALID | TP_STAT= US_VLAN_TPID_VALID; > > + } else if (eth_type_vlan(skb->protocol)) { > > + aux.tp_vlan_tci =3D ntohs(vlan_eth_hdr(skb)->h_vl= an_TCI); > > + aux.tp_vlan_tpid =3D ntohs(skb->protocol); > > } else { > > aux.tp_vlan_tci =3D 0; > > aux.tp_vlan_tpid =3D 0; > > } > > + if (aux.tp_vlan_tci || aux.tp_vlan_tpid) > > + aux.tp_status |=3D TP_STATUS_VLAN_VALID | TP_STAT= US_VLAN_TPID_VALID; > > put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &a= ux); > > vlan_tci 0 is valid identifier. That's the reason explicit field > TP_STATUS_VLAN_VALID was added. >