Commit 856f9dc6 authored by Vladimír Čunát's avatar Vladimír Čunát Committed by Petr Špaček

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.
parent 39d1e63b
......@@ -8,11 +8,12 @@ local function get_http_ttl(pkt)
return ffi.C.packet_ttl(pkt, is_negative)
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')
return ffi.gc(ffi.C.kr_straddr_socket(ipaddr, port, nil),
return res
-- 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment