mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
network: make RouteTable= setting can take multiple name:number pairs in a line
Follow-up for c038ce4606
.
This commit is contained in:
parent
e3f87b07bc
commit
310eff7274
@ -72,11 +72,14 @@
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><varname>RouteTable=</varname></term>
|
<term><varname>RouteTable=</varname></term>
|
||||||
<listitem><para>Specifies the route table name. Takes a route name and table number separated with a
|
<listitem><para>Defines the route table name. Takes a whitespace-separated list of the pairs of
|
||||||
colon. (<literal><replaceable>name</replaceable>:<replaceable>integer</replaceable></literal>. The
|
route table name and number. The route table name and number in each pair are separated with a
|
||||||
route table number must be an integer in the range 1…4294967295. This setting can be specified
|
colon, i.e., <literal><replaceable>name</replaceable>:<replaceable>number</replaceable></literal>.
|
||||||
multiple times. If an empty string is specified, then all options specified earlier are cleared.
|
The route table name must not be <literal>default</literal>, <literal>main</literal>, or
|
||||||
Defaults to unset.</para></listitem>
|
<literal>local</literal>, 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.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
@ -2385,10 +2385,7 @@ int config_parse_route_table_names(
|
|||||||
void *data,
|
void *data,
|
||||||
void *userdata) {
|
void *userdata) {
|
||||||
|
|
||||||
_cleanup_free_ char *name = NULL;
|
|
||||||
Hashmap **s = data;
|
Hashmap **s = data;
|
||||||
uint32_t table;
|
|
||||||
const char *p;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
@ -2401,33 +2398,47 @@ int config_parse_route_table_names(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = rvalue;
|
for (const char *p = rvalue;;) {
|
||||||
r = extract_first_word(&p, &name, ":", 0);
|
_cleanup_free_ char *name = NULL;
|
||||||
|
uint32_t table;
|
||||||
|
char *num;
|
||||||
|
|
||||||
|
r = extract_first_word(&p, &name, NULL, 0);
|
||||||
if (r == -ENOMEM)
|
if (r == -ENOMEM)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
if (r <= 0 || isempty(p)) {
|
if (r < 0) {
|
||||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||||
"Invalid RouteTable=, ignoring assignment: %s", rvalue);
|
"Invalid RouteTable=, ignoring assignment: %s", rvalue);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (r == 0)
|
||||||
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = safe_atou32(p, &table);
|
*num++ = '\0';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = safe_atou32(num, &table);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||||
"Failed to parse RouteTable=, ignoring assignment: %s", p);
|
"Failed to parse route table number '%s', ignoring assignment: %s:%s", num, name, num);
|
||||||
return 0;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table == 0) {
|
if (table == 0) {
|
||||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||||
"Invalid RouteTable=, ignoring assignment: %s", p);
|
"Invalid route table number, ignoring assignment: %s:%s", name, num);
|
||||||
return 0;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = hashmap_ensure_put(s, &string_hash_ops, name, UINT32_TO_PTR(table));
|
r = hashmap_ensure_put(s, &string_hash_ops, name, UINT32_TO_PTR(table));
|
||||||
@ -2435,13 +2446,17 @@ int config_parse_route_table_names(
|
|||||||
return log_oom();
|
return log_oom();
|
||||||
if (r == -EEXIST) {
|
if (r == -EEXIST) {
|
||||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||||
"Specified RouteTable= name and value pair conflicts with others, ignoring assignment: %s", rvalue);
|
"Specified route table name and number pair conflicts with others, ignoring assignment: %s:%s", name, num);
|
||||||
return 0;
|
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)
|
if (r > 0)
|
||||||
TAKE_PTR(name);
|
TAKE_PTR(name);
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int route_section_verify(Route *route, Network *network) {
|
static int route_section_verify(Route *route, Network *network) {
|
||||||
|
Loading…
Reference in New Issue
Block a user