1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
12 while [ -n "$ip" ]; do
15 res
="$(($res + $part))"
16 [ "${ip%.*}" != "$ip" ] && ip
="${ip#*.}" || ip
=
26 config_get_bool _loctmp
"$section" "$option"
27 [ "$_loctmp" -gt 0 ] && append args
"$value"
35 config_get _loctmp
"$section" "$option"
36 [ -z "$_loctmp" ] && return 0
37 append args
"$switch $_loctmp"
48 append_notinterface
() {
58 append_bool
"$cfg" authoritative
"-K"
59 append_bool
"$cfg" nodaemon
"-d"
60 append_bool
"$cfg" domainneeded
"-D"
61 append_bool
"$cfg" filterwin2k
"-f"
62 append_bool
"$cfg" nohosts
"-h"
63 append_bool
"$cfg" nonegcache
"-N"
64 append_bool
"$cfg" strictorder
"-o"
65 append_bool
"$cfg" logqueries
"-q"
66 append_bool
"$cfg" noresolv
"-R"
67 append_bool
"$cfg" localise_queries
"-y"
68 append_bool
"$cfg" readethers
"-Z"
69 append_bool
"$cfg" dbus
"-1"
70 append_bool
"$cfg" boguspriv
"-b"
71 append_bool
"$cfg" expandhosts
"-E"
72 append_bool
"$cfg" enable_tftp
"--enable-tftp"
73 append_bool
"$cfg" nonwildcard
"-z"
75 append_parm
"$cfg" dnsforwardmax
"-0"
76 append_parm
"$cfg" port
"-p"
77 append_parm
"$cfg" ednspacket_max
"-P"
78 append_parm
"$cfg" dhcpleasemax
"-X"
79 append_parm
"$cfg" "queryport" "-Q"
80 append_parm
"$cfg" "domain" "-s"
81 append_parm
"$cfg" "local" "-S"
82 config_list_foreach
"$cfg" "server" append_server
83 config_list_foreach
"$cfg" "interface" append_interface
84 config_list_foreach
"$cfg" "notinterface" append_notinterface
85 config_list_foreach
"$cfg" "addnhosts" append_addnhosts
86 append_parm
"$cfg" "leasefile" "-l"
87 append_parm
"$cfg" "resolvfile" "-r"
88 append_parm
"$cfg" "tftp_root" "--tftp-root"
89 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
91 config_get DOMAIN
"$cfg" domain
93 config_get leasefile
$cfg leasefile
94 [ -e "$leasefile" ] ||
touch "$leasefile"
95 config_get_bool cachelocal
"$cfg" cachelocal
1
97 config_get hostsfile
"$cfg" dhcphostsfile
98 [ -e "$hostsfile" ] && append args
"--dhcp-hostsfile=$hostsfile"
101 dhcp_subscrid_add
() {
104 config_get name
"$cfg" name
105 [ -n "$name" ] ||
return 0
107 config_get subscriberid
"$cfg" subscriberid
108 [ -n "$subscriberid" ] ||
return 0
110 append args
"--dhcp-subscrid=$name,$subscriberid"
112 dhcp_option_add
"$cfg" "$name"
115 dhcp_remoteid_add
() {
118 config_get name
"$cfg" name
119 [ -n "$name" ] ||
return 0
121 config_get remoteid
"$cfg" remoteid
122 [ -n "$remoteid" ] ||
return 0
124 append args
"--dhcp-remoteid=$name,$remoteid"
126 dhcp_option_add
"$cfg" "$name"
129 dhcp_circuitid_add
() {
132 config_get name
"$cfg" name
133 [ -n "$name" ] ||
return 0
135 config_get circuitid
"$cfg" circuitid
136 [ -n "$circuitid" ] ||
return 0
138 append args
"--dhcp-circuitid=$name,$circuitid"
140 dhcp_option_add
"$cfg" "$name"
143 dhcp_userclass_add
() {
146 config_get name
"$cfg" name
147 [ -n "$name" ] ||
return 0
149 config_get userclass
"$cfg" userclass
150 [ -n "$userclass" ] ||
return 0
152 append args
"--dhcp-userclass=$name,$userclass"
154 dhcp_option_add
"$cfg" "$name"
157 dhcp_vendorclass_add
() {
160 config_get name
"$cfg" name
161 [ -n "$name" ] ||
return 0
163 config_get vendorclass
"$cfg" vendorclass
164 [ -n "$vendorclass" ] ||
return 0
166 append args
"--dhcp-vendorclass=$name,$vendorclass"
168 dhcp_option_add
"$cfg" "$name"
174 config_get name
"$cfg" name
175 [ -n "$name" ] && dhcp_option_add
"$cfg" "$name"
177 config_get mac
"$cfg" mac
178 [ -n "$mac" ] ||
return 0
180 config_get ip
"$cfg" ip
181 [ -n "$ip" ] ||
return 0
183 append args
"--dhcp-host=$mac,${name:+net:$name,}$ip"
189 config_get name
"$cfg" name
190 [ -n "$name" ] ||
return 0
192 config_get mac
"$cfg" mac
193 [ -n "$mac" ] ||
return 0
195 append args
"--dhcp-mac=$name,$mac"
197 dhcp_option_add
"$cfg" "$name"
203 config_get name
"$cfg" name
205 config_get filename
"$cfg" filename
206 [ -n "$filename" ] ||
return 0
208 config_get servername
"$cfg" servername
209 [ -n "$servername" ] ||
return 0
211 config_get serveraddress
"$cfg" serveraddress
212 [ -n "$serveraddress" ] ||
return 0
214 append args
"--dhcp-boot=${name:+net:$name,}$filename,$servername,$serveraddress"
216 dhcp_option_add
"$cfg" "$name"
222 config_get net
"$cfg" interface
223 [ -n "$net" ] ||
return 0
225 config_get name
"$cfg" name
226 [ -n "$name" ] || name
="$net"
228 config_get ifname
"$net" ifname
229 [ -n "$ifname" ] ||
return 0
231 config_get dnsserver
"$net" dns
232 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
233 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
236 append_bool
"$cfg" ignore
"-2 $ifname" && return 0
238 config_get proto
"$net" proto
239 [ static
= "$proto" ] ||
return 0
241 config_get ipaddr
"$net" ipaddr
242 config_get netmask
"$cfg" netmask
243 [ -n "$netmask" ] || config_get netmask
"$net" netmask
245 #check for an already active dhcp server on the interface, unless 'force' is set
246 config_get_bool force
"$cfg" force
0
247 [ "$force" -gt 0 ] ||
{
248 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
251 config_get start
"$cfg" start
252 config_get limit
"$cfg" limit
253 config_get leasetime
"$cfg" leasetime
254 config_get options
"$cfg" options
255 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
257 leasetime
="${leasetime:-12h}"
258 start
="$(dhcp_calc "${start:-100}")"
259 limit
="$((${limit:-150} + 1))"
260 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
261 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
262 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
264 dhcp_option_add
"$cfg" "$name"
271 config_get dhcp_option
"$cfg" dhcp_option
272 for o
in $dhcp_option; do
273 append args
"-O $name","$o"
281 config_get name
"$cfg" name
282 [ -n "$name" ] ||
return 0
284 config_get ip
"$cfg" ip
285 [ -n "$ip" ] ||
return 0
287 local oIFS
="$IFS"; IFS
="."; set -- $ip; IFS
="$oIFS"
288 append args
"-A /$name${DOMAIN:+.$DOMAIN}/$ip"
289 append args
"--ptr-record=$4.$3.$2.$1.in-addr.arpa,$name${DOMAIN:+.$DOMAIN}"
298 config_foreach dnsmasq dnsmasq
299 config_foreach dhcp_host_add
host
300 config_foreach dhcp_boot_add boot
301 config_foreach dhcp_mac_add mac
302 config_foreach dhcp_vendorclass_add vendorclass
303 config_foreach dhcp_userclass_add userclass
304 config_foreach dhcp_circuitid_add circuitid
305 config_foreach dhcp_remoteid_add remoteid
306 config_foreach dhcp_subscrid_add subscrid
307 config_foreach dhcp_domain_add domain
308 config_foreach dhcp_add dhcp
310 /usr
/sbin
/dnsmasq
$args && {
311 rm -f /tmp
/resolv.conf
312 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
313 for DNS_SERVER
in $DNS_SERVERS ; do
314 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
320 [ -f /tmp
/resolv.conf
] && {
321 rm -f /tmp
/resolv.conf
322 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf