2021-11-28 16:18:41 +01:00
|
|
|
. /lib/functions.sh
|
|
|
|
|
2021-03-03 19:01:50 +01:00
|
|
|
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
|
|
|
|
|
2021-11-28 16:18:41 +01:00
|
|
|
# clean old rules
|
|
|
|
remove_rules() {
|
|
|
|
local name="$1"
|
|
|
|
|
|
|
|
# check if filter was added by this script
|
|
|
|
if ! [ "$(uci -q get network.$name.addedbyautoconfig)" = '30-network-routerip' ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
uci -q del network.$name
|
|
|
|
}
|
|
|
|
|
|
|
|
config_load network
|
|
|
|
config_foreach remove_rules rule
|
|
|
|
config_foreach remove_rules rule6
|
|
|
|
|
2021-03-03 19:01:50 +01:00
|
|
|
# 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"
|
2021-11-28 16:18:41 +01:00
|
|
|
|
|
|
|
config=$(uci add network rule)
|
|
|
|
uci -q set network.$config.src="$ip"
|
|
|
|
uci -q set network.$config.lookup='fff'
|
|
|
|
# default prio for the ip4table interface option is 10000
|
|
|
|
uci -q set network.$config.priority='10000'
|
|
|
|
uci -q set network.$config.addedbyautoconfig='30-network-routerip'
|
2021-03-03 19:01:50 +01:00
|
|
|
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"
|
2021-11-28 16:18:41 +01:00
|
|
|
|
|
|
|
config=$(uci add network rule6)
|
|
|
|
uci -q set network.$config.src="$ip"
|
|
|
|
uci -q set network.$config.lookup='fff'
|
|
|
|
# default prio for the ip6table interface option is 10000
|
|
|
|
uci -q set network.$config.priority='10000'
|
|
|
|
uci -q set network.$config.addedbyautoconfig='30-network-routerip'
|
2021-03-03 19:01:50 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
apply() {
|
|
|
|
uci commit network
|
|
|
|
}
|
|
|
|
|
|
|
|
revert() {
|
|
|
|
uci revert network
|
|
|
|
}
|