1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-27 03:21:32 +03:00

Merge pull request #13054 from yuwata/network-dhcp-use-domains-8174

network:dhcp4: request domain search list if UseDomains=yes
This commit is contained in:
Yu Watanabe 2019-07-15 03:29:19 +09:00 committed by GitHub
commit 0f44806d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 4 deletions

View File

@ -1041,6 +1041,12 @@ int dhcp4_configure(Link *link) {
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set request flag for classless static route: %m");
}
if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO && !link->network->dhcp_anonymize) {
r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_DOMAIN_SEARCH_LIST);
if (r < 0)
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set request flag for domain search list: %m");
}
if (link->network->dhcp_use_ntp) {
r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_NTP_SERVER);
if (r < 0)

View File

@ -3557,14 +3557,16 @@ int link_save(Link *link) {
fputs_with_space(f, p, NULL, &space);
if (link->network->dhcp_use_domains == DHCP_USE_DOMAINS_YES) {
NDiscDNSSL *dd;
if (dhcp_domainname)
fputs_with_space(f, dhcp_domainname, NULL, &space);
if (dhcp_domains)
fputstrv(f, dhcp_domains, NULL, &space);
if (dhcp6_domains)
fputstrv(f, dhcp6_domains, NULL, &space);
}
if (link->network->ipv6_accept_ra_use_domains == DHCP_USE_DOMAINS_YES) {
NDiscDNSSL *dd;
SET_FOREACH(dd, link->ndisc_dnssl, i)
fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space);
@ -3578,14 +3580,16 @@ int link_save(Link *link) {
fputs_with_space(f, p, NULL, &space);
if (link->network->dhcp_use_domains == DHCP_USE_DOMAINS_ROUTE) {
NDiscDNSSL *dd;
if (dhcp_domainname)
fputs_with_space(f, dhcp_domainname, NULL, &space);
if (dhcp_domains)
fputstrv(f, dhcp_domains, NULL, &space);
if (dhcp6_domains)
fputstrv(f, dhcp6_domains, NULL, &space);
}
if (link->network->ipv6_accept_ra_use_domains == DHCP_USE_DOMAINS_ROUTE) {
NDiscDNSSL *dd;
SET_FOREACH(dd, link->ndisc_dnssl, i)
fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space);

View File

@ -0,0 +1,9 @@
[Match]
Name=veth99
[Network]
DHCP=ipv4
IPv6AcceptRA=no
[DHCPv4]
UseDomains=yes

View File

@ -2233,6 +2233,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
'dhcp-client-use-dns-ipv4.network',
'dhcp-client-use-dns-no.network',
'dhcp-client-use-dns-yes.network',
'dhcp-client-use-domains.network',
'dhcp-client-use-routes-no.network',
'dhcp-client-vrf.network',
'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network',
@ -2241,6 +2242,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
'dhcp-client.network',
'dhcp-server-veth-peer.network',
'dhcp-v4-server-veth-peer.network',
'dhcp-client-use-domains.network',
'static.network']
def setUp(self):
@ -2860,6 +2862,23 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
self.assertRegex(output, '192.168.5.1')
self.assertRegex(output, '2600::1')
def test_dhcp_client_use_domains(self):
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-domains.network')
start_networkd()
wait_online(['veth-peer:carrier'])
start_dnsmasq('--dhcp-option=option:domain-search,example.com')
wait_online(['veth99:routable', 'veth-peer:routable'])
output = check_output(*networkctl_cmd, 'status', 'veth99', env=env)
print(output)
self.assertRegex(output, 'Search Domains: example.com')
time.sleep(3)
output = check_output(*resolvectl_cmd, 'domain', 'veth99', env=env)
print(output)
self.assertRegex(output, 'example.com')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--build-dir', help='Path to build dir', dest='build_dir')