diff mbox

[iproute2] Add support for rt_tables.d

Message ID 1447873400-15337-1-git-send-email-dsa@cumulusnetworks.com
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show

Commit Message

David Ahern Nov. 18, 2015, 7:03 p.m. UTC
Add support for reading table id/name mappings from rt_tables.d
directory.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 lib/rt_names.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Stephen Hemminger Nov. 23, 2015, 11:23 p.m. UTC | #1
On Wed, 18 Nov 2015 11:03:20 -0800
David Ahern <dsa@cumulusnetworks.com> wrote:

> Add support for reading table id/name mappings from rt_tables.d
> directory.
> 
> Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
> ---
>  lib/rt_names.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

This is a useful concept, and I am for incorporating it in the future.

The consensus practice for other utility is to a '.conf' suffix which
allows for README.

Probably should also ship a README file in the package.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/rt_names.c b/lib/rt_names.c
index e87c65dad39e..d835ff9c7ee0 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -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>
@@ -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;
@@ -348,6 +351,21 @@  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];
+
+		if (*de->d_name == '.')
+			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)