diff options
Diffstat (limited to 'src/libnm-core-intern/nm-core-internal.h')
| -rw-r--r-- | src/libnm-core-intern/nm-core-internal.h | 193 |
1 files changed, 124 insertions, 69 deletions
diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 93d75e44..d9634b04 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -199,14 +199,14 @@ typedef enum { /*< skip >*/ NM_SETTING_PARSE_FLAGS_ALL = ((_NM_SETTING_PARSE_FLAGS_LAST - 1) << 1) - 1, } NMSettingParseFlags; -gboolean _nm_connection_replace_settings(NMConnection * connection, - GVariant * new_settings, +gboolean _nm_connection_replace_settings(NMConnection *connection, + GVariant *new_settings, NMSettingParseFlags parse_flags, - GError ** error); + GError **error); gpointer _nm_connection_check_main_setting(NMConnection *connection, - const char * setting_name, - GError ** error); + const char *setting_name, + GError **error); typedef struct { struct { @@ -221,7 +221,7 @@ typedef struct { gboolean nm_connection_serialization_options_equal(const NMConnectionSerializationOptions *a, const NMConnectionSerializationOptions *b); -GVariant *nm_connection_to_dbus_full(NMConnection * connection, +GVariant *nm_connection_to_dbus_full(NMConnection *connection, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); @@ -262,12 +262,12 @@ typedef enum { NMSettingVerifyResult _nm_connection_verify(NMConnection *connection, GError **error); -gboolean _nm_connection_ensure_normalized(NMConnection * connection, +gboolean _nm_connection_ensure_normalized(NMConnection *connection, gboolean allow_modify, - const char * expected_uuid, + const char *expected_uuid, gboolean coerce_uuid, NMConnection **out_connection_clone, - GError ** error); + GError **error); gboolean _nm_connection_remove_setting(NMConnection *connection, GType setting_type); @@ -280,9 +280,9 @@ nm_assert_connection_unchanging(NMConnection *connection) {} #endif -NMConnection *_nm_simple_connection_new_from_dbus(GVariant * dict, +NMConnection *_nm_simple_connection_new_from_dbus(GVariant *dict, NMSettingParseFlags parse_flags, - GError ** error); + GError **error); NMSettingPriority _nm_setting_get_setting_priority(NMSetting *setting); @@ -294,9 +294,9 @@ GHashTable *_nm_setting_option_hash(NMSetting *setting, gboolean create_if_neces void _nm_setting_option_notify(NMSetting *setting, gboolean keys_changed); -guint _nm_setting_option_get_all(NMSetting * setting, +guint _nm_setting_option_get_all(NMSetting *setting, const char *const **out_names, - GVariant *const ** out_values); + GVariant *const **out_values); gboolean _nm_setting_option_clear(NMSetting *setting, const char *optname); @@ -304,7 +304,7 @@ gboolean _nm_setting_option_clear(NMSetting *setting, const char *optname); guint nm_setting_ethtool_init_features( NMSettingEthtool *setting, - NMOptionBool * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */); + NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */); /*****************************************************************************/ @@ -335,7 +335,7 @@ GHashTable *_nm_ip_route_get_attributes(NMIPRoute *route); NMSriovVF *_nm_utils_sriov_vf_from_strparts(const char *index, const char *detail, gboolean ignore_unknown, - GError ** error); + GError **error); gboolean _nm_sriov_vf_attribute_validate_all(const NMSriovVF *vf, GError **error); GPtrArray * @@ -343,23 +343,23 @@ _nm_utils_copy_array(const GPtrArray *array, NMUtilsCopyFunc copy_func, GDestroy GPtrArray *_nm_utils_copy_object_array(const GPtrArray *array); GSList *nm_strv_to_gslist(char **strv, gboolean deep_copy); -char ** _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy); +char **_nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy); GPtrArray *nm_strv_to_ptrarray(char **strv); -char ** _nm_utils_ptrarray_to_strv(const GPtrArray *ptrarray); +char **_nm_utils_ptrarray_to_strv(const GPtrArray *ptrarray); -gboolean _nm_utils_check_file(const char * filename, +gboolean _nm_utils_check_file(const char *filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - struct stat * out_st, - GError ** error); + struct stat *out_st, + GError **error); -gboolean _nm_utils_check_module_file(const char * name, +gboolean _nm_utils_check_module_file(const char *name, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error); + GError **error); /*****************************************************************************/ @@ -370,8 +370,8 @@ extern gboolean _nm_utils_is_manager_process; gboolean _nm_dbus_typecheck_response(GVariant *response, const GVariantType *reply_type, GError **error); -gulong _nm_dbus_signal_connect_data(GDBusProxy * proxy, - const char * signal_name, +gulong _nm_dbus_signal_connect_data(GDBusProxy *proxy, + const char *signal_name, const GVariantType *signature, GCallback c_handler, gpointer data, @@ -380,15 +380,15 @@ gulong _nm_dbus_signal_connect_data(GDBusProxy * proxy, #define _nm_dbus_signal_connect(proxy, name, signature, handler, data) \ _nm_dbus_signal_connect_data(proxy, name, signature, handler, data, NULL, (GConnectFlags) 0) -GVariant *_nm_dbus_proxy_call_finish(GDBusProxy * proxy, - GAsyncResult * res, +GVariant *_nm_dbus_proxy_call_finish(GDBusProxy *proxy, + GAsyncResult *res, const GVariantType *reply_type, - GError ** error); + GError **error); -GVariant *_nm_dbus_connection_call_finish(GDBusConnection * dbus_connection, - GAsyncResult * result, +GVariant *_nm_dbus_connection_call_finish(GDBusConnection *dbus_connection, + GAsyncResult *result, const GVariantType *reply_type, - GError ** error); + GError **error); gboolean _nm_dbus_error_has_name(GError *error, const char *dbus_error_name); @@ -398,19 +398,19 @@ char *_nm_utils_ssid_to_utf8(GBytes *ssid); /*****************************************************************************/ -gboolean _nm_vpn_plugin_info_check_file(const char * filename, +gboolean _nm_vpn_plugin_info_check_file(const char *filename, gboolean check_absolute, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error); + GError **error); const char *_nm_vpn_plugin_info_get_default_dir_etc(void); const char *_nm_vpn_plugin_info_get_default_dir_lib(void); const char *_nm_vpn_plugin_info_get_default_dir_user(void); -GSList *_nm_vpn_plugin_info_list_load_dir(const char * dirname, +GSList *_nm_vpn_plugin_info_list_load_dir(const char *dirname, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, @@ -430,9 +430,9 @@ typedef struct { extern const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[]; -gboolean _nm_utils_dns_option_validate(const char * option, - char ** out_name, - long * out_value, +gboolean _nm_utils_dns_option_validate(const char *option, + char **out_name, + long *out_value, gboolean ipv6, const NMUtilsDNSOptionDesc *option_descs); gssize _nm_utils_dns_option_find_idx(GPtrArray *array, const char *option); @@ -450,24 +450,24 @@ NMUtilsStrStrDictKey *_nm_utils_strstrdictkey_create(const char *v1, const char /*****************************************************************************/ -gboolean _nm_setting_vlan_set_priorities(NMSettingVlan * setting, +gboolean _nm_setting_vlan_set_priorities(NMSettingVlan *setting, NMVlanPriorityMap map, const NMVlanQosMapping *qos_map, guint n_qos_map); -void _nm_setting_vlan_get_priorities(NMSettingVlan * setting, +void _nm_setting_vlan_get_priorities(NMSettingVlan *setting, NMVlanPriorityMap map, NMVlanQosMapping **out_qos_map, - guint * out_n_qos_map); + guint *out_n_qos_map); /*****************************************************************************/ struct ether_addr; -gboolean _nm_utils_generate_mac_address_mask_parse(const char * value, - struct ether_addr * out_mask, +gboolean _nm_utils_generate_mac_address_mask_parse(const char *value, + struct ether_addr *out_mask, struct ether_addr **out_ouis, - gsize * out_ouis_len, - GError ** error); + gsize *out_ouis_len, + GError **error); /*****************************************************************************/ @@ -645,7 +645,7 @@ gboolean nm_ip_routing_rule_get_xifname_bin(const NMIPRoutingRule *self, #define NM_IP_ROUTING_RULE_ATTR_UID_RANGE_END "uid-range-end" NMIPRoutingRule *nm_ip_routing_rule_from_dbus(GVariant *variant, gboolean strict, GError **error); -GVariant * nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self); +GVariant *nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self); /*****************************************************************************/ @@ -660,8 +660,6 @@ const NMSettInfoSetting *nmtst_sett_info_settings(void); typedef enum _nm_packed { NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT = 0, - NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, - NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, } NMSettingPropertyToDBusFcnGPropType; @@ -748,8 +746,37 @@ struct _NMSettInfoProperty { GParamSpec *param_spec; + /* We want that our properties follow a small number of "default" types + * and behaviors. For example, we have int32 and string properties, but + * most properties of a certain type should behave in a similar way. + * + * That common behavior is realized via the property_type, which defines + * general behaviors for the property. + * + * Note that we still will need some property-specific additional tweaks. + * Of course, the name and param_spec are per-property. But below there are + * also flags and hooks, that can augment the behavior in the property_type. + * For example, the property_type in general might be of type string, but + * then we might want for some properties that the setter will strip + * whitespace. That is for example express with the flag direct_set_string_strip, + * which now is per-property-info, and no longer per-property-type. + * + * The distinction between those two is fixed. At the most extreme, we could + * move all fields from property_type to NMSettInfoProperty or we could move + * behavioral tweaks into the classes themselves. It's chosen this way so + * that we still have sensible common behaviors (string type), but minor + * tweaks are per property-info (and don't require a separate property-type). */ const NMSettInfoPropertType *property_type; + union { + /* Optional hook for direct string properties, this gets called when setting the string. + * Return whether the value changed. */ + gboolean (*set_string_fcn)(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, + const char *src); + } direct_hook; + /* This only has meaning for direct properties (property_type->direct_type != NM_VALUE_TYPE_UNSPEC). * In that case, this is the offset where _nm_setting_get_private() can find * the direct location. */ @@ -759,16 +786,30 @@ struct _NMSettInfoProperty { * normalize the string via g_ascii_strdown(). */ bool direct_set_string_ascii_strdown : 1; + /* If TRUE, this is a NM_VALUE_TYPE_STRING direct property, and the setter will + * normalize the string via g_strstrip(). */ + bool direct_set_string_strip : 1; + /* If non-zero, this is a NM_VALUE_TYPE_STRING direct property. Actually, it is * a _nm_setting_property_define_direct_mac_address(), and the setter will * call _nm_utils_hwaddr_canonical_or_invalid() on the string, with the specified * MAC address length. */ guint8 direct_set_string_mac_address_len : 5; - /* If non-zero, this is the addr-family (AF_INET/AF_INET6) for normalizing an IP - * address. */ + /* If non-zero, this is the addr-family (AF_UNSPEC/AF_INET/AF_INET6) for normalizing an IP + * address with _nm_utils_ipaddr_canonical_or_invalid(). + * Note that AF_UNSPEC is zero, so to differentiate between zero and AF_UNSPEC + * this value is actually the address family + 1. So either zero or AF_UNSPEC+1, AF_INET+1, + * or AF_INET6+1. */ guint8 direct_set_string_ip_address_addr_family : 5; + /* Only makes sense together with direct_set_string_ip_address_addr_family. This flag + * is passed to _nm_utils_ipaddr_canonical_or_invalid(). */ + bool direct_set_string_ip_address_addr_family_map_zero_to_null : 1; + + /* Whether the string property is implemented as a (downcast) NMRefString. */ + bool direct_string_is_refstr : 1; + /* Usually, properties that are set to the default value for the GParamSpec * are not serialized to GVariant (and NULL is returned by to_dbus_data(). * Set this flag to force always converting the property even if the value @@ -787,8 +828,8 @@ typedef struct { typedef struct { const GVariantType *(*get_variant_type)(const struct _NMSettInfoSetting *sett_info, - const char * name, - GError ** error); + const char *name, + GError **error); } NMSettInfoSettGendata; typedef struct { @@ -848,6 +889,20 @@ _nm_setting_get_private(NMSetting *self, const NMSettInfoSetting *sett_info, gui return ((((char *) ((gpointer) self)) + sett_info->private_offset) + offset); } +static inline gpointer +_nm_setting_get_private_field(NMSetting *self, + const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *prop_info) +{ + nm_assert(sett_info); + nm_assert(prop_info); + nm_assert(prop_info->property_type); + nm_assert(prop_info->property_type->direct_type > NM_VALUE_TYPE_UNSPEC); + nm_assert(sett_info->private_offset != 0 || prop_info->direct_offset != 0); + + return _nm_setting_get_private(self, sett_info, prop_info->direct_offset); +} + static inline const NMSettInfoProperty * _nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint16 idx) { @@ -861,7 +916,7 @@ _nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint const NMSettInfoProperty * _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info, - const char * property_name); + const char *property_name); const NMSettInfoSetting *_nm_setting_class_get_sett_info(NMSettingClass *setting_class); @@ -874,26 +929,26 @@ _nm_setting_class_get_property_info(NMSettingClass *setting_class, const char *p /*****************************************************************************/ -gboolean _nm_setting_compare(NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, +gboolean _nm_setting_compare(NMConnection *con_a, + NMSetting *set_a, + NMConnection *con_b, + NMSetting *set_b, NMSettingCompareFlags flags); -gboolean _nm_setting_diff(NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, +gboolean _nm_setting_diff(NMConnection *con_a, + NMSetting *set_a, + NMConnection *con_b, + NMSetting *set_b, NMSettingCompareFlags flags, gboolean invert_results, - GHashTable ** results); + GHashTable **results); NMSetting8021xCKScheme _nm_setting_802_1x_cert_get_scheme(GBytes *bytes, GError **error); GBytes *_nm_setting_802_1x_cert_value_to_bytes(NMSetting8021xCKScheme scheme, - const guint8 * val_bin, + const guint8 *val_bin, gssize val_len, - GError ** error); + GError **error); /*****************************************************************************/ @@ -936,19 +991,19 @@ _nm_connection_serialize_secrets(NMConnectionSerializationFlags flags, return FALSE; } -void _nm_connection_clear_secrets_by_secret_flags(NMConnection * self, +void _nm_connection_clear_secrets_by_secret_flags(NMConnection *self, NMSettingSecretFlags filter_flags); -GVariant *_nm_connection_for_each_secret(NMConnection * self, - GVariant * secrets, +GVariant *_nm_connection_for_each_secret(NMConnection *self, + GVariant *secrets, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data); typedef gboolean (*NMConnectionFindSecretFunc)(NMSettingSecretFlags flags, gpointer user_data); -gboolean _nm_connection_find_secret(NMConnection * self, - GVariant * secrets, +gboolean _nm_connection_find_secret(NMConnection *self, + GVariant *secrets, NMConnectionFindSecretFunc callback, gpointer callback_data); @@ -956,7 +1011,7 @@ gboolean _nm_connection_find_secret(NMConnection * self, gboolean nm_utils_base64secret_normalize(const char *base64_key, gsize required_key_len, - char ** out_base64_key_norm); + char **out_base64_key_norm); /*****************************************************************************/ @@ -977,7 +1032,7 @@ gboolean _nmtst_variant_attribute_spec_assert_sorted(const NMVariantAttributeSpe const NMVariantAttributeSpec * _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *const *array, gsize len, - const char * name); + const char *name); /*****************************************************************************/ |