dslite.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. peeraddr="${remoteip6%% *}"
  33. [ -z "$ip6addr" ] && {
  34. local wanif="$tunlink"
  35. if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
  36. proto_notify_error "$cfg" "NO_WAN_LINK"
  37. return
  38. fi
  39. if ! network_get_ipaddr6 ip6addr "$wanif"; then
  40. [ -z "$weakif" ] && weakif="lan"
  41. if ! network_get_ipaddr6 ip6addr "$weakif"; then
  42. proto_notify_error "$cfg" "NO_WAN_LINK"
  43. return
  44. fi
  45. fi
  46. }
  47. proto_init_update "$link" 1
  48. proto_add_ipv4_route "0.0.0.0" 0
  49. proto_add_ipv4_address "192.0.0.2" "" "" "192.0.0.1"
  50. proto_add_tunnel
  51. json_add_string mode ipip6
  52. json_add_int mtu "${mtu:-1280}"
  53. json_add_int ttl "${ttl:-64}"
  54. json_add_string local "$ip6addr"
  55. json_add_string remote "$peeraddr"
  56. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  57. proto_close_tunnel
  58. proto_add_data
  59. [ -n "$zone" ] && json_add_string zone "$zone"
  60. json_add_array firewall
  61. json_add_object ""
  62. json_add_string type nat
  63. json_add_string target ACCEPT
  64. json_close_object
  65. json_close_array
  66. proto_close_data
  67. proto_send_update "$cfg"
  68. }
  69. proto_dslite_teardown() {
  70. local cfg="$1"
  71. }
  72. proto_dslite_init_config() {
  73. no_device=1
  74. available=1
  75. proto_config_add_string "ip6addr"
  76. proto_config_add_string "peeraddr"
  77. proto_config_add_string "tunlink"
  78. proto_config_add_int "mtu"
  79. proto_config_add_int "ttl"
  80. proto_config_add_string "zone"
  81. proto_config_add_string "weakif"
  82. }
  83. [ -n "$INCLUDE_ONLY" ] || {
  84. add_protocol dslite
  85. }