From 2787e7915c1225f05f1e07c62f7c4d1ac9dca5ac Mon Sep 17 00:00:00 2001 From: sarthurdev <965089+sarthurdev@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:47:38 +0200 Subject: dhcp: T3316: Add time-zone node for options 100 and 101 --- interface-definitions/dhcp-server.xml.in | 11 +++++++++++ python/vyos/kea.py | 7 +++++++ smoketest/scripts/cli/test_service_dhcp-server.py | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/interface-definitions/dhcp-server.xml.in b/interface-definitions/dhcp-server.xml.in index 0fa06c534..081f7ed42 100644 --- a/interface-definitions/dhcp-server.xml.in +++ b/interface-definitions/dhcp-server.xml.in @@ -400,6 +400,17 @@ + + + Time zone to send to clients. Uses RFC4833 options 100 and 101 + + + + + + + + Vendor Specific Options diff --git a/python/vyos/kea.py b/python/vyos/kea.py index fa2948233..cb341e0f2 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -83,6 +83,13 @@ def kea_parse_options(config): options.append({'name': 'rfc3442-static-route', 'data': ", ".join(routes if not default_route else routes + [default_route])}) options.append({'name': 'windows-static-route', 'data': ", ".join(routes)}) + if 'time_zone' in config: + with open("/usr/share/zoneinfo/" + config['time_zone'], "rb") as f: + tz_string = f.read().split(b"\n")[-2].decode("utf-8") + + options.append({'name': 'pcode', 'data': tz_string}) + options.append({'name': 'tcode', 'data': config['time_zone']}) + return options def kea_parse_subnet(subnet, config): diff --git a/smoketest/scripts/cli/test_service_dhcp-server.py b/smoketest/scripts/cli/test_service_dhcp-server.py index aeff2aa82..9f6e05ff3 100755 --- a/smoketest/scripts/cli/test_service_dhcp-server.py +++ b/smoketest/scripts/cli/test_service_dhcp-server.py @@ -184,6 +184,7 @@ class TestServiceDHCPServer(VyOSUnitTestSHIM.TestCase): self.cli_set(pool + ['static-route', '10.0.0.0/24', 'next-hop', '192.0.2.1']) self.cli_set(pool + ['ipv6-only-preferred', ipv6_only_preferred]) + self.cli_set(pool + ['time-zone', 'Europe/London']) # check validate() - No DHCP address range or active static-mapping set with self.assertRaises(ConfigSessionError): @@ -262,6 +263,16 @@ class TestServiceDHCPServer(VyOSUnitTestSHIM.TestCase): ['Dhcp4', 'shared-networks', 0, 'subnet4', 0, 'option-data'], {'name': 'ip-forwarding', 'data': "true"}) + # Time zone + self.verify_config_object( + obj, + ['Dhcp4', 'shared-networks', 0, 'subnet4', 0, 'option-data'], + {'name': 'pcode', 'data': 'GMT0BST,M3.5.0/1,M10.5.0'}) + self.verify_config_object( + obj, + ['Dhcp4', 'shared-networks', 0, 'subnet4', 0, 'option-data'], + {'name': 'tcode', 'data': 'Europe/London'}) + # Verify pools self.verify_config_object( obj, -- cgit v1.2.3