diff --git a/usr/local/lib/default.bash b/usr/local/lib/default.bash index 78b3a81..31a98c3 100644 --- a/usr/local/lib/default.bash +++ b/usr/local/lib/default.bash @@ -199,12 +199,12 @@ file_dir_init() local dir - if [[ "$( id -u)" != "0" ]] + if [ ! -f ${File} ] then - ${ECHO} "Can't perform file init of: [${File}] as non root user!" - else - if [ ! -f ${File} ] + if [[ "$( id -u)" != "0" ]] then + ${ECHO} "Can't perform file init of: [${File}] as non root user!" + else dir="$( dirname ${File})" if [ ! -d ${dir} ] diff --git a/usr/local/lib/network.bash b/usr/local/lib/network.bash index 73a396a..6bfc6b7 100644 --- a/usr/local/lib/network.bash +++ b/usr/local/lib/network.bash @@ -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} do - network_dst_tab_get ${dst_id} - - if [[ ${dst_type} == "0" ]] - then - 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_dst_tab_get ${dst_id} + + for ip_route_id in ${NETWORK_IP_ROUTE_ID_LIST} + do 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} - done + + if [[ "${ip_route_device}" == "${target_device}" ]] + then + ${DEBUG} ip route add ${ip_route_ip}/${ip_route_mask} table ${dst_table} dev ${ip_route_device} + fi + 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" @@ -1186,7 +1213,7 @@ network_start() { log_info "Network" "Starting network..." - network_table_init + network_route_init network_bridge_init @@ -1211,7 +1238,7 @@ network_stop() network_bridge_deinit - network_table_deinit + network_route_deinit log_info "Network" "Network stoped!" diff --git a/usr/local/sbin/vyprvpn-down b/usr/local/sbin/openvpn_down similarity index 100% rename from usr/local/sbin/vyprvpn-down rename to usr/local/sbin/openvpn_down diff --git a/usr/local/sbin/vyprvpn-up b/usr/local/sbin/openvpn_up similarity index 91% rename from usr/local/sbin/vyprvpn-up rename to usr/local/sbin/openvpn_up index d986c56..0aec51f 100755 --- a/usr/local/sbin/vyprvpn-up +++ b/usr/local/sbin/openvpn_up @@ -51,8 +51,7 @@ then log_info "VPN-Up" "$line" " Status: [OK]" log_trace "VPN-Up" "[${Dev}]: ip route add table: [${dst_table}] default dev: [${Dev}]" - ${DEBUG} ip route del table ${dst_table} default - ${DEBUG} ip route add table ${dst_table} default dev ${Dev} + network_route_dst_init ${dst_id} else log_error "VPN-Up" "$line" " Status: [ERROR]!" fi