Änderungen

Zur Navigation springen Zur Suche springen
Multiood
Zeile 794: Zeile 794:  
uci commit firewall
 
uci commit firewall
 
</pre>
 
</pre>
 +
 +
== Multihood ==
 +
 +
=== /lib/netifd/proto/bat.sh ===
 +
Make executable
 +
#!/bin/sh
 +
 +
. /lib/functions.sh
 +
. ../netifd-proto.sh
 +
init_proto "$@"
 +
 +
proto_bat_init_config() {
 +
no_device=1
 +
available=1
 +
renew_handler=1
 +
 +
proto_config_add_string 'gw_mode'
 +
}
 +
 +
lookup_site() {
 +
local path="$1" default="$2"
 +
lua -e "print(require('gluon.site').$path('$default'))"
 +
}
 +
 +
lookup_uci() {
 +
local path="$1" default="$2"
 +
uci -q get "$path" || echo "$default"
 +
}
 +
 +
proto_bat_renew() {
 +
local CONFIG="$1"
 +
 +
local ifname
 +
json_get_vars ifname
 +
 +
local IFNAME="${ifname:-$CONFIG}"
 +
 +
lock /var/lock/"$IFNAME".bat.lock
 +
 +
ubus call network.interface dump | jsonfilter \
 +
-e "@.interface[@.proto='batif' && @.data.mesh='${IFNAME:4}' && @.up=true].device" \
 +
| xargs -r -n 1 batctl -m "$IFNAME" interface add
 +
 +
lock -u /var/lock/"$IFNAME".bat.lock
 +
}
 +
 +
proto_bat_setup() {
 +
local CONFIG="$1"
 +
 +
local routing_algo=$(lookup_site 'mesh.batman_adv.routing_algo' 'BATMAN_IV')
 +
 +
local gw_mode ifname
 +
json_get_vars gw_mode ifname
 +
 +
local IFNAME="${ifname:-$CONFIG}"
 +
 +
batctl -m "$IFNAME" routing_algo "$routing_algo"
 +
batctl -m "$IFNAME" interface create
 +
 +
batctl -m "$IFNAME" orig_interval 5000
 +
batctl -m "$IFNAME" hop_penalty "$(lookup_uci 'gluon.mesh_batman_adv.hop_penalty' 15)"
 +
batctl -m "$IFNAME" multicast_mode 0
 +
 +
case "$gw_mode" in
 +
server)
 +
batctl -m "$IFNAME" gw_mode "server"
 +
;;
 +
client)
 +
local gw_sel_class="$(lookup_site 'mesh.batman_adv.gw_sel_class')"
 +
if [ -n "$gw_sel_class" ]; then
 +
batctl -m "$IFNAME" gw_mode "client" "$gw_sel_class"
 +
else
 +
batctl -m "$IFNAME" gw_mode "client"
 +
fi
 +
;;
 +
*)
 +
batctl -m "$IFNAME" gw_mode "off"
 +
;;
 +
esac
 +
 +
 +
local primary0_mac="$(lua -e 'print(require("gluon.util").generate_mac(3))')"
 +
 +
ip link add "pri-${IFNAME:4}" type dummy
 +
echo 1 > /proc/sys/net/ipv6/conf/"pri-${IFNAME:4}"/disable_ipv6
 +
ip link set "pri-${IFNAME:4}" address "$primary0_mac" mtu 1532 up
 +
 +
ip link set "$IFNAME" address "$(lua -e 'print(require("gluon.sysconfig").primary_mac)')"
 +
 +
batctl -m "$IFNAME" interface add "pri-${IFNAME:4}"
 +
 +
proto_init_update "pri-${IFNAME:4}" 1
 +
proto_init_update "$IFNAME" 1
 +
proto_send_update "$CONFIG"
 +
 +
proto_bat_renew "$1"
 +
}
 +
 +
proto_bat_teardown() {
 +
local CONFIG="$1"
 +
local IFNAME="$2"
 +
 +
batctl -m "$IFNAME" interface destroy
 +
ip link del "pri-${IFNAME:4}"
 +
}
 +
 +
add_protocol bat
 +
 +
=== /lib/netifd/proto/batif.sh ===
 +
Make executable
 +
#!/bin/sh
 +
 +
. /lib/functions.sh
 +
. ../netifd-proto.sh
 +
init_proto "$@"
 +
 +
proto_batif_init_config() {
 +
proto_config_add_string 'mesh'
 +
}
 +
 +
proto_batif_setup() {
 +
local CONFIG="$1"
 +
local IFNAME="$2"
 +
 +
local mesh
 +
json_get_vars mesh
 +
 +
ubus call network.interface."$CONFIG" set_data "{\"mesh\":\"$mesh\"}"
 +
 +
proto_init_update "$IFNAME" 1
 +
proto_send_update "$CONFIG"
 +
 +
ubus call network.interface."bat_${mesh}" renew
 +
}
 +
 +
proto_batif_teardown() {
 +
local CONFIG="$1"
 +
local IFNAME="$2"
 +
 +
batctl -m "bat-${mesh}" interface -M del "$IFNAME" 2>/dev/null
 +
}
 +
 +
add_protocol batif
 +
 +
=== Beispiel Netzwerkkonfiguration ===
 +
config interface 'mesh_vlan123'
 +
option ifname 'eth0.123'
 +
option proto 'batif'
 +
option mesh 'hood2'
 +
   
 +
config interface 'bat_hood2'
 +
option ifname 'bat-hood2'
 +
option gw_mode 'client'
 +
option proto 'bat'

Navigationsmenü