Skip to content

Commit

Permalink
Flush routes when an interface goes down.
Browse files Browse the repository at this point in the history
This avoids desynchronisation between Babel and the kernel.
  • Loading branch information
Juliusz Chroboczek committed Aug 10, 2009
1 parent 6a077f8 commit c10cd1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion network.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,17 @@ check_network_ipv4(struct network *net)
if(rc > 0) {
if(!net->ipv4 || memcmp(ipv4, net->ipv4, 4) != 0) {
debugf("Noticed IPv4 change for %s.\n", net->ifname);
flush_network_routes(net, 0);
if(!net->ipv4)
net->ipv4 = malloc(4);
if(net->ipv4)
memcpy(net->ipv4, ipv4, 4);
return 1;
}
} else {
debugf("Noticed IPv4 change for %s.\n", net->ifname);
if(net->ipv4) {
debugf("Noticed IPv4 change for %s.\n", net->ifname);
flush_network_routes(net, 0);
free(net->ipv4);
net->ipv4 = NULL;
return 1;
Expand Down Expand Up @@ -335,6 +337,7 @@ network_up(struct network *net, int up)
send_hello(net);
send_request(net, NULL, 0);
} else {
flush_network_routes(net, 0);
net->buffered = 0;
net->bufsize = 0;
free(net->sendbuf);
Expand Down
16 changes: 16 additions & 0 deletions route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
metric_to_kernel(int metric)
{
Expand Down
1 change: 1 addition & 0 deletions route.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct route *find_installed_route(const unsigned char *prefix,
unsigned char plen);
void flush_route(struct route *route);
void flush_neighbour_routes(struct neighbour *neigh);
void flush_network_routes(struct network *net, int v4only);
void install_route(struct route *route);
void uninstall_route(struct route *route);
void switch_route(struct route *old, struct route *new);
Expand Down

0 comments on commit c10cd1d

Please sign in to comment.