[PATCH v2] Moved network configuration script to own package

mayosemmel mayosemmel at googlemail.com
Mo Mai 16 14:29:27 CEST 2016


Und noch was verplant :-( Sorry!
Kann der jenige, ders ggf. applied die 2te Zeile von der Commit message
bitte einfach wegwerfen? Das gehört auch in einen späteren Commit.

Am Montag, den 16.05.2016, 14:26 +0200 schrieb Jan Kraus:
> also added check if IPv6 prefix is set.
> 
> Signed-off-by: Jan Kraus <mayosemmel at gmail.com>
> ---
> Changes in v2:
> changed start of configurehood (wich will follow in an other patch)
> to configurenetwork and removed dot sourcing
> 
> Changes in configurenetwork (just for understanding):
> 
> @@ -9,6 +9,9 @@
>  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  # GNU General Public License for more details.
>  
> +BOARD="$(uci get board.model.name)"
> +. /etc/network.$BOARD
> +
>  if ! uci get nodewatcher. at network[0].client_interfaces; then
>      echo "Setting nodewatchers client interfaces to: $CLIENTIF"
>      uci set nodewatcher. at network[0].client_interfaces="$CLIENTIF"
> ---
>  bsp/default/root_file_system/etc/network.sh        | 155 --------------------
>  bsp/default/root_file_system/etc/rc.local.tpl      |   4 +-
>  src/packages/fff/fff-network/Makefile              |  39 +++++
>  .../fff-network/files/usr/sbin/configurenetwork    | 158 +++++++++++++++++++++
>  src/packages/fff/fff/Makefile                      |   3 +-
>  5 files changed, 200 insertions(+), 159 deletions(-)
>  delete mode 100644 bsp/default/root_file_system/etc/network.sh
>  create mode 100644 src/packages/fff/fff-network/Makefile
>  create mode 100644 src/packages/fff/fff-network/files/usr/sbin/configurenetwork
> 
> diff --git a/bsp/default/root_file_system/etc/network.sh b/bsp/default/root_file_system/etc/network.sh
> deleted file mode 100644
> index 1a595a5..0000000
> --- a/bsp/default/root_file_system/etc/network.sh
> +++ /dev/null
> @@ -1,155 +0,0 @@
> -#!/bin/sh
> -# This program is free software; you can redistribute it and/or modify
> -# it under the terms of the GNU General Public License as published by
> -# the Free Software Foundation; either version 3 of the License, or
> -# (at your option) any later version.
> -
> -# This program is distributed in the hope that it will be useful,
> -# but WITHOUT ANY WARRANTY; without even the implied warranty of
> -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> -# GNU General Public License for more details.
> -
> -if ! uci get nodewatcher. at network[0].client_interfaces; then
> -    echo "Setting nodewatchers client interfaces to: $CLIENTIF"
> -    uci set nodewatcher. at network[0].client_interfaces="$CLIENTIF"
> -    uci commit
> -fi
> -
> -if ! uci get network.$SWITCHDEV.ifname; 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"
> -
> -    echo "# Allow IPv6 RAs on WAN Port" >> /etc/sysctl.conf
> -
> -    if [[ "$WANDEV" = "$SWITCHDEV" ]]; 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"
> -
> -        echo "net.ipv6.conf.$WANDEV.2.accept_ra_defrtr = 1" >> /etc/sysctl.conf
> -        echo "net.ipv6.conf.$WANDEV.2.accept_ra_pinfo = 1" >> /etc/sysctl.conf
> -        echo "net.ipv6.conf.$WANDEV.2.autoconf = 1" >> /etc/sysctl.conf
> -        echo "net.ipv6.conf.$WANDEV.2.accept_ra_rtr_pref = 1" >> /etc/sysctl.conf
> -    else
> -        echo "net.ipv6.conf.$WANDEV.accept_ra_defrtr = 1" >> /etc/sysctl.conf
> -        echo "net.ipv6.conf.$WANDEV.accept_ra_pinfo = 1" >> /etc/sysctl.conf
> -        echo "net.ipv6.conf.$WANDEV.autoconf = 1" >> /etc/sysctl.conf
> -        echo "net.ipv6.conf.$WANDEV.accept_ra_rtr_pref = 1" >> /etc/sysctl.conf
> -    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
> -    /etc/init.d/network restart
> -fi
> -
> -if [[ -n "$ETHMESHMAC" ]]; then
> -    if uci get network.ethmesh.macaddr
> -    then
> -        echo "MAC for ethmesh is set already"
> -    else
> -        echo "Fixing MAC on eth0.3 (ethmesh)"
> -        sleep 10
> -        NEW_MACADDR=$(cat /sys/class/net/$ETHMESHMAC/address)
> -        uci set network.ethmesh.macaddr=$NEW_MACADDR
> -        uci commit
> -        ifconfig eth0.3 down
> -        ifconfig eth0.3 hw ether $NEW_MACADDR
> -        ifconfig eth0.3 up
> -        /etc/init.d/network restart
> -    fi
> -fi
> -
> -if [[ -n "$ROUTERMAC" ]]; then
> -    if uci get network.mesh.macaddr
> -    then
> -        echo "MAC for mesh is set already"
> -    else
> -        echo "Fixing MAC on br-mesh (mesh)"
> -        sleep 10
> -        NEW_MACADDR=$(cat /sys/class/net/$ROUTERMAC/address)
> -        uci set network.mesh.macaddr=$NEW_MACADDR
> -        uci commit
> -        ifconfig br-mesh down
> -        ifconfig br-mesh hw ether $NEW_MACADDR
> -        ifconfig br-mesh up
> -        /etc/init.d/network restart
> -    fi
> -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
> -        ifconfig eth0 down
> -        ifconfig eth0 hw ether $NEW_MACADDR
> -        ifconfig eth0 up
> -        /etc/init.d/network restart
> -fi
> -
> -if uci get network.mesh.ip6addr
> -then
> -    echo "IPv6 for mesh is set already"
> -else
> -    # Some time needed :(
> -    sleep 5
> -
> -    for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do
> -        ip -6 addr del $ip dev br-mesh
> -    done
> -
> -    prefix="fdff:0::/64"
> -    # Set $prefix::MAC as IP
> -    suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address)
> -    addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
> -    ip -6 addr add $addr dev br-mesh
> -
> -    uci -q del network.globals
> -    uci -q set network.globals=globals
> -    uci -q set network.globals.ula_prefix=$prefix
> -    uci -q add_list network.mesh.ip6addr=$addr
> -    uci -q set network.mesh.proto=static
> -
> -    # Set $prefix::1 as IP
> -    suffix="1"
> -    addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
> -    ip -6 addr add $addr dev br-mesh
> -    uci -q add_list network.mesh.ip6addr=$addr
> -
> -    # Set $prefix::link-local as IP
> -    suffix=$(awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' /sys/class/net/br-mesh/address)
> -    addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
> -    ip -6 addr add $addr dev br-mesh
> -    uci -q add_list network.mesh.ip6addr=$addr
> -
> -    uci -q commit network
> -
> -    /etc/init.d/fff-uradvd restart
> -fi
> diff --git a/bsp/default/root_file_system/etc/rc.local.tpl b/bsp/default/root_file_system/etc/rc.local.tpl
> index 5a18675..74d3ba1 100755
> --- a/bsp/default/root_file_system/etc/rc.local.tpl
> +++ b/bsp/default/root_file_system/etc/rc.local.tpl
> @@ -59,9 +59,7 @@ if ! uci get board.model.name; then
>      uci set board.model.name=$BOARD
>  fi
>  
> -. /etc/network.$BOARD
> -
> -. /etc/network.sh
> +/usr/sbin/configurenetwork
>  
>  # Starting NTP-Client Daemon after 30s to ensure that the interface is up
>  ( sleep 30 ; ntpd -p ${NTPD_IP} ) &
> diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile
> new file mode 100644
> index 0000000..a803afe
> --- /dev/null
> +++ b/src/packages/fff/fff-network/Makefile
> @@ -0,0 +1,39 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=fff-network
> +PKG_VERSION:=0.0.1
> +PKG_RELEASE:=1
> +
> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-network
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/fff-network
> +    SECTION:=base
> +    CATEGORY:=Freifunk
> +    TITLE:= Freifunk-Franken network configuration
> +    URL:=http://www.freifunk-franken.de
> +    DEPENDS:=+fff-uradvd
> +endef
> +
> +define Package/fff-network/description
> +    This package configures the network interfaces
> +endef
> +
> +define Build/Prepare
> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile
> +endef
> +
> +define Build/Configure
> +	# nothing
> +endef
> +
> +define Build/Compile
> +	# nothing
> +endef
> +
> +define Package/fff-network/install
> +	$(CP) ./files/* $(1)/
> +endef
> +
> +$(eval $(call BuildPackage,fff-network))
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
> new file mode 100644
> index 0000000..4122322
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
> @@ -0,0 +1,158 @@
> +#!/bin/sh
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +
> +BOARD="$(uci get board.model.name)"
> +. /etc/network.$BOARD
> +
> +if ! uci get nodewatcher. at network[0].client_interfaces; then
> +    echo "Setting nodewatchers client interfaces to: $CLIENTIF"
> +    uci set nodewatcher. at network[0].client_interfaces="$CLIENTIF"
> +    uci commit
> +fi
> +
> +if ! uci get network.$SWITCHDEV.ifname; 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"
> +
> +    echo "# Allow IPv6 RAs on WAN Port" >> /etc/sysctl.conf
> +
> +    if [[ "$WANDEV" = "$SWITCHDEV" ]]; 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"
> +
> +        echo "net.ipv6.conf.$WANDEV.2.accept_ra_defrtr = 1" >> /etc/sysctl.conf
> +        echo "net.ipv6.conf.$WANDEV.2.accept_ra_pinfo = 1" >> /etc/sysctl.conf
> +        echo "net.ipv6.conf.$WANDEV.2.autoconf = 1" >> /etc/sysctl.conf
> +        echo "net.ipv6.conf.$WANDEV.2.accept_ra_rtr_pref = 1" >> /etc/sysctl.conf
> +    else
> +        echo "net.ipv6.conf.$WANDEV.accept_ra_defrtr = 1" >> /etc/sysctl.conf
> +        echo "net.ipv6.conf.$WANDEV.accept_ra_pinfo = 1" >> /etc/sysctl.conf
> +        echo "net.ipv6.conf.$WANDEV.autoconf = 1" >> /etc/sysctl.conf
> +        echo "net.ipv6.conf.$WANDEV.accept_ra_rtr_pref = 1" >> /etc/sysctl.conf
> +    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
> +    /etc/init.d/network restart
> +fi
> +
> +if [[ -n "$ETHMESHMAC" ]]; then
> +    if uci get network.ethmesh.macaddr
> +    then
> +        echo "MAC for ethmesh is set already"
> +    else
> +        echo "Fixing MAC on eth0.3 (ethmesh)"
> +        sleep 10
> +        NEW_MACADDR=$(cat /sys/class/net/$ETHMESHMAC/address)
> +        uci set network.ethmesh.macaddr=$NEW_MACADDR
> +        uci commit
> +        ifconfig eth0.3 down
> +        ifconfig eth0.3 hw ether $NEW_MACADDR
> +        ifconfig eth0.3 up
> +        /etc/init.d/network restart
> +    fi
> +fi
> +
> +if [[ -n "$ROUTERMAC" ]]; then
> +    if uci get network.mesh.macaddr
> +    then
> +        echo "MAC for mesh is set already"
> +    else
> +        echo "Fixing MAC on br-mesh (mesh)"
> +        sleep 10
> +        NEW_MACADDR=$(cat /sys/class/net/$ROUTERMAC/address)
> +        uci set network.mesh.macaddr=$NEW_MACADDR
> +        uci commit
> +        ifconfig br-mesh down
> +        ifconfig br-mesh hw ether $NEW_MACADDR
> +        ifconfig br-mesh up
> +        /etc/init.d/network restart
> +    fi
> +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
> +        ifconfig eth0 down
> +        ifconfig eth0 hw ether $NEW_MACADDR
> +        ifconfig eth0 up
> +        /etc/init.d/network restart
> +fi
> +
> +if uci get network.mesh.ip6addr
> +then
> +    echo "IPv6 for mesh is set already"
> +else
> +    # Some time needed :(
> +    sleep 5
> +
> +    for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do
> +        ip -6 addr del $ip dev br-mesh
> +    done
> +
> +    prefix="fdff:0::/64"
> +    # Set $prefix::MAC as IP
> +    suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address)
> +    addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
> +    ip -6 addr add $addr dev br-mesh
> +
> +    uci -q del network.globals
> +    uci -q set network.globals=globals
> +    uci -q set network.globals.ula_prefix=$prefix
> +    uci -q add_list network.mesh.ip6addr=$addr
> +    uci -q set network.mesh.proto=static
> +
> +    # Set $prefix::1 as IP
> +    suffix="1"
> +    addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
> +    ip -6 addr add $addr dev br-mesh
> +    uci -q add_list network.mesh.ip6addr=$addr
> +
> +    # Set $prefix::link-local as IP
> +    suffix=$(awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' /sys/class/net/br-mesh/address)
> +    addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
> +    ip -6 addr add $addr dev br-mesh
> +    uci -q add_list network.mesh.ip6addr=$addr
> +
> +    uci -q commit network
> +
> +    /etc/init.d/fff-uradvd restart
> +fi
> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
> index 80ae83b..52ccc14 100644
> --- a/src/packages/fff/fff/Makefile
> +++ b/src/packages/fff/fff/Makefile
> @@ -21,7 +21,8 @@ define Package/fff-base
>               +fff-batman-adv-legacy \
>               +fff-fastd \
>               +fff-firewall \
> -             +fff-support
> +             +fff-support \
> +             +fff-network
>  endef
>  
>  define Package/fff-base/description

-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigröße  : 473 bytes
Beschreibung: This is a digitally signed message part
URL         : <http://lists.freifunk.net/pipermail/franken-dev-freifunk.net/attachments/20160516/67fb52f8/attachment-0002.sig>


Mehr Informationen über die Mailingliste franken-dev