From: Yu Watanabe Date: Wed, 20 Jan 2021 05:33:21 +0000 (+0900) Subject: network: make RouteTable= setting can take multiple name:number pairs in a line X-Git-Tag: v248-rc1~198^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=310eff72744b49b50992c945852f3ce262540cfc;p=thirdparty%2Fsystemd.git network: make RouteTable= setting can take multiple name:number pairs in a line Follow-up for c038ce4606f93d9e58147f87703125270fb744e2. --- diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml index 12ddcf45026..dcce2095edd 100644 --- a/man/networkd.conf.xml +++ b/man/networkd.conf.xml @@ -72,11 +72,14 @@ RouteTable= - Specifies the route table name. Takes a route name and table number separated with a - colon. (name:integer. The - route table number must be an integer in the range 1…4294967295. This setting can be specified - multiple times. If an empty string is specified, then all options specified earlier are cleared. - Defaults to unset. + Defines the route table name. Takes a whitespace-separated list of the pairs of + route table name and number. The route table name and number in each pair are separated with a + colon, i.e., name:number. + The route table name must not be default, main, or + local, as these route table names are predefined with route table number 253, + 254, and 255, respectively. The route table number must be an integer in the range 1…4294967295. + This setting can be specified multiple times. If an empty string is specified, then the list + specified earlier are cleared. Defaults to unset. diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index cfb9befc614..ed6a846e159 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -2385,10 +2385,7 @@ int config_parse_route_table_names( void *data, void *userdata) { - _cleanup_free_ char *name = NULL; Hashmap **s = data; - uint32_t table; - const char *p; int r; assert(filename); @@ -2401,47 +2398,65 @@ int config_parse_route_table_names( return 0; } - p = rvalue; - r = extract_first_word(&p, &name, ":", 0); - if (r == -ENOMEM) - return log_oom(); - if (r <= 0 || isempty(p)) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Invalid RouteTable=, ignoring assignment: %s", rvalue); - return 0; - } + for (const char *p = rvalue;;) { + _cleanup_free_ char *name = NULL; + uint32_t table; + char *num; - if (STR_IN_SET(name, "default", "main","local")) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Route table name %s already preconfigured. Ignoring assignment: %s", name, rvalue); - return 0; - } + r = extract_first_word(&p, &name, NULL, 0); + if (r == -ENOMEM) + return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid RouteTable=, ignoring assignment: %s", rvalue); + return 0; + } + if (r == 0) + return 0; - r = safe_atou32(p, &table); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse RouteTable=, ignoring assignment: %s", p); - return 0; - } + num = strchr(name, ':'); + if (!num) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid route table name and number pair, ignoring assignment: %s", name); + continue; + } - if (table == 0) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Invalid RouteTable=, ignoring assignment: %s", p); - return 0; - } + *num++ = '\0'; - r = hashmap_ensure_put(s, &string_hash_ops, name, UINT32_TO_PTR(table)); - if (r == -ENOMEM) - return log_oom(); - if (r == -EEXIST) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Specified RouteTable= name and value pair conflicts with others, ignoring assignment: %s", rvalue); - return 0; - } - if (r > 0) - TAKE_PTR(name); + if (STR_IN_SET(name, "default", "main", "local")) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Route table name %s already predefined. Ignoring assignment: %s:%s", name, name, num); + continue; + } - return 0; + r = safe_atou32(num, &table); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse route table number '%s', ignoring assignment: %s:%s", num, name, num); + continue; + } + if (table == 0) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid route table number, ignoring assignment: %s:%s", name, num); + continue; + } + + r = hashmap_ensure_put(s, &string_hash_ops, name, UINT32_TO_PTR(table)); + if (r == -ENOMEM) + return log_oom(); + if (r == -EEXIST) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Specified route table name and number pair conflicts with others, ignoring assignment: %s:%s", name, num); + continue; + } + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to store route table name and number pair, ignoring assignment: %s:%s", name, num); + continue; + } + if (r > 0) + TAKE_PTR(name); + } } static int route_section_verify(Route *route, Network *network) {