mirror of
https://github.com/Ysurac/openmptcprouter-vps.git
synced 2025-03-09 15:50:00 +00:00
Rename omr-6in4, add shorewall net interface in params.net and add multipath utility
This commit is contained in:
parent
c85cd75159
commit
fa84079875
9 changed files with 135 additions and 13 deletions
85
omr-service
Executable file
85
omr-service
Executable file
|
@ -0,0 +1,85 @@
|
|||
#!/bin/bash
|
||||
# OpenMPTCProuter VPS service script
|
||||
# This script configure 6in4, multipath and firewall for current VPN
|
||||
|
||||
if [ "$1" = "stop" ] && [ "$(ip link show omr-6in4 up 2>/dev/null)" ]; then
|
||||
ip route del fd00::/8 via fe80::a00:2 dev omr-6in4
|
||||
ip link set omr-6in4 down
|
||||
ip tunnel del omr-6in4
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Force multipath status
|
||||
source /etc/shorewall/params.net
|
||||
for intf in `ls -1 /sys/class/net`; do
|
||||
if [ "$intf" = "$NET_IFACE" ]; then
|
||||
multipath $intf on
|
||||
else
|
||||
multipath $intf off
|
||||
fi
|
||||
done
|
||||
|
||||
# Add IPv6 tunnel
|
||||
if [ "$(ip link show omr-6in4 up 2>/dev/null)" ]; then
|
||||
ip tunnel change omr-6in4 mode sit remote 10.255.255.2 local 10.255.255.1
|
||||
else
|
||||
ip tunnel add omr-6in4 mode sit remote 10.255.255.2 local 10.255.255.1
|
||||
ip addr add fe80::a00:1/64 dev omr-6in4 >/dev/null 2>&1
|
||||
fi
|
||||
ip link set omr-6in4 up
|
||||
ip route replace fd00::/8 via fe80::a00:2 dev omr-6in4
|
||||
|
||||
_ping() {
|
||||
local host=$1
|
||||
ret=$(ping -4 "${host}" \
|
||||
-W 5 \
|
||||
-c 1 \
|
||||
-q
|
||||
) && echo "$ret" | grep -sq "0% packet loss" && {
|
||||
return
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
while true; do
|
||||
source /etc/shorewall/params.vpn
|
||||
iface=""
|
||||
currentaddr=$(ip addr show omr-6in4 | grep link/sit | awk '{print $2}' | tr -d "\n")
|
||||
currentpeer=$(ip addr show omr-6in4 | grep link/sit | awk '{print $4}' | tr -d "\n")
|
||||
if [ -n "$currentpeer" ]; then
|
||||
_ping $currentpeer
|
||||
status=$?
|
||||
if ! $(exit $status) || [ "$currentpeer" != "$OMR_ADDR" ]; then
|
||||
allip_tcp=$(ip -4 addr show gt-tun0 2>/dev/null | grep inet)
|
||||
allip_udp=$(ip -4 addr show gt-udp-tun0 2>/dev/null | grep inet)
|
||||
allip_mlvpn=$(ip -4 addr show mlvpn0 2>/dev/null | grep inet)
|
||||
allip_openvpn=$(ip -4 addr show tun0 2>/dev/null | grep inet)
|
||||
allip="$allip_tcp
|
||||
$allip_udp
|
||||
$allip_openvpn
|
||||
$allip_mlvpn"
|
||||
while IFS= read -r inet; do
|
||||
ip=$(echo $inet | awk '{print $2}' | cut -d/ -f1 | tr -d "\n")
|
||||
ipd=$(echo $ip | sed 's/.1/.2/' | tr -d "\n")
|
||||
if [ "$ipd" != "" ]; then
|
||||
_ping $ipd
|
||||
statusp=$?
|
||||
if $(exit $statusp); then
|
||||
ip tunnel change omr-6in4 mode sit remote $ipd local $ip
|
||||
echo "VPS_ADDR=$ip" > /etc/shorewall/params.vpn
|
||||
echo "OMR_ADDR=$ipd" >> /etc/shorewall/params.vpn
|
||||
iface=$(ip -4 addr | grep $ip | awk '{print $7}' | tr -d "\n")
|
||||
echo "VPS_IFACE=$iface" >> /etc/shorewall/params.vpn
|
||||
systemctl reload shorewall
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done < <(printf '%s\n' "$allip")
|
||||
[ -z "$iface" ] && {
|
||||
systemctl -q restart systemd-networkd
|
||||
sleep 10
|
||||
}
|
||||
fi
|
||||
fi
|
||||
sleep 5
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue