[PATCH v2] sysctl: fix compatibility with procps sysctl

Aaro Koskinen aaro.koskinen at iki.fi
Mon Feb 4 19:37:45 UTC 2019


From: Aaro Koskinen <aaro.koskinen at nokia.com>

Busybox sysctl is incompatible with procps when '.' appears in
directory name, mostly happens with VLANs.

	busybox syntax (since 2008): net.ipv4.conf.eth0.100.mc_forwarding
	 procps syntax (since 2002): net.ipv4.conf.eth0/100.mc_forwarding
	         (supported by both: net/ipv4/conf/eth0.100/mc_forwarding)

Use procps syntax for output; for input, allow both.

Signed-off-by: Aaro Koskinen <aaro.koskinen at nokia.com>
---

	v2: Drop the config option, and support the busybox-specific syntax on
	    input.

 procps/sysctl.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/procps/sysctl.c b/procps/sysctl.c
index 5fa7646d1..eb5ed37dc 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -57,7 +57,28 @@ enum {
 static void sysctl_dots_to_slashes(char *name)
 {
 	char *cptr, *last_good, *end;
+	int n = 0;
 
+	if (!strchr(name, '/'))
+		goto busybox_old_syntax;
+
+	cptr = name;
+	while (*cptr) {
+		if (*cptr == '.') {
+			*cptr = '/';
+			n++;
+		} else if (*cptr == '/') {
+			if (!n)
+				return; /* slash syntax is used */
+			*cptr = '.';
+		} else if (*cptr == '=') {
+			return;
+		}
+		cptr++;
+	}
+	return;
+
+busybox_old_syntax:
 	/* Convert minimum number of '.' to '/' so that
 	 * we end up with existing file's name.
 	 *
@@ -112,6 +133,8 @@ static int sysctl_act_on_setting(char *setting)
 	while (*cptr) {
 		if (*cptr == '/')
 			*cptr = '.';
+		else if (*cptr == '.')
+			*cptr = '/';
 		cptr++;
 	}
 
-- 
2.17.0



More information about the busybox mailing list