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