1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007-2012 OpenWrt.org
4 # Preferably start dnscache after udhcpd/dnsmasq, to be sure /etc/resolv.conf is set correctly. dnsmasq is at S60, so dnscache is put at S65 as seen below. If /etc/resolv.conf is not used, then dnscache may be started at S47, just after the firewall has been set up.
6 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
7 DAEMON
=/usr
/bin
/dnscache
9 DESC
="Caching name server"
12 resolvfile
="/etc/resolv.conf"
15 echo "Starting $DESC: $NAME"
17 config_foreach get_userids global
19 cp -fa /etc
/dnscache
/* $ROOT
22 chown
-R $UID:$GID $ROOT
23 config_foreach start_dnscache dnscache
28 config_get UID
"$cfg" runasuser
29 config_get GID
"$cfg" runasgroup
35 echo $1 >> $ROOT/resolvers
39 echo $1 >> $ROOT/ignoreip
44 config_get logging
"$cfg" logging
45 config_get useresolvconf
"$cfg" useresolvconf
46 config_get iface
"$cfg" interface
47 config_get ifacesend
"$cfg" interfacesend
48 config_get defaultallowif
"$cfg" defaultallowif
49 config_get CACHESIZE
"$cfg" cachesize
50 config_get FORWARDONLY
"$cfg" forwardonly
51 config_get HIDETTL
"$cfg" hidettl
52 config_list_foreach
"$cfg" "resolver" append_server
53 config_get useignore
"$cfg" useignore
54 if [ "$useignore" == "1" ] ; then
55 config_list_foreach
"$cfg" "ignoreip" append_ignore
57 # Add some interface network addresses to list of allowed IP addresses (assumes /24 networks)
58 .
/lib
/functions
/network.sh
59 if [ -n "$defaultallowif" ] ; then
60 for myinterface
in `echo $defaultallowif`; do
61 network_get_ipaddr addr
$myinterface ||
continue
62 # the next line strips the last octet from the ip address
63 addr
=`echo $addr|sed 's/.[0-9]\+$//'`
65 echo Adding
$ROOT/ip
/$addr
68 # Translate listen interface names to IP addresses
69 network_get_ipaddr IP
"$iface"
70 # Translate send interface name to an IP address
71 network_get_ipaddr IPSEND
"$ifacesend"
72 # Unset HIDETTL if equal to 0
73 if [ "$HIDETTL" == "0" ] ; then
76 # If forwardingonly set then activate list of resolvers
77 if [ "$FORWARDONLY" == "0" ] ; then
78 # Unset FORWARDONLY if equal to '0'
81 # Use either fixed list of dnsservers or resolv.conf data
82 if [ "$useresolvconf" == "1" ] ; then
83 if [ -s "$resolvfile" ] ; then
84 cat $resolvfile|
grep nameserver|
sed 's/nameserver //g' > $ROOT/resolvers
86 echo Error
: $resolvfile does not exist.
90 if [ ! "`cat $ROOT/resolvers|wc -L`" == "0" ] ; then
91 cp -f $ROOT/resolvers
$ROOT/servers
/@
> /dev
/null
2>&1
93 echo Error
: No resolvers are defined.
99 # dnscache likes to receive a 128 byte random seed
100 dd if=/dev
/urandom of
=$ROOT/randomseed bs
=128 count
=1 > /dev
/null
2>&1
101 if [ "$DEBUG" == 1 ] ; then
102 $DAEMON < /$ROOT/randomseed
103 elif [ "$logging" == '1' ] ; then
104 $DAEMON 2>&1 < /$ROOT/randomseed | logger
-p local1.info
-t $NAME &
106 $DAEMON > /dev
/null
2>&1 < /$ROOT/randomseed
&
111 echo -n "Stopping $DESC: $NAME"
112 kill `pidof $NAME|sed "s/$$//g"` > /dev
/null
2>&1
117 echo "Restarting $DESC: $NAME... "