[Unbound-users] Generating NAPTR Responses with Python Module

Jeremy Shaffner jeremy at convorelay.com
Tue Oct 29 17:36:19 UTC 2013


Greetings,

I'm trying to use the Python module to generate NAPTR responses.  Starting
with the unmodified resgen.py example script, it correctly responds to A
type queries, but when trying NAPTR, it does not work.

I've made the following changes to the script:

 def operate(id, event, qstate, qdata):
     if (event == MODULE_EVENT_NEW) or (event == MODULE_EVENT_PASS):
-        if (qstate.qinfo.qname_str.endswith(".localdomain.")): #query name
ends with localdomain
+        if (qstate.qinfo.qname_str.endswith(".example.e164.arpa.")):
#query name ends with example.e164.arpa
             #create instance of DNS message (packet) with given parameters
-            msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_A,
RR_CLASS_IN, PKT_QR | PKT_RA | PKT_AA)
+            msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_NAPTR,
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):
-                msg.answer.append("%s 10 IN A 127.0.0.1" %
qstate.qinfo.qname_str)
+            if (qstate.qinfo.qtype == RR_TYPE_NAPTR):
+                log_info("pythonmod: Got NAPTR request")
+                response = "5 IN NAPTR 5 10 \"u\" \"E2U+sip\"
\"!^(.*)$!sip:\\\\1 at 99.99.99.99!\""
+                msg.answer.append("%s %s" %
(qstate.qinfo.qname_str,response))
             #set qstate.return_msg
             if not msg.set_return_msg(qstate):
                 qstate.ext_state[id] = MODULE_ERROR
@@ -55,6 +22,7 @@
             #we don't need validation, result is valid
             qstate.return_msg.rep.security = 2

+            log_info("pythonmod:  Returning answer")
             qstate.return_rcode = RCODE_NOERROR
             qstate.ext_state[id] = MODULE_FINISHED
             return True


This is the log for a test query:

Oct 29 10:28:03 chai unbound: [3598:0] info: 192.168.50.2
0.9.8.7.6.5.4.3.2.1.1.example.e164.arpa. NAPTR IN
Oct 29 10:28:03 chai unbound: [3598:0] info: pythonmod: Got NAPTR request
Oct 29 10:28:03 chai unbound: [3598:0] info: storeResponse: packet: ;;
->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 0#012;; flags: qr aa ra ;
QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0 #012;; QUESTION
SECTION:#012;; 0.9.8.7.6.5.4.3.2.1.1.example.e164.arpa
#011IN#011NAPTR#012#012;;
ANSWER SECTION:#012#012;; AUTHORITY SECTION:#012#012;; ADDITIONAL
SECTION:#012#012;; Query time: 0 msec#012;; WHEN: Thu Jan  1 00:00:00
1970#012;; MSG SIZE  rcvd: 47
Oct 29 10:28:03 chai unbound: [3598:0] info: pythonmod:  Returning answer
Oct 29 10:28:03 chai unbound: [3598:0] info: mesh_run: end 0 recursion
states (0 with reply, 0 detached), 0 waiting replies, 1 recursion replies
sent, 0 replies dropped, 0 states jostled out
Oct 29 10:28:03 chai unbound: [3598:0] info: average recursion processing
time 0.000000 sec
Oct 29 10:28:03 chai unbound: [3598:0] info: histogram of recursion
processing times
Oct 29 10:28:03 chai unbound: [3598:0] info: [25%]=0 median[50%]=0 [75%]=0
Oct 29 10:28:03 chai unbound: [3598:0] info: lower(secs) upper(secs)
recursions
Oct 29 10:28:03 chai unbound: [3598:0] info:    0.000000    0.000001 1

And the output from dig:

dig -p 5353 @192.168.50.2 IN NAPTR 0.9.8.7.6.5.4.3.2.1.1.example.e164.arpa

; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.3 <<>> -p 5353 @192.168.50.2 IN
NAPTR 0.9.8.7.6.5.4.3.2.1.1.example.e164.arpa
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19201
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
; 0.9.8.7.6.5.4.3.2.1.1.example.e164.arpa. IN NAPTR

;; Query time: 0 msec
;; SERVER: 192.168.50.2#5353(192.168.50.2)
;; WHEN: Tue Oct 29 17:28:03 2013
;; MSG SIZE  rcvd: 47



-- 
*Jeremy Shaffner*
Director of Information Technology
*cell/text* 925.480.7770
*Convo #* 240.751.4749
*email/iChat/FaceTime/Google* jeremy at convorelay.com **
****
**Convo™<http://media.convorelay.com/brand/email_sig/website.html?utm_campaign=sent-mail&utm_medium=email&utm_source=website>
 | ****convorelay.com<http://media.convorelay.com/brand/email_sig/website.html?utm_campaign=sent-mail&utm_medium=email&utm_source=website>
 |**
**
**
**
**
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nlnetlabs.nl/pipermail/unbound-users/attachments/20131029/2edf8a25/attachment.htm>


More information about the Unbound-users mailing list