summaryrefslogtreecommitdiff
path: root/python/vyos/template.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-12-30 12:01:22 +0100
committerGitHub <noreply@github.com>2023-12-30 12:01:22 +0100
commit91ec0b5f3ec909fdf0ce81e4567b31fef0608bab (patch)
treedc8b8c6073186a80e285c60f633b28042859b0aa /python/vyos/template.py
parentb37885b01968a5ff0db9e06a13ff79981cedc5c1 (diff)
parentb0754013579f6e5db9027cc5123c99ba18a700a2 (diff)
downloadvyos-1x-91ec0b5f3ec909fdf0ce81e4567b31fef0608bab.tar.gz
vyos-1x-91ec0b5f3ec909fdf0ce81e4567b31fef0608bab.zip
Merge pull request #2714 from vyos/mergify/bp/sagitta/pr-2704
vyos.template: T5869: first_host_address() does not honor RFC4291 section 2.6.1 (backport #2704)
Diffstat (limited to 'python/vyos/template.py')
-rw-r--r--python/vyos/template.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 216f967a7..119ea54d6 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):