finally move buildroot-ng to trunk
[openwrt.git] / package / dnsmasq / files / dnsmasq.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 start() {
5         include /lib/network
6         scan_interfaces
7         
8         # The following is to automatically configure the DHCP settings
9         # based on config settings. Feel free to replace all this crap
10         # with a simple "dnsmasq" and manage everything via the
11         # /etc/dnsmasq.conf config file
12         
13         [ -f /etc/dnsmasq.conf ] || exit
14         
15         args=""
16         iface=lan
17         config_get ifname "$iface" ifname
18         config_get proto "$iface" proto
19         
20         [ "$proto" = static ] && dhcp_enable="${dhcp_enable:-1}"
21         dhcp_start="${dhcp_start:-100}"
22         dhcp_num="${dhcp_num:-50}"
23         dhcp_lease="${dhcp_lease:-12h}"
24         
25         # if dhcp_enable is unset and there is a dhcp server on the network already, default to dhcp_enable=0
26         [ -z "$dhcp_enable" ] && udhcpc -n -q -R -s /bin/true -i $ifname >&- && dhcp_enable="${dhcp_enable:-0}"
27         
28         # dhcp_enable=0 disables the dhcp server
29         (
30                 [ -z "$dhcp_enable" -o "$dhcp_enable" -eq 1 ] && {
31                         # no existing DHCP server?
32         
33                         # calculate settings
34                         config_get ipaddr "$iface" ipaddr
35                         config_get netmask "$iface" netmask
36                         eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150})
37                         
38                         # and pass the args via config parser defines
39                         echo "${dhcp_enable:+@define dhcp_enable 1}"
40                         echo "@define netmask $NETMASK"
41                         echo "@define start $START"
42                         echo "@define end $END"
43                         echo "@define lease ${dhcp_lease:-12h}"
44                 }
45         
46                 # ignore requests from wan interface
47                 config_get wan_proto wan proto
48                 config_get wan_ifname wan ifname
49                 [ -z "$wan_proto" -o "$wan_proto" = "none" ] || echo "@define wan_ifname $wan_ifname"
50         
51                 cat /etc/dnsmasq.conf
52         ) | awk -f /usr/lib/parse-config.awk | dnsmasq -C /proc/self/fd/0
53 }
54
55 stop() {
56         killall dnsmasq
57 }