network: do not use RouteTable= in [DHCPv4] section for DHCPv6 routes

We forgot to add RouteTable= in [DHCPv6] section when we split [DHCP]
into two.
This commit is contained in:
Yu Watanabe 2021-09-08 09:35:34 +09:00
parent 967e6a6403
commit e47bcb7d0b
10 changed files with 86 additions and 31 deletions

View file

@ -2111,6 +2111,7 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>RouteMetric=</varname></term>
<term><varname>UseDNS=</varname></term> <term><varname>UseDNS=</varname></term>
<term><varname>UseNTP=</varname></term> <term><varname>UseNTP=</varname></term>
<term><varname>UseHostname=</varname></term> <term><varname>UseHostname=</varname></term>

View file

@ -18,6 +18,44 @@
#include "socket-util.h" #include "socket-util.h"
#include "string-table.h" #include "string-table.h"
#include "strv.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) { bool link_dhcp_enabled(Link *link, int family) {
assert(link); assert(link);
@ -477,7 +515,7 @@ int config_parse_dhcp_use_ntp(
return 0; return 0;
} }
int config_parse_section_route_table( int config_parse_dhcp_or_ra_route_table(
const char *unit, const char *unit,
const char *filename, const char *filename,
unsigned line, unsigned line,
@ -495,6 +533,11 @@ int config_parse_section_route_table(
assert(filename); assert(filename);
assert(lvalue); 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(rvalue);
assert(data); assert(data);
@ -505,12 +548,34 @@ int config_parse_section_route_table(
return 0; 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 = rt;
network->dhcp_route_table_set = true; 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 = rt;
network->ipv6_accept_ra_route_table_set = true; network->ipv6_accept_ra_route_table_set = true;
break;
default:
assert_not_reached();
} }
return 0; return 0;

View file

@ -44,6 +44,10 @@ typedef struct DUID {
bool set; bool set;
} 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); bool link_dhcp_enabled(Link *link, int family);
static inline bool link_dhcp4_enabled(Link *link) { static inline bool link_dhcp4_enabled(Link *link) {
return link_dhcp_enabled(link, AF_INET); return link_dhcp_enabled(link, AF_INET);
@ -85,7 +89,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp);
CONFIG_PARSER_PROTOTYPE(config_parse_iaid); 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_user_or_vendor_class);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);

View file

@ -211,7 +211,7 @@ static int dhcp4_request_route(Route *in, Link *link) {
if (!route->priority_set) if (!route->priority_set)
route->priority = link->network->dhcp_route_metric; route->priority = link->network->dhcp_route_metric;
if (!route->table_set) if (!route->table_set)
route->table = link_get_dhcp_route_table(link); route->table = link_get_dhcp4_route_table(link);
if (route->mtu == 0) if (route->mtu == 0)
route->mtu = link->network->dhcp_route_mtu; route->mtu = link->network->dhcp_route_mtu;

View file

@ -874,7 +874,7 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
route->family = AF_INET6; route->family = AF_INET6;
route->dst.in6 = *addr; route->dst.in6 = *addr;
route->dst_prefixlen = prefixlen; 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->type = RTN_UNREACHABLE;
route->protocol = RTPROT_DHCP; route->protocol = RTPROT_DHCP;

View file

@ -223,7 +223,7 @@ DHCPv4.IAID, config_parse_iaid,
DHCPv4.DUIDType, config_parse_network_duid_type, 0, 0 DHCPv4.DUIDType, config_parse_network_duid_type, 0, 0
DHCPv4.DUIDRawData, config_parse_network_duid_rawdata, 0, 0 DHCPv4.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
DHCPv4.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET, 0 DHCPv4.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_INET, 0
DHCPv4.RouteTable, config_parse_section_route_table, 0, 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.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCPv4.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port) DHCPv4.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port)
DHCPv4.SendRelease, config_parse_bool, 0, offsetof(Network, dhcp_send_release) DHCPv4.SendRelease, config_parse_bool, 0, offsetof(Network, dhcp_send_release)
@ -253,13 +253,14 @@ DHCPv6.SendOption, config_parse_dhcp_send_option,
DHCPv6.IAID, config_parse_iaid, AF_INET6, 0 DHCPv6.IAID, config_parse_iaid, AF_INET6, 0
DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Network, dhcp6_duid) DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Network, dhcp6_duid)
DHCPv6.DUIDRawData, config_parse_duid_rawdata, 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.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.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.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.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.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.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.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.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.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.RouterDenyList, config_parse_address_filter, AF_INET6, offsetof(Network, ndisc_deny_listed_router)
@ -519,7 +520,7 @@ DHCP.IAID, config_parse_iaid,
DHCP.DUIDType, config_parse_network_duid_type, 0, 0 DHCP.DUIDType, config_parse_network_duid_type, 0, 0
DHCP.DUIDRawData, config_parse_network_duid_rawdata, 0, 0 DHCP.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
DHCP.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_UNSPEC, 0 DHCP.RouteMetric, config_parse_dhcp_or_ra_route_metric, AF_UNSPEC, 0
DHCP.RouteTable, config_parse_section_route_table, 0, 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.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCP.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port) DHCP.ListenPort, config_parse_uint16, 0, offsetof(Network, dhcp_client_port)
DHCP.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_rapid_commit) DHCP.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_rapid_commit)

View file

@ -135,6 +135,8 @@ struct Network {
uint32_t dhcp_route_metric; uint32_t dhcp_route_metric;
bool dhcp_route_metric_set; bool dhcp_route_metric_set;
uint32_t dhcp_route_table; 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_fallback_lease_lifetime;
uint32_t dhcp_route_mtu; uint32_t dhcp_route_mtu;
uint16_t dhcp_client_port; uint16_t dhcp_client_port;
@ -155,7 +157,6 @@ struct Network {
int dhcp_use_gateway; int dhcp_use_gateway;
bool dhcp_use_timezone; bool dhcp_use_timezone;
bool dhcp_use_hostname; bool dhcp_use_hostname;
bool dhcp_route_table_set;
bool dhcp_send_release; bool dhcp_send_release;
bool dhcp_send_decline; bool dhcp_send_decline;
DHCPUseDomains dhcp_use_domains; DHCPUseDomains dhcp_use_domains;
@ -174,6 +175,9 @@ struct Network {
bool dhcp6_use_ntp; bool dhcp6_use_ntp;
bool dhcp6_use_ntp_set; bool dhcp6_use_ntp_set;
bool dhcp6_rapid_commit; bool dhcp6_rapid_commit;
bool dhcp6_route_table;
bool dhcp6_route_table_set;
bool dhcp6_route_table_set_explicitly;
DHCPUseDomains dhcp6_use_domains; DHCPUseDomains dhcp6_use_domains;
bool dhcp6_use_domains_set; bool dhcp6_use_domains_set;
uint32_t dhcp6_iaid; uint32_t dhcp6_iaid;

View file

@ -22,24 +22,6 @@
#define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U #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] = { static const char * const route_type_table[__RTN_MAX] = {
[RTN_UNICAST] = "unicast", [RTN_UNICAST] = "unicast",
[RTN_LOCAL] = "local", [RTN_LOCAL] = "local",

View file

@ -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_routes(Link *link);
int link_drop_foreign_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( int link_request_route(
Link *link, Link *link,
Route *route, Route *route,

View file

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