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
This commit is contained in:
Jose Diaz de Grenu de Pedro 2015-09-17 10:45:45 +02:00
parent 48f62a6e6b
commit 7d8955430a
4 changed files with 70 additions and 0 deletions

View File

@ -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

View File

@ -16,6 +16,7 @@ SRC_URI += "file://0001-del-baudrates.patch \
file://pswitch-press \ file://pswitch-press \
file://pswitch-release \ file://pswitch-release \
file://busybox-static-nodes \ file://busybox-static-nodes \
file://bridgeifupdown \
" "
# hwclock bootscript init parameters # hwclock bootscript init parameters
@ -64,4 +65,12 @@ do_install_append() {
if grep "CONFIG_MAKEDEVS=y" ${WORKDIR}/defconfig; then if grep "CONFIG_MAKEDEVS=y" ${WORKDIR}/defconfig; then
install -m 0755 ${WORKDIR}/busybox-static-nodes ${D}${sysconfdir}/init.d/ install -m 0755 ${WORKDIR}/busybox-static-nodes ${D}${sysconfdir}/init.d/
fi 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
} }

View File

@ -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

View File

@ -3,6 +3,7 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${BP}:" FILESEXTRAPATHS_prepend := "${THISDIR}/${BP}:"
SRC_URI_append = " \ SRC_URI_append = " \
file://interfaces.br0.example \
file://interfaces.eth0.static \ file://interfaces.eth0.static \
file://interfaces.eth0.dhcp \ file://interfaces.eth0.dhcp \
file://interfaces.eth1.static \ file://interfaces.eth1.static \
@ -24,6 +25,7 @@ do_install_append() {
cat ${WORKDIR}/interfaces.eth0.${ETH0_MODE} >> ${D}${sysconfdir}/network/interfaces 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_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 [ -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 # Remove config entries if corresponding variable is not defined
[ -z "${ETH0_STATIC_DNS}" ] && sed -i -e "/##ETH0_STATIC_DNS##/d" ${D}${sysconfdir}/network/interfaces [ -z "${ETH0_STATIC_DNS}" ] && sed -i -e "/##ETH0_STATIC_DNS##/d" ${D}${sysconfdir}/network/interfaces