1
0

ipip.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. proto_init_update "ipip-$cfg" 1
  40. proto_add_tunnel
  41. json_add_string mode "ipip"
  42. json_add_int mtu "${mtu:-1280}"
  43. json_add_int ttl "${ttl:-64}"
  44. [ -n "$tos" ] && json_add_string tos "$tos"
  45. json_add_string local "$ipaddr"
  46. json_add_string remote "$peeraddr"
  47. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  48. json_add_boolean df "${df:-1}"
  49. proto_close_tunnel
  50. proto_add_data
  51. [ -n "$zone" ] && json_add_string zone "$zone"
  52. proto_close_data
  53. proto_send_update "$cfg"
  54. }
  55. proto_ipip_teardown() {
  56. local cfg="$1"
  57. }
  58. proto_ipip_init_config() {
  59. no_device=1
  60. available=1
  61. proto_config_add_int "mtu"
  62. proto_config_add_int "ttl"
  63. proto_config_add_string "tos"
  64. proto_config_add_string "tunlink"
  65. proto_config_add_string "zone"
  66. proto_config_add_string "ipaddr"
  67. proto_config_add_string "peeraddr"
  68. proto_config_add_boolean "df"
  69. }
  70. [ -n "$INCLUDE_ONLY" ] || {
  71. add_protocol ipip
  72. }