From d6c9aa14bca0f7a36e80fd55d5d12adfb0ad9a52 Mon Sep 17 00:00:00 2001 From: Ruben Herold Date: Mon, 31 Aug 2026 13:06:51 +0200 Subject: dhcp-server: T9267: fix substring default length for odd hex digit count The auto-computed substring length floored instead of rounding up, so a value like 0x1 produced substring(..., 0, 0) - an always-empty comparison that can never match, even though Kea itself pads 0x1 to the single byte 0x01. Round up to match Kea's own padding behavior. Found by CodeRabbit review on PR #5436. --- python/vyos/kea.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/vyos/kea.py b/python/vyos/kea.py index e42bb6e1c..b782111c9 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -746,8 +746,10 @@ def _build_option_match_condition(option_number, match_config): substring_config = match_config['substring'] offset = substring_config.get('offset', '0') value_hex = _kea_hex_literal(substring_config['value']) - # length is expressed in bytes; a hex literal is '0x' + 2 hex digits per byte - length = substring_config.get('length') or str((len(value_hex) - 2) // 2) + # length is expressed in bytes; a hex literal is '0x' + 2 hex digits per + # byte, rounded up since Kea itself pads an odd number of hex digits + # with a leading zero + length = substring_config.get('length') or str((len(value_hex) - 1) // 2) return f'substring({kea_path}.hex, {offset}, {length}) == {value_hex}' return _build_hex_condition(kea_path, match_config['value']) -- cgit v1.2.3