NetworkManager/src/libnm-core-impl
Thomas Haller cb73ae3f0b
ifcfg: better handle non-full-membership PKEY_ID with new PKEY_ID_NM variable
Infiniband profiles can have a p-key set. Both in kernel API
("create_child" sysctl) and in NetworkManager API, that key can range
from 0x0001 to 0xFFFF (0x8000 excluded). NetworkManager does not support
renaming the interface, so kernel always assigns the interface name
"$PHYSDEV.$PKEY_ID" (with $PKEY_ID as 4 character hex digits).

Note that the highest bit in the p-key (0x8000) is the full-membership
flag. Internally, kernel only supports full-membership so when we create
for example "ib0.00c1" and "ib0.80c1" interfaces, their actually used
p-key is in both cases 0x80c1 and you can see it with `ip -d link`.
Nonetheless, kernel and NetworkManager allow to configure the p-key
without the highest bit set, and the result differs in the interface
name.

Note that initscripts' ifup-ib0 would always internally coerce the
PKEY_ID variable to have the high bit set ([1]). It also would require
that the `DEVICE=` variable is specified and matches the expected
interface name. So both these configurations are identical and valid:

  DEVICE=ib0.80c1
  PHYSDEV=ib0
  PKEY_ID=0x80c1

and

  DEVICE=ib0.80c1
  PHYSDEV=ib0
  PKEY_ID=0x00c1

Historically, NetworkManager would also implement the same restrictions
([2], [3], [4]). That meant, not all valid NetworkManager infiniband
profiles could be expressed as  ifcfg file. For example, NetworkManager
allows to have "connection.interface-name" (`DEVICE=`) unset (which
ifup-ib and ifcfg reader did not allow). Also, NetworkManager would
allow configuring a "infiniband.p-key" without full membership flag, and
the reader would mangle that.

This caused various problems to the point that when you configure an
infiniband.p-key with a non-full-membership key, the ifcfg-rh written by
NetworkManager was invalid. Either, you could leave
"connection.interface-name" unset, but then the reader would complain
about missing `DEVICE=`. Or, we could write `DEVICE=ib0.00c1;
PKEY_ID=0x00c1`, which was invalid as we expected `DEVICE=ib0.80c1`.

This was addressed by rhbz 2122703 ([5]). The fix was to

  - not require a `DEVICE=` ([6]).
  - don't mangle the `PKEY_ID=` in the reader ([7]).

which happened in 1.41.2 and 1.40.2 (rhel-8.8).

With this change, we could persist any valid infiniband profile to ifcfg
format. We also could read back any valid ifcfg file that NetworkManager
would have written in the past (note that it could not write valid ifcfg
files previously, if the p-key didn't have the full-membership key set).

The problem is, that users were used to edit ifcfg files by hand, and
users would have files with:

  DEVICE=ib0.80c1
  PHYSDEV=ib0
  PKEY_ID=0x00c1

This files had worked before, but now failed to verify as we would
expect `DEVICE=ib0.00c1`. Also, there was a change in behavior that
PKEY_ID is now interpreted without the high bit set. This is reported as
rhbz 2209164 ([8]).

We will do several things to fix that:

1) we now normalize the "connection.interface-name" to be valid. It was
  not useful to set it anyway, as it was redundant. Complaining about a
  redundant setting, which makes little sense to configure, is not useful.
  This is done by [9].

2) we now again treat PKEY_ID= as if it had 0x8000 flag set. This was done by
  [10].

With step 1) and 2), we are able to read any existing ifcfg files out
there in the way we did before 1.41.2.

There is however one piece missing. When we now create a profile using
nmcli/libnm/D-Bus, which has a non-full-membership p-key, then the
profile gets mangled in the process.

If the user uses NetworkManager API to configure an interface and
chooses a non-full-membership p-key, then this should work the same as
with keyfile plugin (or on rhel-9, where keyfile is the default). Note
that before 1.41.2 it didn't work at all, when the user used ifcfg-rh
backend. Likely(?) there are no users who rely on creating such a profile
with nmcli/libnm/D-Bus and expect to automatically have the p-key
normalized. That didn't work before 1.41.2 and didn't behave that way
between 1.41.2 and now.

This patch fixes that by introducing a new key PKEY_ID_NM= for holding
the real p-key. Now ifcfg backend is consistent with handling infiniband
profiles, and old, hand-written ifcfg files still work as before.

There is of course change in behavior, that ifcfg files between 1.41.2
and now were interpreted differently. But that is bug 2209164 ([8]) and
what we fix here.

For now strong reasons, we keep writing the PKEY_ID to file too. It's
redundant, but that is what a human might expect there.

[1]  05333c3602/f/rdma.ifup-ib (_75)
[2]  https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.40.0/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c#L5386
[3]  cb5606cf1c (a7a78fccb2c8c945fd09038656ae734c1b0349ab_3493_3532)
[4]  cb5606cf1c (a7a78fccb2c8c945fd09038656ae734c1b0349ab_3493_3506)
[5]  https://bugzilla.redhat.com/show_bug.cgi?id=2122703
[6]  4c32dd9d25
[7]  a4fe16a426
[8]  https://bugzilla.redhat.com/show_bug.cgi?id=2209164
[9]  4610fd67e6
[10] f8e5e07355

(cherry picked from commit 5e3e38f291)
(cherry picked from commit d8f7fec9e0)
2023-06-05 11:05:16 +02:00
..
tests libnm: truncate too long interface name in nm_setting_infiniband_create_virtual_interface_name() 2023-05-25 22:51:12 +02:00
meson.build build: move nm-crypto to separate directory "src/libnm-crypto" 2022-03-29 11:56:04 +02: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 libnm: normalize interface-name for infiniband profiles 2023-05-25 22:47:24 +02:00
nm-dbus-utils.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-default-libnm-core.h build: move "shared/nm-{glib-aux,log-null,log-core}" to "src/libnm-{glib-aux,log-null,log-core}" 2021-02-24 12:48:20 +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 all: make "ipv6.addr-gen-mode" configurable by global default 2022-06-29 07:38:48 +02:00
nm-meta-setting-base-impl.c libnm: add nm_setting_8021x_scheme_vtable_by_setting_key() helper 2022-03-28 18:27:36 +02: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: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-8021x.c Revert "wifi: support "802-1x.phase1-auth-flags=tls-allow-unsafe-renegotiation" flag" 2022-08-11 19:36:26 +02:00
nm-setting-adsl.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-bluetooth.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-bond-port.c bonding: add support to prio property in bond ports 2023-05-15 16:02:01 +02:00
nm-setting-bond.c bond: add _nm_setting_bond_opt_value_as_intbool() helper 2022-09-29 14:14:41 +02:00
nm-setting-bridge-port.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-bridge.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +01:00
nm-setting-cdma.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-connection.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-dcb.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-dummy.c libnm: extend NMSettInfoSetting with an offset to the private data 2021-07-12 13:34:40 +02:00
nm-setting-ethtool.c ethtool: add and use nm_ethtool_id_get_variant_type() helper 2022-11-10 13:49:17 +01:00
nm-setting-generic.c libnm: extend NMSettInfoSetting with an offset to the private data 2021-07-12 13:34:40 +02:00
nm-setting-gsm.c libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-hostname.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-infiniband.c ifcfg: better handle non-full-membership PKEY_ID with new PKEY_ID_NM variable 2023-06-05 11:05:16 +02:00
nm-setting-ip-config.c dns: add support to no-aaaa option 2023-03-29 12:24:44 +02:00
nm-setting-ip-tunnel.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-ip4-config.c doc: fix route type name (unavailable -> unreachable) 2023-03-09 07:21:43 +01:00
nm-setting-ip6-config.c doc: fix route type name (unavailable -> unreachable) 2023-03-09 07:21:43 +01:00
nm-setting-macsec.c macsec: document the format of CAK and CKN properties 2022-12-05 17:15:06 +01:00
nm-setting-macvlan.c libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-match.c libnm: rework strv properties of NMSetting as "direct" properties 2022-02-10 22:30:27 +01:00
nm-setting-olpc-mesh.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-ovs-bridge.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-ovs-dpdk.c libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-ovs-external-ids.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +01:00
nm-setting-ovs-interface.c libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01: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 format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-ppp.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-pppoe.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-private.h libnm: add direct strv type for NMSetting and use it for "match.interface-name" 2022-02-10 22:30:27 +01:00
nm-setting-proxy.c libnm/docs: fix documentation for "proxy.pac-script" 2022-03-21 15:21:37 +01:00
nm-setting-serial.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-sriov.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-tc-config.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting-team-port.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-team.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-tun.c format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
nm-setting-user.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +01: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: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-vpn.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +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: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +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: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
nm-setting-wired.c libnm: cleanup redundant code for direct properties of NMSetting 2022-01-18 16:22:32 +01:00
nm-setting-wireguard.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +01:00
nm-setting-wireless-security.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +01:00
nm-setting-wireless.c all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update gitlab-ci to f36 2022-07-06 11:06:53 +02:00
nm-setting-wpan.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01:00
nm-setting.c libnm: fix a large amount of Since tags 2022-11-11 16:49:39 +01:00
nm-simple-connection.c libnm: don't clear secrets during NMSimpleConnection:dispose() 2022-01-19 13:42:17 +01:00
nm-team-utils.c all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update gitlab-ci to f36 2022-07-06 11:06:53 +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: add flag to map zero to NULL in _nm_utils_ipaddr_canonical_or_invalid() 2022-01-18 16:22:17 +01:00
nm-utils.c libnm: accept ipv[46].dhcp-iaid as hexstr 2023-02-21 09:45:25 +01:00
nm-vpn-editor-plugin.c libnm: workaround crash in nm_vpn_editor_plugin_import() for plugin requiring GError 2022-11-16 13:37:52 +01:00
nm-vpn-plugin-info.c libnm: actually export a lot of routines that were supposed to be public 2022-11-11 16:49:39 +01: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.