From: Rajasekar Raja Date: Tue, 29 Apr 2025 22:02:11 +0000 (-0700) Subject: zebra: Fixes allowing SRv6 func-bits length 0 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e7a7f6a5247e804a4d3ab75f62fef9dfcdc60b18;p=mirror%2Ffrr.git zebra: Fixes allowing SRv6 func-bits length 0 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 --- 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 index 0000000000..29077131a2 --- /dev/null +++ b/tests/topotests/srv6_locator_custom_bits_length/expected_locators7.json @@ -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" + } + ] + } + ] +} diff --git a/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator_custom_bits_length.py b/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator_custom_bits_length.py index d3df902aae..8887347d95 100755 --- a/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator_custom_bits_length.py +++ b/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator_custom_bits_length.py @@ -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)) diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index 27fe83a7ca..dad265e954 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -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;