2006-10-04 20:05:48 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
|
2006-11-13 21:16:03 +00:00
|
|
|
START=60
|
2007-03-17 13:31:13 +00:00
|
|
|
|
|
|
|
dhcp_calc() {
|
|
|
|
local ip="$1"
|
|
|
|
local res=0
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
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
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
config_get ifname "$net" ifname
|
|
|
|
[ -n "$ifname" ] || return 0
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
config_get_bool ignore "$cfg" ignore
|
|
|
|
[ "$ignore" -gt 0 ] && {
|
|
|
|
append args "-I $ifname"
|
|
|
|
return 0
|
|
|
|
}
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
config_get proto "$net" proto
|
|
|
|
[ static = "$proto" ] || return 0
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
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 ] || {
|
2007-04-12 18:49:02 +00:00
|
|
|
udhcpc -n -q -R -s /bin/true -t 1 -i $ifname >&- && return 0
|
2007-03-17 13:31:13 +00:00
|
|
|
}
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
config_get start "$cfg" start
|
2007-08-19 20:50:52 +00:00
|
|
|
config_get limit "$cfg" limit
|
2007-03-17 13:31:13 +00:00
|
|
|
config_get leasetime "$cfg" leasetime
|
2007-03-31 00:39:55 +00:00
|
|
|
config_get options "$cfg" options
|
2007-03-17 13:31:13 +00:00
|
|
|
|
|
|
|
leasetime="${leasetime:-12h}"
|
|
|
|
start="$(dhcp_calc "${start:-100}")"
|
2007-08-19 20:50:52 +00:00
|
|
|
limit="$((${limit:-150} + 1))"
|
|
|
|
eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
|
2007-03-31 00:39:55 +00:00
|
|
|
append args "-F $START,$END,$NETMASK,$leasetime${options:+ $options}"
|
2007-03-17 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
2007-06-30 19:28:46 +00:00
|
|
|
config_load /var/state/network
|
2007-03-17 13:31:13 +00:00
|
|
|
config_load dhcp
|
|
|
|
|
|
|
|
args=""
|
|
|
|
config_foreach dhcp_add dhcp
|
2006-10-04 20:05:48 +00:00
|
|
|
|
2007-03-17 13:31:13 +00:00
|
|
|
dnsmasq $args && {
|
2007-01-08 21:33:53 +00:00
|
|
|
rm -f /tmp/resolv.conf
|
|
|
|
cat > /tmp/resolv.conf <<EOF
|
|
|
|
nameserver 127.0.0.1
|
|
|
|
search lan
|
|
|
|
EOF
|
|
|
|
}
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
killall dnsmasq
|
|
|
|
}
|