]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
Add support for rt_protos.d
authorDavid Ahern <dsa@cumulusnetworks.com>
Mon, 9 Jan 2017 23:43:09 +0000 (15:43 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 13 Jan 2017 01:31:18 +0000 (17:31 -0800)
Add support for reading proto id/name mappings from rt_protos.d
directory. Allows users to have custom protocol values converted
to human friendly names.

Each file under rt_protos.d has the 'id name' format used by
rt_protos. Only .conf files are read and parsed.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
etc/iproute2/rt_protos.d/README [new file with mode: 0644]
etc/iproute2/rt_tables.d/README
lib/rt_names.c

diff --git a/etc/iproute2/rt_protos.d/README b/etc/iproute2/rt_protos.d/README
new file mode 100644 (file)
index 0000000..f9c599c
--- /dev/null
@@ -0,0 +1,2 @@
+Each file in this directory is an rt_protos configuration file. iproute2
+commands scan this directory processing all files that end in '.conf'.
index 79386f89cc14724a2e5b2a76cdb6ce23429bb83b..0920cb1699acf2d7a804e43c53f61d483a930b32 100644 (file)
@@ -1,3 +1,2 @@
 Each file in this directory is an rt_tables configuration file. iproute2
 commands scan this directory processing all files that end in '.conf'.
-
index c66cb1e439e3ca46ca854143b648f1eb0209ec66..7553288eeb1815e42295b1aadffd4eb9f812640b 100644 (file)
@@ -142,9 +142,36 @@ static int rtnl_rtprot_init;
 
 static void rtnl_rtprot_initialize(void)
 {
+       struct dirent *de;
+       DIR *d;
+
        rtnl_rtprot_init = 1;
        rtnl_tab_initialize(CONFDIR "/rt_protos",
                            rtnl_rtprot_tab, 256);
+
+       d = opendir(CONFDIR "/rt_protos.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_protos.d/%s",
+                        de->d_name);
+               rtnl_tab_initialize(path, rtnl_rtprot_tab, 256);
+       }
+       closedir(d);
 }
 
 const char *rtnl_rtprot_n2a(int id, char *buf, int len)