Commit 16228881 authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

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: default avatarNikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a4b32ce7
...@@ -220,14 +220,6 @@ const struct bond_parm_tbl arp_all_targets_tbl[] = { ...@@ -220,14 +220,6 @@ const struct bond_parm_tbl arp_all_targets_tbl[] = {
{ NULL, -1}, { NULL, -1},
}; };
const struct bond_parm_tbl arp_validate_tbl[] = {
{ "none", BOND_ARP_VALIDATE_NONE},
{ "active", BOND_ARP_VALIDATE_ACTIVE},
{ "backup", BOND_ARP_VALIDATE_BACKUP},
{ "all", BOND_ARP_VALIDATE_ALL},
{ NULL, -1},
};
const struct bond_parm_tbl fail_over_mac_tbl[] = { const struct bond_parm_tbl fail_over_mac_tbl[] = {
{ "none", BOND_FOM_NONE}, { "none", BOND_FOM_NONE},
{ "active", BOND_FOM_ACTIVE}, { "active", BOND_FOM_ACTIVE},
...@@ -4224,15 +4216,18 @@ static int bond_check_params(struct bond_params *params) ...@@ -4224,15 +4216,18 @@ static int bond_check_params(struct bond_params *params)
return -EINVAL; return -EINVAL;
} }
arp_validate_value = bond_parse_parm(arp_validate, bond_opt_initstr(&newval, arp_validate);
arp_validate_tbl); valptr = bond_opt_parse(bond_opt_get(BOND_OPT_ARP_VALIDATE),
if (arp_validate_value == -1) { &newval);
if (!valptr) {
pr_err("Error: invalid arp_validate \"%s\"\n", pr_err("Error: invalid arp_validate \"%s\"\n",
arp_validate == NULL ? "NULL" : arp_validate); arp_validate);
return -EINVAL; return -EINVAL;
} }
} else arp_validate_value = valptr->value;
} else {
arp_validate_value = 0; arp_validate_value = 0;
}
arp_all_targets_value = 0; arp_all_targets_value = 0;
if (arp_all_targets) { if (arp_all_targets) {
...@@ -4249,10 +4244,10 @@ static int bond_check_params(struct bond_params *params) ...@@ -4249,10 +4244,10 @@ static int bond_check_params(struct bond_params *params)
if (miimon) { if (miimon) {
pr_info("MII link monitoring set to %d ms\n", miimon); pr_info("MII link monitoring set to %d ms\n", miimon);
} else if (arp_interval) { } else if (arp_interval) {
valptr = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
arp_validate_value);
pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):", pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
arp_interval, arp_interval, valptr->string, arp_ip_count);
arp_validate_tbl[arp_validate_value].modename,
arp_ip_count);
for (i = 0; i < arp_ip_count; i++) for (i = 0; i < arp_ip_count; i++)
pr_info(" %s", arp_ip_target[i]); pr_info(" %s", arp_ip_target[i]);
......
...@@ -193,7 +193,8 @@ static int bond_changelink(struct net_device *bond_dev, ...@@ -193,7 +193,8 @@ static int bond_changelink(struct net_device *bond_dev,
return -EINVAL; return -EINVAL;
} }
err = bond_option_arp_validate_set(bond, arp_validate); bond_opt_initval(&newval, arp_validate);
err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
if (err) if (err)
return err; return err;
} }
......
...@@ -45,6 +45,14 @@ static struct bond_opt_value bond_xmit_hashtype_tbl[] = { ...@@ -45,6 +45,14 @@ static struct bond_opt_value bond_xmit_hashtype_tbl[] = {
{ NULL, -1, 0}, { NULL, -1, 0},
}; };
static struct bond_opt_value bond_arp_validate_tbl[] = {
{ "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
{ "active", BOND_ARP_VALIDATE_ACTIVE, 0},
{ "backup", BOND_ARP_VALIDATE_BACKUP, 0},
{ "all", BOND_ARP_VALIDATE_ALL, 0},
{ NULL, -1, 0},
};
static struct bond_option bond_opts[] = { static struct bond_option bond_opts[] = {
[BOND_OPT_MODE] = { [BOND_OPT_MODE] = {
.id = BOND_OPT_MODE, .id = BOND_OPT_MODE,
...@@ -69,6 +77,14 @@ static struct bond_option bond_opts[] = { ...@@ -69,6 +77,14 @@ static struct bond_option bond_opts[] = {
.values = bond_xmit_hashtype_tbl, .values = bond_xmit_hashtype_tbl,
.set = bond_option_xmit_hash_policy_set .set = bond_option_xmit_hash_policy_set
}, },
[BOND_OPT_ARP_VALIDATE] = {
.id = BOND_OPT_ARP_VALIDATE,
.name = "arp_validate",
.desc = "validate src/dst of ARP probes",
.unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)),
.values = bond_arp_validate_tbl,
.set = bond_option_arp_validate_set
},
{ } { }
}; };
...@@ -734,31 +750,19 @@ int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets, ...@@ -734,31 +750,19 @@ int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
return ret; return ret;
} }
int bond_option_arp_validate_set(struct bonding *bond, int arp_validate) int bond_option_arp_validate_set(struct bonding *bond,
struct bond_opt_value *newval)
{ {
if (bond_parm_tbl_lookup(arp_validate, arp_validate_tbl) < 0) { pr_info("%s: setting arp_validate to %s (%llu).\n",
pr_err("%s: Ignoring invalid arp_validate value %d.\n", bond->dev->name, newval->string, newval->value);
bond->dev->name, arp_validate);
return -EINVAL;
}
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 (bond->dev->flags & IFF_UP) {
if (!arp_validate) if (!newval->value)
bond->recv_probe = NULL; bond->recv_probe = NULL;
else if (bond->params.arp_interval) else if (bond->params.arp_interval)
bond->recv_probe = bond_arp_rcv; bond->recv_probe = bond_arp_rcv;
} }
bond->params.arp_validate = arp_validate; bond->params.arp_validate = newval->value;
return 0; return 0;
} }
......
...@@ -41,6 +41,7 @@ enum { ...@@ -41,6 +41,7 @@ enum {
BOND_OPT_MODE, BOND_OPT_MODE,
BOND_OPT_PACKETS_PER_SLAVE, BOND_OPT_PACKETS_PER_SLAVE,
BOND_OPT_XMIT_HASH, BOND_OPT_XMIT_HASH,
BOND_OPT_ARP_VALIDATE,
BOND_OPT_LAST BOND_OPT_LAST
}; };
...@@ -105,4 +106,6 @@ int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval); ...@@ -105,4 +106,6 @@ int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval);
int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval); int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval);
int bond_option_xmit_hash_policy_set(struct bonding *bond, int bond_option_xmit_hash_policy_set(struct bonding *bond,
struct bond_opt_value *newval); struct bond_opt_value *newval);
int bond_option_arp_validate_set(struct bonding *bond,
struct bond_opt_value *newval);
#endif /* _BOND_OPTIONS_H */ #endif /* _BOND_OPTIONS_H */
...@@ -325,10 +325,12 @@ static ssize_t bonding_show_arp_validate(struct device *d, ...@@ -325,10 +325,12 @@ static ssize_t bonding_show_arp_validate(struct device *d,
char *buf) char *buf)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct bond_opt_value *val;
return sprintf(buf, "%s %d\n", val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
arp_validate_tbl[bond->params.arp_validate].modename, bond->params.arp_validate);
bond->params.arp_validate);
return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
} }
static ssize_t bonding_store_arp_validate(struct device *d, static ssize_t bonding_store_arp_validate(struct device *d,
...@@ -336,23 +338,12 @@ static ssize_t bonding_store_arp_validate(struct device *d, ...@@ -336,23 +338,12 @@ static ssize_t bonding_store_arp_validate(struct device *d,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
int new_value, ret; int ret;
new_value = bond_parse_parm(buf, arp_validate_tbl);
if (new_value < 0) {
pr_err("%s: Ignoring invalid arp_validate value %s\n",
bond->dev->name, buf);
return -EINVAL;
}
if (!rtnl_trylock())
return restart_syscall();
ret = bond_option_arp_validate_set(bond, new_value); ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_VALIDATE, (char *)buf);
if (!ret) if (!ret)
ret = count; ret = count;
rtnl_unlock();
return ret; return ret;
} }
......
...@@ -462,7 +462,6 @@ int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets, ...@@ -462,7 +462,6 @@ int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
int count); int count);
int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); 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_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); int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets);
int bond_option_primary_set(struct bonding *bond, const char *primary); int bond_option_primary_set(struct bonding *bond, const char *primary);
int bond_option_primary_reselect_set(struct bonding *bond, int bond_option_primary_reselect_set(struct bonding *bond,
......
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