Skip to content

Commit 5929085

Browse files
Przemysław Fierekjwhui
authored andcommitted
[dns64] improve DNS64 script (openthread#110)
1 parent 1bcf693 commit 5929085

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

script/_dns64

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,74 @@
3131
#
3232

3333
BIND_CONF_OPTIONS=/etc/bind/named.conf.options
34-
RESOLV_CONF=/etc/resolv.conf
3534
NAT64_PREFIX=64:ff9b::/96
3635

3736
DNS64_NAMESERVER_ADDR=127.0.0.1
3837
DNS64_CONF="dns64 `echo $NAT64_PREFIX | tr \"/\" \"\/\"` { clients { any; }; recursive-only yes; };"
3938

39+
# Currently solution was verified only on raspbian and ubuntu.
40+
#
41+
without NAT64 || test $PLATFORM = ubuntu || test $PLATFORM = raspbian || die "dns64 is not tested under $PLATFORM."
42+
43+
if [ $PLATFORM = raspbian ]; then
44+
RESOLV_CONF_HEAD=/etc/resolv.conf.head
45+
elif [ $PLATFORM = ubuntu ]; then
46+
RESOLV_CONF_HEAD=/etc/resolvconf/resolv.conf.d/head
47+
fi
48+
49+
dns64_update_resolvconf()
50+
{
51+
if [ $PLATFORM = ubuntu ]; then
52+
sudo resolvconf -u || true
53+
elif [ $PLATFORM = raspbian ]; then
54+
sudo systemctl restart dhcpcd || true
55+
fi
56+
}
57+
4058
dns64_install()
4159
{
4260
with NAT64 && with DNS64 || return 0
4361

4462
test -f $BIND_CONF_OPTIONS || die 'Cannot find bind9 configuration file!'
4563
sudo sed -i '/^};/i\\tallow-recursion { any; };' $BIND_CONF_OPTIONS
4664
sudo sed -i '/^};/i\\t'"$DNS64_CONF" $BIND_CONF_OPTIONS
65+
66+
sudo sh -c "echo \"nameserver $DNS64_NAMESERVER_ADDR\" >> $RESOLV_CONF_HEAD"
67+
68+
if have systemctl; then
69+
sudo systemctl enable bind9 || true
70+
sudo systemctl is-enabled bind9 || die 'Failed to enable bind9!'
71+
sudo systemctl start bind9 || die 'Failed to start bind9!'
72+
fi
73+
74+
dns64_update_resolvconf
4775
}
4876

4977
dns64_uninstall()
5078
{
5179
with NAT64 && with DNS64 || return 0
5280

53-
dns64_stop
81+
dns64_stop
5482
sudo sed -i '/^\tallow-recursion/d' $BIND_CONF_OPTIONS
5583
sudo sed -i '/^\tdns64/d' $BIND_CONF_OPTIONS
84+
85+
sudo sed -i '/^nameserver '$DNS64_NAMESERVER_ADDR'/d' $RESOLV_CONF_HEAD || true
86+
87+
dns64_update_resolvconf
88+
89+
if have systemctl; then
90+
sudo systemctl stop bind9 || true
91+
sudo systemctl disable bind9 || true
92+
fi
5693
}
5794

5895
dns64_start()
5996
{
6097
with NAT64 && with DNS64 || return 0
6198

62-
if have systemctl; then
99+
if have systemctl; then
63100
sudo systemctl start bind9 || die 'Failed to start bind9!'
64101
fi
65-
66-
sudo sed -i '1a nameserver '$DNS64_NAMESERVER_ADDR $RESOLV_CONF
67102
}
68103

69104
dns64_stop()
@@ -73,6 +108,4 @@ dns64_stop()
73108
if have systemctl; then
74109
sudo systemctl stop bind9 || true
75110
fi
76-
77-
sudo sed -i '/^nameserver\s'$DNS64_NAMESERVER_ADDR'/d' $RESOLV_CONF
78111
}

script/_nat64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TAYGA_IPV6_ADDR=fdaa:bb:1::1
3737
NAT44_SERVICE=/etc/init.d/otbr-nat44
3838
WLAN_IFNAMES=eth0
3939

40-
# Currently only ubuntu is verified.
40+
# Currently solution was verified only on raspbian and ubuntu.
4141
#
4242
without NAT64 || test $PLATFORM = ubuntu || test $PLATFORM = raspbian || die "nat64 is not tested under $PLATFORM."
4343

script/update

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@
3636
. script/_wpantund
3737
. script/_ipforward
3838
. script/_nat64
39+
. script/_dns64
3940

4041
main()
4142
{
4243
. $BEFORE_HOOK
4344
otbr_uninstall
4445
wpantund_uninstall
4546
nat64_uninstall
47+
dns64_uninstall
4648
ipforward_uninstall
4749

4850
ipforward_install
4951
nat64_install
52+
dns64_install
5053
wpantund_update
5154
otbr_update
5255
. $AFTER_HOOK

0 commit comments

Comments
 (0)