aboutsummaryrefslogtreecommitdiffstats
path: root/package/dnsmasq/files/dnsmasq.init
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2006-04-05 02:09:22 +0000
committerFelix Fietkau <nbd@openwrt.org>2006-04-05 02:09:22 +0000
commite1b417ee76bd97a05854f4304cef3f73e9da633b (patch)
treef5913675e5868c535c007efb3e09a01ce6890287 /package/dnsmasq/files/dnsmasq.init
parent42269e22a8b817e1e6bc2c9cbb2f03df31221458 (diff)
downloadupstream-e1b417ee76bd97a05854f4304cef3f73e9da633b.tar.gz
upstream-e1b417ee76bd97a05854f4304cef3f73e9da633b.tar.bz2
upstream-e1b417ee76bd97a05854f4304cef3f73e9da633b.zip
large init script cleanup and merge of whiterussian changes, new dnsmasq config handling
git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@3588 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/dnsmasq/files/dnsmasq.init')
-rw-r--r--package/dnsmasq/files/dnsmasq.init45
1 files changed, 45 insertions, 0 deletions
diff --git a/package/dnsmasq/files/dnsmasq.init b/package/dnsmasq/files/dnsmasq.init
new file mode 100644
index 0000000000..17ef43c3d5
--- /dev/null
+++ b/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