]> err.no Git - linux-2.6/commitdiff
bridge: add sysfs hook to flush forwarding table
authorStephen Hemminger <shemminger@linux-foundation.org>
Mon, 9 Apr 2007 19:57:54 +0000 (12:57 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 26 Apr 2007 05:28:47 +0000 (22:28 -0700)
The RSTP daemon needs to be able to flush all dynamic forwarding
entries in the case of topology change.

This is a temporary interface. It will change to a netlink interface
before RSTP daemon is officially released.

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
net/bridge/br_fdb.c
net/bridge/br_private.h
net/bridge/br_sysfs_br.c
net/bridge/br_sysfs_if.c

index dd5a5d5fb280537f59cd7a0f5c29db18aae32659..22645e3edf2343decc265749a5a68f311a6365cd 100644 (file)
@@ -135,7 +135,26 @@ void br_fdb_cleanup(unsigned long _data)
        mod_timer(&br->gc_timer, jiffies + HZ/10);
 }
 
+/* Completely flush all dynamic entries in forwarding database.*/
+void br_fdb_flush(struct net_bridge *br)
+{
+       int i;
 
+       spin_lock_bh(&br->hash_lock);
+       for (i = 0; i < BR_HASH_SIZE; i++) {
+               struct net_bridge_fdb_entry *f;
+               struct hlist_node *h, *n;
+               hlist_for_each_entry_safe(f, h, n, &br->hash[i], hlist) {
+                       if (!f->is_static)
+                               fdb_delete(f);
+               }
+       }
+       spin_unlock_bh(&br->hash_lock);
+}
+
+/* Flush all entries refering to a specific port.
+ * if do_all is set also flush static entries
+ */
 void br_fdb_delete_by_port(struct net_bridge *br,
                           const struct net_bridge_port *p,
                           int do_all)
index fab8ce0ce88d4db66da3bb3cb4b23052f428c17a..3adacdf3406f9285981e15f7a29413091df87489 100644 (file)
@@ -135,6 +135,7 @@ extern int br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
 /* br_fdb.c */
 extern void br_fdb_init(void);
 extern void br_fdb_fini(void);
+extern void br_fdb_flush(struct net_bridge *br);
 extern void br_fdb_changeaddr(struct net_bridge_port *p,
                              const unsigned char *newaddr);
 extern void br_fdb_cleanup(unsigned long arg);
index 01a22ad0cc7591b037c4f6108f6aab311f13618e..6cc5cfe665cd4eba53dabc269f519045aecdcb1b 100644 (file)
@@ -309,6 +309,19 @@ static ssize_t store_group_addr(struct device *d,
 static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR,
                   show_group_addr, store_group_addr);
 
+static ssize_t store_flush(struct device *d,
+                          struct device_attribute *attr,
+                          const char *buf, size_t len)
+{
+       struct net_bridge *br = to_bridge(d);
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       br_fdb_flush(br);
+       return len;
+}
+static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush);
 
 static struct attribute *bridge_attrs[] = {
        &dev_attr_forward_delay.attr,
@@ -328,6 +341,7 @@ static struct attribute *bridge_attrs[] = {
        &dev_attr_topology_change_timer.attr,
        &dev_attr_gc_timer.attr,
        &dev_attr_group_addr.attr,
+       &dev_attr_flush.attr,
        NULL
 };
 
index 0bc2aef8f9f3aa95332f12829ba8962bec29923e..2da22927d8dd158ea341fe53d896dc1f53ea52b6 100644 (file)
@@ -137,6 +137,13 @@ static ssize_t show_hold_timer(struct net_bridge_port *p,
 }
 static BRPORT_ATTR(hold_timer, S_IRUGO, show_hold_timer, NULL);
 
+static ssize_t store_flush(struct net_bridge_port *p, unsigned long v)
+{
+       br_fdb_delete_by_port(p->br, p, 0); // Don't delete local entry
+       return 0;
+}
+static BRPORT_ATTR(flush, S_IWUSR, NULL, store_flush);
+
 static struct brport_attribute *brport_attrs[] = {
        &brport_attr_path_cost,
        &brport_attr_priority,
@@ -152,6 +159,7 @@ static struct brport_attribute *brport_attrs[] = {
        &brport_attr_message_age_timer,
        &brport_attr_forward_delay_timer,
        &brport_attr_hold_timer,
+       &brport_attr_flush,
        NULL
 };