Non-promisc bidge ports support
Subsystems (3)
v3 cover Non-promisc bidge ports support
This series adds functionality to the bridge device to enable operations without setting all ports to promiscuous mode.
The basic concept is this. The bridge keeps track of the ports that support learning and flooding packets to unknown destinations. We call these ports auto-discovery ports since they automatically discover who is behind them through learning and flooding.
If flooding and learning are disabled via flags, then the port requires static configuration to tell it which mac addresses are behind it. This is accomplished through adding of fdbs. These fdbs should be static as dynamic fdbs can expire and systems will become unreachable due to lack of flooding.
If the user marks all ports as needing static configuration then we can safely make them non-promiscuous since we will know all the information about them.
If the user leaves only 1 port as automatic, then we can mark that port as not-promiscuous as well. One could think of this a edge relay similar to what's support by embedded switches in SRIOV devices. Since we have all the information about the other ports, we can just program the mac addresses into the single automatic port to receive all necessary traffic. More information about this is patch 6.
In other cases, we keep all ports promiscuous as before.
There are some other cases when promiscuous mode has to be turned back on. One is when the bridge itself if placed in promiscuous mode (user sets promisc flag). The other is if vlan filtering is turned off. Since this is the default configuration, the default bridge operation is not changed.
Changes since v2:
- White space and spelling fixes from Michael Tsirkin
- Squash patches 6, 7 and 8 to prevent bisect breakage.
Changes since v1:
- Address issues rasied by Stephen Heminger
- Address initializer comments raised by Sergey Shtylyov
- Rebased recent net-next.
Changes since rfc v2:
- Better description of in the commit logs
- Leave port in promiscuous mode if IFF_UNICAST_FLT is disabled on the device.
- Fix issue with flag masking
- Rework patch ordering a bit.
Changes since rfc v1:
- Removed private list. We now traverse the fdb hashtable itself to write necessary addresses to the ports (Stephen's concern)
- Add learning flag to the mask for flags that decides if the port is 'auto' or not (suggest by MST and Jamal).
- Simplified tracking of such ports at the cost of a loop over all ports (suggested by MST)
I've played with quite a large number of ports and the current approach seems to work fairly well.
Thanks
-vlad
Vlad Yasevich (6):
bridge: Turn flag change macro into a function.
bridge: Keep track of ports capable of automatic discovery.
bridge: Add functionality to sync static fdb entries to hw
bridge: Introduce BR_PROMISC flag
bridge: Add addresses from static fdbs to non-promisc ports
bridge: Automatically manage port promiscuous mode.
net/bridge/br_device.c | 7 +++ net/bridge/br_fdb.c | 131 ++++++++++++++++++++++++++++++++++++++++++++--- net/bridge/br_if.c | 123 ++++++++++++++++++++++++++++++++++++++++++-- net/bridge/br_netlink.c | 3 ++ net/bridge/br_private.h | 19 +++++++ net/bridge/br_sysfs_if.c | 30 +++++++---- net/bridge/br_vlan.c | 1 + 7 files changed, 294 insertions(+), 20 deletions(-)
Signature · 1 line
1.9.0
PATCH v3 1/6 bridge: Turn flag change macro into a function.
Turn the flag change macro into a function to allow easier updates and to reduce space.
--- net/bridge/br_sysfs_if.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
net/bridge/br_sysfs_if.c +17 -10
@@ -41,20 +41,27 @@ static ssize_t show_##_name(struct net_bridge_port *p, char *buf) \ } \ static int store_##_name(struct net_bridge_port *p, unsigned long v) \ { \ -unsigned long flags = p->flags; \ -if (v) \ - flags |= _mask; \ -else \ - flags &= ~_mask; \ -if (flags != p->flags) { \ - p->flags = flags; \ -br_ifinfo_notify (RTM_NEWLINK , p); \ - } \ -return 0 ; \ +return store_flag (p, v, _mask); \ } \ static BRPORT_ATTR(_name, S_IRUGO | S_IWUSR, \ show_##_name, store_##_name) +static int store_flag(struct net_bridge_port *p, unsigned long v, +unsigned long mask) +{ +unsigned long flags = p->flags; + +if (v) + flags |= mask; +else + flags &= ~mask; + +if (flags != p->flags) { + p->flags = flags; +br_ifinfo_notify (RTM_NEWLINK , p); + } +return 0 ; +}static ssize_t show_path_cost (struct net_bridge_port *p,char *buf) {
Signature · 1 line
1.9.0
PATCH v3 2/6 bridge: Keep track of ports capable of automatic discovery.
In reply to Vlad YasevichBy default, ports on the bridge are capable of automatic discovery of nodes located behind the port. This is accomplished via flooding of unknown traffic (BR_FLOOD) and learning the mac addresses from these packets (BR_LEARNING).
If the above functionality is disabled by turning off these flags, the port requires static configuration in the form of static FDB entries to function properly.
This patch adds functionality to keep track of all ports capable of automatic discovery. This will later be used to control promiscuity settings.
--- net/bridge/br_if.c | 24 ++++++++++++++++++++++++ net/bridge/br_netlink.c | 3 +++ net/bridge/br_private.h | 5 +++++ net/bridge/br_sysfs_if.c | 5 ++++- 4 files changed, 36 insertions(+), 1 deletion(-)
net/bridge/br_if.c +24 -0
@@ -85,6 +85,18 @@ void br_port_carrier_check(struct net_bridge_port *p)spin_unlock_bh (&br->lock); } +static void nbp_update_port_count (struct net_bridge *br) +{ +struct net_bridge_port *p; +u32 cnt =0 ; + +list_for_each_entry (p, &br->port_list, list) { +if (br_auto_port (p)) + cnt++; + } + br->auto_cnt = cnt; +} +static void release_nbp (struct kobject *kobj) {struct net_bridge_port *p
@@ -146,6 +158,8 @@ static void del_nbp(struct net_bridge_port *p)list_del_rcu (&p->list); +nbp_update_port_count (br); + dev->priv_flags &= ~IFF_BRIDGE_PORT ;netdev_rx_handler_unregister (dev);
@@ -384,6 +398,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)list_add_rcu (&p->list, &br->port_list); +nbp_update_port_count (br); +netdev_update_features (br->dev);if (br->dev->needed_headroom < dev->needed_headroom)
@@ -455,3 +471,11 @@ int br_del_if(struct net_bridge *br, struct net_device *dev)return 0 ; } + +void br_port_flags_change (struct net_bridge_port *p,unsigned long mask) +{ +struct net_bridge *br = p->br; + +if (mask &BR_AUTO_MASK ) +nbp_update_port_count (br); +}
net/bridge/br_netlink.c +3 -0
@@ -328,6 +328,7 @@ static void br_set_port_flag(struct net_bridge_port *p, struct nlattr *tb[],static int br_setport (struct net_bridge_port *p,struct nlattr *tb[]) {int err; +unsigned long old_flags = p->flags;br_set_port_flag (p, tb,IFLA_BRPORT_MODE ,BR_HAIRPIN_MODE );br_set_port_flag (p, tb,IFLA_BRPORT_GUARD ,BR_BPDU_GUARD );
@@ -353,6 +354,8 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[])if (err)return err; } + +br_port_flags_change (p, old_flags ^ p->flags);return 0 ; }
net/bridge/br_private.h +5 -0
@@ -174,6 +174,7 @@ struct net_bridge_port#define BR_ADMIN_COST 0x00000010#define BR_LEARNING 0x00000020#define BR_FLOOD 0x00000040 +#define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING)#ifdef CONFIG_BRIDGE_IGMP_SNOOPING struct bridge_mcast_query ip4_query;
@@ -198,6 +199,8 @@ struct net_bridge_port#endif }; +#define br_auto_port (p) ((p)->flags & BR_AUTO_MASK) +#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)static inline struct net_bridge_port *br_port_get_rcu (const struct net_device *dev)
@@ -290,6 +293,7 @@ struct net_bridgestruct timer_list topology_change_timer;struct timer_list gc_timer;struct kobject *ifobj; +u32 auto_cnt;#ifdef CONFIG_BRIDGE_VLAN_FILTERING u8 vlan_enabled;struct net_port_vlans __rcu *vlan_info;
@@ -415,6 +419,7 @@ int br_del_if(struct net_bridge *br, struct net_device *dev);int br_min_mtu (const struct net_bridge *br);netdev_features_t br_features_recompute (struct net_bridge *br,netdev_features_t features); +void br_port_flags_change (struct net_bridge_port *port,unsigned long mask);/* br_input.c */ int br_handle_frame_finish (struct sk_buff *skb);
net/bridge/br_sysfs_if.c +4 -1
@@ -49,7 +49,9 @@ static BRPORT_ATTR(_name, S_IRUGO | S_IWUSR, \static int store_flag (struct net_bridge_port *p,unsigned long v,unsigned long mask) { -unsigned long flags = p->flags; +unsigned long flags; + + flags = p->flags;if (v) flags |= mask;
@@ -58,6 +60,7 @@ static int store_flag(struct net_bridge_port *p, unsigned long v,if (flags != p->flags) { p->flags = flags; +br_port_flags_change (p, mask);br_ifinfo_notify (RTM_NEWLINK , p); }return 0 ;
Signature · 1 line
1.9.0
PATCH v3 3/6 bridge: Add functionality to sync static fdb entries to hw
In reply to Vlad YasevichAdd code that allows static fdb entires to be synced to the hw list for a specified port. This will be used later to program ports that can function in non-promiscuous mode.
--- net/bridge/br_fdb.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 2 ++ 2 files changed, 58 insertions(+)
net/bridge/br_fdb.c +56 -0
@@ -874,3 +874,59 @@ int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], out:return err; } + +int br_fdb_sync_static (struct net_bridge *br,struct net_bridge_port *p) +{ +struct net_bridge_fdb_entry *fdb, *tmp; +int i; +int err; + +ASSERT_RTNL (); + +for (i =0 ; i <BR_HASH_SIZE ; i++) { +hlist_for_each_entry (fdb, &br->hash[i], hlist) { +/* We only care for static entries */ +if (!fdb->is_static) +continue ; + + err =dev_uc_add (p->dev, fdb->addr.addr); +if (err) + goto rollback; + } + } +return 0 ; + +rollback: +for (i =0 ; i <BR_HASH_SIZE ; i++) { +hlist_for_each_entry (tmp, &br->hash[i], hlist) { +/* If we reached the fdb that failed, we can stop */ +if (tmp == fdb) +break ; + +/* We only care for static entries */ +if (!tmp->is_static) +continue ; + +dev_uc_del (p->dev, tmp->addr.addr); + } + } +return err; +} + +void br_fdb_unsync_static (struct net_bridge *br,struct net_bridge_port *p) +{ +struct net_bridge_fdb_entry *fdb; +int i; + +ASSERT_RTNL (); + +for (i =0 ; i <BR_HASH_SIZE ; i++) { +hlist_for_each_entry_rcu (fdb, &br->hash[i], hlist) { +/* We only care for static entries */ +if (!fdb->is_static) +continue ; + +dev_uc_del (p->dev, fdb->addr.addr); + } + } +}
net/bridge/br_private.h +2 -0
@@ -399,6 +399,8 @@ int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, const unsigned char *addr, u16 nlh_flags);int br_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb,struct net_device *dev,int idx); +int br_fdb_sync_static (struct net_bridge *br,struct net_bridge_port *p); +void br_fdb_unsync_static (struct net_bridge *br,struct net_bridge_port *p);/* br_forward.c */ void br_deliver (const struct net_bridge_port *to,struct sk_buff *skb);
Signature · 1 line
1.9.0
PATCH v3 4/6 bridge: Introduce BR_PROMISC flag
In reply to Vlad YasevichIntroduce a BR_PROMISC per-port flag that will help us track if the current port is supposed to be in promiscuous mode or not. For now, always start in promiscuous mode.
--- net/bridge/br_if.c | 2 +- net/bridge/br_private.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
net/bridge/br_if.c +1 -1
@@ -238,7 +238,7 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br, p->path_cost =port_cost (dev); p->priority =0x8000 >>BR_PORT_BITS ; p->port_no = index; - p->flags =BR_LEARNING |BR_FLOOD ; + p->flags =BR_LEARNING |BR_FLOOD |BR_PROMISC ;br_init_port (p); p->state =BR_STATE_DISABLED ;br_stp_port_timer_init (p);
net/bridge/br_private.h +2 -0
@@ -175,6 +175,7 @@ struct net_bridge_port#define BR_LEARNING 0x00000020#define BR_FLOOD 0x00000040#define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING) +#define BR_PROMISC 0x00000080#ifdef CONFIG_BRIDGE_IGMP_SNOOPING struct bridge_mcast_query ip4_query;
@@ -200,6 +201,7 @@ struct net_bridge_port };#define br_auto_port (p) ((p)->flags & BR_AUTO_MASK) +#define br_promisc_port (p) ((p)->flags & BR_PROMISC)#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)
Signature · 1 line
1.9.0
PATCH v3 5/6 bridge: Add addresses from static fdbs to non-promisc ports
In reply to Vlad YasevichWhen a static fdb entry is created, add the mac address from this fdb entry to any ports that are currently running in non-promiscuous mode. These ports need this data so that they can receive traffic destined to these addresses. By default ports start in promiscuous mode, so this feature is disabled.
--- net/bridge/br_fdb.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 6 deletions(-)
net/bridge/br_fdb.c +69 -6
@@ -85,8 +85,58 @@ static void fdb_rcu_free(struct rcu_head *head)kmem_cache_free (br_fdb_cache, ent); } +/* When a static FDB entry is added, the mac address from the entry is +* added to the bridge private HW address list and all required ports +* are then updated with the new information. +* Called under RTNL. +*/ +static void fdb_add_hw (struct net_bridge *br,const unsigned char *addr) +{ +int err; +struct net_bridge_port *p, *tmp; + +ASSERT_RTNL (); + +list_for_each_entry (p, &br->port_list, list) { +if (!br_promisc_port (p)) { + err =dev_uc_add (p->dev, addr); +if (err) + goto undo; + } + } + +return ; +undo: +list_for_each_entry (tmp, &br->port_list, list) { +if (tmp == p) +break ; +if (!br_promisc_port (tmp)) +dev_uc_del (tmp->dev, addr); + } +} + +/* When a static FDB entry is deleted, the HW address from that entry is +* also removed from the bridge private HW address list and updates all +* the ports with needed information. +* Called under RTNL. +*/ +static void fdb_del_hw (struct net_bridge *br,const unsigned char *addr) +{ +struct net_bridge_port *p; + +ASSERT_RTNL (); + +list_for_each_entry (p, &br->port_list, list) { +if (!br_promisc_port (p)) +dev_uc_del (p->dev, addr); + } +} +static void fdb_delete (struct net_bridge *br,struct net_bridge_fdb_entry *f) { +if (f->is_static) +fdb_del_hw (br, f->addr.addr); +hlist_del_rcu (&f->hlist);fdb_notify (br, f,RTM_DELNEIGH );call_rcu (&f->rcu, fdb_rcu_free);
@@ -466,6 +516,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,return -ENOMEM ; fdb->is_local = fdb->is_static =1 ; +fdb_add_hw (br, addr);fdb_notify (br, fdb,RTM_NEWNEIGH );return 0 ; }
@@ -678,13 +729,25 @@ static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr, }if (fdb_to_nud (fdb) != state) { -if (state &NUD_PERMANENT ) - fdb->is_local = fdb->is_static =1 ; -else if (state &NUD_NOARP ) { +if (state &NUD_PERMANENT ) { + fdb->is_local =1 ; +if (!fdb->is_static) { + fdb->is_static =1 ; +fdb_add_hw (br, addr); + } + }else if (state &NUD_NOARP ) { fdb->is_local =0 ; - fdb->is_static =1 ; - }else - fdb->is_local = fdb->is_static =0 ; +if (!fdb->is_static) { + fdb->is_static =1 ; +fdb_add_hw (br, addr); + } + }else { + fdb->is_local =0 ; +if (fdb->is_static) { + fdb->is_static =0 ; +fdb_del_hw (br, addr); + } + } modified = true; }
Signature · 1 line
1.9.0
PATCH v3 6/6 bridge: Automatically manage port promiscuous mode.
In reply to Vlad YasevichThere exist configurations where the administrator or another management entity has the foreknowledge of all the mac addresses of end systems that are being bridged together.
In these environments, the administrator can statically configure known addresses in the bridge FDB and disable flooding and learning on ports. This makes it possible to turn off promiscuous mode on the interfaces connected to the bridge.
Here is why disabling flooding and learning allows us to control promiscuity:
Consider port X. All traffic coming into this port from outside the
bridge (ingress) will be either forwarded through other ports of the bridge (egress) or dropped. Forwarding (egress) is defined by FDB entries and by flooding in the event that no FDB entry exists. In the event that flooding is disabled, only FDB entries define the egress. Once learning is disabled, only static FDB entries provided by a management entity define the egress. If we provide information from these static FDBs to the ingress port X, then we'll be able to accept all traffic that can be successfully forwarded and drop all the other traffic sooner without spending CPU cycles to process it.
Another way to define the above is as following equations:
ingress = egress + drop
expanding egress
ingress = static FDB + learned FDB + flooding + drop
disabling flooding and learning we a left with
ingress = static FDB + drop
By adding addresses from the static FDB entries to the MAC address filter of an ingress port X, we fully define what the bridge can process without dropping and can thus turn off promiscuous mode, thus dropping packets sooner.
There have been suggestions that we may want to allow learning and update the filters with learned addresses as well. This would require mac-level authentication similar to 802.1x to prevent attacks against the hw filters as they are limited resource.
Additionally, if the user places the bridge device in promiscuous mode, all ports are placed in promiscuous mode regardless of the changes to flooding and learning.
Since the above functionality depends on full static configuration, we have also require that vlan filtering be enabled to take advantage of this. The reason is that the bridge has to be able to receive and process VLAN-tagged frames and the there are only 2 ways to accomplish this right now: promiscuous mode or vlan filtering.
--- net/bridge/br_device.c | 7 ++++ net/bridge/br_if.c | 105 ++++++++++++++++++++++++++++++++++++++++++++---- net/bridge/br_private.h | 10 +++++ net/bridge/br_vlan.c | 1 + 4 files changed, 116 insertions(+), 7 deletions(-)
net/bridge/br_device.c +7 -0
@@ -112,6 +112,12 @@ static void br_dev_set_multicast_list(struct net_device *dev) { } +static void br_dev_change_rx_flags (struct net_device *dev,int change) +{ +if (change &IFF_PROMISC ) +br_manage_promisc (netdev_priv (dev)); +} +static int br_dev_stop (struct net_device *dev) {struct net_bridge *br =netdev_priv (dev);
@@ -309,6 +315,7 @@ static const struct net_device_ops br_netdev_ops = { .ndo_get_stats64 = br_get_stats64, .ndo_set_mac_address = br_set_mac_address, .ndo_set_rx_mode = br_dev_set_multicast_list, + .ndo_change_rx_flags = br_dev_change_rx_flags, .ndo_change_mtu = br_change_mtu, .ndo_do_ioctl = br_dev_ioctl,#ifdef CONFIG_NET_POLL_CONTROLLER
net/bridge/br_if.c +98 -7
143 lines not on this page · raw message
net/bridge/br_private.h +10 -0
@@ -424,6 +424,7 @@ int br_min_mtu(const struct net_bridge *br);netdev_features_t br_features_recompute (struct net_bridge *br,netdev_features_t features);void br_port_flags_change (struct net_bridge_port *port,unsigned long mask); +void br_manage_promisc (struct net_bridge *br);/* br_input.c */ int br_handle_frame_finish (struct sk_buff *skb);
@@ -641,6 +642,10 @@ static inline u16 br_get_pvid(const struct net_port_vlans *v)return v->pvid ?:VLAN_N_VID ; } +static inline int br_vlan_enabled (struct net_bridge *br) +{ +return br->vlan_enabled; +}#else static inline bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
@@ -721,6 +726,11 @@ static inline u16 br_get_pvid(const struct net_port_vlans *v) {return VLAN_N_VID ;/* Returns invalid vid */ } + +static inline int br_vlan_enabled (struct net_bridge *br); +{ +return 0 ; +}#endif /* br_netfilter.c */
net/bridge/br_vlan.c +1 -0
@@ -332,6 +332,7 @@ int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) goto unlock; br->vlan_enabled = val; +br_manage_promisc (br); unlock:rtnl_unlock ();
Signature · 1 line
1.9.0
David Miller
maintainerFrom: Vlad Yasevich <[email protected]>
Date: Fri, 16 May 2014 09:59:14 -0400
Quoted 2 lines
This series adds functionality to the bridge device to enable operations without setting all ports to promiscuous mode.
Series applied, thanks Vlad.