aboutgitcodebugslistschat
path: root/netlink.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-19 09:01:27 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-19 09:01:27 +0200
commit17600d6d6ef0edf60bbf64c5bef594a8a07547cc (patch)
tree7985a9dde7c81ba098296fdcfe63c070b4e36253 /netlink.c
parent1ac0d52820e0cfd6c7f301e3f5d5717cda4dea88 (diff)
downloadpasst-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.tar
passt-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.tar.gz
passt-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.tar.bz2
passt-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.tar.lz
passt-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.tar.xz
passt-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.tar.zst
passt-17600d6d6ef0edf60bbf64c5bef594a8a07547cc.zip
netlink, conf: Actually get prefix/mask length
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'netlink.c')
-rw-r--r--netlink.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/netlink.c b/netlink.c
index 4faa697..10d8a92 100644
--- a/netlink.c
+++ b/netlink.c
@@ -346,10 +346,11 @@ next:
* @ifi: Interface index
* @af: Address family
* @addr: Global address to fill if zero, to set if not, ignored if NULL
+ * @prefix_len: Mask or prefix length, set or fetched (for IPv4)
* @addr_l: Link-scoped address to fill, NULL if not requested
*/
void nl_addr(int ns, unsigned int ifi, sa_family_t af,
- void *addr, int prefix_len, void *addr_l)
+ void *addr, int *prefix_len, void *addr_l)
{
int set = addr && ((af == AF_INET6 && !IN6_IS_ADDR_UNSPECIFIED(addr)) ||
(af == AF_INET && *(uint32_t *)addr));
@@ -380,7 +381,7 @@ void nl_addr(int ns, unsigned int ifi, sa_family_t af,
.ifa.ifa_family = af,
.ifa.ifa_index = ifi,
- .ifa.ifa_prefixlen = prefix_len,
+ .ifa.ifa_prefixlen = *prefix_len,
};
struct ifaddrmsg *ifa;
struct nlmsghdr *nh;
@@ -430,12 +431,14 @@ void nl_addr(int ns, unsigned int ifi, sa_family_t af,
if (rta->rta_type != IFA_ADDRESS)
continue;
- if (af == AF_INET && addr && !*(uint32_t *)addr)
+ if (af == AF_INET && addr && !*(uint32_t *)addr) {
memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta));
- else if (af == AF_INET6 && addr &&
+ *prefix_len = ifa->ifa_prefixlen;
+ } else if (af == AF_INET6 && addr &&
ifa->ifa_scope == RT_SCOPE_UNIVERSE &&
- IN6_IS_ADDR_UNSPECIFIED(addr))
+ IN6_IS_ADDR_UNSPECIFIED(addr)) {
memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta));
+ }
if (addr_l &&
af == AF_INET6 && ifa->ifa_scope == RT_SCOPE_LINK &&