mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 11:00:09 +01:00
ifcfg: merge branch 'th/fix-ifcfg-infiniband-p-key'
https://bugzilla.redhat.com/show_bug.cgi?id=2209164
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1646
(cherry picked from commit 01ab5ce4a8)
This commit is contained in:
commit
46bf0ed6e7
12 changed files with 101 additions and 73 deletions
|
|
@ -3561,7 +3561,9 @@ EXTRA_DIST += \
|
|||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-fabric \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-vn2vn \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband0 \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband1 \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband2 \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ipoib \
|
||||
src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-link_local \
|
||||
|
|
|
|||
|
|
@ -5377,6 +5377,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) {
|
||||
|
|
@ -5387,7 +5388,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,
|
||||
|
|
@ -5406,23 +5414,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);
|
||||
|
|
|
|||
|
|
@ -1032,6 +1032,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),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
NMSIfcfgKeyTypeFlags key_flags;
|
||||
} NMSIfcfgKeyTypeInfo;
|
||||
|
||||
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[262];
|
||||
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[263];
|
||||
|
||||
const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
TYPE=InfiniBand
|
||||
HWADDR=80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22
|
||||
CONNECTED_MODE=yes
|
||||
MTU=65520
|
||||
IPADDR=192.168.2.2
|
||||
NETMASK=255.255.255.0
|
||||
GATEWAY=192.168.2.1
|
||||
|
||||
DEVICE=ib0.80c1
|
||||
PKEY=yes
|
||||
PKEY_ID=0x00c1
|
||||
PHYSDEV=ib0
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
TYPE=InfiniBand
|
||||
HWADDR=80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22
|
||||
CONNECTED_MODE=yes
|
||||
MTU=65520
|
||||
IPADDR=192.168.2.2
|
||||
NETMASK=255.255.255.0
|
||||
GATEWAY=192.168.2.1
|
||||
|
||||
DEVICE=ib0.00c1
|
||||
PKEY=yes
|
||||
PKEY_ID=0x00c1
|
||||
PHYSDEV=ib0
|
||||
|
|
@ -8364,8 +8364,9 @@ test_write_bond_port(void)
|
|||
}
|
||||
|
||||
static void
|
||||
test_read_infiniband(void)
|
||||
test_read_infiniband(gconstpointer test_data)
|
||||
{
|
||||
const guint TEST_IDX = GPOINTER_TO_UINT(test_data);
|
||||
gs_unref_object NMConnection *connection = NULL;
|
||||
NMSettingInfiniband *s_infiniband;
|
||||
char *unmanaged = NULL;
|
||||
|
|
@ -8374,11 +8375,15 @@ test_read_infiniband(void)
|
|||
0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc,
|
||||
0xdd, 0xee, 0xff, 0x00, 0x11, 0x22};
|
||||
const char *transport_mode;
|
||||
const char *test_files[] = {
|
||||
TEST_IFCFG_DIR "/ifcfg-test-infiniband0",
|
||||
TEST_IFCFG_DIR "/ifcfg-test-infiniband1",
|
||||
TEST_IFCFG_DIR "/ifcfg-test-infiniband2",
|
||||
};
|
||||
|
||||
connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-infiniband",
|
||||
NULL,
|
||||
TYPE_INFINIBAND,
|
||||
&unmanaged);
|
||||
g_assert(TEST_IDX < G_N_ELEMENTS(test_files));
|
||||
|
||||
connection = _connection_from_file(test_files[TEST_IDX], NULL, TYPE_INFINIBAND, &unmanaged);
|
||||
g_assert(!unmanaged);
|
||||
|
||||
s_infiniband = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_INFINIBAND);
|
||||
|
|
@ -8390,6 +8395,25 @@ test_read_infiniband(void)
|
|||
transport_mode = nm_setting_infiniband_get_transport_mode(s_infiniband);
|
||||
g_assert(transport_mode);
|
||||
g_assert_cmpstr(transport_mode, ==, "connected");
|
||||
|
||||
nmtst_assert_connection_verifies_without_normalization(connection);
|
||||
|
||||
switch (TEST_IDX) {
|
||||
case 0:
|
||||
g_assert_cmpint(nm_setting_infiniband_get_p_key(s_infiniband), ==, -1);
|
||||
g_assert_cmpstr(nm_setting_infiniband_get_parent(s_infiniband), ==, NULL);
|
||||
g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "ib0");
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
g_assert_cmpint(nm_setting_infiniband_get_p_key(s_infiniband), ==, 0x80c1);
|
||||
g_assert_cmpstr(nm_setting_infiniband_get_parent(s_infiniband), ==, "ib0");
|
||||
g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "ib0.80c1");
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -8422,7 +8446,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;
|
||||
|
|
@ -8503,32 +8526,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
|
||||
|
|
@ -10700,7 +10711,9 @@ main(int argc, char **argv)
|
|||
|
||||
g_test_add_func(TPATH "wifi/read/wep-no-keys", test_read_wifi_wep_no_keys);
|
||||
g_test_add_func(TPATH "wifi/read/wep-agent-keys", test_read_wifi_wep_agent_keys);
|
||||
g_test_add_func(TPATH "infiniband/read", test_read_infiniband);
|
||||
g_test_add_data_func(TPATH "infiniband/read/0", GUINT_TO_POINTER(0), test_read_infiniband);
|
||||
g_test_add_data_func(TPATH "infiniband/read/1", GUINT_TO_POINTER(1), test_read_infiniband);
|
||||
g_test_add_data_func(TPATH "infiniband/read/2", GUINT_TO_POINTER(2), test_read_infiniband);
|
||||
g_test_add_func(TPATH "ipoib/read", test_read_ipoib);
|
||||
g_test_add_func(TPATH "vlan/read", test_read_vlan_interface);
|
||||
g_test_add_func(TPATH "vlan/read-flags-1", test_read_vlan_flags_1);
|
||||
|
|
|
|||
|
|
@ -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---
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.")
|
||||
|
|
|
|||
|
|
@ -614,7 +614,7 @@
|
|||
description="The IP-over-InfiniBand transport mode. Either "datagram" or "connected"." />
|
||||
<property name="p-key"
|
||||
alias="p-key"
|
||||
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. 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." />
|
||||
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." />
|
||||
<property name="parent"
|
||||
alias="parent"
|
||||
description="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"." />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue