2 # dslite.sh - IPv4-in-IPv6 tunnel backend for ipip6 and ds-lite
3 # Copyright (c) 2013 OpenWrt.org
4 # Copyright (c) 2013 Steven Barth <steven@midlink.org>
5 # Copyright (c) 2021 Kenji Uno <ku@digitaldolphins.jp>
6 # Copyright (c) 2024 Arayuki Mago <ms@missing233.com>
8 [ -n "$INCLUDE_ONLY" ] ||
{
10 .
/lib
/functions
/network.sh
21 local link
="$tnl_type-$cfg"
24 local mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
25 json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
27 [ -z "$peeraddr" ] && {
28 proto_notify_error
"$cfg" "MISSING_ADDRESS"
29 proto_block_restart
"$cfg"
33 ( proto_add_host_dependency
"$cfg" "::" "$tunlink" )
35 remoteip6
=$
(resolveip
-6 "$peeraddr")
36 if [ -z "$remoteip6" ]; then
38 remoteip6
=$
(resolveip
-6 "$peeraddr")
39 if [ -z "$remoteip6" ]; then
40 proto_notify_error
"$cfg" "AFTR_DNS_FAIL"
45 for ip6
in $remoteip6; do
50 [ -z "$ip6addr" ] && {
51 local wanif
="$tunlink"
52 if [ -z "$wanif" ] && ! network_find_wan6 wanif
; then
53 proto_notify_error
"$cfg" "NO_WAN_LINK"
57 if ! network_get_ipaddr6 ip6addr
"$wanif"; then
58 [ -z "$weakif" ] && weakif
="lan"
59 if ! network_get_ipaddr6 ip6addr
"$weakif"; then
60 proto_notify_error
"$cfg" "NO_WAN_LINK"
66 proto_init_update
"$link" 1
67 proto_add_ipv4_route
"0.0.0.0" 0
68 proto_add_ipv4_address
"$ip4addr" "" "" "$ip4gateway"
71 json_add_string mode ipip6
72 json_add_int mtu
"${mtu:-1280}"
73 json_add_int ttl
"${ttl:-64}"
74 json_add_string
local "$ip6addr"
75 json_add_string remote
"$peeraddr"
76 [ -n "$tunlink" ] && json_add_string link
"$tunlink"
77 json_add_object
"data"
78 [ -n "$encaplimit" ] && json_add_string encaplimit
"$encaplimit"
83 [ -n "$zone" ] && json_add_string zone
"$zone"
85 if [ "$tnl_type" = "ds" ]; then
86 json_add_array firewall
88 json_add_string
type nat
89 json_add_string target ACCEPT
96 proto_send_update
"$cfg"
103 proto_config_add_string
"ip6addr"
104 proto_config_add_string
"peeraddr"
105 proto_config_add_string
"tunlink"
106 proto_config_add_int
"mtu"
107 proto_config_add_int
"ttl"
108 proto_config_add_string
"encaplimit"
109 proto_config_add_string
"zone"
110 proto_config_add_string
"weakif"
113 proto_ipip6_init_config
() {
115 proto_config_add_string
"ip4ifaddr"
118 proto_ipip6_setup
() {
120 json_get_vars ip4ifaddr
121 tnl_setup
"$1" "$2" "ipip6" "$ip4ifaddr" "0.0.0.0"
124 proto_ipip6_teardown
() {
128 proto_dslite_init_config
() {
132 proto_dslite_setup
() {
133 tnl_setup
"$1" "$2" "ds" "192.0.0.2" "192.0.0.1"
136 proto_dslite_teardown
() {
140 [ -n "$INCLUDE_ONLY" ] ||
{