nat46: Remove unnecessary 464xlat wan forwarding rule
[feed/routing.git] / nat46 / files / 464xlat.sh
1 #!/bin/sh
2 # 464xlat.sh - 464xlat CLAT
3 #
4 # Copyright (c) 2015 Steven Barth <cyrus@openwrt.org>
5 #
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
9 #
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.
14
15 [ -n "$INCLUDE_ONLY" ] || {
16 . /lib/functions.sh
17 . /lib/functions/network.sh
18 . ../netifd-proto.sh
19 init_proto "$@"
20 }
21
22 proto_464xlat_setup() {
23 local cfg="$1"
24 local iface="$2"
25 local link="464-$cfg"
26
27 local ip6addr ip6prefix tunlink zone
28 json_get_vars ip6addr ip6prefix tunlink zone
29
30 [ -z "$zone" ] && zone="wan"
31
32 ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
33
34 if [ -z "$tunlink" ] && ! network_find_wan6 tunlink; then
35 proto_notify_error "$cfg" "NO_WAN_LINK"
36 return
37 fi
38 network_get_device tundev "$tunlink"
39
40 ip6addr=$(464xlatcfg "$link" "$tundev" "$ip6prefix" 192.0.0.1 $ip6addr)
41 if [ -z "$ip6addr" ]; then
42 proto_notify_error "$cfg" "CLAT_CONFIG_FAILED"
43 return
44 fi
45
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
49
50 proto_add_data
51 [ "$zone" != "-" ] && json_add_string zone "$zone"
52
53 json_add_array firewall
54 json_add_object ""
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
59 json_close_object
60 json_add_object ""
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
69 json_close_object
70 json_close_array
71 proto_close_data
72
73 proto_send_update "$cfg"
74 }
75
76 proto_464xlat_teardown() {
77 464xlatcfg "464-$1"
78 }
79
80 proto_464xlat_init_config() {
81 no_device=1
82 available=1
83
84 proto_config_add_string "ip6prefix"
85 proto_config_add_string "ip6addr"
86 proto_config_add_string "tunlink"
87 proto_config_add_string "zone"
88 }
89
90 [ -n "$INCLUDE_ONLY" ] || {
91 add_protocol 464xlat
92 }