diff --git a/src/networkd.c b/src/networkd.c index 8cb0a36..4924909 100644 --- a/src/networkd.c +++ b/src/networkd.c @@ -419,6 +419,14 @@ write_network_file(net_definition* def, const char* rootdir, const char* path) g_string_append_printf(s, "ClientIdentifier=%s\n", def->dhcp_identifier); if (def->critical) g_string_append_printf(s, "CriticalConnection=true\n"); + + /* Only write DHCP options that differ from the networkd default. */ + if (!def->dhcp_options.use_dns) { + g_string_append_printf(s, "UseDNS=false\n"); + } + if (!def->dhcp_options.use_ntp) { + g_string_append_printf(s, "UseNTP=false\n"); + } } /* these do not contain secrets and need to be readable by diff --git a/src/parse.c b/src/parse.c index b4b0364..a75b10b 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1265,6 +1265,12 @@ const mapping_entry_handler nameservers_handlers[] = { {NULL} }; +const mapping_entry_handler dhcp_options_handlers[] = { + {"use-dns", YAML_SCALAR_NODE, handle_netdef_bool, NULL, netdef_offset(dhcp_options.use_dns)}, + {"use-ntp", YAML_SCALAR_NODE, handle_netdef_bool, NULL, netdef_offset(dhcp_options.use_ntp)}, + {NULL} +}; + const mapping_entry_handler ethernet_def_handlers[] = { {"accept-ra", YAML_SCALAR_NODE, handle_accept_ra}, {"addresses", YAML_SEQUENCE_NODE, handle_addresses}, @@ -1272,6 +1278,7 @@ const mapping_entry_handler ethernet_def_handlers[] = { {"dhcp4", YAML_SCALAR_NODE, handle_netdef_bool, NULL, netdef_offset(dhcp4)}, {"dhcp6", YAML_SCALAR_NODE, handle_netdef_bool, NULL, netdef_offset(dhcp6)}, {"dhcp-identifier", YAML_SCALAR_NODE, handle_dhcp_identifier}, + {"dhcp-options", YAML_MAPPING_NODE, NULL, dhcp_options_handlers}, {"gateway4", YAML_SCALAR_NODE, handle_gateway4}, {"gateway6", YAML_SCALAR_NODE, handle_gateway6}, {"link-local", YAML_SEQUENCE_NODE, handle_link_local}, @@ -1296,6 +1303,7 @@ const mapping_entry_handler wifi_def_handlers[] = { {"dhcp4", YAML_SCALAR_NODE, handle_netdef_bool, NULL, netdef_offset(dhcp4)}, {"dhcp6", YAML_SCALAR_NODE, handle_netdef_bool, NULL, netdef_offset(dhcp6)}, {"dhcp-identifier", YAML_SCALAR_NODE, handle_dhcp_identifier}, + {"dhcp-options", YAML_MAPPING_NODE, NULL, dhcp_options_handlers}, {"gateway4", YAML_SCALAR_NODE, handle_gateway4}, {"gateway6", YAML_SCALAR_NODE, handle_gateway6}, {"link-local", YAML_SEQUENCE_NODE, handle_link_local}, @@ -1479,6 +1487,10 @@ handle_network_type(yaml_document_t* doc, yaml_node_t* node, const void* data, G /* systemd-networkd defaults to IPv6 LL enabled; keep that default */ cur_netdef->linklocal.ipv6 = TRUE; g_hash_table_insert(netdefs, cur_netdef->id, cur_netdef); + + /* Default DHCP options. */ + cur_netdef->dhcp_options.use_dns = TRUE; + cur_netdef->dhcp_options.use_ntp = TRUE; } // XXX: breaks multi-pass parsing. diff --git a/src/parse.h b/src/parse.h index 54d103f..bb9638d 100644 --- a/src/parse.h +++ b/src/parse.h @@ -78,6 +78,10 @@ typedef struct net_definition { gboolean dhcp4; gboolean dhcp6; char* dhcp_identifier; + struct { + gboolean use_dns; + gboolean use_ntp; + } dhcp_options; ra_mode accept_ra; GArray* ip4_addresses; GArray* ip6_addresses;