Skip to content

Fix mkReverseRecord for ::1 and 1:: being twice as long, add mkIpv4ReverseRecord, rename mkReverseRecord to mkIPv6ReverseRecord #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ rec {
inherit (dns)
combinators
evalZone
mkReverseRecord
mkIPv4ReverseRecord
mkIPv6ReverseRecord
types
;

Expand Down
2 changes: 1 addition & 1 deletion dns/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ in

inherit combinators;

inherit (dnslib.util) mkReverseRecord;
inherit (dnslib.util) mkIPv4ReverseRecord mkIPv6ReverseRecord;
}
26 changes: 21 additions & 5 deletions dns/util/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,34 @@ let

# : str -> [ str ]
# Returns the record of the ipv6 as a list
mkRecordAux = v6:
mkIPv6RecordAux = v6:
let
splitted = lib.splitString ":" v6;
v6' = if lib.hasPrefix "::" v6 then
"0${v6}"
else if lib.hasSuffix "::" v6 then
"${v6}0"
else
v6;
splitted = lib.splitString ":" v6';
n = 8 - builtins.length (lib.filter (x: x != "") splitted);
in
lib.stringToCharacters (lib.concatMapStrings (align4BytesOrExpand n) splitted);

# : str -> str
# Returns the reversed record of the ipv6
mkReverseRecord = v6:
lib.concatStringsSep "." (lib.reverseList (mkRecordAux v6)) + ".ip6.arpa";
mkIPv6ReverseRecord = v6:
lib.concatStringsSep "." (lib.reverseList (mkIPv6RecordAux v6)) + ".ip6.arpa";

# : str -> str
# Returns the reversed record of the ipv4
mkIPv4ReverseRecord = v4:
lib.concatStringsSep "." (
lib.reverseList (
lib.filter lib.isString (
lib.splitString "." v4
)
)
) + ".in-addr.arpa";
in {
inherit writeCharacterString mkReverseRecord;
inherit writeCharacterString mkIPv4ReverseRecord mkIPv6ReverseRecord;
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
inherit (dns) evalZone;
inherit (dns) combinators;
inherit (dns) types;
inherit (dns) mkReverseRecord;
inherit (dns) mkIPv4ReverseRecord mkIPv6ReverseRecord;
toString = name: zone: builtins.toString (dns.evalZone name zone);
} // dns.combinators;

Expand Down