change the way resolv.conf is being created, so that it also works when dnsmasq is...
[openwrt/svn-archive/openwrt.git] / openwrt / package / dnsmasq / files / S50dnsmasq
1 #!/bin/sh
2
3 # The following is to automatically configure the DHCP settings
4 # based on nvram settings. Feel free to replace all this crap
5 # with a simple "dnsmasq" and manage everything via the
6 # /etc/dnsmasq.conf config file
7
8 # DHCP interface (lan, wan, wifi -- any ifup *)
9 iface=lan
10 ifname=$(nvram get ${iface}_ifname)
11
12 udhcpc -n -q -R -s /bin/true -i $ifname >&- || {
13 # no existing DHCP server?
14
15 # calculate settings
16 ipaddr=$(nvram get ${iface}_ipaddr)
17 netmask=$(nvram get ${iface}_netmask)
18 start=$(nvram get dhcp_start)
19 num=$(nvram get dhcp_num)
20
21 eval $(ipcalc $ipaddr $netmask ${start:-100} ${num:-150})
22 lease=$(nvram get dhcp_lease)
23
24 # and pass the args via the commandline
25 # (because trying to edit the config from here is crazy)
26 args="-K -F $START,$END,$NETMASK,${lease:-12h}"
27 }
28
29 # ignore requests from wan interface
30 wanproto=$(nvram get wan_proto)
31 [ -z "$wanproto" -o "$wanproto" = "none" ] || args="${args} -I $(nvram get wan_ifname)"
32
33 dnsmasq ${args} && {
34 # use dnsmasq for local dns requests
35 rm -f /tmp/resolv.conf
36 cat > /tmp/resolv.conf <<EOF
37 nameserver 127.0.0.1
38 search lan
39 EOF
40 }