2007-10-10 13:28:25 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
START=60
|
|
|
|
|
|
|
|
lease_file=/tmp/dhcpd.leases
|
|
|
|
config_file=/etc/dhcpd.conf
|
|
|
|
pid_file=/var/run/dhcpd.pid
|
2011-05-24 10:01:23 +00:00
|
|
|
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
|
|
|
|
}
|
2007-10-10 13:28:25 +00:00
|
|
|
|
|
|
|
start() {
|
2010-04-11 21:07:54 +00:00
|
|
|
if [ -e $pid_file ] ; then
|
|
|
|
echo " dhcpd already running with PID `cat $pid_file`"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-10-10 13:28:25 +00:00
|
|
|
echo Starting isc-dhcpd
|
|
|
|
|
|
|
|
if [ ! -e $lease_file ]; then
|
|
|
|
echo " Creating $lease_file"
|
|
|
|
touch $lease_file
|
|
|
|
fi
|
|
|
|
|
2008-01-08 17:07:25 +00:00
|
|
|
/usr/sbin/dhcpd -q -cf $config_file -lf $lease_file
|
2007-10-10 13:28:25 +00:00
|
|
|
|
2008-08-28 15:38:13 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2007-10-10 13:28:25 +00:00
|
|
|
echo " isc-dhcpd failed to start"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
echo "Stopping isc-dhcpd"
|
|
|
|
if [ -e $pid_file ]; then
|
2010-04-11 21:07:54 +00:00
|
|
|
kill -KILL `cat $pid_file`
|
2007-10-10 13:28:25 +00:00
|
|
|
|
2008-08-28 15:38:13 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2007-10-10 13:28:25 +00:00
|
|
|
echo " PID " `cat $pid_file` not found
|
|
|
|
echo " Is the DHCP server running?"
|
|
|
|
fi
|
|
|
|
|
2010-04-11 21:07:54 +00:00
|
|
|
rm -f $pid_file
|
2007-10-10 13:28:25 +00:00
|
|
|
else
|
|
|
|
echo " $pid_file not found"
|
|
|
|
fi
|
|
|
|
}
|