Commit 9f53e14e authored by sfeldma@cumulusnetworks.com's avatar sfeldma@cumulusnetworks.com Committed by David S. Miller

bonding: add use_carrier netlink support

Add IFLA_BOND_USE_CARRIER to allow get/set of bonding parameter
use_carrier via netlink.
Signed-off-by: default avatarScott Feldman <sfeldma@cumulusnetworks.com>
Signed-off-by: default avatarJiri Pirko <jiri@resnulli.us>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c7461f9b
...@@ -27,6 +27,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { ...@@ -27,6 +27,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
[IFLA_BOND_MIIMON] = { .type = NLA_U32 }, [IFLA_BOND_MIIMON] = { .type = NLA_U32 },
[IFLA_BOND_UPDELAY] = { .type = NLA_U32 }, [IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
[IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 }, [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
[IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
}; };
static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
...@@ -93,6 +94,13 @@ static int bond_changelink(struct net_device *bond_dev, ...@@ -93,6 +94,13 @@ static int bond_changelink(struct net_device *bond_dev,
if (err) if (err)
return err; return err;
} }
if (data[IFLA_BOND_USE_CARRIER]) {
int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]);
err = bond_option_use_carrier_set(bond, use_carrier);
if (err)
return err;
}
return 0; return 0;
} }
...@@ -115,6 +123,7 @@ static size_t bond_get_size(const struct net_device *bond_dev) ...@@ -115,6 +123,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */ nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
0; 0;
} }
...@@ -142,6 +151,9 @@ static int bond_fill_info(struct sk_buff *skb, ...@@ -142,6 +151,9 @@ static int bond_fill_info(struct sk_buff *skb,
bond->params.downdelay * bond->params.miimon)) bond->params.downdelay * bond->params.miimon))
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
goto nla_put_failure;
return 0; return 0;
nla_put_failure: nla_put_failure:
......
...@@ -245,3 +245,17 @@ int bond_option_downdelay_set(struct bonding *bond, int downdelay) ...@@ -245,3 +245,17 @@ int bond_option_downdelay_set(struct bonding *bond, int downdelay)
return 0; return 0;
} }
int bond_option_use_carrier_set(struct bonding *bond, int use_carrier)
{
if ((use_carrier == 0) || (use_carrier == 1)) {
bond->params.use_carrier = use_carrier;
pr_info("%s: Setting use_carrier to %d.\n",
bond->dev->name, use_carrier);
} else {
pr_info("%s: Ignoring invalid use_carrier value %d.\n",
bond->dev->name, use_carrier);
}
return 0;
}
...@@ -1097,25 +1097,23 @@ static ssize_t bonding_store_carrier(struct device *d, ...@@ -1097,25 +1097,23 @@ static ssize_t bonding_store_carrier(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 (sscanf(buf, "%d", &new_value) != 1) { if (sscanf(buf, "%d", &new_value) != 1) {
pr_err("%s: no use_carrier value specified.\n", pr_err("%s: no use_carrier value specified.\n",
bond->dev->name); bond->dev->name);
ret = -EINVAL; return -EINVAL;
goto out;
}
if ((new_value == 0) || (new_value == 1)) {
bond->params.use_carrier = new_value;
pr_info("%s: Setting use_carrier to %d.\n",
bond->dev->name, new_value);
} else {
pr_info("%s: Ignoring invalid use_carrier value %d.\n",
bond->dev->name, new_value);
} }
out:
if (!rtnl_trylock())
return restart_syscall();
ret = bond_option_use_carrier_set(bond, new_value);
if (!ret)
ret = count;
rtnl_unlock();
return ret; return ret;
} }
static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
......
...@@ -442,6 +442,7 @@ int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_ ...@@ -442,6 +442,7 @@ int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_
int bond_option_miimon_set(struct bonding *bond, int miimon); int bond_option_miimon_set(struct bonding *bond, int miimon);
int bond_option_updelay_set(struct bonding *bond, int updelay); int bond_option_updelay_set(struct bonding *bond, int updelay);
int bond_option_downdelay_set(struct bonding *bond, int downdelay); int bond_option_downdelay_set(struct bonding *bond, int downdelay);
int bond_option_use_carrier_set(struct bonding *bond, int use_carrier);
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);
......
...@@ -334,6 +334,7 @@ enum { ...@@ -334,6 +334,7 @@ enum {
IFLA_BOND_MIIMON, IFLA_BOND_MIIMON,
IFLA_BOND_UPDELAY, IFLA_BOND_UPDELAY,
IFLA_BOND_DOWNDELAY, IFLA_BOND_DOWNDELAY,
IFLA_BOND_USE_CARRIER,
__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