4 # The following is to automatically configure the DHCP settings
5 # based on config settings. Feel free to replace all this crap
6 # with a simple "dnsmasq" and manage everything via the
7 # /etc/dnsmasq.conf config file
9 [ -f /etc/dnsmasq.conf ] || exit
13 eval "ifname=\${${iface}_ifname}"
15 dhcp_enable="${dhcp_enable:-1}"
16 dhcp_start="${dhcp_start:-100}"
17 dhcp_num="${dhcp_num:-50}"
18 dhcp_lease="${dhcp_lease:-12h}"
20 # if dhcp_enable is unset and there is a dhcp server on the network already, default to dhcp_enable=0
21 [ -z "$dhcp_enable" ] && udhcpc -n -q -R -s /bin/true -i $ifname >&- && dhcp_enable="${dhcp_enable:-0}"
23 # dhcp_enable=0 disables the dhcp server
25 [ -z "$dhcp_enable" -o "$dhcp_enable" -eq 1 ] && {
26 # no existing DHCP server?
29 eval "ipaddr=\${${iface}_ipaddr}"
30 eval "netmask=\${${iface}_netmask}"
31 eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150})
33 # and pass the args via config parser defines
34 echo "@define dhcp_enable 1"
35 echo "@define netmask $NETMASK"
36 echo "@define start $START"
37 echo "@define end $END"
38 echo "@define lease ${dhcp_lease:-12h}"
41 # ignore requests from wan interface
42 [ -z "$wan_proto" -o "$wan_proto" = "none" ] || echo "@define wan_ifname $wan_ifname"
45 ) | awk -f /usr/lib/parse-config.awk | dnsmasq -C /proc/self/fd/0