]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: dsa: centralize fast ageing when address learning is turned off
authorVladimir Oltean <vladimir.oltean@nxp.com>
Sun, 8 Aug 2021 14:35:23 +0000 (17:35 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 8 Aug 2021 19:56:51 +0000 (20:56 +0100)
Currently DSA leaves it down to device drivers to fast age the FDB on a
port when address learning is disabled on it. There are 2 reasons for
doing that in the first place:

- when address learning is disabled by user space, through
  IFLA_BRPORT_LEARNING or the brport_attr_learning sysfs, what user
  space typically wants to achieve is to operate in a mode with no
  dynamic FDB entry on that port. But if the port is already up, some
  addresses might have been already learned on it, and it seems silly to
  wait for 5 minutes for them to expire until something useful can be
  done.

- when a port leaves a bridge and becomes standalone, DSA turns off
  address learning on it. This also has the nice side effect of flushing
  the dynamically learned bridge FDB entries on it, which is a good idea
  because standalone ports should not have bridge FDB entries on them.

We let drivers manage fast ageing under this condition because if DSA
were to do it, it would need to track each port's learning state, and
act upon the transition, which it currently doesn't.

But there are 2 reasons why doing it is better after all:

- drivers might get it wrong and not do it (see b53_port_set_learning)

- we would like to flush the dynamic entries from the software bridge
  too, and letting drivers do that would be another pain point

So track the port learning state and trigger a fast age process
automatically within DSA.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx/chip.c
include/net/dsa.h
net/dsa/dsa_priv.h
net/dsa/port.c

index c2c5f1573fe5d974c8fc68a8bc587844f34af205..c45ca2473743886f29cc9dad927c99173dd9523d 100644 (file)
@@ -5797,7 +5797,6 @@ static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
                                       struct netlink_ext_ack *extack)
 {
        struct mv88e6xxx_chip *chip = ds->priv;
-       bool do_fast_age = false;
        int err = -EOPNOTSUPP;
 
        mv88e6xxx_reg_lock(chip);
@@ -5809,9 +5808,6 @@ static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
                err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
                if (err)
                        goto out;
-
-               if (!learning)
-                       do_fast_age = true;
        }
 
        if (flags.mask & BR_FLOOD) {
@@ -5843,9 +5839,6 @@ static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
 out:
        mv88e6xxx_reg_unlock(chip);
 
-       if (do_fast_age)
-               mv88e6xxx_port_fast_age(ds, port);
-
        return err;
 }
 
index d7dc26d316ea421059f66eafa31581b81009e50d..995e9d3f9cfc9c9135f2b4fcec6ba3effce9b6ed 100644 (file)
@@ -254,6 +254,7 @@ struct dsa_port {
        struct device_node      *dn;
        unsigned int            ageing_time;
        bool                    vlan_filtering;
+       bool                    learning;
        u8                      stp_state;
        struct net_device       *bridge_dev;
        int                     bridge_num;
index 8dad40b2cf5c9e1b711ef731a64e6bdcffe8d58f..9575cabd3ec348249edd12e19ad581edea59188c 100644 (file)
@@ -241,7 +241,7 @@ int dsa_port_host_mdb_del(const struct dsa_port *dp,
 int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
                              struct switchdev_brport_flags flags,
                              struct netlink_ext_ack *extack);
-int dsa_port_bridge_flags(const struct dsa_port *dp,
+int dsa_port_bridge_flags(struct dsa_port *dp,
                          struct switchdev_brport_flags flags,
                          struct netlink_ext_ack *extack);
 int dsa_port_vlan_add(struct dsa_port *dp,
index ef5e08b09bb744e379610a77d1aecac27fa9b626..d6a35a03acd61cf0e2180568a08ac4a973d195ea 100644 (file)
@@ -30,6 +30,16 @@ static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v)
        return dsa_tree_notify(dp->ds->dst, e, v);
 }
 
+static void dsa_port_fast_age(const struct dsa_port *dp)
+{
+       struct dsa_switch *ds = dp->ds;
+
+       if (!ds->ops->port_fast_age)
+               return;
+
+       ds->ops->port_fast_age(ds, dp->index);
+}
+
 int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age)
 {
        struct dsa_switch *ds = dp->ds;
@@ -40,7 +50,7 @@ int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age)
 
        ds->ops->port_stp_state_set(ds, port, state);
 
-       if (do_fast_age && ds->ops->port_fast_age) {
+       if (do_fast_age) {
                /* Fast age FDB entries or flush appropriate forwarding database
                 * for the given port, if we are moving it from Learning or
                 * Forwarding state, to Disabled or Blocking or Listening state.
@@ -54,7 +64,7 @@ int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age)
                    (state == BR_STATE_DISABLED ||
                     state == BR_STATE_BLOCKING ||
                     state == BR_STATE_LISTENING))
-                       ds->ops->port_fast_age(ds, port);
+                       dsa_port_fast_age(dp);
        }
 
        dp->stp_state = state;
@@ -633,16 +643,33 @@ int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
        return ds->ops->port_pre_bridge_flags(ds, dp->index, flags, extack);
 }
 
-int dsa_port_bridge_flags(const struct dsa_port *dp,
+int dsa_port_bridge_flags(struct dsa_port *dp,
                          struct switchdev_brport_flags flags,
                          struct netlink_ext_ack *extack)
 {
        struct dsa_switch *ds = dp->ds;
+       int err;
 
        if (!ds->ops->port_bridge_flags)
                return -EOPNOTSUPP;
 
-       return ds->ops->port_bridge_flags(ds, dp->index, flags, extack);
+       err = ds->ops->port_bridge_flags(ds, dp->index, flags, extack);
+       if (err)
+               return err;
+
+       if (flags.mask & BR_LEARNING) {
+               bool learning = flags.val & BR_LEARNING;
+
+               if (learning == dp->learning)
+                       return 0;
+
+               if (dp->learning && !learning)
+                       dsa_port_fast_age(dp);
+
+               dp->learning = learning;
+       }
+
+       return 0;
 }
 
 int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu,