Commit 1d8a3cce authored by Toke Høiland-Jørgensen's avatar Toke Høiland-Jørgensen Committed by Juliusz Chroboczek

Add ability to get routes from multiple kernel tables.

parent 1fbd6fe7
......@@ -226,8 +226,7 @@ main(int argc, char **argv)
goto usage;
break;
case 'T':
import_table = parse_nat(optarg);
if(import_table < 0 || import_table > 0xFFFF)
if(add_import_table(parse_nat(optarg)))
goto usage;
break;
case 'c':
......
......@@ -115,7 +115,9 @@ Use the given kernel routing table for routes inserted by
.BR babeld .
.TP
.BI \-T " table"
Export routes from the given kernel routing table.
Export routes from the given kernel routing table. This can be
specified multiple times in order to export routes from more than one
table.
.TP
.BI \-c " filename"
Specify the name of the configuration file. The default is
......
......@@ -98,3 +98,11 @@ read_random_bytes(void *buf, size_t len)
return rc;
}
int
add_import_table(int table)
{
if(table < 0 || table > 0xFFFF) return -1;
if(import_table_count > MAX_IMPORT_TABLES - 1) return -2;
import_tables[import_table_count++] = table;
return 0;
}
......@@ -42,7 +42,13 @@ struct kernel_route {
#define CHANGE_ROUTE (1 << 1)
#define CHANGE_ADDR (1 << 2)
extern int export_table, import_table;
#ifndef MAX_IMPORT_TABLES
#define MAX_IMPORT_TABLES 10
#endif
extern int export_table, import_tables[MAX_IMPORT_TABLES], import_table_count;
int add_import_table(int table);
int kernel_setup(int setup);
int kernel_setup_socket(int setup);
......
......@@ -51,7 +51,7 @@ THE SOFTWARE.
#include "util.h"
#include "interface.h"
int export_table = -1, import_table = -1;
int export_table = -1, import_tables[MAX_IMPORT_TABLES], import_table_count = 0;
static int old_forwarding = -1;
static int old_ipv4_forwarding = -1;
......@@ -468,8 +468,8 @@ kernel_setup(int setup)
if(export_table < 0)
export_table = RT_TABLE_MAIN;
if(import_table < 0)
import_table = RT_TABLE_MAIN;
if(import_table_count < 1)
import_tables[import_table_count++] = RT_TABLE_MAIN;
dgram_socket = socket(PF_INET, SOCK_DGRAM, 0);
if(dgram_socket < 0)
......@@ -1037,10 +1037,11 @@ parse_kernel_route_rta(struct rtmsg *rtm, int len, struct kernel_route *route)
}
#undef COPY_ADDR
if(table != import_table)
return -1;
int i;
for(i = 0; i < import_table_count; i++)
if(table == import_tables[i])
return 0;
return -1;
}
static void
......
......@@ -57,7 +57,7 @@ static int get_sdl(struct sockaddr_dl *sdl, char *ifname);
static const unsigned char v4prefix[16] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
int export_table = -1, import_table = -1;
int export_table = -1, import_table_count = 0, import_tables[MAX_IMPORT_TABLES];
int
if_eui64(char *ifname, int ifindex, unsigned char *eui)
......@@ -835,6 +835,8 @@ kernel_callback(int (*fn)(int, void*), void *closure)
}
int add_import_table(int table) { return 0; } // not used
/* Local Variables: */
/* c-basic-offset: 4 */
/* indent-tabs-mode: nil */
......
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