Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3741 - (show annotations) (download)
Thu Jul 27 10:25:05 2023 UTC (9 months, 1 week ago) by niro
File size: 29601 byte(s)
-rediffed for dracut-059
1 diff -Naur dracut-059/modules.d/35network-legacy/dhcpcd-script.sh dracut-059-udhcpd/modules.d/35network-legacy/dhcpcd-script.sh
2 --- dracut-059/modules.d/35network-legacy/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100
3 +++ dracut-059-udhcpd/modules.d/35network-legacy/dhcpcd-script.sh 2023-07-27 11:45:45.296355868 +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-059/modules.d/35network-legacy/ifup.sh dracut-059-udhcpd/modules.d/35network-legacy/ifup.sh
267 --- dracut-059/modules.d/35network-legacy/ifup.sh 2022-12-24 17:49:27.000000000 +0100
268 +++ dracut-059-udhcpd/modules.d/35network-legacy/ifup.sh 2023-07-27 11:54:32.885363381 +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 @@ -54,6 +71,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 @@ -86,21 +106,37 @@
304 echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf
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 - -1 \
334 - -cf /etc/dhclient.conf \
335 - -pf "/tmp/dhclient.${netif}.pid" \
336 - -lf "/tmp/dhclient.${netif}.lease" \
337 - "$netif" \
338 + info "Starting dhcp (${DHCP_PROG_NAME}) for interface $netif"
339 + ${DHCP_PROG} ${opts} \
340 + ${_timeout:+${timeoutswitch} "$_timeout"} \
341 + ${DHCP_START} ${netif} \
342 && return 0
343 _COUNT=$((_COUNT + 1))
344 [ "$_COUNT" -lt "$_DHCPRETRY" ] && sleep 1
345 done
346 - warn "dhcp for interface $netif failed"
347 + warn "dhcp (${DHCP_PROG_NAME}) for interface ${netif} failed"
348 # nuke those files since we failed; we might retry dhcp again if it's e.g.
349 # `ip=dhcp,dhcp6` and we check for the PID file at the top
350 rm -f /tmp/dhclient."$netif".pid /tmp/dhclient."$netif".lease
351 diff -Naur dracut-059/modules.d/35network-legacy/kill-dhcpcd.sh dracut-059-udhcpd/modules.d/35network-legacy/kill-dhcpcd.sh
352 --- dracut-059/modules.d/35network-legacy/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100
353 +++ dracut-059-udhcpd/modules.d/35network-legacy/kill-dhcpcd.sh 2023-07-27 11:55:18.002800244 +0200
354 @@ -0,0 +1,16 @@
355 +#!/bin/sh
356 +
357 +for f in /tmp/dhcpcd.*.pid; do
358 + [ -e $f ] || continue
359 + read PID < $f;
360 + kill $PID >/dev/null 2>&1
361 +done
362 +
363 +sleep 0.1
364 +
365 +for f in /tmp/dhcpcd.*.pid; do
366 + [ -e $f ] || continue
367 + read PID < $f;
368 + kill -9 $PID >/dev/null 2>&1
369 +done
370 +
371 diff -Naur dracut-059/modules.d/35network-legacy/kill-udhcpc.sh dracut-059-udhcpd/modules.d/35network-legacy/kill-udhcpc.sh
372 --- dracut-059/modules.d/35network-legacy/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100
373 +++ dracut-059-udhcpd/modules.d/35network-legacy/kill-udhcpc.sh 2023-07-27 11:59:48.994092784 +0200
374 @@ -0,0 +1,15 @@
375 +#!/bin/sh
376 +
377 +for f in /tmp/udhcpc.*.pid; do
378 + [ -e $f ] || continue
379 + read PID < $f;
380 + kill $PID >/dev/null 2>&1
381 +done
382 +
383 +sleep 0.1
384 +
385 +for f in /tmp/udhcpc.*.pid; do
386 + [ -e $f ] || continue
387 + read PID < $f;
388 + kill -9 $PID >/dev/null 2>&1
389 +done
390 diff -Naur dracut-059/modules.d/35network-legacy/module-setup.sh dracut-059-udhcpd/modules.d/35network-legacy/module-setup.sh
391 --- dracut-059/modules.d/35network-legacy/module-setup.sh 2022-12-24 17:49:27.000000000 +0100
392 +++ dracut-059-udhcpd/modules.d/35network-legacy/module-setup.sh 2023-07-27 12:09:16.600483707 +0200
393 @@ -2,7 +2,9 @@
394
395 # called by dracut
396 check() {
397 - require_binaries ip dhclient sed awk grep pgrep tr expr || return 1
398 + . /etc/conf.d/network
399 +
400 + require_binaries ip ifconfig route $DEFAULT_DHCP_PROG sed awk grep pgrep tr expr || return 1
401 require_any_binary arping arping2 || return 1
402
403 return 255
404 @@ -21,6 +23,10 @@
405 # called by dracut
406 install() {
407 local _arch
408 + local _dhcp_prog_name
409 + local _file
410 + . /etc/conf.d/network
411 + _dhcp_prog_name="${DEFAULT_DHCP_PROG##*/}"
412
413 #Adding default link
414 if dracut_module_included "systemd"; then
415 @@ -28,7 +34,8 @@
416 [[ $hostonly ]] && inst_multiple -H -o "${systemdnetworkconfdir}/*.link"
417 fi
418
419 - inst_multiple ip dhclient sed awk grep pgrep tr expr
420 + inst_multiple ip $_dhcp_prog_name sed awk grep pgrep tr expr
421 + inst_multiple ifconfig route
422
423 inst_multiple -o arping arping2
424 strstr "$(arping 2>&1)" "ARPing 2" && mv "$initdir/bin/arping" "$initdir/bin/arping2"
425 @@ -37,10 +44,6 @@
426 inst_multiple -o teamd teamdctl teamnl
427 inst_simple /etc/libnl/classid
428 inst_script "$moddir/ifup.sh" "/sbin/ifup"
429 - inst_script "$moddir/dhcp-multi.sh" "/sbin/dhcp-multi.sh"
430 - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
431 - inst_simple -H "/etc/dhclient.conf"
432 - cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf"
433 inst_hook pre-udev 60 "$moddir/net-genrules.sh"
434 inst_hook cmdline 92 "$moddir/parse-ibft.sh"
435 inst_hook cmdline 95 "$moddir/parse-vlan.sh"
436 @@ -49,7 +52,32 @@
437 inst_hook cmdline 97 "$moddir/parse-bridge.sh"
438 inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
439 inst_hook cmdline 99 "$moddir/parse-ifname.sh"
440 - inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
441 +
442 + case $_dhcp_prog_name in
443 + dhclient)
444 + inst_script "$moddir/dhcp-multi.sh" "/sbin/dhcp-multi.sh"
445 + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
446 + inst_simple -H "/etc/dhclient.conf"
447 + cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf"
448 + inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
449 + ;;
450 +
451 + udhcpc)
452 + inst_script "$moddir/udhcpc-script.sh" "/usr/share/udhcpc/default.script"
453 + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh"
454 + ;;
455 +
456 + dhcpcd)
457 + inst_simple "/etc/dhcpcd.conf"
458 + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks
459 + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do
460 + inst_simple -o $_file
461 + done
462 + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot"
463 + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh"
464 + ;;
465 + esac
466 + inst_simple /etc/conf.d/network
467
468 # install all config files for teaming
469 unset TEAM_MASTER
470 diff -Naur dracut-059/modules.d/35network-legacy/udhcpc-script.sh dracut-059-udhcpd/modules.d/35network-legacy/udhcpc-script.sh
471 --- dracut-059/modules.d/35network-legacy/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100
472 +++ dracut-059-udhcpd/modules.d/35network-legacy/udhcpc-script.sh 2023-07-27 12:11:54.013191653 +0200
473 @@ -0,0 +1,282 @@
474 +#!/bin/sh
475 +
476 +PATH=/usr/sbin:/usr/bin:/sbin:/bin
477 +
478 +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
479 +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
480 +
481 +# We already need a set netif here
482 +netif=$interface
483 +
484 +# setup udhcp environment variables
485 +reason=$1
486 +new_ip_address="$ip"
487 +new_interface_mtu="$mtu"
488 +new_subnet_mask="$mask"
489 +new_broadcast_address="$broadcast"
490 +new_routers="$router"
491 +new_domain_name="$domain"
492 +new_domain_search=""
493 +new_domain_name_servers="$dns"
494 +new_host_name="$hostname"
495 +new_dhcp_lease_time="$lease"
496 +new_max_life=""
497 +new_preferred_life=""
498 +
499 +setup_interface() {
500 + ip=$new_ip_address
501 + mtu=$new_interface_mtu
502 + mask=$new_subnet_mask
503 + bcast=$new_broadcast_address
504 + gw=${new_routers%%,*}
505 + domain=$new_domain_name
506 + search=$(printf -- "$new_domain_search")
507 + namesrv=$new_domain_name_servers
508 + hostname=$new_host_name
509 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
510 + [ -n "$new_max_life" ] && lease_time=$new_max_life
511 + preferred_lft=$lease_time
512 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
513 +
514 + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
515 +
516 + # Taken from debian dhclient-script:
517 + # The 576 MTU is only used for X.25 and dialup connections
518 + # where the admin wants low latency. Such a low MTU can cause
519 + # problems with UDP traffic, among other things. As such,
520 + # disallow MTUs from 576 and below by default, so that broken
521 + # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
522 + if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then
523 + if ! ip link set $netif mtu $mtu ; then
524 + ip link set $netif down
525 + ip link set $netif mtu $mtu
526 + linkup $netif
527 + fi
528 + fi
529 +
530 +# lease time stuff not compatible with busybox ip command
531 +# ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif \
532 +# ${lease_time:+valid_lft $lease_time} \
533 +# ${preferred_lft:+preferred_lft ${preferred_lft}}
534 + ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif
535 +
536 + if [ -n "$gw" ] ; then
537 + if [ "$mask" = "255.255.255.255" ] ; then
538 + # point-to-point connection => set explicit route to gateway
539 + echo ip route add $gw dev $netif > /tmp/net.$netif.gw
540 + fi
541 +
542 + echo "$gw" | {
543 + IFS=' ' read -r main_gw other_gw
544 + echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw
545 + if [ -n "$other_gw" ] ; then
546 + for g in $other_gw; do
547 + echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw
548 + done
549 + fi
550 + }
551 + fi
552 +
553 + if getargbool 1 rd.peerdns; then
554 + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
555 + if [ -n "$namesrv" ] ; then
556 + for s in $namesrv; do
557 + echo nameserver $s
558 + done
559 + fi >> /tmp/net.$netif.resolv.conf
560 + fi
561 + # Note: hostname can be fqdn OR short hostname, so chop off any
562 + # trailing domain name and explicity add any domain if set.
563 + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
564 +}
565 +
566 +setup_interface6() {
567 + domain=$new_domain_name
568 + search=$(printf -- "$new_domain_search")
569 + namesrv=$new_domain_name_servers
570 + hostname=$new_host_name
571 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
572 + [ -n "$new_max_life" ] && lease_time=$new_max_life
573 + preferred_lft=$lease_time
574 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
575 +
576 + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
577 +
578 +# lease time stuff not compatible with busybox ip command
579 +# ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
580 +# dev ${netif} scope global \
581 +# ${lease_time:+valid_lft $lease_time} \
582 +# ${preferred_lft:+preferred_lft ${preferred_lft}}
583 + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
584 + dev ${netif} scope global
585 +
586 + if getargbool 1 rd.peerdns; then
587 + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
588 + if [ -n "$namesrv" ] ; then
589 + for s in $namesrv; do
590 + echo nameserver $s
591 + done
592 + fi >> /tmp/net.$netif.resolv.conf
593 + fi
594 +
595 + # Note: hostname can be fqdn OR short hostname, so chop off any
596 + # trailing domain name and explicity add any domain if set.
597 + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
598 +}
599 +
600 +parse_option_121() {
601 + while [ $# -ne 0 ]; do
602 + mask="$1"
603 + shift
604 +
605 + # Is the destination a multicast group?
606 + if [ $1 -ge 224 -a $1 -lt 240 ]; then
607 + multicast=1
608 + else
609 + multicast=0
610 + fi
611 +
612 + # Parse the arguments into a CIDR net/mask string
613 + if [ $mask -gt 24 ]; then
614 + destination="$1.$2.$3.$4/$mask"
615 + shift; shift; shift; shift
616 + elif [ $mask -gt 16 ]; then
617 + destination="$1.$2.$3.0/$mask"
618 + shift; shift; shift
619 + elif [ $mask -gt 8 ]; then
620 + destination="$1.$2.0.0/$mask"
621 + shift; shift
622 + else
623 + destination="$1.0.0.0/$mask"
624 + shift
625 + fi
626 +
627 + # Read the gateway
628 + gateway="$1.$2.$3.$4"
629 + shift; shift; shift; shift
630 +
631 + # Multicast routing on Linux
632 + # - If you set a next-hop address for a multicast group, this breaks with Cisco switches
633 + # - If you simply leave it link-local and attach it to an interface, it works fine.
634 + if [ $multicast -eq 1 ]; then
635 + temp_result="$destination dev $interface"
636 + else
637 + temp_result="$destination via $gateway dev $interface"
638 + fi
639 +
640 + echo "/sbin/ip route add $temp_result"
641 + done
642 +}
643 +
644 +
645 +case $reason in
646 + PREINIT|preinit)
647 + echo "dhcp: PREINIT $netif up"
648 + linkup $netif
649 + ;;
650 +
651 + PREINIT6|preinit6)
652 + echo "dhcp: PREINIT6 $netif up"
653 + linkup $netif
654 + wait_for_ipv6_dad_link $netif
655 + ;;
656 +
657 + BOUND|bound)
658 + echo "dhcp: BOND setting $netif"
659 + unset layer2
660 + if [ -f /sys/class/net/$netif/device/layer2 ]; then
661 + read layer2 < /sys/class/net/$netif/device/layer2
662 + fi
663 + if [ "$layer2" != "0" ]; then
664 + if command -v arping2 >/dev/null; then
665 + if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address ; then
666 + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
667 + exit 1
668 + fi
669 + else
670 + if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then
671 + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
672 + exit 1
673 + fi
674 + fi
675 + fi
676 + unset layer2
677 + setup_interface
678 + set | while read line || [ -n "$line" ]; do
679 + [ "${line#new_}" = "$line" ] && continue
680 + echo "$line"
681 + done >/tmp/udhcpc.$netif.dhcpopts
682 +
683 + {
684 + echo '. /lib/net-lib.sh'
685 + echo "setup_net $netif"
686 + if [ -n "$new_classless_static_routes" ]; then
687 + OLDIFS="$IFS"
688 + IFS=".$IFS"
689 + parse_option_121 $new_classless_static_routes
690 + IFS="$OLDIFS"
691 + fi
692 + echo "source_hook initqueue/online $netif"
693 + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
694 + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
695 + } > $hookdir/initqueue/setup_net_$netif.sh
696 +
697 + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh
698 + >/tmp/net.$netif.up
699 + if [ -e /sys/class/net/${netif}/address ]; then
700 + > /tmp/net.$(cat /sys/class/net/${netif}/address).up
701 + fi
702 +
703 + ;;
704 +
705 + RENEW|renew|REBIND|rebind)
706 + unset lease_time
707 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
708 + [ -n "$new_max_life" ] && lease_time=$new_max_life
709 + preferred_lft=$lease_time
710 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
711 + ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \
712 + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
713 + >/dev/null 2>&1
714 + ;;
715 +
716 + BOUND6|bound6)
717 + echo "dhcp: BOND6 setting $netif"
718 + setup_interface6
719 +
720 + set | while read line || [ -n "$line" ]; do
721 + [ "${line#new_}" = "$line" ] && continue
722 + echo "$line"
723 + done >/tmp/udhcpc.$netif.dhcpopts
724 +
725 + {
726 + echo '. /lib/net-lib.sh'
727 + echo "setup_net $netif"
728 + echo "source_hook initqueue/online $netif"
729 + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
730 + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
731 + } > $hookdir/initqueue/setup_net_$netif.sh
732 +
733 + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh
734 + >/tmp/net.$netif.up
735 + if [ -e /sys/class/net/${netif}/address ]; then
736 + > /tmp/net.$(cat /sys/class/net/${netif}/address).up
737 + fi
738 + ;;
739 +
740 + RENEW6|renew6|REBIND6|rebind6)
741 + unset lease_time
742 + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
743 + [ -n "$new_max_life" ] && lease_time=$new_max_life
744 + preferred_lft=$lease_time
745 + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
746 + ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \
747 + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
748 + >/dev/null 2>&1
749 + ;;
750 +
751 + *) echo "dhcp: $reason";;
752 +esac
753 +
754 +exit 0
755 +
756 diff -Naur dracut-059/modules.d/40network/net-lib.sh dracut-059-udhcpd/modules.d/40network/net-lib.sh
757 --- dracut-059/modules.d/40network/net-lib.sh 2022-12-24 17:49:27.000000000 +0100
758 +++ dracut-059-udhcpd/modules.d/40network/net-lib.sh 2023-07-27 12:15:48.930558389 +0200
759 @@ -137,6 +137,8 @@
760 [ -e /tmp/net."$netif".override ] && . /tmp/net."$netif".override
761 # shellcheck disable=SC1090
762 [ -e /tmp/dhclient."$netif".dhcpopts ] && . /tmp/dhclient."$netif".dhcpopts
763 + [ -e /tmp/udhcpc."$netif".dhcpopts ] && . /tmp/udhcpc."$netif".dhcpopts
764 + [ -e /tmp/dhcpcd."$netif".dhcpopts ] && . /tmp/dhcpcd."$netif".dhcpopts
765 # set up resolv.conf
766 [ -e /tmp/net."$netif".resolv.conf ] \
767 && awk '!array[$0]++' /tmp/net."$netif".resolv.conf > /etc/resolv.conf
768 @@ -215,6 +217,12 @@
769 for f in "/tmp/dhclient.$i."*; do
770 [ -f "$f" ] && cp -f "$f" /tmp/net."${f#/tmp/dhclient.}"
771 done
772 + for f in "/tmp/udhcpc.$i."*; do
773 + [ -f "$f" ] && cp -f "$f" /tmp/net."${f#/tmp/udhcpc.}"
774 + done
775 + for f in "/tmp/dhcpcd.$i."*; do
776 + [ -f "$f" ] && cp -f "$f" /tmp/net."${f#/tmp/dhcpcd.}"
777 + done
778 done
779 echo "$IFACES" > /tmp/.net.ifaces.new
780 mv /tmp/.net.ifaces.new /tmp/net.ifaces
781 diff -Naur dracut-059/modules.d/40network/netroot.sh dracut-059-udhcpd/modules.d/40network/netroot.sh
782 --- dracut-059/modules.d/40network/netroot.sh 2022-12-24 17:49:27.000000000 +0100
783 +++ dracut-059-udhcpd/modules.d/40network/netroot.sh 2023-07-27 12:16:37.778062865 +0200
784 @@ -42,6 +42,8 @@
785 # Load dhcp options
786 # shellcheck disable=SC1090
787 [ -e /tmp/dhclient."$netif".dhcpopts ] && . /tmp/dhclient."$netif".dhcpopts
788 + [ -e /tmp/dhcpcd."$netif".dhcpopts ] && . /tmp/dhcpcd."$netif".dhcpopts
789 + [ -e /tmp/udhcpc."$netif".dhcpopts ] && . /tmp/udhcpc."$netif".dhcpopts
790
791 # If we have a specific bootdev with no dhcpoptions or empty root-path,
792 # we die. Otherwise we just warn