2 # 6rd.sh - IPv6-in-IPv4 tunnel backend
3 # Copyright (c) 2010-2012 OpenWrt.org
5 [ -n "$INCLUDE_ONLY" ] ||
{
7 .
/lib
/functions
/network.sh
17 local mtu ttl ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen
18 json_get_vars mtu ttl ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen
20 [ -z "$ip6prefix" -o -z "$peeraddr" ] && {
21 proto_notify_error
"$cfg" "MISSING_ADDRESS"
22 proto_block_restart
"$cfg"
26 ( proto_add_host_dependency
"$cfg" 0.0.0.0 )
30 if ! network_find_wan wanif ||
! network_get_ipaddr ipaddr
"$wanif"; then
31 proto_notify_error
"$cfg" "NO_WAN_LINK"
36 # Determine the relay prefix.
37 local ip4prefixlen
="${ip4prefixlen:-0}"
38 local ip4prefix
=$
(ipcalc.sh
"$ipaddr/$ip4prefixlen" |
grep NETWORK
)
39 ip4prefix
="${ip4prefix#NETWORK=}"
41 # Determine our IPv6 address.
42 local ip6subnet
=$
(6rdcalc
"$ip6prefix/$ip6prefixlen" "$ipaddr/$ip4prefixlen")
43 local ip6addr
="${ip6subnet%%::*}::1"
45 proto_init_update
"$link" 1
46 proto_add_ipv6_address
"$ip6addr" "$ip6prefixlen"
47 proto_add_ipv6_route
"::" 0 "::$peeraddr"
50 json_add_string mode sit
51 json_add_int mtu
"${mtu:-1280}"
52 json_add_int ttl
"${ttl:-64}"
53 json_add_string
local "$ipaddr"
54 json_add_string
6rd-prefix
"$ip6prefix/$ip6prefixlen"
55 json_add_string
6rd-relay-prefix
"$ip4prefix/$ip4prefixlen"
58 proto_send_update
"$cfg"
61 proto_6rd_teardown
() {
65 proto_6rd_init_config
() {
69 proto_config_add_int
"mtu"
70 proto_config_add_int
"ttl"
71 proto_config_add_string
"ipaddr"
72 proto_config_add_string
"peeraddr"
73 proto_config_add_string
"ip6prefix"
74 proto_config_add_string
"ip6prefixlen"
75 proto_config_add_string
"ip4prefixlen"
78 [ -n "$INCLUDE_ONLY" ] ||
{