summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-02-19 15:12:54 +0100
committerThomas Haller <thaller@redhat.com>2020-02-19 15:35:07 +0100
commitca83568bbaf35e0a5623519f9dda6de91762ccb7 (patch)
tree4ae3f2138f23d2079aa49605fe7815ee7ef0940f
parenta676b9fce4d6296ce27ea886c36a1f2286020169 (diff)
downloadNetworkManager-th/bond-allow-arp-validate.tar.gz
libnm: cleanup string comparison in "nm-setting-bond.c"th/bond-allow-arp-validate
strcmp() is hard to understand visually. Especially when different patterns are mixed, like: if ( !strcmp (name, NM_SETTING_BOND_OPTION_MIIMON) && strcmp (value, "0") != 0) {
-rw-r--r--libnm-core/nm-setting-bond.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c
index 0154f54fbc..36a92f6e48 100644
--- a/libnm-core/nm-setting-bond.c
+++ b/libnm-core/nm-setting-bond.c
@@ -407,15 +407,17 @@ nm_setting_bond_add_option (NMSettingBond *setting,
nm_clear_g_free (&priv->options_idx_cache);
g_hash_table_insert (priv->options, g_strdup (name), g_strdup (value));
- if ( !strcmp (name, NM_SETTING_BOND_OPTION_MIIMON)
- && strcmp (value, "0") != 0) {
- g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
- g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
- } else if ( !strcmp (name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)
- && strcmp (value, "0") != 0) {
- g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
- g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY);
- g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_UPDELAY);
+ if (nm_streq (name, NM_SETTING_BOND_OPTION_MIIMON)) {
+ if (!nm_streq (value, "0")) {
+ g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
+ g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
+ }
+ } else if (nm_streq (name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)) {
+ if (!nm_streq (value, "0")) {
+ g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
+ g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY);
+ g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_UPDELAY);
+ }
}
_notify (setting, PROP_OPTIONS);
@@ -646,8 +648,8 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
mode_new = nm_utils_bond_mode_int_to_string (mode);
/* Make sure mode is compatible with other settings */
- if ( strcmp (mode_new, "balance-alb") == 0
- || strcmp (mode_new, "balance-tlb") == 0) {
+ if (NM_IN_STRSET (mode_new, "balance-alb",
+ "balance-tlb")) {
if (arp_interval > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
@@ -660,7 +662,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
primary = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_PRIMARY);
- if (strcmp (mode_new, "active-backup") == 0) {
+ if (NM_IN_STRSET (mode_new, "active-backup")) {
GError *tmp_error = NULL;
if (primary && !nm_utils_ifname_valid_kernel (primary, &tmp_error)) {
@@ -686,8 +688,9 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
}
- if (connection && nm_connection_get_setting_infiniband (connection)) {
- if (strcmp (mode_new, "active-backup") != 0) {
+ if ( connection
+ && nm_connection_get_setting_infiniband (connection)) {
+ if (!NM_IN_STRSET (mode_new, "active-backup")) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@@ -778,9 +781,8 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
lacp_rate = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_LACP_RATE);
if ( lacp_rate
- && g_strcmp0 (mode_new, "802.3ad")
- && strcmp (lacp_rate, "slow") != 0
- && strcmp (lacp_rate, "0") != 0) {
+ && !nm_streq0 (mode_new, "802.3ad")
+ && !NM_IN_STRSET (lacp_rate, "0", "slow")) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@@ -807,7 +809,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
/* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */
- if (g_strcmp0 (mode_orig, mode_new) != 0) {
+ if (!nm_streq0 (mode_orig, mode_new)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,