Add nl_sendgetaddr and nl_sendgetaddrs variants for v4/v6.

This commit is contained in:
Nicholas J. Kain 2014-03-28 00:09:53 -04:00
parent 77ce7b9a6c
commit 704e414171
3 changed files with 37 additions and 5 deletions

View File

@ -421,7 +421,7 @@ static int ipbcpfx_clear_others(int fd, uint32_t ipaddr, uint32_t bcast,
.prefixlen = prefixlen, .already_ok = false }; .prefixlen = prefixlen, .already_ok = false };
ssize_t ret; ssize_t ret;
uint32_t seq = ifset_nl_seq++; 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; return -1;
do { do {

View File

@ -197,7 +197,8 @@ int nl_sendgetlink(int fd, int seq, int ifindex)
return nl_sendgetlink_do(fd, seq, ifindex, 1); 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]; char nlbuf[512];
struct nlmsghdr *nlh = (struct nlmsghdr *)nlbuf; struct nlmsghdr *nlh = (struct nlmsghdr *)nlbuf;
@ -211,8 +212,10 @@ int nl_sendgetaddr(int fd, int seq, int ifindex)
nlh->nlmsg_seq = seq; nlh->nlmsg_seq = seq;
ifaddrmsg = NLMSG_DATA(nlh); ifaddrmsg = NLMSG_DATA(nlh);
ifaddrmsg->ifa_family = AF_INET; if (by_afamily)
ifaddrmsg->ifa_index = ifindex; ifaddrmsg->ifa_family = afamily;
if (by_ifindex)
ifaddrmsg->ifa_index = ifindex;
struct sockaddr_nl addr = { struct sockaddr_nl addr = {
.nl_family = AF_NETLINK, .nl_family = AF_NETLINK,
@ -232,6 +235,31 @@ retry_sendto:
return 0; 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 nl_open(int nltype, int nlgroup, int *nlportid)
{ {
int fd; int fd;

View File

@ -56,7 +56,11 @@ int nl_foreach_nlmsg(char *buf, size_t blen, uint32_t seq,
nlmsg_foreach_fn pfn, void *fnarg); nlmsg_foreach_fn pfn, void *fnarg);
int nl_sendgetlinks(int fd, int seq); int nl_sendgetlinks(int fd, int seq);
int nl_sendgetlink(int fd, int seq, int ifindex); 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); int nl_open(int nltype, int nlgroup, int *nlportid);