Commit 0aac68f7 authored by David S. Miller's avatar David S. Miller

Merge branch 'bonding_netlink'

Scott Feldman says:

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

v2:

Addressed v1 review comments.  In particular, Jay's concern about
current sysfs ordering limitations carrying over to iproute.  Netlink
attributes are processed in a priority order in
bond_netlink.c:bond_changelink().  Lower priority attributes can't undo
higher priority attributes when attempting to set both with iproute
command.  For example, this command will fail:

  ip link add bond1 type bond mode active-backup miimon 10 arp_interval 10

Because we're trying to create a new bond to use incompatible miimon
and ARP interval attributes.  However, if attributes are applied
one-at-a-time, previously applied attributes can be overridden:

  ip link add bond1 type bond mode active-backup miimon 10
  ip link set dev bond1 type bond arp_interval 10

These two commands succeed.  The bond is first created to use miimon.
Next, the bond is converted to use ARP interval, which undoes miimon.

v1:

Following Jiri Pirko's lead, add more bonding netlink attributes.  Sending
matching iproute2 patch separately.  sysfs access to attributes is
retained.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 1cbac010 d5c84254
/*
* drivers/net/bond/bond_netlink.c - Netlink interface for bonding
* Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
* Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -23,6 +24,14 @@
static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
[IFLA_BOND_MODE] = { .type = NLA_U8 },
[IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
[IFLA_BOND_MIIMON] = { .type = NLA_U32 },
[IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
[IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
[IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
[IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 },
[IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED },
[IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 },
[IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 },
};
static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
......@@ -40,16 +49,20 @@ static int bond_changelink(struct net_device *bond_dev,
struct nlattr *tb[], struct nlattr *data[])
{
struct bonding *bond = netdev_priv(bond_dev);
int miimon = 0;
int err;
if (data && data[IFLA_BOND_MODE]) {
if (!data)
return 0;
if (data[IFLA_BOND_MODE]) {
int mode = nla_get_u8(data[IFLA_BOND_MODE]);
err = bond_option_mode_set(bond, mode);
if (err)
return err;
}
if (data && data[IFLA_BOND_ACTIVE_SLAVE]) {
if (data[IFLA_BOND_ACTIVE_SLAVE]) {
int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
struct net_device *slave_dev;
......@@ -65,6 +78,82 @@ static int bond_changelink(struct net_device *bond_dev,
if (err)
return err;
}
if (data[IFLA_BOND_MIIMON]) {
miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
err = bond_option_miimon_set(bond, miimon);
if (err)
return err;
}
if (data[IFLA_BOND_UPDELAY]) {
int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
err = bond_option_updelay_set(bond, updelay);
if (err)
return err;
}
if (data[IFLA_BOND_DOWNDELAY]) {
int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
err = bond_option_downdelay_set(bond, downdelay);
if (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;
}
if (data[IFLA_BOND_ARP_INTERVAL]) {
int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
if (arp_interval && miimon) {
pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n",
bond->dev->name);
return -EINVAL;
}
err = bond_option_arp_interval_set(bond, arp_interval);
if (err)
return err;
}
if (data[IFLA_BOND_ARP_IP_TARGET]) {
__be32 targets[BOND_MAX_ARP_TARGETS] = { 0, };
struct nlattr *attr;
int i = 0, rem;
nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
__be32 target = nla_get_u32(attr);
targets[i++] = target;
}
err = bond_option_arp_ip_targets_set(bond, targets, i);
if (err)
return err;
}
if (data[IFLA_BOND_ARP_VALIDATE]) {
int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]);
if (arp_validate && miimon) {
pr_err("%s: ARP validating cannot be used with MII monitoring.\n",
bond->dev->name);
return -EINVAL;
}
err = bond_option_arp_validate_set(bond, arp_validate);
if (err)
return err;
}
if (data[IFLA_BOND_ARP_ALL_TARGETS]) {
int arp_all_targets =
nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]);
err = bond_option_arp_all_targets_set(bond, arp_all_targets);
if (err)
return err;
}
return 0;
}
......@@ -83,7 +172,17 @@ 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 */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
/* IFLA_BOND_ARP_IP_TARGET */
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_ALL_TARGETS */
0;
}
static int bond_fill_info(struct sk_buff *skb,
......@@ -91,11 +190,57 @@ static int bond_fill_info(struct sk_buff *skb,
{
struct bonding *bond = netdev_priv(bond_dev);
struct net_device *slave_dev = bond_option_active_slave_get(bond);
struct nlattr *targets;
int i, targets_added;
if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
goto nla_put_failure;
if (slave_dev &&
nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex))
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
bond->params.updelay * bond->params.miimon))
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
bond->params.downdelay * bond->params.miimon))
goto nla_put_failure;
if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
goto nla_put_failure;
targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
if (!targets)
goto nla_put_failure;
targets_added = 0;
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
if (bond->params.arp_targets[i]) {
nla_put_u32(skb, i, bond->params.arp_targets[i]);
targets_added = 1;
}
}
if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode) ||
(slave_dev &&
nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)))
if (targets_added)
nla_nest_end(skb, targets);
else
nla_nest_cancel(skb, targets);
if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate))
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS,
bond->params.arp_all_targets))
goto nla_put_failure;
return 0;
nla_put_failure:
......
/*
* drivers/net/bond/bond_options.c - bonding options
* Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
* Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -145,3 +146,326 @@ int bond_option_active_slave_set(struct bonding *bond,
unblock_netpoll_tx();
return ret;
}
int bond_option_miimon_set(struct bonding *bond, int miimon)
{
if (miimon < 0) {
pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
bond->dev->name, miimon, 0, INT_MAX);
return -EINVAL;
}
pr_info("%s: Setting MII monitoring interval to %d.\n",
bond->dev->name, miimon);
bond->params.miimon = miimon;
if (bond->params.updelay)
pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
bond->dev->name,
bond->params.updelay * bond->params.miimon);
if (bond->params.downdelay)
pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
bond->dev->name,
bond->params.downdelay * bond->params.miimon);
if (miimon && bond->params.arp_interval) {
pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
bond->dev->name);
bond->params.arp_interval = 0;
if (bond->params.arp_validate)
bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
}
if (bond->dev->flags & IFF_UP) {
/* If the interface is up, we may need to fire off
* the MII timer. If the interface is down, the
* timer will get fired off when the open function
* is called.
*/
if (!miimon) {
cancel_delayed_work_sync(&bond->mii_work);
} else {
cancel_delayed_work_sync(&bond->arp_work);
queue_delayed_work(bond->wq, &bond->mii_work, 0);
}
}
return 0;
}
int bond_option_updelay_set(struct bonding *bond, int updelay)
{
if (!(bond->params.miimon)) {
pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
bond->dev->name);
return -EPERM;
}
if (updelay < 0) {
pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
bond->dev->name, updelay, 0, INT_MAX);
return -EINVAL;
} else {
if ((updelay % bond->params.miimon) != 0) {
pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
bond->dev->name, updelay,
bond->params.miimon,
(updelay / bond->params.miimon) *
bond->params.miimon);
}
bond->params.updelay = updelay / bond->params.miimon;
pr_info("%s: Setting up delay to %d.\n",
bond->dev->name,
bond->params.updelay * bond->params.miimon);
}
return 0;
}
int bond_option_downdelay_set(struct bonding *bond, int downdelay)
{
if (!(bond->params.miimon)) {
pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
bond->dev->name);
return -EPERM;
}
if (downdelay < 0) {
pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
bond->dev->name, downdelay, 0, INT_MAX);
return -EINVAL;
} else {
if ((downdelay % bond->params.miimon) != 0) {
pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
bond->dev->name, downdelay,
bond->params.miimon,
(downdelay / bond->params.miimon) *
bond->params.miimon);
}
bond->params.downdelay = downdelay / bond->params.miimon;
pr_info("%s: Setting down delay to %d.\n",
bond->dev->name,
bond->params.downdelay * bond->params.miimon);
}
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;
}
int bond_option_arp_interval_set(struct bonding *bond, int arp_interval)
{
if (arp_interval < 0) {
pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
bond->dev->name, arp_interval, INT_MAX);
return -EINVAL;
}
if (BOND_NO_USES_ARP(bond->params.mode)) {
pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
bond->dev->name, bond->dev->name);
return -EINVAL;
}
pr_info("%s: Setting ARP monitoring interval to %d.\n",
bond->dev->name, arp_interval);
bond->params.arp_interval = arp_interval;
if (arp_interval) {
if (bond->params.miimon) {
pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
bond->dev->name, bond->dev->name);
bond->params.miimon = 0;
}
if (!bond->params.arp_targets[0])
pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
bond->dev->name);
}
if (bond->dev->flags & IFF_UP) {
/* If the interface is up, we may need to fire off
* the ARP timer. If the interface is down, the
* timer will get fired off when the open function
* is called.
*/
if (!arp_interval) {
if (bond->params.arp_validate)
bond->recv_probe = NULL;
cancel_delayed_work_sync(&bond->arp_work);
} else {
/* arp_validate can be set only in active-backup mode */
if (bond->params.arp_validate)
bond->recv_probe = bond_arp_rcv;
cancel_delayed_work_sync(&bond->mii_work);
queue_delayed_work(bond->wq, &bond->arp_work, 0);
}
}
return 0;
}
static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
__be32 target,
unsigned long last_rx)
{
__be32 *targets = bond->params.arp_targets;
struct list_head *iter;
struct slave *slave;
if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
bond_for_each_slave(bond, slave, iter)
slave->target_last_arp_rx[slot] = last_rx;
targets[slot] = target;
}
}
static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
{
__be32 *targets = bond->params.arp_targets;
int ind;
if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
pr_err("%s: invalid ARP target %pI4 specified for addition\n",
bond->dev->name, &target);
return -EINVAL;
}
if (bond_get_targets_ip(targets, target) != -1) { /* dup */
pr_err("%s: ARP target %pI4 is already present\n",
bond->dev->name, &target);
return -EINVAL;
}
ind = bond_get_targets_ip(targets, 0); /* first free slot */
if (ind == -1) {
pr_err("%s: ARP target table is full!\n",
bond->dev->name);
return -EINVAL;
}
pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target);
_bond_options_arp_ip_target_set(bond, ind, target, jiffies);
return 0;
}
int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
{
int ret;
/* not to race with bond_arp_rcv */
write_lock_bh(&bond->lock);
ret = _bond_option_arp_ip_target_add(bond, target);
write_unlock_bh(&bond->lock);
return ret;
}
int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
{
__be32 *targets = bond->params.arp_targets;
struct list_head *iter;
struct slave *slave;
unsigned long *targets_rx;
int ind, i;
if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
pr_err("%s: invalid ARP target %pI4 specified for removal\n",
bond->dev->name, &target);
return -EINVAL;
}
ind = bond_get_targets_ip(targets, target);
if (ind == -1) {
pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
bond->dev->name, &target);
return -EINVAL;
}
if (ind == 0 && !targets[1] && bond->params.arp_interval)
pr_warn("%s: removing last arp target with arp_interval on\n",
bond->dev->name);
pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
&target);
/* not to race with bond_arp_rcv */
write_lock_bh(&bond->lock);
bond_for_each_slave(bond, slave, iter) {
targets_rx = slave->target_last_arp_rx;
for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
targets_rx[i] = targets_rx[i+1];
targets_rx[i] = 0;
}
for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
targets[i] = targets[i+1];
targets[i] = 0;
write_unlock_bh(&bond->lock);
return 0;
}
int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
int count)
{
int i, ret = 0;
/* not to race with bond_arp_rcv */
write_lock_bh(&bond->lock);
/* clear table */
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
_bond_options_arp_ip_target_set(bond, i, 0, 0);
if (count == 0 && bond->params.arp_interval)
pr_warn("%s: removing last arp target with arp_interval on\n",
bond->dev->name);
for (i = 0; i < count; i++) {
ret = _bond_option_arp_ip_target_add(bond, targets[i]);
if (ret)
break;
}
write_unlock_bh(&bond->lock);
return ret;
}
int bond_option_arp_validate_set(struct bonding *bond, int arp_validate)
{
if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
pr_err("%s: arp_validate only supported in active-backup mode.\n",
bond->dev->name);
return -EINVAL;
}
pr_info("%s: setting arp_validate to %s (%d).\n",
bond->dev->name, arp_validate_tbl[arp_validate].modename,
arp_validate);
if (bond->dev->flags & IFF_UP) {
if (!arp_validate)
bond->recv_probe = NULL;
else if (bond->params.arp_interval)
bond->recv_probe = bond_arp_rcv;
}
bond->params.arp_validate = arp_validate;
return 0;
}
int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets)
{
pr_info("%s: setting arp_all_targets to %s (%d).\n",
bond->dev->name, arp_all_targets_tbl[arp_all_targets].modename,
arp_all_targets);
bond->params.arp_all_targets = arp_all_targets;
return 0;
}
This diff is collapsed.
......@@ -439,6 +439,17 @@ 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);
int bond_option_miimon_set(struct bonding *bond, int miimon);
int bond_option_updelay_set(struct bonding *bond, int updelay);
int bond_option_downdelay_set(struct bonding *bond, int downdelay);
int bond_option_use_carrier_set(struct bonding *bond, int use_carrier);
int bond_option_arp_interval_set(struct bonding *bond, int arp_interval);
int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
int count);
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_validate_set(struct bonding *bond, int arp_validate);
int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets);
struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
struct net_device *bond_option_active_slave_get(struct bonding *bond);
......
......@@ -331,6 +331,14 @@ enum {
IFLA_BOND_UNSPEC,
IFLA_BOND_MODE,
IFLA_BOND_ACTIVE_SLAVE,
IFLA_BOND_MIIMON,
IFLA_BOND_UPDELAY,
IFLA_BOND_DOWNDELAY,
IFLA_BOND_USE_CARRIER,
IFLA_BOND_ARP_INTERVAL,
IFLA_BOND_ARP_IP_TARGET,
IFLA_BOND_ARP_VALIDATE,
IFLA_BOND_ARP_ALL_TARGETS,
__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