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 "-l"
53 append_bool "$cfg" boguspriv "-b"
54 append_bool "$cfg" expandhosts "-E"
56 append_parm "$cfg" dnsforwardmax "-0"
57 append_parm "$cfg" port "-p"
58 append_parm "$cfg" ednspacket_max "-P"
59 append_parm "$cfg" dhcpleasemax "-X"
60 append_parm "$cfg" "addnhosts" "-H"
61 append_parm "$cfg" "queryport" "-Q"
62 append_parm "$cfg" "domain" "-s"
63 append_parm "$cfg" "local" "-S"
64 append_parm "$cfg" "leasefile" "-l"
65 append_parm "$cfg" "resolvfile" "-r"
67 config_get leasefile $cfg leasefile
68 [ -e "$leasefile" ] || touch "$leasefile"
74 config_get name "$cfg" name
75 [ -n "$name" ] || return 0
77 config_get subscriberid "$cfg" subscriberid
78 [ -n "$subscriberid" ] || return 0
80 append args "--dhcp-subscrid=$name,$subscriberid"
82 dhcp_option_add "$cfg" "$name"
88 config_get name "$cfg" name
89 [ -n "$name" ] || return 0
91 config_get remoteid "$cfg" remoteid
92 [ -n "$remoteid" ] || return 0
94 append args "--dhcp-remoteid=$name,$remoteid"
96 dhcp_option_add "$cfg" "$name"
99 dhcp_circuitid_add() {
102 config_get name "$cfg" name
103 [ -n "$name" ] || return 0
105 config_get circuitid "$cfg" circuitid
106 [ -n "$circuitid" ] || return 0
108 append args "--dhcp-circuitid=$name,$circuitid"
110 dhcp_option_add "$cfg" "$name"
113 dhcp_userclass_add() {
116 config_get name "$cfg" name
117 [ -n "$name" ] || return 0
119 config_get userclass "$cfg" userclass
120 [ -n "$userclass" ] || return 0
122 append args "--dhcp-userclass=$name,$userclass"
124 dhcp_option_add "$cfg" "$name"
127 dhcp_vendorclass_add() {
130 config_get name "$cfg" name
131 [ -n "$name" ] || return 0
133 config_get vendorclass "$cfg" vendorclass
134 [ -n "$vendorclass" ] || return 0
136 append args "--dhcp-vendorclass=$name,$vendorclass"
138 dhcp_option_add "$cfg" "$name"
144 config_get name "$cfg" name
145 [ -n "$name" ] || return 0
147 config_get mac "$cfg" mac
148 [ -n "$mac" ] || return 0
150 config_get ip "$cfg" ip
151 [ -n "$ip" ] || return 0
153 append args "--dhcp-host=$mac,$ip"
155 dhcp_option_add "$cfg" "$name"
161 config_get name "$cfg" name
162 [ -n "$name" ] || return 0
164 config_get mac "$cfg" mac
165 [ -n "$mac" ] || return 0
167 append args "--dhcp-mac=$name,$mac"
169 dhcp_option_add "$cfg" "$name"
174 config_get net "$cfg" interface
175 [ -n "$net" ] || return 0
177 config_get name "$cfg" name
178 [ -n "$name" ] || name="$net"
180 config_get ifname "$net" ifname
181 [ -n "$ifname" ] || return 0
183 config_get dnsserver "$net" dns
184 [ -n "$dnsserver" ] && {
185 DNS_SERVERS="$DNS_SERVERS $dnsserver"
188 append_bool "$cfg" ignore "-I $ifname"
190 config_get proto "$net" proto
191 [ static = "$proto" ] || return 0
193 config_get ipaddr "$net" ipaddr
194 config_get netmask "$cfg" netmask
195 [ -n "$netmask" ] || config_get netmask "$net" netmask
197 #check for an already active dhcp server on the interface, unless 'force' is set
198 config_get_bool force "$cfg" force 0
199 [ "$force" -gt 0 ] || {
200 udhcpc -n -q -R -s /bin/true -t 1 -i $ifname >&- && return 0
203 config_get start "$cfg" start
204 config_get limit "$cfg" limit
205 config_get leasetime "$cfg" leasetime
206 config_get options "$cfg" options
207 config_get_bool dynamicdhcp "$cfg" dynamicdhcp 1
209 leasetime="${leasetime:-12h}"
210 start="$(dhcp_calc "${start:-100}")"
211 limit="$((${limit:-150} + 1))"
212 eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
213 if [ "$dynamicdhcp" = "0" ]; then END="static"; fi
214 append args "--dhcp-range=$name,$START,$END,$NETMASK,$leasetime${options:+ $options}"
216 dhcp_option_add "$cfg" "$name"
223 for count in $(seq 0 100); do
224 eval current_value=\$CONFIG_"$cfg"_dhcp"$count"
225 if [ -z "$current_value" ]; then
229 append args "-O $name","$current_value"
240 config_foreach dnsmasq dnsmasq
241 config_foreach dhcp_host_add host
242 config_foreach dhcp_mac_add mac
243 config_foreach dhcp_vendorclass_add vendorclass
244 config_foreach dhcp_userclass_add userclass
245 config_foreach dhcp_circuitid_add circuitid
246 config_foreach dhcp_remoteid_add remoteid
247 config_foreach dhcp_subscrid_add subscrid
248 config_foreach dhcp_add dhcp
250 /usr/sbin/dnsmasq $args && {
251 rm -f /tmp/resolv.conf
252 DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
253 for DNS_SERVER in $DNS_SERVERS ; do
254 echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf