3 [ -n "$INCLUDE_ONLY" ] ||
{
5 .
/lib
/functions
/network.sh
16 local mtu ipv6 ttl tos zone ikey okey icsum ocsum iseqno oseqno multicast
17 json_get_vars mtu ipv6 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 json_add_boolean ipv6
"${ipv6:-1}"
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 nohostroute
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 if [ "${nohostroute}" != "1" ]; then
81 ( proto_add_host_dependency
"$cfg" "$peeraddr" "$tunlink" )
85 local wanif
="$tunlink"
86 if [ -z $wanif ] && ! network_find_wan wanif
; then
87 proto_notify_error
"$cfg" "NO_WAN_LINK"
91 if ! network_get_ipaddr ipaddr
"$wanif"; then
92 proto_notify_error
"$cfg" "NO_WAN_LINK"
97 [ -z "$df" ] && df
="1"
101 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre4t-$cfg"
104 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre4-$cfg"
112 gre_setup
$cfg "greip"
115 proto_gretap_setup
() {
119 json_get_vars network
121 gre_setup
$cfg "gretapip"
124 json_add_string name
"gre4t-$cfg"
125 json_add_boolean link-ext
0
128 for i
in $network; do
129 ubus call network.interface.
"$i" add_device
"$(json_dump)"
138 local ip6addr peer6addr weakif
139 json_get_vars ip6addr peer6addr tunlink weakif encaplimit nohostroute
141 [ -z "$peer6addr" ] && {
142 proto_notify_error
"$cfg" "MISSING_PEER_ADDRESS"
143 proto_block_restart
"$cfg"
147 remoteip6
=$
(resolveip
-t 10 -6 "$peer6addr")
149 if [ -z "$remoteip6" ]; then
150 proto_notify_error
"$cfg" "PEER_RESOLVE_FAIL"
154 for ip6
in $remoteip6; do
159 if [ "${nohostroute}" != "1" ]; then
160 ( proto_add_host_dependency
"$cfg" "$peer6addr" "$tunlink" )
163 [ -z "$ip6addr" ] && {
164 local wanif
="$tunlink"
165 if [ -z $wanif ] && ! network_find_wan6 wanif
; then
166 proto_notify_error
"$cfg" "NO_WAN_LINK"
170 if ! network_get_ipaddr6 ip6addr
"$wanif"; then
171 [ -z "$weakif" ] && weakif
="lan"
172 if ! network_get_ipaddr6 ip6addr
"$weakif"; then
173 proto_notify_error
"$cfg" "NO_WAN_LINK"
181 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "gre6t-$cfg"
184 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "gre6-$cfg"
189 proto_grev6_setup
() {
192 grev6_setup
$cfg "greip6"
195 proto_grev6tap_setup
() {
199 json_get_vars network
201 grev6_setup
$cfg "gretapip6"
204 json_add_string name
"gre6t-$cfg"
205 json_add_boolean link-ext
0
208 for i
in $network; do
209 ubus call network.interface.
"$i" add_device
"$(json_dump)"
213 gretap_generic_teardown
() {
215 json_get_vars network
218 json_add_string name
"$1"
219 json_add_boolean link-ext
0
222 for i
in $network; do
223 ubus call network.interface.
"$i" remove_device
"$(json_dump)"
227 proto_gre_teardown
() {
231 proto_gretap_teardown
() {
234 gretap_generic_teardown
"gre4t-$cfg"
237 proto_grev6_teardown
() {
241 proto_grev6tap_teardown
() {
244 gretap_generic_teardown
"gre6t-$cfg"
247 gre_generic_init_config
() {
251 proto_config_add_int
"mtu"
252 proto_config_add_boolean
"ipv6"
253 proto_config_add_int
"ttl"
254 proto_config_add_string
"tos"
255 proto_config_add_string
"tunlink"
256 proto_config_add_string
"zone"
257 proto_config_add_int
"ikey"
258 proto_config_add_int
"okey"
259 proto_config_add_boolean
"icsum"
260 proto_config_add_boolean
"ocsum"
261 proto_config_add_boolean
"iseqno"
262 proto_config_add_boolean
"oseqno"
263 proto_config_add_boolean
"multicast"
266 proto_gre_init_config
() {
267 gre_generic_init_config
268 proto_config_add_string
"ipaddr"
269 proto_config_add_string
"peeraddr"
270 proto_config_add_boolean
"df"
271 proto_config_add_boolean
"nohostroute"
274 proto_gretap_init_config
() {
275 proto_gre_init_config
276 proto_config_add_string
"network"
279 proto_grev6_init_config
() {
280 gre_generic_init_config
281 proto_config_add_string
"ip6addr"
282 proto_config_add_string
"peer6addr"
283 proto_config_add_string
"weakif"
284 proto_config_add_string
"encaplimit"
285 proto_config_add_boolean
"nohostroute"
288 proto_grev6tap_init_config
() {
289 proto_grev6_init_config
290 proto_config_add_string
"network"
293 [ -n "$INCLUDE_ONLY" ] ||
{
294 [ -d /sys
/module
/ip_gre
] && { add_protocol gre
; add_protocol gretap
; }
295 [ -d /sys
/module
/ip6_gre
] && { add_protocol grev6
; add_protocol grev6tap
; }