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 df ttl tos ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen tunlink zone
18 json_get_vars mtu df ttl tos ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen tunlink zone
20 [ -z "$ip6prefix" -o -z "$peeraddr" ] && {
21 proto_notify_error
"$cfg" "MISSING_ADDRESS"
22 proto_block_restart
"$cfg"
26 ( proto_add_host_dependency
"$cfg" "$peeraddr" "$tunlink" )
29 local wanif
="$tunlink"
30 if [ -z $wanif ] && ! network_find_wan wanif
; then
31 proto_notify_error
"$cfg" "NO_WAN_LINK"
35 if ! network_get_ipaddr ipaddr
"$wanif"; then
36 proto_notify_error
"$cfg" "NO_WAN_LINK"
41 # Determine the relay prefix.
42 local ip4prefixlen
="${ip4prefixlen:-0}"
44 eval "$(ipcalc.sh "$ipaddr/$ip4prefixlen")";ip4prefix
=$NETWORK
46 # Determine our IPv6 address.
47 local ip6subnet
=$
(6rdcalc
"$ip6prefix/$ip6prefixlen" "$ipaddr/$ip4prefixlen")
48 local ip6addr
="${ip6subnet%%::*}::1"
50 # Determine the IPv6 prefix
51 local ip6lanprefix
="$ip6subnet/$(($ip6prefixlen + 32 - $ip4prefixlen))"
53 proto_init_update
"$link" 1
54 proto_add_ipv6_address
"$ip6addr" "$ip6prefixlen"
55 proto_add_ipv6_prefix
"$ip6lanprefix"
57 proto_add_ipv6_route
"::" 0 "::$peeraddr" 4096 "" "$ip6addr/$ip6prefixlen"
58 proto_add_ipv6_route
"::" 0 "::$peeraddr" 4096 "" "$ip6lanprefix"
61 json_add_string mode sit
62 json_add_int mtu
"${mtu:-1280}"
63 json_add_boolean df
"${df:-1}"
64 json_add_int ttl
"${ttl:-64}"
65 [ -n "$tos" ] && json_add_string tos
"$tos"
66 json_add_string
local "$ipaddr"
67 [ -n "$tunlink" ] && json_add_string link
"$tunlink"
69 json_add_object
'data'
70 json_add_string prefix
"$ip6prefix/$ip6prefixlen"
71 json_add_string relay-prefix
"$ip4prefix/$ip4prefixlen"
77 [ -n "$zone" ] && json_add_string zone
"$zone"
80 proto_send_update
"$cfg"
83 proto_6rd_teardown
() {
87 proto_6rd_init_config
() {
91 proto_config_add_int
"mtu"
92 proto_config_add_boolean
"df"
93 proto_config_add_int
"ttl"
94 proto_config_add_string
"tos"
95 proto_config_add_string
"ipaddr"
96 proto_config_add_string
"peeraddr"
97 proto_config_add_string
"ip6prefix"
98 proto_config_add_string
"ip6prefixlen"
99 proto_config_add_string
"ip4prefixlen"
100 proto_config_add_string
"tunlink"
101 proto_config_add_string
"zone"
104 [ -n "$INCLUDE_ONLY" ] ||
{