Skip to contentSkip to conversation

bonding: introduce bonding options Netlink support

PATCH In review Jiri Pirko 5 participants 13 messages Oct 18, 2013 – Oct 30, 2013

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

cover bonding: introduce bonding options Netlink support

This patchset basically allows "mode" and "active_slave" bonding options to be propagated and set up via standart RT Netlink interface.

In future other options can be easily added as well.

Jiri Pirko (7):
bonding: push Netlink bits into separate file
bonding: move mode setting into separate function
bonding: move active_slave setting into separate function
bonding: remove bond_ioctl_change_active()
bonding: move active_slave getting into separate function
bonding: add Netlink support mode option
bonding: add Netlink support active_slave option

 drivers/net/bonding/Makefile       |   2 +-
 drivers/net/bonding/bond_main.c    |  91 ++----------------------
 drivers/net/bonding/bond_netlink.c | 131 ++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_options.c | 142 +++++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   | 127 ++++++++-------------------------
 drivers/net/bonding/bonding.h      |  19 ++++-
 include/uapi/linux/if_link.h       |  11 +++
 7 files changed, 337 insertions(+), 186 deletions(-)
 create mode 100644 drivers/net/bonding/bond_netlink.c
 create mode 100644 drivers/net/bonding/bond_options.c
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/7 bonding: push Netlink bits into separate file

---
 drivers/net/bonding/Makefile       |  2 +-
 drivers/net/bonding/bond_main.c    | 32 ++++------------------
 drivers/net/bonding/bond_netlink.c | 54 ++++++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bonding.h      |  7 +++++
 4 files changed, 67 insertions(+), 28 deletions(-)
 create mode 100644 drivers/net/bonding/bond_netlink.c
drivers/net/bonding/Makefile +1 -1
index 4c21bf6..09e8b2c 100644
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_BONDING) += bonding.o
 
-bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o
+bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o
 
 proc-$(CONFIG_PROC_FS) += bond_procfs.o
 bonding-objs += $(proc-y)
drivers/net/bonding/bond_main.c +5 -27
index dfb4f6d..a113e42 100644
@@ -3951,7 +3951,7 @@ static void bond_destructor(struct net_device *bond_dev)
 	free_netdev(bond_dev);
 }
 
-static void bond_setup(struct net_device *bond_dev)
+void bond_setup(struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
 
@@ -4451,32 +4451,11 @@ static int bond_init(struct net_device *bond_dev)
 	return 0;
 }
 
-static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
-{
-	if (tb[IFLA_ADDRESS]) {
-		if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
-			return -EINVAL;
-		if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
-			return -EADDRNOTAVAIL;
-	}
-	return 0;
-}
-
-static unsigned int bond_get_num_tx_queues(void)
+unsigned int bond_get_num_tx_queues(void)
 {
 	return tx_queues;
 }
 
-static struct rtnl_link_ops bond_link_ops __read_mostly = {
-	.kind			= "bond",
-	.priv_size		= sizeof(struct bonding),
-	.setup			= bond_setup,
-	.validate		= bond_validate,
-	.get_num_tx_queues	= bond_get_num_tx_queues,
-	.get_num_rx_queues	= bond_get_num_tx_queues, /* Use the same number
-							     as for TX queues */
-};
-
 /* Create a new bond based on the specified name and bonding parameters.
  * If name is NULL, obtain a suitable "bond%d" name for us.
  * Caller must NOT hold rtnl_lock; we need to release it here before we
@@ -4563,7 +4542,7 @@ static int __init bonding_init(void)
 	if (res)
 		goto out;
 
-	res = rtnl_link_register(&bond_link_ops);
+	res = bond_netlink_init();
 	if (res)
 		goto err_link;
 
@@ -4579,7 +4558,7 @@ static int __init bonding_init(void)
 out:
 	return res;
 err:
-	rtnl_link_unregister(&bond_link_ops);
+	bond_netlink_fini();
 err_link:
 	unregister_pernet_subsys(&bond_net_ops);
 	goto out;
@@ -4592,7 +4571,7 @@ static void __exit bonding_exit(void)
 
 	bond_destroy_debugfs();
 
-	rtnl_link_unregister(&bond_link_ops);
+	bond_netlink_fini();
 	unregister_pernet_subsys(&bond_net_ops);
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -4609,4 +4588,3 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
 MODULE_AUTHOR("Thomas Davis, [email protected] and many others");
-MODULE_ALIAS_RTNL_LINK("bond");
drivers/net/bonding/bond_netlink.c new file +54 -0

54 lines not on this page · raw message

drivers/net/bonding/bonding.h +7 -0
index bb5c731..a2a353b 100644
@@ -418,6 +418,10 @@ void bond_debug_register(struct bonding *bond);
 void bond_debug_unregister(struct bonding *bond);
 void bond_debug_reregister(struct bonding *bond);
 const char *bond_mode_name(int mode);
+void bond_setup(struct net_device *bond_dev);
+unsigned int bond_get_num_tx_queues(void);
+int bond_netlink_init(void);
+void bond_netlink_fini(void);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
@@ -505,4 +509,7 @@ extern const struct bond_parm_tbl fail_over_mac_tbl[];
 extern const struct bond_parm_tbl pri_reselect_tbl[];
 extern struct bond_parm_tbl ad_select_tbl[];
 
+/* exported from bond_netlink.c */
+extern struct rtnl_link_ops bond_link_ops;
+
 #endif /* _LINUX_BONDING_H */
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH 3/7 bonding: move active_slave setting into separate function

In reply to Jiri Pirko

Do a bit of refactoring on the way.

---
 drivers/net/bonding/bond_options.c | 69 +++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   | 74 +++++++-------------------------------
 drivers/net/bonding/bonding.h      |  1 +
 3 files changed, 83 insertions(+), 61 deletions(-)
drivers/net/bonding/bond_options.c +69 -0
index 294b766..09af5d1 100644
@@ -12,6 +12,9 @@
 
 #include <linux/errno.h>
 #include <linux/if.h>
+#include <linux/netdevice.h>
+#include <linux/rwlock.h>
+#include <linux/rcupdate.h>
 #include "bonding.h"
 
 static bool bond_mode_is_valid(int mode)
@@ -53,3 +56,69 @@ int bond_option_mode_set(struct bonding *bond, int mode)
 	bond->params.mode = mode;
 	return 0;
 }
+
+int bond_option_active_slave_set(struct bonding *bond,
+				 struct net_device *slave_dev)
+{
+	int ret = 0;
+
+	if (slave_dev) {
+		if (!netif_is_bond_slave(slave_dev)) {
+			pr_err("Device %s is not bonding slave.\n",
+			       slave_dev->name);
+			return -EINVAL;
+		}
+
+		if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
+			pr_err("%s: Device %s is not our slave.\n",
+			       bond->dev->name, slave_dev->name);
+			return -EINVAL;
+		}
+	}
+
+	if (!USES_PRIMARY(bond->params.mode)) {
+		pr_err("%s: Unable to change active slave; %s is in mode %d\n",
+		       bond->dev->name, bond->dev->name, bond->params.mode);
+		return -EINVAL;
+	}
+
+	block_netpoll_tx();
+	read_lock(&bond->lock);
+	write_lock_bh(&bond->curr_slave_lock);
+
+	/* check to see if we are clearing active */
+	if (!slave_dev) {
+		pr_info("%s: Clearing current active slave.\n",
+		bond->dev->name);
+		rcu_assign_pointer(bond->curr_active_slave, NULL);
+		bond_select_active_slave(bond);
+	} else {
+		struct slave *old_active = bond->curr_active_slave;
+		struct slave *new_active = bond_slave_get_rtnl(slave_dev);
+
+		BUG_ON(!new_active);
+
+		if (new_active == old_active) {
+			/* do nothing */
+			pr_info("%s: %s is already the current active slave.\n",
+				bond->dev->name, new_active->dev->name);
+		} else {
+			if (old_active && (new_active->link == BOND_LINK_UP) &&
+			    IS_UP(new_active->dev)) {
+				pr_info("%s: Setting %s as active slave.\n",
+					bond->dev->name, new_active->dev->name);
+				bond_change_active_slave(bond, new_active);
+			} else {
+				pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
+				       bond->dev->name, new_active->dev->name,
+				       new_active->dev->name);
+				ret = -EINVAL;
+			}
+		}
+	}
+
+	write_unlock_bh(&bond->curr_slave_lock);
+	read_unlock(&bond->lock);
+	unblock_netpoll_tx();
+	return ret;
+}
drivers/net/bonding/bond_sysfs.c +13 -61

94 lines not on this page · raw message

drivers/net/bonding/bonding.h +1 -0
index 7446849..686759d 100644
@@ -427,6 +427,7 @@ unsigned int bond_get_num_tx_queues(void);
 int bond_netlink_init(void);
 void bond_netlink_fini(void);
 int bond_option_mode_set(struct bonding *bond, int mode);
+int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_dev);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/7 bonding: move mode setting into separate function

In reply to Jiri Pirko
---
 drivers/net/bonding/Makefile       |  2 +-
 drivers/net/bonding/bond_options.c | 55 ++++++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   | 45 ++++++++-----------------------
 drivers/net/bonding/bonding.h      |  9 +++++--
 4 files changed, 74 insertions(+), 37 deletions(-)
 create mode 100644 drivers/net/bonding/bond_options.c
drivers/net/bonding/Makefile +1 -1
index 09e8b2c..5a5d720 100644
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_BONDING) += bonding.o
 
-bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o
+bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o bond_options.o
 
 proc-$(CONFIG_PROC_FS) += bond_procfs.o
 bonding-objs += $(proc-y)
drivers/net/bonding/bond_options.c new file +55 -0

55 lines not on this page · raw message

drivers/net/bonding/bond_sysfs.c +11 -34

60 lines not on this page · raw message

drivers/net/bonding/bonding.h +7 -2
index a2a353b..7446849 100644
@@ -58,6 +58,11 @@
 #define TX_QUEUE_OVERRIDE(mode)				\
 			(((mode) == BOND_MODE_ACTIVEBACKUP) ||	\
 			 ((mode) == BOND_MODE_ROUNDROBIN))
+
+#define BOND_MODE_IS_LB(mode)			\
+		(((mode) == BOND_MODE_TLB) ||	\
+		 ((mode) == BOND_MODE_ALB))
+
 /*
  * Less bad way to call ioctl from within the kernel; this needs to be
  * done some other way to get the call out of interrupt context.
@@ -259,8 +264,7 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
 
 static inline bool bond_is_lb(const struct bonding *bond)
 {
-	return (bond->params.mode == BOND_MODE_TLB ||
-		bond->params.mode == BOND_MODE_ALB);
+	return BOND_MODE_IS_LB(bond->params.mode);
 }
 
 static inline void bond_set_active_slave(struct slave *slave)
@@ -422,6 +426,7 @@ void bond_setup(struct net_device *bond_dev);
 unsigned int bond_get_num_tx_queues(void);
 int bond_netlink_init(void);
 void bond_netlink_fini(void);
+int bond_option_mode_set(struct bonding *bond, int mode);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH 4/7 bonding: remove bond_ioctl_change_active()

In reply to Jiri Pirko

no longer needed since bond_option_active_slave_set() can be used instead.

---
 drivers/net/bonding/bond_main.c | 59 ++---------------------------------------
 1 file changed, 2 insertions(+), 57 deletions(-)
drivers/net/bonding/bond_main.c +2 -57
index a113e42..d90734f 100644
@@ -1910,61 +1910,6 @@ static int  bond_release_and_destroy(struct net_device *bond_dev,
 	return ret;
 }
 
-/*
- * This function changes the active slave to slave <slave_dev>.
- * It returns -EINVAL in the following cases.
- *  - <slave_dev> is not found in the list.
- *  - There is not active slave now.
- *  - <slave_dev> is already active.
- *  - The link state of <slave_dev> is not BOND_LINK_UP.
- *  - <slave_dev> is not running.
- * In these cases, this function does nothing.
- * In the other cases, current_slave pointer is changed and 0 is returned.
- */
-static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev)
-{
-	struct bonding *bond = netdev_priv(bond_dev);
-	struct slave *old_active = NULL;
-	struct slave *new_active = NULL;
-	int res = 0;
-
-	if (!USES_PRIMARY(bond->params.mode))
-		return -EINVAL;
-
-	/* Verify that bond_dev is indeed the master of slave_dev */
-	if (!(slave_dev->flags & IFF_SLAVE) ||
-	    !netdev_has_upper_dev(slave_dev, bond_dev))
-		return -EINVAL;
-
-	read_lock(&bond->lock);
-
-	old_active = bond->curr_active_slave;
-	new_active = bond_get_slave_by_dev(bond, slave_dev);
-	/*
-	 * Changing to the current active: do nothing; return success.
-	 */
-	if (new_active && new_active == old_active) {
-		read_unlock(&bond->lock);
-		return 0;
-	}
-
-	if (new_active &&
-	    old_active &&
-	    new_active->link == BOND_LINK_UP &&
-	    IS_UP(new_active->dev)) {
-		block_netpoll_tx();
-		write_lock_bh(&bond->curr_slave_lock);
-		bond_change_active_slave(bond, new_active);
-		write_unlock_bh(&bond->curr_slave_lock);
-		unblock_netpoll_tx();
-	} else
-		res = -EINVAL;
-
-	read_unlock(&bond->lock);
-
-	return res;
-}
-
 static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
@@ -3257,6 +3202,7 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
 
 static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
 {
+	struct bonding *bond = netdev_priv(bond_dev);
 	struct net_device *slave_dev = NULL;
 	struct ifbond k_binfo;
 	struct ifbond __user *u_binfo = NULL;
@@ -3287,7 +3233,6 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 
 
 		if (mii->reg_num == 1) {
-			struct bonding *bond = netdev_priv(bond_dev);
 			mii->val_out = 0;
 			read_lock(&bond->lock);
 			read_lock(&bond->curr_slave_lock);
@@ -3359,7 +3304,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
-			res = bond_ioctl_change_active(bond_dev, slave_dev);
+			res = bond_option_active_slave_set(bond, slave_dev);
 			break;
 		default:
 			res = -EOPNOTSUPP;
Signature · 1 line
1.8.3.1
author
#5 lore raw

PATCH 5/7 bonding: move active_slave getting into separate function

In reply to Jiri Pirko
---
 drivers/net/bonding/bond_options.c | 18 ++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   |  8 ++++----
 drivers/net/bonding/bonding.h      |  2 ++
 3 files changed, 24 insertions(+), 4 deletions(-)
drivers/net/bonding/bond_options.c +18 -0
index 09af5d1..9a5223c 100644
@@ -57,6 +57,24 @@ int bond_option_mode_set(struct bonding *bond, int mode)
 	return 0;
 }
 
+static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
+							 struct slave *slave)
+{
+	return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
+}
+
+struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
+{
+	struct slave *slave = rcu_dereference(bond->curr_active_slave);
+
+	return __bond_option_active_slave_get(bond, slave);
+}
+
+struct net_device *bond_option_active_slave_get(struct bonding *bond)
+{
+	return __bond_option_active_slave_get(bond, bond->curr_active_slave);
+}
+
 int bond_option_active_slave_set(struct bonding *bond,
 				 struct net_device *slave_dev)
 {
drivers/net/bonding/bond_sysfs.c +4 -4
index abd2600..47749c9 100644
@@ -1219,13 +1219,13 @@ static ssize_t bonding_show_active_slave(struct device *d,
 					 char *buf)
 {
 	struct bonding *bond = to_bond(d);
-	struct slave *curr;
+	struct net_device *slave_dev;
 	int count = 0;
 
 	rcu_read_lock();
-	curr = rcu_dereference(bond->curr_active_slave);
-	if (USES_PRIMARY(bond->params.mode) && curr)
-		count = sprintf(buf, "%s\n", curr->dev->name);
+	slave_dev = bond_option_active_slave_get_rcu(bond);
+	if (slave_dev)
+		count = sprintf(buf, "%s\n", slave_dev->name);
 	rcu_read_unlock();
 
 	return count;
drivers/net/bonding/bonding.h +2 -0
index 686759d..046a605 100644
@@ -428,6 +428,8 @@ int bond_netlink_init(void);
 void bond_netlink_fini(void);
 int bond_option_mode_set(struct bonding *bond, int mode);
 int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_dev);
+struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
+struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
Signature · 1 line
1.8.3.1
author
#6 lore raw

PATCH 6/7 bonding: add Netlink support mode option

In reply to Jiri Pirko
---
 drivers/net/bonding/bond_netlink.c | 56 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/if_link.h       | 10 +++++++
 2 files changed, 66 insertions(+)
drivers/net/bonding/bond_netlink.c +56 -0
index 3e5c5f8..a94f870 100644
@@ -20,6 +20,10 @@
 #include <net/rtnetlink.h>
 #include "bonding.h"
 
+static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
+	[IFLA_BOND_MODE]		= { .type = NLA_U8 },
+};
+
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
 {
 	if (tb[IFLA_ADDRESS]) {
@@ -31,11 +35,63 @@ static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
 	return 0;
 }
 
+static int bond_changelink(struct net_device *bond_dev,
+			   struct nlattr *tb[], struct nlattr *data[])
+{
+	struct bonding *bond = netdev_priv(bond_dev);
+	int err;
+
+	if (data && data[IFLA_BOND_MODE]) {
+		int mode = nla_get_u8(data[IFLA_BOND_MODE]);
+
+		err = bond_option_mode_set(bond, mode);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
+static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
+			struct nlattr *tb[], struct nlattr *data[])
+{
+	int err;
+
+	err = bond_changelink(bond_dev, tb, data);
+	if (err < 0)
+		return err;
+
+	return register_netdevice(bond_dev);
+}
+
+static size_t bond_get_size(const struct net_device *bond_dev)
+{
+	return nla_total_size(sizeof(u8));	/* IFLA_BOND_MODE */
+}
+
+static int bond_fill_info(struct sk_buff *skb,
+			  const struct net_device *bond_dev)
+{
+	struct bonding *bond = netdev_priv(bond_dev);
+
+	if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
+		goto nla_put_failure;
+	return 0;
+
+nla_put_failure:
+	return -EMSGSIZE;
+}
+
 struct rtnl_link_ops bond_link_ops __read_mostly = {
 	.kind			= "bond",
 	.priv_size		= sizeof(struct bonding),
 	.setup			= bond_setup,
+	.maxtype		= IFLA_BOND_MAX,
+	.policy			= bond_policy,
 	.validate		= bond_validate,
+	.newlink		= bond_newlink,
+	.changelink		= bond_changelink,
+	.get_size		= bond_get_size,
+	.fill_info		= bond_fill_info,
 	.get_num_tx_queues	= bond_get_num_tx_queues,
 	.get_num_rx_queues	= bond_get_num_tx_queues, /* Use the same number
 							     as for TX queues */
include/uapi/linux/if_link.h +10 -0
index 80394e8..06fd3fe 100644
@@ -325,6 +325,16 @@ struct ifla_vxlan_port_range {
 	__be16	high;
 };
 
+/* Bonding section */
+
+enum {
+	IFLA_BOND_UNSPEC,
+	IFLA_BOND_MODE,
+	__IFLA_BOND_MAX,
+};
+
+#define IFLA_BOND_MAX	(__IFLA_BOND_MAX - 1)
+
 /* SR-IOV virtual function management section */
 
 enum {
Signature · 1 line
1.8.3.1
author
#7 lore raw

PATCH 7/7 bonding: add Netlink support active_slave option

In reply to Jiri Pirko
---
 drivers/net/bonding/bond_netlink.c | 23 ++++++++++++++++++++++-
 include/uapi/linux/if_link.h       |  1 +
 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/net/bonding/bond_netlink.c +22 -1
index a94f870..fe3500b 100644
@@ -22,6 +22,7 @@
 
 static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
 	[IFLA_BOND_MODE]		= { .type = NLA_U8 },
+	[IFLA_BOND_ACTIVE_SLAVE]	= { .type = NLA_U32 },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -48,6 +49,22 @@ static int bond_changelink(struct net_device *bond_dev,
 		if (err)
 			return err;
 	}
+	if (data && data[IFLA_BOND_ACTIVE_SLAVE]) {
+		int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
+		struct net_device *slave_dev;
+
+		if (ifindex == 0) {
+			slave_dev = NULL;
+		} else {
+			slave_dev = __dev_get_by_index(dev_net(bond_dev),
+						       ifindex);
+			if (!slave_dev)
+				return -ENODEV;
+		}
+		err = bond_option_active_slave_set(bond, slave_dev);
+		if (err)
+			return err;
+	}
 	return 0;
 }
 
@@ -66,14 +83,18 @@ static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
 static size_t bond_get_size(const struct net_device *bond_dev)
 {
 	return nla_total_size(sizeof(u8));	/* IFLA_BOND_MODE */
+		+ nla_total_size(sizeof(u32));	/* IFLA_BOND_ACTIVE_SLAVE */
 }
 
 static int bond_fill_info(struct sk_buff *skb,
 			  const struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
+	struct net_device *slave_dev = bond_option_active_slave_get(bond);
 
-	if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
+	if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode) ||
+	    (slave_dev &&
+	     nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)))
 		goto nla_put_failure;
 	return 0;
 
include/uapi/linux/if_link.h +1 -0
index 06fd3fe..8a1e346 100644
@@ -330,6 +330,7 @@ struct ifla_vxlan_port_range {
 enum {
 	IFLA_BOND_UNSPEC,
 	IFLA_BOND_MODE,
+	IFLA_BOND_ACTIVE_SLAVE,
 	__IFLA_BOND_MAX,
 };
 
Signature · 1 line
1.8.3.1
author
#8 lore raw

PATCH 1/1 iplink: add support for bonding netlink

In reply to Jiri Pirko
---
 include/linux/if_link.h | 11 ++++++
 ip/Makefile             |  2 +-
 ip/iplink.c             |  4 +--
 ip/iplink_bond.c        | 92 +++++++++++++++++++++++++++++++++++++++++++++++++
 man/man8/ip-link.8.in   |  4 +++
 5 files changed, 110 insertions(+), 3 deletions(-)
 create mode 100644 ip/iplink_bond.c
include/linux/if_link.h +11 -0
index ee4f2ba..3f7b343 100644
@@ -318,6 +318,17 @@ enum {
 };
 #define IFLA_VXLAN_MAX	(__IFLA_VXLAN_MAX - 1)
 
+/* Bonding section */
+
+enum {
+	IFLA_BOND_UNSPEC,
+	IFLA_BOND_MODE,
+	IFLA_BOND_ACTIVE_SLAVE,
+	__IFLA_BOND_MAX,
+};
+
+#define IFLA_BOND_MAX	(__IFLA_BOND_MAX - 1)
+
 struct ifla_vxlan_port_range {
 	__be16	low;
 	__be16	high;
ip/Makefile +1 -1
index f10d22f..89a7a36 100644
@@ -5,7 +5,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
     iplink_vlan.o link_veth.o link_gre.o iplink_can.o \
     iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o \
     iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
-    link_iptnl.o link_gre6.o
+    link_iptnl.o link_gre6.o iplink_bond.o
 
 RTMONOBJ=rtmon.o
 
ip/iplink.c +2 -2
index 6cde731..58b6c20 100644
@@ -85,8 +85,8 @@ void iplink_usage(void)
 	if (iplink_have_newlink()) {
 		fprintf(stderr, "\n");
 		fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
-		fprintf(stderr, "          can | bridge | ipoib | ip6tnl | ipip | sit | vxlan |\n");
-		fprintf(stderr, "          gre | gretap | ip6gre | ip6gretap | vti }\n");
+		fprintf(stderr, "          can | bridge | bond | ipoib | ip6tnl | ipip | sit |\n");
+		fprintf(stderr, "          vxlan | gre | gretap | ip6gre | ip6gretap | vti }\n");
 	}
 	exit(-1);
 }
ip/iplink_bond.c new file +92 -0

92 lines not on this page · raw message

man/man8/ip-link.8.in +4 -0
index 8b68c78..1825dc5 100644
@@ -51,6 +51,7 @@ ip-link \- network device configuration
 .ti -8
 .IR TYPE " := [ "
 .BR bridge " | "
+.BR bond " ]"
 .BR can " | "
 .BR dummy " | "
 .BR ifb " | "
@@ -155,6 +156,9 @@ Link types:
 .B bridge
 - Ethernet Bridge device
 .sp
+.B bond
+- Bonding device
+.sp
 .B can
 - Controller Area Network interface
 .sp
Signature · 1 line
1.8.3.1
maintainer
#12 lore raw
In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>
Date: Fri, 18 Oct 2013 17:43:32 +0200

Quoted 4 lines

This patchset basically allows "mode" and "active_slave" bonding options to be propagated and set up via standart RT Netlink interface.

In future other options can be easily added as well.

Nice work Jiri, series applied, thanks.

#9 lore raw

Re: [patch iproute2] iplink: add support for bonding netlink

In reply to Jiri Pirko

ip/iplink_bond.c line 53

Quoted 8 lines · Jiri Pirko <jiri <at> resnulli.us> writes:
ip/iplink_bond.c new file +8 -0
+		} else if (matches(*argv, "active_slave") == 0) {
+			NEXT_ARG();
+			ifindex = if_nametoindex(*argv);
+			if (!ifindex)
+				return -1;
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
+		} else if (matches(*argv, "clear_active_slave") == 0) {
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);

How do active_slave and clear_active_slave work from the ip link cmd line when bond is added, but doesn't have any slaves yet? I did:

ip link add bond1 type bond mode 1
ip link set dev eth1 master bond1
ip link set dev eth2 master bond1

Then tried:

ip link add bond1 type bond active_slave eth1
RTNETLINK answers: File exists

Or:

ip link set dev bond1 active_slave eth1
Error: either "dev" is duplicate, or "active_slave" is a garbage.

I must be dense but I can't figure how you can set active_slave before slaves have been added to bond, or even after slaves have been added to bond.

man/man8/ip-link.8.in ip-link \- network device configuration · line 54

Quoted 9 lines
man/man8/ip-link.8.in +1 -0
index 8b68c78..1825dc5 100644
 <at>  <at>  -51,6 +51,7  <at>  <at>  ip-link \- network device configuration
 .ti -8
 .IR TYPE " := [ "
 .BR bridge " | "
+.BR bond " ]"

That should be " | "?

With patch applied, the man page shows:

TYPE := [ bridge | bond ] can | dummy | ifb | ipoib | macvlan | ...

-scott

#10 lore raw

Re: [patch iproute2] iplink: add support for bonding netlink

Quoted 20 lines · Scott Feldman

ip/iplink_bond.c line 53

Quoted 8 lines · Jiri Pirko <jiri <at> resnulli.us> writes:
ip/iplink_bond.c new file +8 -0
+		} else if (matches(*argv, "active_slave") == 0) {
+			NEXT_ARG();
+			ifindex = if_nametoindex(*argv);
+			if (!ifindex)
+				return -1;
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
+		} else if (matches(*argv, "clear_active_slave") == 0) {
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);

How do active_slave and clear_active_slave work from the ip link cmd line when bond is added, but doesn't have any slaves yet? I did:

ip link add bond1 type bond mode 1
ip link set dev eth1 master bond1
ip link set dev eth2 master bond1

Then tried:

Quoted 7 lines

ip link add bond1 type bond active_slave eth1
RTNETLINK answers: File exists

Or:

ip link set dev bond1 active_slave eth1
Error: either "dev" is duplicate, or "active_slave" is a garbage.

You need to do:
ip link set dev bond1 type bond active_slave eth1

'active_slave' argument is only defined for the 'type bond' operations.

You can not set active slave before enslaving the device and this series doesn't change that.

-vlad

Quoted 28 lines

I must be dense but I can't figure how you can set active_slave before slaves have been added to bond, or even after slaves have been added to bond.

man/man8/ip-link.8.in ip-link \- network device configuration · line 54

Quoted 9 lines
man/man8/ip-link.8.in +1 -0
index 8b68c78..1825dc5 100644
  <at>  <at>  -51,6 +51,7  <at>  <at>  ip-link \- network device configuration
  .ti -8
  .IR TYPE " := [ "
  .BR bridge " | "
+.BR bond " ]"

That should be " | "?

With patch applied, the man page shows:

TYPE := [ bridge | bond ] can | dummy | ifb | ipoib | macvlan | ...

-scott

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html