1 #!/bin/sh /etc/rc.common
3 # Partly taken the the OpenVPN init script (Copyright (C) 2008 Jo-Philipp Wich)
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
10 EXTRA_COMMANDS="up down"
16 local p="$1"; local v="$2"; local p_uc
18 p_uc=$(echo "$p" | tr '[a-z]' '[A-Z]')
19 OPTS="$OPTS \"$p_uc=$v\""
23 local p; local v; local s="$1"; shift
25 config_get v "$s" "$p"
26 [ -n "$v" ] && append_opt "$p" "$v"
35 config_get_bool enable "$s" enable 0
36 [ "$enable" == 0 ] && return 0
38 PID="/var/run/quicktun-$s.pid"
41 config_get interface "$s" interface
42 if [ -z "$interface" ]; then
43 echo "$s: interface not set"
47 if ifconfig "$interface" >/dev/null 2>&1; then
48 echo "$s: interface $interface is already in use"
52 append_opts "$s" interface local_address local_port remote_address remote_port \
53 protocol private_key public_key time_window
55 config_get_bool tun_mode "$s" tun_mode 0
56 [ "$tun_mode" == 1 ] && append_opt tun_mode 1
58 config_get_bool remote_float "$s" remote_float 0
59 [ "$remote_float" == 1 ] && append_opt remote_float 1
61 eval env $OPTS "$SSD" -q -b -p "$PID" -m -x "$BIN" -S
63 while ! ifconfig "$interface" >/dev/null 2>&1; do
64 if ! $SSD -t -q -p $PID -x $BIN -K; then
65 echo "$s: daemon startup failed"
73 [ -n "$up" ] && sh -c "$up" - "$interface"
81 config_get_bool enable "$s" enable 0
82 [ "$enable" == 0 ] && return 0
84 config_get interface "$s" interface
85 if [ -z "$interface" ]; then
86 echo "$s: interface not set"
90 if ! ifconfig "$interface" >/dev/null 2>&1; then
91 echo "$s: interface $interface does not exist"
95 config_get down "$s" down
96 [ -n "$down" ] && sh -c "$down" - "$interface"
98 PID="/var/run/quicktun-$s.pid"
100 $SSD -q -p $PID -x $BIN -K
106 config_foreach start_service quicktun
111 config_foreach stop_service quicktun
122 for INSTANCE in "$@"; do
123 config_get exists "$INSTANCE" TYPE
124 if [ "$exists" == "quicktun" ]; then
125 start_service "$INSTANCE"
134 for INSTANCE in "$@"; do
135 config_get exists "$INSTANCE" TYPE
136 if [ "$exists" == "quicktun" ]; then
137 stop_service "$INSTANCE"