Commit 11fbc1bf authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement hello moderation on idle interfaces.

parent 3337e1f5
......@@ -58,8 +58,11 @@ static int maxmtu;
int reboot_time;
int idle_time = 320;
int wireless_hello_interval = -1;
int wired_hello_interval = -1;
int idle_hello_interval = -1;
int update_interval = -1;
struct network nets[MAXNETS];
......@@ -157,6 +160,9 @@ main(int argc, char **argv)
} else if(strcmp(*arg, "-H") == 0) {
SHIFTE();
wired_hello_interval = atoi(*arg);
} else if(strcmp(*arg, "-i") == 0) {
SHIFTE();
idle_hello_interval = atoi(*arg);
} else if(strcmp(*arg, "-u") == 0) {
SHIFTE();
update_interval = atoi(*arg);
......@@ -194,6 +200,10 @@ main(int argc, char **argv)
if(wired_hello_interval <= 0)
wired_hello_interval = 30;
if(idle_hello_interval <= 0)
idle_hello_interval =
MIN(wireless_hello_interval * 5, wired_hello_interval);
if(update_interval <= 0)
update_interval =
MIN(MAX(wireless_hello_interval * 5, wired_hello_interval),
......@@ -532,9 +542,9 @@ main(int argc, char **argv)
"Syntax: %s "
"[-m multicast_address] [-p port] [-S state-file]\n"
" "
"[-h hello_interval] [-H wired_hello_interval]\n"
"[-h hello] [-H wired_hello] [i idle_hello]\n"
" "
"[-u update_interval] [-k metric] [-s] [-P] [-c cost]\n"
"[-u update] [-k metric] [-s] [-P] [-c cost]\n"
" "
"[-d level] [-x net cost] [-X net cost]... address interface...\n",
argv[0]);
......@@ -659,17 +669,6 @@ kernel_routes_callback(void *closure)
return 1;
}
void
set_hello_interval(struct network *net, int hello_interval)
{
if(hello_interval >= 0)
net->hello_interval = hello_interval;
else if(net->wired)
net->hello_interval = wired_hello_interval;
else
net->hello_interval = wireless_hello_interval;
}
struct network *
add_network(char *ifname, int ifindex, int mtu, int wired, unsigned int cost)
{
......@@ -684,10 +683,8 @@ add_network(char *ifname, int ifindex, int mtu, int wired, unsigned int cost)
nets[numnets].ifindex = ifindex;
nets[numnets].wired = wired;
nets[numnets].cost = cost;
set_hello_interval(&nets[numnets], -1);
nets[numnets].self_update_interval =
MAX(15 + nets[numnets].hello_interval / 2,
nets[numnets].hello_interval);
nets[numnets].activity_time = now.tv_sec;
update_hello_interval(&nets[numnets]);
nets[numnets].txcost_interval = MIN(42, 2 * nets[numnets].hello_interval);
nets[numnets].bufsize = mtu - sizeof(packet_header);
nets[numnets].flush_time = tv_zero;
......@@ -706,6 +703,21 @@ add_network(char *ifname, int ifindex, int mtu, int wired, unsigned int cost)
return &nets[numnets - 1];
}
void
update_hello_interval(struct network *net)
{
if(net->activity_time < now.tv_sec - idle_time)
net->hello_interval = idle_hello_interval;
else if(net->wired)
net->hello_interval = wired_hello_interval;
else
net->hello_interval = wireless_hello_interval;
net->self_update_interval =
MAX(15 + nets[numnets].hello_interval / 2,
nets[numnets].hello_interval);
}
void
expire_routes(void)
{
......
......@@ -76,6 +76,7 @@ struct network {
unsigned char *sendbuf;
int bucket_time;
unsigned int bucket;
int activity_time;
unsigned char hello_seqno;
unsigned int hello_interval;
unsigned int self_update_interval;
......@@ -95,3 +96,5 @@ extern int protocol_port;
extern unsigned char protocol_group[16];
extern int protocol_socket;
extern int kernel_socket;
void update_hello_interval(struct network *net);
......@@ -91,6 +91,7 @@ parse_packet(const unsigned char *from, struct network *net,
net->ifname,
format_address(message + 4),
format_address(from));
net->activity_time = now.tv_sec;
neigh = add_neighbour(message + 4, from, net);
update_neighbour(neigh, message[1], (message[2] << 8 | message[3]));
update_neighbour_metric(neigh);
......@@ -98,6 +99,7 @@ parse_packet(const unsigned char *from, struct network *net,
neigh = find_neighbour(from, net);
if(neigh == NULL)
continue;
net->activity_time = now.tv_sec;
if(message[0] == 1) {
debugf("Received request on %s from %s (%s) for %s.\n",
net->ifname,
......@@ -276,6 +278,7 @@ void
send_hello(struct network *net)
{
debugf("Sending hello to %s.\n", net->ifname);
update_hello_interval(net);
start_message(net, 20);
accumulate_byte(net, 0);
net->hello_seqno = ((net->hello_seqno + 1) & 0xFF);
......
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