network: refuse to override predefined route table name

This commit is contained in:
Yu Watanabe 2023-07-14 16:08:03 +09:00
parent f4defbdc5d
commit e8e91a81ee
3 changed files with 14 additions and 5 deletions

View File

@ -89,9 +89,10 @@
colon, i.e., <literal><replaceable>name</replaceable>:<replaceable>number</replaceable></literal>.
The route table name must not be <literal>default</literal>, <literal>main</literal>, or
<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>
254, and 255, respectively. The route table number must be an integer in the range 1…4294967295,
except for predefined numbers 253, 254, and 255. 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>

View File

@ -501,9 +501,10 @@ int config_parse_route_table_names(
"Route table name cannot be numeric. Ignoring assignment: %s:%s", name, num);
continue;
}
if (STR_IN_SET(name, "default", "main", "local")) {
if (route_table_from_string(name) >= 0) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Route table name %s is already predefined. Ignoring assignment: %s:%s", name, name, num);
"Route table name %s is predefined for %i. Ignoring assignment: %s:%s",
name, route_table_from_string(name), name, num);
continue;
}
@ -518,6 +519,12 @@ int config_parse_route_table_names(
"Invalid route table number, ignoring assignment: %s:%s", name, num);
continue;
}
if (route_table_to_string(table)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Route table name for %s is predefined (%s). Ignoring assignment: %s:%s",
num, route_table_to_string(table), name, num);
continue;
}
r = hashmap_ensure_put(&m->route_table_numbers_by_name, &string_hash_ops_free, name, UINT32_TO_PTR(table));
if (r == -ENOMEM)

View File

@ -153,6 +153,7 @@ static void test_route_tables(Manager *manager) {
/* Invalid pairs */
assert_se(config_parse_route_table_names("manager", "filename", 1, "section", 1, "RouteTable", 0, "main:123 default:333 local:999", manager, manager) >= 0);
assert_se(config_parse_route_table_names("manager", "filename", 1, "section", 1, "RouteTable", 0, "xxx:253 yyy:254 local:255", manager, manager) >= 0);
assert_se(config_parse_route_table_names("manager", "filename", 1, "section", 1, "RouteTable", 0, "1234:321 :567 hoge:foo aaa:-888", manager, manager) >= 0);
assert_se(!manager->route_table_names_by_number);
assert_se(!manager->route_table_numbers_by_name);