diff mbox series

[net-next,5/6] net: dsa: monitor changes to bridge promiscuity

Message ID 20220408200337.718067-6-vladimir.oltean@nxp.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Disable host flooding for DSA ports under a bridge | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 19 this patch: 19
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 17 this patch: 17
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 19 this patch: 19
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 97 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Vladimir Oltean April 8, 2022, 8:03 p.m. UTC
In preparation of changing the bridge such that it stops managing the
IFF_PROMISC flag on offloaded bridge ports, we need to ensure that DSA
preserves behavior in the circumstances that matter.

The bridge software data path implementation (br_handle_frame_finish)
passes a unicast frame up if a BR_FDB_LOCAL entry exists, or if the MAC
DA is unknown, if local_rcv is true. In turn, local_rcv is true when
the bridge device itself is promiscuous.

The analogous behavior in the offloaded plane is to enable flooding of
packets with unknown destination towards the CPU when the bridge device
itself is promiscuous. This change achieves that by monitoring
IFF_PROMISC changes on bridge devices, and calling
dsa_bridge_host_flood_change -> dsa_port_manage_cpu_flood on such changes.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 include/net/dsa.h  |  1 +
 net/dsa/dsa_priv.h |  1 +
 net/dsa/port.c     |  5 +++++
 net/dsa/slave.c    | 43 ++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 45 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 0ea45a4acc80..e8e30be4cde8 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -243,6 +243,7 @@  struct dsa_bridge {
 	refcount_t refcount;
 	u8 tx_fwd_offload:1;
 	u8 have_foreign:1;
+	u8 promisc:1;
 };
 
 struct dsa_port {
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index d610776ecd76..9b868a7c3459 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -321,6 +321,7 @@  int dsa_slave_change_mtu(struct net_device *dev, int new_mtu);
 int dsa_slave_manage_vlan_filtering(struct net_device *dev,
 				    bool vlan_filtering);
 int dsa_bridge_foreign_dev_update(struct net_device *bridge_dev);
+int dsa_bridge_promisc_update(struct net_device *bridge_dev);
 
 static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
 {
diff --git a/net/dsa/port.c b/net/dsa/port.c
index cbee564e1c22..bbcc9c92af5f 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -660,8 +660,13 @@  int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
 	if (err)
 		goto err_foreign_update;
 
+	err = dsa_bridge_promisc_update(bridge_dev);
+	if (err)
+		goto err_promisc_update;
+
 	return 0;
 
+err_promisc_update:
 err_foreign_update:
 	dsa_port_pre_bridge_leave(dp, bridge_dev);
 	dsa_port_bridge_leave(dp, bridge_dev);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 1bc8d830fb46..59ebc4a520e7 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2753,6 +2753,13 @@  static int dsa_slave_netdevice_event(struct notifier_block *nb,
 	}
 	case NETDEV_CHANGE:
 	case NETDEV_UP: {
+		int err;
+
+		if (netif_is_bridge_master(dev)) {
+			err = dsa_bridge_promisc_update(dev);
+			return notifier_from_errno(err);
+		}
+
 		/* Track state of master port.
 		 * DSA driver may require the master port (and indirectly
 		 * the tagger) to be available for some special operation.
@@ -2891,13 +2898,13 @@  static bool dsa_foreign_dev_check(const struct net_device *dev,
 }
 
 /* We need to keep flooding towards the CPU enabled as long as software
- * forwarding is required.
+ * forwarding is required, or the bridge device is promiscuous.
  */
 static void dsa_bridge_host_flood_change(struct dsa_bridge *bridge,
-					 bool have_foreign)
+					 bool have_foreign, bool promisc)
 {
-	bool host_flood_was_enabled = bridge->have_foreign;
-	bool host_flood_enabled = have_foreign;
+	bool host_flood_was_enabled = bridge->have_foreign || bridge->promisc;
+	bool host_flood_enabled = have_foreign || promisc;
 	int inc = host_flood_enabled ? 1 : -1;
 	struct net_device *brport_dev;
 	struct dsa_switch_tree *dst;
@@ -2917,6 +2924,7 @@  static void dsa_bridge_host_flood_change(struct dsa_bridge *bridge,
 
 out:
 	bridge->have_foreign = have_foreign;
+	bridge->promisc = promisc;
 }
 
 int dsa_bridge_foreign_dev_update(struct net_device *bridge_dev)
@@ -2949,7 +2957,32 @@  int dsa_bridge_foreign_dev_update(struct net_device *bridge_dev)
 		}
 	}
 
-	dsa_bridge_host_flood_change(bridge, have_foreign);
+	dsa_bridge_host_flood_change(bridge, have_foreign, bridge->promisc);
+
+	return 0;
+}
+
+int dsa_bridge_promisc_update(struct net_device *bridge_dev)
+{
+	struct dsa_bridge *bridge = NULL;
+	struct dsa_switch_tree *dst;
+	struct dsa_port *dp;
+
+	list_for_each_entry(dst, &dsa_tree_list, list) {
+		dsa_tree_for_each_user_port(dp, dst) {
+			if (dsa_port_offloads_bridge_dev(dp, bridge_dev)) {
+				bridge = dp->bridge;
+				break;
+			}
+		}
+	}
+
+	/* Bridge with no DSA interface in it */
+	if (!bridge)
+		return 0;
+
+	dsa_bridge_host_flood_change(bridge, bridge->have_foreign,
+				     bridge_dev->flags & IFF_PROMISC);
 
 	return 0;
 }