[PATCH] add interface and hosts parsing from uci dhcp config to ISC dhcpd (fix bridges)
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 24 May 2011 10:01:23 +0000 (10:01 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 24 May 2011 10:01:23 +0000 (10:01 +0000)
This allows people to use the luci interface to specify to dhcpd which
interfaces it should listen to, and which static MAC->IP host mappings
should it define
For the interface, this has to be done in the initscript, via
commandline when the server is started
For the static hosts, the initscript makes a file called
/tmp/dhcpd.hosts which you can include in your dhcpd.config to use the
webgui defined hosts
Fix: 7.5.2011. Now works properly on interfaces which are in a bridge

Signed-off-by: Rajko Stojadinovic <admin@rajko.info>
SVN-Revision: 26998

net/dhcp/Makefile
net/dhcp/files/dhcpd.init

index 60adc75bef196cd7abdd71f570ee14339d461521..374ec6fc1febccb3bacf8249fb6b660e6ac7494a 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2008 OpenWrt.org
+# Copyright (C) 2006-2011 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=dhcp
 PKG_VERSION:=3.1.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=ftp://ftp.isc.org/isc/dhcp/
index c9ac1e3084914c9a3428a09804bbc552965875f9..308f3aa40ddce1fb2166f6a84a4d57a5fe1c76f5 100644 (file)
@@ -4,6 +4,65 @@ START=60
 lease_file=/tmp/dhcpd.leases
 config_file=/etc/dhcpd.conf
 pid_file=/var/run/dhcpd.pid
+hosts_file=/tmp/dhcpd.hosts
+dhcp_ifs=""
+
+append_interface() {
+       local ifname=$(uci_get_state network "$1" device)
+       if [ "$(uci_get_state network "$1" type)" = "bridge" ]; then
+               ifname=$(uci_get_state network "$1" ifname); fi
+
+       if [ -z "$dhcp_ifs" ]; then
+               dhcp_ifs="$ifname"
+       else
+               dhcp_ifs="$dhcp_ifs $ifname"
+       fi
+}
+
+parse_dhcp() {
+       local cfg="$1"
+       config_get net "$cfg" interface
+       [ -n "$net" ] || return 0
+
+       config_get_bool ignore "$1" ignore 0
+       if [ "$ignore" -eq 1 ]; then return 0; fi
+
+       append_interface $net
+}
+
+parse_host_entry() {
+               local cfg="$1"
+
+               config_get name "$cfg" name
+
+               config_get ip "$cfg" ip
+               [ -n "$ip" ] || return 0
+
+       local i=0
+               config_get mac "$cfg" mac
+               for m in $mac; do
+               local hostid="$name"
+               if [ $i -ne 0 ]; then hostid="$name"_"$i"; fi
+
+               echo "host $hostid {" >> "$hosts_file"
+               echo "hardware ethernet $m;" >> "$hosts_file"
+               echo "fixed-address $ip;" >> "$hosts_file"
+               echo "}" >> $hosts_file
+
+               i=$((i+1))
+       done
+}
+
+init_config() {
+       echo " #Automatically generated by dhcpd initscript, any modifications will be overwritten" > "$hosts_file"
+
+       include /lib/network
+       scan_interfaces
+       config_load dhcp
+
+       config_foreach parse_host_entry host
+       config_foreach parse_dhcp dhcp
+}
 
 start() {
        if [ -e $pid_file ] ; then