diff options
author | Christian Breunig <christian@breunig.cc> | 2023-12-29 18:01:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-29 18:01:58 +0100 |
commit | 5eab80d53be9c2a05d27a0e011949f7e4a9e38dd (patch) | |
tree | f5826cb28226fde5ca744699e75364761d2c6bc9 /python | |
parent | 5b3b79410dca8753e76692b80b84cadab8357031 (diff) | |
parent | 80e2e80b5504d1da643a0d5c9772a1f9dee0aa99 (diff) | |
download | vyos-1x-5eab80d53be9c2a05d27a0e011949f7e4a9e38dd.tar.gz vyos-1x-5eab80d53be9c2a05d27a0e011949f7e4a9e38dd.zip |
Merge pull request #2704 from c-po/template-t5869
vyos.template: T5869: first_host_address() does not honor RFC4291 section 2.6.1
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/template.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 77b6a5ab0..29ea0889b 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -316,20 +316,15 @@ def is_ipv6(text): except: return False @register_filter('first_host_address') -def first_host_address(text): +def first_host_address(prefix): """ Return first usable (host) IP address from given prefix. Example: - 10.0.0.0/24 -> 10.0.0.1 - 2001:db8::/64 -> 2001:db8:: """ from ipaddress import ip_interface - from ipaddress import IPv4Network - from ipaddress import IPv6Network - - addr = ip_interface(text) - if addr.version == 4: - return str(addr.ip +1) - return str(addr.ip) + tmp = ip_interface(prefix).network + return str(tmp.network_address +1) @register_filter('last_host_address') def last_host_address(text): |