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,29 +225,50 @@ check_link_local_addresses(struct interface *ifp) ...@@ -223,29 +225,50 @@ 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) {
perror("kernel_addresses(link local)"); if(rc < 0)
return -1; perror("kernel_addresses(link local)");
} else if(rc == 0) { else
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 {
ifp->ll = malloc(16 * rc); int changed;
if(ifp->ll == NULL) { if(rc == ifp->numll) {
perror("malloc(ll)"); changed = 0;
for(i = 0; i < rc; i++) {
if(memcmp(ifp->ll[i], ll[i].prefix, 16) != 0) {
changed = 1;
break;
}
}
} else { } else {
for(i = 0; i < rc; i++) changed = 1;
memcpy(ifp->ll[i], ll[i].prefix, 16); }
ifp->numll = rc;
if(changed) {
free(ifp->ll);
ifp->numll = 0;
ifp->ll = malloc(16 * rc);
if(ifp->ll == NULL) {
perror("malloc(ll)");
} else {
for(i = 0; i < rc; i++)
memcpy(ifp->ll[i], ll[i].prefix, 16);
ifp->numll = rc;
}
local_notify_interface(ifp, LOCAL_CHANGE);
} }
} }
......
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