mirror of
https://code.semirocket.science/wrapsix
synced 2024-11-10 08:10:59 +02:00
Resolver is working but not for normal apps yet(?)
Accepts requests and sends responses
This commit is contained in:
parent
f09255b0d7
commit
c27f79705f
@ -1,6 +1,7 @@
|
|||||||
### Configuration of Resolver
|
### Configuration of Resolver
|
||||||
resolver: 1
|
resolver: 1
|
||||||
resolver_ip: '::1'
|
#resolver_ip: '::1'
|
||||||
|
resolver_ip: '2001:470:9985:1:200:e2ff:fe7f:414'
|
||||||
secondary_resolver: 10.0.0.139 # if not set => /etc/resolv.conf
|
secondary_resolver: 10.0.0.139 # if not set => /etc/resolv.conf
|
||||||
|
|
||||||
### Configuration of Wrapper
|
### Configuration of Wrapper
|
||||||
|
@ -19,20 +19,17 @@ class Resolver
|
|||||||
def start
|
def start
|
||||||
@resolver = UDPSocket.open Socket::AF_INET6
|
@resolver = UDPSocket.open Socket::AF_INET6
|
||||||
if @resolver.bind $config['resolver_ip'], 53
|
if @resolver.bind $config['resolver_ip'], 53
|
||||||
p "Started DNS resolver on IPv6 address #{$config['resolver_ip']}" if @debug
|
puts "Started DNS resolver on IPv6 address #{$config['resolver_ip']}" if @debug
|
||||||
else
|
else
|
||||||
p "DNS resolver not started!" if @debug
|
puts "DNS resolver not started!" if @debug
|
||||||
end
|
end
|
||||||
|
|
||||||
# just for now
|
|
||||||
#@hosts = [
|
|
||||||
#{:name => "example.com", :type => "A", :data => "192.168.0.1"}
|
|
||||||
#]
|
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
|
puts "---------- start ----------" if @debug
|
||||||
# Receive and parse query
|
# Receive and parse query
|
||||||
data = @resolver.recvfrom 2048
|
data = @resolver.recvfrom 2048
|
||||||
p "Client: #{data[1].join(' ')}" if @debug
|
print "Client: " if @debug
|
||||||
|
p data[1] if @debug
|
||||||
|
|
||||||
query = Resolv::DNS::Message::decode data[0]
|
query = Resolv::DNS::Message::decode data[0]
|
||||||
print "Whole query: " if @debug
|
print "Whole query: " if @debug
|
||||||
@ -44,36 +41,46 @@ class Resolver
|
|||||||
answer.opcode = query.opcode # Type of Query; copy from query
|
answer.opcode = query.opcode # Type of Query; copy from query
|
||||||
answer.aa = 0 # Is this an authoritative response: 0 = No, 1 = Yes
|
answer.aa = 0 # Is this an authoritative response: 0 = No, 1 = Yes
|
||||||
answer.rd = query.rd # Is Recursion Desired, copied from query
|
answer.rd = query.rd # Is Recursion Desired, copied from query
|
||||||
answer.ra = 1 # Does name server support recursion: 0 = No, 1 = Yes
|
answer.ra = 0 # Does name server support recursion: 0 = No, 1 = Yes
|
||||||
answer.rcode = 0 # Response code: 0 = No errors
|
answer.rcode = 0 # Response code: 0 = No errors
|
||||||
|
|
||||||
query.each_question do |question, typeclass| # There may be multiple questions per query
|
query.each_question do |question, typeclass| # There may be multiple questions per query
|
||||||
|
begin
|
||||||
name = question.to_s # The domain name looked for in the query.
|
name = question.to_s # The domain name looked for in the query.
|
||||||
p "Looking for: #{name}" if @debug
|
puts "Looking for: #{name}" if @debug
|
||||||
record_type = typeclass.name.split("::").last # For example "A", "MX"
|
#record_type = typeclass.name.split("::").last # For example "A", "MX"
|
||||||
p "RR: #{typeclass}" if @debug
|
puts "RR: #{typeclass}" if @debug
|
||||||
p "RR: #{record_type}" if @debug
|
#puts "RR: #{record_type}" if @debug
|
||||||
|
|
||||||
# So let's look for it :c) (in secondary resolver)
|
# So let's look for it :c) (in secondary resolver)
|
||||||
sr = Resolv::DNS::new :nameserver => $config['secondary_resolver']
|
sr = Resolv::DNS::new :nameserver => $config['secondary_resolver']
|
||||||
sr_data = sr.getresource name, typeclass
|
sr_data = sr.getresource name, typeclass
|
||||||
sr_answer = sr_data.address # this is acceptable only for A or so
|
print "Raw answer: " if @debug
|
||||||
p sr_answer if @debug
|
p sr_data if @debug
|
||||||
|
|
||||||
# temporary code
|
record = {}
|
||||||
#ttl = 16000
|
record[:name] = name
|
||||||
#ttl = 86400 # 1 day
|
record[:data] = sr_data
|
||||||
#record = @hosts.find{|host| host[:name] == name && host[:type] == record_type }
|
|
||||||
#unless record.nil?
|
print "Data: " if @debug
|
||||||
# Setup answer to this question
|
p record if @debug
|
||||||
#answer.add_answer(name + ".",ttl,typeclass.new(record[:data]))
|
|
||||||
#answer.encode
|
# completing the answer
|
||||||
#end
|
ttl = 86400 # I think ttl doesn't matter ;c)
|
||||||
|
answer.add_answer name + ".", ttl, record[:data]
|
||||||
|
|
||||||
|
print "My answer: " if @debug
|
||||||
|
p answer if @debug
|
||||||
|
rescue Resolv::ResolvError
|
||||||
|
puts "Error: DNS result has no information for #{name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Send the response
|
# send the response
|
||||||
#server.send answer.encode, 0, data[1][2], data[1][1]
|
@resolver.send answer.encode, 0, data[1][3], data[1][1] # msg, flags, client, port
|
||||||
|
|
||||||
|
puts "---------- end ----------" if @debug
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def exit
|
def exit
|
||||||
|
Loading…
Reference in New Issue
Block a user