]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
bonding: add arp_interval netlink support
authorsfeldma@cumulusnetworks.com <sfeldma@cumulusnetworks.com>
Thu, 12 Dec 2013 22:10:24 +0000 (14:10 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 14 Dec 2013 06:07:32 +0000 (01:07 -0500)
Add IFLA_BOND_ARP_INTERVAL to allow get/set of bonding parameter
arp_interval via netlink.

Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com>
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_netlink.c
drivers/net/bonding/bond_options.c
drivers/net/bonding/bond_sysfs.c
drivers/net/bonding/bonding.h
include/uapi/linux/if_link.h

index 7edf6399cea242e5191390be10dffc6e795151f7..58e71235b75f4b8ce26992e16bd1af864edfcca0 100644 (file)
@@ -28,6 +28,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
        [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 },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -45,6 +46,7 @@ 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)
@@ -74,7 +76,7 @@ static int bond_changelink(struct net_device *bond_dev,
                        return err;
        }
        if (data[IFLA_BOND_MIIMON]) {
-               int miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
+               miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
 
                err = bond_option_miimon_set(bond, miimon);
                if (err)
@@ -101,6 +103,19 @@ static int bond_changelink(struct net_device *bond_dev,
                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;
+       }
        return 0;
 }
 
@@ -124,6 +139,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
                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 */
                0;
 }
 
@@ -154,6 +170,9 @@ static int bond_fill_info(struct sk_buff *skb,
        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;
+
        return 0;
 
 nla_put_failure:
index 6fc7bbf0b85f9690b621a84c03f177125e180c09..a84e729d02ef2e3336539f084184029f3c6f15d3 100644 (file)
@@ -259,3 +259,50 @@ int bond_option_use_carrier_set(struct bonding *bond, int 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;
+}
index 114760af9a6dbe1b94484ad32d8bda1a96c05732..12128bfa88cea526431a4b4a3848fb0dda6a0e1a 100644 (file)
@@ -506,60 +506,21 @@ static ssize_t bonding_store_arp_interval(struct device *d,
                                          const char *buf, size_t count)
 {
        struct bonding *bond = to_bond(d);
-       int new_value, ret = count;
+       int new_value, ret;
 
-       if (!rtnl_trylock())
-               return restart_syscall();
        if (sscanf(buf, "%d", &new_value) != 1) {
                pr_err("%s: no arp_interval value specified.\n",
-                      bond->dev->name);
-               ret = -EINVAL;
-               goto out;
-       }
-       if (new_value < 0) {
-               pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
-                      bond->dev->name, new_value, INT_MAX);
-               ret = -EINVAL;
-               goto out;
-       }
-       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);
-               ret = -EINVAL;
-               goto out;
-       }
-       pr_info("%s: Setting ARP monitoring interval to %d.\n",
-               bond->dev->name, new_value);
-       bond->params.arp_interval = new_value;
-       if (new_value) {
-               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 (!new_value) {
-                       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);
-               }
+               bond->dev->name);
+               return -EINVAL;
        }
-out:
+
+       if (!rtnl_trylock())
+               return restart_syscall();
+
+       ret = bond_option_arp_interval_set(bond, new_value);
+       if (!ret)
+               ret = count;
+
        rtnl_unlock();
        return ret;
 }
index df159da8db3097d0b377e0f382920670edb231b6..44df2738577d8896a24332d186cf77040b03d87f 100644 (file)
@@ -443,6 +443,7 @@ 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);
 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
 struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
index 77c41bda36a42893c298ab975ecde15fd37e05d2..c73d878afd5871108ec9b926e09b4d1c42b455f3 100644 (file)
@@ -335,6 +335,7 @@ enum {
        IFLA_BOND_UPDELAY,
        IFLA_BOND_DOWNDELAY,
        IFLA_BOND_USE_CARRIER,
+       IFLA_BOND_ARP_INTERVAL,
        __IFLA_BOND_MAX,
 };