summaryrefslogtreecommitdiff
path: root/openwrt/package/dnsmasq
diff options
context:
space:
mode:
Diffstat (limited to 'openwrt/package/dnsmasq')
-rw-r--r--openwrt/package/dnsmasq/Makefile2
-rwxr-xr-xopenwrt/package/dnsmasq/files/S50dnsmasq30
-rw-r--r--openwrt/package/dnsmasq/files/dnsmasq.conf8
-rw-r--r--openwrt/package/dnsmasq/files/dnsmasq.init45
4 files changed, 53 insertions, 32 deletions
diff --git a/openwrt/package/dnsmasq/Makefile b/openwrt/package/dnsmasq/Makefile
index 393f0f0..88bd9f2 100644
--- a/openwrt/package/dnsmasq/Makefile
+++ b/openwrt/package/dnsmasq/Makefile
@@ -31,6 +31,6 @@ $(IPKG_DNSMASQ):
$(STRIP) $(IDIR_DNSMASQ)/usr/sbin/*
install -d -m0755 $(IDIR_DNSMASQ)/etc/init.d/
install -m0644 ./files/dnsmasq.conf $(IDIR_DNSMASQ)/etc/dnsmasq.conf
- install -m0755 ./files/S50dnsmasq $(IDIR_DNSMASQ)/etc/init.d/S50dnsmasq
+ install -m0755 ./files/dnsmasq.init $(IDIR_DNSMASQ)/etc/init.d/S50dnsmasq
$(IPKG_BUILD) $(IDIR_DNSMASQ) $(PACKAGE_DIR)
diff --git a/openwrt/package/dnsmasq/files/S50dnsmasq b/openwrt/package/dnsmasq/files/S50dnsmasq
deleted file mode 100755
index 17e331f..0000000
--- a/openwrt/package/dnsmasq/files/S50dnsmasq
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-. /etc/functions.sh
-. /etc/network.overrides
-[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network
-
-# interface to use for DHCP
-iface=lan
-
-ifname=$(nvram get ${iface}_ifname)
-ipaddr=$(nvram get ${iface}_ipaddr)
-netmask=$(nvram get ${iface}_netmask)
-
-# check for existing DHCP server
-udhcpc -n -q -R -s /bin/true -i $ifname >&- || {
-
- ipaddr=$(ip2int $ipaddr)
- netmask=$(ip2int ${netmask:-255.255.255.0})
- network=$((ipaddr&netmask))
-
- start=$(nvram get dhcp_start)
- start=$((network+${start:-100}))
- end=$(nvram get dhcp_num)
- end=$((start+${end:-150}))
-
- wanproto=$(nvram get wan_proto)
- [ -z "$wanproto" -o "$wanproto" = "none" ] || wanif=$(nvram get wan_ifname)
-
- args="-K -F $(int2ip $start),$(int2ip $end),$(int2ip $netmask),12h ${wanif:+-I ${wanif} }"
-}
-dnsmasq ${args}
diff --git a/openwrt/package/dnsmasq/files/dnsmasq.conf b/openwrt/package/dnsmasq/files/dnsmasq.conf
index d4a9f08..7aed3a3 100644
--- a/openwrt/package/dnsmasq/files/dnsmasq.conf
+++ b/openwrt/package/dnsmasq/files/dnsmasq.conf
@@ -9,9 +9,15 @@ local=/lan/
domain=lan
expand-hosts
+@ifdef dhcp_enable
+dhcp-range=@@start@@,@@end@@,@@netmask@@,@@lease@@
+@endif
+@ifdef wan_ifname
+except-interface=@@wan_ifname@@
+@endif
+
# enable dhcp (start,end,netmask,leasetime)
dhcp-authoritative
-#dhcp-range=192.168.1.100,192.168.1.250,255.255.255.0,12h
dhcp-leasefile=/tmp/dhcp.leases
# use /etc/ethers for static hosts; same format as --dhcp-host
diff --git a/openwrt/package/dnsmasq/files/dnsmasq.init b/openwrt/package/dnsmasq/files/dnsmasq.init
new file mode 100644
index 0000000..17ef43c
--- /dev/null
+++ b/openwrt/package/dnsmasq/files/dnsmasq.init
@@ -0,0 +1,45 @@
+#!/bin/sh
+. /etc/config/network
+
+# The following is to automatically configure the DHCP settings
+# based on config settings. Feel free to replace all this crap
+# with a simple "dnsmasq" and manage everything via the
+# /etc/dnsmasq.conf config file
+
+[ -f /etc/dnsmasq.conf ] || exit
+
+args=""
+iface=lan
+eval "ifname=\${${iface}_ifname}"
+
+dhcp_enable="${dhcp_enable:-1}"
+dhcp_start="${dhcp_start:-100}"
+dhcp_num="${dhcp_num:-50}"
+dhcp_lease="${dhcp_lease:-12h}"
+
+# if dhcp_enable is unset and there is a dhcp server on the network already, default to dhcp_enable=0
+[ -z "$dhcp_enable" ] && udhcpc -n -q -R -s /bin/true -i $ifname >&- && dhcp_enable="${dhcp_enable:-0}"
+
+# dhcp_enable=0 disables the dhcp server
+(
+ [ -z "$dhcp_enable" -o "$dhcp_enable" -eq 1 ] && {
+ # no existing DHCP server?
+
+ # calculate settings
+ eval "ipaddr=\${${iface}_ipaddr}"
+ eval "netmask=\${${iface}_netmask}"
+ eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150})
+
+ # and pass the args via config parser defines
+ echo "@define dhcp_enable 1"
+ echo "@define netmask $NETMASK"
+ echo "@define start $START"
+ echo "@define end $END"
+ echo "@define lease ${dhcp_lease:-12h}"
+ }
+
+ # ignore requests from wan interface
+ [ -z "$wan_proto" -o "$wan_proto" = "none" ] || echo "@define wan_ifname $wan_ifname"
+
+ cat /etc/dnsmasq.conf
+) | awk -f /usr/lib/parse-config.awk | dnsmasq -C /proc/self/fd/0