1 #!/bin/sh /etc/rc.common
3 # Copyright (C) 2011 Linus Lüssing
4 # Based on Jo-Philipp Wich's OpenVPN init script
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
11 EXTRA_COMMANDS
="up down"
20 *_
*_
*_
*) v
=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
21 *_
*_
*) v
=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
22 *_
*) v
=${v%%_*}-${v#*_} ;;
29 local p
; local v
; local s
="$1"; local f
="$2"; shift; shift
31 config_get_bool v
"$s" "$p"
32 [ "$v" == 1 ] && echo "$p = yes" >> "$f"
33 [ "$v" == 0 ] && echo "$p = no" >> "$f"
38 local p
; local v
; local s
="$1"; shift
40 config_get v
"$s" "$p"
43 [ -n "$v" ] && append_param
"$p" && ARGS
="$ARGS $v"
49 append_conf_params
() {
50 local p
; local v
; local s
="$1"; local f
="$2"; shift; shift
52 config_get v
"$s" "$p"
55 # Look up OpenWRT interface names
56 [ "$p" = "BindToInterface" ] && {
57 local ifname
=$
(uci
-P /var
/state get network.
$v.ifname
2>&-)
58 [ -n "$ifname" ] && v
="$ifname"
61 [ -n "$v" ] && echo "$p = $v" >> "$f"
73 config_get_bool disabled
"$n" disabled
0
74 [ "$disabled" == 1 ] && return 0
76 if [ "$#" = "2" ]; then
77 [ "$2" != "$n" ] && return 0
81 config_get_bool disabled
"$s" disabled
0
82 [ "$disabled" == 1 ] && {
83 [ -f "$TMP_TINC/$n/hosts/$s" ] && rm "$TMP_TINC/$n/hosts/$s"
87 [ ! -f "/etc/tinc/$n/hosts/$s" ] && {
88 echo -n "tinc: Warning, public key for $s for network $n "
89 echo -n "missing in /etc/tinc/$n/hosts/$s, "
90 echo "skipping configuration of $s"
95 append_conf_bools
"$s" "$TMP_TINC/$n/hosts/$s" \
96 ClampMSS IndirectData PMTUDiscovery
99 append_conf_params
"$s" "$TMP_TINC/$n/hosts/$s" \
100 Address Cipher Compression Digest MACLength PMTU Port Subnet
103 check_gen_own_key
() {
104 local s
="$1"; local n
; local k
106 config_get n
"$s" Name
107 config_get_bool k
"$s" generate_keys
0
108 [ "$k" == 0 ] && return 0
110 ([ -z "$n" ] ||
[ -f "$TMP_TINC/$s/hosts/$n" ] ||
[ -f "$TMP_TINC/$s/rsa_key.priv" ]) && \
112 [ ! -d "$TMP_TINC/$s/hosts" ] && mkdir
-p "$TMP_TINC/$s/hosts"
114 config_get k
"$s" key_size
116 $BIN -c "$TMP_TINC/$s" --generate-keys </dev
/null
118 $BIN -c "$TMP_TINC/$s" "--generate-keys=$k" </dev
/null
121 [ ! -d "/etc/tinc/$s/hosts" ] && mkdir
-p "/etc/tinc/$s/hosts"
122 cp "$TMP_TINC/$s/rsa_key.priv" "/etc/tinc/$s/"
123 [ -n "$n" ] && cp "$TMP_TINC/$s/hosts/$n" "/etc/tinc/$s/hosts/"
132 config_get_bool disabled
"$s" disabled
0
133 [ "$disabled" == 1 ] && return 0
135 [ ! -d "$TMP_TINC/$s" ] && mkdir
-p "$TMP_TINC/$s"
136 [ -d "/etc/tinc/$s" ] && cp -r "/etc/tinc/$s" "$TMP_TINC/"
139 append_conf_bools
"$s" "$TMP_TINC/$s/tinc.conf" \
140 DirectOnly Hostnames IffOneQueue PriorityInheritance \
141 StrictSubnets TunnelServer \
142 ClampMSS IndirectData PMTUDiscovery
145 append_conf_params
"$s" "$TMP_TINC/$s/tinc.conf" \
146 AddressFamily BindToAddress ConnectTo BindToInterface \
147 Forwarding GraphDumpFile Interface KeyExpire MACExpire \
148 MaxTimeout Mode Name PingInterval PingTimeout PrivateKeyFile \
149 ProcessPriority ReplayWindow UDPRcvBuf UDPSndBuf \
150 Address Cipher Compression Digest MACLength PMTU Port Subnet
152 check_gen_own_key
"$s" && return 0
160 config_get_bool disabled
"$s" disabled
0
161 [ "$disabled" == 1 ] && return 0
163 PID
="/var/run/tinc.$s.pid"
170 $BIN -c "$TMP_TINC/$s" -n $s $ARGS --pidfile="$PID"
179 config_get_bool disabled
"$s" disabled
0
180 [ "$disabled" == 0 ] ||
[ "$S" == "TERM" ] ||
return 0
182 PID
="/var/run/tinc.$s.pid"
184 $SSD -q -p $PID -x $BIN -K -s $S
185 [ "$S" == "TERM" ] && {
187 [ -n "$s" ] && rm -rf "$TMP_TINC/$s"
191 hup_net
() { kill_net
"$1" HUP
; }
192 stop_net
() { kill_net
"$1" TERM
; }
197 config_foreach prepare_net tinc-net
198 config_foreach prepare_host tinc-host
200 config_foreach start_net tinc-net
205 config_foreach stop_net tinc-net
210 config_foreach hup_net tinc-net
221 for INSTANCE
in "$@"; do
222 config_get exists
"$INSTANCE" TYPE
223 if [ "$exists" == "tinc-net" ]; then
224 prepare_net
"$INSTANCE"
225 config_foreach prepare_host tinc-host
"$INSTANCE"
226 start_net
"$INSTANCE"
235 for INSTANCE
in "$@"; do
236 config_get exists
"$INSTANCE" TYPE
237 if [ "$exists" == "tinc-net" ]; then