diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-11-13 12:00:45 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-11-13 12:00:45 +0100 |
commit | 943a4a5016cfc75a352bb3711b5c4c8bfe32b740 (patch) | |
tree | a91dd19baefe5128851929760079ba2a54d09454 /python/vyos | |
parent | 62320efc3866fa582852258846c15bfa09a92720 (diff) | |
download | vyos-1x-943a4a5016cfc75a352bb3711b5c4c8bfe32b740.tar.gz vyos-1x-943a4a5016cfc75a352bb3711b5c4c8bfe32b740.zip |
openvpn: T3051: fix creation of ifconfig-pool for client communication
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/template.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 389f6927f..53e1dc1b5 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -190,11 +190,23 @@ def vyos_last_host_address(text): return str(IPv6Network(addr).broadcast_address) @register_filter('inc_ip') -def vyos_inc_ip(text, increment): - """ Return first usable IP address from given prefix. - Example: - - 10.0.0.0/24 -> 10.0.0.1 - - 2001:db8::/64 -> 2001:db8::1 +def vyos_inc_ip(address, increment): + """ Increment given IP address by 'increment' + + Example (inc by 2): + - 10.0.0.0/24 -> 10.0.0.2 + - 2001:db8::/64 -> 2001:db8::2 + """ + from ipaddress import ip_interface + return str(ip_interface(address).ip + int(increment)) + +@register_filter('dec_ip') +def vyos_dec_ip(address, decrement): + """ Decrement given IP address by 'decrement' + + Example (inc by 2): + - 10.0.0.0/24 -> 10.0.0.2 + - 2001:db8::/64 -> 2001:db8::2 """ from ipaddress import ip_interface - return str(ip_interface(text).ip + int(increment)) + return str(ip_interface(address).ip - int(decrement)) |