Skip to content

Commit a4cf50f

Browse files
authored
dhcpv6: T8849: Add time-zone support for Kea DHCPv6 (#5190)
* dhcpv6: T8849: Add time-zone support for Kea DHCPv6 Add DHCPv6 option support for time zone (RFC4833 options 41 and 42). This includes both the POSIX-style TZ string (`new-posix-timezone`) and the IANA time zone name (`new-tzdb-timezone`). * dhcpv6: T8849: Refactor per code-review suggestion * dhcpv6: T8849: Reformat for compliance
1 parent 0805578 commit a4cf50f

3 files changed

Lines changed: 182 additions & 93 deletions

File tree

interface-definitions/include/dhcp/option-v6.xml.i

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@
102102
</constraint>
103103
</properties>
104104
</leafNode>
105+
<leafNode name="time-zone">
106+
<properties>
107+
<help>Time zone to send to clients. Uses RFC4833 options 41 and 42</help>
108+
<completionHelp>
109+
<script>timedatectl list-timezones</script>
110+
</completionHelp>
111+
<constraint>
112+
<validator name="timezone" argument="--validate"/>
113+
</constraint>
114+
</properties>
115+
</leafNode>
105116
<node name="vendor-option">
106117
<properties>
107118
<help>Vendor Specific Options</help>

python/vyos/kea.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ def _find_list_of_dict_index(lst, key='ip', value=''):
8989
return idx
9090

9191

92+
def _read_posix_timezone(tz_name):
93+
try:
94+
with open(f'/usr/share/zoneinfo/{tz_name}', 'rb') as f:
95+
return f.read().split(b'\n')[-2].decode('utf-8').replace(',', '\\,')
96+
except (FileNotFoundError, IOError, IndexError) as e:
97+
raise ConfigError(f'Failed to read timezone data for: {tz_name}') from e
98+
99+
92100
def kea_test_config(process: str, config_path: str) -> tuple[bool, str]:
93101
result, output = rc_cmd(f'{process} -t {config_path}')
94102

@@ -143,9 +151,7 @@ def kea_parse_options(config):
143151
)
144152

145153
if 'time_zone' in config:
146-
with open('/usr/share/zoneinfo/' + config['time_zone'], 'rb') as f:
147-
tz_string = f.read().split(b'\n')[-2].decode('utf-8').replace(',', '\\,')
148-
154+
tz_string = _read_posix_timezone(config['time_zone'])
149155
options.append({'name': 'pcode', 'data': tz_string})
150156
options.append({'name': 'tcode', 'data': config['time_zone']})
151157

@@ -289,6 +295,11 @@ def kea6_parse_options(config):
289295
if hosts:
290296
options.append({'name': 'sip-server-dns', 'data': ', '.join(hosts)})
291297

298+
if 'time_zone' in config:
299+
tz_string = _read_posix_timezone(config['time_zone'])
300+
options.append({'name': 'new-posix-timezone', 'data': tz_string})
301+
options.append({'name': 'new-tzdb-timezone', 'data': config['time_zone']})
302+
292303
cisco_tftp = dict_search_args(config, 'vendor_option', 'cisco', 'tftp-server')
293304
if cisco_tftp:
294305
options.append(

0 commit comments

Comments
 (0)