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_bool readethers
"$cfg" readethers
94 [ "$readethers" = "1" ] && [ -e "/etc/ethers" ] ||
touch /etc
/ethers
96 config_get leasefile
$cfg leasefile
97 [ -e "$leasefile" ] ||
touch "$leasefile"
98 config_get_bool cachelocal
"$cfg" cachelocal
1
100 config_get hostsfile
"$cfg" dhcphostsfile
101 [ -e "$hostsfile" ] && append args
"--dhcp-hostsfile=$hostsfile"
104 dhcp_subscrid_add
() {
107 config_get networkid
"$cfg" networkid
108 [ -n "$networkid" ] ||
return 0
110 config_get subscriberid
"$cfg" subscriberid
111 [ -n "$subscriberid" ] ||
return 0
113 append args
"--dhcp-subscrid=$networkid,$subscriberid"
115 dhcp_option_add
"$cfg" "$networkid"
118 dhcp_remoteid_add
() {
121 config_get networkid
"$cfg" networkid
122 [ -n "$networkid" ] ||
return 0
124 config_get remoteid
"$cfg" remoteid
125 [ -n "$remoteid" ] ||
return 0
127 append args
"--dhcp-remoteid=$networkid,$remoteid"
129 dhcp_option_add
"$cfg" "$networkid"
132 dhcp_circuitid_add
() {
135 config_get networkid
"$cfg" networkid
136 [ -n "$networkid" ] ||
return 0
138 config_get circuitid
"$cfg" circuitid
139 [ -n "$circuitid" ] ||
return 0
141 append args
"--dhcp-circuitid=$networkid,$circuitid"
143 dhcp_option_add
"$cfg" "$networkid"
146 dhcp_userclass_add
() {
149 config_get networkid
"$cfg" networkid
150 [ -n "$networkid" ] ||
return 0
152 config_get userclass
"$cfg" userclass
153 [ -n "$userclass" ] ||
return 0
155 append args
"--dhcp-userclass=$networkid,$userclass"
157 dhcp_option_add
"$cfg" "$networkid"
160 dhcp_vendorclass_add
() {
163 config_get networkid
"$cfg" networkid
164 [ -n "$networkid" ] ||
return 0
166 config_get vendorclass
"$cfg" vendorclass
167 [ -n "$vendorclass" ] ||
return 0
169 append args
"--dhcp-vendorclass=$networkid,$vendorclass"
171 dhcp_option_add
"$cfg" "$networkid"
177 config_get name
"$cfg" name
179 config_get networkid
"$cfg" networkid
180 [ -n "$networkid" ] && dhcp_option_add
"$cfg" "$networkid"
182 config_get ip
"$cfg" ip
183 [ -n "$ip" ] ||
return 0
186 config_get mac
"$cfg" mac
187 for m
in $mac; do append macs
"$m" ","; done
188 [ -n "$macs" ] ||
return 0
190 append args
"--dhcp-host=$macs,${networkid:+net:$networkid,}$ip${name:+,$name}"
196 config_get networkid
"$cfg" networkid
197 [ -n "$networkid" ] ||
return 0
199 config_get mac
"$cfg" mac
200 [ -n "$mac" ] ||
return 0
202 append args
"--dhcp-mac=$networkid,$mac"
204 dhcp_option_add
"$cfg" "$networkid"
210 config_get networkid
"$cfg" networkid
212 config_get filename
"$cfg" filename
213 [ -n "$filename" ] ||
return 0
215 config_get servername
"$cfg" servername
216 [ -n "$servername" ] ||
return 0
218 config_get serveraddress
"$cfg" serveraddress
219 [ -n "$serveraddress" ] ||
return 0
221 append args
"--dhcp-boot=${networkid:+net:$networkid,}$filename,$servername,$serveraddress"
223 dhcp_option_add
"$cfg" "$networkid"
229 config_get net
"$cfg" interface
230 [ -n "$net" ] ||
return 0
232 config_get networkid
"$cfg" networkid
233 [ -n "$networkid" ] || networkid
="$net"
235 config_get ifname
"$net" ifname
236 [ -n "$ifname" ] ||
return 0
238 config_get dnsserver
"$net" dns
239 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
240 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
243 append_bool
"$cfg" ignore
"-2 '$ifname'" && return 0
245 config_get proto
"$net" proto
246 [ static
= "$proto" ] ||
return 0
248 config_get ipaddr
"$net" ipaddr
249 config_get netmask
"$cfg" netmask
250 [ -n "$netmask" ] || config_get netmask
"$net" netmask
252 #check for an already active dhcp server on the interface, unless 'force' is set
253 config_get_bool force
"$cfg" force
0
254 [ "$force" -gt 0 ] ||
{
255 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
258 config_get start
"$cfg" start
259 config_get limit
"$cfg" limit
260 config_get leasetime
"$cfg" leasetime
261 config_get options
"$cfg" options
262 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
264 leasetime
="${leasetime:-12h}"
265 start
="$(dhcp_calc "${start:-100}")"
266 limit
="${limit:-150}"
267 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
268 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
269 append args
"--dhcp-range=$networkid,$START,$END,$NETMASK,$leasetime${options:+ $options}"
271 dhcp_option_add
"$cfg" "$networkid"
278 config_get dhcp_option
"$cfg" dhcp_option
279 for o
in $dhcp_option; do
280 append args
"-O $networkid","$o"
288 config_get name
"$cfg" name
289 [ -n "$name" ] ||
return 0
291 config_get ip
"$cfg" ip
292 [ -n "$ip" ] ||
return 0
294 local oIFS
="$IFS"; IFS
="."; set -- $ip; IFS
="$oIFS"
295 append args
"-A /$name${DOMAIN:+.$DOMAIN}/$ip"
296 append args
"--ptr-record=$4.$3.$2.$1.in-addr.arpa,$name${DOMAIN:+.$DOMAIN}"
305 config_foreach dnsmasq dnsmasq
306 config_foreach dhcp_host_add
host
307 config_foreach dhcp_boot_add boot
308 config_foreach dhcp_mac_add mac
309 config_foreach dhcp_vendorclass_add vendorclass
310 config_foreach dhcp_userclass_add userclass
311 config_foreach dhcp_circuitid_add circuitid
312 config_foreach dhcp_remoteid_add remoteid
313 config_foreach dhcp_subscrid_add subscrid
314 config_foreach dhcp_domain_add domain
315 config_foreach dhcp_add dhcp
317 /usr
/sbin
/dnsmasq
$args && {
318 rm -f /tmp
/resolv.conf
319 [ -n "$DOMAIN" ] && echo "search $DOMAIN" >> /tmp
/resolv.conf
320 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
321 for DNS_SERVER
in $DNS_SERVERS ; do
322 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
328 [ -f /tmp
/resolv.conf
] && {
329 rm -f /tmp
/resolv.conf
330 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf