forked from freifunk-franken/firmware
fff-babeld: use functions for setting initial rules and filters
The current initial setup for fff-babeld is quite static, hard to adjust and full of redundancy. Make it more flexible and improve general readability by using functions. These may be reused by other routines or scripts later. This also drops the static file /etc/config/babeld that was replacing an existing babeld config file, and moves the code to the already existing uci-defaults script. With this step, it will be easier to add conditionals to the uci-defaults script when the original file should not be overwritten later. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
fcb19bd233
commit
c982b81fe8
|
@ -1,7 +1,7 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=fff-babeld
|
||||
PKG_RELEASE:=7
|
||||
PKG_RELEASE:=8
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
config general
|
||||
option export_table '10'
|
||||
option import_table '10'
|
||||
option first_table_number '100'
|
||||
option local_port '33123'
|
||||
|
||||
config interface
|
||||
option type 'wired'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option local 'true'
|
||||
option ip '10.50.0.0/16'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option local 'true'
|
||||
option ip '10.83.0.0/16'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option local 'true'
|
||||
option ip 'fd43:5602:29bd::/48'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option local 'true'
|
||||
option action 'deny'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option ip '10.50.0.0/16'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option ip '10.83.0.0/16'
|
||||
|
||||
config filter
|
||||
option type 'redistribute'
|
||||
option ip 'fd43:5602:29bd::/48'
|
|
@ -1,44 +1,41 @@
|
|||
uci batch <<EOF
|
||||
add network rule
|
||||
set network.@rule[0].src='10.50.0.0/16'
|
||||
set network.@rule[0].lookup='10'
|
||||
set network.@rule[0].priority='20'
|
||||
add network rule
|
||||
set network.@rule[1]=rule
|
||||
set network.@rule[1].dest='10.50.0.0/16'
|
||||
set network.@rule[1].lookup='10'
|
||||
set network.@rule[1].priority='20'
|
||||
add network rule
|
||||
set network.@rule[2].src='10.83.0.0/16'
|
||||
set network.@rule[2].lookup='10'
|
||||
set network.@rule[2].priority='20'
|
||||
add network rule
|
||||
set network.@rule[3]=rule
|
||||
set network.@rule[3].dest='10.83.0.0/16'
|
||||
set network.@rule[3].lookup='10'
|
||||
set network.@rule[3].priority='20'
|
||||
add network rule
|
||||
set network.@rule[4]=rule
|
||||
set network.@rule[4].in='client'
|
||||
set network.@rule[4].lookup='10'
|
||||
set network.@rule[4].priority='31'
|
||||
add network rule6
|
||||
set network.@rule6[0]=rule6
|
||||
set network.@rule6[0].src='fc00::/7'
|
||||
set network.@rule6[0].lookup='10'
|
||||
set network.@rule6[0].priority='20'
|
||||
add network rule6
|
||||
set network.@rule6[1]=rule6
|
||||
set network.@rule6[1].dest='fc00::/7'
|
||||
set network.@rule6[1].lookup='10'
|
||||
set network.@rule6[1].priority='20'
|
||||
add network rule6
|
||||
set network.@rule6[2]=rule6
|
||||
set network.@rule6[2].in='client'
|
||||
set network.@rule6[2].lookup='10'
|
||||
set network.@rule6[2].priority='31'
|
||||
. /lib/functions/fff/babel
|
||||
|
||||
>/etc/config/babeld
|
||||
|
||||
uci batch >/dev/null <<EOF
|
||||
add babeld general
|
||||
set babeld.@general[-1].export_table=10
|
||||
set babeld.@general[-1].import_table=10
|
||||
set babeld.@general[-1].first_table_number=100
|
||||
set babeld.@general[-1].local_port=33123
|
||||
|
||||
add babeld interface
|
||||
set babeld.@interface[-1].type=wired
|
||||
EOF
|
||||
|
||||
babel_add_local_ipfilter 10.50.0.0/16
|
||||
babel_add_local_ipfilter 10.83.0.0/16
|
||||
babel_add_local_ipfilter fd43:5602:29bd::/48
|
||||
|
||||
uci add babeld filter >/dev/null
|
||||
uci set babeld.@filter[-1].type=redistribute
|
||||
uci set babeld.@filter[-1].action=deny
|
||||
uci set babeld.@filter[-1].local=true
|
||||
|
||||
babel_add_ipfilter 10.50.0.0/16
|
||||
babel_add_ipfilter 10.83.0.0/16
|
||||
babel_add_ipfilter fd43:5602:29bd::/48
|
||||
|
||||
babel_add_rule src 10.50.0.0/16 10 20
|
||||
babel_add_rule dest 10.50.0.0/16 10 20
|
||||
babel_add_rule src 10.83.0.0/16 10 20
|
||||
babel_add_rule dest 10.83.0.0/16 10 20
|
||||
babel_add_rule in client 10 31
|
||||
babel_add_rule6 src fc00::/7 10 20
|
||||
babel_add_rule6 dest fc00::/7 10 20
|
||||
babel_add_rule6 in client 10 31
|
||||
|
||||
uci commit babeld
|
||||
uci commit network
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -1,3 +1,56 @@
|
|||
babel_add_ipfilter() {
|
||||
[ "$#" -ne "1" ] && return 1
|
||||
|
||||
local ip=$1
|
||||
|
||||
uci add babeld filter >/dev/null
|
||||
uci set babeld.@filter[-1].type=redistribute
|
||||
uci set babeld.@filter[-1].ip="$ip"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
babel_add_local_ipfilter() {
|
||||
[ "$#" -ne "1" ] && return 1
|
||||
|
||||
babel_add_ipfilter "$1" || return 1
|
||||
uci set babeld.@filter[-1].local=true
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
babel_add_rule() {
|
||||
[ "$#" -ne "4" ] && return 1
|
||||
|
||||
local param="$1"
|
||||
local value="$2"
|
||||
local table="$3"
|
||||
local prio="$4"
|
||||
|
||||
uci add network rule >/dev/null
|
||||
uci set network.@rule[-1]."$param"="$value"
|
||||
uci set network.@rule[-1].lookup="$table"
|
||||
uci set network.@rule[-1].priority="$prio"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
babel_add_rule6() {
|
||||
[ "$#" -ne "4" ] && return 1
|
||||
|
||||
local param="$1"
|
||||
local value="$2"
|
||||
local table="$3"
|
||||
local prio="$4"
|
||||
|
||||
uci add network rule6 >/dev/null
|
||||
uci set network.@rule6[-1]."$param"="$value"
|
||||
uci set network.@rule6[-1].lookup="$table"
|
||||
uci set network.@rule6[-1].priority="$prio"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
babel_add_iifrules() {
|
||||
[ "$#" -ne "1" ] && return 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue