diff options
author | Daniil Baturin <daniil@vyos.io> | 2025-04-15 15:54:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-15 15:54:02 +0100 |
commit | 9e47c2153be7cc0e5ed21ca8a976336d4bf872d8 (patch) | |
tree | ad917159c42092dfe1496edebcdd7f4025eab472 /python | |
parent | 2f54cbc0504a20424274e45b9210467d33acf919 (diff) | |
parent | 176da07ba48f9aac2e39ff45509306f0a0afe9da (diff) | |
download | vyos-1x-9e47c2153be7cc0e5ed21ca8a976336d4bf872d8.tar.gz vyos-1x-9e47c2153be7cc0e5ed21ca8a976336d4bf872d8.zip |
Merge pull request #4412 from sarthurdev/kea_2.6
kea: T7281: Add ping-check, use built-in option for classless static routes
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/kea.py | 13 | ||||
-rwxr-xr-x | python/vyos/template.py | 28 |
2 files changed, 12 insertions, 29 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py index de397d8f9..2b0cac7e6 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -21,7 +21,6 @@ from datetime import datetime from datetime import timezone from vyos.template import is_ipv6 -from vyos.template import isc_static_route from vyos.template import netmask_from_cidr from vyos.utils.dict import dict_search_args from vyos.utils.file import file_permissions @@ -113,22 +112,21 @@ def kea_parse_options(config): default_route = '' if 'default_router' in config: - default_route = isc_static_route('0.0.0.0/0', config['default_router']) + default_route = f'0.0.0.0/0 - {config["default_router"]}' routes = [ - isc_static_route(route, route_options['next_hop']) + f'{route} - {route_options["next_hop"]}' for route, route_options in config['static_route'].items() ] options.append( { - 'name': 'rfc3442-static-route', + 'name': 'classless-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: @@ -149,7 +147,7 @@ def kea_parse_options(config): def kea_parse_subnet(subnet, config): - out = {'subnet': subnet, 'id': int(config['subnet_id'])} + out = {'subnet': subnet, 'id': int(config['subnet_id']), 'user-context': {}} if 'option' in config: out['option-data'] = kea_parse_options(config['option']) @@ -167,6 +165,9 @@ def kea_parse_subnet(subnet, config): out['valid-lifetime'] = int(config['lease']) out['max-valid-lifetime'] = int(config['lease']) + if 'ping_check' in config: + out['user-context']['enable-ping-check'] = True + if 'range' in config: pools = [] for num, range_config in config['range'].items(): diff --git a/python/vyos/template.py b/python/vyos/template.py index e75db1a8d..7ba85a046 100755 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -390,28 +390,6 @@ def compare_netmask(netmask1, netmask2): except: return False -@register_filter('isc_static_route') -def isc_static_route(subnet, router): - # https://ercpe.de/blog/pushing-static-routes-with-isc-dhcp-server - # Option format is: - # <netmask>, <network-byte1>, <network-byte2>, <network-byte3>, <router-byte1>, <router-byte2>, <router-byte3> - # where bytes with the value 0 are omitted. - from ipaddress import ip_network - net = ip_network(subnet) - # add netmask - string = str(net.prefixlen) + ',' - # add network bytes - if net.prefixlen: - width = net.prefixlen // 8 - if net.prefixlen % 8: - width += 1 - string += ','.join(map(str,tuple(net.network_address.packed)[:width])) + ',' - - # add router bytes - string += ','.join(router.split('.')) - - return string - @register_filter('is_file') def is_file(filename): if os.path.exists(filename): @@ -895,7 +873,8 @@ def kea_shared_network_json(shared_networks): network = { 'name': name, 'authoritative': ('authoritative' in config), - 'subnet4': [] + 'subnet4': [], + 'user-context': {} } if 'option' in config: @@ -907,6 +886,9 @@ def kea_shared_network_json(shared_networks): if 'bootfile_server' in config['option']: network['next-server'] = config['option']['bootfile_server'] + if 'ping_check' in config: + network['user-context']['enable-ping-check'] = True + if 'subnet' in config: for subnet, subnet_config in config['subnet'].items(): if 'disable' in subnet_config: |