From e37fe381d5aa3bcd3151d6787427aa419471eb9d Mon Sep 17 00:00:00 2001 From: niten Date: Fri, 3 Nov 2023 12:42:49 -0700 Subject: [PATCH] Change the way intToIpv4 works --- lib/lib/ip.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/lib/ip.nix b/lib/lib/ip.nix index 8d24514..e405625 100644 --- a/lib/lib/ip.nix +++ b/lib/lib/ip.nix @@ -39,8 +39,10 @@ in rec { in foldr (a: b: a + b) 0 (imap0 (i: el: (leftShift el (i * 8))) els); intToIpv4 = int: - concatStringsSep "." - (map (i: toString (bitAnd (rightShift int (i * 8)) 255)) [ 3 2 1 0 ]); + let + toComponent = i: toString (bitAnd (rightShift int (i * 8)) 255); + components = map toComponent [ 3 2 1 0 ]; + in concatStringsSep "." components; maskFromV32Network = network: let @@ -65,12 +67,13 @@ in rec { ip-int = ipv4ToInt ip; net-min = networkMinIp network; net-max = networkMaxIp network; - in (ip-int >= (ipv4ToInt (trace "MIN-IP: ${networkMinIp}" networkMinIp))) - && (ip-int <= (ipv4ToInt (trace "MIN-IP: ${networkMinIp}" networkMaxIp))); + in (ip-int >= (ipv4ToInt networkMinIp)) + && (ip-int <= (ipv4ToInt networkMaxIp)); getNetworkMask = network: toInt (elemAt (splitString "/" network) 1); getNetworkBase = network: + assert (builtins.match ".+/[0-9]+" network) != null; let ip = elemAt (splitString "/" network) 0; insignificantBits = 32 - (getNetworkMask network);