[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220408200337.718067-6-vladimir.oltean@nxp.com>
Date: Fri, 8 Apr 2022 23:03:36 +0300
From: Vladimir Oltean <vladimir.oltean@....com>
To: netdev@...r.kernel.org
Cc: Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Florian Fainelli <f.fainelli@...il.com>,
Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Vladimir Oltean <olteanv@...il.com>,
UNGLinuxDriver@...rochip.com, Paolo Abeni <pabeni@...hat.com>,
Roopa Prabhu <roopa@...dia.com>,
Nikolay Aleksandrov <nikolay@...dia.com>,
Jiri Pirko <jiri@...dia.com>, Ido Schimmel <idosch@...dia.com>,
Tobias Waldekranz <tobias@...dekranz.com>,
Mattias Forsblad <mattias.forsblad@...il.com>
Subject: [PATCH net-next 5/6] net: dsa: monitor changes to bridge promiscuity
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@....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 --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;
}
--
2.25.1
Powered by blists - more mailing lists