3 [ -n "$INCLUDE_ONLY" ] || {
5 . /lib/functions/network.sh
16 local mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno
17 json_get_vars mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno
19 [ -z "$zone" ] && zone="wan"
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 json_add_int ttl "${ttl:-64}"
28 [ -n "$tos" ] && json_add_string tos "$tos"
29 json_add_string local "$local"
30 json_add_string remote "$remote"
31 [ -n "$tunlink" ] && json_add_string link "$tunlink"
32 json_add_string info "${ikey:-0},${okey:-0},${icsum:-0},${ocsum:-0},${iseqno:-0},${oseqno:-0}"
36 [ -n "$zone" ] && json_add_string zone "$zone"
39 proto_send_update "$cfg"
47 json_get_vars df ipaddr peeraddr tunlink
49 [ -z "$peeraddr" ] && {
50 proto_notify_error "$cfg" "MISSING_ADDRESS"
51 proto_block_restart "$cfg"
55 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
58 local wanif="$tunlink"
59 if [ -z $wanif ] && ! network_find_wan wanif; then
60 proto_notify_error "$cfg" "NO_WAN_LINK"
64 if ! network_get_ipaddr ipaddr "$wanif"; then
65 proto_notify_error "$cfg" "NO_WAN_LINK"
70 [ -z "$df" ] && df="1"
72 gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre-$cfg"
78 gre_setup $cfg "greip"
81 proto_gretap_setup() {
87 gre_setup $cfg "gretapip"
90 json_add_string name "gre-$cfg"
91 json_add_boolean link-ext 0
95 ubus call network.interface."$i" add_device "$(json_dump)"
103 local ip6addr peer6addr weakif
104 json_get_vars ip6addr peer6addr tunlink weakif
106 [ -z "$peer6addr" ] && {
107 proto_notify_error "$cfg" "MISSING_ADDRESS"
108 proto_block_restart "$cfg"
112 ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
114 [ -z "$ip6addr" ] && {
115 local wanif="$tunlink"
116 if [ -z $wanif ] && ! network_find_wan6 wanif; then
117 proto_notify_error "$cfg" "NO_WAN_LINK"
121 if ! network_get_ipaddr6 ip6addr "$wanif"; then
122 [ -z "$weakif" ] && weakif="lan"
123 if ! network_get_ipaddr6 ip6addr "$weakif"; then
124 proto_notify_error "$cfg" "NO_WAN_LINK"
130 gre_generic_setup $cfg $mode $ip6addr $peer6addr "grev6-$cfg"
133 proto_grev6_setup() {
136 grev6_setup $cfg "greip6"
139 proto_grev6tap_setup() {
143 json_get_vars network
145 grev6_setup $cfg "gretapip6"
148 json_add_string name "grev6-$cfg"
149 json_add_boolean link-ext 0
152 for i in $network; do
153 ubus call network.interface."$i" add_device "$(json_dump)"
157 gretap_generic_teardown() {
159 json_get_vars network
162 json_add_string name "$1"
163 json_add_boolean link-ext 0
166 for i in $network; do
167 ubus call network.interface."$i" remove_device "$(json_dump)"
171 proto_gre_teardown() {
175 proto_gretap_teardown() {
178 gretap_generic_teardown "gre-$cfg"
181 proto_grev6_teardown() {
185 proto_grev6tap_teardown() {
188 gretap_generic_teardown "grev6-$cfg"
191 gre_generic_init_config() {
195 proto_config_add_int "mtu"
196 proto_config_add_int "ttl"
197 proto_config_add_string "tos"
198 proto_config_add_string "tunlink"
199 proto_config_add_string "zone"
200 proto_config_add_int "ikey"
201 proto_config_add_int "okey"
202 proto_config_add_boolean "icsum"
203 proto_config_add_boolean "ocsum"
204 proto_config_add_boolean "iseqno"
205 proto_config_add_boolean "oseqno"
208 proto_gre_init_config() {
209 gre_generic_init_config
210 proto_config_add_string "ipaddr"
211 proto_config_add_string "peeraddr"
212 proto_config_add_boolean "df"
215 proto_gretap_init_config() {
216 proto_gre_init_config
217 proto_config_add_string "network"
220 proto_grev6_init_config() {
221 gre_generic_init_config
222 proto_config_add_string "ip6addr"
223 proto_config_add_string "peer6addr"
224 proto_config_add_string "weakif"
227 proto_grev6tap_init_config() {
228 proto_grev6_init_config
229 proto_config_add_string "network"
232 [ -n "$INCLUDE_ONLY" ] || {
233 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gre
234 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gretap
235 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6
236 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6tap