dnsruby 1.55 → 1.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -0
  3. data/Rakefile +30 -29
  4. data/demo/axfr.rb +93 -93
  5. data/demo/check_soa.rb +99 -99
  6. data/demo/check_zone.rb +59 -59
  7. data/demo/digdlv.rb +43 -43
  8. data/demo/digroot.rb +34 -34
  9. data/demo/example_recurse.rb +14 -14
  10. data/demo/mresolv.rb +30 -30
  11. data/demo/mx.rb +31 -31
  12. data/demo/rubydig.rb +37 -37
  13. data/demo/to_resolve.txt +3088 -3088
  14. data/demo/trace_dns.rb +46 -46
  15. data/lib/dnsruby.rb +161 -526
  16. data/lib/dnsruby/DNS.rb +305 -0
  17. data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
  18. data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
  19. data/lib/dnsruby/code_mappers.rb +295 -0
  20. data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
  21. data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
  22. data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
  23. data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
  24. data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
  25. data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
  26. data/lib/dnsruby/message/decoder.rb +164 -0
  27. data/lib/dnsruby/message/encoder.rb +75 -0
  28. data/lib/dnsruby/message/header.rb +249 -0
  29. data/lib/dnsruby/message/message.rb +629 -0
  30. data/lib/dnsruby/message/question.rb +86 -0
  31. data/lib/dnsruby/message/section.rb +96 -0
  32. data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
  33. data/lib/dnsruby/packet_sender.rb +661 -0
  34. data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
  35. data/lib/dnsruby/resolv.rb +113 -0
  36. data/lib/dnsruby/resolver.rb +1192 -0
  37. data/lib/dnsruby/resource/A.rb +56 -0
  38. data/lib/dnsruby/resource/AAAA.rb +54 -0
  39. data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
  40. data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
  41. data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
  42. data/lib/dnsruby/resource/DLV.rb +27 -0
  43. data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
  44. data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
  45. data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
  46. data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
  47. data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
  48. data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
  49. data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
  50. data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
  51. data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
  52. data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
  53. data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
  54. data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
  55. data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
  56. data/lib/dnsruby/resource/NSEC.rb +275 -0
  57. data/lib/dnsruby/resource/NSEC3.rb +332 -0
  58. data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
  59. data/lib/dnsruby/resource/OPT.rb +272 -0
  60. data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
  61. data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
  62. data/lib/dnsruby/resource/RR.rb +421 -0
  63. data/lib/dnsruby/resource/RRSIG.rb +275 -0
  64. data/lib/dnsruby/resource/RRSet.rb +190 -0
  65. data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
  66. data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
  67. data/lib/dnsruby/resource/SPF.rb +29 -0
  68. data/lib/dnsruby/resource/SRV.rb +112 -0
  69. data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
  70. data/lib/dnsruby/resource/TKEY.rb +163 -0
  71. data/lib/dnsruby/resource/TSIG.rb +593 -0
  72. data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
  73. data/lib/dnsruby/resource/X25.rb +55 -0
  74. data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
  75. data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
  76. data/lib/dnsruby/resource/resource.rb +25 -0
  77. data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
  78. data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
  79. data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
  80. data/lib/dnsruby/the_log.rb +44 -0
  81. data/lib/dnsruby/update.rb +278 -0
  82. data/lib/dnsruby/validator_thread.rb +124 -0
  83. data/lib/dnsruby/version.rb +3 -0
  84. data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
  85. data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
  86. data/test/spec_helper.rb +16 -0
  87. data/test/tc_axfr.rb +31 -34
  88. data/test/tc_cache.rb +32 -32
  89. data/test/tc_dlv.rb +28 -28
  90. data/test/tc_dns.rb +73 -76
  91. data/test/tc_dnskey.rb +31 -32
  92. data/test/tc_dnsruby.rb +50 -44
  93. data/test/tc_ds.rb +36 -36
  94. data/test/tc_escapedchars.rb +252 -255
  95. data/test/tc_hash.rb +17 -21
  96. data/test/tc_header.rb +48 -57
  97. data/test/tc_hip.rb +19 -22
  98. data/test/tc_ipseckey.rb +18 -21
  99. data/test/tc_keith.rb +300 -0
  100. data/test/tc_message.rb +87 -0
  101. data/test/tc_misc.rb +83 -87
  102. data/test/tc_name.rb +81 -84
  103. data/test/tc_naptr.rb +18 -21
  104. data/test/tc_nsec.rb +55 -55
  105. data/test/tc_nsec3.rb +23 -24
  106. data/test/tc_nsec3param.rb +20 -21
  107. data/test/tc_packet.rb +90 -93
  108. data/test/tc_packet_unique_push.rb +48 -51
  109. data/test/tc_question.rb +30 -33
  110. data/test/tc_queue.rb +16 -17
  111. data/test/tc_recur.rb +16 -17
  112. data/test/tc_res_config.rb +38 -41
  113. data/test/tc_res_env.rb +29 -32
  114. data/test/tc_res_file.rb +26 -29
  115. data/test/tc_res_opt.rb +62 -65
  116. data/test/tc_resolver.rb +287 -242
  117. data/test/tc_rr-opt.rb +70 -63
  118. data/test/tc_rr-txt.rb +68 -71
  119. data/test/tc_rr-unknown.rb +45 -48
  120. data/test/tc_rr.rb +76 -70
  121. data/test/tc_rrset.rb +21 -22
  122. data/test/tc_rrsig.rb +19 -20
  123. data/test/tc_single_resolver.rb +294 -297
  124. data/test/tc_soak.rb +199 -202
  125. data/test/tc_soak_base.rb +29 -34
  126. data/test/tc_sshfp.rb +20 -23
  127. data/test/tc_tcp.rb +32 -35
  128. data/test/tc_tkey.rb +41 -44
  129. data/test/tc_tsig.rb +81 -84
  130. data/test/tc_update.rb +108 -111
  131. data/test/tc_validator.rb +29 -29
  132. data/test/tc_verifier.rb +81 -82
  133. data/test/ts_dnsruby.rb +16 -15
  134. data/test/ts_offline.rb +62 -63
  135. data/test/ts_online.rb +115 -115
  136. metadata +155 -90
  137. data/README +0 -59
  138. data/lib/Dnsruby/DNS.rb +0 -305
  139. data/lib/Dnsruby/PacketSender.rb +0 -656
  140. data/lib/Dnsruby/Resolver.rb +0 -1189
  141. data/lib/Dnsruby/TheLog.rb +0 -44
  142. data/lib/Dnsruby/message.rb +0 -1230
  143. data/lib/Dnsruby/resource/A.rb +0 -56
  144. data/lib/Dnsruby/resource/AAAA.rb +0 -54
  145. data/lib/Dnsruby/resource/DLV.rb +0 -27
  146. data/lib/Dnsruby/resource/NSEC.rb +0 -298
  147. data/lib/Dnsruby/resource/NSEC3.rb +0 -340
  148. data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
  149. data/lib/Dnsruby/resource/OPT.rb +0 -213
  150. data/lib/Dnsruby/resource/RRSIG.rb +0 -275
  151. data/lib/Dnsruby/resource/SPF.rb +0 -29
  152. data/lib/Dnsruby/resource/SRV.rb +0 -112
  153. data/lib/Dnsruby/resource/TKEY.rb +0 -163
  154. data/lib/Dnsruby/resource/TSIG.rb +0 -593
  155. data/lib/Dnsruby/resource/X25.rb +0 -55
  156. data/lib/Dnsruby/resource/resource.rb +0 -678
  157. data/lib/Dnsruby/update.rb +0 -278
  158. 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
- # 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).
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
- # Like an array, but stores the expiration of each record.
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
- # The resolver to use for the queries
157
+ # The resolver to use for the queries
158
158
  attr_accessor :resolver
159
159
 
160
- # For guarding access to shared caches.
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
- # 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
- #
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
- # 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.
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
- # if (!@@hints || @@hints.length == 0)
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
- # Found root authority
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
- # 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
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
- # Query for the server address and add it to hints.
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
- # foreach my $server (keys %hints) {
276
+ # foreach my $server (keys %hints) {
277
277
  hints.keys.each do |server|
278
278
  if (!hints[server] || hints[server].length == 0)
279
- # Wipe the servers without lookups
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
- # Disable recursion flag.
297
+
298
+ # Disable recursion flag.
299
299
  resolver.recurse=(0)
300
- # end
301
-
302
- # return $self->nameservers( map { @{ $_ } } values %{ $self->{'hints'} } );
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
- # 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
- #
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
- # if (sub && UNIVERSAL::isa(sub, 'CODE'))
361
+ # if (sub && UNIVERSAL::isa(sub, 'CODE'))
362
362
  @callback = sub
363
- # end
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
- # 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.
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
- # @TODO@ PROVIDE AN ASYNCHRONOUS SEND WHICH RETURNS MESSAGE WITH ERROR!!!
392
-
393
- # Make sure the hint servers are initialized.
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
- # 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
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
- # 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
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
- # Now see if we already know the zone in question
412
- # Otherwise, see if we know any of its parents (will know at least ".")
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
- # Seed name servers with the closest known authority
416
- # ret = _dorecursion( name, type, klass, ".", @hints, 0)
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
- # print "\n\nRESPONSE:\n#{ret}\n"
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
- # 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
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
- # print "Checking for known zone : #{name}\n"
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
- # strip the name up to the first dot
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
- # print "GOT KNOWN ZONE : #{known_zone}\n"
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
- # print "Known authorities : #{known_authorities}\n"
464
+ # print "Known authorities : #{known_authorities}\n"
465
465
 
466
- # Make sure that known_authorities still contains some authorities!
467
- # If not, remove the zone from zones_cache, and start again
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
- # Get IPs from authorities
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
- # Don't query for V6 if its not there.
514
- # Do this in parallel
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
- # foreach my $rr (@ans) {
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
- # Follow CNAME
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
- # Cut the deck of IPs in a random place.
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
- # Should construct packet ourselves and clear RD bit
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
- # print "Sending msg from resolver, dnssec = #{resolver.dnssec}, do_validation = #{query.do_validation}\n"
620
+ # print "Sending msg from resolver, dnssec = #{resolver.dnssec}, do_validation = #{query.do_validation}\n"
621
621
  packet = resolver.send_message(query)
622
- # @TODO@ Now prune unrelated RRSets (RFC 5452 section 6)
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
- # TheLog.debug(";; nameserver #{levelns.to_s} didn't respond")
626
- # next
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
- # I guess NXDOMAIN is the best we'll ever get
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
- # foreach my $rr (@authority) {
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 ((packet.additional.rrset(rr.nsdname, Types::A).length == 0) &&
667
- (packet.additional.rrset(rr.nsdname, Types::AAAA).length == 0))
668
- auth[server].push([rr.nsdname, rr.ttl])
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
- # foreach my $rr ($packet->additional)
680
+ # foreach my $rr ($packet->additional)
679
681
  packet.additional.each do |rr|
680
682
  if (rr.type == Types::CNAME)
681
- # Store this CNAME into %auth too
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
- # print "Adding #{of} with :\n#{auth}\nto zones_cache\n"
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
- # Now prune the response of any unrelated rrsets (RFC5452 section6)
731
- # "One very simple way to achieve this is to only accept data if it is
732
- # part of the domain for which the query was intended."
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
- # # @TODO@ Leave in the response if it is an SOA, NSEC or RRSIGfor the parent zone
749
- ## elsif ((query_name.subdomain_of?rrset.name) &&
750
- # elsif ((rrset.type == Types.SOA) || (rrset.type == Types.NSEC) || (rrset.type == Types.NSEC3)) #)
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)