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