bridge: Add filling forward path from port to port
Subsystems (4)
Pablo Neira Ayuso
maintainerPATCH 1/4 bridge: Add filling forward path from port to port
From: Eric Woudstra <[email protected]>
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.
Changed call to br_vlan_group() into br_vlan_group_rcu() while at it.
---
v1: I took this existing patch for the bridge vlan filtering, but
bridge vlan filtering is untested at this stage at least for me.
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
@@ -385,16 +385,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
@@ -1630,6 +1630,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,
@@ -1799,6 +1800,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
@@ -1450,6 +1450,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) {
@@ -1462,7 +1463,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_rcu (br); +if (p) + vg =nbp_vlan_group_rcu (p); +else + vg =br_vlan_group_rcu (br);if (idx >=0 && ctx->vlan[idx].proto == br->vlan_proto) {
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/4 net: pass net_device_path_ctx struct to dev_fill_forward_path()
Generalize dev_fill_forward_path() so it can be used by the bridge family to retrieve the bridge vlan filtering information from the bridge port when discovering the bridge flowtable path.
---
v1: A different approach compared to Eric Woudstra's proposal to
add another function to the net core for the bridge case. I am leaning towards making a simple generalization and keep the bridge vlan filtering path discovery special case under the flowtable at this stage.
include/linux/netdevice.h | 2 +- net/core/dev.c | 18 +++++++----------- net/netfilter/nf_flow_table_path.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 13 deletions(-)
include/linux/netdevice.h +1 -1
@@ -3420,7 +3420,7 @@ 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_forward_path (const struct net_device *dev,const u8 *daddr, +int dev_fill_forward_path (struct net_device_path_ctx *ctx,struct net_device_path_stack *stack);struct net_device *dev_get_by_name (struct net *net,const char *name);struct net_device *dev_get_by_name_rcu (struct net *net,const char *name);
net/core/dev.c +7 -11
@@ -750,41 +750,37 @@ static struct net_device_path *dev_fwd_path(struct net_device_path_stack *stack)return &stack->path[k]; } -int dev_fill_forward_path (const struct net_device *dev,const u8 *daddr, +int dev_fill_forward_path (struct net_device_path_ctx *ctx,struct net_device_path_stack *stack) {const struct net_device *last_dev; -struct net_device_path_ctx ctx = { - .dev = dev, - };struct net_device_path *path;int ret =0 ; -memcpy (ctx.daddr, daddr,sizeof (ctx.daddr)); stack->num_paths =0 ; -while (ctx.dev && ctx.dev->netdev_ops->ndo_fill_forward_path) { - last_dev = ctx.dev; +while (ctx->dev && ctx->dev->netdev_ops->ndo_fill_forward_path) { + last_dev = ctx->dev; path =dev_fwd_path (stack);if (!path)return -1 ;memset (path,0 ,sizeof (struct net_device_path )); - ret = ctx.dev->netdev_ops->ndo_fill_forward_path (&ctx, path); + ret = ctx->dev->netdev_ops->ndo_fill_forward_path (ctx, path);if (ret <0 )return -1 ; -if (WARN_ON_ONCE (last_dev == ctx.dev)) +if (WARN_ON_ONCE (last_dev == ctx->dev))return -1 ; } -if (!ctx.dev) +if (!ctx->dev)return ret; path =dev_fwd_path (stack);if (!path)return -1 ; path->type =DEV_PATH_ETHERNET ; - path->dev = ctx.dev; + path->dev = ctx->dev;return ret; }
net/netfilter/nf_flow_table_path.c +11 -1
@@ -42,6 +42,14 @@ static bool nft_is_valid_ether_device(const struct net_device *dev)return true; } +static void nft_dev_fill_forward_path_init (struct net_device_path_ctx *ctx, +const struct net_device *dev,const u8 *daddr) +{ +memset (ctx,0 ,sizeof (*ctx)); + ctx->dev = dev; +memcpy (ctx->daddr, daddr,sizeof (ctx->daddr)); +} + static int nft_dev_fill_forward_path(const struct nf_flow_route *route, const struct dst_entry *dst_cache, const struct nf_conn *ct,
@@ -50,6 +58,7 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route, {const void *daddr = &ct->tuplehash[!dir].tuple.src.u3;struct net_device *dev = dst_cache->dev; +struct net_device_path_ctx ctx;struct neighbour *n;u8 nud_state;
@@ -71,8 +80,9 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,if (!(nud_state &NUD_VALID ))return -1 ; +nft_dev_fill_forward_path_init (&ctx, dev, ha); out: -return dev_fill_forward_path (dev, ha, stack); +return dev_fill_forward_path (&ctx, stack); }struct nft_forward_info {
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 3/4 net: expose dev_fwd_path() helper via static inline
In reply to Pablo Neira AyusoThis is a preparation patch to be used by the bridge family to retrieve the bridge vlan filtering information from the bridge port when discovering the bridge flowtable path.
---
v1: Just a preparation patch to allow to move the bridge vlan filtering
path discovery code to the flowtable infrastructure.
include/linux/netdevice.h | 11 +++++++++++ net/core/dev.c | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-)
include/linux/netdevice.h +11 -0
@@ -3420,6 +3420,17 @@ 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); + +static inline struct net_device_path *dev_fwd_path (struct net_device_path_stack *stack) +{ +int k = stack->num_paths++; + +if (k >=NET_DEVICE_PATH_STACK_MAX ) +return NULL ; + +return &stack->path[k]; +} +int dev_fill_forward_path (struct net_device_path_ctx *ctx,struct net_device_path_stack *stack);struct net_device *dev_get_by_name (struct net *net,const char *name);
net/core/dev.c +0 -10
@@ -740,16 +740,6 @@ int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) }EXPORT_SYMBOL_GPL (dev_fill_metadata_dst); -static struct net_device_path *dev_fwd_path (struct net_device_path_stack *stack) -{ -int k = stack->num_paths++; - -if (k >=NET_DEVICE_PATH_STACK_MAX ) -return NULL ; - -return &stack->path[k]; -} -int dev_fill_forward_path (struct net_device_path_ctx *ctx,struct net_device_path_stack *stack) {
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 4/4 netfilter: flowtable: initial bridge support
In reply to Pablo Neira AyusoThis patch adds bridge flowtable support, this allows to define a shortcut between two bridge ports. This is complementary to the existing inet family flowtable support.
Set up does not require userspace updates, an example ruleset to enable the flowtable in the bridge family is provided here below:
table bridge x {
flowtable y {
hook ingress priority 0
devices = { veth0, veth1 }
}
chain forward {
type filter hook forward priority 0
ip protocol tcp flow add @y counter
counter
}}
I decided to add an explicit nft_flow_offload_bridge_eval() instead of recycling the existing inet function by adding branches to skip the routing part which is obviously not needed in the bridge path. I consider this mostly boiler plate for feature extensibility and better maintability is better to keep it separated. Similarly, the bridge hook that represents the flowtable bridge datapath is implemented in a separated function.
Although connection tracking in the bridge does not support the tracking of IP flows encapsulated in PPPoE and VLAN tracking yet, there are scenarios that involved PPPoE and VLAN that can be supported already, such as those where packets flows through the bridge with no tagging, eg. a VLAN device is used as a bridge port which decapsulates the packets at the ingress path.
Tested with:
- Plain forwarding between bridge ports with no VLAN tagging.
- VLAN device used in bridged ports.
The bridge vlan filtering supported is untested at this stage based on previous work by Eric Woudstra.
Hardware offload is disabled until there is a driver supporting this.
---
v1: Different approach to what Eric Woudstra proposes:
- Instead of extending the existing _eval() and _hook() function that represent the flowtable offload stage and datapath, add new specific functions. It is more code, but it is boilerplate code and it might help to make it more maintainable as new specific bridge features are added, I believe.
- As noted in the commit description, bridge vlan filtering support is untested, I have used the existing code posted by Eric Woudstra in this regard.
include/net/netfilter/nf_flow_table.h | 7 ++ net/netfilter/nf_flow_table_inet.c | 12 +++ net/netfilter/nf_flow_table_ip.c | 134 ++++++++++++++++++++++++++ net/netfilter/nf_flow_table_offload.c | 8 +- net/netfilter/nf_flow_table_path.c | 95 ++++++++++++++++++ net/netfilter/nft_flow_offload.c | 88 ++++++++++++++++- 6 files changed, 340 insertions(+), 4 deletions(-)
include/net/netfilter/nf_flow_table.h +7 -0
@@ -248,6 +248,8 @@ struct nft_pktinfo;int nft_flow_route (const struct nft_pktinfo *pkt,const struct nf_conn *ct,struct nf_flow_route *route,enum ip_conntrack_dir dir,struct nft_flowtable *ft); +int nft_flow_bridge (struct flow_offload *flow,const struct nft_pktinfo *pkt, +enum ip_conntrack_dir dir,struct nft_flowtable *ft); static inline int nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table,
@@ -342,6 +344,8 @@ unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state);unsigned int nf_flow_offload_ipv6_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state); +unsigned int nf_flow_offload_bridge_hook (void *priv,struct sk_buff *skb, +const struct nf_hook_state *state);#if (IS_BUILTIN (CONFIG_NF_FLOW_TABLE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF )) || \ (IS_MODULE (CONFIG_NF_FLOW_TABLE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF_MODULES ))
@@ -377,6 +381,9 @@ int nf_flow_rule_route_ipv4(struct net *net, struct flow_offload *flow,int nf_flow_rule_route_ipv6 (struct net *net,struct flow_offload *flow,enum flow_offload_tuple_dir dir,struct nf_flow_rule *flow_rule); +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_table_offload_init (void );void nf_flow_table_offload_exit (void );
net/netfilter/nf_flow_table_inet.c +12 -0
@@ -65,6 +65,15 @@ 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, + .free = nf_flow_table_free, + .hook = nf_flow_offload_bridge_hook, + .owner =THIS_MODULE , +}; +static struct nf_flowtable_type flowtable_inet = { .family =NFPROTO_INET , .init = nf_flow_table_init,
@@ -97,6 +106,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 +119,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 +129,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" );
net/netfilter/nf_flow_table_ip.c +134 -0
137 lines not on this page · raw message
net/netfilter/nf_flow_table_offload.c +5 -3
@@ -1101,9 +1101,11 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,return offload; } -static bool nf_flow_offload_unsupported (struct flow_offload *flow) +static bool nf_flow_offload_unsupported (struct nf_flowtable *flowtable, +struct flow_offload *flow) { -if (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.tun_num || +if (flowtable->type->family ==NFPROTO_BRIDGE || + flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.tun_num || flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.tun_num)return true;
@@ -1125,7 +1127,7 @@ void nf_flow_offload_refresh(struct nf_flowtable *flowtable,void nf_flow_offload_add (struct nf_flowtable *flowtable,struct flow_offload *flow) { -if (nf_flow_offload_unsupported (flow)) +if (nf_flow_offload_unsupported (flowtable, flow))return ;__set_bit (NF_FLOW_HW , &flow->flags);
net/netfilter/nf_flow_table_path.c +95 -0
104 lines not on this page · raw message
net/netfilter/nft_flow_offload.c +87 -1
114 lines not on this page · raw message
Signature · 1 line
2.47.3
Quoted 40 lines · Pablo Neira Ayuso
From: Eric Woudstra <[email protected]>
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.Changed call to
br_vlan_group()intobr_vlan_group_rcu()while at it.Signed-off-by Eric Woudstra <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>---
v1: I took this existing patch for the bridge vlan filtering, but
bridge vlan filtering is untested at this stage at least for me.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 +2
-3@@ -385,16 +385,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)) {
net/bridge/br_device.c static int br_del_slave(struct net_device *dev, struct net_device *slave_dev) · line 401
Quoted 10 lines
net/bridge/br_device.c +8
-1+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 {
So as per Nikolay's comment on another thread, Can add here:
if (!netif_is_bridge_master(ctx->dev)) return -1;
So that it can continue normally if ctx->dev is a bridge master.
Quoted 53 lines
net/bridge/br_device.c +4
-1+ 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@@ -1630,6 +1630,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,@@ -1799,6 +1800,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@@ -1450,6 +1450,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) {@@ -1462,7 +1463,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_rcu (br); +if (p) + vg =nbp_vlan_group_rcu (p); +else + vg =br_vlan_group_rcu (br);if (idx >=0 && ctx->vlan[idx].proto == br->vlan_proto) {