Skip to contentSkip to conversation

FreeBSD wireguard wg-quick remote IP address assignment is incorrect

DISCUSSION Peter Libassi 2 participants 5 messages Feb 23, 2020 – Feb 25, 2020

lore
Share & tools
lore
#0 lore raw

local wg interface does not respond due to the wg-quick script sets up the interface by reusing the local address as the remote address in the ifconfig command:

root@bsd2:~ # wg-quick up wg0
[#] wireguard-go wg0
INFO: (wg0) 2020/02/20 09:45:16 Starting wireguard-go version 0.0.20200121 [#] wg setconf wg0 /tmp/tmp.87viEAsK/sh-np.YdRfI6
[#] ifconfig wg0 inet 192.168.2.2 192.168.2.2 alias

On linux setting up an IP address on a tun interface does not require a remote address:
[root@vpn2 wireguard]# wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 192.168.2.2/24 dev wg0

In the wg-quick script function add_addr() is where the assignment is made:

cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias

I verifed this by replacing remote address with localhost:

cmd ifconfig "$INTERFACE" inet "$1" "127.0.0.1" alias

Now local ping works. You can give any address I suppose since the ”remote address” of the ifconfig of a tun interface is not really used by wireguard.

I also filed this as FreeBSD bug 244330.

/Peter

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

#1 lore raw

We tried this already and it didn't work. See the below commit. Perhaps you can update that bug report you filed?

commit 2c6cabd73dfb23990c245250ef2e502bdb33d189

Author: Jason A. Donenfeld <[email protected]>
Date:   Thu Feb 28 19:03:11 2019 +0100

wg-quick: freebsd: rebreak interface loopback, while fixing localhost

The commit 7c833642 ("wg-quick: freebsd: allow loopback to work") was supposed to make things better, but actually it just started sending legitimate localhost traffic over the WireGuard interface, which is really quite bad.

This reverts commit 7c833642dfa342218602ab18e7091e86408d2982.

src/wg-quick/freebsd.bash +1 -1
index 93f1a3b7..e83dbef0 100755
@@ -158,7 +158,7 @@ add_addr() {
       if [[ $1 == *:* ]]; then
               cmd ifconfig "$INTERFACE" inet6 "$1" alias
       else
-               cmd ifconfig "$INTERFACE" inet "$1" 127.0.0.1 alias
+               cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
       fi

}
_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

#2 lore raw

Ok, Well even if using another local IP in range 127.0.0.0/8 we can’t be certain we will clash with something else.

How about adding a directive for the remote interface address in wg.conf? Like this:

# cat /usr/local/etc/wireguard/wg0.conf
[Interface]
PrivateKey = <->
ListenPort = 7777
Address = 192.168.2.1/32
RemoteAddress = 192.168.2.2

[Peer]
PublicKey = <->
AllowedIPs = 192.168.2.0/24
Endpoint = 172.16.0.23:7777

# diff /usr/local/bin/wg-quick.org ./wg-quick
17a18
Quoted 1 line

REMOTE_ADDRESS=""

86a88

Quoted 1 line
			RemoteAddress) REMOTEADDRESS="$value"; continue ;;

175c177,181
< cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
---

Quoted 5 lines

if [[ -n $REMOTEADDRESS ]]; then
cmd ifconfig "$INTERFACE" inet "$1" "$REMOTEADDRESS" alias
else
cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
fi

/Peter

Quoted 26 lines

23 feb. 2020 kl. 12:37 skrev Jason A. Donenfeld <[email protected]>:

We tried this already and it didn't work. See the below commit. Perhaps you can update that bug report you filed?

commit 2c6cabd73dfb23990c245250ef2e502bdb33d189

Author: Jason A. Donenfeld <[email protected]>
Date:   Thu Feb 28 19:03:11 2019 +0100

wg-quick: freebsd: rebreak interface loopback, while fixing localhost

The commit 7c833642 ("wg-quick: freebsd: allow loopback to work") was supposed to make things better, but actually it just started sending legitimate localhost traffic over the WireGuard interface, which is really quite bad.

This reverts commit 7c833642dfa342218602ab18e7091e86408d2982.

src/wg-quick/freebsd.bash +0 -0
index 93f1a3b7..e83dbef0 100755

src/wg-quick/freebsd.bash add_addr() { · line 163

Quoted 7 lines
src/wg-quick/freebsd.bash +1 -1
@@ -158,7 +158,7 @@ add_addr() {
      if [[ $1 == *:* ]]; then
              cmd ifconfig "$INTERFACE" inet6 "$1" alias
      else
-               cmd ifconfig "$INTERFACE" inet "$1" 127.0.0.1 alias
+               cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
      fi
 }

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

#3 lore raw
Quoted 17 lines · Peter Libassi

Ok, Well even if using another local IP in range 127.0.0.0/8 we can’t be certain we will clash with something else.

How about adding a directive for the remote interface address in wg.conf? Like this:

# cat /usr/local/etc/wireguard/wg0.conf
[Interface]
PrivateKey = <->
ListenPort = 7777
Address = 192.168.2.1/32
RemoteAddress = 192.168.2.2

[Peer]
PublicKey = <->
AllowedIPs = 192.168.2.0/24
Endpoint = 172.16.0.23:7777

Quoted 13 lines
# diff /usr/local/bin/wg-quick.org ./wg-quick
17a18
Quoted 1 line

REMOTE_ADDRESS=""

86a88

Quoted 1 line

RemoteAddress) REMOTEADDRESS="$value"; continue ;;

175c177,181
< cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
---

Quoted 5 lines

if [[ -n $REMOTEADDRESS ]]; then
cmd ifconfig "$INTERFACE" inet "$1" "$REMOTEADDRESS" alias

    else
                cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
    fi

This is not a correct fix; we're not going to add a configuration nob to work around FreeBSD network stack gotchas.

Rather, I'd prefer to see all the FreeBSD wg-quick semantics redone around multiple routing tables and marks, much like on Linux, though I don't know if that's possible. Barring that, a proper solution probably involves re-reading the ifconfig man page a few dozen times to find out how to have interface addresses as we need them.
_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

#4 lore raw
Quoted 36 lines

23 feb. 2020 kl. 16:32 skrev Jason A. Donenfeld <[email protected]>:

Quoted 17 lines · Peter Libassi

Ok, Well even if using another local IP in range 127.0.0.0/8 we can’t be certain we will clash with something else.

How about adding a directive for the remote interface address in wg.conf? Like this:

# cat /usr/local/etc/wireguard/wg0.conf
[Interface]
PrivateKey = <->
ListenPort = 7777
Address = 192.168.2.1/32
RemoteAddress = 192.168.2.2

[Peer]
PublicKey = <->
AllowedIPs = 192.168.2.0/24
Endpoint = 172.16.0.23:7777

Quoted 13 lines
# diff /usr/local/bin/wg-quick.org ./wg-quick
17a18
Quoted 1 line

REMOTE_ADDRESS=""

86a88

Quoted 1 line

RemoteAddress) REMOTEADDRESS="$value"; continue ;;

175c177,181
< cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias
---

Quoted 5 lines

if [[ -n $REMOTEADDRESS ]]; then
cmd ifconfig "$INTERFACE" inet "$1" "$REMOTEADDRESS" alias
else

               cmd ifconfig "$INTERFACE" inet "$1" "${1%%/*}" alias

fi

Quoted 8 lines

This is not a correct fix; we're not going to add a configuration nob to work around FreeBSD network stack gotchas.

Rather, I'd prefer to see all the FreeBSD wg-quick semantics redone around multiple routing tables and marks, much like on Linux, though I don't know if that's possible. Barring that, a proper solution probably involves re-reading the ifconfig man page a few dozen times to find out how to have interface addresses as we need them.

It works perfectly for my single site-2-site use case. You have two options as I see it. Either convince the FreeBSD team to drop the dest_address requirement or implement local/remote address awareness per [Peer] in the wg-quick script.

/Peter

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard