mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-28 23:19:33 +00:00
Accepts addresses with no profix or no vlan in lua/admin/manage_pool_members.lua
This commit is contained in:
parent
52c316d214
commit
6fcbcdd036
5 changed files with 85 additions and 20 deletions
|
|
@ -542,6 +542,58 @@ function isIPv4Network(address)
|
|||
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
|
||||
--
|
||||
|
||||
function fixPoolMemberFormat(member)
|
||||
if isEmptyString(member) then
|
||||
return nil
|
||||
end
|
||||
|
||||
if isMacAddress(member) then
|
||||
return member
|
||||
end
|
||||
|
||||
-- VLAN
|
||||
local vlan_id
|
||||
local vlan_idx = string.find(member, "@")
|
||||
if vlan_idx == nil then
|
||||
vlan_id = 0
|
||||
elseif vlan_idx == 1 then
|
||||
return nil
|
||||
else
|
||||
local other = string.sub(member, 1, vlan_idx-1)
|
||||
vlan_id = tonumber(string.sub(member, vlan_idx+1))
|
||||
if vlan_id == nil or vlan_id < 0 then
|
||||
return nil
|
||||
end
|
||||
member = other
|
||||
end
|
||||
|
||||
-- prefix is mandatory here
|
||||
local address, prefix = splitNetworkPrefix(member)
|
||||
if address == nil then
|
||||
return nil
|
||||
elseif prefix == nil then
|
||||
prefix = '32'
|
||||
end
|
||||
|
||||
if isIPv4(address) and (tonumber(prefix) >= 0) and (tonumber(prefix) <= 32) then
|
||||
-- ok
|
||||
elseif isIPv6(address) and (tonumber(prefix) >= 0) and (tonumber(prefix) <= 128) then
|
||||
-- ok
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
||||
return address .. '/' .. prefix .. '@' .. vlan_id
|
||||
end
|
||||
|
||||
|
||||
-- ##############################################
|
||||
|
||||
--
|
||||
|
|
@ -576,6 +628,7 @@ function isValidPoolMember(member)
|
|||
if prefix == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
if isIPv4(address) and (tonumber(prefix) >= 0) and (tonumber(prefix) <= 32) then
|
||||
return true
|
||||
elseif isIPv6(address) and (tonumber(prefix) >= 0) and (tonumber(prefix) <= 128) then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue