Class: DnsOne::Server
Instance Method Summary collapse
- #dns_daemon_interfaces ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #resolve(transaction) ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
8 9 10 11 |
# File 'lib/dns_one/server.rb', line 8 def initialize @zone_search = ZoneSearch.instance.setup @req_log = nil end |
Instance Method Details
#dns_daemon_interfaces ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dns_one/server.rb', line 60 def dns_daemon_interfaces if RExec.current_user == 'root' Global.conf.interfaces else ports = Global.conf.interfaces.map do |port| if port[2] <= 1024 Global.logger.warn "Changing listening port #{port.join ':'} to #{port[2] + 10000} for non-root process." port[2] += 10000 end port end ports end end |
#resolve(transaction) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dns_one/server.rb', line 21 def resolve transaction rcode = :NoError resp_log = [] begin domain_name = transaction.question.to_s ip_address = transaction.[:peer] rescue nil records, from_cache = @zone_search.query domain_name, transaction.resource_class, ip_address if records if records.empty? transaction.fail! :NoError else records.each do |rec| resp_log << rec transaction.respond! *[rec.val].flatten, {resource_class: rec.res_class, section: rec.section} end end else rcode = :NXDomain transaction.fail! :NXDomain end rescue => e rcode = :ServFail end @req_log.on_response *[ ip_address, domain_name, transaction.resource_class, rcode, resp_log, from_cache ] raise e if e end |
#run ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/dns_one/server.rb', line 75 def run srv = self RubyDNS::run_server(dns_daemon_interfaces) do on(:start) do srv.start end match(/(.+)/) do |transaction| srv.resolve transaction end otherwise do |transaction| transaction.fail! :NXDomain end end end |