diff --git a/ndhc/ifset.c b/ndhc/ifset.c index 2d25a4c..ea2ca38 100644 --- a/ndhc/ifset.c +++ b/ndhc/ifset.c @@ -421,7 +421,7 @@ static int ipbcpfx_clear_others(int fd, uint32_t ipaddr, uint32_t bcast, .prefixlen = prefixlen, .already_ok = false }; ssize_t ret; uint32_t seq = ifset_nl_seq++; - if (nl_sendgetaddr(fd, seq, client_config.ifindex) < 0) + if (nl_sendgetaddr4(fd, seq, client_config.ifindex) < 0) return -1; do { diff --git a/ndhc/nl.c b/ndhc/nl.c index 292e32a..0cdaef7 100644 --- a/ndhc/nl.c +++ b/ndhc/nl.c @@ -197,7 +197,8 @@ int nl_sendgetlink(int fd, int seq, int ifindex) return nl_sendgetlink_do(fd, seq, ifindex, 1); } -int nl_sendgetaddr(int fd, int seq, int ifindex) +static int nl_sendgetaddr_do(int fd, int seq, int ifindex, int by_ifindex, + int afamily, int by_afamily) { char nlbuf[512]; struct nlmsghdr *nlh = (struct nlmsghdr *)nlbuf; @@ -211,8 +212,10 @@ int nl_sendgetaddr(int fd, int seq, int ifindex) nlh->nlmsg_seq = seq; ifaddrmsg = NLMSG_DATA(nlh); - ifaddrmsg->ifa_family = AF_INET; - ifaddrmsg->ifa_index = ifindex; + if (by_afamily) + ifaddrmsg->ifa_family = afamily; + if (by_ifindex) + ifaddrmsg->ifa_index = ifindex; struct sockaddr_nl addr = { .nl_family = AF_NETLINK, @@ -232,6 +235,31 @@ retry_sendto: return 0; } +int nl_sendgetaddrs(int fd, int seq) +{ + return nl_sendgetaddr_do(fd, seq, 0, 0, 0, 0); +} + +int nl_sendgetaddrs4(int fd, int seq) +{ + return nl_sendgetaddr_do(fd, seq, 0, 0, AF_INET, 1); +} + +int nl_sendgetaddrs6(int fd, int seq) +{ + return nl_sendgetaddr_do(fd, seq, 0, 0, AF_INET6, 1); +} + +int nl_sendgetaddr4(int fd, int seq, int ifindex) +{ + return nl_sendgetaddr_do(fd, seq, ifindex, 1, AF_INET, 1); +} + +int nl_sendgetaddr6(int fd, int seq, int ifindex) +{ + return nl_sendgetaddr_do(fd, seq, ifindex, 1, AF_INET6, 1); +} + int nl_open(int nltype, int nlgroup, int *nlportid) { int fd; diff --git a/ndhc/nl.h b/ndhc/nl.h index 6e54709..fa07528 100644 --- a/ndhc/nl.h +++ b/ndhc/nl.h @@ -56,7 +56,11 @@ int nl_foreach_nlmsg(char *buf, size_t blen, uint32_t seq, nlmsg_foreach_fn pfn, void *fnarg); int nl_sendgetlinks(int fd, int seq); int nl_sendgetlink(int fd, int seq, int ifindex); -int nl_sendgetaddr(int fd, int seq, int ifindex); +int nl_sendgetaddr4(int fd, int seq, int ifindex); +int nl_sendgetaddr6(int fd, int seq, int ifindex); +int nl_sendgetaddrs(int fd, int seq); +int nl_sendgetaddrs4(int fd, int seq); +int nl_sendgetaddrs6(int fd, int seq); int nl_open(int nltype, int nlgroup, int *nlportid);