From patchwork Mon Aug 5 10:56:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 13753508 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 830C61311AC for ; Mon, 5 Aug 2024 10:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855428; cv=none; b=M9PwNRiwA6z9hk/87NR5+m1Km86ytIEfkBv2lhmgm09rRY3asK5crgajxRFPODDuW0aE8FBVIbqg727G6vLzgSlW4GNXVTcVOdCcdsky79jI/6fnO4F0E3Kl+3sqLex37gfwMJNFNpjgrlbmKwKVYRNT1bFisOQ1FuHuVSpPwMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855428; c=relaxed/simple; bh=SlklGaSkB1CVAnGcEiIJsuqo82vRigsMVmvwV1Rzjjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DMqzxVddoSP8uLLjKx//YK3JM7EsfnoPAbQwRTBK4hjpxR++HOpNeDxxqqYKAgDYGJSb/OgHqgj8vF4FCKU+WZEePEB9bCK83vjyB73T1TjcYo1YECMKtaXrjtvk8zdMXzAZlL0KdbH3WIfNAiQji8KnTSBU9K1TD3MmNS+YIg0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=EBAEC6FT; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="EBAEC6FT" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7a1dcc7bc05so644637285a.0 for ; Mon, 05 Aug 2024 03:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1722855425; x=1723460225; darn=vger.kernel.org; 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=rJdRS+SiiKicF87avM76gJAE3mWhqo9TmxE70LOsA1M=; b=EBAEC6FTYU7l2GP3z86WI2d38sjdpYx1j9kGS3PgHwfx/+xh3+pFB/i/sgi3Sl7Sco HwX3GILYpYm77PybMXXQHlrt+7SWTNaJWsJCr1AWePvuVhXz618ZXtmD7a1Evr3b+1fy otSUglMLOLHCRr21L45lw+DigdGLbF5hAvXEA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722855425; x=1723460225; 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=rJdRS+SiiKicF87avM76gJAE3mWhqo9TmxE70LOsA1M=; b=gyVaE0g8g64zJB1QiJuNIzNAY8eUX5c7ot1+anh3J7JP2MbNYXa33seHeGW3qKpi5/ 5Sns5l/zX1k46OEvjUYaBGaFvuQ6oWwupjUHPQK0pvp62fblq++ei0MAG2Lxakd4Avbq tyqoWvQN40NdmSNjLzxsrnFx4GNVuJxCHhdTPfNkL4ncey1Bheu7KePq6z/FxIl1gl+y VYKRiIzSfB+lr7S/c83aOJg9vYOupZs8HB0WF/m+tGvTOUZksru1gyI8VAV7TwOih74r 43oNOI/yh5E3DHVUSBEvwlpXiTVnZ1bfG2vpC1HAy5xH83m7BJ47EOOz+l1ip8c6gDvv ri2g== X-Gm-Message-State: AOJu0YwNbA+GraOlEFSj32u72BzK1XMRNtDFMql9fAFcpKdwa77siuKX rfiEmOzI4GzS2IVQEXHG+ccwu8pY0BGn5AIx0Zza1AqROwFwyBYN//WZNzIX7ozxF9tWEGLVtt9 HOeALZ57wcMlztqJNg+ek20fR2MJGIRTFL0+F6RQVJ6LI2WIEZnC9aJsy8zWQBRTJQiiyB222mj C5RtEmz2LSR/wjA9jMA++vuIPfHlGSdOu+XG8bo5uUqnB3drJE X-Google-Smtp-Source: AGHT+IHNCD+4Q92uNk1E58bDL60e2TUajHHvn04aZ4fx9CN6Ys5PNOwtX2Ol089UZC8vL/uOe1ke2g== X-Received: by 2002:a05:620a:2492:b0:7a3:49dd:2002 with SMTP id af79cd13be357-7a34efe28c6mr1236419285a.55.1722855424913; Mon, 05 Aug 2024 03:57:04 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a34f6fb785sm332890785a.56.2024.08.05.03.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 03:57:04 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Mina Almasry , Pavel Begunkov , Alexander Lobakin , Lorenzo Bianconi , David Howells Cc: Ilya Lifshits Subject: [PATCH net-next 1/5] skb: add skb_vlan_flush helper Date: Mon, 5 Aug 2024 13:56:45 +0300 Message-ID: <20240805105649.1944132-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> References: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor flushing of the inner vlan in the skb_vlan_push by moving the code into static skb_vlan_flush helper. Signed-off-by: Boris Sukholitko --- net/core/skbuff.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 83f8cd8aa2d1..23f0db1db048 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6220,30 +6220,38 @@ int skb_vlan_pop(struct sk_buff *skb) } EXPORT_SYMBOL(skb_vlan_pop); +static int skb_vlan_flush(struct sk_buff *skb) +{ + int offset = skb->data - skb_mac_header(skb); + int err; + + if (WARN_ONCE(offset, + "skb_vlan_push got skb with skb->data not at mac header (offset %d)\n", + offset)) { + return -EINVAL; + } + + err = __vlan_insert_tag(skb, skb->vlan_proto, + skb_vlan_tag_get(skb)); + if (err) + return err; + + skb->protocol = skb->vlan_proto; + skb->mac_len += VLAN_HLEN; + + skb_postpush_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN); + return 0; +} + /* Push a vlan tag either into hwaccel or into payload (if hwaccel tag present). * Expects skb->data at mac header. */ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci) { if (skb_vlan_tag_present(skb)) { - int offset = skb->data - skb_mac_header(skb); - int err; - - if (WARN_ONCE(offset, - "skb_vlan_push got skb with skb->data not at mac header (offset %d)\n", - offset)) { - return -EINVAL; - } - - err = __vlan_insert_tag(skb, skb->vlan_proto, - skb_vlan_tag_get(skb)); + int err = skb_vlan_flush(skb); if (err) return err; - - skb->protocol = skb->vlan_proto; - skb->mac_len += VLAN_HLEN; - - skb_postpush_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN); } __vlan_hwaccel_put_tag(skb, vlan_proto, vlan_tci); return 0; From patchwork Mon Aug 5 10:56:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 13753509 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BA4E1311AC for ; Mon, 5 Aug 2024 10:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855432; cv=none; b=BuwjiSLcv0WHawRdx3ruGgz9Wc6tEFPtQoB9AAsYJ8yVtJHjmlXZMhOOe4pEsKw8YTgqR0vKPgQ4TR9+KGDYKyVW27/4zNRelLfb0H9vmoW4FtqmctfdSdL3j/3+mZSqrPvIFyQfeQdZhA8YAit82y6ea9zBh1IBgYtW58cPA3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855432; c=relaxed/simple; bh=YuT7tgOIJJfuO/twk1piOsn+GOR2DJ2NNNUzwgW9wPU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N0f6ppOrKlBGiWBtGEbpTEXTGYxvDiSKD756EVpTQ1GDjB9jVT3hHT1AuxGVgRlDLJ7THYyKPJd/csSaf0iPO69n+u67v/WNTlG2qO2z+EjtN4r3c9huKtdUb3BJ6r6wPhSAQOZSjcgqGgQ0zJi93VmdA2B9bRJzLWZxn4nDVzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=NWIznNum; arc=none smtp.client-ip=209.85.221.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="NWIznNum" Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-4f6d01961a7so3491238e0c.2 for ; Mon, 05 Aug 2024 03:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1722855428; x=1723460228; darn=vger.kernel.org; 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=pbTOvAUXILro3y1EmGJyFXmNSNhQtv1tC+lWw1ig7R0=; b=NWIznNumvJ/FN0k7lyPSBKvldgvjrwuBWjKwMX0OXiPXbmdbY2Sjh8Wn8BYYWEOmkU xXALAnR7Kat4bSkRTkFiVBTihOT7fMgtRp5jVckxxLPAZAskt1kO26EA3W/a3KMuT3ID gl6dwh5gHQUuTk35oxWw+4A//rshBXm3VtpOI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722855428; x=1723460228; 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=pbTOvAUXILro3y1EmGJyFXmNSNhQtv1tC+lWw1ig7R0=; b=Sv33VvGrCJMb796++03GsPndu0Hzw1Yh5w86YISTVoC6Eiw0cUVQgqlCWgk+Vz4vwU DEyvTqcqpdk215pXWKzalT3r/qCRKpcwN8+yX/tpoC/GYs7nOOH+e3KVVr4plVUvbFG/ EXrXSnLI1C/URbrt9icI7ey4SlDKuyDIDIzzFgTMEJsMs457lQQI8EScqOtmuJpGkPJl KYBf1bxKYmZrnaN3YCswVJMsfPMqWIHC1c1pMkQRFI72LXGOI3CTP7m66wm1rOCa+dQa fY7SN8qBN7l/THF0/Re3YyM8SNRnFqd7qTsf+Mr91aXUaXUQFNh3/DmK/QcVcXiZyxEM hCGQ== X-Gm-Message-State: AOJu0YzHKjr1uNz7HVtNuvx4EJOyrsWDLh1ILSqy3h1+w+luvK+mXxuK B4B9SR2PwAsl/XjY4k18Yt1VogXxVJ+oXjd6X3HAibzAOKJjFnfPEFSGGBV6h2B606g1yiMFE1M H41pIDhGxJRmxOLX58aXhACA42Ed/FW8op5VDvpOscmpPfEcKaRoAe0A1mdDLz2dqI/fjqvZQq1 ejJtqpnEgNm6Ed/6KmcPvX3fp89DlLgXzgjFors885QHTZJE3N X-Google-Smtp-Source: AGHT+IHBMK6AWxi05cPzy6n9vw1rBA38IcnbKl7jLheUm2ytKSvwc37qLxM13MMD/tIsT3TKz+yyfw== X-Received: by 2002:a05:6122:3c51:b0:4f2:e9eb:951e with SMTP id 71dfb90a1353d-4f8a000f41bmr11327752e0c.10.1722855428414; Mon, 05 Aug 2024 03:57:08 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a34f6fb785sm332890785a.56.2024.08.05.03.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 03:57:08 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Mina Almasry , Pavel Begunkov , Alexander Lobakin , Lorenzo Bianconi , David Howells Cc: Ilya Lifshits Subject: [PATCH net-next 2/5] skb: move mac_len adjustment out of skb_vlan_flush Date: Mon, 5 Aug 2024 13:56:46 +0300 Message-ID: <20240805105649.1944132-3-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> References: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Let its callers worry about skb headers adjustment. Signed-off-by: Boris Sukholitko --- net/core/skbuff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 23f0db1db048..1bd817c8ddc8 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6237,7 +6237,6 @@ static int skb_vlan_flush(struct sk_buff *skb) return err; skb->protocol = skb->vlan_proto; - skb->mac_len += VLAN_HLEN; skb_postpush_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN); return 0; @@ -6252,6 +6251,8 @@ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci) int err = skb_vlan_flush(skb); if (err) return err; + + skb->mac_len += VLAN_HLEN; } __vlan_hwaccel_put_tag(skb, vlan_proto, vlan_tci); return 0; From patchwork Mon Aug 5 10:56:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 13753510 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76DDB1311AC for ; Mon, 5 Aug 2024 10:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855435; cv=none; b=O12DIqYNuQSY0oKgfGhfdaYMf/LZzucntlMriZMBw3i35lOvxzGFKsNp3kDFZi+TXnHHfE/4eLf3p7++Z/6rjsqxK3cHhUTYOzY38Wc8UUh1yooDQ0JIEeuyOtkPiXctcVDuRGThOrYyRKR9yIZ7uCA51nXbZPr6pFgv9vVlC44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855435; c=relaxed/simple; bh=c0Z0S1anIl0K69+F6MOi89jUgaugq+mo8EhGncANIoE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cands0B9XIepFtAS3WwoFhETk8H3yv6ClGE3wYFDOPLFu9kOfowzvXEdUS1hmab5G4R5lVCOIEStrU1vUIjgCOhaEf1Hh+yseU3SEFGTu74ewm/xTGupXsP0lV5w9R+NXOWrlKFfw70moKVvADywU6a+D7cYF5Ho2sBIv29XlXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=T/TOuaux; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="T/TOuaux" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7a1d0dc869bso669354185a.2 for ; Mon, 05 Aug 2024 03:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1722855432; x=1723460232; darn=vger.kernel.org; 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=7BMdfpqrY5tm8/jK+EFC7SH1Yd5hnsxPDDCueoCM2z4=; b=T/TOuauxMt7zaGZEWJ5TKs2MaTj5DlkkrSWcJYVXO8L7WlGBJepx4iV9LPvQA/r7DR jgfp8zqgkD1CjvKVeya9g4/nq7kPdkHf9VSSiPtd41uQtgpf5KxccfFB/xk2uIcvEkjs 2xdRfQuSRmnrSbgEdTkmjUnksSLzghmbvCDvc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722855432; x=1723460232; 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=7BMdfpqrY5tm8/jK+EFC7SH1Yd5hnsxPDDCueoCM2z4=; b=Z4Kmziggn8vycdJMIa8JJarJtrieDzc/fMYViRdXRxHg8hOjS2bWRjyVFnWNkx0Odj 95BP8BPbdiSHlGCBJRO2MY8LzeZGa+877EGteeg/TcEZ0sU71IO0UQht5aqRA67B6dW7 MbxZTKc7TfFPxtG2RcdgEO3akaUr2dK/FNCyvD3amyNwqhaLe3ceR1umZIl8VQwQT8MB 7AtY4QWysT7P0FMCBG46G/eu56l0IjpZp4lcivns0sqQL9f9s3dkOmxT4aA6dOfTinPM zs3cAD1YJRHA7MkWVimPjl4ibbgnBeeBVMLNfFOV1MimuAymsE1KGO1eLYkm/Uw08SaI tpug== X-Gm-Message-State: AOJu0Yy+7OPO0fWzXnGwKv4eqCv20bM1Rnr15I4+fEDlRipbIZ/0nznj G95VtQgse5CSSZwDwf41tE7O0ZHUaHfR+IbTC+X+D7sis6aVSZ3eH2tHDEgrICq6lrt1+2qXMIz qnGKb61Kjk1XuxsgLu9QBZnT7HtDvO534ZMBkmN1R3eCKaljEri8L/4bFoomsPkrpV4kTQ1J4Jp xuncD6+MWNLt0JHyZwEaAVTM8Ad5RlapVZvWnlebD9ASlkqbGb X-Google-Smtp-Source: AGHT+IHV0rtcwfrolMcb0zSRySPcPqnrpeSzkUB5JDGw9DzWli+CgxKTr0pg8RUZdXtB98LPsNQzLQ== X-Received: by 2002:a05:620a:4311:b0:79e:ff18:b4f1 with SMTP id af79cd13be357-7a34efd836dmr1512439185a.51.1722855431813; Mon, 05 Aug 2024 03:57:11 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a34f6fb785sm332890785a.56.2024.08.05.03.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 03:57:11 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Mina Almasry , Pavel Begunkov , Alexander Lobakin , Lorenzo Bianconi , David Howells Cc: Ilya Lifshits Subject: [PATCH net-next 3/5] skb: export skb_vlan_flush Date: Mon, 5 Aug 2024 13:56:47 +0300 Message-ID: <20240805105649.1944132-4-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> References: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Make skb_vlan_flush callable by other customers of skbuff. Signed-off-by: Boris Sukholitko --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index cf8f6ce06742..5a9f06691c80 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -4054,6 +4054,7 @@ int skb_ensure_writable(struct sk_buff *skb, unsigned int write_len); int skb_ensure_writable_head_tail(struct sk_buff *skb, struct net_device *dev); int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci); int skb_vlan_pop(struct sk_buff *skb); +int skb_vlan_flush(struct sk_buff *skb); int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); int skb_eth_pop(struct sk_buff *skb); int skb_eth_push(struct sk_buff *skb, const unsigned char *dst, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1bd817c8ddc8..e28b2c8b717d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6220,7 +6220,7 @@ int skb_vlan_pop(struct sk_buff *skb) } EXPORT_SYMBOL(skb_vlan_pop); -static int skb_vlan_flush(struct sk_buff *skb) +int skb_vlan_flush(struct sk_buff *skb) { int offset = skb->data - skb_mac_header(skb); int err; @@ -6241,6 +6241,7 @@ static int skb_vlan_flush(struct sk_buff *skb) skb_postpush_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN); return 0; } +EXPORT_SYMBOL(skb_vlan_flush); /* Push a vlan tag either into hwaccel or into payload (if hwaccel tag present). * Expects skb->data at mac header. From patchwork Mon Aug 5 10:56:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 13753511 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8D67154BE4 for ; Mon, 5 Aug 2024 10:57:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855438; cv=none; b=mb1WhT/EYnztlO7EECcpCtk3j42wV7HLoa3dYEZ96E6MPiL9ksluyIv7baPTjZZPXKO4+6QusEI7DbCLIucRoSO8xZA8qyRY1xr53uw3Y/LiEyMvJnM4esOxwoExqV5gQYYxgcxeWULMCncm3BF8qiRLulfbTN/7TJjPqV7vZvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855438; c=relaxed/simple; bh=v/yXJrBDlpAQrlFKowIyb4g9XUvrM0bLLMWzVwzKonU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O1ClP0/UF2j3/J5LQRzCsdHKBG3/Bw9hgKKbY3oicuyhM2rAWz6dALig6rCs5FEJeX/hxdsaI5VzNA1TOoEQVSD4q6fNxXKhQk9E33KkjAExjcgjJgHK0K0FF32mv4Es6b+cNqbd2eQDM6vOudSWYhmYxdg3+iwtFc7xk5zuVZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=anHvnetz; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="anHvnetz" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7a1e2ac1ee5so662950085a.2 for ; Mon, 05 Aug 2024 03:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1722855435; x=1723460235; darn=vger.kernel.org; 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=5vsfsWl1qU21FyjK2pca4Vhgh1w520tV98Txp3TT/7s=; b=anHvnetzeXki9KIaeBg7uFGwmQxZJK6zXei++vYZXLzh3Vbt8ePVwkjpO3xyX+EoAz PqKEQbloBIUB4ObCJhjmMkMsDLDwm6yz+8Vp/o1V5cY/pEAoojO5T47q6eRxPt8Ir/n9 rKv/PqFAAGyhBUHaLzKn0UnpzfcKmVPut8Om4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722855435; x=1723460235; 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=5vsfsWl1qU21FyjK2pca4Vhgh1w520tV98Txp3TT/7s=; b=IytZM2yCFAbr3fT1Lcm40duUuAymq4gnCqEbzCPNIrIk1HPzEsJFBjl250HIKgv6b2 LSaarKrXgBJR5DxuYls7VPNLmuPd2ahfYpY/ucRtL4/hMNwz+kmdo/d/f0RKxYmbcNiS /IMAI2O9ZdlEY1zbMB1QgWriuiFqdbEHq4WgRqGyEoF9p7+QLDRV2RKVRmt6UODRJxHl PmBKk0XlPqLQFQhYiuDtvCNBQsL6KBc/GWXEpn465G3ORDho8sQ688DCAy1spvufGR5V SLTalhYePPNIP5XFjwY3KI/PBYlN/d6uasoIVm5HrNzxqXTAtr9HqWRhgwOb8B1Ud50e yNWg== X-Gm-Message-State: AOJu0YwFCKGmCb97fO7VboTY5KXaQsOVUpuacAx93litqBHC/JF4RthS P1pF3yB9aoqeu6cHNbvM2NAiXHUCAvlL3+M8tbsx3M8WHyHkEGQrP7DzoPgf9sX3Pbvt3b0v0Hv R/DDb9cilRgx1ECSrzVjC6zNrVFLCAuxWzOmpbmwzKXGmnjYkmYj2h2VsahxS36xOhhZf/A6PeT Tdor/vszAB1Wdcan0DvbkeMo1dp7dwSPXZrRqXOjatZXOjElNM X-Google-Smtp-Source: AGHT+IEmQEjwP1ujLpx4z2MXZ5ZWnHVoyC3L1CtWbmkdFBbRumLuxPvwGVAaYfa/la7U/St01o/DPA== X-Received: by 2002:a05:620a:424d:b0:7a1:c40d:7575 with SMTP id af79cd13be357-7a34eeeb1damr1339125485a.17.1722855435201; Mon, 05 Aug 2024 03:57:15 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a34f6fb785sm332890785a.56.2024.08.05.03.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 03:57:14 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Mina Almasry , Pavel Begunkov , Alexander Lobakin , Lorenzo Bianconi , David Howells Cc: Ilya Lifshits Subject: [PATCH net-next 4/5] act_vlan: open code skb_vlan_push Date: Mon, 5 Aug 2024 13:56:48 +0300 Message-ID: <20240805105649.1944132-5-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> References: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Prepare to do act_vlan specific network header adjustment by copy-pasting several lines of skb_vlan_push code. Signed-off-by: Boris Sukholitko --- net/sched/act_vlan.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c index 22f4b1e8ade9..84b79096df2a 100644 --- a/net/sched/act_vlan.c +++ b/net/sched/act_vlan.c @@ -49,10 +49,15 @@ TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb, goto drop; break; case TCA_VLAN_ACT_PUSH: - err = skb_vlan_push(skb, p->tcfv_push_proto, p->tcfv_push_vid | + if (skb_vlan_tag_present(skb)) { + err = skb_vlan_flush(skb); + if (err) + goto drop; + + skb->mac_len += VLAN_HLEN; + } + __vlan_hwaccel_put_tag(skb, p->tcfv_push_proto, p->tcfv_push_vid | (p->tcfv_push_prio << VLAN_PRIO_SHIFT)); - if (err) - goto drop; break; case TCA_VLAN_ACT_MODIFY: /* No-op if no vlan tag (either hw-accel or in-payload) */ From patchwork Mon Aug 5 10:56:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 13753512 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BCB1154BE4 for ; Mon, 5 Aug 2024 10:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855442; cv=none; b=HZ4ofzb6uDZXcZfSF1YHS/JfiZ3fnHYawwy0ixBC8jUpL6f5UZkIOZS8Gl7cwhkcmuMC56JYjkbiL3a3n76KTqBas2KotURPccHnivPmuJfpAMP5O1q6TIDVMezqE0LcMfo6sNJO/cvhnpgew7r9ZptGVWguVhm3YFTq4f+eXEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722855442; c=relaxed/simple; bh=awncP+NbvdzC4cT4Ugklak4GH4LxTINDlQi4Kzk3Y1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LcBTmhkUi9SEd6qZLiUIHh0mTKkPhUzlU94n26N166qewFjOU5xza5oCxp7ej9nhpJv/1JvgOGp+f9z1WEDeaeOgVCCoGj/0ax0Y59FheC1lLDOyzP0NAlSJWJPttLAKytY4dj6Otfcwi1lq7c7YqhUwdAb8dSsYoX1P00jcOOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=fR3JF2OZ; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="fR3JF2OZ" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7a1d024f775so651315785a.2 for ; Mon, 05 Aug 2024 03:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1722855439; x=1723460239; darn=vger.kernel.org; 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=d+8wRwU8tWwhWYpBIsJnKE89P/+rgqOTvwYqNON+ucs=; b=fR3JF2OZSpctz0kjl573m4cFqoODlrq6IEeR/EZgSW/wLxXgooHjWSk6O9pRnx52aS wb+ExPHIOJ8qz/ZdQDqhI5ixSFPZUcegqDzQRhWZWmZjLxsjBZAxNmIV3IrsWRz6KPMv OnSWzaknnEceAVaeD/XOcaOynSkkM84ylOFKg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722855439; x=1723460239; 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=d+8wRwU8tWwhWYpBIsJnKE89P/+rgqOTvwYqNON+ucs=; b=EX7TDyvh/ql83wO0kNtVGSgQ+F2XzKTRonZVStMS4I9Yq842Z+XjySULMrQ95x7aV0 lHYH/OK3NG//k7wJtjeHid8FlnDsQu3DaOEM0hba0TGHQmbvqj3Z+aAV/9/Uy+/YXSU4 iA+24XXW0w5xKvG7Ry6RnAAkCalGoGINnlsKKCowuK6SenkH/+JW0l9J+mTxgATZie66 CM1+Nu2JyR32ICLBTYOZQ+cmFFC+lDAKAaQA3PaOHlX3uKDX6Q3fU/4guWz2nREtr/v1 tq3/Fhq2ysEdHquN5PY/4wn1xpQIbncDwJOSWyKE7zb5BJwP3sCzX/+2jXZLHcda8pAb aa3Q== X-Gm-Message-State: AOJu0YzlS0fhXcpTfZj2Cj64yr6WrIJ4wLtm7DQj577wEXkOp6tJd4l7 atZdRxfAf4iRy0LEiOp4qctt08tgrv2USapggWP7BSbvYrLDu8BM0/qX9bru1FCi/4zs8BRf3fI 2c0m7LVwhFkpAv+Qu6vcUMXVWkpOpTI9hBmiAhI4MM5CAfVw/pz+BGx8uSVi2DgUVNY+vuKteAz LZYj0xwQzKuEFnmi217JZnp0Xjg+jTK8gh3Ld5nX4KW1T8gtuP X-Google-Smtp-Source: AGHT+IEdEjv2ni5DoSRb5xkTGxVJpDpnNgTP3dFWjWHv8VlKMY/CZGn0s4RBr2Vi489i5lpBOM3woQ== X-Received: by 2002:a05:620a:f14:b0:7a1:dc75:5293 with SMTP id af79cd13be357-7a34efc902bmr1461622785a.58.1722855438580; Mon, 05 Aug 2024 03:57:18 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a34f6fb785sm332890785a.56.2024.08.05.03.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 03:57:18 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Mina Almasry , Pavel Begunkov , Alexander Lobakin , Lorenzo Bianconi , David Howells Cc: Ilya Lifshits Subject: [PATCH net-next 5/5] act_vlan: adjust network header Date: Mon, 5 Aug 2024 13:56:49 +0300 Message-ID: <20240805105649.1944132-6-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> References: <20240805105649.1944132-1-boris.sukholitko@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Consider the following shell script snippet configuring TC rules on the veth interface: ip link add veth0 type veth peer veth1 ip link set veth0 up ip link set veth1 up tc qdisc add dev veth0 clsact tc filter add dev veth0 ingress pref 10 chain 0 flower \ num_of_vlans 2 cvlan_ethtype 0x800 action goto chain 5 tc filter add dev veth0 ingress pref 20 chain 0 flower \ num_of_vlans 1 action vlan push id 100 \ protocol 0x8100 action goto chain 5 tc filter add dev veth0 ingress pref 30 chain 5 flower \ num_of_vlans 2 cvlan_ethtype 0x800 action simple sdata "success" Sending double-tagged vlan packet with the IP payload inside: cat <protocol; } else { vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan); if (!vlan) { fdret = FLOW_DISSECT_RET_OUT_BAD; break; } proto = vlan->h_vlan_encapsulated_proto; nhoff += sizeof(*vlan); } The "else" clause above gets the protocol of the encapsulated packet from the skb data at the network header location. printk debugging has showed that in the good double-tagged packet case proto is htons(0x800 == ETH_P_IP) as expected. However in the single-tagged packet case proto is garbage leading to the failure to match tc filter 30. proto is being set from the skb header pointed by nhoff parameter which is defined at the beginning of __skb_flow_dissect (net/core/flow_dissector.c:1055 in the current version): nhoff = skb_network_offset(skb); Therefore the culprit seems to be that the skb network offset is different between double-tagged packet received from the interface and single-tagged packet having its vlan tag pushed by TC. Lets look at the interesting points of the lifetime of the single/double tagged packets as they traverse our packet flow. Both of them will start at __netif_receive_skb_core where the first vlan tag will be stripped: if (eth_type_vlan(skb->protocol)) { skb = skb_vlan_untag(skb); if (unlikely(!skb)) goto out; } At this stage in double-tagged case skb->data points to the second vlan tag while in single-tagged case skb->data points to the network (eg. IP) header. Looking at TC vlan push action (net/sched/act_vlan.c) we have the following code at tcf_vlan_act (interesting points are in square brackets): if (skb_at_tc_ingress(skb)) [1] skb_push_rcsum(skb, skb->mac_len); .... case TCA_VLAN_ACT_PUSH: if (skb_vlan_tag_present(skb)) { int err = skb_vlan_flush(skb); if (err) goto drop; [2] skb->mac_len += VLAN_HLEN; } break; .... out: if (skb_at_tc_ingress(skb)) [3] skb_pull_rcsum(skb, skb->mac_len); Lets look at what happens with skb->data of the single-tagged packet at each of the above points: 1. As a result of the skb_push_rcsum, skb->data is moved back to the start of the packet. 2. First VLAN tag is moved from the skb into packet buffer, skb->mac_len is incremented, skb->data still points to the start of the packet. 3. As a result of the skb_pull_rcsum, skb->data is moved forward by the modified skb->mac_len, thus pointing to the network header again. Then __skb_flow_dissect will get confused by having double-tagged vlan packet with the skb->data at the network header. The same bug happens also on the egress path. The root cause there is that skb->network_header is in disagreement with skb->mac_len. This patch fixes both of the above problems by adjusting skb->network_header rather than skb->mac_vlan. skb->mac_vlan is being reset accordingly after skb_pull_rcsum is done. Signed-off-by: Boris Sukholitko --- net/sched/act_vlan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c index 84b79096df2a..c113f8026f1f 100644 --- a/net/sched/act_vlan.c +++ b/net/sched/act_vlan.c @@ -54,7 +54,7 @@ TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb, if (err) goto drop; - skb->mac_len += VLAN_HLEN; + skb->network_header -= VLAN_HLEN; } __vlan_hwaccel_put_tag(skb, p->tcfv_push_proto, p->tcfv_push_vid | (p->tcfv_push_prio << VLAN_PRIO_SHIFT)); @@ -101,6 +101,7 @@ TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb, if (skb_at_tc_ingress(skb)) skb_pull_rcsum(skb, skb->mac_len); + skb_reset_mac_len(skb); return action; drop: