gluon_bat0.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . ../netifd-proto.sh
  4. init_proto "$@"
  5. proto_gluon_bat0_init_config() {
  6. no_device=1
  7. available=1
  8. renew_handler=1
  9. }
  10. proto_gluon_bat0_renew() {
  11. local config="$1"
  12. lock /var/lock/gluon_bat0.lock
  13. local ifdump="$(ubus call network.interface dump)"
  14. echo "$ifdump" | jsonfilter \
  15. -e "@.interface[@.proto='gluon_mesh' && @.up=true]['device','data']" \
  16. | while read dev; do
  17. read data
  18. echo bat0 > "/sys/class/net/$dev/batman_adv/mesh_iface"
  19. ! [ "$(echo "$data" | jsonfilter -e "@.transitive")" = 'true' ]
  20. transitive=$?
  21. (echo "$transitive" > "/sys/class/net/$dev/batman_adv/no_rebroadcast") 2>/dev/null
  22. done
  23. lock -u /var/lock/gluon_bat0.lock
  24. }
  25. proto_gluon_bat0_setup() {
  26. local config="$1"
  27. local primary0_mac="$(lua -lgluon.util -e 'print(gluon.util.generate_mac(3))')"
  28. ip link add primary0 type dummy
  29. echo 1 > /proc/sys/net/ipv6/conf/primary0/disable_ipv6
  30. ip link set primary0 address "$primary0_mac" mtu 1532 up
  31. local routing_algo="$(uci -q get batman-adv.bat0.routing_algo || echo 'BATMAN_IV')"
  32. (echo "$routing_algo" >/sys/module/batman_adv/parameters/routing_algo) 2>/dev/null
  33. echo bat0 > /sys/class/net/primary0/batman_adv/mesh_iface
  34. proto_init_update primary0 1
  35. proto_send_update "$config"
  36. proto_gluon_bat0_renew "$1"
  37. }
  38. proto_gluon_bat0_teardown() {
  39. local config="$1"
  40. ip link del bat0
  41. ip link del primary0
  42. }
  43. add_protocol gluon_bat0