Class: Dirndl::Resolver

Inherits:
Object show all
Defined in:
lib/dirndl/resolver.rb

Instance Method Summary collapse

Instance Method Details

#call(query, response) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/dirndl/resolver.rb', line 5

def call query, response
  zone = load_zone_for query.human_qname
  return unless zone
  zone.records_of(DNS::Zonefile::A).each do |rr|
    next unless rr.host == query.human_qname
    answer = "#{rr.host} #{rr.klass} A #{rr.ttl} #{rr.address}"
    response.add answer
  end
end

#load_zone_for(qname) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dirndl/resolver.rb', line 15

def load_zone_for qname
  parts = qname.split /\./
  parts.reverse!
  zone_file_path = parts.inject(zone_db_root_path) { |path, part|
    file = File.join path, "#{part}.zone"
    if File.exists? file
      file
    else

      if path !~ /\.zone$/
        File.join path, part
      else
        path
      end
    end
  }
  return unless zone_file_path =~ /\.zone$/
  DNS::Zonefile.load File.read(zone_file_path)
end