]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: run PreUp hook after creating interface
authorDaniel Gröber <dxld@darkboxed.org>
Wed, 7 Dec 2022 18:00:31 +0000 (19:00 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 18 May 2023 14:38:34 +0000 (16:38 +0200)
Currently PreUp hooks run before the interface 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>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/wg-quick/darwin.bash
src/wg-quick/freebsd.bash
src/wg-quick/linux.bash
src/wg-quick/openbsd.bash

index 8e468189a2fe5342af62f5f1c5a80eb08816bc54..c9381124c9379de92d8f17810b466253cddf2853 100755 (executable)
@@ -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"
index b529ab2a508861d5569feeb3f350cb8ff6f22ea1..f72daf69c112cb0505fd4e10b8d184ca74b2442d 100755 (executable)
@@ -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"
index 69e5bef05cfdae39e7bc66995ef6a097384717a9..4193ce586ccbe45939cf121a9050e86feae15256 100755 (executable)
@@ -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"
index 2adfe4606a785c177d27560ca88b99382fcb2b50..b58ecf5cd7fa10c0f715e875ac1263e4e98c8af6 100755 (executable)
@@ -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"