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"
45 append_bool
"$cfg" authoritative
"-K"
46 append_bool
"$cfg" nodaemon
"-d"
47 append_bool
"$cfg" domainneeded
"-D"
48 append_bool
"$cfg" filterwin2k
"-f"
49 append_bool
"$cfg" nohosts
"-h"
50 append_bool
"$cfg" nonegcache
"-N"
51 append_bool
"$cfg" strictorder
"-o"
52 append_bool
"$cfg" logqueries
"-q"
53 append_bool
"$cfg" noresolv
"-R"
54 append_bool
"$cfg" localise_queries
"-y"
55 append_bool
"$cfg" readethers
"-Z"
56 append_bool
"$cfg" dbus
"-1"
57 append_bool
"$cfg" boguspriv
"-b"
58 append_bool
"$cfg" expandhosts
"-E"
59 append_bool
"$cfg" enable_tftp
"--enable-tftp"
60 append_bool
"$cfg" nonwildcard
"-z"
62 append_parm
"$cfg" dnsforwardmax
"-0"
63 append_parm
"$cfg" port
"-p"
64 append_parm
"$cfg" ednspacket_max
"-P"
65 append_parm
"$cfg" dhcpleasemax
"-X"
66 append_parm
"$cfg" "addnhosts" "-H"
67 append_parm
"$cfg" "queryport" "-Q"
68 append_parm
"$cfg" "domain" "-s"
69 append_parm
"$cfg" "local" "-S"
70 config_list_foreach
"$cfg" "server" append_server
71 append_parm
"$cfg" "leasefile" "-l"
72 append_parm
"$cfg" "resolvfile" "-r"
73 append_parm
"$cfg" "tftp_root" "--tftp-root"
74 append_parm
"$cfg" "dhcp_boot" "--dhcp-boot"
75 append_parm
"$cfg" "interfaces" "-i"
77 config_get leasefile
$cfg leasefile
78 [ -e "$leasefile" ] ||
touch "$leasefile"
79 config_get_bool cachelocal
"$cfg" cachelocal
1
85 config_get name
"$cfg" name
86 [ -n "$name" ] ||
return 0
88 config_get subscriberid
"$cfg" subscriberid
89 [ -n "$subscriberid" ] ||
return 0
91 append args
"--dhcp-subscrid=$name,$subscriberid"
93 dhcp_option_add
"$cfg" "$name"
99 config_get name
"$cfg" name
100 [ -n "$name" ] ||
return 0
102 config_get remoteid
"$cfg" remoteid
103 [ -n "$remoteid" ] ||
return 0
105 append args
"--dhcp-remoteid=$name,$remoteid"
107 dhcp_option_add
"$cfg" "$name"
110 dhcp_circuitid_add
() {
113 config_get name
"$cfg" name
114 [ -n "$name" ] ||
return 0
116 config_get circuitid
"$cfg" circuitid
117 [ -n "$circuitid" ] ||
return 0
119 append args
"--dhcp-circuitid=$name,$circuitid"
121 dhcp_option_add
"$cfg" "$name"
124 dhcp_userclass_add
() {
127 config_get name
"$cfg" name
128 [ -n "$name" ] ||
return 0
130 config_get userclass
"$cfg" userclass
131 [ -n "$userclass" ] ||
return 0
133 append args
"--dhcp-userclass=$name,$userclass"
135 dhcp_option_add
"$cfg" "$name"
138 dhcp_vendorclass_add
() {
141 config_get name
"$cfg" name
142 [ -n "$name" ] ||
return 0
144 config_get vendorclass
"$cfg" vendorclass
145 [ -n "$vendorclass" ] ||
return 0
147 append args
"--dhcp-vendorclass=$name,$vendorclass"
149 dhcp_option_add
"$cfg" "$name"
155 config_get name
"$cfg" name
156 [ -n "$name" ] ||
return 0
158 config_get mac
"$cfg" mac
159 [ -n "$mac" ] ||
return 0
161 config_get ip
"$cfg" ip
162 [ -n "$ip" ] ||
return 0
164 append args
"--dhcp-host=$mac,$ip"
166 dhcp_option_add
"$cfg" "$name"
172 config_get name
"$cfg" name
173 [ -n "$name" ] ||
return 0
175 config_get mac
"$cfg" mac
176 [ -n "$mac" ] ||
return 0
178 append args
"--dhcp-mac=$name,$mac"
180 dhcp_option_add
"$cfg" "$name"
186 config_get name
"$cfg" name
188 config_get filename
"$cfg" filename
189 [ -n "$filename" ] ||
return 0
191 config_get servername
"$cfg" servername
192 [ -n "$servername" ] ||
return 0
194 config_get serveraddress
"$cfg" serveraddress
195 [ -n "$serveraddress" ] ||
return 0
197 append args
"--dhcp-boot=${name:+net:$name,}$filename,$servername,$serveraddress"
199 dhcp_option_add
"$cfg" "$name"
205 config_get net
"$cfg" interface
206 [ -n "$net" ] ||
return 0
208 config_get name
"$cfg" name
209 [ -n "$name" ] || name
="$net"
211 config_get ifname
"$net" ifname
212 [ -n "$ifname" ] ||
return 0
214 config_get dnsserver
"$net" dns
215 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
216 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
219 append_bool
"$cfg" ignore
"-2 $ifname"
221 config_get proto
"$net" proto
222 [ static
= "$proto" ] ||
return 0
224 config_get ipaddr
"$net" ipaddr
225 config_get netmask
"$cfg" netmask
226 [ -n "$netmask" ] || config_get netmask
"$net" netmask
228 #check for an already active dhcp server on the interface, unless 'force' is set
229 config_get_bool force
"$cfg" force
0
230 [ "$force" -gt 0 ] ||
{
231 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
234 config_get start
"$cfg" start
235 config_get limit
"$cfg" limit
236 config_get leasetime
"$cfg" leasetime
237 config_get options
"$cfg" options
238 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
240 leasetime
="${leasetime:-12h}"
241 start
="$(dhcp_calc "${start:-100}")"
242 limit
="$((${limit:-150} + 1))"
243 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
244 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
245 append args
"--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
247 dhcp_option_add
"$cfg" "$name"
254 config_get dhcp_option
"$cfg" dhcp_option
255 for o
in $dhcp_option; do
256 append args
"-O $name","$o"
267 config_foreach dnsmasq dnsmasq
268 config_foreach dhcp_host_add
host
269 config_foreach dhcp_boot_add boot
270 config_foreach dhcp_mac_add mac
271 config_foreach dhcp_vendorclass_add vendorclass
272 config_foreach dhcp_userclass_add userclass
273 config_foreach dhcp_circuitid_add circuitid
274 config_foreach dhcp_remoteid_add remoteid
275 config_foreach dhcp_subscrid_add subscrid
276 config_foreach dhcp_add dhcp
278 /usr
/sbin
/dnsmasq
$args && {
279 rm -f /tmp
/resolv.conf
280 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
281 for DNS_SERVER
in $DNS_SERVERS ; do
282 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
288 [ -f /tmp
/resolv.conf
] && {
289 rm -f /tmp
/resolv.conf
290 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf