1Response generation 2=================== 3 4This example shows how to handle queries and generate response packet. 5 6.. note:: 7 If the python module is the first module and validator module is enabled 8 (``module-config: "python validator iterator"``), a return_msg security flag 9 has to be set at least to 2. Leaving security flag untouched causes that the 10 response will be refused by unbound worker as unbound will consider it as 11 non-valid response. 12 13Complete source code 14-------------------- 15 16.. literalinclude:: ../../examples/resgen.py 17 :language: python 18 19Testing 20------- 21 22Run the unbound server: 23 24``root@localhost>unbound -dv -c ./test-resgen.conf`` 25 26Query for a A record ending with .localdomain 27 28``dig A test.xxx.localdomain @127.0.0.1`` 29 30Dig produces the following output:: 31 32 ;; global options: printcmd 33 ;; Got answer: 34 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48426 35 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 36 37 ;; QUESTION SECTION: 38 ;test.xxx.localdomain. IN A 39 40 ;; ANSWER SECTION: 41 test.xxx.localdomain. 10 IN A 127.0.0.1 42 43 ;; Query time: 2 msec 44 ;; SERVER: 127.0.0.1#53(127.0.0.1) 45 ;; WHEN: Mon Jan 01 12:46:02 2009 46 ;; MSG SIZE rcvd: 54 47 48As we handle (override) in the python module only queries ending with 49``localdomain.``, unbound can still resolve host names. 50