2017-04-12 17:13:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. /lib/functions.sh
|
|
|
|
. ../netifd-proto.sh
|
|
|
|
init_proto "$@"
|
|
|
|
|
|
|
|
proto_gluon_bat0_init_config() {
|
|
|
|
no_device=1
|
|
|
|
available=1
|
|
|
|
renew_handler=1
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_gluon_bat0_renew() {
|
|
|
|
local config="$1"
|
|
|
|
|
|
|
|
lock /var/lock/gluon_bat0.lock
|
|
|
|
|
|
|
|
local ifdump="$(ubus call network.interface dump)"
|
|
|
|
|
|
|
|
echo "$ifdump" | jsonfilter \
|
|
|
|
-e "@.interface[@.proto='gluon_mesh' && @.up=true]['device','data']" \
|
|
|
|
| while read dev; do
|
|
|
|
read data
|
|
|
|
|
|
|
|
echo bat0 > "/sys/class/net/$dev/batman_adv/mesh_iface"
|
|
|
|
|
|
|
|
! [ "$(echo "$data" | jsonfilter -e "@.transitive")" = 'true' ]
|
|
|
|
transitive=$?
|
|
|
|
|
|
|
|
(echo "$transitive" > "/sys/class/net/$dev/batman_adv/no_rebroadcast") 2>/dev/null
|
|
|
|
done
|
|
|
|
|
|
|
|
lock -u /var/lock/gluon_bat0.lock
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_gluon_bat0_setup() {
|
|
|
|
local config="$1"
|
|
|
|
|
2019-06-16 13:51:43 +00:00
|
|
|
local primary0_mac="$(lua -e 'print(require("gluon.util").generate_mac(3))')"
|
2017-04-12 17:13:49 +00:00
|
|
|
|
|
|
|
ip link add primary0 type dummy
|
|
|
|
echo 1 > /proc/sys/net/ipv6/conf/primary0/disable_ipv6
|
|
|
|
ip link set primary0 address "$primary0_mac" mtu 1532 up
|
2017-07-10 21:08:39 +00:00
|
|
|
|
2019-07-27 05:40:26 +00:00
|
|
|
local routing_algo="$(lua -e 'print(require("gluon.site").mesh.batman_adv.routing_algo())')"
|
2019-09-24 22:13:23 +00:00
|
|
|
(echo "$routing_algo" >/sys/module/batman_adv/parameters/routing_algo) 2>/dev/null
|
2017-07-10 21:08:39 +00:00
|
|
|
|
2017-04-12 17:13:49 +00:00
|
|
|
echo bat0 > /sys/class/net/primary0/batman_adv/mesh_iface
|
|
|
|
|
|
|
|
proto_init_update primary0 1
|
|
|
|
proto_send_update "$config"
|
|
|
|
|
|
|
|
proto_gluon_bat0_renew "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_gluon_bat0_teardown() {
|
|
|
|
local config="$1"
|
|
|
|
|
|
|
|
ip link del bat0
|
|
|
|
ip link del primary0
|
|
|
|
}
|
|
|
|
|
|
|
|
add_protocol gluon_bat0
|