Commit d0c25cd4 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Split checking kernel routes from route expiry.

parent 2e928f33
...@@ -73,7 +73,7 @@ int protocol_port; ...@@ -73,7 +73,7 @@ int protocol_port;
unsigned char protocol_group[16]; unsigned char protocol_group[16];
int protocol_socket = -1; int protocol_socket = -1;
int kernel_socket = -1; int kernel_socket = -1;
static int routes_changed = 0; static int kernel_routes_changed = 0;
static volatile sig_atomic_t exiting = 0, dumping = 0; static volatile sig_atomic_t exiting = 0, dumping = 0;
...@@ -81,7 +81,7 @@ struct network *add_network(char *ifname, int ifindex, int bufsize, ...@@ -81,7 +81,7 @@ struct network *add_network(char *ifname, int ifindex, int bufsize,
int wired, unsigned int cost); int wired, unsigned int cost);
void expire_routes(void); void expire_routes(void);
static int kernel_routes_changed(void *closure); static int kernel_routes_callback(void *closure);
static void init_signals(void); static void init_signals(void);
static void dump_tables(FILE *out); static void dump_tables(FILE *out);
...@@ -92,7 +92,7 @@ main(int argc, char **argv) ...@@ -92,7 +92,7 @@ main(int argc, char **argv)
struct ipv6_mreq mreq; struct ipv6_mreq mreq;
int i, rc, fd; int i, rc, fd;
static unsigned char *buf; static unsigned char *buf;
int expiry_time; int expiry_time, kernel_dump_time;
void *vrc; void *vrc;
unsigned int seed; unsigned int seed;
char **arg; char **arg;
...@@ -354,6 +354,9 @@ main(int argc, char **argv) ...@@ -354,6 +354,9 @@ main(int argc, char **argv)
init_signals(); init_signals();
check_myxroutes(); check_myxroutes();
kernel_routes_changed = 0;
kernel_dump_time = now.tv_sec + 20 + random() % 20;
expiry_time = now.tv_sec + 20 + random() % 20; expiry_time = now.tv_sec + 20 + random() % 20;
/* Make some noise so others notice us */ /* Make some noise so others notice us */
...@@ -419,7 +422,7 @@ main(int argc, char **argv) ...@@ -419,7 +422,7 @@ main(int argc, char **argv)
break; break;
if(kernel_socket >= 0 && FD_ISSET(kernel_socket, &readfds)) if(kernel_socket >= 0 && FD_ISSET(kernel_socket, &readfds))
kernel_callback(kernel_routes_changed, NULL); kernel_callback(kernel_routes_callback, NULL);
if(FD_ISSET(protocol_socket, &readfds)) { if(FD_ISSET(protocol_socket, &readfds)) {
rc = babel_recv(protocol_socket, buf, maxmtu, rc = babel_recv(protocol_socket, buf, maxmtu,
...@@ -441,12 +444,24 @@ main(int argc, char **argv) ...@@ -441,12 +444,24 @@ main(int argc, char **argv)
} }
} }
if(routes_changed || now.tv_sec >= expiry_time) { if(now.tv_sec >= expiry_time) {
expire_routes(); expire_routes();
routes_changed = 0;
expiry_time = now.tv_sec + 20 + random() % 20; expiry_time = now.tv_sec + 20 + random() % 20;
} }
if(kernel_routes_changed || now.tv_sec >= kernel_dump_time) {
rc = check_myxroutes();
if(rc > 0)
send_self_update(NULL, 1);
else if(rc < 0)
fprintf(stderr, "Warning: couldn't check installed routes.\n");
kernel_routes_changed = 0;
if(kernel_socket >= 0)
kernel_dump_time = now.tv_sec + 200 + random() % 100;
else
kernel_dump_time = now.tv_sec + 20 + random() % 20;
}
for(i = 0; i < numnets; i++) { for(i = 0; i < numnets; i++) {
if(now.tv_sec >= nets[i].hello_time + nets[i].hello_interval) if(now.tv_sec >= nets[i].hello_time + nets[i].hello_interval)
send_hello(&nets[i]); send_hello(&nets[i]);
...@@ -633,9 +648,9 @@ dump_tables(FILE *out) ...@@ -633,9 +648,9 @@ dump_tables(FILE *out)
} }
static int static int
kernel_routes_changed(void *closure) kernel_routes_callback(void *closure)
{ {
routes_changed = 1; kernel_routes_changed = 1;
return 1; return 1;
} }
...@@ -689,13 +704,7 @@ add_network(char *ifname, int ifindex, int mtu, int wired, unsigned int cost) ...@@ -689,13 +704,7 @@ add_network(char *ifname, int ifindex, int mtu, int wired, unsigned int cost)
void void
expire_routes(void) expire_routes(void)
{ {
int rc, i; int i;
rc = check_myxroutes();
if(rc > 0)
send_self_update(NULL, 1);
else if(rc < 0)
fprintf(stderr, "Warning: couldn't check installed routes.\n");
for(i = 0; i < numneighs; i++) { for(i = 0; i < numneighs; i++) {
if(neighs[i].id[0] == 0) if(neighs[i].id[0] == 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