bridge: don't age out externally added FDB entries
Subsystems (5)
v3 cover bridge: don't age out externally added FDB entries
From: Scott Feldman <[email protected]>
v3: Per davem review: add del_timer_sync on rocker port remove.
v2: Per Jiri review comment: add BR_DEFAULT_AGEING_TIME to defines
Siva originally proposed skipping externally added FDB entries in the bridge's FDB garbage collection func, and moving the ageing of externally added entries to the port driver/device. This broke rocker, since rocker didn't have a hardware (or software) mechanism for ageing out its learned FDB entries.
This patchset reintroduces Siva's bridge driver patch to skip externally added entries and adds support in rocker so rocker can age out its own entries. Rocker does this using a software timer similar to the bridge's FDB garbage collection timer. Other switchdev devices/drivers can use this software timer method or program the device to nofity aged-out entries to the driver.
Updated switchdev.txt documentation to reflect current state-of-the-art. This removes one more XXX todo comment in switchdev.txt.
Scott Feldman (6):
rocker: track when FDB entry is touched.
rocker: store rocker_port in fdb key rather than pport
bridge: define some min/max/default ageing time constants
rocker: adding port ageing_time for ageing out FDB entries
rocker: add FDB cleanup timer
switchdev: update documentation on FDB ageing_time
Siva Mannem (1):
bridge: don't age externally added FDB entries
Documentation/networking/switchdev.txt | 24 +++++------ drivers/net/ethernet/rocker/rocker.c | 70 +++++++++++++++++++++++++++----- include/linux/if_bridge.h | 6 +++ net/bridge/br_device.c | 2 +- net/bridge/br_fdb.c | 2 + 5 files changed, 81 insertions(+), 23 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v3 1/7 rocker: track when FDB entry is touched.
From: Scott Feldman <[email protected]>
The entry is touched once when created, and touched again for each update. The touched time is used to calculate FDB entry age.
--- drivers/net/ethernet/rocker/rocker.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/net/ethernet/rocker/rocker.c +12 -6
@@ -152,6 +152,7 @@ struct rocker_fdb_tbl_entry {struct hlist_node entry;u32 key_crc32;/* key */ bool learned; +unsigned long touched;struct rocker_fdb_tbl_key {u32 pport;u8 addr[ETH_ALEN ];
@@ -3629,6 +3630,7 @@ static int rocker_port_fdb(struct rocker_port *rocker_port,return -ENOMEM ; fdb->learned = (flags &ROCKER_OP_FLAG_LEARNED ); + fdb->touched = jiffies; fdb->key.pport = rocker_port->pport;ether_addr_copy (fdb->key.addr, addr); fdb->key.vlan_id = vlan_id;
@@ -3638,13 +3640,17 @@ static int rocker_port_fdb(struct rocker_port *rocker_port, found =rocker_fdb_tbl_find (rocker, fdb); -if (removing && found) { -rocker_port_kfree (trans, fdb); -if (trans !=SWITCHDEV_TRANS_PREPARE ) -hash_del (&found->entry); - }else if (!removing && !found) { +if (found) { + found->touched = jiffies; +if (removing) { +rocker_port_kfree (trans, fdb); +if (trans !=SWITCHDEV_TRANS_PREPARE ) +hash_del (&found->entry); + } + }else if (!removing) {if (trans !=SWITCHDEV_TRANS_PREPARE ) -hash_add (rocker->fdb_tbl, &fdb->entry, fdb->key_crc32); +hash_add (rocker->fdb_tbl, &fdb->entry, + fdb->key_crc32); }spin_unlock_irqrestore (&rocker->fdb_tbl_lock, lock_flags);
Signature · 1 line
1.7.10.4
PATCH v3 2/7 rocker: store rocker_port in fdb key rather than pport
In reply to [email protected]From: Scott Feldman <[email protected]>
We'll need more info from rocker_port than just pport when we age out fdb entries, so store rocker_port rather than pport in each fdb entry.
--- drivers/net/ethernet/rocker/rocker.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/rocker/rocker.c +4 -4
@@ -154,7 +154,7 @@ struct rocker_fdb_tbl_entry {bool learned;unsigned long touched;struct rocker_fdb_tbl_key { -u32 pport; +struct rocker_port *rocker_port;u8 addr[ETH_ALEN ];__be16 vlan_id; } key;
@@ -3631,7 +3631,7 @@ static int rocker_port_fdb(struct rocker_port *rocker_port, fdb->learned = (flags &ROCKER_OP_FLAG_LEARNED ); fdb->touched = jiffies; - fdb->key.pport = rocker_port->pport; + fdb->key.rocker_port = rocker_port;ether_addr_copy (fdb->key.addr, addr); fdb->key.vlan_id = vlan_id; fdb->key_crc32 =crc32 (~0 , &fdb->key,sizeof (fdb->key));
@@ -3686,7 +3686,7 @@ static int rocker_port_fdb_flush(struct rocker_port *rocker_port,spin_lock_irqsave (&rocker->fdb_tbl_lock, lock_flags);hash_for_each_safe (rocker->fdb_tbl, bkt, tmp, found, entry) { -if (found->key.pport != rocker_port->pport) +if (found->key.rocker_port != rocker_port)continue ;if (!found->learned)continue ;
@@ -4553,7 +4553,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,spin_lock_irqsave (&rocker->fdb_tbl_lock, lock_flags);hash_for_each_safe (rocker->fdb_tbl, bkt, tmp, found, entry) { -if (found->key.pport != rocker_port->pport) +if (found->key.rocker_port != rocker_port)continue ; fdb->addr = found->key.addr; fdb->ndm_state =NUD_REACHABLE ;
Signature · 1 line
1.7.10.4
PATCH v3 3/7 bridge: define some min/max/default ageing time constants
In reply to [email protected]From: Scott Feldman <[email protected]>
---
v2: Per Jiri review comment: add BR_DEFAULT_AGEING_TIME to defines
include/linux/if_bridge.h | 6 ++++++ net/bridge/br_device.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/if_bridge.h +6 -0
@@ -46,6 +46,12 @@ struct br_ip_list {#define BR_LEARNING_SYNC BIT(9)#define BR_PROXYARP_WIFI BIT(10) +/* values as per ieee8021QBridgeFdbAgingTime */ +#define BR_MIN_AGEING_TIME (10 * HZ) +#define BR_MAX_AGEING_TIME (1000000 * HZ) + +#define BR_DEFAULT_AGEING_TIME (300 * HZ) +extern void brioctl_set (int (*ioctl_hook)(struct net *,unsigned int ,void __user *));typedef int br_should_route_hook_t (struct sk_buff *skb);
net/bridge/br_device.c +1 -1
@@ -391,7 +391,7 @@ void br_dev_setup(struct net_device *dev) br->bridge_max_age = br->max_age =20 *HZ ; br->bridge_hello_time = br->hello_time =2 *HZ ; br->bridge_forward_delay = br->forward_delay =15 *HZ ; - br->ageing_time =300 *HZ ; + br->ageing_time =BR_DEFAULT_AGEING_TIME ;br_netfilter_rtable_init (br);br_stp_timer_init (br);
Signature · 1 line
1.7.10.4
Re: [PATCH net-next v3 3/7] bridge: define some min/max/default ageing time constants
Quoted 3 lines · Wed, Sep 23, 2015 at 05:39:16PM CEST, [email protected] wrote:
From: Scott Feldman <[email protected]>
Signed-off-by Scott Feldman <[email protected]>
PATCH v3 4/7 rocker: adding port ageing_time for ageing out FDB entries
In reply to [email protected]From: Scott Feldman <[email protected]>
Follow-up patcheset will allow user to change ageing_time, but for now just hard-code it to a fixed value (the same value used as the default for the bridge driver).
--- drivers/net/ethernet/rocker/rocker.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/rocker/rocker.c +2 -0
@@ -221,6 +221,7 @@ struct rocker_port {__be16 internal_vlan_id;int stp_state;u32 brport_flags; +unsigned long ageing_time;bool ctrls[ROCKER_CTRL_MAX ];unsigned long vlan_bitmap[ROCKER_VLAN_BITMAP_LEN ];struct napi_struct napi_tx;
@@ -4975,6 +4976,7 @@ static int rocker_probe_port(struct rocker *rocker, unsigned int port_number) rocker_port->port_number = port_number; rocker_port->pport = port_number +1 ; rocker_port->brport_flags =BR_LEARNING |BR_LEARNING_SYNC ; + rocker_port->ageing_time =BR_DEFAULT_AGEING_TIME ;INIT_LIST_HEAD (&rocker_port->trans_mem);rocker_port_dev_addr_init (rocker_port);
Signature · 1 line
1.7.10.4
Re: [PATCH net-next v3 4/7] rocker: adding port ageing_time for ageing out FDB entries
Quoted 7 lines · Wed, Sep 23, 2015 at 05:39:17PM CEST, [email protected] wrote:
From: Scott Feldman <[email protected]>
Follow-up patcheset will allow user to change
ageing_time, but for now just hard-code it to a fixed value (the same value used as the default for the bridge driver).Signed-off-by Scott Feldman <[email protected]>
PATCH v3 5/7 rocker: add FDB cleanup timer
In reply to [email protected]From: Scott Feldman <[email protected]>
Add a timer to each rocker switch to do FDB entry cleanup by ageing out expired entries. The timer scheduling algo is copied from the bridge driver, for the most part, to keep the firing of the timer to a minimum.
---
v3: Per davem review: add del_timer_sync on rocker port remove.
drivers/net/ethernet/rocker/rocker.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
drivers/net/ethernet/rocker/rocker.c +42 -0
@@ -248,6 +248,7 @@ struct rocker {u64 flow_tbl_next_cookie;DECLARE_HASHTABLE (group_tbl,16 );spinlock_t group_tbl_lock;/* for group tbl accesses */ +struct timer_list fdb_cleanup_timer;DECLARE_HASHTABLE (fdb_tbl,16 );spinlock_t fdb_tbl_lock;/* for fdb tbl accesses */ unsigned long internal_vlan_bitmap[ROCKER_INTERNAL_VLAN_BITMAP_LEN ];
@@ -3706,6 +3707,41 @@ err_out:return err; } +static void rocker_fdb_cleanup (unsigned long data) +{ +struct rocker *rocker = (struct rocker *)data; +struct rocker_port *rocker_port; +struct rocker_fdb_tbl_entry *entry; +struct hlist_node *tmp; +unsigned long next_timer = jiffies +BR_MIN_AGEING_TIME ; +unsigned long expires; +unsigned long lock_flags; +int flags =ROCKER_OP_FLAG_NOWAIT |ROCKER_OP_FLAG_REMOVE | +ROCKER_OP_FLAG_LEARNED ; +int bkt; + +spin_lock_irqsave (&rocker->fdb_tbl_lock, lock_flags); + +hash_for_each_safe (rocker->fdb_tbl, bkt, tmp, entry, entry) { +if (!entry->learned) +continue ; + rocker_port = entry->key.rocker_port; + expires = entry->touched + rocker_port->ageing_time; +if (time_before_eq (expires, jiffies)) { +rocker_port_fdb_learn (rocker_port,SWITCHDEV_TRANS_NONE , + flags, entry->key.addr, + entry->key.vlan_id); +hash_del (&entry->entry); + }else if (time_before (expires, next_timer)) { + next_timer = expires; + } + } + +spin_unlock_irqrestore (&rocker->fdb_tbl_lock, lock_flags); + +mod_timer (&rocker->fdb_cleanup_timer,round_jiffies_up (next_timer)); +} +static int rocker_port_router_mac (struct rocker_port *rocker_port,enum switchdev_trans trans,int flags,__be16 vlan_id)
@@ -5191,6 +5227,10 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err_init_tbls; } +setup_timer (&rocker->fdb_cleanup_timer, rocker_fdb_cleanup, + (unsigned long ) rocker); +mod_timer (&rocker->fdb_cleanup_timer, jiffies); + err =rocker_probe_ports (rocker);if (err) {dev_err (&pdev->dev,"failed to probe ports\n" );
@@ -5203,6 +5243,7 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)return 0 ; err_probe_ports: +del_timer_sync (&rocker->fdb_cleanup_timer);rocker_free_tbls (rocker); err_init_tbls:free_irq (rocker_msix_vector (rocker,ROCKER_MSIX_VEC_EVENT ), rocker);
@@ -5230,6 +5271,7 @@ static void rocker_remove(struct pci_dev *pdev) {struct rocker *rocker =pci_get_drvdata (pdev); +del_timer_sync (&rocker->fdb_cleanup_timer);rocker_free_tbls (rocker);rocker_write32 (rocker,CONTROL ,ROCKER_CONTROL_RESET );rocker_remove_ports (rocker);
Signature · 1 line
1.7.10.4
PATCH v3 6/7 bridge: don't age externally added FDB entries
In reply to [email protected]From: Siva Mannem <[email protected]>
--- net/bridge/br_fdb.c | 2 ++ 1 file changed, 2 insertions(+)
net/bridge/br_fdb.c +2 -0
@@ -299,6 +299,8 @@ void br_fdb_cleanup(unsigned long _data)unsigned long this_timer;if (f->is_static)continue ; +if (f->added_by_external_learn) +continue ; this_timer = f->updated + delay;if (time_before_eq (this_timer, jiffies))fdb_delete (br, f);
Signature · 1 line
1.7.10.4
PATCH v3 7/7 switchdev: update documentation on FDB ageing_time
In reply to [email protected]From: Scott Feldman <[email protected]>
--- Documentation/networking/switchdev.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Documentation/networking/switchdev.txt +12 -12
@@ -239,20 +239,20 @@ The driver should initialize the attributes to the hardware defaults. FDB Ageing ^^^^^^^^^^ -There are two FDB ageing models supported: 1) ageing by the device, and 2) -ageing by the kernel. Ageing by the device is preferred if many FDB entries -are supported. The driver calls call_switchdev_notifiers(SWITCHDEV_FDB_DEL, -...) to age out the FDB entry. In this model, ageing by the kernel should be -turned off. XXX: how to turn off ageing in kernel on a per-port basis or -otherwise prevent the kernel from ageing out the FDB entry? - -In the kernel ageing model, the standard bridge ageing mechanism is used to age -out stale FDB entries. To keep an FDB entry "alive", the driver should refresh -the FDB entry by calling call_switchdev_notifiers(SWITCHDEV_FDB_ADD, ...). The +The bridge will skip ageing FDB entries marked with NTF_EXT_LEARNED and it is +the responsibility of the port driver/device to age out these entries. If the +port device supports ageing, when the FDB entry expires, it will notify the +driver which in turn will notify the bridge with SWITCHDEV_FDB_DEL. If the +device does not support ageing, the driver can simulate ageing using a +garbage collection timer to monitor FBD entries. Expired entries will be +notified to the bridge using SWITCHDEV_FDB_DEL. See rocker driver for +example of driver running ageing timer. + +To keep an NTF_EXT_LEARNED entry "alive", the driver should refresh the FDB +entry by calling call_switchdev_notifiers(SWITCHDEV_FDB_ADD, ...). The notification will reset the FDB entry's last-used time to now. The driver should rate limit refresh notifications, for example, no more than once a -second. If the FDB entry expires, fdb_delete is called to remove entry from -the device. +second. (The last-used time is visible using the bridge -s fdb option). STP State Change on Port ^^^^^^^^^^^^^^^^^^^^^^^^
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: [email protected]
Date: Wed, 23 Sep 2015 08:39:13 -0700
Quoted 11 lines
From: Scott Feldman <[email protected]>
v3: Per davem review: add
del_timer_syncon rocker port remove.v2: Per Jiri review comment: add
BR_DEFAULT_AGEING_TIMEto definesSiva originally proposed skipping externally added FDB entries in the bridge's FDB garbage collection func, and moving the ageing of externally added entries to the port driver/device. This broke rocker, since rocker didn't have a hardware (or software) mechanism for ageing out its learned FDB entries.
Quoted 8 lines
This patchset reintroduces Siva's bridge driver patch to skip externally added entries and adds support in rocker so rocker can age out its own entries. Rocker does this using a software timer similar to the bridge's FDB garbage collection timer. Other switchdev devices/drivers can use this software timer method or program the device to nofity aged-out entries to the driver.
Updated switchdev.txt documentation to reflect current state-of-the-art. This removes one more XXX todo comment in switchdev.txt.
Series applied, thanks Scott.