From 7d8955430af5f8ab0d06f16e43254f604cec7ae6 Mon Sep 17 00:00:00 2001 From: Jose Diaz de Grenu de Pedro Date: Thu, 17 Sep 2015 10:45:45 +0200 Subject: [PATCH] meta-digi-dey: Add bridging support. Add the networking configuration to support the creation of a bridge interface. Signed-off-by: Jose Diaz de Grenu de Pedro Jose.DiazdeGrenudePedro@digi.com --- .../busybox/busybox/bridgeifupdown | 52 +++++++++++++++++++ .../busybox/busybox_1.23.1.bbappend | 9 ++++ .../init-ifupdown-1.0/interfaces.br0.example | 7 +++ .../init-ifupdown/init-ifupdown_1.0.bbappend | 2 + 4 files changed, 70 insertions(+) create mode 100644 meta-digi-dey/recipes-core/busybox/busybox/bridgeifupdown create mode 100644 meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown-1.0/interfaces.br0.example diff --git a/meta-digi-dey/recipes-core/busybox/busybox/bridgeifupdown b/meta-digi-dey/recipes-core/busybox/busybox/bridgeifupdown new file mode 100644 index 000000000..9191224f8 --- /dev/null +++ b/meta-digi-dey/recipes-core/busybox/busybox/bridgeifupdown @@ -0,0 +1,52 @@ +#!/bin/sh +# Execute only if the interface has a bridge_ports property (this characterizes bridge interfaces) +case "$IF_BRIDGE_PORTS" in + "") + exit 0 + ;; + none) + INTERFACES="" + ;; + *) + INTERFACES="$IF_BRIDGE_PORTS" + ;; +esac + +if [ "$MODE" = "start" ] && [ ! -d /sys/class/net/$IFACE ]; then + # Create the bridge interface using brctl + brctl addbr $IFACE || exit 1 + + # Wait for wlan0 to be ready + sleep 0.5 + + # For all the interfaces in bridge ports, attach to the bridge and remove ip + for port in $INTERFACES; do + brctl addif $IFACE $port && ifconfig $port 0.0.0.0 up + done + + # Setup the bridge (only options supported by busybox) + [ -n "$IF_BRIDEG_AGEING" ] && brctl setageing $IFACE $IF_BRIDGE_AGEING + [ -n "$IF_BRIDGE_BRIDGEPRIO" ] && brctl setbridgeprio $IFACE $IF_BRIDGE_BRIDGEPRIO + [ -n "$IF_BRIDGE_FD" ] && brctl setfd $IFACE $IF_BRIDGE_FD + [ -n "$IF_BRIDGE_HELLO" ] && brctl sethello $IFACE $IF_BRIDGE_HELLO + [ -n "$IF_BRIDGE_MAXAGE" ] && brctl setmaxage $IFACE $IF_BRIDGE_MAXAGE + [ -n "$IF_BRIDGE_PATHCOST" ] && brctl setpathcost $IFACE $IF_BRIDGE_PATHCOST + [ -n "$IF_BRIDGE_PORTPRIO" ] && brctl setportprio $IFACE $IF_BRIDGE_PORTPRIO + [ -n "$IF_BRIDGE_STP" ] && brctl stp $IFACE $IF_BRIDGE_STP + + # Activate the bridge + ifconfig $IFACE 0.0.0.0 up + +elif [ "$MODE" = "stop" ]; then + # Bring down the interface + ifconfig $IFACE down || exit 1 + + # Remove port interfaces from the bridge + for port in $INTERFACES; do + ifconfig $port down && brctl delif $IFACE $port + done + + # Destroy the interface + brctl delbr $IFACE +fi + diff --git a/meta-digi-dey/recipes-core/busybox/busybox_1.23.1.bbappend b/meta-digi-dey/recipes-core/busybox/busybox_1.23.1.bbappend index c0d2d2f9e..674bf7e36 100644 --- a/meta-digi-dey/recipes-core/busybox/busybox_1.23.1.bbappend +++ b/meta-digi-dey/recipes-core/busybox/busybox_1.23.1.bbappend @@ -16,6 +16,7 @@ SRC_URI += "file://0001-del-baudrates.patch \ file://pswitch-press \ file://pswitch-release \ file://busybox-static-nodes \ + file://bridgeifupdown \ " # hwclock bootscript init parameters @@ -64,4 +65,12 @@ do_install_append() { if grep "CONFIG_MAKEDEVS=y" ${WORKDIR}/defconfig; then install -m 0755 ${WORKDIR}/busybox-static-nodes ${D}${sysconfdir}/init.d/ fi + + # Install bridgeifupdown script + if grep "CONFIG_BRCTL" ${WORKDIR}/defconfig; then + install -d ${D}${sysconfdir}/network/if-pre-up.d/ + install -d ${D}${sysconfdir}/network/if-post-down.d/ + install -m 0755 ${WORKDIR}/bridgeifupdown ${D}${sysconfdir}/network/if-pre-up.d/ + ln -s ../if-pre-up.d/bridgeifupdown ${D}${sysconfdir}/network/if-post-down.d/bridgeifupdown + fi } diff --git a/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown-1.0/interfaces.br0.example b/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown-1.0/interfaces.br0.example new file mode 100644 index 000000000..8340c5611 --- /dev/null +++ b/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown-1.0/interfaces.br0.example @@ -0,0 +1,7 @@ + +## Example bridge between eth0 and wlan0 +#auto br0 +#iface br0 inet static +# bridge_ports eth0 wlan0 +# address 192.168.42.50 +# netmask 255.255.255.0 diff --git a/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown_1.0.bbappend b/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown_1.0.bbappend index efccebaf2..452fdecc5 100644 --- a/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown_1.0.bbappend +++ b/meta-digi-dey/recipes-core/init-ifupdown/init-ifupdown_1.0.bbappend @@ -3,6 +3,7 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${BP}:" SRC_URI_append = " \ + file://interfaces.br0.example \ file://interfaces.eth0.static \ file://interfaces.eth0.dhcp \ file://interfaces.eth1.static \ @@ -24,6 +25,7 @@ do_install_append() { cat ${WORKDIR}/interfaces.eth0.${ETH0_MODE} >> ${D}${sysconfdir}/network/interfaces [ -n "${HAVE_EXT_ETH}" ] && cat ${WORKDIR}/interfaces.eth1.${ETH1_MODE} >> ${D}${sysconfdir}/network/interfaces [ -n "${HAVE_WIFI}" ] && cat ${WORKDIR}/interfaces.wlan0.${WLAN0_MODE} >> ${D}${sysconfdir}/network/interfaces + cat ${WORKDIR}/interfaces.br0.example >> ${D}${sysconfdir}/network/interfaces # Remove config entries if corresponding variable is not defined [ -z "${ETH0_STATIC_DNS}" ] && sed -i -e "/##ETH0_STATIC_DNS##/d" ${D}${sysconfdir}/network/interfaces