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
() {
54 append_bool
"$cfg" authoritative
"-K"
55 append_bool
"$cfg" nodaemon
"-d"
56 append_bool
"$cfg" domainneeded
"-D"
57 append_bool
"$cfg" filterwin2k
"-f"
58 append_bool
"$cfg" nohosts
"-h"
59 append_bool
"$cfg" nonegcache
"-N"
60 append_bool
"$cfg" strictorder
"-o"
61 append_bool
"$cfg" logqueries
"-q"
62 append_bool
"$cfg" noresolv
"-R"
63 append_bool
"$cfg" localise_queries
"-y"
64 append_bool
"$cfg" readethers
"-Z"
65 append_bool
"$cfg" dbus
"-1"
66 append_bool
"$cfg" boguspriv
"-b"
67 append_bool
"$cfg" expandhosts
"-E"
68 append_bool
"$cfg" enable_tftp
"--enable-tftp"
69 append_bool
"$cfg" nonwildcard
"-z"
71 append_parm
"$cfg" dnsforwardmax
"-0"
72 append_parm
"$cfg" port
"-p"
73 append_parm
"$cfg" ednspacket_max
"-P"
74 append_parm
"$cfg" dhcpleasemax
"-X"
75 append_parm
"$cfg" "addnhosts" "-H"
76 append_parm
"$cfg" "queryport" "-Q"
77 append_parm
"$cfg" "domain" "-s"
78 append_parm
"$cfg" "local" "-S"
79 config_list_foreach
"$cfg" "server" append_server
80 config_list_foreach
"$cfg" "interface" append_interface
81 config_list_foreach
"$cfg" "notinterface" append_notinterface
82 append_parm
"$cfg" "leasefile" "-l"
83 append_parm
"$cfg" "resolvfile" "-r"
84 append_parm
"$cfg" "tftp_root" "--tftp-root"
85 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
87 config_get DOMAIN
"$cfg" domain
89 config_get leasefile
$cfg leasefile
90 [ -e "$leasefile" ] ||
touch "$leasefile"
91 config_get_bool cachelocal
"$cfg" cachelocal
1
93 config_get hostsfile
"$cfg" dhcphostsfile
94 [ -e "$hostsfile" ] && append args
"--dhcp-hostsfile=$hostsfile"
100 config_get name
"$cfg" name
101 [ -n "$name" ] ||
return 0
103 config_get subscriberid
"$cfg" subscriberid
104 [ -n "$subscriberid" ] ||
return 0
106 append args
"--dhcp-subscrid=$name,$subscriberid"
108 dhcp_option_add
"$cfg" "$name"
111 dhcp_remoteid_add
() {
114 config_get name
"$cfg" name
115 [ -n "$name" ] ||
return 0
117 config_get remoteid
"$cfg" remoteid
118 [ -n "$remoteid" ] ||
return 0
120 append args
"--dhcp-remoteid=$name,$remoteid"
122 dhcp_option_add
"$cfg" "$name"
125 dhcp_circuitid_add
() {
128 config_get name
"$cfg" name
129 [ -n "$name" ] ||
return 0
131 config_get circuitid
"$cfg" circuitid
132 [ -n "$circuitid" ] ||
return 0
134 append args
"--dhcp-circuitid=$name,$circuitid"
136 dhcp_option_add
"$cfg" "$name"
139 dhcp_userclass_add
() {
142 config_get name
"$cfg" name
143 [ -n "$name" ] ||
return 0
145 config_get userclass
"$cfg" userclass
146 [ -n "$userclass" ] ||
return 0
148 append args
"--dhcp-userclass=$name,$userclass"
150 dhcp_option_add
"$cfg" "$name"
153 dhcp_vendorclass_add
() {
156 config_get name
"$cfg" name
157 [ -n "$name" ] ||
return 0
159 config_get vendorclass
"$cfg" vendorclass
160 [ -n "$vendorclass" ] ||
return 0
162 append args
"--dhcp-vendorclass=$name,$vendorclass"
164 dhcp_option_add
"$cfg" "$name"
170 config_get name
"$cfg" name
171 [ -n "$name" ] && dhcp_option_add
"$cfg" "$name"
173 config_get mac
"$cfg" mac
174 [ -n "$mac" ] ||
return 0
176 config_get ip
"$cfg" ip
177 [ -n "$ip" ] ||
return 0
179 append args
"--dhcp-host=$mac,$ip${name:+,$name}"
185 config_get name
"$cfg" name
186 [ -n "$name" ] ||
return 0
188 config_get mac
"$cfg" mac
189 [ -n "$mac" ] ||
return 0
191 append args
"--dhcp-mac=$name,$mac"
193 dhcp_option_add
"$cfg" "$name"
199 config_get name
"$cfg" name
201 config_get filename
"$cfg" filename
202 [ -n "$filename" ] ||
return 0
204 config_get servername
"$cfg" servername
205 [ -n "$servername" ] ||
return 0
207 config_get serveraddress
"$cfg" serveraddress
208 [ -n "$serveraddress" ] ||
return 0
210 append args
"--dhcp-boot=${name:+net:$name,}$filename,$servername,$serveraddress"
212 dhcp_option_add
"$cfg" "$name"
218 config_get net
"$cfg" interface
219 [ -n "$net" ] ||
return 0
221 config_get name
"$cfg" name
222 [ -n "$name" ] || name
="$net"
224 config_get ifname
"$net" ifname
225 [ -n "$ifname" ] ||
return 0
227 config_get dnsserver
"$net" dns
228 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
229 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
232 append_bool
"$cfg" ignore
"-2 $ifname" && return 0
234 config_get proto
"$net" proto
235 [ static
= "$proto" ] ||
return 0
237 config_get ipaddr
"$net" ipaddr
238 config_get netmask
"$cfg" netmask
239 [ -n "$netmask" ] || config_get netmask
"$net" netmask
241 #check for an already active dhcp server on the interface, unless 'force' is set
242 config_get_bool force
"$cfg" force
0
243 [ "$force" -gt 0 ] ||
{
244 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
247 config_get start
"$cfg" start
248 config_get limit
"$cfg" limit
249 config_get leasetime
"$cfg" leasetime
250 config_get options
"$cfg" options
251 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
253 leasetime
="${leasetime:-12h}"
254 start
="$(dhcp_calc "${start:-100}")"
255 limit
="$((${limit:-150} + 1))"
256 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
257 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
258 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
260 dhcp_option_add
"$cfg" "$name"
267 config_get dhcp_option
"$cfg" dhcp_option
268 for o
in $dhcp_option; do
269 append args
"-O $name","$o"
277 config_get name
"$cfg" name
278 [ -n "$name" ] ||
return 0
280 config_get ip
"$cfg" ip
281 [ -n "$ip" ] ||
return 0
283 local oIFS
="$IFS"; IFS
="."; set -- $ip; IFS
="$oIFS"
284 append args
"-A /$name${DOMAIN:+.$DOMAIN}/$ip"
285 append args
"--ptr-record=$4.$3.$2.$1.in-addr.arpa,$name${DOMAIN:+.$DOMAIN}"
294 config_foreach dnsmasq dnsmasq
295 config_foreach dhcp_host_add
host
296 config_foreach dhcp_boot_add boot
297 config_foreach dhcp_mac_add mac
298 config_foreach dhcp_vendorclass_add vendorclass
299 config_foreach dhcp_userclass_add userclass
300 config_foreach dhcp_circuitid_add circuitid
301 config_foreach dhcp_remoteid_add remoteid
302 config_foreach dhcp_subscrid_add subscrid
303 config_foreach dhcp_domain_add domain
304 config_foreach dhcp_add dhcp
306 /usr
/sbin
/dnsmasq
$args && {
307 rm -f /tmp
/resolv.conf
308 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
309 for DNS_SERVER
in $DNS_SERVERS ; do
310 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
316 [ -f /tmp
/resolv.conf
] && {
317 rm -f /tmp
/resolv.conf
318 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf