提交 89901972 编写于 作者: S sfeldma@cumulusnetworks.com 提交者: David S. Miller

bonding: add fail_over_mac attribute netlink support

Add IFLA_BOND_FAIL_OVER_MAC to allow get/set of bonding parameter
fail_over_mac via netlink.
Signed-off-by: NScott Feldman <sfeldma@cumulusnetworks.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 8a41ae44
...@@ -34,6 +34,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { ...@@ -34,6 +34,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
[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] = { .type = NLA_U32 },
[IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 }, [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 },
[IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 },
}; };
static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
...@@ -177,6 +178,14 @@ static int bond_changelink(struct net_device *bond_dev, ...@@ -177,6 +178,14 @@ static int bond_changelink(struct net_device *bond_dev,
if (err) if (err)
return 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;
}
return 0; return 0;
} }
...@@ -207,6 +216,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) ...@@ -207,6 +216,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
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(u32)) + /* IFLA_BOND_PRIMARY */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */ nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
0; 0;
} }
...@@ -275,6 +285,10 @@ static int bond_fill_info(struct sk_buff *skb, ...@@ -275,6 +285,10 @@ static int bond_fill_info(struct sk_buff *skb,
bond->params.primary_reselect)) bond->params.primary_reselect))
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
bond->params.fail_over_mac))
goto nla_put_failure;
return 0; return 0;
nla_put_failure: nla_put_failure:
......
...@@ -535,3 +535,19 @@ int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect) ...@@ -535,3 +535,19 @@ int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
return 0; 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;
}
...@@ -442,33 +442,23 @@ static ssize_t bonding_store_fail_over_mac(struct device *d, ...@@ -442,33 +442,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;
} }
......
...@@ -457,6 +457,7 @@ int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets); ...@@ -457,6 +457,7 @@ 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_set(struct bonding *bond, const char *primary);
int bond_option_primary_reselect_set(struct bonding *bond, int bond_option_primary_reselect_set(struct bonding *bond,
int primary_reselect); int primary_reselect);
int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac);
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);
......
...@@ -341,6 +341,7 @@ enum { ...@@ -341,6 +341,7 @@ enum {
IFLA_BOND_ARP_ALL_TARGETS, IFLA_BOND_ARP_ALL_TARGETS,
IFLA_BOND_PRIMARY, IFLA_BOND_PRIMARY,
IFLA_BOND_PRIMARY_RESELECT, IFLA_BOND_PRIMARY_RESELECT,
IFLA_BOND_FAIL_OVER_MAC,
__IFLA_BOND_MAX, __IFLA_BOND_MAX,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册