diff options
author | Christian Breunig <christian@breunig.cc> | 2023-06-25 20:09:31 +0200 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2023-06-25 20:10:10 +0200 |
commit | ca7c063666c038d104082542f04ead6062e79246 (patch) | |
tree | 41225045b8bd44bdd8f51f8677365d1bd966b4d9 /python | |
parent | 800c3161bffc40cc46833925ec5aa50f30231476 (diff) | |
download | vyos-1x-ca7c063666c038d104082542f04ead6062e79246.tar.gz vyos-1x-ca7c063666c038d104082542f04ead6062e79246.zip |
bcast-relay: T5313: verify() relay interfaces have IPv4 address configured
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/validate.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/python/vyos/validate.py b/python/vyos/validate.py index d18785aaf..e5d8c6043 100644 --- a/python/vyos/validate.py +++ b/python/vyos/validate.py @@ -98,7 +98,7 @@ def is_intf_addr_assigned(intf, address) -> bool: return False def is_addr_assigned(ip_address, vrf=None) -> bool: - """ Verify if the given IPv4/IPv6 address is assigned to any interfac """ + """ Verify if the given IPv4/IPv6 address is assigned to any interface """ from netifaces import interfaces from vyos.util import get_interface_config from vyos.util import dict_search @@ -115,6 +115,24 @@ def is_addr_assigned(ip_address, vrf=None) -> bool: 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 |