1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
11 while [ -n "$ip" ]; do
14 res
="$(($res + $part))"
15 [ "${ip%.*}" != "$ip" ] && ip
="${ip#*.}" || ip
=
25 config_get_bool _tmp
"$section" "$option"
26 [ "$_tmp" -gt 0 ] && append args
"$3"
31 append_bool
"$cfg" authoritative
"-K"
32 append_bool
"$cfg" nodaemon
"-d"
33 append_bool
"$cfg" domainneeded
"-D"
34 append_bool
"$cfg" filterwin2k
"-f"
35 append_bool
"$cfg" nohosts
"-h"
36 append_bool
"$cfg" nonegcache
"-N"
37 append_bool
"$cfg" strictorder
"-o"
38 append_bool
"$cfg" logqueries
"-q"
39 append_bool
"$cfg" noresolv
"-R"
40 append_bool
"$cfg" localise_queries
"-y"
41 append_bool
"$cfg" readethers
"-Z"
42 append_bool
"$cfg" dbus
"-l"
44 config_get dnsforwardmax
"$cfg" dnsforwardmax
45 dnsforwardmax
="${dnsforwardmax:-150}"
46 append args
"-0 $dnsforwardmax"
48 config_get port
"$cfg" port
50 append args
"-p $port"
52 config_get ednspacket_max
"$cfg" ednspacket_max
53 ednspacket_max
="${ednspacket_max:-1280}"
54 append args
"-P $ednspacket_max"
56 config_get dhcpleasemax
"$cfg" dhcpleasemax
57 dhcpleasemax
="${dhcpleasemax:-150}"
58 append args
"-X $dhcpleasemax"
60 config_get addnhosts
"$cfg" addnhosts
61 config_get interface
"$cfg" interface
62 config_get exceptinterface
"$cfg" exceptinterface
63 config_get queryport
"$cfg" queryport
64 config_get domain
"$cfg" domain
70 config_get name
"$cfg" name
71 [ -n "$name" ] ||
return 0
73 config_get subscriberid
"$cfg" subscriberid
74 [ -n "$subscriberid" ] ||
return 0
76 append args
"--dhcp-subscrid=$name,$subscriberid"
78 dhcp_option_add
"$cfg" "$name"
84 config_get name
"$cfg" name
85 [ -n "$name" ] ||
return 0
87 config_get remoteid
"$cfg" remoteid
88 [ -n "$remoteid" ] ||
return 0
90 append args
"--dhcp-remoteid=$name,$remoteid"
92 dhcp_option_add
"$cfg" "$name"
95 dhcp_circuitid_add
() {
98 config_get name
"$cfg" name
99 [ -n "$name" ] ||
return 0
101 config_get circuitid
"$cfg" circuitid
102 [ -n "$circuitid" ] ||
return 0
104 append args
"--dhcp-circuitid=$name,$circuitid"
106 dhcp_option_add
"$cfg" "$name"
109 dhcp_userclass_add
() {
112 config_get name
"$cfg" name
113 [ -n "$name" ] ||
return 0
115 config_get userclass
"$cfg" userclass
116 [ -n "$userclass" ] ||
return 0
118 append args
"--dhcp-userclass=$name,$userclass"
120 dhcp_option_add
"$cfg" "$name"
123 dhcp_vendorclass_add
() {
126 config_get name
"$cfg" name
127 [ -n "$name" ] ||
return 0
129 config_get vendorclass
"$cfg" vendorclass
130 [ -n "$vendorclass" ] ||
return 0
132 append args
"--dhcp-vendorclass=$name,$vendorclass"
134 dhcp_option_add
"$cfg" "$name"
140 config_get name
"$cfg" name
141 [ -n "$name" ] ||
return 0
143 config_get mac
"$cfg" mac
144 [ -n "$mac" ] ||
return 0
147 append args
"--dhcp-host=$mac,$ip"
149 dhcp_option_add
"$cfg" "$name"
155 config_get name
"$cfg" name
156 [ -n "$name" ] ||
return 0
158 config_get mac
"$cfg" mac
159 [ -n "$mac" ] ||
return 0
161 append args
"--dhcp-mac=$name,$mac"
163 dhcp_option_add
"$cfg" "$name"
168 config_get net
"$cfg" interface
169 [ -n "$net" ] ||
return 0
171 config_get name
"$cfg" name
172 [ -n "$name" ] || name
="$net"
174 config_get ifname
"$net" ifname
175 [ -n "$ifname" ] ||
return 0
177 config_get dnsserver
"$net" dns
178 [ -n "$dnsserver" ] && {
179 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
182 append_bool
"$cfg" ignore
"-I $ifname"
184 config_get proto
"$net" proto
185 [ static
= "$proto" ] ||
return 0
187 config_get ipaddr
"$net" ipaddr
188 config_get netmask
"$net" netmask
190 #check for an already active dhcp server on the interface, unless 'force' is set
191 config_get_bool force
"$cfg" force
0
192 [ "$force" -gt 0 ] ||
{
193 udhcpc
-n -q -R -s /bin
/true
-t 1 -i $ifname >&- && return 0
196 config_get start
"$cfg" start
197 config_get limit
"$cfg" limit
198 config_get leasetime
"$cfg" leasetime
199 config_get options
"$cfg" options
201 leasetime
="${leasetime:-12h}"
202 start
="$(dhcp_calc "${start:-100}")"
203 limit
="$((${limit:-150} + 1))"
204 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
205 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
207 dhcp_option_add
"$cfg" "$name"
214 for count
in $
(seq 0 100); do
215 eval current_value
=\
$CONFIG_"$cfg"_dhcp
"$count"
216 if [ -z "$current_value" ]; then
220 append args
"-O $name","$current_value"
231 config_foreach dnsmasq dnsmasq
232 config_foreach dhcp_host_add
host
233 config_foreach dhcp_mac_add mac
234 config_foreach dhcp_vendorclass_add vendorclass
235 config_foreach dhcp_userclass_add userclass
236 config_foreach dhcp_circuitid_add circuitid
237 config_foreach dhcp_remoteid_add remoteid
238 config_foreach dhcp_subscrid_add subscrid
239 config_foreach dhcp_add dhcp
241 /usr
/sbin
/dnsmasq
$args && {
242 rm -f /tmp
/resolv.conf
243 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
244 for DNS_SERVER
in $DNS_SERVERS ; do
245 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf