gluon_wired.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . ../netifd-proto.sh
  4. init_proto "$@"
  5. proto_gluon_wired_init_config() {
  6. proto_config_add_boolean transitive
  7. proto_config_add_int index
  8. proto_config_add_boolean legacy
  9. }
  10. xor2() {
  11. echo -n "${1:0:1}"
  12. echo -n "${1:1:1}" | tr '0123456789abcdef' '23016745ab89efcd'
  13. }
  14. interface_linklocal() {
  15. local macaddr="$(ubus call network.device status '{"name": "'"$1"'"}' | jsonfilter -e '@.macaddr')"
  16. local oldIFS="$IFS"; IFS=':'; set -- $macaddr; IFS="$oldIFS"
  17. echo "fe80::$(xor2 "$1")$2:$3ff:fe$4:$5$6"
  18. }
  19. proto_gluon_wired_setup() {
  20. local config="$1"
  21. local ifname="$2"
  22. local meshif="$config"
  23. local transitive index legacy
  24. json_get_vars transitive index legacy
  25. proto_init_update "$ifname" 1
  26. proto_send_update "$config"
  27. if [ "${legacy:-0}" -eq 0 ]; then
  28. meshif="vx_$config"
  29. json_init
  30. json_add_string name "$meshif"
  31. [ -n "$index" ] && json_add_string macaddr "$(lua -lgluon.util -e "print(gluon.util.generate_mac($index))")"
  32. json_add_string proto 'vxlan6'
  33. json_add_string tunlink "$config"
  34. json_add_string ip6addr "$(interface_linklocal "$ifname")"
  35. json_add_string peer6addr 'ff02::15c'
  36. json_add_int vid "$(lua -lgluon.util -e 'print(tonumber(gluon.util.domain_seed_bytes("gluon-mesh-vxlan", 3), 16))')"
  37. json_add_boolean rxcsum '0'
  38. json_close_object
  39. ubus call network add_dynamic "$(json_dump)"
  40. fi
  41. json_init
  42. json_add_string name "${config}_mesh"
  43. json_add_string ifname "@${meshif}"
  44. json_add_string proto 'gluon_mesh'
  45. json_add_boolean fixed_mtu 1
  46. [ -n "$transitive" ] && json_add_boolean transitive "$transitive"
  47. json_close_object
  48. ubus call network add_dynamic "$(json_dump)"
  49. }
  50. proto_gluon_wired_teardown() {
  51. local config="$1"
  52. proto_init_update "*" 0
  53. proto_send_update "$config"
  54. }
  55. add_protocol gluon_wired