ds-lite: disable NAT according to RFC 7084
[openwrt/staging/chunkeey.git] / package / network / ipv6 / ds-lite / files / dslite.sh
1 #!/bin/sh
2 # dslite.sh - IPv4-in-IPv6 tunnel backend
3 # Copyright (c) 2013 OpenWrt.org
4
5 [ -n "$INCLUDE_ONLY" ] || {
6 . /lib/functions.sh
7 . /lib/functions/network.sh
8 . ../netifd-proto.sh
9 init_proto "$@"
10 }
11
12 proto_dslite_setup() {
13 local cfg="$1"
14 local iface="$2"
15 local link="dslite-$cfg"
16
17 local mtu ttl peeraddr ip6addr tunlink zone weakif
18 json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif
19
20 [ -z "$peeraddr" ] && {
21 proto_notify_error "$cfg" "MISSING_ADDRESS"
22 proto_block_restart "$cfg"
23 return
24 }
25
26 ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
27
28 [ -z "$ip6addr" ] && {
29 local wanif="$tunlink"
30 if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
31 proto_notify_error "$cfg" "NO_WAN_LINK"
32 return
33 fi
34
35 if ! network_get_ipaddr6 ip6addr "$wanif"; then
36 [ -z "$weakif" ] && weakif="lan"
37 if ! network_get_ipaddr6 ip6addr "$weakif"; then
38 proto_notify_error "$cfg" "NO_WAN_LINK"
39 return
40 fi
41 fi
42 }
43
44 proto_init_update "$link" 1
45 proto_add_ipv4_route "0.0.0.0" 0
46 proto_add_ipv4_address "192.0.0.2" "" "" "192.0.0.1"
47
48 proto_add_tunnel
49 json_add_string mode ipip6
50 json_add_int mtu "${mtu:-1280}"
51 json_add_int ttl "${ttl:-64}"
52 json_add_string local "$ip6addr"
53 json_add_string remote "$peeraddr"
54 [ -n "$tunlink" ] && json_add_string link "$tunlink"
55 proto_close_tunnel
56
57 proto_add_data
58 [ -n "$zone" ] && json_add_string zone "$zone"
59
60 json_add_array firewall
61 json_add_object ""
62 json_add_string type nat
63 json_add_string target ACCEPT
64 json_close_object
65 json_close_array
66 proto_close_data
67
68 proto_send_update "$cfg"
69 }
70
71 proto_dslite_teardown() {
72 local cfg="$1"
73 }
74
75 proto_dslite_init_config() {
76 no_device=1
77 available=1
78
79 proto_config_add_string "ip6addr"
80 proto_config_add_string "peeraddr"
81 proto_config_add_string "tunlink"
82 proto_config_add_int "mtu"
83 proto_config_add_int "ttl"
84 proto_config_add_string "zone"
85 proto_config_add_string "weakif"
86 }
87
88 [ -n "$INCLUDE_ONLY" ] || {
89 add_protocol dslite
90 }