From: Vladimír Čunát Date: Tue, 9 Apr 2019 11:12:33 +0000 (+0200) Subject: fixup! modules/http DoH: allocate req.qsource on req.pool X-Git-Tag: v4.0.0~10^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec56c815b3021c90b65b90d6fc61fb287d927a57;p=thirdparty%2Fknot-resolver.git fixup! modules/http DoH: allocate req.qsource on req.pool Change handling of the inability to get address; it happens occasionally and the traces were disruptive. --- diff --git a/modules/http/http_doh.lua b/modules/http/http_doh.lua index fb4283ae1..8091250a0 100644 --- a/modules/http/http_doh.lua +++ b/modules/http/http_doh.lua @@ -8,17 +8,6 @@ local function get_http_ttl(pkt) return ffi.C.packet_ttl(pkt, is_negative) end -local function convert_sockaddr(pool, family, ipaddr, port) - local res = nil - if family and ipaddr and port then - res = ffi.C.kr_straddr_socket(ipaddr, port, pool) - end - if not res then - panic('failed to obtain peer IP address') - end - return res -end - -- Trace execution of DNS queries local function serve_doh(h, stream) local input @@ -57,6 +46,14 @@ local function serve_doh(h, stream) -- return 406, 'only Accept: application/dns-message is supported' -- end + -- We get these values beforehand, because it's easier to handle errors now. + local _, peer_addr, peer_port = stream:peername() + local _, dst_addr, dst_port = stream:localname() + if not (peer_addr and peer_port and dst_addr and dst_port) then + -- The connection probably died in the meantime or something. + return 504, 'failed to determine your address' + end + -- Output buffer local output local output_ttl @@ -90,8 +87,9 @@ local function serve_doh(h, stream) -- set source address so filters can work local function init_cb(req) - req.qsource.addr = convert_sockaddr(req.pool, stream:peername()) - req.qsource.dst_addr = convert_sockaddr(req.pool, stream:localname()) + req.qsource.addr = ffi.C.kr_straddr_socket(peer_addr, peer_port, req.pool) + req.qsource.dst_addr = ffi.C.kr_straddr_socket(dst_addr, dst_port, req.pool) + assert(req.qsource.addr ~= nil and req.qsource.dst_addr ~= nil) req.qsource.flags.tcp = true req.qsource.flags.tls = (stream.connection:checktls() ~= nil) req.qsource.flags.http = true