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
data/lib/Dnsruby/update.rb
DELETED
@@ -1,278 +0,0 @@
|
|
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
|
-
module Dnsruby
|
17
|
-
#Dnsruby::Update is a subclass of Dnsruby::Packet,
|
18
|
-
#to be used for making DNS dynamic updates. Programmers
|
19
|
-
#should refer to RFC 2136 for the semantics of dynamic updates.
|
20
|
-
|
21
|
-
#The first example below shows a complete program; subsequent examples
|
22
|
-
#show only the creation of the update packet.
|
23
|
-
#
|
24
|
-
#== Add a new host
|
25
|
-
#
|
26
|
-
# require 'Dnsruby'
|
27
|
-
#
|
28
|
-
# # Create the update packet.
|
29
|
-
# update = Dnsruby::Update.new('example.com')
|
30
|
-
#
|
31
|
-
# # Prerequisite is that no A records exist for the name.
|
32
|
-
# update.absent('foo.example.com.', 'A')
|
33
|
-
#
|
34
|
-
# # Add two A records for the name.
|
35
|
-
# update.add('foo.example.com.', 'A', 86400, '192.168.1.2')
|
36
|
-
# update.add('foo.example.com.', 'A', 86400, '172.16.3.4')
|
37
|
-
#
|
38
|
-
# # Send the update to the zone's primary master.
|
39
|
-
# res = Dnsruby::Resolver.new({:nameserver => 'primary-master.example.com'})
|
40
|
-
#
|
41
|
-
# begin
|
42
|
-
# reply = res.send_message(update)
|
43
|
-
# print "Update succeeded\n"
|
44
|
-
# rescue Exception => e
|
45
|
-
# print 'Update failed: #{e}\n'
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
#== Add an MX record for a name that already exists
|
49
|
-
#
|
50
|
-
# update = Dnsruby::Update.new('example.com')
|
51
|
-
# update.present('example.com')
|
52
|
-
# update.add('example.com', Dnsruby::Types.MX, 10, 'mailhost.example.com')
|
53
|
-
#
|
54
|
-
#== Add a TXT record for a name that doesn't exist
|
55
|
-
#
|
56
|
-
# update = Dnsruby::Update.new('example.com')
|
57
|
-
# update.absent('info.example.com')
|
58
|
-
# update.add('info.example.com', Types.TXT, 86400, "yabba dabba doo"')
|
59
|
-
#
|
60
|
-
#== Delete all A records for a name
|
61
|
-
#
|
62
|
-
# update = Dnsruby::Update.new('example.com')
|
63
|
-
# update.present('foo.example.com', 'A')
|
64
|
-
# update.delete('foo.example.com', 'A')
|
65
|
-
#
|
66
|
-
#== Delete all RRs for a name
|
67
|
-
#
|
68
|
-
# update = Dnsruby::Update.new('example.com')
|
69
|
-
# update.present('byebye.example.com')
|
70
|
-
# update.delete('byebye.example.com')
|
71
|
-
#
|
72
|
-
#== Perform a signed update
|
73
|
-
#
|
74
|
-
# key_name = 'tsig-key'
|
75
|
-
# key = 'awwLOtRfpGE+rRKF2+DEiw=='
|
76
|
-
#
|
77
|
-
# update = Dnsruby::Update.new('example.com')
|
78
|
-
# update.add('foo.example.com', 'A', 86400, 10.1.2.3'))
|
79
|
-
# update.add('bar.example.com', 'A', 86400, 10.4.5.6'))
|
80
|
-
# res.tsig=(key_name,key)
|
81
|
-
#
|
82
|
-
class Update < Message
|
83
|
-
#Returns a Dnsruby::Update object suitable for performing a DNS
|
84
|
-
#dynamic update. Specifically, it creates a message with the header
|
85
|
-
#opcode set to UPDATE and the zone record type to SOA (per RFC 2136,
|
86
|
-
#Section 2.3).
|
87
|
-
#
|
88
|
-
#Programs must use the push method to add RRs to the prerequisite,
|
89
|
-
#update, and additional sections before performing the update.
|
90
|
-
#
|
91
|
-
#Arguments are the zone name and the class. If the zone is omitted,
|
92
|
-
#the default domain will be taken from the resolver configuration.
|
93
|
-
#If the class is omitted, it defaults to IN.
|
94
|
-
# packet = Dnsruby::Update.new
|
95
|
-
# packet = Dnsruby::Update.new('example.com')
|
96
|
-
# packet = Dnsruby::Update.new('example.com', 'HS')
|
97
|
-
#
|
98
|
-
def initialize(zone=nil, klass=nil)
|
99
|
-
|
100
|
-
# sort out the zone section (RFC2136, section 2.3)
|
101
|
-
if (zone==nil)
|
102
|
-
config = Config.new
|
103
|
-
zone = (config.search)[0]
|
104
|
-
return unless zone
|
105
|
-
end
|
106
|
-
|
107
|
-
type = 'SOA'
|
108
|
-
klass ||= 'IN'
|
109
|
-
|
110
|
-
super(zone, type, klass) || return
|
111
|
-
|
112
|
-
@header.opcode=('UPDATE')
|
113
|
-
@header.rd=(0)
|
114
|
-
@do_validation = false
|
115
|
-
end
|
116
|
-
|
117
|
-
#Ways to create the prerequisite records (exists, notexists, inuse, etc. - RFC2136, section 2.4)
|
118
|
-
#
|
119
|
-
# (1) RRset exists (value independent). At least one RR with a
|
120
|
-
# specified NAME and TYPE (in the zone and class specified by
|
121
|
-
# the Zone Section) must exist.
|
122
|
-
#
|
123
|
-
# update.present(name, type)
|
124
|
-
#
|
125
|
-
# (2) RRset exists (value dependent). A set of RRs with a
|
126
|
-
# specified NAME and TYPE exists and has the same members
|
127
|
-
# with the same RDATAs as the RRset specified here in this
|
128
|
-
# Section.
|
129
|
-
#
|
130
|
-
# update.present(name, type, rdata)
|
131
|
-
#
|
132
|
-
# (4) Name is in use. At least one RR with a specified NAME (in
|
133
|
-
# the zone and class specified by the Zone Section) must exist.
|
134
|
-
# Note that this prerequisite is NOT satisfied by empty
|
135
|
-
# nonterminals.
|
136
|
-
#
|
137
|
-
# update.present(name)
|
138
|
-
def present(*args)
|
139
|
-
ttl = 0
|
140
|
-
rdata = ""
|
141
|
-
klass = Classes.ANY
|
142
|
-
if (args.length>=1) # domain (RFC2136, Section 2.4.4)
|
143
|
-
name = args[0]
|
144
|
-
type = Types.ANY
|
145
|
-
if (args.length>=2) # RRSET (RFC2136, Section 2.4.1)
|
146
|
-
type = args[1]
|
147
|
-
end
|
148
|
-
if (args.length > 2) # RRSET (RFC2136, Section 2.4.2)
|
149
|
-
klass = zone()[0].zclass
|
150
|
-
rdata=args[2]
|
151
|
-
end
|
152
|
-
rec = RR.create("#{name} #{ttl} #{klass} #{type} #{rdata}")
|
153
|
-
add_pre(rec)
|
154
|
-
return rec
|
155
|
-
else
|
156
|
-
raise ArgumentError.new("Wrong number of arguments (#{args.length} for 1 or 2) for Update#absent")
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
#Ways to create the prerequisite records (exists, notexists, inuse, etc. - RFC2136, section 2.4)
|
161
|
-
#Can be called with one arg :
|
162
|
-
#
|
163
|
-
# update.absent(name)
|
164
|
-
# (5) Name is not in use. No RR of any type is owned by a
|
165
|
-
# specified NAME. Note that this prerequisite IS satisfied by
|
166
|
-
# empty nonterminals.
|
167
|
-
#
|
168
|
-
#Or with two :
|
169
|
-
#
|
170
|
-
# update.absent(name, type)
|
171
|
-
# (3) RRset does not exist. No RRs with a specified NAME and TYPE
|
172
|
-
# (in the zone and class denoted by the Zone Section) can exist.
|
173
|
-
#
|
174
|
-
def absent(*args)
|
175
|
-
ttl = 0
|
176
|
-
rdata = ""
|
177
|
-
klass = Classes.NONE
|
178
|
-
if (args.length>=1) # domain (RFC2136, Section 2.4.5)
|
179
|
-
name = args[0]
|
180
|
-
type = Types.ANY
|
181
|
-
if (args.length==2) # RRSET (RFC2136, Section 2.4.3)
|
182
|
-
type = args[1]
|
183
|
-
end
|
184
|
-
rec = RR.create("#{name} #{ttl} #{klass} #{type} #{rdata}")
|
185
|
-
add_pre(rec)
|
186
|
-
return rec
|
187
|
-
else
|
188
|
-
raise ArgumentError.new("Wrong number of arguments (#{args.length} for 1 or 2) for Update#absent")
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
#Ways to create the update records (add, delete, RFC2136, section 2.5)
|
193
|
-
# " 2.5.1 - Add To An RRset
|
194
|
-
#
|
195
|
-
# RRs are added to the Update Section whose NAME, TYPE, TTL, RDLENGTH
|
196
|
-
# and RDATA are those being added, and CLASS is the same as the zone
|
197
|
-
# class. Any duplicate RRs will be silently ignored by the primary
|
198
|
-
# master."
|
199
|
-
#
|
200
|
-
# update.add(rr)
|
201
|
-
# update.add([rr1, rr2])
|
202
|
-
# update.add(name, type, ttl, rdata)
|
203
|
-
#
|
204
|
-
def add(*args)
|
205
|
-
zoneclass=zone()[0].zclass
|
206
|
-
case args[0]
|
207
|
-
when Array
|
208
|
-
args[0].each do |resource|
|
209
|
-
add(resource)
|
210
|
-
end
|
211
|
-
when RR
|
212
|
-
# Make sure that the Class is the same as the zone
|
213
|
-
resource = args[0]
|
214
|
-
if (resource.klass != zoneclass)
|
215
|
-
raise ArgumentError.new("Wrong class #{resource.klass} for update (should be #{zoneclass})!")
|
216
|
-
end
|
217
|
-
add_update(resource)
|
218
|
-
return resource
|
219
|
-
else
|
220
|
-
name=args[0]
|
221
|
-
type=args[1]
|
222
|
-
ttl=args[2]
|
223
|
-
rdata=args[3]
|
224
|
-
resource = nil
|
225
|
-
if (Types.new(type) == Types.TXT)
|
226
|
-
instring = "#{name} #{ttl} #{zoneclass} #{type} ";
|
227
|
-
if (String === rdata)
|
228
|
-
instring += " '#{rdata}'"
|
229
|
-
elsif (Array === rdata)
|
230
|
-
rdata.length.times {|rcounter|
|
231
|
-
instring += " '#{rdata[rcounter]}' "
|
232
|
-
}
|
233
|
-
else
|
234
|
-
instring += rdata
|
235
|
-
end
|
236
|
-
resource = RR.create(instring)
|
237
|
-
else
|
238
|
-
resource = RR.create("#{name} #{ttl} #{zoneclass} #{type} #{rdata}")
|
239
|
-
end
|
240
|
-
add_update(resource)
|
241
|
-
return resource
|
242
|
-
end
|
243
|
-
# @TODO@ Should be able to take RRSet!
|
244
|
-
end
|
245
|
-
|
246
|
-
#Ways to create the update records (add, delete, RFC2136, section 2.5)
|
247
|
-
#
|
248
|
-
#2.5.2 - Delete An RRset
|
249
|
-
# update.delete(name, type)
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#2.5.3 - Delete All RRsets From A Name
|
253
|
-
# update.delete(name)
|
254
|
-
#
|
255
|
-
#2.5.4 - Delete An RR From An RRset
|
256
|
-
# update.delete(name, type, rdata)
|
257
|
-
#
|
258
|
-
def delete(*args)
|
259
|
-
ttl = 0
|
260
|
-
klass = Classes.ANY
|
261
|
-
rdata=""
|
262
|
-
resource = nil
|
263
|
-
case args.length
|
264
|
-
when 1 # name
|
265
|
-
resource = RR.create("#{args[0]} #{ttl} #{klass} #{Types.ANY} #{rdata}")
|
266
|
-
add_update(resource)
|
267
|
-
when 2 # name, type
|
268
|
-
resource = RR.create("#{args[0]} #{ttl} #{klass} #{args[1]} #{rdata}")
|
269
|
-
add_update(resource)
|
270
|
-
when 3 # name, type, rdata
|
271
|
-
resource = RR.create("#{args[0]} #{ttl} IN #{args[1]} #{args[2]}")
|
272
|
-
resource.klass = Classes.NONE
|
273
|
-
add_update(resource)
|
274
|
-
end
|
275
|
-
return resource
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
@@ -1,124 +0,0 @@
|
|
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
|
-
|
17
|
-
module Dnsruby
|
18
|
-
# Takes care of the validation for the SelectThread. If queries need to be
|
19
|
-
# made in order to validate the response, then a separate thread is fired up
|
20
|
-
# to do this.
|
21
|
-
class ValidatorThread # :nodoc: all
|
22
|
-
# include Singleton
|
23
|
-
def initialize(*args)
|
24
|
-
@client_id, @client_queue, @response, @error, @query, @st, @res = args
|
25
|
-
# Create the validation thread, and a queue to receive validation requests
|
26
|
-
# Actually, need to have a thread per validator, as they make recursive calls.
|
27
|
-
# @@mutex = Mutex.new
|
28
|
-
# @@validation_queue = Queue.new
|
29
|
-
# @@validator_thread = Thread.new{
|
30
|
-
# do_validate
|
31
|
-
# }
|
32
|
-
end
|
33
|
-
def run
|
34
|
-
# ONLY START THE NEW THREAD IF VALIDATION NEED OCCUR!!
|
35
|
-
if (should_validate)
|
36
|
-
Thread.new{
|
37
|
-
do_validate
|
38
|
-
}
|
39
|
-
else
|
40
|
-
do_validate
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
# def add_to_queue(item)
|
46
|
-
# print "ADding to validator queue\n"
|
47
|
-
## @@mutex.synchronize{
|
48
|
-
# @@validation_queue.push(item)
|
49
|
-
## }
|
50
|
-
# end
|
51
|
-
def do_validate
|
52
|
-
# while (true)
|
53
|
-
# item = nil
|
54
|
-
# print "Waiting to pop validation item\n"
|
55
|
-
## @@mutex.synchronize{
|
56
|
-
# item = @@validation_queue.pop
|
57
|
-
## }
|
58
|
-
# print "Popped validation request\n"
|
59
|
-
# client_id, client_queue, response, err, query, st, res = item
|
60
|
-
validated_ok = validate(@query, @response, @res)
|
61
|
-
|
62
|
-
validated_ok = false if (@error && !(NXDomain === @error))
|
63
|
-
|
64
|
-
cache_if_valid(@query, @response)
|
65
|
-
|
66
|
-
# Now send the response back to the client...
|
67
|
-
# print "#{Time.now} : Got result for #{@query.question()[0].qname}, #{@query.question()[0].qtype}\n"
|
68
|
-
if (validated_ok)
|
69
|
-
@st.push_validation_response_to_select(@client_id, @client_queue, @response, nil, @query, @res)
|
70
|
-
else
|
71
|
-
@st.push_validation_response_to_select(@client_id, @client_queue, @response,
|
72
|
-
@response.security_error, @query, @res)
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
# end
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
def should_validate
|
81
|
-
return ValidatorThread.requires_validation?(@query, @response, @error, @res)
|
82
|
-
end
|
83
|
-
|
84
|
-
def ValidatorThread.requires_validation?(query, response, error, res)
|
85
|
-
# @error will be nil for DNS RCODE errors - it will be true for TsigError. really?!
|
86
|
-
if ((!error || (error.instance_of?NXDomain)) && query.do_validation)
|
87
|
-
if (res.dnssec)
|
88
|
-
if (response.security_level != Message::SecurityLevel::SECURE)
|
89
|
-
return true
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
return false
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
def validate(query, response, res)
|
98
|
-
if (should_validate)
|
99
|
-
begin
|
100
|
-
# So, we really need to be able to take the response out of the select thread, along
|
101
|
-
# with the responsibility for sending the answer to the client.
|
102
|
-
# Should we have a validator thread? Or a thread per validation?
|
103
|
-
# Then, select thread gets response. It performs basic checks here.
|
104
|
-
# After basic checks, the select-thread punts the response (along with queues, etc.)
|
105
|
-
# to the validator thread.
|
106
|
-
# The validator validates it (or just releases it with no validation), and then
|
107
|
-
# sends the request to the client via the client queue.
|
108
|
-
Dnssec.validate_with_query(query,response)
|
109
|
-
return true
|
110
|
-
rescue VerifyError => e
|
111
|
-
response.security_error = e
|
112
|
-
# Response security_level should already be set
|
113
|
-
return false
|
114
|
-
end
|
115
|
-
end
|
116
|
-
return true
|
117
|
-
end
|
118
|
-
|
119
|
-
def cache_if_valid(query, response)
|
120
|
-
return if @error
|
121
|
-
PacketSender.cache(query, response)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|