2006-04-05 05:09:22 +03:00
|
|
|
#!/bin/sh
|
2006-07-30 06:09:09 +03:00
|
|
|
. /etc/functions.sh
|
2006-10-04 20:11:36 +03:00
|
|
|
include /lib/network
|
2006-07-30 06:09:09 +03:00
|
|
|
scan_interfaces
|
2006-04-05 05:09:22 +03:00
|
|
|
|
|
|
|
# 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
|
2006-07-30 06:09:09 +03:00
|
|
|
config_get ifname "$iface" ifname
|
2006-07-30 06:18:50 +03:00
|
|
|
config_get proto "$iface" proto
|
2006-04-05 05:09:22 +03:00
|
|
|
|
2006-07-30 06:18:50 +03:00
|
|
|
[ "$proto" = static ] && dhcp_enable="${dhcp_enable:-1}"
|
2006-04-05 05:09:22 +03:00
|
|
|
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
|
2006-07-30 06:09:09 +03:00
|
|
|
config_get ipaddr "$iface" ipaddr
|
|
|
|
config_get netmask "$iface" netmask
|
2006-04-05 05:09:22 +03:00
|
|
|
eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150})
|
|
|
|
|
|
|
|
# and pass the args via config parser defines
|
2006-07-30 06:18:50 +03:00
|
|
|
echo "${dhcp_enable:+@define dhcp_enable 1}"
|
2006-04-05 05:09:22 +03:00
|
|
|
echo "@define netmask $NETMASK"
|
|
|
|
echo "@define start $START"
|
|
|
|
echo "@define end $END"
|
|
|
|
echo "@define lease ${dhcp_lease:-12h}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ignore requests from wan interface
|
2006-07-30 06:09:09 +03:00
|
|
|
config_get wan_proto wan proto
|
|
|
|
config_get wan_ifname wan ifname
|
2006-04-05 05:09:22 +03:00
|
|
|
[ -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
|