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 leasefile
$cfg leasefile
94 [ -e "$leasefile" ] ||
touch "$leasefile"
95 config_get_bool cachelocal
"$cfg" cachelocal
1
97 config_get hostsfile
"$cfg" dhcphostsfile
98 [ -e "$hostsfile" ] && append args
"--dhcp-hostsfile=$hostsfile"
101 dhcp_subscrid_add
() {
104 config_get networkid
"$cfg" networkid
105 [ -n "$networkid" ] ||
return 0
107 config_get subscriberid
"$cfg" subscriberid
108 [ -n "$subscriberid" ] ||
return 0
110 append args
"--dhcp-subscrid=$networkid,$subscriberid"
112 dhcp_option_add
"$cfg" "$networkid"
115 dhcp_remoteid_add
() {
118 config_get networkid
"$cfg" networkid
119 [ -n "$networkid" ] ||
return 0
121 config_get remoteid
"$cfg" remoteid
122 [ -n "$remoteid" ] ||
return 0
124 append args
"--dhcp-remoteid=$networkid,$remoteid"
126 dhcp_option_add
"$cfg" "$networkid"
129 dhcp_circuitid_add
() {
132 config_get networkid
"$cfg" networkid
133 [ -n "$networkid" ] ||
return 0
135 config_get circuitid
"$cfg" circuitid
136 [ -n "$circuitid" ] ||
return 0
138 append args
"--dhcp-circuitid=$networkid,$circuitid"
140 dhcp_option_add
"$cfg" "$networkid"
143 dhcp_userclass_add
() {
146 config_get networkid
"$cfg" networkid
147 [ -n "$networkid" ] ||
return 0
149 config_get userclass
"$cfg" userclass
150 [ -n "$userclass" ] ||
return 0
152 append args
"--dhcp-userclass=$networkid,$userclass"
154 dhcp_option_add
"$cfg" "$networkid"
157 dhcp_vendorclass_add
() {
160 config_get networkid
"$cfg" networkid
161 [ -n "$networkid" ] ||
return 0
163 config_get vendorclass
"$cfg" vendorclass
164 [ -n "$vendorclass" ] ||
return 0
166 append args
"--dhcp-vendorclass=$networkid,$vendorclass"
168 dhcp_option_add
"$cfg" "$networkid"
174 config_get name
"$cfg" name
176 config_get networkid
"$cfg" networkid
177 [ -n "$networkid" ] && dhcp_option_add
"$cfg" "$networkid"
179 config_get mac
"$cfg" mac
180 [ -n "$mac" ] ||
return 0
182 config_get ip
"$cfg" ip
183 [ -n "$ip" ] ||
return 0
185 append args
"--dhcp-host=$mac,${networkid:+net:$networkid,}$ip${name:+,$name}"
191 config_get networkid
"$cfg" networkid
192 [ -n "$networkid" ] ||
return 0
194 config_get mac
"$cfg" mac
195 [ -n "$mac" ] ||
return 0
197 append args
"--dhcp-mac=$networkid,$mac"
199 dhcp_option_add
"$cfg" "$networkid"
205 config_get networkid
"$cfg" networkid
207 config_get filename
"$cfg" filename
208 [ -n "$filename" ] ||
return 0
210 config_get servername
"$cfg" servername
211 [ -n "$servername" ] ||
return 0
213 config_get serveraddress
"$cfg" serveraddress
214 [ -n "$serveraddress" ] ||
return 0
216 append args
"--dhcp-boot=${networkid:+net:$networkid,}$filename,$servername,$serveraddress"
218 dhcp_option_add
"$cfg" "$networkid"
224 config_get net
"$cfg" interface
225 [ -n "$net" ] ||
return 0
227 config_get networkid
"$cfg" networkid
228 [ -n "$networkid" ] || networkid
="$net"
230 config_get ifname
"$net" ifname
231 [ -n "$ifname" ] ||
return 0
233 config_get dnsserver
"$net" dns
234 [ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
235 DNS_SERVERS
="$DNS_SERVERS $dnsserver"
238 append_bool
"$cfg" ignore
"-2 $ifname" && return 0
240 config_get proto
"$net" proto
241 [ static
= "$proto" ] ||
return 0
243 config_get ipaddr
"$net" ipaddr
244 config_get netmask
"$cfg" netmask
245 [ -n "$netmask" ] || config_get netmask
"$net" netmask
247 #check for an already active dhcp server on the interface, unless 'force' is set
248 config_get_bool force
"$cfg" force
0
249 [ "$force" -gt 0 ] ||
{
250 udhcpc
-n -q -s /bin
/true
-t 1 -i $ifname >&- && return 0
253 config_get start
"$cfg" start
254 config_get limit
"$cfg" limit
255 config_get leasetime
"$cfg" leasetime
256 config_get options
"$cfg" options
257 config_get_bool dynamicdhcp
"$cfg" dynamicdhcp
1
259 leasetime
="${leasetime:-12h}"
260 start
="$(dhcp_calc "${start:-100}")"
261 limit
="$((${limit:-150} + 1))"
262 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
263 if [ "$dynamicdhcp" = "0" ]; then END
="static"; fi
264 append args
"--dhcp-range=$networkid,$START,$END,$NETMASK,$leasetime${options:+ $options}"
266 dhcp_option_add
"$cfg" "$networkid"
273 config_get dhcp_option
"$cfg" dhcp_option
274 for o
in $dhcp_option; do
275 append args
"-O $networkid","$o"
283 config_get name
"$cfg" name
284 [ -n "$name" ] ||
return 0
286 config_get ip
"$cfg" ip
287 [ -n "$ip" ] ||
return 0
289 local oIFS
="$IFS"; IFS
="."; set -- $ip; IFS
="$oIFS"
290 append args
"-A /$name${DOMAIN:+.$DOMAIN}/$ip"
291 append args
"--ptr-record=$4.$3.$2.$1.in-addr.arpa,$name${DOMAIN:+.$DOMAIN}"
300 config_foreach dnsmasq dnsmasq
301 config_foreach dhcp_host_add
host
302 config_foreach dhcp_boot_add boot
303 config_foreach dhcp_mac_add mac
304 config_foreach dhcp_vendorclass_add vendorclass
305 config_foreach dhcp_userclass_add userclass
306 config_foreach dhcp_circuitid_add circuitid
307 config_foreach dhcp_remoteid_add remoteid
308 config_foreach dhcp_subscrid_add subscrid
309 config_foreach dhcp_domain_add domain
310 config_foreach dhcp_add dhcp
312 /usr
/sbin
/dnsmasq
$args && {
313 rm -f /tmp
/resolv.conf
314 [ -n "$DOMAIN" ] && echo "search $DOMAIN" >> /tmp
/resolv.conf
315 DNS_SERVERS
="$DNS_SERVERS 127.0.0.1"
316 for DNS_SERVER
in $DNS_SERVERS ; do
317 echo "nameserver $DNS_SERVER" >> /tmp
/resolv.conf
323 [ -f /tmp
/resolv.conf
] && {
324 rm -f /tmp
/resolv.conf
325 ln -s /tmp
/resolv.conf.auto
/tmp
/resolv.conf