conntrack: bridge: add double vlan, pppoe and pppoe-in-q
Subsystems (4)
v14 cover conntrack: bridge: add double vlan, pppoe and pppoe-in-q
Conntrack bridge only tracks untagged and 802.1q.
To make the bridge-fastpath experience more similar to the forward-fastpath experience, add double vlan, pppoe and pppoe-in-q tagged packets to bridge conntrack and to bridge filter chain.
Changes in v14:
- nf_checksum(_patial): Use DEBUG_NET_WARN_ON_ONCE( !skb_pointer_if_linear()) instead of pskb_may_pull().
- nft_do_chain_bridge: Added default case ph->proto is neither ipv4 nor ipv6.
- nft_do_chain_bridge: only reset network header when ret == NF_ACCEPT.
Changes in v13:
- Do not use pull/push before/after calling nf_conntrack_in() or nft_do_chain().
- Add patch to correct calculating checksum when skb->data != skb_network_header(skb).
Changes in v12:
- Only allow tracking this traffic when a conntrack zone is set.
- nf_ct_bridge_pre(): skb pull/push without touching the checksum, because the pull is always restored with push.
- nft_do_chain_bridge(): handle the extra header similar to nf_ct_bridge_pre(), using pull/push.
Changes in v11:
- nft_do_chain_bridge(): Proper readout of encapsulated proto.
- nft_do_chain_bridge(): Use skb_set_network_header() instead of thoff.
- removed test script, it is now in separate patch.
v10 split from patch-set: bridge-fastpath and related improvements v9
Eric Woudstra (3):
netfilter: utils: nf_checksum(_partial) correct data!=networkheader
netfilter: bridge: Add conntrack double vlan and pppoe
netfilter: nft_chain_filter: Add bridge double vlan and pppoe
net/bridge/netfilter/nf_conntrack_bridge.c | 88 ++++++++++++++++++---- net/netfilter/nft_chain_filter.c | 59 ++++++++++++++- net/netfilter/utils.c | 20 +++-- 3 files changed, 144 insertions(+), 23 deletions(-)
Signature · 1 line
2.47.1
PATCH v14 1/3 netfilter: utils: nf_checksum(_partial) correct data!=networkheader
In the conntrack hook it may not always be the case that:skb_network_header(skb) == skb->data.
This is problematic when L4 function nf_conntrack_handle_packet() is accessing L3 data. This function uses thoff and ip_hdr() to finds it's data. But it also calculates the checksum. nf_checksum() and nf_checksum_partial() both use lower skb-checksum functions that are based on using skb->data.
When skb_network_header(skb) != skb->data, adjust accordingly, so that the checksum is calculated correctly.
--- net/netfilter/utils.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
net/netfilter/utils.c +14 -6
@@ -124,16 +124,20 @@ __sum16 nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, u8 protocol, unsigned short family) { + unsigned int nhpull = skb_network_header(skb) - skb->data;__sum16 csum =0 ; +DEBUG_NET_WARN_ON_ONCE (!skb_pointer_if_linear (skb, nhpull,0 )); +__skb_pull (skb, nhpull);switch (family) {case AF_INET : - csum =nf_ip_checksum (skb, hook, dataoff, protocol); + csum =nf_ip_checksum (skb, hook, dataoff - nhpull, protocol);break ;case AF_INET6 : - csum =nf_ip6_checksum (skb, hook, dataoff, protocol); + csum =nf_ip6_checksum (skb, hook, dataoff - nhpull, protocol);break ; } +__skb_push (skb, nhpull);return csum; }
@@ -143,18 +147,22 @@ __sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, unsigned int len, u8 protocol, unsigned short family) { + unsigned int nhpull = skb_network_header(skb) - skb->data;__sum16 csum =0 ; +DEBUG_NET_WARN_ON_ONCE (!skb_pointer_if_linear (skb, nhpull,0 )); +__skb_pull (skb, nhpull);switch (family) {case AF_INET : - csum =nf_ip_checksum_partial (skb, hook, dataoff, len, - protocol); + csum =nf_ip_checksum_partial (skb, hook, dataoff - nhpull, + len, protocol);break ;case AF_INET6 : - csum =nf_ip6_checksum_partial (skb, hook, dataoff, len, - protocol); + csum =nf_ip6_checksum_partial (skb, hook, dataoff - nhpull, + len, protocol);break ; } +__skb_push (skb, nhpull);return csum; }
Signature · 1 line
2.47.1
PATCH v14 2/3 netfilter: bridge: Add conntrack double vlan and pppoe
In reply to Eric WoudstraThis adds the capability to conntrack 802.1ad, QinQ, PPPoE and PPPoE-in-Q packets that are passing a bridge, only when a conntrack zone is set.
--- net/bridge/netfilter/nf_conntrack_bridge.c | 88 ++++++++++++++++++---- 1 file changed, 72 insertions(+), 16 deletions(-)
net/bridge/netfilter/nf_conntrack_bridge.c +72 -16
@@ -242,53 +242,109 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, {struct nf_hook_state bridge_state = *state;enum ip_conntrack_info ctinfo; +u32 len, data_len =U32_MAX ; +int ret, offset =0 ;struct nf_conn *ct; -u32 len; -int ret; +__be16 outer_proto; ct =nf_ct_get (skb, &ctinfo);if ((ct && !nf_ct_is_template (ct)) || ctinfo ==IP_CT_UNTRACKED )return NF_ACCEPT ; +if (ct &&nf_ct_zone_id (nf_ct_zone (ct),CTINFO2DIR (ctinfo)) != +NF_CT_DEFAULT_ZONE_ID ) { +switch (skb->protocol) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph; + + offset =PPPOE_SES_HLEN ; +if (!pskb_may_pull (skb, offset)) +return NF_ACCEPT ; + outer_proto = skb->protocol; + ph = (struct ppp_hdr *)(skb->data); +switch (ph->proto) { +case htons (PPP_IP ): + skb->protocol =htons (ETH_P_IP ); +break ; +case htons (PPP_IPV6 ): + skb->protocol =htons (ETH_P_IPV6 ); +break ; +default : +nf_ct_set (skb,NULL ,IP_CT_UNTRACKED ); +return NF_ACCEPT ; + } + data_len =ntohs (ph->hdr.length) -2 ; +skb_set_network_header (skb, offset); +break ; + } +case htons (ETH_P_8021Q ): { +struct vlan_hdr *vhdr; + + offset =VLAN_HLEN ; +if (!pskb_may_pull (skb, offset)) +return NF_ACCEPT ; + outer_proto = skb->protocol; + vhdr = (struct vlan_hdr *)(skb->data); + skb->protocol = vhdr->h_vlan_encapsulated_proto; + data_len =U32_MAX ; +skb_set_network_header (skb, offset); +break ; + } + } + } + + ret =NF_ACCEPT ;switch (skb->protocol) {case htons (ETH_P_IP ): -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) -return NF_ACCEPT ; +if (!pskb_may_pull (skb, offset +sizeof (struct iphdr ))) + goto do_not_track; len =skb_ip_totlen (skb); -if (pskb_trim_rcsum (skb, len)) -return NF_ACCEPT ; +if (data_len < len) + len = data_len; +if (pskb_trim_rcsum (skb, offset + len)) + 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 ; +if (!pskb_may_pull (skb, offset +sizeof (struct ipv6hdr ))) + goto do_not_track; len =sizeof (struct ipv6hdr ) +ntohs (ipv6_hdr (skb)->payload_len); -if (pskb_trim_rcsum (skb, len)) -return NF_ACCEPT ; +if (data_len < len) + len = data_len; +if (pskb_trim_rcsum (skb, offset + len)) + 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_reset_network_header (skb); + skb->protocol = outer_proto; + } +return ret; } static unsigned int nf_ct_bridge_in(void *priv, struct sk_buff *skb,
Signature · 1 line
2.47.1
PATCH v14 3/3 netfilter: nft_chain_filter: Add bridge double vlan and pppoe
In reply to Eric WoudstraThis adds the capability to evaluate 802.1ad, QinQ, PPPoE and PPPoE-in-Q packets in the bridge filter chain.
--- net/netfilter/nft_chain_filter.c | 59 +++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
net/netfilter/nft_chain_filter.c +58 -1
@@ -232,11 +232,62 @@ nft_do_chain_bridge(void *priv,struct sk_buff *skb, const struct nf_hook_state *state) { + __be16 outer_proto, proto = 0;struct nft_pktinfo pkt; +int ret, offset =0 ;nft_set_pktinfo (&pkt, skb, state);switch (eth_hdr (skb)->h_proto) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph; + +if (!pskb_may_pull (skb,PPPOE_SES_HLEN )) +break ; + ph = (struct ppp_hdr *)(skb->data); +switch (ph->proto) { +case htons (PPP_IP ): + offset =PPPOE_SES_HLEN ; + outer_proto = skb->protocol; + proto =htons (ETH_P_IP ); +skb_set_network_header (skb, offset); + skb->protocol = proto; +break ; +case htons (PPP_IPV6 ): + offset =PPPOE_SES_HLEN ; + outer_proto = skb->protocol; + proto =htons (ETH_P_IPV6 ); +skb_set_network_header (skb, offset); + skb->protocol = proto; +break ; +default : + proto =eth_hdr (skb)->h_proto; +break ; + } +break ; + } +case htons (ETH_P_8021Q ): { +struct vlan_hdr *vhdr; + +if (!pskb_may_pull (skb,VLAN_HLEN )) +break ; + vhdr = (struct vlan_hdr *)(skb->data); + offset =VLAN_HLEN ; + outer_proto = skb->protocol; + proto = vhdr->h_vlan_encapsulated_proto; +skb_set_network_header (skb, offset); + skb->protocol = proto; +break ; + } +default : + proto =eth_hdr (skb)->h_proto; +break ; + } + +switch (proto) {case htons (ETH_P_IP ):nft_set_pktinfo_ipv4_validate (&pkt);break ;
@@ -248,7 +299,13 @@ nft_do_chain_bridge(void *priv,break ; } -return nft_do_chain (&pkt, priv); + ret =nft_do_chain (&pkt, priv); + +if (offset && ret ==NF_ACCEPT ) { +skb_reset_network_header (skb); + skb->protocol = outer_proto; + } +return ret; }static const struct nft_chain_type nft_chain_filter_bridge = {
Signature · 1 line
2.47.1
Florian Westphal
maintainerRe: [PATCH v14 nf-next 2/3] netfilter: bridge: Add conntrack double vlan and pppoe
In reply to Eric Woudstranet/bridge/netfilter/nf_conntrack_bridge.c static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, · line 280
Quoted 9 lines · Eric Woudstra
This adds the capability to conntrack 802.1ad, QinQ, PPPoE and PPPoE-in-Q packets that are passing a bridge, only when a conntrack zone is set.
Signed-off-by Eric Woudstra <[email protected]>--- net/bridge/netfilter/nf_conntrack_bridge.c | 88 ++++++++++++++++++---- 1 file changed, 72 insertions(+), 16 deletions(-)net/bridge/netfilter/nf_conntrack_bridge.c +1
-0+ data_len =ntohs (ph->hdr.length) -2 ;
Shouldn't there be some validation on data_len here?
net/bridge/netfilter/nf_conntrack_bridge.c static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, · line 308
Quoted 8 lines
net/bridge/netfilter/nf_conntrack_bridge.c +4
-2+if (!pskb_may_pull (skb, offset +sizeof (struct iphdr ))) + goto do_not_track; len =skb_ip_totlen (skb); -if (pskb_trim_rcsum (skb, len)) -return NF_ACCEPT ; +if (data_len < len) + len = data_len;
Hmm. So if ph->hdr.length is smaller than what ip header claims, len shrinks.
If its higher, then the mismatch is ignored and we only use the ip header length (i.e., the smaller value).
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (pskb_trim_rcsum(skb, offset + len)) + goto do_not_track;
Is the intent that garbage data_len is caught here and
Review
Quoted 2 lines
(quoted diff) +0
-1if (nf_ct_br_ip_check(skb)) - return NF_ACCEPT;
here? If so, maybe a comment could help.
net/bridge/netfilter/nf_conntrack_bridge.c static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, · line 343
Quoted 11 lines
net/bridge/netfilter/nf_conntrack_bridge.c +5
-3+ 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) {
if (ret == NF_ACCEPT && offset) { ...
Else skb could have been free'd. There should be test cases for this functionality included. If we lack test cases for the existing functionality, which might be the case, please consider submitting a reduced test case first so it can be applied regardless of the remaining functionality.
Florian Westphal
maintainerRe: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
In reply to Eric Woudstranet/netfilter/nft_chain_filter.c nft_do_chain_bridge(void *priv, · line 282
Quoted 8 lines · Eric Woudstra
net/netfilter/nft_chain_filter.c +8
-0+if (!pskb_may_pull (skb,VLAN_HLEN )) +break ; + vhdr = (struct vlan_hdr *)(skb->data); + offset =VLAN_HLEN ; + outer_proto = skb->protocol; + proto = vhdr->h_vlan_encapsulated_proto; +skb_set_network_header (skb, offset); + skb->protocol = proto;
Why is skb->protocol munged? Also applies to the previous patch, I forgot to ask.
Re: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 12 lines · Florian Westphal
net/netfilter/nft_chain_filter.c nft_do_chain_bridge(void *priv, · line 282
Quoted 8 lines · Eric Woudstra
net/netfilter/nft_chain_filter.c +8
-0+if (!pskb_may_pull (skb,VLAN_HLEN )) +break ; + vhdr = (struct vlan_hdr *)(skb->data); + offset =VLAN_HLEN ; + outer_proto = skb->protocol; + proto = vhdr->h_vlan_encapsulated_proto; +skb_set_network_header (skb, offset); + skb->protocol = proto;Why is
skb->protocolmunged? Also applies to the previous patch, I forgot to ask.
In the previous patch in nf_ct_bridge_pre(), indeed, no need to munge skb->protocol. So I'll change that.
But in nft_do_chain_bridge() it is needed in the case of matching 'ip saddr', 'ip daddr', 'ip6 saddr' or 'ip6 daddr'. I suspect all ip/ip6 matches are suffering.
So still matching is something like:
tcp dport 8080 counter name "check"
But no match when:
ip saddr 192.168.1.1 tcp dport 8080 counter name "check"
After munging skb->protocol, I do get the match.
I haven't found where yet, but It seems nft is checking skb->protocol, before it tries to match the ip(6) saddr/daddr.
And to answer a question in the other patch: this issue is found by using my script bridge_fastpath.sh. It first checks the connection, conntrack and nft-chain are functional in all testcases. So, it tests the functionality of the patches in this patch-set. I want to improve the script on a few more issues and then send a non-rfc.
Florian Westphal
maintainerRe: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Eric Woudstra <[email protected]> wrote:
[ skb->protocl munging ]
Quoted 3 lines
But in
nft_do_chain_bridge()it is needed in the case of matching 'ip saddr', 'ip daddr', 'ip6 saddr' or 'ip6 daddr'. I suspect all ip/ip6 matches are suffering.
Thats because of implicit dependency insertion on userspace side:
# ip saddr 1.2.3.4 counter ip daddr 3.4.5.6 bridge test-bridge input [ meta load protocol => reg 1 ] [ cmp eq reg 1 0x00000008 ] [ payload load 4b @ network header + 12 => reg 1 ] ...
So, if userspace would NOT do that it would 'just work'.
Pablo, whats your take on this?
We currently don't have a 'nhproto' field in nft_pktinfo and there is no space to add one.
We could say that things work as expected, and that
ip saddr 1.2.3.4
should not magically match packets in e.g. pppoe encap.
I suspect it will start to work if you force it to match in pppoe, e.g. ether type 0x8864 ip saddr ...
so nft won't silently add the skb->protocol dependency.
Its not a technical issue but about how matching is supposed to work in a bridge.
If its supposed to work automatically we need to either:
1. munge skb->protocol in kernel, even tough its wrong (we don't strip the l2 headers).
2. record the real l3 protocol somewhere and make it accessible, then fix the dependency generation in userspace to use the 'new way' (meta l3proto)?
3. change the dependency generation to something else.
But what? 'ether type ip' won't work either for 8021ad etc. 'ip version' can't be used for arp.
Quoted 2 lines
I haven't found where yet, but It seems nft is checking
skb->protocol, before it tries to match the ip(6) saddr/daddr.
Yes, userspace inserts this, see 'nft --debug=netlink add rule bridge ..'
Re: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 34 lines · Florian Westphal
Eric Woudstra <[email protected]> wrote:
[
skb->protoclmunging ]Quoted 3 lines
But in
nft_do_chain_bridge()it is needed in the case of matching 'ip saddr', 'ip daddr', 'ip6 saddr' or 'ip6 daddr'. I suspect all ip/ip6 matches are suffering.Thats because of implicit dependency insertion on userspace side:
# ip saddr 1.2.3.4 counter ip daddr 3.4.5.6 bridge test-bridge input [ meta load protocol => reg 1 ] [ cmp eq reg 1 0x00000008 ] [ payload load 4b @ network header + 12 => reg 1 ] ...So, if userspace would NOT do that it would 'just work'.
Pablo, whats your take on this?
We currently don't have a 'nhproto' field innft_pktinfoand there is no space to add one.We could say that things work as expected, and that
ip saddr 1.2.3.4should not magically match packets in e.g. pppoe encap.
I suspect it will start to work if you force it to match in pppoe, e.g. ether type0x8864ip saddr ...so nft won't silently add the
skb->protocoldependency.Its not a technical issue but about how matching is supposed to work in a bridge.
Quoted 9 lines
If its supposed to work automatically we need to either:
1. mungeskb->protocolin kernel, even tough its wrong (we don't strip the l2 headers).
2. record the real l3 protocol somewhere and make it accessible, then fix the dependency generation in userspace to use the 'new way' (meta l3proto)?
3. change the dependency generation to something else.
But what? 'ether type ip' won't work either for 8021ad etc. 'ip version' can't be used for arp.
Is using 'meta nfproto ipv4' instead an option? This looks at pkt->state->pf, which holds the correct value, not at skb->protcol.
Quoted 5 lines
Quoted 3 lines
I haven't found where yet, but It seems nft is checking
skb->protocol, before it tries to match the ip(6) saddr/daddr.Yes, userspace inserts this, see 'nft --debug=netlink add rule bridge ..'
Florian Westphal
maintainerRe: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 2 lines · Eric Woudstra
Is using 'meta nfproto ipv4' instead an option? This looks at
pkt->state->pf, which holds the correct value, not atskb->protcol.
pf is NFPROTO_BRIDGE.
Re: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
In reply to Florian WestphalQuoted 34 lines · Florian Westphal
Eric Woudstra <[email protected]> wrote:
[
skb->protoclmunging ]Quoted 3 lines
But in
nft_do_chain_bridge()it is needed in the case of matching 'ip saddr', 'ip daddr', 'ip6 saddr' or 'ip6 daddr'. I suspect all ip/ip6 matches are suffering.Thats because of implicit dependency insertion on userspace side:
# ip saddr 1.2.3.4 counter ip daddr 3.4.5.6 bridge test-bridge input [ meta load protocol => reg 1 ] [ cmp eq reg 1 0x00000008 ] [ payload load 4b @ network header + 12 => reg 1 ] ...So, if userspace would NOT do that it would 'just work'.
Pablo, whats your take on this?
We currently don't have a 'nhproto' field innft_pktinfoand there is no space to add one.We could say that things work as expected, and that
ip saddr 1.2.3.4should not magically match packets in e.g. pppoe encap.
I suspect it will start to work if you force it to match in pppoe, e.g. ether type0x8864ip saddr ...so nft won't silently add the
skb->protocoldependency.Its not a technical issue but about how matching is supposed to work in a bridge.
Quoted 10 lines
If its supposed to work automatically we need to either:
1. mungeskb->protocolin kernel, even tough its wrong (we don't strip the l2 headers).
2. record the real l3 protocol somewhere and make it accessible, then fix the dependency generation in userspace to use the 'new way' (meta l3proto)?
3. change the dependency generation to something else.
But what? 'ether type ip' won't work either for 8021ad etc. 'ip version' can't be used for arp.
Hi Florian,
Did you get any information on how to handle this issue?
Quoted 4 lines
Quoted 2 lines
I haven't found where yet, but It seems nft is checking
skb->protocol, before it tries to match the ip(6) saddr/daddr.Yes, userspace inserts this, see 'nft --debug=netlink add rule bridge ..'
Florian Westphal
maintainerRe: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 10 lines · Eric Woudstra
Quoted 10 lines
Thats because of implicit dependency insertion on userspace side:
# ip saddr 1.2.3.4 counter ip daddr 3.4.5.6 bridge test-bridge input [ meta load protocol => reg 1 ] [ cmp eq reg 1 0x00000008 ] [ payload load 4b @ network header + 12 => reg 1 ] ...So, if userspace would NOT do that it would 'just work'.
Quoted 8 lines
Quoted 8 lines
Pablo, whats your take on this?
We currently don't have a 'nhproto' field innft_pktinfoand there is no space to add one.We could say that things work as expected, and that
ip saddr 1.2.3.4should not magically match packets in e.g. pppoe encap.
FTR, I think 'ip saddr 1.2.3.4' (standalone with no other info), should NOT match inside a random l2 tunnel.
Quoted 19 lines
Quoted 8 lines
I suspect it will start to work if you force it to match in pppoe, e.g. ether type
0x8864ip saddr ...so nft won't silently add the
skb->protocoldependency.Its not a technical issue but about how matching is supposed to work in a bridge.
Quoted 10 lines
If its supposed to work automatically we need to either:
1. mungeskb->protocolin kernel, even tough its wrong (we don't strip the l2 headers).
2. record the real l3 protocol somewhere and make it accessible, then fix the dependency generation in userspace to use the 'new way' (meta l3proto)?
3. change the dependency generation to something else.
But what? 'ether type ip' won't work either for 8021ad etc. 'ip version' can't be used for arp.
Quoted 3 lines
Hi Florian,
Did you get any information on how to handle this issue?
Did you check if you can get it to match if you add the relevant l3 dependency in the rule?
I don't think we should (or can) change how the rules get evaluated by making 'ip saddr' match on other l2 tunnel protocols by default.
It is even incompatible with any exiting rulesets, consider e.g. "ip daddr 1.2.3.4 drop" on a bridge, now this address becomes unreachable but it works before your patch (if the address is found in e.g. pppoe header).
'ip/ip6' should work as expected as long as userspace provides the correct ether type and dependencies.
I.e., what this patch adds as C code should work if being provided as part of the rule.
What might make sense is to add the ppp(oe) header to src/proto.c in nftables so users that want to match the header following ppp one don't have to use raw payload match syntax.
What might also make sense is to either add a way to force a call to nft_set_pktinfo_ipv4_validate() from the ruleset, or take your patch but WITHOUT the skb->protocol munging.
However, due to the number of possible l2 header chain combinations I'm not sure we should bother with trying to add all of them.
I worry we would end up turning nft_do_chain_bridge() preamble or nft_set_pktinfo() into some kind of l2 packet dissector.
Maybe one way forward is to introduce
NFT_META_BRI_INET_VALIDATE
nft add rule ... meta inet validate ...
(just an idea, come up with better names...)
We'd have to add NFT_PKTINFO_L3PROTO flag toinclude/net/netfilter/nf_tables.h.
(or, alternatively NFT_PKTINFO_UNSPEC).
Then, set this flag in struct nft_pktinfo, from nft_set_pktinfo_ipv4|6_validate (or from nft_set_pktinfo_unspec).
NFT_META_BRI_INET_VALIDATE, would call nft_set_pktinfo_ipv4_validate or nft_set_pktinfo_ipv6_validate depending on iph->version and set NFT_BREAK verdict if the flag is still absent.
**USERSPACE IS RESPONSIBLE** to prevent arp packets from entering this expression. If they do, then header validation should fail but there would be an off-chance that the garbage is also a valid ipv4 or ipv6 packet.
Re: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 91 lines · Florian Westphal
Quoted 10 lines · Eric Woudstra
Quoted 10 lines
Thats because of implicit dependency insertion on userspace side:
# ip saddr 1.2.3.4 counter ip daddr 3.4.5.6 bridge test-bridge input [ meta load protocol => reg 1 ] [ cmp eq reg 1 0x00000008 ] [ payload load 4b @ network header + 12 => reg 1 ] ...So, if userspace would NOT do that it would 'just work'.
Quoted 8 lines
Quoted 8 lines
Pablo, whats your take on this?
We currently don't have a 'nhproto' field innft_pktinfoand there is no space to add one.We could say that things work as expected, and that
ip saddr 1.2.3.4should not magically match packets in e.g. pppoe encap.
FTR, I think 'ip saddr 1.2.3.4' (standalone with no other info), should NOT match inside a random l2 tunnel.
Quoted 19 lines
Quoted 8 lines
I suspect it will start to work if you force it to match in pppoe, e.g. ether type
0x8864ip saddr ...so nft won't silently add the
skb->protocoldependency.Its not a technical issue but about how matching is supposed to work in a bridge.
Quoted 10 lines
If its supposed to work automatically we need to either:
1. mungeskb->protocolin kernel, even tough its wrong (we don't strip the l2 headers).
2. record the real l3 protocol somewhere and make it accessible, then fix the dependency generation in userspace to use the 'new way' (meta l3proto)?
3. change the dependency generation to something else.
But what? 'ether type ip' won't work either for 8021ad etc. 'ip version' can't be used for arp.Quoted 3 lines
Hi Florian,
Did you get any information on how to handle this issue?
Did you check if you can get it to match if you add the relevant l3 dependency in the rule?
I don't think we should (or can) change how the rules get evaluated by making 'ip saddr' match on other l2 tunnel protocols by default.
It is even incompatible with any exiting rulesets, consider e.g. "ip daddr 1.2.3.4 drop" on a bridge, now this address becomes unreachable but it works before your patch (if the address is found in e.g. pppoe header).
'ip/ip6' should work as expected as long as userspace provides the correct ether type and dependencies.
I.e., what this patch adds as C code should work if being provided as part of the rule.
What might make sense is to add the ppp(oe) header to
src/proto.cin nftables so users that want to match the header following ppp one don't have to use raw payload match syntax.What might also make sense is to either add a way to force a call to
nft_set_pktinfo_ipv4_validate()from the ruleset, or take your patch but WITHOUT theskb->protocolmunging.However, due to the number of possible l2 header chain combinations I'm not sure we should bother with trying to add all of them.
I worry we would end up turning
nft_do_chain_bridge()preamble ornft_set_pktinfo()into some kind of l2 packet dissector.Maybe one way forward is to introduce
NFT_META_BRI_INET_VALIDATEnft add rule ... meta inet validate ...
(just an idea, come up with better names...)We'd have to add
NFT_PKTINFO_L3PROTOflag toinclude/net/netfilter/nf_tables.h.
(or, alternativelyNFT_PKTINFO_UNSPEC).Then, set this flag in struct
nft_pktinfo, from nft_set_pktinfo_ipv4|6_validate (or fromnft_set_pktinfo_unspec).
Quoted 8 lines
NFT_META_BRI_INET_VALIDATE, would callnft_set_pktinfo_ipv4_validateornft_set_pktinfo_ipv6_validatedepending oniph->versionand setNFT_BREAKverdict if the flag is still absent.**USERSPACE IS RESPONSIBLE** to prevent arp packets from entering this expression. If they do, then header validation should fail but there would be an off-chance that the garbage is also a valid ipv4 or ipv6 packet.
I'll try to recap what this would mean for this patch, correct me if I am wrong.
'ip saddr 1.2.3.4' should NOT match inside a random l2 tunnel. That makes the 'issue' expected behavior. If the user must need to match ip(v6) address, it must be solved from userspace, modifying the rule.
This patch (3/3) can be applied as-is, with only one change: remove munging skb->protocol.
Florian Westphal
maintainerRe: [PATCH v14 nf-next 1/3] netfilter: utils: nf_checksum(_partial) correct data!=networkheader
In reply to Eric WoudstraQuoted 22 lines · Eric Woudstra
In the conntrack hook it may not always be the case that:
skb_network_header(skb)==skb->data.This is problematic when L4 function
nf_conntrack_handle_packet()is accessing L3 data. This function uses thoff andip_hdr()to finds it's data. But it also calculates the checksum.nf_checksum()andnf_checksum_partial()both use lower skb-checksum functions that are based on usingskb->data.When
skb_network_header(skb)!=skb->data, adjust accordingly, so that the checksum is calculated correctly.Signed-off-by Eric Woudstra <[email protected]>--- net/netfilter/utils.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)net/netfilter/utils.c +0
-0
net/netfilter/utils.c __sum16 nf_checksum(struct sk_buff *skb, unsigned int hook, · line 127
Quoted 4 lines
net/netfilter/utils.c +1
-0@@ -124,16 +124,20 @@ __sum16 nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, u8 protocol, unsigned short family) { + unsigned int nhpull = skb_network_header(skb) - skb->data;
skb_network_offset() ?
And can you add a comment that tells why there is a need for pull/push pair despite the dataoff - nhpull argument?
net/netfilter/utils.c __sum16 nf_checksum(struct sk_buff *skb, unsigned int hook, · line 128
Quoted 1 line
net/netfilter/utils.c +1
-0+DEBUG_NET_WARN_ON_ONCE (!skb_pointer_if_linear (skb, nhpull,0 ));
maybe if (DEBUG_NET_WARN ...
return 0 ?
net/netfilter/utils.c __sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook, · line 153
Quoted 8 lines
net/netfilter/utils.c +3
-0@@ -143,18 +147,22 @@ __sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, unsigned int len, u8 protocol, unsigned short family) { + unsigned int nhpull = skb_network_header(skb) - skb->data;__sum16 csum =0 ; +DEBUG_NET_WARN_ON_ONCE (!skb_pointer_if_linear (skb, nhpull,0 )); +__skb_pull (skb, nhpull);
Same here, but no need to copy the comment from nf_checksum, its enough to say something like "see nf_checksum()".
Florian Westphal
maintainerRe: [PATCH v14 nf-next 2/3] netfilter: bridge: Add conntrack double vlan and pppoe
In reply to Eric WoudstraQuoted 12 lines · Eric Woudstra
net/bridge/netfilter/nf_conntrack_bridge.c +3
-2enum ip_conntrack_info ctinfo; +u32 len, data_len =U32_MAX ; +int ret, offset =0 ;struct nf_conn *ct; -u32 len; -int ret; +__be16 outer_proto; ct =nf_ct_get (skb, &ctinfo);if ((ct && !nf_ct_is_template (ct)) || ctinfo ==IP_CT_UNTRACKED )return NF_ACCEPT ;
net/bridge/netfilter/nf_conntrack_bridge.c static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, · line 263
Quoted 10 lines
net/bridge/netfilter/nf_conntrack_bridge.c +9
-0+if (ct &&nf_ct_zone_id (nf_ct_zone (ct),CTINFO2DIR (ctinfo)) != +NF_CT_DEFAULT_ZONE_ID ) { +switch (skb->protocol) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph; +
This function is getting too long, please move this to a helper function.
Florian Westphal
maintainerRe: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
In reply to Eric Woudstranet/netfilter/nft_chain_filter.c nft_do_chain_bridge(void *priv, · line 246
Quoted 12 lines · Eric Woudstra
net/netfilter/nft_chain_filter.c +7
-0+__be16 outer_proto, proto =0 ;struct nft_pktinfo pkt; +int ret, offset =0 ;nft_set_pktinfo (&pkt, skb, state);switch (eth_hdr (skb)->h_proto) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph;
Maybe add nft_set_bridge_pktinfo() and place this
entire switch/case there?
Review
Quoted 1 line
(quoted diff) +1
-0+ skb_set_network_header(skb, offset);
I assume thats because the network header still points to the ethernet header at this stage?
Re: [PATCH v14 nf-next 2/3] netfilter: bridge: Add conntrack double vlan and pppoe
In reply to Florian WestphalQuoted 14 lines · Florian Westphal
Quoted 13 lines · Eric Woudstra
net/bridge/netfilter/nf_conntrack_bridge.c +3
-2enum ip_conntrack_info ctinfo; +u32 len, data_len =U32_MAX ; +int ret, offset =0 ;struct nf_conn *ct; -u32 len; -int ret; +__be16 outer_proto; ct =nf_ct_get (skb, &ctinfo);if ((ct && !nf_ct_is_template (ct)) || ctinfo ==IP_CT_UNTRACKED )return NF_ACCEPT ;
Quoted 12 lines
net/bridge/netfilter/nf_conntrack_bridge.c static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, · line 263
Quoted 9 lines
net/bridge/netfilter/nf_conntrack_bridge.c +9
-0+if (ct &&nf_ct_zone_id (nf_ct_zone (ct),CTINFO2DIR (ctinfo)) != +NF_CT_DEFAULT_ZONE_ID ) { +switch (skb->protocol) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph; +This function is getting too long, please move this to a helper function.
Ok. At the end of nf_ct_bridge_pre() I've added:
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (offset && ret == NF_ACCEPT) + skb_reset_network_header(skb);
to reset the network header, only when it had been changed.
Do you want this helper to return the offset, so it can be used here? Or do you think it is more clean to always reset the network header like so:
if (ret == NF_ACCEPT) skb_reset_network_header(skb);
(Same question for nft_do_chain_bridge())
Re: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
In reply to Florian WestphalQuoted 7 lines · Florian Westphal
Quoted 6 lines · Eric Woudstra
net/netfilter/nft_chain_filter.c +2
-0+__be16 outer_proto, proto =0 ;struct nft_pktinfo pkt; +int ret, offset =0 ;nft_set_pktinfo (&pkt, skb, state);
Quoted 10 lines
net/netfilter/nft_chain_filter.c nft_do_chain_bridge(void *priv, · line 246
Quoted 6 lines
net/netfilter/nft_chain_filter.c +5
-0switch (eth_hdr (skb)->h_proto) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph;Maybe add
nft_set_bridge_pktinfo()and place this
entire switch/case there?
Ok. At the end of nft_do_chain_bridge() I've added (after removing skb->protocol munging):
if (offset && ret == NF_ACCEPT) skb_reset_network_header(skb);
To reset the network header, only when it had been changed.
Do you want this helper to return the offset, so it can be used here? Or do you think it is more clean to always reset the network header like so:
if (ret == NF_ACCEPT) skb_reset_network_header(skb);
(Same question for nf_ct_bridge_pre())
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ skb_set_network_header(skb, offset);I assume thats because the network header still points to the ethernet header at this stage?
That is correct.
Florian Westphal
maintainerRe: [PATCH v14 nf-next 3/3] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 9 lines · Eric Woudstra
Ok. At the end of
nft_do_chain_bridge()I've added (after removingskb->protocolmunging):if (offset && ret == NF_ACCEPT) skb_reset_network_header(skb);To reset the network header, only when it had been changed.
Do you want this helper to return the offset, so it can be used here?
Makes sense, yes.
Quoted 6 lines
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ skb_set_network_header(skb, offset);I assume thats because the network header still points to the ethernet header at this stage?
That is correct.
Can you add a comment to that effect? (I assume it points not to ethernet header but to the header that follows, e.g. pppoe).