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"
41 append_bool
"$cfg" authoritative
"-K"
42 append_bool
"$cfg" nodaemon
"-d"
43 append_bool
"$cfg" domainneeded
"-D"
44 append_bool
"$cfg" filterwin2k
"-f"
45 append_bool
"$cfg" nohosts
"-h"
46 append_bool
"$cfg" nonegcache
"-N"
47 append_bool
"$cfg" strictorder
"-o"
48 append_bool
"$cfg" logqueries
"-q"
49 append_bool
"$cfg" noresolv
"-R"
50 append_bool
"$cfg" localise_queries
"-y"
51 append_bool
"$cfg" readethers
"-Z"
52 append_bool
"$cfg" dbus
"-1"
53 append_bool
"$cfg" boguspriv
"-b"
54 append_bool
"$cfg" expandhosts
"-E"
55 append_bool
"$cfg" enable_tftp
"--enable-tftp"
57 append_parm
"$cfg" dnsforwardmax
"-0"
58 append_parm
"$cfg" port
"-p"
59 append_parm
"$cfg" ednspacket_max
"-P"
60 append_parm
"$cfg" dhcpleasemax
"-X"
61 append_parm
"$cfg" "addnhosts" "-H"
62 append_parm
"$cfg" "queryport" "-Q"
63 append_parm
"$cfg" "domain" "-s"
64 append_parm
"$cfg" "local" "-S"
65 append_parm
"$cfg" "leasefile" "-l"
66 append_parm
"$cfg" "resolvfile" "-r"
67 append_parm
"$cfg" "tftp_root" "--tftp-root"
68 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
70 config_get leasefile
$cfg leasefile
71 [ -e "$leasefile" ] ||
touch "$leasefile"
72 config_get_bool cachelocal
"$cfg" cachelocal
1
78 config_get name
"$cfg" name
79 [ -n "$name" ] ||
return 0
81 config_get subscriberid
"$cfg" subscriberid
82 [ -n "$subscriberid" ] ||
return 0
84 append args
"--dhcp-subscrid=$name,$subscriberid"
86 dhcp_option_add
"$cfg" "$name"
92 config_get name
"$cfg" name
93 [ -n "$name" ] ||
return 0
95 config_get remoteid
"$cfg" remoteid
96 [ -n "$remoteid" ] ||
return 0
98 append args
"--dhcp-remoteid=$name,$remoteid"
100 dhcp_option_add
"$cfg" "$name"
103 dhcp_circuitid_add
() {
106 config_get name
"$cfg" name
107 [ -n "$name" ] ||
return 0
109 config_get circuitid
"$cfg" circuitid
110 [ -n "$circuitid" ] ||
return 0
112 append args
"--dhcp-circuitid=$name,$circuitid"
114 dhcp_option_add
"$cfg" "$name"
117 dhcp_userclass_add
() {
120 config_get name
"$cfg" name
121 [ -n "$name" ] ||
return 0
123 config_get userclass
"$cfg" userclass
124 [ -n "$userclass" ] ||
return 0
126 append args
"--dhcp-userclass=$name,$userclass"
128 dhcp_option_add
"$cfg" "$name"
131 dhcp_vendorclass_add
() {
134 config_get name
"$cfg" name
135 [ -n "$name" ] ||
return 0
137 config_get vendorclass
"$cfg" vendorclass
138 [ -n "$vendorclass" ] ||
return 0
140 append args
"--dhcp-vendorclass=$name,$vendorclass"
142 dhcp_option_add
"$cfg" "$name"
148 config_get name
"$cfg" name
149 [ -n "$name" ] ||
return 0
151 config_get mac
"$cfg" mac
152 [ -n "$mac" ] ||
return 0
154 config_get ip
"$cfg" ip
155 [ -n "$ip" ] ||
return 0
157 append args
"--dhcp-host=$mac,$ip"
159 dhcp_option_add
"$cfg" "$name"
165 config_get name
"$cfg" name
166 [ -n "$name" ] ||
return 0
168 config_get mac
"$cfg" mac
169 [ -n "$mac" ] ||
return 0
171 append args
"--dhcp-mac=$name,$mac"
173 dhcp_option_add
"$cfg" "$name"
179 config_get name
"$cfg" name
180 [ -n "$name" ] ||
return 0
182 config_get filename
"$cfg" filename
183 [ -n "$filename" ] ||
return 0
185 config_get servername
"$cfg" servername
186 [ -n "$servername" ] ||
return 0
188 config_get serveraddress
"$cfg" serveraddress
189 [ -n "$serveraddress" ] ||
return 0
191 append args
"--dhcp-boot=net:$name,$filename,$servername,$serveraddress"
193 dhcp_option_add
"$cfg" "$name"
199 config_get net
"$cfg" interface
200 [ -n "$net" ] ||
return 0
202 config_get name
"$cfg" name
203 [ -n "$name" ] || name
="$net"
205 config_get ifname
"$net" ifname
206 [ -n "$ifname" ] ||
return 0
208 config_get dnsserver
"$net" dns
209 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
210 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
213 append_bool
"$cfg" ignore
"-2 $ifname"
215 config_get proto
"$net" proto
216 [ static
= "$proto" ] ||
return 0
218 config_get ipaddr
"$net" ipaddr
219 config_get netmask
"$cfg" netmask
220 [ -n "$netmask" ] || config_get netmask
"$net" netmask
222 #check for an already active dhcp server on the interface, unless 'force' is set
223 config_get_bool force
"$cfg" force
0
224 [ "$force" -gt 0 ] ||
{
225 udhcpc
-n -q -R -s /bin
/true
-t 1 -i $ifname >&- && return 0
228 config_get start
"$cfg" start
229 config_get limit
"$cfg" limit
230 config_get leasetime
"$cfg" leasetime
231 config_get options
"$cfg" options
232 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
234 leasetime
="${leasetime:-12h}"
235 start
="$(dhcp_calc "${start:-100}")"
236 limit
="$((${limit:-150} + 1))"
237 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
238 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
239 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
241 dhcp_option_add
"$cfg" "$name"
248 config_get dhcp_option
"$cfg" dhcp_option
249 for o
in $dhcp_option; do
250 append args
"-O $name","$o"
261 config_foreach dnsmasq dnsmasq
262 config_foreach dhcp_host_add
host
263 config_foreach dhcp_boot_add boot
264 config_foreach dhcp_mac_add mac
265 config_foreach dhcp_vendorclass_add vendorclass
266 config_foreach dhcp_userclass_add userclass
267 config_foreach dhcp_circuitid_add circuitid
268 config_foreach dhcp_remoteid_add remoteid
269 config_foreach dhcp_subscrid_add subscrid
270 config_foreach dhcp_add dhcp
272 /usr
/sbin
/dnsmasq
$args && {
273 rm -f /tmp
/resolv.conf
274 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
275 for DNS_SERVER
in $DNS_SERVERS ; do
276 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
282 [ -f /tmp
/resolv.conf
] && {
283 rm -f /tmp
/resolv.conf
284 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf