ipip.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. [ -n "$INCLUDE_ONLY" ] || {
  3. . /lib/functions.sh
  4. . /lib/functions/network.sh
  5. . ../netifd-proto.sh
  6. init_proto "$@"
  7. }
  8. proto_ipip_setup() {
  9. local cfg="$1"
  10. local remoteip
  11. local df ipaddr peeraddr tunlink ttl tos zone mtu
  12. json_get_vars df ipaddr peeraddr tunlink ttl tos zone mtu
  13. [ -z "$peeraddr" ] && {
  14. proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
  15. proto_block_restart "$cfg"
  16. return
  17. }
  18. remoteip=$(resolveip -t 10 -4 "$peeraddr")
  19. if [ -z "$remoteip" ]; then
  20. proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
  21. return
  22. fi
  23. for ip in $remoteip; do
  24. peeraddr=$ip
  25. break
  26. done
  27. ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
  28. [ -z "$ipaddr" ] && {
  29. local wanif="$tunlink"
  30. if [ -z $wanif ] && ! network_find_wan wanif; then
  31. proto_notify_error "$cfg" "NO_WAN_LINK"
  32. return
  33. fi
  34. if ! network_get_ipaddr ipaddr "$wanif"; then
  35. proto_notify_error "$cfg" "NO_WAN_LINK"
  36. return
  37. fi
  38. }
  39. [ -z "$zone" ] && zone="wan"
  40. proto_init_update "ipip-$cfg" 1
  41. proto_add_tunnel
  42. json_add_string mode "ipip"
  43. json_add_int mtu "${mtu:-1280}"
  44. json_add_int ttl "${ttl:-64}"
  45. [ -n "$tos" ] && json_add_string tos "$tos"
  46. json_add_string local "$ipaddr"
  47. json_add_string remote "$peeraddr"
  48. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  49. json_add_boolean df "${df:-1}"
  50. proto_close_tunnel
  51. proto_add_data
  52. [ -n "$zone" ] && json_add_string zone "$zone"
  53. proto_close_data
  54. proto_send_update "$cfg"
  55. }
  56. proto_ipip_teardown() {
  57. local cfg="$1"
  58. }
  59. proto_ipip_init_config() {
  60. no_device=1
  61. available=1
  62. proto_config_add_int "mtu"
  63. proto_config_add_int "ttl"
  64. proto_config_add_string "tos"
  65. proto_config_add_string "tunlink"
  66. proto_config_add_string "zone"
  67. proto_config_add_string "ipaddr"
  68. proto_config_add_string "peeraddr"
  69. proto_config_add_boolean "df"
  70. }
  71. [ -n "$INCLUDE_ONLY" ] || {
  72. add_protocol ipip
  73. }