Commit 87a7b84b authored by Veaceslav Falico's avatar Veaceslav Falico Committed by David S. Miller

bonding: add helper function bond_get_targets_ip(targets, ip)

Add function bond_get_targets_ip(targets, ip) which searches through
targets array of ips (arp_targets) and returns the position of first
match. If ip == 0, returns the first free slot. On failure to find the
ip or free slot, return -1.

Use it to verify if the arp we've received is valid and in sysfs.

v1->v2:
Fix "[2/6] bonding: add helper function bond_get_targets_ip(targets, ip)",
per Nikolay's advice, to verify if source ip != 0.0.0.0, otherwise we might
update 'null' arp_ip_targets' last_rx. Also, address style.
Signed-off-by: default avatarVeaceslav Falico <vfalico@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 277e2a84
...@@ -2610,19 +2610,16 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave) ...@@ -2610,19 +2610,16 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip) static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
{ {
int i; if (!sip || !bond_has_this_ip(bond, tip)) {
__be32 *targets = bond->params.arp_targets; pr_debug("bva: sip %pI4 tip %pI4 not found\n", &sip, &tip);
for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n",
&sip, &tip, i, &targets[i],
bond_has_this_ip(bond, tip));
if (sip == targets[i]) {
if (bond_has_this_ip(bond, tip))
slave->last_arp_rx = jiffies;
return; return;
} }
if (bond_get_targets_ip(bond->params.arp_targets, sip) == -1) {
pr_debug("bva: sip %pI4 not found in targets\n", &sip);
return;
} }
slave->last_arp_rx = jiffies;
} }
static int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond, static int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
......
...@@ -591,7 +591,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, ...@@ -591,7 +591,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
const char *buf, size_t count) const char *buf, size_t count)
{ {
__be32 newtarget; __be32 newtarget;
int i = 0, done = 0, ret = count; int i = 0, ret = -EINVAL;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
__be32 *targets; __be32 *targets;
...@@ -602,57 +602,44 @@ static ssize_t bonding_store_arp_targets(struct device *d, ...@@ -602,57 +602,44 @@ static ssize_t bonding_store_arp_targets(struct device *d,
if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
pr_err("%s: invalid ARP target %pI4 specified for addition\n", pr_err("%s: invalid ARP target %pI4 specified for addition\n",
bond->dev->name, &newtarget); bond->dev->name, &newtarget);
ret = -EINVAL;
goto out; goto out;
} }
/* look for an empty slot to put the target in, and check for dupes */
for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */
if (targets[i] == newtarget) { /* duplicate */
pr_err("%s: ARP target %pI4 is already present\n", pr_err("%s: ARP target %pI4 is already present\n",
bond->dev->name, &newtarget); bond->dev->name, &newtarget);
ret = -EINVAL;
goto out; goto out;
} }
if (targets[i] == 0) {
pr_info("%s: adding ARP target %pI4.\n", i = bond_get_targets_ip(targets, 0); /* first free slot */
bond->dev->name, &newtarget); if (i == -1) {
done = 1;
targets[i] = newtarget;
}
}
if (!done) {
pr_err("%s: ARP target table is full!\n", pr_err("%s: ARP target table is full!\n",
bond->dev->name); bond->dev->name);
ret = -EINVAL;
goto out; goto out;
} }
pr_info("%s: adding ARP target %pI4.\n", bond->dev->name,
&newtarget);
targets[i] = newtarget;
} else if (buf[0] == '-') { } else if (buf[0] == '-') {
if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
pr_err("%s: invalid ARP target %pI4 specified for removal\n", pr_err("%s: invalid ARP target %pI4 specified for removal\n",
bond->dev->name, &newtarget); bond->dev->name, &newtarget);
ret = -EINVAL;
goto out; goto out;
} }
for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { i = bond_get_targets_ip(targets, newtarget);
if (targets[i] == newtarget) { if (i == -1) {
int j;
pr_info("%s: removing ARP target %pI4.\n",
bond->dev->name, &newtarget);
for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
targets[j] = targets[j+1];
targets[j] = 0;
done = 1;
}
}
if (!done) {
pr_info("%s: unable to remove nonexistent ARP target %pI4.\n", pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
bond->dev->name, &newtarget); bond->dev->name, &newtarget);
ret = -EINVAL;
goto out; goto out;
} }
pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
&newtarget);
for (; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
targets[i] = targets[i+1];
targets[i] = 0;
} else { } else {
pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
bond->dev->name); bond->dev->name);
...@@ -660,6 +647,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, ...@@ -660,6 +647,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
goto out; goto out;
} }
ret = count;
out: out:
return ret; return ret;
} }
......
...@@ -464,6 +464,22 @@ static inline struct slave *bond_slave_has_mac(struct bonding *bond, ...@@ -464,6 +464,22 @@ static inline struct slave *bond_slave_has_mac(struct bonding *bond,
return NULL; return NULL;
} }
/* Check if the ip is present in arp ip list, or first free slot if ip == 0
* Returns -1 if not found, index if found
*/
static inline int bond_get_targets_ip(__be32 *targets, __be32 ip)
{
int i;
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
if (targets[i] == ip)
return i;
else if (targets[i] == 0)
break;
return -1;
}
/* exported from bond_main.c */ /* exported from bond_main.c */
extern int bond_net_id; extern int bond_net_id;
extern const struct bond_parm_tbl bond_lacp_tbl[]; extern const struct bond_parm_tbl bond_lacp_tbl[];
......
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