From 50d67142c73288e7dcba9b56c866d608ac37d1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Fri, 25 Feb 2022 23:16:48 +0100 Subject: [PATCH 1/5] fff-network: Replace runtime configuration with reload_config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of both setting values in the uci configuration and applying them manually, only set the values in the uci configuration and do a combined reload_config afterward. This not only ensures that the changes to the configuration are actually correct, but also decreases the runtime of configurenetwork. Signed-off-by: Fabian Bläse Reviewed-by: Robert Langhammer --- .../files/usr/sbin/configurenetwork | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index 475b072d..e7601274 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -172,8 +172,6 @@ else fi fi -/etc/init.d/network restart - if [ -n "$ETHMESHMAC" ]; then if uci get network.ethmesh.macaddr then @@ -184,11 +182,6 @@ if [ -n "$ETHMESHMAC" ]; then uci set network.ethmesh.macaddr=$ETHMESHMAC uci commit network - - ifconfig $SWITCHDEV.3 down - ifconfig $SWITCHDEV.3 hw ether $ETHMESHMAC - ifconfig $SWITCHDEV.3 up - /etc/init.d/network restart fi fi @@ -202,11 +195,6 @@ if [ -n "$ROUTERMAC" ]; then uci set network.client.macaddr=$ROUTERMAC uci commit network - - ifconfig br-client down - ifconfig br-client hw ether $ROUTERMAC - ifconfig br-client up - /etc/init.d/network restart fi fi @@ -216,10 +204,6 @@ if [ -n "$ETH0MAC" ]; then NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address") uci set network.$ETH0DEV.macaddr=$NEW_MACADDR uci commit network - ifconfig $ETH0DEV down - ifconfig $ETH0DEV hw ether $NEW_MACADDR - ifconfig $ETH0DEV up - /etc/init.d/network restart fi if uci -q get "network.client.ip6addr" > /dev/null @@ -230,14 +214,9 @@ else # Some time needed :( sleep 5 - for ip in $(ip -6 addr show br-client | awk '/fdff/{ print $2 }'); do - ip -6 addr del $ip dev br-client - done - prefix="fdff::/64" # Set $prefix::MAC as IP addr=$(owipcalc "$prefix" add "::$(ipMacSuffix "$ROUTERMAC")") - ip -6 addr add $addr dev br-client uci -q set network.globals.ula_prefix=$prefix uci -q add_list network.client.ip6addr=$addr @@ -245,15 +224,15 @@ else # Set $prefix::1 as IP addr=$(owipcalc "$prefix" add ::1) - ip -6 addr add $addr dev br-client uci -q add_list network.client.ip6addr=$addr # Set $prefix::link-local as IP addr=$(owipcalc "$prefix" add "::$(ipEUISuffix "$ROUTERMAC")") - ip -6 addr add $addr dev br-client uci -q add_list network.client.ip6addr=$addr uci -q commit network [ -s /etc/init.d/fff-uradvd ] && /etc/init.d/fff-uradvd restart fi + +reload_config -- 2.39.2 From 1f0ec0be24a7968f5d98af297cd671b47ff22139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Fri, 25 Feb 2022 23:18:45 +0100 Subject: [PATCH 2/5] fff-network: Remove unnecessary restart of fff-uradvd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The explicit restat of fff-uradvd is not necessary anymore, as appropriate procd reload triggers have been added, and reload_config is executed after every run of configurenetwork. Signed-off-by: Fabian Bläse Reviewed-by: Robert Langhammer --- src/packages/fff/fff-network/files/usr/sbin/configurenetwork | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index e7601274..350f6cd7 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -231,8 +231,6 @@ else uci -q add_list network.client.ip6addr=$addr uci -q commit network - - [ -s /etc/init.d/fff-uradvd ] && /etc/init.d/fff-uradvd restart fi reload_config -- 2.39.2 From 3fb735cfdfdb654ab979267aeab307b27bbf8c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Sun, 8 Aug 2021 14:07:13 +0200 Subject: [PATCH 3/5] Remove static configuration from dynamic script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Robert Langhammer --- .../files/etc/uci-defaults/22-network-base | 141 ++++++++++++++++++ .../files/usr/sbin/configurenetwork | 119 --------------- 2 files changed, 141 insertions(+), 119 deletions(-) create mode 100644 src/packages/fff/fff-network/files/etc/uci-defaults/22-network-base diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22-network-base b/src/packages/fff/fff-network/files/etc/uci-defaults/22-network-base new file mode 100644 index 00000000..92f14c91 --- /dev/null +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22-network-base @@ -0,0 +1,141 @@ +#!/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 diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index 350f6cd7..12f66893 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -6,7 +6,6 @@ BOARD="$(uci get board.model.name)" . /etc/network.$BOARD -[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label) if [ -s /etc/network.config ] ; then . /etc/network.config @@ -103,97 +102,6 @@ elif [ "$TWO_PORT" = "YES" ]; then uci del network.$SWITCHDEV.macaddr fi - uci commit network - fi -else - if ! uci -q get network.$SWITCHDEV > /dev/null ; then - - 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=switch - uci set network.$SWITCHDEV.name=$SWITCHHW - uci set network.$SWITCHDEV.enable=1 - uci set network.$SWITCHDEV.reset=1 - uci set network.$SWITCHDEV.enable_vlan=1 - - 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 -fi - -if [ -n "$ETHMESHMAC" ]; then - if uci get network.ethmesh.macaddr - then - echo "MAC for ethmesh is set already" - else - echo "Fixing MAC on $SWITCHDEV.3 (ethmesh)" - sleep 10 - - uci set network.ethmesh.macaddr=$ETHMESHMAC - uci commit network - fi -fi - -if [ -n "$ROUTERMAC" ]; then - if uci get network.client.macaddr - then - echo "MAC for client is set already" - else - echo "Fixing MAC on br-client" - sleep 10 - - uci set network.client.macaddr=$ROUTERMAC uci commit network fi fi @@ -206,31 +114,4 @@ if [ -n "$ETH0MAC" ]; then uci commit network fi -if uci -q get "network.client.ip6addr" > /dev/null -then - echo "IPv6 for client is set already" -else - echo "Setting IPv6 addresses" - # Some time needed :( - sleep 5 - - prefix="fdff::/64" - # Set $prefix::MAC as IP - addr=$(owipcalc "$prefix" add "::$(ipMacSuffix "$ROUTERMAC")") - - uci -q set network.globals.ula_prefix=$prefix - uci -q add_list network.client.ip6addr=$addr - uci -q set network.client.proto=static - - # Set $prefix::1 as IP - addr=$(owipcalc "$prefix" add ::1) - uci -q add_list network.client.ip6addr=$addr - - # Set $prefix::link-local as IP - addr=$(owipcalc "$prefix" add "::$(ipEUISuffix "$ROUTERMAC")") - uci -q add_list network.client.ip6addr=$addr - - uci -q commit network -fi - reload_config -- 2.39.2 From 96c4c562cba9c18d46b7566b637d92f628ea5fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Thu, 3 Mar 2022 22:01:45 +0100 Subject: [PATCH 4/5] fff-network: Restore accidentally removed packet_steering option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the recent rework of the network configuration, any existing configuration is dropped in a uci-defaults script (22-network-base) and generated from scratch. When rebasing this rather old patchset, the packet_steering option was overlooked, so it is missing now. Restore the removed packet_steering option by setting it using a dedicated uci-defaults script. Signed-off-by: Fabian Bläse --- .../files/etc/uci-defaults/50-packet-steering | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/packages/fff/fff-network/files/etc/uci-defaults/50-packet-steering diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/50-packet-steering b/src/packages/fff/fff-network/files/etc/uci-defaults/50-packet-steering new file mode 100644 index 00000000..1427573d --- /dev/null +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/50-packet-steering @@ -0,0 +1,10 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-or-later + +# Enable RPS +uci batch <<-__EOF__ + set network.globals=globals + set network.globals.packet_steering='1' +__EOF__ + +uci -q commit network -- 2.39.2 From 07c5e90c583e7ad2638a93cb3d30aab9f914b5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Thu, 3 Mar 2022 22:01:11 +0100 Subject: [PATCH 5/5] fff-network: remove hardcoded network config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base network configuration has been completely migrated to uci-defaults scripts and any existing network configuration is dropped. Therefore, the hardcoded /etc/config/network configuration file is not required anymore. Remove it. Signed-off-by: Fabian Bläse --- .../fff/fff-network/files/etc/config/network | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 src/packages/fff/fff-network/files/etc/config/network diff --git a/src/packages/fff/fff-network/files/etc/config/network b/src/packages/fff/fff-network/files/etc/config/network deleted file mode 100644 index 7c88a17b..00000000 --- a/src/packages/fff/fff-network/files/etc/config/network +++ /dev/null @@ -1,30 +0,0 @@ -config globals 'globals' - option packet_steering '1' - -config interface 'loopback' - option ifname 'lo' - option proto 'static' - option ipaddr '127.0.0.1' - option netmask '255.0.0.0' - -config interface 'client' - option type 'bridge' - option auto '1' - -config interface 'wan' - option proto 'none' - option ifname 'eth2' - -config interface 'wan4' - option proto 'dhcp' - option ifname '@wan' - -config interface 'wan6' - option proto 'dhcpv6' - option reqprefix 'no' - option sourcefilter '0' - option ifname '@wan' - -config interface 'ethmesh' - option proto 'batadv_hardif' - option master 'bat0' -- 2.39.2