Commit 3a055e6d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Replace net->up and net->wired by a bitfield net->flags.

parent f7e96e07
...@@ -501,7 +501,7 @@ main(int argc, char **argv) ...@@ -501,7 +501,7 @@ main(int argc, char **argv)
/* Make some noise so that others notice us */ /* Make some noise so that others notice us */
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
/* Apply jitter before we send the first message. */ /* Apply jitter before we send the first message. */
usleep(roughly(10000)); usleep(roughly(10000));
...@@ -528,7 +528,7 @@ main(int argc, char **argv) ...@@ -528,7 +528,7 @@ main(int argc, char **argv)
timeval_min_sec(&tv, kernel_dump_time); timeval_min_sec(&tv, kernel_dump_time);
timeval_min(&tv, &resend_time); timeval_min(&tv, &resend_time);
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
timeval_min(&tv, &net->flush_timeout); timeval_min(&tv, &net->flush_timeout);
timeval_min(&tv, &net->hello_timeout); timeval_min(&tv, &net->hello_timeout);
...@@ -587,7 +587,7 @@ main(int argc, char **argv) ...@@ -587,7 +587,7 @@ main(int argc, char **argv)
} }
} else { } else {
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
if(net->ifindex == sin6.sin6_scope_id) { if(net->ifindex == sin6.sin6_scope_id) {
parse_packet((unsigned char*)&sin6.sin6_addr, net, parse_packet((unsigned char*)&sin6.sin6_addr, net,
...@@ -676,7 +676,7 @@ main(int argc, char **argv) ...@@ -676,7 +676,7 @@ main(int argc, char **argv)
} }
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
if(timeval_compare(&now, &net->hello_timeout) >= 0) if(timeval_compare(&now, &net->hello_timeout) >= 0)
send_hello(net); send_hello(net);
...@@ -699,7 +699,7 @@ main(int argc, char **argv) ...@@ -699,7 +699,7 @@ main(int argc, char **argv)
} }
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
if(net->flush_timeout.tv_sec != 0) { if(net->flush_timeout.tv_sec != 0) {
if(timeval_compare(&now, &net->flush_timeout) >= 0) if(timeval_compare(&now, &net->flush_timeout) >= 0)
...@@ -726,7 +726,7 @@ main(int argc, char **argv) ...@@ -726,7 +726,7 @@ main(int argc, char **argv)
} }
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
send_wildcard_retraction(net); send_wildcard_retraction(net);
/* Make sure that we expire quickly from our neighbours' /* Make sure that we expire quickly from our neighbours'
...@@ -737,7 +737,7 @@ main(int argc, char **argv) ...@@ -737,7 +737,7 @@ main(int argc, char **argv)
gettime(&now); gettime(&now);
} }
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
/* Make sure they got it. */ /* Make sure they got it. */
send_wildcard_retraction(net); send_wildcard_retraction(net);
...@@ -798,7 +798,7 @@ main(int argc, char **argv) ...@@ -798,7 +798,7 @@ main(int argc, char **argv)
fail: fail:
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net_up(net))
continue; continue;
network_up(net, 0); network_up(net, 0);
} }
...@@ -935,7 +935,7 @@ dump_tables(FILE *out) ...@@ -935,7 +935,7 @@ dump_tables(FILE *out)
neigh->reach, neigh->reach,
neighbour_rxcost(neigh), neighbour_rxcost(neigh),
neigh->txcost, neigh->txcost,
neigh->network->up ? "" : " (down)"); net_up(neigh->network) ? "" : " (down)");
} }
for(i = 0; i < numxroutes; i++) { for(i = 0; i < numxroutes; i++) {
fprintf(out, "%s metric %d (exported)\n", fprintf(out, "%s metric %d (exported)\n",
......
...@@ -631,7 +631,7 @@ send_hello_noupdate(struct network *net, unsigned interval) ...@@ -631,7 +631,7 @@ send_hello_noupdate(struct network *net, unsigned interval)
net->hello_seqno = seqno_plus(net->hello_seqno, 1); net->hello_seqno = seqno_plus(net->hello_seqno, 1);
delay_jitter(&net->hello_timeout, net->hello_interval); delay_jitter(&net->hello_timeout, net->hello_interval);
if(!net->up) if(!net_up(net))
return; return;
debugf("Sending hello %d (%d) to %s.\n", debugf("Sending hello %d (%d) to %s.\n",
...@@ -667,7 +667,7 @@ flush_unicast(int dofree) ...@@ -667,7 +667,7 @@ flush_unicast(int dofree)
if(unicast_buffered == 0) if(unicast_buffered == 0)
goto done; goto done;
if(!unicast_neighbour->network->up) if(!net_up(unicast_neighbour->network))
goto done; goto done;
/* Preserve ordering of messages */ /* Preserve ordering of messages */
...@@ -716,7 +716,7 @@ really_send_update(struct network *net, ...@@ -716,7 +716,7 @@ really_send_update(struct network *net,
const unsigned char *real_prefix; const unsigned char *real_prefix;
unsigned short flags = 0; unsigned short flags = 0;
if(!net->up) if(!net_up(net))
return; return;
add_metric = output_filter(id, prefix, plen, net->ifindex); add_metric = output_filter(id, prefix, plen, net->ifindex);
...@@ -845,7 +845,7 @@ flushupdates(struct network *net) ...@@ -845,7 +845,7 @@ flushupdates(struct network *net)
net->update_bufsize = 0; net->update_bufsize = 0;
net->num_buffered_updates = 0; net->num_buffered_updates = 0;
if(!net->up) if(!net_up(net))
goto done; goto done;
debugf(" (flushing %d buffered updates on %s (%d))\n", debugf(" (flushing %d buffered updates on %s (%d))\n",
...@@ -894,7 +894,8 @@ flushupdates(struct network *net) ...@@ -894,7 +894,8 @@ flushupdates(struct network *net)
if(metric < INFINITY) if(metric < INFINITY)
satisfy_request(route->src->prefix, route->src->plen, satisfy_request(route->src->prefix, route->src->plen,
seqno, route->src->id, net); seqno, route->src->id, net);
if(split_horizon && net->wired && route->neigh->network == net) if(split_horizon && (net->flags & NET_WIRED) &&
route->neigh->network == net)
continue; continue;
really_send_update(net, route->src->id, really_send_update(net, route->src->id,
route->src->prefix, route->src->prefix,
...@@ -979,7 +980,7 @@ send_update(struct network *net, int urgent, ...@@ -979,7 +980,7 @@ send_update(struct network *net, int urgent,
return; return;
} }
if(!net->up) if(!net_up(net))
return; return;
selfonly = selfonly =
...@@ -1035,7 +1036,7 @@ send_wildcard_retraction(struct network *net) ...@@ -1035,7 +1036,7 @@ send_wildcard_retraction(struct network *net)
return; return;
} }
if(!net->up) if(!net_up(net))
return; return;
start_message(net, MESSAGE_UPDATE, 10); start_message(net, MESSAGE_UPDATE, 10);
...@@ -1066,7 +1067,7 @@ send_self_update(struct network *net) ...@@ -1066,7 +1067,7 @@ send_self_update(struct network *net)
if(net == NULL) { if(net == NULL) {
struct network *n; struct network *n;
FOR_ALL_NETS(n) { FOR_ALL_NETS(n) {
if(!n->up) if(!net_up(n))
continue; continue;
send_self_update(n); send_self_update(n);
} }
...@@ -1090,7 +1091,7 @@ send_ihu(struct neighbour *neigh, struct network *net) ...@@ -1090,7 +1091,7 @@ send_ihu(struct neighbour *neigh, struct network *net)
if(neigh == NULL && net == NULL) { if(neigh == NULL && net == NULL) {
struct network *n; struct network *n;
FOR_ALL_NETS(n) { FOR_ALL_NETS(n) {
if(n->up) if(net_up(n))
continue; continue;
send_ihu(NULL, n); send_ihu(NULL, n);
} }
...@@ -1111,7 +1112,7 @@ send_ihu(struct neighbour *neigh, struct network *net) ...@@ -1111,7 +1112,7 @@ send_ihu(struct neighbour *neigh, struct network *net)
return; return;
net = neigh->network; net = neigh->network;
if(!net->up) if(!net_up(net))
return; return;
rxcost = neighbour_rxcost(neigh); rxcost = neighbour_rxcost(neigh);
...@@ -1178,7 +1179,7 @@ send_request(struct network *net, ...@@ -1178,7 +1179,7 @@ send_request(struct network *net,
if(net == NULL) { if(net == NULL) {
struct network *n; struct network *n;
FOR_ALL_NETS(n) { FOR_ALL_NETS(n) {
if(n->up) if(net_up(n))
continue; continue;
send_request(n, prefix, plen); send_request(n, prefix, plen);
} }
...@@ -1188,7 +1189,7 @@ send_request(struct network *net, ...@@ -1188,7 +1189,7 @@ send_request(struct network *net,
/* make sure any buffered updates go out before this request. */ /* make sure any buffered updates go out before this request. */
flushupdates(net); flushupdates(net);
if(!net->up) if(!net_up(net))
return; return;
debugf("sending request to %s for %s.\n", debugf("sending request to %s for %s.\n",
...@@ -1250,14 +1251,14 @@ send_multihop_request(struct network *net, ...@@ -1250,14 +1251,14 @@ send_multihop_request(struct network *net,
if(net == NULL) { if(net == NULL) {
struct network *n; struct network *n;
FOR_ALL_NETS(n) { FOR_ALL_NETS(n) {
if(!n->up) if(!net_up(n))
continue; continue;
send_multihop_request(n, prefix, plen, seqno, id, hop_count); send_multihop_request(n, prefix, plen, seqno, id, hop_count);
} }
return; return;
} }
if(!net->up) if(!net_up(net))
return; return;
debugf("Sending request (%d) on %s for %s.\n", debugf("Sending request (%d) on %s for %s.\n",
......
...@@ -273,7 +273,7 @@ neighbour_rxcost(struct neighbour *neigh) ...@@ -273,7 +273,7 @@ neighbour_rxcost(struct neighbour *neigh)
if((reach & 0xFFF0) == 0 || delay >= 180000) { if((reach & 0xFFF0) == 0 || delay >= 180000) {
return INFINITY; return INFINITY;
} else if(neigh->network->wired) { } else if((neigh->network->flags & NET_WIRED)) {
/* To lose one hello is a misfortune, to lose two is carelessness. */ /* To lose one hello is a misfortune, to lose two is carelessness. */
if((reach & 0xC000) == 0xC000) if((reach & 0xC000) == 0xC000)
return neigh->network->cost; return neigh->network->cost;
...@@ -303,7 +303,7 @@ neighbour_cost(struct neighbour *neigh) ...@@ -303,7 +303,7 @@ neighbour_cost(struct neighbour *neigh)
{ {
unsigned a, b; unsigned a, b;
if(!neigh->network->up) if(!net_up(neigh->network))
return INFINITY; return INFINITY;
a = neighbour_txcost(neigh); a = neighbour_txcost(neigh);
...@@ -315,7 +315,7 @@ neighbour_cost(struct neighbour *neigh) ...@@ -315,7 +315,7 @@ neighbour_cost(struct neighbour *neigh)
if(b >= INFINITY) if(b >= INFINITY)
return INFINITY; return INFINITY;
if(neigh->network->wired || (a <= 256 && b <= 256)) { if((neigh->network->flags & NET_WIRED) || (a <= 256 && b <= 256)) {
return a; return a;
} else { } else {
/* a = 256/alpha, b = 256/beta, where alpha and beta are the expected /* a = 256/alpha, b = 256/beta, where alpha and beta are the expected
......
...@@ -105,7 +105,7 @@ update_hello_interval(struct network *net) ...@@ -105,7 +105,7 @@ update_hello_interval(struct network *net)
net->hello_interval = idle_hello_interval; net->hello_interval = idle_hello_interval;
rc = 1; rc = 1;
} }
} else if(net->wired) { } else if((net->flags & NET_WIRED)) {
if(net->hello_interval != wired_hello_interval) { if(net->hello_interval != wired_hello_interval) {
net->hello_interval = wired_hello_interval; net->hello_interval = wired_hello_interval;
rc = 1; rc = 1;
...@@ -190,10 +190,13 @@ network_up(struct network *net, int up) ...@@ -190,10 +190,13 @@ network_up(struct network *net, int up)
int mtu, rc, wired; int mtu, rc, wired;
struct ipv6_mreq mreq; struct ipv6_mreq mreq;
if(up == net->up) if((!!up) == net_up(net))
return 0; return 0;
net->up = up; if(up)
net->flags |= NET_UP;
else
net->flags &= ~NET_UP;
if(up) { if(up) {
unsigned char ll[32][16]; unsigned char ll[32][16];
...@@ -256,8 +259,13 @@ network_up(struct network *net, int up) ...@@ -256,8 +259,13 @@ network_up(struct network *net, int up)
} }
} }
net->wired = wired; if(wired) {
net->cost = wired ? 96 : 256; net->flags |= NET_WIRED;
net->cost = 96;
} else {
net->flags &= ~NET_WIRED;
net->cost = 256;
}
update_hello_interval(net); update_hello_interval(net);
memset(&mreq, 0, sizeof(mreq)); memset(&mreq, 0, sizeof(mreq));
...@@ -334,7 +342,7 @@ network_ll_address(struct network *net, const unsigned char *address) ...@@ -334,7 +342,7 @@ network_ll_address(struct network *net, const unsigned char *address)
{ {
int i; int i;
if(!net->up) if(!net_up(net))
return 0; return 0;
for(i = 0; i < net->numll; i++) for(i = 0; i < net->numll; i++)
...@@ -364,7 +372,7 @@ check_networks(void) ...@@ -364,7 +372,7 @@ check_networks(void)
rc = kernel_interface_operational(net->ifname, net->ifindex); rc = kernel_interface_operational(net->ifname, net->ifindex);
else else
rc = 0; rc = 0;
if((rc > 0) != net->up) { if((rc > 0) != net_up(net)) {
debugf("Noticed status change for %s.\n", net->ifname); debugf("Noticed status change for %s.\n", net->ifname);
network_up(net, rc > 0); network_up(net, rc > 0);
} }
......
...@@ -32,12 +32,14 @@ struct network_conf { ...@@ -32,12 +32,14 @@ struct network_conf {
struct network_conf *next; struct network_conf *next;
}; };
#define NET_UP (1 << 0)
#define NET_WIRED (1<<1)
struct network { struct network {
struct network *next; struct network *next;
struct network_conf *conf; struct network_conf *conf;
char up;
char wired;
unsigned int ifindex; unsigned int ifindex;
unsigned short flags;
unsigned short cost; unsigned short cost;
struct timeval hello_timeout; struct timeval hello_timeout;
struct timeval self_update_timeout; struct timeval self_update_timeout;
...@@ -74,6 +76,12 @@ extern int numnets; ...@@ -74,6 +76,12 @@ extern int numnets;
#define FOR_ALL_NETS(_net) for(_net = networks; _net; _net = _net->next) #define FOR_ALL_NETS(_net) for(_net = networks; _net; _net = _net->next)
static inline int
net_up(struct network *net)
{
return !!(net->flags & NET_UP);
}
struct network *add_network(char *ifname, struct network_conf *conf); struct network *add_network(char *ifname, struct network_conf *conf);
int network_idle(struct network *net); int network_idle(struct network *net);
int update_hello_interval(struct network *net); int update_hello_interval(struct network *net);
......
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