Commit 7230121b authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Make kernel_addresses take an interface name and index.

parent 1f3e1cba
...@@ -57,6 +57,6 @@ int kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -57,6 +57,6 @@ int kernel_route(int operation, const unsigned char *dest, unsigned short plen,
unsigned int newmetric); unsigned int newmetric);
int kernel_routes(struct kernel_route *routes, int maxroutes); int kernel_routes(struct kernel_route *routes, int maxroutes);
int kernel_callback(int (*fn)(int, void*), void *closure); int kernel_callback(int (*fn)(int, void*), void *closure);
int kernel_addresses(struct kernel_route *routes, int maxroutes); int kernel_addresses(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes);
int gettime(struct timeval *tv); int gettime(struct timeval *tv);
...@@ -1120,12 +1120,14 @@ filter_addresses(struct nlmsghdr *nh, void *data) ...@@ -1120,12 +1120,14 @@ filter_addresses(struct nlmsghdr *nh, void *data)
int len; int len;
struct ifaddrmsg *ifa; struct ifaddrmsg *ifa;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
int ifindex = 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];
} }
len = nh->nlmsg_len; len = nh->nlmsg_len;
...@@ -1147,6 +1149,9 @@ filter_addresses(struct nlmsghdr *nh, void *data) ...@@ -1147,6 +1149,9 @@ filter_addresses(struct nlmsghdr *nh, void *data)
if (IN6_IS_ADDR_LINKLOCAL(&addr)) if (IN6_IS_ADDR_LINKLOCAL(&addr))
return 0; return 0;
if (ifindex && ifa->ifa_index != ifindex)
return 0;
kdebugf("found address on interface %s(%d): %s\n", kdebugf("found address on interface %s(%d): %s\n",
if_indextoname(ifa->ifa_index, ifname), ifa->ifa_index, if_indextoname(ifa->ifa_index, ifname), ifa->ifa_index,
format_address(addr.s6_addr)); format_address(addr.s6_addr));
...@@ -1199,11 +1204,12 @@ filter_netlink(struct nlmsghdr *nh, void *data) ...@@ -1199,11 +1204,12 @@ filter_netlink(struct nlmsghdr *nh, void *data)
} }
int int
kernel_addresses(struct kernel_route *routes, int maxroutes) kernel_addresses(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes)
{ {
int maxr = maxroutes; int maxr = maxroutes;
int found = 0; int found = 0;
void *data[] = { &maxr, routes, &found, NULL}; void *data[] = { &maxr, routes, &found, &ifindex, NULL};
struct rtgenmsg g; struct rtgenmsg g;
int rc; int rc;
......
/* /*
Copyright (c) 2007 by Grégoire Henry Copyright (c) 2007 by Grégoire Henry
Copyright (c) 2008 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
...@@ -600,7 +601,8 @@ socket_read(int sock) ...@@ -600,7 +601,8 @@ socket_read(int sock)
} }
int int
kernel_addresses(struct kernel_route *routes, int maxroutes) kernel_addresses(char *ifname, int ifindex,
struct kernel_route *routes, int maxroutes)
{ {
errno = ENOSYS; errno = ENOSYS;
return -1; return -1;
......
...@@ -135,7 +135,7 @@ check_xroutes(int send_updates) ...@@ -135,7 +135,7 @@ check_xroutes(int send_updates)
if(routes == NULL) if(routes == NULL)
return -1; return -1;
rc = kernel_addresses(routes, maxroutes); rc = kernel_addresses(NULL, 0, routes, maxroutes);
if(rc < 0) { if(rc < 0) {
perror("kernel_addresses"); perror("kernel_addresses");
numroutes = 0; numroutes = 0;
......
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