1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-13 00:58:27 +03:00

network: use ltype to distinguish DHCPv4 and DHCPv6

This commit is contained in:
Yu Watanabe 2021-09-08 08:39:26 +09:00
parent 471e332d50
commit 967e6a6403
3 changed files with 61 additions and 29 deletions

View File

@ -272,7 +272,7 @@ int config_parse_dhcp(
return 0;
}
int config_parse_dhcp_route_metric(
int config_parse_dhcp_or_ra_route_metric(
const char* unit,
const char *filename,
unsigned line,
@ -290,6 +290,7 @@ int config_parse_dhcp_route_metric(
assert(filename);
assert(lvalue);
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
assert(rvalue);
assert(data);
@ -300,17 +301,24 @@ int config_parse_dhcp_route_metric(
return 0;
}
if (streq_ptr(section, "DHCPv4")) {
switch(ltype) {
case AF_INET:
network->dhcp_route_metric = metric;
network->dhcp_route_metric_set = true;
} else if (STRPTR_IN_SET(section, "DHCPv6", "IPv6AcceptRA")) {
break;
case AF_INET6:
network->ipv6_accept_ra_route_metric = metric;
network->ipv6_accept_ra_route_metric_set = true;
} else { /* [DHCP] section */
break;
case AF_UNSPEC:
/* For backward compatibility. */
if (!network->dhcp_route_metric_set)
network->dhcp_route_metric = metric;
if (!network->ipv6_accept_ra_route_metric_set)
network->ipv6_accept_ra_route_metric = metric;
break;
default:
assert_not_reached();
}
return 0;
@ -333,6 +341,7 @@ int config_parse_dhcp_use_dns(
assert(filename);
assert(lvalue);
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
assert(rvalue);
assert(data);
@ -343,17 +352,24 @@ int config_parse_dhcp_use_dns(
return 0;
}
if (streq_ptr(section, "DHCPv4")) {
switch(ltype) {
case AF_INET:
network->dhcp_use_dns = r;
network->dhcp_use_dns_set = true;
} else if (streq_ptr(section, "DHCPv6")) {
break;
case AF_INET6:
network->dhcp6_use_dns = r;
network->dhcp6_use_dns_set = true;
} else { /* [DHCP] section */
break;
case AF_UNSPEC:
/* For backward compatibility. */
if (!network->dhcp_use_dns_set)
network->dhcp_use_dns = r;
if (!network->dhcp6_use_dns_set)
network->dhcp6_use_dns = r;
break;
default:
assert_not_reached();
}
return 0;
@ -376,6 +392,7 @@ int config_parse_dhcp_use_domains(
assert(filename);
assert(lvalue);
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
assert(rvalue);
assert(data);
@ -386,17 +403,24 @@ int config_parse_dhcp_use_domains(
return 0;
}
if (streq_ptr(section, "DHCPv4")) {
switch(ltype) {
case AF_INET:
network->dhcp_use_domains = d;
network->dhcp_use_domains_set = true;
} else if (streq_ptr(section, "DHCPv6")) {
break;
case AF_INET6:
network->dhcp6_use_domains = d;
network->dhcp6_use_domains_set = true;
} else { /* [DHCP] section */
break;
case AF_UNSPEC:
/* For backward compatibility. */
if (!network->dhcp_use_domains_set)
network->dhcp_use_domains = d;
if (!network->dhcp6_use_domains_set)
network->dhcp6_use_domains = d;
break;
default:
assert_not_reached();
}
return 0;
@ -419,6 +443,7 @@ int config_parse_dhcp_use_ntp(
assert(filename);
assert(lvalue);
assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
assert(rvalue);
assert(data);
@ -429,17 +454,24 @@ int config_parse_dhcp_use_ntp(
return 0;
}
if (streq_ptr(section, "DHCPv4")) {
switch(ltype) {
case AF_INET:
network->dhcp_use_ntp = r;
network->dhcp_use_ntp_set = true;
} else if (streq_ptr(section, "DHCPv6")) {
break;
case AF_INET6:
network->dhcp6_use_ntp = r;
network->dhcp6_use_ntp_set = true;
} else { /* [DHCP] section */
break;
case AF_UNSPEC:
/* For backward compatibility. */
if (!network->dhcp_use_ntp_set)
network->dhcp_use_ntp = r;
if (!network->dhcp6_use_ntp_set)
network->dhcp6_use_ntp = r;
break;
default:
assert_not_reached();
}
return 0;

View File

@ -80,7 +80,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_or_ra_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);

View File

@ -199,14 +199,14 @@ NextHop.OnLink, config_parse_nexthop_onlink,
NextHop.Blackhole, config_parse_nexthop_blackhole, 0, 0
NextHop.Group, config_parse_nexthop_group, 0, 0
DHCPv4.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)
DHCPv4.UseDNS, config_parse_dhcp_use_dns, 0, 0
DHCPv4.UseDNS, config_parse_dhcp_use_dns, AF_INET, 0
DHCPv4.RoutesToDNS, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_dns)
DHCPv4.UseNTP, config_parse_dhcp_use_ntp, 0, 0
DHCPv4.UseNTP, config_parse_dhcp_use_ntp, AF_INET, 0
DHCPv4.RoutesToNTP, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_ntp)
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)
DHCPv4.UseDomains, config_parse_dhcp_use_domains, 0, 0
DHCPv4.UseDomains, config_parse_dhcp_use_domains, AF_INET, 0
DHCPv4.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
DHCPv4.UseGateway, config_parse_tristate, 0, offsetof(Network, dhcp_use_gateway)
DHCPv4.RequestOptions, config_parse_dhcp_request_options, AF_INET, 0
@ -222,7 +222,7 @@ DHCPv4.UserClass, config_parse_dhcp_user_or_vendor_cl
DHCPv4.IAID, config_parse_iaid, AF_INET, 0
DHCPv4.DUIDType, config_parse_network_duid_type, 0, 0
DHCPv4.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
DHCPv4.RouteMetric, config_parse_dhcp_route_metric, 0, 0
DHCPv4.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET, 0
DHCPv4.RouteTable, config_parse_section_route_table, 0, 0
DHCPv4.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCPv4.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port)
@ -236,10 +236,10 @@ DHCPv4.SendVendorOption, config_parse_dhcp_send_option,
DHCPv4.RouteMTUBytes, config_parse_mtu, AF_INET, offsetof(Network, dhcp_route_mtu)
DHCPv4.FallbackLeaseLifetimeSec, config_parse_dhcp_fallback_lease_lifetime, 0, 0
DHCPv6.UseAddress, config_parse_bool, 0, offsetof(Network, dhcp6_use_address)
DHCPv6.UseDNS, config_parse_dhcp_use_dns, 0, 0
DHCPv6.UseDNS, config_parse_dhcp_use_dns, AF_INET6, 0
DHCPv6.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp6_use_hostname)
DHCPv6.UseDomains, config_parse_dhcp_use_domains, 0, 0
DHCPv6.UseNTP, config_parse_dhcp_use_ntp, 0, 0
DHCPv6.UseDomains, config_parse_dhcp_use_domains, AF_INET6, 0
DHCPv6.UseNTP, config_parse_dhcp_use_ntp, AF_INET6, 0
DHCPv6.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_rapid_commit)
DHCPv6.MUDURL, config_parse_mud_url, 0, offsetof(Network, dhcp6_mudurl)
DHCPv6.RequestOptions, config_parse_dhcp_request_options, AF_INET6, 0
@ -260,7 +260,7 @@ IPv6AcceptRA.UseDomains, config_parse_ipv6_accept_ra_use_dom
IPv6AcceptRA.UseMTU, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_mtu)
IPv6AcceptRA.DHCPv6Client, config_parse_ipv6_accept_ra_start_dhcp6_client, 0, offsetof(Network, ipv6_accept_ra_start_dhcp6_client)
IPv6AcceptRA.RouteTable, config_parse_section_route_table, 0, 0
IPv6AcceptRA.RouteMetric, config_parse_dhcp_route_metric, 0, 0
IPv6AcceptRA.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET6, 0
IPv6AcceptRA.RouterAllowList, config_parse_address_filter, AF_INET6, offsetof(Network, ndisc_allow_listed_router)
IPv6AcceptRA.RouterDenyList, config_parse_address_filter, AF_INET6, offsetof(Network, ndisc_deny_listed_router)
IPv6AcceptRA.PrefixAllowList, config_parse_address_filter, AF_INET6, offsetof(Network, ndisc_allow_listed_prefix)
@ -501,12 +501,12 @@ IPv6PrefixDelegation.Domains, config_parse_radv_search_domains,
IPv6PrefixDelegation.DNSLifetimeSec, config_parse_sec, 0, offsetof(Network, router_dns_lifetime_usec)
DHCPv4.BlackList, config_parse_address_filter, AF_INET, offsetof(Network, dhcp_deny_listed_ip)
DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)
DHCP.UseDNS, config_parse_dhcp_use_dns, 0, 0
DHCP.UseNTP, config_parse_dhcp_use_ntp, 0, 0
DHCP.UseDNS, config_parse_dhcp_use_dns, AF_UNSPEC, 0
DHCP.UseNTP, config_parse_dhcp_use_ntp, AF_UNSPEC, 0
DHCP.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_use_mtu)
DHCP.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname)
DHCP.UseDomains, config_parse_dhcp_use_domains, 0, 0
DHCP.UseDomainName, config_parse_dhcp_use_domains, 0, 0
DHCP.UseDomains, config_parse_dhcp_use_domains, AF_UNSPEC, 0
DHCP.UseDomainName, config_parse_dhcp_use_domains, AF_UNSPEC, 0
DHCP.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
DHCP.Anonymize, config_parse_bool, 0, offsetof(Network, dhcp_anonymize)
DHCP.SendHostname, config_parse_bool, 0, offsetof(Network, dhcp_send_hostname)
@ -518,15 +518,15 @@ DHCP.UserClass, config_parse_dhcp_user_or_vendor_cl
DHCP.IAID, config_parse_iaid, AF_INET, 0
DHCP.DUIDType, config_parse_network_duid_type, 0, 0
DHCP.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
DHCP.RouteMetric, config_parse_dhcp_route_metric, 0, 0
DHCP.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_UNSPEC, 0
DHCP.RouteTable, config_parse_section_route_table, 0, 0
DHCP.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCP.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port)
DHCP.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_rapid_commit)
DHCP.ForceDHCPv6PDOtherInformation, config_parse_bool, 0, offsetof(Network, dhcp6_force_pd_other_information)
DHCPv4.UseDomainName, config_parse_dhcp_use_domains, 0, 0
DHCPv4.UseDomainName, config_parse_dhcp_use_domains, AF_INET, 0
DHCPv4.CriticalConnection, config_parse_tristate, 0, offsetof(Network, dhcp_critical)
DHCPv6.RouteMetric, config_parse_dhcp_route_metric, 0, 0
DHCPv6.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET6, 0
IPv6AcceptRA.DenyList, config_parse_address_filter, AF_INET6, offsetof(Network, ndisc_deny_listed_prefix)
IPv6AcceptRA.BlackList, config_parse_address_filter, AF_INET6, offsetof(Network, ndisc_deny_listed_prefix)
TrafficControlQueueingDiscipline.Parent, config_parse_qdisc_parent, _QDISC_KIND_INVALID, 0