Question
Is it possible to get QEMU to use a named Docker interface and network on the same host machine?
Motivating exmaple:
Let's say I have a DHCP server in a Docker container with static IP running as follows:
pxe_1 | Interface: eth0
pxe_1 | IP: 172.16.100.11
pxe_1 | Subnet: 172.16.100
pxe_1 | Starting PXE server...
...
The Docker (compose) DHCP server is in its own network on the same host with a named interface pxe0:
networks:
pxenet:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.100.0/24
gateway: 172.16.100.1
driver_opts:
com.docker.network.bridge.name: pxe0
Say I want to run a bootloader in QEMU and have the DHCP broadcasts reach the above Docker container. This is my command:
qemu-system-aarch64 \
-serial stdio \
-machine virt,gic-version=3 \
-cpu cortex-a53 \
-m 256M \
-smp 4 \
-bios u-boot.bin
The bootloader startup then looks like this:
U-Boot 2021.01-rc1-g896cc5aa (Nov 06 2020 - 23:33:35 -0800)
...
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (2 ms)
Using virtio-net#32 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
...
The packets from QEMU VM are not reaching the Docker container on the same host.
What network/nic/net QEMU settings are needed for the QEMU VM to be on the same custom Docker network (not using a bridge on the host)?
I'm thinking along the lines of something like this,
-netdev tap,id=pxe0,ifname=pxe0,script=no,downscript=no \
-device e1000,netdev=pxe0,mac=52:55:00:d1:55:01
but fails with
qemu-system-aarch64: could not configure /dev/net/tun (pxe0): Invalid argument
even though ip a reveals
477: pxe0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:8f:81:41:e3 brd ff:ff:ff:ff:ff:ff
inet 172.16.100.1/24 brd 172.16.100.255 scope global pxe0
valid_lft forever preferred_lft forever
inet6 fe80::42:8fff:fe81:41e3/64 scope link
valid_lft forever preferred_lft forever