lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 19 Jul 2023 20:51:02 +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 18/22] lib/rt_names: Read rt_protos.d/* using rtnl_tab_initialize_dir

Signed-off-by: Gioele Barabucci <gioele@...rio.it>
---
 lib/rt_names.c | 52 +++++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/lib/rt_names.c b/lib/rt_names.c
index d9c48813..3b69d05d 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -151,23 +151,18 @@ static char *rtnl_rtprot_tab[256] = {
 };
 
 
-static int rtnl_rtprot_init;
-
-static void rtnl_rtprot_initialize(void)
+static void
+rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size)
 {
+	char dirpath_usr[PATH_MAX], dirpath_etc[PATH_MAX];
 	struct dirent *de;
 	DIR *d;
-	int ret;
 
-	rtnl_rtprot_init = 1;
-	ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_protos",
-	                          rtnl_rtprot_tab, 256);
-	if (ret == -ENOENT)
-		rtnl_tab_initialize(CONF_USR_DIR "/rt_protos",
-		                    rtnl_rtprot_tab, 256);
+	snprintf(dirpath_usr, sizeof(dirpath_usr), "%s/%s", CONF_USR_DIR, ddir);
+	snprintf(dirpath_etc, sizeof(dirpath_etc), "%s/%s", CONF_ETC_DIR, ddir);
 
-	/* load /usr/lib/iproute2/foo.d/X, unless /etc/iproute2/foo.d/X exists */
-	d = opendir(CONF_USR_DIR "/rt_protos.d");
+	/* load /usr/lib/iproute2/foo.d/X conf files, unless /etc/iproute2/foo.d/X exists */
+	d = opendir(dirpath_usr);
 	while (d && (de = readdir(d)) != NULL) {
 		char path[PATH_MAX];
 		size_t len;
@@ -184,21 +179,19 @@ static void rtnl_rtprot_initialize(void)
 			continue;
 
 		/* only consider filenames not present in /etc */
-		snprintf(path, sizeof(path), CONF_USR_DIR "/rt_protos.d/%s",
-		         de->d_name);
+		snprintf(path, sizeof(path), "%s/%s", dirpath_etc, de->d_name);
 		if (lstat(path, &sb) == 0)
 			continue;
 
 		/* load the conf file in /usr */
-		snprintf(path, sizeof(path), CONF_ETC_DIR "/rt_protos.d/%s",
-			 de->d_name);
-		rtnl_tab_initialize(path, rtnl_rtprot_tab, 256);
+		snprintf(path, sizeof(path), "%s/%s", dirpath_usr, de->d_name);
+		rtnl_tab_initialize(path, tab, size);
 	}
 	if (d)
 		closedir(d);
 
-	/* load /etc/iproute2/foo.d/X */
-	d = opendir(CONF_ETC_DIR "/rt_protos.d");
+	/* load /etc/iproute2/foo.d/X conf files */
+	d = opendir(dirpath_etc);
 	while (d && (de = readdir(d)) != NULL) {
 		char path[PATH_MAX];
 		size_t len;
@@ -214,14 +207,29 @@ static void rtnl_rtprot_initialize(void)
 			continue;
 
 		/* load the conf file in /etc */
-		snprintf(path, sizeof(path), CONF_USR_DIR "/rt_protos.d/%s",
-			 de->d_name);
-		rtnl_tab_initialize(path, rtnl_rtprot_tab, 256);
+		snprintf(path, sizeof(path), "%s/%s", dirpath_etc, de->d_name);
+		rtnl_tab_initialize(path, tab, size);
 	}
 	if (d)
 		closedir(d);
 }
 
+static int rtnl_rtprot_init;
+
+static void rtnl_rtprot_initialize(void)
+{
+	int ret;
+
+	rtnl_rtprot_init = 1;
+	ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_protos",
+	                          rtnl_rtprot_tab, 256);
+	if (ret == -ENOENT)
+		rtnl_tab_initialize(CONF_USR_DIR "/rt_protos",
+		                    rtnl_rtprot_tab, 256);
+
+	rtnl_tab_initialize_dir("rt_protos.d", rtnl_rtprot_tab, 256);
+}
+
 const char *rtnl_rtprot_n2a(int id, char *buf, int len)
 {
 	if (id < 0 || id >= 256 || numeric) {
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ