From 856f9dc636c8271e50ef43b673499b715c71b7b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 8 Apr 2019 15:54:43 +0200 Subject: [PATCH] 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. --- modules/http/http_doh.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 -- 2.47.2