2
0

dslite.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. # dslite.sh - IPv4-in-IPv6 tunnel backend
  3. # Copyright (c) 2013 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_dslite_setup() {
  11. local cfg="$1"
  12. local iface="$2"
  13. local link="ds-$cfg"
  14. local remoteip6
  15. local mtu ttl peeraddr ip6addr tunlink zone weakif
  16. json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif
  17. [ -z "$peeraddr" ] && {
  18. proto_notify_error "$cfg" "MISSING_ADDRESS"
  19. proto_block_restart "$cfg"
  20. return
  21. }
  22. ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
  23. remoteip6=$(resolveip -6 "$peeraddr")
  24. if [ -z "$remoteip6" ]; then
  25. sleep 3
  26. remoteip6=$(resolveip -6 "$peeraddr")
  27. if [ -z "$remoteip6" ]; then
  28. proto_notify_error "$cfg" "AFTR_DNS_FAIL"
  29. return
  30. fi
  31. fi
  32. for ip6 in $remoteip6; do
  33. peeraddr=$ip6
  34. break
  35. done
  36. [ -z "$ip6addr" ] && {
  37. local wanif="$tunlink"
  38. if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
  39. proto_notify_error "$cfg" "NO_WAN_LINK"
  40. return
  41. fi
  42. if ! network_get_ipaddr6 ip6addr "$wanif"; then
  43. [ -z "$weakif" ] && weakif="lan"
  44. if ! network_get_ipaddr6 ip6addr "$weakif"; then
  45. proto_notify_error "$cfg" "NO_WAN_LINK"
  46. return
  47. fi
  48. fi
  49. }
  50. proto_init_update "$link" 1
  51. proto_add_ipv4_route "0.0.0.0" 0
  52. proto_add_ipv4_address "192.0.0.2" "" "" "192.0.0.1"
  53. proto_add_tunnel
  54. json_add_string mode ipip6
  55. json_add_int mtu "${mtu:-1280}"
  56. json_add_int ttl "${ttl:-64}"
  57. json_add_string local "$ip6addr"
  58. json_add_string remote "$peeraddr"
  59. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  60. proto_close_tunnel
  61. proto_add_data
  62. [ -n "$zone" ] && json_add_string zone "$zone"
  63. json_add_array firewall
  64. json_add_object ""
  65. json_add_string type nat
  66. json_add_string target ACCEPT
  67. json_close_object
  68. json_close_array
  69. proto_close_data
  70. proto_send_update "$cfg"
  71. }
  72. proto_dslite_teardown() {
  73. local cfg="$1"
  74. }
  75. proto_dslite_init_config() {
  76. no_device=1
  77. available=1
  78. proto_config_add_string "ip6addr"
  79. proto_config_add_string "peeraddr"
  80. proto_config_add_string "tunlink"
  81. proto_config_add_int "mtu"
  82. proto_config_add_int "ttl"
  83. proto_config_add_string "zone"
  84. proto_config_add_string "weakif"
  85. }
  86. [ -n "$INCLUDE_ONLY" ] || {
  87. add_protocol dslite
  88. }