Skip to content

Commit

Permalink
net/linux/addrs: fix point-to-point peer address bug
Browse files Browse the repository at this point in the history
On point-to-point networks IFA_ADDRESS points to the peer address
instead of the local address.

    /*
     * Important comment:
     * IFA_ADDRESS is prefix address, rather than local interface address.
     * It makes no difference for normally configured broadcast interfaces,
     * but for point-to-point IFA_ADDRESS is DESTINATION address,
     * local address is supplied in IFA_LOCAL attribute.
    */
  • Loading branch information
sreimers committed Dec 23, 2024
1 parent db05533 commit eeb1a96
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/net/linux/addrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,17 @@ static bool parse_msg_addr(struct nlmsghdr *msg, ssize_t len,

if (ifa->ifa_family == AF_INET) {
sa_init(&sa, AF_INET);
sa.u.in.sin_addr.s_addr =
*(uint32_t *)RTA_DATA(rta_tb[IFA_ADDRESS]);
if (rta_tb[IFA_LOCAL]) {
/* looks like point-to-point network, use local
* address, instead of peer */
sa.u.in.sin_addr.s_addr = *(
uint32_t *)RTA_DATA(rta_tb[IFA_LOCAL]);
}
else {
sa.u.in.sin_addr.s_addr =
*(uint32_t *)RTA_DATA(
rta_tb[IFA_ADDRESS]);
}
}
else if (ifa->ifa_family == AF_INET6) {
sa_set_in6(&sa, RTA_DATA(rta_tb[IFA_ADDRESS]), 0);
Expand Down

0 comments on commit eeb1a96

Please sign in to comment.