2
0

vti.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. vti_generic_setup() {
  9. local cfg="$1"
  10. local mode="$2"
  11. local local="$3"
  12. local remote="$4"
  13. local link="$5"
  14. local mtu zone ikey
  15. json_get_vars mtu zone ikey okey
  16. [ -z "$zone" ] && zone="wan"
  17. proto_init_update "$link" 1
  18. proto_add_tunnel
  19. json_add_string mode "$mode"
  20. json_add_int mtu "${mtu:-1280}"
  21. json_add_string local "$local"
  22. json_add_string remote "$remote"
  23. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  24. json_add_string info "${ikey:-0},${okey:-0}"
  25. proto_close_tunnel
  26. proto_add_data
  27. [ -n "$zone" ] && json_add_string zone "$zone"
  28. proto_close_data
  29. proto_send_update "$cfg"
  30. }
  31. vti_setup() {
  32. local cfg="$1"
  33. local mode="$2"
  34. local ipaddr peeraddr
  35. json_get_vars df ipaddr peeraddr tunlink
  36. [ -z "$peeraddr" ] && {
  37. proto_notify_error "$cfg" "MISSING_ADDRESS"
  38. proto_block_restart "$cfg"
  39. exit
  40. }
  41. ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
  42. [ -z "$ipaddr" ] && {
  43. local wanif="$tunlink"
  44. if [ -z $wanif ] && ! network_find_wan wanif; then
  45. proto_notify_error "$cfg" "NO_WAN_LINK"
  46. exit
  47. fi
  48. if ! network_get_ipaddr ipaddr "$wanif"; then
  49. proto_notify_error "$cfg" "NO_WAN_LINK"
  50. exit
  51. fi
  52. }
  53. vti_generic_setup $cfg $mode $ipaddr $peeraddr "vti-$cfg"
  54. }
  55. proto_vti_setup() {
  56. local cfg="$1"
  57. vti_setup $cfg "vtiip"
  58. }
  59. vti6_setup() {
  60. local cfg="$1"
  61. local mode="$2"
  62. local ip6addr peer6addr weakif
  63. json_get_vars ip6addr peer6addr tunlink weakif
  64. [ -z "$peer6addr" ] && {
  65. proto_notify_error "$cfg" "MISSING_ADDRESS"
  66. proto_block_restart "$cfg"
  67. exit
  68. }
  69. ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
  70. [ -z "$ip6addr" ] && {
  71. local wanif="$tunlink"
  72. if [ -z $wanif ] && ! network_find_wan6 wanif; then
  73. proto_notify_error "$cfg" "NO_WAN_LINK"
  74. exit
  75. fi
  76. if ! network_get_ipaddr6 ip6addr "$wanif"; then
  77. [ -z "$weakif" ] && weakif="lan"
  78. if ! network_get_ipaddr6 ip6addr "$weakif"; then
  79. proto_notify_error "$cfg" "NO_WAN_LINK"
  80. exit
  81. fi
  82. fi
  83. }
  84. vti_generic_setup $cfg $mode $ip6addr $peer6addr "vti6-$cfg"
  85. }
  86. proto_vti6_setup() {
  87. local cfg="$1"
  88. vti6_setup $cfg "vtiip6"
  89. }
  90. proto_vti_teardown() {
  91. local cfg="$1"
  92. }
  93. proto_vti6_teardown() {
  94. local cfg="$1"
  95. }
  96. vti_generic_init_config() {
  97. no_device=1
  98. available=1
  99. proto_config_add_int "mtu"
  100. proto_config_add_string "tunlink"
  101. proto_config_add_string "zone"
  102. proto_config_add_int "ikey"
  103. proto_config_add_int "okey"
  104. }
  105. proto_vti_init_config() {
  106. vti_generic_init_config
  107. proto_config_add_string "ipaddr"
  108. proto_config_add_string "peeraddr"
  109. }
  110. proto_vti6_init_config() {
  111. vti_generic_init_config
  112. proto_config_add_string "ip6addr"
  113. proto_config_add_string "peer6addr"
  114. proto_config_add_string "weakif"
  115. }
  116. [ -n "$INCLUDE_ONLY" ] || {
  117. [ -f /lib/modules/$(uname -r)/ip_vti.ko ] && add_protocol vti
  118. [ -f /lib/modules/$(uname -r)/ip6_vti.ko ] && add_protocol vti6
  119. }