Message ID | 20180807102507.4264-2-freifunk@adrianschmutzler.de |
---|---|
State | Superseded |
Headers | show |
diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index 980800ae..beb425e9 100644 --- a/src/packages/fff/fff-network/Makefile +++ b/src/packages/fff/fff-network/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-network -PKG_VERSION:=10 +PKG_VERSION:=11 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index 9dc29da1..a0acbcd4 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -104,97 +104,87 @@ if [ -n "$LAN1PORT" ] ; then setupPorts "$LAN1PORT" "${LAN1MODE}" fi -if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then - - 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" ] || ! [ -z "$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" - - enableAutoConf "$WANDEV.2" - else - enableAutoConf "$WANDEV" - 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" - - uci set network.mesh.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 - -if [ "$ONE_PORT" = "YES" ] && ( ! uci -q get network.$SWITCHDEV.ifname || [ "$FORCEPARSE" = '1' ] ) ; then - uci set network.$SWITCHDEV=interface - uci set network.$SWITCHDEV.ifname=$SWITCHDEV - if [ "$ETHMODE" = "WAN" ]; then - enableAutoConf "$WANDEV" - uci set network.mesh.ifname="bat0" - uci set network.wan.ifname="$WANDEV" - uci del uci set network.ethmesh.ifname - uci del network.eth0.macaddr - elif [ "$ETHMODE" = "CLIENT" ] ; then - disableAutoConf "$WANDEV" - uci set network.mesh.ifname="bat0 $SWITCHDEV" - uci set network.wan.ifname="eth1" #eth1 because it is default in config file - uci del network.ethmesh.ifname - uci del network.eth0.macaddr - elif [ "$ETHMODE" = "BATMAN" ] ; then - disableAutoConf "$WANDEV" - uci set network.mesh.ifname="bat0" - uci set network.wan.ifname="eth1" #eth1 because it is default in config file - uci set network.ethmesh.ifname="$SWITCHDEV" - ETH0MAC="w2ap" - fi - uci commit network +if [ "$ONE_PORT" = "YES" ] ; then + if ! uci -q get "network.$SWITCHDEV.ifname" || [ "$FORCEPARSE" = '1' ] ; then + uci set "network.$SWITCHDEV=interface" + uci set "network.$SWITCHDEV.ifname=$SWITCHDEV" + if [ "$ETHMODE" = "WAN" ]; then + enableAutoConf "$WANDEV" + uci set network.mesh.ifname="bat0" + uci set network.wan.ifname="$WANDEV" + uci del network.ethmesh.ifname + uci del network.eth0.macaddr + elif [ "$ETHMODE" = "CLIENT" ] ; then + disableAutoConf "$WANDEV" + uci set network.mesh.ifname="bat0 $SWITCHDEV" + uci set network.wan.ifname="eth1" #eth1 because it is default in config file + uci del network.ethmesh.ifname + uci del network.eth0.macaddr + else # default=BATMAN + disableAutoConf "$WANDEV" + uci set network.mesh.ifname="bat0" + uci set network.wan.ifname="eth1" #eth1 because it is default in config file + uci set network.ethmesh.ifname="$SWITCHDEV" + ETHMESHMAC="$(macFlipLocalBit "$ROUTERMAC")" + ETHMESHDEV="$SWITCHDEV" + fi + uci -q commit network + fi +else + if ! uci -q get "network.$SWITCHDEV" > /dev/null || [ "$FORCEPARSE" = '1' ] ; then + 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" + + # This defines the VLAN for WAN ports inside the switch. + # This is required even if the WAN eth is separate, but the WAN port is in the switch! + 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 + + ETHMESHDEV="$SWITCHDEV.3" + 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" + + uci set network.mesh.ifname="$SWITCHDEV.1 bat0" + uci set network.ethmesh.ifname="$ETHMESHDEV" + + # This defines the WAN interface. We use the VLAN ID only if we do NOT have a separate eth. + # This is different from the criterion for the WAN port dealt with above! + # If the WANDEV is different from the SWITCHDEV, but the WAN port is in the switch, + # the WAN eth has to be connected to the switch untagged! + [ "$WANDEV" = "$SWITCHDEV" ] && WANDEV="${SWITCHDEV}.2" + enableAutoConf "$WANDEV" + uci set network.wan.ifname="$WANDEV" + + uci -q commit network + fi fi /etc/init.d/network restart -if [ -n "$ETHMESHMAC" ]; then - fixMac "$ETHMESHMAC" "${SWITCHDEV}.3" "ethmesh" +if [ -n "$ETHMESHMAC" ] && [ -n "$ETHMESHDEV" ]; then + fixMac "$ETHMESHMAC" "$ETHMESHDEV" "ethmesh" fi if [ -n "$ROUTERMAC" ]; then fixMac "$ROUTERMAC" "br-mesh" "mesh" fi -if [ -n "$ETH0MAC" ]; then - echo "Fixing MAC on eth0" - sleep 10 - NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address") - uci set network.eth0.macaddr=$NEW_MACADDR - uci commit network - ifconfig eth0 down - ifconfig eth0 hw ether $NEW_MACADDR - ifconfig eth0 up - /etc/init.d/network restart -fi - if uci -q get "network.mesh.ip6addr" > /dev/null then echo "IPv6 for mesh is set already"
Hi Adrian, getestet hab ich es nicht. Sollte aber passen. Reviewed-by: Robert Langhammer <rlanghammer@web.de> Am 07.08.18 um 12:25 schrieb Adrian Schmutzler: > This patch rearranges the commands in configurenetwork. The main > goal is to avoid code duplications and make reading easier. Some > "bugs" were addressed on the way: > - Previously, ONEPORT devices went through both major blocks, > resulting e.g. in useless eth0.X interfaces being set up (and > perhaps lots of other strange things). Now, the routines for > ONEPORT and normal devices are separated. > - Updating the /etc/sysctl.conf has been combined to a single > block based on variables set earlier > - WANDEV is reset to WANDEV.2 were applicable to reduce number of > ifs > - "uci del uci set" has been changed to "uci del" > - Spaces have been changed to Tabs were changes were done > - Arguments have been quoted in various places > - Double brackets have been replaced by single brackets > - ETHMODE if has been changed to use BATMAN as default (elseif > changed to else) > - Use ETHMESHMAC for ONEPORT, introduce ETHMESHDEV > - Shift bit of ROUTERMAC for ONEPORT's ETHMESHMAC > > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> > > Tested-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> > > --- > > This is a requirement to remove the dummy interfaces (do.not.use) > > Changes in v2: > - Merged with ETH0MAC replacement patch > > Changes in v3: > - Don't write comment to /etc/sysctl.conf > > Changes in v4: > - Rebased and used en-/disableAutoConf > > Changes in v5: > - Rebased > - Fixed behavior for WAN in switch but different eth > - Bump package version > --- > src/packages/fff/fff-network/Makefile | 2 +- > .../fff-network/files/usr/sbin/configurenetwork | 152 ++++++++++----------- > 2 files changed, 72 insertions(+), 82 deletions(-) > > diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile > index 980800ae..beb425e9 100644 > --- a/src/packages/fff/fff-network/Makefile > +++ b/src/packages/fff/fff-network/Makefile > @@ -1,7 +1,7 @@ > include $(TOPDIR)/rules.mk > > PKG_NAME:=fff-network > -PKG_VERSION:=10 > +PKG_VERSION:=11 > PKG_RELEASE:=1 > > PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) > diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork > index 9dc29da1..a0acbcd4 100755 > --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork > +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork > @@ -104,97 +104,87 @@ if [ -n "$LAN1PORT" ] ; then > setupPorts "$LAN1PORT" "${LAN1MODE}" > fi > > -if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then > - > - 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" ] || ! [ -z "$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" > - > - enableAutoConf "$WANDEV.2" > - else > - enableAutoConf "$WANDEV" > - 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" > - > - uci set network.mesh.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 > - > -if [ "$ONE_PORT" = "YES" ] && ( ! uci -q get network.$SWITCHDEV.ifname || [ "$FORCEPARSE" = '1' ] ) ; then > - uci set network.$SWITCHDEV=interface > - uci set network.$SWITCHDEV.ifname=$SWITCHDEV > - if [ "$ETHMODE" = "WAN" ]; then > - enableAutoConf "$WANDEV" > - uci set network.mesh.ifname="bat0" > - uci set network.wan.ifname="$WANDEV" > - uci del uci set network.ethmesh.ifname > - uci del network.eth0.macaddr > - elif [ "$ETHMODE" = "CLIENT" ] ; then > - disableAutoConf "$WANDEV" > - uci set network.mesh.ifname="bat0 $SWITCHDEV" > - uci set network.wan.ifname="eth1" #eth1 because it is default in config file > - uci del network.ethmesh.ifname > - uci del network.eth0.macaddr > - elif [ "$ETHMODE" = "BATMAN" ] ; then > - disableAutoConf "$WANDEV" > - uci set network.mesh.ifname="bat0" > - uci set network.wan.ifname="eth1" #eth1 because it is default in config file > - uci set network.ethmesh.ifname="$SWITCHDEV" > - ETH0MAC="w2ap" > - fi > - uci commit network > +if [ "$ONE_PORT" = "YES" ] ; then > + if ! uci -q get "network.$SWITCHDEV.ifname" || [ "$FORCEPARSE" = '1' ] ; then > + uci set "network.$SWITCHDEV=interface" > + uci set "network.$SWITCHDEV.ifname=$SWITCHDEV" > + if [ "$ETHMODE" = "WAN" ]; then > + enableAutoConf "$WANDEV" > + uci set network.mesh.ifname="bat0" > + uci set network.wan.ifname="$WANDEV" > + uci del network.ethmesh.ifname > + uci del network.eth0.macaddr > + elif [ "$ETHMODE" = "CLIENT" ] ; then > + disableAutoConf "$WANDEV" > + uci set network.mesh.ifname="bat0 $SWITCHDEV" > + uci set network.wan.ifname="eth1" #eth1 because it is default in config file > + uci del network.ethmesh.ifname > + uci del network.eth0.macaddr > + else # default=BATMAN > + disableAutoConf "$WANDEV" > + uci set network.mesh.ifname="bat0" > + uci set network.wan.ifname="eth1" #eth1 because it is default in config file > + uci set network.ethmesh.ifname="$SWITCHDEV" > + ETHMESHMAC="$(macFlipLocalBit "$ROUTERMAC")" > + ETHMESHDEV="$SWITCHDEV" > + fi > + uci -q commit network > + fi > +else > + if ! uci -q get "network.$SWITCHDEV" > /dev/null || [ "$FORCEPARSE" = '1' ] ; then > + 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" > + > + # This defines the VLAN for WAN ports inside the switch. > + # This is required even if the WAN eth is separate, but the WAN port is in the switch! > + 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 > + > + ETHMESHDEV="$SWITCHDEV.3" > + 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" > + > + uci set network.mesh.ifname="$SWITCHDEV.1 bat0" > + uci set network.ethmesh.ifname="$ETHMESHDEV" > + > + # This defines the WAN interface. We use the VLAN ID only if we do NOT have a separate eth. > + # This is different from the criterion for the WAN port dealt with above! > + # If the WANDEV is different from the SWITCHDEV, but the WAN port is in the switch, > + # the WAN eth has to be connected to the switch untagged! > + [ "$WANDEV" = "$SWITCHDEV" ] && WANDEV="${SWITCHDEV}.2" > + enableAutoConf "$WANDEV" > + uci set network.wan.ifname="$WANDEV" > + > + uci -q commit network > + fi > fi > > /etc/init.d/network restart > > -if [ -n "$ETHMESHMAC" ]; then > - fixMac "$ETHMESHMAC" "${SWITCHDEV}.3" "ethmesh" > +if [ -n "$ETHMESHMAC" ] && [ -n "$ETHMESHDEV" ]; then > + fixMac "$ETHMESHMAC" "$ETHMESHDEV" "ethmesh" > fi > > if [ -n "$ROUTERMAC" ]; then > fixMac "$ROUTERMAC" "br-mesh" "mesh" > fi > > -if [ -n "$ETH0MAC" ]; then > - echo "Fixing MAC on eth0" > - sleep 10 > - NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address") > - uci set network.eth0.macaddr=$NEW_MACADDR > - uci commit network > - ifconfig eth0 down > - ifconfig eth0 hw ether $NEW_MACADDR > - ifconfig eth0 up > - /etc/init.d/network restart > -fi > - > if uci -q get "network.mesh.ip6addr" > /dev/null > then > echo "IPv6 for mesh is set already"