From bdb9f580868906383d200bed1bb827647cb65a37 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 12 Feb 2019 12:49:45 +0900 Subject: [PATCH] network: honor VRF table or explicitly specified route table --- src/network/networkd-dhcp4.c | 7 +------ src/network/networkd-dhcp6.c | 5 ++++- src/network/networkd-ipv4ll.c | 1 + src/network/networkd-link.c | 19 +++++++++++++++++++ src/network/networkd-link.h | 4 ++++ src/network/networkd-ndisc.c | 6 +++--- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index ea5dab3..ace8b25 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -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) diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index c1fba03..183b3fa 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -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); diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c index 3562e90..56a4ff8 100644 --- a/src/network/networkd-ipv4ll.c +++ b/src/network/networkd-ipv4ll.c @@ -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) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 22392d7..24946b1 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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" @@ -32,6 +33,24 @@ #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; diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index dcb1ea6..344873f 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -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, ...) \ diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index e5b8d11..8fcb485 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -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; -- 2.7.4