nmcli: team: do strict checking on runner-tx-hashes
Substrings matching the heading of valid values were allowed if not ambiguous (e.g.: "et" for "eth"). Moreover, upper case variants were accepted too. Do a plain string comparison check against the valid values. Improve also the error message: give a list of valid tx-hashes.
This commit is contained in:
@@ -3940,12 +3940,19 @@ _validate_fcn_team_config (const char *value, char **out_to_free, GError **error
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_is_valid_team_runner_tx_hash_element (const char *tx_hash_element)
|
||||
_is_valid_team_runner_tx_hash_element (const char *tx_hash_element,
|
||||
GError **error)
|
||||
{
|
||||
const char *valid_tx_hashes[] = { "eth", "vlan", "ipv4", "ipv6", "ip",
|
||||
"l3", "tcp", "udp", "sctp", "l4", NULL };
|
||||
if (nmc_string_is_valid (tx_hash_element, valid_tx_hashes, NULL))
|
||||
nm_assert (!error || !*error);
|
||||
|
||||
if (NM_IN_STRSET (tx_hash_element,
|
||||
"eth", "vlan", "ipv4", "ipv6", "ip",
|
||||
"l3", "tcp", "udp", "sctp", "l4")) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_set_error (error, 1, 0, "'%s' is not valid. %s", tx_hash_element,
|
||||
"Valid tx-hashes: [eth, vlan, ipv4, ipv6, ip, l3, tcp, udp, sctp, l4]");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -3953,24 +3960,22 @@ static gboolean
|
||||
_set_fcn_team_runner_tx_hash (ARGS_SET_FCN)
|
||||
{
|
||||
gs_free const char **strv = NULL;
|
||||
gsize i;
|
||||
const char *const*iter;
|
||||
|
||||
nm_assert (!error || !*error);
|
||||
|
||||
strv = nm_utils_strsplit_set (value, " \t,");
|
||||
if (!verify_string_list (strv,
|
||||
property_info->property_name,
|
||||
_is_valid_team_runner_tx_hash_element,
|
||||
error))
|
||||
return FALSE;
|
||||
for (iter = strv; strv && *iter; iter++) {
|
||||
if (!_is_valid_team_runner_tx_hash_element (*iter, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (nm_setting_team_get_num_runner_tx_hash (NM_SETTING_TEAM (setting)))
|
||||
nm_setting_team_remove_runner_tx_hash (NM_SETTING_TEAM (setting), 0);
|
||||
|
||||
if (strv) {
|
||||
for (i = 0; strv[i]; i++)
|
||||
nm_setting_team_add_runner_tx_hash (NM_SETTING_TEAM (setting), strv[i]);
|
||||
}
|
||||
for (iter = strv; strv && *iter; iter++)
|
||||
nm_setting_team_add_runner_tx_hash (NM_SETTING_TEAM (setting), *iter);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user