]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Fixes allowing SRv6 func-bits length 0 18737/head
authorRajasekar Raja <rajasekarr@nvidia.com>
Tue, 29 Apr 2025 22:02:11 +0000 (15:02 -0700)
committerRajasekar Raja <rajasekarr@nvidia.com>
Wed, 30 Apr 2025 14:18:42 +0000 (07:18 -0700)
In current code, when a user inputs function length as 0 for a locator,
the code treats it as a "not configured" value and assigned default (16)
value to it.

This is wrong since the locator default is only to be used when the
function-bits (0-64) is not specified in the locator prefix config.

Fix is to use default value only when the user has not specified the
func-bits

Signed-off-by: Rajasekar Raja <rajasekarr@nvidia.com>
tests/topotests/srv6_locator_custom_bits_length/expected_locators7.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator_custom_bits_length.py
zebra/zebra_srv6_vty.c

diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators7.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators7.json
new file mode 100644 (file)
index 0000000..2907713
--- /dev/null
@@ -0,0 +1,109 @@
+{
+  "locators":[
+    {
+      "name":"loc1",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":32,
+      "nodeBitsLength":16,
+      "functionBitsLength":16,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    },
+    {
+      "name":"loc2",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":32,
+      "nodeBitsLength":16,
+      "functionBitsLength":0,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    },
+    {
+      "name":"loc3",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":32,
+      "nodeBitsLength":16,
+      "functionBitsLength":16,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    },
+    {
+      "name":"loc4",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":32,
+      "nodeBitsLength":16,
+      "functionBitsLength":0,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    },
+    {
+      "name":"loc5",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":24,
+      "nodeBitsLength":24,
+      "functionBitsLength":16,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    },
+    {
+      "name":"loc6",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":24,
+      "nodeBitsLength":24,
+      "functionBitsLength":0,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    },
+    {
+      "name":"loc7",
+      "prefix":"2001:db8:3::/48",
+      "blockBitsLength":32,
+      "nodeBitsLength":16,
+      "functionBitsLength":10,
+      "argumentBitsLength":0,
+      "statusUp":true,
+      "chunks":[
+        {
+          "prefix":"2001:db8:3::/48",
+          "proto":"system"
+        }
+      ]
+    }
+  ]
+}
index d3df902aaed19dc18db54a2be96860a37fcea03c..8887347d95c729d2cc3a2d6f360cc9c3564e81ec 100755 (executable)
@@ -142,6 +142,49 @@ def test_srv6():
     check_sharpd_chunk(router, "expected_chunks6.json")
 
 
+def test_srv6_locator_func_bits():
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+    router = tgen.gears["r1"]
+
+    def _check_srv6_locator(router, expected_locator_file):
+        logger.info("checking zebra locator status")
+        output = json.loads(router.vtysh_cmd("show segment-routing srv6 locator json"))
+        expected = open_json_file("{}/{}".format(CWD, expected_locator_file))
+        return topotest.json_cmp(output, expected)
+
+    def check_srv6_locator(router, expected_file):
+        func = functools.partial(_check_srv6_locator, router, expected_file)
+        _, result = topotest.run_and_expect(func, None, count=10, wait=0.5)
+        assert result is None, "Failed"
+
+    logger.info("Configure various locators with and without func-len")
+    router.vtysh_cmd(
+        """
+        configure terminal
+         segment-routing
+          srv6
+           locators
+            locator loc1
+             prefix 2001:db8:3::/48 block-len 32 node-len 16
+            locator loc2
+             prefix 2001:db8:3::/48 block-len 32 node-len 16 func-bits 0
+            locator loc3
+             prefix 2001:db8:3::/48 node-len 16
+            locator loc4
+             prefix 2001:db8:3::/48 node-len 16 func-bits 0
+            locator loc5
+             prefix 2001:db8:3::/48
+            locator loc6
+             prefix 2001:db8:3::/48 func-bits 0
+            locator loc7
+             prefix 2001:db8:3::/48 block-len 32 node-len 16 func-bits 10
+        """
+    )
+    check_srv6_locator(router, "expected_locators7.json")
+
+
 if __name__ == "__main__":
     args = ["-s"] + sys.argv[1:]
     sys.exit(pytest.main(args))
index 27fe83a7ca626a931d6944245ff5f6b7b842a08f..dad265e954c2ac3d81d71b86473f1db73801e0af 100644 (file)
@@ -801,9 +801,12 @@ DEFPY (locator_prefix,
        struct listnode *node = NULL;
        uint8_t expected_prefixlen;
        struct srv6_sid_format *format;
+       int idx = 0;
 
        locator->prefix = *prefix;
-       func_bit_len = func_bit_len ?: ZEBRA_SRV6_FUNCTION_LENGTH;
+       /* Only set default if func_bit_len was not provided in command */
+       if (func_bit_len == 0 && !argv_find(argv, argc, "func-bits", &idx))
+               func_bit_len = ZEBRA_SRV6_FUNCTION_LENGTH;
 
        expected_prefixlen = prefix->prefixlen;
        format = locator->sid_format;