upgrade dnsmasq to latest version, rewrite dnsmasq init script for uci, rename /bin...
authorFelix Fietkau <nbd@openwrt.org>
Sat, 17 Mar 2007 13:31:13 +0000 (13:31 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 17 Mar 2007 13:31:13 +0000 (13:31 +0000)
SVN-Revision: 6595

package/base-files/files/bin/ipcalc [deleted file]
package/base-files/files/bin/ipcalc.sh [new file with mode: 0755]
package/dnsmasq/Makefile
package/dnsmasq/files/dhcp.conf [new file with mode: 0644]
package/dnsmasq/files/dnsmasq.conf
package/dnsmasq/files/dnsmasq.init

diff --git a/package/base-files/files/bin/ipcalc b/package/base-files/files/bin/ipcalc
deleted file mode 100755 (executable)
index e8efa6b..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-awk -f /usr/lib/common.awk -f - $* <<EOF
-BEGIN {
-       ipaddr=ip2int(ARGV[1])
-       netmask=ip2int(ARGV[2])
-       network=and(ipaddr,netmask)
-       broadcast=or(network,compl(netmask))
-       
-       start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
-       limit=network+1
-       if (start<limit) start=limit
-       
-       end=start+ARGV[4]
-       limit=or(network,compl(netmask))-1
-       if (end>limit) end=limit
-
-       print "IP="int2ip(ipaddr)
-       print "NETMASK="int2ip(netmask)
-       print "BROADCAST="int2ip(broadcast)
-       print "NETWORK="int2ip(network)
-       print "PREFIX="32-bitcount(compl(netmask))
-       
-       # range calculations:
-       # ipcalc <ip> <netmask> <start> <num>
-       
-       if (ARGC > 3) {
-               print "START="int2ip(start)
-               print "END="int2ip(end-1)
-       }
-}
-EOF
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh
new file mode 100755 (executable)
index 0000000..e8efa6b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+awk -f /usr/lib/common.awk -f - $* <<EOF
+BEGIN {
+       ipaddr=ip2int(ARGV[1])
+       netmask=ip2int(ARGV[2])
+       network=and(ipaddr,netmask)
+       broadcast=or(network,compl(netmask))
+       
+       start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
+       limit=network+1
+       if (start<limit) start=limit
+       
+       end=start+ARGV[4]
+       limit=or(network,compl(netmask))-1
+       if (end>limit) end=limit
+
+       print "IP="int2ip(ipaddr)
+       print "NETMASK="int2ip(netmask)
+       print "BROADCAST="int2ip(broadcast)
+       print "NETWORK="int2ip(network)
+       print "PREFIX="32-bitcount(compl(netmask))
+       
+       # range calculations:
+       # ipcalc <ip> <netmask> <start> <num>
+       
+       if (ARGC > 3) {
+               print "START="int2ip(start)
+               print "END="int2ip(end-1)
+       }
+}
+EOF
index 2b6e7945cbc33550b3b9dd9400ed19a5df57f578..6b763741de0eeee247e0e01a74aa0c287eec36a5 100644 (file)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=dnsmasq
-PKG_VERSION:=2.35
+PKG_VERSION:=2.38
 PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq
-PKG_MD5SUM:=57b8643dc394cf2fbd1bced64536c6df
+PKG_MD5SUM:=ab066a97c226066485ad20e5ad5ce424
 
 include $(INCLUDE_DIR)/package.mk
 
@@ -42,7 +42,8 @@ endef
 define Package/dnsmasq/install
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/dnsmasq $(1)/usr/sbin/
-       $(INSTALL_DIR) $(1)/etc
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/dhcp.conf $(1)/etc/config/dhcp
        $(INSTALL_DATA) ./files/dnsmasq.conf $(1)/etc/dnsmasq.conf
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/dnsmasq.init $(1)/etc/init.d/dnsmasq
diff --git a/package/dnsmasq/files/dhcp.conf b/package/dnsmasq/files/dhcp.conf
new file mode 100644 (file)
index 0000000..fb55cf8
--- /dev/null
@@ -0,0 +1,9 @@
+config dhcp
+       option interface        lan
+       option start    100
+       option limit    150
+       option leasetime        12h
+
+config dhcp
+       option interface        wan
+       option ignore   1
index 8a8191b635138b1e69a4b7c14a0c571071f996e3..5be394696ad697bf26ab9f2f3b162ddb2f9cb1c9 100644 (file)
@@ -10,14 +10,8 @@ domain=lan
 expand-hosts
 resolv-file=/tmp/resolv.conf.auto
 
-@ifdef dhcp_enable
-dhcp-range=@@start@@,@@end@@,@@netmask@@,@@lease@@
 dhcp-authoritative
 dhcp-leasefile=/tmp/dhcp.leases
-@endif
-@ifdef wan_ifname
-except-interface=@@wan_ifname@@
-@endif
 
 # use /etc/ethers for static hosts; same format as --dhcp-host
 # <hwaddr> <ipaddr>
index 5e72fd014f59d22271a01e2ef529b91da6b782b9..52973d4ca051807200d62433c4ba538afbdb8ced 100644 (file)
@@ -2,55 +2,67 @@
 # Copyright (C) 2006 OpenWrt.org
 
 START=60
-start() {
-       include /lib/network
-       scan_interfaces
-       
-       # 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
+
+dhcp_calc() {
+       local ip="$1"
+       local res=0
        
-       args=""
-       iface=lan
-       config_get ifname "$iface" ifname
-       config_get proto "$iface" proto
+       while [ -n "$ip" ]; do
+               part="${ip%%.*}"
+               res="$(($res * 256))"
+               res="$(($res + $part))"
+               [ "${ip%.*}" != "$ip" ] && ip="${ip#*.}" || ip=
+       done
+       echo "$res"
+}
+
+dhcp_add() {
+       local cfg="$1"
+
+       config_get net "$cfg" interface
+       [ -n "$net" ] || return 0
        
-       [ "$proto" = static ] && dhcp_enable="${dhcp_enable:-1}"
-       dhcp_start="${dhcp_start:-100}"
-       dhcp_num="${dhcp_num:-50}"
-       dhcp_lease="${dhcp_lease:-12h}"
+       config_get ifname "$net" ifname
+       [ -n "$ifname" ] || return 0
        
-       # 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}"
+       config_get_bool ignore "$cfg" ignore
+       [ "$ignore" -gt 0 ] && {
+               append args "-I $ifname"
+               return 0
+       }
        
-       # dhcp_enable=0 disables the dhcp server
-       (
-               [ -z "$dhcp_enable" -o "$dhcp_enable" -eq 1 ] && {
-                       # no existing DHCP server?
+       config_get proto "$net" proto
+       [ static = "$proto" ] || return 0
        
-                       # calculate settings
-                       config_get ipaddr "$iface" ipaddr
-                       config_get netmask "$iface" netmask
-                       eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150})
-                       
-                       # and pass the args via config parser defines
-                       echo "${dhcp_enable:+@define dhcp_enable 1}"
-                       echo "@define netmask $NETMASK"
-                       echo "@define start $START"
-                       echo "@define end $END"
-                       echo "@define lease ${dhcp_lease:-12h}"
-               }
+       config_get ipaddr "$net" ipaddr
+       config_get netmask "$net" netmask
+
+       # check for an already active dhcp server on the interface, unless 'force' is set
+       config_get_bool force "$cfg" force 0
+       [ "$force" -gt 0 ] || {
+               udhcpc -n -q -R -s /bin/true -i $ifname >&- && return 0
+       }
        
-               # ignore requests from wan interface
-               config_get wan_proto wan proto
-               config_get wan_ifname wan ifname
-               [ -z "$wan_proto" -o "$wan_proto" = "none" ] || echo "@define wan_ifname $wan_ifname"
+       config_get start "$cfg" start
+       config_get end "$cfg" end
+       config_get leasetime "$cfg" leasetime
+
+       leasetime="${leasetime:-12h}"
+       start="$(dhcp_calc "${start:-100}")"
+       end="$((${end:-150} + 1))"
+       eval "$(ipcalc.sh $ipaddr $netmask $start $end)"
+       append args "-F $START,$END,$NETMASK,$leasetime"        
+}
+
+start() {
+       include /lib/network
+       scan_interfaces
+       config_load dhcp
+
+       args=""
+       config_foreach dhcp_add dhcp
        
-               cat /etc/dnsmasq.conf
-       ) | awk -f /lib/config/template.awk | dnsmasq -C /proc/self/fd/0 && {
+       dnsmasq $args && {
                rm -f /tmp/resolv.conf
                cat > /tmp/resolv.conf <<EOF
 nameserver 127.0.0.1