diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-07-07 02:40:17 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-07-12 02:39:43 +0200 |
commit | 94d6e299637db582f156612af32f167643caf4c9 (patch) | |
tree | e1013b86317d20357509ba693e12f3ef6b44b032 /src | |
parent | network: use string table to parse route type (diff) | |
download | systemd-94d6e299637db582f156612af32f167643caf4c9.tar.xz systemd-94d6e299637db582f156612af32f167643caf4c9.zip |
network: make Route.Type= support local, broadcast, anycast, multicast, nat, and xresolve
Closes #12975.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkd-route.c | 22 | ||||
-rw-r--r-- | src/network/networkd-route.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 618d250899..f13214c5ee 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -719,6 +719,8 @@ int network_add_ipv4ll_route(Network *network) { n->family = AF_INET; n->dst_prefixlen = 16; n->scope = RT_SCOPE_LINK; + n->scope_set = true; + n->table_set = true; n->priority = IPV4LL_ROUTE_METRIC; n->protocol = RTPROT_STATIC; @@ -752,10 +754,16 @@ int network_add_default_route_on_device(Network *network) { static const char * const route_type_table[__RTN_MAX] = { [RTN_UNICAST] = "unicast", + [RTN_LOCAL] = "local", + [RTN_BROADCAST] = "broadcast", + [RTN_ANYCAST] = "anycast", + [RTN_MULTICAST] = "multicast", [RTN_BLACKHOLE] = "blackhole", [RTN_UNREACHABLE] = "unreachable", [RTN_PROHIBIT] = "prohibit", [RTN_THROW] = "throw", + [RTN_NAT] = "nat", + [RTN_XRESOLVE] = "xresolve", }; assert_cc(__RTN_MAX <= UCHAR_MAX); @@ -971,6 +979,7 @@ int config_parse_route_scope( return 0; } + n->scope_set = true; TAKE_PTR(n); return 0; } @@ -1008,6 +1017,7 @@ int config_parse_route_table( return 0; } + n->table_set = true; TAKE_PTR(n); return 0; } @@ -1371,6 +1381,18 @@ int route_section_verify(Route *route, Network *network) { route->section->filename, route->section->line); } + if (route->family != AF_INET6) { + if (!route->table_set && IN_SET(route->type, RTN_LOCAL, RTN_BROADCAST, RTN_ANYCAST, RTN_NAT)) + route->table = RT_TABLE_LOCAL; + + if (!route->scope_set) { + if (IN_SET(route->type, RTN_LOCAL, RTN_NAT)) + route->scope = RT_SCOPE_HOST; + else if (IN_SET(route->type, RTN_BROADCAST, RTN_ANYCAST)) + route->scope = RT_SCOPE_LINK; + } + } + if (network->n_static_addresses == 0 && in_addr_is_null(route->family, &route->gw) == 0 && route->gateway_onlink < 0) { diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index e7bd61eb9e..2f0d052325 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -23,11 +23,13 @@ struct Route { unsigned char dst_prefixlen; unsigned char src_prefixlen; unsigned char scope; + bool scope_set; unsigned char protocol; /* RTPROT_* */ unsigned char type; /* RTN_* */ unsigned char tos; uint32_t priority; /* note that ip(8) calls this 'metric' */ uint32_t table; + bool table_set; uint32_t mtu; uint32_t initcwnd; uint32_t initrwnd; |