lib.krebs.genipv6: use normalize-ip6-addr
This commit is contained in:
parent
b6e1cef6a5
commit
cee44811cd
|
@ -3,18 +3,16 @@ with lib;
|
||||||
let {
|
let {
|
||||||
body = netname: subnetname: suffixSpec: rec {
|
body = netname: subnetname: suffixSpec: rec {
|
||||||
address = let
|
address = let
|
||||||
suffix' =
|
suffix' = prependZeros suffixLength suffix;
|
||||||
if hasEmptyGroup (parseAddress suffix)
|
|
||||||
then suffix
|
|
||||||
else joinAddress "::" suffix;
|
|
||||||
in
|
in
|
||||||
checkAddress addressLength (joinAddress subnetPrefix suffix');
|
normalize-ip6-addr
|
||||||
|
(checkAddress addressLength (joinAddress subnetPrefix suffix'));
|
||||||
addressCIDR = "${address}/${toString addressLength}";
|
addressCIDR = "${address}/${toString addressLength}";
|
||||||
addressLength = 128;
|
addressLength = 128;
|
||||||
|
|
||||||
inherit netname;
|
inherit netname;
|
||||||
netCIDR = "${netAddress}/${toString netPrefixLength}";
|
netCIDR = "${netAddress}/${toString netPrefixLength}";
|
||||||
netAddress = joinAddress netPrefix "::";
|
netAddress = appendZeros netPrefixLength netPrefix;
|
||||||
netHash = toString {
|
netHash = toString {
|
||||||
retiolum = 0;
|
retiolum = 0;
|
||||||
wirelum = 1;
|
wirelum = 1;
|
||||||
|
@ -27,22 +25,35 @@ let {
|
||||||
|
|
||||||
inherit subnetname;
|
inherit subnetname;
|
||||||
subnetCIDR = "${subnetAddress}/${toString subnetPrefixLength}";
|
subnetCIDR = "${subnetAddress}/${toString subnetPrefixLength}";
|
||||||
subnetAddress = joinAddress subnetPrefix "::";
|
subnetAddress = appendZeros subnetPrefixLength subnetPrefix;
|
||||||
subnetHash = simplify (hash 4 subnetname);
|
subnetHash = hash 4 subnetname;
|
||||||
subnetPrefix = joinAddress netPrefix subnetHash;
|
subnetPrefix = joinAddress netPrefix subnetHash;
|
||||||
subnetPrefixLength = netPrefixLength + 16;
|
subnetPrefixLength = netPrefixLength + 16;
|
||||||
|
|
||||||
suffix = getAttr (typeOf suffixSpec) {
|
suffix = getAttr (typeOf suffixSpec) {
|
||||||
set =
|
set =
|
||||||
concatMapStringsSep
|
concatStringsSep
|
||||||
":"
|
":"
|
||||||
simplify
|
(stringToGroupsOf 4 (hash (suffixLength / 4) suffixSpec.hostName));
|
||||||
(stringToGroupsOf 4 (hash (suffixLength / 8) suffixSpec.hostName));
|
|
||||||
string = suffixSpec;
|
string = suffixSpec;
|
||||||
};
|
};
|
||||||
suffixLength = addressLength - subnetPrefixLength;
|
suffixLength = addressLength - subnetPrefixLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
appendZeros = n: s: let
|
||||||
|
n' = n / 16;
|
||||||
|
zeroCount = n' - length parsedaddr;
|
||||||
|
parsedaddr = parseAddress s;
|
||||||
|
in
|
||||||
|
formatAddress (parsedaddr ++ map (const "0") (range 1 zeroCount));
|
||||||
|
|
||||||
|
prependZeros = n: s: let
|
||||||
|
n' = n / 16;
|
||||||
|
zeroCount = n' - length parsedaddr;
|
||||||
|
parsedaddr = parseAddress s;
|
||||||
|
in
|
||||||
|
formatAddress (map (const "0") (range 1 zeroCount) ++ parsedaddr);
|
||||||
|
|
||||||
# Split string into list of chunks where each chunk is at most n chars long.
|
# Split string into list of chunks where each chunk is at most n chars long.
|
||||||
# The leftmost chunk might shorter.
|
# The leftmost chunk might shorter.
|
||||||
# Example: stringToGroupsOf "123456" -> ["12" "3456"]
|
# Example: stringToGroupsOf "123456" -> ["12" "3456"]
|
||||||
|
@ -64,8 +75,6 @@ let {
|
||||||
in
|
in
|
||||||
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
|
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
|
||||||
|
|
||||||
simplify = s: head (match "0*(.+)" s);
|
|
||||||
|
|
||||||
hash = n: s: substring 0 n (hashString "sha256" s);
|
hash = n: s: substring 0 n (hashString "sha256" s);
|
||||||
|
|
||||||
dropLast = n: xs: reverseList (drop n (reverseList xs));
|
dropLast = n: xs: reverseList (drop n (reverseList xs));
|
||||||
|
|
Loading…
Reference in a new issue