@@ -707,6 +707,45 @@ static bool prestera_lag_master_check(struct net_device *lag_dev,
return true;
}
+static int prestera_prechangeupper_sanity_checks(struct net_device *dev,
+ struct net_device *upper,
+ struct netdev_notifier_changeupper_info *info,
+ struct netlink_ext_ack *extack)
+{
+ if (!netif_is_bridge_master(upper) &&
+ !netif_is_lag_master(upper)) {
+ NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
+ return -EINVAL;
+ }
+
+ if (!info->linking)
+ return 0;
+
+ if (netdev_has_any_upper_dev(upper)) {
+ NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved");
+ return -EINVAL;
+ }
+
+ if (netif_is_lag_master(upper) &&
+ !prestera_lag_master_check(upper, info->upper_info, extack))
+ return -EOPNOTSUPP;
+
+ if (netif_is_lag_master(upper) && vlan_uses_dev(dev)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Master device is a LAG master and port has a VLAN");
+ return -EINVAL;
+ }
+
+ if (netif_is_lag_port(dev) && is_vlan_dev(upper) &&
+ !netif_is_lag_master(vlan_dev_real_dev(upper))) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Can not put a VLAN on a LAG port");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int prestera_netdev_port_event(struct net_device *lower,
struct net_device *dev,
unsigned long event, void *ptr)
@@ -715,40 +754,18 @@ static int prestera_netdev_port_event(struct net_device *lower,
struct prestera_port *port = netdev_priv(dev);
struct netlink_ext_ack *extack;
struct net_device *upper;
+ int err;
extack = netdev_notifier_info_to_extack(&info->info);
upper = info->upper_dev;
switch (event) {
case NETDEV_PRECHANGEUPPER:
- if (!netif_is_bridge_master(upper) &&
- !netif_is_lag_master(upper)) {
- NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
- return -EINVAL;
- }
-
- if (!info->linking)
- break;
-
- if (netdev_has_any_upper_dev(upper)) {
- NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved");
- return -EINVAL;
- }
+ err = prestera_prechangeupper_sanity_checks(dev, upper, info,
+ extack);
+ if (err)
+ return err;
- if (netif_is_lag_master(upper) &&
- !prestera_lag_master_check(upper, info->upper_info, extack))
- return -EOPNOTSUPP;
- if (netif_is_lag_master(upper) && vlan_uses_dev(dev)) {
- NL_SET_ERR_MSG_MOD(extack,
- "Master device is a LAG master and port has a VLAN");
- return -EINVAL;
- }
- if (netif_is_lag_port(dev) && is_vlan_dev(upper) &&
- !netif_is_lag_master(vlan_dev_real_dev(upper))) {
- NL_SET_ERR_MSG_MOD(extack,
- "Can not put a VLAN on a LAG port");
- return -EINVAL;
- }
break;
case NETDEV_CHANGEUPPER:
In preparation of adding more code to the NETDEV_PRECHANGEUPPER handler, move the existing sanity checks into a dedicated function. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> --- .../ethernet/marvell/prestera/prestera_main.c | 71 ++++++++++++------- 1 file changed, 44 insertions(+), 27 deletions(-)