From eeb1a96dab266b975770914c1ca5ce36dff5dc5b 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, 11 insertions(+), 2 deletions(-) diff --git a/src/net/linux/addrs.c b/src/net/linux/addrs.c index c8a904eda..24bed62e5 100644 --- a/src/net/linux/addrs.c +++ b/src/net/linux/addrs.c @@ -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);