From d7a2d1b7ab94f7ac8e882ab66810d80e686cb62c Mon Sep 17 00:00:00 2001 From: Christopher Clark Date: Wed, 27 Apr 2022 17:06:09 -0700 Subject: xen images, qemuboot: configure xenbr0 bridge for runqemu, testimage Networking for Xen guest virtual machines is commonly configured via bridging in the host system between a physical interface and the guest virtual interfaces. To make it easier to test networking and use testimage with Xen guest virtual machines, extend the bbclass that provides network configuration for qemu machines for the Xen images to configure a Xen bridge and put eth0 onto it when QB_XEN_HOST_BRIDGE is set. Signed-off-by: Christopher Clark Signed-off-by: Bruce Ashfield --- classes/qemuboot-testimage-network.bbclass | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'classes/qemuboot-testimage-network.bbclass') diff --git a/classes/qemuboot-testimage-network.bbclass b/classes/qemuboot-testimage-network.bbclass index 18af1eea..57e03551 100644 --- a/classes/qemuboot-testimage-network.bbclass +++ b/classes/qemuboot-testimage-network.bbclass @@ -1,17 +1,51 @@ # The recipe for init-ifupdown in core has a special-case for all # the Qemu MACHINES: it removes all external network interfaces # by default. However, eth0 is needed for testimage, so enable it here. + +# If QB_NETWORK_XEN_BRIDGE is set, configure bridging for the network. +QB_NETWORK_XEN_BRIDGE ??= "" + enable_runqemu_network() { : # no-op for non-qemu MACHINES } + enable_runqemu_network:qemuall() { + # Do not override a network configuration for eth0 if one is present if ! grep -q eth0 "${IMAGE_ROOTFS}${sysconfdir}/network/interfaces" ; then - cat <>${IMAGE_ROOTFS}${sysconfdir}/network/interfaces + + # Xen host networking: use bridging to support guest networks + if [ -n "${QB_NETWORK_XEN_BRIDGE}" ] ; then + # Configure a Xen host network bridge and put eth0 on it + cat <>${IMAGE_ROOTFS}${sysconfdir}/network/interfaces + +# Bridged host network for Xen testimage +iface eth0 inet manual + +auto xenbr0 +iface xenbr0 inet dhcp + bridge_ports eth0 +EOF + +# Add a script to create the bridge and add eth0 if necessary + cat <>${IMAGE_ROOTFS}${sysconfdir}/network/if-pre-up.d/xenbr0 +#!/bin/sh + +if [ "\$IFACE" = xenbr0 ]; then + brctl addbr xenbr0 || /bin/true + brctl addif xenbr0 eth0 || /bin/true + ifconfig eth0 up +fi +EOF + chmod 755 ${IMAGE_ROOTFS}${sysconfdir}/network/if-pre-up.d/xenbr0 + else + # Just configure eth0 + cat <>${IMAGE_ROOTFS}${sysconfdir}/network/interfaces # Network for testimage auto eth0 iface eth0 inet dhcp EOF + fi fi } ROOTFS_POSTPROCESS_COMMAND += 'enable_runqemu_network;' -- cgit v1.2.3-54-g00ecf