1 # 6in4.sh - IPv6-in-IPv4 tunnel backend
2 # Copyright (c) 2010 OpenWrt.org
4 # Hook into scan_interfaces() to synthesize a .device option
5 # This is needed for /sbin/ifup to properly dispatch control
6 # to setup_interface_6in4() even if no .ifname is set in
9 config_set
"$1" device
"6in4-$1"
12 coldplug_interface_6in4
() {
13 setup_interface_6in4
"6in4-$1" "$1"
16 setup_interface_6in4
() {
19 local link
="6in4-$cfg"
22 config_get local4
"$cfg" ipaddr
25 config_get remote4
"$cfg" peeraddr
28 config_get local6
"$cfg" ip6addr
31 config_get mtu
"$cfg" mtu
34 config_get ttl
"$cfg" ttl
37 config_get_bool defaultroute
"$cfg" defaultroute
1
40 # creating the tunnel below will trigger a net subsystem event
41 # prevent it from touching or iface by disabling .auto here
42 uci_set_state network
"$cfg" ifname
$link
43 uci_set_state network
"$cfg" auto
0
45 ip tunnel add
$link mode sit remote
$remote4 local $local4 ttl
255
47 ip link
set mtu
${mtu:-1280} dev
$link
48 ip tunnel change
$link ttl
${ttl:-64}
49 ip addr add
$local6 dev
$link
51 uci_set_state network
"$cfg" ip6addr
$local6
53 [ "$defaultroute" = 1 ] && {
54 ip
-6 route add
::/0 dev
$link
55 uci_set_state network
"$cfg" defaultroute
1
58 env
-i ACTION
="ifup" INTERFACE
="$cfg" DEVICE
="$link" PROTO
=6in4
/sbin
/hotplug-call
"iface" &
61 stop_interface_6in4
() {
63 local link
="6in4-$cfg"
65 local local6
=$
(uci_get_state network
"$cfg" ip6addr
)
66 local defaultroute
=$
(uci_get_state network
"$cfg" defaultroute
)
68 grep -qs "^ *$link:" /proc
/net
/dev
&& {
69 env
-i ACTION
="ifdown" INTERFACE
="$cfg" DEVICE
="$link" PROTO
=6in4
/sbin
/hotplug-call
"iface" &
71 [ "$defaultroute" = "1" ] && {
72 ip
-6 route del
::/0 dev
$link
75 ip addr del
$local6 dev
$link
76 ip link
set $link down