Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp384611lqp; Wed, 22 May 2024 07:27:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmE29OP/4QOaRjR8j6UzetESHFoYWm5HMnS8QtsloEyG8Ca7UM9bNge3kKlCCLukn/6oCbWfhJU8w2o2OVRtLSmBKepJwPv85T7vrbFA== X-Google-Smtp-Source: AGHT+IHDwY/0Fvj9vRl0SJFfZgpCgzhjnvdo7OMwtLHLRTSQ6BjzrL7PVXrWrXKXYi3oV8Coy7qE X-Received: by 2002:a05:6214:3d8e:b0:6ab:7178:c70a with SMTP id 6a1803df08f44-6ab7f3331bemr19620676d6.13.1716388077806; Wed, 22 May 2024 07:27:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716388077; cv=pass; d=google.com; s=arc-20160816; b=Dj21vA6cbB/YN41XxxNxaPHYTFwwW98r5KSY1ETtt4pinj7x+4PJSA/GPy0yHV39+P HAqsGh3aSiRoRwRcaslm2W6U+/9ZEoWC1m+1k3G89hImtsgptmV5cP147/kJ30PnnVdg UpBPRCTouFn5lx5isShWxvUbykahX2pOFrg8z23oIUF2rtG50c4msfks5VEEqRb7tM5R QwG+dDb475ddyqX7JYNxR4U7lVwcm8UkCGq8deZLEoDqfg1du0KtEuxpe6Rj7Qp6TEcL /lezUrk0vEKcyiAnCCephtxKzbeHzaDW0GxDQmD2EYznyt5fS4dDiq0kMnjrkyFRrq+C awMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=SbBPwv5GSuNadWkN/Ype/GvbpCPfCZDny7K84NYcp+M=; fh=N2S7gIkPKGXDZO6aS9tWY/BYIUUViTac0NxhglgQO0s=; b=aZNmWhfFAPH5hX2fJPMG8IkORW1AartRaS5ooY6IGnaTD5NIsiYYI4btn03ZrL26Y/ h9AldnB3hKR0tFZn7Xo9k61KeHViDECO2MApfHzmmRysSolSrbJbz3AkkFIM3lHaGNPN daOHK3j8Sql+Y2bUakrm3xb0nQeV7+IIpqY20InDfVx7DPCzJF5Kg7Jd5uhfCf/R9sSB hzAj/37dKcapQHUbiwFBvmJxIOKHXavGYExTL9K0DImNXwIySbedwEiLW6tBPpxygUe0 nDAfTiM+K0e40oV7JdYvOaaDNWZcfnwEYWwKAOiqHwEdPFU++iFiFn1AD8xmz5yWksg+ lhzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=SQSSP6QB; 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-186365-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186365-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf364fffsi775463885a.591.2024.05.22.07.27.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 07:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186365-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=SQSSP6QB; 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-186365-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186365-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 77FAB1C22F8B for ; Wed, 22 May 2024 14:27:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65C391419B5; Wed, 22 May 2024 14:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="SQSSP6QB" 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 485531411FA for ; Wed, 22 May 2024 14:27:45 +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=1716388068; cv=none; b=ZfonnhOr3gSHLvnblpW/XR8JB9zkxxbWqcUgPFVe+OdoGDyZmLQKJgWHr86XfJV5LP5dO12Q6Gw5r4tgO6B44NIYmA/3UIT49ApBz8p933Nou5cg4cMEaBssy4krLR6bZf0mtGlTsyx1O+fPEO7dpS7qIYBA10WljMknpK2nPOY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388068; c=relaxed/simple; bh=SbBPwv5GSuNadWkN/Ype/GvbpCPfCZDny7K84NYcp+M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Q5E85KgDtWXvegIYGQ/NtjjUhNp+6DU74t64kRq4k7m9vYvrSf7Dh1vW40mm6Jeqi9kjmwOMVklqxb/DkohiPnWFM0SR1zAa3dCoFJeMv3Nw1P0xPr3z3oRRIa8co0L0bYYsykSAScXHwJggQywEVCiWvA8rKAw7l/UHGkFUskw= 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=SQSSP6QB; 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-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) (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 23C093F339 for ; Wed, 22 May 2024 14:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1716388062; bh=SbBPwv5GSuNadWkN/Ype/GvbpCPfCZDny7K84NYcp+M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SQSSP6QBCHza1n+PqCJT0sF2ABPUMZZPQ0P0Kx9Z/M3fVkGbb1q1BHW+Nl3QKz2P3 i1ehIlI4PLp8HYATlCJEJPlbaiw1msxnnI2SJZZjYYy7BWhHApXap78iCG3sCKUpU/ kGwoHWYyFezjeP6pBD68ythDXEcFYojFJSOA9LgJPA4Zdj/AN2DNOsu1iltEsKl9Rp /qU4b5vHLkfIk7qdoRHWOhxjg6OyRYcdra4M7jYQrZ/CRor40S3Ih66ZdfsqboxinD TDUkgf6JssyKuIH/cnXGFlcUFgleQEIOXZTWTHLtD40FWpFc/Ls8YRCOnAAvGBU/d1 troRJJXjuJD0w== Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2e2c59a053cso2310401fa.0 for ; Wed, 22 May 2024 07:27:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716388061; x=1716992861; h=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=SbBPwv5GSuNadWkN/Ype/GvbpCPfCZDny7K84NYcp+M=; b=wR297k53Rigq5qLBK/m3wzrMRJsyDMNPz/XF1YIT8ciPcC46Vu5MTVNF5IjnF0tB81 InuJLlCkZELZvefrZtFvfbIoVweWbwwFew8T0UI4EyMi9wjYal7u2iG+4txnzndqlEyN Mt60hiAYKUC2T1vhpc1O5Z+7M3sEPnt0GiDfwN1R0tiyT/Rf9kklVOX4cttYMp7SO6XX ocEiadrH96jsbj5IS1WQA5IblXhlokz/snddVt56kakWvaPCnbnrBLPa5wzchr6paCX5 SdelUFPT/xhIxtUCRiHvJh/OfYJQJCremjow59bFUaxJcuE6uWCDewlJG+6Mw8Bmu/Ft PPRA== X-Forwarded-Encrypted: i=1; AJvYcCVyzWqqvZbSchV2503iz/ov50A/5tCqkP9YCM2szwdB7cq9baUHI4gZkZ/zqP7fF2zWGj9ozDvv46WWiaU34Ne3x+oNs5Z53TpflsWp X-Gm-Message-State: AOJu0YwTYhRuI/CjXEwdh5e0m94D68ZzL9e6JtjOdz5WaSBRDMDMRqNV 2+30tgMszLzeB6KsXmwSEv3yh3WfaM3cq4ktcwvwMnGYWoYtf14UQNQ4VBs7VbYQx+jzSiH6nnu gCNMJ0/czkgGm7GVixVfK7+cmk+w1mFR5bSyO91zLgmLaS/J7m/fXBO5ZeKokef8k7mgymqMfG5 KjVghxwm4nSg0U0s3dAlyLdp8VkMhxqXkJxsuHd+VxS+mFI/4XcyqW X-Received: by 2002:a2e:2c16:0:b0:2e0:6313:fe3a with SMTP id 38308e7fff4ca-2e949540d05mr18142521fa.35.1716388061026; Wed, 22 May 2024 07:27:41 -0700 (PDT) X-Received: by 2002:a2e:2c16:0:b0:2e0:6313:fe3a with SMTP id 38308e7fff4ca-2e949540d05mr18142291fa.35.1716388060589; Wed, 22 May 2024 07:27:40 -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> <664ca1651b66_14f7a8294cb@willemb.c.googlers.com.notmuch> In-Reply-To: <664ca1651b66_14f7a8294cb@willemb.c.googlers.com.notmuch> From: Chengen Du Date: Wed, 22 May 2024 22:27:28 +0800 Message-ID: Subject: Re: [PATCH] af_packet: Handle outgoing VLAN packets without hardware offloading To: Willem de Bruijn Cc: Paolo Abeni , davem@davemloft.net, edumazet@google.com, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: multipart/mixed; boundary="000000000000a6bba006190bbcfa" --000000000000a6bba006190bbcfa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Paolo, Thank you for your useful suggestions and information. Hi Willem, The issue initially stems from libpcap [1]. Upon their further investigation, another issue was discovered, leading to a kernel request [2] that describes the problem in detail. In essence, the kernel does not provide VLAN information if hardware VLAN offloading is unavailable in cooked mode. The TCI-TPID is missing because the prb_fill_vlan_info() function in af_packet.c does not modify the tp_vlan_tci/tp_vlan_tpid values since the information is in the payload and not in the sk_buff struct. In cooked mode, the L2 header is stripped, preventing the receiver from determining the correct TCI-TPID value. Additionally, the protocol in SLL is incorrect, which means the receiver cannot parse the L3 header correctly. To reproduce the issue, please follow these steps: 1. ip link add link ens18 ens18.24 type vlan id 24 2. ifconfig ens18.24 1.0.24.1/24 3. ping -n 1.0.24.3 > /dev/null 2>&1 & 4. tcpdump -nn -i any -Q out not tcp and not udp The attached experiment results show that the protocol is incorrectly parsed as IPv4, which leads to inaccurate outcomes. Thanks to Paolo's suggestion, I propose that we add a new bit in the status to indicate the presence of VLAN information in the payload and modify the header's entry (i.e., tp_vlan_tci/tp_vlan_tpid) accordingly. For the sll_protocol part, we can introduce a new member in the sockaddr_ll struct to represent the VLAN-encapsulated protocol, if applicable. In my humble opinion, this approach will not affect current users who rely on the status to handle VLAN parsing, and the sll_protocol will remain unchanged. Please kindly provide your feedback on this proposal, as there may be important points I have overlooked. If this approach seems feasible, I will submit a new version next week. Your assistance and opinions on this issue are important to me, and I truly appreciate them. Best regards, Chengen Du [1] https://github.com/the-tcpdump-group/libpcap/issues/1105 [2] https://marc.info/?l=3Dlinux-netdev&m=3D165074467517201&w=3D4 On Tue, May 21, 2024 at 9:28=E2=80=AFPM Willem de Bruijn wrote: > > Paolo Abeni wrote: > > On Tue, 2024-05-21 at 11:31 +0800, Chengen Du wrote: > > > 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. > > Bogus how exactly? > > > > 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. > > Trying to extract L2 or VLAN information from the any device may be > the real issue here. > > > > > > > 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. > > ETH_HLEN is pulled, but the VLAN tag is still present, right? > > > > > > > As you mentioned, this modification affects existing PF_PACKET receiv= ers. > > > 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 iss= ue. > > > Additionally, I am passionate about contributing to resolving this > > > issue and am willing to work on patches based on your suggestions. > > > > One possible way to address the above in a less invasive manner, could > > be allocating a new TP_STATUS_VLAN_HEADER_IS_PRESENT bit, set it for > > SLL when the vlan is not stripped by H/W and patch tcpdump to interpret > > such info. > > Any change must indeed not break existing users. It's not sufficient > to change pcap/tcpdump. There are lots of other PF_PACKET users out > there. Related, it is helpful to verify that tcpdump agrees to a patch > before we change the ABI for it. --000000000000a6bba006190bbcfa Content-Type: application/vnd.tcpdump.pcap; name="any_sll.pcap" Content-Disposition: attachment; filename="any_sll.pcap" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lwhx0e5n0 1MOyoQIABAAAAAAAAAAAAAAABABxAAAAGPhNZqvjCgAsAAAALAAAAAAEAAEABqoRvXX09QAACAYA AQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDGPhNZq3jCgAsAAAALAAAAAAEAAEABqoRvXX09QAA gQAAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDGfhNZsNBCwAsAAAALAAAAAAEAAEABqoRvXX0 9QAACAYAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDGfhNZsRBCwAsAAAALAAAAAAEAAEABqoR vXX09QAAgQAAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDGvhNZv6eCwAsAAAALAAAAAAEAAEA BqoRvXX09QAACAYAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDGvhNZgCfCwAsAAAALAAAAAAE AAEABqoRvXX09QAAgQAAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDG/hNZs38CwAsAAAALAAA AAAEAAEABqoRvXX09QAACAYAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgDG/hNZtL8CwAsAAAA LAAAAAAEAAEABqoRvXX09QAAgQAAAQgABgQAAaoRvXX09QEAGAEAAAAAAAABABgD --000000000000a6bba006190bbcfa--