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 [ -z "$zone" ] && zone
="wan"
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 proto_init_update
"$link" 1
47 proto_add_ipv4_route
"0.0.0.0" 0 "" "" 2048
48 proto_add_ipv6_route
$ip6addr 128 "" "" "" "" 128
51 [ "$zone" != "-" ] && json_add_string zone
"$zone"
53 json_add_array firewall
55 json_add_string
type nat
56 json_add_string target SNAT
57 json_add_string family inet
58 json_add_string snat_ip
192.0.0.1
61 json_add_string
type rule
62 json_add_string family inet6
63 json_add_string proto all
64 json_add_string direction
in
65 json_add_string dest
"$zone"
66 json_add_string src
"$zone"
67 json_add_string src_ip
$ip6addr
68 json_add_string target ACCEPT
73 proto_send_update
"$cfg"
76 proto_464xlat_teardown
() {
80 proto_464xlat_init_config
() {
84 proto_config_add_string
"ip6prefix"
85 proto_config_add_string
"ip6addr"
86 proto_config_add_string
"tunlink"
87 proto_config_add_string
"zone"
90 [ -n "$INCLUDE_ONLY" ] ||
{