Bug 267818 - net/wireguard: Sometimes doesn't set MTU in correct value
Summary: net/wireguard: Sometimes doesn't set MTU in correct value
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Bernhard Froehlich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-16 22:31 UTC by iron.udjin
Modified: 2023-10-30 12:34 UTC (History)
4 users (show)

See Also:
bugzilla: maintainer-feedback? (decke)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description iron.udjin 2022-11-16 22:31:46 UTC
I don't know which one port is responsible for that:
wireguard-2,1
wireguard-kmod-0.0.20220615
wireguard-tools-1.0.20210914_1

Problem:
In config file I have:
[Interface]
...
MTU = 1400

When I start wireguard for the first time, wg0 interface has MTU 1460. But if I restart it one or more times, it set MTU correctly to 1400. Finally, each time when the server has restarted I need to restart wireguard one or more time by hands to make it set MTU to correct value.

I use wireguard with kernel module.
Comment 1 Bernhard Froehlich freebsd_committer freebsd_triage 2022-11-17 10:02:56 UTC
Please also specify FreeBSD version and if possible paste the shell output when starting wireguard. It should output the ifconfig command it is using (most likely: ifconfig wg0 mtu 1400).

https://git.zx2c4.com/wireguard-tools/tree/src/wg-quick/freebsd.bash#n183

Could be a bug/race condition in wg-quick and/or the kernel module.
Comment 2 iron.udjin 2022-11-17 10:51:38 UTC
13.1-RELEASE-p3

Right after server restarted:
# ifconfig | grep wg0
wg0: flags=80c1<UP,RUNNING,NOARP,MULTICAST> metric 0 mtu 1460

# service wireguard restart
[#] ifconfig wg0 destroy
[#] ifconfig wg create name wg0
[#] wg setconf wg0 /dev/stdin
[#] ifconfig wg0 inet 10.200.200.3/24 alias
[#] ifconfig wg0 mtu 1400
[#] ifconfig wg0 up
[#] route -q -n add -inet 10.10.10.0/24 -interface wg0
[+] Backgrounding route monitor
# ifconfig | grep wg0
wg0: flags=80c1<UP,RUNNING,NOARP,MULTICAST> metric 0 mtu 1460
# service wireguard restart
...
# ifconfig | grep wg0
wg0: flags=80c1<UP,RUNNING,NOARP,MULTICAST> metric 0 mtu 1400
Comment 3 Bernhard Froehlich freebsd_committer freebsd_triage 2022-11-17 15:23:35 UTC
Adding kevans@ probably he has an idea.
Comment 4 Kyle Evans freebsd_committer freebsd_triage 2023-02-16 05:04:43 UTC
Sorry, this stalled a bit. wg(4) sets the mtu exactly twice: upon clone creation, and upon request with the ioctl. The ioctl apparently didn't fail, so it naturally happened after cloning succeeded and the MTU should've stuck without much of anything to race against.

CC jhb@, maybe there's some other part of the stack that may fiddle with the MTU after the interface is created, but I don't think so...
Comment 5 crest 2023-10-30 12:31:10 UTC
Are there any ifconfig invocations in your PreUp/PostUp hooks?
Comment 6 iron.udjin 2023-10-30 12:34:16 UTC
(In reply to crest from comment #5)
No. Here is config:

[Interface]
Address = 10.2.2.3/24
PrivateKey = ***
MTU = 1400

[Peer]
PublicKey = ***
PresharedKey = ***
AllowedIPs = 10.2.2.0/24
Endpoint = *.*.*.*:5555
PersistentKeepalive = 60