From 01d1f64ad408947fbeaebbf2768828504044377f Mon Sep 17 00:00:00 2001
From: Francesco Giudici <fgiudici@redhat.com>
Date: Mon, 5 Feb 2018 17:50:33 +0100
Subject: [PATCH 1/2] nmcli: team: clear runner-tx-hash before adding new
 hashes

https://bugzilla.redhat.com/show_bug.cgi?id=1541922
(cherry picked from commit 350dbb55abf3a80267c398e6f64c2cee4645475a)
---
 clients/common/nm-meta-setting-desc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index d829fa7d4..85b272cbc 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -3976,6 +3976,9 @@ _set_fcn_team_runner_tx_hash (ARGS_SET_FCN)
		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);
+
	while (strv && strv[i])
		nm_setting_team_add_runner_tx_hash (NM_SETTING_TEAM (setting), strv[i++]);
	g_strfreev (strv);
--
2.14.3


From 11f0ca1f23e000e7cbd246a176d8470c8b6ee8a6 Mon Sep 17 00:00:00 2001
From: Francesco Giudici <fgiudici@redhat.com>
Date: Tue, 6 Feb 2018 16:44:11 +0100
Subject: [PATCH 2/2] 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.

(cherry picked from commit fd5b3f802ec204392ada9ee9b75978059323fab4)
---
 clients/common/nm-meta-setting-desc.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 85b272cbc..94404e908 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -3950,12 +3950,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;
 }

@@ -3963,24 +3970,24 @@ static gboolean
 _set_fcn_team_runner_tx_hash (ARGS_SET_FCN)
 {
	char **strv = NULL;
-	guint i = 0;
+	char *const*iter;

	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	strv = _nm_utils_strv_cleanup (g_strsplit_set (value, " \t,", 0),
	                               TRUE, TRUE, TRUE);
-	if (!verify_string_list (strv, property_info->property_name,
-	                         _is_valid_team_runner_tx_hash_element,
-	                         error)) {
-		g_strfreev (strv);
-		return FALSE;
+	for (iter = strv; strv && *iter; iter++) {
+		if (!_is_valid_team_runner_tx_hash_element (*iter, error)) {
+			g_strfreev (strv);
+			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);

-	while (strv && strv[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);
	g_strfreev (strv);

	return TRUE;
--
2.14.3
