aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-01-22 08:53:20 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-22 18:38:42 -0500
commit162288810c9ebd2efb79ee6dc364e266044cac9e (patch)
tree2638c5904daed142d5bbaa8d0dbcfde0c35f1d22
parenta4b32ce7f891d507aa663bc78118ef267f0d6d4c (diff)
bonding: convert arp_validate to use the new option API
This patch adds the necessary changes so arp_validate would use the new bonding option API. Also fix some trivial/style errors. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_main.c27
-rw-r--r--drivers/net/bonding/bond_netlink.c3
-rw-r--r--drivers/net/bonding/bond_options.c40
-rw-r--r--drivers/net/bonding/bond_options.h3
-rw-r--r--drivers/net/bonding/bond_sysfs.c23
-rw-r--r--drivers/net/bonding/bonding.h1
6 files changed, 45 insertions, 52 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 6aacb49034f3..3903c87c8b8c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -220,14 +220,6 @@ const struct bond_parm_tbl arp_all_targets_tbl[] = {
220{ NULL, -1}, 220{ NULL, -1},
221}; 221};
222 222
223const struct bond_parm_tbl arp_validate_tbl[] = {
224{ "none", BOND_ARP_VALIDATE_NONE},
225{ "active", BOND_ARP_VALIDATE_ACTIVE},
226{ "backup", BOND_ARP_VALIDATE_BACKUP},
227{ "all", BOND_ARP_VALIDATE_ALL},
228{ NULL, -1},
229};
230
231const struct bond_parm_tbl fail_over_mac_tbl[] = { 223const struct bond_parm_tbl fail_over_mac_tbl[] = {
232{ "none", BOND_FOM_NONE}, 224{ "none", BOND_FOM_NONE},
233{ "active", BOND_FOM_ACTIVE}, 225{ "active", BOND_FOM_ACTIVE},
@@ -4224,15 +4216,18 @@ static int bond_check_params(struct bond_params *params)
4224 return -EINVAL; 4216 return -EINVAL;
4225 } 4217 }
4226 4218
4227 arp_validate_value = bond_parse_parm(arp_validate, 4219 bond_opt_initstr(&newval, arp_validate);
4228 arp_validate_tbl); 4220 valptr = bond_opt_parse(bond_opt_get(BOND_OPT_ARP_VALIDATE),
4229 if (arp_validate_value == -1) { 4221 &newval);
4222 if (!valptr) {
4230 pr_err("Error: invalid arp_validate \"%s\"\n", 4223 pr_err("Error: invalid arp_validate \"%s\"\n",
4231 arp_validate == NULL ? "NULL" : arp_validate); 4224 arp_validate);
4232 return -EINVAL; 4225 return -EINVAL;
4233 } 4226 }
4234 } else 4227 arp_validate_value = valptr->value;
4228 } else {
4235 arp_validate_value = 0; 4229 arp_validate_value = 0;
4230 }
4236 4231
4237 arp_all_targets_value = 0; 4232 arp_all_targets_value = 0;
4238 if (arp_all_targets) { 4233 if (arp_all_targets) {
@@ -4249,10 +4244,10 @@ static int bond_check_params(struct bond_params *params)
4249 if (miimon) { 4244 if (miimon) {
4250 pr_info("MII link monitoring set to %d ms\n", miimon); 4245 pr_info("MII link monitoring set to %d ms\n", miimon);
4251 } else if (arp_interval) { 4246 } else if (arp_interval) {
4247 valptr = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
4248 arp_validate_value);
4252 pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):", 4249 pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
4253 arp_interval, 4250 arp_interval, valptr->string, arp_ip_count);
4254 arp_validate_tbl[arp_validate_value].modename,
4255 arp_ip_count);
4256 4251
4257 for (i = 0; i < arp_ip_count; i++) 4252 for (i = 0; i < arp_ip_count; i++)
4258 pr_info(" %s", arp_ip_target[i]); 4253 pr_info(" %s", arp_ip_target[i]);
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index 8474af18547d..588730c39748 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -193,7 +193,8 @@ static int bond_changelink(struct net_device *bond_dev,
193 return -EINVAL; 193 return -EINVAL;
194 } 194 }
195 195
196 err = bond_option_arp_validate_set(bond, arp_validate); 196 bond_opt_initval(&newval, arp_validate);
197 err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
197 if (err) 198 if (err)
198 return err; 199 return err;
199 } 200 }
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 71e8c5279bc1..eff68a0f71f0 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -45,6 +45,14 @@ static struct bond_opt_value bond_xmit_hashtype_tbl[] = {
45 { NULL, -1, 0}, 45 { NULL, -1, 0},
46}; 46};
47 47
48static struct bond_opt_value bond_arp_validate_tbl[] = {
49 { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
50 { "active", BOND_ARP_VALIDATE_ACTIVE, 0},
51 { "backup", BOND_ARP_VALIDATE_BACKUP, 0},
52 { "all", BOND_ARP_VALIDATE_ALL, 0},
53 { NULL, -1, 0},
54};
55
48static struct bond_option bond_opts[] = { 56static struct bond_option bond_opts[] = {
49 [BOND_OPT_MODE] = { 57 [BOND_OPT_MODE] = {
50 .id = BOND_OPT_MODE, 58 .id = BOND_OPT_MODE,
@@ -69,6 +77,14 @@ static struct bond_option bond_opts[] = {
69 .values = bond_xmit_hashtype_tbl, 77 .values = bond_xmit_hashtype_tbl,
70 .set = bond_option_xmit_hash_policy_set 78 .set = bond_option_xmit_hash_policy_set
71 }, 79 },
80 [BOND_OPT_ARP_VALIDATE] = {
81 .id = BOND_OPT_ARP_VALIDATE,
82 .name = "arp_validate",
83 .desc = "validate src/dst of ARP probes",
84 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)),
85 .values = bond_arp_validate_tbl,
86 .set = bond_option_arp_validate_set
87 },
72 { } 88 { }
73}; 89};
74 90
@@ -734,31 +750,19 @@ int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
734 return ret; 750 return ret;
735} 751}
736 752
737int bond_option_arp_validate_set(struct bonding *bond, int arp_validate) 753int bond_option_arp_validate_set(struct bonding *bond,
754 struct bond_opt_value *newval)
738{ 755{
739 if (bond_parm_tbl_lookup(arp_validate, arp_validate_tbl) < 0) { 756 pr_info("%s: setting arp_validate to %s (%llu).\n",
740 pr_err("%s: Ignoring invalid arp_validate value %d.\n", 757 bond->dev->name, newval->string, newval->value);
741 bond->dev->name, arp_validate);
742 return -EINVAL;
743 }
744
745 if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
746 pr_err("%s: arp_validate only supported in active-backup mode.\n",
747 bond->dev->name);
748 return -EINVAL;
749 }
750
751 pr_info("%s: setting arp_validate to %s (%d).\n",
752 bond->dev->name, arp_validate_tbl[arp_validate].modename,
753 arp_validate);
754 758
755 if (bond->dev->flags & IFF_UP) { 759 if (bond->dev->flags & IFF_UP) {
756 if (!arp_validate) 760 if (!newval->value)
757 bond->recv_probe = NULL; 761 bond->recv_probe = NULL;
758 else if (bond->params.arp_interval) 762 else if (bond->params.arp_interval)
759 bond->recv_probe = bond_arp_rcv; 763 bond->recv_probe = bond_arp_rcv;
760 } 764 }
761 bond->params.arp_validate = arp_validate; 765 bond->params.arp_validate = newval->value;
762 766
763 return 0; 767 return 0;
764} 768}
diff --git a/drivers/net/bonding/bond_options.h b/drivers/net/bonding/bond_options.h
index 2578f1b6e4dd..15c6c0185b2e 100644
--- a/drivers/net/bonding/bond_options.h
+++ b/drivers/net/bonding/bond_options.h
@@ -41,6 +41,7 @@ enum {
41 BOND_OPT_MODE, 41 BOND_OPT_MODE,
42 BOND_OPT_PACKETS_PER_SLAVE, 42 BOND_OPT_PACKETS_PER_SLAVE,
43 BOND_OPT_XMIT_HASH, 43 BOND_OPT_XMIT_HASH,
44 BOND_OPT_ARP_VALIDATE,
44 BOND_OPT_LAST 45 BOND_OPT_LAST
45}; 46};
46 47
@@ -105,4 +106,6 @@ int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval);
105int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval); 106int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval);
106int bond_option_xmit_hash_policy_set(struct bonding *bond, 107int bond_option_xmit_hash_policy_set(struct bonding *bond,
107 struct bond_opt_value *newval); 108 struct bond_opt_value *newval);
109int bond_option_arp_validate_set(struct bonding *bond,
110 struct bond_opt_value *newval);
108#endif /* _BOND_OPTIONS_H */ 111#endif /* _BOND_OPTIONS_H */
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index d81638c33fdb..e1a4b633013f 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -325,10 +325,12 @@ static ssize_t bonding_show_arp_validate(struct device *d,
325 char *buf) 325 char *buf)
326{ 326{
327 struct bonding *bond = to_bond(d); 327 struct bonding *bond = to_bond(d);
328 struct bond_opt_value *val;
328 329
329 return sprintf(buf, "%s %d\n", 330 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
330 arp_validate_tbl[bond->params.arp_validate].modename, 331 bond->params.arp_validate);
331 bond->params.arp_validate); 332
333 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
332} 334}
333 335
334static ssize_t bonding_store_arp_validate(struct device *d, 336static ssize_t bonding_store_arp_validate(struct device *d,
@@ -336,23 +338,12 @@ static ssize_t bonding_store_arp_validate(struct device *d,
336 const char *buf, size_t count) 338 const char *buf, size_t count)
337{ 339{
338 struct bonding *bond = to_bond(d); 340 struct bonding *bond = to_bond(d);
339 int new_value, ret; 341 int ret;
340
341 new_value = bond_parse_parm(buf, arp_validate_tbl);
342 if (new_value < 0) {
343 pr_err("%s: Ignoring invalid arp_validate value %s\n",
344 bond->dev->name, buf);
345 return -EINVAL;
346 }
347 if (!rtnl_trylock())
348 return restart_syscall();
349 342
350 ret = bond_option_arp_validate_set(bond, new_value); 343 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_VALIDATE, (char *)buf);
351 if (!ret) 344 if (!ret)
352 ret = count; 345 ret = count;
353 346
354 rtnl_unlock();
355
356 return ret; 347 return ret;
357} 348}
358 349
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 9e766043e2b5..9af61716d78a 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -462,7 +462,6 @@ int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
462 int count); 462 int count);
463int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); 463int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
464int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target); 464int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
465int bond_option_arp_validate_set(struct bonding *bond, int arp_validate);
466int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets); 465int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets);
467int bond_option_primary_set(struct bonding *bond, const char *primary); 466int bond_option_primary_set(struct bonding *bond, const char *primary);
468int bond_option_primary_reselect_set(struct bonding *bond, 467int bond_option_primary_reselect_set(struct bonding *bond,