ipip: remove setting default firewall zone to wan
[openwrt/openwrt.git] / package / network / config / ipip / files / ipip.sh
1 #!/bin/sh
2
3 [ -n "$INCLUDE_ONLY" ] || {
4 . /lib/functions.sh
5 . /lib/functions/network.sh
6 . ../netifd-proto.sh
7 init_proto "$@"
8 }
9
10 proto_ipip_setup() {
11 local cfg="$1"
12 local remoteip
13
14 local df ipaddr peeraddr tunlink ttl tos zone mtu
15 json_get_vars df ipaddr peeraddr tunlink ttl tos zone mtu
16
17 [ -z "$peeraddr" ] && {
18 proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
19 proto_block_restart "$cfg"
20 return
21 }
22
23 remoteip=$(resolveip -t 10 -4 "$peeraddr")
24
25 if [ -z "$remoteip" ]; then
26 proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
27 return
28 fi
29
30 for ip in $remoteip; do
31 peeraddr=$ip
32 break
33 done
34
35 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
36
37 [ -z "$ipaddr" ] && {
38 local wanif="$tunlink"
39 if [ -z $wanif ] && ! network_find_wan wanif; then
40 proto_notify_error "$cfg" "NO_WAN_LINK"
41 return
42 fi
43
44 if ! network_get_ipaddr ipaddr "$wanif"; then
45 proto_notify_error "$cfg" "NO_WAN_LINK"
46 return
47 fi
48 }
49
50 proto_init_update "ipip-$cfg" 1
51
52 proto_add_tunnel
53 json_add_string mode "ipip"
54 json_add_int mtu "${mtu:-1280}"
55 json_add_int ttl "${ttl:-64}"
56 [ -n "$tos" ] && json_add_string tos "$tos"
57 json_add_string local "$ipaddr"
58 json_add_string remote "$peeraddr"
59 [ -n "$tunlink" ] && json_add_string link "$tunlink"
60 json_add_boolean df "${df:-1}"
61
62 proto_close_tunnel
63
64 proto_add_data
65 [ -n "$zone" ] && json_add_string zone "$zone"
66 proto_close_data
67
68 proto_send_update "$cfg"
69 }
70
71 proto_ipip_teardown() {
72 local cfg="$1"
73 }
74
75 proto_ipip_init_config() {
76 no_device=1
77 available=1
78
79 proto_config_add_int "mtu"
80 proto_config_add_int "ttl"
81 proto_config_add_string "tos"
82 proto_config_add_string "tunlink"
83 proto_config_add_string "zone"
84 proto_config_add_string "ipaddr"
85 proto_config_add_string "peeraddr"
86 proto_config_add_boolean "df"
87 }
88
89 [ -n "$INCLUDE_ONLY" ] || {
90 add_protocol ipip
91 }