network: introduce radv_prefix_delegation_{from,to}_string()

This commit is contained in:
Yu Watanabe
2018-11-04 00:31:46 +09:00
parent 8a4871c7d1
commit 6b1dec6696
2 changed files with 25 additions and 14 deletions
+5
View File
@@ -78,6 +78,8 @@ typedef enum RADVPrefixDelegation {
RADV_PREFIX_DELEGATION_STATIC,
RADV_PREFIX_DELEGATION_DHCP6,
RADV_PREFIX_DELEGATION_BOTH,
_RADV_PREFIX_DELEGATION_MAX,
_RADV_PREFIX_DELEGATION_INVALID = -1,
} RADVPrefixDelegation;
typedef struct NetworkConfigSection {
@@ -316,3 +318,6 @@ DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
const char* lldp_mode_to_string(LLDPMode m) _const_;
LLDPMode lldp_mode_from_string(const char *s) _pure_;
const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
+20 -14
View File
@@ -12,8 +12,21 @@
#include "parse-util.h"
#include "sd-radv.h"
#include "string-util.h"
#include "string-table.h"
#include "strv.h"
static const char * const radv_prefix_delegation_table[_RADV_PREFIX_DELEGATION_MAX] = {
[RADV_PREFIX_DELEGATION_NONE] = "no",
[RADV_PREFIX_DELEGATION_STATIC] = "static",
[RADV_PREFIX_DELEGATION_DHCP6] = "dhcpv6",
[RADV_PREFIX_DELEGATION_BOTH] = "yes",
};
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(
radv_prefix_delegation,
RADVPrefixDelegation,
RADV_PREFIX_DELEGATION_BOTH);
int config_parse_router_prefix_delegation(
const char *unit,
const char *filename,
@@ -27,7 +40,7 @@ int config_parse_router_prefix_delegation(
void *userdata) {
Network *network = userdata;
int d;
RADVPrefixDelegation d;
assert(filename);
assert(section);
@@ -35,21 +48,14 @@ int config_parse_router_prefix_delegation(
assert(rvalue);
assert(data);
if (streq(rvalue, "static"))
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_STATIC;
else if (streq(rvalue, "dhcpv6"))
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_DHCP6;
else {
d = parse_boolean(rvalue);
if (d > 0)
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_BOTH;
else
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_NONE;
if (d < 0)
log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Router prefix delegation '%s' is invalid, ignoring assignment: %m", rvalue);
d = radv_prefix_delegation_from_string(rvalue);
if (d < 0) {
log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Invalid router prefix delegation '%s', ignoring assignment.", rvalue);
return 0;
}
network->router_prefix_delegation = d;
return 0;
}