ipq40xx: only include ath10k-board-qca4019 for the generic subtarget
[openwrt/staging/chunkeey.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 nohostroute
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 if [ "${nohostroute}" != "1" ]; then
36 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
37 fi
38
39 [ -z "$ipaddr" ] && {
40 local wanif="$tunlink"
41 if [ -z $wanif ] && ! network_find_wan wanif; then
42 proto_notify_error "$cfg" "NO_WAN_LINK"
43 return
44 fi
45
46 if ! network_get_ipaddr ipaddr "$wanif"; then
47 proto_notify_error "$cfg" "NO_WAN_LINK"
48 return
49 fi
50 }
51
52 proto_init_update "ipip-$cfg" 1
53
54 proto_add_tunnel
55 json_add_string mode "ipip"
56 json_add_int mtu "${mtu:-1280}"
57 json_add_int ttl "${ttl:-64}"
58 [ -n "$tos" ] && json_add_string tos "$tos"
59 json_add_string local "$ipaddr"
60 json_add_string remote "$peeraddr"
61 [ -n "$tunlink" ] && json_add_string link "$tunlink"
62 json_add_boolean df "${df:-1}"
63
64 proto_close_tunnel
65
66 proto_add_data
67 [ -n "$zone" ] && json_add_string zone "$zone"
68 proto_close_data
69
70 proto_send_update "$cfg"
71 }
72
73 proto_ipip_teardown() {
74 local cfg="$1"
75 }
76
77 proto_ipip_init_config() {
78 no_device=1
79 available=1
80
81 proto_config_add_int "mtu"
82 proto_config_add_int "ttl"
83 proto_config_add_string "tos"
84 proto_config_add_string "tunlink"
85 proto_config_add_string "zone"
86 proto_config_add_string "ipaddr"
87 proto_config_add_string "peeraddr"
88 proto_config_add_boolean "df"
89 proto_config_add_boolean "nohostroute"
90 }
91
92 [ -n "$INCLUDE_ONLY" ] || {
93 add_protocol ipip
94 }