From bdad94d0d6dc14be1dfbbb78c79ce59184a2c3c8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 1 Jun 2020 13:08:43 +0900 Subject: [PATCH] network: set both dhcp_route_metric and dhcp6_route_metric by DHCP.RouteMetric= for backward compatibility But [DHCPv4] or [DHCPv6] section take precedence. This also update so for UseDNS= and UseNTP=. --- src/network/networkd-dhcp-common.c | 72 ++++++++++++++++++++++-- src/network/networkd-dhcp-common.h | 1 + src/network/networkd-network-gperf.gperf | 14 ++--- src/network/networkd-network.h | 6 ++ 4 files changed, 82 insertions(+), 11 deletions(-) diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c index 66dd8ea08e..9b30764c81 100644 --- a/src/network/networkd-dhcp-common.c +++ b/src/network/networkd-dhcp-common.c @@ -63,6 +63,50 @@ int config_parse_dhcp( return 0; } +int config_parse_dhcp_route_metric( + 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 = data; + uint32_t metric; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = safe_atou32(rvalue, &metric); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse RouteMetric=%s, ignoring assignment: %m", rvalue); + return 0; + } + + if (streq_ptr(section, "DHCPv4")) { + network->dhcp_route_metric = metric; + network->dhcp_route_metric_set = true; + } else if (streq_ptr(section, "DHCPv6")) { + network->dhcp6_route_metric = metric; + network->dhcp6_route_metric_set = true; + } else { /* [DHCP] section */ + if (!network->dhcp_route_metric_set) + network->dhcp_route_metric = metric; + if (!network->dhcp6_route_metric_set) + network->dhcp6_route_metric = metric; + } + + return 0; +} + int config_parse_dhcp_use_dns( const char* unit, const char *filename, @@ -90,8 +134,18 @@ int config_parse_dhcp_use_dns( return 0; } - network->dhcp_use_dns = r; - network->dhcp6_use_dns = r; + if (streq_ptr(section, "DHCPv4")) { + network->dhcp_use_dns = r; + network->dhcp_use_dns_set = true; + } else if (streq_ptr(section, "DHCPv6")) { + network->dhcp6_use_dns = r; + network->dhcp6_use_dns_set = true; + } else { /* [DHCP] section */ + if (!network->dhcp_use_dns_set) + network->dhcp_use_dns = r; + if (!network->dhcp6_use_dns_set) + network->dhcp6_use_dns = r; + } return 0; } @@ -155,8 +209,18 @@ int config_parse_dhcp_use_ntp( return 0; } - network->dhcp_use_ntp = r; - network->dhcp6_use_ntp = r; + if (streq_ptr(section, "DHCPv4")) { + network->dhcp_use_ntp = r; + network->dhcp_use_ntp_set = true; + } else if (streq_ptr(section, "DHCPv6")) { + network->dhcp6_use_ntp = r; + network->dhcp6_use_ntp_set = true; + } else { /* [DHCP] section */ + if (!network->dhcp_use_ntp_set) + network->dhcp_use_ntp = r; + if (!network->dhcp6_use_ntp_set) + network->dhcp6_use_ntp = r; + } return 0; } diff --git a/src/network/networkd-dhcp-common.h b/src/network/networkd-dhcp-common.h index d837f89c25..dd574f1d56 100644 --- a/src/network/networkd-dhcp-common.h +++ b/src/network/networkd-dhcp-common.h @@ -42,6 +42,7 @@ const char *dhcp_option_data_type_to_string(DHCPOptionDataType d) _const_; DHCPOptionDataType dhcp_option_data_type_from_string(const char *d) _pure_; CONFIG_PARSER_PROTOTYPE(config_parse_dhcp); +CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_route_metric); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 4976c62c10..c6b9cb8ddc 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -158,9 +158,9 @@ Route.MultiPathRoute, config_parse_multipath_route, NextHop.Id, config_parse_nexthop_id, 0, 0 NextHop.Gateway, config_parse_nexthop_gateway, 0, 0 DHCPv4.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier) -DHCPv4.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_use_dns) +DHCPv4.UseDNS, config_parse_dhcp_use_dns, 0, 0 DHCPv4.RoutesToDNS, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_dns) -DHCPv4.UseNTP, config_parse_bool, 0, offsetof(Network, dhcp_use_ntp) +DHCPv4.UseNTP, config_parse_dhcp_use_ntp, 0, 0 DHCPv4.UseSIP, config_parse_bool, 0, offsetof(Network, dhcp_use_sip) DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_use_mtu) DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname) @@ -178,7 +178,7 @@ DHCPv4.MaxAttempts, config_parse_dhcp_max_attempts, DHCPv4.UserClass, config_parse_dhcp_user_class, AF_INET, offsetof(Network, dhcp_user_class) DHCPv4.DUIDType, config_parse_duid_type, 0, offsetof(Network, duid) DHCPv4.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Network, duid) -DHCPv4.RouteMetric, config_parse_uint32, 0, offsetof(Network, dhcp_route_metric) +DHCPv4.RouteMetric, config_parse_dhcp_route_metric, 0, 0 DHCPv4.RouteTable, config_parse_section_route_table, 0, 0 DHCPv4.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone) DHCPv4.IAID, config_parse_iaid, 0, 0 @@ -191,8 +191,8 @@ DHCPv4.SendOption, config_parse_dhcp_send_option, DHCPv4.SendVendorOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_client_send_vendor_options) DHCPv4.RouteMTUBytes, config_parse_mtu, AF_INET, offsetof(Network, dhcp_route_mtu) DHCPv4.FallbackLeaseLifetimeSec, config_parse_dhcp_fallback_lease_lifetime, 0, 0 -DHCPv6.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp6_use_dns) -DHCPv6.UseNTP, config_parse_bool, 0, offsetof(Network, dhcp6_use_ntp) +DHCPv6.UseDNS, config_parse_dhcp_use_dns, 0, 0 +DHCPv6.UseNTP, config_parse_dhcp_use_ntp, 0, 0 DHCPv6.RapidCommit, config_parse_bool, 0, offsetof(Network, rapid_commit) DHCPv6.MUDURL, config_parse_dhcp6_mud_url, 0, 0 DHCPv6.RequestOptions, config_parse_dhcp_request_options, AF_INET6, 0 @@ -204,7 +204,7 @@ DHCPv6.AssignAcquiredDelegatedPrefixAddress, config_parse_bool, DHCPv6.PrefixDelegationHint, config_parse_dhcp6_pd_hint, 0, 0 DHCPv6.WithoutRA, config_parse_bool, 0, offsetof(Network, dhcp6_without_ra) DHCPv6.SendOption, config_parse_dhcp_send_option, AF_INET6, offsetof(Network, dhcp6_client_send_options) -DHCPv6.RouteMetric, config_parse_uint32, 0, offsetof(Network, dhcp6_route_metric) +DHCPv6.RouteMetric, config_parse_dhcp_route_metric, 0, 0 IPv6AcceptRA.UseAutonomousPrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_autonomous_prefix) IPv6AcceptRA.UseOnLinkPrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_onlink_prefix) IPv6AcceptRA.UseDNS, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_dns) @@ -395,7 +395,7 @@ DHCP.VendorClassIdentifier, config_parse_string, DHCP.UserClass, config_parse_dhcp_user_class, AF_INET, offsetof(Network, dhcp_user_class) DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Network, duid) DHCP.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Network, duid) -DHCP.RouteMetric, config_parse_uint32, 0, offsetof(Network, dhcp_route_metric) +DHCP.RouteMetric, config_parse_dhcp_route_metric, 0, 0 DHCP.RouteTable, config_parse_section_route_table, 0, 0 DHCP.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone) DHCP.IAID, config_parse_iaid, 0, 0 diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 1d4b68d790..95e4d58b97 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -96,6 +96,7 @@ struct Network { char *dhcp_hostname; uint64_t dhcp_max_attempts; uint32_t dhcp_route_metric; + bool dhcp_route_metric_set; uint32_t dhcp_route_table; uint32_t dhcp_fallback_lease_lifetime; uint32_t dhcp_route_mtu; @@ -106,8 +107,10 @@ struct Network { bool dhcp_send_hostname; bool dhcp_broadcast; bool dhcp_use_dns; + bool dhcp_use_dns_set; bool dhcp_routes_to_dns; bool dhcp_use_ntp; + bool dhcp_use_ntp_set; bool dhcp_use_sip; bool dhcp_use_mtu; bool dhcp_use_routes; @@ -129,10 +132,13 @@ struct Network { /* DHCPv6 Client support*/ bool dhcp6_use_dns; + bool dhcp6_use_dns_set; bool dhcp6_use_ntp; + bool dhcp6_use_ntp_set; bool dhcp6_without_ra; uint8_t dhcp6_pd_length; uint32_t dhcp6_route_metric; + bool dhcp6_route_metric_set; char *dhcp6_mudurl; char **dhcp6_user_class; char **dhcp6_vendor_class;