From fd25969acaaae07e7ead43b23b57d05755535f8b Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 10 Dec 2013 10:05:36 +0100 Subject: [PATCH] simplified reading the net-priority option --- src/config.c | 26 ++++++++++++-------------- src/group-config.c | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/config.c b/src/config.c index d7cbb42b..4451ddb5 100644 --- a/src/config.c +++ b/src/config.c @@ -79,7 +79,7 @@ static struct cfg_options available_options[] = { { .name = "tls-priorities", .type = OPTION_STRING, .mandatory = 0 }, { .name = "chroot-dir", .type = OPTION_STRING, .mandatory = 0 }, { .name = "mtu", .type = OPTION_NUMERIC, .mandatory = 0 }, - { .name = "net-priority", .type = OPTION_NUMERIC, .mandatory = 0 }, + { .name = "net-priority", .type = OPTION_STRING, .mandatory = 0 }, { .name = "output-buffer", .type = OPTION_NUMERIC, .mandatory = 0 }, { .name = "cookie-validity", .type = OPTION_NUMERIC, .mandatory = 1 }, { .name = "auth-timeout", .type = OPTION_NUMERIC, .mandatory = 0 }, @@ -178,20 +178,24 @@ unsigned j; exit(1); \ } -#define READ_NUMERIC_HEX(name, s_name) \ +#define READ_PRIO_TOS(name, s_name) \ val = get_option(name, &mand); \ if (val != NULL) { \ - if (val->valType == OPARG_TYPE_NUMERIC) \ - s_name = val->v.longVal; \ - else if (val->valType == OPARG_TYPE_STRING) \ - s_name = strtol(val->v.strVal, NULL, 16); \ + if (val->valType == OPARG_TYPE_STRING) { \ + if (strncmp(val->v.strVal, "0x", 2) == 0) { \ + s_name = strtol(val->v.strVal, NULL, 16); \ + s_name = TOS_PACK(s_name); \ + } else { \ + s_name = atoi(val->v.strVal); \ + s_name++; \ + } \ + } \ } else if (mand != 0) { \ fprintf(stderr, "Configuration option %s is mandatory.\n", name); \ exit(1); \ } - static int handle_option(const tOptionValue* val) { unsigned j; @@ -331,13 +335,7 @@ unsigned prefix = 0; READ_NUMERIC("mtu", config->default_mtu); - READ_NUMERIC("net-priority", config->net_priority); - if (config->net_priority == 0) { - READ_NUMERIC_HEX("net-priority", config->net_priority); - config->net_priority = TOS_PACK(config->net_priority); - } else { - config->net_priority++; - } + READ_PRIO_TOS("net-priority", config->net_priority); READ_NUMERIC("output-buffer", config->output_buffer); diff --git a/src/group-config.c b/src/group-config.c index 522b87f6..87064b17 100644 --- a/src/group-config.c +++ b/src/group-config.c @@ -53,7 +53,7 @@ static struct cfg_options available_options[] = { { .name = "ipv6-netmask", .type = OPTION_STRING }, { .name = "rx-data-per-sec", .type = OPTION_NUMERIC, }, { .name = "tx-data-per-sec", .type = OPTION_NUMERIC, }, - { .name = "net-priority", .type = OPTION_NUMERIC, }, + { .name = "net-priority", .type = OPTION_STRING, }, }; #define READ_RAW_MULTI_LINE(name, s_name, num) \ @@ -89,13 +89,18 @@ static struct cfg_options available_options[] = { s_name = atoi(val->v.strVal); \ } -#define READ_RAW_NUMERIC_HEX(name, s_name) \ +#define READ_RAW_PRIO_TOS(name, s_name) \ val = optionGetValue(pov, name); \ if (val != NULL) { \ - if (val->valType == OPARG_TYPE_NUMERIC) \ - s_name = val->v.longVal; \ - else if (val->valType == OPARG_TYPE_STRING) \ - s_name = strtol(val->v.strVal, NULL, 16); \ + if (val->valType == OPARG_TYPE_STRING) { \ + if (strncmp(val->v.strVal, "0x", 2) == 0) { \ + s_name = strtol(val->v.strVal, NULL, 16); \ + s_name = TOS_PACK(s_name); \ + } else { \ + s_name = atoi(val->v.strVal); \ + s_name++; \ + } \ + } \ } @@ -161,13 +166,7 @@ unsigned prefix = 0; /* net-priority will contain the actual priority + 1, * to allow having zero as uninitialized. */ - READ_RAW_NUMERIC("net-priority", config->net_priority); - if (config->net_priority == 0) { - READ_RAW_NUMERIC_HEX("net-priority", config->net_priority); - config->net_priority = TOS_PACK(config->net_priority); - } else { - config->net_priority++; - } + READ_RAW_PRIO_TOS("net-priority", config->net_priority); optionUnloadNested(pov);