NetworkManager/src/platform
Thomas Haller 6d9030acb6 device/trivial: add comment about lifetime of "kind" in tc_commit()
In general, all fields of public NMPlatform* structs must be
plain/simple. Meaning: copying the struct must be possible without
caring about cloning/duplicating memory.
In other words, if there are fields which lifetime is limited,
then these fields cannot be inside the public part NMPlatform*.

That is why

  - "NMPlatformLink.kind", "NMPlatformQdisc.kind", "NMPlatformTfilter.kind"
    are set by platform code to an interned string (g_intern_string())
    that has a static lifetime.

  - the "ingress_qos_map" field is inside the ref-counted struct NMPObjectLnkVlan
    and not NMPlatformLnkVlan. This field requires managing the lifetime
    of the array and NMPlatformLnkVlan cannot provide that.

See also for example NMPClass.cmd_obj_copy() which can deep-copy an object.
But this is only suitable for fields in NMPObject*. The purpose of this
rule is that you always can safely copy a NMPlatform* struct without
worrying about the ownership and lifetime of the fields (the field's
lifetime is unlimited).

This rule and managing of resource lifetime is the main reason for the
NMPlatform*/NMPObject* split. NMPlatform* structs simply have no mechanism
for copying/releasing fields, that is why the NMPObject* counterpart exists
(which is ref-counted and has a copy and destructor function).

This is violated in tc_commit() for the "kind" strings. The lifetime
of these strings is tied to the setting instance.

We cannot intern the strings (because these are arbitrary strings
and interned strings are leaked indefinitely). We also cannot g_strdup()
the strings, because NMPlatform* is not supposed to own strings.

So, just add comments that warn about this ugliness.

The more correct solution would be to move the "kind" fields inside
NMPObjectQdisc and NMPObjectTfilter, but that is a lot of extra effort.

(cherry picked from commit f2ae994b23)
2019-05-15 14:07:08 +02:00
..
linux platform: import nl82154.h 2018-06-26 16:21:54 +02:00
tests platform/tests: workaround routing-rules test failure due to suppress_prefixlen on older kernels 2019-05-03 10:42:55 +02:00
wifi platform: assert for out-of-memory in netlink code 2019-05-15 14:07:08 +02:00
wpan platform: assert for out-of-memory in netlink code 2019-05-15 14:07:08 +02:00
nm-fake-platform.c platform: refactor detecting kernel features 2019-04-18 11:19:26 +02:00
nm-fake-platform.h core: refactor private data in "src" 2016-10-04 09:50:56 +02:00
nm-linux-platform.c device/trivial: add comment about lifetime of "kind" in tc_commit() 2019-05-15 14:07:08 +02:00
nm-linux-platform.h platform: use NMDedupMultiIndex for routes in NMPCache 2017-07-05 18:37:38 +02:00
nm-netlink.c platform/netlink: cleanup nlmsg_append() and add nlmsg_append_struct() macro 2019-02-22 09:58:09 +01:00
nm-netlink.h shared: split C-only helper "shared/nm-std-aux" utils out of "shared/nm-utils" 2019-04-18 19:17:23 +02:00
nm-platform-private.h platform: expose emit-signal function from platform 2017-07-05 18:37:39 +02:00
nm-platform-utils.c shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-core 2019-04-18 20:07:44 +02:00
nm-platform-utils.h shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-core 2019-04-18 20:07:44 +02:00
nm-platform.c device/trivial: add comment about lifetime of "kind" in tc_commit() 2019-05-15 14:07:08 +02:00
nm-platform.h device/trivial: add comment about lifetime of "kind" in tc_commit() 2019-05-15 14:07:08 +02:00
nmp-netns.c all: replace g_strerror() calls with nm_strerror_native() 2019-02-12 08:50:28 +01:00
nmp-netns.h core: cleanup implementation of nm_auto* macros to use nm_auto() 2017-10-11 08:43:40 +02:00
nmp-object.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nmp-object.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nmp-rules-manager.c shared: split C-only helper "shared/nm-std-aux" utils out of "shared/nm-utils" 2019-04-18 19:17:23 +02:00
nmp-rules-manager.h platform: add nmp_rules_manager_track_from_platform() 2019-04-13 18:17:16 +02:00