Custom response for autogenerated domains and cache
Eduard Ahmatgareev
e.ahmatgareev at gmail.com
Tue Oct 29 09:38:48 UTC 2019
Hi All,
I am working on feature for our DNS server to avoid forwarding queries to
parent domains, if dns query already contains ip address where delimiter
is: "-"
example:
ip-10-29-171-225.us-west-2.compute.internal.
The code looks like:
if query_domain.endswith(('compute.internal.','ec2.internal.',
'compute.amazonaws.com.', 'compute-1.amazonaws.com.')) or
(len(query_domain.split(".")) == 1):
parse_domain = re.match("(ip|ec2)-((?:\d{1,3}-){3}\d{1,3})$",
query_domain.split(".")[0])
if parse_domain:
ip_address = parse_domain.groups()[1].replace("-", ".")
#create instance of DNS message (packet) with given
parameters
msg = DNSMessage(query_domain, RR_TYPE_A, RR_CLASS_IN,
PKT_QR | PKT_RA | PKT_AA)
#append RR
if (qstate.qinfo.qtype == RR_TYPE_A) or (qstate.qinfo.qtype
== RR_TYPE_ANY):
log_info("[dnsrabbit] request to compute internal
domain: %s response auto generated with ip: %s, type: %s" %
(str(query_domain), str(ip_address), str(str(qstate.qinfo.qtype))))
msg.answer.append("%s 3600 IN A %s" % (query_domain,
ip_address))
#set qstate.return_msg
if not msg.set_return_msg(qstate):
qstate.ext_state[id] = MODULE_ERROR
return True
#we don't need validation, result is valid
qstate.return_msg.rep.security = 2
qstate.return_rcode = RCODE_NOERROR
run_somefunction()
qstate.ext_state[id] = MODULE_FINISHED
return True
In my code I have next problem:
function: run_somefunction calls for each dns query which is overloaded
this function.
I tried to add: storeQueryInCache in my cache, and record successfully
stored in cache, but new queries which arrived to my dns again processed my
function: run_somefunction
if there any possibility to check, if record already present in cache?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nlnetlabs.nl/pipermail/unbound-users/attachments/20191029/f14179b1/attachment.htm>
More information about the Unbound-users
mailing list