summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-07-02 12:45:25 +0200
committerGitHub <noreply@github.com>2021-07-02 12:45:25 +0200
commit15d8cc3ad93b69bcda98c8644a6e10e02cbeaf44 (patch)
tree55987b6d51c5fc9ee92689b235176df941a91f95 /python/vyos/util.py
parentc232fdc4c5464858818f1a83c35ed5d0b7fba15a (diff)
parentf480346bb8e934b1ce2e0fc3be23f7168273bba1 (diff)
downloadvyos-1x-15d8cc3ad93b69bcda98c8644a6e10e02cbeaf44.tar.gz
vyos-1x-15d8cc3ad93b69bcda98c8644a6e10e02cbeaf44.zip
Merge pull request #903 from sarthurdev/T3659_T3656
ipsec: T3656: T3659: Fix passthrough with ipv6. Fix op-mode ipsec commands. Remove python3-crypto dependency.
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py32
1 files changed, 0 insertions, 32 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 586c79fff..cf90dc74f 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -705,38 +705,6 @@ def get_all_vrfs():
data[name] = entry
return data
-def cidr_fit(cidr_a, cidr_b, both_directions = False):
- """
- Does CIDR A fit inside of CIDR B?
-
- Credit: https://gist.github.com/magnetikonline/686fde8ee0bce4d4930ce8738908a009
- """
- def split_cidr(cidr):
- part_list = cidr.split("/")
- if len(part_list) == 1:
- # if just an IP address, assume /32
- part_list.append("32")
-
- # return address and prefix size
- return part_list[0].strip(), int(part_list[1])
- def address_to_bits(address):
- # convert each octet of IP address to binary
- bit_list = [bin(int(part)) for part in address.split(".")]
-
- # join binary parts together
- # note: part[2:] to slice off the leading "0b" from bin() results
- return "".join([part[2:].zfill(8) for part in bit_list])
- def binary_network_prefix(cidr):
- # return CIDR as bits, to the length of the prefix size only (drop the rest)
- address, prefix_size = split_cidr(cidr)
- return address_to_bits(address)[:prefix_size]
-
- prefix_a = binary_network_prefix(cidr_a)
- prefix_b = binary_network_prefix(cidr_b)
- if both_directions:
- return prefix_a.startswith(prefix_b) or prefix_b.startswith(prefix_a)
- return prefix_a.startswith(prefix_b)
-
def print_error(str='', end='\n'):
"""
Print `str` to stderr, terminated with `end`.