From df189a806bff76d27ee2e07c23ede78cb326f7f8 Mon Sep 17 00:00:00 2001 From: Bertrand Marquis Date: Fri, 27 Mar 2020 10:53:58 +0000 Subject: [PATCH] arm-autonomy: Create xenguest network bridge Add a xenguest-network-bridge script to create a network bridge with the host interfaces. Add a xenguest init script to create a xen network interface connected to the bridge Add a network interfaces configuration file to have dhcp configuration on the network bridge Add xenguest-network-bridge to the default host image Add XENGUEST_IMAGE_NETWORK_BRIDGE parameter to xenguest-image to let user setup if a guest should be or not connected to the bridge Change-Id: Id15fde234386376e89c2562e1ffa935c51affa5b Issue-Id: SCM-767 Signed-off-by: Bertrand Marquis Reviewed-by: Diego Sueiro Signed-off-by: Jon Mason --- meta-arm-autonomy/README.md | 5 ++ .../classes/xenguest-image.bbclass | 11 ++++ .../documentation/xenguest-network-bridge.md | 49 +++++++++++++++++ .../images/arm-autonomy-host-image-minimal.bb | 1 + .../xenguest/files/network-bridge.sh.in | 15 ++++++ .../files/xenguest-network-bridge-dhcp.cfg.in | 3 ++ .../xenguest/files/xenguest-network-bridge.in | 44 ++++++++++++++++ .../xenguest/xenguest-network-bridge.bb | 52 +++++++++++++++++++ .../xenguest/xenguest-network-bridge.bbappend | 2 + 9 files changed, 182 insertions(+) create mode 100644 meta-arm-autonomy/documentation/xenguest-network-bridge.md create mode 100755 meta-arm-autonomy/recipes-extended/xenguest/files/network-bridge.sh.in create mode 100644 meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge-dhcp.cfg.in create mode 100755 meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge.in create mode 100644 meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bb create mode 100644 meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bbappend diff --git a/meta-arm-autonomy/README.md b/meta-arm-autonomy/README.md index 93b57232..836d459a 100644 --- a/meta-arm-autonomy/README.md +++ b/meta-arm-autonomy/README.md @@ -42,6 +42,7 @@ its documentation. Those documentation files should be checked for variables: - [xen-devicetree](documentation/xen-devicetree.md) - [xenguest-manager](documentation/xenguest-manager.md) +- [xenguest-network-bridge](documentation/xenguest-network-bridge.md) BSPs ---- @@ -74,6 +75,10 @@ This layer is adding the following recipes and classes: * [xenguest-manager](documentation/xenguest-manager.md): this is a tool to create/remove/start/stop xen guest generated using xenguest-mkimage. +* [xenguest-network-bridge](documentation/xenguest-network-bridge.md): this + recipe add tools and init scripts to create a bridge connected to the + external network on the host and allow guests to be connected to it. + Contributing ------------ This project has not put in place a process for contributions currently. If you diff --git a/meta-arm-autonomy/classes/xenguest-image.bbclass b/meta-arm-autonomy/classes/xenguest-image.bbclass index fecf1ae7..b4d41222 100644 --- a/meta-arm-autonomy/classes/xenguest-image.bbclass +++ b/meta-arm-autonomy/classes/xenguest-image.bbclass @@ -61,6 +61,11 @@ XENGUEST_IMAGE_DISK_SIZE ??= "${@ '4' if not d.getVar('INITRAMFS_IMAGE') else '0 # and containing the root filesystem produced by Yocto XENGUEST_IMAGE_DISK_PARTITIONS ??= "1:${XENGUEST_IMAGE_DISK_SIZE}:ext4:rootfs.tar.gz" +# XENGUEST_IMAGE_NETWORK_BRIDGE can be set to 1 to have a network interface +# on the guest connected to host bridged network. This will provide the guest +# with a network interface connected directly to the external network +XENGUEST_IMAGE_NETWORK_BRIDGE ??= "1" + # Sub-directory in wich the guest is created. This is create in deploy as a # subdirectory and must be coherent between all components using this class so # it must only be modified from local.conf if needed @@ -144,6 +149,12 @@ xenguest_image_create() { else call_xenguest_mkimage update --set-param=GUEST_AUTOBOOT=0 fi + + if [ "${XENGUEST_IMAGE_NETWORK_BRIDGE}" = "1" ]; then + call_xenguest_mkimage update --set-param=NETWORK_BRIDGE=1 + else + call_xenguest_mkimage update --set-param=NETWORK_BRIDGE=0 + fi } # diff --git a/meta-arm-autonomy/documentation/xenguest-network-bridge.md b/meta-arm-autonomy/documentation/xenguest-network-bridge.md new file mode 100644 index 00000000..6653fe81 --- /dev/null +++ b/meta-arm-autonomy/documentation/xenguest-network-bridge.md @@ -0,0 +1,49 @@ +xenguest network bridge +======================= + +Introduction +------------ + +xenguest-network-bridge is creating a network bridge to allow some guests to +have a direct connection to the external network. +To do this, a bridge is created on the host using brctl with the network +interfaces added to it so that the bridge is connected to the external network. +It is also adding a guest init script which will, for guests configured to use +it, create a virtual network interface for the guest and connect it to the +network bridge on the host. + +Usage +----- + +On the host the package xenguest-network-bridge must be included in your image. + +On the xenguest image of your guest, the parameter NETWORK_BRIDGE must be set +to 1 (using xenguest-mkimage --set-param=NETWORK_BRIDGE=1). + +Bitbake parameters +------------------ +Several parameters are available to configure the xenguest network bridge +during Yocto project compilation (those can be set in your project local.conf, +for example). + +The following parameters are available: + +- XENGUEST_NETWORK_BRIDGE_NAME: This variable defines the name of the network + bridge that is created on the host during init. + This is set by default to "xenbr0". + +- XENGUEST_NETWORK_BRIDGE_MEMBERS: This variable defines the list of network + interfaces that are added to the bridge when it is created on the host during + init. + This is set by default to "eth0". + +- XENGUEST_NETWORK_BRIDGE_CONFIG: This variable defines the configuration file + to use to configure the bridge network. By default it points to have file + configuring the network using dhcp. + You can provide a different file using a bbappend and make this variable + point to it if you want to customize your network configuration. + +- XENGUEST_IMAGE_NETWORK_BRIDGE: This variable can be set to 0 or 1 on guest + projects to enable or not the connection of the guest to the host bridge. + This is set by default to "1". + diff --git a/meta-arm-autonomy/recipes-core/images/arm-autonomy-host-image-minimal.bb b/meta-arm-autonomy/recipes-core/images/arm-autonomy-host-image-minimal.bb index ffe5bce4..10c6e4b1 100644 --- a/meta-arm-autonomy/recipes-core/images/arm-autonomy-host-image-minimal.bb +++ b/meta-arm-autonomy/recipes-core/images/arm-autonomy-host-image-minimal.bb @@ -17,6 +17,7 @@ IMAGE_INSTALL += " \ xen-base \ qemu \ xenguest-manager \ + xenguest-network-bridge \ " # Build xen-devicetree to produce a xen ready devicetree diff --git a/meta-arm-autonomy/recipes-extended/xenguest/files/network-bridge.sh.in b/meta-arm-autonomy/recipes-extended/xenguest/files/network-bridge.sh.in new file mode 100755 index 00000000..2a360964 --- /dev/null +++ b/meta-arm-autonomy/recipes-extended/xenguest/files/network-bridge.sh.in @@ -0,0 +1,15 @@ +#!/bin/sh +# This script is setting up a virtual network interface connected to the +# xenguest-network-bridge if NETWORK_BRIDGE is set to 1 in the guest params + +guestname="${1}" + +BRIDGE_NAME="###BRIDGE_NAME###" + +# get guest parameters +. ./params.cfg + +if [ "${NETWORK_BRIDGE:-}" = "1" ]; then + echo "vif = ['${BRIDGE_NAME}']" >> ${guestname}.cfg +fi + diff --git a/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge-dhcp.cfg.in b/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge-dhcp.cfg.in new file mode 100644 index 00000000..6e063793 --- /dev/null +++ b/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge-dhcp.cfg.in @@ -0,0 +1,3 @@ +# Xenguest Network Bridge interface configuration +auto ###BRIDGE_NAME### +iface ###BRIDGE_NAME### inet dhcp diff --git a/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge.in b/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge.in new file mode 100755 index 00000000..2278b80c --- /dev/null +++ b/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge.in @@ -0,0 +1,44 @@ +#!/bin/sh +# +# Xenguest Network Bridge init +# This script creates a network bridge and add host interfaces to it +# It will then be used by xen guests to connect to the external nework +# + +INTFS="###BRIDGE_MEMBERS###" +BR_INTF="###BRIDGE_NAME###" + +case "$1" in + start) + echo "Starting $BR_INTF" + brctl addbr $BR_INTF + for intf in $INTFS; do + echo "Adding $intf to $BR_INTF" + brctl addif $BR_INTF $intf + done + ;; + status) + true + ;; + stop) + echo "Stopping $BR_INTF" + ifdown $BR_INTF + brctl delbr $BR_INTF + ;; + reload) + echo >&2 'Reload not available; use force-reload'; exit 1 + ;; + force-reload|restart) + echo "Restarting host-bridge" + $0 stop + $0 start + ;; + *) + # do not advertise unreasonable commands that there is no reason + # to use with this device + echo $"Usage: $0 {start|stop|status|restart|force-reload}" + exit 1 +esac + +exit $? + diff --git a/meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bb b/meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bb new file mode 100644 index 00000000..babd694d --- /dev/null +++ b/meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bb @@ -0,0 +1,52 @@ +# Recipe to handle xenguest network configuration +DESCRIPTION = "XenGuest Network Bridge" + +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +S = "${WORKDIR}" + +# Please refer to documentation/xenguest-network-bridge.md for documentation on +# those parameters +XENGUEST_NETWORK_BRIDGE_NAME ?= "xenbr0" +XENGUEST_NETWORK_BRIDGE_MEMBERS ?= "eth0" +XENGUEST_NETWORK_BRIDGE_CONFIG ?= "xenguest-network-bridge-dhcp.cfg.in" + +SRC_URI = " \ + file://xenguest-network-bridge.in \ + file://xenguest-network-bridge-dhcp.cfg.in \ + file://network-bridge.sh.in \ + " + +# Bridge configurator needs to run before S01networking init script +# Prefix with a_ to make sure it is executed in runlevel 01 before others +INITSCRIPT_NAME = "a_xenguest-network-bridge" +INITSCRIPT_PARAMS = "defaults 01" + +inherit update-rc.d + +do_install() { + cat ${WORKDIR}/xenguest-network-bridge.in \ + | sed -e "s,###BRIDGE_MEMBERS###,${XENGUEST_NETWORK_BRIDGE_MEMBERS}," \ + | sed -e "s,###BRIDGE_NAME###,${XENGUEST_NETWORK_BRIDGE_NAME}," \ + > ${WORKDIR}/xenguest-network-bridge + cat ${WORKDIR}/${XENGUEST_NETWORK_BRIDGE_CONFIG} \ + | sed -e "s,###BRIDGE_NAME###,${XENGUEST_NETWORK_BRIDGE_NAME}," \ + > ${WORKDIR}/xenguest-network-bridge.cfg + cat ${WORKDIR}/network-bridge.sh.in \ + | sed -e "s,###BRIDGE_NAME###,${XENGUEST_NETWORK_BRIDGE_NAME}," \ + > ${WORKDIR}/network-bridge.sh + install -d -m 755 ${D}${sysconfdir}/init.d + install -m 755 ${WORKDIR}/xenguest-network-bridge \ + ${D}${sysconfdir}/init.d/${INITSCRIPT_NAME} + install -d -m 755 ${D}${sysconfdir}/network/interfaces.d + install -m 755 ${WORKDIR}/xenguest-network-bridge.cfg \ + ${D}${sysconfdir}/network/interfaces.d/. + install -d -m 755 ${D}${sysconfdir}/xenguest/init.pre + install -m 755 ${WORKDIR}/network-bridge.sh \ + ${D}${sysconfdir}/xenguest/init.pre/. +} + +RDEPENDS_${PN} += "bridge-utils" +FILES_${PN} += "${sysconfdir}/network/interfaces.d/xenguest-network-bridge.cfg" +FILES_${PN} += "${sysconfdir}/xenguest/init.pre/network-bridge.sh" diff --git a/meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bbappend b/meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bbappend new file mode 100644 index 00000000..dc849210 --- /dev/null +++ b/meta-arm-autonomy/recipes-extended/xenguest/xenguest-network-bridge.bbappend @@ -0,0 +1,2 @@ +# Juno board has 2 network interfaces, add both of them to the bridge +XENGUEST_NETWORK_BRIDGE_MEMBERS_juno ?= "eth0 eth1"