- Add ip library,
- Move ip low level functions to ip library, - Add libs RPM package.
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
Network Tools V 1.2.0 - A. GIBERT - 2026/04/20
|
Network Tools V 1.2.0 - A. GIBERT - 2026/04/23
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
- Split repository to remove the Rx3 configuration part and push it to rx3-config repo,
|
- Split repository to remove the Rx3 configuration part and push it to rx3-config repo,
|
||||||
- Switch this repository to public,
|
- Switch this repository to public,
|
||||||
- Migrate Network Tools to the new Rx3 Base Bash library,
|
- Migrate Network Tools to the new Rx3 Base Bash library,
|
||||||
|
- Add ip library,
|
||||||
- Move usr/lib, usr/sbin & var/www to lib, sbin & www,
|
- Move usr/lib, usr/sbin & var/www to lib, sbin & www,
|
||||||
- Add dns_host_update() to dns library,
|
- Add dns_host_update() to dns library,
|
||||||
- Add RPM Spec & bash completion files,
|
- Add RPM Spec & bash completion files,
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ Packager: Arnaud G. GIBERT <arnaud@rx3.net>
|
|||||||
|
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
|
|
||||||
Requires: rx3-base
|
Requires: %{name}-libs
|
||||||
|
|
||||||
|
|
||||||
%description
|
%description
|
||||||
These tools aims to manage network operation on Rx3 systems. This include:
|
These tools aims to manage network operation on Rx3 systems. This include:
|
||||||
@@ -69,6 +70,17 @@ This release support IPTables and OpenVPN.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%package libs
|
||||||
|
Summary: Rx3 Network Tools Libraries
|
||||||
|
Requires: rx3-base
|
||||||
|
Requires: bind-utils
|
||||||
|
|
||||||
|
|
||||||
|
%description libs
|
||||||
|
These tools aims to manage network operation on Rx3 systems.
|
||||||
|
This is the bash libraires.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -106,7 +118,6 @@ cp etc/sysconfig/* %{buildroot}%{_sysconfdir}/sysconfig
|
|||||||
%{__mkdir_p} %{buildroot}%{_unitdir}
|
%{__mkdir_p} %{buildroot}%{_unitdir}
|
||||||
cp etc/systemd/system/* %{buildroot}%{_unitdir}
|
cp etc/systemd/system/* %{buildroot}%{_unitdir}
|
||||||
|
|
||||||
|
|
||||||
# Bash completion
|
# Bash completion
|
||||||
%{__mkdir_p} %{buildroot}%{_sysconfdir}/bash_completion.d
|
%{__mkdir_p} %{buildroot}%{_sysconfdir}/bash_completion.d
|
||||||
cp etc/bash_completion.d/* %{buildroot}%{_sysconfdir}/bash_completion.d
|
cp etc/bash_completion.d/* %{buildroot}%{_sysconfdir}/bash_completion.d
|
||||||
@@ -142,7 +153,8 @@ cp www/cgi-bin/*.cgi %{buildroot}%{_webcgi}
|
|||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
%post
|
%post
|
||||||
%_post_service %{name}
|
%_post_service rx3-network
|
||||||
|
%_post_service rx3-vpn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -153,7 +165,8 @@ cp www/cgi-bin/*.cgi %{buildroot}%{_webcgi}
|
|||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
%preun
|
%preun
|
||||||
%_preun_service %{name}
|
%_preun_service rx3-vpn
|
||||||
|
%_preun_service rx3-network
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -170,11 +183,16 @@ cp www/cgi-bin/*.cgi %{buildroot}%{_webcgi}
|
|||||||
%defattr(644,root,root)
|
%defattr(644,root,root)
|
||||||
%{_sysconfdir}/bash_completion.d/*
|
%{_sysconfdir}/bash_completion.d/*
|
||||||
%{_unitdir}/*.service
|
%{_unitdir}/*.service
|
||||||
%{_prefix}/lib/rx3/*
|
|
||||||
%defattr(0755,root,root)
|
%defattr(0755,root,root)
|
||||||
%{_sbindir}/*
|
%{_sbindir}/*
|
||||||
%{_webcgi}/*.cgi
|
%{_webcgi}/*.cgi
|
||||||
|
|
||||||
|
%files libs
|
||||||
|
%doc ReadMe.txt ReleaseNotes.txt ToDo.txt
|
||||||
|
%license COPYING COPYING.LESSER GNU_GPL-3.0.txt GNU_LGPL-3.0.txt GNU_FDL-1.3.txt
|
||||||
|
%defattr(644,root,root)
|
||||||
|
%{_prefix}/lib/rx3/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -184,5 +202,5 @@ cp www/cgi-bin/*.cgi %{buildroot}%{_webcgi}
|
|||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Mon Apr 20 2026 Arnaud G. GIBERT <arnaud@rx3.net> - 1.2.0-1rx3.mga9
|
* Tue Apr 21 2026 Arnaud G. GIBERT <arnaud@rx3.net> - 1.2.0-1rx3.mga9
|
||||||
- Create initial SPEC file for 1.2.0 on Mageia 9
|
- Create initial SPEC file for 1.2.0 on Mageia 9
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ fi
|
|||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
|
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
|
||||||
. "${RX3_LIB_DIR}/base.bash"
|
. "${RX3_LIB_DIR}/ip.bash"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,13 +47,13 @@ fi
|
|||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
declare -Ag DNS_A_TAB
|
declare -Ag DNS_A_TAB
|
||||||
declare -g DNS_A_ID_LIST
|
declare -g DNS_A_ID_LIST=""
|
||||||
|
|
||||||
declare -Ag DNS_PTR_TAB
|
declare -Ag DNS_PTR_TAB
|
||||||
declare -g DNS_PTR_ID_LIST
|
declare -g DNS_PTR_ID_LIST=""
|
||||||
|
|
||||||
declare -g DNS_CACHE_FILE
|
declare -g DNS_CACHE_FILE=""
|
||||||
declare -g DNS_CACHE_LOCK
|
declare -g DNS_CACHE_LOCK=""
|
||||||
#declare -g DNS_CACHE_LOCK="${DNS_CACHE_FILE}"
|
#declare -g DNS_CACHE_LOCK="${DNS_CACHE_FILE}"
|
||||||
|
|
||||||
declare -g DNS_CACHE_UPDATED=0
|
declare -g DNS_CACHE_UPDATED=0
|
||||||
@@ -224,19 +224,19 @@ dns_lookup()
|
|||||||
|
|
||||||
if [[ "${dl_flag}" != "NOCACHE" ]]
|
if [[ "${dl_flag}" != "NOCACHE" ]]
|
||||||
then
|
then
|
||||||
dns_tab_get ${dl_type} ${dl_key}
|
{ dns_tab_get ${dl_type} ${dl_key}; rc=$?; } || true
|
||||||
else
|
else
|
||||||
false
|
rc=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$?" != "0" ]]
|
if [[ "${rc}" != "0" ]]
|
||||||
then
|
then
|
||||||
log_trace "DNS" "Out of Cache: Type: [${dl_type}] Key: [${dl_key}] Flag: [${dl_flag}]"
|
#log_trace "DNS" "Out of Cache: Type: [${dl_type}] Key: [${dl_key}] Flag: [${dl_flag}]"
|
||||||
|
|
||||||
case ${dl_type}
|
case ${dl_type}
|
||||||
in
|
in
|
||||||
"A")
|
"A")
|
||||||
dns_value="$( dig +short ${dl_key} 2>/dev/null)"
|
dns_value="$( dig +short ${dl_key} 2>/dev/null | ip_ip_filter)"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"PTR")
|
"PTR")
|
||||||
@@ -333,8 +333,8 @@ dns_host_update()
|
|||||||
|
|
||||||
dns_init()
|
dns_init()
|
||||||
{
|
{
|
||||||
file_dir_init ${DNS_CACHE_FILE} root apache
|
file_dir_init "${DNS_CACHE_FILE}" root apache
|
||||||
file_dir_init ${DNS_CACHE_LOCK} root apache
|
file_dir_init "${DNS_CACHE_LOCK}" root apache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
145
lib/rx3/ip.bash
Normal file
145
lib/rx3/ip.bash
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Rx3 IP Library
|
||||||
|
#
|
||||||
|
# Copyright (C) 2025-2026 Arnaud G. GIBERT
|
||||||
|
# mailto:arnaud@rx3.net
|
||||||
|
#
|
||||||
|
# This is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this program; If not, see
|
||||||
|
# <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if [[ "${RX3_IP_LIB}" != "" ]]
|
||||||
|
then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
declare -g RX3_IP_LIB=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Includes
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
|
||||||
|
. "${RX3_LIB_DIR}/base.bash"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Global Variable
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Is Valid Ip
|
||||||
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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_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
|
||||||
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
# IP Filter
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ip_ip_filter()
|
||||||
|
{
|
||||||
|
grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
# network_common_load
|
||||||
#--------------------------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -658,7 +576,7 @@ network_src_tab_load()
|
|||||||
|
|
||||||
log_trace "Network" "Loading Src tab..."
|
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
|
while IFS= read -r line
|
||||||
do
|
do
|
||||||
@@ -691,7 +609,7 @@ network_src_tab_load()
|
|||||||
# [[ $nstl_host_name =~ ([0-9]+) ]]
|
# [[ $nstl_host_name =~ ([0-9]+) ]]
|
||||||
# nstl_device="${NETWORK_SRC_LOCAL_DEVICE}-${BASH_REMATCH[1]}"
|
# 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))"
|
device_num="$(( ( ${ip_num} - ${ip_base}) / 4))"
|
||||||
|
|
||||||
nstl_device="${NETWORK_SRC_LOCAL_DEVICE}-${device_num}"
|
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)"
|
dst_ip_new="$( nc -w "${NETWORK_NC_TIMEOUT}" "${proxy_host}" "${proxy_port}" 2>/dev/null)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_valid_ip "${dst_ip_new}"
|
if ip_is_valid_ip "${dst_ip_new}"
|
||||||
then
|
then
|
||||||
if [[ "${dst_ip}" != "${dst_ip_new}" ]]
|
if [[ "${dst_ip}" != "${dst_ip_new}" ]]
|
||||||
then
|
then
|
||||||
|
|||||||
Reference in New Issue
Block a user