aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsfeldma@cumulusnetworks.com <sfeldma@cumulusnetworks.com>2013-12-12 17:10:24 -0500
committerDavid S. Miller <davem@davemloft.net>2013-12-14 01:07:32 -0500
commit06151dbcf3f76edbe900138cde9e862f429918c9 (patch)
tree84622a95346240f5ca72ca1451c3fb8d815725c8
parent9f53e14e86c46a2300f17309f6308ad0dfbb53ff (diff)
bonding: add arp_interval netlink support
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>
-rw-r--r--drivers/net/bonding/bond_netlink.c21
-rw-r--r--drivers/net/bonding/bond_options.c47
-rw-r--r--drivers/net/bonding/bond_sysfs.c61
-rw-r--r--drivers/net/bonding/bonding.h1
-rw-r--r--include/uapi/linux/if_link.h1
5 files changed, 80 insertions, 51 deletions
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index 7edf6399cea2..58e71235b75f 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -28,6 +28,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
28 [IFLA_BOND_UPDELAY] = { .type = NLA_U32 }, 28 [IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
29 [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 }, 29 [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
30 [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 }, 30 [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
31 [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 },
31}; 32};
32 33
33static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) 34static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -45,6 +46,7 @@ static int bond_changelink(struct net_device *bond_dev,
45 struct nlattr *tb[], struct nlattr *data[]) 46 struct nlattr *tb[], struct nlattr *data[])
46{ 47{
47 struct bonding *bond = netdev_priv(bond_dev); 48 struct bonding *bond = netdev_priv(bond_dev);
49 int miimon = 0;
48 int err; 50 int err;
49 51
50 if (!data) 52 if (!data)
@@ -74,7 +76,7 @@ static int bond_changelink(struct net_device *bond_dev,
74 return err; 76 return err;
75 } 77 }
76 if (data[IFLA_BOND_MIIMON]) { 78 if (data[IFLA_BOND_MIIMON]) {
77 int miimon = nla_get_u32(data[IFLA_BOND_MIIMON]); 79 miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
78 80
79 err = bond_option_miimon_set(bond, miimon); 81 err = bond_option_miimon_set(bond, miimon);
80 if (err) 82 if (err)
@@ -101,6 +103,19 @@ static int bond_changelink(struct net_device *bond_dev,
101 if (err) 103 if (err)
102 return err; 104 return err;
103 } 105 }
106 if (data[IFLA_BOND_ARP_INTERVAL]) {
107 int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
108
109 if (arp_interval && miimon) {
110 pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n",
111 bond->dev->name);
112 return -EINVAL;
113 }
114
115 err = bond_option_arp_interval_set(bond, arp_interval);
116 if (err)
117 return err;
118 }
104 return 0; 119 return 0;
105} 120}
106 121
@@ -124,6 +139,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
124 nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */ 139 nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
125 nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */ 140 nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
126 nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */ 141 nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
142 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
127 0; 143 0;
128} 144}
129 145
@@ -154,6 +170,9 @@ static int bond_fill_info(struct sk_buff *skb,
154 if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier)) 170 if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
155 goto nla_put_failure; 171 goto nla_put_failure;
156 172
173 if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
174 goto nla_put_failure;
175
157 return 0; 176 return 0;
158 177
159nla_put_failure: 178nla_put_failure:
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 6fc7bbf0b85f..a84e729d02ef 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -259,3 +259,50 @@ int bond_option_use_carrier_set(struct bonding *bond, int use_carrier)
259 259
260 return 0; 260 return 0;
261} 261}
262
263int bond_option_arp_interval_set(struct bonding *bond, int arp_interval)
264{
265 if (arp_interval < 0) {
266 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
267 bond->dev->name, arp_interval, INT_MAX);
268 return -EINVAL;
269 }
270 if (BOND_NO_USES_ARP(bond->params.mode)) {
271 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
272 bond->dev->name, bond->dev->name);
273 return -EINVAL;
274 }
275 pr_info("%s: Setting ARP monitoring interval to %d.\n",
276 bond->dev->name, arp_interval);
277 bond->params.arp_interval = arp_interval;
278 if (arp_interval) {
279 if (bond->params.miimon) {
280 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
281 bond->dev->name, bond->dev->name);
282 bond->params.miimon = 0;
283 }
284 if (!bond->params.arp_targets[0])
285 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
286 bond->dev->name);
287 }
288 if (bond->dev->flags & IFF_UP) {
289 /* If the interface is up, we may need to fire off
290 * the ARP timer. If the interface is down, the
291 * timer will get fired off when the open function
292 * is called.
293 */
294 if (!arp_interval) {
295 if (bond->params.arp_validate)
296 bond->recv_probe = NULL;
297 cancel_delayed_work_sync(&bond->arp_work);
298 } else {
299 /* arp_validate can be set only in active-backup mode */
300 if (bond->params.arp_validate)
301 bond->recv_probe = bond_arp_rcv;
302 cancel_delayed_work_sync(&bond->mii_work);
303 queue_delayed_work(bond->wq, &bond->arp_work, 0);
304 }
305 }
306
307 return 0;
308}
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 114760af9a6d..12128bfa88ce 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -506,60 +506,21 @@ static ssize_t bonding_store_arp_interval(struct device *d,
506 const char *buf, size_t count) 506 const char *buf, size_t count)
507{ 507{
508 struct bonding *bond = to_bond(d); 508 struct bonding *bond = to_bond(d);
509 int new_value, ret = count; 509 int new_value, ret;
510 510
511 if (!rtnl_trylock())
512 return restart_syscall();
513 if (sscanf(buf, "%d", &new_value) != 1) { 511 if (sscanf(buf, "%d", &new_value) != 1) {
514 pr_err("%s: no arp_interval value specified.\n", 512 pr_err("%s: no arp_interval value specified.\n",
515 bond->dev->name); 513 bond->dev->name);
516 ret = -EINVAL; 514 return -EINVAL;
517 goto out;
518 }
519 if (new_value < 0) {
520 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
521 bond->dev->name, new_value, INT_MAX);
522 ret = -EINVAL;
523 goto out;
524 }
525 if (BOND_NO_USES_ARP(bond->params.mode)) {
526 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
527 bond->dev->name, bond->dev->name);
528 ret = -EINVAL;
529 goto out;
530 }
531 pr_info("%s: Setting ARP monitoring interval to %d.\n",
532 bond->dev->name, new_value);
533 bond->params.arp_interval = new_value;
534 if (new_value) {
535 if (bond->params.miimon) {
536 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
537 bond->dev->name, bond->dev->name);
538 bond->params.miimon = 0;
539 }
540 if (!bond->params.arp_targets[0])
541 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
542 bond->dev->name);
543 }
544 if (bond->dev->flags & IFF_UP) {
545 /* If the interface is up, we may need to fire off
546 * the ARP timer. If the interface is down, the
547 * timer will get fired off when the open function
548 * is called.
549 */
550 if (!new_value) {
551 if (bond->params.arp_validate)
552 bond->recv_probe = NULL;
553 cancel_delayed_work_sync(&bond->arp_work);
554 } else {
555 /* arp_validate can be set only in active-backup mode */
556 if (bond->params.arp_validate)
557 bond->recv_probe = bond_arp_rcv;
558 cancel_delayed_work_sync(&bond->mii_work);
559 queue_delayed_work(bond->wq, &bond->arp_work, 0);
560 }
561 } 515 }
562out: 516
517 if (!rtnl_trylock())
518 return restart_syscall();
519
520 ret = bond_option_arp_interval_set(bond, new_value);
521 if (!ret)
522 ret = count;
523
563 rtnl_unlock(); 524 rtnl_unlock();
564 return ret; 525 return ret;
565} 526}
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index df159da8db30..44df2738577d 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -443,6 +443,7 @@ int bond_option_miimon_set(struct bonding *bond, int miimon);
443int bond_option_updelay_set(struct bonding *bond, int updelay); 443int bond_option_updelay_set(struct bonding *bond, int updelay);
444int bond_option_downdelay_set(struct bonding *bond, int downdelay); 444int bond_option_downdelay_set(struct bonding *bond, int downdelay);
445int bond_option_use_carrier_set(struct bonding *bond, int use_carrier); 445int bond_option_use_carrier_set(struct bonding *bond, int use_carrier);
446int bond_option_arp_interval_set(struct bonding *bond, int arp_interval);
446struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond); 447struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
447struct net_device *bond_option_active_slave_get(struct bonding *bond); 448struct net_device *bond_option_active_slave_get(struct bonding *bond);
448 449
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 77c41bda36a4..c73d878afd58 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -335,6 +335,7 @@ enum {
335 IFLA_BOND_UPDELAY, 335 IFLA_BOND_UPDELAY,
336 IFLA_BOND_DOWNDELAY, 336 IFLA_BOND_DOWNDELAY,
337 IFLA_BOND_USE_CARRIER, 337 IFLA_BOND_USE_CARRIER,
338 IFLA_BOND_ARP_INTERVAL,
338 __IFLA_BOND_MAX, 339 __IFLA_BOND_MAX,
339}; 340};
340 341