Skip to content

Commit 33d11c4

Browse files
pmachataPaolo Abeni
authored andcommitted
mlxsw: spectrum_router: Add a helper to check if netdev has addresses
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 <[email protected]> Reviewed-by: Amit Cohen <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 571c569 commit 33d11c4

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7794,28 +7794,44 @@ static void mlxsw_sp_router_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
77947794
mlxsw_sp_neigh_rif_gone_sync(mlxsw_sp, rif);
77957795
}
77967796

7797+
static bool __mlxsw_sp_dev_addr_list_empty(const struct net_device *dev)
7798+
{
7799+
struct inet6_dev *inet6_dev;
7800+
struct in_device *idev;
7801+
7802+
idev = __in_dev_get_rcu(dev);
7803+
if (idev && idev->ifa_list)
7804+
return false;
7805+
7806+
inet6_dev = __in6_dev_get(dev);
7807+
if (inet6_dev && !list_empty(&inet6_dev->addr_list))
7808+
return false;
7809+
7810+
return true;
7811+
}
7812+
7813+
static bool mlxsw_sp_dev_addr_list_empty(const struct net_device *dev)
7814+
{
7815+
bool addr_list_empty;
7816+
7817+
rcu_read_lock();
7818+
addr_list_empty = __mlxsw_sp_dev_addr_list_empty(dev);
7819+
rcu_read_unlock();
7820+
7821+
return addr_list_empty;
7822+
}
7823+
77977824
static bool
77987825
mlxsw_sp_rif_should_config(struct mlxsw_sp_rif *rif, struct net_device *dev,
77997826
unsigned long event)
78007827
{
7801-
struct inet6_dev *inet6_dev;
7802-
bool addr_list_empty = true;
7803-
struct in_device *idev;
7828+
bool addr_list_empty;
78047829

78057830
switch (event) {
78067831
case NETDEV_UP:
78077832
return rif == NULL;
78087833
case NETDEV_DOWN:
7809-
rcu_read_lock();
7810-
idev = __in_dev_get_rcu(dev);
7811-
if (idev && idev->ifa_list)
7812-
addr_list_empty = false;
7813-
7814-
inet6_dev = __in6_dev_get(dev);
7815-
if (addr_list_empty && inet6_dev &&
7816-
!list_empty(&inet6_dev->addr_list))
7817-
addr_list_empty = false;
7818-
rcu_read_unlock();
7834+
addr_list_empty = mlxsw_sp_dev_addr_list_empty(dev);
78197835

78207836
/* macvlans do not have a RIF, but rather piggy back on the
78217837
* RIF of their lower device.

0 commit comments

Comments
 (0)