ne 19. 2. 2023 o 21:36 Vladimír Čunát <vladimir.cunat(a)nic.cz> napísal(a):
This part won't construct correct wire format for
SVCB.
Yes, you are correct. I had to find more about SVCB records.
But your solution is still missing "additional section".
I build up working solution:
local ffi = require('ffi')
local function DDR_SVCB(state, req)
local answer = req:ensure_answer()
if answer == nil then return nil end
local qry = req:current()
if qry.stype ~= kres.type.SVCB then
return state
end
ffi.C.kr_pkt_make_auth_header(answer)
answer:rcode(kres.rcode.NOERROR)
answer:begin(kres.section.ANSWER)
local records = kres.parse_rdata({
'SVCB 1 dns.levonet.sk. alpn=dot port=853
ipv4hint=109.236.119.2,109.236.120.2
ipv6hint=2a02:6ca3:0:1::2,2a02:6ca3:0:2::2',
'SVCB 2 dns.levonet.sk. alpn=h2 port=443
ipv4hint=109.236.119.2,109.236.120.2
ipv6hint=2a02:6ca3:0:1::2,2a02:6ca3:0:2::2 key7=/dns-query{?dns}',
})
for _, entry in ipairs(records) do
answer:put(qry.sname, 900, answer:qclass(), kres.type.SVCB, entry)
end
answer:begin(kres.section.ADDITIONAL)
answer:put(todname('dns.levonet.sk'), 900, answer:qclass(),
kres.type.A, kres.str2ip('109.236.119.2'))
answer:put(todname('dns.levonet.sk'), 900, answer:qclass(),
kres.type.A, kres.str2ip('109.236.120.2'))
answer:put(todname('dns.levonet.sk'), 900, answer:qclass(),
kres.type.AAAA, kres.str2ip('2a02:6ca3:0:1::2'))
answer:put(todname('dns.levonet.sk'), 900, answer:qclass(),
kres.type.AAAA, kres.str2ip('2a02:6ca3:0:2::2'))
return kres.DONE
end
policy.add(policy.domains(DDR_SVCB, policy.todnames({'_dns.resolver.arpa'})))
and it returns:
kdig _dns.resolver.arpa @109.236.120.2 type64
;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 41607
;; Flags: qr aa rd ra; QUERY: 1; ANSWER: 2; AUTHORITY: 0; ADDITIONAL: 4
;; QUESTION SECTION:
;; _dns.resolver.arpa. IN SVCB
;; ANSWER SECTION:
_dns.resolver.arpa. 900 IN SVCB 1 dns.levonet.sk. alpn=dot port=853
ipv4hint=109.236.119.2,109.236.120.2
ipv6hint=2a02:6ca3:0:1::2,2a02:6ca3:0:2::2
_dns.resolver.arpa. 900 IN SVCB 2 dns.levonet.sk. alpn=h2 port=443
ipv4hint=109.236.119.2,109.236.120.2
ipv6hint=2a02:6ca3:0:1::2,2a02:6ca3:0:2::2 key7="/dns-query{?dns}"
;; ADDITIONAL SECTION:
dns.levonet.sk. 900 IN A 109.236.119.2
dns.levonet.sk. 900 IN A 109.236.120.2
dns.levonet.sk. 900 IN AAAA 2a02:6ca3:0:1::2
dns.levonet.sk. 900 IN AAAA 2a02:6ca3:0:2::2
;; Received 324 B
;; Time 2023-02-19 22:00:07 CET
;; From 109.236.120.2@53(UDP) in 0.8 ms