Contents of /trunk/dracut/patches/dracut-049-network-support-udhcpc-dhcpcd.patch
Parent Directory | Revision Log
Revision 3367 -
(show annotations)
(download)
Mon Jul 8 14:01:12 2019 UTC (5 years, 2 months ago) by niro
File size: 29097 byte(s)
Mon Jul 8 14:01:12 2019 UTC (5 years, 2 months ago) by niro
File size: 29097 byte(s)
-reworked patches for dracut-049
1 | diff -Naur dracut-049/modules.d/35network-legacy/dhcpcd-script.sh dracut-049-magellan/modules.d/35network-legacy/dhcpcd-script.sh |
2 | --- dracut-049/modules.d/35network-legacy/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100 |
3 | +++ dracut-049-magellan/modules.d/35network-legacy/dhcpcd-script.sh 2019-07-08 15:17:38.571500923 +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-049/modules.d/35network-legacy/ifup.sh dracut-049-magellan/modules.d/35network-legacy/ifup.sh |
267 | --- dracut-049/modules.d/35network-legacy/ifup.sh 2019-07-08 15:16:35.043442886 +0200 |
268 | +++ dracut-049-magellan/modules.d/35network-legacy/ifup.sh 2019-07-08 15:22:42.613051277 +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 | @@ -47,20 +67,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 | - -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-049/modules.d/35network-legacy/kill-dhcpcd.sh dracut-049-magellan/modules.d/35network-legacy/kill-dhcpcd.sh |
351 | --- dracut-049/modules.d/35network-legacy/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100 |
352 | +++ dracut-049-magellan/modules.d/35network-legacy/kill-dhcpcd.sh 2019-07-08 15:23:14.497588970 +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-049/modules.d/35network-legacy/kill-udhcpc.sh dracut-049-magellan/modules.d/35network-legacy/kill-udhcpc.sh |
370 | --- dracut-049/modules.d/35network-legacy/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100 |
371 | +++ dracut-049-magellan/modules.d/35network-legacy/kill-udhcpc.sh 2019-07-08 15:23:21.682484882 +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-049/modules.d/35network-legacy/module-setup.sh dracut-049-magellan/modules.d/35network-legacy/module-setup.sh |
389 | --- dracut-049/modules.d/35network-legacy/module-setup.sh 2019-07-08 15:16:35.044442871 +0200 |
390 | +++ dracut-049-magellan/modules.d/35network-legacy/module-setup.sh 2019-07-08 15:26:27.103808548 +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 | @@ -23,7 +24,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 | @@ -32,9 +39,6 @@ |
418 | inst_multiple -o teamd teamdctl teamnl |
419 | inst_simple /etc/libnl/classid |
420 | inst_script "$moddir/ifup.sh" "/sbin/ifup" |
421 | - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" |
422 | - inst_simple -H "/etc/dhclient.conf" |
423 | - cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf" |
424 | inst_hook pre-udev 60 "$moddir/net-genrules.sh" |
425 | inst_hook cmdline 91 "$moddir/dhcp-root.sh" |
426 | inst_hook cmdline 92 "$moddir/parse-ibft.sh" |
427 | @@ -44,7 +48,30 @@ |
428 | inst_hook cmdline 97 "$moddir/parse-bridge.sh" |
429 | inst_hook cmdline 98 "$moddir/parse-ip-opts.sh" |
430 | inst_hook cmdline 99 "$moddir/parse-ifname.sh" |
431 | - inst_hook cleanup 10 "$moddir/kill-dhclient.sh" |
432 | + case $_dhcp_prog_name in |
433 | + dhclient) |
434 | + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" |
435 | + inst_simple -H "/etc/dhclient.conf" |
436 | + cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf" |
437 | + inst_hook cleanup 10 "$moddir/kill-dhclient.sh" |
438 | + ;; |
439 | + |
440 | + udhcpc) |
441 | + inst_script "$moddir/udhcpc-script.sh" "/usr/share/udhcpc/default.script" |
442 | + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh" |
443 | + ;; |
444 | + |
445 | + dhcpcd) |
446 | + inst_simple "/etc/dhcpcd.conf" |
447 | + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks |
448 | + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do |
449 | + inst_simple -o $_file |
450 | + done |
451 | + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot" |
452 | + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh" |
453 | + ;; |
454 | + esac |
455 | + inst_simple /etc/conf.d/network |
456 | |
457 | # install all config files for teaming |
458 | unset TEAM_MASTER |
459 | diff -Naur dracut-049/modules.d/35network-legacy/udhcpc-script.sh dracut-049-magellan/modules.d/35network-legacy/udhcpc-script.sh |
460 | --- dracut-049/modules.d/35network-legacy/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100 |
461 | +++ dracut-049-magellan/modules.d/35network-legacy/udhcpc-script.sh 2019-07-08 15:26:59.772338732 +0200 |
462 | @@ -0,0 +1,281 @@ |
463 | +#!/bin/sh |
464 | + |
465 | +PATH=/usr/sbin:/usr/bin:/sbin:/bin |
466 | + |
467 | +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
468 | +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh |
469 | + |
470 | +# We already need a set netif here |
471 | +netif=$interface |
472 | + |
473 | +# setup udhcp environment variables |
474 | +reason=$1 |
475 | +new_ip_address="$ip" |
476 | +new_interface_mtu="$mtu" |
477 | +new_subnet_mask="$mask" |
478 | +new_broadcast_address="$broadcast" |
479 | +new_routers="$router" |
480 | +new_domain_name="$domain" |
481 | +new_domain_search="" |
482 | +new_domain_name_servers="$dns" |
483 | +new_host_name="$hostname" |
484 | +new_dhcp_lease_time="$lease" |
485 | +new_max_life="" |
486 | +new_preferred_life="" |
487 | + |
488 | +setup_interface() { |
489 | + ip=$new_ip_address |
490 | + mtu=$new_interface_mtu |
491 | + mask=$new_subnet_mask |
492 | + bcast=$new_broadcast_address |
493 | + gw=${new_routers%%,*} |
494 | + domain=$new_domain_name |
495 | + search=$(printf -- "$new_domain_search") |
496 | + namesrv=$new_domain_name_servers |
497 | + hostname=$new_host_name |
498 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
499 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
500 | + preferred_lft=$lease_time |
501 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
502 | + |
503 | + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
504 | + |
505 | + # Taken from debian dhclient-script: |
506 | + # The 576 MTU is only used for X.25 and dialup connections |
507 | + # where the admin wants low latency. Such a low MTU can cause |
508 | + # problems with UDP traffic, among other things. As such, |
509 | + # disallow MTUs from 576 and below by default, so that broken |
510 | + # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). |
511 | + if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then |
512 | + if ! ip link set $netif mtu $mtu ; then |
513 | + ip link set $netif down |
514 | + ip link set $netif mtu $mtu |
515 | + linkup $netif |
516 | + fi |
517 | + fi |
518 | + |
519 | +# lease time stuff not compatible with busybox ip command |
520 | +# ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif \ |
521 | +# ${lease_time:+valid_lft $lease_time} \ |
522 | +# ${preferred_lft:+preferred_lft ${preferred_lft}} |
523 | + ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif |
524 | + |
525 | + if [ -n "$gw" ] ; then |
526 | + if [ "$mask" = "255.255.255.255" ] ; then |
527 | + # point-to-point connection => set explicit route to gateway |
528 | + echo ip route add $gw dev $netif > /tmp/net.$netif.gw |
529 | + fi |
530 | + |
531 | + echo "$gw" | { |
532 | + IFS=' ' read -r main_gw other_gw |
533 | + echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw |
534 | + if [ -n "$other_gw" ] ; then |
535 | + for g in $other_gw; do |
536 | + echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw |
537 | + done |
538 | + fi |
539 | + } |
540 | + fi |
541 | + |
542 | + if getargbool 1 rd.peerdns; then |
543 | + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf |
544 | + if [ -n "$namesrv" ] ; then |
545 | + for s in $namesrv; do |
546 | + echo nameserver $s |
547 | + done |
548 | + fi >> /tmp/net.$netif.resolv.conf |
549 | + fi |
550 | + # Note: hostname can be fqdn OR short hostname, so chop off any |
551 | + # trailing domain name and explicity add any domain if set. |
552 | + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname |
553 | +} |
554 | + |
555 | +setup_interface6() { |
556 | + domain=$new_domain_name |
557 | + search=$(printf -- "$new_domain_search") |
558 | + namesrv=$new_domain_name_servers |
559 | + hostname=$new_host_name |
560 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
561 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
562 | + preferred_lft=$lease_time |
563 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
564 | + |
565 | + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
566 | + |
567 | +# lease time stuff not compatible with busybox ip command |
568 | +# ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \ |
569 | +# dev ${netif} scope global \ |
570 | +# ${lease_time:+valid_lft $lease_time} \ |
571 | +# ${preferred_lft:+preferred_lft ${preferred_lft}} |
572 | + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \ |
573 | + dev ${netif} scope global |
574 | + |
575 | + if getargbool 1 rd.peerdns; then |
576 | + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf |
577 | + if [ -n "$namesrv" ] ; then |
578 | + for s in $namesrv; do |
579 | + echo nameserver $s |
580 | + done |
581 | + fi >> /tmp/net.$netif.resolv.conf |
582 | + fi |
583 | + |
584 | + # Note: hostname can be fqdn OR short hostname, so chop off any |
585 | + # trailing domain name and explicity add any domain if set. |
586 | + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname |
587 | +} |
588 | + |
589 | +parse_option_121() { |
590 | + while [ $# -ne 0 ]; do |
591 | + mask="$1" |
592 | + shift |
593 | + |
594 | + # Is the destination a multicast group? |
595 | + if [ $1 -ge 224 -a $1 -lt 240 ]; then |
596 | + multicast=1 |
597 | + else |
598 | + multicast=0 |
599 | + fi |
600 | + |
601 | + # Parse the arguments into a CIDR net/mask string |
602 | + if [ $mask -gt 24 ]; then |
603 | + destination="$1.$2.$3.$4/$mask" |
604 | + shift; shift; shift; shift |
605 | + elif [ $mask -gt 16 ]; then |
606 | + destination="$1.$2.$3.0/$mask" |
607 | + shift; shift; shift |
608 | + elif [ $mask -gt 8 ]; then |
609 | + destination="$1.$2.0.0/$mask" |
610 | + shift; shift |
611 | + else |
612 | + destination="$1.0.0.0/$mask" |
613 | + shift |
614 | + fi |
615 | + |
616 | + # Read the gateway |
617 | + gateway="$1.$2.$3.$4" |
618 | + shift; shift; shift; shift |
619 | + |
620 | + # Multicast routing on Linux |
621 | + # - If you set a next-hop address for a multicast group, this breaks with Cisco switches |
622 | + # - If you simply leave it link-local and attach it to an interface, it works fine. |
623 | + if [ $multicast -eq 1 ]; then |
624 | + temp_result="$destination dev $interface" |
625 | + else |
626 | + temp_result="$destination via $gateway dev $interface" |
627 | + fi |
628 | + |
629 | + echo "/sbin/ip route add $temp_result" |
630 | + done |
631 | +} |
632 | + |
633 | + |
634 | +case $reason in |
635 | + PREINIT|preinit) |
636 | + echo "dhcp: PREINIT $netif up" |
637 | + linkup $netif |
638 | + ;; |
639 | + |
640 | + PREINIT6|preinit6) |
641 | + echo "dhcp: PREINIT6 $netif up" |
642 | + linkup $netif |
643 | + wait_for_ipv6_dad_link $netif |
644 | + ;; |
645 | + |
646 | + BOUND|bound) |
647 | + echo "dhcp: BOND setting $netif" |
648 | + unset layer2 |
649 | + if [ -f /sys/class/net/$netif/device/layer2 ]; then |
650 | + read layer2 < /sys/class/net/$netif/device/layer2 |
651 | + fi |
652 | + if [ "$layer2" != "0" ]; then |
653 | + if command -v arping2 >/dev/null; then |
654 | + if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address ; then |
655 | + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" |
656 | + exit 1 |
657 | + fi |
658 | + else |
659 | + if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then |
660 | + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" |
661 | + exit 1 |
662 | + fi |
663 | + fi |
664 | + fi |
665 | + unset layer2 |
666 | + setup_interface |
667 | + set | while read line || [ -n "$line" ]; do |
668 | + [ "${line#new_}" = "$line" ] && continue |
669 | + echo "$line" |
670 | + done >/tmp/udhcpc.$netif.dhcpopts |
671 | + |
672 | + { |
673 | + echo '. /lib/net-lib.sh' |
674 | + echo "setup_net $netif" |
675 | + if [ -n "$new_classless_static_routes" ]; then |
676 | + OLDIFS="$IFS" |
677 | + IFS=".$IFS" |
678 | + parse_option_121 $new_classless_static_routes |
679 | + IFS="$OLDIFS" |
680 | + fi |
681 | + echo "source_hook initqueue/online $netif" |
682 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
683 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
684 | + } > $hookdir/initqueue/setup_net_$netif.sh |
685 | + |
686 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh |
687 | + >/tmp/net.$netif.up |
688 | + if [ -e /sys/class/net/${netif}/address ]; then |
689 | + > /tmp/net.$(cat /sys/class/net/${netif}/address).up |
690 | + fi |
691 | + |
692 | + ;; |
693 | + |
694 | + RENEW|renew|REBIND|rebind) |
695 | + unset lease_time |
696 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
697 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
698 | + preferred_lft=$lease_time |
699 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
700 | + ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \ |
701 | + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ |
702 | + >/dev/null 2>&1 |
703 | + ;; |
704 | + |
705 | + BOUND6|bound6) |
706 | + echo "dhcp: BOND6 setting $netif" |
707 | + setup_interface6 |
708 | + |
709 | + set | while read line || [ -n "$line" ]; do |
710 | + [ "${line#new_}" = "$line" ] && continue |
711 | + echo "$line" |
712 | + done >/tmp/udhcpc.$netif.dhcpopts |
713 | + |
714 | + { |
715 | + echo '. /lib/net-lib.sh' |
716 | + echo "setup_net $netif" |
717 | + echo "source_hook initqueue/online $netif" |
718 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
719 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
720 | + } > $hookdir/initqueue/setup_net_$netif.sh |
721 | + |
722 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh |
723 | + >/tmp/net.$netif.up |
724 | + if [ -e /sys/class/net/${netif}/address ]; then |
725 | + > /tmp/net.$(cat /sys/class/net/${netif}/address).up |
726 | + fi |
727 | + ;; |
728 | + |
729 | + RENEW6|renew6|REBIND6|rebind6) |
730 | + unset lease_time |
731 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
732 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
733 | + preferred_lft=$lease_time |
734 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
735 | + ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \ |
736 | + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ |
737 | + >/dev/null 2>&1 |
738 | + ;; |
739 | + |
740 | + *) echo "dhcp: $reason";; |
741 | +esac |
742 | + |
743 | +exit 0 |
744 | diff -Naur dracut-049/modules.d/40network/net-lib.sh dracut-049-magellan/modules.d/40network/net-lib.sh |
745 | --- dracut-049/modules.d/40network/net-lib.sh 2018-10-08 15:38:33.000000000 +0200 |
746 | +++ dracut-049-magellan/modules.d/40network/net-lib.sh 2019-07-08 15:29:03.534562522 +0200 |
747 | @@ -120,6 +120,8 @@ |
748 | [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname |
749 | [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
750 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts |
751 | + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts |
752 | + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts |
753 | # set up resolv.conf |
754 | [ -e /tmp/net.$netif.resolv.conf ] && \ |
755 | awk '!array[$0]++' /tmp/net.$netif.resolv.conf > /etc/resolv.conf |
756 | @@ -196,6 +198,12 @@ |
757 | for f in /tmp/dhclient.$i.*; do |
758 | [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.} |
759 | done |
760 | + for f in /tmp/udhcpc.$i.*; do |
761 | + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/udhcpc.} |
762 | + done |
763 | + for f in /tmp/dhcpcd.$i.*; do |
764 | + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhcpcd.} |
765 | + done |
766 | done |
767 | echo $IFACES > /tmp/.net.ifaces.new |
768 | mv /tmp/.net.ifaces.new /tmp/net.ifaces |
769 | diff -Naur dracut-049/modules.d/40network/netroot.sh dracut-049-magellan/modules.d/40network/netroot.sh |
770 | --- dracut-049/modules.d/40network/netroot.sh 2018-10-08 15:38:33.000000000 +0200 |
771 | +++ dracut-049-magellan/modules.d/40network/netroot.sh 2019-07-08 15:29:47.500932759 +0200 |
772 | @@ -41,6 +41,8 @@ |
773 | if getarg "root=dhcp" || getarg "netroot=dhcp" || getarg "root=dhcp6" || getarg "netroot=dhcp6"; then |
774 | # Load dhcp options |
775 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts |
776 | + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts |
777 | + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts |
778 | |
779 | # If we have a specific bootdev with no dhcpoptions or empty root-path, |
780 | # we die. Otherwise we just warn |