Parcourir la source

tinc: add package

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
Toke Høiland-Jørgensen il y a 10 ans
Parent
révision
c8bec163ad
4 fichiers modifiés avec 358 ajouts et 0 suppressions
  1. 60
    0
      net/tinc/Makefile
  2. 56
    0
      net/tinc/files/tinc.config
  3. 241
    0
      net/tinc/files/tinc.init
  4. 1
    0
      net/tinc/files/tinc.upgrade

+ 60
- 0
net/tinc/Makefile Voir le fichier

@@ -0,0 +1,60 @@
1
+#
2
+# Copyright (C) 2007-2013 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=tinc
11
+PKG_VERSION:=1.0.24
12
+PKG_RELEASE:=1
13
+
14
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
15
+PKG_SOURCE_URL:=http://www.tinc-vpn.org/packages
16
+PKG_MD5SUM:=14a91eb2e85bdc0451a815612521b708
17
+
18
+PKG_INSTALL:=1
19
+
20
+include $(INCLUDE_DIR)/package.mk
21
+
22
+define Package/tinc
23
+  SECTION:=net
24
+  CATEGORY:=Network
25
+  DEPENDS:=+liblzo +libopenssl +kmod-tun
26
+  TITLE:=VPN tunneling daemon
27
+  URL:=http://www.tinc-vpn.org/
28
+  MAINTAINER:=Toke Høiland-Jørgensen <toke@toke.dk>
29
+  SUBMENU:=VPN
30
+endef
31
+
32
+define Package/tinc/description
33
+  tinc is a Virtual Private Network (VPN) daemon that uses tunnelling and
34
+  encryption to create a secure private network between hosts on the Internet.
35
+endef
36
+
37
+TARGET_CFLAGS += -std=gnu99
38
+
39
+CONFIGURE_ARGS += \
40
+	--with-kernel="$(LINUX_DIR)" \
41
+	--with-zlib="$(STAGING_DIR)/usr" \
42
+	--with-lzo-include="$(STAGING_DIR)/usr/include/lzo"
43
+
44
+define Package/tinc/install
45
+	$(INSTALL_DIR) $(1)/usr/sbin
46
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/tincd $(1)/usr/sbin/
47
+	$(INSTALL_DIR) $(1)/etc/init.d/
48
+	$(INSTALL_BIN) files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
49
+	$(INSTALL_DIR) $(1)/etc/config
50
+	$(INSTALL_CONF) files/$(PKG_NAME).config $(1)/etc/config/$(PKG_NAME)
51
+	$(INSTALL_DIR) $(1)/etc/tinc
52
+	$(INSTALL_DIR) $(1)/lib/upgrade/keep.d
53
+	$(INSTALL_DATA) files/tinc.upgrade $(1)/lib/upgrade/keep.d/tinc
54
+endef
55
+
56
+define Package/tinc/conffiles
57
+/etc/config/tinc
58
+endef
59
+
60
+$(eval $(call BuildPackage,tinc))

+ 56
- 0
net/tinc/files/tinc.config Voir le fichier

@@ -0,0 +1,56 @@
1
+config tinc-net NETNAME
2
+	option enabled 0
3
+
4
+	## Daemon Configuration	(cmd arguments)
5
+	#option generate_keys 0
6
+	#option key_size 2048
7
+	#option logfile /tmp/log/tinc.NETNAME.log
8
+	#option debug 3
9
+
10
+	## Server Configuration (tinc.conf)
11
+	#option AddressFamily any
12
+	#option BindToAddress 127.0.0.1
13
+	#option BindToInterface lo
14
+
15
+	#list ConnectTo peer1
16
+
17
+	#option DirectOnly 0
18
+	#option Forwarding internal
19
+	#option GraphDumpFile /tmp/log/tinc.NETNAME.dot
20
+	#option Hostnames 0
21
+	#option IffOneQueue 0
22
+	#option Interface NETNAME
23
+	#option KeyExpire 3600
24
+	#option MACExpire 600
25
+	#option MaxTimeout 900
26
+	#option Mode router
27
+
28
+	option Name NODENAME
29
+
30
+	#option PingInterval 60
31
+	#option PingTimeout 5
32
+	#option PriorityInheritance 0
33
+	#option PrivateKeyFile /etc/tinc/NETNAME/rsa_key.priv
34
+	#option ProcessPriority normal
35
+	#option ReplayWindow 16
36
+	#option StrictSubnets 0
37
+	#option TunnelServer 0
38
+	#option UDPRcvBuf x
39
+	#option UDPSndBuf x
40
+
41
+config tinc-host NODENAME
42
+	option enabled 0
43
+
44
+	option net NETNAME
45
+
46
+	#list Address example.com
47
+	#option Cipher blowfish
48
+	#option ClampMSS yes
49
+	#option Compression 0
50
+	#option Digest sha1
51
+	#option IndirectData 0
52
+	#option MACLength 4
53
+	#option PMTU 1514
54
+	#option PMTUDiscovery yes
55
+	#option Port 655
56
+	#option Subnet 192.168.1.0/24

+ 241
- 0
net/tinc/files/tinc.init Voir le fichier

@@ -0,0 +1,241 @@
1
+#!/bin/sh /etc/rc.common
2
+# Copyright (C) 2011 OpenWrt.org
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.
7
+
8
+START=42
9
+
10
+SERVICE_USE_PID=1
11
+
12
+BIN=/usr/sbin/tincd
13
+EXTRA_COMMANDS="up down"
14
+
15
+LIST_SEP="
16
+"
17
+TMP_TINC="/tmp/tinc"
18
+
19
+append_param() {
20
+	local v="$1"
21
+	case "$v" in
22
+		*_*_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
23
+		*_*_*)   v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
24
+		*_*)     v=${v%%_*}-${v#*_} ;;
25
+	esac
26
+	ARGS="$ARGS --$v"
27
+	return 0
28
+}
29
+
30
+append_conf_bools() {
31
+	local p; local v; local s="$1"; local f="$2"; shift; shift
32
+	for p in $*; do
33
+		config_get_bool v "$s" "$p"
34
+		[ "$v" == 1 ] && echo "$p = yes" >> "$f"
35
+		[ "$v" == 0 ] && echo "$p = no" >> "$f"
36
+	done
37
+}
38
+
39
+append_params() {
40
+	local p; local v; local s="$1"; shift
41
+	for p in $*; do
42
+		config_get v "$s" "$p"
43
+		IFS="$LIST_SEP"
44
+		for v in $v; do
45
+			[ -n "$v" ] && append_param "$p" && ARGS="$ARGS=$v"
46
+		done
47
+		unset IFS
48
+	done
49
+}
50
+
51
+append_conf_params() {
52
+	local p; local v; local s="$1"; local f="$2"; shift; shift
53
+	for p in $*; do
54
+		config_get v "$s" "$p"
55
+		IFS="$LIST_SEP"
56
+		for v in $v; do
57
+			# Look up OpenWRT interface names
58
+			[ "$p" = "BindToInterface" ] && {
59
+				local ifname=$(uci -P /var/state get network.$v.ifname 2>&-)
60
+				[ -n "$ifname" ] && v="$ifname"
61
+			}
62
+
63
+			[ -n "$v" ] && echo "$p = $v" >> "$f"
64
+		done
65
+		unset IFS
66
+	done
67
+}
68
+
69
+section_enabled() {
70
+	config_get_bool enabled "$1" 'enabled' 0
71
+	[ $enabled -gt 0 ]
72
+}
73
+
74
+prepare_host() {
75
+	local s="$1"
76
+	local n
77
+
78
+	# net disabled?
79
+	config_get n "$s" net
80
+	section_enabled "$n" || return 1
81
+
82
+	if [ "$#" = "2" ]; then
83
+		[ "$2" != "$n" ] && return 1
84
+	fi
85
+
86
+	# host disabled?
87
+	section_enabled "$s" || {
88
+		[ -f "$TMP_TINC/$n/hosts/$s" ] && rm "$TMP_TINC/$n/hosts/$s"
89
+		return 1
90
+	}
91
+
92
+	[ ! -f "/etc/tinc/$n/hosts/$s" ] && {
93
+		echo -n "tinc: Warning, public key for $s for network $n "
94
+		echo -n "missing in /etc/tinc/$n/hosts/$s, "
95
+		echo "skipping configuration of $s"
96
+		return 1
97
+	}
98
+
99
+	# append flags
100
+	append_conf_bools "$s" "$TMP_TINC/$n/hosts/$s" \
101
+		ClampMSS IndirectData PMTUDiscovery TCPOnly
102
+
103
+	# append params
104
+	append_conf_params "$s" "$TMP_TINC/$n/hosts/$s" \
105
+		Address Cipher Compression Digest MACLength PMTU \
106
+		Port PublicKey PublicKeyFile Subnet
107
+}
108
+
109
+check_gen_own_key() {
110
+	local s="$1"; local n; local k
111
+
112
+	config_get n "$s" Name
113
+	config_get_bool k "$s" generate_keys 0
114
+	[ "$k" == 0 ] && return 0
115
+
116
+	([ -z "$n" ] || [ -f "$TMP_TINC/$s/hosts/$n" ] || [ -f "$TMP_TINC/$s/rsa_key.priv" ]) && \
117
+		return 0
118
+	[ ! -d "$TMP_TINC/$s/hosts" ] && mkdir -p "$TMP_TINC/$s/hosts"
119
+
120
+	config_get k "$s" key_size
121
+	if [ -z "$k" ]; then
122
+		$BIN -c "$TMP_TINC/$s" --generate-keys </dev/null
123
+	else
124
+		$BIN -c "$TMP_TINC/$s" "--generate-keys=$k" </dev/null
125
+	fi
126
+
127
+	[ ! -d "/etc/tinc/$s/hosts" ] && mkdir -p "/etc/tinc/$s/hosts"
128
+	cp "$TMP_TINC/$s/rsa_key.priv" "/etc/tinc/$s/"
129
+	[ -n "$n" ] && cp "$TMP_TINC/$s/hosts/$n" "/etc/tinc/$s/hosts/"
130
+}
131
+
132
+prepare_net() {
133
+	local s="$1"
134
+	local n
135
+
136
+	section_enabled "$s" || return 1
137
+
138
+        # rm old config
139
+        rm -rf "$TMP_TINC/$s/"
140
+
141
+	[ ! -d "$TMP_TINC/$s" ] && mkdir -p "$TMP_TINC/$s"
142
+	[ -d "/etc/tinc/$s" ] && cp -r "/etc/tinc/$s" "$TMP_TINC/"
143
+
144
+	# append flags
145
+	append_conf_bools "$s" "$TMP_TINC/$s/tinc.conf" \
146
+		DecrementTTL DirectOnly Hostnames IffOneQueue \
147
+		LocalDiscovery PriorityInheritance StrictSubnets TunnelServer \
148
+		ClampMSS IndirectData PMTUDiscovery TCPOnly
149
+
150
+	# append params
151
+	append_conf_params "$s" "$TMP_TINC/$s/tinc.conf" \
152
+		AddressFamily BindToAddress ConnectTo BindToInterface \
153
+		Broadcast Device DeviceType Forwarding \
154
+		GraphDumpFile Interface KeyExpire MACExpire \
155
+		MaxTimeout Mode Name PingInterval PingTimeout \
156
+		PrivateKey PrivateKeyFile ProcessPriority ReplayWindow \
157
+		UDPRcvBuf UDPSndBuf \
158
+		Address Cipher Compression Digest MACLength PMTU \
159
+		Port PublicKey PublicKeyFile Subnet
160
+
161
+	check_gen_own_key "$s" && return 0
162
+}
163
+
164
+start_instance() {
165
+	local s="$1"
166
+
167
+	section_enabled "$s" || return 1
168
+
169
+	ARGS=""
170
+
171
+	# append params
172
+	append_params "$s" logfile debug
173
+
174
+	SERVICE_PID_FILE="/var/run/tinc.$s.pid"
175
+	service_start $BIN -c "$TMP_TINC/$s" -n $s $ARGS --pidfile="$SERVICE_PID_FILE"
176
+}
177
+
178
+stop_instance() {
179
+	local s="$1"
180
+
181
+	section_enabled "$s" || return 1
182
+
183
+	SERVICE_PID_FILE="/var/run/tinc.$s.pid"
184
+	service_stop $BIN
185
+	# rm old config
186
+	rm -rf "$TMP_TINC/$s/"
187
+}
188
+
189
+reload_instance() {
190
+	local s="$1"
191
+
192
+	section_enabled "$s" || return 1
193
+
194
+	SERVICE_PID_FILE="/var/run/tinc.$s.pid"
195
+	service_reload $BIN
196
+}
197
+
198
+start() {
199
+	config_load 'tinc'
200
+
201
+	config_foreach prepare_net 'tinc-net'
202
+	config_foreach prepare_host 'tinc-host'
203
+
204
+	config_foreach start_instance 'tinc-net'
205
+}
206
+
207
+stop() {
208
+	config_load 'tinc'
209
+	config_foreach stop_instance 'tinc-net'
210
+}
211
+
212
+reload() {
213
+	config_load 'tinc'
214
+	config_foreach reload_instance 'tinc-net'
215
+}
216
+
217
+up() {
218
+	local exists
219
+	local instance
220
+	config_load 'tinc'
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_instance "$instance"
227
+		fi
228
+	done
229
+}
230
+
231
+down() {
232
+	local exists
233
+	local instance
234
+	config_load 'tinc'
235
+	for instance in "$@"; do
236
+		config_get exists "$instance" 'TYPE'
237
+		if [ "$exists" == "tinc-net" ]; then
238
+			stop_instance "$instance"
239
+		fi
240
+	done
241
+}

+ 1
- 0
net/tinc/files/tinc.upgrade Voir le fichier

@@ -0,0 +1 @@
1
+/etc/tinc/