3 [ -n "$INCLUDE_ONLY" ] ||
{
5 .
/lib
/functions
/network.sh
16 local mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno multicast
17 json_get_vars mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno multicast
19 [ -z "$multicast" ] && multicast
=1
21 proto_init_update
"$link" 1
24 json_add_string mode
"$mode"
25 json_add_int mtu
"${mtu:-1280}"
26 [ -n "$df" ] && json_add_boolean df
"$df"
27 [ -n "$ttl" ] && json_add_int ttl
"$ttl"
28 [ -n "$tos" ] && json_add_string tos
"$tos"
29 json_add_boolean multicast
"$multicast"
30 json_add_string
local "$local"
31 json_add_string remote
"$remote"
32 [ -n "$tunlink" ] && json_add_string link
"$tunlink"
34 json_add_object
'data'
35 [ -n "$ikey" ] && json_add_int ikey
"$ikey"
36 [ -n "$okey" ] && json_add_int okey
"$okey"
37 [ -n "$icsum" ] && json_add_boolean icsum
"$icsum"
38 [ -n "$ocsum" ] && json_add_boolean ocsum
"$ocsum"
39 [ -n "$iseqno" ] && json_add_boolean iseqno
"$iseqno"
40 [ -n "$oseqno" ] && json_add_boolean oseqno
"$oseqno"
41 [ -n "$encaplimit" ] && json_add_string encaplimit
"$encaplimit"
47 [ -n "$zone" ] && json_add_string zone
"$zone"
50 proto_send_update
"$cfg"
59 json_get_vars df ipaddr peeraddr tunlink nohostroute
61 [ -z "$peeraddr" ] && {
62 proto_notify_error
"$cfg" "MISSING_PEER_ADDRESS"
63 proto_block_restart
"$cfg"
67 remoteip
=$
(resolveip
-t 10 -4 "$peeraddr")
69 if [ -z "$remoteip" ]; then
70 proto_notify_error
"$cfg" "PEER_RESOLVE_FAIL"
74 for ip
in $remoteip; do
79 if [ "${nohostroute}" != "1" ]; then
80 ( proto_add_host_dependency
"$cfg" "$peeraddr" "$tunlink" )
84 local wanif
="$tunlink"
85 if [ -z $wanif ] && ! network_find_wan wanif
; then
86 proto_notify_error
"$cfg" "NO_WAN_LINK"
90 if ! network_get_ipaddr ipaddr
"$wanif"; then
91 proto_notify_error
"$cfg" "NO_WAN_LINK"
96 [ -z "$df" ] && df
="1"
100 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre4t-$cfg"
103 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre4-$cfg"
111 gre_setup
$cfg "greip"
114 proto_gretap_setup
() {
118 json_get_vars network
120 gre_setup
$cfg "gretapip"
123 json_add_string name
"gre4t-$cfg"
124 json_add_boolean link-ext
0
127 for i
in $network; do
128 ubus call network.interface.
"$i" add_device
"$(json_dump)"
137 local ip6addr peer6addr weakif
138 json_get_vars ip6addr peer6addr tunlink weakif encaplimit nohostroute
140 [ -z "$peer6addr" ] && {
141 proto_notify_error
"$cfg" "MISSING_PEER_ADDRESS"
142 proto_block_restart
"$cfg"
146 remoteip6
=$
(resolveip
-t 10 -6 "$peer6addr")
148 if [ -z "$remoteip6" ]; then
149 proto_notify_error
"$cfg" "PEER_RESOLVE_FAIL"
153 for ip6
in $remoteip6; do
158 if [ "${nohostroute}" != "1" ]; then
159 ( proto_add_host_dependency
"$cfg" "$peer6addr" "$tunlink" )
162 [ -z "$ip6addr" ] && {
163 local wanif
="$tunlink"
164 if [ -z $wanif ] && ! network_find_wan6 wanif
; then
165 proto_notify_error
"$cfg" "NO_WAN_LINK"
169 if ! network_get_ipaddr6 ip6addr
"$wanif"; then
170 [ -z "$weakif" ] && weakif
="lan"
171 if ! network_get_ipaddr6 ip6addr
"$weakif"; then
172 proto_notify_error
"$cfg" "NO_WAN_LINK"
180 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "gre6t-$cfg"
183 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "gre6-$cfg"
188 proto_grev6_setup
() {
191 grev6_setup
$cfg "greip6"
194 proto_grev6tap_setup
() {
198 json_get_vars network
200 grev6_setup
$cfg "gretapip6"
203 json_add_string name
"gre6t-$cfg"
204 json_add_boolean link-ext
0
207 for i
in $network; do
208 ubus call network.interface.
"$i" add_device
"$(json_dump)"
212 gretap_generic_teardown
() {
214 json_get_vars network
217 json_add_string name
"$1"
218 json_add_boolean link-ext
0
221 for i
in $network; do
222 ubus call network.interface.
"$i" remove_device
"$(json_dump)"
226 proto_gre_teardown
() {
230 proto_gretap_teardown
() {
233 gretap_generic_teardown
"gre4t-$cfg"
236 proto_grev6_teardown
() {
240 proto_grev6tap_teardown
() {
243 gretap_generic_teardown
"gre6t-$cfg"
246 gre_generic_init_config
() {
250 proto_config_add_int
"mtu"
251 proto_config_add_int
"ttl"
252 proto_config_add_string
"tos"
253 proto_config_add_string
"tunlink"
254 proto_config_add_string
"zone"
255 proto_config_add_int
"ikey"
256 proto_config_add_int
"okey"
257 proto_config_add_boolean
"icsum"
258 proto_config_add_boolean
"ocsum"
259 proto_config_add_boolean
"iseqno"
260 proto_config_add_boolean
"oseqno"
261 proto_config_add_boolean
"multicast"
264 proto_gre_init_config
() {
265 gre_generic_init_config
266 proto_config_add_string
"ipaddr"
267 proto_config_add_string
"peeraddr"
268 proto_config_add_boolean
"df"
269 proto_config_add_boolean
"nohostroute"
272 proto_gretap_init_config
() {
273 proto_gre_init_config
274 proto_config_add_string
"network"
277 proto_grev6_init_config
() {
278 gre_generic_init_config
279 proto_config_add_string
"ip6addr"
280 proto_config_add_string
"peer6addr"
281 proto_config_add_string
"weakif"
282 proto_config_add_string
"encaplimit"
283 proto_config_add_boolean
"nohostroute"
286 proto_grev6tap_init_config
() {
287 proto_grev6_init_config
288 proto_config_add_string
"network"
291 [ -n "$INCLUDE_ONLY" ] ||
{
292 [ -f /lib
/modules
/$
(uname
-r)/gre.ko
] && add_protocol gre
293 [ -f /lib
/modules
/$
(uname
-r)/gre.ko
] && add_protocol gretap
294 [ -f /lib
/modules
/$
(uname
-r)/ip6_gre.ko
] && add_protocol grev6
295 [ -f /lib
/modules
/$
(uname
-r)/ip6_gre.ko
] && add_protocol grev6tap