1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
10 while [ -n "$ip" ]; do
13 res
="$(($res + $part))"
14 [ "${ip%.*}" != "$ip" ] && ip
="${ip#*.}" || ip
=
24 config_get_bool _tmp
"$section" "$option"
25 [ "$_tmp" -gt 0 ] && append args
"$3"
30 append_bool
"$cfg" authoritative
"-K"
31 append_bool
"$cfg" nodaemon
"-d"
32 append_bool
"$cfg" domainneeded
"-D"
33 append_bool
"$cfg" filterwin2k
"-f"
34 append_bool
"$cfg" nohosts
"-I $nohosts"
35 append_bool
"$cfg" nonegcache
"-N"
36 append_bool
"$cfg" strictorder
"-o"
37 append_bool
"$cfg" logqueries
"-q"
38 append_bool
"$cfg" noresolv
"-I $noresolv"
39 append_bool
"$cfg" localise_queries
"-I $localise_queries"
40 append_bool
"$cfg" readethers
"-Z"
41 append_bool
"$cfg" dbus
"-l"
43 config_get dnsforwardmax
"$cfg" dnsforwardmax
44 dnsforwardmax
="${dnsforwardmax:-150}"
45 append args
"-0 $dnsforwardmax"
47 config_get port
"$cfg" port
49 append args
"-p $port"
51 config_get ednspacket_max
"$cfg" ednspacket_max
52 ednspacket_max
="${ednspacket_max:-1280}"
53 append args
"-P $ednspacket_max"
55 config_get dhcpleasemax
"$cfg" dhcpleasemax
56 dhcpleasemax
="${dhcpleasemax:-150}"
57 append args
"-X $dhcpleasemax"
59 config_get addnhosts
"$cfg" addnhosts
60 config_get interface
"$cfg" interface
61 config_get exceptinterface
"$cfg" exceptinterface
62 config_get queryport
"$cfg" queryport
63 config_get domain
"$cfg" domain
69 config_get name
"$cfg" name
70 [ -n "$name" ] ||
return 0
72 config_get subscriberid
"$cfg" subscriberid
73 [ -n "$subscriberid" ] ||
return 0
75 append args
"--dhcp-subscrid=$name,$subscriberid"
77 dhcp_option_add
"$cfg" "$name"
83 config_get name
"$cfg" name
84 [ -n "$name" ] ||
return 0
86 config_get remoteid
"$cfg" remoteid
87 [ -n "$remoteid" ] ||
return 0
89 append args
"--dhcp-remoteid=$name,$remoteid"
91 dhcp_option_add
"$cfg" "$name"
94 dhcp_circuitid_add
() {
97 config_get name
"$cfg" name
98 [ -n "$name" ] ||
return 0
100 config_get circuitid
"$cfg" circuitid
101 [ -n "$circuitid" ] ||
return 0
103 append args
"--dhcp-circuitid=$name,$circuitid"
105 dhcp_option_add
"$cfg" "$name"
108 dhcp_userclass_add
() {
111 config_get name
"$cfg" name
112 [ -n "$name" ] ||
return 0
114 config_get userclass
"$cfg" userclass
115 [ -n "$userclass" ] ||
return 0
117 append args
"--dhcp-userclass=$name,$userclass"
119 dhcp_option_add
"$cfg" "$name"
122 dhcp_vendorclass_add
() {
125 config_get name
"$cfg" name
126 [ -n "$name" ] ||
return 0
128 config_get vendorclass
"$cfg" vendorclass
129 [ -n "$vendorclass" ] ||
return 0
131 append args
"--dhcp-vendorclass=$name,$vendorclass"
133 dhcp_option_add
"$cfg" "$name"
139 config_get name
"$cfg" name
140 [ -n "$name" ] ||
return 0
142 config_get mac
"$cfg" mac
143 [ -n "$mac" ] ||
return 0
146 append args
"--dhcp-host=$mac,$ip"
148 dhcp_option_add
"$cfg" "$name"
154 config_get name
"$cfg" name
155 [ -n "$name" ] ||
return 0
157 config_get mac
"$cfg" mac
158 [ -n "$mac" ] ||
return 0
160 append args
"--dhcp-mac=$name,$mac"
162 dhcp_option_add
"$cfg" "$name"
167 config_get net
"$cfg" interface
168 [ -n "$net" ] ||
return 0
170 config_get name
"$cfg" name
171 [ -n "$name" ] || name
="$net"
173 config_get ifname
"$net" ifname
174 [ -n "$ifname" ] ||
return 0
176 append_bool
"$cfg" ignore
"-I $ifname"
178 config_get proto
"$net" proto
179 [ static
= "$proto" ] ||
return 0
181 config_get ipaddr
"$net" ipaddr
182 config_get netmask
"$net" netmask
184 #check for an already active dhcp server on the interface, unless 'force' is set
185 config_get_bool force
"$cfg" force
0
186 [ "$force" -gt 0 ] ||
{
187 udhcpc
-n -q -R -s /bin
/true
-t 1 -i $ifname >&- && return 0
190 config_get start
"$cfg" start
191 config_get limit
"$cfg" limit
192 config_get leasetime
"$cfg" leasetime
193 config_get options
"$cfg" options
195 leasetime
="${leasetime:-12h}"
196 start
="$(dhcp_calc "${start:-100}")"
197 limit
="$((${limit:-150} + 1))"
198 eval "$(ipcalc.sh $ipaddr $netmask $start $end)"
199 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
201 dhcp_option_add
"$cfg" "$name"
208 for count
in $
(seq 0 100); do
209 eval current_value
=\
$CONFIG_"$cfg"_dhcp
"$count"
210 if [ -z "$current_value" ]; then
214 append args
"-O $name","$current_value"
225 config_foreach dnsmasq dnsmasq
226 config_foreach dhcp_host_add
host
227 config_foreach dhcp_mac_add mac
228 config_foreach dhcp_vendorclass_add vendorclass
229 config_foreach dhcp_userclass_add userclass
230 config_foreach dhcp_circuitid_add circuitid
231 config_foreach dhcp_remoteid_add remoteid
232 config_foreach dhcp_subscrid_add subscrid
233 config_foreach dhcp_add dhcp
235 /usr
/sbin
/dnsmasq
$args && {
236 rm -f /tmp
/resolv.conf
237 cat > /tmp
/resolv.conf
<<EOF