From patchwork Tue Nov 19 10:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13879594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED093D60D1B for ; Tue, 19 Nov 2024 10:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=33FGTDxVghKRUjvQxe8n+i0NIxSacmlAlP2N6q7e0cg=; b=gAnbQkLavkzDVfypjF5otLXR+V HTAC7TJUZpXjeE70iHLMyITnXkwgcYUsO6991Fn9bTMXSxeQQHp1Xpd75DOz3bUvr0VHHW3XtMjmI PuVgFogPYSeZOVvcT4oGyLU2G1w/rByb57xR9mDQAK22MWJxT95ZBUMzssiWs8hl3q7xyuKY7fnF0 1P9Ma2CYQAcp5IJ3zlX+fVwlu9FEJGovOcgDO3tle0rYDc1N15L8AZkn1VYHmzosePvBZvJe9V2Xi KDp7satBTUzm/kSW5TjOJIJvkL7ZL7ei5q7fm+Ss4gKQ3iYxoEMmw1qtS9UHAVxheyaF26or5eIaY jMdS893A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tDLN7-0000000C1l7-2bvV; Tue, 19 Nov 2024 10:22:13 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tDLKN-0000000C0y9-2v2l; Tue, 19 Nov 2024 10:19:25 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a9a6acac4c3so124343966b.0; Tue, 19 Nov 2024 02:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732011562; x=1732616362; darn=lists.infradead.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=33FGTDxVghKRUjvQxe8n+i0NIxSacmlAlP2N6q7e0cg=; b=MDMkRtlm2E+CfGs44wKVQ65M1VcKe2XPDEkYV5s0STNh6HBenXQ18/c/A039Wqm0ql 0nYcOyBNkr07jf9Xm8VI2dEWVes8cQM3w4PuH+5C0pYEcHH5WqDYnDKOkFbg7oExMKk9 v8NofnWdkfiQnhsmhneMOljiY+S8iOd3kUnQsK1j9/X08Jo++gx34R6VFusIoK676Jzq 0yDnOufScUHcJsazUFOjMRb8rbH+pOWvYgwHchCQ7VYDkf1aJl+Jxx3k6bVk5xB8kW7L vzb2vPcmqiaxYZRm4XBogdFcSYY1qsg+wkeKpBI91aRNZquXiv5thihvMlraDM06FKfX zZYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732011562; x=1732616362; 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=33FGTDxVghKRUjvQxe8n+i0NIxSacmlAlP2N6q7e0cg=; b=wDyocGNXUgz6/mrBANEkf0UbI4GTQsC9exFslM5+U/fMHiJOhOSRI5vlRXxOstLPmw 7Zzlc4WKHBZwx7jzJVxQsnx3+mc3tStBdzmtcpRGokqEb+X4q0m+CO1SztU0F8+IS1iz ubZefp1YK1xO/3J+0WTWRZEDZfe0ifRNPsAlnk9YNYXnfNHfhtFFid9j7gMJfYsIClvO up6AEegWmJ6TZXomQeuLYDsk4WipjiT9WBdlVuryod+LuilQiHwy+DfU+8ozV0TvDeoy BT/71pGBmAkU9U6AQp04+z8kgxuVw7qxacEdRBW7KVeKErj6rdjQBLUAm7XeAR1hJ9e7 Umaw== X-Forwarded-Encrypted: i=1; AJvYcCUezfSLsI8Hrg+F9APjavqCdplPsK3bziW3BDwkSofuMeJtATXCzv0EfExYbC2gewtZ2MJlvSTJo/kytAoJao4=@lists.infradead.org, AJvYcCWH4F9kszV5UdzhgTRrSYh8Ka27/pxXKXTrDPWIYz2lm+3fjKwZaiQ2542wmTO64SaT5PaNP4cB6AeHhqTxUuRR@lists.infradead.org X-Gm-Message-State: AOJu0YyKkXMEefFyd0kBnPw3Z2Vr2bKFgjDXEKbHSKNLHfrMkIgPnXZ4 1QQAPXm2hJ0qJlSKwCEgX43bvmINl4dI5aMEbLbVU+NUnLqTt9Xr X-Google-Smtp-Source: AGHT+IHK3RPvVbNkL0ulMmObg1fv6oLItSdSeQYUnbTgITRiDHxNBFC5utDs26XSVr92XJ7sV7zGaQ== X-Received: by 2002:a17:907:96ac:b0:a9a:6477:bd03 with SMTP id a640c23a62f3a-aa483525d3dmr1598769866b.38.1732011561338; Tue, 19 Nov 2024 02:19:21 -0800 (PST) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e081574sm634875566b.179.2024.11.19.02.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 02:19:20 -0800 (PST) From: Eric Woudstra To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , Pablo Neira Ayuso , Jozsef Kadlecsik , Jiri Pirko , Ivan Vecera , Roopa Prabhu , Nikolay Aleksandrov , Matthias Brugger , AngeloGioacchino Del Regno , David Ahern , Sebastian Andrzej Siewior , Lorenzo Bianconi , Joe Damato , Alexander Lobakin , Vladimir Oltean , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Eric Woudstra Subject: [PATCH RFC v2 net-next 02/14] netfilter: bridge: Add conntrack double vlan and pppoe Date: Tue, 19 Nov 2024 11:18:54 +0100 Message-ID: <20241119101906.862680-3-ericwouds@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119101906.862680-1-ericwouds@gmail.com> References: <20241119101906.862680-1-ericwouds@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241119_021923_770145_D915BE4C X-CRM114-Status: GOOD ( 14.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This adds the capability to conntrack 802.1ad, QinQ, PPPoE and PPPoE-in-Q packets that are passing a bridge. Signed-off-by: Eric Woudstra --- net/bridge/netfilter/nf_conntrack_bridge.c | 88 ++++++++++++++++++---- 1 file changed, 75 insertions(+), 13 deletions(-) diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c index 816bb0fde718..31e2bcd71735 100644 --- a/net/bridge/netfilter/nf_conntrack_bridge.c +++ b/net/bridge/netfilter/nf_conntrack_bridge.c @@ -241,56 +241,118 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { struct nf_hook_state bridge_state = *state; + __be16 outer_proto, inner_proto; enum ip_conntrack_info ctinfo; + int ret, offset = 0; struct nf_conn *ct; - u32 len; - int ret; + u32 len, data_len; ct = nf_ct_get(skb, &ctinfo); if ((ct && !nf_ct_is_template(ct)) || ctinfo == IP_CT_UNTRACKED) return NF_ACCEPT; + switch (skb->protocol) { + case htons(ETH_P_PPP_SES): { + struct ppp_hdr { + struct pppoe_hdr hdr; + __be16 proto; + } *ph = (struct ppp_hdr *)(skb->data); + + data_len = ntohs(ph->hdr.length) - 2; + offset = PPPOE_SES_HLEN; + outer_proto = skb->protocol; + switch (ph->proto) { + case htons(PPP_IP): + inner_proto = htons(ETH_P_IP); + break; + case htons(PPP_IPV6): + inner_proto = htons(ETH_P_IPV6); + break; + default: + return NF_ACCEPT; + } + break; + } + case htons(ETH_P_8021Q): { + struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data); + + data_len = 0xffffffff; + offset = VLAN_HLEN; + outer_proto = skb->protocol; + inner_proto = vhdr->h_vlan_encapsulated_proto; + break; + } + default: + data_len = 0xffffffff; + break; + } + + if (offset) { + switch (inner_proto) { + case htons(ETH_P_IP): + case htons(ETH_P_IPV6): + if (!pskb_may_pull(skb, offset)) + return NF_ACCEPT; + skb_pull_rcsum(skb, offset); + skb_reset_network_header(skb); + skb->protocol = inner_proto; + break; + default: + return NF_ACCEPT; + } + } + + ret = NF_ACCEPT; switch (skb->protocol) { case htons(ETH_P_IP): if (!pskb_may_pull(skb, sizeof(struct iphdr))) - return NF_ACCEPT; + goto do_not_track; len = skb_ip_totlen(skb); + if (data_len < len) + len = data_len; if (pskb_trim_rcsum(skb, len)) - return NF_ACCEPT; + goto do_not_track; if (nf_ct_br_ip_check(skb)) - return NF_ACCEPT; + goto do_not_track; bridge_state.pf = NFPROTO_IPV4; ret = nf_ct_br_defrag4(skb, &bridge_state); break; case htons(ETH_P_IPV6): if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) - return NF_ACCEPT; + goto do_not_track; len = sizeof(struct ipv6hdr) + ntohs(ipv6_hdr(skb)->payload_len); + if (data_len < len) + len = data_len; if (pskb_trim_rcsum(skb, len)) - return NF_ACCEPT; + goto do_not_track; if (nf_ct_br_ipv6_check(skb)) - return NF_ACCEPT; + goto do_not_track; bridge_state.pf = NFPROTO_IPV6; ret = nf_ct_br_defrag6(skb, &bridge_state); break; default: nf_ct_set(skb, NULL, IP_CT_UNTRACKED); - return NF_ACCEPT; + goto do_not_track; } - if (ret != NF_ACCEPT) - return ret; + if (ret == NF_ACCEPT) + ret = nf_conntrack_in(skb, &bridge_state); - return nf_conntrack_in(skb, &bridge_state); +do_not_track: + if (offset) { + skb_push_rcsum(skb, offset); + skb_reset_network_header(skb); + skb->protocol = outer_proto; + } + return ret; } - static unsigned int nf_ct_bridge_in(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) {