aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorJon Maloy <jmaloy@redhat.com>2026-03-09 15:52:33 -0400
committerStefano Brivio <sbrivio@redhat.com>2026-03-10 15:28:11 +0100
commit251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a (patch)
tree9f9712de3e1877c1ac472a1420c9fe6b42b64dce
parent045560c20a45a452ca1ed79b15fb01d9da5421e4 (diff)
downloadpasst-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.tar
passt-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.tar.gz
passt-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.tar.bz2
passt-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.tar.lz
passt-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.tar.xz
passt-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.tar.zst
passt-251e676bd0bffe0c3b8bf0e925fbc87b6d4eeb6a.zip
netlink: Return prefix length for IPv6 addresses in nl_addr_get()HEADmaster
nl_addr_get() was not setting the prefix_len output parameter for IPv6 addresses, only for IPv4. This meant callers always got 0 for IPv6, forcing them to use a hardcoded default (64). Fix by assigning *prefix_len even in the IPv6 case. Signed-off-by: Jon Maloy <jmaloy@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--netlink.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/netlink.c b/netlink.c
index 82a2f0c..ee9a6b1 100644
--- a/netlink.c
+++ b/netlink.c
@@ -752,7 +752,7 @@ int nl_addr_set_ll_nodad(int s, unsigned int ifi)
* @ifi: Interface index in outer network namespace
* @af: Address family
* @addr: Global address to fill
- * @prefix_len: Mask or prefix length, to fill (for IPv4)
+ * @prefix_len: Mask or prefix length, to fill
* @addr_l: Link-scoped address to fill (for IPv6)
*
* Return: 0 on success, negative error code on failure
@@ -788,16 +788,11 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af,
(af == AF_INET6 && rta->rta_type != IFA_ADDRESS))
continue;
- if (af == AF_INET && ifa->ifa_prefixlen > prefix_max) {
+ if (ifa->ifa_prefixlen > prefix_max &&
+ (af == AF_INET || ifa->ifa_scope < RT_SCOPE_LINK)) {
memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta));
prefix_max = *prefix_len = ifa->ifa_prefixlen;
- } else if (af == AF_INET6 && addr &&
- ifa->ifa_scope < RT_SCOPE_LINK &&
- ifa->ifa_prefixlen > prefix_max) {
- memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta));
-
- prefix_max = ifa->ifa_prefixlen;
}
if (addr_l &&