diff options
author | Thomas Haller <thaller@redhat.com> | 2020-02-19 16:16:02 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-19 17:15:26 +0100 |
commit | ae1008b239aef5cfb7a33816c15fe9feffc80a38 (patch) | |
tree | 8fb4d1b3a548a834e10fbb52d98cbfc6fe8c20b5 | |
parent | 5ccab333d05a61591bc607623d8553ee97a19a48 (diff) | |
download | NetworkManager-ae1008b239aef5cfb7a33816c15fe9feffc80a38.tar.gz |
libnm: sort "mode" in nm_setting_bond_get_option() first
Internally, the options are tracked in a hash table and of undefined
sort order. However, nm_setting_bond_get_option() always returns a stable
(sorted) order.
Move "mode" as first, because that is usually the most interesting option.
The effect is:
$ nmcli -o connection show "$BOND_PROFILE"
...
-bond.options: arp_interval=5,arp_ip_target=192.168.7.7,arp_validate=active,mode=balance-rr,use_carrier=0
+bond.options: mode=balance-rr,arp_interval=5,arp_ip_target=192.168.7.7,arp_validate=active,use_carrier=0
This doesn't affect keyfile, which sorts the hash keys themself (and
doesn't treat the "mode" special).
This however does affect ifcfg-rh writer how it writes the BONDING_OPTS
variable. I think this change is fine and preferable.
-rw-r--r-- | libnm-core/nm-setting-bond.c | 15 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected | 2 |
2 files changed, 15 insertions, 2 deletions
diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index e22113b0c8..4a9f968d23 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -197,6 +197,19 @@ nm_setting_bond_get_num_options (NMSettingBond *setting) return g_hash_table_size (NM_SETTING_BOND_GET_PRIVATE (setting)->options); } +static int +_get_option_sort (gconstpointer p_a, gconstpointer p_b, gpointer _unused) +{ + const char *a = *((const char *const*) p_a); + const char *b = *((const char *const*) p_b); + + NM_CMP_DIRECT (nm_streq (b, NM_SETTING_BOND_OPTION_MODE), + nm_streq (a, NM_SETTING_BOND_OPTION_MODE)); + NM_CMP_DIRECT_STRCMP (a, b); + nm_assert_not_reached (); + return 0; +} + /** * nm_setting_bond_get_option: * @setting: the #NMSettingBond @@ -236,7 +249,7 @@ nm_setting_bond_get_option (NMSettingBond *setting, return FALSE; if (!G_UNLIKELY (priv->options_idx_cache)) - priv->options_idx_cache = nm_utils_named_values_from_str_dict (priv->options, NULL); + priv->options_idx_cache = nm_utils_named_values_from_str_dict_with_sort (priv->options, NULL, _get_option_sort, NULL); NM_SET_OUT (out_name, priv->options_idx_cache[idx].name); NM_SET_OUT (out_value, priv->options_idx_cache[idx].value_str); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected index 36df7712ae..b288c04a47 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected @@ -1,4 +1,4 @@ -BONDING_OPTS="downdelay=5 miimon=100 mode=balance-rr updelay=10" +BONDING_OPTS="mode=balance-rr downdelay=5 miimon=100 updelay=10" TYPE=Bond BONDING_MASTER=yes HWADDR= |