2014-11-12 21:22:55 +01:00
|
|
|
#!/bin/sh
|
2014-11-10 20:31:28 +01:00
|
|
|
# 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.
|
|
|
|
|
2016-05-16 14:26:49 +02:00
|
|
|
BOARD="$(uci get board.model.name)"
|
|
|
|
. /etc/network.$BOARD
|
|
|
|
|
2014-04-11 22:39:34 +02:00
|
|
|
if ! uci get network.$SWITCHDEV.ifname; then
|
2014-08-16 01:11:18 +02:00
|
|
|
|
|
|
|
SWITCHHW=$(swconfig list | awk '{ print $4 }')
|
|
|
|
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.$SWITCHDEV=switch
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.$SWITCHDEV.name=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
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
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.${SWITCHDEV}_1.device=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
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
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.${SWITCHDEV}_2.device=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
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
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.${SWITCHDEV}_3.device=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
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
|
2014-08-17 14:56:31 +02:00
|
|
|
/etc/init.d/network restart
|
2014-04-11 22:39:34 +02:00
|
|
|
fi
|
2014-04-12 19:15:31 +02:00
|
|
|
|
2016-09-15 21:45:20 +02:00
|
|
|
if [ "$ONE_PORT" = "YES" ]; then
|
|
|
|
uci set network.$SWITCHDEV=interface
|
|
|
|
uci set network.$SWITCHDEV.ifname=$SWITCHDEV
|
|
|
|
if [ "$ETHMODE" = "WAN" ]; then
|
|
|
|
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
|
|
|
|
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
|
|
|
|
echo "net.ipv6.conf.$WANDEV.accept_ra_defrtr = 0" >> /etc/sysctl.conf
|
|
|
|
echo "net.ipv6.conf.$WANDEV.accept_ra_pinfo = 0" >> /etc/sysctl.conf
|
|
|
|
echo "net.ipv6.conf.$WANDEV.autoconf = 0" >> /etc/sysctl.conf
|
|
|
|
echo "net.ipv6.conf.$WANDEV.accept_ra_rtr_pref = 0" >> /etc/sysctl.conf
|
|
|
|
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
|
|
|
|
echo "net.ipv6.conf.$WANDEV.accept_ra_defrtr = 0" >> /etc/sysctl.conf
|
|
|
|
echo "net.ipv6.conf.$WANDEV.accept_ra_pinfo = 0" >> /etc/sysctl.conf
|
|
|
|
echo "net.ipv6.conf.$WANDEV.autoconf = 0" >> /etc/sysctl.conf
|
|
|
|
echo "net.ipv6.conf.$WANDEV.accept_ra_rtr_pref = 0" >> /etc/sysctl.conf
|
|
|
|
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
|
|
|
|
/etc/init.d/network restart
|
|
|
|
fi
|
|
|
|
|
2014-04-12 19:15:31 +02:00
|
|
|
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)"
|
2014-08-17 14:56:31 +02:00
|
|
|
sleep 10
|
2014-04-12 19:15:31 +02:00
|
|
|
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
|
2014-08-17 14:56:31 +02:00
|
|
|
/etc/init.d/network restart
|
2014-04-12 19:15:31 +02:00
|
|
|
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)"
|
2014-08-17 14:56:31 +02:00
|
|
|
sleep 10
|
2014-04-12 19:15:31 +02:00
|
|
|
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
|
2014-08-17 14:56:31 +02:00
|
|
|
/etc/init.d/network restart
|
2014-04-12 19:15:31 +02:00
|
|
|
fi
|
2015-12-31 15:49:55 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$ETH0MAC" ]]; then
|
|
|
|
echo "Fixing MAC on eth0"
|
|
|
|
sleep 10
|
2016-01-23 16:59:00 +01:00
|
|
|
NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address")
|
2015-12-31 15:49:55 +01:00
|
|
|
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
|
2016-01-30 11:59:46 +01:00
|
|
|
|
|
|
|
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
|