summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2024-01-07 21:41:23 +0100
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2024-01-10 00:42:22 +0100
commit74ddb29c6c9ce31450234e77fd39c73d0d51c3c5 (patch)
tree9e50995c79176629e5dc5641d91e0bac24d5fb10 /python
parentdaffee2cbf001dab13799f5b2b69330162491214 (diff)
downloadvyos-1x-74ddb29c6c9ce31450234e77fd39c73d0d51c3c5.tar.gz
vyos-1x-74ddb29c6c9ce31450234e77fd39c73d0d51c3c5.zip
dhcp: T3316: Fix `listen-address` handling and add `listen-interface` as supported by Kea
Diffstat (limited to 'python')
-rw-r--r--python/vyos/template.py17
-rw-r--r--python/vyos/utils/network.py4
2 files changed, 19 insertions, 2 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index c0c09f690..1368f1f61 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -786,6 +786,23 @@ def range_to_regex(num_range):
regex = range_to_regex(num_range)
return f'({regex})'
+@register_filter('kea_address_json')
+def kea_address_json(addresses):
+ from json import dumps
+ from vyos.utils.network import is_addr_assigned
+
+ out = []
+
+ for address in addresses:
+ ifname = is_addr_assigned(address, return_ifname=True)
+
+ if not ifname:
+ continue
+
+ out.append(f'{ifname}/{address}')
+
+ return dumps(out)
+
@register_filter('kea_failover_json')
def kea_failover_json(config):
from json import dumps
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py
index 997ee6309..b782e0bd8 100644
--- a/python/vyos/utils/network.py
+++ b/python/vyos/utils/network.py
@@ -308,7 +308,7 @@ def is_ipv6_link_local(addr):
return False
-def is_addr_assigned(ip_address, vrf=None) -> bool:
+def is_addr_assigned(ip_address, vrf=None, return_ifname=False) -> bool | str:
""" Verify if the given IPv4/IPv6 address is assigned to any interface """
from netifaces import interfaces
from vyos.utils.network import get_interface_config
@@ -323,7 +323,7 @@ def is_addr_assigned(ip_address, vrf=None) -> bool:
continue
if is_intf_addr_assigned(interface, ip_address):
- return True
+ return interface if return_ifname else True
return False