gateway.d: Add scripts for network configuration

This adds scripts to configure vlan and client network.
This also adds sysctl settings to enable forwarding.

Note:
Devices specific properties are sourced from fff-network package.
This creates a dependency on fff-boardname and fff-network.
These properties should be located elsewhere in the future.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Tim Niemeyer <tim@tn-x.org>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
This commit is contained in:
Fabian Bläse 2019-05-13 23:30:48 +02:00 committed by Fabian Bläse
parent 555e91628b
commit 590dbca7a9
4 changed files with 125 additions and 0 deletions

View File

@ -13,6 +13,7 @@ define Package/fff-gateway
CATEGORY:=Freifunk
TITLE:= Freifunk-Franken gateway configuration
URL:=https://www.freifunk-franken.de
DEPENDS:=+fff-boardname +fff-network
endef
define Package/fff-gateway/description

View File

@ -0,0 +1,48 @@
# load uci functions
. /lib/functions.sh
# load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/cpuport
configure() {
add_vlan() {
local vlan="$1"
local ports=$(uci get gateway.$vlan.ports)
local name="$SWITCHDEV"_$vlan
uci set network.$name='switch_vlan'
uci set network.$name.device="$(uci get network.$SWITCHDEV.name)"
uci set network.$name.vlan="$vlan"
uci set network.$name.ports="$CPUPORT $ports"
}
remove_vlan() {
local name="$1"
local switchdev=$(echo $name | cut -d_ -f1)
local vlan=$(echo $name | cut -d_ -f2)
# only remove vlans not present in gateway config
if ! uci -q get gateway.$vlan > /dev/null; then
# remove switch_vlan
uci del network.$name
fi
}
config_load network
config_foreach remove_vlan switch_vlan
config_load gateway
config_foreach add_vlan vlan
}
apply() {
uci commit network
}
revert() {
uci revert network
}

View File

@ -0,0 +1,71 @@
# load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
configure() {
# ipaddr
#remove old ipaddr
uci -q del network.mesh.ipaddr
#set new ipaddr
if ipaddr=$(uci -q get gateway.@client[0].ipaddr); then
for ip in $ipaddr; do
uci add_list network.mesh.ipaddr=$ip
done
else
echo "WARNING: No client ipaddr set!"
fi
#put interface routes from set addresses into fff table
uci set network.mesh.ip4table='fff'
# ip6addr
#remove old ip6addr
for ip in $(uci get network.mesh.ip6addr); do
if echo "$ip" | grep -v -e "fdff:" -e "fe80::1/64" > /dev/null; then
uci del_list network.mesh.ip6addr="$ip"
fi
done
#set new ip6addr
if ip6addr=$(uci -q get gateway.@client[0].ip6addr); then
for ip in $ip6addr; do
uci add_list network.mesh.ip6addr=$ip
done
else
echo "WARNING: No client ip6addr set!"
fi
#put interface routes from set addresses into fff table
uci set network.mesh.ip6table='fff'
# dhcp
uci -q del dhcp.mesh.start
uci -q del dhcp.mesh.limit
if dhcp_start=$(uci -q get gateway.@client[0].dhcp_start); then
uci set dhcp.mesh=dhcp
uci set dhcp.mesh.interface=mesh
uci set dhcp.mesh.start=$dhcp_start
uci set dhcp.mesh.limit=$(uci -q get gateway.@client[0].dhcp_limit)
else
echo "WARNING: No DHCP range start and/or limit set!"
fi
# set interface
#remove all eth interfaces
ifaces=$(uci get network.mesh.ifname | sed 's/\beth[^ ]* *//g')
if vlan=$(uci -q get gateway.@client[0].vlan); then
uci set network.mesh.ifname="${SWITCHDEV}.$vlan $ifaces"
elif iface=$(uci -q get gateway.@client[0].iface); then
uci set network.mesh.ifname="$iface $ifaces"
else
echo "WARNING: No Interface for client specified"
fi
}
apply() {
uci commit network
uci commit dhcp
}
revert() {
uci revert network
uci revert dhcp
}

View File

@ -0,0 +1,5 @@
# Enable forwarding
net.ipv4.conf.all.forwarding=1
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.default.forwarding=1