firmware/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-client

123 lines
3.0 KiB
Plaintext

# load uci functions
. /lib/functions.sh
. /lib/functions/system.sh
. /lib/functions/fff/interfaces
. /lib/functions/fff/routermac
configure() {
add_clientif() {
local name="$1"
uci set network.$name=interface
uci set network.$name.fff_clientif="1"
uci set network.$name.type=bridge
uci set network.$name.proto=static
uci set network.$name.auto=1
[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label)
uci set network.$name.macaddr="$ROUTERMAC"
# ipaddr
#remove old ipaddr
uci -q del network.$name.ipaddr
#set new ipaddr
if ipaddr=$(uci -q get gateway.$name.ipaddr); then
for ip in $ipaddr; do
uci add_list network.$name.ipaddr=$ip
done
else
echo "WARNING: No ipaddr for client interface \"$name\" set!"
fi
#put interface routes from set addresses into fff table
uci set network.$name.ip4table='fff'
# ip6addr
#remove old ip6addr
for ip in $(uci -q get network.$name.ip6addr); do
if echo "$ip" | grep -v -e "fdff:" -e "fe80::1/64" > /dev/null; then
uci del_list network.$name.ip6addr="$ip"
fi
done
#set new ip6addr
if ip6addr=$(uci -q get gateway.$name.ip6addr); then
for ip in $ip6addr; do
uci add_list network.$name.ip6addr=$ip
done
else
echo "WARNING: No ip6addr for client interface \"$name\" set!"
fi
#put interface routes from set addresses into fff table
uci set network.$name.ip6table='fff'
# dhcp
uci -q set dhcp.$name=dhcp
uci -q set dhcp.$name.interface=$name
uci -q set dhcp.$name.leasetime='1h'
uci -q del dhcp.$name.start
uci -q del dhcp.$name.limit
if dhcp_start=$(uci -q get gateway.$name.dhcp_start); then
uci set dhcp.$name=dhcp
uci set dhcp.$name.interface=client
uci set dhcp.$name.start=$dhcp_start
uci set dhcp.$name.limit=$(uci -q get gateway.$name.dhcp_limit)
else
echo "WARNING: No DHCP range start and/or limit for client interface \"$name\" set!"
fi
# ra
uci -q set dhcp.$name.ra='server'
uci -q set dhcp.$name.ra_default='2'
uci -q set dhcp.$name.ra_management='0'
# set interface
#remove all eth interfaces
if vlan=$(uci -q get gateway.$name.vlan); then
uci set network.$name.ifname="${SWITCHDEV}.$vlan"
elif iface=$(uci -q get gateway.$name.iface); then
uci set network.$name.ifname="$iface"
else
echo "WARNING: No ifname/vlan for client interface \"$name\" specified"
fi
}
remove_clientif() {
local name="$1"
# only remove interfaces created by this script
[ "$(uci -q get network.$name.fff_clientif)" == "1" ] || return
# only remove interfaces that disappeared from gwconfig
[ "$(uci -q get gateway.$name)" == "client" ] && return
uci -q del network.$name
uci -q del dhcp.$name
}
if [ "$(uci -q get gateway.client)" != "client" ]; then
echo "ERROR: A client interface named \"client\" is required"
exit 1
fi
config_load network
config_foreach remove_clientif interface
config_load gateway
config_foreach add_clientif client
}
apply() {
uci commit network
uci commit dhcp
}
revert() {
uci revert network
uci revert dhcp
}