Browse Source

fastd: update to v15

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Matthias Schiffer 10 years ago
parent
commit
619f2c1807
4 changed files with 23 additions and 579 deletions
  1. 9
    3
      net/fastd/Config.in
  2. 14
    8
      net/fastd/Makefile
  3. 0
    143
      net/fastd/files/fastd.config
  4. 0
    425
      net/fastd/files/fastd.init

+ 9
- 3
net/fastd/Config.in View File

80
 	default n
80
 	default n
81
 
81
 
82
 config FASTD_WITH_VERIFY
82
 config FASTD_WITH_VERIFY
83
-        bool "Include support for on-verify handlers"
84
-        depends on PACKAGE_fastd
85
-        default n
83
+	bool "Include support for on-verify handlers"
84
+	depends on PACKAGE_fastd
85
+	default n
86
+
87
+config FASTD_WITH_STATUS_SOCKET
88
+	bool "Include support for status sockets"
89
+	depends on PACKAGE_fastd
90
+	default y
91
+
86
 
92
 
87
 endmenu
93
 endmenu

+ 14
- 8
net/fastd/Makefile View File

8
 include $(TOPDIR)/rules.mk
8
 include $(TOPDIR)/rules.mk
9
 
9
 
10
 PKG_NAME:=fastd
10
 PKG_NAME:=fastd
11
-PKG_VERSION:=14
12
-PKG_RELEASE:=3
11
+PKG_VERSION:=15
12
+PKG_RELEASE:=1
13
 
13
 
14
 PKG_MAINTAINER:=Matthias Schiffer <mschiffer@universe-factory.net>
14
 PKG_MAINTAINER:=Matthias Schiffer <mschiffer@universe-factory.net>
15
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
15
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
16
-PKG_SOURCE_URL:=https://projects.universe-factory.net/attachments/download/75
17
-PKG_MD5SUM:=34f6bdebd0410a1fba7c8fd06fff7a05
16
+PKG_SOURCE_URL:=https://projects.universe-factory.net/attachments/download/77
17
+PKG_MD5SUM:=31763188a7fc35d22fd506e406f8c37c
18
 
18
 
19
 PKG_LICENSE:=BSD-2-Clause
19
 PKG_LICENSE:=BSD-2-Clause
20
 PKG_LICENSE_FILE:=COPYRIGHT
20
 PKG_LICENSE_FILE:=COPYRIGHT
35
 	CONFIG_FASTD_WITH_CMDLINE_LOGGING \
35
 	CONFIG_FASTD_WITH_CMDLINE_LOGGING \
36
 	CONFIG_FASTD_WITH_CMDLINE_OPERATION \
36
 	CONFIG_FASTD_WITH_CMDLINE_OPERATION \
37
 	CONFIG_FASTD_WITH_CMDLINE_COMMANDS \
37
 	CONFIG_FASTD_WITH_CMDLINE_COMMANDS \
38
-	CONFIG_FASTD_WITH_VERIFY
38
+	CONFIG_FASTD_WITH_VERIFY \
39
+	CONFIG_FASTD_WITH_STATUS_SOCKET
39
 
40
 
40
 
41
 
41
 PKG_BUILD_DEPENDS:=nacl libuecc
42
 PKG_BUILD_DEPENDS:=nacl libuecc
46
 define Package/fastd
47
 define Package/fastd
47
   SECTION:=net
48
   SECTION:=net
48
   CATEGORY:=Network
49
   CATEGORY:=Network
49
-  DEPENDS:=+kmod-tun +librt +libpthread
50
+  DEPENDS:=+kmod-tun +librt +libpthread +FASTD_WITH_STATUS_SOCKET:libjson-c
50
   TITLE:=Fast and Secure Tunneling Daemon
51
   TITLE:=Fast and Secure Tunneling Daemon
51
   URL:=https://projects.universe-factory.net/projects/fastd
52
   URL:=https://projects.universe-factory.net/projects/fastd
52
   SUBMENU:=VPN
53
   SUBMENU:=VPN
77
 	-DWITH_CMDLINE_OPERATION:BOOL=FALSE \
78
 	-DWITH_CMDLINE_OPERATION:BOOL=FALSE \
78
 	-DWITH_CMDLINE_COMMANDS:BOOL=FALSE \
79
 	-DWITH_CMDLINE_COMMANDS:BOOL=FALSE \
79
 	-DWITH_VERIFY:BOOL=FALSE \
80
 	-DWITH_VERIFY:BOOL=FALSE \
81
+	-DWITH_STATUS_SOCKET:BOOL=FALSE \
80
 	-DWITH_CAPABILITIES:BOOL=FALSE \
82
 	-DWITH_CAPABILITIES:BOOL=FALSE \
81
 	-DENABLE_SYSTEMD:BOOL=FALSE \
83
 	-DENABLE_SYSTEMD:BOOL=FALSE \
82
 	-DENABLE_LIBSODIUM:BOOL=FALSE \
84
 	-DENABLE_LIBSODIUM:BOOL=FALSE \
150
 CMAKE_OPTIONS += -DWITH_VERIFY:BOOL=TRUE
152
 CMAKE_OPTIONS += -DWITH_VERIFY:BOOL=TRUE
151
 endif
153
 endif
152
 
154
 
155
+ifeq ($(CONFIG_FASTD_WITH_STATUS_SOCKET),y)
156
+CMAKE_OPTIONS += -DWITH_STATUS_SOCKET:BOOL=TRUE
157
+endif
158
+
153
 
159
 
154
 define Package/fastd/description
160
 define Package/fastd/description
155
  Fast and secure tunneling daemon, which is optimized on small code size and few dependencies
161
  Fast and secure tunneling daemon, which is optimized on small code size and few dependencies
164
 	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/fastd $(1)/usr/bin/
170
 	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/fastd $(1)/usr/bin/
165
 
171
 
166
 	$(INSTALL_DIR) $(1)/etc/init.d/
172
 	$(INSTALL_DIR) $(1)/etc/init.d/
167
-	$(INSTALL_BIN) files/fastd.init $(1)/etc/init.d/fastd
173
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/openwrt/fastd.init $(1)/etc/init.d/fastd
168
 	$(INSTALL_DIR) $(1)/etc/config
174
 	$(INSTALL_DIR) $(1)/etc/config
169
-	$(INSTALL_CONF) files/fastd.config $(1)/etc/config/fastd
175
+	$(INSTALL_CONF) $(PKG_BUILD_DIR)/doc/examples/openwrt/fastd.config $(1)/etc/config/fastd
170
 	$(INSTALL_DIR) $(1)/etc/fastd
176
 	$(INSTALL_DIR) $(1)/etc/fastd
171
 	$(INSTALL_DIR) $(1)/lib/upgrade/keep.d
177
 	$(INSTALL_DIR) $(1)/lib/upgrade/keep.d
172
 	$(INSTALL_DATA) files/fastd.upgrade $(1)/lib/upgrade/keep.d/fastd
178
 	$(INSTALL_DATA) files/fastd.upgrade $(1)/lib/upgrade/keep.d/fastd

+ 0
- 143
net/fastd/files/fastd.config View File

1
-package fastd
2
-
3
-config fastd sample_config
4
-
5
-	# Set to 1 to enable this instance:
6
-	option enabled 0
7
-
8
-	# Sets a static config file, optional
9
-	# Options set via UCI have higher priority that statically configured ones
10
-#	list config '/etc/fastd/sample_config/fastd.conf'
11
-
12
-	# Configures a single static peer from a configuration file
13
-#	list config_peer '/etc/fastd/sample_config/sample_peer.conf'
14
-
15
-	# Sets an additional directory from which peers configurations are read
16
-	# The peer list can be reloaded without restarting fastd
17
-	# Peer can either be configured via UCI (see examples below) or via peer dirs
18
-	# Can't be used in tun mode
19
-#	list config_peer_dir '/etc/fastd/sample_config/peers'
20
-
21
-	# Sets the log level
22
-	# Possible values: error, warn, info, verbose, debug
23
-	# Default: info
24
-	option syslog_level 'info'
25
-
26
-	# IP address and port of the local end, optional
27
-	# 'any' can be used to bind to both IPv4 and IPv6
28
-	# If no port is given fastd will bind to a random port
29
-#	list bind 'any:1337'
30
-#	list bind '0.0.0.0:1337'
31
-#	list bind '[::]:1337'
32
-
33
-	# "method null" uses no encryption or MAC
34
-	# "method xsalsa20-poly1305" uses the XSalsa20 encryption ad the Poly1305 MAC
35
-	list method 'xsalsa20-poly1305'
36
-
37
-	# "mode tap" will create an ethernet tunnel (tap device),
38
-	# "mode tun" will create an IP tunnel (tun device).
39
-	option mode 'tap'
40
-
41
-	# Set the name of the tunnel interface to use
42
-	option interface 'tap0'
43
-#	option interface 'tun0'
44
-#	option interface 'fastd0'
45
-
46
-	# Sets the MTU of the tunnel interface, default is 1500
47
-	# 1426 is a good value that avoids fragmentation for the xsalsa20-poly1305 method
48
-	# when the tunnel uses an IPv4 connection on a line with an MTU of 1492 or higher
49
-	option mtu 1426
50
-
51
-	# Enables direct forwaring of packets between peers
52
-	# WARNING: Only enable this if you know what you are doing, as this can lead to forwarding loops!
53
-	option forward 0
54
-
55
-	# Disable for compatiblity with fastd v10 and older
56
-	option secure_handshakes 1
57
-
58
-	# Set a packet mark to filter for with iptables or ip rules
59
-#	option packet_mark 42
60
-
61
-	# Limits the maximum number of connections, optional
62
-#	option peer_limit 5
63
-
64
-	# The secret key
65
-	# A keypair can be generated with `fastd --generate-key`
66
-	# When the corresponding public key is lost it can be recovered with `/etc/init.d/fastd show-key <config name>`
67
-#	option secret '0000000000000000000000000000000000000000000000000000000000000000'
68
-
69
-	# Sets the user to run fastd as. Defaults to root
70
-#	option user 'daemon'
71
-
72
-	# Sets the group to run fastd as. Defaults to the user's primary group
73
-#	option group 'daemon'
74
-
75
-	# If set to 1, the logs won't contain peers' IP addresses
76
-#	option hide_ip_addresses '0'
77
-
78
-	# If set to 1, the logs won't contain peers' MAC addresses
79
-#	option hide_mac_addresses '0'
80
-
81
-	# Read the documentation about this one. Only ever useful in severly broken networks.
82
-#	option pmtu ''
83
-
84
-	# command to configure IP addresses etc. after the tunnel interface is up; $1 will be the interface name (optional)
85
-#	option up ''
86
-
87
-	# command to execute before the tunnel interface is set down; $1 will be the interface name (optional)
88
-#	option down ''
89
-
90
-
91
-config peer sample_peer
92
-
93
-	# Set to 1 to enable this peer
94
-	# In tap mode peers can be reloaded dynamically
95
-	option enabled 0
96
-
97
-	# Controls which instance this peer is associated with
98
-	option net 'sample_config'
99
-
100
-	# Controls which peer group this peer belongs to, optional
101
-	# For most use cases peer groups aren't necessary
102
-#	option group 'sample_group'
103
-
104
-	# The peer's public key
105
-	option key '0000000000000000000000000000000000000000000000000000000000000000'
106
-
107
-	# A remote specification consists of an address or a hostname, and a port
108
-	# When a hostname is given, it is recommended to specify the address family to use
109
-	# It is possible to specify no, one or multiple remotes
110
-	# (but all entries must designate the same host as the public key must be unique)
111
-#	list remote '192.0.2.1:1337'
112
-#	list remote '[2001:db8::1]:1337'
113
-#	list remote '"example.com" port 1337'
114
-#	list remote 'ipv4 "example.com" port 1337'
115
-#	list remote 'ipv6 "example.com" port 1337'
116
-
117
-	# Setting float to 1 allow incoming connections with this key from other addresses/hostnames/ports than the specified remotes
118
-#	option float 0
119
-
120
-
121
-config peer_group sample_group
122
-
123
-	# Set to 1 to enable this peer group
124
-	option enabled 0
125
-
126
-	# Controls which instance this peer group is associated with
127
-	# Peer groups can't be used in tun mode
128
-	option net 'sample_config'
129
-
130
-	# Allows configuring nested groups
131
-#	option parent 'other_group'
132
-
133
-	# Includes another config file inside the peer group definition
134
-#	list config '/etc/fastd/sample_config/sample_group.conf'
135
-
136
-	# Configures a single static peer from a configuration file
137
-#	list config_peer '/etc/fastd/sample_config/sample_peer.conf'
138
-
139
-	# Configures an additional peer directory for this group
140
-#	list config_peer_dir '/etc/fastd/sample_config/peers2'
141
-
142
-	# Limits the maximum number of connections to peers in this group (optional)
143
-#	option peer_limit 5

+ 0
- 425
net/fastd/files/fastd.init View File

1
-#!/bin/sh /etc/rc.common
2
-# Copyright (C) 2012-2013 OpenWrt.org
3
-
4
-START=95
5
-
6
-SERVICE_USE_PID=1
7
-
8
-EXTRA_COMMANDS="up down show_key generate_key"
9
-
10
-LIST_SEP="
11
-"
12
-TMP_FASTD=/tmp/fastd
13
-FASTD_COMMAND=/usr/bin/fastd
14
-
15
-
16
-section_enabled() {
17
-	config_get_bool enabled "$1" 'enabled' 0
18
-	[ $enabled -gt 0 ]
19
-}
20
-
21
-error() {
22
-	echo "${initscript}:" "$@" 1>&2
23
-}
24
-
25
-get_key_instance() {
26
-	local s="$1"
27
-
28
-	config_get secret "$s" secret
29
-	if [ "$secret" = 'generate' ]; then
30
-		secret=`"$FASTD_COMMAND" --generate-key --machine-readable`
31
-		uci -q set fastd."$s".secret="$secret" && uci -q commit fastd
32
-	fi
33
-
34
-	echo "$secret"
35
-}
36
-
37
-
38
-escape_string() {
39
-	local t=${1//\\/\\\\}
40
-	echo -n "\"${t//\"/\\\"}\""
41
-}
42
-
43
-guard_value() {
44
-	local t=${1//[^-a-z0-9\[\].:]/}
45
-	echo -n "$t"
46
-}
47
-
48
-guard_remote() {
49
-	local t=${1//[^-a-zA-Z0-9\[\].:\"% ]/}
50
-	local quotes=${t//[^\"]/}
51
-	if [ "${#quotes}" = 0 -o "${#quotes}" = 2 ]; then
52
-		echo -n "$t"
53
-	fi
54
-}
55
-
56
-yes_no() {
57
-	case "$1" in
58
-		0|no|off|false|disabled) echo -n no;;
59
-		*) echo -n yes;;
60
-	esac
61
-}
62
-
63
-config_string_config='include $(escape_string "$value");'
64
-config_string_config_peer='include peer $(escape_string "$value");'
65
-config_string_config_peer_dir='include peers from $(escape_string "$value");'
66
-config_string_bind='bind $(guard_value "$value");'
67
-config_string_method='method $(escape_string "$value");'
68
-config_string_syslog_level='log to syslog level $(guard_value "$value");'
69
-config_string_mode='mode $(guard_value "$value");'
70
-config_string_interface='interface $(escape_string "$value");'
71
-config_string_mtu='mtu $(guard_value "$value");'
72
-config_string_peer_limit='peer limit $(guard_value "$value");'
73
-config_string_user='user $(escape_string "$value");'
74
-config_string_group='group $(escape_string "$value");'
75
-config_string_pmtu='pmtu $(yes_no "$value");'
76
-config_string_forward='forward $(yes_no "$value");'
77
-config_string_hide_ip_addresses='hide ip addresses $(yes_no "$value");'
78
-config_string_hide_mac_addresses='hide mac addresses $(yes_no "$value");'
79
-config_string_secure_handshakes='secure handshakes $(yes_no "$value");'
80
-config_string_packet_mark='packet mark $(guard_value "$value");'
81
-
82
-config_string_peer='peer $(escape_string "$value") {'
83
-config_string_peer_group='peer group $(escape_string "$value") {'
84
-
85
-peer_string_key='key $(escape_string "$value");'
86
-peer_string_float='float $(yes_no "$value");'
87
-peer_string_remote='remote $(guard_remote "$value");'
88
-
89
-generate_option() {
90
-	local __string=$(eval echo \"\$$2\")
91
-	local value="$1";
92
-	eval echo "\"$__string\""
93
-}
94
-
95
-append_option() {
96
-	local v; local len; local s="$1"; local prefix="$2"; local p="$3"
97
-
98
-	config_get len "$s" "${p}_LENGTH"
99
-
100
-	if [ -z "$len" ]; then
101
-		config_get v "$s" "$p"
102
-		[ -n "$v" ] && generate_option "$v" "${prefix}_string_${p}"
103
-	else
104
-		config_list_foreach "$s" "$p" generate_option "${prefix}_string_${p}"
105
-	fi
106
-}
107
-
108
-append_options() {
109
-	local p; local s="$1"; local prefix="$2"; shift; shift
110
-	for p in $*; do
111
-		append_option "$s" "$prefix" "$p"
112
-	done
113
-}
114
-
115
-
116
-generate_config_secret() {
117
-	echo "secret $(escape_string "$1");"
118
-}
119
-
120
-
121
-generate_peer_config() {
122
-	local peer="$1"
123
-
124
-	# These options are deprecated
125
-	config_get address "$peer" address
126
-	config_get hostname "$peer" hostname
127
-	config_get address_family "$peer" address_family
128
-	config_get port "$peer" port
129
-
130
-	if [ "$address" -o "$hostname" ]; then
131
-		if [ -z "$port" ]; then
132
-			error "peer $peer: address or hostname, but no port given"
133
-			return 1
134
-		fi
135
-
136
-		if [ "$hostname" ]; then
137
-			generate_option peer_string_remote "$address_family \"$hostname\" port $port"
138
-		fi
139
-
140
-		if [ "$address" ]; then
141
-			generate_option peer_string_remote "$address port $port"
142
-		fi
143
-	fi
144
-
145
-	append_options "$peer" peer \
146
-		key float remote
147
-}
148
-
149
-generate_single_peer_config() {
150
-	local peer="$1"; local net="$2"
151
-
152
-	config_get peer_net "$peer" net
153
-	config_get peer_group "$peer" group
154
-	[ "$net" = "$peer_net" -a "$peer_group" = '' ] || return 0
155
-
156
-	section_enabled "$peer" || return 0
157
-
158
-	generate_option "$peer" config_string_peer
159
-	generate_peer_config "$peer"
160
-	echo '}'
161
-}
162
-
163
-create_peer_config() {
164
-	local peer="$1"; local net="$2"; local group="$3"; local path="$4"
165
-
166
-	config_get peer_net "$peer" net
167
-	config_get peer_group "$peer" group
168
-	[ "$group" = "$peer_group" ] || return 0
169
-
170
-	if [ "$net" != "$peer_net" ]; then
171
-		[ -z "$group" ] || error "warning: the peer group of peer '$peer' doesn't match its net, the peer will be ignored"
172
-		return 0
173
-	fi
174
-
175
-	section_enabled "$peer" || return 0
176
-
177
-	generate_peer_config "$peer" >"$path/$peer"
178
-}
179
-
180
-update_peer_group() {
181
-	local net="$1"; local group_dir="$2"; local group="$3"; local update_only="$4"
182
-	local path="$TMP_FASTD/fastd.$net/$group_dir"
183
-
184
-	rm -rf "$path"
185
-	mkdir -p "$path"
186
-
187
-	config_foreach create_peer_config 'peer' "$net" "$group" "$path"
188
-
189
-	if [ -z "$update_only" ]; then
190
-		generate_option "$path" config_string_config_peer_dir
191
-	fi
192
-
193
-	config_foreach generate_peer_group_config 'peer_group' "$net" "$group_dir" "$update_only" "$group"
194
-}
195
-
196
-generate_peer_group_config() {
197
-	local group="$1"; local net="$2"; local group_dir="$3%$group"; local update_only="$4"; local parent="$5"
198
-
199
-	config_get group_net "$group" net
200
-	config_get group_parent "$group" parent
201
-	[ "$parent" = "$group_parent" ] || return 0
202
-
203
-	if [ "$net" != "$peer_net" ]; then
204
-		[ -z "$parent" ] || error "warning: the parent of peer group '$group' doesn't match its net, the peer group will be ignored"
205
-		return 0
206
-	fi
207
-
208
-	section_enabled "$group" || return 0
209
-
210
-	if [ -z "$update_only" ]; then
211
-		generate_option "$group" config_string_peer_group
212
-		append_options "$group" config \
213
-			config config_peer config_peer_dir peer_limit
214
-	fi
215
-
216
-	update_peer_group "$net" "$group_dir" "$group" "$update_only"
217
-
218
-	if [ -z "$update_only" ]; then
219
-		echo '}'
220
-	fi
221
-}
222
-
223
-update_peer_groups() {
224
-	local net="$1"; local update_only="$2"
225
-
226
-	update_peer_group "$net" 'peers' '' "$update_only"
227
-}
228
-
229
-generate_config() {
230
-	local s="$1"
231
-
232
-	generate_option 'info' config_string_syslog_level
233
-
234
-	append_options "$s" config \
235
-		config config_peer config_peer_dir bind method syslog_level mode interface mtu peer_limit \
236
-		user group pmtu forward hide_ip_addresses hide_mac_addresses secure_handshakes packet_mark
237
-
238
-	config_get mode "$s" mode
239
-
240
-	if [ "$mode" = "tun" ]; then
241
-		config_foreach generate_single_peer_config 'peer' "$s"
242
-	else
243
-		update_peer_groups "$s"
244
-	fi
245
-}
246
-
247
-
248
-generate_key_instance() {
249
-	local s="$1"
250
-
251
-	config_get secret "$s" secret
252
-	if [ -z "$secret" -o "$secret" = 'generate' ]; then
253
-		secret=`fastd --generate-key --machine-readable`
254
-		uci -q set fastd."$s".secret="$secret" && uci -q commit fastd
255
-	fi
256
-
257
-	generate_config_secret "$secret" | "$FASTD_COMMAND" --config - --show-key --machine-readable
258
-}
259
-
260
-show_key_instance() {
261
-	local s="$1"
262
-
263
-	local secret=`get_key_instance "$s"`
264
-	if [ -z "$secret" ]; then
265
-		error "$s: secret is not set"
266
-		return 1
267
-	fi
268
-
269
-	generate_config_secret "$secret" | "$FASTD_COMMAND" --config - --show-key --machine-readable
270
-}
271
-
272
-start_instance() {
273
-	local s="$1"
274
-
275
-	section_enabled "$s" || return 1
276
-
277
-	SERVICE_PID_FILE="/var/run/fastd.$s.pid"
278
-
279
-	config_get interface "$s" interface
280
-	if [ -z "$interface" ]; then
281
-		error "$s: interface is not set"
282
-		return 1
283
-	fi
284
-
285
-	if ifconfig "$interface" &>/dev/null; then
286
-		error "$s: interface '$interface' is already in use"
287
-		return 1
288
-	fi
289
-
290
-	config_get mode "$s" mode
291
-	if [ -z "$mode" ]; then
292
-		error "$s: mode is not set"
293
-		return 1
294
-	fi
295
-
296
-	local secret=`get_key_instance "$s"`
297
-	if [ -z "$secret" ]; then
298
-		error "$s: secret is not set"
299
-		return 1
300
-	fi
301
-
302
-	rm -f "$SERVICE_PID_FILE"
303
-	touch "$SERVICE_PID_FILE"
304
-
305
-	config_get user "$s" user
306
-	if [ "$user" ]; then
307
-		chown "$user" "$SERVICE_PID_FILE"
308
-	fi
309
-
310
-	(generate_config_secret "$secret"; generate_config "$s") | service_start "$FASTD_COMMAND" --config - --daemon --pid-file "$SERVICE_PID_FILE"
311
-
312
-	if ! ifconfig "$interface" >/dev/null 2>&1; then
313
-		error "$s: startup failed"
314
-		return 1
315
-	fi
316
-
317
-	config_get up "$s" up
318
-	[ -n "$up" ] && sh -c "$up" - "$interface"
319
-}
320
-
321
-stop_instance() {
322
-	local s="$1"
323
-
324
-	section_enabled "$s" || return 1
325
-
326
-	SERVICE_PID_FILE="/var/run/fastd.$s.pid"
327
-
328
-	config_get interface "$s" interface
329
-	if [ -z "$interface" ]; then
330
-		error "$s: interface is not set"
331
-		return 1
332
-	fi
333
-
334
-	if ! ifconfig "$interface" &>/dev/null; then
335
-		error "$s: interface '$interface' does not exist"
336
-		return 1
337
-	fi
338
-
339
-	config_get down "$s" down
340
-	[ -n "$down" ] && sh -c "$down" - "$interface"
341
-
342
-	service_stop "$FASTD_COMMAND"
343
-
344
-	rm -rf "$TMP_FASTD/fastd.$s"
345
-}
346
-
347
-reload_instance() {
348
-	local s="$1"
349
-
350
-	section_enabled "$s" || return 1
351
-
352
-	config_get mode "$s" mode
353
-	[ "$mode" = "tun" ] && return 1
354
-
355
-	update_peer_groups "$s" true
356
-
357
-	SERVICE_PID_FILE="/var/run/fastd.$s.pid"
358
-	service_reload "$FASTD_COMMAND"
359
-}
360
-
361
-start() {
362
-	config_load 'fastd'
363
-	config_foreach start_instance 'fastd'
364
-	return 0
365
-}
366
-
367
-stop() {
368
-	config_load 'fastd'
369
-	config_foreach stop_instance 'fastd'
370
-	return 0
371
-}
372
-
373
-reload() {
374
-	config_load 'fastd'
375
-	config_foreach reload_instance 'fastd'
376
-	return 0
377
-}
378
-
379
-up() {
380
-	local exists
381
-	local instance
382
-	config_load 'fastd'
383
-	for instance in "$@"; do
384
-		config_get exists "$instance" 'TYPE'
385
-		if [ "$exists" = 'fastd' ]; then
386
-			start_instance "$instance"
387
-		fi
388
-	done
389
-}
390
-
391
-down() {
392
-	local exists
393
-	local instance
394
-	config_load 'fastd'
395
-	for instance in "$@"; do
396
-		config_get exists "$instance" 'TYPE'
397
-		if [ "$exists" = 'fastd' ]; then
398
-			stop_instance "$instance"
399
-		fi
400
-	done
401
-}
402
-
403
-show_key() {
404
-	local exists
405
-	local instance
406
-	config_load 'fastd'
407
-	for instance in "$@"; do
408
-		config_get exists "$instance" 'TYPE'
409
-		if [ "$exists" = 'fastd' ]; then
410
-			show_key_instance "$instance"
411
-		fi
412
-	done
413
-}
414
-
415
-generate_key() {
416
-	local exists
417
-	local instance
418
-	config_load 'fastd'
419
-	for instance in "$@"; do
420
-		config_get exists "$instance" 'TYPE'
421
-		if [ "$exists" = 'fastd' ]; then
422
-			generate_key_instance "$instance"
423
-		fi
424
-	done
425
-}