dnstraverse 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/bin/dnstraverse CHANGED
@@ -71,6 +71,10 @@ def progress_main(args)
71
71
  print " -- resolving"
72
72
  end
73
73
  print "\n"
74
+ when :new_referral_set then
75
+ refid = r.refid[0,r.refid.rindex('.')]
76
+ print "#{refid} #{r.parent_ip}"
77
+ print "\n"
74
78
  when :answer_fast then
75
79
  print o[:verbose] ? referral_txt_verbose(r) : referral_txt_normal(r)
76
80
  puts " -- completed earlier (#{r.replaced_by.refid})"
@@ -120,7 +120,6 @@ module DNSTraverse
120
120
  end
121
121
 
122
122
  NOERROR = Dnsruby::RCode.NOERROR
123
- NXDOMAIN = Dnsruby::RCode.NXDOMAIN
124
123
 
125
124
  def process
126
125
  return process_exception if @message.is_a? Exception
@@ -155,9 +154,9 @@ module DNSTraverse
155
154
  @error_message = "Server failure (SERVFAIL)"
156
155
  when Dnsruby::RCode::NXDOMAIN
157
156
  @error_message = "No such domain (NXDOMAIN)"
158
- when Dnsruby::RCode.NOTIMP
157
+ when Dnsruby::RCode::NOTIMP
159
158
  @error_message = "Not implemented (NOTIMP)"
160
- when Dnsruby::RCode.REFUSED
159
+ when Dnsruby::RCode::REFUSED
161
160
  @error_message = "Refused"
162
161
  else
163
162
  @error_message = @message.rcode.to_s
@@ -364,7 +364,7 @@ module DNSTraverse
364
364
 
365
365
  # process this Referral object:
366
366
  # query each IP in @serverips and create a Response object
367
- # return an array of children
367
+ # return an array of sets of children
368
368
  def process(args)
369
369
  raise "This Referral object has already been processed" if processed?
370
370
  raise "You need to resolve this Referral object" unless resolved?
@@ -372,13 +372,16 @@ module DNSTraverse
372
372
  unless (server) then
373
373
  # special case - no server means start from the top with the roots
374
374
  process_add_roots(args)
375
- return @children.values.flatten
375
+ #return @children.values.flatten
376
+ return [ @children.values.flatten ] # one set
376
377
  end
377
378
  process_normal(args)
378
379
  # return a set of Referral objects that need to be processed
379
380
  # this is just using @serverips for ordering the children properly
380
381
  # because we numbered them all already
381
- return @serverips.map {|ip| @children[ip] }.flatten.select {|x| x.is_a? Referral }
382
+ #return @serverips.map {|ip| @children[ip] }.flatten.select {|x| x.is_a? Referral }
383
+ # use serverips to keep ordering, skip key: entries
384
+ return @serverips.select {|ip| @children[ip] }.map {|ip| @children[ip] } # array of sets of children
382
385
  end
383
386
 
384
387
  def process_add_roots(args)
@@ -398,10 +401,9 @@ module DNSTraverse
398
401
 
399
402
  def process_normal(args)
400
403
  Log.debug { "process " + self.to_s }
401
- childsets = @serverips.reject {|ip| ip =~ /^key:/ }.count
402
- childset = 0
404
+ # two phases in order to calculate number of childsets
405
+ childsets = 0
403
406
  for ip in @serverips do
404
- childset+= 1
405
407
  Log.debug { "Process normal #{ip}" }
406
408
  next if ip =~ /^key:/ # resolve failed on something
407
409
  m = nil
@@ -416,12 +418,19 @@ module DNSTraverse
416
418
  :bailiwick => @bailiwick,
417
419
  :infocache => @infocache, :ip => ip,
418
420
  :server => @server,
421
+ :parent_ip => @parent_ip,
419
422
  :decoded_query_cache => @decoded_query_cache)
420
423
  Log.debug { "Process normal #{ip} - done making response" }
421
424
  @responses[ip] = r
422
- case r.status
423
- when :restart, :referral then
424
- Log.debug { "Process normal #{ip} - making referrals" }
425
+ if r.status == :restart or r.status == :referral then
426
+ childsets+= 1
427
+ end
428
+ end
429
+ childset = 0
430
+ @responses.each_pair do |ip, r|
431
+ if r.status == :restart or r.status == :referral then
432
+ childset+= 1
433
+ Log.debug { "Process normal #{ip} - making referrals (childset #{childset})" }
425
434
  refid = childsets == 1 ? @refid : "#{@refid}.#{childset}"
426
435
  refkey = childsets == 1 ? @refkey : "#{@refkey}.#{childsets}"
427
436
  @children[ip] = make_referrals(:qname => r.endname,
@@ -38,6 +38,7 @@ module DNSTraverse
38
38
  @infocache = InfoCache.new(args[:infocache]) # our infocache
39
39
  @starters = nil # initial servers for :referral/:restart
40
40
  @starters_bailiwick = nil # for initial servers for :referral/:restart
41
+ @parent_ip = args[:parent_ip] # passed in in case we get referral_lame, for the key
41
42
  evaluate
42
43
  update_stats_key
43
44
  return self
@@ -56,8 +57,10 @@ module DNSTraverse
56
57
  def update_stats_key
57
58
  r = @decoded_query
58
59
  @stats_key = "key:#{@status}:#{r.ip}:#{@server}:#{r.qname}:#{r.qclass}:#{r.qtype}"
59
- if @stats == :exception and r.message.is_a? Exception then
60
+ if @status == :exception and r.message.is_a? Exception then
60
61
  @stats_key+= ":#{r.message}"
62
+ elsif @status == :referral_lame then
63
+ @stats_key+= ":#{@parent_ip}"
61
64
  end
62
65
  end
63
66
 
@@ -156,9 +156,10 @@ module DNSTraverse
156
156
  r = stack.pop
157
157
  r.answer_calculate
158
158
  report_progress r, :stage => :answer
159
- r.cleanup(cleanup)
160
- if @fast then
159
+ special = r.responses.values.map {|x| x.status }.include?(:referral_lame)
160
+ if @fast and r.status == :normal and (not special) then
161
161
  # store away in @answered hash so we can lookup later
162
+ # normal status only, i.e. not :loop or :noglue
162
163
  key = "#{r.qname}:#{r.qclass}:#{r.qtype}:#{r.server}:#{r.txt_ips_verbose}".downcase!
163
164
  Log.debug { "Fast mode cache store: #{key}" }
164
165
  @answered[key] = r
@@ -168,6 +169,7 @@ module DNSTraverse
168
169
  @seen[r.server.downcase].concat(r.ips_as_array)
169
170
  @seen[r.server.downcase].uniq!
170
171
  end
172
+ r.cleanup(cleanup)
171
173
  next
172
174
  end
173
175
  # ok time to process a new item
@@ -176,11 +178,11 @@ module DNSTraverse
176
178
  key = "#{r.qname}:#{r.qclass}:#{r.qtype}:#{r.server}:#{r.txt_ips_verbose}".downcase!
177
179
  Log.debug { "Fast mode cache lookup: #{key}" }
178
180
  # check for previously stored answer
179
- # special case noglue situation, don't use previous answer
181
+ # special case noglue and loop situations
180
182
  # because attributes are complicated for stats collection and
181
183
  # we don't want to merge them together - creating the noglue
182
184
  # response object is fast anyway
183
- if @answered.key?(key) and (not r.noglue?) then
185
+ if @answered.key?(key) and (not r.noglue?) and (not r.loop?) then
184
186
  Log.debug { "Fast method - completed #{r}" }
185
187
  r.parent.replace_child(r, @answered[key])
186
188
  report_progress r, :stage => :answer_fast
@@ -199,30 +201,31 @@ module DNSTraverse
199
201
  # put a placeholder on the stack
200
202
  stack << r << :calc_answer
201
203
  # get children, one set per IP address of this name server in array
202
- children = r.process({})
204
+ children_sets = r.process({})
203
205
  # now report progress. we already can tell whether this will be
204
206
  # completed in fast mode or not, so we report this information
205
- total_sets = children.map { |c| c.parent_ip }.uniq.count
206
207
  # if there is more than one set (i.e. a DNS server has more than one
207
208
  # IP address and we had to do multiple queries), the children will
208
209
  # been numbered with an extra set digit, and we want to report this to
209
210
  # the user interface
210
211
  seen_parent_ip = Hash.new
211
- children.each do |c|
212
- if total_sets > 1 and not seen_parent_ip.include?(c.parent_ip) then
213
- report_progress c, :stage => :new_referral_set
214
- seen_parent_ip[c.parent_ip] = true
215
- end
216
- if @fast
217
- key = "#{c.qname}:#{c.qclass}:#{c.qtype}:#{c.server}:#{c.txt_ips_verbose}".downcase!
218
- stage = @answered.key?(key) ? :new_fast : :new
219
- else
220
- stage = :new
212
+ for children in children_sets do
213
+ children.each do |c|
214
+ if children_sets.length > 1 and not seen_parent_ip.include?(c.parent_ip) then
215
+ report_progress c, :stage => :new_referral_set
216
+ seen_parent_ip[c.parent_ip] = true
217
+ end
218
+ if @fast
219
+ key = "#{c.qname}:#{c.qclass}:#{c.qtype}:#{c.server}:#{c.txt_ips_verbose}".downcase!
220
+ stage = @answered.key?(key) ? :new_fast : :new
221
+ else
222
+ stage = :new
223
+ end
224
+ report_progress c, :stage => stage
221
225
  end
222
- report_progress c, :stage => stage
223
226
  end
224
227
  # push the children on the stack
225
- stack.push(*children.reverse)
228
+ stack.push(*children_sets.flatten.reverse)
226
229
  end
227
230
  end
228
231
 
@@ -2,7 +2,7 @@ module DNSTraverse
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 9
5
+ PATCH = 10
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnstraverse
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 9
10
- version: 0.1.9
9
+ - 10
10
+ version: 0.1.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Ponder