Skip to content

Commit

Permalink
Rename struct network to interface and associated changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Boutier authored and Juliusz Chroboczek committed Sep 9, 2011
1 parent 5f40b62 commit 1c3b2bb
Show file tree
Hide file tree
Showing 14 changed files with 700 additions and 701 deletions.
128 changes: 64 additions & 64 deletions babeld.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ main(int argc, char **argv)
char *config_file = NULL; char *config_file = NULL;
void *vrc; void *vrc;
unsigned int seed; unsigned int seed;
struct network *net; struct interface *ifp;


gettime(&now); gettime(&now);


Expand Down Expand Up @@ -362,22 +362,22 @@ main(int argc, char **argv)
} }


for(i = optind; i < argc; i++) { for(i = optind; i < argc; i++) {
vrc = add_network(argv[i], NULL); vrc = add_interface(argv[i], NULL);
if(vrc == NULL) if(vrc == NULL)
goto fail; goto fail;
} }


if(networks == NULL) { if(interfaces == NULL) {
fprintf(stderr, "Eek... asked to run on no interfaces!\n"); fprintf(stderr, "Eek... asked to run on no interfaces!\n");
goto fail; goto fail;
} }


FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
/* net->ifindex is not necessarily valid at this point */ /* ifp->ifindex is not necessarily valid at this point */
int ifindex = if_nametoindex(net->ifname); int ifindex = if_nametoindex(ifp->name);
if(ifindex > 0) { if(ifindex > 0) {
unsigned char eui[8]; unsigned char eui[8];
rc = if_eui64(net->ifname, ifindex, eui); rc = if_eui64(ifp->name, ifindex, eui);
if(rc < 0) if(rc < 0)
continue; continue;
memcpy(myid, eui, 8); memcpy(myid, eui, 8);
Expand Down Expand Up @@ -482,7 +482,7 @@ main(int argc, char **argv)
rc = resize_receive_buffer(1500); rc = resize_receive_buffer(1500);
if(rc < 0) if(rc < 0)
goto fail; goto fail;
check_networks(); check_interfaces();
if(receive_buffer == NULL) if(receive_buffer == NULL)
goto fail; goto fail;


Expand All @@ -499,27 +499,27 @@ main(int argc, char **argv)


/* Make some noise so that others notice us, and send retractions in /* Make some noise so that others notice us, and send retractions in
case we were restarted recently */ case we were restarted recently */
FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
/* Apply jitter before we send the first message. */ /* Apply jitter before we send the first message. */
usleep(roughly(10000)); usleep(roughly(10000));
gettime(&now); gettime(&now);
send_hello(net); send_hello(ifp);
send_wildcard_retraction(net); send_wildcard_retraction(ifp);
} }


FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
usleep(roughly(10000)); usleep(roughly(10000));
gettime(&now); gettime(&now);
send_hello(net); send_hello(ifp);
send_wildcard_retraction(net); send_wildcard_retraction(ifp);
send_self_update(net); send_self_update(ifp);
send_request(net, NULL, 0); send_request(ifp, NULL, 0);
flushupdates(net); flushupdates(ifp);
flushbuf(net); flushbuf(ifp);
} }


debugf("Entering main loop.\n"); debugf("Entering main loop.\n");
Expand All @@ -535,13 +535,13 @@ main(int argc, char **argv)
timeval_min_sec(&tv, source_expiry_time); timeval_min_sec(&tv, source_expiry_time);
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_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
timeval_min(&tv, &net->flush_timeout); timeval_min(&tv, &ifp->flush_timeout);
timeval_min(&tv, &net->hello_timeout); timeval_min(&tv, &ifp->hello_timeout);
timeval_min(&tv, &net->update_timeout); timeval_min(&tv, &ifp->update_timeout);
timeval_min(&tv, &net->update_flush_timeout); timeval_min(&tv, &ifp->update_flush_timeout);
} }
timeval_min(&tv, &unicast_flush_timeout); timeval_min(&tv, &unicast_flush_timeout);
FD_ZERO(&readfds); FD_ZERO(&readfds);
Expand Down Expand Up @@ -593,11 +593,11 @@ main(int argc, char **argv)
sleep(1); sleep(1);
} }
} else { } else {
FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
if(net->ifindex == sin6.sin6_scope_id) { if(ifp->ifindex == sin6.sin6_scope_id) {
parse_packet((unsigned char*)&sin6.sin6_addr, net, parse_packet((unsigned char*)&sin6.sin6_addr, ifp,
receive_buffer, rc); receive_buffer, rc);
VALGRIND_MAKE_MEM_UNDEFINED(receive_buffer, VALGRIND_MAKE_MEM_UNDEFINED(receive_buffer,
receive_buffer_size); receive_buffer_size);
Expand Down Expand Up @@ -647,7 +647,7 @@ main(int argc, char **argv)
} }


if(kernel_link_changed || kernel_addr_changed) { if(kernel_link_changed || kernel_addr_changed) {
check_networks(); check_interfaces();
kernel_link_changed = 0; kernel_link_changed = 0;
} }


Expand All @@ -671,7 +671,7 @@ main(int argc, char **argv)
} }


if(now.tv_sec >= expiry_time) { if(now.tv_sec >= expiry_time) {
check_networks(); check_interfaces();
expire_routes(); expire_routes();
expire_resend(); expire_resend();
expiry_time = now.tv_sec + roughly(30); expiry_time = now.tv_sec + roughly(30);
Expand All @@ -682,15 +682,15 @@ main(int argc, char **argv)
source_expiry_time = now.tv_sec + roughly(300); source_expiry_time = now.tv_sec + roughly(300);
} }


FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
if(timeval_compare(&now, &net->hello_timeout) >= 0) if(timeval_compare(&now, &ifp->hello_timeout) >= 0)
send_hello(net); send_hello(ifp);
if(timeval_compare(&now, &net->update_timeout) >= 0) if(timeval_compare(&now, &ifp->update_timeout) >= 0)
send_update(net, 0, NULL, 0); send_update(ifp, 0, NULL, 0);
if(timeval_compare(&now, &net->update_flush_timeout) >= 0) if(timeval_compare(&now, &ifp->update_flush_timeout) >= 0)
flushupdates(net); flushupdates(ifp);
} }


if(resend_time.tv_sec != 0) { if(resend_time.tv_sec != 0) {
Expand All @@ -703,12 +703,12 @@ main(int argc, char **argv)
flush_unicast(1); flush_unicast(1);
} }


FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
if(net->flush_timeout.tv_sec != 0) { if(ifp->flush_timeout.tv_sec != 0) {
if(timeval_compare(&now, &net->flush_timeout) >= 0) if(timeval_compare(&now, &ifp->flush_timeout) >= 0)
flushbuf(net); flushbuf(ifp);
} }
} }


Expand All @@ -726,31 +726,31 @@ main(int argc, char **argv)
while(numroutes > 0) { while(numroutes > 0) {
if(routes[0].installed) if(routes[0].installed)
uninstall_route(&routes[0]); uninstall_route(&routes[0]);
/* We need to flush the route so network_up won't reinstall it */ /* We need to flush the route so interface_up won't reinstall it */
flush_route(&routes[0]); flush_route(&routes[0]);
} }


FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
send_wildcard_retraction(net); send_wildcard_retraction(ifp);
/* Make sure that we expire quickly from our neighbours' /* Make sure that we expire quickly from our neighbours'
association caches. */ association caches. */
send_hello_noupdate(net, 10); send_hello_noupdate(ifp, 10);
flushbuf(net); flushbuf(ifp);
usleep(roughly(1000)); usleep(roughly(1000));
gettime(&now); gettime(&now);
} }
FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
/* Make sure they got it. */ /* Make sure they got it. */
send_wildcard_retraction(net); send_wildcard_retraction(ifp);
send_hello_noupdate(net, 1); send_hello_noupdate(ifp, 1);
flushbuf(net); flushbuf(ifp);
usleep(roughly(10000)); usleep(roughly(10000));
gettime(&now); gettime(&now);
network_up(net, 0); interface_up(ifp, 0);
} }
kernel_setup_socket(0); kernel_setup_socket(0);
kernel_setup(0); kernel_setup(0);
Expand Down Expand Up @@ -802,10 +802,10 @@ main(int argc, char **argv)
exit(1); exit(1);


fail: fail:
FOR_ALL_NETS(net) { FOR_ALL_INTERFACES(ifp) {
if(!net_up(net)) if(!if_up(ifp))
continue; continue;
network_up(net, 0); interface_up(ifp, 0);
} }
kernel_setup_socket(0); kernel_setup_socket(0);
kernel_setup(0); kernel_setup(0);
Expand Down Expand Up @@ -936,12 +936,12 @@ dump_tables(FILE *out)
FOR_ALL_NEIGHBOURS(neigh) { FOR_ALL_NEIGHBOURS(neigh) {
fprintf(out, "Neighbour %s dev %s reach %04x rxcost %d txcost %d chan %d%s.\n", fprintf(out, "Neighbour %s dev %s reach %04x rxcost %d txcost %d chan %d%s.\n",
format_address(neigh->address), format_address(neigh->address),
neigh->network->ifname, neigh->ifp->name,
neigh->reach, neigh->reach,
neighbour_rxcost(neigh), neighbour_rxcost(neigh),
neigh->txcost, neigh->txcost,
neigh->network->channel, neigh->ifp->channel,
net_up(neigh->network) ? "" : " (down)"); if_up(neigh->ifp) ? "" : " (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",
Expand Down Expand Up @@ -980,7 +980,7 @@ dump_tables(FILE *out)
(int)routes[i].seqno, (int)routes[i].seqno,
channels, channels,
(int)(now.tv_sec - routes[i].time), (int)(now.tv_sec - routes[i].time),
routes[i].neigh->network->ifname, routes[i].neigh->ifp->name,
format_address(routes[i].neigh->address), format_address(routes[i].neigh->address),
nexthop ? " nexthop " : "", nexthop ? " nexthop " : "",
nexthop ? format_address(nexthop) : "", nexthop ? format_address(nexthop) : "",
Expand Down
Loading

0 comments on commit 1c3b2bb

Please sign in to comment.