gluon_bat0.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. echo bat0 > /sys/class/net/primary0/batman_adv/mesh_iface
  32. proto_init_update primary0 1
  33. proto_send_update "$config"
  34. proto_gluon_bat0_renew "$1"
  35. }
  36. proto_gluon_bat0_teardown() {
  37. local config="$1"
  38. ip link del bat0
  39. ip link del primary0
  40. }
  41. add_protocol gluon_bat0