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