Commit c10cd1d8 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Flush routes when an interface goes down.

This avoids desynchronisation between Babel and the kernel.
parent 6a077f86
...@@ -162,6 +162,7 @@ check_network_ipv4(struct network *net) ...@@ -162,6 +162,7 @@ check_network_ipv4(struct network *net)
if(rc > 0) { if(rc > 0) {
if(!net->ipv4 || memcmp(ipv4, net->ipv4, 4) != 0) { if(!net->ipv4 || memcmp(ipv4, net->ipv4, 4) != 0) {
debugf("Noticed IPv4 change for %s.\n", net->ifname); debugf("Noticed IPv4 change for %s.\n", net->ifname);
flush_network_routes(net, 0);
if(!net->ipv4) if(!net->ipv4)
net->ipv4 = malloc(4); net->ipv4 = malloc(4);
if(net->ipv4) if(net->ipv4)
...@@ -169,8 +170,9 @@ check_network_ipv4(struct network *net) ...@@ -169,8 +170,9 @@ check_network_ipv4(struct network *net)
return 1; return 1;
} }
} else { } else {
debugf("Noticed IPv4 change for %s.\n", net->ifname);
if(net->ipv4) { if(net->ipv4) {
debugf("Noticed IPv4 change for %s.\n", net->ifname);
flush_network_routes(net, 0);
free(net->ipv4); free(net->ipv4);
net->ipv4 = NULL; net->ipv4 = NULL;
return 1; return 1;
...@@ -335,6 +337,7 @@ network_up(struct network *net, int up) ...@@ -335,6 +337,7 @@ network_up(struct network *net, int up)
send_hello(net); send_hello(net);
send_request(net, NULL, 0); send_request(net, NULL, 0);
} else { } else {
flush_network_routes(net, 0);
net->buffered = 0; net->buffered = 0;
net->bufsize = 0; net->bufsize = 0;
free(net->sendbuf); free(net->sendbuf);
......
...@@ -128,6 +128,22 @@ flush_neighbour_routes(struct neighbour *neigh) ...@@ -128,6 +128,22 @@ flush_neighbour_routes(struct neighbour *neigh)
} }
} }
void
flush_network_routes(struct network *net, int v4only)
{
int i;
i = 0;
while(i < numroutes) {
if(routes[i].neigh->network == net &&
(!v4only || v4mapped(routes[i].nexthop))) {
flush_route(&routes[i]);
continue;
}
i++;
}
}
static int static int
metric_to_kernel(int metric) metric_to_kernel(int metric)
{ {
......
...@@ -42,6 +42,7 @@ struct route *find_installed_route(const unsigned char *prefix, ...@@ -42,6 +42,7 @@ struct route *find_installed_route(const unsigned char *prefix,
unsigned char plen); unsigned char plen);
void flush_route(struct route *route); void flush_route(struct route *route);
void flush_neighbour_routes(struct neighbour *neigh); void flush_neighbour_routes(struct neighbour *neigh);
void flush_network_routes(struct network *net, int v4only);
void install_route(struct route *route); void install_route(struct route *route);
void uninstall_route(struct route *route); void uninstall_route(struct route *route);
void switch_route(struct route *old, struct route *new); void switch_route(struct route *old, struct route *new);
......
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