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 json_add_int ttl "${ttl:-64}"
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"
49 json_get_vars df ipaddr peeraddr tunlink
51 [ -z "$peeraddr" ] && {
52 proto_notify_error "$cfg" "MISSING_ADDRESS"
53 proto_block_restart "$cfg"
57 ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
60 local wanif="$tunlink"
61 if [ -z $wanif ] && ! network_find_wan wanif; then
62 proto_notify_error "$cfg" "NO_WAN_LINK"
66 if ! network_get_ipaddr ipaddr "$wanif"; then
67 proto_notify_error "$cfg" "NO_WAN_LINK"
72 [ -z "$df" ] && df="1"
74 gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre-$cfg"
80 gre_setup $cfg "greip"
83 proto_gretap_setup() {
89 gre_setup $cfg "gretapip"
92 json_add_string name "gre-$cfg"
93 json_add_boolean link-ext 0
97 ubus call network.interface."$i" add_device "$(json_dump)"
105 local ip6addr peer6addr weakif
106 json_get_vars ip6addr peer6addr tunlink weakif
108 [ -z "$peer6addr" ] && {
109 proto_notify_error "$cfg" "MISSING_ADDRESS"
110 proto_block_restart "$cfg"
114 ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
116 [ -z "$ip6addr" ] && {
117 local wanif="$tunlink"
118 if [ -z $wanif ] && ! network_find_wan6 wanif; then
119 proto_notify_error "$cfg" "NO_WAN_LINK"
123 if ! network_get_ipaddr6 ip6addr "$wanif"; then
124 [ -z "$weakif" ] && weakif="lan"
125 if ! network_get_ipaddr6 ip6addr "$weakif"; then
126 proto_notify_error "$cfg" "NO_WAN_LINK"
132 gre_generic_setup $cfg $mode $ip6addr $peer6addr "grev6-$cfg"
135 proto_grev6_setup() {
138 grev6_setup $cfg "greip6"
141 proto_grev6tap_setup() {
145 json_get_vars network
147 grev6_setup $cfg "gretapip6"
150 json_add_string name "grev6-$cfg"
151 json_add_boolean link-ext 0
154 for i in $network; do
155 ubus call network.interface."$i" add_device "$(json_dump)"
159 gretap_generic_teardown() {
161 json_get_vars network
164 json_add_string name "$1"
165 json_add_boolean link-ext 0
168 for i in $network; do
169 ubus call network.interface."$i" remove_device "$(json_dump)"
173 proto_gre_teardown() {
177 proto_gretap_teardown() {
180 gretap_generic_teardown "gre-$cfg"
183 proto_grev6_teardown() {
187 proto_grev6tap_teardown() {
190 gretap_generic_teardown "grev6-$cfg"
193 gre_generic_init_config() {
197 proto_config_add_int "mtu"
198 proto_config_add_int "ttl"
199 proto_config_add_string "tos"
200 proto_config_add_string "tunlink"
201 proto_config_add_string "zone"
202 proto_config_add_int "ikey"
203 proto_config_add_int "okey"
204 proto_config_add_boolean "icsum"
205 proto_config_add_boolean "ocsum"
206 proto_config_add_boolean "iseqno"
207 proto_config_add_boolean "oseqno"
208 proto_config_add_boolean "multicast"
211 proto_gre_init_config() {
212 gre_generic_init_config
213 proto_config_add_string "ipaddr"
214 proto_config_add_string "peeraddr"
215 proto_config_add_boolean "df"
218 proto_gretap_init_config() {
219 proto_gre_init_config
220 proto_config_add_string "network"
223 proto_grev6_init_config() {
224 gre_generic_init_config
225 proto_config_add_string "ip6addr"
226 proto_config_add_string "peer6addr"
227 proto_config_add_string "weakif"
230 proto_grev6tap_init_config() {
231 proto_grev6_init_config
232 proto_config_add_string "network"
235 [ -n "$INCLUDE_ONLY" ] || {
236 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gre
237 [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gretap
238 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6
239 [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6tap