aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@nokia.com>2019-02-08 16:30:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-02-08 16:52:51 +0100
commitc89764c0633670ef28166c70d03bc593f4a1179f (patch)
tree6e109bae5a6fb5979d4ad754ef199031b1fd09b1
parent78301861ef9e8d0edc72898712dbce7d793150a8 (diff)
downloadbusybox-w32-c89764c0633670ef28166c70d03bc593f4a1179f.tar.gz
busybox-w32-c89764c0633670ef28166c70d03bc593f4a1179f.tar.bz2
busybox-w32-c89764c0633670ef28166c70d03bc593f4a1179f.zip
sysctl: fix compatibility with procps sysctl
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. function old new delta sysctl_dots_to_slashes 86 143 +57 sysctl_act_on_setting 443 453 +10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 67/0) Total: 67 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/sysctl.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/procps/sysctl.c b/procps/sysctl.c
index 5303460f9..6d77185ca 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -56,9 +56,32 @@ enum {
56 56
57static void sysctl_dots_to_slashes(char *name) 57static void sysctl_dots_to_slashes(char *name)
58{ 58{
59 char *cptr, *last_good, *end; 59 char *cptr, *last_good, *end, *slash;
60 char end_ch; 60 char end_ch;
61 61
62 end = strchrnul(name, '=');
63
64 slash = strchrnul(name, '/');
65 if (slash < end
66 && strchrnul(name, '.') < slash
67 ) {
68 /* There are both dots and slashes, and 1st dot is
69 * before 1st slash.
70 * (IOW: not raw, unmangled a/b/c.d format)
71 *
72 * procps supports this syntax for names with dots:
73 * net.ipv4.conf.eth0/100.mc_forwarding
74 * (dots and slashes are simply swapped)
75 */
76 while (end != name) {
77 end--;
78 if (*end == '.') *end = '/';
79 else if (*end == '/') *end = '.';
80 }
81 return;
82 }
83 /* else: use our old behavior: */
84
62 /* Convert minimum number of '.' to '/' so that 85 /* Convert minimum number of '.' to '/' so that
63 * we end up with existing file's name. 86 * we end up with existing file's name.
64 * 87 *
@@ -77,7 +100,6 @@ static void sysctl_dots_to_slashes(char *name)
77 * 100 *
78 * To set up testing: modprobe 8021q; vconfig add eth0 100 101 * To set up testing: modprobe 8021q; vconfig add eth0 100
79 */ 102 */
80 end = strchrnul(name, '=');
81 end_ch = *end; 103 end_ch = *end;
82 *end = '.'; /* trick the loop into trying full name too */ 104 *end = '.'; /* trick the loop into trying full name too */
83 105
@@ -114,6 +136,8 @@ static int sysctl_act_on_setting(char *setting)
114 while (*cptr) { 136 while (*cptr) {
115 if (*cptr == '/') 137 if (*cptr == '/')
116 *cptr = '.'; 138 *cptr = '.';
139 else if (*cptr == '.')
140 *cptr = '/';
117 cptr++; 141 cptr++;
118 } 142 }
119 143