.. code-block:: lua
- function luaselector(dq)
+ function lua_selector(dq)
return dq.qtype == DNSQType.A
end
- addAction(LuaRule(luaselector), DropAction())
+ addAction(LuaRule(lua_selector), DropAction())
And for a custom action:
.. code-block:: lua
- function luapoolaction(dq)
- return DNSAction.Pool, "abuse" -- send to abuse pool
+ function lua_route_tc_to_abuse_pool(dq)
+ local tc = dq.dh:getTC()
+ -- The TC (truncated) bit should not be set in a query
+ if tc then
+ return DNSAction.Pool, "abuse" -- send to abuse pool
+ end
+ -- otherwise we keep processing subsequent rules, if any
+ return DNSAction.None
end
- addAction(AllRule(), LuaAction(luapoolaction))
+ addAction(AllRule(), LuaAction(lua_route_tc_to_abuse_pool))
If the YAML configuration is used, there are three different ways of calling a Lua function. The first option is to declare the Lua function in
a global Lua file that will loaded before the YAML configuration is parsed. This is done by creating a Lua file with the exact same name as
.. code-block:: lua
- function luapoolaction(dq)
- return DNSAction.Pool, "abuse" -- send to abuse pool
+ function lua_route_tc_to_abuse_pool(dq)
+ local tc = dq.dh:getTC()
+ -- The TC (truncated) bit should not be set in a query
+ if tc then
+ return DNSAction.Pool, "abuse" -- send to abuse pool
+ end
+ -- otherwise we keep processing subsequent rules, if any
+ return DNSAction.None
end
it is now possible to call this function from the YAML configuration at ``/etc/dnsdist/dnsdist.yml``
.. code-block:: yaml
query_rules:
- - name: "route powerdns.com to the abuse pool"
+ - name: "route truncated queries for powerdns.com to the abuse pool"
selector:
type: "QNameSet"
qnames:
- "powerdns.com."
action:
type: "Lua"
- function_name: "luapoolaction"
+ function_name: "lua_route_tc_to_abuse_pool"
-A second option is to declare the Lua code inline in the YAML configuration file, which requires returning a Lua function, which does not have to be named:
+A second option is to declare the Lua code inline in the YAML configuration file, which requires returning a Lua function, which does not need to be named:
.. code-block:: yaml
query_rules:
- - name: "route powerdns.com to the abuse pool"
+ - name: "route truncated queries for powerdns.com to the abuse pool"
selector:
type: "QNameSet"
qnames:
action:
type: "Lua"
function_code: |
- return function(dq)
- return DNSAction.Pool, "abuse" -- send to abuse pool
+ return function lua_route_tc_to_abuse_pool(dq)
+ local tc = dq.dh:getTC()
+ -- The TC (truncated) bit should not be set in a query
+ if tc then
+ return DNSAction.Pool, "abuse" -- send to abuse pool
+ end
+ -- otherwise we keep processing subsequent rules, if any
+ return DNSAction.None
end
.. code-block:: yaml
query_rules:
- - name: "route powerdns.com to the abuse pool"
+ - name: "route truncated queries for powerdns.com to the abuse pool"
selector:
type: "QNameSet"
qnames:
- "powerdns.com."
action:
type: "Lua"
- function_file: "/etc/dnsdist/lua-to-pool-abuse.lua"
+ function_file: "/etc/dnsdist/truncated-to-pool-abuse.lua"
-where the ``/etc/dnsdist/lua-to-pool-abuse.lua`` file contains:
+where the ``/etc/dnsdist/truncated-to-pool-abuse.lua`` file contains:
.. code-block:: lua
return function(dq)
- return DNSAction.Pool, "abuse" -- send to abuse pool
+ local tc = dq.dh:getTC()
+ -- The TC (truncated) bit should not be set in a query
+ if tc then
+ return DNSAction.Pool, "abuse" -- send to abuse pool
+ end
+ -- otherwise we keep processing subsequent rules, if any
+ return DNSAction.None
end