wg-quick: fix darwin MTU detection
PATCH 1/1 wg-quick: fix darwin MTU detection
---
On macOS The set_mtu function fails to detect the default interface correctly and always sets the (potentially incorrect) default MTU as a result.
The problem is that netstat -nr -f inet returns the interface name in the 4th column, not the 6th.
I used macOS 15.4 for testing, but I am not particularly familiar with the Apple ecosystem. I'm not sure if this never worked, the netstat shipped by Apple changed at some point and how/which other platforms (iOS?) may be affected. So please keep that in mind before merging.
src/wg-quick/darwin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/wg-quick/darwin.bash +1 -1
@@ -177,7 +177,7 @@ set_mtu() { cmd ifconfig "$REAL_INTERFACE" mtu "$MTU" return fi - while read -r destination _ _ _ _ netif _; do + while read -r destination _ _ netif _; do if [[ $destination == default ]]; then defaultif="$netif" break
Signature · 1 line
2.51.0
Hi Florian,
Sorry I didn't see this. I filtered this out because it wasn't formatted correctly (explanation below the break, commit subject not matching other wg-quick commits). Some notes:
Quoted 4 lines · Florian Uekermann
I used macOS 15.4 for testing, but I am not particularly familiar with the Apple ecosystem. I'm not sure if this never worked, the netstat shipped by Apple changed at some point and how/which other platforms (iOS?) may be affected. So please keep that in mind before merging.
If you're submitting a patch with your name on it, please do the research to make sure it's correct! Otherwise, what you're submitting is more of a bug report than a patch.
src/wg-quick/darwin.bash set_mtu() { · line 180
Quoted 13 lines
src/wg-quick/darwin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/wg-quick/darwin.bash +1
-1@@ -177,7 +177,7 @@ set_mtu() { cmd ifconfig "$REAL_INTERFACE" mtu "$MTU" return fi - while read -r destination _ _ _ _ netif _; do + while read -r destination _ _ netif _; do
Should this be changed for the other invocations of netstat -nr -f ... in the code? It's a bit confusing because in del_route(), it looks like the first invocation (for inet) is aware that it's the 6th parameter, while the second invocation (for inet6) seems to stick with this presumption that it's the 4th. So what's going on here?
Consulting the source from Apple, it looks like the 4th param is indeed the right one?
https://github.com/apple-oss-distributions/network_cmds/blob/97e27e6244c16d399bfeb254315ddc5828711c56/netstat.tproj/route.c#L328
What circumstances cause this to change? v4 vs v6? Something else?
I'd like to get to the bottom of this before applying this patch. When you submit a v2, please include your explanation as part of the commit message.
Thanks,
Jason
Hi Jason,
Thanks for following up.
Quoted 3 lines · Jason A. Donenfeld
If you're submitting a patch with your name on it, please do the research to make sure it's correct! Otherwise, what you're submitting is more of a bug report than a patch.
Please treat this as a bug report. That's why I added the disclaimer.
I tried a number of different things before sending this patch with ack, because I wasn't able to get the bug report through the filter (mailing list, mod-mail) or noticed (IRC, Github) after many failed attempts to report it. Some avenue for drive-by bug reports may be beneficial (maybe Github issues). I had given up on reporting this until your reply. Anyway, happy you saw this now.
Quoted 5 lines
Should this be changed for the other invocations of
netstat -nr -f ...in the code? It's a bit confusing because indel_route(), it looks like the first invocation (for inet) is aware that it's the 6th parameter, while the second invocation (for inet6) seems to stick with this presumption that it's the 4th. So what's going on here?
I also suspect del_route needs to be adjusted too, but I have no idea what's going on here.
Quoted 3 lines
I'd like to get to the bottom of this before applying this patch. When you submit a v2, please include your explanation as part of the commit message.
Sorry, I'm not very familiar with the Apple ecosystem and can't figure out what exactly happened or should be done here with the necessary confidence. Please just take this as a bug report.
Best regards,
Florian
Hi Florian,
Could you test this?
https://git.zx2c4.com/wireguard-tools/commit/?id=a998407747005ea7e4e0258d96f105c97241e1d3
Thanks,
Jason
Hi Jason,
Quoted 2 lines · Jason A. Donenfeld
Could you test this?
https://git.zx2c4.com/wireguard-tools/commit/?id=a998407747005ea7e4e0258d96f105c97241e1d3
Yes, it seems to work. I tested this commit and the previous one after connecting to another VPN (to lower MTU of the default interface to 1280) and got a MTUs of 1420 and 1200 respectively. Thanks!
Best regards,
Florian