summaryrefslogtreecommitdiff
path: root/python/vyos/utils
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2022-12-16 11:41:33 +0100
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2023-12-08 00:29:38 +0100
commitd95200e96763e4a7ed02577b1b177c84abb77838 (patch)
treeee6389af45a012f4a48bdaae5375873444061e96 /python/vyos/utils
parentee5c78e966d3b6e98e7b4f94acb4ef88094b5e54 (diff)
downloadvyos-1x-d95200e96763e4a7ed02577b1b177c84abb77838.tar.gz
vyos-1x-d95200e96763e4a7ed02577b1b177c84abb77838.zip
dhcp: T3316: Migrate dhcp/dhcpv6 server to Kea
Diffstat (limited to 'python/vyos/utils')
-rw-r--r--python/vyos/utils/file.py8
-rw-r--r--python/vyos/utils/network.py34
2 files changed, 42 insertions, 0 deletions
diff --git a/python/vyos/utils/file.py b/python/vyos/utils/file.py
index 9f27a7fb9..2af87a0ca 100644
--- a/python/vyos/utils/file.py
+++ b/python/vyos/utils/file.py
@@ -141,6 +141,14 @@ def chmod_2775(path):
bitmask = S_ISGID | S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
chmod(path, bitmask)
+def chmod_775(path):
+ """ Make file executable by all """
+ from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IXOTH
+
+ bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | \
+ S_IROTH | S_IXOTH
+ chmod(path, bitmask)
+
def makedir(path, user=None, group=None):
if os.path.exists(path):
return
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py
index 2a0808fca..abc3d4e5b 100644
--- a/python/vyos/utils/network.py
+++ b/python/vyos/utils/network.py
@@ -519,3 +519,37 @@ def get_vxlan_vni_filter(interface: str) -> list:
os_configured_vnis.append(str(vniStart))
return os_configured_vnis
+
+# Calculate prefix length of an IPv6 range, where possible
+# Python-ified from source: https://gitlab.isc.org/isc-projects/dhcp/-/blob/master/keama/confparse.c#L4591
+def ipv6_prefix_length(low, high):
+ import socket
+
+ bytemasks = [0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff]
+
+ try:
+ lo = bytearray(socket.inet_pton(socket.AF_INET6, low))
+ hi = bytearray(socket.inet_pton(socket.AF_INET6, high))
+ except:
+ return None
+
+ xor = bytearray(a ^ b for a, b in zip(lo, hi))
+
+ plen = 0
+ while plen < 128 and xor[plen // 8] == 0:
+ plen += 8
+
+ if plen == 128:
+ return plen
+
+ for i in range((plen // 8) + 1, 16):
+ if xor[i] != 0:
+ return None
+
+ for i in range(8):
+ msk = ~xor[plen // 8] & 0xff
+
+ if msk == bytemasks[i]:
+ return plen + i + 1
+
+ return None