Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] wg-quick: Allow setting iface VRF in PreUp hook
@ 2022-12-07 18:00 Daniel Gröber
  2022-12-08  8:27 ` Paul Menzel
  2023-05-18 14:39 ` Jason A. Donenfeld
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Gröber @ 2022-12-07 18:00 UTC (permalink / raw)
  To: wireguard; +Cc: Jason A . Donenfeld, Daniel Gröber

Currently PreUp hooks run before the wireguard device is created. This is
problematic for moving the device into a Linux VRFs as this will currently
clear all assigned IPv6 addressess (possibly a bug), so if we did this in
PostUp (i.e. before add_addr) we'll have to manually re-add all assigned
addresses. This is obviously less than ideal.

Instead create the wg device just before running PreUp hooks. We apply this
to all platforms for consistency.

Test case:

    $ ip link add vrf-test type vrf table 1234
    $ ip link add wg-test type wireguard
    $ ip addr add dev wg-test 192.168.42.42/24
    $ ip addr add dev wg-test fe80::/64

    $ ip -br addr show wg-test
    wg-test          DOWN           192.168.42.42/24 fe80::/64

    $ ip link set dev wg-test master vrf-test

    $ ip -br addr show wg-test
    wg-test          DOWN           192.168.42.42/32

Signed-off-by: Daniel Gröber <dxld@darkboxed.org>
---
 src/wg-quick/darwin.bash  | 2 +-
 src/wg-quick/freebsd.bash | 2 +-
 src/wg-quick/linux.bash   | 2 +-
 src/wg-quick/openbsd.bash | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/wg-quick/darwin.bash b/src/wg-quick/darwin.bash
index 8e46818..c938112 100755
--- a/src/wg-quick/darwin.bash
+++ b/src/wg-quick/darwin.bash
@@ -452,8 +452,8 @@ cmd_up() {
 	local i
 	get_real_interface && die "\`$INTERFACE' already exists as \`$REAL_INTERFACE'"
 	trap 'del_if; del_routes; exit' INT TERM EXIT
-	execute_hooks "${PRE_UP[@]}"
 	add_if
+	execute_hooks "${PRE_UP[@]}"
 	set_config
 	for i in "${ADDRESSES[@]}"; do
 		add_addr "$i"
diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash
index b529ab2..f72daf6 100755
--- a/src/wg-quick/freebsd.bash
+++ b/src/wg-quick/freebsd.bash
@@ -420,8 +420,8 @@ cmd_up() {
 	local i
 	[[ -z $(ifconfig "$INTERFACE" 2>/dev/null) ]] || die "\`$INTERFACE' already exists"
 	trap 'del_if; del_routes; clean_temp; exit' INT TERM EXIT
-	execute_hooks "${PRE_UP[@]}"
 	add_if
+	execute_hooks "${PRE_UP[@]}"
 	set_config
 	for i in "${ADDRESSES[@]}"; do
 		add_addr "$i"
diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash
index 69e5bef..4193ce5 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -327,8 +327,8 @@ cmd_up() {
 	local i
 	[[ -z $(ip link show dev "$INTERFACE" 2>/dev/null) ]] || die "\`$INTERFACE' already exists"
 	trap 'del_if; exit' INT TERM EXIT
-	execute_hooks "${PRE_UP[@]}"
 	add_if
+	execute_hooks "${PRE_UP[@]}"
 	set_config
 	for i in "${ADDRESSES[@]}"; do
 		add_addr "$i"
diff --git a/src/wg-quick/openbsd.bash b/src/wg-quick/openbsd.bash
index 2adfe46..b58ecf5 100755
--- a/src/wg-quick/openbsd.bash
+++ b/src/wg-quick/openbsd.bash
@@ -417,8 +417,8 @@ cmd_up() {
 	local i
 	get_real_interface && die "\`$INTERFACE' already exists as \`$REAL_INTERFACE'"
 	trap 'del_if; del_routes; exit' INT TERM EXIT
-	execute_hooks "${PRE_UP[@]}"
 	add_if
+	execute_hooks "${PRE_UP[@]}"
 	set_config
 	for i in "${ADDRESSES[@]}"; do
 		add_addr "$i"
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wg-quick: Allow setting iface VRF in PreUp hook
  2022-12-07 18:00 [PATCH] wg-quick: Allow setting iface VRF in PreUp hook Daniel Gröber
@ 2022-12-08  8:27 ` Paul Menzel
  2023-05-18 14:39 ` Jason A. Donenfeld
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Menzel @ 2022-12-08  8:27 UTC (permalink / raw)
  To: Daniel Gröber; +Cc: Jason A . Donenfeld, wireguard

Dear Daniel,


Thank you for your patch.


Am 07.12.22 um 19:00 schrieb Daniel Gröber:

[…]

> Test case:
> 
>      $ ip link add vrf-test type vrf table 1234
>      $ ip link add wg-test type wireguard
>      $ ip addr add dev wg-test 192.168.42.42/24
>      $ ip addr add dev wg-test fe80::/64
> 
>      $ ip -br addr show wg-test
>      wg-test          DOWN           192.168.42.42/24 fe80::/64
> 
>      $ ip link set dev wg-test master vrf-test
> 
>      $ ip -br addr show wg-test
>      wg-test          DOWN           192.168.42.42/32

Should this be /24?

[…]


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wg-quick: Allow setting iface VRF in PreUp hook
  2022-12-07 18:00 [PATCH] wg-quick: Allow setting iface VRF in PreUp hook Daniel Gröber
  2022-12-08  8:27 ` Paul Menzel
@ 2023-05-18 14:39 ` Jason A. Donenfeld
  1 sibling, 0 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2023-05-18 14:39 UTC (permalink / raw)
  To: Daniel Gröber; +Cc: wireguard

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-18 14:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 18:00 [PATCH] wg-quick: Allow setting iface VRF in PreUp hook Daniel Gröber
2022-12-08  8:27 ` Paul Menzel
2023-05-18 14:39 ` Jason A. Donenfeld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).