Add CIDR support in Historical Flows

This commit is contained in:
Alfredo Cardigliano 2023-01-25 14:38:50 +01:00
parent eaf6f9ebbf
commit 3a36fb9ba3
6 changed files with 89 additions and 45 deletions

View file

@ -500,50 +500,6 @@ end
-- ##############################################
function isIPv4(address)
-- Reuse the for loop to check the address validity
local checkAddress = (function(chunks)
for _, v in pairs(chunks) do
if (tonumber(v) < 0) or (tonumber(v) > 255) then
return false
end
end
return true
end)
local chunks = {address:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")}
local chunksWithPort = {address:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)%:(%d+)$")}
if #chunks == 4 then
return checkAddress(chunks)
elseif #chunksWithPort == 5 then
table.remove(chunksWithPort, 5)
return checkAddress(chunksWithPort)
end
return false
end
-- ##############################################
function isIPv4Network(address)
local parts = split(address, "/")
if #parts == 2 then
local prefix = tonumber(parts[2])
if (prefix == nil) or (math.floor(prefix) ~= prefix) or (prefix < 0) or (prefix > 32) then
return false
end
elseif #parts ~= 1 then
return false
end
return isIPv4(parts[1])
end
-- ##############################################
--
-- Fix member format (IP address to /32 CIDR and VLAN to default 0)
-- E.g. 192.168.1.10 -> 192.168.1.10/32@0