summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-07-23 19:53:16 +0200
committerThomas Haller <thaller@redhat.com>2021-07-23 19:53:16 +0200
commit888735838382cf45530914b34d383277ff4ddbe4 (patch)
tree24276f04d107f02f5de3d743bdca0604d948f49c
parentfaf315148be15bbbf371074d06125f7b9f3bddaa (diff)
parentc1157d73ad7a2ed6a1993611134c723622691fb2 (diff)
downloadNetworkManager-888735838382cf45530914b34d383277ff4ddbe4.tar.gz
libnm: merge branch 'th/setting-more-direct'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/933
-rw-r--r--src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c2
-rw-r--r--src/libnm-core-impl/nm-setting-adsl.c38
-rw-r--r--src/libnm-core-impl/nm-setting-bluetooth.c91
-rw-r--r--src/libnm-core-impl/nm-setting-bridge.c34
-rw-r--r--src/libnm-core-impl/nm-setting-connection.c200
-rw-r--r--src/libnm-core-impl/nm-setting-infiniband.c18
-rw-r--r--src/libnm-core-impl/nm-setting-ip-config.c54
-rw-r--r--src/libnm-core-impl/nm-setting-ip4-config.c2
-rw-r--r--src/libnm-core-impl/nm-setting-ip6-config.c2
-rw-r--r--src/libnm-core-impl/nm-setting-olpc-mesh.c21
-rw-r--r--src/libnm-core-impl/nm-setting-ovs-port.c201
-rw-r--r--src/libnm-core-impl/nm-setting-private.h126
-rw-r--r--src/libnm-core-impl/nm-setting-tun.c147
-rw-r--r--src/libnm-core-impl/nm-setting-wimax.c17
-rw-r--r--src/libnm-core-impl/nm-setting-wired.c17
-rw-r--r--src/libnm-core-impl/nm-setting-wireless.c35
-rw-r--r--src/libnm-core-impl/nm-setting-wpan.c188
-rw-r--r--src/libnm-core-impl/nm-setting.c371
-rw-r--r--src/libnm-core-impl/nm-utils-private.h6
-rw-r--r--src/libnm-core-impl/nm-utils.c56
-rw-r--r--src/libnm-core-impl/tests/test-general.c57
-rw-r--r--src/libnm-core-impl/tests/test-setting.c78
-rw-r--r--src/libnm-core-intern/nm-core-internal.h40
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h4
24 files changed, 1070 insertions, 735 deletions
diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 8d07b15608..015aafed03 100644
--- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -5589,7 +5589,7 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data)
/* assert that the gateway was written and reloaded as expected */
if (!gateway6 || !strcmp(gateway6, "::")) {
- g_assert(nm_setting_ip_config_get_gateway(s_ip6) == NULL);
+ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip6), ==, NULL);
g_assert(written_ifcfg_gateway == NULL);
} else {
g_assert(nm_setting_ip_config_get_gateway(s_ip6) != NULL);
diff --git a/src/libnm-core-impl/nm-setting-adsl.c b/src/libnm-core-impl/nm-setting-adsl.c
index 470753b1d0..5f1888d0e4 100644
--- a/src/libnm-core-impl/nm-setting-adsl.c
+++ b/src/libnm-core-impl/nm-setting-adsl.c
@@ -409,34 +409,28 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass)
*
* ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm".
**/
- _nm_setting_property_define_direct_string(
- properties_override,
- obj_properties,
- NM_SETTING_ADSL_PROTOCOL,
- PROP_PROTOCOL,
- NM_SETTING_PARAM_NONE,
- NMSettingAdslPrivate,
- protocol,
- /* it's special, because set_property() calls g_ascii_strdown() on
- * the string! */
- .direct_has_special_setter = TRUE);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_ADSL_PROTOCOL,
+ PROP_PROTOCOL,
+ NM_SETTING_PARAM_NONE,
+ NMSettingAdslPrivate,
+ protocol,
+ .direct_set_string_ascii_strdown = TRUE);
/**
* NMSettingAdsl:encapsulation:
*
* Encapsulation of ADSL connection. Can be "vcmux" or "llc".
**/
- _nm_setting_property_define_direct_string(
- properties_override,
- obj_properties,
- NM_SETTING_ADSL_ENCAPSULATION,
- PROP_ENCAPSULATION,
- NM_SETTING_PARAM_NONE,
- NMSettingAdslPrivate,
- encapsulation,
- /* it's special, because set_property() calls g_ascii_strdown() on
- * the string! */
- .direct_has_special_setter = TRUE);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_ADSL_ENCAPSULATION,
+ PROP_ENCAPSULATION,
+ NM_SETTING_PARAM_NONE,
+ NMSettingAdslPrivate,
+ encapsulation,
+ .direct_set_string_ascii_strdown = TRUE);
/**
* NMSettingAdsl:vpi:
diff --git a/src/libnm-core-impl/nm-setting-bluetooth.c b/src/libnm-core-impl/nm-setting-bluetooth.c
index aa97e4dcb9..f0b4a3914e 100644
--- a/src/libnm-core-impl/nm-setting-bluetooth.c
+++ b/src/libnm-core-impl/nm-setting-bluetooth.c
@@ -94,6 +94,8 @@ nm_setting_bluetooth_get_bdaddr(NMSettingBluetooth *setting)
return NM_SETTING_BLUETOOTH_GET_PRIVATE(setting)->bdaddr;
}
+/*****************************************************************************/
+
static gboolean
verify(NMSetting *setting, NMConnection *connection, GError **error)
{
@@ -229,46 +231,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
/*****************************************************************************/
static void
-get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
- NMSettingBluetooth *setting = NM_SETTING_BLUETOOTH(object);
-
- switch (prop_id) {
- case PROP_BDADDR:
- g_value_set_string(value, nm_setting_bluetooth_get_bdaddr(setting));
- break;
- case PROP_TYPE:
- g_value_set_string(value, nm_setting_bluetooth_get_connection_type(setting));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
-{
- NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE(object);
-
- switch (prop_id) {
- case PROP_BDADDR:
- g_free(priv->bdaddr);
- priv->bdaddr = g_value_dup_string(value);
- break;
- case PROP_TYPE:
- g_free(priv->type);
- priv->type = g_value_dup_string(value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-/*****************************************************************************/
-
-static void
nm_setting_bluetooth_init(NMSettingBluetooth *setting)
{}
@@ -286,17 +248,6 @@ nm_setting_bluetooth_new(void)
}
static void
-finalize(GObject *object)
-{
- NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE(object);
-
- g_free(priv->bdaddr);
- g_free(priv->type);
-
- G_OBJECT_CLASS(nm_setting_bluetooth_parent_class)->finalize(object);
-}
-
-static void
nm_setting_bluetooth_class_init(NMSettingBluetoothClass *klass)
{
GObjectClass * object_class = G_OBJECT_CLASS(klass);
@@ -305,26 +256,25 @@ nm_setting_bluetooth_class_init(NMSettingBluetoothClass *klass)
g_type_class_add_private(klass, sizeof(NMSettingBluetoothPrivate));
- object_class->get_property = get_property;
- object_class->set_property = set_property;
- object_class->finalize = finalize;
+ object_class->get_property = _nm_setting_property_get_property_direct;
+ object_class->set_property = _nm_setting_property_set_property_direct;
- setting_class->verify = verify;
+ setting_class->verify = verify;
+ setting_class->finalize_direct = TRUE;
/**
* NMSettingBluetooth:bdaddr:
*
* The Bluetooth address of the device.
**/
- obj_properties[PROP_BDADDR] = g_param_spec_string(
- NM_SETTING_BLUETOOTH_BDADDR,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_BDADDR],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_BLUETOOTH_BDADDR,
+ PROP_BDADDR,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingBluetoothPrivate,
+ bdaddr,
+ .direct_set_string_mac_address_len = ETH_ALEN);
/**
* NMSettingBluetooth:type:
@@ -332,12 +282,13 @@ nm_setting_bluetooth_class_init(NMSettingBluetoothClass *klass)
* Either "dun" for Dial-Up Networking connections or "panu" for Personal
* Area Networking connections to devices supporting the NAP profile.
**/
- obj_properties[PROP_TYPE] = g_param_spec_string(NM_SETTING_BLUETOOTH_TYPE,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE
- | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_BLUETOOTH_TYPE,
+ PROP_TYPE,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingBluetoothPrivate,
+ type);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c
index 7ecd7fdbb8..14d005674a 100644
--- a/src/libnm-core-impl/nm-setting-bridge.c
+++ b/src/libnm-core-impl/nm-setting-bridge.c
@@ -1627,15 +1627,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass)
* BRIDGE_MACADDR for bridges is an NM extension.
* ---end---
*/
- obj_properties[PROP_MAC_ADDRESS] = g_param_spec_string(
- NM_SETTING_BRIDGE_MAC_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_MAC_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_BRIDGE_MAC_ADDRESS,
+ PROP_MAC_ADDRESS,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingBridgePrivate,
+ mac_address,
+ .direct_set_string_mac_address_len = ETH_ALEN);
/**
* NMSettingBridge:stp:
@@ -1935,15 +1934,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass)
* example: BRIDGING_OPTS="group_address=01:80:C2:00:00:0A"
* ---end---
*/
- obj_properties[PROP_GROUP_ADDRESS] = g_param_spec_string(
- NM_SETTING_BRIDGE_GROUP_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_GROUP_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_BRIDGE_GROUP_ADDRESS,
+ PROP_GROUP_ADDRESS,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingBridgePrivate,
+ group_address,
+ .direct_set_string_mac_address_len = ETH_ALEN);
/**
* NMSettingBridge:vlan-protocol:
diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c
index a9a6fd9f1f..6aacc31c5e 100644
--- a/src/libnm-core-impl/nm-setting-connection.c
+++ b/src/libnm-core-impl/nm-setting-connection.c
@@ -82,17 +82,17 @@ typedef struct {
char * zone;
char * mud_url;
guint64 timestamp;
- int autoconnect_priority;
- int autoconnect_retries;
- int multi_connect;
- int auth_retries;
- int mdns;
- int llmnr;
- int wait_device_timeout;
- guint gateway_ping_timeout;
+ gint32 autoconnect_priority;
+ gint32 autoconnect_retries;
+ gint32 multi_connect;
+ gint32 auth_retries;
+ gint32 mdns;
+ gint32 llmnr;
+ gint32 wait_device_timeout;
+ gint32 lldp;
+ guint32 gateway_ping_timeout;
NMSettingConnectionAutoconnectSlaves autoconnect_slaves;
NMMetered metered;
- NMSettingConnectionLldp lldp;
bool autoconnect;
bool read_only;
} NMSettingConnectionPrivate;
@@ -1821,14 +1821,7 @@ nm_setting_connection_init(NMSettingConnection *setting)
{
NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE(setting);
- priv->auth_retries = -1;
- priv->autoconnect_priority = NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT;
- priv->autoconnect_retries = -1;
- priv->autoconnect_slaves = NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT;
- priv->lldp = NM_SETTING_CONNECTION_LLDP_DEFAULT;
- priv->llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT;
- priv->mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT;
- priv->wait_device_timeout = -1;
+ priv->autoconnect_slaves = NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT;
}
/**
@@ -1901,9 +1894,9 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
.direct_type = NM_VALUE_TYPE_STRING,
.compare_fcn = compare_fcn_id,
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
- .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
- .from_dbus_is_full = TRUE),
-
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
+ .from_dbus_is_full = TRUE,
+ .from_dbus_direct_allow_transform = TRUE),
NMSettingConnectionPrivate,
id);
@@ -2028,8 +2021,9 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
.missing_from_dbus_fcn =
nm_setting_connection_no_interface_name,
- .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
- .from_dbus_is_full = TRUE),
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
+ .from_dbus_is_full = TRUE,
+ .from_dbus_direct_allow_transform = TRUE),
NMSettingConnectionPrivate,
interface_name);
@@ -2143,14 +2137,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: AUTOCONNECT_PRIORITY=20
* ---end---
*/
- obj_properties[PROP_AUTOCONNECT_PRIORITY] = g_param_spec_int(
- NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY,
- "",
- "",
- NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN,
- NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX,
- NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT,
- G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY,
+ PROP_AUTOCONNECT_PRIORITY,
+ NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN,
+ NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX,
+ NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT,
+ NM_SETTING_PARAM_FUZZY_IGNORE,
+ NMSettingConnectionPrivate,
+ autoconnect_priority);
/**
* NMSettingConnection:autoconnect-retries:
@@ -2170,14 +2166,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: AUTOCONNECT_RETRIES=1
* ---end---
*/
- obj_properties[PROP_AUTOCONNECT_RETRIES] = g_param_spec_int(
- NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES,
- "",
- "",
- -1,
- G_MAXINT32,
- -1,
- G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES,
+ PROP_AUTOCONNECT_RETRIES,
+ -1,
+ G_MAXINT32,
+ -1,
+ NM_SETTING_PARAM_FUZZY_IGNORE,
+ NMSettingConnectionPrivate,
+ autoconnect_retries);
/**
* NMSettingConnection:multi-connect:
@@ -2195,14 +2193,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: MULTI_CONNECT=3
* ---end---
*/
- obj_properties[PROP_MULTI_CONNECT] = g_param_spec_int(
- NM_SETTING_CONNECTION_MULTI_CONNECT,
- "",
- "",
- G_MININT32,
- G_MAXINT32,
- NM_CONNECTION_MULTI_CONNECT_DEFAULT,
- G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_MULTI_CONNECT,
+ PROP_MULTI_CONNECT,
+ G_MININT32,
+ G_MAXINT32,
+ NM_CONNECTION_MULTI_CONNECT_DEFAULT,
+ NM_SETTING_PARAM_FUZZY_IGNORE,
+ NMSettingConnectionPrivate,
+ multi_connect);
/**
* NMSettingConnection:timestamp:
@@ -2392,14 +2392,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: GATEWAY_PING_TIMEOUT=5
* ---end---
*/
- obj_properties[PROP_GATEWAY_PING_TIMEOUT] =
- g_param_spec_uint(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT,
- "",
- "",
- 0,
- 600,
- 0,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT,
+ PROP_GATEWAY_PING_TIMEOUT,
+ 0,
+ 600,
+ 0,
+ NM_SETTING_PARAM_NONE,
+ NMSettingConnectionPrivate,
+ gateway_ping_timeout);
/**
* NMSettingConnection:metered:
@@ -2443,14 +2445,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: LLDP=no
* ---end---
*/
- obj_properties[PROP_LLDP] = g_param_spec_int(NM_SETTING_CONNECTION_LLDP,
- "",
- "",
- G_MININT32,
- G_MAXINT32,
- NM_SETTING_CONNECTION_LLDP_DEFAULT,
- NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE
- | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_LLDP,
+ PROP_LLDP,
+ G_MININT32,
+ G_MAXINT32,
+ NM_SETTING_CONNECTION_LLDP_DEFAULT,
+ NM_SETTING_PARAM_FUZZY_IGNORE,
+ NMSettingConnectionPrivate,
+ lldp);
/**
* NMSettingConnection:auth-retries:
@@ -2470,14 +2474,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* description: Number of retries for authentication.
* ---end---
*/
- obj_properties[PROP_AUTH_RETRIES] = g_param_spec_int(
- NM_SETTING_CONNECTION_AUTH_RETRIES,
- "",
- "",
- -1,
- G_MAXINT32,
- -1,
- G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_AUTH_RETRIES,
+ PROP_AUTH_RETRIES,
+ -1,
+ G_MAXINT32,
+ -1,
+ NM_SETTING_PARAM_FUZZY_IGNORE,
+ NMSettingConnectionPrivate,
+ auth_retries);
/**
* NMSettingConnection:mdns:
@@ -2493,7 +2499,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
*
* This feature requires a plugin which supports mDNS. Otherwise, the
* setting has no effect. One such plugin is dns-systemd-resolved.
-*
+ *
* Since: 1.12
**/
/* ---ifcfg-rh---
@@ -2505,13 +2511,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: MDNS=yes
* ---end---
*/
- obj_properties[PROP_MDNS] = g_param_spec_int(NM_SETTING_CONNECTION_MDNS,
- "",
- "",
- G_MININT32,
- G_MAXINT32,
- NM_SETTING_CONNECTION_MDNS_DEFAULT,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_MDNS,
+ PROP_MDNS,
+ G_MININT32,
+ G_MAXINT32,
+ NM_SETTING_CONNECTION_MDNS_DEFAULT,
+ NM_SETTING_PARAM_NONE,
+ NMSettingConnectionPrivate,
+ mdns);
/**
* NMSettingConnection:llmnr:
@@ -2541,13 +2550,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: LLMNR=yes
* ---end---
*/
- obj_properties[PROP_LLMNR] = g_param_spec_int(NM_SETTING_CONNECTION_LLMNR,
- "",
- "",
- G_MININT32,
- G_MAXINT32,
- NM_SETTING_CONNECTION_LLMNR_DEFAULT,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_LLMNR,
+ PROP_LLMNR,
+ G_MININT32,
+ G_MAXINT32,
+ NM_SETTING_CONNECTION_LLMNR_DEFAULT,
+ NM_SETTING_PARAM_NONE,
+ NMSettingConnectionPrivate,
+ llmnr);
/**
* NMSettingConnection:wait-device-timeout:
@@ -2574,14 +2586,16 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* example: DEVTIMEOUT=5
* ---end---
*/
- obj_properties[PROP_WAIT_DEVICE_TIMEOUT] =
- g_param_spec_int(NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT,
- "",
- "",
- -1,
- G_MAXINT32,
- -1,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT,
+ PROP_WAIT_DEVICE_TIMEOUT,
+ -1,
+ G_MAXINT32,
+ -1,
+ NM_SETTING_PARAM_NONE,
+ NMSettingConnectionPrivate,
+ wait_device_timeout);
/**
* NMSettingConnection:mud-url:
diff --git a/src/libnm-core-impl/nm-setting-infiniband.c b/src/libnm-core-impl/nm-setting-infiniband.c
index 730b2d2649..117d89fced 100644
--- a/src/libnm-core-impl/nm-setting-infiniband.c
+++ b/src/libnm-core-impl/nm-setting-infiniband.c
@@ -426,15 +426,15 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass)
* example: HWADDR=01:02:03:04:05:06:07:08:09:0A:01:02:03:04:05:06:07:08:09:11
* ---end---
*/
- obj_properties[PROP_MAC_ADDRESS] = g_param_spec_string(
- NM_SETTING_INFINIBAND_MAC_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_MAC_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_INFINIBAND_MAC_ADDRESS,
+ PROP_MAC_ADDRESS,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingInfinibandPrivate,
+ mac_address,
+ .direct_set_string_mac_address_len =
+ INFINIBAND_ALEN);
/**
* NMSettingInfiniband:mtu:
diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c
index 7f524a24f7..33b0c8124c 100644
--- a/src/libnm-core-impl/nm-setting-ip-config.c
+++ b/src/libnm-core-impl/nm-setting-ip-config.c
@@ -5775,30 +5775,35 @@ enumerate_values(const NMSettInfoProperty *property_info,
/*****************************************************************************/
-static gboolean
-ip_gateway_set(const NMSettInfoSetting * sett_info,
- const NMSettInfoProperty *property_info,
- NMSetting * setting,
- GVariant * connection_dict,
- GVariant * value,
- NMSettingParseFlags parse_flags,
- GError ** error)
+gboolean
+_nm_setting_property_from_dbus_fcn_direct_ip_config_gateway(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty *property_info,
+ NMSetting * setting,
+ GVariant * connection_dict,
+ GVariant * value,
+ NMSettingParseFlags parse_flags,
+ GError ** error)
{
- /* FIXME: properly handle errors */
-
/* Don't set from 'gateway' if we're going to use the gateway in 'addresses' */
if (_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "gateway"))
return TRUE;
- g_object_set(setting, property_info->name, g_variant_get_string(value, NULL), NULL);
- return TRUE;
+ return _nm_setting_property_from_dbus_fcn_direct(sett_info,
+ property_info,
+ setting,
+ connection_dict,
+ value,
+ parse_flags,
+ error);
}
GArray *
-_nm_sett_info_property_override_create_array_ip_config(void)
+_nm_sett_info_property_override_create_array_ip_config(int addr_family)
{
GArray *properties_override = _nm_sett_info_property_override_create_array();
+ nm_assert_addr_family(addr_family);
+
_nm_properties_override_gobj(
properties_override,
obj_properties[PROP_METHOD],
@@ -5808,14 +5813,14 @@ _nm_sett_info_property_override_create_array_ip_config(void)
_nm_properties_override_gobj(
properties_override,
obj_properties[PROP_GATEWAY],
- NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING,
- .direct_type = NM_VALUE_TYPE_STRING,
- .compare_fcn = _nm_setting_property_compare_fcn_direct,
- .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
- .from_dbus_fcn = ip_gateway_set),
+ NM_SETT_INFO_PROPERT_TYPE_DBUS(
+ G_VARIANT_TYPE_STRING,
+ .direct_type = NM_VALUE_TYPE_STRING,
+ .compare_fcn = _nm_setting_property_compare_fcn_direct,
+ .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway),
.direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, gateway),
- /* The property setter for the gateway performs some normalization and is special! */
- .direct_has_special_setter = TRUE);
+ .direct_set_string_ip_address_addr_family = addr_family);
_nm_properties_override_gobj(
properties_override,
@@ -5975,7 +5980,6 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
{
NMSettingIPConfig * setting = NM_SETTING_IP_CONFIG(object);
NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting);
- const char * gateway;
char ** strv;
guint i;
@@ -6021,12 +6025,10 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
(GDestroyNotify) nm_ip_address_unref);
break;
case PROP_GATEWAY:
- gateway = g_value_get_string(value);
- g_return_if_fail(
- !gateway
- || nm_utils_ipaddr_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), gateway));
g_free(priv->gateway);
- priv->gateway = canonicalize_ip(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), gateway, TRUE);
+ priv->gateway =
+ _nm_utils_ipaddr_canonical_or_invalid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting),
+ g_value_get_string(value));
break;
case PROP_ROUTES:
g_ptr_array_unref(priv->routes);
diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c
index 5995a582b7..ee91b35d34 100644
--- a/src/libnm-core-impl/nm-setting-ip4-config.c
+++ b/src/libnm-core-impl/nm-setting-ip4-config.c
@@ -654,7 +654,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
GObjectClass * object_class = G_OBJECT_CLASS(klass);
NMSettingClass * setting_class = NM_SETTING_CLASS(klass);
NMSettingIPConfigClass *setting_ip_config_class = NM_SETTING_IP_CONFIG_CLASS(klass);
- GArray *properties_override = _nm_sett_info_property_override_create_array_ip_config();
+ GArray *properties_override = _nm_sett_info_property_override_create_array_ip_config(AF_INET);
g_type_class_add_private(klass, sizeof(NMSettingIP4ConfigPrivate));
diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c
index 3c2dfc8595..3c382d54c4 100644
--- a/src/libnm-core-impl/nm-setting-ip6-config.c
+++ b/src/libnm-core-impl/nm-setting-ip6-config.c
@@ -650,7 +650,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass)
GObjectClass * object_class = G_OBJECT_CLASS(klass);
NMSettingClass * setting_class = NM_SETTING_CLASS(klass);
NMSettingIPConfigClass *setting_ip_config_class = NM_SETTING_IP_CONFIG_CLASS(klass);
- GArray *properties_override = _nm_sett_info_property_override_create_array_ip_config();
+ GArray *properties_override = _nm_sett_info_property_override_create_array_ip_config(AF_INET6);
g_type_class_add_private(klass, sizeof(NMSettingIP6ConfigPrivate));
diff --git a/src/libnm-core-impl/nm-setting-olpc-mesh.c b/src/libnm-core-impl/nm-setting-olpc-mesh.c
index ce7bdf1fb7..558b266adc 100644
--- a/src/libnm-core-impl/nm-setting-olpc-mesh.c
+++ b/src/libnm-core-impl/nm-setting-olpc-mesh.c
@@ -184,7 +184,9 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_DHCP_ANYCAST_ADDRESS:
g_free(priv->dhcp_anycast_addr);
- priv->dhcp_anycast_addr = g_value_dup_string(value);
+ priv->dhcp_anycast_addr =
+ _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), ETH_ALEN);
+
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -273,15 +275,14 @@ nm_setting_olpc_mesh_class_init(NMSettingOlpcMeshClass *klass)
*
* This is currently only implemented by dhclient DHCP plugin.
**/
- obj_properties[PROP_DHCP_ANYCAST_ADDRESS] =
- g_param_spec_string(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_DHCP_ANYCAST_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS,
+ PROP_DHCP_ANYCAST_ADDRESS,
+ NM_SETTING_PARAM_NONE,
+ NMSettingOlpcMeshPrivate,
+ dhcp_anycast_addr,
+ .direct_set_string_mac_address_len = ETH_ALEN);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
diff --git a/src/libnm-core-impl/nm-setting-ovs-port.c b/src/libnm-core-impl/nm-setting-ovs-port.c
index a5d92019be..0b10473d07 100644
--- a/src/libnm-core-impl/nm-setting-ovs-port.c
+++ b/src/libnm-core-impl/nm-setting-ovs-port.c
@@ -36,12 +36,12 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_VLAN_MODE,
struct _NMSettingOvsPort {
NMSetting parent;
- char *vlan_mode;
- char *lacp;
- char *bond_mode;
- guint tag;
- guint bond_updelay;
- guint bond_downdelay;
+ char * vlan_mode;
+ char * lacp;
+ char * bond_mode;
+ guint32 tag;
+ guint32 bond_updelay;
+ guint32 bond_downdelay;
};
struct _NMSettingOvsPortClass {
@@ -263,71 +263,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
/*****************************************************************************/
static void
-get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
- NMSettingOvsPort *self = NM_SETTING_OVS_PORT(object);
-
- switch (prop_id) {
- case PROP_VLAN_MODE:
- g_value_set_string(value, self->vlan_mode);
- break;
- case PROP_TAG:
- g_value_set_uint(value, self->tag);
- break;
- case PROP_LACP:
- g_value_set_string(value, self->lacp);
- break;
- case PROP_BOND_MODE:
- g_value_set_string(value, self->bond_mode);
- break;
- case PROP_BOND_UPDELAY:
- g_value_set_uint(value, self->bond_updelay);
- break;
- case PROP_BOND_DOWNDELAY:
- g_value_set_uint(value, self->bond_downdelay);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
-{
- NMSettingOvsPort *self = NM_SETTING_OVS_PORT(object);
-
- switch (prop_id) {
- case PROP_VLAN_MODE:
- g_free(self->vlan_mode);
- self->vlan_mode = g_value_dup_string(value);
- break;
- case PROP_TAG:
- self->tag = g_value_get_uint(value);
- break;
- case PROP_LACP:
- g_free(self->lacp);
- self->lacp = g_value_dup_string(value);
- break;
- case PROP_BOND_MODE:
- g_free(self->bond_mode);
- self->bond_mode = g_value_dup_string(value);
- break;
- case PROP_BOND_UPDELAY:
- self->bond_updelay = g_value_get_uint(value);
- break;
- case PROP_BOND_DOWNDELAY:
- self->bond_downdelay = g_value_get_uint(value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-/*****************************************************************************/
-
-static void
nm_setting_ovs_port_init(NMSettingOvsPort *self)
{}
@@ -347,28 +282,17 @@ nm_setting_ovs_port_new(void)
}
static void
-finalize(GObject *object)
-{
- NMSettingOvsPort *self = NM_SETTING_OVS_PORT(object);
-
- g_free(self->vlan_mode);
- g_free(self->lacp);
- g_free(self->bond_mode);
-
- G_OBJECT_CLASS(nm_setting_ovs_port_parent_class)->finalize(object);
-}
-
-static void
nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
{
- GObjectClass * object_class = G_OBJECT_CLASS(klass);
- NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
+ GObjectClass * object_class = G_OBJECT_CLASS(klass);
+ NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
+ GArray * properties_override = _nm_sett_info_property_override_create_array();
- object_class->get_property = get_property;
- object_class->set_property = set_property;
- object_class->finalize = finalize;
+ object_class->get_property = _nm_setting_property_get_property_direct;
+ object_class->set_property = _nm_setting_property_set_property_direct;
- setting_class->verify = verify;
+ setting_class->verify = verify;
+ setting_class->finalize_direct = TRUE;
/**
* NMSettingOvsPort:vlan-mode:
@@ -378,12 +302,13 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
*
* Since: 1.10
**/
- obj_properties[PROP_VLAN_MODE] = g_param_spec_string(
- NM_SETTING_OVS_PORT_VLAN_MODE,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_OVS_PORT_VLAN_MODE,
+ PROP_VLAN_MODE,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingOvsPort,
+ vlan_mode);
/**
* NMSettingOvsPort:tag:
@@ -392,14 +317,16 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
*
* Since: 1.10
**/
- obj_properties[PROP_TAG] =
- g_param_spec_uint(NM_SETTING_OVS_PORT_TAG,
- "",
- "",
- 0,
- 4095,
- 0,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_OVS_PORT_TAG,
+ PROP_TAG,
+ 0,
+ 4095,
+ 0,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingOvsPort,
+ tag);
/**
* NMSettingOvsPort:lacp:
@@ -408,12 +335,13 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
*
* Since: 1.10
**/
- obj_properties[PROP_LACP] = g_param_spec_string(NM_SETTING_OVS_PORT_LACP,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE
- | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_OVS_PORT_LACP,
+ PROP_LACP,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingOvsPort,
+ lacp);
/**
* NMSettingOvsPort:bond-mode:
@@ -422,12 +350,13 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
*
* Since: 1.10
**/
- obj_properties[PROP_BOND_MODE] = g_param_spec_string(
- NM_SETTING_OVS_PORT_BOND_MODE,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_OVS_PORT_BOND_MODE,
+ PROP_BOND_MODE,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingOvsPort,
+ bond_mode);
/**
* NMSettingOvsPort:bond-updelay:
@@ -436,14 +365,16 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
*
* Since: 1.10
**/
- obj_properties[PROP_BOND_UPDELAY] =
- g_param_spec_uint(NM_SETTING_OVS_PORT_BOND_UPDELAY,
- "",
- "",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_OVS_PORT_BOND_UPDELAY,
+ PROP_BOND_UPDELAY,
+ 0,
+ G_MAXUINT32,
+ 0,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingOvsPort,
+ bond_updelay);
/**
* NMSettingOvsPort:bond-downdelay:
@@ -452,16 +383,22 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass)
*
* Since: 1.10
**/
- obj_properties[PROP_BOND_DOWNDELAY] =
- g_param_spec_uint(NM_SETTING_OVS_PORT_BOND_DOWNDELAY,
- "",
- "",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_OVS_PORT_BOND_DOWNDELAY,
+ PROP_BOND_DOWNDELAY,
+ 0,
+ G_MAXUINT32,
+ 0,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingOvsPort,
+ bond_downdelay);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
- _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_PORT, NULL, NULL, 0);
+ _nm_setting_class_commit(setting_class,
+ NM_META_SETTING_TYPE_OVS_PORT,
+ NULL,
+ properties_override,
+ 0);
}
diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h
index dc0654ce83..d9574499ab 100644
--- a/src/libnm-core-impl/nm-setting-private.h
+++ b/src/libnm-core-impl/nm-setting-private.h
@@ -289,8 +289,10 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i;
extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u;
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean;
+extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_int32;
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32;
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_string;
+extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_mac_address;
NMSettingVerifyResult
_nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error);
@@ -364,6 +366,14 @@ GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting *
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
+GVariant *_nm_setting_property_to_dbus_fcn_direct_mac_address(
+ const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty * property_info,
+ NMConnection * connection,
+ NMSetting * setting,
+ NMConnectionSerializationFlags flags,
+ const NMConnectionSerializationOptions *options);
+
gboolean _nm_setting_property_from_dbus_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
@@ -372,6 +382,32 @@ gboolean _nm_setting_property_from_dbus_fcn_ignore(const NMSettInfoSetting * set
NMSettingParseFlags parse_flags,
GError ** error);
+gboolean
+_nm_setting_property_from_dbus_fcn_direct_ip_config_gateway(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty *property_info,
+ NMSetting * setting,
+ GVariant * connection_dict,
+ GVariant * value,
+ NMSettingParseFlags parse_flags,
+ GError ** error);
+
+gboolean
+_nm_setting_property_from_dbus_fcn_direct_mac_address(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty *property_info,
+ NMSetting * setting,
+ GVariant * connection_dict,
+ GVariant * value,
+ NMSettingParseFlags parse_flags,
+ GError ** error);
+
+gboolean _nm_setting_property_from_dbus_fcn_direct(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty *property_info,
+ NMSetting * setting,
+ GVariant * connection_dict,
+ GVariant * value,
+ NMSettingParseFlags parse_flags,
+ GError ** error);
+
gboolean _nm_setting_property_from_dbus_fcn_gprop(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
@@ -416,7 +452,7 @@ _nm_sett_info_property_override_create_array(void)
return _nm_sett_info_property_override_create_array_sized(20);
}
-GArray *_nm_sett_info_property_override_create_array_ip_config(void);
+GArray *_nm_sett_info_property_override_create_array_ip_config(int addr_family);
void _nm_setting_class_commit(NMSettingClass * setting_class,
NMMetaSettingType meta_type,
@@ -555,9 +591,9 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
G_STATIC_ASSERT( \
!NM_FLAGS_ANY((param_flags), \
~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE))); \
- G_STATIC_ASSERT((min_value) <= (guint64) G_MAXUINT32); \
+ G_STATIC_ASSERT((min_value) <= (guint64) (default_value)); \
+ G_STATIC_ASSERT((default_value) <= (guint64) (max_value)); \
G_STATIC_ASSERT((max_value) <= (guint64) G_MAXUINT32); \
- G_STATIC_ASSERT((default_value) <= (guint64) G_MAXUINT32); \
\
_param_spec = \
g_param_spec_uint("" prop_name "", \
@@ -582,6 +618,52 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
/*****************************************************************************/
+#define _nm_setting_property_define_direct_int32(properties_override, \
+ obj_properties, \
+ prop_name, \
+ prop_id, \
+ min_value, \
+ max_value, \
+ default_value, \
+ param_flags, \
+ private_struct_type, \
+ private_struct_field, \
+ ... /* extra NMSettInfoProperty fields */) \
+ G_STMT_START \
+ { \
+ GParamSpec *_param_spec; \
+ \
+ G_STATIC_ASSERT( \
+ !NM_FLAGS_ANY((param_flags), \
+ ~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE))); \
+ G_STATIC_ASSERT((min_value) >= (gint64) (G_MININT32)); \
+ G_STATIC_ASSERT((min_value) <= (gint64) (default_value)); \
+ G_STATIC_ASSERT((default_value) <= (gint64) (max_value)); \
+ G_STATIC_ASSERT((max_value) <= (gint64) G_MAXUINT32); \
+ \
+ _param_spec = \
+ g_param_spec_int("" prop_name "", \
+ "", \
+ "", \
+ (min_value), \
+ (max_value), \
+ (default_value), \
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
+ \
+ (obj_properties)[(prop_id)] = _param_spec; \
+ \
+ _nm_properties_override_gobj( \
+ (properties_override), \
+ _param_spec, \
+ &nm_sett_info_propert_type_direct_int32, \
+ .direct_offset = \
+ NM_STRUCT_OFFSET_ENSURE_TYPE(gint32, private_struct_type, private_struct_field), \
+ __VA_ARGS__); \
+ } \
+ G_STMT_END
+
+/*****************************************************************************/
+
#define _nm_setting_property_define_direct_string_full(properties_override, \
obj_properties, \
prop_name, \
@@ -645,6 +727,44 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
/*****************************************************************************/
+#define _nm_setting_property_define_direct_mac_address(properties_override, \
+ obj_properties, \
+ prop_name, \
+ prop_id, \
+ param_flags, \
+ private_struct_type, \
+ private_struct_field, \
+ ... /* extra NMSettInfoProperty fields */) \
+ G_STMT_START \
+ { \
+ GParamSpec *_param_spec; \
+ \
+ G_STATIC_ASSERT(!NM_FLAGS_ANY((param_flags), \
+ ~(NM_SETTING_PARAM_SECRET | NM_SETTING_PARAM_FUZZY_IGNORE \
+ | NM_SETTING_PARAM_INFERRABLE \
+ | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \
+ \
+ _param_spec = \
+ g_param_spec_string("" prop_name "", \
+ "", \
+ "", \
+ NULL, \
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
+ \
+ (obj_properties)[(prop_id)] = _param_spec; \
+ \
+ _nm_properties_override_gobj( \
+ (properties_override), \
+ _param_spec, \
+ &nm_sett_info_propert_type_direct_mac_address, \
+ .direct_offset = \
+ NM_STRUCT_OFFSET_ENSURE_TYPE(char *, private_struct_type, private_struct_field), \
+ __VA_ARGS__); \
+ } \
+ G_STMT_END
+
+/*****************************************************************************/
+
gboolean _nm_setting_use_legacy_property(NMSetting * setting,
GVariant * connection_dict,
const char *legacy_property,
diff --git a/src/libnm-core-impl/nm-setting-tun.c b/src/libnm-core-impl/nm-setting-tun.c
index 99a68024ee..2698a14541 100644
--- a/src/libnm-core-impl/nm-setting-tun.c
+++ b/src/libnm-core-impl/nm-setting-tun.c
@@ -32,12 +32,12 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MODE,
PROP_MULTI_QUEUE, );
typedef struct {
- char * owner;
- char * group;
- NMSettingTunMode mode;
- bool pi;
- bool vnet_hdr;
- bool multi_queue;
+ char * owner;
+ char * group;
+ guint32 mode;
+ bool pi;
+ bool vnet_hdr;
+ bool multi_queue;
} NMSettingTunPrivate;
/**
@@ -198,77 +198,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
/*****************************************************************************/
static void
-get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
- NMSettingTun * setting = NM_SETTING_TUN(object);
- NMSettingTunPrivate *priv = NM_SETTING_TUN_GET_PRIVATE(setting);
-
- switch (prop_id) {
- case PROP_MODE:
- g_value_set_uint(value, priv->mode);
- break;
- case PROP_OWNER:
- g_value_set_string(value, priv->owner);
- break;
- case PROP_GROUP:
- g_value_set_string(value, priv->group);
- break;
- case PROP_PI:
- g_value_set_boolean(value, priv->pi);
- break;
- case PROP_VNET_HDR:
- g_value_set_boolean(value, priv->vnet_hdr);
- break;
- case PROP_MULTI_QUEUE:
- g_value_set_boolean(value, priv->multi_queue);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
-{
- NMSettingTun * setting = NM_SETTING_TUN(object);
- NMSettingTunPrivate *priv = NM_SETTING_TUN_GET_PRIVATE(setting);
-
- switch (prop_id) {
- case PROP_MODE:
- priv->mode = g_value_get_uint(value);
- break;
- case PROP_OWNER:
- g_free(priv->owner);
- priv->owner = g_value_dup_string(value);
- break;
- case PROP_GROUP:
- g_free(priv->group);
- priv->group = g_value_dup_string(value);
- break;
- case PROP_PI:
- priv->pi = g_value_get_boolean(value);
- break;
- case PROP_VNET_HDR:
- priv->vnet_hdr = g_value_get_boolean(value);
- break;
- case PROP_MULTI_QUEUE:
- priv->multi_queue = g_value_get_boolean(value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-/*****************************************************************************/
-
-static void
nm_setting_tun_init(NMSettingTun *self)
-{
- NMSettingTunPrivate *priv = NM_SETTING_TUN_GET_PRIVATE(self);
-
- priv->mode = NM_SETTING_TUN_MODE_TUN;
-}
+{}
/**
* nm_setting_tun_new:
@@ -286,18 +217,6 @@ nm_setting_tun_new(void)
}
static void
-finalize(GObject *object)
-{
- NMSettingTun * setting = NM_SETTING_TUN(object);
- NMSettingTunPrivate *priv = NM_SETTING_TUN_GET_PRIVATE(setting);
-
- g_free(priv->owner);
- g_free(priv->group);
-
- G_OBJECT_CLASS(nm_setting_tun_parent_class)->finalize(object);
-}
-
-static void
nm_setting_tun_class_init(NMSettingTunClass *klass)
{
GObjectClass * object_class = G_OBJECT_CLASS(klass);
@@ -306,11 +225,11 @@ nm_setting_tun_class_init(NMSettingTunClass *klass)
g_type_class_add_private(klass, sizeof(NMSettingTunPrivate));
- object_class->get_property = get_property;
- object_class->set_property = set_property;
- object_class->finalize = finalize;
+ object_class->get_property = _nm_setting_property_get_property_direct;
+ object_class->set_property = _nm_setting_property_set_property_direct;
- setting_class->verify = verify;
+ setting_class->verify = verify;
+ setting_class->finalize_direct = TRUE;
/**
* NMSettingTun:mode:
@@ -322,14 +241,16 @@ nm_setting_tun_class_init(NMSettingTunClass *klass)
*
* Since: 1.2
*/
- obj_properties[PROP_MODE] =
- g_param_spec_uint(NM_SETTING_TUN_MODE,
- "",
- "",
- 0,
- G_MAXUINT,
- NM_SETTING_TUN_MODE_TUN,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_TUN_MODE,
+ PROP_MODE,
+ 0,
+ G_MAXUINT32,
+ NM_SETTING_TUN_MODE_TUN,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingTunPrivate,
+ mode);
/**
* NMSettingTun:owner:
@@ -339,12 +260,13 @@ nm_setting_tun_class_init(NMSettingTunClass *klass)
*
* Since: 1.2
*/
- obj_properties[PROP_OWNER] = g_param_spec_string(NM_SETTING_TUN_OWNER,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE
- | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_TUN_OWNER,
+ PROP_OWNER,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingTunPrivate,
+ owner);
/**
* NMSettingTun:group:
@@ -354,12 +276,13 @@ nm_setting_tun_class_init(NMSettingTunClass *klass)
*
* Since: 1.2
*/
- obj_properties[PROP_GROUP] = g_param_spec_string(NM_SETTING_TUN_GROUP,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE
- | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_TUN_GROUP,
+ PROP_GROUP,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingTunPrivate,
+ group);
/**
* NMSettingTun:pi:
diff --git a/src/libnm-core-impl/nm-setting-wimax.c b/src/libnm-core-impl/nm-setting-wimax.c
index 9f2f6e3bf5..48a662262f 100644
--- a/src/libnm-core-impl/nm-setting-wimax.c
+++ b/src/libnm-core-impl/nm-setting-wimax.c
@@ -252,15 +252,14 @@ nm_setting_wimax_class_init(NMSettingWimaxClass *klass)
*
* Deprecated: 1.2: WiMAX is no longer supported.
**/
- obj_properties[PROP_MAC_ADDRESS] =
- g_param_spec_string(NM_SETTING_WIMAX_MAC_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_MAC_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_WIMAX_MAC_ADDRESS,
+ PROP_MAC_ADDRESS,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWimaxPrivate,
+ mac_address,
+ .direct_set_string_mac_address_len = ETH_ALEN);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c
index 4c35545ce2..37e324fa5c 100644
--- a/src/libnm-core-impl/nm-setting-wired.c
+++ b/src/libnm-core-impl/nm-setting-wired.c
@@ -1409,15 +1409,14 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass)
* permanent MAC address exists, the MAC address initially configured on the device.
* ---end---
*/
- obj_properties[PROP_MAC_ADDRESS] = g_param_spec_string(
- NM_SETTING_WIRED_MAC_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_MAC_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_WIRED_MAC_ADDRESS,
+ PROP_MAC_ADDRESS,
+ NM_SETTING_PARAM_INFERRABLE,
+ NMSettingWiredPrivate,
+ device_mac_address,
+ .direct_set_string_mac_address_len = ETH_ALEN);
/**
* NMSettingWired:cloned-mac-address:
diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c
index 4b7ec8fa1e..2611568131 100644
--- a/src/libnm-core-impl/nm-setting-wireless.c
+++ b/src/libnm-core-impl/nm-setting-wireless.c
@@ -1277,7 +1277,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
break;
case PROP_BSSID:
g_free(priv->bssid);
- priv->bssid = g_value_dup_string(value);
+ priv->bssid = _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), ETH_ALEN);
break;
case PROP_RATE:
priv->rate = g_value_get_uint(value);
@@ -1533,14 +1533,14 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass)
* example: BSSID=00:1E:BD:64:83:21
* ---end---
*/
- obj_properties[PROP_BSSID] = g_param_spec_string(NM_SETTING_WIRELESS_BSSID,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_BSSID],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_WIRELESS_BSSID,
+ PROP_BSSID,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWirelessPrivate,
+ bssid,
+ .direct_set_string_mac_address_len = ETH_ALEN);
/**
* NMSettingWireless:rate:
@@ -1611,15 +1611,14 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass)
* permanent MAC address exists, the MAC address initially configured on the device.
* ---end---
*/
- obj_properties[PROP_MAC_ADDRESS] =
- g_param_spec_string(NM_SETTING_WIRELESS_MAC_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- _nm_properties_override_gobj(properties_override,
- obj_properties[PROP_MAC_ADDRESS],
- &nm_sett_info_propert_type_mac_address);
+ _nm_setting_property_define_direct_mac_address(properties_override,
+ obj_properties,
+ NM_SETTING_WIRELESS_MAC_ADDRESS,
+ PROP_MAC_ADDRESS,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWirelessPrivate,
+ device_mac_address,
+ .direct_set_string_mac_address_len = ETH_ALEN);
/**
* NMSettingWireless:cloned-mac-address:
diff --git a/src/libnm-core-impl/nm-setting-wpan.c b/src/libnm-core-impl/nm-setting-wpan.c
index 30d81890c8..1b556ff7c1 100644
--- a/src/libnm-core-impl/nm-setting-wpan.c
+++ b/src/libnm-core-impl/nm-setting-wpan.c
@@ -43,10 +43,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MAC_ADDRESS,
typedef struct {
char * mac_address;
- guint16 pan_id;
- guint16 short_address;
- gint16 page;
- gint16 channel;
+ guint32 pan_id;
+ guint32 short_address;
+ gint32 page;
+ gint32 channel;
} NMSettingWpanPrivate;
/**
@@ -201,73 +201,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
/*****************************************************************************/
static void
-get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
- NMSettingWpan *setting = NM_SETTING_WPAN(object);
-
- switch (prop_id) {
- case PROP_MAC_ADDRESS:
- g_value_set_string(value, nm_setting_wpan_get_mac_address(setting));
- break;
- case PROP_PAN_ID:
- g_value_set_uint(value, nm_setting_wpan_get_pan_id(setting));
- break;
- case PROP_SHORT_ADDRESS:
- g_value_set_uint(value, nm_setting_wpan_get_short_address(setting));
- break;
- case PROP_PAGE:
- g_value_set_int(value, nm_setting_wpan_get_page(setting));
- break;
- case PROP_CHANNEL:
- g_value_set_int(value, nm_setting_wpan_get_channel(setting));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
-{
- NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE(object);
-
- switch (prop_id) {
- case PROP_MAC_ADDRESS:
- g_free(priv->mac_address);
- priv->mac_address =
- _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), IEEE802154_ADDR_LEN);
- break;
- case PROP_PAN_ID:
- priv->pan_id = g_value_get_uint(value);
- break;
- case PROP_SHORT_ADDRESS:
- priv->short_address = g_value_get_uint(value);
- break;
- case PROP_PAGE:
- priv->page = g_value_get_int(value);
- break;
- case PROP_CHANNEL:
- priv->channel = g_value_get_int(value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-/*****************************************************************************/
-
-static void
nm_setting_wpan_init(NMSettingWpan *setting)
-{
- NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE(setting);
-
- priv->pan_id = G_MAXUINT16;
- priv->short_address = G_MAXUINT16;
- priv->page = NM_SETTING_WPAN_PAGE_DEFAULT;
- priv->channel = NM_SETTING_WPAN_CHANNEL_DEFAULT;
-}
+{}
/**
* nm_setting_wpan_new:
@@ -285,28 +220,19 @@ nm_setting_wpan_new(void)
}
static void
-finalize(GObject *object)
-{
- NMSettingWpanPrivate *priv = NM_SETTING_WPAN_GET_PRIVATE(object);
-
- g_free(priv->mac_address);
-
- G_OBJECT_CLASS(nm_setting_wpan_parent_class)->finalize(object);
-}
-
-static void
nm_setting_wpan_class_init(NMSettingWpanClass *klass)
{
- GObjectClass * object_class = G_OBJECT_CLASS(klass);
- NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
+ GObjectClass * object_class = G_OBJECT_CLASS(klass);
+ NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
+ GArray * properties_override = _nm_sett_info_property_override_create_array();
g_type_class_add_private(setting_class, sizeof(NMSettingWpanPrivate));
- object_class->get_property = get_property;
- object_class->set_property = set_property;
- object_class->finalize = finalize;
+ object_class->get_property = _nm_setting_property_get_property_direct;
+ object_class->set_property = _nm_setting_property_set_property_direct;
- setting_class->verify = verify;
+ setting_class->verify = verify;
+ setting_class->finalize_direct = TRUE;
/**
* NMSettingWpan:mac-address:
@@ -321,39 +247,47 @@ nm_setting_wpan_class_init(NMSettingWpanClass *klass)
* (e.g. 76:d8:9b:87:66:60:84:ee).
* ---end---
*/
- obj_properties[PROP_MAC_ADDRESS] =
- g_param_spec_string(NM_SETTING_WPAN_MAC_ADDRESS,
- "",
- "",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_string(properties_override,
+ obj_properties,
+ NM_SETTING_WPAN_MAC_ADDRESS,
+ PROP_MAC_ADDRESS,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWpanPrivate,
+ mac_address,
+ .direct_set_string_mac_address_len =
+ IEEE802154_ADDR_LEN);
/**
* NMSettingWpan:pan-id:
*
* IEEE 802.15.4 Personal Area Network (PAN) identifier.
**/
- obj_properties[PROP_PAN_ID] = g_param_spec_uint(NM_SETTING_WPAN_PAN_ID,
- "",
- "",
- 0,
- G_MAXUINT16,
- G_MAXUINT16,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_WPAN_PAN_ID,
+ PROP_PAN_ID,
+ 0,
+ G_MAXUINT16,
+ G_MAXUINT16,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWpanPrivate,
+ pan_id);
/**
* NMSettingWpan:short-address:
*
* Short IEEE 802.15.4 address to be used within a restricted environment.
**/
- obj_properties[PROP_SHORT_ADDRESS] =
- g_param_spec_uint(NM_SETTING_WPAN_SHORT_ADDRESS,
- "",
- "",
- 0,
- G_MAXUINT16,
- G_MAXUINT16,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_uint32(properties_override,
+ obj_properties,
+ NM_SETTING_WPAN_SHORT_ADDRESS,
+ PROP_SHORT_ADDRESS,
+ 0,
+ G_MAXUINT16,
+ G_MAXUINT16,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWpanPrivate,
+ short_address);
/**
* NMSettingWpan:page:
@@ -363,13 +297,16 @@ nm_setting_wpan_class_init(NMSettingWpanClass *klass)
*
* Since: 1.16
**/
- obj_properties[PROP_PAGE] = g_param_spec_int(NM_SETTING_WPAN_PAGE,
- "",
- "",
- G_MININT16,
- G_MAXINT16,
- NM_SETTING_WPAN_PAGE_DEFAULT,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_WPAN_PAGE,
+ PROP_PAGE,
+ G_MININT16,
+ G_MAXINT16,
+ NM_SETTING_WPAN_PAGE_DEFAULT,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWpanPrivate,
+ page);
/**
* NMSettingWpan:channel:
@@ -379,15 +316,22 @@ nm_setting_wpan_class_init(NMSettingWpanClass *klass)
*
* Since: 1.16
**/
- obj_properties[PROP_CHANNEL] = g_param_spec_int(NM_SETTING_WPAN_CHANNEL,
- "",
- "",
- G_MININT16,
- G_MAXINT16,
- NM_SETTING_WPAN_CHANNEL_DEFAULT,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ _nm_setting_property_define_direct_int32(properties_override,
+ obj_properties,
+ NM_SETTING_WPAN_CHANNEL,
+ PROP_CHANNEL,
+ G_MININT16,
+ G_MAXINT16,
+ NM_SETTING_WPAN_CHANNEL_DEFAULT,
+ NM_SETTING_PARAM_NONE,
+ NMSettingWpanPrivate,
+ channel);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
- _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_WPAN, NULL, NULL, 0);
+ _nm_setting_class_commit(setting_class,
+ NM_META_SETTING_TYPE_WPAN,
+ NULL,
+ properties_override,
+ NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS);
}
diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c
index 342f9e0fa5..70370d4e51 100644
--- a/src/libnm-core-impl/nm-setting.c
+++ b/src/libnm-core-impl/nm-setting.c
@@ -674,6 +674,27 @@ _nm_setting_use_legacy_property(NMSetting * setting,
/*****************************************************************************/
+static gboolean
+_property_direct_set_string(const NMSettInfoProperty *property_info, char **dst, const char *src)
+{
+ if (property_info->direct_set_string_ascii_strdown)
+ return nm_utils_strdup_reset_take(dst, src ? g_ascii_strdown(src, -1) : NULL);
+ if (property_info->direct_set_string_mac_address_len > 0) {
+ return nm_utils_strdup_reset_take(dst,
+ _nm_utils_hwaddr_canonical_or_invalid(
+ src,
+ property_info->direct_set_string_mac_address_len));
+ }
+ if (property_info->direct_set_string_ip_address_addr_family != 0) {
+ return nm_utils_strdup_reset_take(
+ dst,
+ _nm_utils_ipaddr_canonical_or_invalid(
+ property_info->direct_set_string_ip_address_addr_family,
+ src));
+ }
+ return nm_utils_strdup_reset(dst, src);
+}
+
void
_nm_setting_property_get_property_direct(GObject * object,
guint prop_id,
@@ -702,6 +723,14 @@ _nm_setting_property_get_property_direct(GObject * object,
g_value_set_boolean(value, *p_val);
return;
}
+ case NM_VALUE_TYPE_INT32:
+ {
+ const gint32 *p_val =
+ _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+
+ g_value_set_int(value, *p_val);
+ return;
+ }
case NM_VALUE_TYPE_UINT32:
{
const guint32 *p_val =
@@ -747,9 +776,6 @@ _nm_setting_property_set_property_direct(GObject * object,
nm_assert(property_info->param_spec == pspec);
- /* properties with special setters are not yet implemented! */
- nm_assert(!property_info->direct_has_special_setter);
-
switch (property_info->property_type->direct_type) {
case NM_VALUE_TYPE_BOOL:
{
@@ -762,6 +788,21 @@ _nm_setting_property_set_property_direct(GObject * object,
*p_val = v;
goto out_notify;
}
+ case NM_VALUE_TYPE_INT32:
+ {
+ gint32 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+ int v;
+
+ v = g_value_get_int(value);
+ if (*p_val == v)
+ return;
+ *p_val = v;
+
+ /* truncation cannot happen, because the param_spec is supposed to have suitable
+ * minimum/maximum values so that we are in range for int32. */
+ nm_assert(*p_val == v);
+ goto out_notify;
+ }
case NM_VALUE_TYPE_UINT32:
{
guint32 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
@@ -778,13 +819,12 @@ _nm_setting_property_set_property_direct(GObject * object,
goto out_notify;
}
case NM_VALUE_TYPE_STRING:
- {
- char **p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
-
- if (!nm_utils_strdup_reset(p_val, g_value_get_string(value)))
+ if (!_property_direct_set_string(
+ property_info,
+ _nm_setting_get_private(setting, sett_info, property_info->direct_offset),
+ g_value_get_string(value)))
return;
goto out_notify;
- }
default:
goto out_fail;
}
@@ -833,6 +873,17 @@ _init_direct(NMSetting *setting)
*p_val = def_val;
break;
}
+ case NM_VALUE_TYPE_INT32:
+ {
+ gint32 *p_val =
+ _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+ int def_val;
+
+ def_val = NM_G_PARAM_SPEC_GET_DEFAULT_INT(property_info->param_spec);
+ nm_assert(*p_val == 0);
+ *p_val = def_val;
+ break;
+ }
case NM_VALUE_TYPE_UINT32:
{
guint32 *p_val =
@@ -879,6 +930,7 @@ _finalize_direct(NMSetting *setting)
switch (property_info->property_type->direct_type) {
case NM_VALUE_TYPE_NONE:
case NM_VALUE_TYPE_BOOL:
+ case NM_VALUE_TYPE_INT32:
case NM_VALUE_TYPE_UINT32:
break;
case NM_VALUE_TYPE_STRING:
@@ -917,6 +969,17 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting *
return NULL;
return g_variant_ref(nm_g_variant_singleton_b(val));
}
+ case NM_VALUE_TYPE_INT32:
+ {
+ gint32 val;
+
+ val =
+ *((gint32 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset));
+ if (!property_info->to_dbus_including_default
+ && val == NM_G_PARAM_SPEC_GET_DEFAULT_INT(property_info->param_spec))
+ return NULL;
+ return g_variant_new_int32(val);
+ }
case NM_VALUE_TYPE_UINT32:
{
guint32 val;
@@ -955,6 +1018,27 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting *
}
GVariant *
+_nm_setting_property_to_dbus_fcn_direct_mac_address(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty * property_info,
+ NMConnection * connection,
+ NMSetting * setting,
+ NMConnectionSerializationFlags flags,
+ const NMConnectionSerializationOptions *options)
+{
+ const char *val;
+
+ nm_assert(property_info->property_type == &nm_sett_info_propert_type_direct_mac_address);
+ nm_assert(property_info->property_type->direct_type == NM_VALUE_TYPE_STRING);
+ nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec));
+ nm_assert(!property_info->to_dbus_including_default);
+
+ val = *((const char *const *) _nm_setting_get_private(setting,
+ sett_info,
+ property_info->direct_offset));
+ return nm_utils_hwaddr_to_dbus(val);
+}
+
+GVariant *
_nm_setting_property_to_dbus_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
@@ -1008,8 +1092,6 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s
case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT:
nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_HASH_TABLE));
return nm_utils_strdict_to_variant_ass(g_value_get_boxed(&prop_value));
- case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS:
- return nm_utils_hwaddr_to_dbus(g_value_get_string(&prop_value));
}
return nm_assert_unreachable_val(NULL);
@@ -1028,6 +1110,215 @@ _nm_setting_property_from_dbus_fcn_ignore(const NMSettInfoSetting * sett_info,
}
gboolean
+_nm_setting_property_from_dbus_fcn_direct_mac_address(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty *property_info,
+ NMSetting * setting,
+ GVariant * connection_dict,
+ GVariant * value,
+ NMSettingParseFlags parse_flags,
+ GError ** error)
+{
+ gsize length = 0;
+ const guint8 *array;
+
+ nm_assert(property_info->param_spec);
+ nm_assert(property_info->property_type == &nm_sett_info_propert_type_direct_mac_address);
+ nm_assert(g_variant_type_equal(property_info->property_type->dbus_type, "ay"));
+ nm_assert(
+ g_variant_type_equal(g_variant_get_type(value), property_info->property_type->dbus_type));
+ nm_assert(property_info->direct_set_string_mac_address_len > 0);
+
+ array = g_variant_get_fixed_array(value, &length, 1);
+
+ if (nm_utils_strdup_reset_take(
+ _nm_setting_get_private(setting, sett_info, property_info->direct_offset),
+ length > 0 ? nm_utils_hwaddr_ntoa(array, length) : NULL))
+ g_object_notify_by_pspec(G_OBJECT(setting), property_info->param_spec);
+
+ return TRUE;
+}
+
+gboolean
+_nm_setting_property_from_dbus_fcn_direct(const NMSettInfoSetting * sett_info,
+ const NMSettInfoProperty *property_info,
+ NMSetting * setting,
+ GVariant * connection_dict,
+ GVariant * value,
+ NMSettingParseFlags parse_flags,
+ GError ** error)
+{
+ nm_assert(property_info->param_spec);
+ nm_assert(NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE));
+ nm_assert(!NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_CONSTRUCT_ONLY));
+ nm_assert(!property_info->property_type->typdata_from_dbus.gprop_fcn);
+
+#define _variant_get_value_transform(property_info, value, gtype, gvalue_get, out_val) \
+ ({ \
+ const NMSettInfoProperty const *_property_info = (property_info); \
+ const GType _gtype = (gtype); \
+ GVariant * _value = (value); \
+ gboolean _success = FALSE; \
+ \
+ nm_assert(_property_info->param_spec->value_type == _gtype); \
+ if (_property_info->property_type->from_dbus_direct_allow_transform) { \
+ nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \
+ \
+ g_value_init(&_gvalue, _gtype); \
+ if (_nm_property_variant_to_gvalue(_value, &_gvalue)) { \
+ *(out_val) = (gvalue_get(&_gvalue)); \
+ _success = TRUE; \
+ } \
+ } \
+ _success; \
+ })
+
+ switch (property_info->property_type->direct_type) {
+ case NM_VALUE_TYPE_BOOL:
+ {
+ bool * p_val;
+ gboolean v;
+
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN))
+ v = g_variant_get_boolean(value);
+ else {
+ if (!_variant_get_value_transform(property_info,
+ value,
+ G_TYPE_BOOLEAN,
+ g_value_get_boolean,
+ &v))
+ goto out_error_wrong_dbus_type;
+ v = !!v;
+ }
+
+ p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+ if (*p_val == v)
+ goto out_unchanged;
+ *p_val = v;
+ goto out_notify;
+ }
+ case NM_VALUE_TYPE_INT32:
+ {
+ const GParamSpecInt *param_spec;
+ gint32 * p_val;
+ int v;
+
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT32)) {
+ G_STATIC_ASSERT(sizeof(int) >= sizeof(gint32));
+ v = g_variant_get_int32(value);
+ } else {
+ if (!_variant_get_value_transform(property_info,
+ value,
+ G_TYPE_INT,
+ g_value_get_int,
+ &v))
+ goto out_error_wrong_dbus_type;
+ }
+
+ p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+ if (*p_val == v)
+ goto out_unchanged;
+
+ param_spec = NM_G_PARAM_SPEC_CAST_INT(property_info->param_spec);
+ if (v < param_spec->minimum || v > param_spec->maximum)
+ goto out_error_param_spec_validation;
+ *p_val = v;
+ goto out_notify;
+ }
+ case NM_VALUE_TYPE_UINT32:
+ {
+ const GParamSpecUInt *param_spec;
+ guint32 * p_val;
+ guint v;
+
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ G_STATIC_ASSERT(sizeof(guint) >= sizeof(guint32));
+ v = g_variant_get_uint32(value);
+ } else {
+ if (!_variant_get_value_transform(property_info,
+ value,
+ G_TYPE_UINT,
+ g_value_get_uint,
+ &v))
+ goto out_error_wrong_dbus_type;
+ }
+
+ p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+ if (*p_val == v)
+ goto out_unchanged;
+
+ param_spec = NM_G_PARAM_SPEC_CAST_UINT(property_info->param_spec);
+ if (v < param_spec->minimum || v > param_spec->maximum)
+ goto out_error_param_spec_validation;
+ *p_val = v;
+ goto out_notify;
+ }
+ case NM_VALUE_TYPE_STRING:
+ {
+ gs_free char *v_free = NULL;
+ char ** p_val;
+ const char * v;
+
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ v = g_variant_get_string(value, NULL);
+ } else {
+ if (!_variant_get_value_transform(property_info,
+ value,
+ G_TYPE_STRING,
+ g_value_dup_string,
+ &v_free))
+ goto out_error_wrong_dbus_type;
+ v = v_free;
+ }
+
+ p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
+ if (!_property_direct_set_string(property_info, p_val, v))
+ goto out_unchanged;
+
+ goto out_notify;
+ }
+ default:
+ break;
+ }
+
+ nm_assert_not_reached();
+
+out_unchanged:
+ return TRUE;
+
+out_notify:
+ g_object_notify_by_pspec(G_OBJECT(setting), property_info->param_spec);
+ return TRUE;
+
+out_error_wrong_dbus_type:
+ if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT))
+ return TRUE;
+ g_set_error(error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("can't set property of type '%s' from value of type '%s'"),
+ property_info->property_type->dbus_type
+ ? g_variant_type_peek_string(property_info->property_type->dbus_type)
+ : (property_info->param_spec
+ ? g_type_name(property_info->param_spec->value_type)
+ : "(unknown)"),
+ g_variant_get_type_string(value));
+ g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name);
+ return FALSE;
+
+out_error_param_spec_validation:
+ if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT))
+ return TRUE;
+ g_set_error(error,
+ NM_UTILS_ERROR,
+ NM_UTILS_ERROR_UNKNOWN,
+ _("value of type '%s' is invalid or out of range for property '%s'"),
+ g_variant_get_type_string(value),
+ property_info->name);
+ g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name);
+ return FALSE;
+}
+
+gboolean
_nm_setting_property_from_dbus_fcn_gprop(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
@@ -1150,28 +1441,18 @@ set_property_from_dbus(const NMSettInfoProperty *property_info,
property_info->property_type->dbus_type))
return FALSE;
property_info->property_type->typdata_from_dbus.gprop_fcn(src_value, dst_value);
- } else if (dst_value->g_type == G_TYPE_BYTES) {
+ return TRUE;
+ }
+
+ if (dst_value->g_type == G_TYPE_BYTES) {
if (!g_variant_is_of_type(src_value, G_VARIANT_TYPE_BYTESTRING))
return FALSE;
_nm_utils_bytes_from_dbus(src_value, dst_value);
- } else {
- GValue tmp = G_VALUE_INIT;
-
- g_dbus_gvariant_to_gvalue(src_value, &tmp);
- if (G_VALUE_TYPE(&tmp) == G_VALUE_TYPE(dst_value))
- *dst_value = tmp;
- else {
- gboolean success;
-
- success = g_value_transform(&tmp, dst_value);
- g_value_unset(&tmp);
- if (!success)
- return FALSE;
- }
+ return TRUE;
}
- return TRUE;
+ return _nm_property_variant_to_gvalue(src_value, dst_value);
}
/**
@@ -1847,7 +2128,9 @@ _nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info,
gconstpointer p_a;
gconstpointer p_b;
- nm_assert(property_info->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct);
+ nm_assert(NM_IN_SET(property_info->property_type->to_dbus_fcn,
+ _nm_setting_property_to_dbus_fcn_direct,
+ _nm_setting_property_to_dbus_fcn_direct_mac_address));
if (!property_info->param_spec)
return nm_assert_unreachable_val(NM_TERNARY_DEFAULT);
@@ -1864,6 +2147,8 @@ _nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info,
switch (property_info->property_type->direct_type) {
case NM_VALUE_TYPE_BOOL:
return *((const bool *) p_a) == *((const bool *) p_b);
+ case NM_VALUE_TYPE_INT32:
+ return *((const gint32 *) p_a) == *((const gint32 *) p_b);
case NM_VALUE_TYPE_UINT32:
return *((const guint32 *) p_a) == *((const guint32 *) p_b);
case NM_VALUE_TYPE_STRING:
@@ -2909,24 +3194,44 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean =
.direct_type = NM_VALUE_TYPE_BOOL,
.compare_fcn = _nm_setting_property_compare_fcn_direct,
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
- .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
- .from_dbus_is_full = TRUE);
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
+ .from_dbus_is_full = TRUE,
+ .from_dbus_direct_allow_transform = TRUE);
+
+const NMSettInfoPropertType nm_sett_info_propert_type_direct_int32 =
+ NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT32,
+ .direct_type = NM_VALUE_TYPE_INT32,
+ .compare_fcn = _nm_setting_property_compare_fcn_direct,
+ .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
+ .from_dbus_is_full = TRUE,
+ .from_dbus_direct_allow_transform = TRUE);
const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 =
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT32,
.direct_type = NM_VALUE_TYPE_UINT32,
.compare_fcn = _nm_setting_property_compare_fcn_direct,
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
- .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
- .from_dbus_is_full = TRUE);
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
+ .from_dbus_is_full = TRUE,
+ .from_dbus_direct_allow_transform = TRUE);
const NMSettInfoPropertType nm_sett_info_propert_type_direct_string =
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING,
.direct_type = NM_VALUE_TYPE_STRING,
.compare_fcn = _nm_setting_property_compare_fcn_direct,
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
- .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
- .from_dbus_is_full = TRUE);
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
+ .from_dbus_is_full = TRUE,
+ .from_dbus_direct_allow_transform = TRUE);
+
+const NMSettInfoPropertType nm_sett_info_propert_type_direct_mac_address =
+ NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(
+ G_VARIANT_TYPE_BYTESTRING,
+ .direct_type = NM_VALUE_TYPE_STRING,
+ .compare_fcn = _nm_setting_property_compare_fcn_direct,
+ .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct_mac_address,
+ .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct_mac_address);
/*****************************************************************************/
diff --git a/src/libnm-core-impl/nm-utils-private.h b/src/libnm-core-impl/nm-utils-private.h
index eec84dc637..572cdba4bf 100644
--- a/src/libnm-core-impl/nm-utils-private.h
+++ b/src/libnm-core-impl/nm-utils-private.h
@@ -32,9 +32,9 @@ gboolean _nm_utils_wps_method_validate(NMSettingWirelessSecurityWpsMethod wps_me
/* D-Bus transform funcs */
-extern const NMSettInfoPropertType nm_sett_info_propert_type_strdict;
+gboolean _nm_property_variant_to_gvalue(GVariant *src_value, GValue *dst_value);
-extern const NMSettInfoPropertType nm_sett_info_propert_type_mac_address;
+extern const NMSettInfoPropertType nm_sett_info_propert_type_strdict;
extern const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address;
@@ -44,6 +44,8 @@ void _nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value);
char *_nm_utils_hwaddr_canonical_or_invalid(const char *mac, gssize length);
+char *_nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip);
+
gboolean _nm_utils_hwaddr_link_local_valid(const char *mac);
gboolean _nm_sriov_vf_parse_vlans(NMSriovVF *vf, const char *str, GError **error);
diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c
index 5b1f85ccb5..0e383ffaf6 100644
--- a/src/libnm-core-impl/nm-utils.c
+++ b/src/libnm-core-impl/nm-utils.c
@@ -3648,6 +3648,23 @@ nm_utils_wifi_strength_bars(guint8 strength)
return " ";
}
+gboolean
+_nm_property_variant_to_gvalue(GVariant *src_value, GValue *dst_value)
+{
+ GValue tmp = G_VALUE_INIT;
+ gboolean success;
+
+ g_dbus_gvariant_to_gvalue(src_value, &tmp);
+ if (G_VALUE_TYPE(&tmp) == G_VALUE_TYPE(dst_value)) {
+ *dst_value = tmp;
+ return TRUE;
+ }
+
+ success = g_value_transform(&tmp, dst_value);
+ g_value_unset(&tmp);
+ return success;
+}
+
/**
* nm_utils_hwaddr_len:
* @type: the type of address; either <literal>ARPHRD_ETHER</literal> or
@@ -3880,6 +3897,25 @@ _nm_utils_hwaddr_canonical_or_invalid(const char *mac, gssize length)
return g_strdup(mac);
}
+char *
+_nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip)
+{
+ NMIPAddr addr_bin;
+
+ nm_assert_addr_family(addr_family);
+
+ if (!ip)
+ return NULL;
+
+ if (!nm_utils_parse_inaddr_bin(addr_family, ip, NULL, &addr_bin))
+ return g_strdup(ip);
+
+ if (nm_ip_addr_is_null(addr_family, &addr_bin))
+ return NULL;
+
+ return nm_utils_inet_ntop_dup(addr_family, &addr_bin);
+}
+
/*
* Determine if given Ethernet address is link-local
*
@@ -4149,26 +4185,6 @@ const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address =
.to_dbus_fcn = _nm_utils_hwaddr_cloned_data_synth,
.from_dbus_fcn = _nm_utils_hwaddr_cloned_data_set, );
-static void
-_nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value)
-{
- gsize length = 0;
- const guint8 *array = g_variant_get_fixed_array(dbus_value, &length, 1);
- char * str;
-
- str = length ? nm_utils_hwaddr_ntoa(array, length) : NULL;
- g_value_take_string(prop_value, str);
-}
-
-const NMSettInfoPropertType nm_sett_info_propert_type_mac_address =
- NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_BYTESTRING,
- .typdata_from_dbus.gprop_fcn = _nm_utils_hwaddr_from_dbus,
- .typdata_to_dbus.gprop_type =
- NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS,
- .compare_fcn = _nm_setting_property_compare_fcn_default,
- .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
- .from_dbus_is_full = TRUE);
-
/*****************************************************************************/
/* Validate secret-flags. Most settings don't validate them, which is a bug.
diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c
index 824ac5a206..26f0ca595d 100644
--- a/src/libnm-core-impl/tests/test-general.c
+++ b/src/libnm-core-impl/tests/test-general.c
@@ -10558,6 +10558,60 @@ test_strsplit_quoted(void)
/*****************************************************************************/
static void
+test_nm_property_variant_to_gvalue(void)
+{
+#define _test_variant_to_gvalue_bad(variant, gtype) \
+ G_STMT_START \
+ { \
+ gs_unref_variant GVariant * _variant = (variant); \
+ GType _gtype = (gtype); \
+ nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \
+ \
+ g_value_init(&_gvalue, _gtype); \
+ g_assert_cmpint(_nm_property_variant_to_gvalue(_variant, &_gvalue), ==, FALSE); \
+ } \
+ G_STMT_END
+
+#define _test_variant_to_gvalue(variant, gtype, check) \
+ G_STMT_START \
+ { \
+ gs_unref_variant GVariant * _variant = (variant); \
+ GType _gtype = (gtype); \
+ nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \
+ _nm_unused GValue *const gg = &_gvalue; \
+ \
+ g_value_init(&_gvalue, _gtype); \
+ g_assert_cmpint(_nm_property_variant_to_gvalue(_variant, &_gvalue), ==, TRUE); \
+ check; \
+ } \
+ G_STMT_END
+
+#define _test_variant_to_gvalue_int(variant, gtype, gvalue_get, expected) \
+ _test_variant_to_gvalue((variant), (gtype), g_assert_cmpint(gvalue_get(gg), ==, (expected)))
+
+ _test_variant_to_gvalue_bad(g_variant_new_string(""), G_TYPE_BOOLEAN);
+ _test_variant_to_gvalue(g_variant_new_string(""),
+ G_TYPE_STRING,
+ g_assert_cmpstr(g_value_get_string(gg), ==, ""));
+ _test_variant_to_gvalue_int(g_variant_new_boolean(FALSE),
+ G_TYPE_BOOLEAN,
+ g_value_get_boolean,
+ FALSE);
+ _test_variant_to_gvalue_int(g_variant_new_boolean(TRUE),
+ G_TYPE_BOOLEAN,
+ g_value_get_boolean,
+ TRUE);
+ _test_variant_to_gvalue_int(g_variant_new_int32(0), G_TYPE_BOOLEAN, g_value_get_boolean, FALSE);
+ _test_variant_to_gvalue_int(g_variant_new_int32(1), G_TYPE_BOOLEAN, g_value_get_boolean, 1);
+ _test_variant_to_gvalue_int(g_variant_new_int32(2), G_TYPE_BOOLEAN, g_value_get_boolean, 1);
+ _test_variant_to_gvalue_int(g_variant_new_byte(0), G_TYPE_BOOLEAN, g_value_get_boolean, 0);
+ _test_variant_to_gvalue_int(g_variant_new_byte(1), G_TYPE_BOOLEAN, g_value_get_boolean, 1);
+ _test_variant_to_gvalue_int(g_variant_new_byte(2), G_TYPE_BOOLEAN, g_value_get_boolean, 1);
+}
+
+/*****************************************************************************/
+
+static void
_do_wifi_ghz_freqs(const guint *freqs, const char *band)
{
int len;
@@ -10876,6 +10930,9 @@ main(int argc, char **argv)
g_test_add_func("/core/general/test_setting_connection_permissions_property",
test_setting_connection_permissions_property);
+ g_test_add_func("/core/general/test_nm_property_variant_to_gvalue",
+ test_nm_property_variant_to_gvalue);
+
g_test_add_func("/core/general/test_connection_compare_same", test_connection_compare_same);
g_test_add_func("/core/general/test_connection_compare_key_only_in_a",
test_connection_compare_key_only_in_a);
diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c
index 1c081b55db..1aab3d14a1 100644
--- a/src/libnm-core-impl/tests/test-setting.c
+++ b/src/libnm-core-impl/tests/test-setting.c
@@ -7,6 +7,8 @@
#include <linux/pkt_sched.h>
#include <net/if.h>
+#include <linux/if_ether.h>
+#include <linux/if_infiniband.h>
#include "libnm-glib-aux/nm-uuid.h"
#include "libnm-glib-aux/nm-json-aux.h"
@@ -4451,6 +4453,25 @@ test_setting_metadata(void)
g_assert(sip->param_spec);
g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN);
can_set_including_default = TRUE;
+ } else if (sip->property_type->direct_type == NM_VALUE_TYPE_INT32) {
+ const GParamSpecInt *pspec;
+
+ g_assert(sip->property_type == &nm_sett_info_propert_type_direct_int32);
+ g_assert(g_variant_type_equal(sip->property_type->dbus_type, "i"));
+ g_assert(sip->property_type->to_dbus_fcn
+ == _nm_setting_property_to_dbus_fcn_direct);
+ g_assert(sip->param_spec);
+ g_assert(sip->param_spec->value_type == G_TYPE_INT);
+
+ pspec = NM_G_PARAM_SPEC_CAST_INT(sip->param_spec);
+ g_assert_cmpint(pspec->minimum, <=, pspec->maximum);
+ g_assert_cmpint(pspec->default_value, >=, pspec->minimum);
+ g_assert_cmpint(pspec->default_value, <=, pspec->maximum);
+
+ g_assert_cmpint(pspec->minimum, >=, (gint64) G_MININT32);
+ g_assert_cmpint(pspec->maximum, <=, (gint64) G_MAXINT32);
+
+ can_set_including_default = TRUE;
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT32) {
const GParamSpecUInt *pspec;
@@ -4470,14 +4491,39 @@ test_setting_metadata(void)
can_set_including_default = TRUE;
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_STRING) {
- g_assert(g_variant_type_equal(sip->property_type->dbus_type, "s"));
- g_assert(sip->property_type->to_dbus_fcn
- == _nm_setting_property_to_dbus_fcn_direct);
+ if (sip->property_type == &nm_sett_info_propert_type_direct_mac_address) {
+ g_assert(g_variant_type_equal(sip->property_type->dbus_type, "ay"));
+ g_assert(sip->property_type->to_dbus_fcn
+ == _nm_setting_property_to_dbus_fcn_direct_mac_address);
+ g_assert(NM_IN_SET((guint) sip->direct_set_string_mac_address_len,
+ ETH_ALEN,
+ 8,
+ INFINIBAND_ALEN));
+ } else {
+ g_assert(g_variant_type_equal(sip->property_type->dbus_type, "s"));
+ g_assert(sip->property_type->to_dbus_fcn
+ == _nm_setting_property_to_dbus_fcn_direct);
+ }
g_assert(sip->param_spec);
g_assert(sip->param_spec->value_type == G_TYPE_STRING);
} else
g_assert_not_reached();
+ if (sip->direct_set_string_ascii_strdown)
+ g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING);
+
+ if (sip->direct_set_string_mac_address_len != 0) {
+ g_assert(NM_IN_SET(sip->property_type,
+ &nm_sett_info_propert_type_direct_string,
+ &nm_sett_info_propert_type_direct_mac_address));
+ g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING);
+ }
+
+ g_assert(((sip->direct_set_string_mac_address_len != 0)
+ + (!!sip->direct_set_string_ascii_strdown)
+ + (sip->direct_set_string_ip_address_addr_family != 0))
+ <= 1);
+
if (!sip->property_type->to_dbus_fcn) {
/* it's allowed to have no to_dbus_fcn(), to ignore a property. But such
* properties must not have a param_spec. */
@@ -4500,9 +4546,6 @@ test_setting_metadata(void)
case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT:
g_assert(sip->param_spec->value_type == G_TYPE_HASH_TABLE);
goto check_done;
- case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS:
- g_assert(sip->param_spec->value_type == G_TYPE_STRING);
- goto check_done;
case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT:
goto check_done;
}
@@ -4519,11 +4562,29 @@ check_done:;
g_assert(sip->property_type->from_dbus_fcn
== _nm_setting_property_from_dbus_fcn_gprop);
}
+ if (sip->property_type->from_dbus_direct_allow_transform) {
+ g_assert(sip->property_type->from_dbus_fcn
+ == _nm_setting_property_from_dbus_fcn_direct);
+ }
+ if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_direct) {
+ /* for the moment, all direct properties allow transformation. */
+ g_assert(sip->property_type->from_dbus_direct_allow_transform);
+ }
+
if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_gprop)
g_assert(sip->param_spec);
+ if (sip->property_type->from_dbus_fcn) {
+ if (sip->property_type->direct_type != NM_VALUE_TYPE_NONE) {
+ g_assert(NM_IN_SET(sip->property_type->from_dbus_fcn,
+ _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway,
+ _nm_setting_property_from_dbus_fcn_direct_mac_address,
+ _nm_setting_property_from_dbus_fcn_direct));
+ }
+ }
g_assert(sip->property_type->from_dbus_is_full
== NM_IN_SET(sip->property_type->from_dbus_fcn,
+ _nm_setting_property_from_dbus_fcn_direct,
_nm_setting_property_from_dbus_fcn_gprop,
_nm_setting_property_from_dbus_fcn_ignore));
@@ -4536,8 +4597,9 @@ check_done:;
} else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_direct) {
g_assert(sip->param_spec);
g_assert(sip->property_type->direct_type != NM_VALUE_TYPE_NONE);
- g_assert(sip->property_type->to_dbus_fcn
- == _nm_setting_property_to_dbus_fcn_direct);
+ g_assert(NM_IN_SET(sip->property_type->to_dbus_fcn,
+ _nm_setting_property_to_dbus_fcn_direct,
+ _nm_setting_property_to_dbus_fcn_direct_mac_address));
} else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_ignore) {
if (NM_IN_SET(sip->property_type,
&nm_sett_info_propert_type_deprecated_ignore_i,
diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h
index 26f69d3e65..4a8b9f66e7 100644
--- a/src/libnm-core-intern/nm-core-internal.h
+++ b/src/libnm-core-intern/nm-core-internal.h
@@ -679,7 +679,6 @@ typedef enum _nm_packed {
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,
- NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS,
} NMSettingPropertyToDBusFcnGPropType;
typedef struct {
@@ -702,6 +701,13 @@ typedef struct {
* from_dbus_fcn() are ignored. If true, then error are propagated. */
bool from_dbus_is_full : 1;
+ /* Only if from_dbus_fcn is set to _nm_setting_property_from_dbus_fcn_direct.
+ * Historically, libnm used g_dbus_gvariant_to_gvalue() and g_value_transform() to
+ * convert from D-Bus to the GObject property. Thereby, various transformations are
+ * allowed and supported. If this is TRUE, then such transformations are still
+ * allowed for backward compatibility. */
+ bool from_dbus_direct_allow_transform : 1;
+
/* compare_fcn() returns a ternary, where DEFAULT means that the property should not
* be compared due to the compare @flags. A TRUE/FALSE result means that the property is
* equal/not-equal.
@@ -721,12 +727,10 @@ typedef struct {
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn;
struct {
- union {
- /* If from_dbus_fcn is set to _nm_setting_property_from_dbus_fcn_gprop,
- * then this is an optional handler for converting between GVariant and
- * GValue. */
- NMSettInfoPropGPropFromDBusFcn gprop_fcn;
- };
+ /* Only if from_dbus_fcn is set to _nm_setting_property_from_dbus_fcn_gprop.
+ * This is an optional handler for converting between GVariant and
+ * GValue. */
+ NMSettInfoPropGPropFromDBusFcn gprop_fcn;
} typdata_from_dbus;
struct {
@@ -749,15 +753,19 @@ struct _NMSettInfoProperty {
* the direct location. */
guint16 direct_offset;
- /* Currently, properties that set property_type->direct_type only have to_dbus_fcn()
- * implemented "the direct way". For the property setter, they still call g_object_set().
- * In the future, also other operations, like from_dbus_fcn() should be implemented
- * by direct access (thereby, bypassing g_object_set()).
- *
- * A "direct_has_special_setter" property does something unusual, that will require special attention
- * in the future, when we implement more functionality regarding the setter. It has no effect,
- * except of marking those properties and serve as a reminder that special care needs to be taken. */
- bool direct_has_special_setter : 1;
+ /* If TRUE, this is a NM_VALUE_TYPE_STRING direct property, and the setter will
+ * normalize the string via g_ascii_strdown(). */
+ bool direct_set_string_ascii_strdown : 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. */
+ guint8 direct_set_string_ip_address_addr_family : 5;
/* 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().
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index 747f626bfa..e8c282d8a2 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -1437,6 +1437,8 @@ GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char *
#define NM_G_PARAM_SPEC_CAST_BOOLEAN(param_spec) \
_NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_BOOLEAN, GParamSpecBoolean)
+#define NM_G_PARAM_SPEC_CAST_INT(param_spec) \
+ _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_INT, GParamSpecInt)
#define NM_G_PARAM_SPEC_CAST_UINT(param_spec) \
_NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_UINT, GParamSpecUInt)
#define NM_G_PARAM_SPEC_CAST_UINT64(param_spec) \
@@ -1446,6 +1448,8 @@ GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char *
#define NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(param_spec) \
(NM_G_PARAM_SPEC_CAST_BOOLEAN(NM_ENSURE_NOT_NULL(param_spec))->default_value)
+#define NM_G_PARAM_SPEC_GET_DEFAULT_INT(param_spec) \
+ (NM_G_PARAM_SPEC_CAST_INT(NM_ENSURE_NOT_NULL(param_spec))->default_value)
#define NM_G_PARAM_SPEC_GET_DEFAULT_UINT(param_spec) \
(NM_G_PARAM_SPEC_CAST_UINT(NM_ENSURE_NOT_NULL(param_spec))->default_value)
#define NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(param_spec) \