Header flags can now be set from Lua, as well as packet payload clearing.
# Utils
kr_rand_uint
kr_make_query
- kr_pkt_make_auth_header
kr_pkt_put
kr_pkt_recycle
kr_pkt_clear_payload
return knot_pkt_put(pkt, 0, &rr, KNOT_PF_FREE);
}
-void kr_pkt_make_auth_header(knot_pkt_t *pkt)
-{
- assert(pkt && pkt->wire);
- knot_wire_clear_ad(pkt->wire);
- knot_wire_set_aa(pkt->wire);
-}
-
const char *kr_inaddr(const struct sockaddr *addr)
{
if (!addr) {
int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
uint16_t rclass, uint16_t rtype, const uint8_t *rdata, uint16_t rdlen);
-/** Set packet header suitable for authoritative answer. (for policy module) */
-KR_EXPORT
-void kr_pkt_make_auth_header(knot_pkt_t *pkt);
-
/** Simple storage for IPx address or AF_UNSPEC. */
union inaddr {
struct sockaddr ip;
local dname_localhost = todname('localhost.')
-- Rule for localhost. zone; see RFC6303, sec. 3
-local function localhost(_, req)
- local qry = req:current()
+local function localhost(_, req, qry)
local answer = req.answer
- ffi.C.kr_pkt_make_auth_header(answer)
+ answer:ad(false)
+ answer:aa(true)
local is_exact = ffi.C.knot_dname_is_equal(qry.sname, dname_localhost)
end
end
- ffi.C.kr_pkt_make_auth_header(answer)
+ answer:ad(false)
+ answer:aa(true)
answer:rcode(kres.rcode.NOERROR)
answer:begin(kres.section.ANSWER)
if is_exact and qry.stype == kres.type.PTR then
return function (_, req)
-- Write authority information
local answer = req.answer
- ffi.C.kr_pkt_make_auth_header(answer)
+ answer:ad(false)
+ answer:aa(true)
answer:rcode(kres.rcode.NXDOMAIN)
answer:begin(kres.section.AUTHORITY)
mkauth_soa(answer, answer:qname())
-- If not rewritten, chain action
if not changed then return end
-- Replace section if renumbering
- local qname = pkt:qname()
- local qclass = pkt:qclass()
- local qtype = pkt:qtype()
- pkt:recycle()
- pkt:question(qname, qclass, qtype)
- for i = 1, ancount do
- local rr = records[i]
+ pkt:clear_payload()
+ for _, rr in ipairs(records) do
-- Strip signatures as rewritten data cannot be validated
if rr.type ~= kres.type.RRSIG then
pkt:put(rr.owner, rr.ttl, rr.class, rr.type, rr.rdata)