In order for bridge port members to get a chance to implement unicast
and multicast address filtering correctly, which would matter for e.g:
switch network devices, synchronize the UC and MC lists down to the
individual bridge port members using switchdev HOST_MDB objects such
that this does not impact drivers that already have a ndo_set_rx_mode()
operation which likely already operate in promiscuous mode.

When the bridge has multicast snooping enabled, proper HOST_MDB
notifications will be sent through br_mdb_notify() already.

Signed-off-by: Florian Fainelli <f.faine...@gmail.com>
---
 net/bridge/br_device.c | 55 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 013323b6dbe4..ce10d6b7b151 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -18,6 +18,7 @@
 #include <linux/ethtool.h>
 #include <linux/list.h>
 #include <linux/netfilter_bridge.h>
+#include <net/switchdev.h>
 
 #include <linux/uaccess.h>
 #include "br_private.h"
@@ -182,8 +183,62 @@ static int br_dev_open(struct net_device *dev)
        return 0;
 }
 
+static int bridge_sync_unsync_mc_addr(struct net_device *dev,
+                                     const unsigned char *addr,
+                                     bool add)
+{
+       struct net_bridge *br = netdev_priv(dev);
+       struct switchdev_obj_port_mdb mdb = {
+               .obj = {
+                       .orig_dev = dev,
+                       .id = SWITCHDEV_OBJ_ID_HOST_MDB,
+                       .flags = SWITCHDEV_F_DEFER,
+               },
+               .vid = 0,
+       };
+       struct net_bridge_port *p;
+       int ret = -EOPNOTSUPP;
+
+#ifdef CONFIG_BRIDGE_VLAN_FILTERING
+       if (br_vlan_enabled(dev))
+               mdb.vid = br->default_pvid;
+#endif
+
+       ether_addr_copy(mdb.addr, addr);
+       spin_lock_bh(&br->lock);
+       list_for_each_entry(p, &br->port_list, list) {
+               if (add)
+                       ret = switchdev_port_obj_add(p->dev, &mdb.obj, NULL);
+               else
+                       ret = switchdev_port_obj_del(p->dev, &mdb.obj);
+               if (ret)
+                       goto out;
+       }
+out:
+       spin_unlock_bh(&br->lock);
+       return ret;
+}
+
+static int bridge_sync_mc_addr(struct net_device *dev,
+                              const unsigned char *addr)
+{
+       return bridge_sync_unsync_mc_addr(dev, addr, true);
+}
+
+static int bridge_unsync_mc_addr(struct net_device *dev,
+                                const unsigned char *addr)
+{
+       return bridge_sync_unsync_mc_addr(dev, addr, false);
+}
+
 static void br_dev_set_multicast_list(struct net_device *dev)
 {
+       /* HOST_MDB notifications are sent through MDB notifications */
+       if (br_multicast_enabled(dev))
+               return;
+
+       __hw_addr_sync_dev(&dev->mc, dev, bridge_sync_mc_addr,
+                          bridge_unsync_mc_addr);
 }
 
 static void br_dev_change_rx_flags(struct net_device *dev, int change)
-- 
2.17.1

Reply via email to