Custom response for autogenerated domains and cache

Eduard Ahmatgareev e.ahmatgareev at
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: "-"

The code looks like:
if query_domain.endswith(('compute.internal.','ec2.internal.',
'', '')) or
(len(query_domain.split(".")) == 1):
            parse_domain = re.match("(ip|ec2)-((?:\d{1,3}-){3}\d{1,3})$",

            if parse_domain:
                ip_address = parse_domain.groups()[1].replace("-", ".")

                #create instance of DNS message (packet) with given
                msg = DNSMessage(query_domain, RR_TYPE_A, RR_CLASS_IN,
                #append RR
                if (qstate.qinfo.qtype == RR_TYPE_A) or (qstate.qinfo.qtype
                    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,
                #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
       = 2
                qstate.return_rcode = RCODE_NOERROR


                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: <>

More information about the Unbound-users mailing list