Skip to content

Commit

Permalink
Add support for rt_tables.d
Browse files Browse the repository at this point in the history
Add support for reading table id/name mappings from rt_tables.d
directory.

Suggested-by: Roopa Prabhu <[email protected]>
Signed-off-by: David Ahern <[email protected]>
  • Loading branch information
David Ahern authored and Stephen Hemminger committed Nov 29, 2015
1 parent 906ac54 commit 13ada95
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions etc/iproute2/rt_tables.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Each file in this directory is an rt_tables configuration file. iproute2
commands scan this directory processing all files that end in '.conf'.

26 changes: 26 additions & 0 deletions lib/rt_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <dirent.h>

#include <asm/types.h>
#include <linux/rtnetlink.h>
Expand Down Expand Up @@ -339,6 +340,8 @@ static int rtnl_rttable_init;

static void rtnl_rttable_initialize(void)
{
struct dirent *de;
DIR *d;
int i;

rtnl_rttable_init = 1;
Expand All @@ -348,6 +351,29 @@ static void rtnl_rttable_initialize(void)
}
rtnl_hash_initialize(CONFDIR "/rt_tables",
rtnl_rttable_hash, 256);

d = opendir(CONFDIR "/rt_tables.d");
if (!d)
return;

while ((de = readdir(d)) != NULL) {
char path[PATH_MAX];
size_t len;

if (*de->d_name == '.')
continue;

/* only consider filenames ending in '.conf' */
len = strlen(de->d_name);
if (len <= 5)
continue;
if (strcmp(de->d_name + len - 5, ".conf"))
continue;

snprintf(path, sizeof(path), CONFDIR "/rt_tables.d/%s", de->d_name);
rtnl_hash_initialize(path, rtnl_rttable_hash, 256);
}
closedir(d);
}

const char * rtnl_rttable_n2a(__u32 id, char *buf, int len)
Expand Down

0 comments on commit 13ada95

Please sign in to comment.