diff options
author | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2023-10-05 13:47:38 +0200 |
---|---|---|
committer | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2023-12-08 00:29:40 +0100 |
commit | 2787e7915c1225f05f1e07c62f7c4d1ac9dca5ac (patch) | |
tree | 9f0724328d94ef3b2a938e203c44fb82f2c81a63 | |
parent | 4484a7398482caffdd5e0a74f73f46b162785bf3 (diff) | |
download | vyos-1x-2787e7915c1225f05f1e07c62f7c4d1ac9dca5ac.tar.gz vyos-1x-2787e7915c1225f05f1e07c62f7c4d1ac9dca5ac.zip |
dhcp: T3316: Add time-zone node for options 100 and 101
-rw-r--r-- | interface-definitions/dhcp-server.xml.in | 11 | ||||
-rw-r--r-- | python/vyos/kea.py | 7 | ||||
-rwxr-xr-x | smoketest/scripts/cli/test_service_dhcp-server.py | 11 |
3 files changed, 29 insertions, 0 deletions
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 @@ <multi/> </properties> </leafNode> + <leafNode name="time-zone"> + <properties> + <help>Time zone to send to clients. Uses RFC4833 options 100 and 101</help> + <completionHelp> + <script>timedatectl list-timezones</script> + </completionHelp> + <constraint> + <validator name="timezone" argument="--validate"/> + </constraint> + </properties> + </leafNode> <node name="vendor-option"> <properties> <help>Vendor Specific Options</help> 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, |