|
| 1 | +diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml |
| 2 | +index 85b21ee..50af6e1 100644 |
| 3 | +--- a/man/networkd.conf.xml |
| 4 | ++++ b/man/networkd.conf.xml |
| 5 | +@@ -182,6 +182,15 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00</programlisting> |
| 6 | + </example> |
| 7 | + </listitem> |
| 8 | + </varlistentry> |
| 9 | ++ |
| 10 | ++ <varlistentry> |
| 11 | ++ <term><varname>UseDomains=</varname></term> |
| 12 | ++ <listitem><para>Specifies the default value for per-network <varname>UseDomains=</varname>. |
| 13 | ++ Takes a boolean. See for details in |
| 14 | ++ <citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 15 | ++ Defaults to <literal>no</literal>.</para> |
| 16 | ++ </listitem> |
| 17 | ++ </varlistentry> |
| 18 | + </variablelist> |
| 19 | + </refsect1> |
| 20 | + |
| 21 | +@@ -202,6 +211,7 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00</programlisting> |
| 22 | + <varlistentry> |
| 23 | + <term><varname>DUIDType=</varname></term> |
| 24 | + <term><varname>DUIDRawData=</varname></term> |
| 25 | ++ <term><varname>UseDomains=</varname></term> |
| 26 | + <listitem><para>As in the [DHCPv4] section.</para></listitem> |
| 27 | + </varlistentry> |
| 28 | + </variablelist> |
| 29 | +diff --git a/man/systemd.network.xml b/man/systemd.network.xml |
| 30 | +index a98157d..aba93cb 100644 |
| 31 | +--- a/man/systemd.network.xml |
| 32 | ++++ b/man/systemd.network.xml |
| 33 | +@@ -1954,7 +1954,9 @@ Table=1234</programlisting></para> |
| 34 | + to the effect of the <option>Domains=</option> setting. If set to <option>route</option>, the |
| 35 | + domain name received from the DHCP server will be used for routing DNS queries only, but not |
| 36 | + for searching, similar to the effect of the <option>Domains=</option> setting when the |
| 37 | +- argument is prefixed with <literal>~</literal>. Defaults to false.</para> |
| 38 | ++ argument is prefixed with <literal>~</literal>.When unspecified, the value specified in the same |
| 39 | ++ setting in<citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
| 40 | ++ which defaults to <literal>no</literal>, will be used.</para> |
| 41 | + |
| 42 | + <para>It is recommended to enable this option only on trusted networks, as setting this |
| 43 | + affects resolution of all hostnames, in particular of single-label names. It is generally |
| 44 | +diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c |
| 45 | +index 7996960..3c79e8d 100644 |
| 46 | +--- a/src/network/networkd-dhcp-common.c |
| 47 | ++++ b/src/network/networkd-dhcp-common.c |
| 48 | +@@ -455,6 +455,8 @@ int config_parse_dhcp_use_domains( |
| 49 | + return 0; |
| 50 | + } |
| 51 | + |
| 52 | ++DEFINE_CONFIG_PARSE_ENUM(config_parse_default_dhcp_use_domains, dhcp_use_domains, DHCPUseDomains, "Failed to parse UseDomains=") |
| 53 | ++ |
| 54 | + int config_parse_dhcp_use_ntp( |
| 55 | + const char* unit, |
| 56 | + const char *filename, |
| 57 | +diff --git a/src/network/networkd-dhcp-common.h b/src/network/networkd-dhcp-common.h |
| 58 | +index c19bc10..5a1d446 100644 |
| 59 | +--- a/src/network/networkd-dhcp-common.h |
| 60 | ++++ b/src/network/networkd-dhcp-common.h |
| 61 | +@@ -92,6 +92,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp); |
| 62 | + CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_metric); |
| 63 | + CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns); |
| 64 | + CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains); |
| 65 | ++CONFIG_PARSER_PROTOTYPE(config_parse_default_dhcp_use_domains); |
| 66 | + CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp); |
| 67 | + CONFIG_PARSER_PROTOTYPE(config_parse_iaid); |
| 68 | + CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_table); |
| 69 | +diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf |
| 70 | +index 8ed90f0..2bdeec0 100644 |
| 71 | +--- a/src/network/networkd-gperf.gperf |
| 72 | ++++ b/src/network/networkd-gperf.gperf |
| 73 | +@@ -26,8 +26,10 @@ Network.SpeedMeterIntervalSec, config_parse_sec, |
| 74 | + Network.ManageForeignRoutingPolicyRules, config_parse_bool, 0, offsetof(Manager, manage_foreign_rules) |
| 75 | + Network.ManageForeignRoutes, config_parse_bool, 0, offsetof(Manager, manage_foreign_routes) |
| 76 | + Network.RouteTable, config_parse_route_table_names, 0, 0 |
| 77 | ++DHCPv4.UseDomains, config_parse_default_dhcp_use_domains, 0, offsetof(Manager, dhcp_use_domains) |
| 78 | + DHCPv4.DUIDType, config_parse_duid_type, 0, offsetof(Manager, dhcp_duid) |
| 79 | + DHCPv4.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, dhcp_duid) |
| 80 | ++DHCPv6.UseDomains, config_parse_default_dhcp_use_domains, 0, offsetof(Manager, dhcp6_use_domains) |
| 81 | + DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Manager, dhcp6_duid) |
| 82 | + DHCPv6.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, dhcp6_duid) |
| 83 | + /* Deprecated */ |
| 84 | +diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h |
| 85 | +index 3631358..cd0012c 100644 |
| 86 | +--- a/src/network/networkd-manager.h |
| 87 | ++++ b/src/network/networkd-manager.h |
| 88 | +@@ -54,6 +54,9 @@ struct Manager { |
| 89 | + OrderedSet *address_pools; |
| 90 | + Set *dhcp_pd_subnet_ids; |
| 91 | + |
| 92 | ++ DHCPUseDomains dhcp_use_domains; |
| 93 | ++ DHCPUseDomains dhcp6_use_domains; |
| 94 | ++ |
| 95 | + usec_t network_dirs_ts_usec; |
| 96 | + |
| 97 | + DUID dhcp_duid; |
| 98 | +diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c |
| 99 | +index 873ad2e..ddec0e1 100644 |
| 100 | +--- a/src/network/networkd-network.c |
| 101 | ++++ b/src/network/networkd-network.c |
| 102 | +@@ -393,6 +393,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi |
| 103 | + .dhcp_use_sip = true, |
| 104 | + .dhcp_use_dns = true, |
| 105 | + .dhcp_routes_to_dns = true, |
| 106 | ++ .dhcp_use_domains = manager->dhcp_use_domains, |
| 107 | + .dhcp_use_hostname = true, |
| 108 | + .dhcp_use_routes = true, |
| 109 | + .dhcp_use_gateway = -1, |
| 110 | +@@ -407,6 +408,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi |
| 111 | + .dhcp6_use_address = true, |
| 112 | + .dhcp6_use_pd_prefix = true, |
| 113 | + .dhcp6_use_dns = true, |
| 114 | ++ .dhcp6_use_domains = manager->dhcp6_use_domains, |
| 115 | + .dhcp6_use_hostname = true, |
| 116 | + .dhcp6_use_ntp = true, |
| 117 | + .dhcp6_duid.type = _DUID_TYPE_INVALID, |
| 118 | +diff --git a/src/network/networkd.conf b/src/network/networkd.conf |
| 119 | +index 38dc9f1..03c319a 100644 |
| 120 | +--- a/src/network/networkd.conf |
| 121 | ++++ b/src/network/networkd.conf |
| 122 | +@@ -22,7 +22,9 @@ |
| 123 | + [DHCPv4] |
| 124 | + #DUIDType=vendor |
| 125 | + #DUIDRawData= |
| 126 | ++#UseDomains=no |
| 127 | + |
| 128 | + [DHCPv6] |
| 129 | + #DUIDType=vendor |
| 130 | + #DUIDRawData= |
| 131 | ++#UseDomains=no |
| 132 | +diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py |
| 133 | +index cc450ae..2c076b9 100755 |
| 134 | +--- a/test/test-network/systemd-networkd-tests.py |
| 135 | ++++ b/test/test-network/systemd-networkd-tests.py |
| 136 | +@@ -4977,6 +4977,48 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): |
| 137 | + output = check_output(*resolvectl_cmd, 'domain', 'veth99', env=env) |
| 138 | + print(output) |
| 139 | + self.assertRegex(output, 'example.com') |
| 140 | ++ |
| 141 | ++ def test_dhcp_client_default_use_domains(self): |
| 142 | ++ def check(self, ipv4, ipv6): |
| 143 | ++ os.makedirs(networkd_conf_dropin_path, exist_ok=True) |
| 144 | ++ with open(os.path.join(networkd_conf_dropin_path, 'default_use_domains.conf'), mode='w', encoding='utf-8') as f: |
| 145 | ++ f.write('[DHCPv4]\nUseDomains=') |
| 146 | ++ f.write('yes\n' if ipv4 else 'no\n') |
| 147 | ++ f.write('[DHCPv6]\nUseDomains=') |
| 148 | ++ f.write('yes\n' if ipv6 else 'no\n') |
| 149 | ++ |
| 150 | ++ restart_networkd() |
| 151 | ++ self.wait_online(['veth-peer:carrier']) |
| 152 | ++ start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1] --dhcp-option=option:domain-search,example.com --dhcp-option=option6:domain-search,example.com') |
| 153 | ++ |
| 154 | ++ self.wait_online(['veth99:routable', 'veth-peer:routable']) |
| 155 | ++ |
| 156 | ++ # link becomes 'routable' when at least one protocol provide an valid address. Hence, we need to explicitly wait for both addresses. |
| 157 | ++ self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 metric 1024 brd 192.168.5.255 scope global dynamic', ipv='-4') |
| 158 | ++ self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') |
| 159 | ++ |
| 160 | ++ for _ in range(20): |
| 161 | ++ output = check_output(*resolvectl_cmd, 'domain', 'veth99', env=env) |
| 162 | ++ if ipv4 or ipv6: |
| 163 | ++ if 'example.com' in output: |
| 164 | ++ break |
| 165 | ++ else: |
| 166 | ++ if 'example.com' not in output: |
| 167 | ++ break |
| 168 | ++ time.sleep(0.5) |
| 169 | ++ else: |
| 170 | ++ print(output) |
| 171 | ++ self.fail('unexpected domain setting in resolved...') |
| 172 | ++ |
| 173 | ++ stop_dnsmasq() |
| 174 | ++ remove_networkd_conf_dropin(['default_use_domains.conf']) |
| 175 | ++ |
| 176 | ++ copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network') |
| 177 | ++ networkd_ci_path |
| 178 | ++ check(self, True, True) |
| 179 | ++ check(self, True, False) |
| 180 | ++ check(self, False, True) |
| 181 | ++ check(self, False, False) |
| 182 | + |
| 183 | + def test_dhcp_client_decline(self): |
| 184 | + copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-decline.network', 'dhcp-client-decline.network') |
0 commit comments