Zeile 369: |
Zeile 369: |
| option ifname 'eth0.15' | | option ifname 'eth0.15' |
| option proto 'gluon_wired' | | option proto 'gluon_wired' |
| + | option disabled '0' |
| option transitive '1' | | option transitive '1' |
− | option disabled '0'
| |
| option macaddr '02:fb:e4:51:9a:15' | | option macaddr '02:fb:e4:51:9a:15' |
| | | |
| config interface 'mesh_vlan16' | | config interface 'mesh_vlan16' |
| option ifname 'eth0.16' | | option ifname 'eth0.16' |
− | option proto 'batif' | + | option proto 'agravis_wired' |
− | option mesh 'ol2' | + | option domain 'oldenburg2' |
| + | option domainif 'ol2' |
| + | option disabled '0' |
| + | option transitive '1' |
| option macaddr '02:fb:e4:51:9a:16' | | option macaddr '02:fb:e4:51:9a:16' |
| | | |
Zeile 382: |
Zeile 385: |
| option ifname 'eth0.17' | | option ifname 'eth0.17' |
| option proto 'gluon_wired' | | option proto 'gluon_wired' |
| + | option disabled '0' |
| option transitive '1' | | option transitive '1' |
− | option disabled '0'
| |
| option macaddr '02:fb:e4:51:9a:17' | | option macaddr '02:fb:e4:51:9a:17' |
| | | |
| config interface 'mesh_vlan18' | | config interface 'mesh_vlan18' |
| option ifname 'eth0.18' | | option ifname 'eth0.18' |
− | option index '0' | + | option proto 'gluon_wired' |
| + | option disabled '0' |
| option transitive '1' | | option transitive '1' |
− | option disabled '0'
| |
− | option proto 'gluon_wired'
| |
| option macaddr '02:fb:e4:51:9a:18' | | option macaddr '02:fb:e4:51:9a:18' |
| | | |
Zeile 473: |
Zeile 475: |
| config interface 'mesh_vlan30' | | config interface 'mesh_vlan30' |
| option ifname 'eth0.30' | | option ifname 'eth0.30' |
− | option proto 'batif' | + | option proto 'agravis_wired' |
− | option mesh 'rastede' | + | option domain 'rastede' |
| + | option domainif 'rastede' |
| + | option disabled '0' |
| + | option transitive '1' |
| option macaddr '02:fb:e4:51:9a:30' | | option macaddr '02:fb:e4:51:9a:30' |
| | | |
| config interface 'mesh_vlan31' | | config interface 'mesh_vlan31' |
| option ifname 'eth0.31' | | option ifname 'eth0.31' |
− | option proto 'batif' | + | option proto 'agravis_wired' |
− | option mesh 'ol2' | + | option domain 'oldenburg2' |
| + | option domainif 'ol2' |
| + | option disabled '0' |
| + | option transitive '1' |
| option macaddr '02:fb:e4:51:9a:31' | | option macaddr '02:fb:e4:51:9a:31' |
| | | |
Zeile 611: |
Zeile 619: |
| config interface 'mesh_vlan50' | | config interface 'mesh_vlan50' |
| option ifname 'eth0.50' | | option ifname 'eth0.50' |
− | option proto 'batif' | + | option proto 'agravis_wired' |
− | option mesh 'ol2' | + | option domain 'oldenburg2' |
| + | option domainif 'ol2' |
| + | option disabled '0' |
| + | option transitive '1' |
| option macaddr '02:fb:e4:51:9a:50' | | option macaddr '02:fb:e4:51:9a:50' |
| | | |
Zeile 747: |
Zeile 758: |
| option transitive '1' | | option transitive '1' |
| option macaddr '02:fb:e4:51:9a:69' | | option macaddr '02:fb:e4:51:9a:69' |
| + | |
| + | config interface 'agravis_bat_ol2' |
| + | option gw_mode 'client' |
| + | option proto 'agravis_bat' |
| + | option domain 'oldenburg2' |
| + | option domainif 'ol2' |
| | | |
| config interface 'bat_ol2' | | config interface 'bat_ol2' |
| + | option multicast_router '2' |
| option ifname 'bat-ol2' | | option ifname 'bat-ol2' |
| + | option auto '1' |
| + | option macaddr 'b4:fb:e4:51:9a:46' |
| + | option learning '1' |
| + | option proto 'none' |
| + | |
| + | config interface 'agravis_bat_rastede' |
| option gw_mode 'client' | | option gw_mode 'client' |
− | option proto 'bat' | + | option proto 'agravis_bat' |
| + | option domain 'rastede' |
| + | option domainif 'rastede' |
| | | |
| config interface 'bat_rastede' | | config interface 'bat_rastede' |
| + | option multicast_router '2' |
| option ifname 'bat-rastede' | | option ifname 'bat-rastede' |
− | option gw_mode 'client'
| + | option auto '1' |
− | option proto 'bat'
| + | option macaddr 'b4:fb:e4:51:9a:46' |
| + | option learning '1' |
| + | option proto 'none' |
| | | |
| config interface 'mgmt' | | config interface 'mgmt' |
Zeile 800: |
Zeile 829: |
| | | |
| == Multihood == | | == Multihood == |
− | | + | /lib/gluon/upgrade/742-agravis |
− | === /lib/netifd/proto/bat.sh ===
| |
− | Make executable
| |
| #!/bin/sh | | #!/bin/sh |
− | | + | function mkifsetupteardown() { |
− | . /lib/functions.sh
| + | mkdir "$2" |
− | . ../netifd-proto.sh
| + | find "$1" -type d -print | sed -n "s|^$1/||p" | while IFS= read -r dir; do |
− | init_proto "$@"
| + | mkdir "$2/$dir" |
− |
| + | done |
− | proto_bat_init_config() {
| + | find "$1" -type f -print | sed -n "s|^$1/||p" | while IFS= read -r file; do |
− | no_device=1 | + | sed 's/gluon_bat0/agravis_bat_$DOMAINIF/' "$1/$file" > "$2/$file" |
− | available=1
| + | <nowiki> </nowiki> chmod +x "$2/$file" |
− | renew_handler=1
| + | done |
− | | |
− | proto_config_add_string 'gw_mode' | |
| } | | } |
| | | |
− | lookup_site() { | + | mkifsetupteardown "/lib/gluon/core/mesh/setup.d" "/lib/gluon/core/mesh/agravis-setup.d" |
− | local path="$1" default="$2"
| + | mkifsetupteardown "/lib/gluon/core/mesh/post-setup.d" "/lib/gluon/core/mesh/agravis-post-setup.d" |
− | lua -e "print(require('gluon.site').$path('$default'))"
| + | mkifsetupteardown "/lib/gluon/core/mesh/teardown.d" "/lib/gluon/core/mesh/agravis-teardown.d" |
− | } | |
| | | |
− | lookup_uci() { | + | <nowiki>#</nowiki> TODO lua -e "print(require('gluon.site').$path('$default'))" returning correct site? |
− | local path="$1" default="$2"
| + | sed -e 's/gluon_bat0.lock/agravis_bat_$domainif.lock/' \ |
− | uci -q get "$path" || echo "$default"
| + | <nowiki> </nowiki> -e 's/gluon_bat0/agravis_bat/' \ |
− | } | + | <nowiki> </nowiki> -e 's/local gw_mode/local gw_mode domain domainif/' \ |
| + | <nowiki> </nowiki> -e 's/json_get_vars gw_mode/json_get_vars gw_mode domain domainif/' \ |
| + | <nowiki> </nowiki> -e 's/primary0_/pri_/' \ |
| + | <nowiki> </nowiki> -e 's/primary0/pri-$domainif/' \ |
| + | <nowiki> </nowiki> -e 's/batctl/batctl -m "bat-$domainif"/' \ |
| + | <nowiki> </nowiki> -e '/^proto_agravis_bat_renew() {$/{N;s/proto_agravis_bat_renew() {\n\tlocal config="$1"/proto_agravis_bat_renew() {\n\tlocal config="$1"\n\n\tlocal domain domainif\n\tjson_get_vars domain domainif/}' \ |
| + | <nowiki> </nowiki> -e '/^proto_agravis_bat_teardown() {$/{N;s/proto_agravis_bat_teardown() {\n\tlocal config="$1"/proto_agravis_bat_teardown() {\n\tlocal config="$1"\n\n\tlocal domain domainif\n\tjson_get_vars domain domainif/}' \ |
| + | <nowiki> </nowiki> -e "s/@.proto='gluon_mesh'/@.proto='agravis_mesh' \&\& @.data.domainif='\$domainif'/" \ |
| + | <nowiki> </nowiki> -e "s/proto_config_add_string 'gw_mode'/proto_config_add_string 'gw_mode'\n\tproto_config_add_string 'domain'\n\tproto_config_add_string 'domainif'/" \ |
| + | <nowiki> </nowiki> /lib/netifd/proto/gluon_bat0.sh >/lib/netifd/proto/agravis_bat.sh |
| + | chmod +x /lib/netifd/proto/agravis_bat.sh |
| | | |
− | proto_bat_renew() { | + | sed -e 's/gluon_mesh/agravis_mesh/' \ |
− | local CONFIG="$1"
| + | <nowiki> </nowiki> -e 's!/lib/gluon/core/mesh/!/lib/gluon/core/mesh/agravis-!' \ |
− |
| + | <nowiki> </nowiki> -e 's/local fixed_mtu transitive/local fixed_mtu transitive domain domainif/' \ |
− | local ifname
| + | <nowiki> </nowiki> -e 's/json_get_vars fixed_mtu transitive/json_get_vars fixed_mtu transitive domain domainif/' \ |
− | json_get_vars ifname
| + | <nowiki> </nowiki> -e 's/export TRANSITIVE="${transitive:-0}"/export TRANSITIVE="${transitive:-0}"\n\texport DOMAIN="$domain"\n\texport DOMAINIF="$domainif"/' \ |
− |
| + | <nowiki> </nowiki> -e 's/json_add_boolean transitive "$TRANSITIVE"/json_add_boolean transitive "$TRANSITIVE"\n\tjson_add_string domain "$DOMAIN"\n\tjson_add_string domainif "$DOMAINIF"/' \ |
− | local IFNAME="${ifname:-$CONFIG}"
| + | <nowiki> </nowiki> -e 's/proto_config_add_boolean transitive/proto_config_add_boolean transitive\n\tproto_config_add_string domain\n\tproto_config_add_string domainif/' \ |
| + | <nowiki> </nowiki> -e 's!for script in /lib/gluon/core/mesh/agravis-teardown.d/!local domain domainif\n\tjson_get_vars domain domainif\n\texport DOMAIN="$domain"\n\texport DOMAINIF="$domainif"\n\n\tfor script in /lib/gluon/core/mesh/agravis-teardown.d/!' \ |
| + | <nowiki> </nowiki> /lib/netifd/proto/gluon_mesh.sh >/lib/netifd/proto/agravis_mesh.sh |
| + | chmod +x /lib/netifd/proto/agravis_mesh.sh |
| | | |
− | lock /var/lock/"$IFNAME".bat.lock
| + | sed -e 's/gluon_wired/agravis_wired/' \ |
| + | <nowiki> </nowiki> -e 's/proto_config_add_string vxpeer6addr/proto_config_add_string vxpeer6addr\n\tproto_config_add_string domain\n\tproto_config_add_string domainif/' \ |
| + | <nowiki> </nowiki> -e 's/local transitive index vxlan vxpeer6addr/local transitive index vxlan vxpeer6addr domain domainif/' \ |
| + | <nowiki> </nowiki> -e 's/json_get_vars transitive index vxlan vxpeer6addr/json_get_vars transitive index vxlan vxpeer6addr domain domainif/' \ |
| + | <nowiki> </nowiki> -e "s/json_add_string proto 'gluon_mesh'/json_add_string proto 'agravis_mesh'\n\tjson_add_string domain \"\$domain\"\n\tjson_add_string domainif \"\$domainif\"/" \ |
| + | <nowiki> </nowiki> -e "s#require(\"gluon.util\").domain_seed_bytes(#require(\"gluon.agravis\").domain_seed_bytes(\"'\"\$(cat /lib/gluon/domains/\"\$domain\".json | jsonfilter -e \"@.domain_seed\")\"'\", #" \ |
| + | <nowiki> </nowiki> /lib/netifd/proto/gluon_wired.sh >/lib/netifd/proto/agravis_wired.sh |
| + | chmod +x /lib/netifd/proto/agravis_wired.sh |
| | | |
− | ubus call network.interface dump | jsonfilter \
| + | cat <<EOF >/usr/lib/lua/gluon/agravis.lua |
− | -e "@.interface[@.proto='batif' && @.data.mesh='${IFNAME:4}' && @.up=true].device" \
| + | local util = require 'gluon.util' |
− | | xargs -r -n 1 batctl -m "$IFNAME" interface add
| |
| | | |
− | lock -u /var/lock/"$IFNAME".bat.lock
| + | local M = {} |
− | } | |
− |
| |
− | 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() { | + | function M.domain_seed_bytes(domain_seed, key, length) |
− | local CONFIG="$1" | + | local ret = <nowiki>''</nowiki> |
− | local IFNAME="$2" | + | local v = <nowiki>''</nowiki> |
| + | local i = 0 |
| | | |
− | batctl -m "$IFNAME" interface destroy | + | -- Inspired by HKDF key expansion, but much simpler, as we don't need |
− | ip link del "pri-${IFNAME:4}" | + | -- cryptographic strength |
− | }
| + | while ret:len() < 2*length do |
| + | i = i + 1 |
| + | v = hash.md5(v .. key .. domain_seed:lower() .. i) |
| + | ret = ret .. v |
| + | end |
| | | |
− | add_protocol bat
| + | return ret:sub(0, 2*length) |
− | | + | end |
− | === /lib/netifd/proto/batif.sh ===
| |
− | Make executable
| |
− | #!/bin/sh | |
| | | |
− | . /lib/functions.sh | + | return M |
− | . ../netifd-proto.sh | + | EOF |
− | init_proto "$@"
| |
| | | |
− | proto_batif_init_config() { | + | sed -i "s/@.proto='gluon_mesh'/(@.proto='gluon_mesh' || @.proto='agravis_mesh')/" /etc/init.d/gluon-respondd |
− | 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'
| |