[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210712152142.800651-7-vladimir.oltean@nxp.com>
Date: Mon, 12 Jul 2021 18:21:24 +0300
From: Vladimir Oltean <vladimir.oltean@....com>
To: netdev@...r.kernel.org, Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>
Cc: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Vivien Didelot <vivien.didelot@...il.com>,
Jiri Pirko <jiri@...nulli.us>,
Ido Schimmel <idosch@...sch.org>,
Tobias Waldekranz <tobias@...dekranz.com>,
Roopa Prabhu <roopa@...dia.com>,
Nikolay Aleksandrov <nikolay@...dia.com>,
Stephen Hemminger <stephen@...workplumber.org>,
bridge@...ts.linux-foundation.org,
Grygorii Strashko <grygorii.strashko@...com>
Subject: [RFC PATCH v3 net-next 06/24] net: prestera: refactor prechangeupper sanity checks
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@....com>
---
.../ethernet/marvell/prestera/prestera_main.c | 71 ++++++++++++-------
1 file changed, 44 insertions(+), 27 deletions(-)
diff --git a/drivers/net/ethernet/marvell/prestera/prestera_main.c b/drivers/net/ethernet/marvell/prestera/prestera_main.c
index 979214ce1952..508c03cc8edb 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_main.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_main.c
@@ -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:
--
2.25.1
Powered by blists - more mailing lists