mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
qemu: Homogenize network setup
- Always respect the requested model to emulate. Before this change, a device configured to run in TAP mode would ignore a user's requested model and always emulate a e1000. This worked on x86_64 where that driver is part of the kernel, but that is not true for aarch64. - Always supply a mactab. It was very confusing that the interface names would change, in Infix, depending on the selected networking mode. - Remove old decoy variables that were assigned but never used anywhere. - Separately setup the host and target side of a nic (i.e. use a -netdev/-device pair instead of the -nic shortcut). This lets us share the host side setup across all modes.
This commit is contained in:
committed by
Joachim Wiberg
parent
9e5904936a
commit
f660f6e9c7
@@ -136,7 +136,7 @@ endchoice
|
||||
|
||||
config QEMU_NET_MODEL
|
||||
string "Interface model"
|
||||
default "virtio"
|
||||
default "virtio-net-pci"
|
||||
|
||||
config QEMU_NET_BRIDGE_DEV
|
||||
string "Bridge device"
|
||||
|
||||
+21
-11
@@ -157,26 +157,36 @@ host_args()
|
||||
echo -n "-virtfs local,path=$CONFIG_QEMU_HOST,security_model=none,writeout=immediate,mount_tag=hostfs "
|
||||
}
|
||||
|
||||
net_dev_args()
|
||||
{
|
||||
local name="e$1"
|
||||
local mac=$(printf "02:00:00:00:00:%02x" $1)
|
||||
|
||||
echo -n "-device $CONFIG_QEMU_NET_MODEL,netdev=$name,mac=$mac "
|
||||
echo "$name $mac" >>"$mactab"
|
||||
}
|
||||
|
||||
net_args()
|
||||
{
|
||||
QEMU_NET_MODEL=${QEMU_NET_MODEL:-virtio}
|
||||
# Infix will pick up this file via fwcfg and install it to /etc
|
||||
mactab=$(dirname "$CONFIG_QEMU_ROOTFS")/mactab
|
||||
:> "$mactab"
|
||||
echo -n "-fw_cfg name=opt/mactab,file=$mactab "
|
||||
|
||||
if [ "$CONFIG_QEMU_NET_BRIDGE" = "y" ]; then
|
||||
QEMU_NET_BRIDGE_DEV=${QEMU_NET_BRIDGE_DEV:-virbr0}
|
||||
echo -n "-nic bridge,br=$CONFIG_QEMU_NET_BRIDGE_DEV,model=$CONFIG_QEMU_NET_MODEL "
|
||||
echo -n "-netdev bridge,id=e0,br=$CONFIG_QEMU_NET_BRIDGE_DEV "
|
||||
net_dev_args 0
|
||||
elif [ "$CONFIG_QEMU_NET_TAP" = "y" ]; then
|
||||
QEMU_NET_TAP_N=${QEMU_NET_TAP_N:-1}
|
||||
mactab=$(dirname "$CONFIG_QEMU_ROOTFS")/mactab
|
||||
rm -f "$mactab"
|
||||
for i in $(seq 0 $(($CONFIG_QEMU_NET_TAP_N - 1))); do
|
||||
printf "e$i 52:54:00:12:34:%02x\n" $((0x56 + i)) >>"$mactab"
|
||||
echo -n "-netdev tap,id=nd$i,ifname=qtap$i -device e1000,netdev=nd$i "
|
||||
echo -n "-netdev tap,id=e$i,ifname=qtap$i "
|
||||
net_dev_args $i
|
||||
done
|
||||
echo -n "-fw_cfg name=opt/mactab,file=$mactab "
|
||||
elif [ "$CONFIG_QEMU_NET_USER" = "y" ]; then
|
||||
[ "$CONFIG_QEMU_NET_USER_OPTS" ] && QEMU_NET_USER_OPTS="$CONFIG_QEMU_NET_USER_OPTS,"
|
||||
local useropts=
|
||||
[ "$CONFIG_QEMU_NET_USER_OPTS" ] && useropts=",$CONFIG_QEMU_NET_USER_OPTS"
|
||||
|
||||
echo -n "-nic user,${QEMU_NET_USER_OPTS}model=$CONFIG_QEMU_NET_MODEL "
|
||||
echo -n "-netdev user,id=e0${useropts} "
|
||||
net_dev_args 0
|
||||
else
|
||||
echo -n "-nic none"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user