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
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 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
82 local wanif="$tunlink"
83 if [ -z $wanif ] && ! network_find_wan wanif; then
84 proto_notify_error "$cfg" "NO_WAN_LINK"
88 if ! network_get_ipaddr ipaddr "$wanif"; then
89 proto_notify_error "$cfg" "NO_WAN_LINK"
94 [ -z "$df" ] && df="1"
98 gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre4t-$cfg"
101 gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre4-$cfg"
109 gre_setup $cfg "greip"
112 proto_gretap_setup() {
116 json_get_vars network
118 gre_setup $cfg "gretapip"
121 json_add_string name "gre4t-$cfg"
122 json_add_boolean link-ext 0
125 for i in $network; do
126 ubus call network.interface."$i" add_device "$(json_dump)"
135 local ip6addr peer6addr weakif
136 json_get_vars ip6addr peer6addr tunlink weakif encaplimit
138 [ -z "$peer6addr" ] && {
139 proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
140 proto_block_restart "$cfg"
144 remoteip6=$(resolveip -t 10 -6 "$peer6addr")
146 if [ -z "$remoteip6" ]; then
147 proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
151 for ip6 in $remoteip6; do
156 ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
158 [ -z "$ip6addr" ] && {
159 local wanif="$tunlink"
160 if [ -z $wanif ] && ! network_find_wan6 wanif; then
161 proto_notify_error "$cfg" "NO_WAN_LINK"
165 if ! network_get_ipaddr6 ip6addr "$wanif"; then
166 [ -z "$weakif" ] && weakif="lan"
167 if ! network_get_ipaddr6 ip6addr "$weakif"; then
168 proto_notify_error "$cfg" "NO_WAN_LINK"
176 gre_generic_setup $cfg $mode $ip6addr $peer6addr "gre6t-$cfg"
179 gre_generic_setup $cfg $mode $ip6addr $peer6addr "gre6-$cfg"
184 proto_grev6_setup() {
187 grev6_setup $cfg "greip6"
190 proto_grev6tap_setup() {
194 json_get_vars network
196 grev6_setup $cfg "gretapip6"
199 json_add_string name "gre6t-$cfg"
200 json_add_boolean link-ext 0
203 for i in $network; do
204 ubus call network.interface."$i" add_device "$(json_dump)"
208 gretap_generic_teardown() {
210 json_get_vars network
213 json_add_string name "$1"
214 json_add_boolean link-ext 0
217 for i in $network; do
218 ubus call network.interface."$i" remove_device "$(json_dump)"
222 proto_gre_teardown() {
226 proto_gretap_teardown() {
229 gretap_generic_teardown "gre4t-$cfg"
232 proto_grev6_teardown() {
236 proto_grev6tap_teardown() {
239 gretap_generic_teardown "gre6t-$cfg"
242 gre_generic_init_config() {
246 proto_config_add_int "mtu"
247 proto_config_add_int "ttl"
248 proto_config_add_string "tos"
249 proto_config_add_string "tunlink"
250 proto_config_add_string "zone"
251 proto_config_add_int "ikey"
252 proto_config_add_int "okey"
253 proto_config_add_boolean "icsum"
254 proto_config_add_boolean "ocsum"
255 proto_config_add_boolean "iseqno"
256 proto_config_add_boolean "oseqno"
257 proto_config_add_boolean "multicast"
260 proto_gre_init_config() {
261 gre_generic_init_config
262 proto_config_add_string "ipaddr"
263 proto_config_add_string "peeraddr"
264 proto_config_add_boolean "df"
267 proto_gretap_init_config() {
268 proto_gre_init_config
269 proto_config_add_string "network"
272 proto_grev6_init_config() {
273 gre_generic_init_config
274 proto_config_add_string "ip6addr"
275 proto_config_add_string "peer6addr"
276 proto_config_add_string "weakif"
277 proto_config_add_string "encaplimit"
280 proto_grev6tap_init_config() {
281 proto_grev6_init_config
282 proto_config_add_string "network"
285 [ -n "$INCLUDE_ONLY" ] || {
286 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gre
287 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gretap
288 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6
289 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6tap