comparison mod_net_proxy/mod_net_proxy.lua @ 3562:b33b2fbdc713

mod_net_proxy: Ensure port numbers are coerced into numbers LuaSocket likes to use strings for port numbers for some reason, so this might help with some type related problems.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Apr 2019 21:44:29 +0200
parents 97b30fec709c
children 9d65eb3fcb15
comparison
equal deleted inserted replaced
3561:deb5ece56c49 3562:b33b2fbdc713
287 end 287 end
288 conn.clientport = conn.port; 288 conn.clientport = conn.port;
289 end 289 end
290 290
291 -- Attempt to find service by processing port<>service mappings 291 -- Attempt to find service by processing port<>service mappings
292 local mapping = mappings[conn:serverport()]; 292 local mapping = mappings[tonumber(conn:serverport())];
293 if mapping == nil then 293 if mapping == nil then
294 conn:close(); 294 conn:close();
295 module:log("warn", "Connection %s@%s terminated: Could not find mapping for port %d", 295 module:log("warn", "Connection %s@%s terminated: Could not find mapping for port %d",
296 conn:ip(), conn:proxyip(), conn:serverport()); 296 conn:ip(), conn:proxyip(), conn:serverport());
297 return; 297 return;
441 end 441 end
442 442
443 -- Process all configured port mappings and generate a list of mapped ports 443 -- Process all configured port mappings and generate a list of mapped ports
444 local mapped_ports = {}; 444 local mapped_ports = {};
445 for port, mapping in pairs(config_mappings) do 445 for port, mapping in pairs(config_mappings) do
446 port = tonumber(port);
446 table.insert(mapped_ports, port); 447 table.insert(mapped_ports, port);
447 mappings[port] = { 448 mappings[port] = {
448 service_name = mapping, 449 service_name = mapping,
449 service = nil, 450 service = nil,
450 }; 451 };