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"
47 append_notinterface
() {
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" "addnhosts" "-H"
75 append_parm
"$cfg" "queryport" "-Q"
76 append_parm
"$cfg" "domain" "-s"
77 append_parm
"$cfg" "local" "-S"
78 config_list_foreach
"$cfg" "server" append_server
79 config_list_foreach
"$cfg" "interface" append_interface
80 config_list_foreach
"$cfg" "notinterface" append_notinterface
81 append_parm
"$cfg" "leasefile" "-l"
82 append_parm
"$cfg" "resolvfile" "-r"
83 append_parm
"$cfg" "tftp_root" "--tftp-root"
84 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
86 config_get leasefile
$cfg leasefile
87 [ -e "$leasefile" ] ||
touch "$leasefile"
88 config_get_bool cachelocal
"$cfg" cachelocal
1
90 config_get hostsfile
"$cfg" dhcphostsfile
91 [ -e "$hostsfile" ] && append args
"--dhcp-hostsfile=$hostsfile"
97 config_get name
"$cfg" name
98 [ -n "$name" ] ||
return 0
100 config_get subscriberid
"$cfg" subscriberid
101 [ -n "$subscriberid" ] ||
return 0
103 append args
"--dhcp-subscrid=$name,$subscriberid"
105 dhcp_option_add
"$cfg" "$name"
108 dhcp_remoteid_add
() {
111 config_get name
"$cfg" name
112 [ -n "$name" ] ||
return 0
114 config_get remoteid
"$cfg" remoteid
115 [ -n "$remoteid" ] ||
return 0
117 append args
"--dhcp-remoteid=$name,$remoteid"
119 dhcp_option_add
"$cfg" "$name"
122 dhcp_circuitid_add
() {
125 config_get name
"$cfg" name
126 [ -n "$name" ] ||
return 0
128 config_get circuitid
"$cfg" circuitid
129 [ -n "$circuitid" ] ||
return 0
131 append args
"--dhcp-circuitid=$name,$circuitid"
133 dhcp_option_add
"$cfg" "$name"
136 dhcp_userclass_add
() {
139 config_get name
"$cfg" name
140 [ -n "$name" ] ||
return 0
142 config_get userclass
"$cfg" userclass
143 [ -n "$userclass" ] ||
return 0
145 append args
"--dhcp-userclass=$name,$userclass"
147 dhcp_option_add
"$cfg" "$name"
150 dhcp_vendorclass_add
() {
153 config_get name
"$cfg" name
154 [ -n "$name" ] ||
return 0
156 config_get vendorclass
"$cfg" vendorclass
157 [ -n "$vendorclass" ] ||
return 0
159 append args
"--dhcp-vendorclass=$name,$vendorclass"
161 dhcp_option_add
"$cfg" "$name"
167 config_get name
"$cfg" name
168 [ -n "$name" ] ||
return 0
170 config_get mac
"$cfg" mac
171 [ -n "$mac" ] ||
return 0
173 config_get ip
"$cfg" ip
174 [ -n "$ip" ] ||
return 0
176 append args
"--dhcp-host=$mac,$ip"
178 dhcp_option_add
"$cfg" "$name"
184 config_get name
"$cfg" name
185 [ -n "$name" ] ||
return 0
187 config_get mac
"$cfg" mac
188 [ -n "$mac" ] ||
return 0
190 append args
"--dhcp-mac=$name,$mac"
192 dhcp_option_add
"$cfg" "$name"
198 config_get name
"$cfg" name
200 config_get filename
"$cfg" filename
201 [ -n "$filename" ] ||
return 0
203 config_get servername
"$cfg" servername
204 [ -n "$servername" ] ||
return 0
206 config_get serveraddress
"$cfg" serveraddress
207 [ -n "$serveraddress" ] ||
return 0
209 append args
"--dhcp-boot=${name:+net:$name,}$filename,$servername,$serveraddress"
211 dhcp_option_add
"$cfg" "$name"
217 config_get net
"$cfg" interface
218 [ -n "$net" ] ||
return 0
220 config_get name
"$cfg" name
221 [ -n "$name" ] || name
="$net"
223 config_get ifname
"$net" ifname
224 [ -n "$ifname" ] ||
return 0
226 config_get dnsserver
"$net" dns
227 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
228 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
231 append_bool
"$cfg" ignore
"-2 $ifname" && return 0
233 config_get proto
"$net" proto
234 [ static
= "$proto" ] ||
return 0
236 config_get ipaddr
"$net" ipaddr
237 config_get netmask
"$cfg" netmask
238 [ -n "$netmask" ] || config_get netmask
"$net" netmask
240 #check for an already active dhcp server on the interface, unless 'force' is set
241 config_get_bool force
"$cfg" force
0
242 [ "$force" -gt 0 ] ||
{
243 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
246 config_get start
"$cfg" start
247 config_get limit
"$cfg" limit
248 config_get leasetime
"$cfg" leasetime
249 config_get options
"$cfg" options
250 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
252 leasetime
="${leasetime:-12h}"
253 start
="$(dhcp_calc "${start:-100}")"
254 limit
="$((${limit:-150} + 1))"
255 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
256 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
257 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
259 dhcp_option_add
"$cfg" "$name"
266 config_get dhcp_option
"$cfg" dhcp_option
267 for o
in $dhcp_option; do
268 append args
"-O $name","$o"
279 config_foreach dnsmasq dnsmasq
280 config_foreach dhcp_host_add
host
281 config_foreach dhcp_boot_add boot
282 config_foreach dhcp_mac_add mac
283 config_foreach dhcp_vendorclass_add vendorclass
284 config_foreach dhcp_userclass_add userclass
285 config_foreach dhcp_circuitid_add circuitid
286 config_foreach dhcp_remoteid_add remoteid
287 config_foreach dhcp_subscrid_add subscrid
288 config_foreach dhcp_add dhcp
290 /usr
/sbin
/dnsmasq
$args && {
291 rm -f /tmp
/resolv.conf
292 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
293 for DNS_SERVER
in $DNS_SERVERS ; do
294 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
300 [ -f /tmp
/resolv.conf
] && {
301 rm -f /tmp
/resolv.conf
302 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf