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