simplified reading the net-priority option

This commit is contained in:
Nikos Mavrogiannopoulos
2013-12-10 10:05:36 +01:00
parent b4c2aebd9e
commit fd25969aca
2 changed files with 24 additions and 27 deletions

View File

@@ -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);

View File

@@ -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);