Netfilter updates for net-next
Subsystems (5)
Florian Westphal
maintainercover Netfilter updates for net-next
Hi,
The following set contains updates for the *net-next* tree:
1. nf_tables 'brouting' support, from Sriram Yagnaraman.
2. Update bridge netfilter and ovs conntrack helpers to handle IPv6 Jumbo packets properly, i.e. fetch the packet length from hop-by-hop extension header, from Xin Long.
This comes with a test BIG TCP test case, added to tools/testing/selftests/net/.
3. Fix spelling and indentation in conntrack, from Jeremy Sowden.
Please consider pulling from
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git
----------------------------------------------------------------
The following changes since commit 7d8c48917a9576b5fc8871aa4946149b0e4a4927:
dt-bindings: net: dsa: mediatek,mt7530: change some descriptions to literal (2023-03-08 13:05:37 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git main
for you to fetch changes up to b0ca200077b3872056e6a8291c9a50f803658c2a:
netfilter: nat: fix indentation of function arguments (2023-03-08 14:25:44 +0100)
----------------------------------------------------------------
Jeremy Sowden (2):
netfilter: conntrack: fix typo
netfilter: nat: fix indentation of function arguments
Sriram Yagnaraman (1):
netfilter: bridge: introduce broute meta statement
Xin Long (6):
netfilter: bridge: call pskb_may_pull in br_nf_check_hbh_len
netfilter: bridge: check len before accessing more nh data
netfilter: bridge: move pskb_trim_rcsum out of br_nf_check_hbh_len
netfilter: move br_nf_check_hbh_len to utils
netfilter: use nf_ip6_check_hbh_len in nf_ct_skb_network_trim
selftests: add a selftest for big tcp
include/linux/netfilter_ipv6.h | 2 + include/uapi/linux/netfilter/nf_tables.h | 2 + net/bridge/br_netfilter_ipv6.c | 79 ++-------- net/bridge/netfilter/nft_meta_bridge.c | 71 ++++++++- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_ovs.c | 11 +- net/netfilter/nf_nat_core.c | 4 +- net/netfilter/utils.c | 52 +++++++ tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/big_tcp.sh | 180 +++++++++++++++++++++++ 10 files changed, 327 insertions(+), 77 deletions(-) create mode 100755 tools/testing/selftests/net/big_tcp.sh
Florian Westphal
maintainerPATCH 1/9 netfilter: bridge: introduce broute meta statement
From: Sriram Yagnaraman <[email protected]>
nftables equivalent for ebtables -t broute.
Implement broute meta statement to set br_netfilter_broute flag in skb to force a packet to be routed instead of being bridged.
--- include/uapi/linux/netfilter/nf_tables.h | 2 + net/bridge/netfilter/nft_meta_bridge.c | 71 +++++++++++++++++++++++- 2 files changed, 70 insertions(+), 3 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -931,6 +931,7 @@ enum nft_exthdr_attributes {* @NFT_META_TIME_HOUR: hour of day (in seconds) * @NFT_META_SDIF: slave device interface index * @NFT_META_SDIFNAME: slave device interface name +* @NFT_META_BRI_BROUTE: packet br_netfilter_broute bit */ enum nft_meta_keys {NFT_META_LEN ,
@@ -969,6 +970,7 @@ enum nft_meta_keys {NFT_META_TIME_HOUR ,NFT_META_SDIF ,NFT_META_SDIFNAME , +NFT_META_BRI_BROUTE , __NFT_META_IIFTYPE, };
net/bridge/netfilter/nft_meta_bridge.c +68 -3
95 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH net-next 1/9] netfilter: bridge: introduce broute meta statement
This series was applied to netdev/net-next.git (main) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Florian Westphal <[email protected]>:
Quoted 8 lines · On Wed, 8 Mar 2023 20:30:25 +0100 you wrote:
From: Sriram Yagnaraman <[email protected]>
nftables equivalent for ebtables -t broute.
Implement broute meta statement to set
br_netfilter_brouteflag in skb to force a packet to be routed instead of being bridged.[...]
Here is the summary with links:
- [net-next,1/9] netfilter: bridge: introduce broute meta statement
https://git.kernel.org/netdev/net-next/c/4386b9218577 - [net-next,2/9] netfilter: bridge: call pskb_may_pull in br_nf_check_hbh_len https://git.kernel.org/netdev/net-next/c/9ccff83b1322 - [net-next,3/9] netfilter: bridge: check len before accessing more nh data https://git.kernel.org/netdev/net-next/c/a7f1a2f43e68 - [net-next,4/9] netfilter: bridge: move pskb_trim_rcsum out of br_nf_check_hbh_len https://git.kernel.org/netdev/net-next/c/0b24bd71a6c0 - [net-next,5/9] netfilter: move br_nf_check_hbh_len to utils https://git.kernel.org/netdev/net-next/c/28e144cf5f72 - [net-next,6/9] netfilter: use nf_ip6_check_hbh_len in nf_ct_skb_network_trim https://git.kernel.org/netdev/net-next/c/eaafdaa3e922 - [net-next,7/9] selftests: add a selftest for big tcp https://git.kernel.org/netdev/net-next/c/6bb382bcf742 - [net-next,8/9] netfilter: conntrack: fix typo https://git.kernel.org/netdev/net-next/c/e5d015a114da - [net-next,9/9] netfilter: nat: fix indentation of function arguments https://git.kernel.org/netdev/net-next/c/b0ca200077b3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH 2/9 netfilter: bridge: call pskb_may_pull in br_nf_check_hbh_len
In reply to Florian WestphalFrom: Xin Long <[email protected]>
When checking Hop-by-hop option header, if the option data is in nonlinear area, it should do pskb_may_pull instead of discarding the skb as a bad IPv6 packet.
--- net/bridge/br_netfilter_ipv6.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
net/bridge/br_netfilter_ipv6.c +9 -5
@@ -45,14 +45,18 @@*/ static int br_nf_check_hbh_len (struct sk_buff *skb) { -unsigned char *raw = (u8 *)(ipv6_hdr (skb) +1 ); +int len, off =sizeof (struct ipv6hdr ); +unsigned char *nh;u32 pkt_len; -const unsigned char *nh =skb_network_header (skb); -int off = raw - nh; -int len = (raw[1 ] +1 ) <<3 ; -if ((raw + len) - skb->data >skb_headlen (skb)) +if (!pskb_may_pull (skb, off +8 )) goto bad; + nh = (unsigned char *)(ipv6_hdr (skb) +1 ); + len = (nh[1 ] +1 ) <<3 ; + +if (!pskb_may_pull (skb, off + len)) + goto bad; + nh =skb_network_header (skb); off +=2 ; len -=2 ;
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 3/9 netfilter: bridge: check len before accessing more nh data
In reply to Florian WestphalFrom: Xin Long <[email protected]>
In the while loop of br_nf_check_hbh_len(), similar to ip6_parse_tlv(), before accessing 'nh[off + 1]', it should add a check 'len < 2'; and before parsing IPV6_TLV_JUMBO, it should add a check 'optlen > len', in case of overflows.
--- net/bridge/br_netfilter_ipv6.c | 45 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-)
net/bridge/br_netfilter_ipv6.c +20 -25
@@ -50,54 +50,49 @@ static int br_nf_check_hbh_len(struct sk_buff *skb)u32 pkt_len;if (!pskb_may_pull (skb, off +8 )) - goto bad; +return -1 ; nh = (unsigned char *)(ipv6_hdr (skb) +1 ); len = (nh[1 ] +1 ) <<3 ;if (!pskb_may_pull (skb, off + len)) - goto bad; +return -1 ; nh =skb_network_header (skb); off +=2 ; len -=2 ; -while (len >0 ) { -int optlen = nh[off +1 ] +2 ; - -switch (nh[off]) { -case IPV6_TLV_PAD1 : - optlen =1 ; -break ; +int optlen; -case IPV6_TLV_PADN : -break ; +if (nh[off] ==IPV6_TLV_PAD1 ) { + off++; + len--; +continue ; + } +if (len <2 ) +return -1 ; + optlen = nh[off +1 ] +2 ; +if (optlen > len) +return -1 ; -case IPV6_TLV_JUMBO : +if (nh[off] ==IPV6_TLV_JUMBO ) {if (nh[off +1 ] !=4 || (off &3 ) !=2 ) - goto bad; +return -1 ; pkt_len =ntohl (*(__be32 *)(nh + off +2 ));if (pkt_len <=IPV6_MAXPLEN ||ipv6_hdr (skb)->payload_len) - goto bad; +return -1 ;if (pkt_len > skb->len -sizeof (struct ipv6hdr )) - goto bad; +return -1 ;if (pskb_trim_rcsum (skb, pkt_len +sizeof (struct ipv6hdr ))) - goto bad; +return -1 ; nh =skb_network_header (skb); -break ; -default : -if (optlen > len) - goto bad; -break ; } off += optlen; len -= optlen; } -if (len ==0 ) -return 0 ; -bad: -return -1 ; + +return len ?-1 :0 ; }int br_validate_ipv6 (struct net *net,struct sk_buff *skb)
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 4/9 netfilter: bridge: move pskb_trim_rcsum out of br_nf_check_hbh_len
In reply to Florian WestphalFrom: Xin Long <[email protected]>
br_nf_check_hbh_len() is a function to check the Hop-by-hop option header, and shouldn't do pskb_trim_rcsum() there. This patch is to pass pkt_len out to br_validate_ipv6() and do pskb_trim_rcsum() after calling br_validate_ipv6() instead.
--- net/bridge/br_netfilter_ipv6.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-)
net/bridge/br_netfilter_ipv6.c +14 -19
@@ -43,11 +43,10 @@/* We only check the length. A bridge shouldn't do any hop-by-hop stuff * anyway */ -static int br_nf_check_hbh_len (struct sk_buff *skb) +static int br_nf_check_hbh_len (struct sk_buff *skb,u32 *plen) {int len, off =sizeof (struct ipv6hdr );unsigned char *nh; -u32 pkt_len;if (!pskb_may_pull (skb, off +8 ))return -1 ;
@@ -75,6 +74,8 @@ static int br_nf_check_hbh_len(struct sk_buff *skb)return -1 ;if (nh[off] ==IPV6_TLV_JUMBO ) { +u32 pkt_len; +if (nh[off +1 ] !=4 || (off &3 ) !=2 )return -1 ; pkt_len =ntohl (*(__be32 *)(nh + off +2 ));
@@ -83,10 +84,7 @@ static int br_nf_check_hbh_len(struct sk_buff *skb)return -1 ;if (pkt_len > skb->len -sizeof (struct ipv6hdr ))return -1 ; -if (pskb_trim_rcsum (skb, - pkt_len +sizeof (struct ipv6hdr ))) -return -1 ; - nh =skb_network_header (skb); + *plen = pkt_len; } off += optlen; len -= optlen;
@@ -114,22 +112,19 @@ int br_validate_ipv6(struct net *net, struct sk_buff *skb) goto inhdr_error; pkt_len =ntohs (hdr->payload_len); +if (hdr->nexthdr ==NEXTHDR_HOP &&br_nf_check_hbh_len (skb, &pkt_len)) + goto drop; -if (pkt_len || hdr->nexthdr !=NEXTHDR_HOP ) { -if (pkt_len + ip6h_len > skb->len) { -__IP6_INC_STATS (net, idev, -IPSTATS_MIB_INTRUNCATEDPKTS ); - goto drop; - } -if (pskb_trim_rcsum (skb, pkt_len + ip6h_len)) { -__IP6_INC_STATS (net, idev, -IPSTATS_MIB_INDISCARDS ); - goto drop; - } - hdr =ipv6_hdr (skb); +if (pkt_len + ip6h_len > skb->len) { +__IP6_INC_STATS (net, idev, +IPSTATS_MIB_INTRUNCATEDPKTS ); + goto drop; } -if (hdr->nexthdr ==NEXTHDR_HOP &&br_nf_check_hbh_len (skb)) +if (pskb_trim_rcsum (skb, pkt_len + ip6h_len)) { +__IP6_INC_STATS (net, idev, +IPSTATS_MIB_INDISCARDS ); goto drop; + }memset (IP6CB (skb),0 ,sizeof (struct inet6_skb_parm ));/* No IP options in IPv6 header; however it should be
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 5/9 netfilter: move br_nf_check_hbh_len to utils
In reply to Florian WestphalFrom: Xin Long <[email protected]>
Rename br_nf_check_hbh_len() to nf_ip6_check_hbh_len() and move it to netfilter utils, so that it can be used by other modules, like ovs and tc.
--- include/linux/netfilter_ipv6.h | 2 ++ net/bridge/br_netfilter_ipv6.c | 55 +--------------------------------- net/netfilter/utils.c | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 54 deletions(-)
include/linux/netfilter_ipv6.h +2 -0
@@ -197,6 +197,8 @@ static inline int nf_cookie_v6_check(const struct ipv6hdr *iph,__sum16 nf_ip6_checksum (struct sk_buff *skb,unsigned int hook,unsigned int dataoff,u_int8_t protocol); +int nf_ip6_check_hbh_len (struct sk_buff *skb,u32 *plen); +int ipv6_netfilter_init (void );void ipv6_netfilter_fini (void );
net/bridge/br_netfilter_ipv6.c +1 -54
67 lines not on this page · raw message
net/netfilter/utils.c +52 -0
55 lines not on this page · raw message
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 6/9 netfilter: use nf_ip6_check_hbh_len in nf_ct_skb_network_trim
In reply to Florian WestphalFrom: Xin Long <[email protected]>
For IPv6 Jumbo packets, the ipv6_hdr(skb)->payload_len is always 0, and its real payload_len ( > 65535) is saved in hbh exthdr. With 0 length for the jumbo packets, all data and exthdr will be trimmed in nf_ct_skb_network_trim().
This patch is to call nf_ip6_check_hbh_len() to get real pkt_len of the IPv6 packet, similar to br_validate_ipv6().
--- net/netfilter/nf_conntrack_ovs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_ovs.c +9 -2
@@ -6,6 +6,7 @@#include <net/netfilter/ipv6/nf_defrag_ipv6.h> #include <net/ipv6_frag.h> #include <net/ip.h> +#include <linux/netfilter_ipv6.h> /* 'skb' should already be pulled to nh_ofs. */ int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,
@@ -120,8 +121,14 @@ int nf_ct_skb_network_trim(struct sk_buff *skb, int family) len =skb_ip_totlen (skb);break ;case NFPROTO_IPV6 : - len =sizeof (struct ipv6hdr ) - +ntohs (ipv6_hdr (skb)->payload_len); + len =ntohs (ipv6_hdr (skb)->payload_len); +if (ipv6_hdr (skb)->nexthdr ==NEXTHDR_HOP ) { +int err =nf_ip6_check_hbh_len (skb, &len); + +if (err) +return err; + } + len +=sizeof (struct ipv6hdr );break ;default : len = skb->len;
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 7/9 selftests: add a selftest for big tcp
In reply to Florian WestphalFrom: Xin Long <[email protected]>
This test runs on the client-router-server topo, and monitors the traffic on the RX devices of router and server while sending BIG TCP packets with netperf from client to server. Meanwhile, it changes 'tso' on the TX devs and 'gro' on the RX devs. Then it checks if any BIG TCP packets appears on the RX devs with 'ip/ip6tables -m length ! --length 0:65535' for each case.
Note that we also add tc action ct in link1 ingress to cover the ipv6 jumbo packets process in nf_ct_skb_network_trim() of nf_conntrack_ovs.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/big_tcp.sh | 180 +++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100755 tools/testing/selftests/net/big_tcp.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -48,6 +48,7 @@ TEST_PROGS += l2_tos_ttl_inherit.sh TEST_PROGS += bind_bhash.sh TEST_PROGS += ip_local_port_range.sh TEST_PROGS += rps_default_mask.sh +TEST_PROGS += big_tcp.sh TEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh TEST_GEN_FILES = socket nettest
tools/testing/selftests/net/big_tcp.sh new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 8/9 netfilter: conntrack: fix typo
In reply to Florian WestphalFrom: Jeremy Sowden <[email protected]>
There's a spelling mistake in a comment. Fix it.
--- net/netfilter/nf_conntrack_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1294,7 +1294,7 @@ __nf_conntrack_confirm(struct sk_buff *skb) }EXPORT_SYMBOL_GPL (__nf_conntrack_confirm); -/* Returns true if a connection correspondings to the tuple (required +/* Returns true if a connection corresponds to the tuple (required for NAT). */ int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
Signature · 1 line
2.39.2
Florian Westphal
maintainerPATCH 9/9 netfilter: nat: fix indentation of function arguments
In reply to Florian WestphalFrom: Jeremy Sowden <[email protected]>
A couple of arguments to a function call are incorrectly indented. Fix them.
--- net/netfilter/nf_nat_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_nat_core.c +2 -2
@@ -549,8 +549,8 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,if (range->flags &NF_NAT_RANGE_PROTO_SPECIFIED ) {if (!(range->flags &NF_NAT_RANGE_PROTO_OFFSET ) &&l4proto_in_range (tuple, maniptype, - &range->min_proto, - &range->max_proto) && + &range->min_proto, + &range->max_proto) && (range->min_proto.all == range->max_proto.all || !nf_nat_used_tuple (tuple, ct)))return ;
Signature · 1 line
2.39.2