aboutsummaryrefslogtreecommitdiffstats
path: root/main/unbound/migrate-dnscache-to-unbound
blob: a2ad99e4f756736a7652a1b17e7e9bc50ef19b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh


to_subnet() {
	pref=$1
	case "$pref" in
	*.*.*.*) echo $pref/32;;
	*.*.*) echo $pref.0/24;;
	*.*) echo $pref.0.0/16;;
	*) echo $pref.0.0.0/8;;
	esac
}

gen_stub_zones() {
	local zonefile ip
	local fwdtype="stub"
	if [ -n "$FORWARDONLY" ]; then
		fwdtype="forward"
	fi
	for zonefile in "$root"/etc/dnscache/servers/*; do
		local zone=${zonefile##*/}
		if [ "$zone" = "@" ] || [ "$zone" = '*' ]; then
			continue
		fi
		
		echo "${fwdtype}-zone:"
		echo -e "\tname: ${zone}"
		for ip in $(cat $zonefile); do
			echo -e "\t${fwdtype}-addr: $ip"
		done
		echo ""
	done
}

root=${root:-/}
while getopts "r:" opt; do
	case "$opt" in
	'r') root="$OPTARG";;
	esac
done

confd="$root"/etc/conf.d/dnscache
if [ -r "$confd" ]; then
	. "$confd"
fi

interface="$IP"
outgoing_interface="$IPSEND"

echo $IPSEND
echo $IP
echo $FORWARDONLY

for i in "$root"/etc/dnscache/ip/*; do
	[ -f "$i" ] || continue
	access_control="$access_control $(to_subnet ${i##*/})"
done

echo -e "\tinterface: $IP\n"
echo -e "\toutgoing-interface: $IPSEND\n"
for i in $access_control; do
	echo -e "\taccess-control: $i allow"
done
echo ""

gen_stub_zones