Contents of /trunk/dracut/patches/dracut-044-network-support-udhcpc-dhcpcd.patch
Parent Directory | Revision Log
Revision 2727 -
(show annotations)
(download)
Mon Nov 30 10:44:31 2015 UTC (8 years, 9 months ago) by niro
File size: 18007 byte(s)
Mon Nov 30 10:44:31 2015 UTC (8 years, 9 months ago) by niro
File size: 18007 byte(s)
-rediffed patches for dracut-044
1 | diff -Naur dracut-044/modules.d/40network/dhcpcd-script.sh dracut-044-magellan/modules.d/40network/dhcpcd-script.sh |
2 | --- dracut-044/modules.d/40network/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100 |
3 | +++ dracut-044-magellan/modules.d/40network/dhcpcd-script.sh 2015-11-30 11:07:30.863845155 +0100 |
4 | @@ -0,0 +1,194 @@ |
5 | +#!/bin/sh |
6 | + |
7 | +PATH=/usr/sbin:/usr/bin:/sbin:/bin |
8 | + |
9 | +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
10 | +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh |
11 | + |
12 | +# We already need a set netif here |
13 | +netif=$interface |
14 | + |
15 | +setup_interface() { |
16 | + ip=$new_ip_address |
17 | + mtu=$new_interface_mtu |
18 | + mask=$new_subnet_mask |
19 | + bcast=$new_broadcast_address |
20 | + gw=${new_routers%%,*} |
21 | + domain=$new_domain_name |
22 | + search=$(printf -- "$new_domain_search") |
23 | + namesrv=$new_domain_name_servers |
24 | + hostname=$new_host_name |
25 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
26 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
27 | + preferred_lft=$lease_time |
28 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
29 | + |
30 | + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
31 | + |
32 | + # Taken from debian dhclient-script: |
33 | + # The 576 MTU is only used for X.25 and dialup connections |
34 | + # where the admin wants low latency. Such a low MTU can cause |
35 | + # problems with UDP traffic, among other things. As such, |
36 | + # disallow MTUs from 576 and below by default, so that broken |
37 | + # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). |
38 | + if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then |
39 | + if ! ip link set $netif mtu $mtu ; then |
40 | + ip link set $netif down |
41 | + ip link set $netif mtu $mtu |
42 | + linkup $netif |
43 | + fi |
44 | + fi |
45 | + |
46 | + ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif \ |
47 | + ${lease_time:+valid_lft $lease_time} \ |
48 | + ${preferred_lft:+preferred_lft ${preferred_lft}} |
49 | + |
50 | + if [ -n "$gw" ] ; then |
51 | + if [ "$mask" = "255.255.255.255" ] ; then |
52 | + # point-to-point connection => set explicit route to gateway |
53 | + echo ip route add $gw dev $netif > /tmp/net.$netif.gw |
54 | + fi |
55 | + echo ip route replace default via $gw dev $netif >> /tmp/net.$netif.gw |
56 | + fi |
57 | + |
58 | + if getargbool 1 rd.peerdns; then |
59 | + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf |
60 | + if [ -n "$namesrv" ] ; then |
61 | + for s in $namesrv; do |
62 | + echo nameserver $s |
63 | + done |
64 | + fi >> /tmp/net.$netif.resolv.conf |
65 | + fi |
66 | + # Note: hostname can be fqdn OR short hostname, so chop off any |
67 | + # trailing domain name and explicity add any domain if set. |
68 | + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname |
69 | +} |
70 | + |
71 | +setup_interface6() { |
72 | + domain=$new_domain_name |
73 | + search=$(printf -- "$new_domain_search") |
74 | + namesrv=$new_domain_name_servers |
75 | + hostname=$new_host_name |
76 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
77 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
78 | + preferred_lft=$lease_time |
79 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
80 | + |
81 | + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
82 | + |
83 | + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \ |
84 | + dev ${netif} scope global \ |
85 | + ${lease_time:+valid_lft $lease_time} \ |
86 | + ${preferred_lft:+preferred_lft ${preferred_lft}} |
87 | + |
88 | + if getargbool 1 rd.peerdns; then |
89 | + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf |
90 | + if [ -n "$namesrv" ] ; then |
91 | + for s in $namesrv; do |
92 | + echo nameserver $s |
93 | + done |
94 | + fi >> /tmp/net.$netif.resolv.conf |
95 | + fi |
96 | + |
97 | + # Note: hostname can be fqdn OR short hostname, so chop off any |
98 | + # trailing domain name and explicity add any domain if set. |
99 | + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname |
100 | +} |
101 | + |
102 | +case $reason in |
103 | + PREINIT) |
104 | + echo "dhcp: PREINIT $netif up" |
105 | + linkup $netif |
106 | + ;; |
107 | + |
108 | + PREINIT6) |
109 | + echo "dhcp: PREINIT6 $netif up" |
110 | + linkup $netif |
111 | + wait_for_ipv6_dad $netif |
112 | + ;; |
113 | + |
114 | + BOUND) |
115 | + echo "dhcp: BOND setting $netif" |
116 | + unset layer2 |
117 | + if [ -f /sys/class/net/$netif/device/layer2 ]; then |
118 | + read layer2 < /sys/class/net/$netif/device/layer2 |
119 | + fi |
120 | + if [ "$layer2" != "0" ]; then |
121 | + if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then |
122 | + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" |
123 | + exit 1 |
124 | + fi |
125 | + fi |
126 | + unset layer2 |
127 | + setup_interface |
128 | + set | while read line || [ -n "$line" ]; do |
129 | + [ "${line#new_}" = "$line" ] && continue |
130 | + echo "$line" |
131 | + done >/tmp/dhcpcd.$netif.dhcpopts |
132 | + |
133 | + { |
134 | + echo '. /lib/net-lib.sh' |
135 | + echo "setup_net $netif" |
136 | + echo "source_hook initqueue/online $netif" |
137 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
138 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
139 | + } > $hookdir/initqueue/setup_net_$netif.sh |
140 | + |
141 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh |
142 | + >/tmp/net.$netif.up |
143 | + if [ -e /sys/class/net/${netif}/address ]; then |
144 | + > /tmp/net.$(cat /sys/class/net/${netif}/address).up |
145 | + fi |
146 | + |
147 | + ;; |
148 | + |
149 | + RENEW|REBIND) |
150 | + unset lease_time |
151 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
152 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
153 | + preferred_lft=$lease_time |
154 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
155 | + ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \ |
156 | + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ |
157 | + >/dev/null 2>&1 |
158 | + ;; |
159 | + |
160 | + BOUND6) |
161 | + echo "dhcp: BOND6 setting $netif" |
162 | + setup_interface6 |
163 | + |
164 | + set | while read line || [ -n "$line" ]; do |
165 | + [ "${line#new_}" = "$line" ] && continue |
166 | + echo "$line" |
167 | + done >/tmp/dhcpcd.$netif.dhcpopts |
168 | + |
169 | + { |
170 | + echo '. /lib/net-lib.sh' |
171 | + echo "setup_net $netif" |
172 | + echo "source_hook initqueue/online $netif" |
173 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
174 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
175 | + } > $hookdir/initqueue/setup_net_$netif.sh |
176 | + |
177 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh |
178 | + >/tmp/net.$netif.up |
179 | + if [ -e /sys/class/net/${netif}/address ]; then |
180 | + > /tmp/net.$(cat /sys/class/net/${netif}/address).up |
181 | + fi |
182 | + ;; |
183 | + |
184 | + RENEW6|REBIND6) |
185 | + unset lease_time |
186 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
187 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
188 | + preferred_lft=$lease_time |
189 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
190 | + ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \ |
191 | + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ |
192 | + >/dev/null 2>&1 |
193 | + ;; |
194 | + |
195 | + *) echo "dhcp: $reason";; |
196 | +esac |
197 | + |
198 | +exit 0 |
199 | diff -Naur dracut-044/modules.d/40network/ifup.sh dracut-044-magellan/modules.d/40network/ifup.sh |
200 | --- dracut-044/modules.d/40network/ifup.sh 2015-11-25 14:22:28.000000000 +0100 |
201 | +++ dracut-044-magellan/modules.d/40network/ifup.sh 2015-11-30 11:25:08.061792465 +0100 |
202 | @@ -10,6 +10,23 @@ |
203 | type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
204 | type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh |
205 | |
206 | +# load magellan settings |
207 | +[ -f /etc/conf.d/network ] && . /etc/conf.d/network |
208 | +# some sane defaults |
209 | +if [[ -n $DEFAULT_DHCP_PROG ]] |
210 | +then |
211 | + DHCP_PROG="$DEFAULT_DHCP_PROG" |
212 | +else |
213 | + DHCP_PROG="/sbin/dhcpcd" |
214 | +fi |
215 | +if [[ -n $DEFAULT_DHCP_START ]] |
216 | +then |
217 | + DHCP_START="$DEFAULT_DHCP_START" |
218 | +else |
219 | + DHCP_START="-t 10" |
220 | +fi |
221 | +DHCP_PROG_NAME="${DHCP_PROG##*/}" |
222 | + |
223 | # Huh? No $1? |
224 | [ -z "$1" ] && exit 1 |
225 | |
226 | @@ -89,6 +106,9 @@ |
227 | |
228 | # Run dhclient |
229 | do_dhcp() { |
230 | + local opts |
231 | + local timeoutswitch |
232 | + |
233 | # dhclient-script will mark the netif up and generate the online |
234 | # event for nfsroot |
235 | # XXX add -V vendor class and option parsing per kernel |
236 | @@ -105,20 +125,37 @@ |
237 | return 1 |
238 | fi |
239 | |
240 | + case $DHCP_PROG_NAME in |
241 | + dhclient) |
242 | + opts="$@ -1 -q" |
243 | + opts+=" -cf /etc/dhclient.conf" |
244 | + opts+=" -pf /tmp/$DHCP_PROG_NAME.$netif.pid" |
245 | + opts+=" -lf /tmp/$DHCP_PROG_NAME.$netif.lease" |
246 | + timeoutswitch="-timeout" |
247 | + ;; |
248 | + |
249 | + dhcpcd) |
250 | + opts="$@ -q" |
251 | + timeoutswitch="--timeout" |
252 | + ;; |
253 | + |
254 | + udhcpc) |
255 | + opts="-q" |
256 | + opts+=" -p /tmp/$DHCP_PROG_NAME.$netif.pid" |
257 | + timeoutswitch="--timeout" |
258 | + ;; |
259 | + esac |
260 | + |
261 | while [ $_COUNT -lt $_DHCPRETRY ]; do |
262 | - info "Starting dhcp for interface $netif" |
263 | - dhclient "$@" \ |
264 | - ${_timeout:+-timeout $_timeout} \ |
265 | - -q \ |
266 | - -cf /etc/dhclient.conf \ |
267 | - -pf /tmp/dhclient.$netif.pid \ |
268 | - -lf /tmp/dhclient.$netif.lease \ |
269 | - $netif \ |
270 | + info "Starting dhcp ($DHCP_PROG_NAME) for interface $netif" |
271 | + $DHCP_PROG $opts \ |
272 | + ${_timeout:+$timeoutswitch $_timeout} \ |
273 | + $DHCP_START $netif \ |
274 | && return 0 |
275 | _COUNT=$(($_COUNT+1)) |
276 | [ $_COUNT -lt $_DHCPRETRY ] && sleep 1 |
277 | done |
278 | - warn "dhcp for interface $netif failed" |
279 | + warn "dhcp ($DHCP_PROG_NAME) for interface $netif failed" |
280 | return 1 |
281 | } |
282 | |
283 | diff -Naur dracut-044/modules.d/40network/kill-dhcpcd.sh dracut-044-magellan/modules.d/40network/kill-dhcpcd.sh |
284 | --- dracut-044/modules.d/40network/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100 |
285 | +++ dracut-044-magellan/modules.d/40network/kill-dhcpcd.sh 2015-11-30 11:28:36.339251470 +0100 |
286 | @@ -0,0 +1,17 @@ |
287 | +#!/bin/sh |
288 | + |
289 | +for f in /tmp/dhcpcd.*.pid \ |
290 | + /run/dhcpcd.*.pid /run/dhcpcd.pid; do |
291 | + [ -e $f ] || continue |
292 | + read PID < $f; |
293 | + kill $PID >/dev/null 2>&1 |
294 | +done |
295 | + |
296 | +sleep 0.1 |
297 | + |
298 | +for f in /tmp/dhcpcd.*.pid \ |
299 | + /run/dhcpcd.*.pid /run/dhcpcd.pid; do |
300 | + [ -e $f ] || continue |
301 | + read PID < $f; |
302 | + kill -9 $PID >/dev/null 2>&1 |
303 | +done |
304 | diff -Naur dracut-044/modules.d/40network/kill-udhcpc.sh dracut-044-magellan/modules.d/40network/kill-udhcpc.sh |
305 | --- dracut-044/modules.d/40network/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100 |
306 | +++ dracut-044-magellan/modules.d/40network/kill-udhcpc.sh 2015-11-30 11:31:03.830427861 +0100 |
307 | @@ -0,0 +1,17 @@ |
308 | +#!/bin/sh |
309 | + |
310 | +for f in /tmp/udhcpc.*.pid \ |
311 | + /run/udhcpc.*.pid /run/udhcpc.pid; do |
312 | + [ -e $f ] || continue |
313 | + read PID < $f; |
314 | + kill $PID >/dev/null 2>&1 |
315 | +done |
316 | + |
317 | +sleep 0.1 |
318 | + |
319 | +for f in /tmp/udhcpc.*.pid \ |
320 | + /run/udhcpc.*.pid /run/udhcpc.pid; do |
321 | + [ -e $f ] || continue |
322 | + read PID < $f; |
323 | + kill -9 $PID >/dev/null 2>&1 |
324 | +done |
325 | diff -Naur dracut-044/modules.d/40network/module-setup.sh dracut-044-magellan/modules.d/40network/module-setup.sh |
326 | --- dracut-044/modules.d/40network/module-setup.sh 2015-11-25 14:22:28.000000000 +0100 |
327 | +++ dracut-044-magellan/modules.d/40network/module-setup.sh 2015-11-30 11:34:12.360076369 +0100 |
328 | @@ -3,8 +3,9 @@ |
329 | # called by dracut |
330 | check() { |
331 | local _program |
332 | + . /etc/conf.d/network |
333 | |
334 | - require_binaries ip arping dhclient || return 1 |
335 | + require_binaries ip ifconfig route arping $DEFAULT_DHCP_PROG || return 1 |
336 | |
337 | return 255 |
338 | } |
339 | @@ -23,17 +24,20 @@ |
340 | # called by dracut |
341 | install() { |
342 | local _arch _i _dir |
343 | - inst_multiple ip arping dhclient sed |
344 | + local _dhcp_prog_name |
345 | + local _file |
346 | + . /etc/conf.d/network |
347 | + _dhcp_prog_name="${DEFAULT_DHCP_PROG##*/}" |
348 | + |
349 | + inst_multiple ip arping $_dhcp_prog_name sed |
350 | + inst_multiple ifconfig route |
351 | inst_multiple -o ping ping6 |
352 | inst_multiple -o brctl |
353 | inst_multiple -o teamd teamdctl teamnl |
354 | inst_simple /etc/libnl/classid |
355 | inst_script "$moddir/ifup.sh" "/sbin/ifup" |
356 | inst_script "$moddir/netroot.sh" "/sbin/netroot" |
357 | - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" |
358 | inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh" |
359 | - inst_simple -H "/etc/dhclient.conf" |
360 | - cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf" |
361 | inst_hook pre-udev 50 "$moddir/ifname-genrules.sh" |
362 | inst_hook pre-udev 60 "$moddir/net-genrules.sh" |
363 | inst_hook cmdline 91 "$moddir/dhcp-root.sh" |
364 | @@ -44,7 +48,30 @@ |
365 | inst_hook cmdline 97 "$moddir/parse-bridge.sh" |
366 | inst_hook cmdline 98 "$moddir/parse-ip-opts.sh" |
367 | inst_hook cmdline 99 "$moddir/parse-ifname.sh" |
368 | - inst_hook cleanup 10 "$moddir/kill-dhclient.sh" |
369 | + case $_dhcp_prog_name in |
370 | + dhclient) |
371 | + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" |
372 | + inst_simple -H "/etc/dhclient.conf" |
373 | + cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf" |
374 | + inst_hook cleanup 10 "$moddir/kill-dhclient.sh" |
375 | + ;; |
376 | + |
377 | + udhcpc) |
378 | + inst_script "$moddir/udhcpc-script.sh" "/usr/share/udhcpc/default.script" |
379 | + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh" |
380 | + ;; |
381 | + |
382 | + dhcpcd) |
383 | + inst_simple "/etc/dhcpcd.conf" |
384 | + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks |
385 | + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do |
386 | + inst_simple -o $_file |
387 | + done |
388 | + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot" |
389 | + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh" |
390 | + ;; |
391 | + esac |
392 | + inst_simple /etc/conf.d/network |
393 | |
394 | _arch=$(uname -m) |
395 | |
396 | diff -Naur dracut-044/modules.d/40network/net-lib.sh dracut-044-magellan/modules.d/40network/net-lib.sh |
397 | --- dracut-044/modules.d/40network/net-lib.sh 2015-11-25 14:22:28.000000000 +0100 |
398 | +++ dracut-044-magellan/modules.d/40network/net-lib.sh 2015-11-30 11:36:40.217220446 +0100 |
399 | @@ -118,6 +118,8 @@ |
400 | [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname |
401 | [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
402 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts |
403 | + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts |
404 | + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts |
405 | # set up resolv.conf |
406 | [ -e /tmp/net.$netif.resolv.conf ] && \ |
407 | cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf |
408 | @@ -189,6 +191,12 @@ |
409 | for f in /tmp/dhclient.$i.*; do |
410 | [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.} |
411 | done |
412 | + for f in /tmp/udhcpc.$i.*; do |
413 | + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/udhcpc.} |
414 | + done |
415 | + for f in /tmp/dhcpcd.$i.*; do |
416 | + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhcpcd.} |
417 | + done |
418 | done |
419 | echo $IFACES > /tmp/.net.ifaces.new |
420 | mv /tmp/.net.ifaces.new /tmp/net.ifaces |
421 | diff -Naur dracut-044/modules.d/40network/udhcpc-script.sh dracut-044-magellan/modules.d/40network/udhcpc-script.sh |
422 | --- dracut-044/modules.d/40network/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100 |
423 | +++ dracut-044-magellan/modules.d/40network/udhcpc-script.sh 2015-11-30 11:40:04.848639915 +0100 |
424 | @@ -0,0 +1,102 @@ |
425 | +#!/bin/sh |
426 | + |
427 | +# global options passed by udhcpc |
428 | +# what to run |
429 | +# $1 - which command to run, possible are: bound|deconfig|nak|renew |
430 | +# router - routers address |
431 | +# subnet - the subnet |
432 | +# dhcptype - type of dhcp |
433 | +# interface - which iface gets configured |
434 | +# serverid - ip of the dhcd server |
435 | +# dns - dns to use |
436 | +# ip - ip-address to use |
437 | +# lease - lease time of a dhcp configuration |
438 | +# mask - network mask to use |
439 | + |
440 | +PATH=/usr/sbin:/usr/bin:/sbin:/bin |
441 | + |
442 | +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
443 | +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh |
444 | + |
445 | +# We already need a set netif here |
446 | +netif="${interface}" |
447 | + |
448 | +# Huh? Interface configured? |
449 | +[ -f "/tmp/net.$netif.up" ] && exit 0 |
450 | + |
451 | +# renew dhcp leases |
452 | +bound() |
453 | +{ |
454 | + local RESOLV_CONF="/etc/resolv.conf" |
455 | + local BROADCAST |
456 | + local NETMASK |
457 | + local i |
458 | + |
459 | + [[ -n ${broadcast} ]] && BROADCAST="broadcast ${broadcast}" |
460 | + [[ -n ${subnet} ]] && NETMASK="netmask ${subnet}" |
461 | + |
462 | + /sbin/ifconfig ${interface} ${ip} ${BROADCAST} ${NETMASK} |
463 | + |
464 | + if [ -n "${router}" ] |
465 | + then |
466 | + echo "deleting routers" |
467 | + while /sbin/route del default gw 0.0.0.0 dev ${interface} |
468 | + do : |
469 | + done |
470 | + |
471 | + metric=0 |
472 | + for i in ${router} |
473 | + do |
474 | + /sbin/route add default gw ${i} dev ${interface} metric $((metric++)) |
475 | + done |
476 | + fi |
477 | + |
478 | + echo -n > ${RESOLV_CONF} |
479 | + [[ -n ${domain} ]] && echo "domain ${domain}" >> ${RESOLV_CONF} |
480 | + for i in ${dns} |
481 | + do |
482 | + echo adding dns ${i} |
483 | + echo "nameserver ${i}" >> ${RESOLV_CONF} |
484 | + done |
485 | + |
486 | + set | while read line; do |
487 | + [ "${line#new_}" = "$line" ] && continue |
488 | + echo "$line" |
489 | + done >/tmp/udhcpc.$netif.dhcpopts |
490 | + |
491 | + { |
492 | + echo '. /lib/net-lib.sh' |
493 | + echo "setup_net $netif" |
494 | + echo "source_hook initqueue/online $netif" |
495 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
496 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
497 | + } > $hookdir/initqueue/setup_net_$netif.sh |
498 | + |
499 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh |
500 | + >/tmp/net.$netif.up |
501 | +} |
502 | + |
503 | +renew() |
504 | +{ |
505 | + # same as bound() |
506 | + bound |
507 | +} |
508 | + |
509 | +deconfig() |
510 | +{ |
511 | + /sbin/ifconfig ${interface} 0.0.0.0 |
512 | +} |
513 | + |
514 | +# what to do if a dhcp request failed |
515 | +nak() |
516 | +{ |
517 | + echo "Received a NAK: ${message}" |
518 | +} |
519 | + |
520 | + |
521 | +case $1 in |
522 | + bound) bound ;; |
523 | + renew) renew ;; |
524 | + deconfig) deconfig ;; |
525 | + nak) nak ;; |
526 | +esac |