Commit 89e8aa90 authored by Pavel Tikhomirov's avatar Pavel Tikhomirov Committed by Pavel Emelyanov

net/sysctl: remove excess type conversions for sysctl_entry.type

use native SYSCTL_TYPE__CTL_32 and SYSCTL_TYPE__CTL_STR

v2: add BUILD_BUG_ONS to check SysctlType constants are equal to
__CTL_STR and CTL_32, change __CTL_STR to CTL_STR in SysctlType enum.
Signed-off-by: 's avatarPavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 11c4f5f6
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "proc_parse.h" #include "proc_parse.h"
#include "setproctitle.h" #include "setproctitle.h"
#include "sysctl.h"
struct cr_options opts; struct cr_options opts;
...@@ -252,6 +253,8 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -252,6 +253,8 @@ int main(int argc, char *argv[], char *envp[])
}; };
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE); BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
BUILD_BUG_ON(CTL_32 != SYSCTL_TYPE__CTL_32);
BUILD_BUG_ON(__CTL_STR != SYSCTL_TYPE__CTL_STR);
if (fault_injection_init()) if (fault_injection_init())
return 1; return 1;
......
...@@ -66,11 +66,12 @@ static bool sysctl_entries_equal(SysctlEntry *a, SysctlEntry *b) ...@@ -66,11 +66,12 @@ static bool sysctl_entries_equal(SysctlEntry *a, SysctlEntry *b)
if (a->type != b->type) if (a->type != b->type)
return false; return false;
switch (CTL_TYPE(a->type)) { switch (a->type) {
case CTL_32: case SYSCTL_TYPE__CTL_32:
return a->has_iarg && b->has_iarg && a->iarg == b->iarg; return a->has_iarg && b->has_iarg && a->iarg == b->iarg;
case __CTL_STR: case SYSCTL_TYPE__CTL_STR:
return a->sarg && b->sarg && !strcmp(a->sarg, b->sarg); return a->sarg && b->sarg && !strcmp(a->sarg, b->sarg);
default:;
} }
return false; return false;
...@@ -191,8 +192,8 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto ...@@ -191,8 +192,8 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
snprintf(path[i], MAX_CONF_OPT_PATH, CONF_OPT_PATH, proto, tgt, devconfs[i]); snprintf(path[i], MAX_CONF_OPT_PATH, CONF_OPT_PATH, proto, tgt, devconfs[i]);
req[ri].name = path[i]; req[ri].name = path[i];
switch (CTL_TYPE(conf[i]->type)) { switch (conf[i]->type) {
case CTL_32: case SYSCTL_TYPE__CTL_32:
req[ri].type = CTL_32; req[ri].type = CTL_32;
/* skip non-existing sysctl */ /* skip non-existing sysctl */
...@@ -201,7 +202,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto ...@@ -201,7 +202,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
req[ri].arg = &conf[i]->iarg; req[ri].arg = &conf[i]->iarg;
break; break;
case __CTL_STR: case SYSCTL_TYPE__CTL_STR:
req[ri].type = CTL_STR(MAX_STR_CONF_LEN); req[ri].type = CTL_STR(MAX_STR_CONF_LEN);
flags |= op == CTL_READ && !strcmp(devconfs[i], "stable_secret") flags |= op == CTL_READ && !strcmp(devconfs[i], "stable_secret")
? CTL_FLAGS_READ_EIO_SKIP : 0; ? CTL_FLAGS_READ_EIO_SKIP : 0;
...@@ -230,10 +231,10 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto ...@@ -230,10 +231,10 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
/* (un)mark (non-)existing sysctls in image */ /* (un)mark (non-)existing sysctls in image */
for (i = 0; i < ri; i++) for (i = 0; i < ri; i++)
if (req[i].flags & CTL_FLAGS_HAS) { if (req[i].flags & CTL_FLAGS_HAS) {
if (CTL_TYPE(rconf[i]->type) == CTL_32) if (rconf[i]->type == SYSCTL_TYPE__CTL_32)
rconf[i]->has_iarg = true; rconf[i]->has_iarg = true;
} else { } else {
if (CTL_TYPE(rconf[i]->type) == __CTL_STR) if (rconf[i]->type == SYSCTL_TYPE__CTL_STR)
rconf[i]->sarg = NULL; rconf[i]->sarg = NULL;
} }
} }
...@@ -380,9 +381,9 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi, ...@@ -380,9 +381,9 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
sysctl_entry__init(&confs6[i]); sysctl_entry__init(&confs6[i]);
netdev.conf6[i] = &confs6[i]; netdev.conf6[i] = &confs6[i];
if (strcmp(devconfs6[i], "stable_secret")) { if (strcmp(devconfs6[i], "stable_secret")) {
netdev.conf6[i]->type = CTL_32; netdev.conf6[i]->type = SYSCTL_TYPE__CTL_32;
} else { } else {
netdev.conf6[i]->type = __CTL_STR; netdev.conf6[i]->type = SYSCTL_TYPE__CTL_STR;
netdev.conf6[i]->sarg = stable_secret; netdev.conf6[i]->sarg = stable_secret;
} }
} }
...@@ -1179,11 +1180,11 @@ static int dump_netns_conf(struct cr_imgset *fds) ...@@ -1179,11 +1180,11 @@ static int dump_netns_conf(struct cr_imgset *fds)
netns.def_conf6[i] = &def_confs6[i]; netns.def_conf6[i] = &def_confs6[i];
netns.all_conf6[i] = &all_confs6[i]; netns.all_conf6[i] = &all_confs6[i];
if (strcmp(devconfs6[i], "stable_secret")) { if (strcmp(devconfs6[i], "stable_secret")) {
netns.def_conf6[i]->type = CTL_32; netns.def_conf6[i]->type = SYSCTL_TYPE__CTL_32;
netns.all_conf6[i]->type = CTL_32; netns.all_conf6[i]->type = SYSCTL_TYPE__CTL_32;
} else { } else {
netns.def_conf6[i]->type = __CTL_STR; netns.def_conf6[i]->type = SYSCTL_TYPE__CTL_STR;
netns.all_conf6[i]->type = __CTL_STR; netns.all_conf6[i]->type = SYSCTL_TYPE__CTL_STR;
netns.def_conf6[i]->sarg = def_stable_secret; netns.def_conf6[i]->sarg = def_stable_secret;
netns.all_conf6[i]->sarg = all_stable_secret; netns.all_conf6[i]->sarg = all_stable_secret;
} }
......
enum SysctlType { enum SysctlType {
__CTL_STR = 5; CTL_STR = 5;
CTL_32 = 6; CTL_32 = 6;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment