- Add ip library,
- Move ip low level functions to ip library, - Add libs RPM package.
This commit is contained in:
@@ -79,88 +79,6 @@ declare -g NETWORK_NC_TIMEOUT
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# is_valid_ip
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
is_valid_ip()
|
||||
{
|
||||
local ip=$1
|
||||
local regex='^([0-9]{1,3}\.){3}[0-9]{1,3}$'
|
||||
|
||||
|
||||
if [[ $ip =~ $regex ]]
|
||||
then
|
||||
IFS='.' read -r o1 o2 o3 o4 <<< "$ip"
|
||||
|
||||
for octet in $o1 $o2 $o3 $o4
|
||||
do
|
||||
if (( octet < 0 || octet > 255 ))
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# ip_to_num
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ip_to_num()
|
||||
{
|
||||
local ip="$1"
|
||||
local a
|
||||
local b
|
||||
local c
|
||||
local d
|
||||
|
||||
IFS=. read -r a b c d <<< "${ip}"
|
||||
|
||||
echo $(( (a << 24) + (b << 16) + (c << 8) + d ))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# num_to_ip
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
num_to_ip()
|
||||
{
|
||||
local num="$1"
|
||||
|
||||
|
||||
# Optional safety check
|
||||
if (( num < 0 || num > 4294967295 ))
|
||||
then
|
||||
echo_error "num_to_ip: value out of range (0‑4294967295)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract each byte by shifting and masking
|
||||
local a=$(( (num >> 24) & 255 ))
|
||||
local b=$(( (num >> 16) & 255 ))
|
||||
local c=$(( (num >> 8) & 255 ))
|
||||
local d=$(( num & 255 ))
|
||||
|
||||
printf '%d.%d.%d.%d\n' "$a" "$b" "$c" "$d"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# network_common_load
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -658,7 +576,7 @@ network_src_tab_load()
|
||||
|
||||
log_trace "Network" "Loading Src tab..."
|
||||
|
||||
ip_base=$( ip_to_num ${NETWORK_SRC_LOCAL_ADDRESS})
|
||||
ip_base=$( ip_ip_to_num ${NETWORK_SRC_LOCAL_ADDRESS})
|
||||
|
||||
while IFS= read -r line
|
||||
do
|
||||
@@ -691,7 +609,7 @@ network_src_tab_load()
|
||||
# [[ $nstl_host_name =~ ([0-9]+) ]]
|
||||
# nstl_device="${NETWORK_SRC_LOCAL_DEVICE}-${BASH_REMATCH[1]}"
|
||||
|
||||
ip_num=$(ip_to_num ${nstl_ip})
|
||||
ip_num=$(ip_ip_to_num ${nstl_ip})
|
||||
device_num="$(( ( ${ip_num} - ${ip_base}) / 4))"
|
||||
|
||||
nstl_device="${NETWORK_SRC_LOCAL_DEVICE}-${device_num}"
|
||||
@@ -1214,7 +1132,7 @@ network_dst_address_refresh()
|
||||
dst_ip_new="$( nc -w "${NETWORK_NC_TIMEOUT}" "${proxy_host}" "${proxy_port}" 2>/dev/null)"
|
||||
fi
|
||||
|
||||
if is_valid_ip "${dst_ip_new}"
|
||||
if ip_is_valid_ip "${dst_ip_new}"
|
||||
then
|
||||
if [[ "${dst_ip}" != "${dst_ip_new}" ]]
|
||||
then
|
||||
|
||||
Reference in New Issue
Block a user