summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-06-25 20:09:31 +0200
committerChristian Breunig <christian@breunig.cc>2023-06-25 20:25:30 +0200
commitc77e641c521c03b6098613833fe22e09b11ad23f (patch)
tree80ed85663637db90c5f7c375be7885ef14e56aa0 /python/vyos
parent9c756d5dd20ee059b76a3e8ba2d5602e5a9bbefc (diff)
downloadvyos-1x-c77e641c521c03b6098613833fe22e09b11ad23f.tar.gz
vyos-1x-c77e641c521c03b6098613833fe22e09b11ad23f.zip
bcast-relay: T5313: verify() relay interfaces have IPv4 address configured
(cherry picked from commit ca7c063666c038d104082542f04ead6062e79246)
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/validate.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/python/vyos/validate.py b/python/vyos/validate.py
index 9aa23d3dc..83862b722 100644
--- a/python/vyos/validate.py
+++ b/python/vyos/validate.py
@@ -111,6 +111,24 @@ def is_addr_assigned(addr):
return False
+def is_afi_configured(interface, afi):
+ """ Check if given address family is configured, or in other words - an IP
+ address is assigned to the interface. """
+ from netifaces import ifaddresses
+ from netifaces import AF_INET
+ from netifaces import AF_INET6
+
+ if afi not in [AF_INET, AF_INET6]:
+ raise ValueError('Address family must be in [AF_INET, AF_INET6]')
+
+ try:
+ addresses = ifaddresses(interface)
+ except ValueError as e:
+ print(e)
+ return False
+
+ return afi in addresses
+
def is_loopback_addr(addr):
""" Check if supplied IPv4/IPv6 address is a loopback address """
from ipaddress import ip_address