summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorcblackburn-igl <chris.blackburn@infinitivegroup.co.uk>2025-10-28 15:38:43 +0000
committerGitHub <noreply@github.com>2025-10-28 15:38:43 +0000
commit1737b16dd87778358266222e2ef061eb15d63019 (patch)
tree0e127460ae080ad35a06b4e719d261ab3f7a1805 /python
parentecc4c85b799047f51e4a32ae5b0590017a6ce374 (diff)
downloadvyos-1x-1737b16dd87778358266222e2ef061eb15d63019.tar.gz
vyos-1x-1737b16dd87778358266222e2ef061eb15d63019.zip
dhcp-server: T3936: Added support for DHCP Option 82 (#4665)
* dhcp-server: T3936: Added support for DHCP Option 82 This commit adds support in both the CLI and the underlying code for DHCP Option 82 to be used to filter/route DHCP address assignments. The primary use case for this is to support enterprise switches which can "tag" DHCP requests with physical real world informaiton such as which switch first saw the request and which port it originated from (known in this context as remote-id and circuit-id). Once client-classes have been defined they can be assigned to subnets or ranges so that only certain addresses get assigned to specific requests. There is also a corresponding documentation update which pairs with this code change. (cherry picked from commit 326b5e713cb363a2b9f69e2204c4ee2ccd9939bb) * Update src/conf_mode/service_dhcp-server.py Co-authored-by: Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> * Update src/conf_mode/service_dhcp-server.py Co-authored-by: Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> * Update interface-definitions/include/dhcp/dhcp-server-common-config.xml.i Co-authored-by: Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> --------- Co-authored-by: Daniil Baturin <daniil@baturin.org> Co-authored-by: Nataliia S. <81954790+natali-rs1985@users.noreply.github.com>
Diffstat (limited to 'python')
-rw-r--r--python/vyos/kea.py25
-rwxr-xr-xpython/vyos/template.py19
2 files changed, 44 insertions, 0 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index f48cf293d..323fded5d 100644
--- a/python/vyos/kea.py
+++ b/python/vyos/kea.py
@@ -179,6 +179,9 @@ def kea_parse_subnet(subnet, config):
if 'ping_check' in config:
out['user-context']['enable-ping-check'] = True
+ if 'client_class' in config:
+ out['client-class'] = config['client_class']
+
if 'range' in config:
pools = []
for num, range_config in config['range'].items():
@@ -194,6 +197,9 @@ def kea_parse_subnet(subnet, config):
if 'bootfile_server' in range_config['option']:
pool['next-server'] = range_config['option']['bootfile_server']
+ if 'client_class' in range_config:
+ pool['client-class'] = range_config['client_class']
+
pools.append(pool)
out['pools'] = pools
@@ -677,3 +683,22 @@ def kea_get_server_leases(config, inet, vrf_name, pools=[], state=[], origin=Non
data.pop(idx)
return data
+
+def _build_relay_hex_condition(sub_option_index, value):
+ if value.startswith("0x"):
+ return f"relay4[{sub_option_index}].hex == {value}"
+ else:
+ return f"relay4[{sub_option_index}].hex == 0x{value.encode().hex().lower()}"
+
+def kea_build_client_class_test(config):
+ conditions = []
+
+ if "relay_agent_information" in config:
+ if "circuit_id" in config["relay_agent_information"]:
+ conditions.append(_build_relay_hex_condition(1, config["relay_agent_information"]["circuit_id"]))
+ if "remote_id" in config["relay_agent_information"]:
+ conditions.append(_build_relay_hex_condition(2, config["relay_agent_information"]["remote_id"]))
+
+ test = " and ".join(conditions)
+
+ return test
diff --git a/python/vyos/template.py b/python/vyos/template.py
index f384f752d..44278e963 100755
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -914,6 +914,25 @@ def kea_high_availability_json(config):
return dumps(data)
+@register_filter('kea_client_class_json')
+def kea_client_class_json(client_classes):
+ from vyos.kea import kea_build_client_class_test
+ from json import dumps
+ out = []
+
+ for name, config in client_classes.items():
+ if 'disable' in config:
+ continue
+
+ client_class = {
+ 'name': name,
+ 'test': kea_build_client_class_test(config)
+ }
+
+ out.append(client_class)
+
+ return dumps(out, indent=4)
+
@register_filter('kea_dynamic_dns_update_main_json')
def kea_dynamic_dns_update_main_json(config):
from vyos.kea import kea_parse_ddns_settings