diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-12-01 18:18:09 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-12-04 18:20:44 +0100 |
commit | 84b7ade286e4022e62684237246cd04b9d37b5db (patch) | |
tree | 7466e318d795071755012032a361d52bf8863aa2 /python/vyos | |
parent | 2a33a6f71bbbaf7a6c26278b29f583e418b38354 (diff) | |
download | vyos-1x-84b7ade286e4022e62684237246cd04b9d37b5db.tar.gz vyos-1x-84b7ade286e4022e62684237246cd04b9d37b5db.zip |
dhcp: T3100: migrate server configuration to get_config_dict()
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/template.py | 23 |
1 files changed, 23 insertions, 0 deletions
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: + # <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 |