network: honor VRF table or explicitly specified route table

This commit is contained in:
Yu Watanabe 2019-02-12 12:49:45 +09:00
parent d5fa333960
commit bdb9f58086
6 changed files with 32 additions and 10 deletions

View 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)

View 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);

View 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)

View 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"
@ -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;

View 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, ...) \

View 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;