From 0a2711eaad2a97ddd29a7e91908376a0f88573ce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 17:02:52 +0200 Subject: [PATCH 01/16] glib-aux: add NM_VALUE_TYPE_NONE We have NM_VALUE_TYPE_UNSPEC (with numeric value 1). NM_VALUE_TYPE_UNSPEC means that there is some undefined opaque type, that cannot be handled generically. But what we also need is NM_VALUE_TYPE_NONE (with numeric value 0) to express that no type was set. --- src/libnm-glib-aux/nm-json-aux.h | 2 ++ src/libnm-glib-aux/nm-value-type.h | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/libnm-glib-aux/nm-json-aux.h b/src/libnm-glib-aux/nm-json-aux.h index 936e914641..b61c1f843a 100644 --- a/src/libnm-glib-aux/nm-json-aux.h +++ b/src/libnm-glib-aux/nm-json-aux.h @@ -339,6 +339,7 @@ nm_value_type_to_json(NMValueType value_type, GString *gstr, gconstpointer p_fie case NM_VALUE_TYPE_STRING: nm_json_gstr_append_string(gstr, *((const char *const *) p_field)); return; + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } @@ -368,6 +369,7 @@ nm_value_type_from_json(const NMJsonVt * vt, case NM_VALUE_TYPE_STRING: return (nm_jansson_json_as_string(vt, elem, out_val) > 0); + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } diff --git a/src/libnm-glib-aux/nm-value-type.h b/src/libnm-glib-aux/nm-value-type.h index 6156896c14..541797e9bf 100644 --- a/src/libnm-glib-aux/nm-value-type.h +++ b/src/libnm-glib-aux/nm-value-type.h @@ -7,6 +7,7 @@ #define __NM_VALUE_TYPE_H__ typedef enum _nm_packed { + NM_VALUE_TYPE_NONE = 0, NM_VALUE_TYPE_UNSPEC = 1, NM_VALUE_TYPE_BOOL = 2, NM_VALUE_TYPE_INT32 = 3, @@ -90,6 +91,7 @@ nm_value_type_cmp(NMValueType value_type, gconstpointer p_a, gconstpointer p_b) return 0; case NM_VALUE_TYPE_STRING: return nm_strcmp0(*((const char *const *) p_a), *((const char *const *) p_b)); + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } @@ -129,6 +131,7 @@ nm_value_type_copy(NMValueType value_type, gpointer dst, gconstpointer src) *((char **) dst) = g_strdup(*((const char *const *) src)); } return; + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } @@ -169,6 +172,7 @@ nm_value_type_get_from_variant(NMValueType value_type, * clear how many bits we would need. */ /* fall-through */ + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } @@ -198,6 +202,7 @@ nm_value_type_to_variant(NMValueType value_type, gconstpointer src) * clear how many bits we would need. */ /* fall-through */ + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } @@ -225,6 +230,7 @@ nm_value_type_get_variant_type(NMValueType value_type) * clear how many bits we would need. */ /* fall-through */ + case NM_VALUE_TYPE_NONE: case NM_VALUE_TYPE_UNSPEC: break; } From da7c2a6ebeab9ecba88072717e91240cadf9f7cb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 08:10:58 +0200 Subject: [PATCH 02/16] glib-aux: add uint32 and uint64 types to NMValueType --- src/libnm-glib-aux/nm-json-aux.h | 53 ++++++++++++++++++++++++++++++ src/libnm-glib-aux/nm-value-type.h | 34 ++++++++++++++++--- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/libnm-glib-aux/nm-json-aux.h b/src/libnm-glib-aux/nm-json-aux.h index b61c1f843a..ba2b35d27c 100644 --- a/src/libnm-glib-aux/nm-json-aux.h +++ b/src/libnm-glib-aux/nm-json-aux.h @@ -270,6 +270,49 @@ nm_jansson_json_as_int64(const NMJsonVt *vt, const nm_json_t *elem, gint64 *out_ return 1; } +static inline int +nm_jansson_json_as_uint32(const NMJsonVt *vt, const nm_json_t *elem, guint32 *out_val) +{ + nm_json_int_t v; + + if (!elem) + return 0; + + if (!nm_json_is_integer(elem)) + return -EINVAL; + + v = vt->nm_json_integer_value(elem); + if (v < 0) + return -ERANGE; + if (v > (guint64) G_MAXUINT32) + return -ERANGE; + + NM_SET_OUT(out_val, v); + return 1; +} + +static inline int +nm_jansson_json_as_uint(const NMJsonVt *vt, const nm_json_t *elem, guint *out_val) +{ + nm_json_int_t v; + + if (!elem) + return 0; + + if (!nm_json_is_integer(elem)) + return -EINVAL; + + v = vt->nm_json_integer_value(elem); + if (v < 0) + return -ERANGE; + + if (v > (guint64) G_MAXUINT) + return -ERANGE; + + NM_SET_OUT(out_val, v); + return 1; +} + static inline int nm_jansson_json_as_uint64(const NMJsonVt *vt, const nm_json_t *elem, guint64 *out_val) { @@ -333,6 +376,12 @@ nm_value_type_to_json(NMValueType value_type, GString *gstr, gconstpointer p_fie case NM_VALUE_TYPE_INT64: nm_json_gstr_append_int64(gstr, *((const gint64 *) p_field)); return; + case NM_VALUE_TYPE_UINT32: + nm_json_gstr_append_uint64(gstr, *((const guint32 *) p_field)); + return; + case NM_VALUE_TYPE_UINT: + nm_json_gstr_append_uint64(gstr, *((const guint *) p_field)); + return; case NM_VALUE_TYPE_UINT64: nm_json_gstr_append_uint64(gstr, *((const guint64 *) p_field)); return; @@ -361,6 +410,10 @@ nm_value_type_from_json(const NMJsonVt * vt, return (nm_jansson_json_as_int(vt, elem, out_val) > 0); case NM_VALUE_TYPE_INT64: return (nm_jansson_json_as_int64(vt, elem, out_val) > 0); + case NM_VALUE_TYPE_UINT32: + return (nm_jansson_json_as_uint32(vt, elem, out_val) > 0); + case NM_VALUE_TYPE_UINT: + return (nm_jansson_json_as_uint(vt, elem, out_val) > 0); case NM_VALUE_TYPE_UINT64: return (nm_jansson_json_as_uint64(vt, elem, out_val) > 0); diff --git a/src/libnm-glib-aux/nm-value-type.h b/src/libnm-glib-aux/nm-value-type.h index 541797e9bf..4e54ad463c 100644 --- a/src/libnm-glib-aux/nm-value-type.h +++ b/src/libnm-glib-aux/nm-value-type.h @@ -13,8 +13,10 @@ typedef enum _nm_packed { NM_VALUE_TYPE_INT32 = 3, NM_VALUE_TYPE_INT = 4, NM_VALUE_TYPE_INT64 = 5, - NM_VALUE_TYPE_UINT64 = 6, - NM_VALUE_TYPE_STRING = 7, + NM_VALUE_TYPE_UINT32 = 6, + NM_VALUE_TYPE_UINT = 7, + NM_VALUE_TYPE_UINT64 = 8, + NM_VALUE_TYPE_STRING = 9, } NMValueType; /*****************************************************************************/ @@ -86,6 +88,12 @@ nm_value_type_cmp(NMValueType value_type, gconstpointer p_a, gconstpointer p_b) case NM_VALUE_TYPE_INT64: NM_CMP_DIRECT(*((const gint64 *) p_a), *((const gint64 *) p_b)); return 0; + case NM_VALUE_TYPE_UINT32: + NM_CMP_DIRECT(*((const guint32 *) p_a), *((const guint32 *) p_b)); + return 0; + case NM_VALUE_TYPE_UINT: + NM_CMP_DIRECT(*((const guint *) p_a), *((const guint *) p_b)); + return 0; case NM_VALUE_TYPE_UINT64: NM_CMP_DIRECT(*((const guint64 *) p_a), *((const guint64 *) p_b)); return 0; @@ -121,6 +129,12 @@ nm_value_type_copy(NMValueType value_type, gpointer dst, gconstpointer src) case NM_VALUE_TYPE_INT64: (*((gint64 *) dst) = *((const gint64 *) src)); return; + case NM_VALUE_TYPE_UINT32: + (*((guint32 *) dst) = *((const guint32 *) src)); + return; + case NM_VALUE_TYPE_UINT: + (*((guint *) dst) = *((const guint *) src)); + return; case NM_VALUE_TYPE_UINT64: (*((guint64 *) dst) = *((const guint64 *) src)); return; @@ -154,6 +168,9 @@ nm_value_type_get_from_variant(NMValueType value_type, case NM_VALUE_TYPE_INT64: *((gint64 *) dst) = g_variant_get_int64(variant); return; + case NM_VALUE_TYPE_UINT32: + *((guint32 *) dst) = g_variant_get_uint32(variant); + return; case NM_VALUE_TYPE_UINT64: *((guint64 *) dst) = g_variant_get_uint64(variant); return; @@ -168,7 +185,8 @@ nm_value_type_get_from_variant(NMValueType value_type, return; case NM_VALUE_TYPE_INT: - /* "int" also does not have a define variant type, because it's not + case NM_VALUE_TYPE_UINT: + /* "int" and "uint" also does not have a defined variant type, because it's not * clear how many bits we would need. */ /* fall-through */ @@ -191,6 +209,8 @@ nm_value_type_to_variant(NMValueType value_type, gconstpointer src) return g_variant_new_int32(*((const gint32 *) src)); case NM_VALUE_TYPE_INT64: return g_variant_new_int64(*((const gint64 *) src)); + case NM_VALUE_TYPE_UINT32: + return g_variant_new_uint32(*((const guint32 *) src)); case NM_VALUE_TYPE_UINT64: return g_variant_new_uint64(*((const guint64 *) src)); case NM_VALUE_TYPE_STRING: @@ -198,7 +218,8 @@ nm_value_type_to_variant(NMValueType value_type, gconstpointer src) return v_string ? g_variant_new_string(v_string) : NULL; case NM_VALUE_TYPE_INT: - /* "int" also does not have a define variant type, because it's not + case NM_VALUE_TYPE_UINT: + /* "int" and "uint" also does not have a defined variant type, because it's not * clear how many bits we would need. */ /* fall-through */ @@ -220,13 +241,16 @@ nm_value_type_get_variant_type(NMValueType value_type) return G_VARIANT_TYPE_INT32; case NM_VALUE_TYPE_INT64: return G_VARIANT_TYPE_INT64; + case NM_VALUE_TYPE_UINT32: + return G_VARIANT_TYPE_UINT32; case NM_VALUE_TYPE_UINT64: return G_VARIANT_TYPE_UINT64; case NM_VALUE_TYPE_STRING: return G_VARIANT_TYPE_STRING; case NM_VALUE_TYPE_INT: - /* "int" also does not have a define variant type, because it's not + case NM_VALUE_TYPE_UINT: + /* "int" and "uint" also does not have a defined variant type, because it's not * clear how many bits we would need. */ /* fall-through */ From dc649d1336ede7ec6b515f6d806ee782ec58cadb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 20:54:09 +0200 Subject: [PATCH 03/16] libnm/tests: add test for setting "6lowpan.parent" --- src/libnm-core-impl/tests/test-setting.c | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index f29cd6a8c1..81ecb3b03d 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4747,6 +4747,38 @@ test_setting_connection_secondaries_verify(void) /*****************************************************************************/ +static void +test_6lowpan_1(void) +{ + gs_unref_object NMConnection *con = NULL; + NMSetting6Lowpan * s_6low; + gs_free char * value = NULL; + + con = nmtst_create_minimal_connection("test-sec", NULL, NM_SETTING_6LOWPAN_SETTING_NAME, NULL); + + s_6low = NM_SETTING_6LOWPAN(nm_connection_get_setting(con, NM_TYPE_SETTING_6LOWPAN)); + g_assert(s_6low); + + g_assert_cmpstr(nm_setting_6lowpan_get_parent(s_6low), ==, NULL); + g_object_get(s_6low, NM_SETTING_6LOWPAN_PARENT, &value, NULL); + g_assert_cmpstr(value, ==, NULL); + nm_clear_g_free(&value); + + g_object_set(s_6low, NM_SETTING_6LOWPAN_PARENT, "hello", NULL); + g_assert_cmpstr(nm_setting_6lowpan_get_parent(s_6low), ==, "hello"); + g_object_get(s_6low, NM_SETTING_6LOWPAN_PARENT, &value, NULL); + g_assert_cmpstr(value, ==, "hello"); + nm_clear_g_free(&value); + + g_object_set(s_6low, NM_SETTING_6LOWPAN_PARENT, "world", NULL); + g_assert_cmpstr(nm_setting_6lowpan_get_parent(s_6low), ==, "world"); + g_object_get(s_6low, NM_SETTING_6LOWPAN_PARENT, &value, NULL); + g_assert_cmpstr(value, ==, "world"); + nm_clear_g_free(&value); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -4788,6 +4820,8 @@ main(int argc, char **argv) g_test_add_func("/libnm/settings/ethtool/ring", test_ethtool_ring); g_test_add_func("/libnm/settings/ethtool/pause", test_ethtool_pause); + g_test_add_func("/libnm/settings/6lowpan/1", test_6lowpan_1); + g_test_add_func("/libnm/settings/sriov/vf", test_sriov_vf); g_test_add_func("/libnm/settings/sriov/vf-dup", test_sriov_vf_dup); g_test_add_func("/libnm/settings/sriov/vf-vlan", test_sriov_vf_vlan); From d6f802abcdea440d0144cdd6cabe11c86fd7bf19 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 14:53:16 +0200 Subject: [PATCH 04/16] libnm: extend NMSettInfoSetting with an offset to the private data NMSetting instances either have no private data, they use g_type_add_class_private(), or they embed the private data in the NMSetting struct. In all cases, we can find the private data at a fixed offset. Track that offset in the NMSettInfoSetting meta data. This will be useful, because properties really are stored in simple fields, like a boolean property can be stored in a "bool" field. We will extend the property meta data to track the offset of this property field, but we also need to know where the offset starts. --- src/libnm-core-impl/nm-setting-6lowpan.c | 9 ++++---- src/libnm-core-impl/nm-setting-8021x.c | 9 ++++---- src/libnm-core-impl/nm-setting-adsl.c | 9 ++++---- src/libnm-core-impl/nm-setting-bluetooth.c | 9 ++++---- src/libnm-core-impl/nm-setting-bond.c | 9 ++++---- src/libnm-core-impl/nm-setting-bridge-port.c | 9 ++++---- src/libnm-core-impl/nm-setting-bridge.c | 9 ++++---- src/libnm-core-impl/nm-setting-cdma.c | 2 +- src/libnm-core-impl/nm-setting-connection.c | 9 ++++---- src/libnm-core-impl/nm-setting-dcb.c | 9 ++++---- src/libnm-core-impl/nm-setting-dummy.c | 2 +- src/libnm-core-impl/nm-setting-ethtool.c | 5 +++-- src/libnm-core-impl/nm-setting-generic.c | 2 +- src/libnm-core-impl/nm-setting-gsm.c | 9 ++++---- src/libnm-core-impl/nm-setting-hostname.c | 2 +- src/libnm-core-impl/nm-setting-infiniband.c | 9 ++++---- src/libnm-core-impl/nm-setting-ip-tunnel.c | 9 ++++---- src/libnm-core-impl/nm-setting-ip4-config.c | 9 ++++---- src/libnm-core-impl/nm-setting-ip6-config.c | 9 ++++---- src/libnm-core-impl/nm-setting-macsec.c | 9 ++++---- src/libnm-core-impl/nm-setting-macvlan.c | 9 ++++---- src/libnm-core-impl/nm-setting-match.c | 2 +- src/libnm-core-impl/nm-setting-olpc-mesh.c | 9 ++++---- src/libnm-core-impl/nm-setting-ovs-bridge.c | 9 ++++---- src/libnm-core-impl/nm-setting-ovs-dpdk.c | 2 +- .../nm-setting-ovs-external-ids.c | 9 ++++---- .../nm-setting-ovs-interface.c | 2 +- src/libnm-core-impl/nm-setting-ovs-patch.c | 2 +- src/libnm-core-impl/nm-setting-ovs-port.c | 2 +- src/libnm-core-impl/nm-setting-ppp.c | 9 ++++---- src/libnm-core-impl/nm-setting-pppoe.c | 2 +- src/libnm-core-impl/nm-setting-private.h | 17 ++++++--------- src/libnm-core-impl/nm-setting-proxy.c | 9 ++++---- src/libnm-core-impl/nm-setting-serial.c | 9 ++++---- src/libnm-core-impl/nm-setting-sriov.c | 9 ++++---- src/libnm-core-impl/nm-setting-tc-config.c | 9 ++++---- src/libnm-core-impl/nm-setting-team-port.c | 9 ++++---- src/libnm-core-impl/nm-setting-team.c | 9 ++++---- src/libnm-core-impl/nm-setting-tun.c | 9 ++++---- src/libnm-core-impl/nm-setting-user.c | 9 ++++---- src/libnm-core-impl/nm-setting-veth.c | 2 +- src/libnm-core-impl/nm-setting-vlan.c | 9 ++++---- src/libnm-core-impl/nm-setting-vpn.c | 9 ++++---- src/libnm-core-impl/nm-setting-vrf.c | 2 +- src/libnm-core-impl/nm-setting-vxlan.c | 9 ++++---- src/libnm-core-impl/nm-setting-wifi-p2p.c | 2 +- src/libnm-core-impl/nm-setting-wimax.c | 9 ++++---- src/libnm-core-impl/nm-setting-wired.c | 9 ++++---- src/libnm-core-impl/nm-setting-wireguard.c | 9 ++++---- .../nm-setting-wireless-security.c | 9 ++++---- src/libnm-core-impl/nm-setting-wireless.c | 9 ++++---- src/libnm-core-impl/nm-setting-wpan.c | 2 +- src/libnm-core-impl/nm-setting.c | 21 +++++++++++++++---- src/libnm-core-impl/tests/test-setting.c | 12 +++++++++++ src/libnm-core-intern/nm-core-internal.h | 18 +++++++++++++++- 55 files changed, 249 insertions(+), 176 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-6lowpan.c b/src/libnm-core-impl/nm-setting-6lowpan.c index c07fb38e69..f647b249b5 100644 --- a/src/libnm-core-impl/nm-setting-6lowpan.c +++ b/src/libnm-core-impl/nm-setting-6lowpan.c @@ -225,8 +225,9 @@ nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_6LOWPAN, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_6LOWPAN, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-8021x.c b/src/libnm-core-impl/nm-setting-8021x.c index 6ddbd68066..940bf951eb 100644 --- a/src/libnm-core-impl/nm-setting-8021x.c +++ b/src/libnm-core-impl/nm-setting-8021x.c @@ -4648,8 +4648,9 @@ nm_setting_802_1x_class_init(NMSetting8021xClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_802_1X, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_802_1X, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-adsl.c b/src/libnm-core-impl/nm-setting-adsl.c index 9f45163dff..233467240e 100644 --- a/src/libnm-core-impl/nm-setting-adsl.c +++ b/src/libnm-core-impl/nm-setting-adsl.c @@ -454,8 +454,9 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_ADSL, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_ADSL, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-bluetooth.c b/src/libnm-core-impl/nm-setting-bluetooth.c index 4bd91a691a..aa97e4dcb9 100644 --- a/src/libnm-core-impl/nm-setting-bluetooth.c +++ b/src/libnm-core-impl/nm-setting-bluetooth.c @@ -341,8 +341,9 @@ nm_setting_bluetooth_class_init(NMSettingBluetoothClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_BLUETOOTH, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_BLUETOOTH, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-bond.c b/src/libnm-core-impl/nm-setting-bond.c index 252adc73b5..6ef85f633e 100644 --- a/src/libnm-core-impl/nm-setting-bond.c +++ b/src/libnm-core-impl/nm-setting-bond.c @@ -1231,8 +1231,9 @@ nm_setting_bond_class_init(NMSettingBondClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_BOND, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_BOND, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-bridge-port.c b/src/libnm-core-impl/nm-setting-bridge-port.c index 33d0c00915..aefefe6f14 100644 --- a/src/libnm-core-impl/nm-setting-bridge-port.c +++ b/src/libnm-core-impl/nm-setting-bridge-port.c @@ -609,8 +609,9 @@ nm_setting_bridge_port_class_init(NMSettingBridgePortClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_BRIDGE_PORT, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_BRIDGE_PORT, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index e987310f6f..54df6480b4 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -2301,8 +2301,9 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_BRIDGE, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_BRIDGE, + NULL, + properties_override, + G_STRUCT_OFFSET(NMSettingBridge, _priv)); } diff --git a/src/libnm-core-impl/nm-setting-cdma.c b/src/libnm-core-impl/nm-setting-cdma.c index 6dc61e8385..ca81bf385c 100644 --- a/src/libnm-core-impl/nm-setting-cdma.c +++ b/src/libnm-core-impl/nm-setting-cdma.c @@ -370,5 +370,5 @@ nm_setting_cdma_class_init(NMSettingCdmaClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_CDMA); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_CDMA, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 4441d965d9..bb5c3c82e5 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -2568,8 +2568,9 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_CONNECTION, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_CONNECTION, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index f9602c3bbf..fa666654c5 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -1282,8 +1282,9 @@ nm_setting_dcb_class_init(NMSettingDcbClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_DCB, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_DCB, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-dummy.c b/src/libnm-core-impl/nm-setting-dummy.c index a998a27b14..bfc82aeaec 100644 --- a/src/libnm-core-impl/nm-setting-dummy.c +++ b/src/libnm-core-impl/nm-setting-dummy.c @@ -78,5 +78,5 @@ nm_setting_dummy_class_init(NMSettingDummyClass *klass) setting_class->verify = verify; - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_DUMMY); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_DUMMY, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-ethtool.c b/src/libnm-core-impl/nm-setting-ethtool.c index abedcae3eb..901dab487f 100644 --- a/src/libnm-core-impl/nm-setting-ethtool.c +++ b/src/libnm-core-impl/nm-setting-ethtool.c @@ -407,11 +407,12 @@ nm_setting_ethtool_class_init(NMSettingEthtoolClass *klass) setting_class->verify = verify; - _nm_setting_class_commit_full( + _nm_setting_class_commit( setting_class, NM_META_SETTING_TYPE_ETHTOOL, NM_SETT_INFO_SETT_DETAIL(.gendata_info = NM_SETT_INFO_SETT_GENDATA(.get_variant_type = get_variant_type, ), ), - NULL); + NULL, + 0); } diff --git a/src/libnm-core-impl/nm-setting-generic.c b/src/libnm-core-impl/nm-setting-generic.c index 0eff1ddf49..ce212554cf 100644 --- a/src/libnm-core-impl/nm-setting-generic.c +++ b/src/libnm-core-impl/nm-setting-generic.c @@ -74,5 +74,5 @@ nm_setting_generic_class_init(NMSettingGenericClass *klass) g_type_class_add_private(klass, sizeof(NMSettingGenericPrivate)); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_GENERIC); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_GENERIC, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-gsm.c b/src/libnm-core-impl/nm-setting-gsm.c index a177f7fb8c..d7d8457d01 100644 --- a/src/libnm-core-impl/nm-setting-gsm.c +++ b/src/libnm-core-impl/nm-setting-gsm.c @@ -879,8 +879,9 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_GSM, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_GSM, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-hostname.c b/src/libnm-core-impl/nm-setting-hostname.c index 248ae556e3..d002d70eab 100644 --- a/src/libnm-core-impl/nm-setting-hostname.c +++ b/src/libnm-core-impl/nm-setting-hostname.c @@ -335,5 +335,5 @@ nm_setting_hostname_class_init(NMSettingHostnameClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_HOSTNAME); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_HOSTNAME, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-infiniband.c b/src/libnm-core-impl/nm-setting-infiniband.c index 95dc7b6696..730b2d2649 100644 --- a/src/libnm-core-impl/nm-setting-infiniband.c +++ b/src/libnm-core-impl/nm-setting-infiniband.c @@ -530,8 +530,9 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_INFINIBAND, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_INFINIBAND, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index d87a59f4a8..e5a34f0c41 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -881,8 +881,9 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_IP_TUNNEL, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_IP_TUNNEL, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 15bae0cd40..f7f5931e4f 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -1052,8 +1052,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_IP4_CONFIG, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_IP4_CONFIG, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index f6d59a46d1..c72418dd69 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1096,8 +1096,9 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_IP6_CONFIG, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_IP6_CONFIG, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-macsec.c b/src/libnm-core-impl/nm-setting-macsec.c index 55024bb4c2..c180802505 100644 --- a/src/libnm-core-impl/nm-setting-macsec.c +++ b/src/libnm-core-impl/nm-setting-macsec.c @@ -686,8 +686,9 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_MACSEC, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_MACSEC, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-macvlan.c b/src/libnm-core-impl/nm-setting-macvlan.c index 9cb2b2621f..070a53064a 100644 --- a/src/libnm-core-impl/nm-setting-macvlan.c +++ b/src/libnm-core-impl/nm-setting-macvlan.c @@ -347,8 +347,9 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_MACVLAN, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_MACVLAN, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-match.c b/src/libnm-core-impl/nm-setting-match.c index e4f7c1a810..20c6b798e6 100644 --- a/src/libnm-core-impl/nm-setting-match.c +++ b/src/libnm-core-impl/nm-setting-match.c @@ -901,5 +901,5 @@ nm_setting_match_class_init(NMSettingMatchClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MATCH); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MATCH, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-olpc-mesh.c b/src/libnm-core-impl/nm-setting-olpc-mesh.c index 103f619519..ce7bdf1fb7 100644 --- a/src/libnm-core-impl/nm-setting-olpc-mesh.c +++ b/src/libnm-core-impl/nm-setting-olpc-mesh.c @@ -285,8 +285,9 @@ nm_setting_olpc_mesh_class_init(NMSettingOlpcMeshClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_OLPC_MESH, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_OLPC_MESH, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-ovs-bridge.c b/src/libnm-core-impl/nm-setting-ovs-bridge.c index 22738d204d..f4a46c6e3b 100644 --- a/src/libnm-core-impl/nm-setting-ovs-bridge.c +++ b/src/libnm-core-impl/nm-setting-ovs-bridge.c @@ -374,8 +374,9 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_OVS_BRIDGE, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_OVS_BRIDGE, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-dpdk.c b/src/libnm-core-impl/nm-setting-ovs-dpdk.c index 957b0f5716..3107531b27 100644 --- a/src/libnm-core-impl/nm-setting-ovs-dpdk.c +++ b/src/libnm-core-impl/nm-setting-ovs-dpdk.c @@ -148,5 +148,5 @@ nm_setting_ovs_dpdk_class_init(NMSettingOvsDpdkClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_DPDK); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_DPDK, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-external-ids.c b/src/libnm-core-impl/nm-setting-ovs-external-ids.c index b73c1af497..d8f41a5919 100644 --- a/src/libnm-core-impl/nm-setting-ovs-external-ids.c +++ b/src/libnm-core-impl/nm-setting-ovs-external-ids.c @@ -544,8 +544,9 @@ nm_setting_ovs_external_ids_class_init(NMSettingOvsExternalIDsClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_OVS_EXTERNAL_IDS, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_OVS_EXTERNAL_IDS, + NULL, + properties_override, + G_STRUCT_OFFSET(NMSettingOvsExternalIDs, _priv)); } diff --git a/src/libnm-core-impl/nm-setting-ovs-interface.c b/src/libnm-core-impl/nm-setting-ovs-interface.c index 1fde96050a..58a01fcc4c 100644 --- a/src/libnm-core-impl/nm-setting-ovs-interface.c +++ b/src/libnm-core-impl/nm-setting-ovs-interface.c @@ -423,5 +423,5 @@ nm_setting_ovs_interface_class_init(NMSettingOvsInterfaceClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_INTERFACE); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_INTERFACE, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-patch.c b/src/libnm-core-impl/nm-setting-ovs-patch.c index a226a26d47..578f5ee247 100644 --- a/src/libnm-core-impl/nm-setting-ovs-patch.c +++ b/src/libnm-core-impl/nm-setting-ovs-patch.c @@ -184,5 +184,5 @@ nm_setting_ovs_patch_class_init(NMSettingOvsPatchClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_PATCH); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_PATCH, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-port.c b/src/libnm-core-impl/nm-setting-ovs-port.c index 821f29ab14..a5d92019be 100644 --- a/src/libnm-core-impl/nm-setting-ovs-port.c +++ b/src/libnm-core-impl/nm-setting-ovs-port.c @@ -463,5 +463,5 @@ nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_PORT); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_PORT, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-ppp.c b/src/libnm-core-impl/nm-setting-ppp.c index cc722c4456..77713feb9e 100644 --- a/src/libnm-core-impl/nm-setting-ppp.c +++ b/src/libnm-core-impl/nm-setting-ppp.c @@ -806,8 +806,9 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_PPP, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_PPP, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-pppoe.c b/src/libnm-core-impl/nm-setting-pppoe.c index 12beb51a5b..1c97c05b15 100644 --- a/src/libnm-core-impl/nm-setting-pppoe.c +++ b/src/libnm-core-impl/nm-setting-pppoe.c @@ -370,5 +370,5 @@ nm_setting_pppoe_class_init(NMSettingPppoeClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_PPPOE); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_PPPOE, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index a16004905b..de76914df0 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -319,22 +319,17 @@ _nm_sett_info_property_override_create_array(void) { /* pre-allocate a relatively large buffer to avoid frequent re-allocations. * Note that the buffer is only short-lived and will be destroyed by - * _nm_setting_class_commit_full(). */ + * _nm_setting_class_commit(). */ return _nm_sett_info_property_override_create_array_sized(20); } GArray *_nm_sett_info_property_override_create_array_ip_config(void); -void _nm_setting_class_commit_full(NMSettingClass * setting_class, - NMMetaSettingType meta_type, - const NMSettInfoSettDetail *detail, - GArray * properties_override); - -static inline void -_nm_setting_class_commit(NMSettingClass *setting_class, NMMetaSettingType meta_type) -{ - _nm_setting_class_commit_full(setting_class, meta_type, NULL, NULL); -} +void _nm_setting_class_commit(NMSettingClass * setting_class, + NMMetaSettingType meta_type, + const NMSettInfoSettDetail *detail, + GArray * properties_override, + gint16 private_offset); #define NM_SETT_INFO_SETT_GENDATA(...) \ ({ \ diff --git a/src/libnm-core-impl/nm-setting-proxy.c b/src/libnm-core-impl/nm-setting-proxy.c index fd09e1d402..e4bd88fa73 100644 --- a/src/libnm-core-impl/nm-setting-proxy.c +++ b/src/libnm-core-impl/nm-setting-proxy.c @@ -396,8 +396,9 @@ nm_setting_proxy_class_init(NMSettingProxyClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_PROXY, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_PROXY, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index c87de166ac..0029551bc4 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -345,8 +345,9 @@ nm_setting_serial_class_init(NMSettingSerialClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_SERIAL, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_SERIAL, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index b18d184af8..e55bc4c53f 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -1365,8 +1365,9 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_SRIOV, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_SRIOV, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index a23371a10b..a82e65e61b 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -2258,8 +2258,9 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_TC_CONFIG, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_TC_CONFIG, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-team-port.c b/src/libnm-core-impl/nm-setting-team-port.c index 316fc67c96..11aae92638 100644 --- a/src/libnm-core-impl/nm-setting-team-port.c +++ b/src/libnm-core-impl/nm-setting-team-port.c @@ -694,8 +694,9 @@ nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) g_object_class_install_properties(object_class, G_N_ELEMENTS(obj_properties), obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_TEAM_PORT, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_TEAM_PORT, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-team.c b/src/libnm-core-impl/nm-setting-team.c index b9a368c51d..8669c58618 100644 --- a/src/libnm-core-impl/nm-setting-team.c +++ b/src/libnm-core-impl/nm-setting-team.c @@ -1827,8 +1827,9 @@ nm_setting_team_class_init(NMSettingTeamClass *klass) g_object_class_install_properties(object_class, G_N_ELEMENTS(obj_properties), obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_TEAM, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_TEAM, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-tun.c b/src/libnm-core-impl/nm-setting-tun.c index d75dcf80ab..3975d00027 100644 --- a/src/libnm-core-impl/nm-setting-tun.c +++ b/src/libnm-core-impl/nm-setting-tun.c @@ -413,8 +413,9 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_TUN, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_TUN, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-user.c b/src/libnm-core-impl/nm-setting-user.c index 0f99baa221..d5e028ce53 100644 --- a/src/libnm-core-impl/nm-setting-user.c +++ b/src/libnm-core-impl/nm-setting-user.c @@ -587,8 +587,9 @@ nm_setting_user_class_init(NMSettingUserClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_USER, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_USER, + NULL, + properties_override, + G_STRUCT_OFFSET(NMSettingUser, _priv)); } diff --git a/src/libnm-core-impl/nm-setting-veth.c b/src/libnm-core-impl/nm-setting-veth.c index 70cfe50b42..43d8da4f93 100644 --- a/src/libnm-core-impl/nm-setting-veth.c +++ b/src/libnm-core-impl/nm-setting-veth.c @@ -190,5 +190,5 @@ nm_setting_veth_class_init(NMSettingVethClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VETH); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VETH, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index e4e07e35dd..78eb9924bc 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -994,8 +994,9 @@ nm_setting_vlan_class_init(NMSettingVlanClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_VLAN, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_VLAN, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index 351f3fd721..c94a86e9f9 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -1252,8 +1252,9 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_VPN, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_VPN, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-vrf.c b/src/libnm-core-impl/nm-setting-vrf.c index a5ee739592..0eac3cf6d6 100644 --- a/src/libnm-core-impl/nm-setting-vrf.c +++ b/src/libnm-core-impl/nm-setting-vrf.c @@ -160,5 +160,5 @@ nm_setting_vrf_class_init(NMSettingVrfClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VRF); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VRF, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-vxlan.c b/src/libnm-core-impl/nm-setting-vxlan.c index f2aeb66a16..845ede04c6 100644 --- a/src/libnm-core-impl/nm-setting-vxlan.c +++ b/src/libnm-core-impl/nm-setting-vxlan.c @@ -836,8 +836,9 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_VXLAN, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_VXLAN, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-wifi-p2p.c b/src/libnm-core-impl/nm-setting-wifi-p2p.c index 8f677479d3..1d27ee538a 100644 --- a/src/libnm-core-impl/nm-setting-wifi-p2p.c +++ b/src/libnm-core-impl/nm-setting-wifi-p2p.c @@ -300,5 +300,5 @@ nm_setting_wifi_p2p_class_init(NMSettingWifiP2PClass *setting_wifi_p2p_class) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_WIFI_P2P); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_WIFI_P2P, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting-wimax.c b/src/libnm-core-impl/nm-setting-wimax.c index 6d9f3284fa..9f2f6e3bf5 100644 --- a/src/libnm-core-impl/nm-setting-wimax.c +++ b/src/libnm-core-impl/nm-setting-wimax.c @@ -264,8 +264,9 @@ nm_setting_wimax_class_init(NMSettingWimaxClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_WIMAX, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_WIMAX, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 7a702de2cc..7e64949de7 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -1745,8 +1745,9 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_WIRED, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_WIRED, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index 3290ff567f..ba99ea0bfb 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -2601,8 +2601,9 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_WIREGUARD, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_WIREGUARD, + NULL, + properties_override, + G_STRUCT_OFFSET(NMSettingWireGuard, _priv)); } diff --git a/src/libnm-core-impl/nm-setting-wireless-security.c b/src/libnm-core-impl/nm-setting-wireless-security.c index 9e3c8d819f..ed77563295 100644 --- a/src/libnm-core-impl/nm-setting-wireless-security.c +++ b/src/libnm-core-impl/nm-setting-wireless-security.c @@ -1993,8 +1993,9 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_WIRELESS_SECURITY, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_WIRELESS_SECURITY, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index 5bdedf9bfb..a7ad9624ba 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -1985,8 +1985,9 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit_full(setting_class, - NM_META_SETTING_TYPE_WIRELESS, - NULL, - properties_override); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_WIRELESS, + NULL, + properties_override, + NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); } diff --git a/src/libnm-core-impl/nm-setting-wpan.c b/src/libnm-core-impl/nm-setting-wpan.c index f1d532af8e..30d81890c8 100644 --- a/src/libnm-core-impl/nm-setting-wpan.c +++ b/src/libnm-core-impl/nm-setting-wpan.c @@ -389,5 +389,5 @@ nm_setting_wpan_class_init(NMSettingWpanClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_WPAN); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_WPAN, NULL, NULL, 0); } diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 3f32e181d8..11c2096617 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -264,10 +264,11 @@ _property_infos_sort(const NMSettInfoProperty *property_infos, } void -_nm_setting_class_commit_full(NMSettingClass * setting_class, - NMMetaSettingType meta_type, - const NMSettInfoSettDetail *detail, - GArray * properties_override) +_nm_setting_class_commit(NMSettingClass * setting_class, + NMMetaSettingType meta_type, + const NMSettInfoSettDetail *detail, + GArray * properties_override, + gint16 private_offset) { NMSettInfoSetting *sett_info; gs_free GParamSpec **property_specs = NULL; @@ -400,6 +401,18 @@ has_property_type: setting_class->setting_info = &nm_meta_setting_infos[meta_type]; sett_info->setting_class = setting_class; + + if (private_offset == NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS) { + int o; + + o = g_type_class_get_instance_private_offset(setting_class); + nm_assert(o != NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); + nm_assert(o > G_MININT16); + nm_assert(o < 0); + private_offset = o; + } + sett_info->private_offset = private_offset; + if (detail) sett_info->detail = *detail; nm_assert(properties_override->len > 0); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 81ecb3b03d..15dbf0f8b9 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4404,6 +4404,18 @@ test_setting_metadata(void) g_assert_cmpint(sis->property_infos_len, >, 0); g_assert(sis->property_infos); + { + int offset; + + if (sis->private_offset < 0) { + offset = g_type_class_get_instance_private_offset(sis->setting_class); + g_assert_cmpint(sis->private_offset, ==, offset); + } else { + /* it would be nice to assert that this class has no private data. + * But we cannot. */ + } + } + h_properties = g_hash_table_new(nm_str_hash, g_str_equal); for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 9ffaa05fd9..fd6f9892ec 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -762,10 +762,26 @@ struct _NMSettInfoSetting { */ const NMSettInfoProperty *const *property_infos_sorted; - guint property_infos_len; + guint property_infos_len; + + /* the offset in bytes to get the private data from the @self pointer. */ + gint16 private_offset; + NMSettInfoSettDetail detail; }; +#define NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS ((gint16) G_MININT16) + +static inline gpointer +_nm_setting_get_private(NMSetting *self, const NMSettInfoSetting *sett_info, guint16 offset) +{ + nm_assert(NM_IS_SETTING(self)); + nm_assert(sett_info); + nm_assert(NM_SETTING_GET_CLASS(self) == sett_info->setting_class); + + return ((((char *) ((gpointer) self)) + sett_info->private_offset) + offset); +} + static inline const NMSettInfoProperty * _nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint idx) { From 8024279cf707f8f715c14d0b6ed8d1b1e0f72011 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 17:04:37 +0200 Subject: [PATCH 05/16] libnm: add direct_offset for boolean properties Introduce a new mechanism for how to handle properties generically. We have NMSettInfoSetting, NMSettInfoProperty and NMSettInfoPropertType with meta data about settings and their properties. For example, we have a simple boolean property. Then (usually) we have a boolean GParamSpec, and a plain boolean field in the NMSetting's private data. We need very little to get (and convert to keyfile, GVariant), set (from keyfile, GVariant) and compare this property. All we need to know, is the GParamSpec and the offset of the bool field. Introduce a new mechanism for that, and as example implement NM_SETTING_CONNECTION_AUTOCONNECT property this way. Note that this patch only changes the to_dbus_fcn() for the boolean property. But this opens up all kind of further improvements. What we eventually also can do is replace GObjectClass.get_property() with a generic variant, that knows how to get and set the property. --- src/libnm-core-impl/nm-setting-connection.c | 17 ++--- src/libnm-core-impl/nm-setting-private.h | 74 +++++++++++++++++++-- src/libnm-core-impl/nm-setting.c | 31 +++++++++ src/libnm-core-impl/tests/test-setting.c | 15 ++++- src/libnm-core-intern/nm-core-internal.h | 14 ++++ 5 files changed, 137 insertions(+), 14 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index bb5c3c82e5..4f51da5ab7 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -93,8 +93,8 @@ typedef struct { NMSettingConnectionAutoconnectSlaves autoconnect_slaves; NMMetered metered; NMSettingConnectionLldp lldp; + bool autoconnect; bool read_only : 1; - bool autoconnect : 1; } NMSettingConnectionPrivate; /** @@ -2078,13 +2078,14 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: Whether the connection should be autoconnected (not only while booting). * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_CONNECTION_AUTOCONNECT, - PROP_AUTOCONNECT, - TRUE, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_connection_get_autoconnect); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_CONNECTION_AUTOCONNECT, + PROP_AUTOCONNECT, + TRUE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingConnectionPrivate, + autoconnect); /** * NMSettingConnection:autoconnect-priority: diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index de76914df0..5c533d4ade 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -253,6 +253,8 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u 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_boolean; extern const NMSettInfoPropertType nm_sett_info_propert_type_string; @@ -275,6 +277,13 @@ GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); +GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + GVariant * _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * sett_info, guint property_idx, @@ -376,11 +385,14 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p g_array_append_vals(properties_override, prop_info, 1); } -#define _nm_properties_override_gobj(properties_override, p_param_spec, p_property_type, ...) \ - _nm_properties_override((properties_override), \ - NM_SETT_INFO_PROPERTY(.name = NULL, \ - .param_spec = (p_param_spec), \ - .property_type = (p_property_type), \ +#define _nm_properties_override_gobj(properties_override, \ + p_param_spec, \ + p_property_type, \ + ... /* extra NMSettInfoProperty fields */) \ + _nm_properties_override((properties_override), \ + NM_SETT_INFO_PROPERTY(.name = NULL, \ + .param_spec = (p_param_spec), \ + .property_type = (p_property_type), \ __VA_ARGS__)) #define _nm_properties_override_dbus(properties_override, p_name, p_property_type) \ @@ -390,6 +402,58 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ +/* Define "direct" properties. These are properties that have a GParamSpec and + * NMSettInfoPropertType.direct_type != NM_VALUE_TYPE_NONE. + * + * With this, the location of the data is known at + * + * _nm_setting_get_private(setting, sett_info, property_info->direct_offset) + * + * which allows to generically handle the property operations (like get, set, compare). + */ + +#define _nm_setting_property_define_direct_boolean(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + default_value, \ + param_flags, \ + private_struct_type, \ + private_struct_field, \ + ... /* extra NMSettInfoProperty fields */) \ + G_STMT_START \ + { \ + const gboolean _default_value = (default_value); \ + GParamSpec * _param_spec; \ + \ + G_STATIC_ASSERT( \ + !NM_FLAGS_ANY((param_flags), \ + ~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE \ + | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \ + \ + nm_assert(NM_IN_SET(_default_value, 0, 1)); \ + \ + _param_spec = \ + g_param_spec_boolean("" prop_name "", \ + "", \ + "", \ + _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_boolean, \ + .direct_offset = \ + NM_STRUCT_OFFSET_ENSURE_TYPE(bool, private_struct_type, private_struct_field), \ + __VA_ARGS__); \ + } \ + G_STMT_END + +/*****************************************************************************/ + #define _nm_setting_property_define_boolean_full(properties_override, \ obj_properties, \ prop_name, \ diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 11c2096617..8dfdad26d8 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -544,6 +544,32 @@ _nm_setting_use_legacy_property(NMSetting * setting, /*****************************************************************************/ +GVariant * +_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) +{ + const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; + + switch (property_info->property_type->direct_type) { + case NM_VALUE_TYPE_BOOL: + { + gboolean val; + + val = *((bool *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + if (!property_info->to_dbus_data.including_default + && val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) + return NULL; + return g_variant_ref(nm_g_variant_singleton_b(val)); + } + default: + return nm_assert_unreachable_val(NULL); + } +} + GVariant * _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * sett_info, guint property_idx, @@ -2415,6 +2441,11 @@ const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32); +const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, + .direct_type = NM_VALUE_TYPE_BOOL, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); + const NMSettInfoPropertType nm_sett_info_propert_type_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( G_VARIANT_TYPE_BOOLEAN, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_boolean); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 15dbf0f8b9..41db66e909 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4433,6 +4433,19 @@ test_setting_metadata(void) g_assert(sip->property_type->dbus_type); g_assert(g_variant_type_string_is_valid((const char *) sip->property_type->dbus_type)); + if (sip->property_type->direct_type == NM_VALUE_TYPE_NONE) { + g_assert_cmpint(sip->direct_offset, ==, 0); + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_BOOL) { + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_boolean); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "b")); + 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_BOOLEAN); + can_set_including_default = TRUE; + } else + g_assert_not_reached(); + 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 and no gprop_to_dbus_fcn. */ @@ -4598,7 +4611,7 @@ check_done:; const NMSettInfoPropertType *pt_2 = a_property_types[prop_idx_2]; if (!g_variant_type_equal(pt->dbus_type, pt_2->dbus_type) - || pt->to_dbus_fcn != pt_2->to_dbus_fcn + || pt->direct_type != pt_2->direct_type || pt->to_dbus_fcn != pt_2->to_dbus_fcn || pt->from_dbus_fcn != pt_2->from_dbus_fcn || pt->missing_from_dbus_fcn != pt_2->missing_from_dbus_fcn || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index fd6f9892ec..2c5bb93428 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -78,6 +78,7 @@ #include "nm-vpn-dbus-interface.h" #include "nm-vpn-editor-plugin.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" +#include "libnm-glib-aux/nm-value-type.h" /* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated * connection can be replaced by a already-defined connection. This flag only @@ -684,6 +685,14 @@ typedef enum _nm_packed { typedef struct { const GVariantType *dbus_type; + /* If this is not NM_VALUE_TYPE_UNSPEC, then this is a "direct" property, + * meaning that _nm_setting_get_private() at NMSettInfoProperty.direct_offset + * gives direct access to the field. + * + * Direct properties can use this information to generically implement access + * to the property value. */ + NMValueType direct_type; + NMSettInfoPropToDBusFcn to_dbus_fcn; NMSettInfoPropFromDBusFcn from_dbus_fcn; NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn; @@ -707,6 +716,11 @@ struct _NMSettInfoProperty { const NMSettInfoPropertType *property_type; + /* 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. */ + guint16 direct_offset; + struct { union { gpointer none; From 03dc5ad3919f451136ef1b14cbd3f0e971a9307e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 18:14:04 +0200 Subject: [PATCH 06/16] libnm: let NMSettingIPConfigPrivate be tracked by subclasses For our property meta data handling we require that all the meta data is associated with one GType. NMSettingIPConfig is a parent class of NMSettingIP[46]Config. Note that we already have _nm_sett_info_property_override_create_array_ip_config() because the meta data must be initialized together at one place. We will require that we can find the offset for properties based on one offset per type. That is cumbersome, if NMSettingIPConfigPrivate is private itself. Simplify that, by internally sharing NMSettingIPConfigPrivate and let the subclasses embed the private data in their own private data. Optimally we would simply embed the private struct as field into NMSettingIPConfig. But that would be an ABI change as that struct was public before 1.32. Don't change ABI for now, so we have to awkwardly place it into the subclasses private data. --- src/libnm-core-impl/nm-setting-ip-config.c | 59 +++++++++------------ src/libnm-core-impl/nm-setting-ip4-config.c | 21 +++++--- src/libnm-core-impl/nm-setting-ip6-config.c | 15 ++++-- src/libnm-core-impl/nm-setting-private.h | 37 ++++++++++++- 4 files changed, 87 insertions(+), 45 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 2ae02eeb99..ddd1cc8d54 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -3911,36 +3911,25 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingIPConfig, PROP_DHCP_IAID, PROP_DHCP_REJECT_SERVERS, ); -typedef struct { - GPtrArray *dns; /* array of IP address strings */ - GPtrArray *dns_search; /* array of domain name strings */ - GPtrArray *dns_options; /* array of DNS options */ - GPtrArray *addresses; /* array of NMIPAddress */ - GPtrArray *routes; /* array of NMIPRoute */ - GPtrArray *routing_rules; - GArray * dhcp_reject_servers; - char * method; - char * gateway; - char * dhcp_hostname; - char * dhcp_iaid; - gint64 route_metric; - guint dhcp_hostname_flags; - int dns_priority; - int dad_timeout; - int dhcp_timeout; - int required_timeout; - guint32 route_table; - bool ignore_auto_routes : 1; - bool ignore_auto_dns : 1; - bool dhcp_send_hostname : 1; - bool never_default : 1; - bool may_fail : 1; -} NMSettingIPConfigPrivate; - G_DEFINE_ABSTRACT_TYPE(NMSettingIPConfig, nm_setting_ip_config, NM_TYPE_SETTING) -#define NM_SETTING_IP_CONFIG_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), NM_TYPE_SETTING_IP_CONFIG, NMSettingIPConfigPrivate)) +static inline NMSettingIPConfigPrivate * +_NM_SETTING_IP_CONFIG_GET_PRIVATE(NMSettingIPConfig *self) +{ + NMSettingIPConfigClass *klass; + + nm_assert(NM_IS_SETTING_IP_CONFIG(self)); + + klass = NM_SETTING_IP_CONFIG_GET_CLASS(self); + + nm_assert(klass->private_offset < 0); + + return (gpointer) (((char *) ((gpointer) self)) + klass->private_offset); +} + +#define NM_SETTING_IP_CONFIG_GET_PRIVATE(self) \ + _NM_SETTING_IP_CONFIG_GET_PRIVATE( \ + NM_GOBJECT_CAST_NON_NULL(NMSettingIPConfig, self, NM_IS_SETTING_IP_CONFIG, NMSetting)) /*****************************************************************************/ @@ -6065,10 +6054,10 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps /*****************************************************************************/ -static void -nm_setting_ip_config_init(NMSettingIPConfig *setting) +void +_nm_setting_ip_config_private_init(gpointer self, NMSettingIPConfigPrivate *priv) { - NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); + nm_assert(NM_IS_SETTING_IP_CONFIG(self)); priv->dns = g_ptr_array_new_with_free_func(g_free); priv->dns_search = g_ptr_array_new_with_free_func(g_free); @@ -6081,6 +6070,12 @@ nm_setting_ip_config_init(NMSettingIPConfig *setting) priv->required_timeout = -1; } +static void +nm_setting_ip_config_init(NMSettingIPConfig *setting) +{ + /* cannot yet access NM_SETTING_IP_CONFIG_GET_PRIVATE(). */ +} + static void finalize(GObject *object) { @@ -6111,8 +6106,6 @@ nm_setting_ip_config_class_init(NMSettingIPConfigClass *klass) GObjectClass * object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - g_type_class_add_private(klass, sizeof(NMSettingIPConfigPrivate)); - object_class->get_property = get_property; object_class->set_property = set_property; object_class->finalize = finalize; diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index f7f5931e4f..1704820bde 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -40,6 +40,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_DHCP_CLIENT_ID, PROP_DHCP_VENDOR_CLASS_IDENTIFIER, ); typedef struct { + NMSettingIPConfigPrivate parent; + char *dhcp_client_id; char *dhcp_fqdn; char *dhcp_vendor_class_identifier; @@ -598,7 +600,11 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static void nm_setting_ip4_config_init(NMSettingIP4Config *setting) -{} +{ + NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE(setting); + + _nm_setting_ip_config_private_init(setting, &priv->parent); +} /** * nm_setting_ip4_config_new: @@ -628,11 +634,12 @@ finalize(GObject *object) static void nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *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_ip_config(); + 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(); - g_type_class_add_private(setting_class, sizeof(NMSettingIP4ConfigPrivate)); + g_type_class_add_private(klass, sizeof(NMSettingIP4ConfigPrivate)); object_class->get_property = get_property; object_class->set_property = set_property; @@ -640,6 +647,8 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) setting_class->verify = verify; + setting_ip_config_class->private_offset = g_type_class_get_instance_private_offset(klass); + /* ---ifcfg-rh--- * property: method * variable: BOOTPROTO @@ -1056,5 +1065,5 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) NM_META_SETTING_TYPE_IP4_CONFIG, NULL, properties_override, - NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); + setting_ip_config_class->private_offset); } diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index c72418dd69..55564d602f 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -45,6 +45,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_IP6_PRIVACY, PROP_RA_TIMEOUT, ); typedef struct { + NMSettingIPConfigPrivate parent; + char * token; char * dhcp_duid; NMSettingIP6ConfigPrivacy ip6_privacy; @@ -594,6 +596,8 @@ nm_setting_ip6_config_init(NMSettingIP6Config *setting) { NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE(setting); + _nm_setting_ip_config_private_init(setting, &priv->parent); + priv->ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; priv->addr_gen_mode = NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY; } @@ -626,9 +630,10 @@ finalize(GObject *object) static void nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *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_ip_config(); + 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(); g_type_class_add_private(klass, sizeof(NMSettingIP6ConfigPrivate)); @@ -638,6 +643,8 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) setting_class->verify = verify; + setting_ip_config_class->private_offset = g_type_class_get_instance_private_offset(klass); + /* ---ifcfg-rh--- * property: method * variable: IPV6INIT, IPV6FORWARDING, IPV6_AUTOCONF, DHCPV6C, IPV6_DISABLED @@ -1100,5 +1107,5 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) NM_META_SETTING_TYPE_IP6_CONFIG, NULL, properties_override, - NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS); + setting_ip_config_class->private_offset); } diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 5c533d4ade..656d438531 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -127,15 +127,48 @@ struct _NMSettingClass { */ struct _NMSettingIPConfig { NMSetting parent; + /* In the past, this struct was public API. Preserve ABI! */ }; struct _NMSettingIPConfigClass { NMSettingClass parent; - /* Padding for future expansion */ - gpointer padding[8]; + /* In the past, this struct was public API. Preserve ABI! */ + union { + gpointer _dummy; + int private_offset; + }; + gpointer padding[7]; }; +typedef struct { + GPtrArray *dns; /* array of IP address strings */ + GPtrArray *dns_search; /* array of domain name strings */ + GPtrArray *dns_options; /* array of DNS options */ + GPtrArray *addresses; /* array of NMIPAddress */ + GPtrArray *routes; /* array of NMIPRoute */ + GPtrArray *routing_rules; + GArray * dhcp_reject_servers; + char * method; + char * gateway; + char * dhcp_hostname; + char * dhcp_iaid; + gint64 route_metric; + guint dhcp_hostname_flags; + int dns_priority; + int dad_timeout; + int dhcp_timeout; + int required_timeout; + guint32 route_table; + bool ignore_auto_routes : 1; + bool ignore_auto_dns : 1; + bool dhcp_send_hostname : 1; + bool never_default : 1; + bool may_fail : 1; +} NMSettingIPConfigPrivate; + +void _nm_setting_ip_config_private_init(gpointer self, NMSettingIPConfigPrivate *priv); + /*****************************************************************************/ NMSettingPriority _nm_setting_get_base_type_priority(NMSetting *setting); From 233776c2c7b8be99fac1e6a09a7c7fe1d3c85986 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 17:28:21 +0200 Subject: [PATCH 07/16] libnm: use _nm_setting_property_define_direct_boolean() There is a new way how to implement default boolean properties. Use it. --- src/libnm-core-impl/nm-setting-8021x.c | 34 +-- src/libnm-core-impl/nm-setting-bridge-port.c | 17 +- src/libnm-core-impl/nm-setting-bridge.c | 102 +++++---- src/libnm-core-impl/nm-setting-connection.c | 17 +- src/libnm-core-impl/nm-setting-gsm.c | 34 +-- src/libnm-core-impl/nm-setting-ip-config.c | 54 ++--- src/libnm-core-impl/nm-setting-ip-tunnel.c | 17 +- src/libnm-core-impl/nm-setting-macsec.c | 34 +-- src/libnm-core-impl/nm-setting-macvlan.c | 34 +-- src/libnm-core-impl/nm-setting-ovs-bridge.c | 51 +++-- src/libnm-core-impl/nm-setting-ppp.c | 221 ++++++++++--------- src/libnm-core-impl/nm-setting-private.h | 82 +------ src/libnm-core-impl/nm-setting-proxy.c | 17 +- src/libnm-core-impl/nm-setting-tun.c | 51 +++-- src/libnm-core-impl/nm-setting-vpn.c | 26 ++- src/libnm-core-impl/nm-setting-vxlan.c | 86 ++++---- src/libnm-core-impl/nm-setting-wired.c | 19 +- src/libnm-core-impl/nm-setting-wireguard.c | 17 +- src/libnm-core-impl/nm-setting-wireless.c | 17 +- src/libnm-core-impl/nm-setting.c | 22 -- src/libnm-core-impl/tests/test-setting.c | 6 - src/libnm-core-intern/nm-core-internal.h | 1 - 22 files changed, 455 insertions(+), 504 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-8021x.c b/src/libnm-core-impl/nm-setting-8021x.c index 940bf951eb..f5592c97a5 100644 --- a/src/libnm-core-impl/nm-setting-8021x.c +++ b/src/libnm-core-impl/nm-setting-8021x.c @@ -176,8 +176,8 @@ typedef struct { NMSettingSecretFlags pin_flags; NMSettingSecretFlags private_key_password_flags; NMSettingSecretFlags phase2_private_key_password_flags; - bool optional : 1; - bool system_ca_certs : 1; + bool optional; + bool system_ca_certs; } NMSetting8021xPrivate; /** @@ -4588,13 +4588,14 @@ nm_setting_802_1x_class_init(NMSetting8021xClass *klass) * description: a boolean value. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_802_1X_SYSTEM_CA_CERTS, - PROP_SYSTEM_CA_CERTS, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_802_1x_get_system_ca_certs); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_802_1X_SYSTEM_CA_CERTS, + PROP_SYSTEM_CA_CERTS, + FALSE, + NM_SETTING_PARAM_NONE, + NMSetting8021xPrivate, + system_ca_certs); /** * NMSetting8021x:auth-timeout: @@ -4638,13 +4639,14 @@ nm_setting_802_1x_class_init(NMSetting8021xClass *klass) * description: whether the 802.1X authentication is optional * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_802_1X_OPTIONAL, - PROP_OPTIONAL, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_802_1x_get_optional); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_802_1X_OPTIONAL, + PROP_OPTIONAL, + FALSE, + NM_SETTING_PARAM_NONE, + NMSetting8021xPrivate, + optional); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-bridge-port.c b/src/libnm-core-impl/nm-setting-bridge-port.c index aefefe6f14..50be8452d1 100644 --- a/src/libnm-core-impl/nm-setting-bridge-port.c +++ b/src/libnm-core-impl/nm-setting-bridge-port.c @@ -36,7 +36,7 @@ typedef struct { GPtrArray *vlans; guint16 priority; guint16 path_cost; - bool hairpin_mode : 1; + bool hairpin_mode; } NMSettingBridgePortPrivate; /** @@ -564,13 +564,14 @@ nm_setting_bridge_port_class_init(NMSettingBridgePortClass *klass) * description: Hairpin mode of the bridge port. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, - PROP_HAIRPIN_MODE, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_port_get_hairpin_mode); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, + PROP_HAIRPIN_MODE, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePortPrivate, + hairpin_mode); /** * NMSettingBridgePort:vlans: (type GPtrArray(NMBridgeVlan)) diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index 54df6480b4..2624a4e3e3 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -77,12 +77,12 @@ typedef struct { guint16 max_age; guint16 vlan_default_pvid; guint16 group_forward_mask; - bool multicast_snooping : 1; - bool vlan_filtering : 1; - bool stp : 1; - bool vlan_stats_enabled : 1; - bool multicast_query_use_ifaddr : 1; - bool multicast_querier : 1; + bool stp; + bool multicast_snooping; + bool vlan_filtering; + bool vlan_stats_enabled; + bool multicast_query_use_ifaddr; + bool multicast_querier; } NMSettingBridgePrivate; /** @@ -1672,13 +1672,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * description: Span tree protocol participation. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_STP, - PROP_STP, - NM_BRIDGE_STP_DEF, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_get_stp); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_STP, + PROP_STP, + NM_BRIDGE_STP_DEF, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePrivate, + stp); /** * NMSettingBridge:priority: @@ -1831,13 +1832,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * description: IGMP snooping support. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_MULTICAST_SNOOPING, - PROP_MULTICAST_SNOOPING, - NM_BRIDGE_MULTICAST_SNOOPING_DEF, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_get_multicast_snooping); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_MULTICAST_SNOOPING, + PROP_MULTICAST_SNOOPING, + NM_BRIDGE_MULTICAST_SNOOPING_DEF, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePrivate, + multicast_snooping); /** * NMSettingBridge:vlan-filtering: @@ -1854,13 +1856,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * description: VLAN filtering support. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_VLAN_FILTERING, - PROP_VLAN_FILTERING, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_get_vlan_filtering); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_VLAN_FILTERING, + PROP_VLAN_FILTERING, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePrivate, + vlan_filtering); /** * NMSettingBridge:vlan-default-pvid: @@ -2001,13 +2004,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * * Since: 1.24 */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, - PROP_VLAN_STATS_ENABLED, - NM_BRIDGE_VLAN_STATS_ENABLED_DEF, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_get_vlan_stats_enabled); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, + PROP_VLAN_STATS_ENABLED, + NM_BRIDGE_VLAN_STATS_ENABLED_DEF, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePrivate, + vlan_stats_enabled); /** * NMSettingBridge:multicast-router: @@ -2052,13 +2056,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * * Since: 1.24 */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, - PROP_MULTICAST_QUERY_USE_IFADDR, - NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_get_multicast_query_use_ifaddr); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, + PROP_MULTICAST_QUERY_USE_IFADDR, + NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePrivate, + multicast_query_use_ifaddr); /** * NMSettingBridge:multicast-querier: @@ -2075,13 +2080,14 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * * Since: 1.24 */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_BRIDGE_MULTICAST_QUERIER, - PROP_MULTICAST_QUERIER, - NM_BRIDGE_MULTICAST_QUERIER_DEF, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_bridge_get_multicast_querier); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_MULTICAST_QUERIER, + PROP_MULTICAST_QUERIER, + NM_BRIDGE_MULTICAST_QUERIER_DEF, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBridgePrivate, + multicast_querier); /** * NMSettingBridge:multicast-hash-max: diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 4f51da5ab7..f833aea7c0 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -94,7 +94,7 @@ typedef struct { NMMetered metered; NMSettingConnectionLldp lldp; bool autoconnect; - bool read_only : 1; + bool read_only; } NMSettingConnectionPrivate; /** @@ -2200,13 +2200,14 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * service's D-Bus interface with the right privileges, or %TRUE if the * connection is read-only and cannot be modified. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_CONNECTION_READ_ONLY, - PROP_READ_ONLY, - FALSE, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_connection_get_read_only); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_CONNECTION_READ_ONLY, + PROP_READ_ONLY, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingConnectionPrivate, + read_only); /** * NMSettingConnection:zone: diff --git a/src/libnm-core-impl/nm-setting-gsm.c b/src/libnm-core-impl/nm-setting-gsm.c index d7d8457d01..8b2749d9ae 100644 --- a/src/libnm-core-impl/nm-setting-gsm.c +++ b/src/libnm-core-impl/nm-setting-gsm.c @@ -51,8 +51,8 @@ typedef struct { NMSettingSecretFlags password_flags; NMSettingSecretFlags pin_flags; guint32 mtu; - bool auto_config : 1; - bool home_only : 1; + bool auto_config; + bool home_only; } NMSettingGsmPrivate; /** @@ -667,13 +667,14 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Since: 1.22 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_GSM_AUTO_CONFIG, - PROP_AUTO_CONFIG, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_gsm_get_auto_config); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_GSM_AUTO_CONFIG, + PROP_AUTO_CONFIG, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + auto_config); /** * NMSettingGsm:number: @@ -794,13 +795,14 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * When %TRUE, only connections to the home network will be allowed. * Connections to roaming networks will not be made. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_GSM_HOME_ONLY, - PROP_HOME_ONLY, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_gsm_get_home_only); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_GSM_HOME_ONLY, + PROP_HOME_ONLY, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + home_only); /** * NMSettingGsm:device-id: diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index ddd1cc8d54..70807f7c4e 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5816,35 +5816,39 @@ _nm_sett_info_property_override_create_array_ip_config(void) .to_dbus_fcn = _routing_rules_dbus_only_synth, .from_dbus_fcn = _routing_rules_dbus_only_set, )); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_IGNORE_AUTO_ROUTES], - &nm_sett_info_propert_type_boolean, - .to_dbus_data.get_boolean = (gboolean(*)( - NMSetting *)) nm_setting_ip_config_get_ignore_auto_routes); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_IGNORE_AUTO_ROUTES], + &nm_sett_info_propert_type_direct_boolean, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, ignore_auto_routes)); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_IGNORE_AUTO_DNS], - &nm_sett_info_propert_type_boolean, - .to_dbus_data.get_boolean = (gboolean(*)( - NMSetting *)) nm_setting_ip_config_get_ignore_auto_dns); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_IGNORE_AUTO_DNS], + &nm_sett_info_propert_type_direct_boolean, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, ignore_auto_dns)); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_DHCP_SEND_HOSTNAME], - &nm_sett_info_propert_type_boolean, - .to_dbus_data.get_boolean = (gboolean(*)( - NMSetting *)) nm_setting_ip_config_get_dhcp_send_hostname); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DHCP_SEND_HOSTNAME], + &nm_sett_info_propert_type_direct_boolean, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, dhcp_send_hostname)); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_NEVER_DEFAULT], - &nm_sett_info_propert_type_boolean, - .to_dbus_data.get_boolean = (gboolean(*)( - NMSetting *)) nm_setting_ip_config_get_never_default); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_NEVER_DEFAULT], + &nm_sett_info_propert_type_direct_boolean, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, never_default)); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_MAY_FAIL], - &nm_sett_info_propert_type_boolean, - .to_dbus_data.get_boolean = - (gboolean(*)(NMSetting *)) nm_setting_ip_config_get_may_fail); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_MAY_FAIL], + &nm_sett_info_propert_type_direct_boolean, + .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, may_fail)); return properties_override; } diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index e5a34f0c41..50adc73ee3 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -44,7 +44,7 @@ typedef struct { NMIPTunnelMode mode; guint32 mtu; guint32 flags; - bool path_mtu_discovery : 1; + bool path_mtu_discovery; } NMSettingIPTunnelPrivate; /** @@ -770,13 +770,14 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY, - PROP_PATH_MTU_DISCOVERY, - TRUE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip_tunnel_get_path_mtu_discovery); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY, + PROP_PATH_MTU_DISCOVERY, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + path_mtu_discovery); /** * NMSettingIPTunnel:input-key: diff --git a/src/libnm-core-impl/nm-setting-macsec.c b/src/libnm-core-impl/nm-setting-macsec.c index c180802505..1802ba6d21 100644 --- a/src/libnm-core-impl/nm-setting-macsec.c +++ b/src/libnm-core-impl/nm-setting-macsec.c @@ -45,8 +45,8 @@ typedef struct { NMSettingMacsecMode mode; NMSettingSecretFlags mka_cak_flags; NMSettingMacsecValidation validation; - bool encrypt : 1; - bool send_sci : 1; + bool encrypt; + bool send_sci; } NMSettingMacsecPrivate; /** @@ -583,13 +583,14 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_MACSEC_ENCRYPT, - PROP_ENCRYPT, - TRUE, - NM_SETTING_PARAM_NONE, - nm_setting_macsec_get_encrypt); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_MACSEC_ENCRYPT, + PROP_ENCRYPT, + TRUE, + NM_SETTING_PARAM_NONE, + NMSettingMacsecPrivate, + encrypt); /** * NMSettingMacsec:mka-cak: @@ -676,13 +677,14 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.12 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_MACSEC_SEND_SCI, - PROP_SEND_SCI, - TRUE, - NM_SETTING_PARAM_NONE, - nm_setting_macsec_get_send_sci); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_MACSEC_SEND_SCI, + PROP_SEND_SCI, + TRUE, + NM_SETTING_PARAM_NONE, + NMSettingMacsecPrivate, + send_sci); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-macvlan.c b/src/libnm-core-impl/nm-setting-macvlan.c index 070a53064a..255ec7d595 100644 --- a/src/libnm-core-impl/nm-setting-macvlan.c +++ b/src/libnm-core-impl/nm-setting-macvlan.c @@ -30,8 +30,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, PROP_MODE, PROP_PROMISCUOUS, PROP typedef struct { char * parent; NMSettingMacvlanMode mode; - bool promiscuous : 1; - bool tap : 1; + bool promiscuous; + bool tap; } NMSettingMacvlanPrivate; /** @@ -322,13 +322,14 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_MACVLAN_PROMISCUOUS, - PROP_PROMISCUOUS, - TRUE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_macvlan_get_promiscuous); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_MACVLAN_PROMISCUOUS, + PROP_PROMISCUOUS, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacvlanPrivate, + promiscuous); /** * NMSettingMacvlan:tap: @@ -337,13 +338,14 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_MACVLAN_TAP, - PROP_TAP, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_macvlan_get_tap); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_MACVLAN_TAP, + PROP_TAP, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacvlanPrivate, + tap); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ovs-bridge.c b/src/libnm-core-impl/nm-setting-ovs-bridge.c index f4a46c6e3b..711d5461c1 100644 --- a/src/libnm-core-impl/nm-setting-ovs-bridge.c +++ b/src/libnm-core-impl/nm-setting-ovs-bridge.c @@ -37,9 +37,9 @@ struct _NMSettingOvsBridge { char *fail_mode; char *datapath_type; - bool mcast_snooping_enable : 1; - bool rstp_enable : 1; - bool stp_enable : 1; + bool mcast_snooping_enable; + bool rstp_enable; + bool stp_enable; }; struct _NMSettingOvsBridgeClass { @@ -320,13 +320,14 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE, - PROP_MCAST_SNOOPING_ENABLE, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ovs_bridge_get_mcast_snooping_enable); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE, + PROP_MCAST_SNOOPING_ENABLE, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingOvsBridge, + mcast_snooping_enable); /** * NMSettingOvsBridge:rstp-enable: @@ -335,13 +336,14 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_OVS_BRIDGE_RSTP_ENABLE, - PROP_RSTP_ENABLE, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ovs_bridge_get_rstp_enable); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_RSTP_ENABLE, + PROP_RSTP_ENABLE, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingOvsBridge, + rstp_enable); /** * NMSettingOvsBridge:stp-enable: @@ -350,13 +352,14 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_OVS_BRIDGE_STP_ENABLE, - PROP_STP_ENABLE, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ovs_bridge_get_stp_enable); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_STP_ENABLE, + PROP_STP_ENABLE, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingOvsBridge, + stp_enable); /** * NMSettingOvsBridge:datapath-type: diff --git a/src/libnm-core-impl/nm-setting-ppp.c b/src/libnm-core-impl/nm-setting-ppp.c index 77713feb9e..7e62ec6569 100644 --- a/src/libnm-core-impl/nm-setting-ppp.c +++ b/src/libnm-core-impl/nm-setting-ppp.c @@ -47,19 +47,19 @@ typedef struct { guint32 mtu; guint32 lcp_echo_failure; guint32 lcp_echo_interval; - bool noauth : 1; - bool refuse_eap : 1; - bool refuse_pap : 1; - bool refuse_chap : 1; - bool refuse_mschap : 1; - bool refuse_mschapv2 : 1; - bool nobsdcomp : 1; - bool nodeflate : 1; - bool no_vj_comp : 1; - bool require_mppe : 1; - bool require_mppe_128 : 1; - bool mppe_stateful : 1; - bool crtscts : 1; + bool noauth; + bool refuse_eap; + bool refuse_pap; + bool refuse_chap; + bool refuse_mschap; + bool refuse_mschapv2; + bool nobsdcomp; + bool nodeflate; + bool no_vj_comp; + bool require_mppe; + bool require_mppe_128; + bool mppe_stateful; + bool crtscts; } NMSettingPppPrivate; /** @@ -552,117 +552,126 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * authenticate itself to the client. If %FALSE, require authentication * from the remote side. In almost all cases, this should be %TRUE. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_NOAUTH, - PROP_NOAUTH, - TRUE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_noauth); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NOAUTH, + PROP_NOAUTH, + TRUE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + noauth); /** * NMSettingPpp:refuse-eap: * * If %TRUE, the EAP authentication method will not be used. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REFUSE_EAP, - PROP_REFUSE_EAP, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_refuse_eap); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_EAP, + PROP_REFUSE_EAP, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + refuse_eap); /** * NMSettingPpp:refuse-pap: * * If %TRUE, the PAP authentication method will not be used. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REFUSE_PAP, - PROP_REFUSE_PAP, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_refuse_pap); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_PAP, + PROP_REFUSE_PAP, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + refuse_pap); /** * NMSettingPpp:refuse-chap: * * If %TRUE, the CHAP authentication method will not be used. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REFUSE_CHAP, - PROP_REFUSE_CHAP, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_refuse_chap); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_CHAP, + PROP_REFUSE_CHAP, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + refuse_chap); /** * NMSettingPpp:refuse-mschap: * * If %TRUE, the MSCHAP authentication method will not be used. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REFUSE_MSCHAP, - PROP_REFUSE_MSCHAP, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_refuse_mschap); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_MSCHAP, + PROP_REFUSE_MSCHAP, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + refuse_mschap); /** * NMSettingPpp:refuse-mschapv2: * * If %TRUE, the MSCHAPv2 authentication method will not be used. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REFUSE_MSCHAPV2, - PROP_REFUSE_MSCHAPV2, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_refuse_mschapv2); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_MSCHAPV2, + PROP_REFUSE_MSCHAPV2, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + refuse_mschapv2); /** * NMSettingPpp:nobsdcomp: * * If %TRUE, BSD compression will not be requested. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_NOBSDCOMP, - PROP_NOBSDCOMP, - FALSE, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_ppp_get_nobsdcomp); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NOBSDCOMP, + PROP_NOBSDCOMP, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + nobsdcomp); /** * NMSettingPpp:nodeflate: * * If %TRUE, "deflate" compression will not be requested. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_NODEFLATE, - PROP_NODEFLATE, - FALSE, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_ppp_get_nodeflate); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NODEFLATE, + PROP_NODEFLATE, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + nodeflate); /** * NMSettingPpp:no-vj-comp: * * If %TRUE, Van Jacobsen TCP header compression will not be requested. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_NO_VJ_COMP, - PROP_NO_VJ_COMP, - FALSE, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_ppp_get_no_vj_comp); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NO_VJ_COMP, + PROP_NO_VJ_COMP, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + no_vj_comp); /** * NMSettingPpp:require-mppe: @@ -672,13 +681,14 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * session will fail. Note that MPPE is not used on mobile broadband * connections. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REQUIRE_MPPE, - PROP_REQUIRE_MPPE, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_require_mppe); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REQUIRE_MPPE, + PROP_REQUIRE_MPPE, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + require_mppe); /** * NMSettingPpp:require-mppe-128: @@ -687,13 +697,14 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * required for the PPP session, and the "require-mppe" property must also * be set to %TRUE. If 128-bit MPPE is not available the session will fail. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_REQUIRE_MPPE_128, - PROP_REQUIRE_MPPE_128, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_require_mppe_128); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REQUIRE_MPPE_128, + PROP_REQUIRE_MPPE_128, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + require_mppe_128); /** * NMSettingPpp:mppe-stateful: @@ -701,13 +712,14 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * If %TRUE, stateful MPPE is used. See pppd documentation for more * information on stateful MPPE. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_MPPE_STATEFUL, - PROP_MPPE_STATEFUL, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_mppe_stateful); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_MPPE_STATEFUL, + PROP_MPPE_STATEFUL, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + mppe_stateful); /** * NMSettingPpp:crtscts: @@ -716,13 +728,14 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * flow control with RTS and CTS signals. This value should normally be set * to %FALSE. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PPP_CRTSCTS, - PROP_CRTSCTS, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_ppp_get_crtscts); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_CRTSCTS, + PROP_CRTSCTS, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + crtscts); /** * NMSettingPpp:baud: diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 656d438531..dcfd4e6154 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -160,11 +160,11 @@ typedef struct { int dhcp_timeout; int required_timeout; guint32 route_table; - bool ignore_auto_routes : 1; - bool ignore_auto_dns : 1; - bool dhcp_send_hostname : 1; - bool never_default : 1; - bool may_fail : 1; + bool ignore_auto_routes; + bool ignore_auto_dns; + bool dhcp_send_hostname; + bool never_default; + bool may_fail; } NMSettingIPConfigPrivate; void _nm_setting_ip_config_private_init(gpointer self, NMSettingIPConfigPrivate *priv); @@ -288,7 +288,6 @@ 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_boolean; extern const NMSettInfoPropertType nm_sett_info_propert_type_string; NMSettingVerifyResult @@ -317,14 +316,6 @@ GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); -GVariant * -_nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * sett_info, - guint property_idx, - NMConnection * connection, - NMSetting * setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); - GVariant * _nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info, guint property_idx, @@ -487,69 +478,6 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ -#define _nm_setting_property_define_boolean_full(properties_override, \ - obj_properties, \ - prop_name, \ - prop_id, \ - default_value, \ - param_flags, \ - property_type, \ - get_fcn, \ - ...) \ - G_STMT_START \ - { \ - const gboolean _default_value = (default_value); \ - GParamSpec * _param_spec; \ - const NMSettInfoPropertType *const _property_type = (property_type); \ - \ - G_STATIC_ASSERT( \ - !NM_FLAGS_ANY((param_flags), \ - ~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE \ - | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \ - \ - nm_assert(_property_type); \ - nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_boolean); \ - \ - nm_assert(NM_IN_SET(_default_value, 0, 1)); \ - \ - _param_spec = \ - g_param_spec_boolean("" prop_name "", \ - "", \ - "", \ - _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, \ - _property_type, \ - .to_dbus_data.get_boolean = \ - (gboolean(*)(NMSetting *)) (get_fcn), \ - __VA_ARGS__); \ - } \ - G_STMT_END - -#define _nm_setting_property_define_boolean(properties_override, \ - obj_properties, \ - prop_name, \ - prop_id, \ - default_value, \ - param_flags, \ - get_fcn, \ - ...) \ - _nm_setting_property_define_boolean_full((properties_override), \ - (obj_properties), \ - prop_name, \ - (prop_id), \ - (default_value), \ - (param_flags), \ - &nm_sett_info_propert_type_boolean, \ - (get_fcn), \ - __VA_ARGS__) - -/*****************************************************************************/ - #define _nm_setting_property_define_string_full(properties_override, \ obj_properties, \ prop_name, \ diff --git a/src/libnm-core-impl/nm-setting-proxy.c b/src/libnm-core-impl/nm-setting-proxy.c index e4bd88fa73..3f888ec7d3 100644 --- a/src/libnm-core-impl/nm-setting-proxy.c +++ b/src/libnm-core-impl/nm-setting-proxy.c @@ -32,7 +32,7 @@ typedef struct { char *pac_url; char *pac_script; int method; - bool browser_only : 1; + bool browser_only; } NMSettingProxyPrivate; /** @@ -345,13 +345,14 @@ nm_setting_proxy_class_init(NMSettingProxyClass *klass) * description: Whether the proxy configuration is for browser only. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_PROXY_BROWSER_ONLY, - PROP_BROWSER_ONLY, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_proxy_get_browser_only); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_PROXY_BROWSER_ONLY, + PROP_BROWSER_ONLY, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingProxyPrivate, + browser_only); /** * NMSettingProxy:pac-url: diff --git a/src/libnm-core-impl/nm-setting-tun.c b/src/libnm-core-impl/nm-setting-tun.c index 3975d00027..99a68024ee 100644 --- a/src/libnm-core-impl/nm-setting-tun.c +++ b/src/libnm-core-impl/nm-setting-tun.c @@ -35,9 +35,9 @@ typedef struct { char * owner; char * group; NMSettingTunMode mode; - bool pi : 1; - bool vnet_hdr : 1; - bool multi_queue : 1; + bool pi; + bool vnet_hdr; + bool multi_queue; } NMSettingTunPrivate; /** @@ -369,13 +369,14 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) * * Since: 1.2 */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_TUN_PI, - PROP_PI, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_tun_get_pi); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_TUN_PI, + PROP_PI, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingTunPrivate, + pi); /** * NMSettingTun:vnet-hdr: @@ -385,13 +386,14 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) * * Since: 1.2 */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_TUN_VNET_HDR, - PROP_VNET_HDR, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_tun_get_vnet_hdr); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_TUN_VNET_HDR, + PROP_VNET_HDR, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingTunPrivate, + vnet_hdr); /** * NMSettingTun:multi-queue: @@ -403,13 +405,14 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) * * Since: 1.2 */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_TUN_MULTI_QUEUE, - PROP_MULTI_QUEUE, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_tun_get_multi_queue); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_TUN_MULTI_QUEUE, + PROP_MULTI_QUEUE, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingTunPrivate, + multi_queue); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index c94a86e9f9..1df4f66130 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -47,11 +47,6 @@ typedef struct { */ char *user_name; - /* Whether the VPN stays up across link changes, until the user - * explicitly disconnects it. - */ - gboolean persistent; - /* The hash table is created at setting object * init time and should not be replaced. It is * a char * -> char * mapping, and both the key @@ -72,6 +67,12 @@ typedef struct { /* Timeout for the VPN service to establish the connection */ guint32 timeout; + + /* Whether the VPN stays up across link changes, until the user + * explicitly disconnects it. + */ + bool persistent; + } NMSettingVpnPrivate; /** @@ -1172,13 +1173,14 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) * the VPN will attempt to stay connected across link changes and outages, * until explicitly disconnected. **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_VPN_PERSISTENT, - PROP_PERSISTENT, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_vpn_get_persistent); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_VPN_PERSISTENT, + PROP_PERSISTENT, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingVpnPrivate, + persistent); /** * NMSettingVpn:data: (type GHashTable(utf8,utf8)): diff --git a/src/libnm-core-impl/nm-setting-vxlan.c b/src/libnm-core-impl/nm-setting-vxlan.c index 845ede04c6..e625034338 100644 --- a/src/libnm-core-impl/nm-setting-vxlan.c +++ b/src/libnm-core-impl/nm-setting-vxlan.c @@ -53,11 +53,11 @@ typedef struct { guint ttl; guint ageing; guint limit; - bool learning : 1; - bool proxy : 1; - bool rsc : 1; - bool l2_miss : 1; - bool l3_miss : 1; + bool proxy; + bool learning; + bool rsc; + bool l2_miss; + bool l3_miss; } NMSettingVxlanPrivate; /** @@ -595,6 +595,7 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) "", NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + /** * NMSettingVxlan:id: * @@ -765,13 +766,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_VXLAN_PROXY, - PROP_PROXY, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_vxlan_get_proxy); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_PROXY, + PROP_PROXY, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + proxy); /** * NMSettingVxlan:learning: @@ -781,13 +783,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_VXLAN_LEARNING, - PROP_LEARNING, - TRUE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_vxlan_get_learning); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_LEARNING, + PROP_LEARNING, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + learning); /** * NMSettingVxlan:rsc: @@ -796,13 +799,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_VXLAN_RSC, - PROP_RSC, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_vxlan_get_rsc); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_RSC, + PROP_RSC, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + rsc); /** * NMSettingVxlan:l2-miss: @@ -811,13 +815,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_VXLAN_L2_MISS, - PROP_L2_MISS, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_vxlan_get_l2_miss); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_L2_MISS, + PROP_L2_MISS, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + l2_miss); /** * NMSettingVxlan:l3-miss: @@ -826,13 +831,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_VXLAN_L3_MISS, - PROP_L3_MISS, - FALSE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_vxlan_get_l3_miss); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_L3_MISS, + PROP_L3_MISS, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + l3_miss); 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 7e64949de7..326cdc1f4b 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -66,7 +66,7 @@ typedef struct { NMTernary accept_all_mac_addresses; guint32 speed; guint32 mtu; - bool auto_negotiate : 1; + bool auto_negotiate; } NMSettingWiredPrivate; /** @@ -1380,14 +1380,15 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * "speed" and "duplex" parameters (skips link configuration). * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_WIRED_AUTO_NEGOTIATE, - PROP_AUTO_NEGOTIATE, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_wired_get_auto_negotiate, - .to_dbus_data.including_default = TRUE); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_WIRED_AUTO_NEGOTIATE, + PROP_AUTO_NEGOTIATE, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + auto_negotiate, + .to_dbus_data.including_default = TRUE); /** * NMSettingWired:mac-address: diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index ba99ea0bfb..d6fa853bed 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -902,8 +902,8 @@ typedef struct { guint32 fwmark; guint32 mtu; guint16 listen_port; + bool peer_routes; bool private_key_valid : 1; - bool peer_routes : 1; } NMSettingWireGuardPrivate; /** @@ -2514,13 +2514,14 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_WIREGUARD_PEER_ROUTES, - PROP_PEER_ROUTES, - TRUE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_wireguard_get_peer_routes); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_PEER_ROUTES, + PROP_PEER_ROUTES, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingWireGuardPrivate, + peer_routes); /** * NMSettingWireGuard:mtu: diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index a7ad9624ba..83f8afc158 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -63,7 +63,7 @@ typedef struct { guint32 mtu; guint32 powersave; guint32 wowl; - bool hidden : 1; + bool hidden; } NMSettingWirelessPrivate; /** @@ -1833,13 +1833,14 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: Whether the network hides the SSID. * ---end--- */ - _nm_setting_property_define_boolean(properties_override, - obj_properties, - NM_SETTING_WIRELESS_HIDDEN, - PROP_HIDDEN, - FALSE, - NM_SETTING_PARAM_NONE, - nm_setting_wireless_get_hidden); + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_WIRELESS_HIDDEN, + PROP_HIDDEN, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + hidden); /** * NMSettingWireless:powersave: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 8dfdad26d8..c3b324d603 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -570,24 +570,6 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * } } -GVariant * -_nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * sett_info, - guint property_idx, - NMConnection * connection, - NMSetting * setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options) -{ - const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; - gboolean val; - - val = !!property_info->to_dbus_data.get_boolean(setting); - if (!property_info->to_dbus_data.including_default - && val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) - return NULL; - return g_variant_ref(nm_g_variant_singleton_b(val)); -} - GVariant * _nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info, guint property_idx, @@ -2446,10 +2428,6 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = .direct_type = NM_VALUE_TYPE_BOOL, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); -const NMSettInfoPropertType nm_sett_info_propert_type_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( - G_VARIANT_TYPE_BOOLEAN, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_boolean); - const NMSettInfoPropertType nm_sett_info_propert_type_string = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 41db66e909..beec0aff88 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4481,12 +4481,6 @@ check_done:; != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); can_set_including_default = TRUE; - } else if (sip->property_type->to_dbus_fcn - == _nm_setting_property_to_dbus_fcn_get_boolean) { - g_assert(sip->param_spec); - g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN); - g_assert(sip->to_dbus_data.get_boolean); - can_set_including_default = TRUE; } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_string) { g_assert(sip->param_spec); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 2c5bb93428..4d7a4cb852 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -725,7 +725,6 @@ struct _NMSettInfoProperty { union { gpointer none; NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; - gboolean (*get_boolean)(NMSetting *); const char *(*get_string)(NMSetting *); }; From 7556b4f382f0cdb382dd96d728a8ceff2efa6487 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 19:17:19 +0200 Subject: [PATCH 08/16] libnm: add direct_offset for string properties And, as an example used for property "connection.stable-id". --- src/libnm-core-impl/nm-setting-connection.c | 13 +++-- src/libnm-core-impl/nm-setting-private.h | 64 +++++++++++++++++++++ src/libnm-core-impl/nm-setting.c | 26 +++++++++ src/libnm-core-impl/tests/test-setting.c | 6 ++ 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index f833aea7c0..61e1cca122 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1956,12 +1956,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: Token to generate stable IDs. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_STABLE_ID, - PROP_STABLE_ID, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_connection_get_stable_id); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_STABLE_ID, + PROP_STABLE_ID, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingConnectionPrivate, + stable_id); /** * NMSettingConnection:interface-name: diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index dcfd4e6154..cf7e0d7541 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -287,6 +287,7 @@ 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_string; extern const NMSettInfoPropertType nm_sett_info_propert_type_string; @@ -478,6 +479,69 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ +#define _nm_setting_property_define_direct_string_full(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + param_flags, \ + property_type, \ + private_struct_type, \ + private_struct_field, \ + ...) \ + G_STMT_START \ + { \ + GParamSpec * _param_spec; \ + const NMSettInfoPropertType *_property_type = (property_type); \ + \ + 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))); \ + \ + nm_assert(_property_type); \ + nm_assert(g_variant_type_equal(_property_type->dbus_type, "s")); \ + nm_assert(_property_type->direct_type == NM_VALUE_TYPE_STRING); \ + nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); \ + \ + _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, \ + _property_type, \ + .direct_offset = \ + NM_STRUCT_OFFSET_ENSURE_TYPE(char *, private_struct_type, private_struct_field), \ + __VA_ARGS__); \ + } \ + G_STMT_END + +#define _nm_setting_property_define_direct_string(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + param_flags, \ + private_struct_type, \ + private_struct_field, \ + ...) \ + _nm_setting_property_define_direct_string_full((properties_override), \ + (obj_properties), \ + prop_name, \ + (prop_id), \ + (param_flags), \ + &nm_sett_info_propert_type_direct_string, \ + private_struct_type, \ + private_struct_field, \ + __VA_ARGS__) + +/*****************************************************************************/ + #define _nm_setting_property_define_string_full(properties_override, \ obj_properties, \ prop_name, \ diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index c3b324d603..9a4e202b19 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -565,6 +565,27 @@ _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_STRING: + { + const char *val; + + /* For string properties that are implemented via this function, the default is always NULL. + * In general, having strings default to NULL is most advisable. + * + * Setting "including_default" for a string makes no sense because a + * GVariant of type "s" cannot express NULL. */ + nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); + nm_assert(!property_info->to_dbus_data.including_default); + + val = *((const char *const *) _nm_setting_get_private(setting, + sett_info, + property_info->direct_offset)); + if (!val) + return NULL; + if (!val[0]) + return g_variant_ref(nm_g_variant_singleton_s_empty()); + return g_variant_new_string(val); + } default: return nm_assert_unreachable_val(NULL); } @@ -2428,6 +2449,11 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = .direct_type = NM_VALUE_TYPE_BOOL, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); +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, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); + const NMSettInfoPropertType nm_sett_info_propert_type_string = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index beec0aff88..85b96d899a 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4443,6 +4443,12 @@ 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_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); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_STRING); } else g_assert_not_reached(); From 102a1f5c314ace0039bb4c06b490aeac884eaa95 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 17:28:21 +0200 Subject: [PATCH 09/16] libnm: use _nm_setting_property_define_direct_string() --- src/libnm-core-impl/nm-setting-6lowpan.c | 13 +-- src/libnm-core-impl/nm-setting-adsl.c | 60 +++++++----- src/libnm-core-impl/nm-setting-connection.c | 103 +++++++++++--------- src/libnm-core-impl/nm-setting-ip-config.c | 24 ++--- src/libnm-core-impl/nm-setting-ip-tunnel.c | 65 ++++++------ src/libnm-core-impl/nm-setting-ip4-config.c | 39 ++++---- src/libnm-core-impl/nm-setting-ip6-config.c | 26 ++--- src/libnm-core-impl/nm-setting-private.h | 66 ------------- src/libnm-core-impl/nm-setting-wired.c | 65 ++++++------ src/libnm-core-impl/nm-setting.c | 31 ------ src/libnm-core-impl/tests/test-setting.c | 5 - src/libnm-core-intern/nm-core-internal.h | 11 ++- 12 files changed, 227 insertions(+), 281 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-6lowpan.c b/src/libnm-core-impl/nm-setting-6lowpan.c index f647b249b5..1fc2a2d4a9 100644 --- a/src/libnm-core-impl/nm-setting-6lowpan.c +++ b/src/libnm-core-impl/nm-setting-6lowpan.c @@ -216,12 +216,13 @@ nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) * * Since: 1.14 **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_6LOWPAN_PARENT, - PROP_PARENT, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_6lowpan_get_parent); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_6LOWPAN_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSetting6LowpanPrivate, + parent); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-adsl.c b/src/libnm-core-impl/nm-setting-adsl.c index 233467240e..470753b1d0 100644 --- a/src/libnm-core-impl/nm-setting-adsl.c +++ b/src/libnm-core-impl/nm-setting-adsl.c @@ -370,24 +370,26 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass) * * Username used to authenticate with the ADSL service. **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_ADSL_USERNAME, - PROP_USERNAME, - NM_SETTING_PARAM_NONE, - nm_setting_adsl_get_username); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_ADSL_USERNAME, + PROP_USERNAME, + NM_SETTING_PARAM_NONE, + NMSettingAdslPrivate, + username); /** * NMSettingAdsl:password: * * Password used to authenticate with the ADSL service. **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_ADSL_PASSWORD, - PROP_PASSWORD, - NM_SETTING_PARAM_SECRET, - nm_setting_adsl_get_password); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_ADSL_PASSWORD, + PROP_PASSWORD, + NM_SETTING_PARAM_SECRET, + NMSettingAdslPrivate, + password); /** * NMSettingAdsl:password-flags: @@ -407,24 +409,34 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass) * * ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm". **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_ADSL_PROTOCOL, - PROP_PROTOCOL, - NM_SETTING_PARAM_NONE, - nm_setting_adsl_get_protocol); + _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); /** * NMSettingAdsl:encapsulation: * * Encapsulation of ADSL connection. Can be "vcmux" or "llc". **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_ADSL_ENCAPSULATION, - PROP_ENCAPSULATION, - NM_SETTING_PARAM_NONE, - nm_setting_adsl_get_encapsulation); + _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); /** * NMSettingAdsl:vpi: diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 61e1cca122..a044f1ae21 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1872,12 +1872,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: User friendly name for the connection profile. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_ID, - PROP_ID, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_connection_get_id); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_ID, + PROP_ID, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingConnectionPrivate, + id); /** * NMSettingConnection:uuid: @@ -1902,12 +1903,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * creates the UUID itself (by hashing the filename). * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_UUID, - PROP_UUID, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_connection_get_uuid); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_UUID, + PROP_UUID, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingConnectionPrivate, + uuid); /** * NMSettingConnection:stable-id: @@ -1987,17 +1989,19 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * can be required for some connection types. * ---end--- */ - _nm_setting_property_define_string_full( + _nm_setting_property_define_direct_string_full( properties_override, obj_properties, NM_SETTING_CONNECTION_INTERFACE_NAME, PROP_INTERFACE_NAME, NM_SETTING_PARAM_INFERRABLE, NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string, + .direct_type = NM_VALUE_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .missing_from_dbus_fcn = nm_setting_connection_no_interface_name), - nm_setting_connection_get_interface_name); + NMSettingConnectionPrivate, + interface_name); /** * NMSettingConnection:type: @@ -2017,12 +2021,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * example: TYPE=Ethernet; TYPE=Bond; TYPE=Bridge; DEVICETYPE=TeamPort * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_TYPE, - PROP_TYPE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_connection_get_connection_type); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_TYPE, + PROP_TYPE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingConnectionPrivate, + type); /** * NMSettingConnection:permissions: @@ -2229,13 +2234,14 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * example: ZONE=Work * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_ZONE, - PROP_ZONE, - NM_SETTING_PARAM_FUZZY_IGNORE - | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY, - nm_setting_connection_get_zone); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_ZONE, + PROP_ZONE, + NM_SETTING_PARAM_FUZZY_IGNORE + | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY, + NMSettingConnectionPrivate, + zone); /** * NMSettingConnection:master: @@ -2251,12 +2257,14 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * for compatibility with legacy tooling. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_MASTER, - PROP_MASTER, - NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE, - nm_setting_connection_get_master); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_MASTER, + PROP_MASTER, + NM_SETTING_PARAM_FUZZY_IGNORE + | NM_SETTING_PARAM_INFERRABLE, + NMSettingConnectionPrivate, + master); /** * NMSettingConnection:slave-type: @@ -2275,12 +2283,14 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * and BRIDGE_UUID for bridging. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_SLAVE_TYPE, - PROP_SLAVE_TYPE, - NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE, - nm_setting_connection_get_slave_type); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_SLAVE_TYPE, + PROP_SLAVE_TYPE, + NM_SETTING_PARAM_FUZZY_IGNORE + | NM_SETTING_PARAM_INFERRABLE, + NMSettingConnectionPrivate, + slave_type); /** * NMSettingConnection:autoconnect-slaves: @@ -2562,12 +2572,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * example: https://yourdevice.example.com/model.json * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_MUD_URL, - PROP_MUD_URL, - NM_SETTING_PARAM_NONE, - nm_setting_connection_get_mud_url); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_MUD_URL, + PROP_MUD_URL, + NM_SETTING_PARAM_NONE, + NMSettingConnectionPrivate, + mud_url); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 70807f7c4e..a9214af4e4 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5776,32 +5776,32 @@ _nm_sett_info_property_override_create_array_ip_config(void) _nm_properties_override_gobj( properties_override, obj_properties[PROP_METHOD], - &nm_sett_info_propert_type_string, - .to_dbus_data.get_string = - (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_method); + &nm_sett_info_propert_type_direct_string, + .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, method)); _nm_properties_override_gobj( properties_override, obj_properties[PROP_GATEWAY], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string, + .direct_type = NM_VALUE_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .from_dbus_fcn = ip_gateway_set), - .to_dbus_data.get_string = - (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_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); _nm_properties_override_gobj( properties_override, obj_properties[PROP_DHCP_HOSTNAME], - &nm_sett_info_propert_type_string, - .to_dbus_data.get_string = - (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_dhcp_hostname); + &nm_sett_info_propert_type_direct_string, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, dhcp_hostname)); _nm_properties_override_gobj( properties_override, obj_properties[PROP_DHCP_IAID], - &nm_sett_info_propert_type_string, - .to_dbus_data.get_string = - (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_dhcp_iaid); + &nm_sett_info_propert_type_direct_string, + .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, dhcp_iaid)); /* ---dbus--- * property: routing-rules diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index 50adc73ee3..66a2cb551b 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -675,12 +675,13 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP_TUNNEL_PARENT, - PROP_PARENT, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip_tunnel_get_parent); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + parent); /** * NMSettingIPTunnel:mode: @@ -707,12 +708,13 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP_TUNNEL_LOCAL, - PROP_LOCAL, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip_tunnel_get_local); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_LOCAL, + PROP_LOCAL, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + local); /** * NMSettingIPTunnel:remote: @@ -722,12 +724,13 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP_TUNNEL_REMOTE, - PROP_REMOTE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip_tunnel_get_remote); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_REMOTE, + PROP_REMOTE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + remote); /** * NMSettingIPTunnel:ttl @@ -787,12 +790,13 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP_TUNNEL_INPUT_KEY, - PROP_INPUT_KEY, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip_tunnel_get_input_key); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_INPUT_KEY, + PROP_INPUT_KEY, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + input_key); /** * NMSettingIPTunnel:output-key: @@ -802,12 +806,13 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP_TUNNEL_OUTPUT_KEY, - PROP_OUTPUT_KEY, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip_tunnel_get_output_key); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_OUTPUT_KEY, + PROP_OUTPUT_KEY, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + output_key); /** * NMSettingIPTunnel:encapsulation-limit: diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 1704820bde..4b6f92083d 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -856,12 +856,13 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: DHCP_CLIENT_ID=ax-srv-1; DHCP_CLIENT_ID=01:44:44:44:44:44:44 * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, - PROP_DHCP_CLIENT_ID, - NM_SETTING_PARAM_NONE, - nm_setting_ip4_config_get_dhcp_client_id); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, + PROP_DHCP_CLIENT_ID, + NM_SETTING_PARAM_NONE, + NMSettingIP4ConfigPrivate, + dhcp_client_id); /* ---ifcfg-rh--- * property: dad-timeout @@ -907,12 +908,13 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: DHCP_FQDN=foo.bar.com * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP4_CONFIG_DHCP_FQDN, - PROP_DHCP_FQDN, - NM_SETTING_PARAM_NONE, - nm_setting_ip4_config_get_dhcp_fqdn); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP4_CONFIG_DHCP_FQDN, + PROP_DHCP_FQDN, + NM_SETTING_PARAM_NONE, + NMSettingIP4ConfigPrivate, + dhcp_fqdn); /** * NMSettingIP4Config:dhcp-vendor-class-identifier: @@ -933,12 +935,13 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: DHCP_VENDOR_CLASS_IDENTIFIER=foo * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, - PROP_DHCP_VENDOR_CLASS_IDENTIFIER, - NM_SETTING_PARAM_NONE, - nm_setting_ip4_config_get_dhcp_vendor_class_identifier); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, + PROP_DHCP_VENDOR_CLASS_IDENTIFIER, + NM_SETTING_PARAM_NONE, + NMSettingIP4ConfigPrivate, + dhcp_vendor_class_identifier); /* IP4-specific property overrides */ diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 55564d602f..6e0e9897b7 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -921,12 +921,13 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: IPV6_TOKEN=::53 * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP6_CONFIG_TOKEN, - PROP_TOKEN, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_ip6_config_get_token); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_TOKEN, + PROP_TOKEN, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIP6ConfigPrivate, + token); /** * NMSettingIP6Config:ra-timeout: @@ -1001,12 +1002,13 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: DHCPV6_DUID=LL; DHCPV6_DUID=0301deadbeef0001; DHCPV6_DUID=03:01:de:ad:be:ef:00:01 * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_IP6_CONFIG_DHCP_DUID, - PROP_DHCP_DUID, - NM_SETTING_PARAM_NONE, - nm_setting_ip6_config_get_dhcp_duid); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_DHCP_DUID, + PROP_DHCP_DUID, + NM_SETTING_PARAM_NONE, + NMSettingIP6ConfigPrivate, + dhcp_duid); /* IP6-specific property overrides */ diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index cf7e0d7541..f76c719342 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -289,8 +289,6 @@ 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_string; -extern const NMSettInfoPropertType nm_sett_info_propert_type_string; - NMSettingVerifyResult _nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error); @@ -317,14 +315,6 @@ GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); -GVariant * -_nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info, - guint property_idx, - NMConnection * connection, - NMSetting * setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); - GVariant *_nm_setting_to_dbus(NMSetting * setting, NMConnection * connection, NMConnectionSerializationFlags flags, @@ -542,62 +532,6 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ -#define _nm_setting_property_define_string_full(properties_override, \ - obj_properties, \ - prop_name, \ - prop_id, \ - param_flags, \ - property_type, \ - get_fcn, \ - ...) \ - G_STMT_START \ - { \ - GParamSpec * _param_spec; \ - const NMSettInfoPropertType *const _property_type = (property_type); \ - \ - 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))); \ - nm_assert(_property_type); \ - nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_string); \ - \ - _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, \ - _property_type, \ - .to_dbus_data.get_string = \ - (const char *(*) (NMSetting *) ) (get_fcn), \ - __VA_ARGS__); \ - } \ - G_STMT_END - -#define _nm_setting_property_define_string(properties_override, \ - obj_properties, \ - prop_name, \ - prop_id, \ - param_flags, \ - get_fcn, \ - ...) \ - _nm_setting_property_define_string_full((properties_override), \ - (obj_properties), \ - prop_name, \ - (prop_id), \ - (param_flags), \ - &nm_sett_info_propert_type_string, \ - (get_fcn), \ - __VA_ARGS__) - -/*****************************************************************************/ - gboolean _nm_setting_use_legacy_property(NMSetting * setting, GVariant * connection_dict, const char *legacy_property, diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 326cdc1f4b..3c0f0302f5 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -1291,12 +1291,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * description: The property is not saved by the plugin. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_WIRED_PORT, - PROP_PORT, - NM_SETTING_PARAM_NONE, - nm_setting_wired_get_port); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRED_PORT, + PROP_PORT, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + port); /** * NMSettingWired:speed: @@ -1353,12 +1354,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * "duplex" parameter in the ETHOOL_OPTS variable. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_WIRED_DUPLEX, - PROP_DUPLEX, - NM_SETTING_PARAM_NONE, - nm_setting_wired_get_duplex); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRED_DUPLEX, + PROP_DUPLEX, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + duplex); /** * NMSettingWired:auto-negotiate: @@ -1532,12 +1534,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * cloned-mac-address. * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, - PROP_GENERATE_MAC_ADDRESS_MASK, - NM_SETTING_PARAM_FUZZY_IGNORE, - nm_setting_wired_get_generate_mac_address_mask); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, + PROP_GENERATE_MAC_ADDRESS_MASK, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWiredPrivate, + generate_mac_address_mask); /** * NMSettingWired:mac-address-blacklist: @@ -1628,12 +1631,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * example: NETTYPE=qeth * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_WIRED_S390_NETTYPE, - PROP_S390_NETTYPE, - NM_SETTING_PARAM_INFERRABLE, - nm_setting_wired_get_s390_nettype); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRED_S390_NETTYPE, + PROP_S390_NETTYPE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingWiredPrivate, + s390_nettype); /** * NMSettingWired:s390-options: (type GHashTable(utf8,utf8)): @@ -1713,12 +1717,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * example: ETHTOOL_OPTS="wol gs sopass 00:11:22:33:44:55" * ---end--- */ - _nm_setting_property_define_string(properties_override, - obj_properties, - NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, - PROP_WAKE_ON_LAN_PASSWORD, - NM_SETTING_PARAM_NONE, - nm_setting_wired_get_wake_on_lan_password); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, + PROP_WAKE_ON_LAN_PASSWORD, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + wol_password); /** * NMSettingWired:accept-all-mac-addresses: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 9a4e202b19..4c51bc08f0 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -591,33 +591,6 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * } } -GVariant * -_nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info, - guint property_idx, - NMConnection * connection, - NMSetting * setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options) -{ - const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; - const char * val; - - /* For string properties that are implemented via this function, the default is always NULL. - * In general, having strings default to NULL is most advisable. - * - * Setting "including_default" for a string makes no sense because a - * GVariant of type "s" cannot express NULL. */ - nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); - nm_assert(!property_info->to_dbus_data.including_default); - - val = property_info->to_dbus_data.get_string(setting); - if (!val) - return NULL; - if (!val[0]) - return g_variant_ref(nm_g_variant_singleton_s_empty()); - return g_variant_new_string(val); -} - GVariant * _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, guint property_idx, @@ -2454,10 +2427,6 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_string = .direct_type = NM_VALUE_TYPE_STRING, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); -const NMSettInfoPropertType nm_sett_info_propert_type_string = - NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string); - /*****************************************************************************/ static GenData * diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 85b96d899a..d00a9796b5 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4487,11 +4487,6 @@ check_done:; != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); can_set_including_default = TRUE; - } else if (sip->property_type->to_dbus_fcn - == _nm_setting_property_to_dbus_fcn_get_string) { - g_assert(sip->param_spec); - g_assert(sip->param_spec->value_type == G_TYPE_STRING); - g_assert(sip->to_dbus_data.get_string); } if (!can_set_including_default) diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 4d7a4cb852..2933c73c29 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -721,11 +721,20 @@ 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; + struct { union { gpointer none; NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; - const char *(*get_string)(NMSetting *); }; /* Usually, properties that are set to the default value for the GParamSpec From f1cb07e4380bb632080a53973ce53391d299f623 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 23:00:21 +0200 Subject: [PATCH 10/16] libnm: support lookup of property-info by param-spec We also need to find efficiently the property-info for a given GParamSpec. Add a lookup index for that. --- src/libnm-core-impl/nm-setting-private.h | 4 ++ src/libnm-core-impl/nm-setting.c | 87 ++++++++++++++++++++++-- src/libnm-core-impl/tests/test-setting.c | 46 +++++++++++++ src/libnm-core-intern/nm-core-internal.h | 13 ++++ 4 files changed, 146 insertions(+), 4 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index f76c719342..39e5992126 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -332,6 +332,10 @@ gboolean _nm_setting_property_is_regular_secret_flags(NMSetting * setting, /*****************************************************************************/ +const NMSettInfoProperty * +_nm_sett_info_property_lookup_by_param_spec(const NMSettInfoSetting *sett_info, + const GParamSpec * param_spec); + static inline GArray * _nm_sett_info_property_override_create_array_sized(guint reserved_size) { diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 4c51bc08f0..eef2a30d5c 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -263,6 +263,16 @@ _property_infos_sort(const NMSettInfoProperty *property_infos, return arr; } +static int +_property_lookup_by_param_spec_sort(gconstpointer p_a, gconstpointer p_b, gpointer user_data) +{ + const NMSettInfoPropertLookupByParamSpec *a = p_a; + const NMSettInfoPropertLookupByParamSpec *b = p_b; + + NM_CMP_DIRECT(a->param_spec_as_uint, b->param_spec_as_uint); + return 0; +} + void _nm_setting_class_commit(NMSettingClass * setting_class, NMMetaSettingType meta_type, @@ -271,10 +281,11 @@ _nm_setting_class_commit(NMSettingClass * setting_class, gint16 private_offset) { NMSettInfoSetting *sett_info; - gs_free GParamSpec **property_specs = NULL; - guint n_property_specs; - guint override_len; - guint i; + gs_free GParamSpec ** property_specs = NULL; + guint n_property_specs; + NMSettInfoPropertLookupByParamSpec *lookup_by_iter; + guint override_len; + guint i; nm_assert(NM_IS_SETTING_CLASS(setting_class)); nm_assert(!setting_class->setting_info); @@ -424,6 +435,33 @@ has_property_type: sett_info->property_infos_len, setting_class); + nm_assert(sett_info->property_infos_len < G_MAXUINT16); + sett_info->property_lookup_by_param_spec_len = 0; + for (i = 0; i < sett_info->property_infos_len; i++) { + if (sett_info->property_infos[i].param_spec) { + sett_info->property_lookup_by_param_spec_len++; + } + } + sett_info->property_lookup_by_param_spec = + g_new(NMSettInfoPropertLookupByParamSpec, sett_info->property_lookup_by_param_spec_len); + lookup_by_iter = + (NMSettInfoPropertLookupByParamSpec *) sett_info->property_lookup_by_param_spec; + for (i = 0; i < sett_info->property_infos_len; i++) { + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; + + if (property_info->param_spec) { + *(lookup_by_iter++) = (NMSettInfoPropertLookupByParamSpec){ + .param_spec_as_uint = (uintptr_t) ((gpointer) property_info->param_spec), + .property_info = property_info, + }; + } + } + g_qsort_with_data(sett_info->property_lookup_by_param_spec, + sett_info->property_lookup_by_param_spec_len, + sizeof(NMSettInfoPropertLookupByParamSpec), + _property_lookup_by_param_spec_sort, + NULL); + g_array_free(properties_override, TRUE); } @@ -473,6 +511,47 @@ _nm_setting_class_get_sett_info(NMSettingClass *setting_class) return sett_info; } +const NMSettInfoProperty * +_nm_sett_info_property_lookup_by_param_spec(const NMSettInfoSetting *sett_info, + const GParamSpec * param_spec) +{ + NMSettInfoPropertLookupByParamSpec needle; + int imin; + int imax; + int imid; + int cmp; + + nm_assert(sett_info); + nm_assert(param_spec); + + /* ensure that "int" is large enough to contain the index variables. */ + G_STATIC_ASSERT_EXPR(sizeof(int) > sizeof(sett_info->property_lookup_by_param_spec_len)); + + if (sett_info->property_lookup_by_param_spec_len == 0) + return NULL; + + needle.param_spec_as_uint = (uintptr_t) ((gpointer) param_spec); + + imin = 0; + imax = sett_info->property_lookup_by_param_spec_len - 1; + while (imin <= imax) { + imid = imin + (imax - imin) / 2; + + cmp = _property_lookup_by_param_spec_sort(&sett_info->property_lookup_by_param_spec[imid], + &needle, + NULL); + if (cmp == 0) + return sett_info->property_lookup_by_param_spec[imid].property_info; + + if (cmp < 0) + imin = imid + 1; + else + imax = imid - 1; + } + + return NULL; +} + /*****************************************************************************/ void diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index d00a9796b5..944b3cc5b5 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4388,6 +4388,9 @@ test_setting_metadata(void) guint prop_idx; gs_free GParamSpec **property_specs = NULL; guint n_property_specs; + guint n_param_spec; + guint i; + guint j; g_assert(sis); @@ -4418,6 +4421,8 @@ test_setting_metadata(void) h_properties = g_hash_table_new(nm_str_hash, g_str_equal); + n_param_spec = 0; + for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; GArray * property_types_data; @@ -4426,6 +4431,9 @@ test_setting_metadata(void) g_assert(sip->name); + if (sip->param_spec) + n_param_spec++; + if (prop_idx > 0) g_assert_cmpint(strcmp(sis->property_infos[prop_idx - 1].name, sip->name), <, 0); @@ -4587,6 +4595,44 @@ check_done:; g_assert_cmpstr(sis->property_infos[0].name, ==, NM_SETTING_NAME); } else g_assert_cmpint(meta_type, !=, NM_META_SETTING_TYPE_ETHTOOL); + + g_assert_cmpint(n_param_spec, >, 0); + g_assert_cmpint(n_param_spec, ==, sis->property_lookup_by_param_spec_len); + g_assert(sis->property_lookup_by_param_spec); + for (i = 0; i < sis->property_lookup_by_param_spec_len; i++) { + const NMSettInfoPropertLookupByParamSpec *p = &sis->property_lookup_by_param_spec[i]; + guint n_found; + + if (i > 0) { + g_assert_cmpint(sis->property_lookup_by_param_spec[i - 1].param_spec_as_uint, + <, + p->param_spec_as_uint); + } + g_assert(p->property_info); + g_assert(p->property_info >= sis->property_infos); + g_assert(p->property_info < &sis->property_infos[sis->property_infos_len]); + g_assert(p->property_info + == &sis->property_infos[p->property_info - sis->property_infos]); + + g_assert(p->property_info->param_spec); + g_assert(p->param_spec_as_uint + == ((uintptr_t) ((gpointer) p->property_info->param_spec))); + + g_assert(_nm_sett_info_property_lookup_by_param_spec(sis, p->property_info->param_spec) + == p->property_info); + + n_found = 0; + for (j = 0; j < sis->property_infos_len; j++) { + const NMSettInfoProperty *pip2 = &sis->property_infos[j]; + + if (pip2->param_spec + && p->param_spec_as_uint == ((uintptr_t) ((gpointer) pip2->param_spec))) { + g_assert(pip2 == p->property_info); + n_found++; + } + } + g_assert(n_found == 1); + } } { diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 2933c73c29..6735a9e5b4 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -745,6 +745,15 @@ struct _NMSettInfoProperty { } to_dbus_data; }; +typedef struct { + /* we want to do binary search by "GParamSpec *", but unrelated pointers + * are not directly comparable in C. No problem, we convert them to + * uintptr_t for the search, that is guaranteed to work. */ + uintptr_t param_spec_as_uint; + + const NMSettInfoProperty *property_info; +} NMSettInfoPropertLookupByParamSpec; + typedef struct { const GVariantType *(*get_variant_type)(const struct _NMSettInfoSetting *sett_info, const char * name, @@ -784,8 +793,12 @@ struct _NMSettInfoSetting { */ const NMSettInfoProperty *const *property_infos_sorted; + const NMSettInfoPropertLookupByParamSpec *property_lookup_by_param_spec; + guint property_infos_len; + guint16 property_lookup_by_param_spec_len; + /* the offset in bytes to get the private data from the @self pointer. */ gint16 private_offset; From 69db8a462a0f7f5d3fcfc0a4ecc2502a76fbe48d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 20:48:40 +0200 Subject: [PATCH 11/16] libnm: add generic GObject property getter/setter If we only have simple, direct properties, then we have all the information we need for a generic get_property()/set_property() implmenentation. --- src/libnm-core-impl/nm-setting-6lowpan.c | 39 +-------- src/libnm-core-impl/nm-setting-private.h | 10 +++ src/libnm-core-impl/nm-setting.c | 107 +++++++++++++++++++++++ 3 files changed, 119 insertions(+), 37 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-6lowpan.c b/src/libnm-core-impl/nm-setting-6lowpan.c index 1fc2a2d4a9..c7f1aca66e 100644 --- a/src/libnm-core-impl/nm-setting-6lowpan.c +++ b/src/libnm-core-impl/nm-setting-6lowpan.c @@ -128,41 +128,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSetting6Lowpan * setting = NM_SETTING_6LOWPAN(object); - NMSetting6LowpanPrivate *priv = NM_SETTING_6LOWPAN_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_value_set_string(value, priv->parent); - 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) -{ - NMSetting6Lowpan * setting = NM_SETTING_6LOWPAN(object); - NMSetting6LowpanPrivate *priv = NM_SETTING_6LOWPAN_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_6lowpan_init(NMSetting6Lowpan *setting) {} @@ -202,8 +167,8 @@ nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) g_type_class_add_private(klass, sizeof(NMSetting6LowpanPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; object_class->finalize = finalize; setting_class->verify = verify; diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 39e5992126..e35543e170 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -301,6 +301,16 @@ gboolean _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType typ gboolean _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_type); +void _nm_setting_property_get_property_direct(GObject * object, + guint prop_id, + GValue * value, + GParamSpec *pspec); + +void _nm_setting_property_set_property_direct(GObject * object, + guint prop_id, + const GValue *value, + GParamSpec * pspec); + GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, guint property_idx, NMConnection * connection, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index eef2a30d5c..faad3bcae6 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -623,6 +623,113 @@ _nm_setting_use_legacy_property(NMSetting * setting, /*****************************************************************************/ +void +_nm_setting_property_get_property_direct(GObject * object, + guint prop_id, + GValue * value, + GParamSpec *pspec) +{ + NMSetting * setting = NM_SETTING(object); + const NMSettInfoSetting * sett_info; + const NMSettInfoProperty *property_info; + + sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); + nm_assert(sett_info); + + property_info = _nm_sett_info_property_lookup_by_param_spec(sett_info, pspec); + if (!property_info) + goto out_fail; + + nm_assert(property_info->param_spec == pspec); + + switch (property_info->property_type->direct_type) { + case NM_VALUE_TYPE_BOOL: + { + const bool *p_val = + _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + + g_value_set_boolean(value, *p_val); + return; + } + case NM_VALUE_TYPE_STRING: + { + const char *const *p_val = + _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + + g_value_set_string(value, *p_val); + return; + } + default: + goto out_fail; + } + + return; + +out_fail: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); +} + +void +_nm_setting_property_set_property_direct(GObject * object, + guint prop_id, + const GValue *value, + GParamSpec * pspec) +{ + NMSetting * setting = NM_SETTING(object); + const NMSettInfoSetting * sett_info; + const NMSettInfoProperty *property_info; + + sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); + nm_assert(sett_info); + + property_info = _nm_sett_info_property_lookup_by_param_spec(sett_info, pspec); + if (!property_info) + goto out_fail; + + 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: + { + bool * p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + gboolean v; + + v = g_value_get_boolean(value); + if (*p_val == v) + return; + *p_val = v; + 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))) + return; + goto out_notify; + } + default: + goto out_fail; + } + + return; + +out_notify: + /* If explicit-notify would be set, we would need to emit g_object_notify_by_pspec(). + * + * Currently we never set that, also because we still support glib 2.40. */ + nm_assert(!NM_FLAGS_HAS(pspec->flags, 1 << 30 /* G_PARAM_EXPLICIT_NOTIFY */)); + return; + +out_fail: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); +} + +/*****************************************************************************/ + GVariant * _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info, guint property_idx, From 27621dde45586b8beba773966ceac4f1c61d7e75 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Jun 2021 23:51:42 +0200 Subject: [PATCH 12/16] libnm: add generic cleanup function to finalize NMSetting If all settings would be strictly be implemented as "direct" properties, we could call this from NMSetting.finalize() and be done with it. As it is, for now we cannot, so it's still cumbersome. --- src/libnm-core-impl/nm-setting-6lowpan.c | 15 +--- src/libnm-core-impl/nm-setting-private.h | 99 ++++++++++++++---------- src/libnm-core-impl/nm-setting.c | 47 ++++++++++- 3 files changed, 104 insertions(+), 57 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-6lowpan.c b/src/libnm-core-impl/nm-setting-6lowpan.c index c7f1aca66e..fe7bf1c566 100644 --- a/src/libnm-core-impl/nm-setting-6lowpan.c +++ b/src/libnm-core-impl/nm-setting-6lowpan.c @@ -147,17 +147,6 @@ nm_setting_6lowpan_new(void) return g_object_new(NM_TYPE_SETTING_6LOWPAN, NULL); } -static void -finalize(GObject *object) -{ - NMSetting6Lowpan * setting = NM_SETTING_6LOWPAN(object); - NMSetting6LowpanPrivate *priv = NM_SETTING_6LOWPAN_GET_PRIVATE(setting); - - g_free(priv->parent); - - G_OBJECT_CLASS(nm_setting_6lowpan_parent_class)->finalize(object); -} - static void nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) { @@ -169,9 +158,9 @@ nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) object_class->get_property = _nm_setting_property_get_property_direct; object_class->set_property = _nm_setting_property_set_property_direct; - object_class->finalize = finalize; - setting_class->verify = verify; + setting_class->verify = verify; + setting_class->finalize_direct = TRUE; /** * NMSetting6Lowpan:parent: diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index e35543e170..047dccb283 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -115,7 +115,20 @@ struct _NMSettingClass { guint /* NMSettingParseFlags */ parse_flags, GError ** error); - gpointer padding[1]; + union { + gpointer padding[1]; + struct { + /* Whether NMSetting.finalize() calls _nm_setting_property_finalize_direct(). Subclasses + * need to be aware of that, and currently this is opt-in. + * + * The only reason because subclasses need to be aware of this, is that they + * otherwise might clear the properties already and leave dangling pointers. + * + * Eventually all setting classes should stop touching their direct properties + * during finalize, and always let NMSetting.finalize() handle them. */ + bool finalize_direct : 1; + }; + }; const struct _NMMetaSettingInfo *setting_info; }; @@ -483,47 +496,47 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ -#define _nm_setting_property_define_direct_string_full(properties_override, \ - obj_properties, \ - prop_name, \ - prop_id, \ - param_flags, \ - property_type, \ - private_struct_type, \ - private_struct_field, \ - ...) \ - G_STMT_START \ - { \ - GParamSpec * _param_spec; \ - const NMSettInfoPropertType *_property_type = (property_type); \ - \ - 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))); \ - \ - nm_assert(_property_type); \ - nm_assert(g_variant_type_equal(_property_type->dbus_type, "s")); \ - nm_assert(_property_type->direct_type == NM_VALUE_TYPE_STRING); \ - nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); \ - \ - _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, \ - _property_type, \ - .direct_offset = \ - NM_STRUCT_OFFSET_ENSURE_TYPE(char *, private_struct_type, private_struct_field), \ - __VA_ARGS__); \ - } \ +#define _nm_setting_property_define_direct_string_full(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + param_flags, \ + property_type, \ + private_struct_type, \ + private_struct_field, \ + ... /* extra NMSettInfoProperty fields */) \ + G_STMT_START \ + { \ + GParamSpec * _param_spec; \ + const NMSettInfoPropertType *_property_type = (property_type); \ + \ + 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))); \ + \ + nm_assert(_property_type); \ + nm_assert(g_variant_type_equal(_property_type->dbus_type, "s")); \ + nm_assert(_property_type->direct_type == NM_VALUE_TYPE_STRING); \ + nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); \ + \ + _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, \ + _property_type, \ + .direct_offset = \ + NM_STRUCT_OFFSET_ENSURE_TYPE(char *, private_struct_type, private_struct_field), \ + __VA_ARGS__); \ + } \ G_STMT_END #define _nm_setting_property_define_direct_string(properties_override, \ @@ -533,7 +546,7 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p param_flags, \ private_struct_type, \ private_struct_field, \ - ...) \ + ... /* extra NMSettInfoProperty fields */) \ _nm_setting_property_define_direct_string_full((properties_override), \ (obj_properties), \ prop_name, \ diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index faad3bcae6..5ae7296263 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -730,6 +730,46 @@ out_fail: /*****************************************************************************/ +static void +_finalize_direct(NMSetting *setting) +{ + const NMSettInfoSetting *sett_info; + guint i; + + sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); + nm_assert(sett_info); + + for (i = 0; i < sett_info->property_infos_len; i++) { + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; + + /* We only: + * + * - reset fields where there is something to free. E.g. boolean + * properties are not reset to their default. + * - clear/free properties, without emitting g_object_notify_by_pspec(), + * because this is called only during finalization. */ + + switch (property_info->property_type->direct_type) { + case NM_VALUE_TYPE_NONE: + case NM_VALUE_TYPE_BOOL: + break; + case NM_VALUE_TYPE_STRING: + { + char **p_val = + _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + + nm_clear_g_free(p_val); + break; + } + default: + nm_assert_not_reached(); + break; + } + } +} + +/*****************************************************************************/ + GVariant * _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info, guint property_idx, @@ -3052,7 +3092,9 @@ nm_setting_init(NMSetting *setting) static void finalize(GObject *object) { - NMSettingPrivate *priv = NM_SETTING_GET_PRIVATE(object); + NMSetting * self = NM_SETTING(object); + NMSettingPrivate *priv = NM_SETTING_GET_PRIVATE(self); + NMSettingClass * klass = NM_SETTING_GET_CLASS(self); if (priv->gendata) { g_free(priv->gendata->names); @@ -3062,6 +3104,9 @@ finalize(GObject *object) } G_OBJECT_CLASS(nm_setting_parent_class)->finalize(object); + + if (klass->finalize_direct) + _finalize_direct(self); } static void From 3c801ec4f35eb3a2f2ba42413072ba555f5a25fd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 07:57:41 +0200 Subject: [PATCH 13/16] libnm: add direct_offset for uint32 properties And as example, implement NMSettingVrf.table this way. This also makes all properties of NMSettingVrf implemened as "direct" properties, and we can drop the explicit getter/setters. --- src/libnm-core-impl/nm-setting-private.h | 46 +++++++++++++++++ src/libnm-core-impl/nm-setting-vrf.c | 64 +++++++----------------- src/libnm-core-impl/nm-setting.c | 40 +++++++++++++++ src/libnm-core-impl/tests/test-setting.c | 18 +++++++ 4 files changed, 122 insertions(+), 46 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 047dccb283..48f225b6d4 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -300,6 +300,7 @@ 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_uint32; extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_string; NMSettingVerifyResult @@ -496,6 +497,51 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ +#define _nm_setting_property_define_direct_uint32(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) <= (guint64) G_MAXUINT32); \ + G_STATIC_ASSERT((max_value) <= (guint64) G_MAXUINT32); \ + G_STATIC_ASSERT((default_value) <= (guint64) G_MAXUINT32); \ + \ + _param_spec = \ + g_param_spec_uint("" 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_uint32, \ + .direct_offset = \ + NM_STRUCT_OFFSET_ENSURE_TYPE(guint32, 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, \ diff --git a/src/libnm-core-impl/nm-setting-vrf.c b/src/libnm-core-impl/nm-setting-vrf.c index 0eac3cf6d6..e2707053ef 100644 --- a/src/libnm-core-impl/nm-setting-vrf.c +++ b/src/libnm-core-impl/nm-setting-vrf.c @@ -80,38 +80,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingVrf *self = NM_SETTING_VRF(object); - - switch (prop_id) { - case PROP_TABLE: - g_value_set_uint(value, self->table); - 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) -{ - NMSettingVrf *self = NM_SETTING_VRF(object); - - switch (prop_id) { - case PROP_TABLE: - self->table = g_value_get_uint(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_vrf_init(NMSettingVrf *setting) {} @@ -134,13 +102,15 @@ nm_setting_vrf_new(void) static void nm_setting_vrf_class_init(NMSettingVrfClass *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->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; /** * NMSettingVrf:table: @@ -149,16 +119,18 @@ nm_setting_vrf_class_init(NMSettingVrfClass *klass) * * Since: 1.24 **/ - obj_properties[PROP_TABLE] = - g_param_spec_uint(NM_SETTING_VRF_TABLE, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VRF_TABLE, + PROP_TABLE, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVrf, + table); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VRF, NULL, NULL, 0); + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VRF, NULL, properties_override, 0); } diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 5ae7296263..a473dbc7ae 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -651,6 +651,14 @@ _nm_setting_property_get_property_direct(GObject * object, g_value_set_boolean(value, *p_val); return; } + case NM_VALUE_TYPE_UINT32: + { + const guint32 *p_val = + _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + + g_value_set_uint(value, *p_val); + return; + } case NM_VALUE_TYPE_STRING: { const char *const *p_val = @@ -703,6 +711,21 @@ _nm_setting_property_set_property_direct(GObject * object, *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); + guint v; + + v = g_value_get_uint(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 uint32. */ + nm_assert(*p_val == v); + goto out_notify; + } case NM_VALUE_TYPE_STRING: { char **p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); @@ -752,6 +775,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_UINT32: break; case NM_VALUE_TYPE_STRING: { @@ -791,6 +815,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_UINT32: + { + guint32 val; + + val = *( + (guint32 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + if (!property_info->to_dbus_data.including_default + && val == NM_G_PARAM_SPEC_GET_DEFAULT_UINT(property_info->param_spec)) + return NULL; + return g_variant_new_uint32(val); + } case NM_VALUE_TYPE_STRING: { const char *val; @@ -2648,6 +2683,11 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = .direct_type = NM_VALUE_TYPE_BOOL, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); +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, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); + 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, diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 944b3cc5b5..b0511ef9a4 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4450,6 +4450,24 @@ test_setting_metadata(void) == _nm_setting_property_to_dbus_fcn_direct); 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_UINT32) { + const GParamSpecUInt *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_uint32); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "u")); + 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_UINT); + + pspec = NM_G_PARAM_SPEC_CAST_UINT(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->maximum, <=, (guint64) G_MAXUINT32); + 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")); From 56241f328feb725c1300314cd0ee85d2c53fd3f2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 08:52:02 +0200 Subject: [PATCH 14/16] libnm: always initialize default values for "direct" properties We encode the default value "direct" properties in the GParamSpec. But we also avoid CONSTRUCT properties, because they have an overhead and they are generally odd for the settings. So up to now, it was cumbersome to explicitly set the default value, but it was also error prone. Avoid that by always initializing the default value for our "direct" properties. --- src/libnm-core-impl/nm-setting-bridge.c | 6 -- src/libnm-core-impl/nm-setting-connection.c | 1 - src/libnm-core-impl/nm-setting-ip-config.c | 16 ++--- src/libnm-core-impl/nm-setting-ip-tunnel.c | 6 +- src/libnm-core-impl/nm-setting-macsec.c | 2 - src/libnm-core-impl/nm-setting-macvlan.c | 6 +- src/libnm-core-impl/nm-setting-ppp.c | 6 +- src/libnm-core-impl/nm-setting-vxlan.c | 1 - src/libnm-core-impl/nm-setting-wireguard.c | 1 - src/libnm-core-impl/nm-setting.c | 80 +++++++++++++++++++++ src/libnm-core-impl/tests/test-setting.c | 3 + 11 files changed, 93 insertions(+), 35 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index 2624a4e3e3..4567a28f0a 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -1564,19 +1564,13 @@ nm_setting_bridge_init(NMSettingBridge *setting) priv->multicast_last_member_interval = NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_DEF; priv->multicast_membership_interval = NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_DEF; priv->multicast_hash_max = NM_BRIDGE_MULTICAST_HASH_MAX_DEF; - priv->multicast_snooping = NM_BRIDGE_MULTICAST_SNOOPING_DEF; priv->priority = NM_BRIDGE_PRIORITY_DEF; - priv->stp = NM_BRIDGE_STP_DEF; priv->vlan_default_pvid = NM_BRIDGE_VLAN_DEFAULT_PVID_DEF; priv->multicast_query_interval = NM_BRIDGE_MULTICAST_QUERY_INTERVAL_DEF; priv->multicast_query_response_interval = NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_DEF; priv->multicast_querier_interval = NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_DEF; priv->multicast_startup_query_count = NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_DEF; priv->multicast_startup_query_interval = NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_DEF; - - nm_assert(priv->multicast_querier == NM_BRIDGE_MULTICAST_QUERIER_DEF); - nm_assert(priv->multicast_query_use_ifaddr == NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF); - nm_assert(priv->vlan_stats_enabled == NM_BRIDGE_VLAN_STATS_ENABLED_DEF); } /** diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index a044f1ae21..869093f156 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1801,7 +1801,6 @@ nm_setting_connection_init(NMSettingConnection *setting) NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE(setting); priv->auth_retries = -1; - priv->autoconnect = TRUE; priv->autoconnect_priority = NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT; priv->autoconnect_retries = -1; priv->autoconnect_slaves = NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT; diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index a9214af4e4..f1e0d7adce 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -6063,15 +6063,13 @@ _nm_setting_ip_config_private_init(gpointer self, NMSettingIPConfigPrivate *priv { nm_assert(NM_IS_SETTING_IP_CONFIG(self)); - priv->dns = g_ptr_array_new_with_free_func(g_free); - priv->dns_search = g_ptr_array_new_with_free_func(g_free); - priv->addresses = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); - priv->routes = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_route_unref); - priv->route_metric = -1; - priv->dhcp_send_hostname = TRUE; - priv->may_fail = TRUE; - priv->dad_timeout = -1; - priv->required_timeout = -1; + priv->dns = g_ptr_array_new_with_free_func(g_free); + priv->dns_search = g_ptr_array_new_with_free_func(g_free); + priv->addresses = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); + priv->routes = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_route_unref); + priv->route_metric = -1; + priv->dad_timeout = -1; + priv->required_timeout = -1; } static void diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index 66a2cb551b..f75ca1d5b7 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -615,11 +615,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static void nm_setting_ip_tunnel_init(NMSettingIPTunnel *self) -{ - NMSettingIPTunnelPrivate *priv = NM_SETTING_IP_TUNNEL_GET_PRIVATE(self); - - priv->path_mtu_discovery = TRUE; -} +{} /** * nm_setting_ip_tunnel_new: diff --git a/src/libnm-core-impl/nm-setting-macsec.c b/src/libnm-core-impl/nm-setting-macsec.c index 1802ba6d21..1a9e9bd8ab 100644 --- a/src/libnm-core-impl/nm-setting-macsec.c +++ b/src/libnm-core-impl/nm-setting-macsec.c @@ -492,9 +492,7 @@ nm_setting_macsec_init(NMSettingMacsec *self) NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(self); nm_assert(priv->mode == NM_SETTING_MACSEC_MODE_PSK); - priv->encrypt = TRUE; priv->port = 1; - priv->send_sci = TRUE; priv->validation = NM_SETTING_MACSEC_VALIDATION_STRICT; } diff --git a/src/libnm-core-impl/nm-setting-macvlan.c b/src/libnm-core-impl/nm-setting-macvlan.c index 255ec7d595..32b30c2cfa 100644 --- a/src/libnm-core-impl/nm-setting-macvlan.c +++ b/src/libnm-core-impl/nm-setting-macvlan.c @@ -234,11 +234,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static void nm_setting_macvlan_init(NMSettingMacvlan *self) -{ - NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE(self); - - priv->promiscuous = TRUE; -} +{} /** * nm_setting_macvlan_new: diff --git a/src/libnm-core-impl/nm-setting-ppp.c b/src/libnm-core-impl/nm-setting-ppp.c index 7e62ec6569..74bd2572d2 100644 --- a/src/libnm-core-impl/nm-setting-ppp.c +++ b/src/libnm-core-impl/nm-setting-ppp.c @@ -512,11 +512,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static void nm_setting_ppp_init(NMSettingPpp *self) -{ - NMSettingPppPrivate *priv = NM_SETTING_PPP_GET_PRIVATE(self); - - priv->noauth = TRUE; -} +{} /** * nm_setting_ppp_new: diff --git a/src/libnm-core-impl/nm-setting-vxlan.c b/src/libnm-core-impl/nm-setting-vxlan.c index e625034338..c2d23a7fb6 100644 --- a/src/libnm-core-impl/nm-setting-vxlan.c +++ b/src/libnm-core-impl/nm-setting-vxlan.c @@ -536,7 +536,6 @@ nm_setting_vxlan_init(NMSettingVxlan *self) priv->destination_port = DST_PORT_DEFAULT; priv->ageing = 300; - priv->learning = TRUE; } /** diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index d6fa853bed..a270881edf 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -2372,7 +2372,6 @@ nm_setting_wireguard_init(NMSettingWireGuard *setting) priv->peers_arr = g_ptr_array_new(); priv->peers_hash = g_hash_table_new(nm_pstr_hash, nm_pstr_equal); - priv->peer_routes = TRUE; priv->ip4_auto_default_route = NM_TERNARY_DEFAULT; priv->ip6_auto_default_route = NM_TERNARY_DEFAULT; } diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index a473dbc7ae..f81367097a 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -753,6 +753,59 @@ out_fail: /*****************************************************************************/ +static void +_init_direct(NMSetting *setting) +{ + const NMSettInfoSetting *sett_info; + guint i; + + sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); + nm_assert(sett_info); + + for (i = 0; i < sett_info->property_infos_len; i++) { + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; + + /* We don't emit any g_object_notify_by_pspec(), because this is + * only supposed to be called during initialization of the GObject + * instance. */ + + switch (property_info->property_type->direct_type) { + case NM_VALUE_TYPE_NONE: + break; + case NM_VALUE_TYPE_BOOL: + { + bool *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + gboolean def_val; + + def_val = NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec); + nm_assert(*p_val == FALSE); + *p_val = def_val; + break; + } + case NM_VALUE_TYPE_UINT32: + { + guint32 *p_val = + _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + guint def_val; + + def_val = NM_G_PARAM_SPEC_GET_DEFAULT_UINT(property_info->param_spec); + nm_assert(*p_val == 0); + *p_val = def_val; + break; + } + case NM_VALUE_TYPE_STRING: + nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); + nm_assert(!( + *((const char *const *) + _nm_setting_get_private(setting, sett_info, property_info->direct_offset)))); + break; + default: + nm_assert_not_reached(); + break; + } + } +} + static void _finalize_direct(NMSetting *setting) { @@ -3129,6 +3182,32 @@ static void nm_setting_init(NMSetting *setting) {} +static void +constructed(GObject *object) +{ + NMSetting * self = NM_SETTING(object); + NMSettingClass *klass = NM_SETTING_GET_CLASS(self); + + /* we don't support that NMSetting subclasses override constructed. + * They all must have no G_PARAM_CONSTRUCT/G_PARAM_CONSTRUCT_ONLY + * properties, otherwise the automatism of _init_direct() needs + * careful adjustment. */ + nm_assert(G_OBJECT_CLASS(klass)->constructed == constructed); + + /* we always initialize the defaults of the (direct) properties. Note that: + * + * - we don't use CONSTRUCT properties, because they have an overhead during + * each object creation. Via _init_direct() we can do it more efficiently. + * + * - we always call this, because we want to get all default values right. + * We even call this for NMSetting subclasses that (historically) are not + * yet aware of this happening. + */ + _init_direct(self); + + G_OBJECT_CLASS(nm_setting_parent_class)->constructed(object); +} + static void finalize(GObject *object) { @@ -3156,6 +3235,7 @@ nm_setting_class_init(NMSettingClass *setting_class) g_type_class_add_private(setting_class, sizeof(NMSettingPrivate)); + object_class->constructed = constructed; object_class->get_property = get_property; object_class->finalize = finalize; diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index b0511ef9a4..51077e2360 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4566,6 +4566,9 @@ check_done:; if (NM_FLAGS_HAS(sip->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) g_assert(sip->property_type->to_dbus_fcn); + + g_assert(!NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_CONSTRUCT)); + g_assert(!NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_CONSTRUCT_ONLY)); } } From 3a7a88fe61198a365da7b726ece6804f84a51bbd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 09:22:11 +0200 Subject: [PATCH 15/16] libnm: implement NMSettingPpp with all direct properties --- src/libnm-core-impl/nm-setting-ppp.c | 232 +++++++-------------------- 1 file changed, 56 insertions(+), 176 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ppp.c b/src/libnm-core-impl/nm-setting-ppp.c index 74bd2572d2..83708515ce 100644 --- a/src/libnm-core-impl/nm-setting-ppp.c +++ b/src/libnm-core-impl/nm-setting-ppp.c @@ -337,6 +337,8 @@ nm_setting_ppp_get_lcp_echo_interval(NMSettingPpp *setting) return NM_SETTING_PPP_GET_PRIVATE(setting)->lcp_echo_interval; } +/*****************************************************************************/ + static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { @@ -376,140 +378,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingPpp *setting = NM_SETTING_PPP(object); - - switch (prop_id) { - case PROP_NOAUTH: - g_value_set_boolean(value, nm_setting_ppp_get_noauth(setting)); - break; - case PROP_REFUSE_EAP: - g_value_set_boolean(value, nm_setting_ppp_get_refuse_eap(setting)); - break; - case PROP_REFUSE_PAP: - g_value_set_boolean(value, nm_setting_ppp_get_refuse_pap(setting)); - break; - case PROP_REFUSE_CHAP: - g_value_set_boolean(value, nm_setting_ppp_get_refuse_chap(setting)); - break; - case PROP_REFUSE_MSCHAP: - g_value_set_boolean(value, nm_setting_ppp_get_refuse_mschap(setting)); - break; - case PROP_REFUSE_MSCHAPV2: - g_value_set_boolean(value, nm_setting_ppp_get_refuse_mschapv2(setting)); - break; - case PROP_NOBSDCOMP: - g_value_set_boolean(value, nm_setting_ppp_get_nobsdcomp(setting)); - break; - case PROP_NODEFLATE: - g_value_set_boolean(value, nm_setting_ppp_get_nodeflate(setting)); - break; - case PROP_NO_VJ_COMP: - g_value_set_boolean(value, nm_setting_ppp_get_no_vj_comp(setting)); - break; - case PROP_REQUIRE_MPPE: - g_value_set_boolean(value, nm_setting_ppp_get_require_mppe(setting)); - break; - case PROP_REQUIRE_MPPE_128: - g_value_set_boolean(value, nm_setting_ppp_get_require_mppe_128(setting)); - break; - case PROP_MPPE_STATEFUL: - g_value_set_boolean(value, nm_setting_ppp_get_mppe_stateful(setting)); - break; - case PROP_CRTSCTS: - g_value_set_boolean(value, nm_setting_ppp_get_crtscts(setting)); - break; - case PROP_BAUD: - g_value_set_uint(value, nm_setting_ppp_get_baud(setting)); - break; - case PROP_MRU: - g_value_set_uint(value, nm_setting_ppp_get_mru(setting)); - break; - case PROP_MTU: - g_value_set_uint(value, nm_setting_ppp_get_mtu(setting)); - break; - case PROP_LCP_ECHO_FAILURE: - g_value_set_uint(value, nm_setting_ppp_get_lcp_echo_failure(setting)); - break; - case PROP_LCP_ECHO_INTERVAL: - g_value_set_uint(value, nm_setting_ppp_get_lcp_echo_interval(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) -{ - NMSettingPppPrivate *priv = NM_SETTING_PPP_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_NOAUTH: - priv->noauth = g_value_get_boolean(value); - break; - case PROP_REFUSE_EAP: - priv->refuse_eap = g_value_get_boolean(value); - break; - case PROP_REFUSE_PAP: - priv->refuse_pap = g_value_get_boolean(value); - break; - case PROP_REFUSE_CHAP: - priv->refuse_chap = g_value_get_boolean(value); - break; - case PROP_REFUSE_MSCHAP: - priv->refuse_mschap = g_value_get_boolean(value); - break; - case PROP_REFUSE_MSCHAPV2: - priv->refuse_mschapv2 = g_value_get_boolean(value); - break; - case PROP_NOBSDCOMP: - priv->nobsdcomp = g_value_get_boolean(value); - break; - case PROP_NODEFLATE: - priv->nodeflate = g_value_get_boolean(value); - break; - case PROP_NO_VJ_COMP: - priv->no_vj_comp = g_value_get_boolean(value); - break; - case PROP_REQUIRE_MPPE: - priv->require_mppe = g_value_get_boolean(value); - break; - case PROP_REQUIRE_MPPE_128: - priv->require_mppe_128 = g_value_get_boolean(value); - break; - case PROP_MPPE_STATEFUL: - priv->mppe_stateful = g_value_get_boolean(value); - break; - case PROP_CRTSCTS: - priv->crtscts = g_value_get_boolean(value); - break; - case PROP_BAUD: - priv->baud = g_value_get_uint(value); - break; - case PROP_MRU: - priv->mru = g_value_get_uint(value); - break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; - case PROP_LCP_ECHO_FAILURE: - priv->lcp_echo_failure = g_value_get_uint(value); - break; - case PROP_LCP_ECHO_INTERVAL: - priv->lcp_echo_interval = g_value_get_uint(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ppp_init(NMSettingPpp *self) {} @@ -536,10 +404,11 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) g_type_class_add_private(klass, sizeof(NMSettingPppPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; + 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; /** * NMSettingPpp:noauth: @@ -740,14 +609,16 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * baudrate. This value should normally be left as 0 to automatically * choose the speed. **/ - obj_properties[PROP_BAUD] = g_param_spec_uint(NM_SETTING_PPP_BAUD, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_PPP_BAUD, + PROP_BAUD, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + baud); /** * NMSettingPpp:mru: @@ -756,13 +627,16 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * larger than the specified size. If non-zero, the MRU should be between * 128 and 16384. */ - obj_properties[PROP_MRU] = g_param_spec_uint(NM_SETTING_PPP_MRU, - "", - "", - 0, - 16384, - 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_PPP_MRU, + PROP_MRU, + 0, + 16384, + 0, + NM_SETTING_PARAM_NONE, + NMSettingPppPrivate, + mru); /** * NMSettingPpp:mtu: @@ -770,14 +644,16 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * If non-zero, instruct pppd to send packets no larger than the specified * size. **/ - obj_properties[PROP_MTU] = g_param_spec_uint(NM_SETTING_PPP_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_PPP_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + mtu); /** * NMSettingPpp:lcp-echo-failure: @@ -787,14 +663,16 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * peer. The "lcp-echo-interval" property must also be set to a non-zero * value if this property is used. **/ - obj_properties[PROP_LCP_ECHO_FAILURE] = g_param_spec_uint( - NM_SETTING_PPP_LCP_ECHO_FAILURE, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_PPP_LCP_ECHO_FAILURE, + PROP_LCP_ECHO_FAILURE, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + lcp_echo_failure); /** * NMSettingPpp:lcp-echo-interval: @@ -804,14 +682,16 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * peers will respond to echo requests and some will not, and it is not * possible to autodetect this. **/ - obj_properties[PROP_LCP_ECHO_INTERVAL] = g_param_spec_uint( - NM_SETTING_PPP_LCP_ECHO_INTERVAL, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_PPP_LCP_ECHO_INTERVAL, + PROP_LCP_ECHO_INTERVAL, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingPppPrivate, + lcp_echo_interval); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); From 4c9fa15e39b468d33eeab53c0c4635bca1f993dd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 11:44:46 +0200 Subject: [PATCH 16/16] libnm: make NMSettInfoSetting.property_infos_len uint16 Uint16 is plenty. --- src/libnm-core-impl/nm-keyfile.c | 4 +- src/libnm-core-impl/nm-setting.c | 96 ++++++++++++------------ src/libnm-core-intern/nm-core-internal.h | 4 +- 3 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c index c6c4a2eb57..a58c76db6a 100644 --- a/src/libnm-core-impl/nm-keyfile.c +++ b/src/libnm-core-impl/nm-keyfile.c @@ -3351,7 +3351,7 @@ _read_setting(KeyfileReaderInfo *info) gs_unref_object NMSetting *setting = NULL; const char * alias; GType type; - guint i; + guint16 i; alias = nm_keyfile_plugin_get_setting_name_for_alias(info->group); if (!alias) @@ -4088,7 +4088,7 @@ nm_keyfile_write(NMConnection * connection, KeyfileWriterInfo info; NMSetting ** settings; int i; - guint j; + guint16 j; g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL); g_return_val_if_fail(!error || !*error, NULL); diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index f81367097a..f6ef8c74ba 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -227,11 +227,11 @@ _property_infos_sort_cmp_setting_connection(gconstpointer p_a, static const NMSettInfoProperty *const * _property_infos_sort(const NMSettInfoProperty *property_infos, - guint property_infos_len, + guint16 property_infos_len, NMSettingClass * setting_class) { const NMSettInfoProperty **arr; - guint i; + guint16 i; #if NM_MORE_ASSERTS > 5 /* assert that the property names are all unique and sorted. */ @@ -286,6 +286,7 @@ _nm_setting_class_commit(NMSettingClass * setting_class, NMSettInfoPropertLookupByParamSpec *lookup_by_iter; guint override_len; guint i; + guint16 j; nm_assert(NM_IS_SETTING_CLASS(setting_class)); nm_assert(!setting_class->setting_info); @@ -325,18 +326,18 @@ _nm_setting_class_commit(NMSettingClass * setting_class, for (i = 0; i < override_len; i++) { const NMSettInfoProperty *p = &g_array_index(properties_override, NMSettInfoProperty, i); gboolean found = FALSE; - guint j; + guint k; nm_assert( !_nm_sett_info_property_find_in_array((NMSettInfoProperty *) properties_override->data, i, p->name)); - for (j = 0; j < n_property_specs; j++) { - if (!nm_streq(property_specs[j]->name, p->name)) + for (k = 0; k < n_property_specs; k++) { + if (!nm_streq(property_specs[k]->name, p->name)) continue; nm_assert(!found); found = TRUE; - nm_assert(p->param_spec == property_specs[j]); + nm_assert(p->param_spec == property_specs[k]); } nm_assert(found == (p->param_spec != NULL)); } @@ -427,6 +428,7 @@ has_property_type: if (detail) sett_info->detail = *detail; nm_assert(properties_override->len > 0); + nm_assert(properties_override->len < G_MAXUINT16); sett_info->property_infos_len = properties_override->len; sett_info->property_infos = nm_memdup(properties_override->data, sizeof(NMSettInfoProperty) * properties_override->len); @@ -437,8 +439,8 @@ has_property_type: nm_assert(sett_info->property_infos_len < G_MAXUINT16); sett_info->property_lookup_by_param_spec_len = 0; - for (i = 0; i < sett_info->property_infos_len; i++) { - if (sett_info->property_infos[i].param_spec) { + for (j = 0; j < sett_info->property_infos_len; j++) { + if (sett_info->property_infos[j].param_spec) { sett_info->property_lookup_by_param_spec_len++; } } @@ -446,8 +448,8 @@ has_property_type: g_new(NMSettInfoPropertLookupByParamSpec, sett_info->property_lookup_by_param_spec_len); lookup_by_iter = (NMSettInfoPropertLookupByParamSpec *) sett_info->property_lookup_by_param_spec; - for (i = 0; i < sett_info->property_infos_len; i++) { - const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; + for (j = 0; j < sett_info->property_infos_len; j++) { + const NMSettInfoProperty *property_info = &sett_info->property_infos[j]; if (property_info->param_spec) { *(lookup_by_iter++) = (NMSettInfoPropertLookupByParamSpec){ @@ -757,7 +759,7 @@ static void _init_direct(NMSetting *setting) { const NMSettInfoSetting *sett_info; - guint i; + guint16 i; sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); nm_assert(sett_info); @@ -810,7 +812,7 @@ static void _finalize_direct(NMSetting *setting) { const NMSettInfoSetting *sett_info; - guint i; + guint16 i; sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); nm_assert(sett_info); @@ -1079,7 +1081,9 @@ _nm_setting_to_dbus(NMSetting * setting, NMSettingPrivate * priv; GVariantBuilder builder; const NMSettInfoSetting *sett_info; - guint n_properties, i; + guint n_properties; + guint i; + guint16 j; const char *const * gendata_keys; g_return_val_if_fail(NM_IS_SETTING(setting), NULL); @@ -1097,12 +1101,12 @@ _nm_setting_to_dbus(NMSetting * setting, } sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); - for (i = 0; i < sett_info->property_infos_len; i++) { + for (j = 0; j < sett_info->property_infos_len; j++) { gs_unref_variant GVariant *dbus_value = NULL; - dbus_value = property_to_dbus(sett_info, i, connection, setting, flags, options, FALSE); + dbus_value = property_to_dbus(sett_info, j, connection, setting, flags, options, FALSE); if (dbus_value) { - g_variant_builder_add(&builder, "{sv}", sett_info->property_infos[i].name, dbus_value); + g_variant_builder_add(&builder, "{sv}", sett_info->property_infos[j].name, dbus_value); } } @@ -1218,8 +1222,7 @@ init_from_dbus(NMSetting * setting, GError ** error) { const NMSettInfoSetting *sett_info; - - guint i; + guint16 i; nm_assert(NM_IS_SETTING(setting)); nm_assert(!NM_FLAGS_ANY(parse_flags, ~NM_SETTING_PARSE_FLAGS_ALL)); @@ -1449,6 +1452,9 @@ _gobject_copy_property(GObject *src, GObject *dst, const char *property_name, GT static void duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NMSetting *dst) { + gboolean frozen = FALSE; + guint16 i; + if (sett_info->detail.gendata_info) { GenData *gendata = _gendata_hash(src, FALSE); @@ -1467,33 +1473,28 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM } } - if (sett_info->property_infos_len > 0) { - gboolean frozen = FALSE; - guint i; + for (i = 0; i < sett_info->property_infos_len; i++) { + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; - for (i = 0; i < sett_info->property_infos_len; i++) { - const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; - - if (property_info->param_spec) { - if ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) - != G_PARAM_WRITABLE) - continue; - - if (!frozen) { - g_object_freeze_notify(G_OBJECT(dst)); - frozen = TRUE; - } - _gobject_copy_property(G_OBJECT(src), - G_OBJECT(dst), - property_info->param_spec->name, - G_PARAM_SPEC_VALUE_TYPE(property_info->param_spec)); + if (property_info->param_spec) { + if ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) + != G_PARAM_WRITABLE) continue; - } - } - if (frozen) - g_object_thaw_notify(G_OBJECT(dst)); + if (!frozen) { + g_object_freeze_notify(G_OBJECT(dst)); + frozen = TRUE; + } + _gobject_copy_property(G_OBJECT(src), + G_OBJECT(dst), + property_info->param_spec->name, + G_PARAM_SPEC_VALUE_TYPE(property_info->param_spec)); + continue; + } } + + if (frozen) + g_object_thaw_notify(G_OBJECT(dst)); } /** @@ -1823,7 +1824,7 @@ _nm_setting_compare(NMConnection * con_a, NMSettingCompareFlags flags) { const NMSettInfoSetting *sett_info; - guint i; + guint16 i; g_return_val_if_fail(NM_IS_SETTING(a), FALSE); g_return_val_if_fail(NM_IS_SETTING(b), FALSE); @@ -1913,7 +1914,6 @@ _nm_setting_diff(NMConnection * con_a, GHashTable ** results) { const NMSettInfoSetting *sett_info; - guint i; NMSettingDiffResult a_result = NM_SETTING_DIFF_RESULT_IN_A; NMSettingDiffResult b_result = NM_SETTING_DIFF_RESULT_IN_B; NMSettingDiffResult a_result_default = NM_SETTING_DIFF_RESULT_IN_A_DEFAULT; @@ -1921,6 +1921,7 @@ _nm_setting_diff(NMConnection * con_a, gboolean results_created = FALSE; gboolean compared_any = FALSE; gboolean diff_found = FALSE; + guint16 i; g_return_val_if_fail(results != NULL, FALSE); g_return_val_if_fail(NM_IS_SETTING(a), FALSE); @@ -2158,6 +2159,7 @@ nm_setting_enumerate_values(NMSetting *setting, NMSettingValueIterFn func, gpoin { const NMSettInfoSetting *sett_info; guint i; + guint16 j; g_return_if_fail(NM_IS_SETTING(setting)); g_return_if_fail(func != NULL); @@ -2196,9 +2198,9 @@ nm_setting_enumerate_values(NMSetting *setting, NMSettingValueIterFn func, gpoin return; } - for (i = 0; i < sett_info->property_infos_len; i++) { + for (j = 0; j < sett_info->property_infos_len; j++) { NM_SETTING_GET_CLASS(setting)->enumerate_values( - _nm_sett_info_property_info_get_sorted(sett_info, i), + _nm_sett_info_property_info_get_sorted(sett_info, j), setting, func, user_data); @@ -2210,7 +2212,7 @@ aggregate(NMSetting *setting, int type_i, gpointer arg) { NMConnectionAggregateType type = type_i; const NMSettInfoSetting * sett_info; - guint i; + guint16 i; nm_assert(NM_IN_SET(type, NM_CONNECTION_AGGREGATE_ANY_SECRETS, @@ -2340,7 +2342,7 @@ _nm_setting_clear_secrets(NMSetting * setting, { const NMSettInfoSetting *sett_info; gboolean changed = FALSE; - guint i; + guint16 i; gboolean (*my_clear_secrets)(const struct _NMSettInfoSetting *sett_info, guint property_idx, NMSetting * setting, diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 6735a9e5b4..98fc0509ae 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -795,7 +795,7 @@ struct _NMSettInfoSetting { const NMSettInfoPropertLookupByParamSpec *property_lookup_by_param_spec; - guint property_infos_len; + guint16 property_infos_len; guint16 property_lookup_by_param_spec_len; @@ -818,7 +818,7 @@ _nm_setting_get_private(NMSetting *self, const NMSettInfoSetting *sett_info, gui } static inline const NMSettInfoProperty * -_nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint idx) +_nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint16 idx) { nm_assert(sett_info); nm_assert(idx < sett_info->property_infos_len);