Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] wg-quick: add syncconf
@ 2021-02-09 15:58 Marc-Antoine Perennou
  0 siblings, 0 replies; only message in thread
From: Marc-Antoine Perennou @ 2021-02-09 15:58 UTC (permalink / raw)
  To: wireguard

Simplifies the process to reload an updated configuration, avoid subshells

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
---
 src/man/wg-quick.8            |  4 ++++
 src/systemd/wg-quick@.service |  2 +-
 src/wg-quick/darwin.bash      | 13 ++++++++++++-
 src/wg-quick/freebsd.bash     | 11 ++++++++++-
 src/wg-quick/linux.bash       | 11 ++++++++++-
 src/wg-quick/openbsd.bash     | 11 ++++++++++-
 6 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/man/wg-quick.8 b/src/man/wg-quick.8
index b84eb64..f52a3fe 100644
--- a/src/man/wg-quick.8
+++ b/src/man/wg-quick.8
@@ -256,6 +256,10 @@ sessions:
 
 \fB    # wg syncconf wgnet0 <(wg-quick strip wgnet0)\fP
 
+You can also use the \fIsyncconf\fP command for the same purpose
+
+\fB    # wg-quick syncconf wgnet0\fP
+
 .SH SEE ALSO
 .BR wg (8),
 .BR ip (8),
diff --git a/src/systemd/wg-quick@.service b/src/systemd/wg-quick@.service
index dbdab44..cb8b3a9 100644
--- a/src/systemd/wg-quick@.service
+++ b/src/systemd/wg-quick@.service
@@ -15,7 +15,7 @@ Type=oneshot
 RemainAfterExit=yes
 ExecStart=/usr/bin/wg-quick up %i
 ExecStop=/usr/bin/wg-quick down %i
-ExecReload=/bin/bash -c 'exec /usr/bin/wg syncconf %i <(exec /usr/bin/wg-quick strip %i)'
+ExecReload=/usr/bin/wg-quick syncconf %i
 Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity
 
 [Install]
diff --git a/src/wg-quick/darwin.bash b/src/wg-quick/darwin.bash
index cde1b54..94c669e 100755
--- a/src/wg-quick/darwin.bash
+++ b/src/wg-quick/darwin.bash
@@ -418,7 +418,7 @@ execute_hooks() {
 
 cmd_usage() {
 	cat >&2 <<-_EOF
-	Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
+	Usage: $PROGRAM [ up | down | save | strip | syncconf ] [ CONFIG_FILE | INTERFACE ]
 
 	  CONFIG_FILE is a configuration file, whose filename is the interface name
 	  followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -489,6 +489,13 @@ cmd_strip() {
 	echo "$WG_CONFIG"
 }
 
+cmd_syncconf() {
+	if ! get_real_interface || [[ " $(wg show interfaces) " != *" $REAL_INTERFACE "* ]]; then
+		die "\`$INTERFACE' is not a WireGuard interface"
+	fi
+	cmd wg syncconf "$REAL_INTERFACE" <(echo "$WG_CONFIG")
+}
+
 # ~~ function override insertion point ~~
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
@@ -510,6 +517,10 @@ elif [[ $# -eq 2 && $1 == strip ]]; then
 	auto_su
 	parse_options "$2"
 	cmd_strip
+elif [[ $# -eq 2 && $1 == syncconf ]]; then
+	auto_su
+	parse_options "$2"
+	cmd_syncconf
 else
 	cmd_usage
 	exit 1
diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash
index e1ee67f..9415926 100755
--- a/src/wg-quick/freebsd.bash
+++ b/src/wg-quick/freebsd.bash
@@ -387,7 +387,7 @@ execute_hooks() {
 
 cmd_usage() {
 	cat >&2 <<-_EOF
-	Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
+	Usage: $PROGRAM [ up | down | save | strip | syncconf ] [ CONFIG_FILE | INTERFACE ]
 
 	  CONFIG_FILE is a configuration file, whose filename is the interface name
 	  followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -454,6 +454,11 @@ cmd_strip() {
 	echo "$WG_CONFIG"
 }
 
+cmd_syncconf() {
+	[[ " $(wg show interfaces) " == *" $INTERFACE "* ]] || die "\`$INTERFACE' is not a WireGuard interface"
+	cmd wg syncconf "$INTERFACE" <(echo "$WG_CONFIG")
+}
+
 # ~~ function override insertion point ~~
 
 make_temp
@@ -477,6 +482,10 @@ elif [[ $# -eq 2 && $1 == strip ]]; then
 	auto_su
 	parse_options "$2"
 	cmd_strip
+elif [[ $# -eq 2 && $1 == syncconf ]]; then
+	auto_su
+	parse_options "$2"
+	cmd_syncconf
 else
 	cmd_usage
 	exit 1
diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash
index e4d4c4f..83ae4a8 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -298,7 +298,7 @@ execute_hooks() {
 
 cmd_usage() {
 	cat >&2 <<-_EOF
-	Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
+	Usage: $PROGRAM [ up | down | save | strip | syncconf ] [ CONFIG_FILE | INTERFACE ]
 
 	  CONFIG_FILE is a configuration file, whose filename is the interface name
 	  followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -361,6 +361,11 @@ cmd_strip() {
 	echo "$WG_CONFIG"
 }
 
+cmd_syncconf() {
+	[[ " $(wg show interfaces) " == *" $INTERFACE "* ]] || die "\`$INTERFACE' is not a WireGuard interface"
+	cmd wg syncconf "$INTERFACE" <(echo "$WG_CONFIG")
+}
+
 # ~~ function override insertion point ~~
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
@@ -381,6 +386,10 @@ elif [[ $# -eq 2 && $1 == strip ]]; then
 	auto_su
 	parse_options "$2"
 	cmd_strip
+elif [[ $# -eq 2 && $1 == syncconf ]]; then
+	auto_su
+	parse_options "$2"
+	cmd_syncconf
 else
 	cmd_usage
 	exit 1
diff --git a/src/wg-quick/openbsd.bash b/src/wg-quick/openbsd.bash
index 15550c8..6d0efa8 100755
--- a/src/wg-quick/openbsd.bash
+++ b/src/wg-quick/openbsd.bash
@@ -376,7 +376,7 @@ execute_hooks() {
 
 cmd_usage() {
 	cat >&2 <<-_EOF
-	Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
+	Usage: $PROGRAM [ up | down | save | strip | syncconf ] [ CONFIG_FILE | INTERFACE ]
 
 	  CONFIG_FILE is a configuration file, whose filename is the interface name
 	  followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -441,6 +441,11 @@ cmd_strip() {
 	echo "$WG_CONFIG"
 }
 
+cmd_syncconf() {
+	get_real_interface || die "\`$INTERFACE' is not a WireGuard interface"
+	cmd wg syncconf "$REAL_INTERFACE" <(echo "$WG_CONFIG")
+}
+
 # ~~ function override insertion point ~~
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
@@ -461,6 +466,10 @@ elif [[ $# -eq 2 && $1 == strip ]]; then
 	auto_su
 	parse_options "$2"
 	cmd_strip
+elif [[ $# -eq 2 && $1 == syncconf ]]; then
+	auto_su
+	parse_options "$2"
+	cmd_syncconf
 else
 	cmd_usage
 	exit 1
-- 
2.30.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-10 15:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 15:58 [PATCH] wg-quick: add syncconf Marc-Antoine Perennou

Development discussion of WireGuard

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/wireguard/0 wireguard/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 wireguard wireguard/ http://inbox.vuxu.org/wireguard \
		wireguard@lists.zx2c4.com
	public-inbox-index wireguard

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.wireguard


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git