summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-12-29 13:29:02 +0100
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2023-12-29 17:03:07 +0000
commit07294ffd83191093fc1086ff9d1949666be57971 (patch)
treedea8dc4678aa66f460efa8571dd02377c7903d58 /python
parent93427954f3abbce755847e61d0dd6471dce1bdd9 (diff)
downloadvyos-1x-07294ffd83191093fc1086ff9d1949666be57971.tar.gz
vyos-1x-07294ffd83191093fc1086ff9d1949666be57971.zip
vyos.template: T5869: first_host_address() does not honor RFC4291 section 2.6.1
The subnet router anycast address is predefined. Its format is as follows: | n bits | 128-n bits | +------------------------------------------------+----------------+ | subnet prefix | 00000000000000 | +------------------------------------------------+----------------+ The "subnet prefix" in an anycast address is the prefix that identifies a specific link. This anycast address is syntactically the same as a unicast address for an interface on the link with the interface identifier set to zero. Packets sent to the Subnet-Router anycast address will be delivered to one router on the subnet. All routers are required to support the Subnet-Router anycast addresses for the subnets to which they have interfaces. The Subnet-Router anycast address is intended to be used for applications where a node needs to communicate with any one of the set of routers. Our code as of now returns the subnet router anycast address as the first_host_address(). (cherry picked from commit cc4ce81ece57faca8ce111b8f3748389ecb40202)
Diffstat (limited to 'python')
-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):