Commit e45020f7 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use FOR_ALL_NEIGHBOURS throughout.

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