class GenericHandler
A generic handler for DNS queries.
Definitions
def initialize(server, socket)
Create a new handler.
Signature
-
parameter
server
Server
The server to handle queries for.
-
parameter
socket
Socket
The socket to read/write data from/to.
Implementation
def initialize(server, socket)
@server = server
@socket = socket
end
attr :server
Signature
-
attribute
Server
The server that will process incoming queries.
attr :socket
Signature
-
attribute
Socket
The socket to read/write data from/to.
def error_response(query = nil, code = Resolv::DNS::RCode::ServFail)
Create a new error response.
Signature
-
parameter
query
Resolv::DNS::Message
The query that caused the error.
-
parameter
code
Integer
The error code to return.
-
returns
Resolv::DNS::Message
The error response.
Implementation
def error_response(query = nil, code = Resolv::DNS::RCode::ServFail)
# Encoding may fail, so we need to handle this particular case:
server_failure = Resolv::DNS::Message::new(query ? query.id : 0)
server_failure.qr = 1
server_failure.opcode = query ? query.opcode : 0
server_failure.aa = 1
server_failure.rd = 0
server_failure.ra = 0
server_failure.rcode = code
# We can't do anything at this point...
return server_failure
end
def process_query(data, **options)
Process an incoming query.
Signature
-
parameter
data
String
The incoming query data.
-
parameter
options
Hash
Additional options to pass to the server.
Implementation
def process_query(data, **options)
Console.debug "Receiving incoming query (#{data.bytesize} bytes) to #{self.class.name}..."
begin
query = Resolv::DNS::Message.decode(data)
return @server.process_query(query, **options)
rescue => error
Console::Event::Failure.for(error).emit "Failed to process query!"
return error_response(query)
end
end