Class: MKIt::DNS

Inherits:
Async::DNS::Server
  • Object
show all
Defined in:
lib/mkit/mkit_dns.rb

Instance Method Summary collapse

Constructor Details

#initializeDNS

Returns a new instance of DNS.



26
27
28
29
30
31
32
33
34
35
# File 'lib/mkit/mkit_dns.rb', line 26

def initialize
  addr = MKIt::Interface.ip
  listen_addr = [
    [:udp, addr, 53],
    [:tcp, addr, 53],
  ]
  super(listen_addr)
  @logger.info!
  @resolver = RubyDNS::Resolver.new(Async::DNS::System.nameservers)
end

Instance Method Details

#process(name, resource_class, transaction) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mkit/mkit_dns.rb', line 36

def process(name, resource_class, transaction)
  host = DnsHost.find_by_name(name)
  if host.nil?
    transaction.passthrough!(@resolver)
  else
    ipaddr = IPAddr.new host.ip
    if resource_class == Resolv::DNS::Resource::IN::A
      transaction.respond!(ipaddr.to_s)
    elsif resource_class == Resolv::DNS::Resource::IN::AAAA
      transaction.respond!(ipaddr.ipv4_mapped.to_s)
    else
      transaction.fail!(:NXDomain)
    end
  end
end