Magellan Linux

Contents of /trunk/dracut/patches/dracut-048-network-support-udhcpc-dhcpcd.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3218 - (show annotations) (download)
Thu Aug 23 12:13:01 2018 UTC (5 years, 8 months ago) by niro
File size: 28921 byte(s)
-reworked for dracut-048
1 diff -Naur dracut-048/modules.d/40network/dhcpcd-script.sh dracut-048-network/modules.d/40network/dhcpcd-script.sh
2 --- dracut-048/modules.d/40network/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100
3 +++ dracut-048-network/modules.d/40network/dhcpcd-script.sh 2018-08-23 14:01:42.540155544 +0200
4 @@ -0,0 +1,261 @@
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 +
56 + echo "$gw" | {
57 + IFS=' ' read -r main_gw other_gw
58 + echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw
59 + if [ -n "$other_gw" ] ; then
60 + for g in $other_gw; do
61 + echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw
62 + done
63 + fi
64 + }
65 + fi
66 +
67 + if getargbool 1 rd.peerdns; then
68 + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
69 + if [ -n "$namesrv" ] ; then
70 + for s in $namesrv; do
71 + echo nameserver $s
72 + done
73 + fi >> /tmp/net.$netif.resolv.conf
74 + fi
75 + # Note: hostname can be fqdn OR short hostname, so chop off any
76 + # trailing domain name and explicity add any domain if set.
77 + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
78 +}
79 +
80 +setup_interface6() {
81 + domain=$new_domain_name
82 + search=$(printf -- "$new_domain_search")
83 + namesrv=$new_domain_name_servers
84 + hostname=$new_host_name
85 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
86 + [ -n "$new_max_life" ] && lease_time=$new_max_life
87 + preferred_lft=$lease_time
88 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
89 +
90 + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
91 +
92 + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
93 + dev ${netif} scope global \
94 + ${lease_time:+valid_lft $lease_time} \
95 + ${preferred_lft:+preferred_lft ${preferred_lft}}
96 +
97 + if getargbool 1 rd.peerdns; then
98 + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
99 + if [ -n "$namesrv" ] ; then
100 + for s in $namesrv; do
101 + echo nameserver $s
102 + done
103 + fi >> /tmp/net.$netif.resolv.conf
104 + fi
105 +
106 + # Note: hostname can be fqdn OR short hostname, so chop off any
107 + # trailing domain name and explicity add any domain if set.
108 + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
109 +}
110 +
111 +parse_option_121() {
112 + while [ $# -ne 0 ]; do
113 + mask="$1"
114 + shift
115 +
116 + # Is the destination a multicast group?
117 + if [ $1 -ge 224 -a $1 -lt 240 ]; then
118 + multicast=1
119 + else
120 + multicast=0
121 + fi
122 +
123 + # Parse the arguments into a CIDR net/mask string
124 + if [ $mask -gt 24 ]; then
125 + destination="$1.$2.$3.$4/$mask"
126 + shift; shift; shift; shift
127 + elif [ $mask -gt 16 ]; then
128 + destination="$1.$2.$3.0/$mask"
129 + shift; shift; shift
130 + elif [ $mask -gt 8 ]; then
131 + destination="$1.$2.0.0/$mask"
132 + shift; shift
133 + else
134 + destination="$1.0.0.0/$mask"
135 + shift
136 + fi
137 +
138 + # Read the gateway
139 + gateway="$1.$2.$3.$4"
140 + shift; shift; shift; shift
141 +
142 + # Multicast routing on Linux
143 + # - If you set a next-hop address for a multicast group, this breaks with Cisco switches
144 + # - If you simply leave it link-local and attach it to an interface, it works fine.
145 + if [ $multicast -eq 1 ]; then
146 + temp_result="$destination dev $interface"
147 + else
148 + temp_result="$destination via $gateway dev $interface"
149 + fi
150 +
151 + echo "/sbin/ip route add $temp_result"
152 + done
153 +}
154 +
155 +
156 +case $reason in
157 + PREINIT)
158 + echo "dhcp: PREINIT $netif up"
159 + linkup $netif
160 + ;;
161 +
162 + PREINIT6)
163 + echo "dhcp: PREINIT6 $netif up"
164 + linkup $netif
165 + wait_for_ipv6_dad_link $netif
166 + ;;
167 +
168 + BOUND)
169 + echo "dhcp: BOND setting $netif"
170 + unset layer2
171 + if [ -f /sys/class/net/$netif/device/layer2 ]; then
172 + read layer2 < /sys/class/net/$netif/device/layer2
173 + fi
174 + if [ "$layer2" != "0" ]; then
175 + if command -v arping2 >/dev/null; then
176 + if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address ; then
177 + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
178 + exit 1
179 + fi
180 + else
181 + if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then
182 + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
183 + exit 1
184 + fi
185 + fi
186 + fi
187 + unset layer2
188 + setup_interface
189 + set | while read line || [ -n "$line" ]; do
190 + [ "${line#new_}" = "$line" ] && continue
191 + echo "$line"
192 + done >/tmp/dhcpcd.$netif.dhcpopts
193 +
194 + {
195 + echo '. /lib/net-lib.sh'
196 + echo "setup_net $netif"
197 + if [ -n "$new_classless_static_routes" ]; then
198 + OLDIFS="$IFS"
199 + IFS=".$IFS"
200 + parse_option_121 $new_classless_static_routes
201 + IFS="$OLDIFS"
202 + fi
203 + echo "source_hook initqueue/online $netif"
204 + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
205 + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
206 + } > $hookdir/initqueue/setup_net_$netif.sh
207 +
208 + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh
209 + >/tmp/net.$netif.up
210 + if [ -e /sys/class/net/${netif}/address ]; then
211 + > /tmp/net.$(cat /sys/class/net/${netif}/address).up
212 + fi
213 +
214 + ;;
215 +
216 + RENEW|REBIND)
217 + unset lease_time
218 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
219 + [ -n "$new_max_life" ] && lease_time=$new_max_life
220 + preferred_lft=$lease_time
221 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
222 + ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \
223 + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
224 + >/dev/null 2>&1
225 + ;;
226 +
227 + BOUND6)
228 + echo "dhcp: BOND6 setting $netif"
229 + setup_interface6
230 +
231 + set | while read line || [ -n "$line" ]; do
232 + [ "${line#new_}" = "$line" ] && continue
233 + echo "$line"
234 + done >/tmp/dhcpcd.$netif.dhcpopts
235 +
236 + {
237 + echo '. /lib/net-lib.sh'
238 + echo "setup_net $netif"
239 + echo "source_hook initqueue/online $netif"
240 + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
241 + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
242 + } > $hookdir/initqueue/setup_net_$netif.sh
243 +
244 + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh
245 + >/tmp/net.$netif.up
246 + if [ -e /sys/class/net/${netif}/address ]; then
247 + > /tmp/net.$(cat /sys/class/net/${netif}/address).up
248 + fi
249 + ;;
250 +
251 + RENEW6|REBIND6)
252 + unset lease_time
253 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
254 + [ -n "$new_max_life" ] && lease_time=$new_max_life
255 + preferred_lft=$lease_time
256 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
257 + ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \
258 + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
259 + >/dev/null 2>&1
260 + ;;
261 +
262 + *) echo "dhcp: $reason";;
263 +esac
264 +
265 +exit 0
266 diff -Naur dracut-048/modules.d/40network/ifup.sh dracut-048-network/modules.d/40network/ifup.sh
267 --- dracut-048/modules.d/40network/ifup.sh 2018-07-06 10:37:51.000000000 +0200
268 +++ dracut-048-network/modules.d/40network/ifup.sh 2018-08-23 13:58:30.450793079 +0200
269 @@ -10,6 +10,23 @@
270 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
271 type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
272
273 +# load magellan settings
274 +[ -f /etc/conf.d/network ] && . /etc/conf.d/network
275 +# some sane defaults
276 +if [[ -n $DEFAULT_DHCP_PROG ]]
277 +then
278 + DHCP_PROG="$DEFAULT_DHCP_PROG"
279 +else
280 + DHCP_PROG="/sbin/dhcpcd"
281 +fi
282 +if [[ -n $DEFAULT_DHCP_START ]]
283 +then
284 + DHCP_START="$DEFAULT_DHCP_START"
285 +else
286 + DHCP_START="-t 10"
287 +fi
288 +DHCP_PROG_NAME="${DHCP_PROG##*/}"
289 +
290 # Huh? No $1?
291 [ -z "$1" ] && exit 1
292
293 @@ -25,6 +42,9 @@
294
295 # Run dhclient
296 do_dhcp() {
297 + local opts
298 + local timeoutswitch
299 +
300 # dhclient-script will mark the netif up and generate the online
301 # event for nfsroot
302 # XXX add -V vendor class and option parsing per kernel
303 @@ -41,20 +61,37 @@
304 return 1
305 fi
306
307 + case $DHCP_PROG_NAME in
308 + dhclient)
309 + opts="$@ -1 -q"
310 + opts+=" -cf /etc/dhclient.conf"
311 + opts+=" -pf /tmp/$DHCP_PROG_NAME.$netif.pid"
312 + opts+=" -lf /tmp/$DHCP_PROG_NAME.$netif.lease"
313 + timeoutswitch="-timeout"
314 + ;;
315 +
316 + dhcpcd)
317 + opts="$@ -q"
318 + timeoutswitch="--timeout"
319 + ;;
320 +
321 + udhcpc)
322 + opts="-q"
323 + opts+=" -p /tmp/$DHCP_PROG_NAME.$netif.pid"
324 + timeoutswitch="--timeout"
325 + ;;
326 + esac
327 +
328 while [ $_COUNT -lt $_DHCPRETRY ]; do
329 - info "Starting dhcp for interface $netif"
330 - dhclient "$@" \
331 - ${_timeout:+-timeout $_timeout} \
332 - -q \
333 - -cf /etc/dhclient.conf \
334 - -pf /tmp/dhclient.$netif.pid \
335 - -lf /tmp/dhclient.$netif.lease \
336 - $netif \
337 + info "Starting dhcp ($DHCP_PROG_NAME) for interface $netif"
338 + $DHCP_PROG $opts \
339 + ${_timeout:+$timeoutswitch $_timeout} \
340 + $DHCP_START $netif \
341 && return 0
342 _COUNT=$(($_COUNT+1))
343 [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
344 done
345 - warn "dhcp for interface $netif failed"
346 + warn "dhcp ($DHCP_PROG_NAME) for interface $netif failed"
347 return 1
348 }
349
350 diff -Naur dracut-048/modules.d/40network/kill-dhcpcd.sh dracut-048-network/modules.d/40network/kill-dhcpcd.sh
351 --- dracut-048/modules.d/40network/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100
352 +++ dracut-048-network/modules.d/40network/kill-dhcpcd.sh 2018-08-23 13:58:30.451793065 +0200
353 @@ -0,0 +1,15 @@
354 +#!/bin/sh
355 +
356 +for f in /tmp/dhcpcd.*.pid; do
357 + [ -e $f ] || continue
358 + read PID < $f;
359 + kill $PID >/dev/null 2>&1
360 +done
361 +
362 +sleep 0.1
363 +
364 +for f in /tmp/dhcpcd.*.pid; do
365 + [ -e $f ] || continue
366 + read PID < $f;
367 + kill -9 $PID >/dev/null 2>&1
368 +done
369 diff -Naur dracut-048/modules.d/40network/kill-udhcpc.sh dracut-048-network/modules.d/40network/kill-udhcpc.sh
370 --- dracut-048/modules.d/40network/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100
371 +++ dracut-048-network/modules.d/40network/kill-udhcpc.sh 2018-08-23 13:58:30.451793065 +0200
372 @@ -0,0 +1,15 @@
373 +#!/bin/sh
374 +
375 +for f in /tmp/udhcpc.*.pid; do
376 + [ -e $f ] || continue
377 + read PID < $f;
378 + kill $PID >/dev/null 2>&1
379 +done
380 +
381 +sleep 0.1
382 +
383 +for f in /tmp/udhcpc.*.pid; do
384 + [ -e $f ] || continue
385 + read PID < $f;
386 + kill -9 $PID >/dev/null 2>&1
387 +done
388 diff -Naur dracut-048/modules.d/40network/module-setup.sh dracut-048-network/modules.d/40network/module-setup.sh
389 --- dracut-048/modules.d/40network/module-setup.sh 2018-07-06 10:37:51.000000000 +0200
390 +++ dracut-048-network/modules.d/40network/module-setup.sh 2018-08-23 13:58:30.451793065 +0200
391 @@ -3,8 +3,9 @@
392 # called by dracut
393 check() {
394 local _program
395 + . /etc/conf.d/network
396
397 - require_binaries ip dhclient sed awk grep || return 1
398 + require_binaries ip ifconfig route $DEFAULT_DHCP_PROG sed awk grep || return 1
399 require_any_binary arping arping2 || return 1
400
401 return 255
402 @@ -24,7 +25,13 @@
403 # called by dracut
404 install() {
405 local _arch _i _dir
406 - inst_multiple ip dhclient sed awk grep
407 + local _dhcp_prog_name
408 + local _file
409 + . /etc/conf.d/network
410 + _dhcp_prog_name="${DEFAULT_DHCP_PROG##*/}"
411 +
412 + inst_multiple ip $_dhcp_prog_name sed awk grep
413 + inst_multiple ifconfig route
414
415 inst_multiple -o arping arping2
416 strstr "$(arping 2>&1)" "ARPing 2" && mv "$initdir/bin/arping" "$initdir/bin/arping2"
417 @@ -34,10 +41,7 @@
418 inst_simple /etc/libnl/classid
419 inst_script "$moddir/ifup.sh" "/sbin/ifup"
420 inst_script "$moddir/netroot.sh" "/sbin/netroot"
421 - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
422 inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh"
423 - inst_simple -H "/etc/dhclient.conf"
424 - cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf"
425 inst_hook pre-udev 50 "$moddir/ifname-genrules.sh"
426 inst_hook pre-udev 60 "$moddir/net-genrules.sh"
427 inst_hook cmdline 91 "$moddir/dhcp-root.sh"
428 @@ -48,7 +52,30 @@
429 inst_hook cmdline 97 "$moddir/parse-bridge.sh"
430 inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
431 inst_hook cmdline 99 "$moddir/parse-ifname.sh"
432 - inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
433 + case $_dhcp_prog_name in
434 + dhclient)
435 + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
436 + inst_simple -H "/etc/dhclient.conf"
437 + cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf"
438 + inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
439 + ;;
440 +
441 + udhcpc)
442 + inst_script "$moddir/udhcpc-script.sh" "/usr/share/udhcpc/default.script"
443 + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh"
444 + ;;
445 +
446 + dhcpcd)
447 + inst_simple "/etc/dhcpcd.conf"
448 + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks
449 + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do
450 + inst_simple -o $_file
451 + done
452 + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot"
453 + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh"
454 + ;;
455 + esac
456 + inst_simple /etc/conf.d/network
457
458 # install all config files for teaming
459 unset TEAM_MASTER
460 diff -Naur dracut-048/modules.d/40network/net-lib.sh dracut-048-network/modules.d/40network/net-lib.sh
461 --- dracut-048/modules.d/40network/net-lib.sh 2018-07-06 10:37:51.000000000 +0200
462 +++ dracut-048-network/modules.d/40network/net-lib.sh 2018-08-23 13:58:30.452793051 +0200
463 @@ -120,6 +120,8 @@
464 [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname
465 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
466 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
467 + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts
468 + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts
469 # set up resolv.conf
470 [ -e /tmp/net.$netif.resolv.conf ] && \
471 awk '!array[$0]++' /tmp/net.$netif.resolv.conf > /etc/resolv.conf
472 @@ -196,6 +198,12 @@
473 for f in /tmp/dhclient.$i.*; do
474 [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.}
475 done
476 + for f in /tmp/udhcpc.$i.*; do
477 + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/udhcpc.}
478 + done
479 + for f in /tmp/dhcpcd.$i.*; do
480 + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhcpcd.}
481 + done
482 done
483 echo $IFACES > /tmp/.net.ifaces.new
484 mv /tmp/.net.ifaces.new /tmp/net.ifaces
485 diff -Naur dracut-048/modules.d/40network/netroot.sh dracut-048-network/modules.d/40network/netroot.sh
486 --- dracut-048/modules.d/40network/netroot.sh 2018-07-06 10:37:51.000000000 +0200
487 +++ dracut-048-network/modules.d/40network/netroot.sh 2018-08-23 13:58:30.452793051 +0200
488 @@ -41,6 +41,8 @@
489 if getarg "root=dhcp" || getarg "netroot=dhcp" || getarg "root=dhcp6" || getarg "netroot=dhcp6"; then
490 # Load dhcp options
491 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
492 + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts
493 + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts
494
495 # If we have a specific bootdev with no dhcpoptions or empty root-path,
496 # we die. Otherwise we just warn
497 diff -Naur dracut-048/modules.d/40network/udhcpc-script.sh dracut-048-network/modules.d/40network/udhcpc-script.sh
498 --- dracut-048/modules.d/40network/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100
499 +++ dracut-048-network/modules.d/40network/udhcpc-script.sh 2018-08-23 14:04:28.764873152 +0200
500 @@ -0,0 +1,281 @@
501 +#!/bin/sh
502 +
503 +PATH=/usr/sbin:/usr/bin:/sbin:/bin
504 +
505 +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
506 +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
507 +
508 +# We already need a set netif here
509 +netif=$interface
510 +
511 +# setup udhcp environment variables
512 +reason=$1
513 +new_ip_address="$ip"
514 +new_interface_mtu="$mtu"
515 +new_subnet_mask="$mask"
516 +new_broadcast_address="$broadcast"
517 +new_routers="$router"
518 +new_domain_name="$domain"
519 +new_domain_search=""
520 +new_domain_name_servers="$dns"
521 +new_host_name="$hostname"
522 +new_dhcp_lease_time="$lease"
523 +new_max_life=""
524 +new_preferred_life=""
525 +
526 +setup_interface() {
527 + ip=$new_ip_address
528 + mtu=$new_interface_mtu
529 + mask=$new_subnet_mask
530 + bcast=$new_broadcast_address
531 + gw=${new_routers%%,*}
532 + domain=$new_domain_name
533 + search=$(printf -- "$new_domain_search")
534 + namesrv=$new_domain_name_servers
535 + hostname=$new_host_name
536 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
537 + [ -n "$new_max_life" ] && lease_time=$new_max_life
538 + preferred_lft=$lease_time
539 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
540 +
541 + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
542 +
543 + # Taken from debian dhclient-script:
544 + # The 576 MTU is only used for X.25 and dialup connections
545 + # where the admin wants low latency. Such a low MTU can cause
546 + # problems with UDP traffic, among other things. As such,
547 + # disallow MTUs from 576 and below by default, so that broken
548 + # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
549 + if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then
550 + if ! ip link set $netif mtu $mtu ; then
551 + ip link set $netif down
552 + ip link set $netif mtu $mtu
553 + linkup $netif
554 + fi
555 + fi
556 +
557 +# lease time stuff not compatible with busybox ip command
558 +# ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif \
559 +# ${lease_time:+valid_lft $lease_time} \
560 +# ${preferred_lft:+preferred_lft ${preferred_lft}}
561 + ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif
562 +
563 + if [ -n "$gw" ] ; then
564 + if [ "$mask" = "255.255.255.255" ] ; then
565 + # point-to-point connection => set explicit route to gateway
566 + echo ip route add $gw dev $netif > /tmp/net.$netif.gw
567 + fi
568 +
569 + echo "$gw" | {
570 + IFS=' ' read -r main_gw other_gw
571 + echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw
572 + if [ -n "$other_gw" ] ; then
573 + for g in $other_gw; do
574 + echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw
575 + done
576 + fi
577 + }
578 + fi
579 +
580 + if getargbool 1 rd.peerdns; then
581 + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
582 + if [ -n "$namesrv" ] ; then
583 + for s in $namesrv; do
584 + echo nameserver $s
585 + done
586 + fi >> /tmp/net.$netif.resolv.conf
587 + fi
588 + # Note: hostname can be fqdn OR short hostname, so chop off any
589 + # trailing domain name and explicity add any domain if set.
590 + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
591 +}
592 +
593 +setup_interface6() {
594 + domain=$new_domain_name
595 + search=$(printf -- "$new_domain_search")
596 + namesrv=$new_domain_name_servers
597 + hostname=$new_host_name
598 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
599 + [ -n "$new_max_life" ] && lease_time=$new_max_life
600 + preferred_lft=$lease_time
601 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
602 +
603 + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
604 +
605 +# lease time stuff not compatible with busybox ip command
606 +# ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
607 +# dev ${netif} scope global \
608 +# ${lease_time:+valid_lft $lease_time} \
609 +# ${preferred_lft:+preferred_lft ${preferred_lft}}
610 + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
611 + dev ${netif} scope global
612 +
613 + if getargbool 1 rd.peerdns; then
614 + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
615 + if [ -n "$namesrv" ] ; then
616 + for s in $namesrv; do
617 + echo nameserver $s
618 + done
619 + fi >> /tmp/net.$netif.resolv.conf
620 + fi
621 +
622 + # Note: hostname can be fqdn OR short hostname, so chop off any
623 + # trailing domain name and explicity add any domain if set.
624 + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
625 +}
626 +
627 +parse_option_121() {
628 + while [ $# -ne 0 ]; do
629 + mask="$1"
630 + shift
631 +
632 + # Is the destination a multicast group?
633 + if [ $1 -ge 224 -a $1 -lt 240 ]; then
634 + multicast=1
635 + else
636 + multicast=0
637 + fi
638 +
639 + # Parse the arguments into a CIDR net/mask string
640 + if [ $mask -gt 24 ]; then
641 + destination="$1.$2.$3.$4/$mask"
642 + shift; shift; shift; shift
643 + elif [ $mask -gt 16 ]; then
644 + destination="$1.$2.$3.0/$mask"
645 + shift; shift; shift
646 + elif [ $mask -gt 8 ]; then
647 + destination="$1.$2.0.0/$mask"
648 + shift; shift
649 + else
650 + destination="$1.0.0.0/$mask"
651 + shift
652 + fi
653 +
654 + # Read the gateway
655 + gateway="$1.$2.$3.$4"
656 + shift; shift; shift; shift
657 +
658 + # Multicast routing on Linux
659 + # - If you set a next-hop address for a multicast group, this breaks with Cisco switches
660 + # - If you simply leave it link-local and attach it to an interface, it works fine.
661 + if [ $multicast -eq 1 ]; then
662 + temp_result="$destination dev $interface"
663 + else
664 + temp_result="$destination via $gateway dev $interface"
665 + fi
666 +
667 + echo "/sbin/ip route add $temp_result"
668 + done
669 +}
670 +
671 +
672 +case $reason in
673 + PREINIT|preinit)
674 + echo "dhcp: PREINIT $netif up"
675 + linkup $netif
676 + ;;
677 +
678 + PREINIT6|preinit6)
679 + echo "dhcp: PREINIT6 $netif up"
680 + linkup $netif
681 + wait_for_ipv6_dad_link $netif
682 + ;;
683 +
684 + BOUND|bound)
685 + echo "dhcp: BOND setting $netif"
686 + unset layer2
687 + if [ -f /sys/class/net/$netif/device/layer2 ]; then
688 + read layer2 < /sys/class/net/$netif/device/layer2
689 + fi
690 + if [ "$layer2" != "0" ]; then
691 + if command -v arping2 >/dev/null; then
692 + if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address ; then
693 + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
694 + exit 1
695 + fi
696 + else
697 + if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then
698 + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
699 + exit 1
700 + fi
701 + fi
702 + fi
703 + unset layer2
704 + setup_interface
705 + set | while read line || [ -n "$line" ]; do
706 + [ "${line#new_}" = "$line" ] && continue
707 + echo "$line"
708 + done >/tmp/udhcpc.$netif.dhcpopts
709 +
710 + {
711 + echo '. /lib/net-lib.sh'
712 + echo "setup_net $netif"
713 + if [ -n "$new_classless_static_routes" ]; then
714 + OLDIFS="$IFS"
715 + IFS=".$IFS"
716 + parse_option_121 $new_classless_static_routes
717 + IFS="$OLDIFS"
718 + fi
719 + echo "source_hook initqueue/online $netif"
720 + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
721 + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
722 + } > $hookdir/initqueue/setup_net_$netif.sh
723 +
724 + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh
725 + >/tmp/net.$netif.up
726 + if [ -e /sys/class/net/${netif}/address ]; then
727 + > /tmp/net.$(cat /sys/class/net/${netif}/address).up
728 + fi
729 +
730 + ;;
731 +
732 + RENEW|renew|REBIND|rebind)
733 + unset lease_time
734 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
735 + [ -n "$new_max_life" ] && lease_time=$new_max_life
736 + preferred_lft=$lease_time
737 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
738 + ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \
739 + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
740 + >/dev/null 2>&1
741 + ;;
742 +
743 + BOUND6|bound6)
744 + echo "dhcp: BOND6 setting $netif"
745 + setup_interface6
746 +
747 + set | while read line || [ -n "$line" ]; do
748 + [ "${line#new_}" = "$line" ] && continue
749 + echo "$line"
750 + done >/tmp/udhcpc.$netif.dhcpopts
751 +
752 + {
753 + echo '. /lib/net-lib.sh'
754 + echo "setup_net $netif"
755 + echo "source_hook initqueue/online $netif"
756 + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
757 + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
758 + } > $hookdir/initqueue/setup_net_$netif.sh
759 +
760 + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh
761 + >/tmp/net.$netif.up
762 + if [ -e /sys/class/net/${netif}/address ]; then
763 + > /tmp/net.$(cat /sys/class/net/${netif}/address).up
764 + fi
765 + ;;
766 +
767 + RENEW6|renew6|REBIND6|rebind6)
768 + unset lease_time
769 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
770 + [ -n "$new_max_life" ] && lease_time=$new_max_life
771 + preferred_lft=$lease_time
772 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
773 + ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \
774 + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
775 + >/dev/null 2>&1
776 + ;;
777 +
778 + *) echo "dhcp: $reason";;
779 +esac
780 +
781 +exit 0