netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] Add support for rt_tables.d
@ 2015-11-18 19:03 David Ahern
  2015-11-23 23:23 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: David Ahern @ 2015-11-18 19:03 UTC (permalink / raw)
  To: stephen, netdev; +Cc: David Ahern

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(+)

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)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2] Add support for rt_tables.d
  2015-11-18 19:03 [PATCH iproute2] Add support for rt_tables.d David Ahern
@ 2015-11-23 23:23 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2015-11-23 23:23 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-23 23:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-18 19:03 [PATCH iproute2] Add support for rt_tables.d David Ahern
2015-11-23 23:23 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).