From 6192b846ca0d15602e94ddb5da4420b7c60d64a5 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Fri, 15 Aug 2014 14:21:08 +0200 Subject: networkd: add support for Domains= to .network files This allows the search/routing domanis to be specified per link/network and be passed on to resolved. --- man/systemd.network.xml | 13 ++++++++++++- src/network/networkd-link.c | 16 ++++++++++++++-- src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 28 ++++++++++++++++++++++++++++ src/network/networkd.h | 13 ++++++++++++- 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 290aa6efe5..024509968a 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -301,7 +301,18 @@ This option may be specified more than once. - + + Domains= + + The domains used for DNS resolution over this link. + + + + NTP= + + An NTP server address. This option may be specified more than once. + + Bridge= diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 9eb2e89091..d25343ba2b 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1722,6 +1722,7 @@ int link_save(Link *link) { if (link->network) { char **address; + char **domain; fputs("DNS=", f); @@ -1763,15 +1764,26 @@ int link_save(Link *link) { fputs("\n", f); + fprintf(f, "DOMAINS="); + if (link->network->dhcp_domains && link->dhcp_lease) { const char *domainname; r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname); - if (r >= 0) - fprintf(f, "DOMAINS=%s\n", domainname); + if (r >= 0) { + fputs(domainname, f); + if (link->network->domains) + fputs(" ", f); + } } + STRV_FOREACH(domain, link->network->domains) + fprintf(f, "%s%s", *domain, + (domain + 1 ? " " : "")); + + fputs("\n", f); + fprintf(f, "LLMNR=%s\n", llmnr_support_to_string(link->network->llmnr)); } diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 9cd7a4aa61..c5b9614a2b 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -37,6 +37,7 @@ Network.IPv4LL, config_parse_bool, 0, Network.IPv4LLRoute, config_parse_bool, 0, offsetof(Network, ipv4ll_route) Network.Address, config_parse_address, 0, 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.NTP, config_parse_strv, 0, offsetof(Network, ntp) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index e13e4a0f62..bbc5d279e9 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -341,6 +341,34 @@ int config_parse_netdev(const char *unit, 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) { + char ***domains = data; + char **domain; + int r; + + r = config_parse_strv(unit, filename, line, section, section_line, + lvalue, ltype, rvalue, domains, userdata); + if (r < 0) + return r; + + strv_uniq(*domains); + + STRV_FOREACH(domain, *domains) + if (is_localhost(*domain) || !hostname_is_valid(*domain)) + strv_remove(*domains, *domain); + + return 0; +} + int config_parse_tunnel(const char *unit, const char *filename, unsigned line, diff --git a/src/network/networkd.h b/src/network/networkd.h index 90e798dbf5..a9867d9e7f 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -111,7 +111,7 @@ struct Network { Hashmap *addresses_by_section; Hashmap *routes_by_section; - char **dns, **ntp; + char **domains, **dns, **ntp; LLMNRSupport llmnr; @@ -224,6 +224,17 @@ int config_parse_netdev(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_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_tunnel(const char *unit, const char *filename, unsigned line, -- cgit v1.2.3-54-g00ecf