mirror of
https://github.com/systemd/systemd.git
synced 2024-12-18 06:33:36 +08:00
Merge pull request #32290 from yuwata/network-conf-parser-cleanups
network,nspawn: several cleanups for conf-parsers
This commit is contained in:
commit
8276dd9ef2
@ -47,6 +47,7 @@ sources = files(
|
||||
'networkd-dhcp4.c',
|
||||
'networkd-dhcp6-bus.c',
|
||||
'networkd-dhcp6.c',
|
||||
'networkd-dns.c',
|
||||
'networkd-ipv4acd.c',
|
||||
'networkd-ipv4ll.c',
|
||||
'networkd-ipv6-proxy-ndp.c',
|
||||
@ -65,6 +66,7 @@ sources = files(
|
||||
'networkd-network-bus.c',
|
||||
'networkd-network.c',
|
||||
'networkd-nexthop.c',
|
||||
'networkd-ntp.c',
|
||||
'networkd-queue.c',
|
||||
'networkd-radv.c',
|
||||
'networkd-route.c',
|
||||
|
@ -530,160 +530,6 @@ int config_parse_dhcp_send_hostname(
|
||||
|
||||
return 0;
|
||||
}
|
||||
int config_parse_dhcp_use_dns(
|
||||
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) {
|
||||
|
||||
Network *network = userdata;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse UseDNS=%s, ignoring assignment: %m", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (ltype) {
|
||||
case AF_INET:
|
||||
network->dhcp_use_dns = r;
|
||||
network->dhcp_use_dns_set = true;
|
||||
break;
|
||||
case AF_INET6:
|
||||
network->dhcp6_use_dns = r;
|
||||
network->dhcp6_use_dns_set = true;
|
||||
break;
|
||||
case AF_UNSPEC:
|
||||
/* For backward compatibility. */
|
||||
if (!network->dhcp_use_dns_set)
|
||||
network->dhcp_use_dns = r;
|
||||
if (!network->dhcp6_use_dns_set)
|
||||
network->dhcp6_use_dns = r;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_dhcp_use_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) {
|
||||
|
||||
Network *network = userdata;
|
||||
DHCPUseDomains d;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
d = dhcp_use_domains_from_string(rvalue);
|
||||
if (d < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, d,
|
||||
"Failed to parse %s=%s, ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (ltype) {
|
||||
case AF_INET:
|
||||
network->dhcp_use_domains = d;
|
||||
network->dhcp_use_domains_set = true;
|
||||
break;
|
||||
case AF_INET6:
|
||||
network->dhcp6_use_domains = d;
|
||||
network->dhcp6_use_domains_set = true;
|
||||
break;
|
||||
case AF_UNSPEC:
|
||||
/* For backward compatibility. */
|
||||
if (!network->dhcp_use_domains_set)
|
||||
network->dhcp_use_domains = d;
|
||||
if (!network->dhcp6_use_domains_set)
|
||||
network->dhcp6_use_domains = d;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_default_dhcp_use_domains, dhcp_use_domains, DHCPUseDomains, "Failed to parse UseDomains=")
|
||||
|
||||
int config_parse_dhcp_use_ntp(
|
||||
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) {
|
||||
|
||||
Network *network = userdata;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse UseNTP=%s, ignoring assignment: %m", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (ltype) {
|
||||
case AF_INET:
|
||||
network->dhcp_use_ntp = r;
|
||||
network->dhcp_use_ntp_set = true;
|
||||
break;
|
||||
case AF_INET6:
|
||||
network->dhcp6_use_ntp = r;
|
||||
network->dhcp6_use_ntp_set = true;
|
||||
break;
|
||||
case AF_UNSPEC:
|
||||
/* For backward compatibility. */
|
||||
if (!network->dhcp_use_ntp_set)
|
||||
network->dhcp_use_ntp = r;
|
||||
if (!network->dhcp6_use_ntp_set)
|
||||
network->dhcp6_use_ntp = r;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_dhcp_or_ra_route_table(
|
||||
const char *unit,
|
||||
@ -1139,14 +985,6 @@ int config_parse_dhcp_request_options(
|
||||
}
|
||||
}
|
||||
|
||||
static const char* const dhcp_use_domains_table[_DHCP_USE_DOMAINS_MAX] = {
|
||||
[DHCP_USE_DOMAINS_NO] = "no",
|
||||
[DHCP_USE_DOMAINS_ROUTE] = "route",
|
||||
[DHCP_USE_DOMAINS_YES] = "yes",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dhcp_use_domains, DHCPUseDomains, DHCP_USE_DOMAINS_YES);
|
||||
|
||||
static const char * const dhcp_option_data_type_table[_DHCP_OPTION_DATA_MAX] = {
|
||||
[DHCP_OPTION_DATA_UINT8] = "uint8",
|
||||
[DHCP_OPTION_DATA_UINT16] = "uint16",
|
||||
|
@ -24,14 +24,6 @@ typedef struct Link Link;
|
||||
typedef struct Manager Manager;
|
||||
typedef struct Network Network;
|
||||
|
||||
typedef enum DHCPUseDomains {
|
||||
DHCP_USE_DOMAINS_NO,
|
||||
DHCP_USE_DOMAINS_YES,
|
||||
DHCP_USE_DOMAINS_ROUTE,
|
||||
_DHCP_USE_DOMAINS_MAX,
|
||||
_DHCP_USE_DOMAINS_INVALID = -EINVAL,
|
||||
} DHCPUseDomains;
|
||||
|
||||
typedef enum DHCPOptionDataType {
|
||||
DHCP_OPTION_DATA_UINT8,
|
||||
DHCP_OPTION_DATA_UINT16,
|
||||
@ -87,9 +79,6 @@ static inline bool in6_prefix_is_filtered(const struct in6_addr *prefix, uint8_t
|
||||
|
||||
int link_get_captive_portal(Link *link, const char **ret);
|
||||
|
||||
const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
|
||||
DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
|
||||
|
||||
const char *dhcp_option_data_type_to_string(DHCPOptionDataType d) _const_;
|
||||
DHCPOptionDataType dhcp_option_data_type_from_string(const char *d) _pure_;
|
||||
|
||||
@ -97,10 +86,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_route_metric);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ndisc_route_metric);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_hostname);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_default_dhcp_use_domains);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_table);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "networkd-queue.h"
|
||||
#include "networkd-route-util.h"
|
||||
#include "parse-util.h"
|
||||
@ -342,7 +343,7 @@ static int link_push_uplink_to_dhcp_server(
|
||||
addresses[n_addresses++] = ia;
|
||||
}
|
||||
|
||||
use_dhcp_lease_data = link->network->dhcp_use_dns;
|
||||
use_dhcp_lease_data = link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4);
|
||||
break;
|
||||
|
||||
case SD_DHCP_LEASE_NTP: {
|
||||
@ -365,7 +366,7 @@ static int link_push_uplink_to_dhcp_server(
|
||||
addresses[n_addresses++] = ia.in;
|
||||
}
|
||||
|
||||
use_dhcp_lease_data = link->network->dhcp_use_ntp;
|
||||
use_dhcp_lease_data = link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-nexthop.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "networkd-queue.h"
|
||||
#include "networkd-route.h"
|
||||
#include "networkd-setlink.h"
|
||||
@ -728,7 +729,7 @@ static int dhcp4_request_routes_to_dns(Link *link) {
|
||||
assert(link->dhcp_lease);
|
||||
assert(link->network);
|
||||
|
||||
if (!link->network->dhcp_use_dns ||
|
||||
if (!link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4) ||
|
||||
!link->network->dhcp_routes_to_dns)
|
||||
return 0;
|
||||
|
||||
@ -749,7 +750,7 @@ static int dhcp4_request_routes_to_ntp(Link *link) {
|
||||
assert(link->dhcp_lease);
|
||||
assert(link->network);
|
||||
|
||||
if (!link->network->dhcp_use_ntp ||
|
||||
if (!link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4) ||
|
||||
!link->network->dhcp_routes_to_ntp)
|
||||
return 0;
|
||||
|
||||
@ -1540,13 +1541,13 @@ static int dhcp4_configure(Link *link) {
|
||||
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for classless static route: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) {
|
||||
if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP4) > 0) {
|
||||
r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_DOMAIN_SEARCH);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for domain search list: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp_use_ntp) {
|
||||
if (link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
|
||||
r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_NTP_SERVER);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for NTP server: %m");
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "networkd-dhcp6.h"
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "networkd-queue.h"
|
||||
#include "networkd-route.h"
|
||||
#include "networkd-state-file.h"
|
||||
@ -633,13 +634,13 @@ static int dhcp6_configure(Link *link) {
|
||||
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set MUD URL: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp6_use_dns) {
|
||||
if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
|
||||
r = sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_DNS_SERVER);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request DNS servers: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp6_use_domains > 0) {
|
||||
if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP6) > 0) {
|
||||
r = sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_DOMAIN);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request domains: %m");
|
||||
@ -651,7 +652,7 @@ static int dhcp6_configure(Link *link) {
|
||||
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request captive portal: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp6_use_ntp) {
|
||||
if (link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
|
||||
r = sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_NTP_SERVER);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request NTP servers: %m");
|
||||
|
290
src/network/networkd-dns.c
Normal file
290
src/network/networkd-dns.c
Normal file
@ -0,0 +1,290 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "dns-domain.h"
|
||||
#include "hostname-util.h"
|
||||
#include "networkd-dns.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-network.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-table.h"
|
||||
|
||||
UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto) {
|
||||
UseDomains n, c, m;
|
||||
|
||||
assert(link);
|
||||
assert(link->manager);
|
||||
|
||||
if (!link->network)
|
||||
return USE_DOMAINS_NO;
|
||||
|
||||
switch (proto) {
|
||||
case NETWORK_CONFIG_SOURCE_DHCP4:
|
||||
n = link->network->dhcp_use_domains;
|
||||
c = link->network->compat_dhcp_use_domains;
|
||||
m = link->manager->dhcp_use_domains;
|
||||
break;
|
||||
case NETWORK_CONFIG_SOURCE_DHCP6:
|
||||
n = link->network->dhcp6_use_domains;
|
||||
c = link->network->compat_dhcp_use_domains;
|
||||
m = link->manager->dhcp6_use_domains;
|
||||
break;
|
||||
case NETWORK_CONFIG_SOURCE_NDISC:
|
||||
n = link->network->ndisc_use_domains;
|
||||
c = _USE_DOMAINS_INVALID;
|
||||
m = _USE_DOMAINS_INVALID;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
/* If per-network and per-protocol setting is specified, use it. */
|
||||
if (n >= 0)
|
||||
return n;
|
||||
|
||||
/* If compat setting is specified, use it. */
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
/* If global per-protocol setting is specified, use it. */
|
||||
if (m >= 0)
|
||||
return m;
|
||||
|
||||
/* Otherwise, defaults to no. */
|
||||
return USE_DOMAINS_NO;
|
||||
}
|
||||
|
||||
bool link_get_use_dns(Link *link, NetworkConfigSource proto) {
|
||||
int n, c;
|
||||
|
||||
assert(link);
|
||||
|
||||
if (!link->network)
|
||||
return false;
|
||||
|
||||
switch (proto) {
|
||||
case NETWORK_CONFIG_SOURCE_DHCP4:
|
||||
n = link->network->dhcp_use_dns;
|
||||
c = link->network->compat_dhcp_use_dns;
|
||||
break;
|
||||
case NETWORK_CONFIG_SOURCE_DHCP6:
|
||||
n = link->network->dhcp6_use_dns;
|
||||
c = link->network->compat_dhcp_use_dns;
|
||||
break;
|
||||
case NETWORK_CONFIG_SOURCE_NDISC:
|
||||
n = link->network->ndisc_use_dns;
|
||||
c = -1;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
/* If per-network and per-protocol setting is specified, use it. */
|
||||
if (n >= 0)
|
||||
return n;
|
||||
|
||||
/* If compat setting is specified, use it. */
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
/* Otherwise, defaults to yes. */
|
||||
return true;
|
||||
}
|
||||
|
||||
int config_parse_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) {
|
||||
|
||||
Network *n = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
n->search_domains = ordered_set_free(n->search_domains);
|
||||
n->route_domains = ordered_set_free(n->route_domains);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL, *normalized = NULL;
|
||||
const char *domain;
|
||||
bool is_route;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to extract search or route domain, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
is_route = w[0] == '~';
|
||||
domain = is_route ? w + 1 : w;
|
||||
|
||||
if (dns_name_is_root(domain) || streq(domain, "*")) {
|
||||
/* If the root domain appears as is, or the special token "*" is found, we'll
|
||||
* consider this as routing domain, unconditionally. */
|
||||
is_route = true;
|
||||
domain = "."; /* make sure we don't allow empty strings, thus write the root
|
||||
* domain as "." */
|
||||
} else {
|
||||
r = dns_name_normalize(domain, 0, &normalized);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"'%s' is not a valid domain name, ignoring.", domain);
|
||||
continue;
|
||||
}
|
||||
|
||||
domain = normalized;
|
||||
|
||||
if (is_localhost(domain)) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"'localhost' domain may not be configured as search or route domain, ignoring assignment: %s",
|
||||
domain);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
OrderedSet **set = is_route ? &n->route_domains : &n->search_domains;
|
||||
r = ordered_set_put_strdup(set, domain);
|
||||
if (r == -EEXIST)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_dns(
|
||||
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) {
|
||||
|
||||
Network *n = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
for (unsigned i = 0; i < n->n_dns; i++)
|
||||
in_addr_full_free(n->dns[i]);
|
||||
n->dns = mfree(n->dns);
|
||||
n->n_dns = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_(in_addr_full_freep) struct in_addr_full *dns = NULL;
|
||||
_cleanup_free_ char *w = NULL;
|
||||
struct in_addr_full **m;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid syntax, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
r = in_addr_full_new_from_string(w, &dns);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse dns server address, ignoring: %s", w);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IN_SET(dns->port, 53, 853))
|
||||
dns->port = 0;
|
||||
|
||||
m = reallocarray(n->dns, n->n_dns + 1, sizeof(struct in_addr_full*));
|
||||
if (!m)
|
||||
return log_oom();
|
||||
|
||||
m[n->n_dns++] = TAKE_PTR(dns);
|
||||
n->dns = m;
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_dnssec_negative_trust_anchors(
|
||||
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) {
|
||||
|
||||
Set **nta = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*nta = set_free_free(*nta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to extract negative trust anchor domain, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
r = dns_name_is_valid(w);
|
||||
if (r <= 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"%s is not a valid domain name, ignoring.", w);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = set_ensure_consume(nta, &dns_name_hash_ops, TAKE_PTR(w));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
static const char* const use_domains_table[_USE_DOMAINS_MAX] = {
|
||||
[USE_DOMAINS_NO] = "no",
|
||||
[USE_DOMAINS_ROUTE] = "route",
|
||||
[USE_DOMAINS_YES] = "yes",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(use_domains, UseDomains, USE_DOMAINS_YES);
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_use_domains, use_domains, UseDomains, "Failed to parse UseDomains=")
|
28
src/network/networkd-dns.h
Normal file
28
src/network/networkd-dns.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "macro.h"
|
||||
#include "networkd-util.h"
|
||||
|
||||
typedef struct Link Link;
|
||||
|
||||
typedef enum UseDomains {
|
||||
USE_DOMAINS_NO,
|
||||
USE_DOMAINS_YES,
|
||||
USE_DOMAINS_ROUTE,
|
||||
_USE_DOMAINS_MAX,
|
||||
_USE_DOMAINS_INVALID = -EINVAL,
|
||||
} UseDomains;
|
||||
|
||||
UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto);
|
||||
bool link_get_use_dns(Link *link, NetworkConfigSource proto);
|
||||
|
||||
const char* use_domains_to_string(UseDomains p) _const_;
|
||||
UseDomains use_domains_from_string(const char *s) _pure_;
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_domains);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dns);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_use_domains);
|
@ -7,6 +7,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
|
||||
#include "conf-parser.h"
|
||||
#include "networkd-conf.h"
|
||||
#include "networkd-dhcp-common.h"
|
||||
#include "networkd-dns.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-route-util.h"
|
||||
%}
|
||||
@ -30,10 +31,10 @@ Network.RouteTable, config_parse_route_table_names,
|
||||
Network.IPv4Forwarding, config_parse_tristate, 0, offsetof(Manager, ip_forwarding[0])
|
||||
Network.IPv6Forwarding, config_parse_tristate, 0, offsetof(Manager, ip_forwarding[1])
|
||||
Network.IPv6PrivacyExtensions, config_parse_ipv6_privacy_extensions, 0, offsetof(Manager, ipv6_privacy_extensions)
|
||||
DHCPv4.UseDomains, config_parse_default_dhcp_use_domains, 0, offsetof(Manager, dhcp_use_domains)
|
||||
DHCPv4.UseDomains, config_parse_use_domains, 0, offsetof(Manager, dhcp_use_domains)
|
||||
DHCPv4.DUIDType, config_parse_duid_type, 0, offsetof(Manager, dhcp_duid)
|
||||
DHCPv4.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, dhcp_duid)
|
||||
DHCPv6.UseDomains, config_parse_default_dhcp_use_domains, 0, offsetof(Manager, dhcp6_use_domains)
|
||||
DHCPv6.UseDomains, config_parse_use_domains, 0, offsetof(Manager, dhcp6_use_domains)
|
||||
DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Manager, dhcp6_duid)
|
||||
DHCPv6.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, dhcp6_duid)
|
||||
DHCPServer.PersistLeases, config_parse_bool, 0, offsetof(Manager, dhcp_server_persist_leases)
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "networkd-neighbor.h"
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-nexthop.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "networkd-route-util.h"
|
||||
#include "networkd-route.h"
|
||||
#include "networkd-routing-policy-rule.h"
|
||||
@ -448,7 +449,7 @@ static int dns_append_json(Link *link, JsonVariant **v) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (link->dhcp_lease && link->network->dhcp_use_dns) {
|
||||
if (link->dhcp_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
|
||||
const struct in_addr *dns;
|
||||
union in_addr_union s;
|
||||
int n_dns;
|
||||
@ -469,7 +470,7 @@ static int dns_append_json(Link *link, JsonVariant **v) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease && link->network->dhcp6_use_dns) {
|
||||
if (link->dhcp6_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
|
||||
const struct in6_addr *dns;
|
||||
union in_addr_union s;
|
||||
int n_dns;
|
||||
@ -490,7 +491,7 @@ static int dns_append_json(Link *link, JsonVariant **v) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->network->ndisc_use_dns) {
|
||||
if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) {
|
||||
NDiscRDNSS *a;
|
||||
|
||||
SET_FOREACH(a, link->ndisc_rdnss) {
|
||||
@ -564,7 +565,7 @@ static int ntp_append_json(Link *link, JsonVariant **v) {
|
||||
}
|
||||
|
||||
if (!link->ntp) {
|
||||
if (link->dhcp_lease && link->network->dhcp_use_ntp) {
|
||||
if (link->dhcp_lease && link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
|
||||
const struct in_addr *ntp;
|
||||
union in_addr_union s;
|
||||
int n_ntp;
|
||||
@ -585,7 +586,7 @@ static int ntp_append_json(Link *link, JsonVariant **v) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease && link->network->dhcp6_use_ntp) {
|
||||
if (link->dhcp6_lease && link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
|
||||
const struct in6_addr *ntp_addr;
|
||||
union in_addr_union s;
|
||||
char **ntp_fqdn;
|
||||
@ -671,7 +672,7 @@ static int domain_append_json(int family, const char *domain, NetworkConfigSourc
|
||||
static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
OrderedSet *link_domains, *network_domains;
|
||||
DHCPUseDomains use_domains;
|
||||
UseDomains use_domains;
|
||||
union in_addr_union s;
|
||||
char **domains;
|
||||
const char *domain;
|
||||
@ -685,7 +686,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
|
||||
link_domains = is_route ? link->route_domains : link->search_domains;
|
||||
network_domains = is_route ? link->network->route_domains : link->network->search_domains;
|
||||
use_domains = is_route ? DHCP_USE_DOMAINS_ROUTE : DHCP_USE_DOMAINS_YES;
|
||||
use_domains = is_route ? USE_DOMAINS_ROUTE : USE_DOMAINS_YES;
|
||||
|
||||
ORDERED_SET_FOREACH(domain, link_domains ?: network_domains) {
|
||||
r = domain_append_json(AF_UNSPEC, domain,
|
||||
@ -697,7 +698,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
|
||||
if (!link_domains) {
|
||||
if (link->dhcp_lease &&
|
||||
link->network->dhcp_use_domains == use_domains) {
|
||||
link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP4) == use_domains) {
|
||||
r = sd_dhcp_lease_get_server_identifier(link->dhcp_lease, &s.in);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -717,7 +718,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease &&
|
||||
link->network->dhcp6_use_domains == use_domains) {
|
||||
link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP6) == use_domains) {
|
||||
r = sd_dhcp6_lease_get_server_address(link->dhcp6_lease, &s.in6);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -730,7 +731,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->network->ndisc_use_domains == use_domains) {
|
||||
if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_NDISC) == use_domains) {
|
||||
NDiscDNSSL *a;
|
||||
|
||||
SET_FOREACH(a, link->ndisc_dnssl) {
|
||||
|
@ -599,6 +599,8 @@ int manager_new(Manager **ret, bool test_mode) {
|
||||
.manage_foreign_nexthops = true,
|
||||
.ethtool_fd = -EBADF,
|
||||
.persistent_storage_fd = persistent_storage_open(),
|
||||
.dhcp_use_domains = _USE_DOMAINS_INVALID,
|
||||
.dhcp6_use_domains = _USE_DOMAINS_INVALID,
|
||||
.dhcp_duid.type = DUID_TYPE_EN,
|
||||
.dhcp6_duid.type = DUID_TYPE_EN,
|
||||
.duid_product_uuid.type = DUID_TYPE_UUID,
|
||||
|
@ -64,8 +64,8 @@ struct Manager {
|
||||
OrderedSet *address_pools;
|
||||
Set *dhcp_pd_subnet_ids;
|
||||
|
||||
DHCPUseDomains dhcp_use_domains;
|
||||
DHCPUseDomains dhcp6_use_domains;
|
||||
UseDomains dhcp_use_domains;
|
||||
UseDomains dhcp6_use_domains;
|
||||
|
||||
DUID dhcp_duid;
|
||||
DUID dhcp6_duid;
|
||||
|
@ -1409,7 +1409,7 @@ static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) {
|
||||
assert(link->network);
|
||||
assert(rt);
|
||||
|
||||
if (!link->network->ndisc_use_dns)
|
||||
if (!link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC))
|
||||
return 0;
|
||||
|
||||
r = sd_ndisc_router_get_sender_address(rt, &router);
|
||||
@ -1501,7 +1501,7 @@ static int ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) {
|
||||
assert(link->network);
|
||||
assert(rt);
|
||||
|
||||
if (link->network->ndisc_use_domains == DHCP_USE_DOMAINS_NO)
|
||||
if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_NDISC) <= 0)
|
||||
return 0;
|
||||
|
||||
r = sd_ndisc_router_get_sender_address(rt, &router);
|
||||
@ -2483,7 +2483,5 @@ static const char* const ndisc_start_dhcp6_client_table[_IPV6_ACCEPT_RA_START_DH
|
||||
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client, IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES);
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_ndisc_use_domains, dhcp_use_domains, DHCPUseDomains,
|
||||
"Failed to parse UseDomains= setting");
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_ndisc_start_dhcp6_client, ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client,
|
||||
"Failed to parse DHCPv6Client= setting");
|
||||
|
@ -65,4 +65,3 @@ int link_request_ndisc(Link *link);
|
||||
int ndisc_reconfigure_address(Address *address, Link *link);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ndisc_start_dhcp6_client);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ndisc_use_domains);
|
||||
|
@ -20,6 +20,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
|
||||
#include "networkd-dhcp-server.h"
|
||||
#include "networkd-dhcp4.h"
|
||||
#include "networkd-dhcp6.h"
|
||||
#include "networkd-dns.h"
|
||||
#include "networkd-ipv4ll.h"
|
||||
#include "networkd-ipv6-proxy-ndp.h"
|
||||
#include "networkd-ipv6ll.h"
|
||||
@ -29,6 +30,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-neighbor.h"
|
||||
#include "networkd-nexthop.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "networkd-radv.h"
|
||||
#include "networkd-route.h"
|
||||
#include "networkd-routing-policy-rule.h"
|
||||
@ -221,15 +223,15 @@ NextHop.Blackhole, config_parse_nexthop_blackhole,
|
||||
NextHop.Group, config_parse_nexthop_group, 0, 0
|
||||
DHCPv4.RequestAddress, config_parse_in_addr_non_null, AF_INET, offsetof(Network, dhcp_request_address)
|
||||
DHCPv4.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)
|
||||
DHCPv4.UseDNS, config_parse_dhcp_use_dns, AF_INET, 0
|
||||
DHCPv4.UseDNS, config_parse_tristate, 0, offsetof(Network, dhcp_use_dns)
|
||||
DHCPv4.RoutesToDNS, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_dns)
|
||||
DHCPv4.UseNTP, config_parse_dhcp_use_ntp, AF_INET, 0
|
||||
DHCPv4.UseNTP, config_parse_tristate, 0, offsetof(Network, dhcp_use_ntp)
|
||||
DHCPv4.RoutesToNTP, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_ntp)
|
||||
DHCPv4.UseSIP, config_parse_bool, 0, offsetof(Network, dhcp_use_sip)
|
||||
DHCPv4.UseCaptivePortal, config_parse_bool, 0, offsetof(Network, dhcp_use_captive_portal)
|
||||
DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_use_mtu)
|
||||
DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname)
|
||||
DHCPv4.UseDomains, config_parse_dhcp_use_domains, AF_INET, 0
|
||||
DHCPv4.UseDomains, config_parse_use_domains, 0, offsetof(Network, dhcp_use_domains)
|
||||
DHCPv4.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
|
||||
DHCPv4.UseGateway, config_parse_tristate, 0, offsetof(Network, dhcp_use_gateway)
|
||||
DHCPv4.QuickAck, config_parse_bool, 0, offsetof(Network, dhcp_quickack)
|
||||
@ -270,10 +272,10 @@ DHCPv4.NFTSet, config_parse_nft_set,
|
||||
DHCPv4.RapidCommit, config_parse_tristate, 0, offsetof(Network, dhcp_use_rapid_commit)
|
||||
DHCPv6.UseAddress, config_parse_bool, 0, offsetof(Network, dhcp6_use_address)
|
||||
DHCPv6.UseDelegatedPrefix, config_parse_bool, 0, offsetof(Network, dhcp6_use_pd_prefix)
|
||||
DHCPv6.UseDNS, config_parse_dhcp_use_dns, AF_INET6, 0
|
||||
DHCPv6.UseDNS, config_parse_tristate, 0, offsetof(Network, dhcp6_use_dns)
|
||||
DHCPv6.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp6_use_hostname)
|
||||
DHCPv6.UseDomains, config_parse_dhcp_use_domains, AF_INET6, 0
|
||||
DHCPv6.UseNTP, config_parse_dhcp_use_ntp, AF_INET6, 0
|
||||
DHCPv6.UseDomains, config_parse_use_domains, 0, offsetof(Network, dhcp6_use_domains)
|
||||
DHCPv6.UseNTP, config_parse_tristate, 0, offsetof(Network, dhcp6_use_ntp)
|
||||
DHCPv6.UseCaptivePortal, config_parse_bool, 0, offsetof(Network, dhcp6_use_captive_portal)
|
||||
DHCPv6.MUDURL, config_parse_mud_url, 0, offsetof(Network, dhcp6_mudurl)
|
||||
DHCPv6.SendHostname, config_parse_dhcp_send_hostname, AF_INET6, 0
|
||||
@ -298,8 +300,8 @@ IPv6AcceptRA.UseRoutePrefix, config_parse_bool,
|
||||
IPv6AcceptRA.UseAutonomousPrefix, config_parse_bool, 0, offsetof(Network, ndisc_use_autonomous_prefix)
|
||||
IPv6AcceptRA.UseOnLinkPrefix, config_parse_bool, 0, offsetof(Network, ndisc_use_onlink_prefix)
|
||||
IPv6AcceptRA.UsePREF64, config_parse_bool, 0, offsetof(Network, ndisc_use_pref64)
|
||||
IPv6AcceptRA.UseDNS, config_parse_bool, 0, offsetof(Network, ndisc_use_dns)
|
||||
IPv6AcceptRA.UseDomains, config_parse_ndisc_use_domains, 0, offsetof(Network, ndisc_use_domains)
|
||||
IPv6AcceptRA.UseDNS, config_parse_tristate, 0, offsetof(Network, ndisc_use_dns)
|
||||
IPv6AcceptRA.UseDomains, config_parse_use_domains, 0, offsetof(Network, ndisc_use_domains)
|
||||
IPv6AcceptRA.UseMTU, config_parse_bool, 0, offsetof(Network, ndisc_use_mtu)
|
||||
IPv6AcceptRA.UseHopLimit, config_parse_bool, 0, offsetof(Network, ndisc_use_hop_limit)
|
||||
IPv6AcceptRA.UseReachableTime, config_parse_bool, 0, offsetof(Network, ndisc_use_reachable_time)
|
||||
@ -587,12 +589,12 @@ IPv6PrefixDelegation.Domains, config_parse_radv_search_domains,
|
||||
IPv6PrefixDelegation.DNSLifetimeSec, config_parse_sec, 0, offsetof(Network, router_dns_lifetime_usec)
|
||||
DHCPv4.BlackList, config_parse_in_addr_prefixes, AF_INET, offsetof(Network, dhcp_deny_listed_ip)
|
||||
DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)
|
||||
DHCP.UseDNS, config_parse_dhcp_use_dns, AF_UNSPEC, 0
|
||||
DHCP.UseNTP, config_parse_dhcp_use_ntp, AF_UNSPEC, 0
|
||||
DHCP.UseDNS, config_parse_tristate, 0, offsetof(Network, compat_dhcp_use_dns)
|
||||
DHCP.UseNTP, config_parse_tristate, 0, offsetof(Network, compat_dhcp_use_ntp)
|
||||
DHCP.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_use_mtu)
|
||||
DHCP.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname)
|
||||
DHCP.UseDomains, config_parse_dhcp_use_domains, AF_UNSPEC, 0
|
||||
DHCP.UseDomainName, config_parse_dhcp_use_domains, AF_UNSPEC, 0
|
||||
DHCP.UseDomains, config_parse_use_domains, 0, offsetof(Network, compat_dhcp_use_domains)
|
||||
DHCP.UseDomainName, config_parse_use_domains, 0, offsetof(Network, compat_dhcp_use_domains)
|
||||
DHCP.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
|
||||
DHCP.Anonymize, config_parse_bool, 0, offsetof(Network, dhcp_anonymize)
|
||||
DHCP.SendHostname, config_parse_dhcp_send_hostname, AF_UNSPEC, 0
|
||||
@ -610,7 +612,7 @@ DHCP.UseTimezone, config_parse_bool,
|
||||
DHCP.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port)
|
||||
DHCP.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_use_rapid_commit)
|
||||
DHCP.ForceDHCPv6PDOtherInformation, config_parse_warn_compat, DISABLED_LEGACY, 0
|
||||
DHCPv4.UseDomainName, config_parse_dhcp_use_domains, AF_INET, 0
|
||||
DHCPv4.UseDomainName, config_parse_use_domains, 0, offsetof(Network, dhcp_use_domains)
|
||||
DHCPv4.CriticalConnection, config_parse_tristate, 0, offsetof(Network, dhcp_critical)
|
||||
DHCPv6.RouteMetric, config_parse_ndisc_route_metric, AF_INET6, 0
|
||||
DHCPv6.ForceDHCPv6PDOtherInformation, config_parse_warn_compat, DISABLED_LEGACY, 0
|
||||
|
@ -43,9 +43,6 @@
|
||||
#include "strv.h"
|
||||
#include "tclass.h"
|
||||
|
||||
/* Let's assume that anything above this number is a user misconfiguration. */
|
||||
#define MAX_NTP_SERVERS 128U
|
||||
|
||||
static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret) {
|
||||
const char *kind_string;
|
||||
NetDev *netdev;
|
||||
@ -380,15 +377,19 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
|
||||
|
||||
.keep_configuration = manager->keep_configuration,
|
||||
|
||||
.compat_dhcp_use_domains = _USE_DOMAINS_INVALID,
|
||||
.compat_dhcp_use_dns = -1,
|
||||
.compat_dhcp_use_ntp = -1,
|
||||
|
||||
.dhcp_duid.type = _DUID_TYPE_INVALID,
|
||||
.dhcp_critical = -1,
|
||||
.dhcp_use_ntp = true,
|
||||
.dhcp_use_ntp = -1,
|
||||
.dhcp_routes_to_ntp = true,
|
||||
.dhcp_use_sip = true,
|
||||
.dhcp_use_captive_portal = true,
|
||||
.dhcp_use_dns = true,
|
||||
.dhcp_use_dns = -1,
|
||||
.dhcp_routes_to_dns = true,
|
||||
.dhcp_use_domains = manager->dhcp_use_domains,
|
||||
.dhcp_use_domains = _USE_DOMAINS_INVALID,
|
||||
.dhcp_use_hostname = true,
|
||||
.dhcp_use_routes = true,
|
||||
.dhcp_use_gateway = -1,
|
||||
@ -404,10 +405,10 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
|
||||
|
||||
.dhcp6_use_address = true,
|
||||
.dhcp6_use_pd_prefix = true,
|
||||
.dhcp6_use_dns = true,
|
||||
.dhcp6_use_domains = manager->dhcp6_use_domains,
|
||||
.dhcp6_use_dns = -1,
|
||||
.dhcp6_use_domains = _USE_DOMAINS_INVALID,
|
||||
.dhcp6_use_hostname = true,
|
||||
.dhcp6_use_ntp = true,
|
||||
.dhcp6_use_ntp = -1,
|
||||
.dhcp6_use_captive_portal = true,
|
||||
.dhcp6_use_rapid_commit = true,
|
||||
.dhcp6_send_hostname = true,
|
||||
@ -478,7 +479,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
|
||||
|
||||
.ndisc = -1,
|
||||
.ndisc_use_redirect = true,
|
||||
.ndisc_use_dns = true,
|
||||
.ndisc_use_dns = -1,
|
||||
.ndisc_use_gateway = true,
|
||||
.ndisc_use_captive_portal = true,
|
||||
.ndisc_use_route_prefix = true,
|
||||
@ -922,288 +923,6 @@ int config_parse_stacked_netdev(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_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) {
|
||||
|
||||
Network *n = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
n->search_domains = ordered_set_free(n->search_domains);
|
||||
n->route_domains = ordered_set_free(n->route_domains);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL, *normalized = NULL;
|
||||
const char *domain;
|
||||
bool is_route;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to extract search or route domain, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
is_route = w[0] == '~';
|
||||
domain = is_route ? w + 1 : w;
|
||||
|
||||
if (dns_name_is_root(domain) || streq(domain, "*")) {
|
||||
/* If the root domain appears as is, or the special token "*" is found, we'll
|
||||
* consider this as routing domain, unconditionally. */
|
||||
is_route = true;
|
||||
domain = "."; /* make sure we don't allow empty strings, thus write the root
|
||||
* domain as "." */
|
||||
} else {
|
||||
r = dns_name_normalize(domain, 0, &normalized);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"'%s' is not a valid domain name, ignoring.", domain);
|
||||
continue;
|
||||
}
|
||||
|
||||
domain = normalized;
|
||||
|
||||
if (is_localhost(domain)) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"'localhost' domain may not be configured as search or route domain, ignoring assignment: %s",
|
||||
domain);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
OrderedSet **set = is_route ? &n->route_domains : &n->search_domains;
|
||||
r = ordered_set_put_strdup(set, domain);
|
||||
if (r == -EEXIST)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_timezone(
|
||||
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) {
|
||||
|
||||
char **tz = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*tz = mfree(*tz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = verify_timezone(rvalue, LOG_WARNING);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Timezone is not valid, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_and_strdup_warn(tz, rvalue);
|
||||
}
|
||||
|
||||
int config_parse_dns(
|
||||
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) {
|
||||
|
||||
Network *n = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
for (unsigned i = 0; i < n->n_dns; i++)
|
||||
in_addr_full_free(n->dns[i]);
|
||||
n->dns = mfree(n->dns);
|
||||
n->n_dns = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_(in_addr_full_freep) struct in_addr_full *dns = NULL;
|
||||
_cleanup_free_ char *w = NULL;
|
||||
struct in_addr_full **m;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid syntax, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
r = in_addr_full_new_from_string(w, &dns);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse dns server address, ignoring: %s", w);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IN_SET(dns->port, 53, 853))
|
||||
dns->port = 0;
|
||||
|
||||
m = reallocarray(n->dns, n->n_dns + 1, sizeof(struct in_addr_full*));
|
||||
if (!m)
|
||||
return log_oom();
|
||||
|
||||
m[n->n_dns++] = TAKE_PTR(dns);
|
||||
n->dns = m;
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_dnssec_negative_trust_anchors(
|
||||
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) {
|
||||
|
||||
Set **nta = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*nta = set_free_free(*nta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to extract negative trust anchor domain, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
r = dns_name_is_valid(w);
|
||||
if (r <= 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"%s is not a valid domain name, ignoring.", w);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = set_ensure_consume(nta, &dns_name_hash_ops, TAKE_PTR(w));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_ntp(
|
||||
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) {
|
||||
|
||||
char ***l = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*l = strv_free(*l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to extract NTP server name, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
r = dns_name_is_valid_or_address(w);
|
||||
if (r <= 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"%s is not a valid domain name or IP address, ignoring.", w);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strv_length(*l) > MAX_NTP_SERVERS) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"More than %u NTP servers specified, ignoring \"%s\" and any subsequent entries.",
|
||||
MAX_NTP_SERVERS, w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = strv_consume(l, TAKE_PTR(w));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_required_for_online(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "networkd-dhcp-common.h"
|
||||
#include "networkd-dhcp4.h"
|
||||
#include "networkd-dhcp6.h"
|
||||
#include "networkd-dns.h"
|
||||
#include "networkd-ipv6ll.h"
|
||||
#include "networkd-lldp-rx.h"
|
||||
#include "networkd-ndisc.h"
|
||||
@ -112,6 +113,11 @@ struct Network {
|
||||
bool default_route_on_device;
|
||||
AddressFamily ip_masquerade;
|
||||
|
||||
/* For backward compatibility, only applied to DHCPv4 and DHCPv6. */
|
||||
UseDomains compat_dhcp_use_domains;
|
||||
int compat_dhcp_use_dns;
|
||||
int compat_dhcp_use_ntp;
|
||||
|
||||
/* DHCP Client Support */
|
||||
AddressFamily dhcp;
|
||||
struct in_addr dhcp_request_address;
|
||||
@ -143,11 +149,9 @@ struct Network {
|
||||
int dhcp_broadcast;
|
||||
int dhcp_ipv6_only_mode;
|
||||
int dhcp_use_rapid_commit;
|
||||
bool dhcp_use_dns;
|
||||
bool dhcp_use_dns_set;
|
||||
int dhcp_use_dns;
|
||||
bool dhcp_routes_to_dns;
|
||||
bool dhcp_use_ntp;
|
||||
bool dhcp_use_ntp_set;
|
||||
int dhcp_use_ntp;
|
||||
bool dhcp_routes_to_ntp;
|
||||
bool dhcp_use_sip;
|
||||
bool dhcp_use_captive_portal;
|
||||
@ -162,8 +166,7 @@ struct Network {
|
||||
bool dhcp_use_6rd;
|
||||
bool dhcp_send_release;
|
||||
bool dhcp_send_decline;
|
||||
DHCPUseDomains dhcp_use_domains;
|
||||
bool dhcp_use_domains_set;
|
||||
UseDomains dhcp_use_domains;
|
||||
Set *dhcp_deny_listed_ip;
|
||||
Set *dhcp_allow_listed_ip;
|
||||
Set *dhcp_request_options;
|
||||
@ -177,15 +180,12 @@ struct Network {
|
||||
bool dhcp6_use_pd_prefix;
|
||||
bool dhcp6_send_hostname;
|
||||
bool dhcp6_send_hostname_set;
|
||||
bool dhcp6_use_dns;
|
||||
bool dhcp6_use_dns_set;
|
||||
int dhcp6_use_dns;
|
||||
bool dhcp6_use_hostname;
|
||||
bool dhcp6_use_ntp;
|
||||
bool dhcp6_use_ntp_set;
|
||||
int dhcp6_use_ntp;
|
||||
bool dhcp6_use_captive_portal;
|
||||
bool dhcp6_use_rapid_commit;
|
||||
DHCPUseDomains dhcp6_use_domains;
|
||||
bool dhcp6_use_domains_set;
|
||||
UseDomains dhcp6_use_domains;
|
||||
uint32_t dhcp6_iaid;
|
||||
bool dhcp6_iaid_set;
|
||||
bool dhcp6_iaid_set_explicitly;
|
||||
@ -338,7 +338,7 @@ struct Network {
|
||||
/* NDisc support */
|
||||
int ndisc;
|
||||
bool ndisc_use_redirect;
|
||||
bool ndisc_use_dns;
|
||||
int ndisc_use_dns;
|
||||
bool ndisc_use_gateway;
|
||||
bool ndisc_use_route_prefix;
|
||||
bool ndisc_use_autonomous_prefix;
|
||||
@ -352,7 +352,7 @@ struct Network {
|
||||
bool ndisc_use_pref64;
|
||||
bool active_slave;
|
||||
bool primary_slave;
|
||||
DHCPUseDomains ndisc_use_domains;
|
||||
UseDomains ndisc_use_domains;
|
||||
IPv6AcceptRAStartDHCP6Client ndisc_start_dhcp6_client;
|
||||
uint32_t ndisc_route_table;
|
||||
bool ndisc_route_table_set;
|
||||
@ -424,11 +424,6 @@ bool network_has_static_ipv6_configurations(Network *network);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_domains);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dns);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
|
||||
|
101
src/network/networkd-ntp.c
Normal file
101
src/network/networkd-ntp.c
Normal file
@ -0,0 +1,101 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "dns-domain.h"
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "parse-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
/* Let's assume that anything above this number is a user misconfiguration. */
|
||||
#define MAX_NTP_SERVERS 128U
|
||||
|
||||
bool link_get_use_ntp(Link *link, NetworkConfigSource proto) {
|
||||
int n, c;
|
||||
|
||||
assert(link);
|
||||
|
||||
if (!link->network)
|
||||
return false;
|
||||
|
||||
switch (proto) {
|
||||
case NETWORK_CONFIG_SOURCE_DHCP4:
|
||||
n = link->network->dhcp_use_ntp;
|
||||
c = link->network->compat_dhcp_use_ntp;
|
||||
break;
|
||||
case NETWORK_CONFIG_SOURCE_DHCP6:
|
||||
n = link->network->dhcp6_use_ntp;
|
||||
c = link->network->compat_dhcp_use_ntp;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
/* If per-network and per-protocol setting is specified, use it. */
|
||||
if (n >= 0)
|
||||
return n;
|
||||
|
||||
/* If compat setting is specified, use it. */
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
/* Otherwise, defaults to yes. */
|
||||
return true;
|
||||
}
|
||||
|
||||
int config_parse_ntp(
|
||||
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) {
|
||||
|
||||
char ***l = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*l = strv_free(*l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, 0);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to extract NTP server name, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
r = dns_name_is_valid_or_address(w);
|
||||
if (r <= 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"%s is not a valid domain name or IP address, ignoring.", w);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strv_length(*l) > MAX_NTP_SERVERS) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"More than %u NTP servers specified, ignoring \"%s\" and any subsequent entries.",
|
||||
MAX_NTP_SERVERS, w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = strv_consume(l, TAKE_PTR(w));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
11
src/network/networkd-ntp.h
Normal file
11
src/network/networkd-ntp.h
Normal file
@ -0,0 +1,11 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "networkd-util.h"
|
||||
|
||||
typedef struct Link Link;
|
||||
|
||||
bool link_get_use_ntp(Link *link, NetworkConfigSource proto);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
|
@ -15,6 +15,7 @@
|
||||
#include "networkd-manager-bus.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-ntp.h"
|
||||
#include "networkd-state-file.h"
|
||||
#include "ordered-set.h"
|
||||
#include "set.h"
|
||||
@ -101,7 +102,7 @@ static int link_put_dns(Link *link, OrderedSet **s) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (link->dhcp_lease && link->network->dhcp_use_dns) {
|
||||
if (link->dhcp_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
|
||||
const struct in_addr *addresses;
|
||||
|
||||
r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses);
|
||||
@ -112,7 +113,7 @@ static int link_put_dns(Link *link, OrderedSet **s) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease && link->network->dhcp6_use_dns) {
|
||||
if (link->dhcp6_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
|
||||
const struct in6_addr *addresses;
|
||||
|
||||
r = sd_dhcp6_lease_get_dns(link->dhcp6_lease, &addresses);
|
||||
@ -123,7 +124,7 @@ static int link_put_dns(Link *link, OrderedSet **s) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->network->ndisc_use_dns) {
|
||||
if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) {
|
||||
NDiscRDNSS *a;
|
||||
|
||||
SET_FOREACH(a, link->ndisc_rdnss) {
|
||||
@ -150,7 +151,7 @@ static int link_put_ntp(Link *link, OrderedSet **s) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (link->dhcp_lease && link->network->dhcp_use_ntp) {
|
||||
if (link->dhcp_lease && link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
|
||||
const struct in_addr *addresses;
|
||||
|
||||
r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &addresses);
|
||||
@ -161,7 +162,7 @@ static int link_put_ntp(Link *link, OrderedSet **s) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease && link->network->dhcp6_use_ntp) {
|
||||
if (link->dhcp6_lease && link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
|
||||
const struct in6_addr *addresses;
|
||||
char **fqdn;
|
||||
|
||||
@ -206,7 +207,7 @@ static int link_put_sip(Link *link, OrderedSet **s) {
|
||||
|
||||
static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
|
||||
OrderedSet *link_domains, *network_domains;
|
||||
DHCPUseDomains use_domains;
|
||||
UseDomains use_domains;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -215,7 +216,7 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
|
||||
|
||||
link_domains = is_route ? link->route_domains : link->search_domains;
|
||||
network_domains = is_route ? link->network->route_domains : link->network->search_domains;
|
||||
use_domains = is_route ? DHCP_USE_DOMAINS_ROUTE : DHCP_USE_DOMAINS_YES;
|
||||
use_domains = is_route ? USE_DOMAINS_ROUTE : USE_DOMAINS_YES;
|
||||
|
||||
if (link_domains)
|
||||
return ordered_set_put_string_set(s, link_domains);
|
||||
@ -224,7 +225,7 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (link->dhcp_lease && link->network->dhcp_use_domains == use_domains) {
|
||||
if (link->dhcp_lease && link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP4) == use_domains) {
|
||||
const char *domainname;
|
||||
char **domains;
|
||||
|
||||
@ -243,7 +244,7 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease && link->network->dhcp6_use_domains == use_domains) {
|
||||
if (link->dhcp6_lease && link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP6) == use_domains) {
|
||||
char **domains;
|
||||
|
||||
r = sd_dhcp6_lease_get_domains(link->dhcp6_lease, &domains);
|
||||
@ -254,7 +255,7 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
|
||||
}
|
||||
}
|
||||
|
||||
if (link->network->ndisc_use_domains == use_domains) {
|
||||
if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_NDISC) == use_domains) {
|
||||
NDiscDNSSL *a;
|
||||
|
||||
SET_FOREACH(a, link->ndisc_dnssl) {
|
||||
@ -528,7 +529,7 @@ static void serialize_addresses(
|
||||
fputc('\n', f);
|
||||
}
|
||||
|
||||
static void link_save_domains(Link *link, FILE *f, OrderedSet *static_domains, DHCPUseDomains use_domains) {
|
||||
static void link_save_domains(Link *link, FILE *f, OrderedSet *static_domains, UseDomains use_domains) {
|
||||
bool space = false;
|
||||
const char *p;
|
||||
|
||||
@ -539,10 +540,10 @@ static void link_save_domains(Link *link, FILE *f, OrderedSet *static_domains, D
|
||||
ORDERED_SET_FOREACH(p, static_domains)
|
||||
fputs_with_separator(f, p, NULL, &space);
|
||||
|
||||
if (use_domains == DHCP_USE_DOMAINS_NO)
|
||||
if (use_domains == USE_DOMAINS_NO)
|
||||
return;
|
||||
|
||||
if (link->dhcp_lease && link->network->dhcp_use_domains == use_domains) {
|
||||
if (link->dhcp_lease && link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP4) == use_domains) {
|
||||
const char *domainname;
|
||||
char **domains;
|
||||
|
||||
@ -552,14 +553,14 @@ static void link_save_domains(Link *link, FILE *f, OrderedSet *static_domains, D
|
||||
fputstrv(f, domains, NULL, &space);
|
||||
}
|
||||
|
||||
if (link->dhcp6_lease && link->network->dhcp6_use_domains == use_domains) {
|
||||
if (link->dhcp6_lease && link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP6) == use_domains) {
|
||||
char **domains;
|
||||
|
||||
if (sd_dhcp6_lease_get_domains(link->dhcp6_lease, &domains) >= 0)
|
||||
fputstrv(f, domains, NULL, &space);
|
||||
}
|
||||
|
||||
if (link->network->ndisc_use_domains == use_domains) {
|
||||
if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_NDISC) == use_domains) {
|
||||
NDiscDNSSL *dd;
|
||||
|
||||
SET_FOREACH(dd, link->ndisc_dnssl)
|
||||
@ -666,14 +667,14 @@ static int link_save(Link *link) {
|
||||
serialize_addresses(f, NULL, &space,
|
||||
NULL,
|
||||
link->dhcp_lease,
|
||||
link->network->dhcp_use_dns,
|
||||
link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4),
|
||||
SD_DHCP_LEASE_DNS,
|
||||
link->dhcp6_lease,
|
||||
link->network->dhcp6_use_dns,
|
||||
link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6),
|
||||
sd_dhcp6_lease_get_dns,
|
||||
NULL);
|
||||
|
||||
if (link->network->ndisc_use_dns) {
|
||||
if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) {
|
||||
NDiscRDNSS *dd;
|
||||
|
||||
SET_FOREACH(dd, link->ndisc_rdnss)
|
||||
@ -693,10 +694,10 @@ static int link_save(Link *link) {
|
||||
serialize_addresses(f, "NTP", NULL,
|
||||
link->network->ntp,
|
||||
link->dhcp_lease,
|
||||
link->network->dhcp_use_ntp,
|
||||
link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4),
|
||||
SD_DHCP_LEASE_NTP,
|
||||
link->dhcp6_lease,
|
||||
link->network->dhcp6_use_ntp,
|
||||
link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP6),
|
||||
sd_dhcp6_lease_get_ntp_addrs,
|
||||
sd_dhcp6_lease_get_ntp_fqdn);
|
||||
|
||||
@ -720,18 +721,18 @@ static int link_save(Link *link) {
|
||||
|
||||
fputs("DOMAINS=", f);
|
||||
if (link->search_domains)
|
||||
link_save_domains(link, f, link->search_domains, DHCP_USE_DOMAINS_NO);
|
||||
link_save_domains(link, f, link->search_domains, USE_DOMAINS_NO);
|
||||
else
|
||||
link_save_domains(link, f, link->network->search_domains, DHCP_USE_DOMAINS_YES);
|
||||
link_save_domains(link, f, link->network->search_domains, USE_DOMAINS_YES);
|
||||
fputc('\n', f);
|
||||
|
||||
/************************************************************/
|
||||
|
||||
fputs("ROUTE_DOMAINS=", f);
|
||||
if (link->route_domains)
|
||||
link_save_domains(link, f, link->route_domains, DHCP_USE_DOMAINS_NO);
|
||||
link_save_domains(link, f, link->route_domains, USE_DOMAINS_NO);
|
||||
else
|
||||
link_save_domains(link, f, link->network->route_domains, DHCP_USE_DOMAINS_ROUTE);
|
||||
link_save_domains(link, f, link->network->route_domains, USE_DOMAINS_ROUTE);
|
||||
fputc('\n', f);
|
||||
|
||||
/************************************************************/
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char **argv) {
|
||||
test_table(bond_xmit_hash_policy, NETDEV_BOND_XMIT_HASH_POLICY);
|
||||
test_table(dhcp6_message_status, DHCP6_STATUS);
|
||||
test_table_sparse(dhcp6_message_type, DHCP6_MESSAGE_TYPE); /* enum starts from 1 */
|
||||
test_table(dhcp_use_domains, DHCP_USE_DOMAINS);
|
||||
test_table(use_domains, USE_DOMAINS);
|
||||
test_table(duplex, DUP);
|
||||
test_table(ip6tnl_mode, NETDEV_IP6_TNL_MODE);
|
||||
test_table(ipv6_privacy_extensions, IPV6_PRIVACY_EXTENSIONS);
|
||||
|
@ -58,7 +58,7 @@ Exec.OOMScoreAdjust, config_parse_oom_score_adjust, 0,
|
||||
Exec.CPUAffinity, config_parse_cpu_affinity, 0, 0
|
||||
Exec.ResolvConf, config_parse_resolv_conf, 0, offsetof(Settings, resolv_conf)
|
||||
Exec.LinkJournal, config_parse_link_journal, 0, 0
|
||||
Exec.Timezone, config_parse_timezone, 0, offsetof(Settings, timezone)
|
||||
Exec.Timezone, config_parse_timezone_mode, 0, offsetof(Settings, timezone)
|
||||
Exec.SuppressSync, config_parse_tristate, 0, offsetof(Settings, suppress_sync)
|
||||
Files.ReadOnly, config_parse_tristate, 0, offsetof(Settings, read_only)
|
||||
Files.Volatile, config_parse_volatile_mode, 0, offsetof(Settings, volatile_mode)
|
||||
|
@ -835,21 +835,21 @@ int config_parse_cpu_affinity(
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_resolv_conf, resolv_conf_mode, ResolvConfMode, "Failed to parse resolv.conf mode");
|
||||
|
||||
static const char *const resolv_conf_mode_table[_RESOLV_CONF_MODE_MAX] = {
|
||||
[RESOLV_CONF_OFF] = "off",
|
||||
[RESOLV_CONF_COPY_HOST] = "copy-host",
|
||||
[RESOLV_CONF_COPY_STATIC] = "copy-static",
|
||||
[RESOLV_CONF_COPY_UPLINK] = "copy-uplink",
|
||||
[RESOLV_CONF_COPY_STUB] = "copy-stub",
|
||||
[RESOLV_CONF_REPLACE_HOST] = "replace-host",
|
||||
[RESOLV_CONF_OFF] = "off",
|
||||
[RESOLV_CONF_COPY_HOST] = "copy-host",
|
||||
[RESOLV_CONF_COPY_STATIC] = "copy-static",
|
||||
[RESOLV_CONF_COPY_UPLINK] = "copy-uplink",
|
||||
[RESOLV_CONF_COPY_STUB] = "copy-stub",
|
||||
[RESOLV_CONF_REPLACE_HOST] = "replace-host",
|
||||
[RESOLV_CONF_REPLACE_STATIC] = "replace-static",
|
||||
[RESOLV_CONF_REPLACE_UPLINK] = "replace-uplink",
|
||||
[RESOLV_CONF_REPLACE_STUB] = "replace-stub",
|
||||
[RESOLV_CONF_BIND_HOST] = "bind-host",
|
||||
[RESOLV_CONF_BIND_STATIC] = "bind-static",
|
||||
[RESOLV_CONF_BIND_UPLINK] = "bind-uplink",
|
||||
[RESOLV_CONF_BIND_STUB] = "bind-stub",
|
||||
[RESOLV_CONF_DELETE] = "delete",
|
||||
[RESOLV_CONF_AUTO] = "auto",
|
||||
[RESOLV_CONF_REPLACE_STUB] = "replace-stub",
|
||||
[RESOLV_CONF_BIND_HOST] = "bind-host",
|
||||
[RESOLV_CONF_BIND_STATIC] = "bind-static",
|
||||
[RESOLV_CONF_BIND_UPLINK] = "bind-uplink",
|
||||
[RESOLV_CONF_BIND_STUB] = "bind-stub",
|
||||
[RESOLV_CONF_DELETE] = "delete",
|
||||
[RESOLV_CONF_AUTO] = "auto",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(resolv_conf_mode, ResolvConfMode, RESOLV_CONF_AUTO);
|
||||
@ -914,15 +914,15 @@ int config_parse_link_journal(
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_timezone, timezone_mode, TimezoneMode, "Failed to parse timezone mode");
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_timezone_mode, timezone_mode, TimezoneMode, "Failed to parse timezone mode");
|
||||
|
||||
static const char *const timezone_mode_table[_TIMEZONE_MODE_MAX] = {
|
||||
[TIMEZONE_OFF] = "off",
|
||||
[TIMEZONE_COPY] = "copy",
|
||||
[TIMEZONE_BIND] = "bind",
|
||||
[TIMEZONE_OFF] = "off",
|
||||
[TIMEZONE_COPY] = "copy",
|
||||
[TIMEZONE_BIND] = "bind",
|
||||
[TIMEZONE_SYMLINK] = "symlink",
|
||||
[TIMEZONE_DELETE] = "delete",
|
||||
[TIMEZONE_AUTO] = "auto",
|
||||
[TIMEZONE_DELETE] = "delete",
|
||||
[TIMEZONE_AUTO] = "auto",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(timezone_mode, TimezoneMode, TIMEZONE_AUTO);
|
||||
@ -930,10 +930,10 @@ DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(timezone_mode, TimezoneMode, TIMEZONE_AU
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_userns_ownership, user_namespace_ownership, UserNamespaceOwnership, "Failed to parse user namespace ownership mode");
|
||||
|
||||
static const char *const user_namespace_ownership_table[_USER_NAMESPACE_OWNERSHIP_MAX] = {
|
||||
[USER_NAMESPACE_OWNERSHIP_OFF] = "off",
|
||||
[USER_NAMESPACE_OWNERSHIP_OFF] = "off",
|
||||
[USER_NAMESPACE_OWNERSHIP_CHOWN] = "chown",
|
||||
[USER_NAMESPACE_OWNERSHIP_MAP] = "map",
|
||||
[USER_NAMESPACE_OWNERSHIP_AUTO] = "auto",
|
||||
[USER_NAMESPACE_OWNERSHIP_MAP] = "map",
|
||||
[USER_NAMESPACE_OWNERSHIP_AUTO] = "auto",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(user_namespace_ownership, UserNamespaceOwnership);
|
||||
|
@ -268,7 +268,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_oom_score_adjust);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_cpu_affinity);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_resolv_conf);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_link_journal);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_timezone_mode);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_userns_chown);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_userns_ownership);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_bind_user);
|
||||
|
@ -1979,3 +1979,37 @@ int config_parse_unsigned_bounded(
|
||||
DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent, "Failed to parse percent value");
|
||||
DEFINE_CONFIG_PARSE(config_parse_permyriad, parse_permyriad, "Failed to parse permyriad value");
|
||||
DEFINE_CONFIG_PARSE_PTR(config_parse_sec_fix_0, parse_sec_fix_0, usec_t, "Failed to parse time value");
|
||||
|
||||
int config_parse_timezone(
|
||||
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) {
|
||||
|
||||
char **tz = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*tz = mfree(*tz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = verify_timezone(rvalue, LOG_WARNING);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Timezone is not valid, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_and_strdup_warn(tz, rvalue);
|
||||
}
|
||||
|
@ -250,6 +250,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_percent);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_permyriad);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_pid);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_sec_fix_0);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
|
||||
|
||||
typedef enum Disabled {
|
||||
DISABLED_CONFIGURATION,
|
||||
|
Loading…
Reference in New Issue
Block a user