From: Vladimír Čunát Date: Mon, 8 Apr 2019 13:54:43 +0000 (+0200) Subject: modules/http DoH: allocate req.qsource on req.pool X-Git-Tag: v4.0.0~10^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=856f9dc636c8271e50ef43b673499b715c71b7b9;p=thirdparty%2Fknot-resolver.git modules/http DoH: allocate req.qsource on req.pool The problem is that C structures are not scanned by lua GC, so we'd have to keep these alive in some other way; therefore it's simpler to just use the mempool. --- diff --git a/modules/http/http_doh.lua b/modules/http/http_doh.lua index 95bf02e3d..e7a8f2a86 100644 --- a/modules/http/http_doh.lua +++ b/modules/http/http_doh.lua @@ -8,11 +8,12 @@ local function get_http_ttl(pkt) return ffi.C.packet_ttl(pkt, is_negative) end -local function convert_sockaddr(family, ipaddr, port) - if not (family and ipaddr and port) then +local function convert_sockaddr(pool, family, ipaddr, port) + local res = ffi.C.kr_straddr_socket(ipaddr, port, pool) -- resilient to bad parameters + if not (family and ipaddr and port and res ~= nil) then panic('failed to obtain peer IP address') end - return ffi.gc(ffi.C.kr_straddr_socket(ipaddr, port, nil), ffi.C.free) + return res end -- Trace execution of DNS queries @@ -86,8 +87,8 @@ local function serve_doh(h, stream) -- set source address so filters can work local function init_cb(req) - req.qsource.addr = convert_sockaddr(stream:peername()) - req.qsource.dst_addr = convert_sockaddr(stream:localname()) + req.qsource.addr = convert_sockaddr(req.pool, stream:peername()) + req.qsource.dst_addr = convert_sockaddr(req.pool, stream:localname()) req.qsource.flags.tcp = true req.qsource.flags.tls = (stream.connection:checktls() ~= nil) req.qsource.flags.http = true