Skip to contentSkip to conversation

wg-quick: fix darwin MTU detection

PATCH In review Florian Uekermann 2 participants 5 messages Feb 8 – May 8

lore
Share & tools
lore
#0 lore raw

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
index 1b7fe5e..0467f0e 100755
@@ -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
#1 lore raw

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
index 1b7fe5e..0467f0e 100755
@@ -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

#2 lore raw

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 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?

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