mirror of
https://github.com/gSpotx2f/ruantiblock_openwrt.git
synced 2026-05-14 06:30:59 +00:00
Blackhole route for VPN configuration.
luci-app-ruantiblock: UI changes for settings.js. ruantiblock-mod-lua, ruantiblock-mod-py: Added BLLIST_CIDR_EXCLUDED option.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
--[[
|
||||
(с) 2020 gSpot <https://github.com/gSpotx2f>
|
||||
(с) 2020 gSpot <https://github.com/gSpotx2f/iptool-lua>
|
||||
|
||||
Some functions for manipulating IPv4 addresses.
|
||||
|
||||
@@ -98,6 +98,7 @@ local function summarize_address_range(first, last)
|
||||
end
|
||||
local nbits = math.min(count_righthand_zero_bits(first, ip_bits), bit_length(last - first + 1) - 1)
|
||||
ret_val = {[1] = first, [2] = (ip_bits - nbits)}
|
||||
|
||||
first = first + lshift(1, nbits)
|
||||
if first - 1 == ipv4_capacity then
|
||||
return
|
||||
@@ -154,6 +155,50 @@ local function get_supernet(network, new_prefix)
|
||||
return band(network_address, lshift(netmask, diff_prefixlen))
|
||||
end
|
||||
|
||||
local function overlap_ip(ip, network)
|
||||
local network_address, prefixlen
|
||||
if type(network) == "string" then
|
||||
network_address, prefixlen = get_network_addr(network)
|
||||
elseif type(network) == "table" then
|
||||
network_address, prefixlen = network[1], network[2]
|
||||
else
|
||||
return
|
||||
end
|
||||
ip = ip_to_int(ip)
|
||||
if ip == nil then
|
||||
return
|
||||
end
|
||||
local offset = ipv4_length - prefixlen
|
||||
return (rshift(ip, offset) == rshift(network_address, offset))
|
||||
|
||||
end
|
||||
|
||||
local function check_network(net)
|
||||
local network_address, prefixlen
|
||||
if type(net) == "string" then
|
||||
network_address, prefixlen = get_network_addr(net)
|
||||
elseif type(net) == "table" then
|
||||
network_address, prefixlen = net[1], net[2]
|
||||
else
|
||||
return
|
||||
end
|
||||
return network_address, prefixlen
|
||||
end
|
||||
|
||||
local function overlap_net(subnet, network)
|
||||
local network_address_1, prefixlen_1 = check_network(subnet)
|
||||
local network_address_2, prefixlen_2 = check_network(network)
|
||||
if (network_address_1 == nil or prefixlen_1 == nil or
|
||||
network_address_2 == nil or prefixlen_2 == nil) then
|
||||
return
|
||||
end
|
||||
if network_address_1 == network_address_2 then
|
||||
return true
|
||||
end
|
||||
local offset = ipv4_length - math.min(prefixlen_1, prefixlen_2)
|
||||
return (rshift(network_address_1, offset) == rshift(network_address_2, offset))
|
||||
end
|
||||
|
||||
return {
|
||||
validate_ip = validate_ip,
|
||||
ip_to_int = ip_to_int,
|
||||
@@ -162,4 +207,6 @@ return {
|
||||
get_network_addr = get_network_addr,
|
||||
hosts_from_network = hosts_from_network,
|
||||
get_supernet = get_supernet,
|
||||
overlap_ip = overlap_ip,
|
||||
overlap_net = overlap_net,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user