diff --git a/fetch-root-zone.rkt b/fetch-root-zone.rkt new file mode 100644 index 0000000..482b90d --- /dev/null +++ b/fetch-root-zone.rkt @@ -0,0 +1,41 @@ +#lang racket + +(require net/url) + +(define records + (map (lambda (r) (string-split r "\t")) + (string-split (port->string + (get-pure-port + (string->url "http://www.internic.net/domain/root.zone"))) + "\n"))) + +(define (split-host-str s) + (map string->bytes/utf-8 (string-split s "."))) + +(define (split-ip-str s) + (list->vector (map string->number (string-split s ".")))) + +(pretty-write + `(list + ,@(filter values + (for/list [(r records)] + (match r + [(list "." + "" + "" + ttl-str + "IN" + "NS" + (regexp #px"^(.+)\\.$" (list _ host-str))) + `(NS/ttl '() + ',(split-host-str host-str) + ,(string->number ttl-str))] + [(list (regexp #px"^([^.]+\\.root-servers\\.net)\\.$" (list _ host-str)) + ttl-str + "IN" + "A" + ip-str) + `(A/ttl ',(split-host-str host-str) + ',(split-ip-str ip-str) + ,(string->number ttl-str))] + [_ #f]))))) diff --git a/test-dns.rkt b/test-dns.rkt index 75ce542..c4291ad 100644 --- a/test-dns.rkt +++ b/test-dns.rkt @@ -156,30 +156,30 @@ 'no-error (list (question (domain '(#"google" #"com")) '* 'in #f)) (list - (rr (domain '(#"google" #"com")) 'txt 'in 3119 '(#"v=spf1 include:_netblocks.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all")) - (rr (domain '(#"google" #"com")) 'a 'in 285 '#(74 125 226 146)) - (rr (domain '(#"google" #"com")) 'a 'in 285 '#(74 125 226 148)) - (rr (domain '(#"google" #"com")) 'a 'in 285 '#(74 125 226 145)) - (rr (domain '(#"google" #"com")) 'a 'in 285 '#(74 125 226 147)) - (rr (domain '(#"google" #"com")) 'a 'in 285 '#(74 125 226 144)) - (rr (domain '(#"google" #"com")) 'ns 'in 238877 (domain '(#"ns2" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'ns 'in 238877 (domain '(#"ns3" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'ns 'in 238877 (domain '(#"ns1" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'ns 'in 238877 (domain '(#"ns4" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'mx 'in 42 (mx 20 (domain '(#"alt1" #"aspmx" #"l" #"google" #"com")))) - (rr (domain '(#"google" #"com")) 'mx 'in 42 (mx 30 (domain '(#"alt2" #"aspmx" #"l" #"google" #"com")))) - (rr (domain '(#"google" #"com")) 'mx 'in 42 (mx 10 (domain '(#"aspmx" #"l" #"google" #"com")))) - (rr (domain '(#"google" #"com")) 'mx 'in 42 (mx 40 (domain '(#"alt3" #"aspmx" #"l" #"google" #"com")))) - (rr (domain '(#"google" #"com")) 'mx 'in 42 (mx 50 (domain '(#"alt4" #"aspmx" #"l" #"google" #"com"))))) + (rr (domain '(#"google" #"com")) 'in 3119 (rdata-txt 'txt '(#"v=spf1 include:_netblocks.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"))) + (rr (domain '(#"google" #"com")) 'in 285 (rdata-ipv4 'a '#(74 125 226 146))) + (rr (domain '(#"google" #"com")) 'in 285 (rdata-ipv4 'a '#(74 125 226 148))) + (rr (domain '(#"google" #"com")) 'in 285 (rdata-ipv4 'a '#(74 125 226 145))) + (rr (domain '(#"google" #"com")) 'in 285 (rdata-ipv4 'a '#(74 125 226 147))) + (rr (domain '(#"google" #"com")) 'in 285 (rdata-ipv4 'a '#(74 125 226 144))) + (rr (domain '(#"google" #"com")) 'in 238877 (rdata-domain 'ns (domain '(#"ns2" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 238877 (rdata-domain 'ns (domain '(#"ns3" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 238877 (rdata-domain 'ns (domain '(#"ns1" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 238877 (rdata-domain 'ns (domain '(#"ns4" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 42 (rdata-mx 'mx 20 (domain '(#"alt1" #"aspmx" #"l" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 42 (rdata-mx 'mx 30 (domain '(#"alt2" #"aspmx" #"l" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 42 (rdata-mx 'mx 10 (domain '(#"aspmx" #"l" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 42 (rdata-mx 'mx 40 (domain '(#"alt3" #"aspmx" #"l" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 42 (rdata-mx 'mx 50 (domain '(#"alt4" #"aspmx" #"l" #"google" #"com"))))) '() (list - (rr (domain '(#"ns3" #"google" #"com")) 'a 'in 238287 '#(216 239 36 10)) - (rr (domain '(#"ns1" #"google" #"com")) 'a 'in 238287 '#(216 239 32 10)) - (rr (domain '(#"ns4" #"google" #"com")) 'a 'in 238287 '#(216 239 38 10)) - (rr (domain '(#"ns2" #"google" #"com")) 'a 'in 238287 '#(216 239 34 10)) - (rr (domain '(#"alt2" #"aspmx" #"l" #"google" #"com")) 'a 'in 240 '#(74 125 39 27)) - (rr (domain '(#"aspmx" #"l" #"google" #"com")) 'a 'in 246 '#(74 125 115 27)) - (rr (domain '(#"alt1" #"aspmx" #"l" #"google" #"com")) 'a 'in 33 '#(74 125 77 27))))) + (rr (domain '(#"ns3" #"google" #"com")) 'in 238287 (rdata-ipv4 'a '#(216 239 36 10))) + (rr (domain '(#"ns1" #"google" #"com")) 'in 238287 (rdata-ipv4 'a '#(216 239 32 10))) + (rr (domain '(#"ns4" #"google" #"com")) 'in 238287 (rdata-ipv4 'a '#(216 239 38 10))) + (rr (domain '(#"ns2" #"google" #"com")) 'in 238287 (rdata-ipv4 'a '#(216 239 34 10))) + (rr (domain '(#"alt2" #"aspmx" #"l" #"google" #"com")) 'in 240 (rdata-ipv4 'a '#(74 125 39 27))) + (rr (domain '(#"aspmx" #"l" #"google" #"com")) 'in 246 (rdata-ipv4 'a '#(74 125 115 27))) + (rr (domain '(#"alt1" #"aspmx" #"l" #"google" #"com")) 'in 33 (rdata-ipv4 'a '#(74 125 77 27)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Roundtrip tests @@ -271,7 +271,7 @@ 'no-error (list (question (domain '(#"google" #"com")) 'aaaa 'in #f)) '() - (list (rr (domain '(#"google" #"com")) 'soa 'in 594 (soa (domain '(#"ns1" #"google" #"com")) (domain '(#"dns-admin" #"google" #"com")) 1454883 7200 1800 1209600 300))) + (list (rr (domain '(#"google" #"com")) 'in 594 (rdata-soa 'soa (domain '(#"ns1" #"google" #"com")) (domain '(#"dns-admin" #"google" #"com")) 1454883 7200 1800 1209600 300))) '())) ;; Wed Jun 29 21:05:03 2011 (4e0bcbbf): UDP: localhost sent 32 bytes: @@ -318,7 +318,7 @@ 'no-recursion-available 'no-error (list (question (domain '(#"www" #"google" #"com")) 'aaaa 'in #f)) - (list (rr (domain '(#"www" #"google" #"com")) 'cname 'in 604800 (domain '(#"www" #"l" #"google" #"com")))) + (list (rr (domain '(#"www" #"google" #"com")) 'in 604800 (rdata-domain 'cname (domain '(#"www" #"l" #"google" #"com"))))) '() '())) @@ -348,8 +348,8 @@ 'no-recursion-available 'no-error (list (question (domain '(#"ipv6" #"google" #"com")) 'aaaa 'in #f)) - (list (rr (domain '(#"ipv6" #"google" #"com")) 'cname 'in 604800 (domain '(#"ipv6" #"l" #"google" #"com"))) - (rr (domain '(#"ipv6" #"l" #"google" #"com")) 'aaaa 'in 300 '#(32 1 72 96 128 15 0 0 0 0 0 0 0 0 0 104))) + (list (rr (domain '(#"ipv6" #"google" #"com")) 'in 604800 (rdata-domain 'cname (domain '(#"ipv6" #"l" #"google" #"com")))) + (rr (domain '(#"ipv6" #"l" #"google" #"com")) 'in 300 (rdata-ipv6 'aaaa '#(32 1 72 96 128 15 0 0 0 0 0 0 0 0 0 104)))) '() '())) @@ -440,24 +440,24 @@ 'recursion-available 'no-error (list (question X 'srv 'in #f)) - (list (rr X 'srv 'in 882 (srv 20 0 5269 (domain '(#"xmpp-server4" #"l" #"google" #"com")))) - (rr X 'srv 'in 882 (srv 5 0 5269 (domain '(#"xmpp-server" #"l" #"google" #"com")))) - (rr X 'srv 'in 882 (srv 20 0 5269 (domain '(#"xmpp-server1" #"l" #"google" #"com")))) - (rr X 'srv 'in 882 (srv 20 0 5269 (domain '(#"xmpp-server2" #"l" #"google" #"com")))) - (rr X 'srv 'in 882 (srv 20 0 5269 (domain '(#"xmpp-server3" #"l" #"google" #"com"))))) - (list (rr (domain '(#"google" #"com")) 'ns 'in 87076 (domain '(#"ns3" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'ns 'in 87076 (domain '(#"ns4" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'ns 'in 87076 (domain '(#"ns2" #"google" #"com"))) - (rr (domain '(#"google" #"com")) 'ns 'in 87076 (domain '(#"ns1" #"google" #"com")))) - (list (rr (domain '(#"xmpp-server" #"l" #"google" #"com")) 'a 'in 282 '#(74 125 153 125)) - (rr (domain '(#"xmpp-server1" #"l" #"google" #"com")) 'a 'in 1782 '#(74 125 53 125)) - (rr (domain '(#"xmpp-server2" #"l" #"google" #"com")) 'a 'in 1782 '#(74 125 47 125)) - (rr (domain '(#"xmpp-server3" #"l" #"google" #"com")) 'a 'in 1782 '#(74 125 45 125)) - (rr (domain '(#"xmpp-server4" #"l" #"google" #"com")) 'a 'in 1782 '#(74 125 45 125)) - (rr (domain '(#"ns1" #"google" #"com")) 'a 'in 2737 '#(216 239 32 10)) - (rr (domain '(#"ns2" #"google" #"com")) 'a 'in 2737 '#(216 239 34 10)) - (rr (domain '(#"ns3" #"google" #"com")) 'a 'in 2737 '#(216 239 36 10)) - (rr (domain '(#"ns4" #"google" #"com")) 'a 'in 2737 '#(216 239 38 10)))))) + (list (rr X 'in 882 (rdata-srv 'srv 20 0 5269 (domain '(#"xmpp-server4" #"l" #"google" #"com")))) + (rr X 'in 882 (rdata-srv 'srv 5 0 5269 (domain '(#"xmpp-server" #"l" #"google" #"com")))) + (rr X 'in 882 (rdata-srv 'srv 20 0 5269 (domain '(#"xmpp-server1" #"l" #"google" #"com")))) + (rr X 'in 882 (rdata-srv 'srv 20 0 5269 (domain '(#"xmpp-server2" #"l" #"google" #"com")))) + (rr X 'in 882 (rdata-srv 'srv 20 0 5269 (domain '(#"xmpp-server3" #"l" #"google" #"com"))))) + (list (rr (domain '(#"google" #"com")) 'in 87076 (rdata-domain 'ns (domain '(#"ns3" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 87076 (rdata-domain 'ns (domain '(#"ns4" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 87076 (rdata-domain 'ns (domain '(#"ns2" #"google" #"com")))) + (rr (domain '(#"google" #"com")) 'in 87076 (rdata-domain 'ns (domain '(#"ns1" #"google" #"com"))))) + (list (rr (domain '(#"xmpp-server" #"l" #"google" #"com")) 'in 282 (rdata-ipv4 'a '#(74 125 153 125))) + (rr (domain '(#"xmpp-server1" #"l" #"google" #"com")) 'in 1782 (rdata-ipv4 'a '#(74 125 53 125))) + (rr (domain '(#"xmpp-server2" #"l" #"google" #"com")) 'in 1782 (rdata-ipv4 'a '#(74 125 47 125))) + (rr (domain '(#"xmpp-server3" #"l" #"google" #"com")) 'in 1782 (rdata-ipv4 'a '#(74 125 45 125))) + (rr (domain '(#"xmpp-server4" #"l" #"google" #"com")) 'in 1782 (rdata-ipv4 'a '#(74 125 45 125))) + (rr (domain '(#"ns1" #"google" #"com")) 'in 2737 (rdata-ipv4 'a '#(216 239 32 10))) + (rr (domain '(#"ns2" #"google" #"com")) 'in 2737 (rdata-ipv4 'a '#(216 239 34 10))) + (rr (domain '(#"ns3" #"google" #"com")) 'in 2737 (rdata-ipv4 'a '#(216 239 36 10))) + (rr (domain '(#"ns4" #"google" #"com")) 'in 2737 (rdata-ipv4 'a '#(216 239 38 10))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Zone saving/loading. @@ -473,9 +473,9 @@ (let () (define rrs - (list (rr (domain '(#"a")) 'cname 'in 30 (domain '(#"b"))) - (rr (domain '(#"b")) 'cname 'in 30 (domain '(#"c"))) - (rr (domain '(#"c")) 'cname 'in 30 (domain '(#"d"))))) + (list (rr (domain '(#"a")) 'in 30 (rdata-domain 'cname (domain '(#"b")))) + (rr (domain '(#"b")) 'in 30 (rdata-domain 'cname (domain '(#"c")))) + (rr (domain '(#"c")) 'in 30 (rdata-domain 'cname (domain '(#"d")))))) (define (check-transpose ns) (define permuted (map (lambda (i) (list-ref rrs i)) ns)) (check-equal? (cname-sort permuted) rrs)) diff --git a/test-rrs.rkt b/test-rrs.rkt index ea77659..f6595f1 100644 --- a/test-rrs.rkt +++ b/test-rrs.rkt @@ -62,32 +62,32 @@ (A '(#"subns" #"example") '#(127 0 0 2)))) (define test-roots - (list (A/ttl '(#"a" #"root-servers" #"net") '#(198 41 0 4) 3600000) - (A/ttl '(#"b" #"root-servers" #"net") '#(192 228 79 201) 3600000) - (A/ttl '(#"c" #"root-servers" #"net") '#(192 33 4 12) 3600000) - (A/ttl '(#"d" #"root-servers" #"net") '#(199 7 91 13) 3600000) - (A/ttl '(#"e" #"root-servers" #"net") '#(192 203 230 10) 3600000) - (A/ttl '(#"f" #"root-servers" #"net") '#(192 5 5 241) 3600000) - (A/ttl '(#"g" #"root-servers" #"net") '#(192 112 36 4) 3600000) - (A/ttl '(#"h" #"root-servers" #"net") '#(128 63 2 53) 3600000) - (A/ttl '(#"i" #"root-servers" #"net") '#(192 36 148 17) 3600000) - (A/ttl '(#"j" #"root-servers" #"net") '#(192 58 128 30) 3600000) - (A/ttl '(#"k" #"root-servers" #"net") '#(193 0 14 129) 3600000) - (A/ttl '(#"l" #"root-servers" #"net") '#(199 7 83 42) 3600000) - (A/ttl '(#"m" #"root-servers" #"net") '#(202 12 27 33) 3600000) - (NS/ttl '() '(#"a" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"b" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"c" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"d" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"e" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"f" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"g" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"h" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"i" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"j" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"k" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"l" #"root-servers" #"net") 3600000) - (NS/ttl '() '(#"m" #"root-servers" #"net") 3600000))) + (list (NS/ttl '() '(#"a" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"b" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"c" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"d" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"e" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"f" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"g" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"h" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"i" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"j" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"k" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"l" #"root-servers" #"net") 518400) + (NS/ttl '() '(#"m" #"root-servers" #"net") 518400) + (A/ttl '(#"a" #"root-servers" #"net") '#(198 41 0 4) 518400) + (A/ttl '(#"b" #"root-servers" #"net") '#(192 228 79 201) 518400) + (A/ttl '(#"c" #"root-servers" #"net") '#(192 33 4 12) 518400) + (A/ttl '(#"d" #"root-servers" #"net") '#(199 7 91 13) 518400) + (A/ttl '(#"e" #"root-servers" #"net") '#(192 203 230 10) 518400) + (A/ttl '(#"f" #"root-servers" #"net") '#(192 5 5 241) 518400) + (A/ttl '(#"g" #"root-servers" #"net") '#(192 112 36 4) 518400) + (A/ttl '(#"h" #"root-servers" #"net") '#(198 97 190 53) 518400) + (A/ttl '(#"i" #"root-servers" #"net") '#(192 36 148 17) 518400) + (A/ttl '(#"j" #"root-servers" #"net") '#(192 58 128 30) 518400) + (A/ttl '(#"k" #"root-servers" #"net") '#(193 0 14 129) 518400) + (A/ttl '(#"l" #"root-servers" #"net") '#(199 7 83 42) 518400) + (A/ttl '(#"m" #"root-servers" #"net") '#(202 12 27 33) 518400))) (define pathological-roots (list (NS '(#"a") '(#"ns" #"b"))