diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 533379c678..ad14209a3c 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -5358,6 +5358,7 @@ parse_infiniband_p_key(shvarFile *ifcfg, int *out_p_key, char **out_parent, GErr gs_free char *physdev = NULL; gs_free char *pkey_id = NULL; int id; + int fixup_id = 0; physdev = svGetValueStr_cp(ifcfg, "PHYSDEV"); if (!physdev) { @@ -5368,7 +5369,14 @@ parse_infiniband_p_key(shvarFile *ifcfg, int *out_p_key, char **out_parent, GErr return FALSE; } - pkey_id = svGetValueStr_cp(ifcfg, "PKEY_ID"); + pkey_id = svGetValueStr_cp(ifcfg, "PKEY_ID_NM"); + if (!pkey_id) { + /* Only check for "$PKEY_ID". That key is interpreted as having the + * full membership flag set ("fixup_id"). */ + fixup_id = 0x8000; + pkey_id = svGetValueStr_cp(ifcfg, "PKEY_ID"); + } + if (!pkey_id) { g_set_error(error, NM_SETTINGS_ERROR, @@ -5387,23 +5395,7 @@ parse_infiniband_p_key(shvarFile *ifcfg, int *out_p_key, char **out_parent, GErr return FALSE; } - /* The highest bit 0x8000 indicates full membership, which kernel always - * automatically sets. - * - * NetworkManager supports p-keys without the high bit set. That affects - * the interface name (nmp_utils_new_infiniband_name()) and is what - * we write to "create_child"/"delete_child" sysctl. Kernel will honor - * such p-keys for the interface name, but for other purposes it adds the - * highest bit. That makes using p-keys without the highest bit odd. - * - * Historically, /etc/sysconfig/network-scripts/ifup-ib would always add "|=0x8000". - * The reader does that too. - * - * Note that this means ifcfg cannot handle p-keys without the highest bit set, - * and when trying to store that to ifcfg format, the profile will be mangled/modified - * by the ifcg plugin (unlike keyfile backend, which preserves the original p-key value). - */ - id |= 0x8000; + id |= fixup_id; *out_p_key = id; *out_parent = g_steal_pointer(&physdev); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index ef4276da73..7fc33967ac 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -1028,6 +1028,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("PHYSDEV", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("PKEY", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("PKEY_ID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), + _KEY_TYPE("PKEY_ID_NM", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("PMF", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("PORTNAME", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("POWERSAVE", NMS_IFCFG_KEY_TYPE_IS_PLAIN), diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index e3d3d87321..7302625cc1 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -33,7 +33,7 @@ typedef struct { NMSIfcfgKeyTypeFlags key_flags; } NMSIfcfgKeyTypeInfo; -extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[257]; +extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[258]; const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 9610cd6471..b78bbe4166 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -1054,28 +1054,24 @@ write_infiniband_setting(NMConnection *connection, p_key = nm_setting_infiniband_get_p_key(s_infiniband); if (p_key != -1) { - /* The reader normalizes KKEY_ID with |=0x8000. Also do that when - * writing the profile so that what we write, is consistent with what - * we would read. */ - p_key |= 0x8000; - svSetValueStr(ifcfg, "PKEY", "yes"); + svSetValueInt64(ifcfg, "PKEY_ID", p_key); + if (!NM_FLAGS_HAS(p_key, 0x8000)) { + /* initscripts' ifup-ib used to always interpret the PKEY_ID with + * the full membership flag (0x8000) set. For compatibility, we do + * interpret PKEY_ID as having that flag set. + * + * However, now we want to persist a p-key which doesn't have the + * flag. Use a NetworkManager specific variable for that. This configuration + * is not supported by initscripts' ifup-ib. + */ + svSetValueInt64(ifcfg, "PKEY_ID_NM", p_key); + } + parent = nm_setting_infiniband_get_parent(s_infiniband); svSetValueStr(ifcfg, "PHYSDEV", parent); - - if (parent && nm_connection_get_interface_name(connection)) { - /* The connection.interface-name depends on the p-key. Also, - * nm_connection_normalize() will automatically adjust the - * interface-name to match the p-key. - * - * As we patched the p-key above, also anticipate that change, and - * don't write a DEVICE= to the file, which would we normalize - * differently, when reading it back. */ - *out_interface_name = - nm_setting_infiniband_create_virtual_interface_name(parent, p_key); - } } svSetValueStr(ifcfg, "TYPE", TYPE_INFINIBAND); diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index b391aa2392..b5f830c866 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8419,7 +8419,6 @@ test_write_infiniband(gconstpointer test_data) const int TEST_IDX = GPOINTER_TO_INT(test_data); nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMConnection *expected = NULL; gs_unref_object NMConnection *reread = NULL; gboolean reread_same = FALSE; NMSettingConnection *s_con; @@ -8500,32 +8499,20 @@ test_write_infiniband(gconstpointer test_data) nmtst_assert_connection_verifies(connection); - if (p_key != -1 && p_key < 0x8000) { - expected = nm_simple_connection_new_clone(connection); - g_object_set(nm_connection_get_setting(expected, NM_TYPE_SETTING_INFINIBAND), - NM_SETTING_INFINIBAND_P_KEY, - (int) (p_key | 0x8000), - NULL); - } else - expected = g_object_ref(connection); - _writer_new_connection_reread(connection, TEST_SCRATCH_DIR, &testfile, NO_EXPECTED, &reread, &reread_same); - _assert_reread_same(expected, reread); - if (p_key == -1 || p_key > 0x8000) - g_assert(reread_same); - else - g_assert(!reread_same); + _assert_reread_same(connection, reread); + g_assert(reread_same); g_assert_cmpstr(interface_name, ==, nm_connection_get_interface_name(reread)); g_assert_cmpint(nm_setting_infiniband_get_p_key( _nm_connection_get_setting(reread, NM_TYPE_SETTING_INFINIBAND)), ==, - p_key == -1 ? -1 : (p_key | 0x8000)); + p_key); } static void diff --git a/src/libnm-core-impl/nm-setting-infiniband.c b/src/libnm-core-impl/nm-setting-infiniband.c index 0753a8db2d..6df92ceb47 100644 --- a/src/libnm-core-impl/nm-setting-infiniband.c +++ b/src/libnm-core-impl/nm-setting-infiniband.c @@ -461,31 +461,31 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) /** * NMSettingInfiniband:p-key: * - * The InfiniBand P_Key to use for this device. A value of -1 means to use - * the default P_Key (aka "the P_Key at index 0"). Otherwise, it is a + * The InfiniBand p-key to use for this device. A value of -1 means to use + * the default p-key (aka "the p-key at index 0"). Otherwise, it is a * 16-bit unsigned integer, whose high bit 0x8000 is set if it is a "full - * membership" P_Key. The values 0 and 0x8000 are not allowed. + * membership" p-key. The values 0 and 0x8000 are not allowed. * * With the p-key set, the interface name is always "$parent.$p_key". * Setting "connection.interface-name" to another name is not supported. * * Note that kernel will internally always set the full membership bit, - * although the interface name does not reflect that. Thus, not setting - * the high bit is probably not useful. - * - * If the profile is stored in ifcfg-rh format, then the full membership - * bit is automatically added. To get consistent behavior, it is - * best to only use p-key values with the full membership bit set. + * although the interface name does not reflect that. Usually the user + * would want to configure a full membership p-key with 0x8000 flag set. **/ /* ---ifcfg-rh--- * property: p-key - * variable: PKEY_ID (and PKEY=yes) + * variable: PKEY_ID or PKEY_ID_NM(*) (requires PKEY=yes) * default: PKEY=no * description: InfiniBand P_Key. The value can be a hex number prefixed with "0x" * or a decimal number. - * When PKEY_ID is specified, PHYSDEV and DEVICE also must be specified. + * When PKEY_ID is specified, PHYSDEV must be specified. * Note that ifcfg-rh format will always automatically set the full membership - * bit 0x8000. Other p-key cannot be stored. + * flag 0x8000 for the PKEY_ID variable. To express IDs without the full membership + * flag, use PKEY_ID_NM. Note that kernel internally treats the interface as + * having the full membership flag set, this mainly affects the interface name. + * For the ifcfg file to be supported by initscripts' ifup-ib, the DEVICE= + * must always be set. NetworkManager does not require that. * example: PKEY=yes PKEY_ID=2 PHYSDEV=mlx4_ib0 DEVICE=mlx4_ib0.8002 * ---end--- */ diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index 01629a71f7..e8115dac82 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -153,7 +153,7 @@ #define DESCRIBE_DOC_NM_SETTING_GSM_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MAC_ADDRESS N_("If specified, this connection will only apply to the IPoIB device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing).") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames.") -#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise, it is a 16-bit unsigned integer, whose high bit 0x8000 is set if it is a \"full membership\" P_Key. The values 0 and 0x8000 are not allowed. With the p-key set, the interface name is always \"$parent.$p_key\". Setting \"connection.interface-name\" to another name is not supported. Note that kernel will internally always set the full membership bit, although the interface name does not reflect that. Thus, not setting the high bit is probably not useful. If the profile is stored in ifcfg-rh format, then the full membership bit is automatically added. To get consistent behavior, it is best to only use p-key values with the full membership bit set.") +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand p-key to use for this device. A value of -1 means to use the default p-key (aka \"the p-key at index 0\"). Otherwise, it is a 16-bit unsigned integer, whose high bit 0x8000 is set if it is a \"full membership\" p-key. The values 0 and 0x8000 are not allowed. With the p-key set, the interface name is always \"$parent.$p_key\". Setting \"connection.interface-name\" to another name is not supported. Note that kernel will internally always set the full membership bit, although the interface name does not reflect that. Usually the user would want to configure a full membership p-key with 0x8000 flag set.") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_PARENT N_("The interface name of the parent device of this device. Normally NULL, but if the \"p_key\" property is set, then you must specify the base device by setting either this property or \"mac-address\".") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_TRANSPORT_MODE N_("The IP-over-InfiniBand transport mode. Either \"datagram\" or \"connected\".") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES N_("A list of IPv4 addresses and their prefix length. Multiple addresses can be separated by comma. For example \"192.168.1.5/24, 10.1.0.5/24\". The addresses are listed in decreasing priority, meaning the first address will be the primary address.") diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in index 0a69c926e4..37896ccd6e 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in +++ b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in @@ -614,7 +614,7 @@ description="The IP-over-InfiniBand transport mode. Either "datagram" or "connected"." /> + description="The InfiniBand p-key to use for this device. A value of -1 means to use the default p-key (aka "the p-key at index 0"). Otherwise, it is a 16-bit unsigned integer, whose high bit 0x8000 is set if it is a "full membership" p-key. The values 0 and 0x8000 are not allowed. With the p-key set, the interface name is always "$parent.$p_key". Setting "connection.interface-name" to another name is not supported. Note that kernel will internally always set the full membership bit, although the interface name does not reflect that. Usually the user would want to configure a full membership p-key with 0x8000 flag set." />