3 [ -n "$INCLUDE_ONLY" ] ||
{
5 .
/lib
/functions
/network.sh
16 local mtu ttl zone ikey okey icsum ocsum iseqno oseqno
17 json_get_vars mtu ttl zone ikey okey icsum ocsum iseqno oseqno
19 [ -z "$zone" ] && zone
="wan"
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 json_add_int ttl
"${ttl:-64}"
28 json_add_string
local "$local"
29 json_add_string remote
"$remote"
30 [ -n "$tunlink" ] && json_add_string link
"$tunlink"
31 json_add_string info
"${ikey:-0},${okey:-0},${icsum:-0},${ocsum:-0},${iseqno:-0},${oseqno:-0}"
35 [ -n "$zone" ] && json_add_string zone
"$zone"
38 proto_send_update
"$cfg"
46 json_get_vars df ipaddr peeraddr tunlink
48 [ -z "$peeraddr" ] && {
49 proto_notify_error
"$cfg" "MISSING_ADDRESS"
50 proto_block_restart
"$cfg"
54 ( proto_add_host_dependency
"$cfg" "0.0.0.0" "$tunlink" )
57 local wanif
="$tunlink"
58 if [ -z $wanif ] && ! network_find_wan wanif
; then
59 proto_notify_error
"$cfg" "NO_WAN_LINK"
63 if ! network_get_ipaddr ipaddr
"$wanif"; then
64 proto_notify_error
"$cfg" "NO_WAN_LINK"
69 [ -z "$df" ] && df
="1"
71 gre_generic_setup
$cfg $mode $ipaddr $peeraddr "gre-$cfg"
77 gre_setup
$cfg "greip"
80 proto_gretap_setup
() {
86 gre_setup
$cfg "gretapip"
89 json_add_string name
"gre-$cfg"
90 json_add_boolean link-ext
0
94 ubus call network.interface.
"$i" add_device
"$(json_dump)"
102 local ip6addr peer6addr weakif
103 json_get_vars ip6addr peer6addr tunlink weakif
105 [ -z "$peer6addr" ] && {
106 proto_notify_error
"$cfg" "MISSING_ADDRESS"
107 proto_block_restart
"$cfg"
111 ( proto_add_host_dependency
"$cfg" "::" "$tunlink" )
113 [ -z "$ip6addr" ] && {
114 local wanif
="$tunlink"
115 if [ -z $wanif ] && ! network_find_wan6 wanif
; then
116 proto_notify_error
"$cfg" "NO_WAN_LINK"
120 if ! network_get_ipaddr6 ip6addr
"$wanif"; then
121 [ -z "$weakif" ] && weakif
="lan"
122 if ! network_get_ipaddr6 ip6addr
"$weakif"; then
123 proto_notify_error
"$cfg" "NO_WAN_LINK"
129 gre_generic_setup
$cfg $mode $ip6addr $peer6addr "grev6-$cfg"
132 proto_grev6_setup
() {
135 grev6_setup
$cfg "greip6"
138 proto_grev6tap_setup
() {
142 json_get_vars network
144 grev6_setup
$cfg "gretapip6"
147 json_add_string name
"grev6-$cfg"
148 json_add_boolean link-ext
0
151 for i
in $network; do
152 ubus call network.interface.
"$i" add_device
"$(json_dump)"
156 gretap_generic_teardown
() {
158 json_get_vars network
161 json_add_string name
"$1"
162 json_add_boolean link-ext
0
165 for i
in $network; do
166 ubus call network.interface.
"$i" remove_device
"$(json_dump)"
170 proto_gre_teardown
() {
174 proto_gretap_teardown
() {
177 gretap_generic_teardown
"gre-$cfg"
180 proto_grev6_teardown
() {
184 proto_grev6tap_teardown
() {
187 gretap_generic_teardown
"grev6-$cfg"
190 gre_generic_init_config
() {
194 proto_config_add_int
"mtu"
195 proto_config_add_int
"ttl"
196 proto_config_add_string
"tunlink"
197 proto_config_add_string
"zone"
198 proto_config_add_int
"ikey"
199 proto_config_add_int
"okey"
200 proto_config_add_boolean
"icsum"
201 proto_config_add_boolean
"ocsum"
202 proto_config_add_boolean
"iseqno"
203 proto_config_add_boolean
"oseqno"
206 proto_gre_init_config
() {
207 gre_generic_init_config
208 proto_config_add_string
"ipaddr"
209 proto_config_add_string
"peeraddr"
210 proto_config_add_boolean
"df"
213 proto_gretap_init_config
() {
214 proto_gre_init_config
215 proto_config_add_string
"network"
218 proto_grev6_init_config
() {
219 gre_generic_init_config
220 proto_config_add_string
"ip6addr"
221 proto_config_add_string
"peer6addr"
222 proto_config_add_string
"weakif"
225 proto_grev6tap_init_config
() {
226 proto_grev6_init_config
227 proto_config_add_string
"network"
230 [ -n "$INCLUDE_ONLY" ] ||
{
231 [ -f /lib
/modules
/$
(uname
-r)/gre.ko
] && add_protocol gre
232 [ -f /lib
/modules
/$
(uname
-r)/gre.ko
] && add_protocol gretap
233 [ -f /lib
/modules
/$
(uname
-r)/ip6_gre.ko
] && add_protocol grev6
234 [ -f /lib
/modules
/$
(uname
-r)/ip6_gre.ko
] && add_protocol grev6tap