forked from freifunk-franken/firmware
Most of the configuration done in configurenetwork is static and does not change after the first boot. Move this static configuration into a uci-defaults script, which is only executed on first boot. Configuration which might be changed at runtime (e.g. port assignment), is kept in the configurenetwork script. To improve readability and speed, combine multiple uci commands into a uci batch. Drop any existing network configuration before applying our own configuration. This requires the network.globals section to be created explicitly. Also, the fdff:: addresses, ETHMESHMAC and ROUTERMAC can be set unconditionally, as the uci-defaults script is only executed once. Other than that, the static configuration has not been altered. Signed-off-by: Fabian Bläse <fabian@blaese.de> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
142 lines
3.8 KiB
Bash
142 lines
3.8 KiB
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
. /lib/functions/system.sh
|
|
. /lib/functions/fff/network
|
|
|
|
BOARD="$(uci get board.model.name)"
|
|
. /etc/network.$BOARD
|
|
|
|
[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label)
|
|
|
|
# Clear possibly existing network configuration
|
|
> /etc/config/network
|
|
|
|
# Add basic network configuration
|
|
uci batch <<-__EOF__
|
|
set network.loopback='interface'
|
|
set network.loopback.ifname='lo'
|
|
set network.loopback.proto='static'
|
|
set network.loopback.ipaddr='127.0.0.1'
|
|
set network.loopback.netmask='255.0.0.0'
|
|
|
|
set network.client='interface'
|
|
set network.client.type='bridge'
|
|
set network.client.auto='1'
|
|
|
|
set network.wan='interface'
|
|
set network.wan.proto='none'
|
|
set network.wan.ifname="$WANDEV"
|
|
|
|
set network.wan4='interface'
|
|
set network.wan4.proto='dhcp'
|
|
set network.wan4.ifname='@wan'
|
|
|
|
set network.wan6='interface'
|
|
set network.wan6.proto='dhcpv6'
|
|
set network.wan6.reqprefix='no'
|
|
set network.wan6.sourcefilter='0'
|
|
set network.wan6.ifname='@wan'
|
|
|
|
set network.ethmesh='interface'
|
|
set network.ethmesh.proto='batadv_hardif'
|
|
set network.ethmesh.master='bat0'
|
|
__EOF__
|
|
|
|
SWITCHHW=$(swconfig list | awk '{ print $4 }')
|
|
if [ "$DSA" = "1" ]; then
|
|
uci batch <<-__EOF__
|
|
set network.$SWITCHDEV=device
|
|
set network.$SWITCHDEV.name=$SWITCHDEV
|
|
set network.$SWITCHDEV.type=bridge
|
|
# temporary workaround for netifd bug present in OpenWrt 21.02.0 (FS#4104)
|
|
set network.$SWITCHDEV.bridge_empty='1'
|
|
|
|
set network.${SWITCHDEV}_1=bridge-vlan
|
|
set network.${SWITCHDEV}_1.device=$SWITCHDEV
|
|
set network.${SWITCHDEV}_1.vlan=1
|
|
set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS"
|
|
|
|
set network.${SWITCHDEV}_3=bridge-vlan
|
|
set network.${SWITCHDEV}_3.device=$SWITCHDEV
|
|
set network.${SWITCHDEV}_3.vlan=3
|
|
set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS"
|
|
__EOF__
|
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$WAN_PORTS" ]; then
|
|
uci batch <<-__EOF__
|
|
set network.${SWITCHDEV}_2=bridge-vlan
|
|
set network.${SWITCHDEV}_2.device=$SWITCHDEV
|
|
set network.${SWITCHDEV}_2.vlan=2
|
|
set network.${SWITCHDEV}_2.ports="$WAN_PORTS"
|
|
__EOF__
|
|
fi
|
|
elif [ -n "$SWITCHHW" ]; then
|
|
uci batch <<-__EOF__
|
|
set network.$SWITCHDEV=switch
|
|
set network.$SWITCHDEV.name=$SWITCHHW
|
|
set network.$SWITCHDEV.enable=1
|
|
set network.$SWITCHDEV.reset=1
|
|
set network.$SWITCHDEV.enable_vlan=1
|
|
|
|
set network.${SWITCHDEV}_1=switch_vlan
|
|
set network.${SWITCHDEV}_1.device=$SWITCHHW
|
|
set network.${SWITCHDEV}_1.vlan=1
|
|
set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS"
|
|
|
|
set network.${SWITCHDEV}_3=switch_vlan
|
|
set network.${SWITCHDEV}_3.device=$SWITCHHW
|
|
set network.${SWITCHDEV}_3.vlan=3
|
|
set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS"
|
|
__EOF__
|
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ] || [ -n "$WAN_PORTS" ]; then
|
|
uci batch <<-__EOF__
|
|
set network.${SWITCHDEV}_2=switch_vlan
|
|
set network.${SWITCHDEV}_2.device=$SWITCHHW
|
|
set network.${SWITCHDEV}_2.vlan=2
|
|
set network.${SWITCHDEV}_2.ports="$WAN_PORTS"
|
|
__EOF__
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$SWITCHHW" ] || [ "$DSA" = "1" ]; then
|
|
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
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$ETHMESHMAC" ]; then
|
|
uci set network.ethmesh.macaddr=$ETHMESHMAC
|
|
fi
|
|
|
|
if [ -n "$ROUTERMAC" ]; then
|
|
uci set network.client.macaddr=$ROUTERMAC
|
|
fi
|
|
|
|
|
|
prefix="fdff::/64"
|
|
|
|
# Set $prefix::1 as IP
|
|
addr1=$(owipcalc "$prefix" add ::1)
|
|
# Set $prefix::MAC as IP
|
|
addr2=$(owipcalc "$prefix" add "::$(ipMacSuffix "$ROUTERMAC")")
|
|
# Set $prefix::EUI64 as IP
|
|
addr3=$(owipcalc "$prefix" add "::$(ipEUISuffix "$ROUTERMAC")")
|
|
|
|
uci batch <<-__EOF__
|
|
del network.globals
|
|
set network.globals=globals
|
|
set network.globals.ula_prefix=$prefix
|
|
add_list network.client.ip6addr=$addr1
|
|
add_list network.client.ip6addr=$addr2
|
|
add_list network.client.ip6addr=$addr3
|
|
set network.client.proto=static
|
|
__EOF__
|
|
|
|
|
|
uci -q commit network
|