Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update iputils.lua #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/resty/iputils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ end


local function parse_cidr(cidr)
local s, e = string.find(cidr, '-', 0, true)
if s ~= nil then
local sIP = string.sub(cidr, 0, s - 1)
local eIP = string.sub(cidr, e + 1, string.len(cidr))
local lower, _ = ip2bin(sIP) -- Convert IP to binary
if not lower then
return nil, nil
end
local upper, _ = ip2bin(eIP) -- Convert IP to binary
if not upper then
return nil, nil
end
return unsign(lower), unsign(upper)
end

local mask_split = split_cidr(cidr, '/')
local net = mask_split[1]
local mask = mask_split[2] or "32"
Expand Down