From 31ec2b64895a5de9bfeb4d561c77e7f824431ed2 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sun, 18 Jan 2026 15:07:32 +0100 Subject: [PATCH] Add/fix reverse ipv4 --- zoneConfig.nix | 4 +++- zones/reverse-ipv4.nix | 32 +++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/zoneConfig.nix b/zoneConfig.nix index 8df1a78..d9bf773 100644 --- a/zoneConfig.nix +++ b/zoneConfig.nix @@ -13,7 +13,7 @@ let { "pvv.ntnu.no" = ./zones/pvv.ntnu.no.nix; "pvv.org" = ./zones/pvv.org.nix; - "reverse-ipv4" = ./zones/reverse-ipv4.nix; + "in-addr.arpa" = ./zones/reverse-ipv4.nix; #"reverse-ipv6" = ./zones/reverse-ipv6.nix; }; in @@ -27,4 +27,6 @@ stdenvNoCC.mkDerivation { '' + (lib.concatMapAttrsStringSep "\n" (name: path: "cp ${path} $out/zones/${name}.zone") zoneConfigs); + + # TODO: Write named.conf to include the zones, set allow-transfer, etc. } diff --git a/zones/reverse-ipv4.nix b/zones/reverse-ipv4.nix index 9feeebd..29eba02 100644 --- a/zones/reverse-ipv4.nix +++ b/zones/reverse-ipv4.nix @@ -2,11 +2,29 @@ with dns.lib.combinators; let - hosts = import ../hosts.nix; - ptrdnameSuffix = ".pvv.ntnu.no."; + pvvv4 = hostPart: "129.241.210.${toString hostPart}"; + domainSuffix = ".pvv.ntnu.no."; + flipV4 = ip: lib.concatStringsSep "." (lib.reverseList (lib.splitString "." ip)); + + pvvHostRecords = import ../pvv-subdomains.nix { inherit dns lib; }; + # Take all the A-records, and flip them to generate opposing PTR records + # TODO: Handle duplicates? + pvvHostReverseRecords = builtins.listToAttrs ( + lib.concatLists ( + lib.mapAttrsToList ( target: host: + lib.map + (aRecord: { name = flipV4 aRecord; value.PTR = [ (target + domainSuffix) ]; }) + (host.A or []) + ) pvvHostRecords + ) + ); + + additionalReverseRecords = { + "${flipV4 "129.241.210.129"}".PTR = [ "el-swd.nettel.ntnu.no." ]; # Gateway router/switch + }; in { - useOrigin = true; # Don't output fully qualified names + useOrigin = false; # Use fully qualified names SOA = { nameServer = "dvask.pvv.ntnu.no"; @@ -18,10 +36,6 @@ in "nn.unintett.no" ]; - subdomains = let - ptr = ptrdname: { PTR = [ ptrdname ]; }; - pvvptr = ptrdname: ptr (ptrdname + ptrdnameSuffix); - in { - "129" = ptr "el-swd.nettel.ntnu.no."; # Gateway router/switch - }; + # Additional + subdomains = pvvHostReverseRecords // additionalReverseRecords; }