You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.0 KiB

  1. #!/bin/sh
  2. # aiccu.sh - AICCU proto
  3. # Copyright (c) 2014 OpenWrt.org
  4. [ -n "$INCLUDE_ONLY" ] || {
  5. . /lib/functions.sh
  6. . /lib/functions/network.sh
  7. . ../netifd-proto.sh
  8. init_proto "$@"
  9. }
  10. proto_aiccu_setup() {
  11. local cfg="$1"
  12. local iface="$2"
  13. local link="aiccu-$cfg"
  14. local username password protocol server ip6prefix tunnelid requiretls defaultroute nat heartbeat verbose sourcerouting ip6addr
  15. json_get_vars username password protocol server ip6prefix tunnelid requiretls defaultroute nat heartbeat verbose sourcerouting ip6addr
  16. [ -z "$username" -o -z "$password" ] && {
  17. proto_notify_error "$cfg" "MISSING_USERNAME_OR_PASSWORD"
  18. proto_block_restart "$cfg"
  19. return
  20. }
  21. ( proto_add_host_dependency "$cfg" 0.0.0.0 )
  22. CFGFILE="/var/etc/${link}.conf"
  23. PIDFILE="/var/run/${link}.pid"
  24. mkdir -p /var/run /var/etc
  25. echo "username $username" > "$CFGFILE"
  26. echo "password $password" >> "$CFGFILE"
  27. echo "ipv6_interface $link" >> "$CFGFILE"
  28. [ -n "$server" ] && echo "server $server" >> "$CFGFILE"
  29. [ -n "$protocol" ] && echo "protocol $protocol" >> "$CFGFILE"
  30. [ -n "$tunnel_id" ] && echo "tunnel_id $tunnel_id" >> "$CFGFILE"
  31. [ -n "$requiretls" ] && echo "requiretls $requiretls" >> "$CFGFILE"
  32. [ "$nat" == 1 ] && echo "behindnat true" >> "$CFGFILE"
  33. [ "$heartbeat" == 1 ] && echo "makebeats true" >> "$CFGFILE"
  34. [ "$verbose" == 1 ] && echo "verbose true" >> "$CFGFILE"
  35. echo "defaultroute false" >> "$CFGFILE"
  36. echo "daemonize true" >> "$CFGFILE"
  37. echo "pidfile $PIDFILE" >> "$CFGFILE"
  38. aiccu start "$CFGFILE"
  39. [ "$?" -ne 0 ] && {
  40. proto_notify_error "$cfg" "AICCU_FAILED_SEE_LOG"
  41. proto_block_restart "$cfg"
  42. return
  43. }
  44. proto_init_update "$link" 1
  45. local source=""
  46. [ "$sourcerouting" != "0" ] && source="::/128"
  47. [ "$defaultroute" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$source"
  48. [ -n "$ip6addr" ] && {
  49. local local6="${ip6addr%%/*}"
  50. local mask6="${ip6addr##*/}"
  51. [[ "$local6" = "$mask6" ]] && mask6=
  52. proto_add_ipv6_address "$local6" "$mask6"
  53. [ "$defaultroute" != "0" -a "$sourcerouting" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$local6/$mask6"
  54. }
  55. [ -n "$ip6prefix" ] && {
  56. proto_add_ipv6_prefix "$ip6prefix"
  57. [ "$defaultroute" != "0" -a "$sourcerouting" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$ip6prefix"
  58. }
  59. proto_send_update "$cfg"
  60. }
  61. proto_aiccu_teardown() {
  62. local cfg="$1"
  63. local link="aiccu-$cfg"
  64. CFGFILE="/var/etc/${link}.conf"
  65. aiccu stop "$CFGFILE"
  66. }
  67. proto_aiccu_init_config() {
  68. no_device=1
  69. available=1
  70. proto_config_add_string "username"
  71. proto_config_add_string "password"
  72. proto_config_add_string "protocol"
  73. proto_config_add_string "server"
  74. proto_config_add_string "ip6addr:ip6addr"
  75. proto_config_add_string "ip6prefix:ip6addr"
  76. proto_config_add_string "tunnelid"
  77. proto_config_add_boolean "requiretls"
  78. proto_config_add_boolean "defaultroute"
  79. proto_config_add_boolean "sourcerouting"
  80. proto_config_add_boolean "nat"
  81. proto_config_add_boolean "heartbeat"
  82. proto_config_add_boolean "verbose"
  83. }
  84. [ -n "$INCLUDE_ONLY" ] || {
  85. add_protocol aiccu
  86. }