IPIP: IP in IP package support
[openwrt/svn-archive/archive.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
13 local df ipaddr peeraddr tunlink ttl tos zone mtu
14 json_get_vars df ipaddr peeraddr tunlink ttl tos zone mtu
15
16 [ -z "$peeraddr" ] && {
17 proto_notify_error "$cfg" "MISSING_ADDRESS"
18 proto_block_restart "$cfg"
19 return
20 }
21
22 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
23
24 [ -z "$ipaddr" ] && {
25 local wanif="$tunlink"
26 if [ -z $wanif ] && ! network_find_wan wanif; then
27 proto_notify_error "$cfg" "NO_WAN_LINK"
28 return
29 fi
30
31 if ! network_get_ipaddr ipaddr "$wanif"; then
32 proto_notify_error "$cfg" "NO_WAN_LINK"
33 return
34 fi
35 }
36
37 [ -z "$zone" ] && zone="wan"
38
39 proto_init_update "ipip-$cfg" 1
40
41 proto_add_tunnel
42 json_add_string mode "ipip"
43 json_add_int mtu "${mtu:-1280}"
44 json_add_int ttl "${ttl:-64}"
45 [ -n "$tos" ] && json_add_string tos "$tos"
46 json_add_string local "$ipaddr"
47 json_add_string remote "$peeraddr"
48 [ -n "$tunlink" ] && json_add_string link "$tunlink"
49 json_add_boolean df "${df:-1}"
50
51 proto_close_tunnel
52
53 proto_add_data
54 [ -n "$zone" ] && json_add_string zone "$zone"
55 proto_close_data
56
57 proto_send_update "$cfg"
58 }
59
60 proto_ipip_teardown() {
61 local cfg="$1"
62 }
63
64 proto_ipip_init_config() {
65 no_device=1
66 available=1
67
68 proto_config_add_int "mtu"
69 proto_config_add_int "ttl"
70 proto_config_add_string "tos"
71 proto_config_add_string "tunlink"
72 proto_config_add_string "zone"
73 proto_config_add_string "ipaddr"
74 proto_config_add_string "peeraddr"
75 proto_config_add_boolean "df"
76 }
77
78 [ -n "$INCLUDE_ONLY" ] || {
79 add_protocol ipip
80 }