mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 18:55:40 +03:00
resolved,networkd: unify ResolveSupport enum
networkd previously knew an enum "ResolveSupport" for configuring per-interface LLMNR support, resolved had a similar enum just called "Support", with the same value and similar pasers. Unify this, call the enum ResolveSupport, and port both daemons to it.
This commit is contained in:
parent
b18b866215
commit
af49ca27ff
@ -1054,7 +1054,9 @@ libshared_la_SOURCES = \
|
||||
src/shared/machine-image.c \
|
||||
src/shared/machine-image.h \
|
||||
src/shared/machine-pool.c \
|
||||
src/shared/machine-pool.h
|
||||
src/shared/machine-pool.h \
|
||||
src/shared/resolve-util.c \
|
||||
src/shared/resolve-util.h
|
||||
|
||||
if HAVE_UTMP
|
||||
libshared_la_SOURCES += \
|
||||
|
@ -45,7 +45,7 @@ Network.Address, config_parse_address,
|
||||
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_resolve, 0, offsetof(Network, llmnr)
|
||||
Network.LLMNR, config_parse_resolve_support, 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)
|
||||
|
@ -22,6 +22,7 @@
|
||||
***/
|
||||
|
||||
#include "condition.h"
|
||||
#include "resolve-util.h"
|
||||
|
||||
typedef struct Network Network;
|
||||
|
||||
|
@ -101,13 +101,3 @@ int config_parse_address_family_boolean_with_kernel(
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_WITH_BOOLEAN(resolve_support, ResolveSupport, RESOLVE_SUPPORT_YES);
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve, resolve_support, ResolveSupport, "Failed to parse resolve support");
|
||||
|
@ -33,20 +33,8 @@ typedef enum AddressFamilyBoolean {
|
||||
_ADDRESS_FAMILY_BOOLEAN_INVALID = -1,
|
||||
} AddressFamilyBoolean;
|
||||
|
||||
typedef enum ResolveSupport {
|
||||
RESOLVE_SUPPORT_NO,
|
||||
RESOLVE_SUPPORT_YES,
|
||||
RESOLVE_SUPPORT_RESOLVE,
|
||||
_RESOLVE_SUPPORT_MAX,
|
||||
_RESOLVE_SUPPORT_INVALID = -1,
|
||||
} ResolveSupport;
|
||||
|
||||
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);
|
||||
int config_parse_address_family_boolean(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_address_family_boolean_with_kernel(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);
|
||||
|
||||
const char* resolve_support_to_string(ResolveSupport i) _const_;
|
||||
ResolveSupport resolve_support_from_string(const char *s) _pure_;
|
||||
|
||||
const char *address_family_boolean_to_string(AddressFamilyBoolean b) _const_;
|
||||
AddressFamilyBoolean address_family_boolean_from_string(const char *s) _const_;
|
||||
|
@ -200,40 +200,6 @@ int config_parse_search_domains(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_support(
|
||||
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) {
|
||||
|
||||
Support support, *v = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
support = support_from_string(rvalue);
|
||||
if (support < 0) {
|
||||
r = parse_boolean(rvalue);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse support level '%s'. Ignoring.", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
support = r ? SUPPORT_YES : SUPPORT_NO;
|
||||
}
|
||||
|
||||
*v = support;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_dnssec(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
@ -35,5 +35,4 @@ const struct ConfigPerfItem* resolved_gperf_lookup(const char *key, unsigned len
|
||||
|
||||
int config_parse_dns_servers(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_search_domains(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_support(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_dnssec(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);
|
||||
|
@ -17,5 +17,5 @@ struct ConfigPerfItem;
|
||||
Resolve.DNS, config_parse_dns_servers, DNS_SERVER_SYSTEM, 0
|
||||
Resolve.FallbackDNS, config_parse_dns_servers, DNS_SERVER_FALLBACK, 0
|
||||
Resolve.Domains, config_parse_search_domains, 0, 0
|
||||
Resolve.LLMNR, config_parse_support, 0, offsetof(Manager, llmnr_support)
|
||||
Resolve.LLMNR, config_parse_resolve_support,0, offsetof(Manager, llmnr_support)
|
||||
Resolve.DNSSEC, config_parse_dnssec, 0, 0
|
||||
|
@ -46,7 +46,7 @@ int link_new(Manager *m, Link **ret, int ifindex) {
|
||||
return -ENOMEM;
|
||||
|
||||
l->ifindex = ifindex;
|
||||
l->llmnr_support = SUPPORT_YES;
|
||||
l->llmnr_support = RESOLVE_SUPPORT_YES;
|
||||
|
||||
r = hashmap_put(m->links, INT_TO_PTR(ifindex), l);
|
||||
if (r < 0)
|
||||
@ -99,8 +99,8 @@ static void link_allocate_scopes(Link *l) {
|
||||
l->unicast_scope = dns_scope_free(l->unicast_scope);
|
||||
|
||||
if (link_relevant(l, AF_INET) &&
|
||||
l->llmnr_support != SUPPORT_NO &&
|
||||
l->manager->llmnr_support != SUPPORT_NO) {
|
||||
l->llmnr_support != RESOLVE_SUPPORT_NO &&
|
||||
l->manager->llmnr_support != RESOLVE_SUPPORT_NO) {
|
||||
if (!l->llmnr_ipv4_scope) {
|
||||
r = dns_scope_new(l->manager, &l->llmnr_ipv4_scope, l, DNS_PROTOCOL_LLMNR, AF_INET);
|
||||
if (r < 0)
|
||||
@ -110,8 +110,8 @@ static void link_allocate_scopes(Link *l) {
|
||||
l->llmnr_ipv4_scope = dns_scope_free(l->llmnr_ipv4_scope);
|
||||
|
||||
if (link_relevant(l, AF_INET6) &&
|
||||
l->llmnr_support != SUPPORT_NO &&
|
||||
l->manager->llmnr_support != SUPPORT_NO &&
|
||||
l->llmnr_support != RESOLVE_SUPPORT_NO &&
|
||||
l->manager->llmnr_support != RESOLVE_SUPPORT_NO &&
|
||||
socket_ipv6_is_supported()) {
|
||||
if (!l->llmnr_ipv6_scope) {
|
||||
r = dns_scope_new(l->manager, &l->llmnr_ipv6_scope, l, DNS_PROTOCOL_LLMNR, AF_INET6);
|
||||
@ -122,8 +122,8 @@ static void link_allocate_scopes(Link *l) {
|
||||
l->llmnr_ipv6_scope = dns_scope_free(l->llmnr_ipv6_scope);
|
||||
|
||||
if (link_relevant(l, AF_INET) &&
|
||||
l->mdns_support != SUPPORT_NO &&
|
||||
l->manager->mdns_support != SUPPORT_NO) {
|
||||
l->mdns_support != RESOLVE_SUPPORT_NO &&
|
||||
l->manager->mdns_support != RESOLVE_SUPPORT_NO) {
|
||||
if (!l->mdns_ipv4_scope) {
|
||||
r = dns_scope_new(l->manager, &l->mdns_ipv4_scope, l, DNS_PROTOCOL_MDNS, AF_INET);
|
||||
if (r < 0)
|
||||
@ -133,8 +133,8 @@ static void link_allocate_scopes(Link *l) {
|
||||
l->mdns_ipv4_scope = dns_scope_free(l->mdns_ipv4_scope);
|
||||
|
||||
if (link_relevant(l, AF_INET6) &&
|
||||
l->mdns_support != SUPPORT_NO &&
|
||||
l->manager->mdns_support != SUPPORT_NO) {
|
||||
l->mdns_support != RESOLVE_SUPPORT_NO &&
|
||||
l->manager->mdns_support != RESOLVE_SUPPORT_NO) {
|
||||
if (!l->mdns_ipv6_scope) {
|
||||
r = dns_scope_new(l->manager, &l->mdns_ipv6_scope, l, DNS_PROTOCOL_MDNS, AF_INET6);
|
||||
if (r < 0)
|
||||
@ -233,22 +233,16 @@ static int link_update_llmnr_support(Link *l) {
|
||||
if (r < 0)
|
||||
goto clear;
|
||||
|
||||
r = parse_boolean(b);
|
||||
if (r < 0) {
|
||||
if (streq(b, "resolve"))
|
||||
l->llmnr_support = SUPPORT_RESOLVE;
|
||||
else
|
||||
goto clear;
|
||||
|
||||
} else if (r > 0)
|
||||
l->llmnr_support = SUPPORT_YES;
|
||||
else
|
||||
l->llmnr_support = SUPPORT_NO;
|
||||
l->llmnr_support = resolve_support_from_string(b);
|
||||
if (l->llmnr_support < 0) {
|
||||
r = -EINVAL;
|
||||
goto clear;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
clear:
|
||||
l->llmnr_support = SUPPORT_YES;
|
||||
l->llmnr_support = RESOLVE_SUPPORT_YES;
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -459,8 +453,8 @@ void link_address_add_rrs(LinkAddress *a, bool force_remove) {
|
||||
if (!force_remove &&
|
||||
link_address_relevant(a) &&
|
||||
a->link->llmnr_ipv4_scope &&
|
||||
a->link->llmnr_support == SUPPORT_YES &&
|
||||
a->link->manager->llmnr_support == SUPPORT_YES) {
|
||||
a->link->llmnr_support == RESOLVE_SUPPORT_YES &&
|
||||
a->link->manager->llmnr_support == RESOLVE_SUPPORT_YES) {
|
||||
|
||||
if (!a->link->manager->llmnr_host_ipv4_key) {
|
||||
a->link->manager->llmnr_host_ipv4_key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, a->link->manager->llmnr_hostname);
|
||||
@ -516,8 +510,8 @@ void link_address_add_rrs(LinkAddress *a, bool force_remove) {
|
||||
if (!force_remove &&
|
||||
link_address_relevant(a) &&
|
||||
a->link->llmnr_ipv6_scope &&
|
||||
a->link->llmnr_support == SUPPORT_YES &&
|
||||
a->link->manager->llmnr_support == SUPPORT_YES) {
|
||||
a->link->llmnr_support == RESOLVE_SUPPORT_YES &&
|
||||
a->link->manager->llmnr_support == RESOLVE_SUPPORT_YES) {
|
||||
|
||||
if (!a->link->manager->llmnr_host_ipv6_key) {
|
||||
a->link->manager->llmnr_host_ipv6_key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, a->link->manager->llmnr_hostname);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "in-addr-util.h"
|
||||
#include "ratelimit.h"
|
||||
#include "resolve-util.h"
|
||||
|
||||
typedef struct Link Link;
|
||||
typedef struct LinkAddress LinkAddress;
|
||||
@ -66,8 +67,8 @@ struct Link {
|
||||
LIST_HEAD(DnsSearchDomain, search_domains);
|
||||
unsigned n_search_domains;
|
||||
|
||||
Support llmnr_support;
|
||||
Support mdns_support;
|
||||
ResolveSupport llmnr_support;
|
||||
ResolveSupport mdns_support;
|
||||
|
||||
DnsScope *unicast_scope;
|
||||
DnsScope *llmnr_ipv4_scope;
|
||||
|
@ -47,7 +47,7 @@ int manager_llmnr_start(Manager *m) {
|
||||
|
||||
assert(m);
|
||||
|
||||
if (m->llmnr_support == SUPPORT_NO)
|
||||
if (m->llmnr_support == RESOLVE_SUPPORT_NO)
|
||||
return 0;
|
||||
|
||||
r = manager_llmnr_ipv4_udp_fd(m);
|
||||
@ -80,7 +80,7 @@ int manager_llmnr_start(Manager *m) {
|
||||
|
||||
eaddrinuse:
|
||||
log_warning("There appears to be another LLMNR responder running. Turning off LLMNR support.");
|
||||
m->llmnr_support = SUPPORT_NO;
|
||||
m->llmnr_support = RESOLVE_SUPPORT_NO;
|
||||
manager_llmnr_stop(m);
|
||||
|
||||
return 0;
|
||||
|
@ -476,7 +476,7 @@ int manager_new(Manager **ret) {
|
||||
m->mdns_ipv4_fd = m->mdns_ipv6_fd = -1;
|
||||
m->hostname_fd = -1;
|
||||
|
||||
m->llmnr_support = SUPPORT_YES;
|
||||
m->llmnr_support = RESOLVE_SUPPORT_YES;
|
||||
m->read_resolv_conf = true;
|
||||
m->need_builtin_fallbacks = true;
|
||||
|
||||
@ -1163,10 +1163,3 @@ int manager_compile_search_domains(Manager *m, OrderedSet **domains) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char* const support_table[_SUPPORT_MAX] = {
|
||||
[SUPPORT_NO] = "no",
|
||||
[SUPPORT_YES] = "yes",
|
||||
[SUPPORT_RESOLVE] = "resolve",
|
||||
};
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(support, Support, SUPPORT_YES);
|
||||
|
@ -28,17 +28,9 @@
|
||||
#include "hashmap.h"
|
||||
#include "list.h"
|
||||
#include "ordered-set.h"
|
||||
#include "resolve-util.h"
|
||||
|
||||
typedef struct Manager Manager;
|
||||
typedef enum Support Support;
|
||||
|
||||
enum Support {
|
||||
SUPPORT_NO,
|
||||
SUPPORT_YES,
|
||||
SUPPORT_RESOLVE,
|
||||
_SUPPORT_MAX,
|
||||
_SUPPORT_INVALID = -1
|
||||
};
|
||||
|
||||
#include "resolved-dns-query.h"
|
||||
#include "resolved-dns-search-domain.h"
|
||||
@ -53,8 +45,8 @@ enum Support {
|
||||
struct Manager {
|
||||
sd_event *event;
|
||||
|
||||
Support llmnr_support;
|
||||
Support mdns_support;
|
||||
ResolveSupport llmnr_support;
|
||||
ResolveSupport mdns_support;
|
||||
|
||||
/* Network */
|
||||
Hashmap *links;
|
||||
@ -165,6 +157,3 @@ int manager_is_own_hostname(Manager *m, const char *name);
|
||||
|
||||
int manager_compile_dns_servers(Manager *m, OrderedSet **servers);
|
||||
int manager_compile_search_domains(Manager *m, OrderedSet **domains);
|
||||
|
||||
const char* support_to_string(Support p) _const_;
|
||||
int support_from_string(const char *s) _pure_;
|
||||
|
@ -42,7 +42,7 @@ int manager_mdns_start(Manager *m) {
|
||||
|
||||
assert(m);
|
||||
|
||||
if (m->mdns_support == SUPPORT_NO)
|
||||
if (m->mdns_support == RESOLVE_SUPPORT_NO)
|
||||
return 0;
|
||||
|
||||
r = manager_mdns_ipv4_fd(m);
|
||||
@ -63,7 +63,7 @@ int manager_mdns_start(Manager *m) {
|
||||
|
||||
eaddrinuse:
|
||||
log_warning("There appears to be another mDNS responder running. Turning off mDNS support.");
|
||||
m->mdns_support = SUPPORT_NO;
|
||||
m->mdns_support = RESOLVE_SUPPORT_NO;
|
||||
manager_mdns_stop(m);
|
||||
|
||||
return 0;
|
||||
|
33
src/shared/resolve-util.c
Normal file
33
src/shared/resolve-util.c
Normal file
@ -0,0 +1,33 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2016 Lennart Poettering
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "resolve-util.h"
|
||||
#include "string-table.h"
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_support, resolve_support, ResolveSupport, "Failed to parse resolve support setting");
|
||||
|
||||
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_WITH_BOOLEAN(resolve_support, ResolveSupport, RESOLVE_SUPPORT_YES);
|
39
src/shared/resolve-util.h
Normal file
39
src/shared/resolve-util.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2016 Lennart Poettering
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum ResolveSupport ResolveSupport;
|
||||
|
||||
enum ResolveSupport {
|
||||
RESOLVE_SUPPORT_NO,
|
||||
RESOLVE_SUPPORT_YES,
|
||||
RESOLVE_SUPPORT_RESOLVE,
|
||||
_RESOLVE_SUPPORT_MAX,
|
||||
_RESOLVE_SUPPORT_INVALID = -1
|
||||
};
|
||||
|
||||
int config_parse_resolve_support(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);
|
||||
|
||||
const char* resolve_support_to_string(ResolveSupport p) _const_;
|
||||
ResolveSupport resolve_support_from_string(const char *s) _pure_;
|
Loading…
Reference in New Issue
Block a user