From: Yu Watanabe Date: Sun, 7 Jul 2019 00:40:17 +0000 (+0900) Subject: network: make Route.Type= support local, broadcast, anycast, multicast, nat, and... X-Git-Tag: v243-rc1~143^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94d6e299637db582f156612af32f167643caf4c9;p=thirdparty%2Fsystemd.git network: make Route.Type= support local, broadcast, anycast, multicast, nat, and xresolve Closes #12975. --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 612450dbd8c..70abb14c450 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -1232,7 +1232,11 @@ Type= - Specifies the type for the route. If unicast, a regular route is defined, i.e. a + Specifies the type for the route. Takes one of unicast, + local, broadcast, anycast, + multicast, blackhole, unreachable, + prohibit, throw, nat, and + xresolve. If unicast, a regular route is defined, i.e. a route indicating the path to take to a destination network address. If blackhole, packets to the defined route are discarded silently. If unreachable, packets to the defined route are discarded and the ICMP message "Host Unreachable" is generated. If prohibit, packets diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 618d2508995..f13214c5ee6 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 e7bd61eb9ec..2f0d052325e 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;