forked from freifunk-franken/firmware
148 lines
5.7 KiB
Bash
Executable File
148 lines
5.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
. /lib/functions/system.sh
|
|
. /lib/functions/fff/network
|
|
. /lib/functions/fff/cpuport
|
|
. /lib/functions/fff/interfaces
|
|
. /lib/functions/fff/switchports
|
|
|
|
# Add cpuport to switch configuration
|
|
CLIENT_PORTS="$(get_cpu_port) $CLIENT_PORTS"
|
|
BATMAN_PORTS="$(get_cpu_port) $BATMAN_PORTS"
|
|
[ -n "$WAN_PORTS" ] && WAN_PORTS="$(get_cpu_port) $WAN_PORTS"
|
|
|
|
if [ -s /etc/network.config ] ; then
|
|
. /etc/network.config
|
|
fi
|
|
|
|
if [ "$ONE_PORT" = "YES" ]; then
|
|
uci set network.$SWITCHDEV=interface
|
|
uci set network.$SWITCHDEV.ifname=$SWITCHDEV
|
|
if [ "$ETHMODE" = "WAN" ]; then
|
|
uci set network.client.ifname="bat0"
|
|
uci set network.wan.ifname="$WANDEV"
|
|
uci del network.ethmesh.ifname
|
|
uci del network.${SWITCHDEV}.macaddr
|
|
elif [ "$ETHMODE" = "CLIENT" ] ; then
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"
|
|
uci set network.wan.ifname="eth2" #eth2 because it is default in config file
|
|
uci del network.ethmesh.ifname
|
|
uci del network.${SWITCHDEV}.macaddr
|
|
elif [ "$ETHMODE" = "BATMAN" ] ; then
|
|
uci set network.client.ifname="bat0"
|
|
uci set network.wan.ifname="eth2" #eth2 because it is default in config file
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"
|
|
ETH0DEV="$SWITCHDEV"
|
|
fi
|
|
uci commit network
|
|
elif [ "$TWO_PORT" = "YES" ]; then
|
|
uci set network.$WANDEV=interface
|
|
uci set network.$WANDEV.ifname="$WANDEV"
|
|
uci set network.$SWITCHDEV=interface
|
|
uci set network.$SWITCHDEV.ifname="$SWITCHDEV"
|
|
# Only one WAN possible, second port will be unset if both are WAN
|
|
if [ "$LAN0MODE" = "WAN" ]; then
|
|
if [ "$LAN1MODE" = "CLIENT" ]; then
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"; else
|
|
uci set network.client.ifname=bat0; fi
|
|
# WAN
|
|
uci set network.wan.ifname="$WANDEV"
|
|
if [ "$LAN1MODE" = "BATMAN" ]; then
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"; else
|
|
uci del network.ethmesh.ifname; fi
|
|
# Two client ports are possible
|
|
elif [ "$LAN0MODE" = "CLIENT" ]; then
|
|
if [ "$LAN1MODE" = "CLIENT" ]; then
|
|
uci set network.client.ifname="bat0 $WANDEV $SWITCHDEV"; else
|
|
uci set network.client.ifname="bat0 $WANDEV"; fi
|
|
if [ "$LAN1MODE" = "WAN" ]; then
|
|
uci set network.wan.ifname="$SWITCHDEV"; else
|
|
uci set network.wan.ifname=eth2; fi #eth2 because it is default in config file
|
|
if [ "$LAN1MODE" = "BATMAN" ]; then
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"; else
|
|
uci del network.ethmesh.ifname; fi
|
|
# Only one BATMAN port possible, second port will be unset if both are BATMAN
|
|
elif [ "$LAN0MODE" = "BATMAN" ] ; then
|
|
if [ "$LAN1MODE" = "CLIENT" ]; then
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"; else
|
|
uci set network.client.ifname=bat0; fi
|
|
if [ "$LAN1MODE" = "WAN" ]; then
|
|
uci set network.wan.ifname="$SWITCHDEV"; else
|
|
uci set network.wan.ifname=eth2; fi #eth2 because it is default in config file
|
|
# BATMAN
|
|
uci set network.ethmesh.ifname="$WANDEV"
|
|
fi
|
|
if [ "$LAN0MODE" = "BATMAN" ]; then
|
|
ETH0DEV="$WANDEV" # only needed for setting macaddr
|
|
uci del network.$SWITCHDEV.macaddr
|
|
elif [ "$LAN1MODE" = "BATMAN" ]; then
|
|
# $WANDEV will win if both are set to BATMAN, as above
|
|
ETH0DEV="$SWITCHDEV" # only needed for setting macaddr
|
|
uci del network.$WANDEV.macaddr
|
|
else
|
|
uci del network.$WANDEV.macaddr
|
|
uci del network.$SWITCHDEV.macaddr
|
|
fi
|
|
|
|
uci commit network
|
|
else
|
|
if [ "$DSA" = "1" ]; then
|
|
uci set network.$SWITCHDEV=device
|
|
uci set network.$SWITCHDEV.name=$SWITCHDEV
|
|
uci set network.$SWITCHDEV.type=bridge
|
|
# temporary workaround for netifd bug present in OpenWrt 21.02.0 (FS#4104)
|
|
uci set network.$SWITCHDEV.bridge_empty='1'
|
|
|
|
uci set network.${SWITCHDEV}_1=bridge-vlan
|
|
uci set network.${SWITCHDEV}_1.device=$SWITCHDEV
|
|
uci set network.${SWITCHDEV}_1.vlan=1
|
|
uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS"
|
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$WAN_PORTS" ]; then
|
|
uci set network.${SWITCHDEV}_2=bridge-vlan
|
|
uci set network.${SWITCHDEV}_2.device=$SWITCHDEV
|
|
uci set network.${SWITCHDEV}_2.vlan=2
|
|
uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS"
|
|
fi
|
|
|
|
uci set network.${SWITCHDEV}_3=bridge-vlan
|
|
uci set network.${SWITCHDEV}_3.device=$SWITCHDEV
|
|
uci set network.${SWITCHDEV}_3.vlan=3
|
|
uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS"
|
|
else
|
|
SWITCHHW=$(swconfig list | awk '{ print $4 }')
|
|
|
|
uci set network.${SWITCHDEV}_1=switch_vlan
|
|
uci set network.${SWITCHDEV}_1.device=$SWITCHHW
|
|
uci set network.${SWITCHDEV}_1.vlan=1
|
|
uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS"
|
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ] || [ -n "$WAN_PORTS" ]; then
|
|
uci set network.${SWITCHDEV}_2=switch_vlan
|
|
uci set network.${SWITCHDEV}_2.device=$SWITCHHW
|
|
uci set network.${SWITCHDEV}_2.vlan=2
|
|
uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS"
|
|
fi
|
|
|
|
uci set network.${SWITCHDEV}_3=switch_vlan
|
|
uci set network.${SWITCHDEV}_3.device=$SWITCHHW
|
|
uci set network.${SWITCHDEV}_3.vlan=3
|
|
uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS"
|
|
fi
|
|
|
|
uci set network.client.ifname="$SWITCHDEV.1 bat0"
|
|
|
|
uci set network.ethmesh.ifname="$SWITCHDEV.3"
|
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ]; then
|
|
uci set network.wan.ifname=$WANDEV.2
|
|
else
|
|
uci set network.wan.ifname=$WANDEV
|
|
fi
|
|
|
|
uci commit network
|
|
fi
|
|
|
|
/etc/init.d/network restart
|