- Rename vyprvpn-up/down to openvpn-up/down,

- Add network_route_dst_init function, to support VPN up/down roting table update.
This commit is contained in:
2025-08-09 10:29:41 +02:00
parent 67cb4f2940
commit e17b7ab24b
4 changed files with 64 additions and 38 deletions

View File

@@ -199,12 +199,12 @@ file_dir_init()
local dir local dir
if [[ "$( id -u)" != "0" ]] if [ ! -f ${File} ]
then then
${ECHO} "Can't perform file init of: [${File}] as non root user!" if [[ "$( id -u)" != "0" ]]
else
if [ ! -f ${File} ]
then then
${ECHO} "Can't perform file init of: [${File}] as non root user!"
else
dir="$( dirname ${File})" dir="$( dirname ${File})"
if [ ! -d ${dir} ] if [ ! -d ${dir} ]

View File

@@ -698,40 +698,51 @@ network_tab_dump()
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
# network_table_init # network_route_init
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
network_table_init() network_route_dst_init()
{ {
local dst_id="$1"
network_dst_tab_get ${dst_id}
if [[ ${dst_type} == "0" ]]
then
log_trace "Network" "Copy main default route into table ${dst_table} (VPN Local routing table)"
if [[ "$(ip route list match 0.0.0.0 table main)" != "" ]]
then
${DEBUG} ip route add $(ip route list match 0.0.0.0 table main) table ${dst_table}
fi
else
log_trace "Network" "Define default route to device: [${dst_device}] into table: [${dst_table}]"
if [[ "$(ip link show ${dst_device})" != "" ]]
then
${DEBUG} ip route add default dev ${dst_device} table ${dst_table}
fi
fi
target_device=${dst_device}
log_trace "Network" "Add [${target_device}] Rx3 routes in VPN tables"
for dst_id in ${NETWORK_DST_ID_LIST} for dst_id in ${NETWORK_DST_ID_LIST}
do do
network_dst_tab_get ${dst_id} network_dst_tab_get ${dst_id}
if [[ ${dst_type} == "0" ]] for ip_route_id in ${NETWORK_IP_ROUTE_ID_LIST}
then do
log_trace "Network" "Copy main default route into table 3 (VPN Local routing table)"
if [[ "$(ip route list match 0.0.0.0 table main)" != "" ]]
then
${DEBUG} ip route add $(ip route list match 0.0.0.0 table main) table 3
fi
else
log_trace "Network" "Define default route to device: [${dst_device}] into table: [${dst_table}]"
if [[ "$(ip link show ${dst_device})" != "" ]]
then
${DEBUG} ip route add default dev ${dst_device} table ${dst_table}
fi
fi
log_trace "Network" "Add Rx3 routes in VPN tables"
for ip_route_id in ${NETWORK_IP_ROUTE_ID_LIST}
do
network_ip_route_tab_get ${ip_route_id} network_ip_route_tab_get ${ip_route_id}
${DEBUG} ip route add ${ip_route_ip}/${ip_route_mask} table ${dst_table} dev ${ip_route_device} if [[ "${ip_route_device}" == "${target_device}" ]]
done then
${DEBUG} ip route add ${ip_route_ip}/${ip_route_mask} table ${dst_table} dev ${ip_route_device}
fi
done
done done
} }
@@ -740,10 +751,26 @@ network_table_init()
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
# network_table_deinit # network_route_init
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
network_table_deinit() network_route_init()
{
for dst_id in ${NETWORK_DST_ID_LIST}
do
network_route_dst_init ${dst_id}
done
}
#--------------------------------------------------------------------------------------------------------------------------
# network_route_deinit
#--------------------------------------------------------------------------------------------------------------------------
network_route_deinit()
{ {
log_trace "Network" "Remove Rx3 routes in VPN tables" log_trace "Network" "Remove Rx3 routes in VPN tables"
@@ -1186,7 +1213,7 @@ network_start()
{ {
log_info "Network" "Starting network..." log_info "Network" "Starting network..."
network_table_init network_route_init
network_bridge_init network_bridge_init
@@ -1211,7 +1238,7 @@ network_stop()
network_bridge_deinit network_bridge_deinit
network_table_deinit network_route_deinit
log_info "Network" "Network stoped!" log_info "Network" "Network stoped!"

View File

@@ -51,8 +51,7 @@ then
log_info "VPN-Up" "$line" " Status: [OK]" log_info "VPN-Up" "$line" " Status: [OK]"
log_trace "VPN-Up" "[${Dev}]: ip route add table: [${dst_table}] default dev: [${Dev}]" log_trace "VPN-Up" "[${Dev}]: ip route add table: [${dst_table}] default dev: [${Dev}]"
${DEBUG} ip route del table ${dst_table} default network_route_dst_init ${dst_id}
${DEBUG} ip route add table ${dst_table} default dev ${Dev}
else else
log_error "VPN-Up" "$line" " Status: [ERROR]!" log_error "VPN-Up" "$line" " Status: [ERROR]!"
fi fi