sd-network: make LLMNR specific config parser generic

Rename the enum, the lookup functions and the parser for LLMNRSupport so
the type can be reused for mDNS.
This commit is contained in:
Daniel Mack
2015-08-25 14:26:01 +02:00
parent 9c56a6f3e2
commit a7e5da6e33
4 changed files with 31 additions and 31 deletions
+1 -1
View File
@@ -2378,7 +2378,7 @@ int link_save(Link *link) {
yes_no(link->network->wildcard_domain));
fprintf(f, "LLMNR=%s\n",
llmnr_support_to_string(link->network->llmnr));
resolve_support_to_string(link->network->llmnr));
}
if (!hashmap_isempty(link->bound_to_links)) {
+1 -1
View File
@@ -45,7 +45,7 @@ Network.Address, config_parse_address, 0
Network.Gateway, config_parse_gateway, 0, 0
Network.Domains, config_parse_domains, 0, offsetof(Network, domains)
Network.DNS, config_parse_strv, 0, offsetof(Network, dns)
Network.LLMNR, config_parse_llmnr, 0, offsetof(Network, llmnr)
Network.LLMNR, config_parse_resolve, 0, offsetof(Network, llmnr)
Network.NTP, config_parse_strv, 0, offsetof(Network, ntp)
Network.IPForward, config_parse_address_family_boolean_with_kernel,0, offsetof(Network, ip_forward)
Network.IPMasquerade, config_parse_bool, 0, offsetof(Network, ip_masquerade)
+15 -15
View File
@@ -111,7 +111,7 @@ static int network_load_one(Manager *manager, const char *filename) {
network->allow_port_to_be_root = true;
network->unicast_flood = true;
network->llmnr = LLMNR_SUPPORT_YES;
network->llmnr = RESOLVE_SUPPORT_YES;
network->link_local = ADDRESS_FAMILY_IPV6;
@@ -632,15 +632,15 @@ static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, DCHPClientIdentifier);
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DCHPClientIdentifier, "Failed to parse client identifier type");
static const char* const llmnr_support_table[_LLMNR_SUPPORT_MAX] = {
[LLMNR_SUPPORT_NO] = "no",
[LLMNR_SUPPORT_YES] = "yes",
[LLMNR_SUPPORT_RESOLVE] = "resolve",
static const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
[RESOLVE_SUPPORT_NO] = "no",
[RESOLVE_SUPPORT_YES] = "yes",
[RESOLVE_SUPPORT_RESOLVE] = "resolve",
};
DEFINE_STRING_TABLE_LOOKUP(llmnr_support, LLMNRSupport);
DEFINE_STRING_TABLE_LOOKUP(resolve_support, ResolveSupport);
int config_parse_llmnr(
int config_parse_resolve(
const char* unit,
const char *filename,
unsigned line,
@@ -652,32 +652,32 @@ int config_parse_llmnr(
void *data,
void *userdata) {
LLMNRSupport *llmnr = data;
ResolveSupport *resolve = data;
int k;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(llmnr);
assert(resolve);
/* Our enum shall be a superset of booleans, hence first try
* to parse as boolean, and then as enum */
k = parse_boolean(rvalue);
if (k > 0)
*llmnr = LLMNR_SUPPORT_YES;
*resolve = RESOLVE_SUPPORT_YES;
else if (k == 0)
*llmnr = LLMNR_SUPPORT_NO;
*resolve = RESOLVE_SUPPORT_NO;
else {
LLMNRSupport s;
ResolveSupport s;
s = llmnr_support_from_string(rvalue);
s = resolve_support_from_string(rvalue);
if (s < 0){
log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse LLMNR option, ignoring: %s", rvalue);
log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse %s option, ignoring: %s", lvalue, rvalue);
return 0;
}
*llmnr = s;
*resolve = s;
}
return 0;
+14 -14
View File
@@ -64,13 +64,13 @@ typedef enum AddressFamilyBoolean {
_ADDRESS_FAMILY_BOOLEAN_INVALID = -1,
} AddressFamilyBoolean;
typedef enum LLMNRSupport {
LLMNR_SUPPORT_NO,
LLMNR_SUPPORT_YES,
LLMNR_SUPPORT_RESOLVE,
_LLMNR_SUPPORT_MAX,
_LLMNR_SUPPORT_INVALID = -1,
} LLMNRSupport;
typedef enum ResolveSupport {
RESOLVE_SUPPORT_NO,
RESOLVE_SUPPORT_YES,
RESOLVE_SUPPORT_RESOLVE,
_RESOLVE_SUPPORT_MAX,
_RESOLVE_SUPPORT_INVALID = -1,
} ResolveSupport;
typedef enum LinkOperationalState {
LINK_OPERSTATE_OFF,
@@ -178,7 +178,7 @@ struct Network {
bool wildcard_domain;
char **domains, **dns, **ntp, **bind_carrier;
LLMNRSupport llmnr;
ResolveSupport llmnr;
LIST_FIELDS(Network, networks);
};
@@ -421,14 +421,14 @@ int config_parse_ipv6token(const char *unit, const char *filename, unsigned line
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
/* LLMNR support */
/* Resolve protocols support */
const char* llmnr_support_to_string(LLMNRSupport i) _const_;
LLMNRSupport llmnr_support_from_string(const char *s) _pure_;
const char* resolve_support_to_string(ResolveSupport i) _const_;
ResolveSupport resolve_support_from_string(const char *s) _pure_;
int config_parse_llmnr(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_resolve(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
/* Address Pool */