From d0bce9ef6246fa0b1ee1ce401f2fa9c7be124b30 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Tue, 10 May 2022 15:19:01 -0400 Subject: [PATCH] infiniband: Reject the invalid pkey value The pkey values 0x0000 and 0x8000 are not supported by kernel, raise an error when the user specifies such a pkey value. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/infiniband/ulp/ipoib/ipoib_main.c?id=c5eb0a61238dd6faf37f58c9ce61c9980aaffd7a#n2394 Signed-off-by: Wen Liang --- .../network_lsr/argument_validator.py | 9 ++++ tests/unit/test_network_connections.py | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/module_utils/network_lsr/argument_validator.py b/module_utils/network_lsr/argument_validator.py index b1299cd..bb5fa0c 100644 --- a/module_utils/network_lsr/argument_validator.py +++ b/module_utils/network_lsr/argument_validator.py @@ -2091,6 +2091,15 @@ class ArgValidator_DictConnection(ArgValidatorDict): if result["infiniband"]["transport_mode"] is None: result["infiniband"]["transport_mode"] = "datagram" if result["infiniband"]["p_key"] != -1: + if ( + result["infiniband"]["p_key"] == 0x0000 + or result["infiniband"]["p_key"] == 0x8000 + ): + raise ValidationError( + name, + "the pkey value {0} is not allowed as such a pkey value is not " + "supported by kernel".format(result["infiniband"]["p_key"]), + ) if "mac" not in result and "parent" not in result: raise ValidationError( name + ".infiniband.p_key", diff --git a/tests/unit/test_network_connections.py b/tests/unit/test_network_connections.py index d3d6368..85deabd 100644 --- a/tests/unit/test_network_connections.py +++ b/tests/unit/test_network_connections.py @@ -4986,6 +4986,49 @@ class TestValidatorDictBond(Python26CompatTestCase): self.validator.validate(self.test_connections) +class TestValidatorDictInfiniband(Python26CompatTestCase): + def setUp(self): + self.validator = network_lsr.argument_validator.ArgValidator_ListConnections() + self.test_connections = [ + { + "name": "ib0", + "type": "infiniband", + "interface_name": "ib0", + }, + { + "name": "ib0-10", + "type": "infiniband", + "infiniband": { + "p_key": 10, + "transport_mode": "datagram", + }, + "parent": "ib0", + }, + ] + + def test_invalid_pkey_values(self): + self.test_connections[1]["infiniband"]["p_key"] = 0x0000 + self.assertRaisesRegex( + ValidationError, + "the pkey value {0} is not allowed as such a pkey value is not " + "supported by kernel".format( + self.test_connections[1]["infiniband"]["p_key"] + ), + self.validator.validate, + self.test_connections, + ) + self.test_connections[1]["infiniband"]["p_key"] = 0x8000 + self.assertRaisesRegex( + ValidationError, + "the pkey value {0} is not allowed as such a pkey value is not " + "supported by kernel".format( + self.test_connections[1]["infiniband"]["p_key"] + ), + self.validator.validate, + self.test_connections, + ) + + class TestSysUtils(unittest.TestCase): def test_link_read_permaddress(self): self.assertEqual(SysUtil._link_read_permaddress("lo"), "00:00:00:00:00:00")