dnsruby 1.55 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +96 -0
- data/Rakefile +30 -29
- data/demo/axfr.rb +93 -93
- data/demo/check_soa.rb +99 -99
- data/demo/check_zone.rb +59 -59
- data/demo/digdlv.rb +43 -43
- data/demo/digroot.rb +34 -34
- data/demo/example_recurse.rb +14 -14
- data/demo/mresolv.rb +30 -30
- data/demo/mx.rb +31 -31
- data/demo/rubydig.rb +37 -37
- data/demo/to_resolve.txt +3088 -3088
- data/demo/trace_dns.rb +46 -46
- data/lib/dnsruby.rb +161 -526
- data/lib/dnsruby/DNS.rb +305 -0
- data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
- data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
- data/lib/dnsruby/code_mappers.rb +295 -0
- data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
- data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
- data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
- data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
- data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
- data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
- data/lib/dnsruby/message/decoder.rb +164 -0
- data/lib/dnsruby/message/encoder.rb +75 -0
- data/lib/dnsruby/message/header.rb +249 -0
- data/lib/dnsruby/message/message.rb +629 -0
- data/lib/dnsruby/message/question.rb +86 -0
- data/lib/dnsruby/message/section.rb +96 -0
- data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
- data/lib/dnsruby/packet_sender.rb +661 -0
- data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
- data/lib/dnsruby/resolv.rb +113 -0
- data/lib/dnsruby/resolver.rb +1192 -0
- data/lib/dnsruby/resource/A.rb +56 -0
- data/lib/dnsruby/resource/AAAA.rb +54 -0
- data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
- data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
- data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
- data/lib/dnsruby/resource/DLV.rb +27 -0
- data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
- data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
- data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
- data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
- data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
- data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
- data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
- data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
- data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
- data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
- data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
- data/lib/dnsruby/resource/NSEC.rb +275 -0
- data/lib/dnsruby/resource/NSEC3.rb +332 -0
- data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
- data/lib/dnsruby/resource/OPT.rb +272 -0
- data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
- data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
- data/lib/dnsruby/resource/RR.rb +421 -0
- data/lib/dnsruby/resource/RRSIG.rb +275 -0
- data/lib/dnsruby/resource/RRSet.rb +190 -0
- data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
- data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
- data/lib/dnsruby/resource/SPF.rb +29 -0
- data/lib/dnsruby/resource/SRV.rb +112 -0
- data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
- data/lib/dnsruby/resource/TKEY.rb +163 -0
- data/lib/dnsruby/resource/TSIG.rb +593 -0
- data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
- data/lib/dnsruby/resource/X25.rb +55 -0
- data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
- data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
- data/lib/dnsruby/resource/resource.rb +25 -0
- data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
- data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
- data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
- data/lib/dnsruby/the_log.rb +44 -0
- data/lib/dnsruby/update.rb +278 -0
- data/lib/dnsruby/validator_thread.rb +124 -0
- data/lib/dnsruby/version.rb +3 -0
- data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
- data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
- data/test/spec_helper.rb +16 -0
- data/test/tc_axfr.rb +31 -34
- data/test/tc_cache.rb +32 -32
- data/test/tc_dlv.rb +28 -28
- data/test/tc_dns.rb +73 -76
- data/test/tc_dnskey.rb +31 -32
- data/test/tc_dnsruby.rb +50 -44
- data/test/tc_ds.rb +36 -36
- data/test/tc_escapedchars.rb +252 -255
- data/test/tc_hash.rb +17 -21
- data/test/tc_header.rb +48 -57
- data/test/tc_hip.rb +19 -22
- data/test/tc_ipseckey.rb +18 -21
- data/test/tc_keith.rb +300 -0
- data/test/tc_message.rb +87 -0
- data/test/tc_misc.rb +83 -87
- data/test/tc_name.rb +81 -84
- data/test/tc_naptr.rb +18 -21
- data/test/tc_nsec.rb +55 -55
- data/test/tc_nsec3.rb +23 -24
- data/test/tc_nsec3param.rb +20 -21
- data/test/tc_packet.rb +90 -93
- data/test/tc_packet_unique_push.rb +48 -51
- data/test/tc_question.rb +30 -33
- data/test/tc_queue.rb +16 -17
- data/test/tc_recur.rb +16 -17
- data/test/tc_res_config.rb +38 -41
- data/test/tc_res_env.rb +29 -32
- data/test/tc_res_file.rb +26 -29
- data/test/tc_res_opt.rb +62 -65
- data/test/tc_resolver.rb +287 -242
- data/test/tc_rr-opt.rb +70 -63
- data/test/tc_rr-txt.rb +68 -71
- data/test/tc_rr-unknown.rb +45 -48
- data/test/tc_rr.rb +76 -70
- data/test/tc_rrset.rb +21 -22
- data/test/tc_rrsig.rb +19 -20
- data/test/tc_single_resolver.rb +294 -297
- data/test/tc_soak.rb +199 -202
- data/test/tc_soak_base.rb +29 -34
- data/test/tc_sshfp.rb +20 -23
- data/test/tc_tcp.rb +32 -35
- data/test/tc_tkey.rb +41 -44
- data/test/tc_tsig.rb +81 -84
- data/test/tc_update.rb +108 -111
- data/test/tc_validator.rb +29 -29
- data/test/tc_verifier.rb +81 -82
- data/test/ts_dnsruby.rb +16 -15
- data/test/ts_offline.rb +62 -63
- data/test/ts_online.rb +115 -115
- metadata +155 -90
- data/README +0 -59
- data/lib/Dnsruby/DNS.rb +0 -305
- data/lib/Dnsruby/PacketSender.rb +0 -656
- data/lib/Dnsruby/Resolver.rb +0 -1189
- data/lib/Dnsruby/TheLog.rb +0 -44
- data/lib/Dnsruby/message.rb +0 -1230
- data/lib/Dnsruby/resource/A.rb +0 -56
- data/lib/Dnsruby/resource/AAAA.rb +0 -54
- data/lib/Dnsruby/resource/DLV.rb +0 -27
- data/lib/Dnsruby/resource/NSEC.rb +0 -298
- data/lib/Dnsruby/resource/NSEC3.rb +0 -340
- data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
- data/lib/Dnsruby/resource/OPT.rb +0 -213
- data/lib/Dnsruby/resource/RRSIG.rb +0 -275
- data/lib/Dnsruby/resource/SPF.rb +0 -29
- data/lib/Dnsruby/resource/SRV.rb +0 -112
- data/lib/Dnsruby/resource/TKEY.rb +0 -163
- data/lib/Dnsruby/resource/TSIG.rb +0 -593
- data/lib/Dnsruby/resource/X25.rb +0 -55
- data/lib/Dnsruby/resource/resource.rb +0 -678
- data/lib/Dnsruby/update.rb +0 -278
- data/lib/Dnsruby/validator_thread.rb +0 -124
@@ -1,118 +1,118 @@
|
|
1
|
-
|
2
|
-
#Copyright 2007 Nominet UK
|
3
|
-
#
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
#you may not use this file except in compliance with the License.
|
6
|
-
#You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
#See the License for the specific language governing permissions and
|
14
|
-
#limitations under the License.
|
15
|
-
|
1
|
+
# --
|
2
|
+
# Copyright 2007 Nominet UK
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
16
|
module Dnsruby
|
17
|
-
#Dnsruby::Recursor - Perform recursive dns lookups
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#This module uses a Dnsruby::Resolver to perform recursive queries.
|
24
|
-
#
|
25
|
-
|
26
|
-
#
|
27
|
-
#Rob Brown, bbb@cpan.org
|
28
|
-
#Alex Dalitz, alexd@nominet.org.uk
|
29
|
-
#
|
30
|
-
|
31
|
-
#
|
32
|
-
#Dnsruby::Resolver,
|
33
|
-
#
|
34
|
-
|
35
|
-
#
|
36
|
-
#Copyright (c) 2002, Rob Brown. All rights reserved.
|
37
|
-
#Portions Copyright (c) 2005, Olaf M Kolkman.
|
38
|
-
#Ruby version with caching and validation Copyright (c) 2008, AlexD (Nominet UK)
|
39
|
-
#
|
40
|
-
#Example lookup process:
|
41
|
-
#
|
42
|
-
#[root@box root]# dig +trace www.rob.com.au.
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#au. 172800 IN NS NS2.BERKELEY.EDU.
|
64
|
-
#au. 172800 IN NS NS1.BERKELEY.EDU.
|
65
|
-
#au. 172800 IN NS NS.UU.NET.
|
66
|
-
#au. 172800 IN NS BOX2.AUNIC.NET.
|
67
|
-
#au. 172800 IN NS SEC1.APNIC.NET.
|
68
|
-
#au. 172800 IN NS SEC3.APNIC.NET.
|
69
|
-
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#com.au. 259200 IN NS ns4.ausregistry.net.
|
74
|
-
#com.au. 259200 IN NS dns1.telstra.net.
|
75
|
-
#com.au. 259200 IN NS au2ld.CSIRO.au.
|
76
|
-
#com.au. 259200 IN NS audns01.syd.optus.net.
|
77
|
-
#com.au. 259200 IN NS ns.ripe.net.
|
78
|
-
#com.au. 259200 IN NS ns1.ausregistry.net.
|
79
|
-
#com.au. 259200 IN NS ns2.ausregistry.net.
|
80
|
-
#com.au. 259200 IN NS ns3.ausregistry.net.
|
81
|
-
#com.au. 259200 IN NS ns3.melbourneit.com.
|
82
|
-
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#com.au. 259200 IN NS ns1.ausregistry.net.
|
87
|
-
#com.au. 259200 IN NS ns2.ausregistry.net.
|
88
|
-
#com.au. 259200 IN NS ns3.ausregistry.net.
|
89
|
-
#com.au. 259200 IN NS ns4.ausregistry.net.
|
90
|
-
#com.au. 259200 IN NS ns3.melbourneit.com.
|
91
|
-
#com.au. 259200 IN NS dns1.telstra.net.
|
92
|
-
#com.au. 259200 IN NS au2ld.CSIRO.au.
|
93
|
-
#com.au. 259200 IN NS ns.ripe.net.
|
94
|
-
#com.au. 259200 IN NS audns01.syd.optus.net.
|
95
|
-
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#rob.com.au. 86400 IN NS sy-dns02.tmns.net.au.
|
102
|
-
#rob.com.au. 86400 IN NS sy-dns01.tmns.net.au.
|
103
|
-
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#www.rob.com.au. 7200 IN A 139.134.5.123
|
108
|
-
#rob.com.au. 7200 IN NS sy-dns01.tmns.net.au.
|
109
|
-
#rob.com.au. 7200 IN NS sy-dns02.tmns.net.au.
|
110
|
-
|
111
|
-
#
|
112
|
-
#
|
17
|
+
# Dnsruby::Recursor - Perform recursive dns lookups
|
18
|
+
#
|
19
|
+
# require 'Dnsruby'
|
20
|
+
# rec = Dnsruby::Recursor.new()
|
21
|
+
# answer = rec.recurse("rob.com.au")
|
22
|
+
#
|
23
|
+
# This module uses a Dnsruby::Resolver to perform recursive queries.
|
24
|
+
#
|
25
|
+
# === AUTHOR
|
26
|
+
#
|
27
|
+
# Rob Brown, bbb@cpan.org
|
28
|
+
# Alex Dalitz, alexd@nominet.org.uk
|
29
|
+
#
|
30
|
+
# === SEE ALSO
|
31
|
+
#
|
32
|
+
# Dnsruby::Resolver,
|
33
|
+
#
|
34
|
+
# === COPYRIGHT
|
35
|
+
#
|
36
|
+
# Copyright (c) 2002, Rob Brown. All rights reserved.
|
37
|
+
# Portions Copyright (c) 2005, Olaf M Kolkman.
|
38
|
+
# Ruby version with caching and validation Copyright (c) 2008, AlexD (Nominet UK)
|
39
|
+
#
|
40
|
+
# Example lookup process:
|
41
|
+
#
|
42
|
+
# [root@box root]# dig +trace www.rob.com.au.
|
43
|
+
#
|
44
|
+
# ; <<>> DiG 9.2.0 <<>> +trace www.rob.com.au.
|
45
|
+
# ;; global options: printcmd
|
46
|
+
# . 507343 IN NS C.ROOT-SERVERS.NET.
|
47
|
+
# . 507343 IN NS D.ROOT-SERVERS.NET.
|
48
|
+
# . 507343 IN NS E.ROOT-SERVERS.NET.
|
49
|
+
# . 507343 IN NS F.ROOT-SERVERS.NET.
|
50
|
+
# . 507343 IN NS G.ROOT-SERVERS.NET.
|
51
|
+
# . 507343 IN NS H.ROOT-SERVERS.NET.
|
52
|
+
# . 507343 IN NS I.ROOT-SERVERS.NET.
|
53
|
+
# . 507343 IN NS J.ROOT-SERVERS.NET.
|
54
|
+
# . 507343 IN NS K.ROOT-SERVERS.NET.
|
55
|
+
# . 507343 IN NS L.ROOT-SERVERS.NET.
|
56
|
+
# . 507343 IN NS M.ROOT-SERVERS.NET.
|
57
|
+
# . 507343 IN NS A.ROOT-SERVERS.NET.
|
58
|
+
# . 507343 IN NS B.ROOT-SERVERS.NET.
|
59
|
+
# ;; Received 436 bytes from 127.0.0.1#53(127.0.0.1) in 9 ms
|
60
|
+
# ;;; But these should be hard coded as the hints
|
61
|
+
#
|
62
|
+
# ;;; Ask H.ROOT-SERVERS.NET gave:
|
63
|
+
# au. 172800 IN NS NS2.BERKELEY.EDU.
|
64
|
+
# au. 172800 IN NS NS1.BERKELEY.EDU.
|
65
|
+
# au. 172800 IN NS NS.UU.NET.
|
66
|
+
# au. 172800 IN NS BOX2.AUNIC.NET.
|
67
|
+
# au. 172800 IN NS SEC1.APNIC.NET.
|
68
|
+
# au. 172800 IN NS SEC3.APNIC.NET.
|
69
|
+
# ;; Received 300 bytes from 128.63.2.53#53(H.ROOT-SERVERS.NET) in 322 ms
|
70
|
+
# ;;; A little closer than before
|
71
|
+
#
|
72
|
+
# ;;; Ask NS2.BERKELEY.EDU gave:
|
73
|
+
# com.au. 259200 IN NS ns4.ausregistry.net.
|
74
|
+
# com.au. 259200 IN NS dns1.telstra.net.
|
75
|
+
# com.au. 259200 IN NS au2ld.CSIRO.au.
|
76
|
+
# com.au. 259200 IN NS audns01.syd.optus.net.
|
77
|
+
# com.au. 259200 IN NS ns.ripe.net.
|
78
|
+
# com.au. 259200 IN NS ns1.ausregistry.net.
|
79
|
+
# com.au. 259200 IN NS ns2.ausregistry.net.
|
80
|
+
# com.au. 259200 IN NS ns3.ausregistry.net.
|
81
|
+
# com.au. 259200 IN NS ns3.melbourneit.com.
|
82
|
+
# ;; Received 387 bytes from 128.32.206.12#53(NS2.BERKELEY.EDU) in 10312 ms
|
83
|
+
# ;;; A little closer than before
|
84
|
+
#
|
85
|
+
# ;;; Ask ns4.ausregistry.net gave:
|
86
|
+
# com.au. 259200 IN NS ns1.ausregistry.net.
|
87
|
+
# com.au. 259200 IN NS ns2.ausregistry.net.
|
88
|
+
# com.au. 259200 IN NS ns3.ausregistry.net.
|
89
|
+
# com.au. 259200 IN NS ns4.ausregistry.net.
|
90
|
+
# com.au. 259200 IN NS ns3.melbourneit.com.
|
91
|
+
# com.au. 259200 IN NS dns1.telstra.net.
|
92
|
+
# com.au. 259200 IN NS au2ld.CSIRO.au.
|
93
|
+
# com.au. 259200 IN NS ns.ripe.net.
|
94
|
+
# com.au. 259200 IN NS audns01.syd.optus.net.
|
95
|
+
# ;; Received 259 bytes from 137.39.1.3#53(ns4.ausregistry.net) in 606 ms
|
96
|
+
# ;;; Uh... yeah... I already knew this
|
97
|
+
# ;;; from what NS2.BERKELEY.EDU told me.
|
98
|
+
# ;;; ns4.ausregistry.net must have brain damage
|
99
|
+
#
|
100
|
+
# ;;; Ask ns1.ausregistry.net gave:
|
101
|
+
# rob.com.au. 86400 IN NS sy-dns02.tmns.net.au.
|
102
|
+
# rob.com.au. 86400 IN NS sy-dns01.tmns.net.au.
|
103
|
+
# ;; Received 87 bytes from 203.18.56.41#53(ns1.ausregistry.net) in 372 ms
|
104
|
+
# ;;; Ah, much better. Something more useful.
|
105
|
+
#
|
106
|
+
# ;;; Ask sy-dns02.tmns.net.au gave:
|
107
|
+
# www.rob.com.au. 7200 IN A 139.134.5.123
|
108
|
+
# rob.com.au. 7200 IN NS sy-dns01.tmns.net.au.
|
109
|
+
# rob.com.au. 7200 IN NS sy-dns02.tmns.net.au.
|
110
|
+
# ;; Received 135 bytes from 139.134.2.18#53(sy-dns02.tmns.net.au) in 525 ms
|
111
|
+
# ;;; FINALLY, THE ANSWER!
|
112
|
+
# Now,DNSSEC validation is performed (unless disabled).
|
113
113
|
class Recursor
|
114
114
|
class AddressCache # :nodoc: all
|
115
|
-
#
|
115
|
+
# Like an array, but stores the expiration of each record.
|
116
116
|
def initialize(*args)
|
117
117
|
@hash = Hash.new # stores addresses against their expiration
|
118
118
|
@mutex = Mutex.new # This class is thread-safe
|
@@ -154,16 +154,16 @@ module Dnsruby
|
|
154
154
|
end
|
155
155
|
attr_accessor :nameservers, :callback, :recurse, :ipv6_ok
|
156
156
|
attr_reader :hints
|
157
|
-
#
|
157
|
+
# The resolver to use for the queries
|
158
158
|
attr_accessor :resolver
|
159
159
|
|
160
|
-
#
|
160
|
+
# For guarding access to shared caches.
|
161
161
|
@@mutex = Mutex.new # :nodoc: all
|
162
162
|
@@hints = nil
|
163
163
|
@@authority_cache = Hash.new
|
164
164
|
@@zones_cache = nil
|
165
165
|
@@nameservers = nil
|
166
|
-
|
166
|
+
|
167
167
|
def initialize(res = nil)
|
168
168
|
if (res)
|
169
169
|
@resolver = res
|
@@ -176,18 +176,18 @@ module Dnsruby
|
|
176
176
|
end
|
177
177
|
@ipv6_ok = false
|
178
178
|
end
|
179
|
-
#Initialize the hint servers. Recursive queries need a starting name
|
180
|
-
#server to work off of. This method takes a list of IP addresses to use
|
181
|
-
#as the starting servers. These name servers should be authoritative for
|
182
|
-
#the root (.) zone.
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#If no hints are passed, the default nameserver is asked for the hints.
|
187
|
-
#Normally these IPs can be obtained from the following location:
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
179
|
+
# Initialize the hint servers. Recursive queries need a starting name
|
180
|
+
# server to work off of. This method takes a list of IP addresses to use
|
181
|
+
# as the starting servers. These name servers should be authoritative for
|
182
|
+
# the root (.) zone.
|
183
|
+
#
|
184
|
+
# res.hints=(ips)
|
185
|
+
#
|
186
|
+
# If no hints are passed, the default nameserver is asked for the hints.
|
187
|
+
# Normally these IPs can be obtained from the following location:
|
188
|
+
#
|
189
|
+
# ftp://ftp.internic.net/domain/named.root
|
190
|
+
#
|
191
191
|
def hints=(hints)
|
192
192
|
Recursor.set_hints(hints, @resolver)
|
193
193
|
end
|
@@ -214,12 +214,12 @@ module Dnsruby
|
|
214
214
|
@@hints = hints
|
215
215
|
end
|
216
216
|
TheLog.debug(";; verifying (root) zone...\n")
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
217
|
+
# bind always asks one of the hint servers
|
218
|
+
# for who it thinks is authoritative for
|
219
|
+
# the (root) zone as a sanity check.
|
220
|
+
# Nice idea.
|
221
221
|
|
222
|
-
#
|
222
|
+
# if (!@@hints || @@hints.length == 0)
|
223
223
|
resolver.recurse=(1)
|
224
224
|
packet=resolver.query_no_validation_or_recursion(".", "NS", "IN")
|
225
225
|
hints = Hash.new
|
@@ -228,7 +228,7 @@ module Dnsruby
|
|
228
228
|
ans.each do |rr|
|
229
229
|
if (rr.name.to_s =~ /^\.?$/ and
|
230
230
|
rr.type == Types::NS)
|
231
|
-
#
|
231
|
+
# Found root authority
|
232
232
|
server = rr.nsdname.to_s.downcase
|
233
233
|
server.sub!(/\.$/,"")
|
234
234
|
TheLog.debug(";; FOUND HINT: #{server}\n")
|
@@ -237,13 +237,13 @@ module Dnsruby
|
|
237
237
|
end
|
238
238
|
if ((packet.additional.length == 0) ||
|
239
239
|
((packet.additional.length == 1) && (packet.additional()[0].type == Types.OPT)))
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
240
|
+
# Some resolvers (e.g. 8.8.8.8) do not send an additional section -
|
241
|
+
# need to make explicit queries for these :(
|
242
|
+
# Probably best to limit the number of outstanding queries - extremely bursty behaviour otherwise
|
243
|
+
# What happens if we select only name
|
244
244
|
q = Queue.new
|
245
245
|
hints.keys.each {|server|
|
246
|
-
#
|
246
|
+
# Query for the server address and add it to hints.
|
247
247
|
['A', 'AAAA'].each {|type|
|
248
248
|
msg = Message.new
|
249
249
|
msg.do_caching = @do_caching
|
@@ -273,10 +273,10 @@ module Dnsruby
|
|
273
273
|
end
|
274
274
|
end
|
275
275
|
end
|
276
|
-
#
|
276
|
+
# foreach my $server (keys %hints) {
|
277
277
|
hints.keys.each do |server|
|
278
278
|
if (!hints[server] || hints[server].length == 0)
|
279
|
-
#
|
279
|
+
# Wipe the servers without lookups
|
280
280
|
hints.delete(server)
|
281
281
|
end
|
282
282
|
end
|
@@ -294,12 +294,12 @@ module Dnsruby
|
|
294
294
|
else
|
295
295
|
raise ResolvError.new( "Server ["+(@@nameservers)[0].to_s+".] did not give answers")
|
296
296
|
end
|
297
|
-
|
298
|
-
#
|
297
|
+
|
298
|
+
# Disable recursion flag.
|
299
299
|
resolver.recurse=(0)
|
300
|
-
#
|
301
|
-
|
302
|
-
#
|
300
|
+
# end
|
301
|
+
|
302
|
+
# return $self->nameservers( map { @{ $_ } } values %{ $self->{'hints'} } );
|
303
303
|
if (Array === @@hints)
|
304
304
|
temp = []
|
305
305
|
@@hints.each {|hint|
|
@@ -327,14 +327,14 @@ module Dnsruby
|
|
327
327
|
server.sub!(/\.$/,"")
|
328
328
|
if (server)
|
329
329
|
if ( rr.type == Types::A)
|
330
|
-
#print ";; ADDITIONAL HELP: $server -> [".$rr->rdatastr."]\n" if $self->{'debug'};
|
330
|
+
# print ";; ADDITIONAL HELP: $server -> [".$rr->rdatastr."]\n" if $self->{'debug'};
|
331
331
|
if (hints[server]!=nil)
|
332
332
|
TheLog.debug(";; STORING IP: #{server} IN A "+rr.address.to_s+"\n")
|
333
333
|
hints[server].push([rr.address.to_s, rr.ttl])
|
334
334
|
end
|
335
335
|
end
|
336
336
|
if ( rr.type == Types::AAAA)
|
337
|
-
#print ";; ADDITIONAL HELP: $server -> [".$rr->rdatastr."]\n" if $self->{'debug'};
|
337
|
+
# print ";; ADDITIONAL HELP: $server -> [".$rr->rdatastr."]\n" if $self->{'debug'};
|
338
338
|
if (hints[server])
|
339
339
|
TheLog.debug(";; STORING IP6: #{server} IN AAAA "+rr.address.to_s+"\n")
|
340
340
|
hints[server].push([rr.address.to_s, rr.ttl])
|
@@ -343,26 +343,26 @@ module Dnsruby
|
|
343
343
|
|
344
344
|
end
|
345
345
|
end
|
346
|
-
|
347
|
-
|
348
|
-
#This method takes a code reference, which is then invoked each time a
|
349
|
-
#packet is received during the recursive lookup. For example to emulate
|
350
|
-
#dig's C<+trace> function:
|
351
|
-
#
|
352
|
-
#
|
353
|
-
#
|
354
|
-
#
|
355
|
-
#
|
356
|
-
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
#
|
346
|
+
|
347
|
+
|
348
|
+
# This method takes a code reference, which is then invoked each time a
|
349
|
+
# packet is received during the recursive lookup. For example to emulate
|
350
|
+
# dig's C<+trace> function:
|
351
|
+
#
|
352
|
+
# res.recursion_callback(Proc.new { |packet|
|
353
|
+
# print packet.additional.inspect
|
354
|
+
#
|
355
|
+
# print";; Received %d bytes from %s\n\n",
|
356
|
+
# packetanswersize,
|
357
|
+
# packet.answerfrom);
|
358
|
+
# })
|
359
|
+
#
|
360
360
|
def recursion_callback=(sub)
|
361
|
-
#
|
361
|
+
# if (sub && UNIVERSAL::isa(sub, 'CODE'))
|
362
362
|
@callback = sub
|
363
|
-
#
|
363
|
+
# end
|
364
364
|
end
|
365
|
-
|
365
|
+
|
366
366
|
def recursion_callback
|
367
367
|
return @callback
|
368
368
|
end
|
@@ -379,51 +379,51 @@ module Dnsruby
|
|
379
379
|
return query(name, type, klass, true)
|
380
380
|
end
|
381
381
|
|
382
|
-
#This method is much like the normal query() method except it disables
|
383
|
-
#the recurse flag in the packet and explicitly performs the recursion.
|
384
|
-
#
|
385
|
-
#
|
386
|
-
#
|
387
|
-
#
|
388
|
-
#The Recursor maintains a cache of known nameservers.
|
389
|
-
#DNSSEC validation is performed unless true is passed as the fourth parameter.
|
382
|
+
# This method is much like the normal query() method except it disables
|
383
|
+
# the recurse flag in the packet and explicitly performs the recursion.
|
384
|
+
#
|
385
|
+
# packet = res.query( "www.netscape.com.", "A")
|
386
|
+
# packet = res.query( "www.netscape.com.", "A", "IN", true) # no validation
|
387
|
+
#
|
388
|
+
# The Recursor maintains a cache of known nameservers.
|
389
|
+
# DNSSEC validation is performed unless true is passed as the fourth parameter.
|
390
390
|
def query(name, type=Types.A, klass=Classes.IN, no_validation = false)
|
391
|
-
#
|
392
|
-
|
393
|
-
#
|
391
|
+
# @TODO@ PROVIDE AN ASYNCHRONOUS SEND WHICH RETURNS MESSAGE WITH ERROR!!!
|
392
|
+
|
393
|
+
# Make sure the hint servers are initialized.
|
394
394
|
@@mutex.synchronize {
|
395
395
|
self.hints=(Hash.new) unless @@hints
|
396
396
|
}
|
397
397
|
@resolver.recurse=(0)
|
398
|
-
#
|
399
|
-
#
|
400
|
-
#
|
401
|
-
#
|
398
|
+
# Make sure the authority cache is clean.
|
399
|
+
# It is only used to store A and AAAA records of
|
400
|
+
# the suposedly authoritative name servers.
|
401
|
+
# TTLs are respected
|
402
402
|
@@mutex.synchronize {
|
403
403
|
if (!@@zones_cache)
|
404
404
|
Recursor.clear_caches(@resolver)
|
405
405
|
end
|
406
406
|
}
|
407
407
|
|
408
|
-
#
|
409
|
-
#
|
408
|
+
# So we have normal hashes, but the array of addresses at the end is now an AddressCache
|
409
|
+
# which respects the ttls of the A/AAAA records
|
410
410
|
|
411
|
-
#
|
412
|
-
#
|
411
|
+
# Now see if we already know the zone in question
|
412
|
+
# Otherwise, see if we know any of its parents (will know at least ".")
|
413
413
|
known_zone, known_authorities = get_closest_known_zone_authorities_for(name) # ".", @hints if nothing else
|
414
414
|
|
415
|
-
#
|
416
|
-
#
|
415
|
+
# Seed name servers with the closest known authority
|
416
|
+
# ret = _dorecursion( name, type, klass, ".", @hints, 0)
|
417
417
|
ret = _dorecursion( name, type, klass, known_zone, known_authorities, 0, no_validation)
|
418
418
|
Dnssec.validate(ret) if !no_validation
|
419
|
-
#
|
419
|
+
# print "\n\nRESPONSE:\n#{ret}\n"
|
420
420
|
return ret
|
421
421
|
end
|
422
422
|
|
423
423
|
def get_closest_known_zone_for(n) # :nodoc:
|
424
|
-
#
|
425
|
-
#
|
426
|
-
#
|
424
|
+
# Find the closest parent of name that we know
|
425
|
+
# e.g. for nominet.org.uk, try nominet.org.uk., org.uk., uk., .
|
426
|
+
# does @zones_cache contain the name we're after
|
427
427
|
if (Name === n)
|
428
428
|
n = n.to_s # @TODO@ This is a bit crap!
|
429
429
|
end
|
@@ -433,7 +433,7 @@ module Dnsruby
|
|
433
433
|
end
|
434
434
|
|
435
435
|
while (true)
|
436
|
-
#
|
436
|
+
# print "Checking for known zone : #{name}\n"
|
437
437
|
zone = nil
|
438
438
|
@@mutex.synchronize{
|
439
439
|
zone = @@zones_cache[name]
|
@@ -442,7 +442,7 @@ module Dnsruby
|
|
442
442
|
end
|
443
443
|
}
|
444
444
|
return false if name=="."
|
445
|
-
#
|
445
|
+
# strip the name up to the first dot
|
446
446
|
first_dot = name.index(".")
|
447
447
|
if (first_dot == (name.length-1))
|
448
448
|
name = "."
|
@@ -457,14 +457,14 @@ module Dnsruby
|
|
457
457
|
known_authorities, known_zone = nil
|
458
458
|
while (!done)
|
459
459
|
known_zone = get_closest_known_zone_for(name)
|
460
|
-
#
|
460
|
+
# print "GOT KNOWN ZONE : #{known_zone}\n"
|
461
461
|
@@mutex.synchronize {
|
462
462
|
known_authorities = @@zones_cache[known_zone] # ".", @hints if nothing else
|
463
463
|
}
|
464
|
-
#
|
464
|
+
# print "Known authorities : #{known_authorities}\n"
|
465
465
|
|
466
|
-
#
|
467
|
-
#
|
466
|
+
# Make sure that known_authorities still contains some authorities!
|
467
|
+
# If not, remove the zone from zones_cache, and start again
|
468
468
|
if (known_authorities && known_authorities.values.length > 0)
|
469
469
|
done = true
|
470
470
|
else
|
@@ -475,7 +475,7 @@ module Dnsruby
|
|
475
475
|
end
|
476
476
|
return known_zone, known_authorities # @TODO@ Need to synchronize access to these!
|
477
477
|
end
|
478
|
-
|
478
|
+
|
479
479
|
def _dorecursion(name, type, klass, known_zone, known_authorities, depth, no_validation) # :nodoc:
|
480
480
|
|
481
481
|
if ( depth > 255 )
|
@@ -483,12 +483,12 @@ module Dnsruby
|
|
483
483
|
@errorstring="Recursion too deep, aborted"
|
484
484
|
return nil
|
485
485
|
end
|
486
|
-
|
486
|
+
|
487
487
|
known_zone.sub!(/\.*$/, ".")
|
488
|
-
|
488
|
+
|
489
489
|
ns = [] # Array of AddressCaches (was array of array of addresses)
|
490
490
|
@@mutex.synchronize{
|
491
|
-
#
|
491
|
+
# Get IPs from authorities
|
492
492
|
known_authorities.keys.each do |ns_rec|
|
493
493
|
if (known_authorities[ns_rec] != nil && known_authorities[ns_rec] != [] )
|
494
494
|
@@authority_cache[ns_rec] = known_authorities[ns_rec]
|
@@ -498,7 +498,7 @@ module Dnsruby
|
|
498
498
|
ns.push(@@authority_cache[ns_rec])
|
499
499
|
end
|
500
500
|
end
|
501
|
-
|
501
|
+
|
502
502
|
if (ns.length == 0)
|
503
503
|
found_auth = 0
|
504
504
|
TheLog.debug(";; _dorecursion() Failed to extract nameserver IPs:")
|
@@ -506,12 +506,12 @@ module Dnsruby
|
|
506
506
|
known_authorities.keys.each do |ns_rec|
|
507
507
|
if (known_authorities[ns_rec]==nil || known_authorities[ns_rec]==[])
|
508
508
|
TheLog.debug(";; _dorecursion() Manual lookup for authority [#{ns_rec}]")
|
509
|
-
|
509
|
+
|
510
510
|
auth_packet=nil
|
511
511
|
ans=[]
|
512
|
-
|
513
|
-
#
|
514
|
-
#
|
512
|
+
|
513
|
+
# Don't query for V6 if its not there.
|
514
|
+
# Do this in parallel
|
515
515
|
ip_mutex = Mutex.new
|
516
516
|
ip6_thread = Thread.start {
|
517
517
|
if ( @ipv6_ok)
|
@@ -530,22 +530,22 @@ module Dnsruby
|
|
530
530
|
".", # known_zone
|
531
531
|
@@hints, # known_authorities
|
532
532
|
depth+1); # depth
|
533
|
-
|
533
|
+
|
534
534
|
ip_mutex.synchronize {
|
535
535
|
ans.push(auth_packet.answer ) if auth_packet
|
536
536
|
}
|
537
537
|
}
|
538
538
|
ip6_thread.join
|
539
539
|
ip4_thread.join
|
540
|
-
|
540
|
+
|
541
541
|
if ( ans.length > 0 )
|
542
542
|
TheLog.debug(";; _dorecursion() Answers found for [#{ns_rec}]")
|
543
|
-
#
|
543
|
+
# foreach my $rr (@ans) {
|
544
544
|
ans.each do |rr_arr|
|
545
545
|
rr_arr.each do |rr|
|
546
546
|
TheLog.debug(";; RR:" + rr.inspect + "")
|
547
547
|
if (rr.type == Types::CNAME)
|
548
|
-
#
|
548
|
+
# Follow CNAME
|
549
549
|
server = rr.name.to_s.downcase
|
550
550
|
if (server)
|
551
551
|
server.sub!(/\.*$/, ".")
|
@@ -590,14 +590,14 @@ module Dnsruby
|
|
590
590
|
return nil
|
591
591
|
end
|
592
592
|
}
|
593
|
-
|
594
|
-
#
|
593
|
+
|
594
|
+
# Cut the deck of IPs in a random place.
|
595
595
|
TheLog.debug(";; _dorecursion() cutting deck of (" + ns.length.to_s + ") authorities...")
|
596
596
|
splitpos = rand(ns.length)
|
597
597
|
start = ns[0, splitpos]
|
598
598
|
endarr = ns[splitpos, ns.length - splitpos]
|
599
599
|
ns = endarr + start
|
600
|
-
|
600
|
+
|
601
601
|
nameservers = []
|
602
602
|
ns.each do |nss|
|
603
603
|
nss.each {|n|
|
@@ -611,19 +611,19 @@ module Dnsruby
|
|
611
611
|
}
|
612
612
|
resolver.retry_delay = nameservers.length
|
613
613
|
begin
|
614
|
-
#
|
614
|
+
# Should construct packet ourselves and clear RD bit
|
615
615
|
query = Message.new(name, type, klass)
|
616
616
|
query.header.rd = false
|
617
617
|
query.do_validation = true
|
618
618
|
query.do_caching = false
|
619
619
|
query.do_validation = false if no_validation
|
620
|
-
#
|
620
|
+
# print "Sending msg from resolver, dnssec = #{resolver.dnssec}, do_validation = #{query.do_validation}\n"
|
621
621
|
packet = resolver.send_message(query)
|
622
|
-
#
|
622
|
+
# @TODO@ Now prune unrelated RRSets (RFC 5452 section 6)
|
623
623
|
prune_rrsets_to_rfc5452(packet, known_zone)
|
624
624
|
rescue ResolvTimeout, IOError => e
|
625
|
-
#
|
626
|
-
#
|
625
|
+
# TheLog.debug(";; nameserver #{levelns.to_s} didn't respond")
|
626
|
+
# next
|
627
627
|
TheLog.debug("No response!")
|
628
628
|
return nil
|
629
629
|
end
|
@@ -631,14 +631,14 @@ module Dnsruby
|
|
631
631
|
if (@callback)
|
632
632
|
@callback.call(packet)
|
633
633
|
end
|
634
|
-
|
634
|
+
|
635
635
|
of = nil
|
636
636
|
TheLog.debug(";; _dorecursion() Response received from [" + @answerfrom.to_s + "]")
|
637
637
|
status = packet.rcode
|
638
638
|
authority = packet.authority
|
639
639
|
if (status)
|
640
640
|
if (status == "NXDOMAIN")
|
641
|
-
#
|
641
|
+
# I guess NXDOMAIN is the best we'll ever get
|
642
642
|
TheLog.debug(";; _dorecursion() returning NXDOMAIN")
|
643
643
|
return packet
|
644
644
|
elsif (packet.answer.length > 0)
|
@@ -649,7 +649,7 @@ module Dnsruby
|
|
649
649
|
return packet
|
650
650
|
elsif (authority.length > 0)
|
651
651
|
auth = Hash.new
|
652
|
-
#
|
652
|
+
# foreach my $rr (@authority) {
|
653
653
|
authority.each do |rr|
|
654
654
|
if (rr.type.to_s =~ /^(NS|SOA)$/)
|
655
655
|
server = (rr.type == Types::NS ? rr.nsdname : rr.mname).to_s.downcase
|
@@ -663,9 +663,11 @@ module Dnsruby
|
|
663
663
|
elsif (of =~ /#{known_zone}/)
|
664
664
|
TheLog.debug(";; _dorecursion() FOUND closer authority for [#{of}] at [#{server}].")
|
665
665
|
auth[server] ||= AddressCache.new #[] @TODO@ If there is no additional record for this, then we want to use the authority!
|
666
|
-
if (
|
667
|
-
|
668
|
-
|
666
|
+
if (rr.type == Types.NS)
|
667
|
+
if ((packet.additional.rrset(rr.nsdname, Types::A).length == 0) &&
|
668
|
+
(packet.additional.rrset(rr.nsdname, Types::AAAA).length == 0))
|
669
|
+
auth[server].push([rr.nsdname, rr.ttl])
|
670
|
+
end
|
669
671
|
end
|
670
672
|
else
|
671
673
|
TheLog.debug(";; _dorecursion() Confused name server [" + @answerfrom + "] thinks [#{of}] is closer than [#{known_zone}]?")
|
@@ -675,10 +677,10 @@ module Dnsruby
|
|
675
677
|
TheLog.debug(";; _dorecursion() Ignoring NON NS entry found in authority section: " + rr.inspect)
|
676
678
|
end
|
677
679
|
end
|
678
|
-
#
|
680
|
+
# foreach my $rr ($packet->additional)
|
679
681
|
packet.additional.each do |rr|
|
680
682
|
if (rr.type == Types::CNAME)
|
681
|
-
#
|
683
|
+
# Store this CNAME into %auth too
|
682
684
|
server = rr.name.to_s.downcase
|
683
685
|
if (server)
|
684
686
|
server.sub!(/\.*$/, ".")
|
@@ -690,7 +692,7 @@ module Dnsruby
|
|
690
692
|
auth[server] = auth[cname]
|
691
693
|
next
|
692
694
|
end
|
693
|
-
|
695
|
+
|
694
696
|
end
|
695
697
|
elsif (rr.type == Types::A || rr.type == Types::AAAA)
|
696
698
|
server = rr.name.to_s.downcase
|
@@ -711,7 +713,7 @@ module Dnsruby
|
|
711
713
|
TheLog.debug(";; _dorecursion() Ignoring useless: " + rr.inspect)
|
712
714
|
end
|
713
715
|
if (of =~ /#{known_zone}/)
|
714
|
-
#
|
716
|
+
# print "Adding #{of} with :\n#{auth}\nto zones_cache\n"
|
715
717
|
@@mutex.synchronize{
|
716
718
|
@@zones_cache[of]=auth
|
717
719
|
}
|
@@ -722,14 +724,14 @@ module Dnsruby
|
|
722
724
|
end
|
723
725
|
end
|
724
726
|
end
|
725
|
-
|
727
|
+
|
726
728
|
return nil
|
727
729
|
end
|
728
730
|
|
729
731
|
def prune_rrsets_to_rfc5452(packet, zone)
|
730
|
-
#
|
731
|
-
#
|
732
|
-
#
|
732
|
+
# Now prune the response of any unrelated rrsets (RFC5452 section6)
|
733
|
+
# "One very simple way to achieve this is to only accept data if it is
|
734
|
+
# part of the domain for which the query was intended."
|
733
735
|
if (!packet.header.aa)
|
734
736
|
return
|
735
737
|
end
|
@@ -745,9 +747,9 @@ module Dnsruby
|
|
745
747
|
if ((n.to_s == zone) || (n.to_s == Name.create(zone).to_s) ||
|
746
748
|
(n.subdomain_of?(Name.create(zone))) ||
|
747
749
|
(rrset.type == Types::OPT))
|
748
|
-
#
|
749
|
-
|
750
|
-
#
|
750
|
+
# # @TODO@ Leave in the response if it is an SOA, NSEC or RRSIGfor the parent zone
|
751
|
+
# # elsif ((query_name.subdomain_of?rrset.name) &&
|
752
|
+
# elsif ((rrset.type == Types.SOA) || (rrset.type == Types.NSEC) || (rrset.type == Types.NSEC3)) #)
|
751
753
|
else
|
752
754
|
TheLog.debug"Removing #{rrset.name}, #{rrset.type} from response from server for #{zone}"
|
753
755
|
packet.send(section).remove_rrset(rrset.name, rrset.type)
|