summaryrefslogtreecommitdiff
path: root/src/network/networkd-dhcp-common.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-09-08 09:35:34 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-09-14 17:51:19 +0900
commite47bcb7d0b2cb07c5c594e374baeb061bb7f88ba (patch)
tree8d4673cf5b281a64f3f5f6d88382df512a3d33db /src/network/networkd-dhcp-common.c
parent967e6a64035df48a5449b5b11bf5fd88ed478954 (diff)
downloadsystemd-e47bcb7d0b2cb07c5c594e374baeb061bb7f88ba.tar.gz
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.
Diffstat (limited to 'src/network/networkd-dhcp-common.c')
-rw-r--r--src/network/networkd-dhcp-common.c71
1 files changed, 68 insertions, 3 deletions
diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c
index 09c242c730..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);
@@ -477,7 +515,7 @@ int config_parse_dhcp_use_ntp(
return 0;
}
-int config_parse_section_route_table(
+int config_parse_dhcp_or_ra_route_table(
const char *unit,
const char *filename,
unsigned line,
@@ -495,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);
@@ -505,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;