summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRuben Herold <ruben@puettmann.net>2026-08-31 13:06:51 +0200
committerViacheslav Hletenko <seversss265@gmail.com>2026-10-15 16:05:57 +0300
commitd6c9aa14bca0f7a36e80fd55d5d12adfb0ad9a52 (patch)
tree20ee49ec5b56f36c69e8c78d7f7aa93d98f27154 /python
parent2e5ea7a8304ed6ce504b3928e3b2f52574a61397 (diff)
downloadvyos-1x-d6c9aa14bca0f7a36e80fd55d5d12adfb0ad9a52.tar.gz
vyos-1x-d6c9aa14bca0f7a36e80fd55d5d12adfb0ad9a52.zip
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.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/kea.py6
1 files changed, 4 insertions, 2 deletions
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'])