| 1 | ==================================== |
|---|
| 2 | This is the luabackend for PowerDNS! |
|---|
| 3 | ==================================== |
|---|
| 4 | |
|---|
| 5 | Note: shortly before the 3.2 release of PowerDNS, Fredrik Danerklinkt |
|---|
| 6 | (author of this Luabackend) opened https://github.com/fredan/luabackend |
|---|
| 7 | and is doing development there. |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | http://www.lua.org for more information about what Lua really is. |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | This backend is just a "glue" between PowerDNS and your own Lua application. |
|---|
| 14 | |
|---|
| 15 | What this means is that you can not have a working setup that can serve you |
|---|
| 16 | dns-questions directly from start. What you need to do is to program your own |
|---|
| 17 | backend completely in Lua! Which database server to use etc is now up to you! |
|---|
| 18 | |
|---|
| 19 | What you have here is the possibility to make your own "dns-server" without the |
|---|
| 20 | knowledge of programming in c/c++. |
|---|
| 21 | |
|---|
| 22 | There is one thing that needs to be said. Remember that each thread |
|---|
| 23 | PowerDNS launches of this backend is completely different so they cannot |
|---|
| 24 | share information between each other! |
|---|
| 25 | |
|---|
| 26 | You will need some kind of a database that can be shared for this. |
|---|
| 27 | |
|---|
| 28 | All the functionnames that PowerDNS accept for a backend should be the same |
|---|
| 29 | in your Lua script, in lowercase. Also, the parameters should be in the same |
|---|
| 30 | order. Where there is a structure in c/c++ there is a table in the Lua backend. |
|---|
| 31 | This is also true for return values. A few functions expect that you return a |
|---|
| 32 | table in a table. |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | ============= |
|---|
| 36 | NEW FUNCTIONS |
|---|
| 37 | ============= |
|---|
| 38 | |
|---|
| 39 | There is a couple of new functions for you to use in Lua: |
|---|
| 40 | |
|---|
| 41 | ---------------------------------------- |
|---|
| 42 | logger(log_facility, "your", "messages") |
|---|
| 43 | ---------------------------------------- |
|---|
| 44 | |
|---|
| 45 | All these log_facilities is available: |
|---|
| 46 | log_all, log_ntlog, log_alert, log_critical, log_error, log_warning, log_notice, |
|---|
| 47 | log_info, log_debug, log_none |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | ----------- |
|---|
| 51 | dnspacket() |
|---|
| 52 | ----------- |
|---|
| 53 | |
|---|
| 54 | This will give you back three parameters with |
|---|
| 55 | remote_ip, remote_port and local_ip in that order. |
|---|
| 56 | |
|---|
| 57 | Can only be used in the functions list() and getsoa(). |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | ------------------------ |
|---|
| 61 | getarg("your_parameter") |
|---|
| 62 | ------------------------ |
|---|
| 63 | |
|---|
| 64 | This one tries to get the value of the name "lua-your_parameter" from the |
|---|
| 65 | pdns.conf file. |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | ------------------------ |
|---|
| 69 | mustdo("your_parameter") |
|---|
| 70 | ------------------------ |
|---|
| 71 | |
|---|
| 72 | This is the same as getarg() but return a boolean instead of a string. |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | You also have all the different QTypes in a table called 'QTypes'. |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | ==================== |
|---|
| 79 | WHAT HAS BEEN TESTED |
|---|
| 80 | ==================== |
|---|
| 81 | |
|---|
| 82 | The only functionality of the minimal functions except zone-transfer has |
|---|
| 83 | been tested. |
|---|
| 84 | |
|---|
| 85 | In the included powerdns-luabackend.lua file there is a example of how |
|---|
| 86 | this can be done. Note that this is more or less a static example since |
|---|
| 87 | there is no possibility for each thread to know when something has changed. |
|---|
| 88 | |
|---|
| 89 | However, you can run 'pdns_control reload' and it should reload the hole thing |
|---|
| 90 | from scratch (does not work for the moment, PowerDNS only calls two thread with |
|---|
| 91 | the reload command - not all of them). |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | =========================================== |
|---|
| 95 | WHAT YOU WILL FIND UNDER THE TEST DIRECTORY |
|---|
| 96 | =========================================== |
|---|
| 97 | |
|---|
| 98 | The script 'pdns' is used to test the server on the ip address '127.0.0.1' with |
|---|
| 99 | the port 5300. You should be able to run the following test with the included |
|---|
| 100 | 'powerdns-luabackend.lua' file: |
|---|
| 101 | |
|---|
| 102 | $dig any www.test.com @127.0.0.1 -p5300 +multiline |
|---|
| 103 | ; <<>> DiG 9.7.3 <<>> any www.test.com @127.0.0.1 -p5300 +multiline |
|---|
| 104 | ;; global options: +cmd |
|---|
| 105 | ;; Got answer: |
|---|
| 106 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1001 |
|---|
| 107 | ;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0 |
|---|
| 108 | ;; WARNING: recursion requested but not available |
|---|
| 109 | |
|---|
| 110 | ;; QUESTION SECTION: |
|---|
| 111 | ;www.test.com. IN ANY |
|---|
| 112 | |
|---|
| 113 | ;; ANSWER SECTION: |
|---|
| 114 | www.test.com. 120 IN CNAME host.test.com. |
|---|
| 115 | host.test.com. 120 IN A 10.11.12.13 |
|---|
| 116 | host.test.com. 120 IN AAAA 1:2:3:4:5:6:7:8 |
|---|
| 117 | |
|---|
| 118 | ;; Query time: 1 msec |
|---|
| 119 | ;; SERVER: 127.0.0.1#5300(127.0.0.1) |
|---|
| 120 | ;; WHEN: Thu Jun 2 22:19:56 2011 |
|---|
| 121 | ;; MSG SIZE rcvd: 93 |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | ============================= |
|---|
| 125 | OPTIONS IN THE CONFIGURE FILE |
|---|
| 126 | ============================= |
|---|
| 127 | |
|---|
| 128 | The default values is: |
|---|
| 129 | |
|---|
| 130 | lua-filename = powerdns-luabackend.lua |
|---|
| 131 | lua-logging-query = no |
|---|
| 132 | |
|---|
| 133 | You can also override all the default functionsnames for the luafunctions if you |
|---|
| 134 | want. The prefix is lua-f_<functionname>=mynewfunction. For example: |
|---|
| 135 | |
|---|
| 136 | lua-f_lookup = mynewfunction |
|---|
| 137 | |
|---|
| 138 | will call the function 'mynewfunction' for the lookup-routine. |
|---|
| 139 | |
|---|
| 140 | If you want your own configuration parameters you can have that too. |
|---|
| 141 | Just call the function getarg("my_parameter") and it will return the value |
|---|
| 142 | of 'lua-my_parameter'. For boolean you use the function mustdo("my_parameter"). |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | ============================== |
|---|
| 146 | YOUR OWN ERROR FUNCTION IN LUA |
|---|
| 147 | ============================== |
|---|
| 148 | |
|---|
| 149 | You can have an error function in Lua when Lua gives back a error. |
|---|
| 150 | |
|---|
| 151 | First make your error function then you put this in pdns.conf: |
|---|
| 152 | |
|---|
| 153 | lua-f_exec_error = <your_name_of_the_error_function_in_lua> |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | ====== |
|---|
| 157 | DNSSEC |
|---|
| 158 | ====== |
|---|
| 159 | |
|---|
| 160 | You can have full dnssec support in our Lua application. You should note the |
|---|
| 161 | following regarding this: |
|---|
| 162 | |
|---|
| 163 | You don't have to implement the function 'updateDNSSECOrderAndAuth' since the |
|---|
| 164 | default code will work correctly for you via the backend itself. |
|---|
| 165 | |
|---|
| 166 | The functions activateDomainKey and deactivateDomainKey can be implemented via a |
|---|
| 167 | new function called updateDomainKey, which has three parameters (the other two |
|---|
| 168 | has only two parameters) where the third is a boolean which is true or false |
|---|
| 169 | depending on which function that was called from the beginning. |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | ======================= |
|---|
| 173 | INFORMATION FOR LOGGING |
|---|
| 174 | ======================= |
|---|
| 175 | |
|---|
| 176 | If you have the parameter 'query-logging' or 'lua-logging-query' set to |
|---|
| 177 | true/yes/on, then you will see what is happening in each function when PowerDNS |
|---|
| 178 | calls them. |
|---|
| 179 | |
|---|
| 180 | This can, hopefully, help you with some debugging if you run into some kind of |
|---|
| 181 | trouble with your Lua application. |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | =============== |
|---|
| 185 | ASKING QUESTION |
|---|
| 186 | =============== |
|---|
| 187 | |
|---|
| 188 | You can send question about this backend to >dev/null first and if you don't get any |
|---|
| 189 | answer from that you can try to send them to me at fredan-pdns@fredan.org |
|---|
| 190 | |
|---|
| 191 | Fredrik Danerklint. |
|---|