From: M P Robert <mprobert@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: wg-quick set_mtu_up - largest or smallest MTU?
Date: Fri, 3 Nov 2023 13:12:22 +0000 [thread overview]
Message-ID: <81DE093A-5905-49CA-A412-5F934E0E0EBB@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]
I was looking at the auto MTU detection in wg-quick.
It appears that wg-quick is taking the LARGEST of all endpoint MTUs
https://github.com/WireGuard/wireguard-tools/blob/13f4ac4cb74b5a833fa7f825ba785b1e5774e84f/src/wg-quick/linux.bash#L134
In a scenario where you have different peers on different network devices or routes with different MTUs, I would think you would want to take the SMALLEST mtu from all peers in order to avoid having fragmentation talking to the peers on networks with smaller MTUs.
Or perhaps fragmentation for some peers is faster than selecting a smaller packet size for all peers? Or I am missing something (more likely). Happy to be educated on this point.
I don't have git-send-email setup at this point, but just in case this is a valid issue, I've attached a sample fix for set_mtu_up that will take the smallest of the discovered peer MTUs rather than the largest. I'm not a bash guy, so just take it for illustration purposes.
Thanks!
-Matt
[-- Attachment #2: wg-quick.set_mtu_up.sh --]
[-- Type: application/octet-stream, Size: 912 bytes --]
set_mtu_up() {
local mtu=0 mtufound=0 endpoint output
if [[ -n $MTU ]]; then
cmd ip link set mtu "$MTU" up dev "$INTERFACE"
return
fi
while read -r _ endpoint; do
[[ $endpoint =~ ^\[?([a-z0-9:.]+)\]?:[0-9]+$ ]] || continue
output="$(ip route get "${BASH_REMATCH[1]}" || true)"
[[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ( $mtufound -eq 0 || ${BASH_REMATCH[1]} -lt $mtu ) ]] && mtu="${BASH_REMATCH[1]}" && mtufound=1
done < <(wg show "$INTERFACE" endpoints)
if [[ $mtufound -eq 0 ]]; then
read -r output < <(ip route show default || true) || true
[[ $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ]] && mtu="${BASH_REMATCH[1]}" && mtufound=1
fi
[[ $mtufound -eq 1 ]] || mtu=1500
cmd ip link set mtu $(( mtu - 80 )) up dev "$INTERFACE"
}
[-- Attachment #3: Type: text/plain, Size: 2 bytes --]
next reply other threads:[~2023-11-19 13:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 13:12 M P Robert [this message]
2023-11-19 14:41 ` Daniel Gröber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81DE093A-5905-49CA-A412-5F934E0E0EBB@gmail.com \
--to=mprobert@gmail.com \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).