]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
net: dsa: add FDB notifier
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Fri, 19 May 2017 21:00:53 +0000 (17:00 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 May 2017 23:37:32 +0000 (19:37 -0400)
Add two new DSA_NOTIFIER_FDB_ADD and DSA_NOTIFIER_FDB_DEL events to
notify not only a single switch, but all switches of a the fabric when
an FDB entry is added or removed.

For the moment, keep the current behavior and ignore other switches.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa_priv.h
net/dsa/port.c
net/dsa/switch.c

index becaf8a61b1361d29ea438dbd334c8c647b1506d..6a7d0d7d0489729ddca0c43c2b36bec2bd7ab792 100644 (file)
@@ -20,6 +20,8 @@ enum {
        DSA_NOTIFIER_AGEING_TIME,
        DSA_NOTIFIER_BRIDGE_JOIN,
        DSA_NOTIFIER_BRIDGE_LEAVE,
+       DSA_NOTIFIER_FDB_ADD,
+       DSA_NOTIFIER_FDB_DEL,
 };
 
 /* DSA_NOTIFIER_AGEING_TIME */
@@ -36,6 +38,14 @@ struct dsa_notifier_bridge_info {
        int port;
 };
 
+/* DSA_NOTIFIER_FDB_* */
+struct dsa_notifier_fdb_info {
+       const struct switchdev_obj_port_fdb *fdb;
+       struct switchdev_trans *trans;
+       int sw_index;
+       int port;
+};
+
 struct dsa_device_ops {
        struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
        struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
index 59328a35394d61690c239bec1e46f6481e949ffd..ed88d838164297a4c792359ba1827a001d67f984 100644 (file)
@@ -151,29 +151,26 @@ int dsa_port_fdb_add(struct dsa_port *dp,
                     const struct switchdev_obj_port_fdb *fdb,
                     struct switchdev_trans *trans)
 {
-       struct dsa_switch *ds = dp->ds;
-
-       if (switchdev_trans_ph_prepare(trans)) {
-               if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
-                       return -EOPNOTSUPP;
-
-               return ds->ops->port_fdb_prepare(ds, dp->index, fdb, trans);
-       }
-
-       ds->ops->port_fdb_add(ds, dp->index, fdb, trans);
+       struct dsa_notifier_fdb_info info = {
+               .sw_index = dp->ds->index,
+               .port = dp->index,
+               .trans = trans,
+               .fdb = fdb,
+       };
 
-       return 0;
+       return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info);
 }
 
 int dsa_port_fdb_del(struct dsa_port *dp,
                     const struct switchdev_obj_port_fdb *fdb)
 {
-       struct dsa_switch *ds = dp->ds;
-
-       if (ds->ops->port_fdb_del)
-               return -EOPNOTSUPP;
+       struct dsa_notifier_fdb_info info = {
+               .sw_index = dp->ds->index,
+               .port = dp->index,
+               .fdb = fdb,
+       };
 
-       return ds->ops->port_fdb_del(ds, dp->index, fdb);
+       return dsa_port_notify(dp, DSA_NOTIFIER_FDB_DEL, &info);
 }
 
 int dsa_port_fdb_dump(struct dsa_port *dp, struct switchdev_obj_port_fdb *fdb,
index 540770ecc8b08c7146b67cfc252e1f35f2080b16..e71cc860d32ccb6e6bed0cb5df4a7f064114b024 100644 (file)
@@ -84,6 +84,43 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds,
        return 0;
 }
 
+static int dsa_switch_fdb_add(struct dsa_switch *ds,
+                             struct dsa_notifier_fdb_info *info)
+{
+       const struct switchdev_obj_port_fdb *fdb = info->fdb;
+       struct switchdev_trans *trans = info->trans;
+
+       /* Do not care yet about other switch chips of the fabric */
+       if (ds->index != info->sw_index)
+               return 0;
+
+       if (switchdev_trans_ph_prepare(trans)) {
+               if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
+                       return -EOPNOTSUPP;
+
+               return ds->ops->port_fdb_prepare(ds, info->port, fdb, trans);
+       }
+
+       ds->ops->port_fdb_add(ds, info->port, fdb, trans);
+
+       return 0;
+}
+
+static int dsa_switch_fdb_del(struct dsa_switch *ds,
+                             struct dsa_notifier_fdb_info *info)
+{
+       const struct switchdev_obj_port_fdb *fdb = info->fdb;
+
+       /* Do not care yet about other switch chips of the fabric */
+       if (ds->index != info->sw_index)
+               return 0;
+
+       if (!ds->ops->port_fdb_del)
+               return -EOPNOTSUPP;
+
+       return ds->ops->port_fdb_del(ds, info->port, fdb);
+}
+
 static int dsa_switch_event(struct notifier_block *nb,
                            unsigned long event, void *info)
 {
@@ -100,6 +137,12 @@ static int dsa_switch_event(struct notifier_block *nb,
        case DSA_NOTIFIER_BRIDGE_LEAVE:
                err = dsa_switch_bridge_leave(ds, info);
                break;
+       case DSA_NOTIFIER_FDB_ADD:
+               err = dsa_switch_fdb_add(ds, info);
+               break;
+       case DSA_NOTIFIER_FDB_DEL:
+               err = dsa_switch_fdb_del(ds, info);
+               break;
        default:
                err = -EOPNOTSUPP;
                break;