fff-layer3-config: add router_ip option

For some purposes (e.g. SNAT, vxlan) it might be necessary to have an
additional address just for the router which is not attached to any
interfaces. Addresses like this are typically added to the loopback
interface.

The new options "router_ip" and "router_ip6" are added to the gateway
config to allow the user to configure such addresses. It is possible to
both specify the address with or without a subnet size.

The default configuration contains the IPv4 loopback address
(127.0.0.1/8) explicitly, but this is not necessary. These addresses are
configured automatically, even if they are not present in the
configuration, so they can safely be removed, if present.

The filters of our routing daemon babeld are adjusted accordingly, so
the newly added addresses are announced correctly.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Christian Dresel <freifunk@dresel.systems>
Reviewed-by: Johannes Kimmel <fff@bareminimum.eu>
This commit is contained in:
Fabian Bläse 2021-03-03 19:01:50 +01:00
parent 5509ae287e
commit e07f6121cc
3 changed files with 41 additions and 2 deletions

View File

@ -21,6 +21,11 @@ config filter
option local 'true'
option ip 'fd43:5602:29bd::/48'
config filter
option type 'redistribute'
option local 'true'
option if 'lo'
config filter
option type 'redistribute'
option local 'true'

View File

@ -36,11 +36,14 @@ babel_add_peeraddr() {
if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then
uci add_list "$option"="$peer_ip"
elif router_ip=$(uci -q get gateway.meta.router_ip); then
# use router_ip if no peer_ip is set
uci add_list "$option"="$router_ip"
elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then
# use ipaddr (without subnet) if no peer_ip set
# use client interface address (without subnet) if no router_ip is set
uci add_list "$option"=$(echo $ipaddr | cut -d / -f1)
else
echo "WARNING: Neither peer_ip nor ipaddr set! IPv4 routing is not possible."
echo "WARNING: No peer_ip, router_ip or client interface ipaddr set! IPv4 routing is not possible."
return 1
fi

View File

@ -0,0 +1,31 @@
configure() {
local router_ip
local router_ip6
# clean old addresses
uci -q del network.loopback.ipaddr
uci -q del network.loopback.ip6addr
# remove netmask entry that ships by default
uci -q del network.loopback.netmask
# add router_ip
router_ip=$(uci -q get gateway.meta.router_ip)
for ip in $router_ip; do
uci -q add_list network.loopback.ipaddr="$ip"
done
# add router_ip6
router_ip6=$(uci -q get gateway.meta.router_ip6)
for ip in $router_ip6; do
uci -q add_list network.loopback.ip6addr="$ip"
done
}
apply() {
uci commit network
}
revert() {
uci revert network
}