mirror of https://github.com/OpenIPC/firmware.git
[no ci] Package: adjust vtund tunnel script
parent
9b1d582f93
commit
6346c442d2
|
@ -5,12 +5,11 @@
|
||||||
# Simple script for get IP and Routes via UDHCPC on VTUNd tun/tap interfaces
|
# Simple script for get IP and Routes via UDHCPC on VTUNd tun/tap interfaces
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
set_routes() {
|
set_routes() {
|
||||||
local max=128
|
local max=128
|
||||||
local type
|
local type
|
||||||
while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
|
while [ -n "$1" ] && [ -n "$2" ] && [ "$max" -gt 0 ]; do
|
||||||
[ ${1##*/} -eq 32 ] && type=host || type=net
|
[ "${1##*/}" -eq 32 ] && type=host || type=net
|
||||||
echo "udhcpc: adding route for $type $1 via $2"
|
echo "udhcpc: adding route for $type $1 via $2"
|
||||||
route add -$type "$1" gw "$2" dev "$interface"
|
route add -$type "$1" gw "$2" dev "$interface"
|
||||||
max=$(($max-1))
|
max=$(($max-1))
|
||||||
|
@ -18,18 +17,13 @@ set_routes() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
||||||
deconfig)
|
deconfig)
|
||||||
ip a flush dev $interface
|
ip a flush dev "$interface"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
renew|bound)
|
renew|bound)
|
||||||
ip a add $ip/$subnet dev $interface
|
ip a add "$ip/$subnet" dev "$interface"
|
||||||
[ -n "$staticroutes" ] && set_routes $staticroutes
|
[ -n "$staticroutes" ] && set_routes "$staticroutes"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
|
@ -5,61 +5,49 @@
|
||||||
# Busybox applets: awk cat echo insmod ip modprobe sha1sum sleep tr tunctl udhcpc uptime
|
# Busybox applets: awk cat echo insmod ip modprobe sha1sum sleep tr tunctl udhcpc uptime
|
||||||
#
|
#
|
||||||
|
|
||||||
|
vtund_enable="true"
|
||||||
vtund_enable="1"
|
vtund_server=${1:-vtun.localhost}
|
||||||
vtund_server=$1
|
|
||||||
vtund_server=${vtund_server:=vtun.localhost}
|
|
||||||
vtund_port="5000"
|
vtund_port="5000"
|
||||||
vtund_iface="tunnel"
|
vtund_iface="tunnel"
|
||||||
vtund_salt=""
|
|
||||||
device_name="IPC-VTUND"
|
device_name="IPC-VTUND"
|
||||||
kernel_module=""
|
|
||||||
working_dir="/tmp"
|
working_dir="/tmp"
|
||||||
|
|
||||||
|
|
||||||
identity() {
|
identity() {
|
||||||
identity_src=$(ip r | awk '/default/ {print $5}' | head -n 1)
|
identity_src=$(ip r | awk '/default/ {print $5}' | head -n 1)
|
||||||
identity_mac=$(cat /sys/class/net/${identity_src}/address | tr 'a-z' 'A-Z')
|
identity_mac=$(cat /sys/class/net/"$identity_src"/address | tr 'a-z' 'A-Z')
|
||||||
identity_pas=$(echo ${vtund_salt}${identity_mac} | sha1sum | awk '{print $1}')
|
identity_pas=$(echo "$identity_mac" | sha1sum | awk '{print $1}')
|
||||||
identity_tid=$(echo ${identity_mac} | tr -d ':')
|
identity_tid=$(echo "$identity_mac" | tr -d ':')
|
||||||
identity_cfg=${working_dir}/vtund.conf
|
identity_cfg=$working_dir/vtund.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface() {
|
interface() {
|
||||||
[ -L /sys/class/net/${vtund_iface} ] || (modprobe tun; tunctl -t ${vtund_iface}) >/dev/null 2>&1
|
[ -L /sys/class/net/$vtund_iface ] || (modprobe tun; tunctl -t $vtund_iface) >/dev/null 2>&1
|
||||||
[ -f ${working_dir}/udhcpc-${vtund_iface}.pid ] && kill -9 $(cat ${working_dir}/udhcpc-${vtund_iface}.pid) >/dev/null 2>&1
|
[ -f $working_dir/udhcpc-$vtund_iface.pid ] && kill -9 "$(cat $working_dir/udhcpc-$vtund_iface.pid)" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
config() {
|
config() {
|
||||||
( echo "#"
|
( echo "options {"
|
||||||
echo "options {"
|
echo " port $vtund_port;"
|
||||||
echo " port ${vtund_port};"
|
|
||||||
echo " ifconfig /sbin/ifconfig;"
|
echo " ifconfig /sbin/ifconfig;"
|
||||||
echo "}"
|
echo "}"
|
||||||
echo "${identity_tid} {"
|
echo "$identity_tid {"
|
||||||
echo " password ${identity_pas};"
|
echo " password $identity_pas;"
|
||||||
echo " device ${vtund_iface};"
|
echo " device $vtund_iface;"
|
||||||
echo " stat no;"
|
echo " stat no;"
|
||||||
echo " persist yes;"
|
echo " persist yes;"
|
||||||
echo " keepalive 10:5;"
|
echo " keepalive 10:5;"
|
||||||
echo " timeout 10;"
|
echo " timeout 10;"
|
||||||
echo " up {"
|
echo " up {"
|
||||||
echo " ifconfig \"${vtund_iface} hw ether ${identity_mac} mtu 1500 -multicast up\";"
|
echo " ifconfig \"$vtund_iface hw ether $identity_mac mtu 1500 -multicast up\";"
|
||||||
echo " program \"udhcpc -T 1 -t 5 -R -b -O staticroutes -S -s tapip -p ${working_dir}/udhcpc-${vtund_iface}.pid -i ${vtund_iface} -x hostname:${device_name}-${identity_tid}\";"
|
echo " program \"udhcpc -T 1 -t 5 -R -b -O staticroutes -S -s tapip -p $working_dir/udhcpc-$vtund_iface.pid -i $vtund_iface -x hostname:$device_name-$identity_tid\";"
|
||||||
echo " };"
|
echo " };"
|
||||||
echo " down {"
|
echo " down {"
|
||||||
echo " ifconfig \"${vtund_iface} down\";"
|
echo " ifconfig \"$vtund_iface down\";"
|
||||||
echo " };"
|
echo " };"
|
||||||
echo "}"
|
echo "}"
|
||||||
) >${identity_cfg}
|
) >$identity_cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [ "$vtund_enable" = "true" ]; then
|
||||||
if [ ${vtund_enable} = 1 ]; then
|
(while true; do identity; interface; config; vtund -n -f "$identity_cfg" "$identity_tid" "$vtund_server" >/dev/null 2>&1; done) &
|
||||||
(while true ; do sleep 10; identity; interface; config; vtund -n -f ${identity_cfg} ${identity_tid} ${vtund_server} >/dev/null 2>&1; done) &
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
Loading…
Reference in New Issue