ipip.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 df ipaddr peeraddr tunlink ttl tos zone mtu
  11. json_get_vars df ipaddr peeraddr tunlink ttl tos zone mtu
  12. [ -z "$peeraddr" ] && {
  13. proto_notify_error "$cfg" "MISSING_ADDRESS"
  14. proto_block_restart "$cfg"
  15. return
  16. }
  17. ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
  18. [ -z "$ipaddr" ] && {
  19. local wanif="$tunlink"
  20. if [ -z $wanif ] && ! network_find_wan wanif; then
  21. proto_notify_error "$cfg" "NO_WAN_LINK"
  22. return
  23. fi
  24. if ! network_get_ipaddr ipaddr "$wanif"; then
  25. proto_notify_error "$cfg" "NO_WAN_LINK"
  26. return
  27. fi
  28. }
  29. [ -z "$zone" ] && zone="wan"
  30. proto_init_update "ipip-$cfg" 1
  31. proto_add_tunnel
  32. json_add_string mode "ipip"
  33. json_add_int mtu "${mtu:-1280}"
  34. json_add_int ttl "${ttl:-64}"
  35. [ -n "$tos" ] && json_add_string tos "$tos"
  36. json_add_string local "$ipaddr"
  37. json_add_string remote "$peeraddr"
  38. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  39. json_add_boolean df "${df:-1}"
  40. proto_close_tunnel
  41. proto_add_data
  42. [ -n "$zone" ] && json_add_string zone "$zone"
  43. proto_close_data
  44. proto_send_update "$cfg"
  45. }
  46. proto_ipip_teardown() {
  47. local cfg="$1"
  48. }
  49. proto_ipip_init_config() {
  50. no_device=1
  51. available=1
  52. proto_config_add_int "mtu"
  53. proto_config_add_int "ttl"
  54. proto_config_add_string "tos"
  55. proto_config_add_string "tunlink"
  56. proto_config_add_string "zone"
  57. proto_config_add_string "ipaddr"
  58. proto_config_add_string "peeraddr"
  59. proto_config_add_boolean "df"
  60. }
  61. [ -n "$INCLUDE_ONLY" ] || {
  62. add_protocol ipip
  63. }