mediatek: add firmware name for AQR PHYs on mt7988a-rfb
[openwrt/openwrt.git] / package / network / ipv6 / ds-lite / files / dslite.sh
1 #!/bin/sh
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>
7
8 [ -n "$INCLUDE_ONLY" ] || {
9 . /lib/functions.sh
10 . /lib/functions/network.sh
11 . ../netifd-proto.sh
12 init_proto "$@"
13 }
14
15 tnl_setup() {
16 local cfg="$1"
17 local iface="$2"
18 local tnl_type="$3"
19 local ip4addr="$4"
20 local ip4gateway="$5"
21 local link="$tnl_type-$cfg"
22 local remoteip6
23
24 local mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
25 json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif encaplimit
26
27 [ -z "$peeraddr" ] && {
28 proto_notify_error "$cfg" "MISSING_ADDRESS"
29 proto_block_restart "$cfg"
30 return
31 }
32
33 ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
34
35 remoteip6=$(resolveip -6 "$peeraddr")
36 if [ -z "$remoteip6" ]; then
37 sleep 3
38 remoteip6=$(resolveip -6 "$peeraddr")
39 if [ -z "$remoteip6" ]; then
40 proto_notify_error "$cfg" "AFTR_DNS_FAIL"
41 return
42 fi
43 fi
44
45 for ip6 in $remoteip6; do
46 peeraddr=$ip6
47 break
48 done
49
50 [ -z "$ip6addr" ] && {
51 local wanif="$tunlink"
52 if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
53 proto_notify_error "$cfg" "NO_WAN_LINK"
54 return
55 fi
56
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"
61 return
62 fi
63 fi
64 }
65
66 proto_init_update "$link" 1
67 proto_add_ipv4_route "0.0.0.0" 0
68 proto_add_ipv4_address "$ip4addr" "" "" "$ip4gateway"
69
70 proto_add_tunnel
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"
79 json_close_object
80 proto_close_tunnel
81
82 proto_add_data
83 [ -n "$zone" ] && json_add_string zone "$zone"
84
85 if [ "$tnl_type" = "ds" ]; then
86 json_add_array firewall
87 json_add_object ""
88 json_add_string type nat
89 json_add_string target ACCEPT
90 json_close_object
91 json_close_array
92 fi
93
94 proto_close_data
95
96 proto_send_update "$cfg"
97 }
98
99 init_config() {
100 no_device=1
101 available=1
102
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"
111 }
112
113 proto_ipip6_init_config() {
114 init_config
115 proto_config_add_string "ip4ifaddr"
116 }
117
118 proto_ipip6_setup() {
119 local ip4ifaddr
120 json_get_vars ip4ifaddr
121 tnl_setup "$1" "$2" "ipip6" "$ip4ifaddr" "0.0.0.0"
122 }
123
124 proto_ipip6_teardown() {
125 local cfg="$1"
126 }
127
128 proto_dslite_init_config() {
129 init_config
130 }
131
132 proto_dslite_setup() {
133 tnl_setup "$1" "$2" "ds" "192.0.0.2" "192.0.0.1"
134 }
135
136 proto_dslite_teardown() {
137 local cfg="$1"
138 }
139
140 [ -n "$INCLUDE_ONLY" ] || {
141 add_protocol ipip6
142 add_protocol dslite
143 }