diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 48326a25c1..52043789ed 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2111,6 +2111,7 @@ IPv6Token=prefixstable:2002:da8:1:: + RouteMetric= UseDNS= UseNTP= UseHostname= diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c index 25725f4f28..8138c4eda7 100644 --- a/src/network/networkd-dhcp-common.c +++ b/src/network/networkd-dhcp-common.c @@ -18,6 +18,44 @@ #include "socket-util.h" #include "string-table.h" #include "strv.h" +#include "vrf.h" + +static uint32_t link_get_vrf_table(Link *link) { + assert(link); + assert(link->network); + + return link->network->vrf ? VRF(link->network->vrf)->table : RT_TABLE_MAIN; +} + +uint32_t link_get_dhcp4_route_table(Link *link) { + assert(link); + assert(link->network); + + /* When the interface is part of an VRF use the VRFs routing table, unless + * another table is explicitly specified. */ + + if (link->network->dhcp_route_table_set) + return link->network->dhcp_route_table; + 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); + + if (link->network->ipv6_accept_ra_route_table_set) + return link->network->ipv6_accept_ra_route_table; + return link_get_vrf_table(link); +} bool link_dhcp_enabled(Link *link, int family) { assert(link); @@ -272,7 +310,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 +328,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 +339,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 +379,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 +390,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 +430,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 +441,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 +481,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,23 +492,30 @@ 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; } -int config_parse_section_route_table( +int config_parse_dhcp_or_ra_route_table( const char *unit, const char *filename, unsigned line, @@ -463,6 +533,11 @@ int config_parse_section_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(rvalue); assert(data); @@ -473,12 +548,34 @@ int config_parse_section_route_table( return 0; } - if (STRPTR_IN_SET(section, "DHCP", "DHCPv4")) { + switch(ltype) { + case (RTPROT_DHCP<<16) | AF_INET: network->dhcp_route_table = rt; network->dhcp_route_table_set = true; - } else { /* section is IPv6AcceptRA */ + 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: network->ipv6_accept_ra_route_table = rt; network->ipv6_accept_ra_route_table_set = true; + break; + default: + assert_not_reached(); } return 0; diff --git a/src/network/networkd-dhcp-common.h b/src/network/networkd-dhcp-common.h index 236640e9e0..faabe5430a 100644 --- a/src/network/networkd-dhcp-common.h +++ b/src/network/networkd-dhcp-common.h @@ -44,6 +44,10 @@ typedef struct DUID { bool set; } 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); static inline bool link_dhcp4_enabled(Link *link) { return link_dhcp_enabled(link, AF_INET); @@ -80,12 +84,12 @@ 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); CONFIG_PARSER_PROTOTYPE(config_parse_iaid); -CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table); +CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_table); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options); diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index dcc16e0a5d..247416a750 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -135,6 +135,26 @@ static int dhcp4_after_route_configure(Request *req, void *object) { return 0; } +static int dhcp4_retry(Link *link) { + int r; + + assert(link); + + r = dhcp4_remove_all(link); + if (r < 0) + return r; + + r = link_request_static_nexthops(link, true); + if (r < 0) + return r; + + r = link_request_static_routes(link, true); + if (r < 0) + return r; + + return dhcp4_request_address_and_routes(link, false); +} + static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { int r; @@ -165,19 +185,7 @@ static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li link->dhcp4_route_failed = false; link->dhcp4_route_retrying = true; - r = dhcp4_remove_all(link); - if (r < 0) - link_enter_failed(link); - - r = link_request_static_nexthops(link, true); - if (r < 0) - link_enter_failed(link); - - r = link_request_static_routes(link, true); - if (r < 0) - link_enter_failed(link); - - r = dhcp4_request_address_and_routes(link, false); + r = dhcp4_retry(link); if (r < 0) link_enter_failed(link); @@ -197,6 +205,16 @@ static int dhcp4_request_route(Route *in, Link *link) { assert(route); assert(link); + route->family = AF_INET; + if (!route->protocol_set) + route->protocol = RTPROT_DHCP; + if (!route->priority_set) + route->priority = link->network->dhcp_route_metric; + if (!route->table_set) + route->table = link_get_dhcp4_route_table(link); + if (route->mtu == 0) + route->mtu = link->network->dhcp_route_mtu; + r = link_has_route(link, route); if (r < 0) return r; @@ -243,14 +261,10 @@ static int dhcp4_request_prefix_route(Link *link) { if (r < 0) return r; - route->family = AF_INET; route->dst.in.s_addr = address.s_addr & netmask.s_addr; route->dst_prefixlen = in4_addr_netmask_to_prefixlen(&netmask); route->prefsrc.in = address; route->scope = RT_SCOPE_LINK; - route->protocol = RTPROT_DHCP; - route->table = link_get_dhcp_route_table(link); - route->mtu = link->network->dhcp_route_mtu; return dhcp4_request_route(TAKE_PTR(route), link); } @@ -272,15 +286,10 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw) if (r < 0) return r; - route->family = AF_INET; route->dst.in = *gw; route->dst_prefixlen = 32; route->prefsrc.in = address; route->scope = RT_SCOPE_LINK; - route->protocol = RTPROT_DHCP; - route->priority = link->network->dhcp_route_metric; - route->table = link_get_dhcp_route_table(link); - route->mtu = link->network->dhcp_route_mtu; return dhcp4_request_route(TAKE_PTR(route), link); } @@ -454,12 +463,7 @@ static int dhcp4_request_static_routes(Link *link, struct in_addr *ret_default_g if (r < 0) return r; - route->family = AF_INET; route->gw_family = AF_INET; - route->protocol = RTPROT_DHCP; - route->priority = link->network->dhcp_route_metric; - route->table = link_get_dhcp_route_table(link); - route->mtu = link->network->dhcp_route_mtu; r = sd_dhcp_route_get_gateway(static_routes[i], &gw); if (r < 0) @@ -537,14 +541,9 @@ static int dhcp4_request_gateway(Link *link, struct in_addr *gw) { return r; /* Next, add a default gateway. */ - route->family = AF_INET; route->gw_family = AF_INET; route->gw.in = router[0]; route->prefsrc.in = address; - route->protocol = RTPROT_DHCP; - route->priority = link->network->dhcp_route_metric; - route->table = link_get_dhcp_route_table(link); - route->mtu = link->network->dhcp_route_mtu; r = dhcp4_request_route(TAKE_PTR(route), link); if (r < 0) @@ -586,14 +585,6 @@ static int dhcp4_request_semi_static_routes(Link *link, const struct in_addr *gw return r; route->gw.in = *gw; - if (!route->protocol_set) - route->protocol = RTPROT_DHCP; - if (!route->priority_set) - route->priority = link->network->dhcp_route_metric; - if (!route->table_set) - route->table = link_get_dhcp_route_table(link); - if (route->mtu == 0) - route->mtu = link->network->dhcp_route_mtu; r = dhcp4_request_route(TAKE_PTR(route), link); if (r < 0) @@ -627,13 +618,8 @@ static int dhcp4_request_routes_to_servers( if (r < 0) return r; - route->family = AF_INET; route->dst.in = servers[i]; route->dst_prefixlen = 32; - route->protocol = RTPROT_DHCP; - route->priority = link->network->dhcp_route_metric; - route->table = link_get_dhcp_route_table(link); - route->mtu = link->network->dhcp_route_mtu; r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw); if (r < 0) @@ -923,7 +909,7 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link * static int dhcp4_request_address(Link *link, bool announce) { _cleanup_(address_freep) Address *addr = NULL; uint32_t lifetime = CACHE_INFO_INFINITY_LIFE_TIME; - struct in_addr address, netmask; + struct in_addr address, netmask, server; unsigned prefixlen; Request *req; int r; @@ -942,6 +928,10 @@ static int dhcp4_request_address(Link *link, bool announce) { if (r < 0) return log_link_warning_errno(link, r, "DHCP error: no netmask: %m"); + r = sd_dhcp_lease_get_server_identifier(link->dhcp_lease, &server); + if (r < 0) + return log_link_debug_errno(link, r, "DHCP error: failed to get DHCP server IP address: %m"); + if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) { r = sd_dhcp_lease_get_lifetime(link->dhcp_lease, &lifetime); if (r < 0) @@ -960,19 +950,21 @@ static int dhcp4_request_address(Link *link, bool announce) { if (r > 0 && in4_addr_is_set(&router[0])) log_struct(LOG_INFO, LOG_LINK_INTERFACE(link), - LOG_LINK_MESSAGE(link, "DHCPv4 address "IPV4_ADDRESS_FMT_STR"/%u via "IPV4_ADDRESS_FMT_STR, + LOG_LINK_MESSAGE(link, "DHCPv4 address "IPV4_ADDRESS_FMT_STR"/%u, gateway "IPV4_ADDRESS_FMT_STR" acquired from "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(address), prefixlen, - IPV4_ADDRESS_FMT_VAL(router[0])), + IPV4_ADDRESS_FMT_VAL(router[0]), + IPV4_ADDRESS_FMT_VAL(server)), "ADDRESS="IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(address), "PREFIXLEN=%u", prefixlen, "GATEWAY="IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(router[0])); else log_struct(LOG_INFO, LOG_LINK_INTERFACE(link), - LOG_LINK_MESSAGE(link, "DHCPv4 address "IPV4_ADDRESS_FMT_STR"/%u", + LOG_LINK_MESSAGE(link, "DHCPv4 address "IPV4_ADDRESS_FMT_STR"/%u acquired from "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(address), - prefixlen), + prefixlen, + IPV4_ADDRESS_FMT_VAL(server)), "ADDRESS="IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(address), "PREFIXLEN=%u", prefixlen); } @@ -992,11 +984,9 @@ static int dhcp4_request_address(Link *link, bool announce) { addr->route_metric = link->network->dhcp_route_metric; addr->duplicate_address_detection = link->network->dhcp_send_decline ? ADDRESS_FAMILY_IPV4 : ADDRESS_FAMILY_NO; - if (link->network->dhcp_label) { - addr->label = strdup(link->network->dhcp_label); - if (!addr->label) - return log_oom(); - } + r = free_and_strdup_warn(&addr->label, link->network->dhcp_label); + if (r < 0) + return r; if (address_get(link, addr, NULL) < 0) link->dhcp4_configured = false; diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 2f755bc4eb..824047fcc1 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -874,7 +874,7 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad route->family = AF_INET6; route->dst.in6 = *addr; route->dst_prefixlen = prefixlen; - route->table = link_get_dhcp_route_table(link); + route->table = link_get_dhcp6_route_table(link); route->type = RTN_UNREACHABLE; route->protocol = RTPROT_DHCP; diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 1c796486a1..866ea89007 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -403,6 +403,13 @@ static int ndisc_request_route(Route *in, Link *link, sd_ndisc_router *rt) { assert(link); assert(rt); + if (!route->table_set) + route->table = link_get_ipv6_accept_ra_route_table(link); + if (!route->priority_set) + route->priority = link->network->ipv6_accept_ra_route_metric; + if (!route->protocol_set) + route->protocol = RTPROT_RA; + r = link_has_route(link, route); if (r < 0) return r; @@ -536,7 +543,7 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) { static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { _cleanup_(route_freep) Route *route = NULL; struct in6_addr gateway; - uint32_t table, mtu = 0; + uint32_t mtu = 0; unsigned preference; uint16_t lifetime; usec_t time_now; @@ -581,16 +588,11 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { return log_link_error_errno(link, r, "Failed to get default router MTU from RA: %m"); } - table = link_get_ipv6_accept_ra_route_table(link); - r = route_new(&route); if (r < 0) return log_oom(); route->family = AF_INET6; - route->table = table; - route->priority = link->network->ipv6_accept_ra_route_metric; - route->protocol = RTPROT_RA; route->pref = preference; route->gw_family = AF_INET6; route->gw.in6 = gateway; @@ -614,12 +616,6 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { return r; route->gw.in6 = gateway; - if (!route->table_set) - route->table = table; - if (!route->priority_set) - route->priority = link->network->ipv6_accept_ra_route_metric; - if (!route->protocol_set) - route->protocol = RTPROT_RA; if (!route->pref_set) route->pref = preference; route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC); @@ -878,9 +874,6 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) { return log_oom(); route->family = AF_INET6; - route->table = link_get_ipv6_accept_ra_route_table(link); - route->priority = link->network->ipv6_accept_ra_route_metric; - route->protocol = RTPROT_RA; route->flags = RTM_F_PREFIX; route->dst_prefixlen = prefixlen; route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC); @@ -961,9 +954,6 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) { return log_oom(); route->family = AF_INET6; - route->table = link_get_ipv6_accept_ra_route_table(link); - route->priority = link->network->ipv6_accept_ra_route_metric; - route->protocol = RTPROT_RA; route->pref = preference; route->gw.in6 = gateway; route->gw_family = AF_INET6; diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index ef5248fa38..b42d5ad3a4 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -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,8 +222,8 @@ 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.RouteTable, config_parse_section_route_table, 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.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) @@ -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 @@ -253,14 +253,15 @@ 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.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) 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_section_route_table, 0, 0 -IPv6AcceptRA.RouteMetric, config_parse_dhcp_route_metric, 0, 0 +IPv6AcceptRA.RouteTable, config_parse_dhcp_or_ra_route_table, (RTPROT_RA<<16) | AF_INET6, 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 +502,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 +519,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.RouteTable, config_parse_section_route_table, 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.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 diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 81d484ce53..40a52797a6 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -135,6 +135,8 @@ struct Network { uint32_t dhcp_route_metric; 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; @@ -155,7 +157,6 @@ struct Network { int dhcp_use_gateway; bool dhcp_use_timezone; bool dhcp_use_hostname; - bool dhcp_route_table_set; bool dhcp_send_release; bool dhcp_send_decline; DHCPUseDomains dhcp_use_domains; @@ -174,6 +175,9 @@ struct Network { bool dhcp6_use_ntp; bool dhcp6_use_ntp_set; bool dhcp6_rapid_commit; + 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; diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index c01f1ca14a..7c89e66ab9 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -22,24 +22,6 @@ #define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U -static uint32_t link_get_vrf_table(const Link *link) { - return link->network->vrf ? VRF(link->network->vrf)->table : RT_TABLE_MAIN; -} - -uint32_t link_get_dhcp_route_table(const Link *link) { - /* When the interface is part of an VRF use the VRFs routing table, unless - * another table is explicitly specified. */ - if (link->network->dhcp_route_table_set) - return link->network->dhcp_route_table; - return link_get_vrf_table(link); -} - -uint32_t link_get_ipv6_accept_ra_route_table(const Link *link) { - if (link->network->ipv6_accept_ra_route_table_set) - return link->network->ipv6_accept_ra_route_table; - return link_get_vrf_table(link); -} - static const char * const route_type_table[__RTN_MAX] = { [RTN_UNICAST] = "unicast", [RTN_LOCAL] = "local", diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index 235a91f08d..2e5a073a2b 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -84,9 +84,6 @@ bool gateway_is_ready(Link *link, int onlink, int family, const union in_addr_un int link_drop_routes(Link *link); int link_drop_foreign_routes(Link *link); -uint32_t link_get_dhcp_route_table(const Link *link); -uint32_t link_get_ipv6_accept_ra_route_table(const Link *link); - int link_request_route( Link *link, Route *route, diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index 71ead0df9c..fdd7f73bae 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -148,6 +148,7 @@ RouteMetric= IAID= DUIDType= DUIDRawData= +RouteTable= [DHCPv6PrefixDelegation] SubnetId= Announce=