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"
49 append_bool
"$cfg" authoritative
"-K"
50 append_bool
"$cfg" nodaemon
"-d"
51 append_bool
"$cfg" domainneeded
"-D"
52 append_bool
"$cfg" filterwin2k
"-f"
53 append_bool
"$cfg" nohosts
"-h"
54 append_bool
"$cfg" nonegcache
"-N"
55 append_bool
"$cfg" strictorder
"-o"
56 append_bool
"$cfg" logqueries
"-q"
57 append_bool
"$cfg" noresolv
"-R"
58 append_bool
"$cfg" localise_queries
"-y"
59 append_bool
"$cfg" readethers
"-Z"
60 append_bool
"$cfg" dbus
"-1"
61 append_bool
"$cfg" boguspriv
"-b"
62 append_bool
"$cfg" expandhosts
"-E"
63 append_bool
"$cfg" enable_tftp
"--enable-tftp"
64 append_bool
"$cfg" nonwildcard
"-z"
66 append_parm
"$cfg" dnsforwardmax
"-0"
67 append_parm
"$cfg" port
"-p"
68 append_parm
"$cfg" ednspacket_max
"-P"
69 append_parm
"$cfg" dhcpleasemax
"-X"
70 append_parm
"$cfg" "addnhosts" "-H"
71 append_parm
"$cfg" "queryport" "-Q"
72 append_parm
"$cfg" "domain" "-s"
73 append_parm
"$cfg" "local" "-S"
74 config_list_foreach
"$cfg" "server" append_server
75 config_list_foreach
"$cfg" "interface" append_interface
76 append_parm
"$cfg" "leasefile" "-l"
77 append_parm
"$cfg" "resolvfile" "-r"
78 append_parm
"$cfg" "tftp_root" "--tftp-root"
79 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
81 config_get leasefile
$cfg leasefile
82 [ -e "$leasefile" ] ||
touch "$leasefile"
83 config_get_bool cachelocal
"$cfg" cachelocal
1
85 config_get hostsfile
"$cfg" dhcphostsfile
86 [ -e "$hostsfile" ] && append args
"--dhcp-hostsfile=$hostsfile"
92 config_get name
"$cfg" name
93 [ -n "$name" ] ||
return 0
95 config_get subscriberid
"$cfg" subscriberid
96 [ -n "$subscriberid" ] ||
return 0
98 append args
"--dhcp-subscrid=$name,$subscriberid"
100 dhcp_option_add
"$cfg" "$name"
103 dhcp_remoteid_add
() {
106 config_get name
"$cfg" name
107 [ -n "$name" ] ||
return 0
109 config_get remoteid
"$cfg" remoteid
110 [ -n "$remoteid" ] ||
return 0
112 append args
"--dhcp-remoteid=$name,$remoteid"
114 dhcp_option_add
"$cfg" "$name"
117 dhcp_circuitid_add
() {
120 config_get name
"$cfg" name
121 [ -n "$name" ] ||
return 0
123 config_get circuitid
"$cfg" circuitid
124 [ -n "$circuitid" ] ||
return 0
126 append args
"--dhcp-circuitid=$name,$circuitid"
128 dhcp_option_add
"$cfg" "$name"
131 dhcp_userclass_add
() {
134 config_get name
"$cfg" name
135 [ -n "$name" ] ||
return 0
137 config_get userclass
"$cfg" userclass
138 [ -n "$userclass" ] ||
return 0
140 append args
"--dhcp-userclass=$name,$userclass"
142 dhcp_option_add
"$cfg" "$name"
145 dhcp_vendorclass_add
() {
148 config_get name
"$cfg" name
149 [ -n "$name" ] ||
return 0
151 config_get vendorclass
"$cfg" vendorclass
152 [ -n "$vendorclass" ] ||
return 0
154 append args
"--dhcp-vendorclass=$name,$vendorclass"
156 dhcp_option_add
"$cfg" "$name"
162 config_get name
"$cfg" name
163 [ -n "$name" ] ||
return 0
165 config_get mac
"$cfg" mac
166 [ -n "$mac" ] ||
return 0
168 config_get ip
"$cfg" ip
169 [ -n "$ip" ] ||
return 0
171 append args
"--dhcp-host=$mac,$ip"
173 dhcp_option_add
"$cfg" "$name"
179 config_get name
"$cfg" name
180 [ -n "$name" ] ||
return 0
182 config_get mac
"$cfg" mac
183 [ -n "$mac" ] ||
return 0
185 append args
"--dhcp-mac=$name,$mac"
187 dhcp_option_add
"$cfg" "$name"
193 config_get name
"$cfg" name
195 config_get filename
"$cfg" filename
196 [ -n "$filename" ] ||
return 0
198 config_get servername
"$cfg" servername
199 [ -n "$servername" ] ||
return 0
201 config_get serveraddress
"$cfg" serveraddress
202 [ -n "$serveraddress" ] ||
return 0
204 append args
"--dhcp-boot=${name:+net:$name,}$filename,$servername,$serveraddress"
206 dhcp_option_add
"$cfg" "$name"
212 config_get net
"$cfg" interface
213 [ -n "$net" ] ||
return 0
215 config_get name
"$cfg" name
216 [ -n "$name" ] || name
="$net"
218 config_get ifname
"$net" ifname
219 [ -n "$ifname" ] ||
return 0
221 config_get dnsserver
"$net" dns
222 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
223 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
226 append_bool
"$cfg" ignore
"-2 $ifname" && return 0
228 config_get proto
"$net" proto
229 [ static
= "$proto" ] ||
return 0
231 config_get ipaddr
"$net" ipaddr
232 config_get netmask
"$cfg" netmask
233 [ -n "$netmask" ] || config_get netmask
"$net" netmask
235 #check for an already active dhcp server on the interface, unless 'force' is set
236 config_get_bool force
"$cfg" force
0
237 [ "$force" -gt 0 ] ||
{
238 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
241 config_get start
"$cfg" start
242 config_get limit
"$cfg" limit
243 config_get leasetime
"$cfg" leasetime
244 config_get options
"$cfg" options
245 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
247 leasetime
="${leasetime:-12h}"
248 start
="$(dhcp_calc "${start:-100}")"
249 limit
="$((${limit:-150} + 1))"
250 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
251 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
252 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
254 dhcp_option_add
"$cfg" "$name"
261 config_get dhcp_option
"$cfg" dhcp_option
262 for o
in $dhcp_option; do
263 append args
"-O $name","$o"
274 config_foreach dnsmasq dnsmasq
275 config_foreach dhcp_host_add
host
276 config_foreach dhcp_boot_add boot
277 config_foreach dhcp_mac_add mac
278 config_foreach dhcp_vendorclass_add vendorclass
279 config_foreach dhcp_userclass_add userclass
280 config_foreach dhcp_circuitid_add circuitid
281 config_foreach dhcp_remoteid_add remoteid
282 config_foreach dhcp_subscrid_add subscrid
283 config_foreach dhcp_add dhcp
285 /usr
/sbin
/dnsmasq
$args && {
286 rm -f /tmp
/resolv.conf
287 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
288 for DNS_SERVER
in $DNS_SERVERS ; do
289 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
295 [ -f /tmp
/resolv.conf
] && {
296 rm -f /tmp
/resolv.conf
297 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf