2 # 464xlat.sh - 464xlat CLAT
4 # Copyright (c) 2015 Steven Barth <cyrus@openwrt.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2
8 # as published by the Free Software Foundation
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 [ -n "$INCLUDE_ONLY" ] ||
{
17 .
/lib
/functions
/network.sh
22 proto_464xlat_setup
() {
27 local ip6addr ip6prefix tunlink zone
28 json_get_vars ip6addr ip6prefix tunlink zone
30 [ "$zone" = "-" ] && zone
=""
32 ( proto_add_host_dependency
"$cfg" "::" "$tunlink" )
34 if [ -z "$tunlink" ] && ! network_find_wan6 tunlink
; then
35 proto_notify_error
"$cfg" "NO_WAN_LINK"
38 network_get_device tundev
"$tunlink"
40 ip6addr
=$
(464xlatcfg
"$link" "$tundev" "$ip6prefix" 192.0.0.1 $ip6addr)
41 if [ -z "$ip6addr" ]; then
42 proto_notify_error
"$cfg" "CLAT_CONFIG_FAILED"
46 ip
-6 rule del from all lookup
local
47 ip
-6 rule add from all lookup
local pref
1
48 ip
-6 rule add to
$ip6addr lookup prelocal pref
0
49 echo "$ip6addr" > /tmp
/464-$cfg-anycast
51 proto_init_update
"$link" 1
52 proto_add_ipv4_route
"0.0.0.0" 0 "" "" 2048
53 proto_add_ipv6_route
$ip6addr 128 "" "" "" "" 128
56 [ -n "$zone" ] && json_add_string zone
"$zone"
58 json_add_array firewall
59 [ -z "$zone" ] && zone
=$
(fw3
-q network
$iface 2>/dev
/null
)
62 json_add_string
type nat
63 json_add_string target SNAT
64 json_add_string family inet
65 json_add_string snat_ip
192.0.0.1
69 json_add_string
type rule
70 json_add_string family inet6
71 json_add_string proto all
72 json_add_string direction
in
73 json_add_string dest
"$zone"
74 json_add_string src
"$zone"
75 json_add_string src_ip
$ip6addr
76 json_add_string target ACCEPT
82 proto_send_update
"$cfg"
85 proto_464xlat_teardown
() {
89 [ -f /tmp
/464-$cfg-anycast ] ||
return
90 local ip6addr
=$
(cat /tmp
/464-$cfg-anycast)
94 rm -rf /tmp
/464-$cfg-anycast
95 [ -n "$ip6addr" ] && ip
-6 rule del to
$ip6addr lookup prelocal
97 if [ -z "$(ls /tmp/464-*-anycast 2>&-)" ]; then
98 ip
-6 rule del from all lookup
local
99 ip
-6 rule add from all lookup
local pref
0
103 proto_464xlat_init_config
() {
107 proto_config_add_string
"ip6prefix"
108 proto_config_add_string
"ip6addr"
109 proto_config_add_string
"tunlink"
110 proto_config_add_string
"zone"
113 [ -n "$INCLUDE_ONLY" ] ||
{