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"
35 json_add_object
'data'
36 [ -n "$ikey" ] && json_add_int ikey
"$ikey"
37 [ -n "$okey" ] && json_add_int okey
"$okey"
38 [ -n "$icsum" ] && json_add_boolean icsum
"$icsum"
39 [ -n "$ocsum" ] && json_add_boolean ocsum
"$ocsum"
40 [ -n "$iseqno" ] && json_add_boolean iseqno
"$iseqno"
41 [ -n "$oseqno" ] && json_add_boolean oseqno
"$oseqno"
42 [ -n "$encaplimit" ] && json_add_string encaplimit
"$encaplimit"
48 [ -n "$zone" ] && json_add_string zone
"$zone"
51 proto_send_update
"$cfg"
60 json_get_vars df ipaddr peeraddr tunlink
62 [ -z "$peeraddr" ] && {
63 proto_notify_error
"$cfg" "MISSING_PEER_ADDRESS"
64 proto_block_restart
"$cfg"
68 remoteip
=$
(resolveip
-t 10 -4 "$peeraddr")
70 if [ -z "$remoteip" ]; then
71 proto_notify_error
"$cfg" "PEER_RESOLVE_FAIL"
75 for ip
in $remoteip; do
80 ( proto_add_host_dependency
"$cfg" "$peeraddr" "$tunlink" )
83 local wanif
="$tunlink"
84 if [ -z $wanif ] && ! network_find_wan wanif
; then
85 proto_notify_error
"$cfg" "NO_WAN_LINK"
89 if ! network_get_ipaddr ipaddr
"$wanif"; then
90 proto_notify_error
"$cfg" "NO_WAN_LINK"
95 [ -z "$df" ] && df
="1"
99 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre4t-$cfg"
102 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre4-$cfg"
110 gre_setup
$cfg "greip"
113 proto_gretap_setup
() {
117 json_get_vars network
119 gre_setup
$cfg "gretapip"
122 json_add_string name
"gre4t-$cfg"
123 json_add_boolean link-ext
0
126 for i
in $network; do
127 ubus call network.interface.
"$i" add_device
"$(json_dump)"
136 local ip6addr peer6addr weakif
137 json_get_vars ip6addr peer6addr tunlink weakif encaplimit
139 [ -z "$peer6addr" ] && {
140 proto_notify_error
"$cfg" "MISSING_PEER_ADDRESS"
141 proto_block_restart
"$cfg"
145 remoteip6
=$
(resolveip
-t 10 -6 "$peer6addr")
147 if [ -z "$remoteip6" ]; then
148 proto_notify_error
"$cfg" "PEER_RESOLVE_FAIL"
152 for ip6
in $remoteip6; do
157 ( proto_add_host_dependency
"$cfg" "$peer6addr" "$tunlink" )
159 [ -z "$ip6addr" ] && {
160 local wanif
="$tunlink"
161 if [ -z $wanif ] && ! network_find_wan6 wanif
; then
162 proto_notify_error
"$cfg" "NO_WAN_LINK"
166 if ! network_get_ipaddr6 ip6addr
"$wanif"; then
167 [ -z "$weakif" ] && weakif
="lan"
168 if ! network_get_ipaddr6 ip6addr
"$weakif"; then
169 proto_notify_error
"$cfg" "NO_WAN_LINK"
177 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "gre6t-$cfg"
180 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "gre6-$cfg"
185 proto_grev6_setup
() {
188 grev6_setup
$cfg "greip6"
191 proto_grev6tap_setup
() {
195 json_get_vars network
197 grev6_setup
$cfg "gretapip6"
200 json_add_string name
"gre6t-$cfg"
201 json_add_boolean link-ext
0
204 for i
in $network; do
205 ubus call network.interface.
"$i" add_device
"$(json_dump)"
209 gretap_generic_teardown
() {
211 json_get_vars network
214 json_add_string name
"$1"
215 json_add_boolean link-ext
0
218 for i
in $network; do
219 ubus call network.interface.
"$i" remove_device
"$(json_dump)"
223 proto_gre_teardown
() {
227 proto_gretap_teardown
() {
230 gretap_generic_teardown
"gre4t-$cfg"
233 proto_grev6_teardown
() {
237 proto_grev6tap_teardown
() {
240 gretap_generic_teardown
"gre6t-$cfg"
243 gre_generic_init_config
() {
247 proto_config_add_int
"mtu"
248 proto_config_add_int
"ttl"
249 proto_config_add_string
"tos"
250 proto_config_add_string
"tunlink"
251 proto_config_add_string
"zone"
252 proto_config_add_int
"ikey"
253 proto_config_add_int
"okey"
254 proto_config_add_boolean
"icsum"
255 proto_config_add_boolean
"ocsum"
256 proto_config_add_boolean
"iseqno"
257 proto_config_add_boolean
"oseqno"
258 proto_config_add_boolean
"multicast"
261 proto_gre_init_config
() {
262 gre_generic_init_config
263 proto_config_add_string
"ipaddr"
264 proto_config_add_string
"peeraddr"
265 proto_config_add_boolean
"df"
268 proto_gretap_init_config
() {
269 proto_gre_init_config
270 proto_config_add_string
"network"
273 proto_grev6_init_config
() {
274 gre_generic_init_config
275 proto_config_add_string
"ip6addr"
276 proto_config_add_string
"peer6addr"
277 proto_config_add_string
"weakif"
278 proto_config_add_string
"encaplimit"
281 proto_grev6tap_init_config
() {
282 proto_grev6_init_config
283 proto_config_add_string
"network"
286 [ -n "$INCLUDE_ONLY" ] ||
{
287 [ -f /lib
/modules
/$
(uname
-r)/gre.ko
] && add_protocol gre
288 [ -f /lib
/modules
/$
(uname
-r)/gre.ko
] && add_protocol gretap
289 [ -f /lib
/modules
/$
(uname
-r)/ip6_gre.ko
] && add_protocol grev6
290 [ -f /lib
/modules
/$
(uname
-r)/ip6_gre.ko
] && add_protocol grev6tap