Following this guide to setup a macvtap
works great.
An excerpt from the guide loosk like this:
# ip link add link eth1 name macvtap0 type macvtap
# ip link set macvtap0 address 1a:46:0b:ca:bc:7b up
# ip link show macvtap0
The guide then goes on to explain that you can do:
#qemu-system-x86_64 -net nic,model=virtio,addr=1a:46:0b:ca:bc:7b -net tap,fd=3 3<>/dev/tap11
And that works great, if your macvtap
ends up on /dev/tap11
.
But how do you check which /dev/tapX
interface actually got assigned to the macvtap0
above?
I have quite a lot of services setting up tap devices on my machine at random times. And I can't guess which one my specific one ended up on.
I was hoping that booting the qemu machine with:
-netdev tap,ifname="macvtap0",id=network0,script=no,downscript=no \
-device i82559b,netdev=network0,mac=${MAC}
Would work, where macvtap0
is the device I've just created.
However, that gives me:
qemu-system-x86_64: could not configure /dev/net/tun (macvtap0): Invalid argument
Outlined in this article: How to find the connection between tap interface and its file descriptor? - they describe a way to do it by accessing the PID and check associated file descriptors, problem here for me is that qemu isn't setting up the device, I am. And there's no PID associated with it.
Sow how can I get the file-handle under /dev
associated with the newly created macvtap
interface?
Edit: I'm already a few days in on this problem, but I just realised that I forgot to check /sys/class/net/macvtap0/
, and there is a /tap2
device. Obivously I need to iterate through all the contents still to find a name matching regex(tap[0-9]+)
. This will work, but not sure it's the best/correct way to do this.