Commit 10d8b2fb authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Adapt rest of babel to new filtering, xroute and kernel interfaces.

parent e9e2537c
......@@ -49,11 +49,11 @@ THE SOFTWARE.
#include "xroute.h"
#include "message.h"
#include "request.h"
#include "filter.h"
struct timeval now;
unsigned char myid[16];
int do_ipv4 = 0;
int debug = 0;
static int maxmtu;
......@@ -96,11 +96,12 @@ main(int argc, char **argv)
static unsigned char *buf;
struct timeval check_neighbours_time;
int expiry_time, kernel_dump_time;
char *config_file = NULL;
void *vrc;
unsigned int seed;
char **arg;
parse_address("ff02::cca6:c0f9:e182:5373", protocol_group);
parse_address("ff02::cca6:c0f9:e182:5373", protocol_group, NULL);
protocol_port = 8475;
#define SHIFT() do { arg++; } while(0)
......@@ -116,7 +117,7 @@ main(int argc, char **argv)
break;
} else if(strcmp(*arg, "-m") == 0) {
SHIFTE();
rc = parse_address(*arg, protocol_group);
rc = parse_address(*arg, protocol_group, NULL);
if(rc < 0)
goto syntax;
if(protocol_group[0] != 0xff) {
......@@ -132,8 +133,7 @@ main(int argc, char **argv)
} else if(strcmp(*arg, "-p") == 0) {
SHIFTE();
protocol_port = atoi(*arg);
} else if(strcmp(*arg, "-x") == 0 || strcmp(*arg, "-X") == 0) {
int force = (strcmp(*arg, "-X") == 0);
} else if(strcmp(*arg, "-X") == 0) {
if(numxroutes >= MAXXROUTES) {
fprintf(stderr, "Too many exported routes.\n");
exit(1);
......@@ -141,7 +141,7 @@ main(int argc, char **argv)
SHIFTE();
rc = parse_net(*arg,
xroutes[numxroutes].prefix,
&xroutes[numxroutes].plen);
&xroutes[numxroutes].plen, NULL);
if(rc < 0)
goto syntax;
SHIFTE();
......@@ -153,7 +153,8 @@ main(int argc, char **argv)
goto syntax;
xroutes[numxroutes].metric = metric;
}
xroutes[numxroutes].exported = force ? 2 : 0;
xroutes[numxroutes].forced = 1;
xroutes[numxroutes].ifindex = 0;
numxroutes++;
} else if(strcmp(*arg, "-h") == 0) {
SHIFTE();
......@@ -174,11 +175,6 @@ main(int argc, char **argv)
goto syntax;
} else if(strcmp(*arg, "-P") == 0) {
parasitic = 1;
} else if(strcmp(*arg, "-c") == 0) {
SHIFTE();
add_cost = atoi(*arg);
if(add_cost < 0 || add_cost > INFINITY)
goto syntax;
} else if(strcmp(*arg, "-s") == 0) {
split_horizon = 0;
} else if(strcmp(*arg, "-S") == 0) {
......@@ -187,8 +183,6 @@ main(int argc, char **argv)
} else if(strcmp(*arg, "-d") == 0) {
SHIFTE();
debug = atoi(*arg);
} else if(strcmp(*arg, "-4") == 0) {
do_ipv4 = 1;
} else if(strcmp(*arg, "-l") == 0) {
link_detect = 1;
} else if(strcmp(*arg, "-w") == 0) {
......@@ -203,12 +197,38 @@ main(int argc, char **argv)
import_table = atoi(*arg);
if(import_table < 0 || import_table > 0xFFFF)
goto syntax;
} else if(strcmp(*arg, "-c") == 0) {
SHIFTE();
config_file = *arg;
} else if(strcmp(*arg, "-C") == 0) {
int rc;
SHIFTE();
rc = parse_config_from_string(*arg);
if(rc < 0) {
fprintf(stderr,
"Couldn't parse configuration from command line.\n");
exit(1);
}
} else {
goto syntax;
}
SHIFTE();
}
if(!config_file) {
if(access("/etc/babel.conf", R_OK) >= 0)
config_file = "/etc/babel.conf";
}
if(config_file) {
rc = parse_config_from_file(config_file);
if(rc < 0) {
fprintf(stderr,
"Couldn't parse configuration from file %s.\n", *arg);
exit(1);
}
}
if(wireless_hello_interval <= 0)
wireless_hello_interval = 6;
......@@ -223,7 +243,7 @@ main(int argc, char **argv)
if(seqno_interval <= 0)
seqno_interval = MAX(wireless_hello_interval - 1, 2);
rc = parse_address(*arg, myid);
rc = parse_address(*arg, myid, NULL);
if(rc < 0)
goto syntax;
SHIFTE();
......@@ -271,7 +291,7 @@ main(int argc, char **argv)
rc = sscanf(buf, "%99s %d %ld\n", buf2, &s, &t);
if(rc == 3 && s >= 0 && s <= 0xFFFF) {
unsigned char sid[16];
rc = parse_address(buf2, sid);
rc = parse_address(buf2, sid, NULL);
if(rc < 0) {
fprintf(stderr, "Couldn't parse babel-state.\n");
} else {
......@@ -295,7 +315,7 @@ main(int argc, char **argv)
fprintf(stderr, "Respecting %ld second silent time.\n",
(long int)(reboot_time + silent_time - now.tv_sec));
rc = kernel_setup(1, do_ipv4);
rc = kernel_setup(1);
if(rc < 0) {
fprintf(stderr, "kernel_setup failed.\n");
exit(1);
......@@ -601,7 +621,7 @@ main(int argc, char **argv)
kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex);
}
kernel_setup_socket(0);
kernel_setup(0, do_ipv4);
kernel_setup(0);
fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if(fd < 0) {
......@@ -632,11 +652,11 @@ main(int argc, char **argv)
"Syntax: %s "
"[-m multicast_address] [-p port] [-S state-file]\n"
" "
"[-h hello] [-H wired_hello] [-i idle_hello]\n"
"[-h hello] [-H wired_hello] [-i idle_hello] [-u update]\n"
" "
"[-u update] [-k metric] [-4] [-s] [-P] [-c cost] [-l] [-w]\n"
"[-k metric] [-s] [-P] [-l] [-w] [-d level]\n"
" "
"[-d level] [-t table] [-T table] [-x net cost] [-X net cost]\n"
"[-t table] [-T table] [-X net cost] [-c file] [-C statement]\n"
" "
"id interface...\n",
argv[0]);
......@@ -649,7 +669,7 @@ main(int argc, char **argv)
kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex);
}
kernel_setup_socket(0);
kernel_setup(0, do_ipv4);
kernel_setup(0);
exit(1);
}
......@@ -728,9 +748,7 @@ dump_tables(FILE *out)
fprintf(out, "%s metric %d (%s)\n",
format_prefix(xroutes[i].prefix, xroutes[i].plen),
xroutes[i].metric,
xroutes[i].exported ?
xroutes[i].exported > 1 ? "forced" : "exported" :
"not exported");
xroutes[i].forced ? "forced" : "exported");
}
for(i = 0; i < numroutes; i++) {
int id =
......
......@@ -63,7 +63,6 @@ THE SOFTWARE.
extern struct timeval now;
extern int debug;
extern int reboot_time;
extern int do_ipv4;
extern int wireless_hello_interval, wired_hello_interval, idle_hello_interval;
extern int idle_time;
extern int link_detect;
......
......@@ -43,7 +43,6 @@ struct timeval update_flush_time = {0, 0};
const unsigned char packet_header[8] = {42, 1};
int add_cost = 0;
int parasitic = 0;
int silent_time = 30;
int split_horizon = 1;
......@@ -259,7 +258,7 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
return;
}
xroute = find_exported_xroute(prefix, plen);
xroute = find_xroute(prefix, plen);
if(xroute) {
if(router_hash == hash_id(myid) && seqno_compare(seqno, myseqno) > 0)
update_myseqno(1);
......@@ -550,7 +549,11 @@ really_send_update(struct network *net,
const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short metric)
{
if(!export_filter(address, prefix, plen)) {
int add_metric;
add_metric = output_filter(address, prefix, plen, net->ifindex);
if(add_metric < INFINITY) {
if(plen >= 96 && v4mapped(prefix)) {
const unsigned char *sid;
unsigned char v4route[16];
......@@ -563,7 +566,8 @@ really_send_update(struct network *net,
sid = message_source_id(net);
if(sid == NULL || memcmp(address, sid, 16) != 0)
send_message(net, 3, 0xFF, 0, 0, 0xFFFF, address);
send_message(net, 5, plen - 96, 0, seqno, metric, v4route);
send_message(net, 5, plen - 96, 0, seqno, metric + add_metric,
v4route);
} else {
if(in_prefix(address, prefix, plen)) {
send_message(net, 3, plen, 0, seqno, metric, address);
......@@ -573,7 +577,8 @@ really_send_update(struct network *net,
sid = message_source_id(net);
if(sid == NULL || memcmp(address, sid, 16) != 0)
send_message(net, 3, 0xFF, 0, 0, 0xFFFF, address);
send_message(net, 4, plen, 0, seqno, metric, prefix);
send_message(net, 4, plen, 0, seqno, metric + add_metric,
prefix);
}
}
}
......@@ -600,7 +605,7 @@ flushupdates(void)
struct source *src;
unsigned short seqno;
unsigned short metric;
xroute = find_exported_xroute(buffered_updates[i].prefix,
xroute = find_xroute(buffered_updates[i].prefix,
buffered_updates[i].plen);
if(xroute) {
really_send_update(net, myid,
......@@ -615,7 +620,7 @@ flushupdates(void)
net->wired && route->neigh->network == net)
continue;
seqno = route->seqno;
metric = MIN((int)route->metric + add_cost, INFINITY);
metric = route->metric;
really_send_update(net, route->src->address,
route->src->prefix,
route->src->plen,
......@@ -712,7 +717,7 @@ send_update(struct network *net, int urgent,
if(prefix == NULL) {
send_self_update(net, 0);
net->update_time = now.tv_sec;
} else if(find_exported_xroute(prefix, plen)) {
} else if(find_xroute(prefix, plen)) {
buffer_update(net, prefix, plen);
}
return;
......@@ -772,7 +777,6 @@ send_self_update(struct network *net, int force_seqno)
net->self_update_time = now.tv_sec;
for(i = 0; i < numxroutes; i++) {
if(xroutes[i].exported)
send_update(net, 0, xroutes[i].prefix, xroutes[i].plen);
}
}
......@@ -799,7 +803,6 @@ send_self_retract(struct network *net)
seqno_time = now.tv_sec;
net->self_update_time = now.tv_sec;
for(i = 0; i < numxroutes; i++) {
if(xroutes[i].exported)
really_send_update(net, myid, xroutes[i].prefix, xroutes[i].plen,
myseqno, 0xFFFF);
}
......
......@@ -26,7 +26,6 @@ extern unsigned short myseqno;
extern int seqno_time;
extern int seqno_interval;
extern int add_cost;
extern int parasitic;
extern int silent_time;
extern int broadcast_ihu;
......
......@@ -51,14 +51,12 @@ add_network(char *ifname, int ifindex, int mtu, int wired, unsigned int cost)
nets[numnets].up = (kernel_interface_operational(ifname, ifindex) > 0);
nets[numnets].ifindex = ifindex;
nets[numnets].ipv4 = NULL;
if(do_ipv4) {
rc = kernel_interface_ipv4(ifname, ifindex, ipv4);
if(rc >= 0) {
nets[numnets].ipv4 = malloc(4);
if(nets[numnets].ipv4)
memcpy(nets[numnets].ipv4, ipv4, 4);
}
}
nets[numnets].wired = wired;
nets[numnets].cost = cost;
......@@ -148,9 +146,7 @@ check_networks(void)
unsigned char ipv4[4];
for(i = 0; i < numnets; i++) {
rc = do_ipv4 ?
kernel_interface_ipv4(nets[i].ifname, nets[i].ifindex, ipv4) :
0;
rc = kernel_interface_ipv4(nets[i].ifname, nets[i].ifindex, ipv4);
if(rc > 0) {
if(!nets[i].ipv4 || memcmp(ipv4, nets[i].ipv4, 4) != 0) {
if(!nets[i].ipv4)
......
......@@ -30,6 +30,7 @@ THE SOFTWARE.
#include "neighbour.h"
#include "request.h"
#include "message.h"
#include "network.h"
#include "filter.h"
int request_resend_time = 0;
......@@ -70,8 +71,8 @@ record_request(const unsigned char *prefix, unsigned char plen,
{
struct request *request;
if(import_filter(NULL, prefix, plen, NULL) ||
export_filter(NULL, prefix, plen))
if(input_filter(NULL, prefix, plen, NULL, network->ifindex) >= INFINITY ||
output_filter(NULL, prefix, plen, network->ifindex) >= INFINITY)
return 0;
request = find_request(prefix, plen, NULL);
......
......@@ -329,6 +329,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
struct route *route;
struct source *src;
int metric, feasible;
int add_metric;
if(martian_prefix(p, plen)) {
fprintf(stderr, "Rejecting martian route to %s through %s.\n",
......@@ -336,7 +337,8 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
return NULL;
}
if(import_filter(a, p, plen, neigh->id))
add_metric = input_filter(a, p, plen, neigh->id, neigh->network->ifindex);
if(add_metric >= INFINITY)
return NULL;
src = find_source(a, p, plen, 1, seqno);
......@@ -345,7 +347,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
feasible = update_feasible(a, p, plen, seqno, refmetric);
route = find_route(p, plen, neigh, nexthop);
metric = MIN((int)refmetric + neighbour_cost(neigh), INFINITY);
metric = MIN((int)refmetric + neighbour_cost(neigh) + add_metric, INFINITY);
if(route) {
struct source *oldsrc;
......@@ -426,7 +428,7 @@ consider_route(struct route *route)
if(!route_feasible(route))
return;
if(find_exported_xroute(route->src->prefix, route->src->plen))
if(find_xroute(route->src->prefix, route->src->plen))
return;
installed = find_installed_route(route->src->prefix, route->src->plen);
......
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