Commit 5387cf03 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix monitoring of interface addresses

parent 122a0c73
...@@ -178,6 +178,7 @@ check_interface_ipv4(struct interface *ifp) ...@@ -178,6 +178,7 @@ check_interface_ipv4(struct interface *ifp)
ifp->ipv4 = malloc(4); ifp->ipv4 = malloc(4);
if(ifp->ipv4) if(ifp->ipv4)
memcpy(ifp->ipv4, ipv4, 4); memcpy(ifp->ipv4, ipv4, 4);
local_notify_interface(ifp, LOCAL_CHANGE);
return 1; return 1;
} }
} else { } else {
...@@ -186,6 +187,7 @@ check_interface_ipv4(struct interface *ifp) ...@@ -186,6 +187,7 @@ check_interface_ipv4(struct interface *ifp)
flush_interface_routes(ifp, 0); flush_interface_routes(ifp, 0);
free(ifp->ipv4); free(ifp->ipv4);
ifp->ipv4 = NULL; ifp->ipv4 = NULL;
local_notify_interface(ifp, LOCAL_CHANGE);
return 1; return 1;
} }
} }
...@@ -223,22 +225,41 @@ check_link_local_addresses(struct interface *ifp) ...@@ -223,22 +225,41 @@ check_link_local_addresses(struct interface *ifp)
{ {
struct kernel_route ll[32]; struct kernel_route ll[32];
int rc, i; int rc, i;
if(ifp->ll)
free(ifp->ll);
ifp->numll = 0;
ifp->ll = NULL;
rc = kernel_addresses(ifp->ifindex, 1, ll, 32); rc = kernel_addresses(ifp->ifindex, 1, ll, 32);
if(rc < 0) { if(rc <= 0) {
if(rc < 0)
perror("kernel_addresses(link local)"); perror("kernel_addresses(link local)");
return -1; else
} else if(rc == 0) {
fprintf(stderr, "Interface %s has no link-local address.\n", fprintf(stderr, "Interface %s has no link-local address.\n",
ifp->name); ifp->name);
if(ifp->ll) {
free(ifp->ll);
ifp->numll = 0;
ifp->ll = NULL;
}
local_notify_interface(ifp, LOCAL_CHANGE);
/* Most probably DAD hasn't finished yet. Reschedule us /* Most probably DAD hasn't finished yet. Reschedule us
real soon. */ real soon. */
schedule_interfaces_check(2000, 0); schedule_interfaces_check(2000, 0);
return -1; return -1;
} else { } else {
int changed;
if(rc == ifp->numll) {
changed = 0;
for(i = 0; i < rc; i++) {
if(memcmp(ifp->ll[i], ll[i].prefix, 16) != 0) {
changed = 1;
break;
}
}
} else {
changed = 1;
}
if(changed) {
free(ifp->ll);
ifp->numll = 0;
ifp->ll = malloc(16 * rc); ifp->ll = malloc(16 * rc);
if(ifp->ll == NULL) { if(ifp->ll == NULL) {
perror("malloc(ll)"); perror("malloc(ll)");
...@@ -247,6 +268,8 @@ check_link_local_addresses(struct interface *ifp) ...@@ -247,6 +268,8 @@ check_link_local_addresses(struct interface *ifp)
memcpy(ifp->ll[i], ll[i].prefix, 16); memcpy(ifp->ll[i], ll[i].prefix, 16);
ifp->numll = rc; ifp->numll = rc;
} }
local_notify_interface(ifp, LOCAL_CHANGE);
}
} }
return 0; return 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