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 in the IPv6 case, matching the IPv4
behavior.
Signed-off-by: Jon Maloy
---
conf.c | 2 +-
netlink.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/conf.c b/conf.c
index ee1b4fe..b894ec5 100644
--- a/conf.c
+++ b/conf.c
@@ -805,7 +805,7 @@ static unsigned int conf_ip6(struct ctx *c, unsigned int ifi)
if (!e) {
e = &c->addrs[c->addr_count++];
e->addr = addr;
- e->prefix_len = prefix_len ? prefix_len : 64;
+ e->prefix_len = prefix_len;
e->flags = CONF_ADDR_HOST;
}
diff --git a/netlink.c b/netlink.c
index 82a2f0c..769cb23 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
@@ -797,7 +797,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af,
ifa->ifa_prefixlen > prefix_max) {
memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta));
- prefix_max = ifa->ifa_prefixlen;
+ prefix_max = *prefix_len = ifa->ifa_prefixlen;
}
if (addr_l &&
--
2.52.0