Commit e45020f7 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use FOR_ALL_NEIGHBOURS throughout.

parent 8d3c6f0e
...@@ -902,23 +902,24 @@ init_signals(void) ...@@ -902,23 +902,24 @@ init_signals(void)
static void static void
dump_tables(FILE *out) dump_tables(FILE *out)
{ {
struct neighbour *neigh;
int i; int i;
fprintf(out, "\n"); fprintf(out, "\n");
fprintf(out, "My id %s seqno %d\n", format_address(myid), myseqno); fprintf(out, "My id %s seqno %d\n", format_address(myid), myseqno);
for(i = 0; i < numneighs; i++) { FOR_ALL_NEIGHBOURS(neigh) {
if(!neighbour_valid(&neighs[i])) if(!neighbour_valid(neigh))
continue; continue;
fprintf(out, "Neighbour %s ", format_address(neighs[i].id)); fprintf(out, "Neighbour %s ", format_address(neigh->id));
fprintf(out, "at %s dev %s reach %04x rxcost %d txcost %d%s.\n", fprintf(out, "at %s dev %s reach %04x rxcost %d txcost %d%s.\n",
format_address(neighs[i].address), format_address(neigh->address),
neighs[i].network->ifname, neigh->network->ifname,
neighs[i].reach, neigh->reach,
neighbour_rxcost(&neighs[i]), neighbour_rxcost(neigh),
neighs[i].txcost, neigh->txcost,
neighs[i].network->up ? "" : " (down)"); neigh->network->up ? "" : " (down)");
} }
for(i = 0; i < numxroutes; i++) { for(i = 0; i < numxroutes; i++) {
fprintf(out, "%s metric %d (%s)\n", fprintf(out, "%s metric %d (%s)\n",
......
...@@ -1009,8 +1009,6 @@ send_self_update(struct network *net, int force_seqno) ...@@ -1009,8 +1009,6 @@ send_self_update(struct network *net, int force_seqno)
void void
send_ihu(struct neighbour *neigh, struct network *net) send_ihu(struct neighbour *neigh, struct network *net)
{ {
int i;
if(neigh == NULL && net == NULL) { if(neigh == NULL && net == NULL) {
struct network *n; struct network *n;
FOR_ALL_NETS(n) { FOR_ALL_NETS(n) {
...@@ -1022,11 +1020,12 @@ send_ihu(struct neighbour *neigh, struct network *net) ...@@ -1022,11 +1020,12 @@ send_ihu(struct neighbour *neigh, struct network *net)
} }
if(neigh == NULL) { if(neigh == NULL) {
for(i = 0; i < numneighs; i++) { struct neighbour *ngh;
if(!neighbour_valid(&neighs[i])) FOR_ALL_NEIGHBOURS(ngh) {
if(!neighbour_valid(ngh))
continue; continue;
if(neighs[i].network == net) if(ngh->network == net)
send_ihu(&neighs[i], net); send_ihu(ngh, net);
} }
} else { } else {
int rxcost, interval; int rxcost, interval;
...@@ -1055,11 +1054,11 @@ send_ihu(struct neighbour *neigh, struct network *net) ...@@ -1055,11 +1054,11 @@ send_ihu(struct neighbour *neigh, struct network *net)
void void
send_marginal_ihu(struct network *net) send_marginal_ihu(struct network *net)
{ {
int i; struct neighbour *neigh;
for(i = 0; i < numneighs; i++) { FOR_ALL_NEIGHBOURS(neigh) {
if(!neighbour_valid(&neighs[i]) || (net && neighs[i].network != net)) if(!neighbour_valid(neigh) || (net && neigh->network != net))
continue; continue;
if(neighs[i].txcost >= 384 || (neighs[i].reach & 0xF000) != 0xF000) if(neigh->txcost >= 384 || (neigh->reach & 0xF000) != 0xF000)
send_ihu(&neighs[i], net); send_ihu(neigh, net);
} }
} }
...@@ -62,13 +62,13 @@ flush_neighbour(struct neighbour *neigh) ...@@ -62,13 +62,13 @@ flush_neighbour(struct neighbour *neigh)
struct neighbour * struct neighbour *
find_neighbour(const unsigned char *address, struct network *net) find_neighbour(const unsigned char *address, struct network *net)
{ {
int i; struct neighbour *neigh;
for(i = 0; i < numneighs; i++) { FOR_ALL_NEIGHBOURS(neigh) {
if(!neighbour_valid(&neighs[i])) if(!neighbour_valid(neigh))
continue; continue;
if(memcmp(address, neighs[i].address, 16) == 0 && if(memcmp(address, neigh->address, 16) == 0 &&
neighs[i].network == net) neigh->network == net)
return &neighs[i]; return neigh;
} }
return NULL; return NULL;
} }
...@@ -77,9 +77,8 @@ struct neighbour * ...@@ -77,9 +77,8 @@ struct neighbour *
add_neighbour(const unsigned char *id, const unsigned char *address, add_neighbour(const unsigned char *id, const unsigned char *address,
struct network *net) struct network *net)
{ {
struct neighbour *neigh; struct neighbour *neigh, *ngh;
const struct timeval zero = {0, 0}; const struct timeval zero = {0, 0};
int i;
neigh = find_neighbour(address, net); neigh = find_neighbour(address, net);
if(neigh) { if(neigh) {
...@@ -94,9 +93,9 @@ add_neighbour(const unsigned char *id, const unsigned char *address, ...@@ -94,9 +93,9 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
} }
debugf("Creating neighbour %s (%s).\n", debugf("Creating neighbour %s (%s).\n",
format_address(id), format_address(address)); format_address(id), format_address(address));
for(i = 0; i < numneighs; i++) { FOR_ALL_NEIGHBOURS(ngh) {
if(!neighbour_valid(&neighs[i])) if(!neighbour_valid(ngh))
neigh = &neighs[i]; neigh = ngh;
} }
if(!neigh) { if(!neigh) {
if(numneighs >= MAXNEIGHBOURS) { if(numneighs >= MAXNEIGHBOURS) {
...@@ -235,35 +234,36 @@ reset_txcost(struct neighbour *neigh) ...@@ -235,35 +234,36 @@ reset_txcost(struct neighbour *neigh)
int int
check_neighbours() check_neighbours()
{ {
int i, changed, delay; struct neighbour *neigh;
int changed, delay;
int msecs = 50000; int msecs = 50000;
debugf("Checking neighbours.\n"); debugf("Checking neighbours.\n");
for(i = 0; i < numneighs; i++) { FOR_ALL_NEIGHBOURS(neigh) {
if(!neighbour_valid(&neighs[i])) if(!neighbour_valid(neigh))
continue; continue;
changed = update_neighbour(&neighs[i], -1, 0); changed = update_neighbour(neigh, -1, 0);
if(neighs[i].reach == 0 || if(neigh->reach == 0 ||
neighs[i].hello_time.tv_sec > now.tv_sec || /* clock stepped */ neigh->hello_time.tv_sec > now.tv_sec || /* clock stepped */
timeval_minus_msec(&now, &neighs[i].hello_time) > 300000) { timeval_minus_msec(&now, &neigh->hello_time) > 300000) {
flush_neighbour(&neighs[i]); flush_neighbour(neigh);
continue; continue;
} }
delay = timeval_minus_msec(&now, &neighs[i].ihu_time); delay = timeval_minus_msec(&now, &neigh->ihu_time);
changed = changed || reset_txcost(&neighs[i]); changed = changed || reset_txcost(neigh);
if(changed) if(changed)
update_neighbour_metric(&neighs[i]); update_neighbour_metric(neigh);
if(neighs[i].hello_interval > 0) if(neigh->hello_interval > 0)
msecs = MIN(msecs, neighs[i].hello_interval * 10); msecs = MIN(msecs, neigh->hello_interval * 10);
if(neighs[i].ihu_interval > 0) if(neigh->ihu_interval > 0)
msecs = MIN(msecs, neighs[i].ihu_interval * 10); msecs = MIN(msecs, neigh->ihu_interval * 10);
} }
return msecs; return msecs;
......
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