1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010-2011 OpenWrt.org
4 # Partly taken the OpenVPN init script (Copyright (C) 2008 Jo-Philipp Wich)
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
13 EXTRA_COMMANDS="up down"
19 local p="$1"; local v="$2"; local p_uc
21 p_uc=$(echo "$p" | tr '[a-z]' '[A-Z]')
22 OPTS="$OPTS \"$p_uc=$v\""
26 local p; local v; local s="$1"; shift
28 config_get v "$s" "$p"
29 [ -n "$v" ] && append_opt "$p" "$v"
34 config_get_bool enabled "$1" 'enabled' 0
39 echo "${initscript}:" "$@" 1>&2
45 section_enabled "$s" || return 1
47 SERVICE_PID_FILE="/var/run/quicktun-$s.pid"
50 config_get interface "$s" interface
51 if [ -z "$interface" ]; then
52 error "$s: interface '$interface' is not set"
56 if ifconfig "$interface" &>/dev/null; then
57 error "$s: interface '$interface' is already in use"
61 append_opts "$s" interface local_address local_port remote_address remote_port \
62 protocol private_key public_key time_window
64 config_get_bool tun_mode "$s" tun_mode 0
65 [ "$tun_mode" == 1 ] && append_opt tun_mode 1
67 config_get_bool remote_float "$s" remote_float 0
68 [ "$remote_float" == 1 ] && append_opt remote_float 1
70 eval env $OPTS service_start /usr/sbin/quicktun
72 while ! ifconfig "$interface" >/dev/null 2>&1; do
73 if ! service_check /usr/sbin/quicktun; then
74 error "$s: startup failed"
82 [ -n "$up" ] && sh -c "$up" - "$interface"
88 section_enabled "$s" || return 1
90 SERVICE_PID_FILE="/var/run/quicktun-$s.pid"
92 config_get interface "$s" interface
93 if [ -z "$interface" ]; then
94 error "$s: interface '$interface' is not set"
98 if ! ifconfig "$interface" &>/dev/null; then
99 error "$s: interface '$interface' does not exist"
103 config_get down "$s" down
104 [ -n "$down" ] && sh -c "$down" - "$interface"
106 service_stop /usr/sbin/quicktun
110 config_load 'quicktun'
111 config_foreach start_instance 'quicktun'
115 config_load 'quicktun'
116 config_foreach stop_instance 'quicktun'
122 config_load 'quicktun'
123 for instance in "$@"; do
124 config_get exists "$instance" 'TYPE'
125 if [ "$exists" == "quicktun" ]; then
126 start_instance "$instance"
134 config_load 'quicktun'
135 for instance in "$@"; do
136 config_get exists "$instance" 'TYPE'
137 if [ "$exists" == "quicktun" ]; then
138 stop_instance "$instance"