]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: honor VRF table or explicitly specified route table
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Feb 2019 03:49:45 +0000 (12:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 15 Feb 2019 02:45:39 +0000 (11:45 +0900)
src/network/networkd-dhcp4.c
src/network/networkd-dhcp6.c
src/network/networkd-ipv4ll.c
src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-ndisc.c

index ea5dab3858cfa3d68b3286f61d0cca6a88045383..ace8b254d1484053ea83b6dfd876721aa3ca7922 100644 (file)
@@ -6,7 +6,6 @@
 #include "alloc-util.h"
 #include "hostname-util.h"
 #include "parse-util.h"
-#include "netdev/vrf.h"
 #include "network-internal.h"
 #include "networkd-link.h"
 #include "networkd-manager.h"
@@ -67,11 +66,7 @@ static int link_set_dhcp_routes(Link *link) {
         if (!link->network->dhcp_use_routes)
                 return 0;
 
-        /* When the interface is part of an VRF use the VRFs routing table, unless
-         * there is a another table specified. */
-        table = link->network->dhcp_route_table;
-        if (!link->network->dhcp_route_table_set && link->network->vrf)
-                table = VRF(link->network->vrf)->table;
+        table = link_get_dhcp_route_table(link);
 
         r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
         if (r < 0)
index c1fba03f9fe3457e000befdb6b347181494719d3..183b3fa97fd92badc72e380e1857367cd87bd763 100644 (file)
@@ -289,6 +289,7 @@ static int dhcp6_lease_pd_prefix_acquired(sd_dhcp6_client *client, Link *link) {
 
                 if (pd_prefix_len < 64) {
                         Route *route = NULL;
+                        uint32_t table;
 
                         (void) in_addr_to_string(AF_INET6, &pd_prefix, &buf);
 
@@ -300,8 +301,10 @@ static int dhcp6_lease_pd_prefix_acquired(sd_dhcp6_client *client, Link *link) {
                                 continue;
                         }
 
+                        table = link_get_dhcp_route_table(link);
+
                         route_add(link, AF_INET6, &pd_prefix, pd_prefix_len,
-                                  0, 0, 0, &route);
+                                  0, 0, table, &route);
                         route_update(route, NULL, 0, NULL, NULL, 0, 0,
                                      RTN_UNREACHABLE);
 
index 3562e90535ddce1f5ea1736060a109d8581e06e3..56a4ff8b8532f7ef6580937f99486973712ada63 100644 (file)
@@ -134,6 +134,7 @@ static int ipv4ll_address_claimed(sd_ipv4ll *ll, Link *link) {
         route->scope = RT_SCOPE_LINK;
         route->protocol = RTPROT_STATIC;
         route->priority = IPV4LL_ROUTE_METRIC;
+        route->table = link_get_vrf_table(link);
 
         r = route_configure(route, link, ipv4ll_route_handler);
         if (r < 0)
index 22392d70bc4790ca1e32851c03cb395dd3b45059..24946b1df82f149c85834ef9464bf511ab12bfaa 100644 (file)
@@ -14,6 +14,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "missing_network.h"
+#include "netdev/vrf.h"
 #include "netlink-util.h"
 #include "network-internal.h"
 #include "networkd-ipv6-proxy-ndp.h"
 #include "util.h"
 #include "virt.h"
 
+uint32_t link_get_vrf_table(Link *link) {
+        return link->network->vrf ? VRF(link->network->vrf)->table : RT_TABLE_MAIN;
+}
+
+uint32_t link_get_dhcp_route_table(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(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);
+}
+
 DUID* link_get_duid(Link *link) {
         if (link->network->duid.type != _DUID_TYPE_INVALID)
                 return &link->network->duid;
index dcb1ea68dd987ae5ad170dbdc298edb38a2bdb73..344873f303ff58a2acd88d3ff376b4a47890a47b 100644 (file)
@@ -185,6 +185,10 @@ int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
 int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
 int link_send_changed(Link *link, const char *property, ...) _sentinel_;
 
+uint32_t link_get_vrf_table(Link *link);
+uint32_t link_get_dhcp_route_table(Link *link);
+uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
+
 /* Macros which append INTERFACE= to the message */
 
 #define log_link_full(link, level, error, ...)                          \
index e5b8d115551b71f2edb57eb5978087fc1d778544..8fcb4851c44dcf8bff9c5f88b664c1d7c976208e 100644 (file)
@@ -103,7 +103,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
                 return log_link_error_errno(link, r, "Could not allocate route: %m");
 
         route->family = AF_INET6;
-        route->table = link->network->ipv6_accept_ra_route_table;
+        route->table = link_get_ipv6_accept_ra_route_table(link);
         route->priority = link->network->dhcp_route_metric;
         route->protocol = RTPROT_RA;
         route->pref = preference;
@@ -238,7 +238,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
                 return log_link_error_errno(link, r, "Could not allocate route: %m");
 
         route->family = AF_INET6;
-        route->table = link->network->ipv6_accept_ra_route_table;
+        route->table = link_get_ipv6_accept_ra_route_table(link);
         route->priority = link->network->dhcp_route_metric;
         route->protocol = RTPROT_RA;
         route->flags = RTM_F_PREFIX;
@@ -299,7 +299,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
                 return log_link_error_errno(link, r, "Could not allocate route: %m");
 
         route->family = AF_INET6;
-        route->table = link->network->ipv6_accept_ra_route_table;
+        route->table = link_get_ipv6_accept_ra_route_table(link);
         route->protocol = RTPROT_RA;
         route->pref = preference;
         route->gw.in6 = gateway;