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 "$zone" ] && zone="wan"
20 [ -z "$multicast" ] && multicast=1
22 proto_init_update "$link" 1
25 json_add_string mode "$mode"
26 json_add_int mtu "${mtu:-1280}"
27 [ -n "$df" ] && json_add_boolean df "$df"
28 [ -n "$ttl" ] && json_add_int ttl "$ttl"
29 [ -n "$tos" ] && json_add_string tos "$tos"
30 json_add_boolean multicast "$multicast"
31 json_add_string local "$local"
32 json_add_string remote "$remote"
33 [ -n "$tunlink" ] && json_add_string link "$tunlink"
34 json_add_string info "${ikey:-0},${okey:-0},${icsum:-0},${ocsum:-0},${iseqno:-0},${oseqno:-0}"
38 [ -n "$zone" ] && json_add_string zone "$zone"
41 proto_send_update "$cfg"
50 json_get_vars df ipaddr peeraddr tunlink
52 [ -z "$peeraddr" ] && {
53 proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
54 proto_block_restart "$cfg"
58 remoteip=$(resolveip -t 10 -4 "$peeraddr")
60 if [ -z "$remoteip" ]; then
61 proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
65 for ip in $remoteip; do
70 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
73 local wanif="$tunlink"
74 if [ -z $wanif ] && ! network_find_wan wanif; then
75 proto_notify_error "$cfg" "NO_WAN_LINK"
79 if ! network_get_ipaddr ipaddr "$wanif"; then
80 proto_notify_error "$cfg" "NO_WAN_LINK"
85 [ -z "$df" ] && df="1"
89 gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre4t-$cfg"
92 gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre4-$cfg"
100 gre_setup $cfg "greip"
103 proto_gretap_setup() {
107 json_get_vars network
109 gre_setup $cfg "gretapip"
112 json_add_string name "gre4t-$cfg"
113 json_add_boolean link-ext 0
116 for i in $network; do
117 ubus call network.interface."$i" add_device "$(json_dump)"
126 local ip6addr peer6addr weakif
127 json_get_vars ip6addr peer6addr tunlink weakif
129 [ -z "$peer6addr" ] && {
130 proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
131 proto_block_restart "$cfg"
135 remoteip6=$(resolveip -t 10 -6 "$peer6addr")
137 if [ -z "$remoteip6" ]; then
138 proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
142 for ip6 in $remoteip6; do
147 ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
149 [ -z "$ip6addr" ] && {
150 local wanif="$tunlink"
151 if [ -z $wanif ] && ! network_find_wan6 wanif; then
152 proto_notify_error "$cfg" "NO_WAN_LINK"
156 if ! network_get_ipaddr6 ip6addr "$wanif"; then
157 [ -z "$weakif" ] && weakif="lan"
158 if ! network_get_ipaddr6 ip6addr "$weakif"; then
159 proto_notify_error "$cfg" "NO_WAN_LINK"
167 gre_generic_setup $cfg $mode $ip6addr $peer6addr "gre6t-$cfg"
170 gre_generic_setup $cfg $mode $ip6addr $peer6addr "gre6-$cfg"
175 proto_grev6_setup() {
178 grev6_setup $cfg "greip6"
181 proto_grev6tap_setup() {
185 json_get_vars network
187 grev6_setup $cfg "gretapip6"
190 json_add_string name "gre6t-$cfg"
191 json_add_boolean link-ext 0
194 for i in $network; do
195 ubus call network.interface."$i" add_device "$(json_dump)"
199 gretap_generic_teardown() {
201 json_get_vars network
204 json_add_string name "$1"
205 json_add_boolean link-ext 0
208 for i in $network; do
209 ubus call network.interface."$i" remove_device "$(json_dump)"
213 proto_gre_teardown() {
217 proto_gretap_teardown() {
220 gretap_generic_teardown "gre4t-$cfg"
223 proto_grev6_teardown() {
227 proto_grev6tap_teardown() {
230 gretap_generic_teardown "gre6t-$cfg"
233 gre_generic_init_config() {
237 proto_config_add_int "mtu"
238 proto_config_add_int "ttl"
239 proto_config_add_string "tos"
240 proto_config_add_string "tunlink"
241 proto_config_add_string "zone"
242 proto_config_add_int "ikey"
243 proto_config_add_int "okey"
244 proto_config_add_boolean "icsum"
245 proto_config_add_boolean "ocsum"
246 proto_config_add_boolean "iseqno"
247 proto_config_add_boolean "oseqno"
248 proto_config_add_boolean "multicast"
251 proto_gre_init_config() {
252 gre_generic_init_config
253 proto_config_add_string "ipaddr"
254 proto_config_add_string "peeraddr"
255 proto_config_add_boolean "df"
258 proto_gretap_init_config() {
259 proto_gre_init_config
260 proto_config_add_string "network"
263 proto_grev6_init_config() {
264 gre_generic_init_config
265 proto_config_add_string "ip6addr"
266 proto_config_add_string "peer6addr"
267 proto_config_add_string "weakif"
270 proto_grev6tap_init_config() {
271 proto_grev6_init_config
272 proto_config_add_string "network"
275 [ -n "$INCLUDE_ONLY" ] || {
276 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gre
277 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gretap
278 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6
279 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6tap