Last active
March 11, 2024 12:48
-
-
Save zigelboim-misha/5ab773db45d90304e88d1ab3a0150e0a to your computer and use it in GitHub Desktop.
Changing the default MTU on a MacOS Docker Desktop to allow Linking XDP eBPF programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mtu": 1500 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could not attach XDP program: create link: numerical result out of range
The error from the title occurred while trying to link an
ebpf
program to the kernelsXDP
on my MacOS from inside a docker container.Here is the source code - https://github.com/cilium/ebpf/blob/main/examples/xdp/main.go
It's from ciliums example repository.
Running The eBPF Program
I have this
clang
file this I want to link onto my kernel:This should count how many packets each protocol had up to this moment. To compile it we use
go generate
. It then generates some.o
and.go
files that ourGolang
program can use.The following
Golang
file loads theclang
onto the kernel:By running
go build
we create the executable, that we will run to run ourebpf
program.The Problem
When I tried running the executable with the network interface
eth0
I received the following error:Me and my co-founders thought it's connected to the network interface
eth0
but did not have a clue on how to check it.Maybe MacOS has problems with
eth0
anden0
or something similar as usinglo
instead ofeth0
worked as planned.Fix
After chatting with 2 nice guys on
ebpf
s slack - here is a link to the full discussion https://cilium.slack.com/archives/C4XCTGYEM/p1710150479896969We understood that's the problem is the
MTU
on my host machine (my new MacBook 14 Pro M2 Pro), the MacOSs defaultMTU
value is too big:I had to change the default value for
com.docker.network.driver.mtu
from65535
to1500
:Now it looks like this:
And I can count the packets:
References