3 # Copyright (c) 2017, The OpenThread Authors.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # 3. Neither the name of the copyright holder nor the
14 # names of its contributors may be used to endorse or promote products
15 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
30 # This script manipulates nat64 configuration.
33 TAYGA_DEFAULT=/etc/default/tayga
34 TAYGA_CONF=/etc/tayga.conf
35 TAYGA_IPV4_ADDR=192.168.255.1
36 TAYGA_IPV6_ADDR=fdaa:bb:1::1
37 TAYGA_TUN_V6_ADDR=fdaa:bb:1::2
38 NAT44_SERVICE=/etc/init.d/otbr-nat44
41 # Currently solution was verified only on raspbian and ubuntu.
43 #without NAT64 || test $PLATFORM = ubuntu || test $PLATFORM = raspbian || die "nat64 is not tested under $PLATFORM."
47 with NAT64 || return 0
49 test -f $TAYGA_DEFAULT -a -f $TAYGA_CONF || die 'Cannot find tayga configuration file!'
50 sudo sed -i 's/^RUN="no"/RUN="yes"/' $TAYGA_DEFAULT
51 sudo sed -i 's/^IPV4_TUN_ADDR=""/IPV4_TUN_ADDR="'$TAYGA_IPV4_ADDR'"/' $TAYGA_DEFAULT
52 sudo sed -i 's/^IPV6_TUN_ADDR=""/IPV6_TUN_ADDR="'$TAYGA_TUN_V6_ADDR'"/' $TAYGA_DEFAULT
53 sudo sed -i 's/^prefix /##prefix /' $TAYGA_CONF
54 sudo sed -i 's/^# prefix 64:ff9b::\/96/prefix 64:ff9b::\/96/' $TAYGA_CONF
55 sudo sed -i '/^#ipv6-addr/a ipv6-addr '$TAYGA_IPV6_ADDR $TAYGA_CONF
56 sudo tee $NAT44_SERVICE <<EOF
59 # Copyright (c) 2017, The OpenThread Authors.
60 # All rights reserved.
62 # Redistribution and use in source and binary forms, with or without
63 # modification, are permitted provided that the following conditions are met:
64 # 1. Redistributions of source code must retain the above copyright
65 # notice, this list of conditions and the following disclaimer.
66 # 2. Redistributions in binary form must reproduce the above copyright
67 # notice, this list of conditions and the following disclaimer in the
68 # documentation and/or other materials provided with the distribution.
69 # 3. Neither the name of the copyright holder nor the
70 # names of its contributors may be used to endorse or promote products
71 # derived from this software without specific prior written permission.
73 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
77 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
78 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
79 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
80 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
81 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
82 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
83 # POSSIBILITY OF SUCH DAMAGE.
86 # Provides: otbr-nat44
87 # Required-Start: tayga
91 # Default-Start: 2 3 4 5
93 # Short-Description: iptables NAT44
94 # Description: NAT44 is require for OpenThread border router
95 # to connect to arbitrary IPv4 endpoints.
98 . /lib/lsb/init-functions
104 for IFNAME in $WLAN_IFNAMES; do
105 echo " iptables -t nat -A POSTROUTING -o $IFNAME -j MASQUERADE" | sudo tee -a $NAT44_SERVICE
107 sudo tee -a $NAT44_SERVICE <<EOF
109 restart|reload|force-reload)
110 echo "Error: argument '\$1' not supported" >&2
117 echo "Usage: \$0 start|stop" >&2
122 sudo chmod a+x $NAT44_SERVICE
123 if have systemctl; then
124 sudo systemctl stop tayga || die 'Unable to stop tayga service!'
125 sudo systemctl enable otbr-nat44 || die 'Unable to enable nat44 service!'
131 with NAT64 || return 0
134 sudo sed -i 's/^RUN="yes"/RUN="no"/' $TAYGA_DEFAULT
135 sudo sed -i 's/^IPV4_TUN_ADDR="'$TAYGA_IPV4_ADDR'"/IPV4_TUN_ADDR=""/' $TAYGA_DEFAULT
136 sudo sed -i 's/^prefix 64:ff9b::\/96/# prefix 64:ff9b::\/96/' $TAYGA_CONF
137 sudo sed -i 's/^##prefix /prefix /' $TAYGA_CONF
138 sudo sed -i '/^ipv6-addr '$TAYGA_IPV6_ADDR'/d' $TAYGA_CONF
140 if have systemctl; then
141 sudo systemctl disable otbr-nat44 || true
144 # systemctl disable doesn't remove sym-links
145 if have update-rc.d; then
146 sudo update-rc.d otbr-nat44 remove || true
148 test ! -f $NAT44_SERVICE || sudo rm $NAT44_SERVICE
153 with NAT64 || return 0
156 service tayga start || die 'Failed to start tayga'
157 elif have systemctl; then
158 sudo systemctl start tayga || die 'Failed to start tayga!'
159 sudo systemctl enable tayga || die 'Failed to enable tayga!'
160 sudo systemctl start otbr-nat44 || die 'Failed to start NAT44!'
166 with NAT64 || return 0
169 service tayga stop || true
170 elif have systemctl; then
171 sudo systemctl stop tayga || true
172 sudo systemctl stop otbr-nat44 || true