From 84b7ade286e4022e62684237246cd04b9d37b5db Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 1 Dec 2020 18:18:09 +0100 Subject: dhcp: T3100: migrate server configuration to get_config_dict() --- python/vyos/template.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'python') diff --git a/python/vyos/template.py b/python/vyos/template.py index b31f5bea2..5993ffd95 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -214,3 +214,26 @@ def dec_ip(address, decrement): """ from ipaddress import ip_interface return str(ip_interface(address).ip - int(decrement)) + + +@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: + # , , , , , , + # 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 -- cgit v1.2.3