performance - move external blacklists checks from nginx to LUA

This commit is contained in:
bunkerity
2021-05-10 17:51:07 +02:00
parent 009d6fb5ae
commit fd61df205f
14 changed files with 141 additions and 38 deletions

31
lua/dataloader.lua Normal file
View File

@@ -0,0 +1,31 @@
local M = {}
local iputils = require "resty.iputils"
function M.load_ip (path, dict)
local file = io.open(path, "r")
if not file then
ngx.log(ngx.ERR, "[INIT] can't open " .. path)
else
io.input(file)
local i = 0
for line in io.lines() do
if string.match(line, "/") then
local lower, upper = iputils.parse_cidr(line)
local bin_ip = lower
while bin_ip <= upper do
dict:set(bin_ip, true, 0)
bin_ip = bin_ip + 1
i = i + 1
end
else
local bin_ip, bin_octets = iputils.ip2bin(line)
dict:set(bin_ip, true, 0)
i = i + 1
end
end
ngx.log(ngx.ERR, "[INIT] loaded " .. tostring(i) .. " IPs from " .. path)
io.close(file)
end
end
return M