diff options
Diffstat (limited to 'libnm-core/nm-setting-bond.c')
| -rw-r--r-- | libnm-core/nm-setting-bond.c | 106 |
1 files changed, 47 insertions, 59 deletions
diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 0c84b3a0..51ce2deb 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -21,13 +21,12 @@ #include "nm-default.h" -#include <string.h> +#include "nm-setting-bond.h" + #include <stdlib.h> -#include <errno.h> #include <netinet/in.h> #include <arpa/inet.h> -#include "nm-setting-bond.h" #include "nm-utils.h" #include "nm-utils-private.h" #include "nm-connection-private.h" @@ -46,11 +45,9 @@ /*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMSettingBond, PROP_OPTIONS, - LAST_PROP -}; +); typedef struct { GHashTable *options; @@ -178,19 +175,14 @@ nm_setting_bond_get_option (NMSettingBond *setting, static gboolean validate_int (const char *name, const char *value, const BondDefault *def) { - long num; - guint i; + guint64 num; - for (i = 0; i < strlen (value); i++) { - if (!g_ascii_isdigit (value[i]) && value[i] != '-') - return FALSE; - } - - errno = 0; - num = strtol (value, NULL, 10); - if (errno) + if (!NM_STRCHAR_ALL (value, ch, g_ascii_isdigit (ch))) return FALSE; - if (num < def->min || num > def->max) + + num = _nm_utils_ascii_str_to_uint64 (value, 10, def->min, def->max, G_MAXUINT64); + if ( num == G_MAXUINT64 + && errno != 0) return FALSE; return TRUE; @@ -365,7 +357,7 @@ nm_setting_bond_add_option (NMSettingBond *setting, g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_UPDELAY); } - g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS); + _notify (setting, PROP_OPTIONS); return TRUE; } @@ -398,7 +390,7 @@ nm_setting_bond_remove_option (NMSettingBond *setting, nm_clear_g_free (&priv->options_idx_cache); found = g_hash_table_remove (priv->options, name); if (found) - g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS); + _notify (setting, PROP_OPTIONS); return found; } @@ -811,15 +803,15 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ static gboolean -options_hash_match (NMSettingBond *s_bond, - GHashTable *options1, - GHashTable *options2, +options_equal_asym (NMSettingBond *s_bond, + NMSettingBond *s_bond2, NMSettingCompareFlags flags) { + GHashTable *options2 = NM_SETTING_BOND_GET_PRIVATE (s_bond2)->options; GHashTableIter iter; const char *key, *value, *value2; - g_hash_table_iter_init (&iter, options1); + g_hash_table_iter_init (&iter, NM_SETTING_BOND_GET_PRIVATE (s_bond)->options); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) { if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { @@ -841,15 +833,10 @@ options_hash_match (NMSettingBond *s_bond, value2 = g_hash_table_lookup (options2, "num_grat_arp"); } - if (value2) { - if (nm_streq (value, value2)) - continue; - } else { - if (nm_streq (value, nm_setting_bond_get_option_default (s_bond, key))) - continue; - } - - return FALSE; + if (!value2) + value2 = nm_setting_bond_get_option_default (s_bond2, key); + if (!nm_streq (value, value2)) + return FALSE; } return TRUE; @@ -857,31 +844,32 @@ options_hash_match (NMSettingBond *s_bond, static gboolean options_equal (NMSettingBond *s_bond, - GHashTable *options1, - GHashTable *options2, + NMSettingBond *s_bond2, NMSettingCompareFlags flags) { - return options_hash_match (s_bond, options1, options2, flags) - && options_hash_match (s_bond, options2, options1, flags); + return options_equal_asym (s_bond, s_bond2, flags) + && options_equal_asym (s_bond2, s_bond, flags); } -static gboolean -compare_property (NMSetting *setting, +static NMTernary +compare_property (const NMSettInfoSetting *sett_info, + guint property_idx, + NMSetting *setting, NMSetting *other, - const GParamSpec *prop_spec, NMSettingCompareFlags flags) { - NMSettingClass *setting_class; - - if (nm_streq0 (prop_spec->name, NM_SETTING_BOND_OPTIONS)) { - return options_equal (NM_SETTING_BOND (setting), - NM_SETTING_BOND_GET_PRIVATE (setting)->options, - NM_SETTING_BOND_GET_PRIVATE (other)->options, - flags); + if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_BOND_OPTIONS)) { + return ( !other + || options_equal (NM_SETTING_BOND (setting), + NM_SETTING_BOND (other), + flags)); } - setting_class = NM_SETTING_CLASS (nm_setting_bond_parent_class); - return setting_class->compare_property (setting, other, prop_spec, flags); + return NM_SETTING_CLASS (nm_setting_bond_parent_class)->compare_property (sett_info, + property_idx, + setting, + other, + flags); } /*****************************************************************************/ @@ -966,8 +954,8 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) g_type_class_add_private (klass, sizeof (NMSettingBondPrivate)); - object_class->set_property = set_property; object_class->get_property = get_property; + object_class->set_property = set_property; object_class->finalize = finalize; setting_class->verify = verify; @@ -987,17 +975,15 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) * example: BONDING_OPTS="miimon=100 mode=broadcast" * ---end--- */ - g_object_class_install_property - (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_SETTING_BOND_OPTIONS, "", "", - G_TYPE_HASH_TABLE, - G_PARAM_READWRITE | - NM_SETTING_PARAM_INFERRABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_OPTIONS] = + g_param_spec_boxed (NM_SETTING_BOND_OPTIONS, "", "", + G_TYPE_HASH_TABLE, + G_PARAM_READWRITE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS); _properties_override_add_transform (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_BOND_OPTIONS), + obj_properties[PROP_OPTIONS], G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus); @@ -1016,6 +1002,8 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) _nm_setting_get_deprecated_virtual_interface_name, NULL); + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BOND, NULL, properties_override); } |