-
Notifications
You must be signed in to change notification settings - Fork 0
/
tunneldigger.init
100 lines (84 loc) · 2.23 KB
/
tunneldigger.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh /etc/rc.common
. $IPKG_INSTROOT/lib/functions/network.sh
START=90
PIDPATH=/var/run
tunnel_id=0
missing() {
echo "Not starting tunneldigger \"$1\" - missing $2" >&2
}
handle_td() {
local cfg=$1
local enabled
local addresses
local uuid
local interface
local group
local limit_bw_down
local hook_script
local bind_interface
local broker_selection
config_get_bool enabled "$cfg" enabled 1
config_get addresses "$cfg" address
config_get uuid "$cfg" uuid
config_get interface "$cfg" interface
config_get group "$cfg" group
config_get limit_bw_down "$cfg" limit_bw_down
config_get hook_script "$cfg" hook_script
config_get bind_interface "$cfg" bind_interface
config_get broker_selection "$cfg" broker_selection
let tunnel_id++
[ $enabled -eq 0 ] && return
# The hoplug script will take care of tunnels bound to an interface
[ ! -z "${bind_interface}" ] && return
local broker_opts=""
local address
for address in $addresses; do
append broker_opts "-b ${address}"
done
[ ! -z "${limit_bw_down}" ] && append broker_opts "-L ${limit_bw_down}"
[ ! -z "${hook_script}" ] && append broker_opts "-s ${hook_script}"
[ ! -z "${broker_selection}" ] && {
# Set broker selection.
case "${broker_selection}" in
usage)
append broker_opts "-a"
;;
first)
append broker_opts "-g"
;;
random)
append broker_opts "-r"
;;
esac
}
if [ -z "$uuid" ]; then
missing $cfg uuid
return
elif [ -z "$interface" ]; then
missing $cfg interface
return
fi
echo "Starting tunneldigger \"$cfg\" on ${interface}"
/sbin/start-stop-daemon -S -q -b -m -c root:${group} -p ${PIDPATH}/tunneldigger.${interface}.pid -x /usr/bin/tunneldigger -- -u ${uuid} -i ${interface} -t ${tunnel_id} ${broker_opts}
}
start() {
config_load tunneldigger
config_foreach handle_td broker
}
stop() {
for PIDFILE in `find ${PIDPATH}/ -name "tunneldigger\.*\.pid"`; do
PID="$(cat ${PIDFILE})"
IFACE="$(echo ${PIDFILE} | awk -F\/tunneldigger '{print $2}' | cut -d'.' -f2)"
echo "Stopping tunneldigger for interface ${IFACE}"
start-stop-daemon -K -q -p $PIDFILE
while test -d "/proc/${PID}"; do
echo " waiting for tunneldigger to stop"
sleep 1
done
echo " tunneldigger stopped"
done
}
restart() {
stop
start
}