Skip to content

Commit

Permalink
dhcp: T3316: Add time-zone node for options 100 and 101
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthurdev committed Dec 7, 2023
1 parent 4484a73 commit 2787e79
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions interface-definitions/dhcp-server.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
7 changes: 7 additions & 0 deletions python/vyos/kea.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions smoketest/scripts/cli/test_service_dhcp-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_dhcp_single_pool_options(self):

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):
Expand Down Expand Up @@ -262,6 +263,16 @@ def test_dhcp_single_pool_options(self):
['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,
Expand Down

0 comments on commit 2787e79

Please sign in to comment.