Commit fd51cbf6 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix kernel_ll_addresses.

It was completely broken, but compensated with another bug.  No kidding.
parent d275c6aa
...@@ -31,35 +31,6 @@ THE SOFTWARE. ...@@ -31,35 +31,6 @@ THE SOFTWARE.
#include "kernel_netlink.c" #include "kernel_netlink.c"
#endif #endif
/* Return an interface's link-local addresses */
int
kernel_ll_addresses(char *ifname, int ifindex,
unsigned char (*addresses)[16], int maxaddr)
{
struct kernel_route routes[64];
int rc, i, j;
rc = kernel_addresses(ifname, ifindex, routes, 64);
if(rc < 0)
return -1;
j = 0;
for(i = 0; i < rc; i++) {
unsigned char *prefix;
if(j >= maxaddr)
break;
if(routes[i].ifindex != ifindex)
continue;
prefix = routes[i].prefix;
if(prefix[0] == 0xFE && prefix[1] == 0x80 &&
memcmp(prefix + 2, zeroes, 6) == 0) {
memcpy(addresses[j], prefix, 16);
j++;
}
}
return j;
}
/* Like gettimeofday, but returns monotonic time. If POSIX clocks are not /* Like gettimeofday, but returns monotonic time. If POSIX clocks are not
available, falls back to gettimeofday but enforces monotonicity. */ available, falls back to gettimeofday but enforces monotonicity. */
int int
......
...@@ -61,6 +61,6 @@ int kernel_callback(int (*fn)(int, void*), void *closure); ...@@ -61,6 +61,6 @@ int kernel_callback(int (*fn)(int, void*), void *closure);
int kernel_addresses(char *ifname, int ifindex, int kernel_addresses(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes); struct kernel_route *routes, int maxroutes);
int kernel_ll_addresses(char *ifname, int ifindex, int kernel_ll_addresses(char *ifname, int ifindex,
unsigned char (*addresses)[16], int maxaddr); struct kernel_route *routes, int maxroutes);
int if_eui64(char *ifname, int ifindex, unsigned char *eui); int if_eui64(char *ifname, int ifindex, unsigned char *eui);
int gettime(struct timeval *tv); int gettime(struct timeval *tv);
...@@ -1182,13 +1182,15 @@ filter_addresses(struct nlmsghdr *nh, void *data) ...@@ -1182,13 +1182,15 @@ filter_addresses(struct nlmsghdr *nh, void *data)
struct ifaddrmsg *ifa; struct ifaddrmsg *ifa;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
int ifindex = 0; int ifindex = 0;
int ll = 0;
if (data) { if (data) {
void **args = (void **)data; void **args = (void **)data;
maxroutes = *(int *)args[0]; maxroutes = *(int *)args[0];
routes = (struct kernel_route*)args[1]; routes = (struct kernel_route*)args[1];
found = (int *)args[2]; found = (int *)args[2];
ifindex = args[3] ? 0 : *(int*)args[3]; ifindex = args[3] ? *(int*)args[3] : 0;
ll = args[4] ? !!*(int*)args[4] : 0;
} }
len = nh->nlmsg_len; len = nh->nlmsg_len;
...@@ -1207,7 +1209,7 @@ filter_addresses(struct nlmsghdr *nh, void *data) ...@@ -1207,7 +1209,7 @@ filter_addresses(struct nlmsghdr *nh, void *data)
if (rc < 0) if (rc < 0)
return 0; return 0;
if (IN6_IS_ADDR_LINKLOCAL(&addr)) if (ll == !IN6_IS_ADDR_LINKLOCAL(&addr))
return 0; return 0;
if (ifindex && ifa->ifa_index != ifindex) if (ifindex && ifa->ifa_index != ifindex)
...@@ -1264,13 +1266,14 @@ filter_netlink(struct nlmsghdr *nh, void *data) ...@@ -1264,13 +1266,14 @@ filter_netlink(struct nlmsghdr *nh, void *data)
return 0; return 0;
} }
int static int
kernel_addresses(char *ifname, int ifindex, kernel_addresses_internal(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes) struct kernel_route *routes, int maxroutes,
int ll)
{ {
int maxr = maxroutes; int maxr = maxroutes;
int found = 0; int found = 0;
void *data[] = { &maxr, routes, &found, &ifindex, NULL}; void *data[] = { &maxr, routes, &found, &ifindex, &ll, NULL };
struct rtgenmsg g; struct rtgenmsg g;
int rc; int rc;
...@@ -1304,6 +1307,20 @@ kernel_addresses(char *ifname, int ifindex, ...@@ -1304,6 +1307,20 @@ kernel_addresses(char *ifname, int ifindex,
return found; return found;
} }
int
kernel_addresses(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes)
{
return kernel_addresses_internal(ifname, ifindex, routes, maxroutes, 0);
}
int
kernel_ll_addresses(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes)
{
return kernel_addresses_internal(ifname, ifindex, routes, maxroutes, 1);
}
int int
kernel_callback(int (*fn)(int, void*), void *closure) kernel_callback(int (*fn)(int, void*), void *closure)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment