bridge-fastpath and related improvements
Subsystems (7)
v5 cover bridge-fastpath and related improvements
This patchset makes it possible to set up a software fastpath between bridged interfaces. One patch adds the flow rule for the hardware fastpath. This creates the possibility to have a hardware offloaded fastpath between bridged interfaces. More patches are added to solve issues found with the existing code.
To set up the fastpath with offloading, add this extra flowtable:
table bridge filter {
flowtable fb {
hook ingress priority filter
devices = { lan0, lan1, lan2, lan3, lan4, wlan0, wlan1 }
flags offload
}
chain forward {
type filter hook forward priority filter; policy accept;
ct state established flow add @fb
}
}Creating a separate fastpath for bridges.
forward fastpath bypass
.----------------------------------------.
/ \
| IP - forwarding |
| / \ v
| / wan ...
| /
| |
| |
| brlan.1
| |
| +-------------------------------+
| | vlan 1 |
| | |
| | brlan (vlan-filtering) |
| +---------------+ |
| | DSA-SWITCH | |
| | | vlan 1 |
| | | to |
| | vlan 1 | untagged |
| +---------------+---------------+
. / \
------>lan0 wlan1
. ^ ^
. | |
. \_________________/
. bridge fastpath bypass
.
^
vlan 1 tagged packetsWhile testing direct transmit in the software forward-fastpath, it is useful to enslave the wan interface to another bridge, brwan. This will make sure both directions of the software forward-fastpath use direct transmit.
To have the ability to handle xmit direct with outgoing encaps in the bridge fastpass bypass, we need to be able to handle them without going through vlan/pppoe devices. So I've applied, amended and squashed wenxu's patchset. This patch also makes it possible to egress from vlan-filtering brlan to lan0 with vlan tagged packets, if the bridge master port is doing the vlan tagging, instead of the vlan-device. Without this patch, this is not possible in the bridge-fastpath and also not in the forward-fastpath, as seen in the figure above.
There are also some more fixes for filling in the forward path. These fixes also apply to for the forward-fastpath. They include handling DEV_PATH_MTK_WDMA in nft_dev_path_info(). There are now 2 patches for avoiding ingress_vlans bit set for bridged dsa user ports and foreign (dsa) ports.
Another patch introduces DEV_PATH_BR_VLAN_KEEP_HW, needed for the bridge-fastpath only.
Conntrack bridge only tracks untagged and 802.1q. To make the bridge fastpath experience more similar to the forward fastpath experience, I've added double vlan, pppoe and pppoe-in-q tagged packets to bridge conntrack and to bridge filter chain.
Note: While testing direct transmit in the software forward-fastpath, without the capability of setting the offload flag, it is sometimes useful to enslave the wan interface to another bridge, brwan. This will make sure both directions of the software forward-fastpath use direct transmit, which also happens when the offload flag is set.
I have send RFC v2 as I previously only owned a dsa device. I now have obtained a switchdev supporting SWITCHDEV_OBJ_ID_PORT_VLAN, and found there was more to do to handle the ingress_vlans bit and corresponding vlan encap.
I send v4 and above as non-RFC as the previous 2 RFC's did not get any comment.
Changes in v5:
- Conntrack double vlan and pppoe patch: Moved pskb_may_pull() up to the first switch statement, to the start of the cases. Removed the second switch statement. Replaced 0xffffffff with U32_MAX.
- Added patch removing hw_outdev, out.hw_ifindex and out.hw_ifidx members.
- Fix error path returned from nft_flow_offload_bridge_init().
- Cosmetics.
Changes in v4:
- Added !CONFIG_NET_SWITCHDEV version of
br_switchdev_port_vlan_no_foreign_add().
Changes in v3:
- Squashed the two 'port to port' patches to avoid build errors when only one of the two commits is applied.
Changes in v2:
- Introduce DEV_PATH_BR_VLAN_KEEP_HW for use in the bridge-fastpath only. It is needed for switchdevs supporting SWITCHDEV_OBJ_ID_PORT_VLAN.
- Different approach for handling BR_VLFLAG_ADDED_BY_SWITCHDEV in br_vlan_fill_forward_path_mode() for foreign devices. Introduce SWITCHDEV_F_NO_FOREIGN, BR_VLFLAG_TAGGING_BY_SWITCHDEV and br_switchdev_port_vlan_no_foreign_add(). The latter function can be used to make sure the vlan was added to a switchdev native device. When that fails, adding the vlan with br_switchdev_port_vlan_add() means it was added to a switchdev foreign device.
- Clear ingress_vlans bit and corresponding encap for dsa user ports.
- Add check for ingress_vlans bit to nft_dev_fill_bridge_path().
- Adapted cover letter description to make clear the patches apply to software fastpath, making hardware-offloaded fastpath possible.
- Fixed clang error for vlan_hdr * and struct ppp_hdr * by adding block.
- Updated !CONFIG_BRIDGE_VLAN_FILTERING version of br_vlan_fill_forward_path_pvid().
- Removed erroneous check netif_is_bridge_master(ctx->dev) from dev_fill_bridge_path().
- Cosmetic changes.
Eric Woudstra (14):
netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit
direct
netfilter: flow: remove hw_outdev, out.hw_ifindex and out.hw_ifidx
netfilter: bridge: Add conntrack double vlan and pppoe
netfilter: nft_chain_filter: Add bridge double vlan and pppoe
bridge: Add filling forward path from port to port
net: core: dev: Add dev_fill_bridge_path()
netfilter :nf_flow_table_offload: Add nf_flow_rule_bridge()
netfilter: nf_flow_table_inet: Add nf_flowtable_type flowtable_bridge
netfilter: nft_flow_offload: Add NFPROTO_BRIDGE to validate
netfilter: nft_flow_offload: Add DEV_PATH_MTK_WDMA to
nft_dev_path_info()
netfilter: nft_flow_offload: No ingress_vlan forward info for dsa user
port
bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
bridge: Introduce DEV_PATH_BR_VLAN_KEEP_HW for bridge-fastpath
netfilter: nft_flow_offload: Add bridgeflow to nft_flow_offload_eval()
include/linux/netdevice.h | 3 + include/net/netfilter/nf_flow_table.h | 5 +- include/net/switchdev.h | 1 + net/bridge/br_device.c | 23 ++- net/bridge/br_private.h | 12 ++ net/bridge/br_switchdev.c | 15 ++ net/bridge/br_vlan.c | 29 +++- net/bridge/netfilter/nf_conntrack_bridge.c | 81 ++++++++-- net/core/dev.c | 66 ++++++-- net/netfilter/nf_flow_table_core.c | 1 - net/netfilter/nf_flow_table_inet.c | 13 ++ net/netfilter/nf_flow_table_ip.c | 96 +++++++++++- net/netfilter/nf_flow_table_offload.c | 15 +- net/netfilter/nft_chain_filter.c | 20 ++- net/netfilter/nft_flow_offload.c | 168 +++++++++++++++++++-- net/switchdev/switchdev.c | 2 +- 16 files changed, 490 insertions(+), 60 deletions(-)
Signature · 1 line
2.47.1
PATCH v5 1/14 netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct
Loosely based on wenxu's patches:
"nf_flow_table_offload: offload the vlan/PPPoE encap in the flowtable".
Fixed double vlan and pppoe packets, almost entirely rewriting the patch.
After this patch, it is possible to transmit packets in the fastpath with outgoing encaps, without using vlan- and/or pppoe-devices.
This makes it possible to use more different kinds of network setups. For example, when bridge tagging is used to egress vlan tagged packets using the forward fastpath. Another example is passing 802.1q tagged packets through a bridge using the bridge fastpath.
This also makes the software fastpath process more similar to the hardware offloaded fastpath process, where encaps are also pushed.
After applying this patch, always info->outdev = info->hw_outdev, so the netfilter code can be further cleaned up by removing:
* hw_outdev from struct nft_forward_info
* out.hw_ifindex from struct nf_flow_route
* out.hw_ifidx from struct flow_offload_tuple
--- net/netfilter/nf_flow_table_ip.c | 96 +++++++++++++++++++++++++++++++- net/netfilter/nft_flow_offload.c | 6 +- 2 files changed, 96 insertions(+), 6 deletions(-)
net/netfilter/nf_flow_table_ip.c +94 -2
@@ -306,6 +306,92 @@ static bool nf_flow_skb_encap_protocol(struct sk_buff *skb, __be16 proto,return false; } +static int nf_flow_vlan_inner_push (struct sk_buff *skb,__be16 proto,u16 id) +{ +struct vlan_hdr *vhdr; + +if (skb_cow_head (skb,VLAN_HLEN )) +return -1 ; + +__skb_push (skb,VLAN_HLEN ); +skb_reset_network_header (skb); + + vhdr = (struct vlan_hdr *)(skb->data); + vhdr->h_vlan_TCI =htons (id); + vhdr->h_vlan_encapsulated_proto = skb->protocol; + skb->protocol = proto; + +return 0 ; +} + +static int nf_flow_ppoe_push (struct sk_buff *skb,u16 id) +{ +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph; +int data_len = skb->len +2 ; +__be16 proto; + +if (skb_cow_head (skb,PPPOE_SES_HLEN )) +return -1 ; + +if (skb->protocol ==htons (ETH_P_IP )) + proto =htons (PPP_IP ); +else if (skb->protocol ==htons (ETH_P_IPV6 )) + proto =htons (PPP_IPV6 ); +else +return -1 ; + +__skb_push (skb,PPPOE_SES_HLEN ); +skb_reset_network_header (skb); + + ph = (struct ppp_hdr *)(skb->data); + ph->hdr.ver =1 ; + ph->hdr.type =1 ; + ph->hdr.code =0 ; + ph->hdr.sid =htons (id); + ph->hdr.length =htons (data_len); + ph->proto = proto; + skb->protocol =htons (ETH_P_PPP_SES ); + +return 0 ; +} + +static int nf_flow_encap_push (struct sk_buff *skb, +struct flow_offload_tuple_rhash *tuplehash, +unsigned short *type) +{ +int i =0 , ret =0 ; + +if (!tuplehash->tuple.encap_num) +return 0 ; + +if (tuplehash->tuple.encap[i].proto ==htons (ETH_P_8021Q ) || + tuplehash->tuple.encap[i].proto ==htons (ETH_P_8021AD )) { +__vlan_hwaccel_put_tag (skb, tuplehash->tuple.encap[i].proto, + tuplehash->tuple.encap[i].id); + i++; +if (i >= tuplehash->tuple.encap_num) +return 0 ; + } + +switch (tuplehash->tuple.encap[i].proto) { +case htons (ETH_P_8021Q ): + *type =ETH_P_8021Q ; + ret =nf_flow_vlan_inner_push (skb, + tuplehash->tuple.encap[i].proto, + tuplehash->tuple.encap[i].id); +break ; +case htons (ETH_P_PPP_SES ): + *type =ETH_P_PPP_SES ; + ret =nf_flow_ppoe_push (skb, + tuplehash->tuple.encap[i].id); +break ; + } +return ret; +} +static void nf_flow_encap_pop (struct sk_buff *skb,struct flow_offload_tuple_rhash *tuplehash) {
@@ -335,6 +421,7 @@ static void nf_flow_encap_pop(struct sk_buff *skb,static unsigned int nf_flow_queue_xmit (struct net *net,struct sk_buff *skb,const struct flow_offload_tuple_rhash *tuplehash, +struct flow_offload_tuple_rhash *other_tuplehash,unsigned short type) {struct net_device *outdev;
@@ -343,6 +430,9 @@ static unsigned int nf_flow_queue_xmit(struct net *net, struct sk_buff *skb,if (!outdev)return NF_DROP ; +if (nf_flow_encap_push (skb, other_tuplehash, &type) <0 ) +return NF_DROP ; + skb->dev = outdev;dev_hard_header (skb, skb->dev, type, tuplehash->tuple.out.h_dest, tuplehash->tuple.out.h_source, skb->len);
@@ -464,7 +554,8 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, ret =NF_STOLEN ;break ;case FLOW_OFFLOAD_XMIT_DIRECT : - ret =nf_flow_queue_xmit (state->net, skb, tuplehash,ETH_P_IP ); + ret =nf_flow_queue_xmit (state->net, skb, tuplehash, + &flow->tuplehash[!dir],ETH_P_IP );if (ret ==NF_DROP )flow_offload_teardown (flow);break ;
@@ -761,7 +852,8 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, ret =NF_STOLEN ;break ;case FLOW_OFFLOAD_XMIT_DIRECT : - ret =nf_flow_queue_xmit (state->net, skb, tuplehash,ETH_P_IPV6 ); + ret =nf_flow_queue_xmit (state->net, skb, tuplehash, + &flow->tuplehash[!dir],ETH_P_IPV6 );if (ret ==NF_DROP )flow_offload_teardown (flow);break ;
net/netfilter/nft_flow_offload.c +2 -4
@@ -124,13 +124,12 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, info->indev =NULL ;break ; } -if (!info->outdev) - info->outdev = path->dev; info->encap[info->num_encaps].id = path->encap.id; info->encap[info->num_encaps].proto = path->encap.proto; info->num_encaps++;if (path->type ==DEV_PATH_PPPOE )memcpy (info->h_dest, path->encap.h_dest,ETH_ALEN ); + info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ;break ;case DEV_PATH_BRIDGE :if (is_zero_ether_addr (info->h_source))
@@ -158,8 +157,7 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,break ; } } -if (!info->outdev) - info->outdev = info->indev; + info->outdev = info->indev; info->hw_outdev = info->indev;
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 01/14] netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct
Quoted 23 lines · Eric Woudstra
Loosely based on wenxu's patches:
"
nf_flow_table_offload: offload the vlan/PPPoE encap in the flowtable".Fixed double vlan and pppoe packets, almost entirely rewriting the patch.
After this patch, it is possible to transmit packets in the fastpath with outgoing encaps, without using vlan- and/or pppoe-devices.
This makes it possible to use more different kinds of network setups. For example, when bridge tagging is used to egress vlan tagged packets using the forward fastpath. Another example is passing 802.1q tagged packets through a bridge using the bridge fastpath.
This also makes the software fastpath process more similar to the hardware offloaded fastpath process, where encaps are also pushed.
After applying this patch, always
info->outdev=info->hw_outdev, so the netfilter code can be further cleaned up by removing:
*hw_outdevfrom structnft_forward_info
* out.hw_ifindex from structnf_flow_route
* out.hw_ifidx from structflow_offload_tuple
Quoted 6 lines
Signed-off-by Eric Woudstra <[email protected]>--- net/netfilter/nf_flow_table_ip.c | 96 +++++++++++++++++++++++++++++++- net/netfilter/nft_flow_offload.c | 6 +- 2 files changed, 96 insertions(+), 6 deletions(-)
Too bad the existing vlan push helpers can't be used. :)
PATCH v5 2/14 netfilter: flow: remove hw_outdev, out.hw_ifindex and out.hw_ifidx
In reply to Eric WoudstraNow always info->outdev == info->hw_outdev, so the netfilter code can be further cleaned up by removing:
* hw_outdev from struct nft_forward_info
* out.hw_ifindex from struct nf_flow_route
* out.hw_ifidx from struct flow_offload_tuple
--- include/net/netfilter/nf_flow_table.h | 2 -- net/netfilter/nf_flow_table_core.c | 1 - net/netfilter/nf_flow_table_offload.c | 2 +- net/netfilter/nft_flow_offload.c | 4 ---- 4 files changed, 1 insertion(+), 8 deletions(-)
include/net/netfilter/nf_flow_table.h +0 -2
@@ -145,7 +145,6 @@ struct flow_offload_tuple { };struct {u32 ifidx; -u32 hw_ifidx;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; } out;
@@ -211,7 +210,6 @@ struct nf_flow_route { } in;struct {u32 ifindex; -u32 hw_ifindex;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; } out;
net/netfilter/nf_flow_table_core.c +0 -1
@@ -127,7 +127,6 @@ static int flow_offload_fill_route(struct flow_offload *flow,memcpy (flow_tuple->out.h_source, route->tuple[dir].out.h_source,ETH_ALEN ); flow_tuple->out.ifidx = route->tuple[dir].out.ifindex; - flow_tuple->out.hw_ifidx = route->tuple[dir].out.hw_ifindex;dst_release (dst);break ;case FLOW_OFFLOAD_XMIT_XFRM :
net/netfilter/nf_flow_table_offload.c +1 -1
@@ -555,7 +555,7 @@ static void flow_offload_redirect(struct net *net,switch (this_tuple->xmit_type) {case FLOW_OFFLOAD_XMIT_DIRECT : this_tuple = &flow->tuplehash[dir].tuple; - ifindex = this_tuple->out.hw_ifidx; + ifindex = this_tuple->out.ifidx;break ;case FLOW_OFFLOAD_XMIT_NEIGH : other_tuple = &flow->tuplehash[!dir].tuple;
net/netfilter/nft_flow_offload.c +0 -4
@@ -80,7 +80,6 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,struct nft_forward_info {const struct net_device *indev;const struct net_device *outdev; -const struct net_device *hw_outdev;struct id {__u16 id;__be16 proto;
@@ -159,8 +158,6 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, } info->outdev = info->indev; - info->hw_outdev = info->indev; -if (nf_flowtable_hw_offload (flowtable) &&nft_is_valid_ether_device (info->indev)) info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ;
@@ -212,7 +209,6 @@ static void nft_dev_forward_path(struct nf_flow_route *route,memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN );memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); route->tuple[dir].out.ifindex = info.outdev->ifindex; - route->tuple[dir].out.hw_ifindex = info.hw_outdev->ifindex; route->tuple[dir].xmit_type = info.xmit_type; } }
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 02/14] netfilter: flow: remove hw_outdev, out.hw_ifindex and out.hw_ifidx
Quoted 6 lines · Eric Woudstra
Now always
info->outdev==info->hw_outdev, so the netfilter code can be further cleaned up by removing:
*hw_outdevfrom structnft_forward_info
* out.hw_ifindex from structnf_flow_route
* out.hw_ifidx from structflow_offload_tuple
Quoted 8 lines
Signed-off-by Eric Woudstra <[email protected]>--- include/net/netfilter/nf_flow_table.h | 2 -- net/netfilter/nf_flow_table_core.c | 1 - net/netfilter/nf_flow_table_offload.c | 2 +- net/netfilter/nft_flow_offload.c | 4 ---- 4 files changed, 1 insertion(+), 8 deletions(-)
PATCH v5 3/14 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.
--- net/bridge/netfilter/nf_conntrack_bridge.c | 81 ++++++++++++++++++---- 1 file changed, 69 insertions(+), 12 deletions(-)
net/bridge/netfilter/nf_conntrack_bridge.c +69 -12
@@ -242,53 +242,110 @@ 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; +int ret, offset =0 ;struct nf_conn *ct; -u32 len; -int ret; +__be16 outer_proto; +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); + + offset =PPPOE_SES_HLEN ; +if (!pskb_may_pull (skb, offset)) +return NF_ACCEPT ; + outer_proto = skb->protocol; +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_pull_rcsum (skb, offset); +skb_reset_network_header (skb); +break ; + } +case htons (ETH_P_8021Q ): { +struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data); + + offset =VLAN_HLEN ; +if (!pskb_may_pull (skb, offset)) +return NF_ACCEPT ; + outer_proto = skb->protocol; + skb->protocol = vhdr->h_vlan_encapsulated_proto; + data_len =U32_MAX ; +skb_pull_rcsum (skb, offset); +skb_reset_network_header (skb); +break ; + } +default : + data_len =U32_MAX ; +break ; + } + + 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,
Signature · 1 line
2.47.1
Nikolay Aleksandrov
maintainerRe: [PATCH v5 net-next 03/14] netfilter: bridge: Add conntrack double vlan and pppoe
Quoted 28 lines · Eric Woudstra
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 <[email protected]>--- net/bridge/netfilter/nf_conntrack_bridge.c | 81 ++++++++++++++++++---- 1 file changed, 69 insertions(+), 12 deletions(-)net/bridge/netfilter/nf_conntrack_bridge.c +3
-2@@ -242,53 +242,110 @@ 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; +int ret, offset =0 ;struct nf_conn *ct; -u32 len; -int ret; +__be16 outer_proto; +u32 len, data_len; 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 264
Quoted 10 lines
net/bridge/netfilter/nf_conntrack_bridge.c +10
-0+switch (skb->protocol) { +case htons (ETH_P_PPP_SES ): { +struct ppp_hdr { +struct pppoe_hdr hdr; +__be16 proto; + } *ph = (struct ppp_hdr *)(skb->data); + + offset =PPPOE_SES_HLEN ; +if (!pskb_may_pull (skb, offset)) +return NF_ACCEPT ;
You should reload ph because pskb_may_pull() may change the skb and it can become invalid
Quoted 13 lines
net/bridge/netfilter/nf_conntrack_bridge.c +13
-0+ outer_proto = skb->protocol; +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 ;
net/bridge/netfilter/nf_conntrack_bridge.c static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, · line 287
Quoted 10 lines
net/bridge/netfilter/nf_conntrack_bridge.c +10
-0+skb_pull_rcsum (skb, offset); +skb_reset_network_header (skb); +break ; + } +case htons (ETH_P_8021Q ): { +struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data); + + offset =VLAN_HLEN ; +if (!pskb_may_pull (skb, offset)) +return NF_ACCEPT ;
ditto about vhdr, should be reloaded after the may pull
Quoted 74 lines
net/bridge/netfilter/nf_conntrack_bridge.c +33
-10+ outer_proto = skb->protocol; + skb->protocol = vhdr->h_vlan_encapsulated_proto; + data_len =U32_MAX ; +skb_pull_rcsum (skb, offset); +skb_reset_network_header (skb); +break ; + } +default : + data_len =U32_MAX ; +break ; + } + + 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,
PATCH v5 4/14 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 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
net/netfilter/nft_chain_filter.c +19 -1
@@ -232,11 +232,27 @@ nft_do_chain_bridge(void *priv,struct sk_buff *skb, const struct nf_hook_state *state) { + struct ethhdr *ethh = eth_hdr(skb);struct nft_pktinfo pkt; +int thoff;nft_set_pktinfo (&pkt, skb, state); -switch (eth_hdr (skb)->h_proto) { +switch (ethh->h_proto) { +case htons (ETH_P_PPP_SES ): + thoff =PPPOE_SES_HLEN ; + ethh += thoff; +break ; +case htons (ETH_P_8021Q ): + thoff =VLAN_HLEN ; + ethh += thoff; +break ; +default : + thoff =0 ; +break ; + } + +switch (ethh->h_proto) {case htons (ETH_P_IP ):nft_set_pktinfo_ipv4_validate (&pkt);break ;
@@ -248,6 +264,8 @@ nft_do_chain_bridge(void *priv,break ; } + pkt.thoff += thoff; +return nft_do_chain (&pkt, priv); }
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 04/14] netfilter: nft_chain_filter: Add bridge double vlan and pppoe
Quoted 7 lines · Eric Woudstra
This adds the capability to evaluate 802.1ad, QinQ, PPPoE and PPPoE-in-Q packets in the bridge filter chain.
Signed-off-by Eric Woudstra <[email protected]>--- net/netfilter/nft_chain_filter.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
PATCH v5 5/14 bridge: Add filling forward path from port to port
In reply to Eric WoudstraIf a port is passed as argument instead of the master, then:
At br_fill_forward_path(): find the master and use it to fill the forward path.
At br_vlan_fill_forward_path_pvid(): lookup vlan group from port instead.
--- net/bridge/br_device.c | 19 ++++++++++++++----- net/bridge/br_private.h | 2 ++ net/bridge/br_vlan.c | 6 +++++- 3 files changed, 21 insertions(+), 6 deletions(-)
net/bridge/br_device.c +14 -5
@@ -383,16 +383,25 @@ static int br_del_slave(struct net_device *dev, struct net_device *slave_dev)static int br_fill_forward_path (struct net_device_path_ctx *ctx,struct net_device_path *path) { +struct net_bridge_port *src, *dst;struct net_bridge_fdb_entry *f; -struct net_bridge_port *dst;struct net_bridge *br; -if (netif_is_bridge_port (ctx->dev)) -return -1 ; +if (netif_is_bridge_port (ctx->dev)) { +struct net_device *br_dev; + + br_dev =netdev_master_upper_dev_get_rcu ((struct net_device *)ctx->dev); +if (!br_dev) +return -1 ; - br =netdev_priv (ctx->dev); + src =br_port_get_rcu (ctx->dev); + br =netdev_priv (br_dev); + }else { + src =NULL ; + br =netdev_priv (ctx->dev); + } -br_vlan_fill_forward_path_pvid (br, ctx, path); +br_vlan_fill_forward_path_pvid (br, src, ctx, path); f =br_fdb_find_rcu (br, ctx->daddr, path->bridge.vlan_id);if (!f)
net/bridge/br_private.h +2 -0
@@ -1584,6 +1584,7 @@ bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, const struct net_bridge_vlan *range_end);void br_vlan_fill_forward_path_pvid (struct net_bridge *br, +struct net_bridge_port *p,struct net_device_path_ctx *ctx,struct net_device_path *path); int br_vlan_fill_forward_path_mode(struct net_bridge *br,
@@ -1753,6 +1754,7 @@ static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, }static inline void br_vlan_fill_forward_path_pvid (struct net_bridge *br, +struct net_bridge_port *p,struct net_device_path_ctx *ctx,struct net_device_path *path) {
net/bridge/br_vlan.c +5 -1
@@ -1441,6 +1441,7 @@ int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)EXPORT_SYMBOL_GPL (br_vlan_get_pvid_rcu);void br_vlan_fill_forward_path_pvid (struct net_bridge *br, +struct net_bridge_port *p,struct net_device_path_ctx *ctx,struct net_device_path *path) {
@@ -1453,7 +1454,10 @@ void br_vlan_fill_forward_path_pvid(struct net_bridge *br,if (!br_opt_get (br,BROPT_VLAN_ENABLED ))return ; - vg =br_vlan_group (br); +if (p) + vg =nbp_vlan_group (p); +else + vg =br_vlan_group (br);if (idx >=0 && ctx->vlan[idx].proto == br->vlan_proto) {
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 05/14] bridge: Add filling forward path from port to port
Quoted 8 lines · Eric Woudstra
If a port is passed as argument instead of the master, then:
At
br_fill_forward_path(): find the master and use it to fill the forward path.At
br_vlan_fill_forward_path_pvid(): lookup vlan group from port instead.
Quoted 7 lines
Signed-off-by Eric Woudstra <[email protected]>--- net/bridge/br_device.c | 19 ++++++++++++++----- net/bridge/br_private.h | 2 ++ net/bridge/br_vlan.c | 6 +++++- 3 files changed, 21 insertions(+), 6 deletions(-)
PATCH v5 6/14 net: core: dev: Add dev_fill_bridge_path()
In reply to Eric WoudstraNew function dev_fill_bridge_path(), similar to dev_fill_forward_path(). It handles starting from a bridge port instead of the bridge master. The structures ctx and nft_forward_info need to be already filled in with the (vlan) encaps.
--- include/linux/netdevice.h | 2 ++ net/core/dev.c | 66 +++++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 13 deletions(-)
include/linux/netdevice.h +2 -0
@@ -3280,6 +3280,8 @@ void dev_remove_offload(struct packet_offload *po);int dev_get_iflink (const struct net_device *dev);int dev_fill_metadata_dst (struct net_device *dev,struct sk_buff *skb); +int dev_fill_bridge_path (struct net_device_path_ctx *ctx, +struct net_device_path_stack *stack);int dev_fill_forward_path (const struct net_device *dev,const u8 *daddr,struct net_device_path_stack *stack); struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags,
net/core/dev.c +53 -13
97 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 06/14] net: core: dev: Add dev_fill_bridge_path()
Quoted 11 lines · Eric Woudstra
New function
dev_fill_bridge_path(), similar todev_fill_forward_path(). It handles starting from a bridge port instead of the bridge master. The structures ctx andnft_forward_infoneed to be already filled in with the (vlan) encaps.Signed-off-by Eric Woudstra <[email protected]>--- include/linux/netdevice.h | 2 ++ net/core/dev.c | 66 +++++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 13 deletions(-)
PATCH v5 7/14 netfilter :nf_flow_table_offload: Add nf_flow_rule_bridge()
In reply to Eric WoudstraAdd nf_flow_rule_bridge().
It only calls the common rule and adds the redirect.
--- include/net/netfilter/nf_flow_table.h | 3 +++ net/netfilter/nf_flow_table_offload.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)
include/net/netfilter/nf_flow_table.h +3 -0
@@ -340,6 +340,9 @@ void nf_flow_table_offload_flush_cleanup(struct nf_flowtable *flowtable);int nf_flow_table_offload_setup (struct nf_flowtable *flowtable,struct net_device *dev,enum flow_block_command cmd); +int nf_flow_rule_bridge (struct net *net,struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule);int nf_flow_rule_route_ipv4 (struct net *net,struct flow_offload *flow,enum flow_offload_tuple_dir dir,struct nf_flow_rule *flow_rule);
net/netfilter/nf_flow_table_offload.c +13 -0
@@ -679,6 +679,19 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow,return 0 ; } +int nf_flow_rule_bridge (struct net *net,struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) +{ +if (nf_flow_rule_route_common (net, flow, dir, flow_rule) <0 ) +return -1 ; + +flow_offload_redirect (net, flow, dir, flow_rule); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nf_flow_rule_bridge); +int nf_flow_rule_route_ipv4 (struct net *net,struct flow_offload *flow,enum flow_offload_tuple_dir dir,struct nf_flow_rule *flow_rule)
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 07/14] netfilter :nf_flow_table_offload: Add nf_flow_rule_bridge()
Quoted 10 lines · Eric Woudstra
Add
nf_flow_rule_bridge().It only calls the common rule and adds the redirect.
Signed-off-by Eric Woudstra <[email protected]>--- include/net/netfilter/nf_flow_table.h | 3 +++ net/netfilter/nf_flow_table_offload.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)
PATCH v5 8/14 netfilter: nf_flow_table_inet: Add nf_flowtable_type flowtable_bridge
In reply to Eric WoudstraThis will allow a flowtable to be added to the nft bridge family.
--- net/netfilter/nf_flow_table_inet.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
net/netfilter/nf_flow_table_inet.c +13 -0
@@ -65,6 +65,16 @@ static int nf_flow_rule_route_inet(struct net *net,return err; } +static struct nf_flowtable_type flowtable_bridge = { + .family =NFPROTO_BRIDGE , + .init = nf_flow_table_init, + .setup = nf_flow_table_offload_setup, + .action = nf_flow_rule_bridge, + .free = nf_flow_table_free, + .hook = nf_flow_offload_inet_hook, + .owner =THIS_MODULE , +}; +static struct nf_flowtable_type flowtable_inet = { .family =NFPROTO_INET , .init = nf_flow_table_init,
@@ -97,6 +107,7 @@ static struct nf_flowtable_type flowtable_ipv6 = {static int __init nf_flow_inet_module_init (void ) { +nft_register_flowtable_type (&flowtable_bridge);nft_register_flowtable_type (&flowtable_ipv4);nft_register_flowtable_type (&flowtable_ipv6);nft_register_flowtable_type (&flowtable_inet);
@@ -109,6 +120,7 @@ static void __exit nf_flow_inet_module_exit(void)nft_unregister_flowtable_type (&flowtable_inet);nft_unregister_flowtable_type (&flowtable_ipv6);nft_unregister_flowtable_type (&flowtable_ipv4); +nft_unregister_flowtable_type (&flowtable_bridge); }module_init (nf_flow_inet_module_init);
@@ -118,5 +130,6 @@ MODULE_LICENSE("GPL");MODULE_AUTHOR ("Pablo Neira Ayuso <[email protected]>" );MODULE_ALIAS_NF_FLOWTABLE (AF_INET );MODULE_ALIAS_NF_FLOWTABLE (AF_INET6 ); +MODULE_ALIAS_NF_FLOWTABLE (AF_BRIDGE );MODULE_ALIAS_NF_FLOWTABLE (1 );/* NFPROTO_INET */ MODULE_DESCRIPTION ("Netfilter flow table mixed IPv4/IPv6 module" );
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 08/14] netfilter: nf_flow_table_inet: Add nf_flowtable_type flowtable_bridge
Quoted 7 lines · Eric Woudstra
This will allow a flowtable to be added to the nft bridge family.
Signed-off-by Eric Woudstra <[email protected]>--- net/netfilter/nf_flow_table_inet.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
PATCH v5 9/14 netfilter: nft_flow_offload: Add NFPROTO_BRIDGE to validate
In reply to Eric WoudstraNeed to add NFPROTO_BRIDGE to nft_flow_offload_validate() to support the bridge-fastpath.
--- net/netfilter/nft_flow_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_flow_offload.c +2 -1
@@ -421,7 +421,8 @@ static int nft_flow_offload_validate(const struct nft_ctx *ctx,if (ctx->family !=NFPROTO_IPV4 && ctx->family !=NFPROTO_IPV6 && - ctx->family !=NFPROTO_INET ) + ctx->family !=NFPROTO_INET && + ctx->family !=NFPROTO_BRIDGE )return -EOPNOTSUPP ;return nft_chain_validate_hooks (ctx->chain, hook_mask);
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 09/14] netfilter: nft_flow_offload: Add NFPROTO_BRIDGE to validate
Quoted 7 lines · Eric Woudstra
Need to add
NFPROTO_BRIDGEtonft_flow_offload_validate()to support the bridge-fastpath.Signed-off-by Eric Woudstra <[email protected]>--- net/netfilter/nft_flow_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v5 10/14 netfilter: nft_flow_offload: Add DEV_PATH_MTK_WDMA to nft_dev_path_info()
In reply to Eric WoudstraIn case of using mediatek wireless, in nft_dev_fill_forward_path(), the forward path is filled, ending with mediatek wlan1.
Because DEV_PATH_MTK_WDMA is unknown inside nft_dev_path_info() it returns with info.indev = NULL. Then nft_dev_forward_path() returns without setting the direct transmit parameters.
This results in a neighbor transmit, and direct transmit not possible. But we want to use it for flow between bridged interfaces.
So this patch adds DEV_PATH_MTK_WDMA to nft_dev_path_info() and makes direct transmission possible.
--- net/netfilter/nft_flow_offload.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nft_flow_offload.c +5 -0
@@ -105,6 +105,7 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,switch (path->type) {case DEV_PATH_ETHERNET :case DEV_PATH_DSA : +case DEV_PATH_MTK_WDMA :case DEV_PATH_VLAN :case DEV_PATH_PPPOE : info->indev = path->dev;
@@ -117,6 +118,10 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, i = stack->num_paths;break ; } +if (path->type ==DEV_PATH_MTK_WDMA ) { + i = stack->num_paths; +break ; + }/* DEV_PATH_VLAN and DEV_PATH_PPPOE */ if (info->num_encaps >=NF_FLOW_TABLE_ENCAP_MAX ) {
Signature · 1 line
2.47.1
PATCH v5 11/14 netfilter: nft_flow_offload: No ingress_vlan forward info for dsa user port
In reply to Eric WoudstraThe bitfield info->ingress_vlans and correcponding vlan encap are used for a switchdev user port. However, they should not be set for a dsa user port.
--- net/netfilter/nft_flow_offload.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nft_flow_offload.c +5 -0
@@ -116,6 +116,11 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,break ;if (path->type ==DEV_PATH_DSA ) { i = stack->num_paths; +if (!info->num_encaps || + !(info->ingress_vlans &BIT (info->num_encaps -1 ))) +break ; + info->num_encaps--; + info->ingress_vlans &= ~BIT (info->num_encaps -1 );break ; }if (path->type ==DEV_PATH_MTK_WDMA ) {
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 11/14] netfilter: nft_flow_offload: No ingress_vlan forward info for dsa user port
Quoted 8 lines · Eric Woudstra
The bitfield
info->ingress_vlansand correcponding vlan encap are used for a switchdev user port. However, they should not be set for a dsa user port.Signed-off-by Eric Woudstra <[email protected]>--- net/netfilter/nft_flow_offload.c | 5 +++++ 1 file changed, 5 insertions(+)
PATCH v5 12/14 bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
In reply to Eric WoudstraIn network setup as below:
fastpath bypass
.----------------------------------------.
/ \
| IP - forwarding |
| / \ v
| / wan ...
| /
| |
| |
| brlan.1
| |
| +-------------------------------+
| | vlan 1 |
| | |
| | brlan (vlan-filtering) |
| | +---------------+
| | | DSA-SWITCH |
| | vlan 1 | |
| | to | |
| | untagged 1 vlan 1 |
| +---------------+---------------+
. / \
----->wlan1 lan0
. .
. ^
^ vlan 1 tagged packetsuntagged packets
br_vlan_fill_forward_path_mode() sets DEV_PATH_BR_VLAN_UNTAG_HW when filling in from brlan.1 towards wlan1. But it should be set to DEV_PATH_BR_VLAN_UNTAG in this case. Using BR_VLFLAG_ADDED_BY_SWITCHDEV is not correct. The dsa switchdev adds it as a foreign port.
The same problem for all foreignly added dsa vlans on the bridge.
First add the vlan, trying only native devices.
If this fails, we know this may be a vlan from a foreign device.
Use BR_VLFLAG_TAGGING_BY_SWITCHDEV to make sure DEV_PATH_BR_VLAN_UNTAG_HW is set only when there if no foreign device involved.
--- include/net/switchdev.h | 1 + net/bridge/br_private.h | 10 ++++++++++ net/bridge/br_switchdev.c | 15 +++++++++++++++ net/bridge/br_vlan.c | 7 ++++++- net/switchdev/switchdev.c | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-)
include/net/switchdev.h +1 -0
@@ -15,6 +15,7 @@#define SWITCHDEV_F_NO_RECURSE BIT(0)#define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1)#define SWITCHDEV_F_DEFER BIT(2) +#define SWITCHDEV_F_NO_FOREIGN BIT(3)enum switchdev_attr_id {SWITCHDEV_ATTR_ID_UNDEFINED ,
net/bridge/br_private.h +10 -0
@@ -180,6 +180,7 @@ enum {BR_VLFLAG_MCAST_ENABLED =BIT (2 ),BR_VLFLAG_GLOBAL_MCAST_ENABLED =BIT (3 ),BR_VLFLAG_NEIGH_SUPPRESS_ENABLED =BIT (4 ), + BR_VLFLAG_TAGGING_BY_SWITCHDEV = BIT(5), };/**
@@ -2184,6 +2185,8 @@ void br_switchdev_mdb_notify(struct net_device *dev, int type);int br_switchdev_port_vlan_add (struct net_device *dev,u16 vid,u16 flags,bool changed,struct netlink_ext_ack *extack); +int br_switchdev_port_vlan_no_foreign_add (struct net_device *dev,u16 vid,u16 flags, +bool changed,struct netlink_ext_ack *extack);int br_switchdev_port_vlan_del (struct net_device *dev,u16 vid);void br_switchdev_init (struct net_bridge *br);
@@ -2267,6 +2270,13 @@ static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid,return -EOPNOTSUPP ; } +static inline int br_switchdev_port_vlan_no_foreign_add (struct net_device *dev,u16 vid, +u16 flags,bool changed, +struct netlink_ext_ack *extack) +{ +return -EOPNOTSUPP ; +} +static inline int br_switchdev_port_vlan_del (struct net_device *dev,u16 vid) {return -EOPNOTSUPP ;
net/bridge/br_switchdev.c +15 -0
@@ -187,6 +187,21 @@ int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,return switchdev_port_obj_add (dev, &v.obj, extack); } +int br_switchdev_port_vlan_no_foreign_add (struct net_device *dev,u16 vid,u16 flags, +bool changed,struct netlink_ext_ack *extack) +{ +struct switchdev_obj_port_vlan v = { + .obj.orig_dev = dev, + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .obj.flags =SWITCHDEV_F_NO_FOREIGN , + .flags = flags, + .vid = vid, + .changed = changed, + }; + +return switchdev_port_obj_add (dev, &v.obj, extack); +} +int br_switchdev_port_vlan_del (struct net_device *dev,u16 vid) {struct switchdev_obj_port_vlan v = {
net/bridge/br_vlan.c +6 -1
@@ -109,6 +109,11 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,/* Try switchdev op first. In case it is not supported, fallback to * 8021q add. */ + err =br_switchdev_port_vlan_no_foreign_add (dev, v->vid, flags, false, extack); +if (err != -EOPNOTSUPP ) { + v->priv_flags |=BR_VLFLAG_ADDED_BY_SWITCHDEV |BR_VLFLAG_TAGGING_BY_SWITCHDEV ; +return err; + } err =br_switchdev_port_vlan_add (dev, v->vid, flags, false, extack);if (err == -EOPNOTSUPP )return vlan_vid_add (dev, br->vlan_proto, v->vid);
@@ -1491,7 +1496,7 @@ int br_vlan_fill_forward_path_mode(struct net_bridge *br,if (path->bridge.vlan_mode ==DEV_PATH_BR_VLAN_TAG ) path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP ; -else if (v->priv_flags &BR_VLFLAG_ADDED_BY_SWITCHDEV ) +else if (v->priv_flags &BR_VLFLAG_TAGGING_BY_SWITCHDEV ) path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG_HW ;else path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG ;
net/switchdev/switchdev.c +1 -1
@@ -749,7 +749,7 @@ static int __switchdev_handle_port_obj_add(struct net_device *dev,/* Event is neither on a bridge nor a LAG. Check whether it is on an * interface that is in a bridge with us. */ -if (!foreign_dev_check_cb) +if (!foreign_dev_check_cb || port_obj_info->obj->flags &SWITCHDEV_F_NO_FOREIGN )return err; br =netdev_master_upper_dev_get (dev);
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 12/14] bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
Quoted 43 lines · Eric Woudstra
In network setup as below:
fastpath bypass
.----------------------------------------.
/ \| IP - forwarding | | / \ v | / wan ... | / | | | | | brlan.1 | | | +-------------------------------+ | | vlan 1 | | | | | | brlan (vlan-filtering) | | | +---------------+ | | | DSA-SWITCH | | | vlan 1 | | | | to | | | | untagged 1 vlan 1 | | +---------------+---------------+ . / \ ----->wlan1 lan0 . . . ^ ^ vlan 1 tagged packetsuntagged packets
br_vlan_fill_forward_path_mode()setsDEV_PATH_BR_VLAN_UNTAG_HWwhen filling in from brlan.1 towards wlan1. But it should be set toDEV_PATH_BR_VLAN_UNTAGin this case. UsingBR_VLFLAG_ADDED_BY_SWITCHDEVis not correct. The dsa switchdev adds it as a foreign port.The same problem for all foreignly added dsa vlans on the bridge.
First add the vlan, trying only native devices.
If this fails, we know this may be a vlan from a foreign device.Use
BR_VLFLAG_TAGGING_BY_SWITCHDEVto make sureDEV_PATH_BR_VLAN_UNTAG_HWis set only when there if no foreign device involved.
Quoted 9 lines
Signed-off-by Eric Woudstra <[email protected]>--- include/net/switchdev.h | 1 + net/bridge/br_private.h | 10 ++++++++++ net/bridge/br_switchdev.c | 15 +++++++++++++++ net/bridge/br_vlan.c | 7 ++++++- net/switchdev/switchdev.c | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-)
Re: [PATCH v5 net-next 12/14] bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
In reply to Eric WoudstraQuoted 37 lines · Eric Woudstra
In network setup as below:
fastpath bypass
.----------------------------------------.
/ \| IP - forwarding | | / \ v | / wan ... | / | | | | | brlan.1 | | | +-------------------------------+ | | vlan 1 | | | | | | brlan (vlan-filtering) | | | +---------------+ | | | DSA-SWITCH | | | vlan 1 | | | | to | | | | untagged 1 vlan 1 | | +---------------+---------------+ . / \ ----->wlan1 lan0 . . . ^ ^ vlan 1 tagged packetsuntagged packets
br_vlan_fill_forward_path_mode()setsDEV_PATH_BR_VLAN_UNTAG_HWwhen filling in from brlan.1 towards wlan1. But it should be set toDEV_PATH_BR_VLAN_UNTAGin this case. UsingBR_VLFLAG_ADDED_BY_SWITCHDEVis not correct. The dsa switchdev adds it as a foreign port.The same problem for all foreignly added dsa vlans on the bridge.
Quoted 8 lines
First add the vlan, trying only native devices.
If this fails, we know this may be a vlan from a foreign device.Use
BR_VLFLAG_TAGGING_BY_SWITCHDEVto make sureDEV_PATH_BR_VLAN_UNTAG_HWis set only when there if no foreign device involved.Signed-off-by Eric Woudstra <[email protected]>---
Shouldn't mlxsw_sp_switchdev_vxlan_vlans_add() also respect the SWITCHDEV_F_NO_FOREIGN flag? My (maybe incorrect) understanding of bridging topologies with vxlan and mlxsw is that they are neighbor bridge ports, and mlxsw doesn't (seem to) call switchdev_bridge_port_offload() for the vxlan bridge port. This technically makes vxlan a foreign bridge port to mlxsw, so it should skip reacting on VLAN switchdev objects when that flag is set, just for uniform behavior across the board.
(your patch repeats the notifier without the SWITCHDEV_F_NO_FOREIGN flag anyway, so it only matters for flowtable offload).
Re: [PATCH v5 net-next 12/14] bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
Quoted 56 lines · Vladimir Oltean
Quoted 37 lines · Eric Woudstra
In network setup as below:
fastpath bypass
.----------------------------------------.
/ \| IP - forwarding | | / \ v | / wan ... | / | | | | | brlan.1 | | | +-------------------------------+ | | vlan 1 | | | | | | brlan (vlan-filtering) | | | +---------------+ | | | DSA-SWITCH | | | vlan 1 | | | | to | | | | untagged 1 vlan 1 | | +---------------+---------------+ . / \ ----->wlan1 lan0 . . . ^ ^ vlan 1 tagged packetsuntagged packets
br_vlan_fill_forward_path_mode()setsDEV_PATH_BR_VLAN_UNTAG_HWwhen filling in from brlan.1 towards wlan1. But it should be set toDEV_PATH_BR_VLAN_UNTAGin this case. UsingBR_VLFLAG_ADDED_BY_SWITCHDEVis not correct. The dsa switchdev adds it as a foreign port.The same problem for all foreignly added dsa vlans on the bridge.
Quoted 8 lines
First add the vlan, trying only native devices.
If this fails, we know this may be a vlan from a foreign device.Use
BR_VLFLAG_TAGGING_BY_SWITCHDEVto make sureDEV_PATH_BR_VLAN_UNTAG_HWis set only when there if no foreign device involved.Signed-off-by Eric Woudstra <[email protected]>---
Shouldn't
mlxsw_sp_switchdev_vxlan_vlans_add()also respect theSWITCHDEV_F_NO_FOREIGNflag? My (maybe incorrect) understanding of bridging topologies with vxlan and mlxsw is that they are neighbor bridge ports, and mlxsw doesn't (seem to) callswitchdev_bridge_port_offload()for the vxlan bridge port. This technically makes vxlan a foreign bridge port to mlxsw, so it should skip reacting on VLAN switchdev objects when that flag is set, just for uniform behavior across the board.
Quoted 2 lines
(your patch repeats the notifier without the
SWITCHDEV_F_NO_FOREIGNflag anyway, so it only matters for flowtable offload).
Or should mlxsw_sp_switchdev_blocking_event() use switchdev_handle_port_obj_add_foreign() to add the vxlan foreign port?
Then all foreign ports are added in a uniform manner and SWITCHDEV_F_NO_FOREIGN is respected.
I do not have the hardware to test any changes in that code.
Re: [PATCH v5 net-next 12/14] bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
Quoted 8 lines · Eric Woudstra
Or should
mlxsw_sp_switchdev_blocking_event()useswitchdev_handle_port_obj_add_foreign()to add the vxlan foreign port?Then all foreign ports are added in a uniform manner and
SWITCHDEV_F_NO_FOREIGNis respected.I do not have the hardware to test any changes in that code.
Personally, in your place I wouldn't have the courage to refactor that much in a driver as complex as spectrum, but if you CC the right people from Nvidia who can test, I guess you could give that a try.
Actually, how I came to spectrum was that I was thinking about an alternative mechanism of detecting "foreign or not", other than emitting two switchdev notifiers. You emit just the usual, single one, but whoever handles it for a foreign bridge port will set a new bool port_obj_info->handled_by_foreign, very similar to the existing bool port_obj_info->handled. I was looking around to see who else open-codes the switchdev object handling rather than use the switchdev_handle_*() helpers, and that's how I came across spectrum. It would seem, at first glance, easier to set just this in spectrum:
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +1 -0
@@ -3953,6 +3953,7 @@ mlxsw_sp_switchdev_vxlan_vlans_add(struct net_device *vxlan_dev,return 0 ; port_obj_info->handled = true; + port_obj_info->handled_by_foreign = true; bridge_device =mlxsw_sp_bridge_device_find (mlxsw_sp->bridge, br_dev);if (!bridge_device)
and this in the object replication helper:
net/switchdev/switchdev.c +2 -0
@@ -763,6 +763,8 @@ static int __switchdev_handle_port_obj_add(struct net_device *dev,if (!foreign_dev_check_cb (switchdev, dev))return err; + port_obj_info->handled_by_foreign = true; +return __switchdev_handle_port_obj_add (br, port_obj_info, check_cb, foreign_dev_check_cb, add_cb); }
Just some care needs to be taken to only consider "handled_by_foreign" just when "handled" is true.
I haven't yet decided which variant I like better, just thought I'd mention this as something which requires a single switchdev notification.
Anyway, in the future I'll have to do some more tweaks with these flags in the context of LAG. These flags (BR_VLFLAG_ADDED_BY_SWITCHDEV, now also BR_VLFLAG_TAGGING_BY_SWITCHDEV after this patch) can dynamically change, and the existing code isn't great because it doesn't handle that.
For example:
ip link add br0 type bridge
ip link set swp0 master br0
ip link set bond0 master br0 # bond0 is a foreign interface to swp0 at this time
bridge vlan add dev bond0 vid 100 # this won't get BR_VLFLAG_TAGGING_BY_SWITCHDEV
ip link set swp1 master bond0 # bond0 is no longer a foreign interface to swp0, assuming the same phys_switch_id
# vid 100 should get BR_VLFLAG_TAGGING_BY_SWITCHDEV during br_switchdev_vlan_replay()
Considering that br_switchdev_vlan_replay() will need to re-evaluate the BR_VLFLAG_TAGGING_BY_SWITCHDEV flag, I guess I do prefer the simpler variant after all - it is one call less that will have to be made during replay as well.
PATCH v5 13/14 bridge: Introduce DEV_PATH_BR_VLAN_KEEP_HW for bridge-fastpath
In reply to Eric WoudstraThis patch introduces DEV_PATH_BR_VLAN_KEEP_HW. It is needed in the bridge fastpath for switchdevs supporting SWITCHDEV_OBJ_ID_PORT_VLAN.
It is similar to DEV_PATH_BR_VLAN_TAG, with the correcponding bit in ingress_vlans set.
In the forward fastpath it is not needed.
--- include/linux/netdevice.h | 1 + net/bridge/br_device.c | 4 ++++ net/bridge/br_vlan.c | 18 +++++++++++------- net/netfilter/nft_flow_offload.c | 3 +++ 4 files changed, 19 insertions(+), 7 deletions(-)
include/linux/netdevice.h +1 -0
@@ -868,6 +868,7 @@ struct net_device_path {DEV_PATH_BR_VLAN_TAG ,DEV_PATH_BR_VLAN_UNTAG ,DEV_PATH_BR_VLAN_UNTAG_HW , +DEV_PATH_BR_VLAN_KEEP_HW , } vlan_mode;u16 vlan_id;__be16 vlan_proto;
net/bridge/br_device.c +4 -0
@@ -430,6 +430,10 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx,case DEV_PATH_BR_VLAN_UNTAG : ctx->num_vlans--;break ; +case DEV_PATH_BR_VLAN_KEEP_HW : +if (!src) + path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP ; +break ;case DEV_PATH_BR_VLAN_KEEP :break ; }
net/bridge/br_vlan.c +11 -7
@@ -1494,13 +1494,17 @@ int br_vlan_fill_forward_path_mode(struct net_bridge *br,if (!(v->flags &BRIDGE_VLAN_INFO_UNTAGGED ))return 0 ; -if (path->bridge.vlan_mode ==DEV_PATH_BR_VLAN_TAG ) - path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP ; -else if (v->priv_flags &BR_VLFLAG_TAGGING_BY_SWITCHDEV ) - path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG_HW ; -else - path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG ; - +if (path->bridge.vlan_mode ==DEV_PATH_BR_VLAN_TAG ) { +if (v->priv_flags &BR_VLFLAG_TAGGING_BY_SWITCHDEV ) + path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP_HW ; +else + path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP ; + }else { +if (v->priv_flags &BR_VLFLAG_TAGGING_BY_SWITCHDEV ) + path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG_HW ; +else + path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG ; + }return 0 ; }
net/netfilter/nft_flow_offload.c +3 -0
@@ -148,6 +148,9 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,case DEV_PATH_BR_VLAN_UNTAG_HW : info->ingress_vlans |=BIT (info->num_encaps -1 );break ; +case DEV_PATH_BR_VLAN_KEEP_HW : + info->ingress_vlans |=BIT (info->num_encaps); + fallthrough;case DEV_PATH_BR_VLAN_TAG : info->encap[info->num_encaps].id = path->bridge.vlan_id; info->encap[info->num_encaps].proto = path->bridge.vlan_proto;
Signature · 1 line
2.47.1
Re: [PATCH v5 net-next 13/14] bridge: Introduce DEV_PATH_BR_VLAN_KEEP_HW for bridge-fastpath
Quoted 8 lines · Eric Woudstra
This patch introduces
DEV_PATH_BR_VLAN_KEEP_HW. It is needed in the bridge fastpath for switchdevs supportingSWITCHDEV_OBJ_ID_PORT_VLAN.It is similar to
DEV_PATH_BR_VLAN_TAG, with the correcponding bit iningress_vlansset.In the forward fastpath it is not needed.
Quoted 8 lines
Signed-off-by Eric Woudstra <[email protected]>--- include/linux/netdevice.h | 1 + net/bridge/br_device.c | 4 ++++ net/bridge/br_vlan.c | 18 +++++++++++------- net/netfilter/nft_flow_offload.c | 3 +++ 4 files changed, 19 insertions(+), 7 deletions(-)
PATCH v5 14/14 netfilter: nft_flow_offload: Add bridgeflow to nft_flow_offload_eval()
In reply to Eric WoudstraEdit nft_flow_offload_eval() to make it possible to handle a flowtable of the nft bridge family.
Use nft_flow_offload_bridge_init() to fill the flow tuples. It uses nft_dev_fill_bridge_path() in each direction.
--- net/netfilter/nft_flow_offload.c | 142 +++++++++++++++++++++++++++++-- 1 file changed, 137 insertions(+), 5 deletions(-)
net/netfilter/nft_flow_offload.c +137 -5
@@ -193,6 +193,128 @@ static bool nft_flowtable_find_dev(const struct net_device *dev,return found; } +static int nft_dev_fill_bridge_path (struct flow_offload *flow, +struct nft_flowtable *ft, +enum ip_conntrack_dir dir, +const struct net_device *src_dev, +const struct net_device *dst_dev, +unsigned char *src_ha, +unsigned char *dst_ha) +{ +struct flow_offload_tuple_rhash *th = flow->tuplehash; +struct net_device_path_ctx ctx = {}; +struct net_device_path_stack stack; +struct nft_forward_info info = {}; +int i, j =0 ; + +for (i = th[dir].tuple.encap_num -1 ; i >=0 ; i--) { +if (info.num_encaps >=NF_FLOW_TABLE_ENCAP_MAX ) +return -1 ; + +if (th[dir].tuple.in_vlan_ingress &BIT (i)) +continue ; + + info.encap[info.num_encaps].id = th[dir].tuple.encap[i].id; + info.encap[info.num_encaps].proto = th[dir].tuple.encap[i].proto; + info.num_encaps++; + +if (th[dir].tuple.encap[i].proto ==htons (ETH_P_PPP_SES )) +continue ; + +if (ctx.num_vlans >=NET_DEVICE_PATH_VLAN_MAX ) +return -1 ; + ctx.vlan[ctx.num_vlans].id = th[dir].tuple.encap[i].id; + ctx.vlan[ctx.num_vlans].proto = th[dir].tuple.encap[i].proto; + ctx.num_vlans++; + } + ctx.dev = src_dev; +ether_addr_copy (ctx.daddr, dst_ha); + +if (dev_fill_bridge_path (&ctx, &stack) <0 ) +return -1 ; + +nft_dev_path_info (&stack, &info, dst_ha, &ft->data); + +if (!info.indev || info.indev != dst_dev) +return -1 ; + + th[!dir].tuple.iifidx = info.indev->ifindex; +for (i = info.num_encaps -1 ; i >=0 ; i--) { + th[!dir].tuple.encap[j].id = info.encap[i].id; + th[!dir].tuple.encap[j].proto = info.encap[i].proto; +if (info.ingress_vlans &BIT (i)) + th[!dir].tuple.in_vlan_ingress |=BIT (j); + j++; + } + th[!dir].tuple.encap_num = info.num_encaps; + + th[dir].tuple.mtu = dst_dev->mtu; +ether_addr_copy (th[dir].tuple.out.h_source, src_ha); +ether_addr_copy (th[dir].tuple.out.h_dest, dst_ha); + th[dir].tuple.out.ifidx = info.outdev->ifindex; + th[dir].tuple.xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ; + +return 0 ; +} + +static int nft_flow_offload_bridge_init (struct flow_offload *flow, +const struct nft_pktinfo *pkt, +enum ip_conntrack_dir dir, +struct nft_flowtable *ft) +{ +const struct net_device *in_dev, *out_dev; +struct ethhdr *eth =eth_hdr (pkt->skb); +struct flow_offload_tuple *tuple; +struct pppoe_hdr *phdr; +struct vlan_hdr *vhdr; +int err, i =0 ; + + in_dev =nft_in (pkt); +if (!in_dev || !nft_flowtable_find_dev (in_dev, ft)) +return -1 ; + + out_dev =nft_out (pkt); +if (!out_dev || !nft_flowtable_find_dev (out_dev, ft)) +return -1 ; + + tuple = &flow->tuplehash[!dir].tuple; + +if (skb_vlan_tag_present (pkt->skb)) { + tuple->encap[i].id =skb_vlan_tag_get (pkt->skb); + tuple->encap[i].proto = pkt->skb->vlan_proto; + i++; + } +switch (pkt->skb->protocol) { +case htons (ETH_P_8021Q ): + vhdr = (struct vlan_hdr *)skb_network_header (pkt->skb); + tuple->encap[i].id =ntohs (vhdr->h_vlan_TCI); + tuple->encap[i].proto = pkt->skb->protocol; + i++; +break ; +case htons (ETH_P_PPP_SES ): + phdr = (struct pppoe_hdr *)skb_network_header (pkt->skb); + tuple->encap[i].id =ntohs (phdr->sid); + tuple->encap[i].proto = pkt->skb->protocol; + i++; +break ; + } + tuple->encap_num = i; + + err =nft_dev_fill_bridge_path (flow, ft, !dir, out_dev, in_dev, + eth->h_dest, eth->h_source); +if (err <0 ) +return err; + +memset (tuple->encap,0 ,sizeof (tuple->encap)); + + err =nft_dev_fill_bridge_path (flow, ft, dir, in_dev, out_dev, + eth->h_source, eth->h_dest); +if (err <0 ) +return err; + +return 0 ; +} + static void nft_dev_forward_path(struct nf_flow_route *route, const struct nf_conn *ct, enum ip_conntrack_dir dir,
@@ -311,6 +433,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, {struct nft_flow_offload *priv =nft_expr_priv (expr);struct nf_flowtable *flowtable = &priv->flowtable->data; +bool routing = flowtable->type->family !=NFPROTO_BRIDGE ;struct tcphdr _tcph, *tcph =NULL ;struct nf_flow_route route = {};enum ip_conntrack_info ctinfo;
@@ -364,14 +487,21 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, goto out; dir =CTINFO2DIR (ctinfo); -if (nft_flow_route (pkt, ct, &route, dir, priv->flowtable) <0 ) - goto err_flow_route; +if (routing) { +if (nft_flow_route (pkt, ct, &route, dir, priv->flowtable) <0 ) + goto err_flow_route; + } flow =flow_offload_alloc (ct);if (!flow) goto err_flow_alloc; -flow_offload_route_init (flow, &route); +if (routing) +flow_offload_route_init (flow, &route); +else +if (nft_flow_offload_bridge_init (flow, pkt, dir, priv->flowtable) <0 ) + goto err_flow_add; +if (tcph)flow_offload_ct_tcp (ct);
@@ -419,8 +549,10 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, err_flow_add:flow_offload_free (flow); err_flow_alloc: -dst_release (route.tuple[dir].dst); -dst_release (route.tuple[!dir].dst); +if (routing) { +dst_release (route.tuple[dir].dst); +dst_release (route.tuple[!dir].dst); + } err_flow_route:clear_bit (IPS_OFFLOAD_BIT , &ct->status); out:
Signature · 1 line
2.47.1