Skip to content
Browse files

Rename struct network to interface and associated changes.

  • Loading branch information...
1 parent 5f40b62 commit 1c3b2bb897478ec0430896b83e0c07cab4debd97 @boutier boutier committed with
Showing with 700 additions and 701 deletions.
  1. +64 −64 babeld.c
  2. +46 −46 configuration.c
  3. +3 −3 kernel_netlink.c
  4. +2 −2 local.c
  5. +303 −303 message.c
  6. +13 −13 message.h
  7. +16 −16 neighbour.c
  8. +2 −2 neighbour.h
  9. +185 −185 network.c
  10. +28 −29 network.h
  11. +12 −12 resend.c
  12. +4 −4 resend.h
  13. +19 −19 route.c
  14. +3 −3 route.h
View
128 babeld.c
@@ -108,7 +108,7 @@ main(int argc, char **argv)
char *config_file = NULL;
void *vrc;
unsigned int seed;
- struct network *net;
+ struct interface *ifp;
gettime(&now);
@@ -362,22 +362,22 @@ main(int argc, char **argv)
}
for(i = optind; i < argc; i++) {
- vrc = add_network(argv[i], NULL);
+ vrc = add_interface(argv[i], NULL);
if(vrc == NULL)
goto fail;
}
- if(networks == NULL) {
+ if(interfaces == NULL) {
fprintf(stderr, "Eek... asked to run on no interfaces!\n");
goto fail;
}
- FOR_ALL_NETS(net) {
- /* net->ifindex is not necessarily valid at this point */
- int ifindex = if_nametoindex(net->ifname);
+ FOR_ALL_INTERFACES(ifp) {
+ /* ifp->ifindex is not necessarily valid at this point */
+ int ifindex = if_nametoindex(ifp->name);
if(ifindex > 0) {
unsigned char eui[8];
- rc = if_eui64(net->ifname, ifindex, eui);
+ rc = if_eui64(ifp->name, ifindex, eui);
if(rc < 0)
continue;
memcpy(myid, eui, 8);
@@ -482,7 +482,7 @@ main(int argc, char **argv)
rc = resize_receive_buffer(1500);
if(rc < 0)
goto fail;
- check_networks();
+ check_interfaces();
if(receive_buffer == NULL)
goto fail;
@@ -499,27 +499,27 @@ main(int argc, char **argv)
/* Make some noise so that others notice us, and send retractions in
case we were restarted recently */
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
/* Apply jitter before we send the first message. */
usleep(roughly(10000));
gettime(&now);
- send_hello(net);
- send_wildcard_retraction(net);
+ send_hello(ifp);
+ send_wildcard_retraction(ifp);
}
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
usleep(roughly(10000));
gettime(&now);
- send_hello(net);
- send_wildcard_retraction(net);
- send_self_update(net);
- send_request(net, NULL, 0);
- flushupdates(net);
- flushbuf(net);
+ send_hello(ifp);
+ send_wildcard_retraction(ifp);
+ send_self_update(ifp);
+ send_request(ifp, NULL, 0);
+ flushupdates(ifp);
+ flushbuf(ifp);
}
debugf("Entering main loop.\n");
@@ -535,13 +535,13 @@ main(int argc, char **argv)
timeval_min_sec(&tv, source_expiry_time);
timeval_min_sec(&tv, kernel_dump_time);
timeval_min(&tv, &resend_time);
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
- timeval_min(&tv, &net->flush_timeout);
- timeval_min(&tv, &net->hello_timeout);
- timeval_min(&tv, &net->update_timeout);
- timeval_min(&tv, &net->update_flush_timeout);
+ timeval_min(&tv, &ifp->flush_timeout);
+ timeval_min(&tv, &ifp->hello_timeout);
+ timeval_min(&tv, &ifp->update_timeout);
+ timeval_min(&tv, &ifp->update_flush_timeout);
}
timeval_min(&tv, &unicast_flush_timeout);
FD_ZERO(&readfds);
@@ -593,11 +593,11 @@ main(int argc, char **argv)
sleep(1);
}
} else {
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
- if(net->ifindex == sin6.sin6_scope_id) {
- parse_packet((unsigned char*)&sin6.sin6_addr, net,
+ if(ifp->ifindex == sin6.sin6_scope_id) {
+ parse_packet((unsigned char*)&sin6.sin6_addr, ifp,
receive_buffer, rc);
VALGRIND_MAKE_MEM_UNDEFINED(receive_buffer,
receive_buffer_size);
@@ -647,7 +647,7 @@ main(int argc, char **argv)
}
if(kernel_link_changed || kernel_addr_changed) {
- check_networks();
+ check_interfaces();
kernel_link_changed = 0;
}
@@ -671,7 +671,7 @@ main(int argc, char **argv)
}
if(now.tv_sec >= expiry_time) {
- check_networks();
+ check_interfaces();
expire_routes();
expire_resend();
expiry_time = now.tv_sec + roughly(30);
@@ -682,15 +682,15 @@ main(int argc, char **argv)
source_expiry_time = now.tv_sec + roughly(300);
}
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
- if(timeval_compare(&now, &net->hello_timeout) >= 0)
- send_hello(net);
- if(timeval_compare(&now, &net->update_timeout) >= 0)
- send_update(net, 0, NULL, 0);
- if(timeval_compare(&now, &net->update_flush_timeout) >= 0)
- flushupdates(net);
+ if(timeval_compare(&now, &ifp->hello_timeout) >= 0)
+ send_hello(ifp);
+ if(timeval_compare(&now, &ifp->update_timeout) >= 0)
+ send_update(ifp, 0, NULL, 0);
+ if(timeval_compare(&now, &ifp->update_flush_timeout) >= 0)
+ flushupdates(ifp);
}
if(resend_time.tv_sec != 0) {
@@ -703,12 +703,12 @@ main(int argc, char **argv)
flush_unicast(1);
}
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
- if(net->flush_timeout.tv_sec != 0) {
- if(timeval_compare(&now, &net->flush_timeout) >= 0)
- flushbuf(net);
+ if(ifp->flush_timeout.tv_sec != 0) {
+ if(timeval_compare(&now, &ifp->flush_timeout) >= 0)
+ flushbuf(ifp);
}
}
@@ -726,31 +726,31 @@ main(int argc, char **argv)
while(numroutes > 0) {
if(routes[0].installed)
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]);
}
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
- send_wildcard_retraction(net);
+ send_wildcard_retraction(ifp);
/* Make sure that we expire quickly from our neighbours'
association caches. */
- send_hello_noupdate(net, 10);
- flushbuf(net);
+ send_hello_noupdate(ifp, 10);
+ flushbuf(ifp);
usleep(roughly(1000));
gettime(&now);
}
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
/* Make sure they got it. */
- send_wildcard_retraction(net);
- send_hello_noupdate(net, 1);
- flushbuf(net);
+ send_wildcard_retraction(ifp);
+ send_hello_noupdate(ifp, 1);
+ flushbuf(ifp);
usleep(roughly(10000));
gettime(&now);
- network_up(net, 0);
+ interface_up(ifp, 0);
}
kernel_setup_socket(0);
kernel_setup(0);
@@ -802,10 +802,10 @@ main(int argc, char **argv)
exit(1);
fail:
- FOR_ALL_NETS(net) {
- if(!net_up(net))
+ FOR_ALL_INTERFACES(ifp) {
+ if(!if_up(ifp))
continue;
- network_up(net, 0);
+ interface_up(ifp, 0);
}
kernel_setup_socket(0);
kernel_setup(0);
@@ -936,12 +936,12 @@ dump_tables(FILE *out)
FOR_ALL_NEIGHBOURS(neigh) {
fprintf(out, "Neighbour %s dev %s reach %04x rxcost %d txcost %d chan %d%s.\n",
format_address(neigh->address),
- neigh->network->ifname,
+ neigh->ifp->name,
neigh->reach,
neighbour_rxcost(neigh),
neigh->txcost,
- neigh->network->channel,
- net_up(neigh->network) ? "" : " (down)");
+ neigh->ifp->channel,
+ if_up(neigh->ifp) ? "" : " (down)");
}
for(i = 0; i < numxroutes; i++) {
fprintf(out, "%s metric %d (exported)\n",
@@ -980,7 +980,7 @@ dump_tables(FILE *out)
(int)routes[i].seqno,
channels,
(int)(now.tv_sec - routes[i].time),
- routes[i].neigh->network->ifname,
+ routes[i].neigh->ifp->name,
format_address(routes[i].neigh->address),
nexthop ? " nexthop " : "",
nexthop ? format_address(nexthop) : "",
View
92 configuration.c
@@ -40,7 +40,7 @@ THE SOFTWARE.
struct filter *input_filters = NULL;
struct filter *output_filters = NULL;
struct filter *redistribute_filters = NULL;
-struct network_conf *network_confs = NULL;
+struct interface_conf *interface_confs = NULL;
/* get_next_char callback */
typedef int (*gnc_t)(void*);
@@ -370,15 +370,15 @@ parse_filter(gnc_t gnc, void *closure)
return NULL;
}
-static struct network_conf *
-parse_nconf(gnc_t gnc, void *closure)
+static struct interface_conf *
+parse_ifconf(gnc_t gnc, void *closure)
{
int c;
char *token;
- struct network_conf *nconf;
+ struct interface_conf *if_conf;
- nconf = calloc(1, sizeof(struct network_conf));
- if(nconf == NULL)
+ if_conf = calloc(1, sizeof(struct interface_conf));
+ if(if_conf == NULL)
goto error;
c = gnc(closure);
@@ -393,7 +393,7 @@ parse_nconf(gnc_t gnc, void *closure)
if(c < -1 || token == NULL)
goto error;
- nconf->ifname = token;
+ if_conf->ifname = token;
while(c >= 0 && c != '\n') {
c = skip_whitespace(c, gnc, closure);
@@ -410,43 +410,43 @@ parse_nconf(gnc_t gnc, void *closure)
c = getint(c, &cost, gnc, closure);
if(c < -1 || cost <= 0 || cost > 0xFFFF)
goto error;
- nconf->cost = cost;
+ if_conf->cost = cost;
} else if(strcmp(token, "hello-interval") == 0) {
int interval;
c = getmsec(c, &interval, gnc, closure);
if(c < -1 || interval <= 0 || interval > 10 * 0xFFFF)
goto error;
- nconf->hello_interval = interval;
+ if_conf->hello_interval = interval;
} else if(strcmp(token, "update-interval") == 0) {
int interval;
c = getmsec(c, &interval, gnc, closure);
if(c < -1 || interval <= 0 || interval > 10 * 0xFFFF)
goto error;
- nconf->update_interval = interval;
+ if_conf->update_interval = interval;
} else if(strcmp(token, "wired") == 0) {
int v;
c = getbool(c, &v, gnc, closure);
if(c < -1)
goto error;
- nconf->wired = v;
+ if_conf->wired = v;
} else if(strcmp(token, "faraway") == 0) {
int v;
c = getbool(c, &v, gnc, closure);
if(c < -1)
goto error;
- nconf->faraway = v;
+ if_conf->faraway = v;
} else if(strcmp(token, "link-quality") == 0) {
int v;
c = getbool(c, &v, gnc, closure);
if(c < -1)
goto error;
- nconf->lq = v;
+ if_conf->lq = v;
} else if(strcmp(token, "split-horizon") == 0) {
int v;
c = getbool(c, &v, gnc, closure);
if(c < -1)
goto error;
- nconf->split_horizon = v;
+ if_conf->split_horizon = v;
} else if(strcmp(token, "channel") == 0) {
char *t, *end;
@@ -455,19 +455,19 @@ parse_nconf(gnc_t gnc, void *closure)
goto error;
if(strcmp(t, "noninterfering") == 0)
- nconf->channel = NET_CHANNEL_NONINTERFERING;
+ if_conf->channel = IF_CHANNEL_NONINTERFERING;
else if(strcmp(t, "interfering") == 0)
- nconf->channel = NET_CHANNEL_INTERFERING;
+ if_conf->channel = IF_CHANNEL_INTERFERING;
else {
- nconf->channel = strtol(t, &end, 0);
+ if_conf->channel = strtol(t, &end, 0);
if(*end != '\0')
goto error;
}
free(t);
- if((nconf->channel < 1 || nconf->channel > 254) &&
- nconf->channel != NET_CHANNEL_NONINTERFERING)
+ if((if_conf->channel < 1 || if_conf->channel > 254) &&
+ if_conf->channel != IF_CHANNEL_NONINTERFERING)
goto error;
} else {
goto error;
@@ -475,10 +475,10 @@ parse_nconf(gnc_t gnc, void *closure)
free(token);
}
- return nconf;
+ return if_conf;
error:
- free(nconf);
+ free(if_conf);
return NULL;
}
@@ -499,7 +499,7 @@ add_filter(struct filter *filter, struct filter **filters)
}
static void
-merge_nconf(struct network_conf *dest, struct network_conf *src)
+merge_ifconf(struct interface_conf *dest, struct interface_conf *src)
{
assert(strcmp(dest->ifname, src->ifname) == 0);
@@ -520,24 +520,24 @@ merge_nconf(struct network_conf *dest, struct network_conf *src)
}
static void
-add_nconf(struct network_conf *nconf, struct network_conf **nconfs)
+add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs)
{
- if(*nconfs == NULL) {
- nconf->next = NULL;
- *nconfs = nconf;
+ if(*if_confs == NULL) {
+ if_conf->next = NULL;
+ *if_confs = if_conf;
} else {
- struct network_conf *n;
- n = *nconfs;
- while(n->next) {
- if(strcmp(n->ifname, nconf->ifname) == 0) {
- merge_nconf(n, nconf);
- free(nconf);
+ struct interface_conf *if_c;
+ if_c = *if_confs;
+ while(if_c->next) {
+ if(strcmp(if_c->ifname, if_conf->ifname) == 0) {
+ merge_ifconf(if_c, if_conf);
+ free(if_conf);
return;
}
- n = n->next;
+ if_c = if_c->next;
}
- nconf->next = NULL;
- n->next = nconf;
+ if_conf->next = NULL;
+ if_c->next = if_conf;
}
}
@@ -582,11 +582,11 @@ parse_config(gnc_t gnc, void *closure)
return -1;
add_filter(filter, &redistribute_filters);
} else if(strcmp(token, "interface") == 0) {
- struct network_conf *nconf;
- nconf = parse_nconf(gnc, closure);
- if(nconf == NULL)
+ struct interface_conf *if_conf;
+ if_conf = parse_ifconf(gnc, closure);
+ if(if_conf == NULL)
return -1;
- add_nconf(nconf, &network_confs);
+ add_ifconf(if_conf, &interface_confs);
} else {
return -1;
}
@@ -759,15 +759,15 @@ finalise_config()
filter->plen_le = 128;
add_filter(filter, &redistribute_filters);
- while(network_confs) {
- struct network_conf *n;
+ while(interface_confs) {
+ struct interface_conf *if_conf;
void *vrc;
- n = network_confs;
- network_confs = network_confs->next;
- n->next = NULL;
- vrc = add_network(n->ifname, n);
+ if_conf = interface_confs;
+ interface_confs = interface_confs->next;
+ if_conf->next = NULL;
+ vrc = add_interface(if_conf->ifname, if_conf);
if(vrc == NULL) {
- fprintf(stderr, "Couldn't add interface %s.\n", n->ifname);
+ fprintf(stderr, "Couldn't add interface %s.\n", if_conf->ifname);
return -1;
}
}
View
6 kernel_netlink.c
@@ -1239,7 +1239,7 @@ filter_link(struct nlmsghdr *nh, void *data)
int ifindex;
char *ifname;
unsigned int ifflags;
- struct network *net;
+ struct interface *ifp;
len = nh->nlmsg_len;
@@ -1257,8 +1257,8 @@ filter_link(struct nlmsghdr *nh, void *data)
return 0;
kdebugf("filter_interfaces: link change on if %s(%d): 0x%x\n",
ifname, ifindex, (unsigned)ifflags);
- FOR_ALL_NETS(net) {
- if (strcmp(net->ifname, ifname) == 0)
+ FOR_ALL_INTERFACES(ifp) {
+ if (strcmp(ifp->name, ifname) == 0)
return 1;
}
return 0;
View
4 local.c
@@ -140,7 +140,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
address as a unique identifier. */
(unsigned long int)neigh,
format_address(neigh->address),
- neigh->network->ifname,
+ neigh->ifp->name,
neigh->reach,
neighbour_rxcost(neigh),
neighbour_txcost(neigh),
@@ -207,7 +207,7 @@ local_notify_route(struct route *route, int kind)
format_eui64(route->src->id),
route_metric(route), route->refmetric,
format_address(route->neigh->address),
- route->neigh->network->ifname);
+ route->neigh->ifp->name);
if(rc < 0 || rc >= 512)
goto fail;
View
606 message.c
@@ -182,7 +182,7 @@ channels_len(unsigned char *channels)
}
void
-parse_packet(const unsigned char *from, struct network *net,
+parse_packet(const unsigned char *from, struct interface *ifp,
const unsigned char *packet, int packetlen)
{
int i;
@@ -203,18 +203,18 @@ parse_packet(const unsigned char *from, struct network *net,
if(packet[0] != 42) {
fprintf(stderr, "Received malformed packet on %s from %s.\n",
- net->ifname, format_address(from));
+ ifp->name, format_address(from));
return;
}
if(packet[1] != 2) {
fprintf(stderr,
"Received packet with unknown version %d on %s from %s.\n",
- packet[1], net->ifname, format_address(from));
+ packet[1], ifp->name, format_address(from));
return;
}
- neigh = find_neighbour(from, net);
+ neigh = find_neighbour(from, ifp);
if(neigh == NULL) {
fprintf(stderr, "Couldn't allocate neighbour.\n");
return;
@@ -234,7 +234,7 @@ parse_packet(const unsigned char *from, struct network *net,
type = message[0];
if(type == MESSAGE_PAD1) {
debugf("Received pad1 from %s on %s.\n",
- format_address(from), net->ifname);
+ format_address(from), ifp->name);
i++;
continue;
}
@@ -250,18 +250,18 @@ parse_packet(const unsigned char *from, struct network *net,
if(type == MESSAGE_PADN) {
debugf("Received pad%d from %s on %s.\n",
- len, format_address(from), net->ifname);
+ len, format_address(from), ifp->name);
} else if(type == MESSAGE_ACK_REQ) {
unsigned short nonce, interval;
if(len < 6) goto fail;
DO_NTOHS(nonce, message + 4);
DO_NTOHS(interval, message + 6);
debugf("Received ack-req (%04X %d) from %s on %s.\n",
- nonce, interval, format_address(from), net->ifname);
+ nonce, interval, format_address(from), ifp->name);
send_ack(neigh, nonce, interval);
} else if(type == MESSAGE_ACK) {
debugf("Received ack from %s on %s.\n",
- format_address(from), net->ifname);
+ format_address(from), ifp->name);
/* Nothing right now */
} else if(type == MESSAGE_HELLO) {
unsigned short seqno, interval;
@@ -271,9 +271,9 @@ parse_packet(const unsigned char *from, struct network *net,
DO_NTOHS(interval, message + 6);
debugf("Received hello %d (%d) from %s on %s.\n",
seqno, interval,
- format_address(from), net->ifname);
- net->activity_time = now.tv_sec;
- update_hello_interval(net);
+ format_address(from), ifp->name);
+ ifp->activity_time = now.tv_sec;
+ update_hello_interval(ifp);
changed = update_neighbour(neigh, seqno, interval);
update_neighbour_metric(neigh, changed);
if(interval > 0)
@@ -289,9 +289,9 @@ parse_packet(const unsigned char *from, struct network *net,
if(rc < 0) goto fail;
debugf("Received ihu %d (%d) from %s on %s for %s.\n",
txcost, interval,
- format_address(from), net->ifname,
+ format_address(from), ifp->name,
format_address(address));
- if(message[2] == 0 || network_ll_address(net, address)) {
+ if(message[2] == 0 || interface_ll_address(ifp, address)) {
int changed = txcost != neigh->txcost;
neigh->txcost = txcost;
neigh->ihu_time = now;
@@ -308,7 +308,7 @@ parse_packet(const unsigned char *from, struct network *net,
memcpy(router_id, message + 4, 8);
have_router_id = 1;
debugf("Received router-id %s from %s on %s.\n",
- format_eui64(router_id), format_address(from), net->ifname);
+ format_eui64(router_id), format_address(from), ifp->name);
} else if(type == MESSAGE_NH) {
unsigned char nh[16];
int rc;
@@ -326,7 +326,7 @@ parse_packet(const unsigned char *from, struct network *net,
}
debugf("Received nh %s (%d) from %s on %s.\n",
format_address(nh), message[2],
- format_address(from), net->ifname);
+ format_address(from), ifp->name);
if(message[2] == 1) {
memcpy(v4_nh, nh, 16);
have_v4_nh = 1;
@@ -391,7 +391,7 @@ parse_packet(const unsigned char *from, struct network *net,
(message[3] & 0x80) ? "/prefix" : "",
(message[3] & 0x40) ? "/id" : "",
format_prefix(prefix, plen),
- format_address(from), net->ifname);
+ format_address(from), ifp->name);
if(message[2] == 0) {
if(metric < 0xFFFF) {
@@ -412,11 +412,11 @@ parse_packet(const unsigned char *from, struct network *net,
}
if(message[2] == 1) {
- if(!net->ipv4)
+ if(!ifp->ipv4)
goto done;
}
- if((net->flags & NET_FARAWAY)) {
+ if((ifp->flags & IF_FARAWAY)) {
channels[0] = 0;
} else {
/* This will be overwritten by parse_route_attributes below. */
@@ -425,7 +425,7 @@ parse_packet(const unsigned char *from, struct network *net,
channels[0] = 0;
} else {
/* Assume interfering. */
- channels[0] = NET_CHANNEL_INTERFERING;
+ channels[0] = IF_CHANNEL_INTERFERING;
channels[1] = 0;
}
@@ -447,14 +447,14 @@ parse_packet(const unsigned char *from, struct network *net,
plen = message[3] + (message[2] == 1 ? 96 : 0);
debugf("Received request for %s from %s on %s.\n",
message[2] == 0 ? "any" : format_prefix(prefix, plen),
- format_address(from), net->ifname);
+ format_address(from), ifp->name);
if(message[2] == 0) {
/* If a neighbour is requesting a full route dump from us,
we might as well send it an IHU. */
send_ihu(neigh, NULL);
- send_update(neigh->network, 0, NULL, 0);
+ send_update(neigh->ifp, 0, NULL, 0);
} else {
- send_update(neigh->network, 0, prefix, plen);
+ send_update(neigh->ifp, 0, prefix, plen);
}
} else if(type == MESSAGE_MH_REQUEST) {
unsigned char prefix[16], plen;
@@ -469,13 +469,13 @@ parse_packet(const unsigned char *from, struct network *net,
debugf("Received request (%d) for %s from %s on %s (%s, %d).\n",
message[6],
format_prefix(prefix, plen),
- format_address(from), net->ifname,
+ format_address(from), ifp->name,
format_eui64(message + 8), seqno);
handle_request(neigh, prefix, plen, message[6],
seqno, message + 8);
} else {
debugf("Received unknown packet type %d from %s on %s.\n",
- type, format_address(from), net->ifname);
+ type, format_address(from), ifp->name);
}
done:
i += len + 2;
@@ -483,7 +483,7 @@ parse_packet(const unsigned char *from, struct network *net,
fail:
fprintf(stderr, "Couldn't parse packet (%d, %d) from %s on %s.\n",
- message[0], message[1], format_address(from), net->ifname);
+ message[0], message[1], format_address(from), ifp->name);
goto done;
}
return;
@@ -494,20 +494,20 @@ parse_packet(const unsigned char *from, struct network *net,
should never trigger. But I'm superstitious. */
static int
-check_bucket(struct network *net)
+check_bucket(struct interface *ifp)
{
- if(net->bucket <= 0) {
- int seconds = now.tv_sec - net->bucket_time;
+ if(ifp->bucket <= 0) {
+ int seconds = now.tv_sec - ifp->bucket_time;
if(seconds > 0) {
- net->bucket = MIN(BUCKET_TOKENS_MAX,
+ ifp->bucket = MIN(BUCKET_TOKENS_MAX,
seconds * BUCKET_TOKENS_PER_SEC);
}
/* Reset bucket time unconditionally, in case clock is stepped. */
- net->bucket_time = now.tv_sec;
+ ifp->bucket_time = now.tv_sec;
}
- if(net->bucket > 0) {
- net->bucket--;
+ if(ifp->bucket > 0) {
+ ifp->bucket--;
return 1;
} else {
return 0;
@@ -515,65 +515,65 @@ check_bucket(struct network *net)
}
void
-flushbuf(struct network *net)
+flushbuf(struct interface *ifp)
{
int rc;
struct sockaddr_in6 sin6;
- assert(net->buffered <= net->bufsize);
+ assert(ifp->buffered <= ifp->bufsize);
- flushupdates(net);
+ flushupdates(ifp);
- if(net->buffered > 0) {
+ if(ifp->buffered > 0) {
debugf(" (flushing %d buffered bytes on %s)\n",
- net->buffered, net->ifname);
- if(check_bucket(net)) {
+ ifp->buffered, ifp->name);
+ if(check_bucket(ifp)) {
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
memcpy(&sin6.sin6_addr, protocol_group, 16);
sin6.sin6_port = htons(protocol_port);
- sin6.sin6_scope_id = net->ifindex;
- DO_HTONS(packet_header + 2, net->buffered);
+ sin6.sin6_scope_id = ifp->ifindex;
+ DO_HTONS(packet_header + 2, ifp->buffered);
rc = babel_send(protocol_socket,
packet_header, sizeof(packet_header),
- net->sendbuf, net->buffered,
+ ifp->sendbuf, ifp->buffered,
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0)
perror("send");
} else {
fprintf(stderr, "Warning: bucket full, dropping packet to %s.\n",
- net->ifname);
+ ifp->name);
}
}
- VALGRIND_MAKE_MEM_UNDEFINED(net->sendbuf, net->bufsize);
- net->buffered = 0;
- net->have_buffered_hello = 0;
- net->have_buffered_id = 0;
- net->have_buffered_nh = 0;
- net->have_buffered_prefix = 0;
- net->flush_timeout.tv_sec = 0;
- net->flush_timeout.tv_usec = 0;
+ VALGRIND_MAKE_MEM_UNDEFINED(ifp->sendbuf, ifp->bufsize);
+ ifp->buffered = 0;
+ ifp->have_buffered_hello = 0;
+ ifp->have_buffered_id = 0;
+ ifp->have_buffered_nh = 0;
+ ifp->have_buffered_prefix = 0;
+ ifp->flush_timeout.tv_sec = 0;
+ ifp->flush_timeout.tv_usec = 0;
}
static void
-schedule_flush(struct network *net)
+schedule_flush(struct interface *ifp)
{
- unsigned msecs = jitter(net, 0);
- if(net->flush_timeout.tv_sec != 0 &&
- timeval_minus_msec(&net->flush_timeout, &now) < msecs)
+ unsigned msecs = jitter(ifp, 0);
+ if(ifp->flush_timeout.tv_sec != 0 &&
+ timeval_minus_msec(&ifp->flush_timeout, &now) < msecs)
return;
- set_timeout(&net->flush_timeout, msecs);
+ set_timeout(&ifp->flush_timeout, msecs);
}
static void
-schedule_flush_now(struct network *net)
+schedule_flush_now(struct interface *ifp)
{
/* Almost now */
unsigned msecs = roughly(10);
- if(net->flush_timeout.tv_sec != 0 &&
- timeval_minus_msec(&net->flush_timeout, &now) < msecs)
+ if(ifp->flush_timeout.tv_sec != 0 &&
+ timeval_minus_msec(&ifp->flush_timeout, &now) < msecs)
return;
- set_timeout(&net->flush_timeout, msecs);
+ set_timeout(&ifp->flush_timeout, msecs);
}
static void
@@ -590,49 +590,49 @@ schedule_unicast_flush(unsigned msecs)
}
static void
-ensure_space(struct network *net, int space)
+ensure_space(struct interface *ifp, int space)
{
- if(net->bufsize - net->buffered < space)
- flushbuf(net);
+ if(ifp->bufsize - ifp->buffered < space)
+ flushbuf(ifp);
}
static void
-start_message(struct network *net, int type, int len)
+start_message(struct interface *ifp, int type, int len)
{
- if(net->bufsize - net->buffered < len + 2)
- flushbuf(net);
- net->sendbuf[net->buffered++] = type;
- net->sendbuf[net->buffered++] = len;
+ if(ifp->bufsize - ifp->buffered < len + 2)
+ flushbuf(ifp);
+ ifp->sendbuf[ifp->buffered++] = type;
+ ifp->sendbuf[ifp->buffered++] = len;
}
static void
-end_message(struct network *net, int type, int bytes)
+end_message(struct interface *ifp, int type, int bytes)
{
- assert(net->buffered >= bytes + 2 &&
- net->sendbuf[net->buffered - bytes - 2] == type &&
- net->sendbuf[net->buffered - bytes - 1] == bytes);
- schedule_flush(net);
+ assert(ifp->buffered >= bytes + 2 &&
+ ifp->sendbuf[ifp->buffered - bytes - 2] == type &&
+ ifp->sendbuf[ifp->buffered - bytes - 1] == bytes);
+ schedule_flush(ifp);
}
static void
-accumulate_byte(struct network *net, unsigned char value)
+accumulate_byte(struct interface *ifp, unsigned char value)
{
- net->sendbuf[net->buffered++] = value;
+ ifp->sendbuf[ifp->buffered++] = value;
}
static void
-accumulate_short(struct network *net, unsigned short value)
+accumulate_short(struct interface *ifp, unsigned short value)
{
- DO_HTONS(net->sendbuf + net->buffered, value);
- net->buffered += 2;
+ DO_HTONS(ifp->sendbuf + ifp->buffered, value);
+ ifp->buffered += 2;
}
static void
-accumulate_bytes(struct network *net,
+accumulate_bytes(struct interface *ifp,
const unsigned char *value, unsigned len)
{
- memcpy(net->sendbuf + net->buffered, value, len);
- net->buffered += len;
+ memcpy(ifp->sendbuf + ifp->buffered, value, len);
+ ifp->buffered += len;
}
static int
@@ -641,7 +641,7 @@ start_unicast_message(struct neighbour *neigh, int type, int len)
if(unicast_neighbour) {
if(neigh != unicast_neighbour ||
unicast_buffered + len + 2 >=
- MIN(UNICAST_BUFSIZE, neigh->network->bufsize))
+ MIN(UNICAST_BUFSIZE, neigh->ifp->bufsize))
flush_unicast(0);
}
if(!unicast_buffer)
@@ -664,7 +664,7 @@ end_unicast_message(struct neighbour *neigh, int type, int bytes)
assert(unicast_neighbour == neigh && unicast_buffered >= bytes + 2 &&
unicast_buffer[unicast_buffered - bytes - 2] == type &&
unicast_buffer[unicast_buffered - bytes - 1] == bytes);
- schedule_unicast_flush(jitter(neigh->network, 0));
+ schedule_unicast_flush(jitter(neigh->ifp, 0));
}
static void
@@ -693,7 +693,7 @@ send_ack(struct neighbour *neigh, unsigned short nonce, unsigned short interval)
{
int rc;
debugf("Sending ack (%04x) to %s on %s.\n",
- nonce, format_address(neigh->address), neigh->network->ifname);
+ nonce, format_address(neigh->address), neigh->ifp->name);
rc = start_unicast_message(neigh, MESSAGE_ACK, 2); if(rc < 0) return;
accumulate_unicast_short(neigh, nonce);
end_unicast_message(neigh, MESSAGE_ACK, 2);
@@ -702,41 +702,41 @@ send_ack(struct neighbour *neigh, unsigned short nonce, unsigned short interval)
}
void
-send_hello_noupdate(struct network *net, unsigned interval)
+send_hello_noupdate(struct interface *ifp, unsigned interval)
{
/* This avoids sending multiple hellos in a single packet, which breaks
link quality estimation. */
- if(net->have_buffered_hello)
- flushbuf(net);
+ if(ifp->have_buffered_hello)
+ flushbuf(ifp);
- net->hello_seqno = seqno_plus(net->hello_seqno, 1);
- set_timeout(&net->hello_timeout, net->hello_interval);
+ ifp->hello_seqno = seqno_plus(ifp->hello_seqno, 1);
+ set_timeout(&ifp->hello_timeout, ifp->hello_interval);
- if(!net_up(net))
+ if(!if_up(ifp))
return;
debugf("Sending hello %d (%d) to %s.\n",
- net->hello_seqno, interval, net->ifname);
-
- start_message(net, MESSAGE_HELLO, 6);
- accumulate_short(net, 0);
- accumulate_short(net, net->hello_seqno);
- accumulate_short(net, interval > 0xFFFF ? 0xFFFF : interval);
- end_message(net, MESSAGE_HELLO, 6);
- net->have_buffered_hello = 1;
+ ifp->hello_seqno, interval, ifp->name);
+
+ start_message(ifp, MESSAGE_HELLO, 6);
+ accumulate_short(ifp, 0);
+ accumulate_short(ifp, ifp->hello_seqno);
+ accumulate_short(ifp, interval > 0xFFFF ? 0xFFFF : interval);
+ end_message(ifp, MESSAGE_HELLO, 6);
+ ifp->have_buffered_hello = 1;
}
void
-send_hello(struct network *net)
+send_hello(struct interface *ifp)
{
int changed;
- changed = update_hello_interval(net);
- send_hello_noupdate(net, (net->hello_interval + 9) / 10);
+ changed = update_hello_interval(ifp);
+ send_hello_noupdate(ifp, (ifp->hello_interval + 9) / 10);
/* Send full IHU every 3 hellos, and marginal IHU each time */
- if(changed || net->hello_seqno % 3 == 0)
- send_ihu(NULL, net);
+ if(changed || ifp->hello_seqno % 3 == 0)
+ send_ihu(NULL, ifp);
else
- send_marginal_ihu(net);
+ send_marginal_ihu(ifp);
}
void
@@ -748,18 +748,18 @@ flush_unicast(int dofree)
if(unicast_buffered == 0)
goto done;
- if(!net_up(unicast_neighbour->network))
+ if(!if_up(unicast_neighbour->ifp))
goto done;
/* Preserve ordering of messages */
- flushbuf(unicast_neighbour->network);
+ flushbuf(unicast_neighbour->ifp);
- if(check_bucket(unicast_neighbour->network)) {
+ if(check_bucket(unicast_neighbour->ifp)) {
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
memcpy(&sin6.sin6_addr, unicast_neighbour->address, 16);
sin6.sin6_port = htons(protocol_port);
- sin6.sin6_scope_id = unicast_neighbour->network->ifindex;
+ sin6.sin6_scope_id = unicast_neighbour->ifp->ifindex;
DO_HTONS(packet_header + 2, unicast_buffered);
rc = babel_send(protocol_socket,
packet_header, sizeof(packet_header),
@@ -772,7 +772,7 @@ flush_unicast(int dofree)
"Warning: bucket full, dropping unicast packet"
"to %s if %s.\n",
format_address(unicast_neighbour->address),
- unicast_neighbour->network->ifname);
+ unicast_neighbour->ifp->name);
}
done:
@@ -788,7 +788,7 @@ flush_unicast(int dofree)
}
static void
-really_send_update(struct network *net,
+really_send_update(struct interface *ifp,
const unsigned char *id,
const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short metric,
@@ -804,82 +804,82 @@ really_send_update(struct network *net,
channels_size = channels_len >= 0 ? channels_len + 2 : 0;
- if(!net_up(net))
+ if(!if_up(ifp))
return;
- add_metric = output_filter(id, prefix, plen, net->ifindex);
+ add_metric = output_filter(id, prefix, plen, ifp->ifindex);
if(add_metric >= INFINITY)
return;
metric = MIN(metric + add_metric, INFINITY);
/* Worst case */
- ensure_space(net, 20 + 12 + 28);
+ ensure_space(ifp, 20 + 12 + 28);
v4 = plen >= 96 && v4mapped(prefix);
if(v4) {
- if(!net->ipv4)
+ if(!ifp->ipv4)
return;
- if(!net->have_buffered_nh ||
- memcmp(net->buffered_nh, net->ipv4, 4) != 0) {
- start_message(net, MESSAGE_NH, 6);
- accumulate_byte(net, 1);
- accumulate_byte(net, 0);
- accumulate_bytes(net, net->ipv4, 4);
- end_message(net, MESSAGE_NH, 6);
- memcpy(net->buffered_nh, net->ipv4, 4);
- net->have_buffered_nh = 1;
+ if(!ifp->have_buffered_nh ||
+ memcmp(ifp->buffered_nh, ifp->ipv4, 4) != 0) {
+ start_message(ifp, MESSAGE_NH, 6);
+ accumulate_byte(ifp, 1);
+ accumulate_byte(ifp, 0);
+ accumulate_bytes(ifp, ifp->ipv4, 4);
+ end_message(ifp, MESSAGE_NH, 6);
+ memcpy(ifp->buffered_nh, ifp->ipv4, 4);
+ ifp->have_buffered_nh = 1;
}
real_prefix = prefix + 12;
real_plen = plen - 96;
} else {
- if(net->have_buffered_prefix) {
+ if(ifp->have_buffered_prefix) {
while(omit < plen / 8 &&
- net->buffered_prefix[omit] == prefix[omit])
+ ifp->buffered_prefix[omit] == prefix[omit])
omit++;
}
- if(!net->have_buffered_prefix || plen >= 48)
+ if(!ifp->have_buffered_prefix || plen >= 48)
flags |= 0x80;
real_prefix = prefix;
real_plen = plen;
}
- if(!net->have_buffered_id || memcmp(id, net->buffered_id, 8) != 0) {
+ if(!ifp->have_buffered_id || memcmp(id, ifp->buffered_id, 8) != 0) {
if(real_plen == 128 && memcmp(real_prefix + 8, id, 8) == 0) {
flags |= 0x40;
} else {
- start_message(net, MESSAGE_ROUTER_ID, 10);
- accumulate_short(net, 0);
- accumulate_bytes(net, id, 8);
- end_message(net, MESSAGE_ROUTER_ID, 10);
+ start_message(ifp, MESSAGE_ROUTER_ID, 10);
+ accumulate_short(ifp, 0);
+ accumulate_bytes(ifp, id, 8);
+ end_message(ifp, MESSAGE_ROUTER_ID, 10);
}
- memcpy(net->buffered_id, id, 16);
- net->have_buffered_id = 1;
+ memcpy(ifp->buffered_id, id, 16);
+ ifp->have_buffered_id = 1;
}
- start_message(net, MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit +
+ start_message(ifp, MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit +
channels_size);
- accumulate_byte(net, v4 ? 1 : 2);
- accumulate_byte(net, flags);
- accumulate_byte(net, real_plen);
- accumulate_byte(net, omit);
- accumulate_short(net, (net->update_interval + 5) / 10);
- accumulate_short(net, seqno);
- accumulate_short(net, metric);
- accumulate_bytes(net, real_prefix + omit, (real_plen + 7) / 8 - omit);
+ accumulate_byte(ifp, v4 ? 1 : 2);
+ accumulate_byte(ifp, flags);
+ accumulate_byte(ifp, real_plen);
+ accumulate_byte(ifp, omit);
+ accumulate_short(ifp, (ifp->update_interval + 5) / 10);
+ accumulate_short(ifp, seqno);
+ accumulate_short(ifp, metric);
+ accumulate_bytes(ifp, real_prefix + omit, (real_plen + 7) / 8 - omit);
/* Note that an empty channels TLV is different from no such TLV. */
if(channels_len >= 0) {
- accumulate_byte(net, 2);
- accumulate_byte(net, channels_len);
- accumulate_bytes(net, channels, channels_len);
+ accumulate_byte(ifp, 2);
+ accumulate_byte(ifp, channels_len);
+ accumulate_bytes(ifp, channels, channels_len);
}
- end_message(net, MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit +
+ end_message(ifp, MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit +
channels_size);
if(flags & 0x80) {
- memcpy(net->buffered_prefix, prefix, 16);
- net->have_buffered_prefix = 1;
+ memcpy(ifp->buffered_prefix, prefix, 16);
+ ifp->have_buffered_prefix = 1;
}
}
@@ -918,7 +918,7 @@ compare_buffered_updates(const void *av, const void *bv)
}
void
-flushupdates(struct network *net)
+flushupdates(struct interface *ifp)
{
struct xroute *xroute;
struct route *route;
@@ -926,26 +926,26 @@ flushupdates(struct network *net)
unsigned char last_plen = 0xFF;
int i;
- if(net == NULL) {
- struct network *n;
- FOR_ALL_NETS(n)
- flushupdates(n);
+ if(ifp == NULL) {
+ struct interface *ifp_aux;
+ FOR_ALL_INTERFACES(ifp_aux)
+ flushupdates(ifp_aux);
return;
}
- if(net->num_buffered_updates > 0) {
- struct buffered_update *b = net->buffered_updates;
- int n = net->num_buffered_updates;
+ if(ifp->num_buffered_updates > 0) {
+ struct buffered_update *b = ifp->buffered_updates;
+ int n = ifp->num_buffered_updates;
- net->buffered_updates = NULL;
- net->update_bufsize = 0;
- net->num_buffered_updates = 0;
+ ifp->buffered_updates = NULL;
+ ifp->update_bufsize = 0;
+ ifp->num_buffered_updates = 0;
- if(!net_up(net))
+ if(!if_up(ifp))
goto done;
debugf(" (flushing %d buffered updates on %s (%d))\n",
- n, net->ifname, net->ifindex);
+ n, ifp->name, ifp->ifindex);
/* In order to send fewer update messages, we want to send updates
with the same router-id together, with IPv6 going out before IPv4. */
@@ -975,7 +975,7 @@ flushupdates(struct network *net)
route = find_installed_route(b[i].prefix, b[i].plen);
if(xroute && (!route || xroute->metric <= kernel_metric)) {
- really_send_update(net, myid,
+ really_send_update(ifp, myid,
xroute->prefix, xroute->plen,
myseqno, xroute->metric,
NULL, 0);
@@ -984,39 +984,39 @@ flushupdates(struct network *net)
} else if(route) {
unsigned char channels[DIVERSITY_HOPS];
int chlen;
- struct network *route_net = route->neigh->network;
+ struct interface *route_ifp = route->neigh->ifp;
unsigned short metric;
unsigned short seqno;
seqno = route->seqno;
metric =
- route_interferes(route, net) ?
+ route_interferes(route, ifp) ?
route_metric(route) :
route_metric_noninterfering(route);
if(metric < INFINITY)
satisfy_request(route->src->prefix, route->src->plen,
- seqno, route->src->id, net);
+ seqno, route->src->id, ifp);
- if((net->flags & NET_SPLIT_HORIZON) &&
- route->neigh->network == net)
+ if((ifp->flags & IF_SPLIT_HORIZON) &&
+ route->neigh->ifp == ifp)
continue;
- if(route_net->channel == NET_CHANNEL_NONINTERFERING) {
+ if(route_ifp->channel == IF_CHANNEL_NONINTERFERING) {
memcpy(channels, route->channels, DIVERSITY_HOPS);
} else {
- if(route_net->channel == NET_CHANNEL_UNKNOWN)
- channels[0] = NET_CHANNEL_INTERFERING;
+ if(route_ifp->channel == IF_CHANNEL_UNKNOWN)
+ channels[0] = IF_CHANNEL_INTERFERING;
else {
- assert(route_net->channel > 0 &&
- route_net->channel <= 254);
- channels[0] = route_net->channel;
+ assert(route_ifp->channel > 0 &&
+ route_ifp->channel <= 254);
+ channels[0] = route_ifp->channel;
}
memcpy(channels + 1, route->channels, DIVERSITY_HOPS - 1);
}
chlen = channels_len(channels);
- really_send_update(net, route->src->id,
+ really_send_update(ifp, route->src->id,
route->src->prefix,
route->src->plen,
seqno, metric,
@@ -1027,44 +1027,44 @@ flushupdates(struct network *net)
} else {
/* There's no route for this prefix. This can happen shortly
after an xroute has been retracted, so send a retraction. */
- really_send_update(net, myid, b[i].prefix, b[i].plen,
+ really_send_update(ifp, myid, b[i].prefix, b[i].plen,
myseqno, INFINITY, NULL, -1);
}
}
- schedule_flush_now(net);
+ schedule_flush_now(ifp);
done:
free(b);
}
- net->update_flush_timeout.tv_sec = 0;
- net->update_flush_timeout.tv_usec = 0;
+ ifp->update_flush_timeout.tv_sec = 0;
+ ifp->update_flush_timeout.tv_usec = 0;
}
static void
-schedule_update_flush(struct network *net, int urgent)
+schedule_update_flush(struct interface *ifp, int urgent)
{
unsigned msecs;
- msecs = update_jitter(net, urgent);
- if(net->update_flush_timeout.tv_sec != 0 &&
- timeval_minus_msec(&net->update_flush_timeout, &now) < msecs)
+ msecs = update_jitter(ifp, urgent);
+ if(ifp->update_flush_timeout.tv_sec != 0 &&
+ timeval_minus_msec(&ifp->update_flush_timeout, &now) < msecs)
return;
- set_timeout(&net->update_flush_timeout, msecs);
+ set_timeout(&ifp->update_flush_timeout, msecs);
}
static void
-buffer_update(struct network *net,
+buffer_update(struct interface *ifp,
const unsigned char *prefix, unsigned char plen)
{
- if(net->num_buffered_updates > 0 &&
- net->num_buffered_updates >= net->update_bufsize)
- flushupdates(net);
+ if(ifp->num_buffered_updates > 0 &&
+ ifp->num_buffered_updates >= ifp->update_bufsize)
+ flushupdates(ifp);
- if(net->update_bufsize == 0) {
+ if(ifp->update_bufsize == 0) {
int n;
- assert(net->buffered_updates == NULL);
- n = MAX(net->bufsize / 16, 4);
+ assert(ifp->buffered_updates == NULL);
+ n = MAX(ifp->bufsize / 16, 4);
again:
- net->buffered_updates = malloc(n * sizeof(struct buffered_update));
- if(net->buffered_updates == NULL) {
+ ifp->buffered_updates = malloc(n * sizeof(struct buffered_update));
+ if(ifp->buffered_updates == NULL) {
perror("malloc(buffered_updates)");
if(n > 4) {
n = 4;
@@ -1072,27 +1072,27 @@ buffer_update(struct network *net,
}
return;
}
- net->update_bufsize = n;
- net->num_buffered_updates = 0;
+ ifp->update_bufsize = n;
+ ifp->num_buffered_updates = 0;
}
- memcpy(net->buffered_updates[net->num_buffered_updates].prefix,
+ memcpy(ifp->buffered_updates[ifp->num_buffered_updates].prefix,
prefix, 16);
- net->buffered_updates[net->num_buffered_updates].plen = plen;
- net->num_buffered_updates++;
+ ifp->buffered_updates[ifp->num_buffered_updates].plen = plen;
+ ifp->num_buffered_updates++;
}
void
-send_update(struct network *net, int urgent,
+send_update(struct interface *ifp, int urgent,
const unsigned char *prefix, unsigned char plen)
{
int i;
- if(net == NULL) {
- struct network *n;
+ if(ifp == NULL) {
+ struct interface *ifp_aux;
struct route *route;
- FOR_ALL_NETS(n)
- send_update(n, urgent, prefix, plen);
+ FOR_ALL_INTERFACES(ifp_aux)
+ send_update(ifp_aux, urgent, prefix, plen);
if(prefix) {
/* Since flushupdates only deals with non-wildcard interfaces, we
need to do this now. */
@@ -1104,41 +1104,41 @@ send_update(struct network *net, int urgent,
return;
}
- if(!net_up(net))
+ if(!if_up(ifp))
return;
if(prefix) {
if(!parasitic || find_xroute(prefix, plen)) {
debugf("Sending update to %s for %s.\n",
- net->ifname, format_prefix(prefix, plen));
- buffer_update(net, prefix, plen);
+ ifp->name, format_prefix(prefix, plen));
+ buffer_update(ifp, prefix, plen);
}
} else {
- if(!network_idle(net)) {
- send_self_update(net);
+ if(!interface_idle(ifp)) {
+ send_self_update(ifp);
if(!parasitic) {
- debugf("Sending update to %s for any.\n", net->ifname);
+ debugf("Sending update to %s for any.\n", ifp->name);
for(i = 0; i < numroutes; i++)
if(routes[i].installed)
- buffer_update(net,
+ buffer_update(ifp,
routes[i].src->prefix,
routes[i].src->plen);
}
}
- set_timeout(&net->update_timeout, net->update_interval);
+ set_timeout(&ifp->update_timeout, ifp->update_interval);
}
- schedule_update_flush(net, urgent);
+ schedule_update_flush(ifp, urgent);
}
void
-send_update_resend(struct network *net,
+send_update_resend(struct interface *ifp,
const unsigned char *prefix, unsigned char plen)
{
int delay;
assert(prefix != NULL);
- send_update(net, 1, prefix, plen);
+ send_update(ifp, 1, prefix, plen);
delay = 2000;
delay = MIN(delay, wireless_hello_interval / 2);
@@ -1148,29 +1148,29 @@ send_update_resend(struct network *net,
}
void
-send_wildcard_retraction(struct network *net)
+send_wildcard_retraction(struct interface *ifp)
{
- if(net == NULL) {
- struct network *n;
- FOR_ALL_NETS(n)
- send_wildcard_retraction(n);
+ if(ifp == NULL) {
+ struct interface *ifp_aux;
+ FOR_ALL_INTERFACES(ifp_aux)
+ send_wildcard_retraction(ifp_aux);
return;
}
- if(!net_up(net))
+ if(!if_up(ifp))
return;
- start_message(net, MESSAGE_UPDATE, 10);
- accumulate_byte(net, 0);
- accumulate_byte(net, 0x40);
- accumulate_byte(net, 0);
- accumulate_byte(net, 0);
- accumulate_short(net, 0xFFFF);
- accumulate_short(net, myseqno);
- accumulate_short(net, 0xFFFF);
- end_message(net, MESSAGE_UPDATE, 10);
-
- net->have_buffered_id = 0;
+ start_message(ifp, MESSAGE_UPDATE, 10);
+ accumulate_byte(ifp, 0);
+ accumulate_byte(ifp, 0x40);
+ accumulate_byte(ifp, 0);
+ accumulate_byte(ifp, 0);
+ accumulate_short(ifp, 0xFFFF);
+ accumulate_short(ifp, myseqno);
+ accumulate_short(ifp, 0xFFFF);
+ end_message(ifp, MESSAGE_UPDATE, 10);
+
+ ifp->have_buffered_id = 0;
}
void
@@ -1181,39 +1181,39 @@ update_myseqno()
}
void
-send_self_update(struct network *net)
+send_self_update(struct interface *ifp)
{
int i;
- if(net == NULL) {
- struct network *n;
- FOR_ALL_NETS(n) {
- if(!net_up(n))
+ if(ifp == NULL) {
+ struct interface *ifp_aux;
+ FOR_ALL_INTERFACES(ifp_aux) {
+ if(!if_up(ifp_aux))
continue;
- send_self_update(n);
+ send_self_update(ifp_aux);
}
return;
}
- if(!network_idle(net)) {
- debugf("Sending self update to %s.\n", net->ifname);
+ if(!interface_idle(ifp)) {
+ debugf("Sending self update to %s.\n", ifp->name);
for(i = 0; i < numxroutes; i++)
- send_update(net, 0, xroutes[i].prefix, xroutes[i].plen);
+ send_update(ifp, 0, xroutes[i].prefix, xroutes[i].plen);
}
}
void
-send_ihu(struct neighbour *neigh, struct network *net)
+send_ihu(struct neighbour *neigh, struct interface *ifp)
{
int rxcost, interval;
int ll;
- if(neigh == NULL && net == NULL) {
- struct network *n;
- FOR_ALL_NETS(n) {
- if(net_up(n))
+ if(neigh == NULL && ifp == NULL) {
+ struct interface *ifp_aux;
+ FOR_ALL_INTERFACES(ifp_aux) {
+ if(if_up(ifp_aux))
continue;
- send_ihu(NULL, n);
+ send_ihu(NULL, ifp_aux);
}
return;
}
@@ -1221,22 +1221,22 @@ send_ihu(struct neighbour *neigh, struct network *net)
if(neigh == NULL) {
struct neighbour *ngh;
FOR_ALL_NEIGHBOURS(ngh) {
- if(ngh->network == net)
- send_ihu(ngh, net);
+ if(ngh->ifp == ifp)
+ send_ihu(ngh, ifp);
}
return;
}
- if(net && neigh->network != net)
+ if(ifp && neigh->ifp != ifp)
return;
- net = neigh->network;
- if(!net_up(net))
+ ifp = neigh->ifp;
+ if(!if_up(ifp))
return;
rxcost = neighbour_rxcost(neigh);
- interval = (net->hello_interval * 3 + 9) / 10;
+ interval = (ifp->hello_interval * 3 + 9) / 10;
/* Conceptually, an IHU is a unicast message. We usually send them as
multicast, since this allows aggregation into a single packet and
@@ -1245,22 +1245,22 @@ send_ihu(struct neighbour *neigh, struct network *net)
debugf("Sending %sihu %d on %s to %s.\n",
unicast_neighbour == neigh ? "unicast " : "",
rxcost,
- neigh->network->ifname,
+ neigh->ifp->name,
format_address(neigh->address));
ll = linklocal(neigh->address);
if(unicast_neighbour != neigh) {
- start_message(net, MESSAGE_IHU, ll ? 14 : 22);
- accumulate_byte(net, ll ? 3 : 2);
- accumulate_byte(net, 0);
- accumulate_short(net, rxcost);
- accumulate_short(net, interval);
+ start_message(ifp, MESSAGE_IHU, ll ? 14 : 22);
+ accumulate_byte(ifp, ll ? 3 : 2);
+ accumulate_byte(ifp, 0);
+ accumulate_short(ifp, rxcost);
+ accumulate_short(ifp, interval);
if(ll)
- accumulate_bytes(net, neigh->address + 8, 8);
+ accumulate_bytes(ifp, neigh->address + 8, 8);
else
- accumulate_bytes(net, neigh->address, 16);
- end_message(net, MESSAGE_IHU, ll ? 14 : 22);
+ accumulate_bytes(ifp, neigh->address, 16);
+ end_message(ifp, MESSAGE_IHU, ll ? 14 : 22);
} else {
int rc;
rc = start_unicast_message(neigh, MESSAGE_IHU, ll ? 14 : 22);
@@ -1279,54 +1279,54 @@ send_ihu(struct neighbour *neigh, struct network *net)
/* Send IHUs to all marginal neighbours */
void
-send_marginal_ihu(struct network *net)
+send_marginal_ihu(struct interface *ifp)
{
struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) {
- if(net && neigh->network != net)
+ if(ifp && neigh->ifp != ifp)
continue;
if(neigh->txcost >= 384 || (neigh->reach & 0xF000) != 0xF000)
- send_ihu(neigh, net);
+ send_ihu(neigh, ifp);
}
}
void
-send_request(struct network *net,
+send_request(struct interface *ifp,
const unsigned char *prefix, unsigned char plen)
{
int v4, len;
- if(net == NULL) {
- struct network *n;
- FOR_ALL_NETS(n) {
- if(net_up(n))
+ if(ifp == NULL) {
+ struct interface *ifp_auxn;
+ FOR_ALL_INTERFACES(ifp_auxn) {
+ if(if_up(ifp_auxn))
continue;
- send_request(n, prefix, plen);
+ send_request(ifp_auxn, prefix, plen);
}
return;
}
/* make sure any buffered updates go out before this request. */
- flushupdates(net);
+ flushupdates(ifp);
- if(!net_up(net))
+ if(!if_up(ifp))
return;
debugf("sending request to %s for %s.\n",
- net->ifname, prefix ? format_prefix(prefix, plen) : "any");
+ ifp->name, prefix ? format_prefix(prefix, plen) : "any");
v4 = plen >= 96 && v4mapped(prefix);
len = !prefix ? 2 : v4 ? 6 : 18;
- start_message(net, MESSAGE_REQUEST, len);
- accumulate_byte(net, !prefix ? 0 : v4 ? 1 : 2);
- accumulate_byte(net, !prefix ? 0 : v4 ? plen - 96 : plen);
+ start_message(ifp, MESSAGE_REQUEST, len);
+ accumulate_byte(ifp, !prefix ? 0 : v4 ? 1 : 2);
+ accumulate_byte(ifp, !prefix ? 0 : v4 ? plen - 96 : plen);
if(prefix) {
if(v4)
- accumulate_bytes(net, prefix + 12, 4);
+ accumulate_bytes(ifp, prefix + 12, 4);
else
- accumulate_bytes(net, prefix, 16);
+ accumulate_bytes(ifp, prefix, 16);
}
- end_message(net, MESSAGE_REQUEST, len);
+ end_message(ifp, MESSAGE_REQUEST, len);
}
void
@@ -1336,7 +1336,7 @@ send_unicast_request(struct neighbour *neigh,
int rc, v4, len;
/* make sure any buffered updates go out before this request. */
- flushupdates(neigh->network);
+ flushupdates(neigh->ifp);
debugf("sending unicast request to %s for %s.\n",
format_address(neigh->address),
@@ -1358,7 +1358,7 @@ send_unicast_request(struct neighbour *neigh,
}
void
-send_multihop_request(struct network *net,
+send_multihop_request(struct interface *ifp,
const unsigned char *prefix, unsigned char plen,
unsigned short seqno, const unsigned char *id,
unsigned short hop_count)
@@ -1366,41 +1366,41 @@ send_multihop_request(struct network *net,
int v4, pb, len;
/* Make sure any buffered updates go out before this request. */
- flushupdates(net);
+ flushupdates(ifp);
- if(net == NULL) {
- struct network *n;
- FOR_ALL_NETS(n) {
- if(!net_up(n))
+ if(ifp == NULL) {
+ struct interface *ifp_aux;
+ FOR_ALL_INTERFACES(ifp_aux) {
+ if(!if_up(ifp_aux))
continue;
- send_multihop_request(n, prefix, plen, seqno, id, hop_count);
+ send_multihop_request(ifp_aux, prefix, plen, seqno, id, hop_count);
}
return;
}
- if(!net_up(net))
+ if(!if_up(ifp))
return;
debugf("Sending request (%d) on %s for %s.\n",
- hop_count, net->ifname, format_prefix(prefix, plen));
+ hop_count, ifp->name, format_prefix(prefix, plen));
v4 = plen >= 96 && v4mapped(prefix);
pb = v4 ? ((plen - 96) + 7) / 8 : (plen + 7) / 8;
len = 6 + 8 + pb;
- start_message(net, MESSAGE_MH_REQUEST, len);
- accumulate_byte(net, v4 ? 1 : 2);
- accumulate_byte(net, v4 ? plen - 96 : plen);
- accumulate_short(net, seqno);
- accumulate_byte(net, hop_count);
- accumulate_byte(net, 0);
- accumulate_bytes(net, id, 8);
+ start_message(ifp, MESSAGE_MH_REQUEST, len);
+ accumulate_byte(ifp, v4 ? 1 : 2);
+ accumulate_byte(ifp, v4 ? plen - 96 : plen);
+ accumulate_short(ifp, seqno);
+ accumulate_byte(ifp, hop_count);
+ accumulate_byte(ifp, 0);
+ accumulate_bytes(ifp, id, 8);
if(prefix) {
if(v4)
- accumulate_bytes(net, prefix + 12, pb);
+ accumulate_bytes(ifp, prefix + 12, pb);
else
- accumulate_bytes(net, prefix, pb);
+ accumulate_bytes(ifp, prefix, pb);
}
- end_message(net, MESSAGE_MH_REQUEST, len);
+ end_message(ifp, MESSAGE_MH_REQUEST, len);
}
void
@@ -1412,7 +1412,7 @@ send_unicast_multihop_request(struct neighbour *neigh,
int rc, v4, pb, len;
/* Make sure any buffered updates go out before this request. */
- flushupdates(neigh->network);
+ flushupdates(neigh->ifp);
debugf("Sending multi-hop request to %s for %s (%d hops).\n",
format_address(neigh->address),
@@ -1455,7 +1455,7 @@ send_request_resend(struct neighbour *neigh,
delay = MIN(delay, wired_hello_interval / 2);
delay = MAX(delay, 10);
record_resend(RESEND_REQUEST, prefix, plen, seqno, id,
- neigh ? neigh->network : NULL, delay);
+ neigh ? neigh->ifp : NULL, delay);
}
void
@@ -1480,14 +1480,14 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
update_myseqno();
}
}
- send_update(neigh->network, 1, prefix, plen);
+ send_update(neigh->ifp, 1, prefix, plen);
return;
}
if(route &&
(memcmp(id, route->src->id, 8) != 0 ||
seqno_compare(seqno, route->seqno) <= 0)) {
- send_update(neigh->network, 1, prefix, plen);
+ send_update(neigh->ifp, 1, prefix, plen);
return;
}
@@ -1500,7 +1500,7 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
return;
}
- if(request_redundant(neigh->network, prefix, plen, seqno, id))
+ if(request_redundant(neigh->ifp, prefix, plen, seqno, id))
return;
/* Let's try to forward this request. */
@@ -1524,5 +1524,5 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
send_unicast_multihop_request(successor, prefix, plen, seqno, id,
hop_count - 1);
record_resend(RESEND_REQUEST, prefix, plen, seqno, id,
- neigh->network, 0);
+ neigh->ifp, 0);
}
View
26 message.h
@@ -50,29 +50,29 @@ extern unsigned char packet_header[4];
extern struct neighbour *unicast_neighbour;
extern struct timeval unicast_flush_timeout;
-void parse_packet(const unsigned char *from, struct network *net,
+void parse_packet(const unsigned char *from, struct interface *ifp,
const unsigned char *packet, int packetlen);
-void flushbuf(struct network *net);
-void flushupdates(struct network *net);
+void flushbuf(struct interface *ifp);
+void flushupdates(struct interface *ifp);
void send_ack(struct neighbour *neigh, unsigned short nonce,
unsigned short interval);
-void send_hello_noupdate(struct network *net, unsigned interval);
-void send_hello(struct network *net);
+void send_hello_noupdate(struct interface *ifp, unsigned interval);
+void send_hello(struct interface *ifp);
void flush_unicast(int dofree);
-void send_update(struct network *net, int urgent,
+void send_update(struct interface *ifp, int urgent,
const unsigned char *prefix, unsigned char plen);
-void send_update_resend(struct network *net,
+void send_update_resend(struct interface *ifp,
const unsigned char *prefix, unsigned char plen);
-void send_wildcard_retraction(struct network *net);
+void send_wildcard_retraction(struct interface *ifp);
void update_myseqno(void);
-void send_self_update(struct network *net);
-void send_ihu(struct neighbour *neigh, struct network *net);
-void send_marginal_ihu(struct network *net);
-void send_request(struct network *net,
+void send_self_update(struct interface *ifp);
+void send_ihu(struct neighbour *neigh, struct interface *ifp);
+void send_marginal_ihu(struct interface *ifp);
+void send_request(struct interface *ifp,
const unsigned char *prefix, unsigned char plen);
void send_unicast_request(struct neighbour *neigh,
const unsigned char *prefix, unsigned char plen);
-void send_multihop_request(struct network *net,
+void send_multihop_request(struct interface *ifp,
const unsigned char *prefix, unsigned char plen,
unsigned short seqno, const unsigned char *id,
unsigned short hop_count);
View
32 neighbour.c
@@ -39,12 +39,12 @@ THE SOFTWARE.
struct neighbour *neighs = NULL;
static struct neighbour *
-find_neighbour_nocreate(const unsigned char *address, struct network *net)
+find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
{
struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) {
if(memcmp(address, neigh->address, 16) == 0 &&
- neigh->network == net)
+ neigh->ifp == ifp)
return neigh;
}
return NULL;
@@ -71,17 +71,17 @@ flush_neighbour(struct neighbour *neigh)
}
struct neighbour *
-find_neighbour(const unsigned char *address, struct network *net)
+find_neighbour(const unsigned char *address, struct interface *ifp)
{
struct neighbour *neigh;
const struct timeval zero = {0, 0};
- neigh = find_neighbour_nocreate(address, net);
+ neigh = find_neighbour_nocreate(address, ifp);
if(neigh)
return neigh;
debugf("Creating neighbour %s on %s.\n",
- format_address(address), net->ifname);
+ format_address(address), ifp->name);
neigh = malloc(sizeof(struct neighbour));
if(neigh == NULL) {
@@ -97,11 +97,11 @@ find_neighbour(const unsigned char *address, struct network *net)
neigh->hello_time = zero;
neigh->hello_interval = 0;
neigh->ihu_interval = 0;
- neigh->network = net;
+ neigh->ifp = ifp;
neigh->next = neighs;
neighs = neigh;
local_notify_neighbour(neigh, LOCAL_ADD);
- send_hello(net);
+ send_hello(ifp);
return neigh;
}
@@ -174,14 +174,14 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
/* Make sure to give neighbours some feedback early after association */
if((neigh->reach & 0xBF00) == 0x8000) {
/* A new neighbour */
- send_hello(neigh->network);
+ send_hello(neigh->ifp);
} else {
/* Don't send hellos, in order to avoid a positive feedback loop. */
int a = (neigh->reach & 0xC000);
int b = (neigh->reach & 0x3000);
if((a == 0xC000 && b == 0) || (a == 0 && b == 0x3000)) {
/* Reachability is either 1100 or 0011 */
- send_self_update(neigh->network);
+ send_self_update(neigh->ifp);
}
}
@@ -269,25 +269,25 @@ neighbour_rxcost(struct neighbour *neigh)
if((reach & 0xFFF0) == 0 || delay >= 180000) {
return INFINITY;
- } else if((neigh->network->flags & NET_LQ)) {
+ } else if((neigh->ifp->flags & IF_LQ)) {
int sreach =
((reach & 0x8000) >> 2) +
((reach & 0x4000) >> 1) +
(reach & 0x3FFF);
/* 0 <= sreach <= 0x7FFF */
- int cost = (0x8000 * neigh->network->cost) / (sreach + 1);
- /* cost >= network->cost */
+ int cost = (0x8000 * neigh->ifp->cost) / (sreach + 1);
+ /* cost >= interface->cost */
if(delay >= 40000)
cost = (cost * (delay - 20000) + 10000) / 20000;
return MIN(cost, INFINITY);
} else {
/* To lose one hello is a misfortune, to lose two is carelessness. */
if((reach & 0xC000) == 0xC000)
- return neigh->network->cost;
+ return neigh->ifp->cost;
else if((reach & 0xC000) == 0)
return INFINITY;
else if((reach & 0x2000))
- return neigh->network->cost;
+ return neigh->ifp->cost;
else
return INFINITY;
}
@@ -298,7 +298,7 @@ neighbour_cost(struct neighbour *neigh)
{
unsigned a, b;
- if(!net_up(neigh->network))
+ if(!if_up(neigh->ifp))
return INFINITY;
a = neighbour_txcost(neigh);
@@ -310,7 +310,7 @@ neighbour_cost(struct neighbour *neigh)
if(b >= INFINITY)
return INFINITY;
- if(!(neigh->network->flags & NET_LQ) || (a <= 256 && b <= 256)) {
+ if(!(neigh->ifp->flags & IF_LQ) || (a <= 256 && b <= 256)) {
return a;
} else {
/* a = 256/alpha, b = 256/beta, where alpha and beta are the expected
View
4 neighbour.h
@@ -31,7 +31,7 @@ struct neighbour {
struct timeval ihu_time;
unsigned short hello_interval; /* in centiseconds */
unsigned short ihu_interval; /* in centiseconds */
- struct network *network;
+ struct interface *ifp;
};
extern struct neighbour *neighs;
@@ -42,7 +42,7 @@ extern struct neighbour *neighs;
int neighbour_valid(struct neighbour *neigh);
void flush_neighbour(struct neighbour *neigh);
struct neighbour *find_neighbour(const unsigned char *address,
- struct network *net);
+ struct interface *ifp);
int update_neighbour(struct neighbour *neigh, int hello, int hello_interval);
unsigned check_neighbours(void);
unsigned neighbour_txcost(struct neighbour *neigh);
View
370 network.c
@@ -41,80 +41,80 @@ THE SOFTWARE.
#include "route.h"
#include "configuration.h"
-struct network *networks = NULL;
+struct interface *interfaces = NULL;
-static struct network *
-last_network(void)
+static struct interface *
+last_interface(void)
{
- struct network *net = networks;
+ struct interface *ifp = interfaces;
- if(!net)
+ if(!ifp)
return NULL;
- while(net->next)
- net = net->next;
+ while(ifp->next)
+ ifp = ifp->next;
- return net;
+ return ifp;
}
-struct network *
-add_network(char *ifname, struct network_conf *conf)
+struct interface *
+add_interface(char *ifname, struct interface_conf *if_conf)
{
- struct network *net;
+ struct interface *ifp;
- assert(!conf || strcmp(ifname, conf->ifname) == 0);
+ assert(!if_conf || strcmp(ifname, if_conf->ifname) == 0);
- FOR_ALL_NETS(net) {
- if(strcmp(net->ifname, ifname) == 0) {
- assert(conf == NULL);
- return net;
+ FOR_ALL_INTERFACES(ifp) {
+ if(strcmp(ifp->name, ifname) == 0) {
+ assert(if_conf == NULL);
+ return ifp;
}
}
- net = malloc(sizeof(struct network));
- if(net == NULL)
+ ifp = malloc(sizeof(struct interface));
+ if(ifp == NULL)
return NULL;
- memset(net, 0, sizeof(struct network));
- strncpy(net->ifname, ifname, IF_NAMESIZE);
- net->conf = conf;
-