Skip to content

Commit

Permalink
arpping: make update neighbours work again
Browse files Browse the repository at this point in the history
The arping is using inconsistent sender_ip_addr and target_ip_addr in
messages.  This causes the client receiving the arp message not to update
the arp table entries.

The specific performance is as follows:

There is a machine 2 with IP 10.20.30.3 configured on eth0:0 that is in the
same IP subnet as eth0.  This IP was originally used on another machine 1,
and th IP needs to be changed back to the machine 1.  When using the arping
command to announce what ethernet address has IP 10.20.30.3, the arp table
on machine 3 is not updated.

Machine 3 original arp table:

    10.20.30.3  machine 2 eth0:0    00:00:00:00:00:02
    10.20.30.2  machine 2 eth0      00:00:00:00:00:02
    10.20.30.1  machine 1 eth0      00:00:00:00:00:01

Create interface eth0:0 on machine 1, and use the arping command to send arp
packets.  Expected outcome on machine 3:

    10.20.30.3  machine 1 eth0:0    00:00:00:00:00:01
    10.20.30.2  machine 2 eth0      00:00:00:00:00:02
    10.20.30.1  machine 1 eth0      00:00:00:00:00:01

Actual results on machine 3:

    10.20.30.3  machine 2 eth0:0    00:00:00:00:00:02
    10.20.30.2  machine 2 eth0      00:00:00:00:00:02
    10.20.30.1  machine 1 eth0      00:00:00:00:00:01

Fixes: #298
Fixes: 68f12fc
Signed-off-by: Aichun Li <liaichun@huawei.com>
  • Loading branch information
lac-0073 authored and kerolasa committed Nov 1, 2020
1 parent 4fd276c commit 86ed089
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions arping.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ int main(int argc, char **argv)
}
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET;
if (!ctl.unsolicited && (ctl.source || ctl.gsrc.s_addr)) {
if (ctl.source || ctl.gsrc.s_addr) {
saddr.sin_addr = ctl.gsrc;
if (bind(probe_fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1)
error(2, errno, "bind");
Expand All @@ -979,12 +979,14 @@ int main(int argc, char **argv)
saddr.sin_port = htons(1025);
saddr.sin_addr = ctl.gdst;

if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, (char *)&on, sizeof(on)) == -1)
error(0, errno, _("WARNING: setsockopt(SO_DONTROUTE)"));
if (connect(probe_fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1)
error(2, errno, "connect");
if (getsockname(probe_fd, (struct sockaddr *)&saddr, &alen) == -1)
error(2, errno, "getsockname");
if (!ctl.unsolicited) {
if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, (char *)&on, sizeof(on)) == -1)
error(0, errno, _("WARNING: setsockopt(SO_DONTROUTE)"));
if (connect(probe_fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1)
error(2, errno, "connect");
if (getsockname(probe_fd, (struct sockaddr *)&saddr, &alen) == -1)
error(2, errno, "getsockname");
}
ctl.gsrc = saddr.sin_addr;
}
close(probe_fd);
Expand Down

1 comment on commit 86ed089

@lac-0073
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Please sign in to comment.