Merge pull request #21653 from yuwata/network-dhcp6pd-unreachable-route-cleanups

network: dhcp6pd: cleanups for unreachable route
This commit is contained in:
Yu Watanabe 2021-12-07 20:28:18 +09:00 committed by GitHub
commit 5ed057b67b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 57 deletions

View file

@ -2085,7 +2085,6 @@ Table=1234</programlisting></para>
</varlistentry>
<varlistentry>
<term><varname>RouteMetric=</varname></term>
<term><varname>UseDNS=</varname></term>
<term><varname>UseNTP=</varname></term>
<term><varname>UseHostname=</varname></term>

View file

@ -39,15 +39,6 @@ uint32_t link_get_dhcp4_route_table(Link *link) {
return link_get_vrf_table(link);
}
uint32_t link_get_dhcp6_route_table(Link *link) {
assert(link);
assert(link->network);
if (link->network->dhcp6_route_table_set)
return link->network->dhcp6_route_table;
return link_get_vrf_table(link);
}
uint32_t link_get_ipv6_accept_ra_route_table(Link *link) {
assert(link);
assert(link->network);
@ -533,13 +524,9 @@ int config_parse_dhcp_or_ra_route_table(
assert(filename);
assert(lvalue);
assert(IN_SET(ltype,
(RTPROT_DHCP<<16) | AF_UNSPEC,
(RTPROT_DHCP<<16) | AF_INET,
(RTPROT_DHCP<<16) | AF_INET6,
(RTPROT_RA<<16) | AF_INET6));
assert(IN_SET(ltype, AF_INET, AF_INET6));
assert(rvalue);
assert(data);
assert(userdata);
r = safe_atou32(rvalue, &rt);
if (r < 0) {
@ -549,28 +536,11 @@ int config_parse_dhcp_or_ra_route_table(
}
switch(ltype) {
case (RTPROT_DHCP<<16) | AF_INET:
case AF_INET:
network->dhcp_route_table = rt;
network->dhcp_route_table_set = true;
network->dhcp_route_table_set_explicitly = true;
break;
case (RTPROT_DHCP<<16) | AF_INET6:
network->dhcp6_route_table = rt;
network->dhcp6_route_table_set = true;
network->dhcp6_route_table_set_explicitly = true;
break;
case (RTPROT_DHCP<<16) | AF_UNSPEC:
/* For backward compatibility. */
if (!network->dhcp_route_table_set_explicitly) {
network->dhcp_route_table = rt;
network->dhcp_route_table_set = true;
}
if (!network->dhcp6_route_table_set_explicitly) {
network->dhcp6_route_table = rt;
network->dhcp6_route_table_set = true;
}
break;
case (RTPROT_RA<<16) | AF_INET6:
case AF_INET6:
network->ipv6_accept_ra_route_table = rt;
network->ipv6_accept_ra_route_table_set = true;
break;

View file

@ -51,7 +51,6 @@ typedef struct DUID {
} DUID;
uint32_t link_get_dhcp4_route_table(Link *link);
uint32_t link_get_dhcp6_route_table(Link *link);
uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
bool link_dhcp_enabled(Link *link, int family);

View file

@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <linux/ipv6_route.h>
#include "sd-dhcp6-client.h"
#include "hashmap.h"
@ -696,19 +698,26 @@ static int dhcp6_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li
return 1;
}
static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *addr, uint8_t prefixlen, usec_t lifetime_usec) {
static int dhcp6_request_unreachable_route(
Link *link,
const struct in6_addr *addr,
uint8_t prefixlen,
usec_t lifetime_usec,
const union in_addr_union *server_address) {
_cleanup_(route_freep) Route *route = NULL;
_cleanup_free_ char *buf = NULL;
Route *existing;
int r;
assert(link);
assert(addr);
assert(server_address);
(void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
if (prefixlen >= 64) {
_cleanup_free_ char *buf = NULL;
if (prefixlen == 64) {
log_link_debug(link, "Not adding a blocking route for DHCPv6 delegated subnet %s since distributed prefix is 64",
(void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
log_link_debug(link, "Not adding a blocking route for DHCPv6 delegated prefix %s since the prefix has length >= 64.",
strna(buf));
return 0;
}
@ -718,13 +727,13 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
return log_oom();
route->source = NETWORK_CONFIG_SOURCE_DHCP6;
route->provider = *server_address;
route->family = AF_INET6;
route->dst.in6 = *addr;
route->dst_prefixlen = prefixlen;
route->table = link_get_dhcp6_route_table(link);
route->type = RTN_UNREACHABLE;
route->protocol = RTPROT_DHCP;
route->priority = DHCP_ROUTE_METRIC;
route->priority = IP6_RT_PRIO_USER;
route->lifetime_usec = lifetime_usec;
if (route_get(link->manager, NULL, route, &existing) < 0)
@ -734,9 +743,13 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
r = link_request_route(link, TAKE_PTR(route), true, &link->dhcp6_messages,
dhcp6_route_handler, NULL);
if (r < 0)
if (r < 0) {
_cleanup_free_ char *buf = NULL;
(void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
return log_link_error_errno(link, r, "Failed to request unreachable route for DHCPv6 delegated subnet %s: %m",
strna(buf));
}
return 0;
}
@ -774,7 +787,7 @@ static int dhcp6_pd_prefix_add(Link *link, const struct in6_addr *prefix, uint8_
if (r < 0)
return log_link_error_errno(link, r, "Failed to store DHCPv6 PD prefix %s: %m", strna(buf));
return prefixlen <= 64;
return 0;
}
static int dhcp6_pd_assign_prefixes(Link *link, Link *uplink) {
@ -827,6 +840,7 @@ static int dhcp6_pd_assign_prefixes(Link *link, Link *uplink) {
}
int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
union in_addr_union server_address;
usec_t timestamp_usec;
Link *link;
int r;
@ -834,6 +848,10 @@ int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
assert(dhcp6_link);
assert(dhcp6_link->dhcp6_lease);
r = sd_dhcp6_lease_get_server_address(dhcp6_link->dhcp6_lease, &server_address.in6);
if (r < 0)
return log_link_warning_errno(dhcp6_link, r, "Failed to get server address of DHCPv6 lease: %m");
r = sd_dhcp6_lease_get_timestamp(dhcp6_link->dhcp6_lease, clock_boottime_or_monotonic(), &timestamp_usec);
if (r < 0)
return log_link_warning_errno(dhcp6_link, r, "Failed to get timestamp of DHCPv6 lease: %m");
@ -860,10 +878,8 @@ int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
r = dhcp6_pd_prefix_add(dhcp6_link, &pd_prefix, pd_prefix_len);
if (r < 0)
return r;
if (r == 0)
continue;
r = dhcp6_request_unreachable_route(dhcp6_link, &pd_prefix, pd_prefix_len, lifetime_valid_usec);
r = dhcp6_request_unreachable_route(dhcp6_link, &pd_prefix, pd_prefix_len, lifetime_valid_usec, &server_address);
if (r < 0)
return r;
}

View file

@ -228,7 +228,7 @@ DHCPv4.IAID, config_parse_iaid,
DHCPv4.DUIDType, config_parse_network_duid_type, 0, 0
DHCPv4.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
DHCPv4.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET, 0
DHCPv4.RouteTable, config_parse_dhcp_or_ra_route_table, (RTPROT_DHCP<<16) | AF_INET, 0
DHCPv4.RouteTable, config_parse_dhcp_or_ra_route_table, AF_INET, 0
DHCPv4.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCPv4.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port)
DHCPv4.SendRelease, config_parse_bool, 0, offsetof(Network, dhcp_send_release)
@ -257,7 +257,6 @@ DHCPv6.SendOption, config_parse_dhcp_send_option,
DHCPv6.IAID, config_parse_iaid, AF_INET6, 0
DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Network, dhcp6_duid)
DHCPv6.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Network, dhcp6_duid)
DHCPv6.RouteTable, config_parse_dhcp_or_ra_route_table, (RTPROT_DHCP<<16) | AF_INET6, 0
IPv6AcceptRA.UseGateway, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_gateway)
IPv6AcceptRA.UseRoutePrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_route_prefix)
IPv6AcceptRA.UseAutonomousPrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_autonomous_prefix)
@ -266,7 +265,7 @@ IPv6AcceptRA.UseDNS, config_parse_bool,
IPv6AcceptRA.UseDomains, config_parse_ipv6_accept_ra_use_domains, 0, offsetof(Network, ipv6_accept_ra_use_domains)
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_dhcp_or_ra_route_table, (RTPROT_RA<<16) | AF_INET6, 0
IPv6AcceptRA.RouteTable, config_parse_dhcp_or_ra_route_table, AF_INET6, 0
IPv6AcceptRA.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET6, 0
IPv6AcceptRA.RouterAllowList, config_parse_in_addr_prefixes, AF_INET6, offsetof(Network, ndisc_allow_listed_router)
IPv6AcceptRA.RouterDenyList, config_parse_in_addr_prefixes, AF_INET6, offsetof(Network, ndisc_deny_listed_router)
@ -543,7 +542,7 @@ DHCP.IAID, config_parse_iaid,
DHCP.DUIDType, config_parse_network_duid_type, 0, 0
DHCP.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
DHCP.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_UNSPEC, 0
DHCP.RouteTable, config_parse_dhcp_or_ra_route_table, (RTPROT_DHCP<<16) | AF_UNSPEC, 0
DHCP.RouteTable, config_parse_dhcp_or_ra_route_table, AF_INET, 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_warn_compat, DISABLED_LEGACY, 0

View file

@ -133,7 +133,6 @@ struct Network {
bool dhcp_route_metric_set;
uint32_t dhcp_route_table;
bool dhcp_route_table_set;
bool dhcp_route_table_set_explicitly;
uint32_t dhcp_fallback_lease_lifetime;
uint32_t dhcp_route_mtu;
uint16_t dhcp_client_port;
@ -172,9 +171,6 @@ struct Network {
bool dhcp6_use_hostname;
bool dhcp6_use_ntp;
bool dhcp6_use_ntp_set;
bool dhcp6_route_table;
bool dhcp6_route_table_set;
bool dhcp6_route_table_set_explicitly;
DHCPUseDomains dhcp6_use_domains;
bool dhcp6_use_domains_set;
uint32_t dhcp6_iaid;

View file

@ -149,7 +149,6 @@ RouteMetric=
IAID=
DUIDType=
DUIDRawData=
RouteTable=
[DHCPv6PrefixDelegation]
UplinkInterface=
SubnetId=