NetworkManager/src/libnm-core-impl
Thomas Haller bd8d49495b
libnm: embed private structure in NMSetting and avoid g_type_class_add_private()
Historically, the NMSetting types were in public headers. Theoretically,
that allowed users to subtype our classes. However in practice that was
impossible because they lacked required access to internal functions to
fully create an NMSetting class outside of libnm. And it also was not
useful, because you simply cannot extend libnm by subtyping a libnm
class. And supporting such a use case would be hard and limit what we can
do in libnm.

Having GObject structs in public headers also require that we don't
change it's layout. The ABI of those structs must not change, if anybody
out there was actually subclassing our GObjects.

In libnm 1.34 (commit e46d484fae ('libnm: hide NMSetting types from
public headers')) we moved the structs from headers to internal.
This would have caused a compiler error if anybody was using those
struct definitions. However, we still didn't change the ABI/layout so
that we didn't break users who relied on it (for whatever reason).

It doesn't seem there were any affected user. We waited long enough.
Change internal ABI.

No longer use g_type_class_add_private(). Instead, embed the private
structs directly (_NM_GET_PRIVATE()) or indirectly
(_NM_GET_PRIVATE_PTR()) in the object.

The main benefit is for debugging in the debugger, where we can now
easily find the private data. Previously that was so cumbersome to be
effectively impossible.

It's also the fastest possible way, since NM_SETTING_*_GET_PRIVATE()
literally resolves to "&self->_priv" (plus static asserts and
nm_assert() for type checking).

_NM_GET_PRIVATE() also propagates constness and requires that the
argument is a compatible pointer type (at compile time).

Note that g_type_class_add_private() is also deprecated in glib 2.58 and
replaced by G_ADD_PRIVATE(). For one, we still don't rely on 2.58. Also,
G_ADD_PRIVATE() is a worse solution as it supports a usecase that we
don't care for (public structs in headers). _NM_GET_PRIVATE() is still
faster, works with older glib and most importantly: is better for
debugging as you can find the private data from an object pointer.

For NMSettingIPConfig this is rather awkward, because all direct
properties require a common "klass->private_offset". This was however
the case before this change. Nothing new here. And if you ever touch
this and do something wrong, many unit tests will fail. It's almost
impossible to get wrong, albeit it can be confusing to understand.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1773
2023-10-31 11:29:37 +01:00
..
tests wifi: add 6ghz device capability flag 2023-10-03 08:28:58 +02:00
gen-metadata-nm-settings-libnm-core.c libnm/trivial: fix style 2022-11-10 14:41:38 +01:00
gen-metadata-nm-settings-libnm-core.xml.in libnm: add ethtool channels properties 2023-10-18 06:53:07 +00:00
meson.build all: add "link" setting 2023-03-02 16:51:16 +01:00
nm-connection-private.h format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-connection.c all: use nm_strv_contains() instead of nm_strv_find_first() for membership check 2023-10-23 10:09:07 +02:00
nm-default-libnm-core.h libnm: move nm-errors.h include away from nm-connection.h 2022-11-13 23:36:37 +01:00
nm-errors.c libnm: don't depend nm-crypto on "nm-error.h" 2022-03-29 11:56:03 +02:00
nm-keyfile-utils.c glib-aux: drop nm_str_buf_init() for NM_STR_BUF_INIT() 2022-05-09 19:18:30 +02:00
nm-keyfile.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-meta-setting-base-impl.c all: add "link" setting 2023-03-02 16:51:16 +01:00
nm-property-compare.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-property-compare.h clang-format: use "IndentPPDirectives:None" instead of "BeforeHash" 2021-07-09 08:49:06 +02:00
nm-setting-6lowpan.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-8021x.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-adsl.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-bluetooth.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-bond-port.c bonding: add support to prio property in bond ports 2023-05-03 10:44:06 +02:00
nm-setting-bond.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-bridge-port.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-bridge.c libnm: make ref counting of immutable types thread safe 2022-12-20 10:35:02 +01:00
nm-setting-cdma.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-connection.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-dcb.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-dummy.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-ethtool.c libnm: add ethtool channels properties 2023-10-18 06:53:07 +00:00
nm-setting-generic.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-gsm.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-hostname.c libnm: actually export a lot of routines that were supposed to be public 2022-11-08 11:43:00 +01:00
nm-setting-infiniband.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-ip-config.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-ip-tunnel.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-ip4-config.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-ip6-config.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-link.c all: add "link" setting 2023-03-02 16:51:16 +01:00
nm-setting-loopback.c loopback: reject setting "slave-type"/"master" for "loopback" profiles 2022-12-01 13:24:18 +01:00
nm-setting-macsec.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-macvlan.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-match.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-setting-olpc-mesh.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-ovs-bridge.c libnm: actually export a lot of routines that were supposed to be public 2022-11-08 11:43:00 +01:00
nm-setting-ovs-dpdk.c all: add support for ovs-dpdk n-rxq-desc and n-txq-desc 2023-01-17 08:45:04 +01:00
nm-setting-ovs-external-ids.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-setting-ovs-interface.c ovs: add ofport_request option to ovs interface 2022-09-02 08:46:36 +00:00
nm-setting-ovs-other-config.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-setting-ovs-patch.c libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-ovs-port.c libnm: accept "dot1q-tunnel" as vlan mode for ovs-ports 2022-11-25 14:15:41 +01:00
nm-setting-ppp.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-pppoe.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-private.h libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-proxy.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-serial.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-sriov.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-setting-tc-config.c libnm: add "description:" for overrides with doctext 2023-05-19 12:51:59 +02:00
nm-setting-team-port.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-team.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-tun.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-user.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-setting-veth.c libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-vlan.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-vpn.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-vrf.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-vxlan.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-wifi-p2p.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-wimax.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-wired.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-wireguard.c libnm: fix annotation for out_is_valid of nm_wireguard_peer_get_allowed_ip() 2023-04-16 16:49:37 +02:00
nm-setting-wireless-security.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-wireless.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting-wpan.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-setting.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-simple-connection.c libnm: embed private structure in NMSetting and avoid g_type_class_add_private() 2023-10-31 11:29:37 +01:00
nm-team-utils.c all: use nm_strv_contains() instead of nm_strv_find_first() for membership check 2023-10-23 10:09:07 +02:00
nm-team-utils.h format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-utils-private.h libnm: move verify() for OVS connection type to separate function 2023-01-11 12:45:35 +01:00
nm-utils.c doc: reorder gtkdoc annotations for consistency 2023-03-29 11:46:48 +02:00
nm-vpn-editor-plugin.c doc: replace all (allow-none) annotations by (optional) and/or (nullable) 2023-03-27 11:49:43 +02:00
nm-vpn-plugin-info.c all: use nm_strv_contains() instead of nm_strv_find_first() for membership check 2023-10-23 10:09:07 +02:00
README.md build: move "libnm-core/" to "src/" and split it 2021-02-18 19:46:51 +01:00

libnm-core-impl

NetworkManager provides a client library libnm. NetworkManager core does not (dynamically) link against all of libnm. Instead, it statically links against a part of it. That part is the static helper library libnm-core-impl.

libnm-core-impl implements (and provides) the API from libnm-core-public, which is part of the public API of libnm. In this form, libnm-core-impl is part of the implementation of libnm. It also implements (and provides) an internal API libnm-core-intern which can only be used by those who link statically against libnm-core-impl.

Only NetworkManager core and libnm are allowed to statically link with libnm-core-impl. Consequently, only those are allowed to include libnm-core-intern.

This directory should not be added to the include search path of other components as they are only allowed to include libnm-core-public and libnm-core-intern.