OSDN Git Service

mlxsw: spectrum_router: Add a helper to check if netdev has addresses
authorPetr Machata <petrm@nvidia.com>
Mon, 12 Jun 2023 15:31:07 +0000 (17:31 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Wed, 14 Jun 2023 11:12:20 +0000 (13:12 +0200)
This function will be useful later as the driver will need to retroactively
create RIFs for new uppers with addresses.

Add another helper that assumes RCU lock, and restructure the code to
skip the IPv6 branch not through conditioning on the addr_list_empty
variable, but by directly returning the result value. This makes the skip
more obvious than it previously was.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

index 1e05ecd..25dbdda 100644 (file)
@@ -7794,28 +7794,44 @@ static void mlxsw_sp_router_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
        mlxsw_sp_neigh_rif_gone_sync(mlxsw_sp, rif);
 }
 
+static bool __mlxsw_sp_dev_addr_list_empty(const struct net_device *dev)
+{
+       struct inet6_dev *inet6_dev;
+       struct in_device *idev;
+
+       idev = __in_dev_get_rcu(dev);
+       if (idev && idev->ifa_list)
+               return false;
+
+       inet6_dev = __in6_dev_get(dev);
+       if (inet6_dev && !list_empty(&inet6_dev->addr_list))
+               return false;
+
+       return true;
+}
+
+static bool mlxsw_sp_dev_addr_list_empty(const struct net_device *dev)
+{
+       bool addr_list_empty;
+
+       rcu_read_lock();
+       addr_list_empty = __mlxsw_sp_dev_addr_list_empty(dev);
+       rcu_read_unlock();
+
+       return addr_list_empty;
+}
+
 static bool
 mlxsw_sp_rif_should_config(struct mlxsw_sp_rif *rif, struct net_device *dev,
                           unsigned long event)
 {
-       struct inet6_dev *inet6_dev;
-       bool addr_list_empty = true;
-       struct in_device *idev;
+       bool addr_list_empty;
 
        switch (event) {
        case NETDEV_UP:
                return rif == NULL;
        case NETDEV_DOWN:
-               rcu_read_lock();
-               idev = __in_dev_get_rcu(dev);
-               if (idev && idev->ifa_list)
-                       addr_list_empty = false;
-
-               inet6_dev = __in6_dev_get(dev);
-               if (addr_list_empty && inet6_dev &&
-                   !list_empty(&inet6_dev->addr_list))
-                       addr_list_empty = false;
-               rcu_read_unlock();
+               addr_list_empty = mlxsw_sp_dev_addr_list_empty(dev);
 
                /* macvlans do not have a RIF, but rather piggy back on the
                 * RIF of their lower device.