From a54a49061bca0a908e89d4afa5f668c66317d0e5 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 23 Dec 2024 17:43:17 +0100 Subject: [PATCH] net/linux/addrs: fix point-to-point peer address bug 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. */ --- src/net/linux/addrs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/net/linux/addrs.c b/src/net/linux/addrs.c index c8a904eda..2d825f3df 100644 --- a/src/net/linux/addrs.c +++ b/src/net/linux/addrs.c @@ -81,6 +81,7 @@ static bool parse_msg_addr(struct nlmsghdr *msg, ssize_t len, for (nlh = msg; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len)) { struct sa sa; uint32_t flags; + void *addr; char if_name[IF_NAMESIZE]; if (nlh->nlmsg_type == NLMSG_DONE) { @@ -109,13 +110,19 @@ static bool parse_msg_addr(struct nlmsghdr *msg, ssize_t len, continue; } + if (rta_tb[IFA_LOCAL]) + /* looks like point-to-point network, use local + * address, instead of peer */ + addr = RTA_DATA(rta_tb[IFA_LOCAL]); + else + addr = RTA_DATA(rta_tb[IFA_ADDRESS]); + 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]); + sa.u.in.sin_addr.s_addr = *(uint32_t *)addr; } else if (ifa->ifa_family == AF_INET6) { - sa_set_in6(&sa, RTA_DATA(rta_tb[IFA_ADDRESS]), 0); + sa_set_in6(&sa, addr, 0); sa_set_scopeid(&sa, ifa->ifa_index); } else