Commit 7271174f authored by David S. Miller's avatar David S. Miller

Merge branch 'bonding_netlink'

Scott Feldman says:

====================
bonding: add some more netlink attributes

The following series implements five more bonding netlink attributes:

	primary
	primary_reselect
	fail_over_mac
	xmit_hash_policy
	resend_igmp

Tested with modified iproute2 to verify attributes can be set at bond creation
time or set later.  Verified sysfs interface to attributes continues to work.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c3bd8549 d8838de7
...@@ -32,6 +32,11 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { ...@@ -32,6 +32,11 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
[IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED }, [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED },
[IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 }, [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 },
[IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 }, [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 },
[IFLA_BOND_PRIMARY] = { .type = NLA_U32 },
[IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 },
[IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 },
[IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 },
[IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 },
}; };
static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
...@@ -154,6 +159,51 @@ static int bond_changelink(struct net_device *bond_dev, ...@@ -154,6 +159,51 @@ static int bond_changelink(struct net_device *bond_dev,
if (err) if (err)
return err; return err;
} }
if (data[IFLA_BOND_PRIMARY]) {
int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]);
struct net_device *dev;
char *primary = "";
dev = __dev_get_by_index(dev_net(bond_dev), ifindex);
if (dev)
primary = dev->name;
err = bond_option_primary_set(bond, primary);
if (err)
return err;
}
if (data[IFLA_BOND_PRIMARY_RESELECT]) {
int primary_reselect =
nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
err = bond_option_primary_reselect_set(bond, primary_reselect);
if (err)
return err;
}
if (data[IFLA_BOND_FAIL_OVER_MAC]) {
int fail_over_mac =
nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
err = bond_option_fail_over_mac_set(bond, fail_over_mac);
if (err)
return err;
}
if (data[IFLA_BOND_XMIT_HASH_POLICY]) {
int xmit_hash_policy =
nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);
err = bond_option_xmit_hash_policy_set(bond, xmit_hash_policy);
if (err)
return err;
}
if (data[IFLA_BOND_RESEND_IGMP]) {
int resend_igmp =
nla_get_u32(data[IFLA_BOND_RESEND_IGMP]);
err = bond_option_resend_igmp_set(bond, resend_igmp);
if (err)
return err;
}
return 0; return 0;
} }
...@@ -182,6 +232,11 @@ static size_t bond_get_size(const struct net_device *bond_dev) ...@@ -182,6 +232,11 @@ static size_t bond_get_size(const struct net_device *bond_dev)
nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS + nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */
0; 0;
} }
...@@ -241,6 +296,27 @@ static int bond_fill_info(struct sk_buff *skb, ...@@ -241,6 +296,27 @@ static int bond_fill_info(struct sk_buff *skb,
bond->params.arp_all_targets)) bond->params.arp_all_targets))
goto nla_put_failure; goto nla_put_failure;
if (bond->primary_slave &&
nla_put_u32(skb, IFLA_BOND_PRIMARY,
bond->primary_slave->dev->ifindex))
goto nla_put_failure;
if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
bond->params.primary_reselect))
goto nla_put_failure;
if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
bond->params.fail_over_mac))
goto nla_put_failure;
if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY,
bond->params.xmit_policy))
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP,
bond->params.resend_igmp))
goto nla_put_failure;
return 0; return 0;
nla_put_failure: nla_put_failure:
......
...@@ -467,3 +467,112 @@ int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets) ...@@ -467,3 +467,112 @@ int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets)
return 0; return 0;
} }
int bond_option_primary_set(struct bonding *bond, const char *primary)
{
struct list_head *iter;
struct slave *slave;
int err = 0;
block_netpoll_tx();
read_lock(&bond->lock);
write_lock_bh(&bond->curr_slave_lock);
if (!USES_PRIMARY(bond->params.mode)) {
pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
bond->dev->name, bond->dev->name, bond->params.mode);
err = -EINVAL;
goto out;
}
/* check to see if we are clearing primary */
if (!strlen(primary)) {
pr_info("%s: Setting primary slave to None.\n",
bond->dev->name);
bond->primary_slave = NULL;
memset(bond->params.primary, 0, sizeof(bond->params.primary));
bond_select_active_slave(bond);
goto out;
}
bond_for_each_slave(bond, slave, iter) {
if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
pr_info("%s: Setting %s as primary slave.\n",
bond->dev->name, slave->dev->name);
bond->primary_slave = slave;
strcpy(bond->params.primary, slave->dev->name);
bond_select_active_slave(bond);
goto out;
}
}
strncpy(bond->params.primary, primary, IFNAMSIZ);
bond->params.primary[IFNAMSIZ - 1] = 0;
pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
bond->dev->name, primary, bond->dev->name);
out:
write_unlock_bh(&bond->curr_slave_lock);
read_unlock(&bond->lock);
unblock_netpoll_tx();
return err;
}
int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
{
bond->params.primary_reselect = primary_reselect;
pr_info("%s: setting primary_reselect to %s (%d).\n",
bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
primary_reselect);
block_netpoll_tx();
write_lock_bh(&bond->curr_slave_lock);
bond_select_active_slave(bond);
write_unlock_bh(&bond->curr_slave_lock);
unblock_netpoll_tx();
return 0;
}
int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac)
{
if (bond_has_slaves(bond)) {
pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
bond->dev->name);
return -EPERM;
}
bond->params.fail_over_mac = fail_over_mac;
pr_info("%s: Setting fail_over_mac to %s (%d).\n",
bond->dev->name, fail_over_mac_tbl[fail_over_mac].modename,
fail_over_mac);
return 0;
}
int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy)
{
bond->params.xmit_policy = xmit_hash_policy;
pr_info("%s: setting xmit hash policy to %s (%d).\n",
bond->dev->name,
xmit_hashtype_tbl[xmit_hash_policy].modename, xmit_hash_policy);
return 0;
}
int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp)
{
if (resend_igmp < 0 || resend_igmp > 255) {
pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
bond->dev->name, resend_igmp);
return -EINVAL;
}
bond->params.resend_igmp = resend_igmp;
pr_info("%s: Setting resend_igmp to %d.\n",
bond->dev->name, resend_igmp);
return 0;
}
...@@ -318,7 +318,7 @@ static ssize_t bonding_store_xmit_hash(struct device *d, ...@@ -318,7 +318,7 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int new_value, ret = count; int new_value, ret;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
new_value = bond_parse_parm(buf, xmit_hashtype_tbl); new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
...@@ -326,14 +326,17 @@ static ssize_t bonding_store_xmit_hash(struct device *d, ...@@ -326,14 +326,17 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n", pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
bond->dev->name, bond->dev->name,
(int)strlen(buf) - 1, buf); (int)strlen(buf) - 1, buf);
ret = -EINVAL; return -EINVAL;
} else {
bond->params.xmit_policy = new_value;
pr_info("%s: setting xmit hash policy to %s (%d).\n",
bond->dev->name,
xmit_hashtype_tbl[new_value].modename, new_value);
} }
if (!rtnl_trylock())
return restart_syscall();
ret = bond_option_xmit_hash_policy_set(bond, new_value);
if (!ret)
ret = count;
rtnl_unlock();
return ret; return ret;
} }
static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
...@@ -442,33 +445,23 @@ static ssize_t bonding_store_fail_over_mac(struct device *d, ...@@ -442,33 +445,23 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int new_value, ret = count; int new_value, ret;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
if (!rtnl_trylock())
return restart_syscall();
if (bond_has_slaves(bond)) {
pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
bond->dev->name);
ret = -EPERM;
goto out;
}
new_value = bond_parse_parm(buf, fail_over_mac_tbl); new_value = bond_parse_parm(buf, fail_over_mac_tbl);
if (new_value < 0) { if (new_value < 0) {
pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
bond->dev->name, buf); bond->dev->name, buf);
ret = -EINVAL; return -EINVAL;
goto out;
} }
bond->params.fail_over_mac = new_value; if (!rtnl_trylock())
pr_info("%s: Setting fail_over_mac to %s (%d).\n", return restart_syscall();
bond->dev->name, fail_over_mac_tbl[new_value].modename,
new_value); ret = bond_option_fail_over_mac_set(bond, new_value);
if (!ret)
ret = count;
out:
rtnl_unlock(); rtnl_unlock();
return ret; return ret;
} }
...@@ -871,56 +864,22 @@ static ssize_t bonding_store_primary(struct device *d, ...@@ -871,56 +864,22 @@ static ssize_t bonding_store_primary(struct device *d,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
struct slave *slave; int ret;
if (!rtnl_trylock())
return restart_syscall();
block_netpoll_tx();
write_lock_bh(&bond->curr_slave_lock);
if (!USES_PRIMARY(bond->params.mode)) {
pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
bond->dev->name, bond->dev->name, bond->params.mode);
goto out;
}
sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
if (ifname[0] == '\n')
ifname[0] = '\0';
/* check to see if we are clearing primary */ if (!rtnl_trylock())
if (!strlen(ifname) || buf[0] == '\n') { return restart_syscall();
pr_info("%s: Setting primary slave to None.\n",
bond->dev->name);
bond->primary_slave = NULL;
memset(bond->params.primary, 0, sizeof(bond->params.primary));
bond_select_active_slave(bond);
goto out;
}
bond_for_each_slave(bond, slave, iter) {
if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
pr_info("%s: Setting %s as primary slave.\n",
bond->dev->name, slave->dev->name);
bond->primary_slave = slave;
strcpy(bond->params.primary, slave->dev->name);
bond_select_active_slave(bond);
goto out;
}
}
strncpy(bond->params.primary, ifname, IFNAMSIZ); ret = bond_option_primary_set(bond, ifname);
bond->params.primary[IFNAMSIZ - 1] = 0; if (!ret)
ret = count;
pr_info("%s: Recording %s as primary, "
"but it has not been enslaved to %s yet.\n",
bond->dev->name, ifname, bond->dev->name);
out:
write_unlock_bh(&bond->curr_slave_lock);
unblock_netpoll_tx();
rtnl_unlock(); rtnl_unlock();
return ret;
return count;
} }
static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
bonding_show_primary, bonding_store_primary); bonding_show_primary, bonding_store_primary);
...@@ -943,32 +902,24 @@ static ssize_t bonding_store_primary_reselect(struct device *d, ...@@ -943,32 +902,24 @@ static ssize_t bonding_store_primary_reselect(struct device *d,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int new_value, ret = count; int new_value, ret;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
if (!rtnl_trylock())
return restart_syscall();
new_value = bond_parse_parm(buf, pri_reselect_tbl); new_value = bond_parse_parm(buf, pri_reselect_tbl);
if (new_value < 0) { if (new_value < 0) {
pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
bond->dev->name, bond->dev->name,
(int) strlen(buf) - 1, buf); (int) strlen(buf) - 1, buf);
ret = -EINVAL; return -EINVAL;
goto out;
} }
bond->params.primary_reselect = new_value; if (!rtnl_trylock())
pr_info("%s: setting primary_reselect to %s (%d).\n", return restart_syscall();
bond->dev->name, pri_reselect_tbl[new_value].modename,
new_value); ret = bond_option_primary_reselect_set(bond, new_value);
if (!ret)
ret = count;
block_netpoll_tx();
write_lock_bh(&bond->curr_slave_lock);
bond_select_active_slave(bond);
write_unlock_bh(&bond->curr_slave_lock);
unblock_netpoll_tx();
out:
rtnl_unlock(); rtnl_unlock();
return ret; return ret;
} }
...@@ -1385,21 +1336,17 @@ static ssize_t bonding_store_resend_igmp(struct device *d, ...@@ -1385,21 +1336,17 @@ static ssize_t bonding_store_resend_igmp(struct device *d,
if (sscanf(buf, "%d", &new_value) != 1) { if (sscanf(buf, "%d", &new_value) != 1) {
pr_err("%s: no resend_igmp value specified.\n", pr_err("%s: no resend_igmp value specified.\n",
bond->dev->name); bond->dev->name);
ret = -EINVAL; return -EINVAL;
goto out;
} }
if (new_value < 0 || new_value > 255) { if (!rtnl_trylock())
pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", return restart_syscall();
bond->dev->name, new_value);
ret = -EINVAL;
goto out;
}
pr_info("%s: Setting resend_igmp to %d.\n", ret = bond_option_resend_igmp_set(bond, new_value);
bond->dev->name, new_value); if (!ret)
bond->params.resend_igmp = new_value; ret = count;
out:
rtnl_unlock();
return ret; return ret;
} }
......
...@@ -454,6 +454,13 @@ int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); ...@@ -454,6 +454,13 @@ int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target); int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
int bond_option_arp_validate_set(struct bonding *bond, int arp_validate); int bond_option_arp_validate_set(struct bonding *bond, int arp_validate);
int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets); int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets);
int bond_option_primary_set(struct bonding *bond, const char *primary);
int bond_option_primary_reselect_set(struct bonding *bond,
int primary_reselect);
int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac);
int bond_option_xmit_hash_policy_set(struct bonding *bond,
int xmit_hash_policy);
int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp);
struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
struct net_device *bond_option_active_slave_get(struct bonding *bond); struct net_device *bond_option_active_slave_get(struct bonding *bond);
......
...@@ -339,6 +339,11 @@ enum { ...@@ -339,6 +339,11 @@ enum {
IFLA_BOND_ARP_IP_TARGET, IFLA_BOND_ARP_IP_TARGET,
IFLA_BOND_ARP_VALIDATE, IFLA_BOND_ARP_VALIDATE,
IFLA_BOND_ARP_ALL_TARGETS, IFLA_BOND_ARP_ALL_TARGETS,
IFLA_BOND_PRIMARY,
IFLA_BOND_PRIMARY_RESELECT,
IFLA_BOND_FAIL_OVER_MAC,
IFLA_BOND_XMIT_HASH_POLICY,
IFLA_BOND_RESEND_IGMP,
__IFLA_BOND_MAX, __IFLA_BOND_MAX,
}; };
......
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