[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230719185106.17614-21-gioele@svario.it>
Date: Wed, 19 Jul 2023 20:51:04 +0200
From: Gioele Barabucci <gioele@...rio.it>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>,
Gioele Barabucci <gioele@...rio.it>
Subject: [iproute2 20/22] lib/rt_names: Read rt_tables.d/* using rtnl_hash_initialize_dir
Signed-off-by: Gioele Barabucci <gioele@...rio.it>
---
lib/rt_names.c | 50 ++++++++++++++++++++++----------------------------
1 file changed, 22 insertions(+), 28 deletions(-)
diff --git a/lib/rt_names.c b/lib/rt_names.c
index 090fc883..eca8b4fa 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -152,7 +152,8 @@ static char *rtnl_rtprot_tab[256] = {
static void
-rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size)
+rtnl_tabhash_initialize_dir(const char *ddir, void *tabhash, const int size,
+ const bool is_tab)
{
char dirpath_usr[PATH_MAX], dirpath_etc[PATH_MAX];
struct dirent *de;
@@ -185,7 +186,10 @@ rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size)
/* load the conf file in /usr */
snprintf(path, sizeof(path), "%s/%s", dirpath_usr, de->d_name);
- rtnl_tab_initialize(path, tab, size);
+ if (is_tab)
+ rtnl_tab_initialize(path, (char**)tabhash, size);
+ else
+ rtnl_hash_initialize(path, (struct rtnl_hash_entry**)tabhash, size);
}
if (d)
closedir(d);
@@ -208,12 +212,26 @@ rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size)
/* load the conf file in /etc */
snprintf(path, sizeof(path), "%s/%s", dirpath_etc, de->d_name);
- rtnl_tab_initialize(path, tab, size);
+ if (is_tab)
+ rtnl_tab_initialize(path, (char**)tabhash, size);
+ else
+ rtnl_hash_initialize(path, (struct rtnl_hash_entry**)tabhash, size);
}
if (d)
closedir(d);
}
+static void
+rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size) {
+ rtnl_tabhash_initialize_dir(ddir, (void*)tab, size, true);
+}
+
+static void
+rtnl_hash_initialize_dir(const char *ddir, struct rtnl_hash_entry **tab,
+ const int size) {
+ rtnl_tabhash_initialize_dir(ddir, (void*)tab, size, false);
+}
+
static int rtnl_rtprot_init;
static void rtnl_rtprot_initialize(void)
@@ -489,8 +507,6 @@ static int rtnl_rttable_init;
static void rtnl_rttable_initialize(void)
{
- struct dirent *de;
- DIR *d;
int i;
int ret;
@@ -505,29 +521,7 @@ static void rtnl_rttable_initialize(void)
rtnl_hash_initialize(CONF_USR_DIR "/rt_tables",
rtnl_rttable_hash, 256);
- d = opendir(CONF_ETC_DIR "/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),
- CONF_ETC_DIR "/rt_tables.d/%s", de->d_name);
- rtnl_hash_initialize(path, rtnl_rttable_hash, 256);
- }
- closedir(d);
+ rtnl_hash_initialize_dir("rt_tables.d", rtnl_rttable_hash, 256);
}
const char *rtnl_rttable_n2a(__u32 id, char *buf, int len)
--
2.39.2
Powered by blists - more mailing lists