Commit 7f82d0e1 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add support for local xroutes.

parent 17fae294
......@@ -154,7 +154,7 @@ main(int argc, char **argv)
goto syntax;
xroutes[numxroutes].metric = metric;
}
xroutes[numxroutes].forced = 1;
xroutes[numxroutes].kind = XROUTE_FORCED;
xroutes[numxroutes].ifindex = 0;
numxroutes++;
} else if(strcmp(*arg, "-h") == 0) {
......@@ -731,7 +731,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].forced ? "forced" : "exported");
xroutes[i].kind == XROUTE_FORCED ? "forced" : "exported");
}
for(i = 0; i < numroutes; i++) {
int id =
......
......@@ -67,14 +67,20 @@ flush_xroute(struct xroute *xroute)
}
int
add_xroute(unsigned char prefix[16], unsigned char plen,
add_xroute(int kind, unsigned char prefix[16], unsigned char plen,
unsigned short metric, unsigned int ifindex, int proto)
{
struct xroute *xroute = find_xroute(prefix, plen);
if(xroute) {
if(xroute->metric <= metric)
if(xroute->kind < kind)
return 0;
if(xroute->forced)
else if(xroute->kind > kind) {
flush_xroute(xroute);
return add_xroute(kind, prefix, plen, metric, ifindex, proto);
}
if(xroute->metric <= metric)
return 0;
xroute->metric = metric;
return 1;
......@@ -83,9 +89,9 @@ add_xroute(unsigned char prefix[16], unsigned char plen,
if(numxroutes >= MAXXROUTES)
return -1;
xroutes[numxroutes].kind = kind;
memcpy(xroutes[numxroutes].prefix, prefix, 16);
xroutes[numxroutes].plen = plen;
xroutes[numxroutes].forced = 0;
xroutes[numxroutes].metric = metric;
xroutes[numxroutes].ifindex = ifindex;
xroutes[numxroutes].proto = proto;
......@@ -107,7 +113,7 @@ check_xroutes()
i = 0;
while(i < numxroutes) {
if(xroutes[i].forced) {
if(xroutes[i].kind != XROUTE_REDISTRIBUTED) {
i++;
continue;
}
......@@ -146,7 +152,8 @@ check_xroutes()
if(metric == METRIC_INHERIT)
metric = routes[i].metric;
if(metric < INFINITY) {
rc = add_xroute(routes[i].prefix, routes[i].plen,
rc = add_xroute(XROUTE_REDISTRIBUTED,
routes[i].prefix, routes[i].plen,
metric, routes[i].ifindex, routes[i].proto);
if(rc)
change = 1;
......@@ -169,7 +176,8 @@ check_addresses()
if (rc < 0)
break;
for (i = 0; i < rc && numxroutes < MAXXROUTES; i++) {
rc = add_xroute(addresses[i].s6_addr, 128, 0, nets[i].ifindex,
rc = add_xroute(XROUTE_LOCAL,
addresses[i].s6_addr, 128, 0, nets[i].ifindex,
RTPROTO_BABEL_LOCAL);
if (rc < 0)
break;
......
......@@ -23,10 +23,16 @@ THE SOFTWARE.
int check_xroutes(void);
int check_addresses(void);
/* These should come in decreasing order of priority. */
#define XROUTE_FORCED 1
#define XROUTE_LOCAL 2
#define XROUTE_REDISTRIBUTED 3
struct xroute {
unsigned char prefix[16];
unsigned char plen;
char forced;
char kind;
unsigned short metric;
unsigned int ifindex;
int proto;
......@@ -36,4 +42,6 @@ extern struct xroute xroutes[MAXXROUTES];
extern int numxroutes;
struct xroute *find_xroute(const unsigned char *prefix, unsigned char plen);
int add_xroute(int kind, unsigned char prefix[16], unsigned char plen,
unsigned short metric, unsigned int ifindex, int proto);
int check_xroutes(void);
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