[2/2] fff-fastd: throw the outsourced part of vpn-select into the fff-fastd package

Submitted by Robert Langhammer on June 17, 2020, 9:46 p.m.

Details

Message ID 20200617214652.4933-2-rlanghammer@web.de
State Superseded
Headers show

Commit Message

Robert Langhammer June 17, 2020, 9:46 p.m.
This is the former configuration and start-stop part from vpn-select for fastd.

Signed-off-by: Robert Langhammer <rlanghammer@web.de>
---
 .../fff-fastd/files/etc/vpn-select.d/fastd    | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd

--
2.20.1

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd b/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd
new file mode 100644
index 0000000..106daa0
--- /dev/null
+++ b/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd
@@ -0,0 +1,33 @@ 
+# remove old config
+rm /tmp/fastd_fff_peers/*
+
+
+fastd_config() {
+	[ -d /tmp/fastd_fff_peers ] || mkdir /tmp/fastd_fff_peers
+
+	# write fastd-config
+	json_get_var servername name
+	filename="/etc/fastd/fff/peers/$servername"
+	echo "#name \"${servername}\";" > "$filename"
+	json_get_var key key
+	echo "key \"${key}\";" >> "$filename"
+	json_get_var address address
+	json_get_var port port
+	echo "remote \"${address}\" port ${port};" >> "$filename"
+	echo "" >> "$filename"
+	echo "float yes;" >> "$filename"
+}
+
+fastd_start_stop() {
+	/etc/init.d/fastd reload # does nothing if fastd was not running
+
+	# fastd start/stop for various situations
+	# this is needed for first start and if fastd comes up or disappears in hoodfile
+	pidfile="/tmp/run/fastd.fff.pid"
+	if [ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ]; then
+		([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start
+	else
+		([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) && /etc/init.d/fastd stop
+	fi
+}
+

Comments

Fabian Blaese June 18, 2020, 9:53 a.m.
Sieht gut aus.

Reviewed-by: Fabian Bläse <fabian@blaese.de>

Da die beiden Patches nicht unabhängig voneinander funktionieren, der eine Code entfernt, den der andere woanders wieder hinzufügt, und das ganze insgesamt auch nicht unübersichtlich lang ist, würde ich vermutlich eher beide Patches zusammenfassen.

Gruß
Fabian

On 17.06.20 23:46, Robert Langhammer wrote:
> This is the former configuration and start-stop part from vpn-select for fastd.
> 
> Signed-off-by: Robert Langhammer <rlanghammer@web.de>
> ---
>  .../fff-fastd/files/etc/vpn-select.d/fastd    | 33 +++++++++++++++++++
>  1 file changed, 33 insertions(+)
>  create mode 100644 src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd
> 
> diff --git a/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd b/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd
> new file mode 100644
> index 0000000..106daa0
> --- /dev/null
> +++ b/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd
> @@ -0,0 +1,33 @@
> +# remove old config
> +rm /tmp/fastd_fff_peers/*
> +
> +
> +fastd_config() {
> +	[ -d /tmp/fastd_fff_peers ] || mkdir /tmp/fastd_fff_peers
> +
> +	# write fastd-config
> +	json_get_var servername name
> +	filename="/etc/fastd/fff/peers/$servername"
> +	echo "#name \"${servername}\";" > "$filename"
> +	json_get_var key key
> +	echo "key \"${key}\";" >> "$filename"
> +	json_get_var address address
> +	json_get_var port port
> +	echo "remote \"${address}\" port ${port};" >> "$filename"
> +	echo "" >> "$filename"
> +	echo "float yes;" >> "$filename"
> +}
> +
> +fastd_start_stop() {
> +	/etc/init.d/fastd reload # does nothing if fastd was not running
> +
> +	# fastd start/stop for various situations
> +	# this is needed for first start and if fastd comes up or disappears in hoodfile
> +	pidfile="/tmp/run/fastd.fff.pid"
> +	if [ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ]; then
> +		([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start
> +	else
> +		([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) && /etc/init.d/fastd stop
> +	fi
> +}
> +
> --
> 2.20.1
>