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 _loctmp
"$section" "$option"
26 [ "$_loctmp" -gt 0 ] && append args
"$value"
34 config_get _loctmp
"$section" "$option"
35 [ -z "$_loctmp" ] && return 0
36 append args
"$switch $_loctmp"
53 append_bool
"$cfg" authoritative
"-K"
54 append_bool
"$cfg" nodaemon
"-d"
55 append_bool
"$cfg" domainneeded
"-D"
56 append_bool
"$cfg" filterwin2k
"-f"
57 append_bool
"$cfg" nohosts
"-h"
58 append_bool
"$cfg" nonegcache
"-N"
59 append_bool
"$cfg" strictorder
"-o"
60 append_bool
"$cfg" logqueries
"-q"
61 append_bool
"$cfg" noresolv
"-R"
62 append_bool
"$cfg" localise_queries
"-y"
63 append_bool
"$cfg" readethers
"-Z"
64 append_bool
"$cfg" dbus
"-1"
65 append_bool
"$cfg" boguspriv
"-b"
66 append_bool
"$cfg" expandhosts
"-E"
67 append_bool
"$cfg" enable_tftp
"--enable-tftp"
68 append_bool
"$cfg" nonwildcard
"-z"
70 append_parm
"$cfg" dnsforwardmax
"-0"
71 append_parm
"$cfg" port
"-p"
72 append_parm
"$cfg" ednspacket_max
"-P"
73 append_parm
"$cfg" dhcpleasemax
"-X"
74 append_parm
"$cfg" "queryport" "-Q"
75 append_parm
"$cfg" "domain" "-s"
76 append_parm
"$cfg" "local" "-S"
77 config_list_foreach
"$cfg" "server" append_server
78 config_list_foreach
"$cfg" "interface" append_interface
79 config_list_foreach
"$cfg" "addnhosts" append_addnhosts
80 append_parm
"$cfg" "leasefile" "-l"
81 append_parm
"$cfg" "resolvfile" "-r"
82 append_parm
"$cfg" "tftp_root" "--tftp-root"
83 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
85 config_get leasefile
$cfg leasefile
86 [ -e "$leasefile" ] ||
touch "$leasefile"
87 config_get_bool cachelocal
"$cfg" cachelocal
1
93 config_get name
"$cfg" name
94 [ -n "$name" ] ||
return 0
96 config_get subscriberid
"$cfg" subscriberid
97 [ -n "$subscriberid" ] ||
return 0
99 append args
"--dhcp-subscrid=$name,$subscriberid"
101 dhcp_option_add
"$cfg" "$name"
104 dhcp_remoteid_add
() {
107 config_get name
"$cfg" name
108 [ -n "$name" ] ||
return 0
110 config_get remoteid
"$cfg" remoteid
111 [ -n "$remoteid" ] ||
return 0
113 append args
"--dhcp-remoteid=$name,$remoteid"
115 dhcp_option_add
"$cfg" "$name"
118 dhcp_circuitid_add
() {
121 config_get name
"$cfg" name
122 [ -n "$name" ] ||
return 0
124 config_get circuitid
"$cfg" circuitid
125 [ -n "$circuitid" ] ||
return 0
127 append args
"--dhcp-circuitid=$name,$circuitid"
129 dhcp_option_add
"$cfg" "$name"
132 dhcp_userclass_add
() {
135 config_get name
"$cfg" name
136 [ -n "$name" ] ||
return 0
138 config_get userclass
"$cfg" userclass
139 [ -n "$userclass" ] ||
return 0
141 append args
"--dhcp-userclass=$name,$userclass"
143 dhcp_option_add
"$cfg" "$name"
146 dhcp_vendorclass_add
() {
149 config_get name
"$cfg" name
150 [ -n "$name" ] ||
return 0
152 config_get vendorclass
"$cfg" vendorclass
153 [ -n "$vendorclass" ] ||
return 0
155 append args
"--dhcp-vendorclass=$name,$vendorclass"
157 dhcp_option_add
"$cfg" "$name"
163 config_get name
"$cfg" name
164 [ -n "$name" ] ||
return 0
166 config_get mac
"$cfg" mac
167 [ -n "$mac" ] ||
return 0
169 config_get ip
"$cfg" ip
170 [ -n "$ip" ] ||
return 0
172 append args
"--dhcp-host=$mac,$ip"
174 dhcp_option_add
"$cfg" "$name"
180 config_get name
"$cfg" name
181 [ -n "$name" ] ||
return 0
183 config_get mac
"$cfg" mac
184 [ -n "$mac" ] ||
return 0
186 append args
"--dhcp-mac=$name,$mac"
188 dhcp_option_add
"$cfg" "$name"
194 config_get name
"$cfg" name
196 config_get filename
"$cfg" filename
197 [ -n "$filename" ] ||
return 0
199 config_get servername
"$cfg" servername
200 [ -n "$servername" ] ||
return 0
202 config_get serveraddress
"$cfg" serveraddress
203 [ -n "$serveraddress" ] ||
return 0
205 append args
"--dhcp-boot=${name:+net:$name,}$filename,$servername,$serveraddress"
207 dhcp_option_add
"$cfg" "$name"
213 config_get net
"$cfg" interface
214 [ -n "$net" ] ||
return 0
216 config_get name
"$cfg" name
217 [ -n "$name" ] || name
="$net"
219 config_get ifname
"$net" ifname
220 [ -n "$ifname" ] ||
return 0
222 config_get dnsserver
"$net" dns
223 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
224 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
227 append_bool
"$cfg" ignore
"-2 $ifname" && return 0
229 config_get proto
"$net" proto
230 [ static
= "$proto" ] ||
return 0
232 config_get ipaddr
"$net" ipaddr
233 config_get netmask
"$cfg" netmask
234 [ -n "$netmask" ] || config_get netmask
"$net" netmask
236 #check for an already active dhcp server on the interface, unless 'force' is set
237 config_get_bool force
"$cfg" force
0
238 [ "$force" -gt 0 ] ||
{
239 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
242 config_get start
"$cfg" start
243 config_get limit
"$cfg" limit
244 config_get leasetime
"$cfg" leasetime
245 config_get options
"$cfg" options
246 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
248 leasetime
="${leasetime:-12h}"
249 start
="$(dhcp_calc "${start:-100}")"
250 limit
="$((${limit:-150} + 1))"
251 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
252 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
253 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
255 dhcp_option_add
"$cfg" "$name"
262 config_get dhcp_option
"$cfg" dhcp_option
263 for o
in $dhcp_option; do
264 append args
"-O $name","$o"
275 config_foreach dnsmasq dnsmasq
276 config_foreach dhcp_host_add
host
277 config_foreach dhcp_boot_add boot
278 config_foreach dhcp_mac_add mac
279 config_foreach dhcp_vendorclass_add vendorclass
280 config_foreach dhcp_userclass_add userclass
281 config_foreach dhcp_circuitid_add circuitid
282 config_foreach dhcp_remoteid_add remoteid
283 config_foreach dhcp_subscrid_add subscrid
284 config_foreach dhcp_add dhcp
286 /usr
/sbin
/dnsmasq
$args && {
287 rm -f /tmp
/resolv.conf
288 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
289 for DNS_SERVER
in $DNS_SERVERS ; do
290 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
296 [ -f /tmp
/resolv.conf
] && {
297 rm -f /tmp
/resolv.conf
298 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf