mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 20:40:21 +01:00
libnm: accept special table names for policy-routing
The tables "main", "local", and "default" have well known names.
Accept them as aliases when parsing the string representation of
the rule.
Note that iproute2 also considers /etc/iproute2/rt_tables for table
names. In particular, that allows a user to re-map the well-known names
like "main" to a different table. We never honor that file, and "main"
always means table 254.
Note that this only affects how we parse the string representation for
rules. As the representation is neither unique nor enforced to be normalized,
being more graceful here is no problem.
The point is of course that the user possibly has existing iproute2
scripts that use such keyword. This makes it simpler to copy & paste
the rule.
(cherry picked from commit 70b23c7979)
This commit is contained in:
parent
747021681b
commit
a55467a334
1 changed files with 12 additions and 3 deletions
|
|
@ -2994,7 +2994,8 @@ nm_ip_routing_rule_from_string (const char *str,
|
|||
* Of course, valid rules can be converted to string and read back the same (round-trip).
|
||||
*
|
||||
* - iproute2 in may regards is flexible about the command lines. For example
|
||||
* - for tables it accepts table names from /etc/iproute2/rt_tables
|
||||
* - for tables it accepts table names from /etc/iproute2/rt_tables. We only
|
||||
* accept the special aliases "main", "local", and "default".
|
||||
* - key names like "preference" can be abbreviated to "prefe", we don't do that.
|
||||
* - the "preference"/"priority" may be unspecified, in which kernel automatically
|
||||
* chooses an unused priority (during `ip rule add`). We don't allow for that, the
|
||||
|
|
@ -3074,8 +3075,16 @@ nm_ip_routing_rule_from_string (const char *str,
|
|||
if (i64_table != -1)
|
||||
goto next_fail_word0_duplicate_key;
|
||||
i64_table = _nm_utils_ascii_str_to_int64 (word1, 0, 1, G_MAXUINT32, -1);
|
||||
if (i64_table == -1)
|
||||
goto next_fail_word1_invalid_value;
|
||||
if (i64_table == -1) {
|
||||
if (nm_streq (word1, "main"))
|
||||
i64_table = RT_TABLE_MAIN;
|
||||
else if (nm_streq (word1, "local"))
|
||||
i64_table = RT_TABLE_LOCAL;
|
||||
else if (nm_streq (word1, "default"))
|
||||
i64_table = RT_TABLE_DEFAULT;
|
||||
else
|
||||
goto next_fail_word1_invalid_value;
|
||||
}
|
||||
goto next_words_consumed;
|
||||
}
|
||||
if (NM_IN_STRSET (word0, "tos",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue