summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-06-30 21:49:53 +0200
committerGitHub <noreply@github.com>2023-06-30 21:49:53 +0200
commit64cc7d7e3b9e2f0f8e16cb95272336062700b91f (patch)
tree8f8e16c4fe6e2b443dda0de28eaf3b608a65891e /python/vyos
parent6efdecdaa20359b56d1ff856c9f6f1f736f77a7f (diff)
parent77bce8f54bad791ea7ab6e6100ee11c97ec3dfb4 (diff)
downloadvyos-1x-64cc7d7e3b9e2f0f8e16cb95272336062700b91f.tar.gz
vyos-1x-64cc7d7e3b9e2f0f8e16cb95272336062700b91f.zip
Merge pull request #2057 from c-po/t5313-backport
bcast-relay: T5313: verify() relay interfaces have IPv4 address configured
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