libs/core: remove various uses of global vars in luci.ip
This commit is contained in:
parent
07e06f185a
commit
481cd6feb7
1 changed files with 10 additions and 1 deletions
|
@ -220,7 +220,7 @@ function IPv6(address, netmask)
|
||||||
end
|
end
|
||||||
|
|
||||||
local borderl = address:sub(1, 1) == ":" and 2 or 1
|
local borderl = address:sub(1, 1) == ":" and 2 or 1
|
||||||
local borderh, zeroh, chunk, block
|
local borderh, zeroh, chunk, block, i
|
||||||
|
|
||||||
if #address > 45 then return nil end
|
if #address > 45 then return nil end
|
||||||
|
|
||||||
|
@ -297,6 +297,7 @@ function Hex( hex, prefix, family, swap )
|
||||||
local len = __maxlen(family)
|
local len = __maxlen(family)
|
||||||
local tmp = ""
|
local tmp = ""
|
||||||
local data = { }
|
local data = { }
|
||||||
|
local i
|
||||||
|
|
||||||
for i = 1, (len/4) - #hex do tmp = tmp .. '0' end
|
for i = 1, (len/4) - #hex do tmp = tmp .. '0' end
|
||||||
|
|
||||||
|
@ -403,6 +404,7 @@ end
|
||||||
-- @see cidr.equal
|
-- @see cidr.equal
|
||||||
function cidr.lower( self, addr )
|
function cidr.lower( self, addr )
|
||||||
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
|
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
|
||||||
|
local i
|
||||||
for i = 1, #self[2] do
|
for i = 1, #self[2] do
|
||||||
if self[2][i] ~= addr[2][i] then
|
if self[2][i] ~= addr[2][i] then
|
||||||
return self[2][i] < addr[2][i]
|
return self[2][i] < addr[2][i]
|
||||||
|
@ -420,6 +422,7 @@ end
|
||||||
-- @see cidr.equal
|
-- @see cidr.equal
|
||||||
function cidr.higher( self, addr )
|
function cidr.higher( self, addr )
|
||||||
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
|
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
|
||||||
|
local i
|
||||||
for i = 1, #self[2] do
|
for i = 1, #self[2] do
|
||||||
if self[2][i] ~= addr[2][i] then
|
if self[2][i] ~= addr[2][i] then
|
||||||
return self[2][i] > addr[2][i]
|
return self[2][i] > addr[2][i]
|
||||||
|
@ -437,6 +440,7 @@ end
|
||||||
-- @see cidr.higher
|
-- @see cidr.higher
|
||||||
function cidr.equal( self, addr )
|
function cidr.equal( self, addr )
|
||||||
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
|
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
|
||||||
|
local i
|
||||||
for i = 1, #self[2] do
|
for i = 1, #self[2] do
|
||||||
if self[2][i] ~= addr[2][i] then
|
if self[2][i] ~= addr[2][i] then
|
||||||
return false
|
return false
|
||||||
|
@ -460,6 +464,7 @@ function cidr.prefix( self, mask )
|
||||||
|
|
||||||
if not obj then return nil end
|
if not obj then return nil end
|
||||||
|
|
||||||
|
local _, word
|
||||||
for _, word in ipairs(obj[2]) do
|
for _, word in ipairs(obj[2]) do
|
||||||
if word == 0xFFFF then
|
if word == 0xFFFF then
|
||||||
prefix = prefix + 16
|
prefix = prefix + 16
|
||||||
|
@ -489,6 +494,7 @@ function cidr.network( self, bits )
|
||||||
local data = { }
|
local data = { }
|
||||||
bits = bits or self[3]
|
bits = bits or self[3]
|
||||||
|
|
||||||
|
local i
|
||||||
for i = 1, math.floor( bits / 16 ) do
|
for i = 1, math.floor( bits / 16 ) do
|
||||||
data[#data+1] = self[2][i]
|
data[#data+1] = self[2][i]
|
||||||
end
|
end
|
||||||
|
@ -578,6 +584,7 @@ end
|
||||||
-- @return CIDR representing the new address or nil on overflow error
|
-- @return CIDR representing the new address or nil on overflow error
|
||||||
-- @see cidr.sub
|
-- @see cidr.sub
|
||||||
function cidr.add( self, amount, inplace )
|
function cidr.add( self, amount, inplace )
|
||||||
|
local pos
|
||||||
local data = { unpack(self[2]) }
|
local data = { unpack(self[2]) }
|
||||||
local shorts = __array16( amount, self[1] )
|
local shorts = __array16( amount, self[1] )
|
||||||
|
|
||||||
|
@ -609,6 +616,7 @@ end
|
||||||
-- @return CIDR representing the new address or nil on underflow error
|
-- @return CIDR representing the new address or nil on underflow error
|
||||||
-- @see cidr.add
|
-- @see cidr.add
|
||||||
function cidr.sub( self, amount, inplace )
|
function cidr.sub( self, amount, inplace )
|
||||||
|
local pos
|
||||||
local data = { unpack(self[2]) }
|
local data = { unpack(self[2]) }
|
||||||
local shorts = __array16( amount, self[1] )
|
local shorts = __array16( amount, self[1] )
|
||||||
|
|
||||||
|
@ -649,6 +657,7 @@ end
|
||||||
-- @see cidr.minhost
|
-- @see cidr.minhost
|
||||||
function cidr.maxhost( self )
|
function cidr.maxhost( self )
|
||||||
if self[3] <= __sublen(self[1]) then
|
if self[3] <= __sublen(self[1]) then
|
||||||
|
local i
|
||||||
local data = { unpack(self[2]) }
|
local data = { unpack(self[2]) }
|
||||||
local offset = math.floor( self[3] / 16 ) + 1
|
local offset = math.floor( self[3] / 16 ) + 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue