Skip to content

Commit 7569459

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: manage flooding on the CPU ports
DSA can treat IFF_PROMISC and IFF_ALLMULTI on standalone user ports as signifying whether packets with an unknown MAC DA will be received or not. Since known MAC DAs are handled by FDB/MDB entries, this means that promiscuity is analogous to including/excluding the CPU port from the flood domain of those packets. There are two ways to signal CPU flooding to drivers. The first (chosen here) is to synthesize a call to ds->ops->port_bridge_flags() for the CPU port, with a mask of BR_FLOOD | BR_MCAST_FLOOD. This has the effect of turning on egress flooding on the CPU port regardless of source. The alternative would be to create a new ds->ops->port_host_flood() which is called per user port. Some switches (sja1105) have a flood domain that is managed per {ingress port, egress port} pair, so it would make more sense for this kind of switch to not flood the CPU from port A if just port B requires it. Nonetheless, the sja1105 has other quirks that prevent it from making use of unicast filtering, and without a concrete user making use of this feature, I chose not to implement it. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 499aa9e commit 7569459

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

net/dsa/slave.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,55 @@ static int dsa_slave_close(struct net_device *dev)
229229
return 0;
230230
}
231231

232+
/* Keep flooding enabled towards this port's CPU port as long as it serves at
233+
* least one port in the tree that requires it.
234+
*/
235+
static void dsa_port_manage_cpu_flood(struct dsa_port *dp)
236+
{
237+
struct switchdev_brport_flags flags = {
238+
.mask = BR_FLOOD | BR_MCAST_FLOOD,
239+
};
240+
struct dsa_switch_tree *dst = dp->ds->dst;
241+
struct dsa_port *cpu_dp = dp->cpu_dp;
242+
struct dsa_port *other_dp;
243+
int err;
244+
245+
list_for_each_entry(other_dp, &dst->ports, list) {
246+
if (!dsa_port_is_user(other_dp))
247+
continue;
248+
249+
if (other_dp->cpu_dp != cpu_dp)
250+
continue;
251+
252+
if (other_dp->slave->flags & IFF_ALLMULTI)
253+
flags.val |= BR_MCAST_FLOOD;
254+
if (other_dp->slave->flags & IFF_PROMISC)
255+
flags.val |= BR_FLOOD;
256+
}
257+
258+
err = dsa_port_pre_bridge_flags(dp, flags, NULL);
259+
if (err)
260+
return;
261+
262+
dsa_port_bridge_flags(cpu_dp, flags, NULL);
263+
}
264+
232265
static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
233266
{
234267
struct net_device *master = dsa_slave_to_master(dev);
268+
struct dsa_port *dp = dsa_slave_to_port(dev);
269+
struct dsa_switch *ds = dp->ds;
235270

236271
if (change & IFF_ALLMULTI)
237272
dev_set_allmulti(master,
238273
dev->flags & IFF_ALLMULTI ? 1 : -1);
239274
if (change & IFF_PROMISC)
240275
dev_set_promiscuity(master,
241276
dev->flags & IFF_PROMISC ? 1 : -1);
277+
278+
if (dsa_switch_supports_uc_filtering(ds) &&
279+
dsa_switch_supports_mc_filtering(ds))
280+
dsa_port_manage_cpu_flood(dp);
242281
}
243282

244283
static void dsa_slave_set_rx_mode(struct net_device *dev)

0 commit comments

Comments
 (0)