Commit c6514f36 authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-enslavement'

Petr Machata says:

====================
mlxsw: Permit enslavement to netdevices with uppers

The mlxsw driver currently makes the assumption that the user applies
configuration in a bottom-up manner. Thus netdevices need to be added to
the bridge before IP addresses are configured on that bridge or SVI added
on top of it. Enslaving a netdevice to another netdevice that already has
uppers is in fact forbidden by mlxsw for this reason. Despite this safety,
it is rather easy to get into situations where the offloaded configuration
is just plain wrong.

As an example, take a front panel port, configure an IP address: it gets a
RIF. Now enslave the port to the bridge, and the RIF is gone. Remove the
port from the bridge again, but the RIF never comes back. There is a number
of similar situations, where changing the configuration there and back
utterly breaks the offload.

Similarly, detaching a front panel port from a configured topology means
unoffloading of this whole topology -- VLAN uppers, next hops, etc.
Attaching the port back is then not permitted at all. If it were, it would
not result in a working configuration, because much of mlxsw is written to
react to changes in immediate configuration. There is nothing that would go
visit netdevices in the attached-to topology and offload existing routes
and VLAN memberships, for example.

In this patchset, introduce a number of replays to be invoked so that this
sort of post-hoc offload is supported. Then remove the vetoes that
disallowed enslavement of front panel ports to other netdevices with
uppers.

The patchset progresses as follows:

- In patch #1, fix an issue in the bridge driver. To my knowledge, the
  issue could not have resulted in a buggy behavior previously, and thus is
  packaged with this patchset instead of being sent separately to net.

- In patch #2, add a new helper to the switchdev code.

- In patch #3, drop mlxsw selftests that will not be relevant after this
  patchset anymore.

- Patches #4, #5, #6, #7 and #8 prepare the codebase for smoother
  introduction of the rest of the code.

- Patches #9, #10, #11, #12, #13 and #14 replay various aspects of upper
  configuration when a front panel port is introduced into a topology.
  Individual patches take care of bridge and LAG RIF memberships, switchdev
  replay, nexthop and neighbors replay, and MACVLAN offload.

- Patches #15 and #16 introduce RIFs for newly-relevant netdevices when a
  front panel port is enslaved (in which case all uppers are newly
  relevant), or, respectively, deslaved (in which case the newly-relevant
  netdevice is the one being deslaved).

- Up until this point, the introduced scaffolding was not really used,
  because mlxsw still forbids enslavement of mlxsw netdevices to uppers
  with uppers. In patch #17, this condition is finally relaxed.

A sizable selftest suite is available to test all this new code. That will
be sent in a separate patchset.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a5dc694e 2c5ffe8d
......@@ -1132,8 +1132,8 @@ static int mlxsw_sp_port_add_vid(struct net_device *dev,
return PTR_ERR_OR_ZERO(mlxsw_sp_port_vlan_create(mlxsw_sp_port, vid));
}
static int mlxsw_sp_port_kill_vid(struct net_device *dev,
__be16 __always_unused proto, u16 vid)
int mlxsw_sp_port_kill_vid(struct net_device *dev,
__be16 __always_unused proto, u16 vid)
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
......@@ -4337,6 +4337,88 @@ static int mlxsw_sp_port_lag_index_get(struct mlxsw_sp *mlxsw_sp,
return -EBUSY;
}
static int mlxsw_sp_lag_uppers_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev,
struct netlink_ext_ack *extack)
{
struct net_device *upper_dev;
struct net_device *master;
struct list_head *iter;
int done = 0;
int err;
master = netdev_master_upper_dev_get(lag_dev);
if (master && netif_is_bridge_master(master)) {
err = mlxsw_sp_port_bridge_join(mlxsw_sp_port, lag_dev, master,
extack);
if (err)
return err;
}
netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
if (!is_vlan_dev(upper_dev))
continue;
master = netdev_master_upper_dev_get(upper_dev);
if (master && netif_is_bridge_master(master)) {
err = mlxsw_sp_port_bridge_join(mlxsw_sp_port,
upper_dev, master,
extack);
if (err)
goto err_port_bridge_join;
}
++done;
}
return 0;
err_port_bridge_join:
netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
if (!is_vlan_dev(upper_dev))
continue;
master = netdev_master_upper_dev_get(upper_dev);
if (!master || !netif_is_bridge_master(master))
continue;
if (!done--)
break;
mlxsw_sp_port_bridge_leave(mlxsw_sp_port, upper_dev, master);
}
master = netdev_master_upper_dev_get(lag_dev);
if (master && netif_is_bridge_master(master))
mlxsw_sp_port_bridge_leave(mlxsw_sp_port, lag_dev, master);
return err;
}
static void
mlxsw_sp_lag_uppers_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev)
{
struct net_device *upper_dev;
struct net_device *master;
struct list_head *iter;
netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
if (!is_vlan_dev(upper_dev))
continue;
master = netdev_master_upper_dev_get(upper_dev);
if (!master)
continue;
mlxsw_sp_port_bridge_leave(mlxsw_sp_port, upper_dev, master);
}
master = netdev_master_upper_dev_get(lag_dev);
if (master)
mlxsw_sp_port_bridge_leave(mlxsw_sp_port, lag_dev, master);
}
static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev,
struct netlink_ext_ack *extack)
......@@ -4361,6 +4443,12 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port,
err = mlxsw_sp_port_lag_index_get(mlxsw_sp, lag_id, &port_index);
if (err)
return err;
err = mlxsw_sp_lag_uppers_bridge_join(mlxsw_sp_port, lag_dev,
extack);
if (err)
goto err_lag_uppers_bridge_join;
err = mlxsw_sp_lag_col_port_add(mlxsw_sp_port, lag_id, port_index);
if (err)
goto err_col_port_add;
......@@ -4381,8 +4469,14 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port,
if (err)
goto err_router_join;
err = mlxsw_sp_netdevice_enslavement_replay(mlxsw_sp, lag_dev, extack);
if (err)
goto err_replay;
return 0;
err_replay:
mlxsw_sp_router_port_leave_lag(mlxsw_sp_port, lag_dev);
err_router_join:
lag->ref_count--;
mlxsw_sp_port->lagged = 0;
......@@ -4390,6 +4484,8 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port,
mlxsw_sp_port->local_port);
mlxsw_sp_lag_col_port_remove(mlxsw_sp_port, lag_id);
err_col_port_add:
mlxsw_sp_lag_uppers_bridge_leave(mlxsw_sp_port, lag_dev);
err_lag_uppers_bridge_join:
if (!lag->ref_count)
mlxsw_sp_lag_destroy(mlxsw_sp, lag_id);
return err;
......@@ -4639,9 +4735,62 @@ static bool mlxsw_sp_bridge_vxlan_is_valid(struct net_device *br_dev,
return true;
}
static bool mlxsw_sp_netdev_is_master(struct net_device *upper_dev,
struct net_device *dev)
{
return upper_dev == netdev_master_upper_dev_get(dev);
}
static int __mlxsw_sp_netdevice_event(struct mlxsw_sp *mlxsw_sp,
unsigned long event, void *ptr,
bool process_foreign);
static int mlxsw_sp_netdevice_validate_uppers(struct mlxsw_sp *mlxsw_sp,
struct net_device *dev,
struct netlink_ext_ack *extack)
{
struct net_device *upper_dev;
struct list_head *iter;
int err;
netdev_for_each_upper_dev_rcu(dev, upper_dev, iter) {
struct netdev_notifier_changeupper_info info = {
.info = {
.dev = dev,
.extack = extack,
},
.master = mlxsw_sp_netdev_is_master(upper_dev, dev),
.upper_dev = upper_dev,
.linking = true,
/* upper_info is relevant for LAG devices. But we would
* only need this if LAG were a valid upper above
* another upper (e.g. a bridge that is a member of a
* LAG), and that is never a valid configuration. So we
* can keep this as NULL.
*/
.upper_info = NULL,
};
err = __mlxsw_sp_netdevice_event(mlxsw_sp,
NETDEV_PRECHANGEUPPER,
&info, true);
if (err)
return err;
err = mlxsw_sp_netdevice_validate_uppers(mlxsw_sp, upper_dev,
extack);
if (err)
return err;
}
return 0;
}
static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
struct net_device *dev,
unsigned long event, void *ptr)
unsigned long event, void *ptr,
bool replay_deslavement)
{
struct netdev_notifier_changeupper_info *info;
struct mlxsw_sp_port *mlxsw_sp_port;
......@@ -4679,8 +4828,11 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
(!netif_is_bridge_master(upper_dev) ||
!mlxsw_sp_bridge_device_is_offloaded(mlxsw_sp,
upper_dev))) {
NL_SET_ERR_MSG_MOD(extack, "Enslaving a port to a device that already has an upper device is not supported");
return -EINVAL;
err = mlxsw_sp_netdevice_validate_uppers(mlxsw_sp,
upper_dev,
extack);
if (err)
return err;
}
if (netif_is_lag_master(upper_dev) &&
!mlxsw_sp_master_lag_check(mlxsw_sp, upper_dev,
......@@ -4695,11 +4847,6 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
NL_SET_ERR_MSG_MOD(extack, "Can not put a VLAN on a LAG port");
return -EINVAL;
}
if (netif_is_macvlan(upper_dev) &&
!mlxsw_sp_rif_exists(mlxsw_sp, lower_dev)) {
NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
return -EOPNOTSUPP;
}
if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev)) {
NL_SET_ERR_MSG_MOD(extack, "Master device is an OVS master and this device has a VLAN");
return -EINVAL;
......@@ -4746,15 +4893,20 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
case NETDEV_CHANGEUPPER:
upper_dev = info->upper_dev;
if (netif_is_bridge_master(upper_dev)) {
if (info->linking)
if (info->linking) {
err = mlxsw_sp_port_bridge_join(mlxsw_sp_port,
lower_dev,
upper_dev,
extack);
else
} else {
mlxsw_sp_port_bridge_leave(mlxsw_sp_port,
lower_dev,
upper_dev);
if (!replay_deslavement)
break;
mlxsw_sp_netdevice_deslavement_replay(mlxsw_sp,
lower_dev);
}
} else if (netif_is_lag_master(upper_dev)) {
if (info->linking) {
err = mlxsw_sp_port_lag_join(mlxsw_sp_port,
......@@ -4763,6 +4915,8 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
mlxsw_sp_port_lag_col_dist_disable(mlxsw_sp_port);
mlxsw_sp_port_lag_leave(mlxsw_sp_port,
upper_dev);
mlxsw_sp_netdevice_deslavement_replay(mlxsw_sp,
dev);
}
} else if (netif_is_ovs_master(upper_dev)) {
if (info->linking)
......@@ -4815,13 +4969,15 @@ static int mlxsw_sp_netdevice_port_lower_event(struct net_device *dev,
static int mlxsw_sp_netdevice_port_event(struct net_device *lower_dev,
struct net_device *port_dev,
unsigned long event, void *ptr)
unsigned long event, void *ptr,
bool replay_deslavement)
{
switch (event) {
case NETDEV_PRECHANGEUPPER:
case NETDEV_CHANGEUPPER:
return mlxsw_sp_netdevice_port_upper_event(lower_dev, port_dev,
event, ptr);
event, ptr,
replay_deslavement);
case NETDEV_CHANGELOWERSTATE:
return mlxsw_sp_netdevice_port_lower_event(port_dev, event,
ptr);
......@@ -4830,6 +4986,30 @@ static int mlxsw_sp_netdevice_port_event(struct net_device *lower_dev,
return 0;
}
/* Called for LAG or its upper VLAN after the per-LAG-lower processing was done,
* to do any per-LAG / per-LAG-upper processing.
*/
static int mlxsw_sp_netdevice_post_lag_event(struct net_device *dev,
unsigned long event,
void *ptr)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(dev);
struct netdev_notifier_changeupper_info *info = ptr;
if (!mlxsw_sp)
return 0;
switch (event) {
case NETDEV_CHANGEUPPER:
if (info->linking)
break;
if (netif_is_bridge_master(info->upper_dev))
mlxsw_sp_netdevice_deslavement_replay(mlxsw_sp, dev);
break;
}
return 0;
}
static int mlxsw_sp_netdevice_lag_event(struct net_device *lag_dev,
unsigned long event, void *ptr)
{
......@@ -4840,19 +5020,19 @@ static int mlxsw_sp_netdevice_lag_event(struct net_device *lag_dev,
netdev_for_each_lower_dev(lag_dev, dev, iter) {
if (mlxsw_sp_port_dev_check(dev)) {
ret = mlxsw_sp_netdevice_port_event(lag_dev, dev, event,
ptr);
ptr, false);
if (ret)
return ret;
}
}
return 0;
return mlxsw_sp_netdevice_post_lag_event(lag_dev, event, ptr);
}
static int mlxsw_sp_netdevice_port_vlan_event(struct net_device *vlan_dev,
struct net_device *dev,
unsigned long event, void *ptr,
u16 vid)
u16 vid, bool replay_deslavement)
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
......@@ -4883,27 +5063,30 @@ static int mlxsw_sp_netdevice_port_vlan_event(struct net_device *vlan_dev,
(!netif_is_bridge_master(upper_dev) ||
!mlxsw_sp_bridge_device_is_offloaded(mlxsw_sp,
upper_dev))) {
NL_SET_ERR_MSG_MOD(extack, "Enslaving a port to a device that already has an upper device is not supported");
return -EINVAL;
}
if (netif_is_macvlan(upper_dev) &&
!mlxsw_sp_rif_exists(mlxsw_sp, vlan_dev)) {
NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
return -EOPNOTSUPP;
err = mlxsw_sp_netdevice_validate_uppers(mlxsw_sp,
upper_dev,
extack);
if (err)
return err;
}
break;
case NETDEV_CHANGEUPPER:
upper_dev = info->upper_dev;
if (netif_is_bridge_master(upper_dev)) {
if (info->linking)
if (info->linking) {
err = mlxsw_sp_port_bridge_join(mlxsw_sp_port,
vlan_dev,
upper_dev,
extack);
else
} else {
mlxsw_sp_port_bridge_leave(mlxsw_sp_port,
vlan_dev,
upper_dev);
if (!replay_deslavement)
break;
mlxsw_sp_netdevice_deslavement_replay(mlxsw_sp,
vlan_dev);
}
} else if (netif_is_macvlan(upper_dev)) {
if (!info->linking)
mlxsw_sp_rif_macvlan_del(mlxsw_sp, upper_dev);
......@@ -4927,26 +5110,26 @@ static int mlxsw_sp_netdevice_lag_port_vlan_event(struct net_device *vlan_dev,
if (mlxsw_sp_port_dev_check(dev)) {
ret = mlxsw_sp_netdevice_port_vlan_event(vlan_dev, dev,
event, ptr,
vid);
vid, false);
if (ret)
return ret;
}
}
return 0;
return mlxsw_sp_netdevice_post_lag_event(vlan_dev, event, ptr);
}
static int mlxsw_sp_netdevice_bridge_vlan_event(struct net_device *vlan_dev,
static int mlxsw_sp_netdevice_bridge_vlan_event(struct mlxsw_sp *mlxsw_sp,
struct net_device *vlan_dev,
struct net_device *br_dev,
unsigned long event, void *ptr,
u16 vid)
u16 vid, bool process_foreign)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(vlan_dev);
struct netdev_notifier_changeupper_info *info = ptr;
struct netlink_ext_ack *extack;
struct net_device *upper_dev;
if (!mlxsw_sp)
if (!process_foreign && !mlxsw_sp_lower_get(vlan_dev))
return 0;
extack = netdev_notifier_info_to_extack(&info->info);
......@@ -4959,13 +5142,6 @@ static int mlxsw_sp_netdevice_bridge_vlan_event(struct net_device *vlan_dev,
NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
return -EOPNOTSUPP;
}
if (!info->linking)
break;
if (netif_is_macvlan(upper_dev) &&
!mlxsw_sp_rif_exists(mlxsw_sp, vlan_dev)) {
NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
return -EOPNOTSUPP;
}
break;
case NETDEV_CHANGEUPPER:
upper_dev = info->upper_dev;
......@@ -4979,36 +5155,42 @@ static int mlxsw_sp_netdevice_bridge_vlan_event(struct net_device *vlan_dev,
return 0;
}
static int mlxsw_sp_netdevice_vlan_event(struct net_device *vlan_dev,
unsigned long event, void *ptr)
static int mlxsw_sp_netdevice_vlan_event(struct mlxsw_sp *mlxsw_sp,
struct net_device *vlan_dev,
unsigned long event, void *ptr,
bool process_foreign)
{
struct net_device *real_dev = vlan_dev_real_dev(vlan_dev);
u16 vid = vlan_dev_vlan_id(vlan_dev);
if (mlxsw_sp_port_dev_check(real_dev))
return mlxsw_sp_netdevice_port_vlan_event(vlan_dev, real_dev,
event, ptr, vid);
event, ptr, vid,
true);
else if (netif_is_lag_master(real_dev))
return mlxsw_sp_netdevice_lag_port_vlan_event(vlan_dev,
real_dev, event,
ptr, vid);
else if (netif_is_bridge_master(real_dev))
return mlxsw_sp_netdevice_bridge_vlan_event(vlan_dev, real_dev,
event, ptr, vid);
return mlxsw_sp_netdevice_bridge_vlan_event(mlxsw_sp, vlan_dev,
real_dev, event,
ptr, vid,
process_foreign);
return 0;
}
static int mlxsw_sp_netdevice_bridge_event(struct net_device *br_dev,
unsigned long event, void *ptr)
static int mlxsw_sp_netdevice_bridge_event(struct mlxsw_sp *mlxsw_sp,
struct net_device *br_dev,
unsigned long event, void *ptr,
bool process_foreign)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(br_dev);
struct netdev_notifier_changeupper_info *info = ptr;
struct netlink_ext_ack *extack;
struct net_device *upper_dev;
u16 proto;
if (!mlxsw_sp)
if (!process_foreign && !mlxsw_sp_lower_get(br_dev))
return 0;
extack = netdev_notifier_info_to_extack(&info->info);
......@@ -5036,11 +5218,6 @@ static int mlxsw_sp_netdevice_bridge_event(struct net_device *br_dev,
NL_SET_ERR_MSG_MOD(extack, "VLAN uppers are only supported with 802.1q VLAN protocol");
return -EOPNOTSUPP;
}
if (netif_is_macvlan(upper_dev) &&
!mlxsw_sp_rif_exists(mlxsw_sp, br_dev)) {
NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
return -EOPNOTSUPP;
}
break;
case NETDEV_CHANGEUPPER:
upper_dev = info->upper_dev;
......@@ -5146,35 +5323,48 @@ static int mlxsw_sp_netdevice_vxlan_event(struct mlxsw_sp *mlxsw_sp,
return 0;
}
static int mlxsw_sp_netdevice_event(struct notifier_block *nb,
unsigned long event, void *ptr)
static int __mlxsw_sp_netdevice_event(struct mlxsw_sp *mlxsw_sp,
unsigned long event, void *ptr,
bool process_foreign)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct mlxsw_sp_span_entry *span_entry;
struct mlxsw_sp *mlxsw_sp;
int err = 0;
mlxsw_sp = container_of(nb, struct mlxsw_sp, netdevice_nb);
if (event == NETDEV_UNREGISTER) {
span_entry = mlxsw_sp_span_entry_find_by_port(mlxsw_sp, dev);
if (span_entry)
mlxsw_sp_span_entry_invalidate(mlxsw_sp, span_entry);
}
mlxsw_sp_span_respin(mlxsw_sp);
if (netif_is_vxlan(dev))
err = mlxsw_sp_netdevice_vxlan_event(mlxsw_sp, dev, event, ptr);
else if (mlxsw_sp_port_dev_check(dev))
err = mlxsw_sp_netdevice_port_event(dev, dev, event, ptr);
err = mlxsw_sp_netdevice_port_event(dev, dev, event, ptr, true);
else if (netif_is_lag_master(dev))
err = mlxsw_sp_netdevice_lag_event(dev, event, ptr);
else if (is_vlan_dev(dev))
err = mlxsw_sp_netdevice_vlan_event(dev, event, ptr);
err = mlxsw_sp_netdevice_vlan_event(mlxsw_sp, dev, event, ptr,
process_foreign);
else if (netif_is_bridge_master(dev))
err = mlxsw_sp_netdevice_bridge_event(dev, event, ptr);
err = mlxsw_sp_netdevice_bridge_event(mlxsw_sp, dev, event, ptr,
process_foreign);
else if (netif_is_macvlan(dev))
err = mlxsw_sp_netdevice_macvlan_event(dev, event, ptr);
return err;
}
static int mlxsw_sp_netdevice_event(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct mlxsw_sp *mlxsw_sp;
int err;
mlxsw_sp = container_of(nb, struct mlxsw_sp, netdevice_nb);
mlxsw_sp_span_respin(mlxsw_sp);
err = __mlxsw_sp_netdevice_event(mlxsw_sp, event, ptr, false);
return notifier_from_errno(err);
}
......
......@@ -700,6 +700,8 @@ int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
struct mlxsw_sp_port_vlan *
mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
int mlxsw_sp_port_kill_vid(struct net_device *dev,
__be16 __always_unused proto, u16 vid);
int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
u16 vid_end, bool is_member, bool untagged);
int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
......
......@@ -2872,6 +2872,21 @@ static bool mlxsw_sp_dev_lower_is_port(struct net_device *dev)
return !!mlxsw_sp_port;
}
static int mlxsw_sp_router_schedule_neigh_work(struct mlxsw_sp_router *router,
struct neighbour *n)
{
struct net *net;
net = neigh_parms_net(n->parms);
/* Take a reference to ensure the neighbour won't be destructed until we
* drop the reference in delayed work.
*/
neigh_clone(n);
return mlxsw_sp_router_schedule_work(net, router, n,
mlxsw_sp_router_neigh_event_work);
}
static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
unsigned long event, void *ptr)
{
......@@ -2879,7 +2894,6 @@ static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
unsigned long interval;
struct neigh_parms *p;
struct neighbour *n;
struct net *net;
router = container_of(nb, struct mlxsw_sp_router, netevent_nb);
......@@ -2903,7 +2917,6 @@ static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
break;
case NETEVENT_NEIGH_UPDATE:
n = ptr;
net = neigh_parms_net(n->parms);
if (n->tbl->family != AF_INET && n->tbl->family != AF_INET6)
return NOTIFY_DONE;
......@@ -2911,13 +2924,7 @@ static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
if (!mlxsw_sp_dev_lower_is_port(n->dev))
return NOTIFY_DONE;
/* Take a reference to ensure the neighbour won't be
* destructed until we drop the reference in delayed
* work.
*/
neigh_clone(n);
return mlxsw_sp_router_schedule_work(net, router, n,
mlxsw_sp_router_neigh_event_work);
return mlxsw_sp_router_schedule_neigh_work(router, n);
case NETEVENT_IPV4_MPATH_HASH_UPDATE:
case NETEVENT_IPV6_MPATH_HASH_UPDATE:
......@@ -2976,6 +2983,52 @@ static void mlxsw_sp_neigh_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
}
}
struct mlxsw_sp_neigh_rif_made_sync {
struct mlxsw_sp *mlxsw_sp;
struct mlxsw_sp_rif *rif;
int err;
};
static void mlxsw_sp_neigh_rif_made_sync_each(struct neighbour *n, void *data)
{
struct mlxsw_sp_neigh_rif_made_sync *rms = data;
int rc;
if (rms->err)
return;
if (n->dev != mlxsw_sp_rif_dev(rms->rif))
return;
rc = mlxsw_sp_router_schedule_neigh_work(rms->mlxsw_sp->router, n);
if (rc != NOTIFY_DONE)
rms->err = -ENOMEM;
}
static int mlxsw_sp_neigh_rif_made_sync(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_rif *rif)
{
struct mlxsw_sp_neigh_rif_made_sync rms = {
.mlxsw_sp = mlxsw_sp,
.rif = rif,
};
neigh_for_each(&arp_tbl, mlxsw_sp_neigh_rif_made_sync_each, &rms);
if (rms.err)
goto err_arp;
#if IS_ENABLED(CONFIG_IPV6)
neigh_for_each(&nd_tbl, mlxsw_sp_neigh_rif_made_sync_each, &rms);
#endif
if (rms.err)
goto err_nd;
return 0;
err_nd:
err_arp:
mlxsw_sp_neigh_rif_gone_sync(mlxsw_sp, rif);
return rms.err;
}
enum mlxsw_sp_nexthop_type {
MLXSW_SP_NEXTHOP_TYPE_ETH,
MLXSW_SP_NEXTHOP_TYPE_IPIP,
......@@ -4397,6 +4450,19 @@ static int mlxsw_sp_nexthop_type_init(struct mlxsw_sp *mlxsw_sp,
return err;
}
static int mlxsw_sp_nexthop_type_rif_made(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh)
{
switch (nh->type) {
case MLXSW_SP_NEXTHOP_TYPE_ETH:
return mlxsw_sp_nexthop_neigh_init(mlxsw_sp, nh);
case MLXSW_SP_NEXTHOP_TYPE_IPIP:
break;
}
return 0;
}
static void mlxsw_sp_nexthop_type_rif_gone(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh)
{
......@@ -4525,6 +4591,35 @@ static void mlxsw_sp_nexthop_rif_update(struct mlxsw_sp *mlxsw_sp,
}
}
static int mlxsw_sp_nexthop_rif_made_sync(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_rif *rif)
{
struct mlxsw_sp_nexthop *nh, *tmp;
unsigned int n = 0;
int err;
list_for_each_entry_safe(nh, tmp, &rif->crif->nexthop_list,
crif_list_node) {
err = mlxsw_sp_nexthop_type_rif_made(mlxsw_sp, nh);
if (err)
goto err_nexthop_type_rif;
mlxsw_sp_nexthop_group_refresh(mlxsw_sp, nh->nhgi->nh_grp);
n++;
}
return 0;
err_nexthop_type_rif:
list_for_each_entry_safe(nh, tmp, &rif->crif->nexthop_list,
crif_list_node) {
if (!n--)
break;
mlxsw_sp_nexthop_type_rif_gone(mlxsw_sp, nh);
mlxsw_sp_nexthop_group_refresh(mlxsw_sp, nh->nhgi->nh_grp);
}
return err;
}
static void mlxsw_sp_nexthop_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_rif *rif)
{
......@@ -7885,6 +7980,26 @@ static int mlxsw_sp_router_rif_disable(struct mlxsw_sp *mlxsw_sp, u16 rif)
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ritr), ritr_pl);
}
static int mlxsw_sp_router_rif_made_sync(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_rif *rif)
{
int err;
err = mlxsw_sp_neigh_rif_made_sync(mlxsw_sp, rif);
if (err)
return err;
err = mlxsw_sp_nexthop_rif_made_sync(mlxsw_sp, rif);
if (err)
goto err_nexthop;
return 0;
err_nexthop:
mlxsw_sp_neigh_rif_gone_sync(mlxsw_sp, rif);
return err;
}
static void mlxsw_sp_router_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_rif *rif)
{
......@@ -8322,6 +8437,10 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp,
goto err_mr_rif_add;
}
err = mlxsw_sp_router_rif_made_sync(mlxsw_sp, rif);
if (err)
goto err_rif_made_sync;
if (netdev_offload_xstats_enabled(params->dev,
NETDEV_OFFLOAD_XSTATS_TYPE_L3)) {
err = mlxsw_sp_router_port_l3_stats_enable(rif);
......@@ -8336,6 +8455,8 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp,
return rif;
err_stats_enable:
mlxsw_sp_router_rif_gone_sync(mlxsw_sp, rif);
err_rif_made_sync:
err_mr_rif_add:
for (i--; i >= 0; i--)
mlxsw_sp_mr_rif_del(vr->mr_table[i], rif);
......@@ -8884,10 +9005,11 @@ static int mlxsw_sp_inetaddr_port_vlan_event(struct net_device *l3_dev,
}
static int mlxsw_sp_inetaddr_port_event(struct net_device *port_dev,
unsigned long event,
unsigned long event, bool nomaster,
struct netlink_ext_ack *extack)
{
if (netif_is_any_bridge_port(port_dev) || netif_is_lag_port(port_dev))
if (!nomaster && (netif_is_any_bridge_port(port_dev) ||
netif_is_lag_port(port_dev)))
return 0;
return mlxsw_sp_inetaddr_port_vlan_event(port_dev, port_dev, event,
......@@ -8918,10 +9040,10 @@ static int __mlxsw_sp_inetaddr_lag_event(struct net_device *l3_dev,
}
static int mlxsw_sp_inetaddr_lag_event(struct net_device *lag_dev,
unsigned long event,
unsigned long event, bool nomaster,
struct netlink_ext_ack *extack)
{
if (netif_is_bridge_port(lag_dev))
if (!nomaster && netif_is_bridge_port(lag_dev))
return 0;
return __mlxsw_sp_inetaddr_lag_event(lag_dev, lag_dev, event,
......@@ -8980,7 +9102,7 @@ static int mlxsw_sp_inetaddr_bridge_event(struct mlxsw_sp *mlxsw_sp,
static int mlxsw_sp_inetaddr_vlan_event(struct mlxsw_sp *mlxsw_sp,
struct net_device *vlan_dev,
unsigned long event,
unsigned long event, bool nomaster,
struct netlink_ext_ack *extack)
{
struct net_device *real_dev = vlan_dev_real_dev(vlan_dev);
......@@ -8988,7 +9110,7 @@ static int mlxsw_sp_inetaddr_vlan_event(struct mlxsw_sp *mlxsw_sp,
u16 lower_pvid;
int err;
if (netif_is_bridge_port(vlan_dev))
if (!nomaster && netif_is_bridge_port(vlan_dev))
return 0;
if (mlxsw_sp_port_dev_check(real_dev)) {
......@@ -9059,10 +9181,8 @@ static int mlxsw_sp_rif_macvlan_add(struct mlxsw_sp *mlxsw_sp,
int err;
rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, vlan->lowerdev);
if (!rif) {
NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
return -EOPNOTSUPP;
}
if (!rif)
return 0;
err = mlxsw_sp_rif_fdb_op(mlxsw_sp, macvlan_dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), true);
......@@ -9132,19 +9252,21 @@ static int mlxsw_sp_inetaddr_macvlan_event(struct mlxsw_sp *mlxsw_sp,
static int __mlxsw_sp_inetaddr_event(struct mlxsw_sp *mlxsw_sp,
struct net_device *dev,
unsigned long event,
unsigned long event, bool nomaster,
struct netlink_ext_ack *extack)
{
if (mlxsw_sp_port_dev_check(dev))
return mlxsw_sp_inetaddr_port_event(dev, event, extack);
return mlxsw_sp_inetaddr_port_event(dev, event, nomaster,
extack);
else if (netif_is_lag_master(dev))
return mlxsw_sp_inetaddr_lag_event(dev, event, extack);
return mlxsw_sp_inetaddr_lag_event(dev, event, nomaster,
extack);
else if (netif_is_bridge_master(dev))
return mlxsw_sp_inetaddr_bridge_event(mlxsw_sp, dev, -1, event,
extack);
else if (is_vlan_dev(dev))
return mlxsw_sp_inetaddr_vlan_event(mlxsw_sp, dev, event,
extack);
nomaster, extack);
else if (netif_is_macvlan(dev))
return mlxsw_sp_inetaddr_macvlan_event(mlxsw_sp, dev, event,
extack);
......@@ -9171,7 +9293,8 @@ static int mlxsw_sp_inetaddr_event(struct notifier_block *nb,
if (!mlxsw_sp_rif_should_config(rif, dev, event))
goto out;
err = __mlxsw_sp_inetaddr_event(router->mlxsw_sp, dev, event, NULL);
err = __mlxsw_sp_inetaddr_event(router->mlxsw_sp, dev, event, false,
NULL);
out:
mutex_unlock(&router->lock);
return notifier_from_errno(err);
......@@ -9195,7 +9318,8 @@ static int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
if (!mlxsw_sp_rif_should_config(rif, dev, event))
goto out;
err = __mlxsw_sp_inetaddr_event(mlxsw_sp, dev, event, ivi->extack);
err = __mlxsw_sp_inetaddr_event(mlxsw_sp, dev, event, false,
ivi->extack);
out:
mutex_unlock(&mlxsw_sp->router->lock);
return notifier_from_errno(err);
......@@ -9224,7 +9348,7 @@ static void mlxsw_sp_inet6addr_event_work(struct work_struct *work)
if (!mlxsw_sp_rif_should_config(rif, dev, event))
goto out;
__mlxsw_sp_inetaddr_event(mlxsw_sp, dev, event, NULL);
__mlxsw_sp_inetaddr_event(mlxsw_sp, dev, event, false, NULL);
out:
mutex_unlock(&mlxsw_sp->router->lock);
rtnl_unlock();
......@@ -9278,7 +9402,8 @@ static int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
if (!mlxsw_sp_rif_should_config(rif, dev, event))
goto out;
err = __mlxsw_sp_inetaddr_event(mlxsw_sp, dev, event, i6vi->extack);
err = __mlxsw_sp_inetaddr_event(mlxsw_sp, dev, event, false,
i6vi->extack);
out:
mutex_unlock(&mlxsw_sp->router->lock);
return notifier_from_errno(err);
......@@ -9598,10 +9723,11 @@ static int mlxsw_sp_port_vrf_join(struct mlxsw_sp *mlxsw_sp,
*/
rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, l3_dev);
if (rif)
__mlxsw_sp_inetaddr_event(mlxsw_sp, l3_dev, NETDEV_DOWN,
__mlxsw_sp_inetaddr_event(mlxsw_sp, l3_dev, NETDEV_DOWN, false,
extack);
return __mlxsw_sp_inetaddr_event(mlxsw_sp, l3_dev, NETDEV_UP, extack);
return __mlxsw_sp_inetaddr_event(mlxsw_sp, l3_dev, NETDEV_UP, false,
extack);
}
static void mlxsw_sp_port_vrf_leave(struct mlxsw_sp *mlxsw_sp,
......@@ -9612,7 +9738,7 @@ static void mlxsw_sp_port_vrf_leave(struct mlxsw_sp *mlxsw_sp,
rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, l3_dev);
if (!rif)
return;
__mlxsw_sp_inetaddr_event(mlxsw_sp, l3_dev, NETDEV_DOWN, NULL);
__mlxsw_sp_inetaddr_event(mlxsw_sp, l3_dev, NETDEV_DOWN, false, NULL);
}
static bool mlxsw_sp_is_vrf_event(unsigned long event, void *ptr)
......@@ -9655,6 +9781,116 @@ mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
return err;
}
struct mlxsw_sp_router_replay_inetaddr_up {
struct mlxsw_sp *mlxsw_sp;
struct netlink_ext_ack *extack;
unsigned int done;
bool deslavement;
};
static int mlxsw_sp_router_replay_inetaddr_up(struct net_device *dev,
struct netdev_nested_priv *priv)
{
struct mlxsw_sp_router_replay_inetaddr_up *ctx = priv->data;
bool nomaster = ctx->deslavement;
struct mlxsw_sp_crif *crif;
int err;
if (mlxsw_sp_dev_addr_list_empty(dev))
return 0;
crif = mlxsw_sp_crif_lookup(ctx->mlxsw_sp->router, dev);
if (!crif || crif->rif)
return 0;
if (!mlxsw_sp_rif_should_config(crif->rif, dev, NETDEV_UP))
return 0;
err = __mlxsw_sp_inetaddr_event(ctx->mlxsw_sp, dev, NETDEV_UP,
nomaster, ctx->extack);
if (err)
return err;
ctx->done++;
return 0;
}
static int mlxsw_sp_router_unreplay_inetaddr_up(struct net_device *dev,
struct netdev_nested_priv *priv)
{
struct mlxsw_sp_router_replay_inetaddr_up *ctx = priv->data;
bool nomaster = ctx->deslavement;
struct mlxsw_sp_crif *crif;
if (!ctx->done)
return 0;
if (mlxsw_sp_dev_addr_list_empty(dev))
return 0;
crif = mlxsw_sp_crif_lookup(ctx->mlxsw_sp->router, dev);
if (!crif || !crif->rif)
return 0;
/* We are rolling back NETDEV_UP, so ask for that. */
if (!mlxsw_sp_rif_should_config(crif->rif, dev, NETDEV_UP))
return 0;
__mlxsw_sp_inetaddr_event(ctx->mlxsw_sp, dev, NETDEV_DOWN, nomaster,
NULL);
ctx->done--;
return 0;
}
int mlxsw_sp_netdevice_enslavement_replay(struct mlxsw_sp *mlxsw_sp,
struct net_device *upper_dev,
struct netlink_ext_ack *extack)
{
struct mlxsw_sp_router_replay_inetaddr_up ctx = {
.mlxsw_sp = mlxsw_sp,
.extack = extack,
.deslavement = false,
};
struct netdev_nested_priv priv = {
.data = &ctx,
};
int err;
err = mlxsw_sp_router_replay_inetaddr_up(upper_dev, &priv);
if (err)
return err;
err = netdev_walk_all_upper_dev_rcu(upper_dev,
mlxsw_sp_router_replay_inetaddr_up,
&priv);
if (err)
goto err_replay_up;
return 0;
err_replay_up:
netdev_walk_all_upper_dev_rcu(upper_dev,
mlxsw_sp_router_unreplay_inetaddr_up,
&priv);
mlxsw_sp_router_unreplay_inetaddr_up(upper_dev, &priv);
return err;
}
void mlxsw_sp_netdevice_deslavement_replay(struct mlxsw_sp *mlxsw_sp,
struct net_device *dev)
{
struct mlxsw_sp_router_replay_inetaddr_up ctx = {
.mlxsw_sp = mlxsw_sp,
.deslavement = true,
};
struct netdev_nested_priv priv = {
.data = &ctx,
};
mlxsw_sp_router_replay_inetaddr_up(dev, &priv);
}
static int
mlxsw_sp_port_vid_router_join_existing(struct mlxsw_sp_port *mlxsw_sp_port,
u16 vid, struct net_device *dev,
......@@ -9671,15 +9907,84 @@ mlxsw_sp_port_vid_router_join_existing(struct mlxsw_sp_port *mlxsw_sp_port,
dev, extack);
}
static void
mlxsw_sp_port_vid_router_leave(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
struct net_device *dev)
{
struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port,
vid);
if (WARN_ON(!mlxsw_sp_port_vlan))
return;
__mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port_vlan);
}
static int __mlxsw_sp_router_port_join_lag(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev,
struct netlink_ext_ack *extack)
{
u16 default_vid = MLXSW_SP_DEFAULT_VID;
struct net_device *upper_dev;
struct list_head *iter;
int done = 0;
u16 vid;
int err;
return mlxsw_sp_port_vid_router_join_existing(mlxsw_sp_port,
default_vid, lag_dev,
extack);
err = mlxsw_sp_port_vid_router_join_existing(mlxsw_sp_port, default_vid,
lag_dev, extack);
if (err)
return err;
netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
if (!is_vlan_dev(upper_dev))
continue;
vid = vlan_dev_vlan_id(upper_dev);
err = mlxsw_sp_port_vid_router_join_existing(mlxsw_sp_port, vid,
upper_dev, extack);
if (err)
goto err_router_join_dev;
++done;
}
return 0;
err_router_join_dev:
netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
if (!is_vlan_dev(upper_dev))
continue;
if (!done--)
break;
vid = vlan_dev_vlan_id(upper_dev);
mlxsw_sp_port_vid_router_leave(mlxsw_sp_port, vid, upper_dev);
}
mlxsw_sp_port_vid_router_leave(mlxsw_sp_port, default_vid, lag_dev);
return err;
}
static void
__mlxsw_sp_router_port_leave_lag(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev)
{
u16 default_vid = MLXSW_SP_DEFAULT_VID;
struct net_device *upper_dev;
struct list_head *iter;
u16 vid;
netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
if (!is_vlan_dev(upper_dev))
continue;
vid = vlan_dev_vlan_id(upper_dev);
mlxsw_sp_port_vid_router_leave(mlxsw_sp_port, vid, upper_dev);
}
mlxsw_sp_port_vid_router_leave(mlxsw_sp_port, default_vid, lag_dev);
}
int mlxsw_sp_router_port_join_lag(struct mlxsw_sp_port *mlxsw_sp_port,
......@@ -9695,6 +10000,14 @@ int mlxsw_sp_router_port_join_lag(struct mlxsw_sp_port *mlxsw_sp_port,
return err;
}
void mlxsw_sp_router_port_leave_lag(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev)
{
mutex_lock(&mlxsw_sp_port->mlxsw_sp->router->lock);
__mlxsw_sp_router_port_leave_lag(mlxsw_sp_port, lag_dev);
mutex_unlock(&mlxsw_sp_port->mlxsw_sp->router->lock);
}
static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb,
unsigned long event, void *ptr)
{
......@@ -9740,6 +10053,40 @@ static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb,
return notifier_from_errno(err);
}
struct mlxsw_sp_macvlan_replay {
struct mlxsw_sp *mlxsw_sp;
struct netlink_ext_ack *extack;
};
static int mlxsw_sp_macvlan_replay_upper(struct net_device *dev,
struct netdev_nested_priv *priv)
{
const struct mlxsw_sp_macvlan_replay *rms = priv->data;
struct netlink_ext_ack *extack = rms->extack;
struct mlxsw_sp *mlxsw_sp = rms->mlxsw_sp;
if (!netif_is_macvlan(dev))
return 0;
return mlxsw_sp_rif_macvlan_add(mlxsw_sp, dev, extack);
}
static int mlxsw_sp_macvlan_replay(struct mlxsw_sp_rif *rif,
struct netlink_ext_ack *extack)
{
struct mlxsw_sp_macvlan_replay rms = {
.mlxsw_sp = rif->mlxsw_sp,
.extack = extack,
};
struct netdev_nested_priv priv = {
.data = &rms,
};
return netdev_walk_all_upper_dev_rcu(mlxsw_sp_rif_dev(rif),
mlxsw_sp_macvlan_replay_upper,
&priv);
}
static int __mlxsw_sp_rif_macvlan_flush(struct net_device *dev,
struct netdev_nested_priv *priv)
{
......@@ -9762,7 +10109,6 @@ static int mlxsw_sp_rif_macvlan_flush(struct mlxsw_sp_rif *rif)
if (!netif_is_macvlan_port(dev))
return 0;
netdev_warn(dev, "Router interface is deleted. Upper macvlans will not work\n");
return netdev_walk_all_upper_dev_rcu(dev,
__mlxsw_sp_rif_macvlan_flush, &priv);
}
......@@ -9820,6 +10166,10 @@ static int mlxsw_sp_rif_subport_configure(struct mlxsw_sp_rif *rif,
if (err)
goto err_rif_subport_op;
err = mlxsw_sp_macvlan_replay(rif, extack);
if (err)
goto err_macvlan_replay;
err = mlxsw_sp_rif_fdb_op(rif->mlxsw_sp, dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), true);
if (err)
......@@ -9835,6 +10185,8 @@ static int mlxsw_sp_rif_subport_configure(struct mlxsw_sp_rif *rif,
mlxsw_sp_rif_fdb_op(rif->mlxsw_sp, dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), false);
err_rif_fdb_op:
mlxsw_sp_rif_macvlan_flush(rif);
err_macvlan_replay:
mlxsw_sp_rif_subport_op(rif, false);
err_rif_subport_op:
mlxsw_sp_rif_mac_profile_put(rif->mlxsw_sp, mac_profile);
......@@ -9921,6 +10273,10 @@ static int mlxsw_sp_rif_fid_configure(struct mlxsw_sp_rif *rif,
if (err)
goto err_fid_bc_flood_set;
err = mlxsw_sp_macvlan_replay(rif, extack);
if (err)
goto err_macvlan_replay;
err = mlxsw_sp_rif_fdb_op(rif->mlxsw_sp, dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), true);
if (err)
......@@ -9936,6 +10292,8 @@ static int mlxsw_sp_rif_fid_configure(struct mlxsw_sp_rif *rif,
mlxsw_sp_rif_fdb_op(rif->mlxsw_sp, dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), false);
err_rif_fdb_op:
mlxsw_sp_rif_macvlan_flush(rif);
err_macvlan_replay:
mlxsw_sp_fid_flood_set(rif->fid, MLXSW_SP_FLOOD_TYPE_BC,
mlxsw_sp_router_port(mlxsw_sp), false);
err_fid_bc_flood_set:
......@@ -10083,6 +10441,10 @@ static int mlxsw_sp_rif_vlan_configure(struct mlxsw_sp_rif *rif, u16 efid,
if (err)
goto err_fid_bc_flood_set;
err = mlxsw_sp_macvlan_replay(rif, extack);
if (err)
goto err_macvlan_replay;
err = mlxsw_sp_rif_fdb_op(rif->mlxsw_sp, dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), true);
if (err)
......@@ -10098,6 +10460,8 @@ static int mlxsw_sp_rif_vlan_configure(struct mlxsw_sp_rif *rif, u16 efid,
mlxsw_sp_rif_fdb_op(rif->mlxsw_sp, dev->dev_addr,
mlxsw_sp_fid_index(rif->fid), false);
err_rif_fdb_op:
mlxsw_sp_rif_macvlan_flush(rif);
err_macvlan_replay:
mlxsw_sp_fid_flood_set(rif->fid, MLXSW_SP_FLOOD_TYPE_BC,
mlxsw_sp_router_port(mlxsw_sp), false);
err_fid_bc_flood_set:
......
......@@ -178,5 +178,12 @@ int mlxsw_sp_router_bridge_vlan_add(struct mlxsw_sp *mlxsw_sp,
int mlxsw_sp_router_port_join_lag(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev,
struct netlink_ext_ack *extack);
void mlxsw_sp_router_port_leave_lag(struct mlxsw_sp_port *mlxsw_sp_port,
struct net_device *lag_dev);
int mlxsw_sp_netdevice_enslavement_replay(struct mlxsw_sp *mlxsw_sp,
struct net_device *upper_dev,
struct netlink_ext_ack *extack);
void mlxsw_sp_netdevice_deslavement_replay(struct mlxsw_sp *mlxsw_sp,
struct net_device *dev);
#endif /* _MLXSW_ROUTER_H_*/
......@@ -384,6 +384,91 @@ mlxsw_sp_bridge_port_find(struct mlxsw_sp_bridge *bridge,
return __mlxsw_sp_bridge_port_find(bridge_device, brport_dev);
}
static int mlxsw_sp_port_obj_add(struct net_device *dev, const void *ctx,
const struct switchdev_obj *obj,
struct netlink_ext_ack *extack);
static int mlxsw_sp_port_obj_del(struct net_device *dev, const void *ctx,
const struct switchdev_obj *obj);
struct mlxsw_sp_bridge_port_replay_switchdev_objs {
struct net_device *brport_dev;
struct mlxsw_sp_port *mlxsw_sp_port;
int done;
};
static int
mlxsw_sp_bridge_port_replay_switchdev_objs(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
struct switchdev_notifier_port_obj_info *port_obj_info = ptr;
struct netlink_ext_ack *extack = port_obj_info->info.extack;
struct mlxsw_sp_bridge_port_replay_switchdev_objs *rso;
int err = 0;
rso = (void *)port_obj_info->info.ctx;
if (event != SWITCHDEV_PORT_OBJ_ADD ||
dev != rso->brport_dev)
goto out;
/* When a port is joining the bridge through a LAG, there likely are
* VLANs configured on that LAG already. The replay will thus attempt to
* have the given port-vlans join the corresponding FIDs. But the LAG
* netdevice has already called the ndo_vlan_rx_add_vid NDO for its VLAN
* memberships, back before CHANGEUPPER was distributed and netdevice
* master set. So now before propagating the VLAN events further, we
* first need to kill the corresponding VID at the mlxsw_sp_port.
*
* Note that this doesn't need to be rolled back on failure -- if the
* replay fails, the enslavement is off, and the VIDs would be killed by
* LAG anyway as part of its rollback.
*/
if (port_obj_info->obj->id == SWITCHDEV_OBJ_ID_PORT_VLAN) {
u16 vid = SWITCHDEV_OBJ_PORT_VLAN(port_obj_info->obj)->vid;
err = mlxsw_sp_port_kill_vid(rso->mlxsw_sp_port->dev, 0, vid);
if (err)
goto out;
}
++rso->done;
err = mlxsw_sp_port_obj_add(rso->mlxsw_sp_port->dev, NULL,
port_obj_info->obj, extack);
out:
return notifier_from_errno(err);
}
static struct notifier_block mlxsw_sp_bridge_port_replay_switchdev_objs_nb = {
.notifier_call = mlxsw_sp_bridge_port_replay_switchdev_objs,
};
static int
mlxsw_sp_bridge_port_unreplay_switchdev_objs(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
struct switchdev_notifier_port_obj_info *port_obj_info = ptr;
struct mlxsw_sp_bridge_port_replay_switchdev_objs *rso;
rso = (void *)port_obj_info->info.ctx;
if (event != SWITCHDEV_PORT_OBJ_ADD ||
dev != rso->brport_dev)
return NOTIFY_DONE;
if (!rso->done--)
return NOTIFY_STOP;
mlxsw_sp_port_obj_del(rso->mlxsw_sp_port->dev, NULL,
port_obj_info->obj);
return NOTIFY_DONE;
}
static struct notifier_block mlxsw_sp_bridge_port_unreplay_switchdev_objs_nb = {
.notifier_call = mlxsw_sp_bridge_port_unreplay_switchdev_objs,
};
static struct mlxsw_sp_bridge_port *
mlxsw_sp_bridge_port_create(struct mlxsw_sp_bridge_device *bridge_device,
struct net_device *brport_dev,
......@@ -2350,6 +2435,33 @@ static struct mlxsw_sp_port *mlxsw_sp_lag_rep_port(struct mlxsw_sp *mlxsw_sp,
return NULL;
}
static int
mlxsw_sp_bridge_port_replay(struct mlxsw_sp_bridge_port *bridge_port,
struct mlxsw_sp_port *mlxsw_sp_port,
struct netlink_ext_ack *extack)
{
struct mlxsw_sp_bridge_port_replay_switchdev_objs rso = {
.brport_dev = bridge_port->dev,
.mlxsw_sp_port = mlxsw_sp_port,
};
struct notifier_block *nb;
int err;
nb = &mlxsw_sp_bridge_port_replay_switchdev_objs_nb;
err = switchdev_bridge_port_replay(bridge_port->dev, mlxsw_sp_port->dev,
&rso, NULL, nb, extack);
if (err)
goto err_replay;
return 0;
err_replay:
nb = &mlxsw_sp_bridge_port_unreplay_switchdev_objs_nb;
switchdev_bridge_port_replay(bridge_port->dev, mlxsw_sp_port->dev,
&rso, NULL, nb, extack);
return err;
}
static int
mlxsw_sp_bridge_vlan_aware_port_join(struct mlxsw_sp_bridge_port *bridge_port,
struct mlxsw_sp_port *mlxsw_sp_port,
......@@ -2364,7 +2476,7 @@ mlxsw_sp_bridge_vlan_aware_port_join(struct mlxsw_sp_bridge_port *bridge_port,
if (mlxsw_sp_port->default_vlan->fid)
mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port->default_vlan);
return 0;
return mlxsw_sp_bridge_port_replay(bridge_port, mlxsw_sp_port, extack);
}
static int
......@@ -2536,6 +2648,7 @@ mlxsw_sp_bridge_8021d_port_join(struct mlxsw_sp_bridge_device *bridge_device,
struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
struct net_device *dev = bridge_port->dev;
u16 vid;
int err;
vid = is_vlan_dev(dev) ? vlan_dev_vlan_id(dev) : MLXSW_SP_DEFAULT_VID;
mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
......@@ -2551,8 +2664,20 @@ mlxsw_sp_bridge_8021d_port_join(struct mlxsw_sp_bridge_device *bridge_device,
if (mlxsw_sp_port_vlan->fid)
mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port_vlan);
return mlxsw_sp_port_vlan_bridge_join(mlxsw_sp_port_vlan, bridge_port,
extack);
err = mlxsw_sp_port_vlan_bridge_join(mlxsw_sp_port_vlan, bridge_port,
extack);
if (err)
return err;
err = mlxsw_sp_bridge_port_replay(bridge_port, mlxsw_sp_port, extack);
if (err)
goto err_replay;
return 0;
err_replay:
mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
return err;
}
static void
......@@ -2769,8 +2894,15 @@ int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
if (err)
goto err_port_join;
err = mlxsw_sp_netdevice_enslavement_replay(mlxsw_sp, br_dev, extack);
if (err)
goto err_replay;
return 0;
err_replay:
bridge_device->ops->port_leave(bridge_device, bridge_port,
mlxsw_sp_port);
err_port_join:
mlxsw_sp_bridge_port_put(mlxsw_sp->bridge, bridge_port);
return err;
......
......@@ -231,6 +231,7 @@ enum switchdev_notifier_type {
SWITCHDEV_BRPORT_OFFLOADED,
SWITCHDEV_BRPORT_UNOFFLOADED,
SWITCHDEV_BRPORT_REPLAY,
};
struct switchdev_notifier_info {
......@@ -299,6 +300,11 @@ void switchdev_bridge_port_unoffload(struct net_device *brport_dev,
const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb);
int switchdev_bridge_port_replay(struct net_device *brport_dev,
struct net_device *dev, const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb,
struct netlink_ext_ack *extack);
void switchdev_deferred_process(void);
int switchdev_port_attr_set(struct net_device *dev,
......
......@@ -234,6 +234,14 @@ static int br_switchdev_blocking_event(struct notifier_block *nb,
br_switchdev_port_unoffload(p, b->ctx, b->atomic_nb,
b->blocking_nb);
break;
case SWITCHDEV_BRPORT_REPLAY:
brport_info = ptr;
b = &brport_info->brport;
err = br_switchdev_port_replay(p, b->dev, b->ctx, b->atomic_nb,
b->blocking_nb, extack);
err = notifier_from_errno(err);
break;
}
out:
......
......@@ -2118,6 +2118,12 @@ void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb);
int br_switchdev_port_replay(struct net_bridge_port *p,
struct net_device *dev, const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb,
struct netlink_ext_ack *extack);
bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb);
void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb);
......@@ -2168,6 +2174,16 @@ br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
{
}
static inline int
br_switchdev_port_replay(struct net_bridge_port *p,
struct net_device *dev, const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb,
struct netlink_ext_ack *extack)
{
return -EOPNOTSUPP;
}
static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb)
{
return false;
......
......@@ -727,6 +727,8 @@ br_switchdev_mdb_replay(struct net_device *br_dev, struct net_device *dev,
err = br_switchdev_mdb_replay_one(nb, dev,
SWITCHDEV_OBJ_PORT_MDB(obj),
action, ctx, extack);
if (err == -EOPNOTSUPP)
err = 0;
if (err)
goto out_free_mdb;
}
......@@ -759,8 +761,10 @@ static int nbp_switchdev_sync_objs(struct net_bridge_port *p, const void *ctx,
err = br_switchdev_mdb_replay(br_dev, dev, ctx, true, blocking_nb,
extack);
if (err && err != -EOPNOTSUPP)
if (err) {
/* -EOPNOTSUPP not propagated from MDB replay. */
return err;
}
err = br_switchdev_fdb_replay(br_dev, ctx, true, atomic_nb);
if (err && err != -EOPNOTSUPP)
......@@ -825,3 +829,12 @@ void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx,
nbp_switchdev_del(p);
}
int br_switchdev_port_replay(struct net_bridge_port *p,
struct net_device *dev, const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb,
struct netlink_ext_ack *extack)
{
return nbp_switchdev_sync_objs(p, ctx, atomic_nb, blocking_nb, extack);
}
......@@ -862,3 +862,28 @@ void switchdev_bridge_port_unoffload(struct net_device *brport_dev,
NULL);
}
EXPORT_SYMBOL_GPL(switchdev_bridge_port_unoffload);
int switchdev_bridge_port_replay(struct net_device *brport_dev,
struct net_device *dev, const void *ctx,
struct notifier_block *atomic_nb,
struct notifier_block *blocking_nb,
struct netlink_ext_ack *extack)
{
struct switchdev_notifier_brport_info brport_info = {
.brport = {
.dev = dev,
.ctx = ctx,
.atomic_nb = atomic_nb,
.blocking_nb = blocking_nb,
},
};
int err;
ASSERT_RTNL();
err = call_switchdev_blocking_notifiers(SWITCHDEV_BRPORT_REPLAY,
brport_dev, &brport_info.info,
extack);
return notifier_to_errno(err);
}
EXPORT_SYMBOL_GPL(switchdev_bridge_port_replay);
......@@ -16,7 +16,6 @@ ALL_TESTS="
bridge_deletion_test
bridge_vlan_flags_test
vlan_1_test
lag_bridge_upper_test
duplicate_vlans_test
vlan_rif_refcount_test
subport_rif_refcount_test
......@@ -211,33 +210,6 @@ vlan_1_test()
ip link del dev $swp1.1
}
lag_bridge_upper_test()
{
# Test that ports cannot be enslaved to LAG devices that have uppers
# and that failure is handled gracefully. See commit b3529af6bb0d
# ("spectrum: Reference count VLAN entries") for more details
RET=0
ip link add name bond1 type bond mode 802.3ad
ip link add name br0 type bridge vlan_filtering 1
ip link set dev bond1 master br0
ip link set dev $swp1 down
ip link set dev $swp1 master bond1 &> /dev/null
check_fail $? "managed to enslave port to lag when should not"
# This might generate a trace, if we did not handle the failure
# correctly
ip -6 address add 2001:db8:1::1/64 dev $swp1
ip -6 address del 2001:db8:1::1/64 dev $swp1
log_test "lag with bridge upper"
ip link del dev br0
ip link del dev bond1
}
duplicate_vlans_test()
{
# Test that on a given port a VLAN is only used once. Either as VLAN
......@@ -510,9 +482,6 @@ vlan_interface_uppers_test()
ip link set dev $swp1 master br0
ip link add link br0 name br0.10 type vlan id 10
ip link add link br0.10 name macvlan0 \
type macvlan mode private &> /dev/null
check_fail $? "managed to create a macvlan when should not"
ip -6 address add 2001:db8:1::1/64 dev br0.10
ip link add link br0.10 name macvlan0 type macvlan mode private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment