Contents of /trunk/dracut/patches/dracut-045-network-support-udhcpc-dhcpcd-3.patch
Parent Directory | Revision Log
Revision 2909 -
(show annotations)
(download)
Fri Apr 7 13:51:21 2017 UTC (7 years, 5 months ago) by niro
File size: 22025 byte(s)
Fri Apr 7 13:51:21 2017 UTC (7 years, 5 months ago) by niro
File size: 22025 byte(s)
-reworked again using our magellan udhcpc script as base
1 | diff -Naur dracut-045/modules.d/40network/dhcpcd-script.sh dracut-045-udhcpc/modules.d/40network/dhcpcd-script.sh |
2 | --- dracut-045/modules.d/40network/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100 |
3 | +++ dracut-045-udhcpc/modules.d/40network/dhcpcd-script.sh 2017-04-04 17:14:05.727102593 +0200 |
4 | @@ -0,0 +1,258 @@ |
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 | + modify_routes add "$(parse_option_121 $new_classless_static_routes)" |
199 | + fi |
200 | + echo "source_hook initqueue/online $netif" |
201 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
202 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
203 | + } > $hookdir/initqueue/setup_net_$netif.sh |
204 | + |
205 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh |
206 | + >/tmp/net.$netif.up |
207 | + if [ -e /sys/class/net/${netif}/address ]; then |
208 | + > /tmp/net.$(cat /sys/class/net/${netif}/address).up |
209 | + fi |
210 | + |
211 | + ;; |
212 | + |
213 | + RENEW|REBIND) |
214 | + unset lease_time |
215 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
216 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
217 | + preferred_lft=$lease_time |
218 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
219 | + ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \ |
220 | + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ |
221 | + >/dev/null 2>&1 |
222 | + ;; |
223 | + |
224 | + BOUND6) |
225 | + echo "dhcp: BOND6 setting $netif" |
226 | + setup_interface6 |
227 | + |
228 | + set | while read line || [ -n "$line" ]; do |
229 | + [ "${line#new_}" = "$line" ] && continue |
230 | + echo "$line" |
231 | + done >/tmp/dhcpcd.$netif.dhcpopts |
232 | + |
233 | + { |
234 | + echo '. /lib/net-lib.sh' |
235 | + echo "setup_net $netif" |
236 | + echo "source_hook initqueue/online $netif" |
237 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
238 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
239 | + } > $hookdir/initqueue/setup_net_$netif.sh |
240 | + |
241 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh |
242 | + >/tmp/net.$netif.up |
243 | + if [ -e /sys/class/net/${netif}/address ]; then |
244 | + > /tmp/net.$(cat /sys/class/net/${netif}/address).up |
245 | + fi |
246 | + ;; |
247 | + |
248 | + RENEW6|REBIND6) |
249 | + unset lease_time |
250 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time |
251 | + [ -n "$new_max_life" ] && lease_time=$new_max_life |
252 | + preferred_lft=$lease_time |
253 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life |
254 | + ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \ |
255 | + ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ |
256 | + >/dev/null 2>&1 |
257 | + ;; |
258 | + |
259 | + *) echo "dhcp: $reason";; |
260 | +esac |
261 | + |
262 | +exit 0 |
263 | diff -Naur dracut-045/modules.d/40network/ifup.sh dracut-045-udhcpc/modules.d/40network/ifup.sh |
264 | --- dracut-045/modules.d/40network/ifup.sh 2017-04-03 10:26:25.000000000 +0200 |
265 | +++ dracut-045-udhcpc/modules.d/40network/ifup.sh 2017-04-04 17:18:32.580199239 +0200 |
266 | @@ -10,6 +10,23 @@ |
267 | type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
268 | type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh |
269 | |
270 | +# load magellan settings |
271 | +[ -f /etc/conf.d/network ] && . /etc/conf.d/network |
272 | +# some sane defaults |
273 | +if [[ -n $DEFAULT_DHCP_PROG ]] |
274 | +then |
275 | + DHCP_PROG="$DEFAULT_DHCP_PROG" |
276 | +else |
277 | + DHCP_PROG="/sbin/dhcpcd" |
278 | +fi |
279 | +if [[ -n $DEFAULT_DHCP_START ]] |
280 | +then |
281 | + DHCP_START="$DEFAULT_DHCP_START" |
282 | +else |
283 | + DHCP_START="-t 10" |
284 | +fi |
285 | +DHCP_PROG_NAME="${DHCP_PROG##*/}" |
286 | + |
287 | # Huh? No $1? |
288 | [ -z "$1" ] && exit 1 |
289 | |
290 | @@ -25,6 +42,9 @@ |
291 | |
292 | # Run dhclient |
293 | do_dhcp() { |
294 | + local opts |
295 | + local timeoutswitch |
296 | + |
297 | # dhclient-script will mark the netif up and generate the online |
298 | # event for nfsroot |
299 | # XXX add -V vendor class and option parsing per kernel |
300 | @@ -41,20 +61,37 @@ |
301 | return 1 |
302 | fi |
303 | |
304 | + case $DHCP_PROG_NAME in |
305 | + dhclient) |
306 | + opts="$@ -1 -q" |
307 | + opts+=" -cf /etc/dhclient.conf" |
308 | + opts+=" -pf /tmp/$DHCP_PROG_NAME.$netif.pid" |
309 | + opts+=" -lf /tmp/$DHCP_PROG_NAME.$netif.lease" |
310 | + timeoutswitch="-timeout" |
311 | + ;; |
312 | + |
313 | + dhcpcd) |
314 | + opts="$@ -q" |
315 | + timeoutswitch="--timeout" |
316 | + ;; |
317 | + |
318 | + udhcpc) |
319 | + opts="-q" |
320 | + opts+=" -p /tmp/$DHCP_PROG_NAME.$netif.pid" |
321 | + timeoutswitch="--timeout" |
322 | + ;; |
323 | + esac |
324 | + |
325 | while [ $_COUNT -lt $_DHCPRETRY ]; do |
326 | - info "Starting dhcp for interface $netif" |
327 | - dhclient "$@" \ |
328 | - ${_timeout:+-timeout $_timeout} \ |
329 | - -q \ |
330 | - -cf /etc/dhclient.conf \ |
331 | - -pf /tmp/dhclient.$netif.pid \ |
332 | - -lf /tmp/dhclient.$netif.lease \ |
333 | - $netif \ |
334 | + info "Starting dhcp ($DHCP_PROG_NAME) for interface $netif" |
335 | + $DHCP_PROG $opts \ |
336 | + ${_timeout:+$timeoutswitch $_timeout} \ |
337 | + $DHCP_START $netif \ |
338 | && return 0 |
339 | _COUNT=$(($_COUNT+1)) |
340 | [ $_COUNT -lt $_DHCPRETRY ] && sleep 1 |
341 | done |
342 | - warn "dhcp for interface $netif failed" |
343 | + warn "dhcp ($DHCP_PROG_NAME) for interface $netif failed" |
344 | return 1 |
345 | } |
346 | |
347 | diff -Naur dracut-045/modules.d/40network/kill-dhcpcd.sh dracut-045-udhcpc/modules.d/40network/kill-dhcpcd.sh |
348 | --- dracut-045/modules.d/40network/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100 |
349 | +++ dracut-045-udhcpc/modules.d/40network/kill-dhcpcd.sh 2017-04-04 17:19:45.883403170 +0200 |
350 | @@ -0,0 +1,15 @@ |
351 | +#!/bin/sh |
352 | + |
353 | +for f in /tmp/dhcpcd.*.pid; do |
354 | + [ -e $f ] || continue |
355 | + read PID < $f; |
356 | + kill $PID >/dev/null 2>&1 |
357 | +done |
358 | + |
359 | +sleep 0.1 |
360 | + |
361 | +for f in /tmp/dhcpcd.*.pid; do |
362 | + [ -e $f ] || continue |
363 | + read PID < $f; |
364 | + kill -9 $PID >/dev/null 2>&1 |
365 | +done |
366 | diff -Naur dracut-045/modules.d/40network/kill-udhcpc.sh dracut-045-udhcpc/modules.d/40network/kill-udhcpc.sh |
367 | --- dracut-045/modules.d/40network/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100 |
368 | +++ dracut-045-udhcpc/modules.d/40network/kill-udhcpc.sh 2017-04-04 17:20:09.041151778 +0200 |
369 | @@ -0,0 +1,15 @@ |
370 | +#!/bin/sh |
371 | + |
372 | +for f in /tmp/udhcpc.*.pid; do |
373 | + [ -e $f ] || continue |
374 | + read PID < $f; |
375 | + kill $PID >/dev/null 2>&1 |
376 | +done |
377 | + |
378 | +sleep 0.1 |
379 | + |
380 | +for f in /tmp/udhcpc.*.pid; do |
381 | + [ -e $f ] || continue |
382 | + read PID < $f; |
383 | + kill -9 $PID >/dev/null 2>&1 |
384 | +done |
385 | diff -Naur dracut-045/modules.d/40network/module-setup.sh dracut-045-udhcpc/modules.d/40network/module-setup.sh |
386 | --- dracut-045/modules.d/40network/module-setup.sh 2017-04-03 10:26:25.000000000 +0200 |
387 | +++ dracut-045-udhcpc/modules.d/40network/module-setup.sh 2017-04-04 17:24:59.932997302 +0200 |
388 | @@ -3,8 +3,9 @@ |
389 | # called by dracut |
390 | check() { |
391 | local _program |
392 | + . /etc/conf.d/network |
393 | |
394 | - require_binaries ip dhclient || return 1 |
395 | + require_binaries ip ifconfig route $DEFAULT_DHCP_PROG || return 1 |
396 | require_any_binary arping arping2 || return 1 |
397 | |
398 | return 255 |
399 | @@ -24,17 +25,20 @@ |
400 | # called by dracut |
401 | install() { |
402 | local _arch _i _dir |
403 | - inst_multiple ip dhclient sed awk |
404 | + local _dhcp_prog_name |
405 | + local _file |
406 | + . /etc/conf.d/network |
407 | + _dhcp_prog_name="${DEFAULT_DHCP_PROG##*/}" |
408 | + |
409 | + inst_multiple ip $_dhcp_prog_name sed awk |
410 | + inst_multiple ifconfig route |
411 | inst_multiple -o arping arping2 |
412 | inst_multiple -o ping ping6 |
413 | inst_multiple -o teamd teamdctl teamnl |
414 | inst_simple /etc/libnl/classid |
415 | inst_script "$moddir/ifup.sh" "/sbin/ifup" |
416 | inst_script "$moddir/netroot.sh" "/sbin/netroot" |
417 | - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" |
418 | inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh" |
419 | - inst_simple -H "/etc/dhclient.conf" |
420 | - cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf" |
421 | inst_hook pre-udev 50 "$moddir/ifname-genrules.sh" |
422 | inst_hook pre-udev 60 "$moddir/net-genrules.sh" |
423 | inst_hook cmdline 91 "$moddir/dhcp-root.sh" |
424 | @@ -45,7 +49,30 @@ |
425 | inst_hook cmdline 97 "$moddir/parse-bridge.sh" |
426 | inst_hook cmdline 98 "$moddir/parse-ip-opts.sh" |
427 | inst_hook cmdline 99 "$moddir/parse-ifname.sh" |
428 | - inst_hook cleanup 10 "$moddir/kill-dhclient.sh" |
429 | + case $_dhcp_prog_name in |
430 | + dhclient) |
431 | + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" |
432 | + inst_simple -H "/etc/dhclient.conf" |
433 | + cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf" |
434 | + inst_hook cleanup 10 "$moddir/kill-dhclient.sh" |
435 | + ;; |
436 | + |
437 | + udhcpc) |
438 | + inst_script "$moddir/udhcpc-script.sh" "/usr/share/udhcpc/default.script" |
439 | + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh" |
440 | + ;; |
441 | + |
442 | + dhcpcd) |
443 | + inst_simple "/etc/dhcpcd.conf" |
444 | + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks |
445 | + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do |
446 | + inst_simple -o $_file |
447 | + done |
448 | + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot" |
449 | + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh" |
450 | + ;; |
451 | + esac |
452 | + inst_simple /etc/conf.d/network |
453 | |
454 | # install all config files for teaming |
455 | unset TEAM_MASTER |
456 | diff -Naur dracut-045/modules.d/40network/net-lib.sh dracut-045-udhcpc/modules.d/40network/net-lib.sh |
457 | --- dracut-045/modules.d/40network/net-lib.sh 2017-04-03 10:26:25.000000000 +0200 |
458 | +++ dracut-045-udhcpc/modules.d/40network/net-lib.sh 2017-04-04 17:25:57.728371148 +0200 |
459 | @@ -120,6 +120,8 @@ |
460 | [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname |
461 | [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override |
462 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts |
463 | + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts |
464 | + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts |
465 | # set up resolv.conf |
466 | [ -e /tmp/net.$netif.resolv.conf ] && \ |
467 | awk '!array[$0]++' /tmp/net.$netif.resolv.conf > /etc/resolv.conf |
468 | @@ -196,6 +198,12 @@ |
469 | for f in /tmp/dhclient.$i.*; do |
470 | [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.} |
471 | done |
472 | + for f in /tmp/udhcpc.$i.*; do |
473 | + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/udhcpc.} |
474 | + done |
475 | + for f in /tmp/dhcpcd.$i.*; do |
476 | + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhcpcd.} |
477 | + done |
478 | done |
479 | echo $IFACES > /tmp/.net.ifaces.new |
480 | mv /tmp/.net.ifaces.new /tmp/net.ifaces |
481 | diff -Naur dracut-045/modules.d/40network/netroot.sh dracut-045-udhcpc/modules.d/40network/netroot.sh |
482 | --- dracut-045/modules.d/40network/netroot.sh 2017-04-03 10:26:25.000000000 +0200 |
483 | +++ dracut-045-udhcpc/modules.d/40network/netroot.sh 2017-04-04 17:27:39.875264813 +0200 |
484 | @@ -41,6 +41,8 @@ |
485 | if getarg "root=dhcp" || getarg "netroot=dhcp" || getarg "root=dhcp6" || getarg "netroot=dhcp6"; then |
486 | # Load dhcp options |
487 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts |
488 | + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts |
489 | + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts |
490 | |
491 | # If we have a specific bootdev with no dhcpoptions or empty root-path, |
492 | # we die. Otherwise we just warn |
493 | diff -Naur dracut-045/modules.d/40network/udhcpc-script.sh dracut-045-udhcpc/modules.d/40network/udhcpc-script.sh |
494 | --- dracut-045/modules.d/40network/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100 |
495 | +++ dracut-045-udhcpc/modules.d/40network/udhcpc-script.sh 2017-04-07 15:47:32.482124028 +0200 |
496 | @@ -0,0 +1,129 @@ |
497 | +#!/bin/sh |
498 | + |
499 | +# global options passed by udhcpc |
500 | +# what to run |
501 | +# $1 - which command to run, possible are: bound|deconfig|nak|renew |
502 | +# router - a list of routers |
503 | +# subnet - the assigend subnet mask |
504 | +# dhcptype - type of dhcp (safely ignored) |
505 | +# interface - which iface gets configured |
506 | +# serverid - ip of the dhcd server |
507 | +# dns - a list of dns server |
508 | +# ip - ip-address to use |
509 | +# lease - lease time of a dhcp configuration, in seconds |
510 | +# mask - the number of bits in the netmask (ie: 24) |
511 | +# boot_file - the bootp boot file option |
512 | +# siaddr - the bootp next server option |
513 | +# sname - the bootp server name option |
514 | +# timezone - offset in seconds from utc |
515 | +# timesvr - a list of time servers |
516 | +# namesvr - a list of ien116 name servers |
517 | +# logsvr - a list of mit-lcs udp log servers |
518 | +# cookiesvr - a list of rfc865 cookie servers |
519 | +# lprsvr - a list of lpr servers |
520 | +# hostname - the assigned hostname |
521 | +# bootsize - the length in 512 octect blocks of the bootfile |
522 | +# domain - the domain name of the network |
523 | +# swapsvr - the ip address of the clients swap server |
524 | +# rootpath - the path name of the clients root disk |
525 | +# ipttl - the ttl to use for this network |
526 | +# mtu - the mtu to use for this network |
527 | +# broadcast - the broadcast address for this network |
528 | +# ntpsrv - a list of ntp servers |
529 | +# wins - a list of wins servers |
530 | +# message - reason for a dhcpnak |
531 | +# tftp - the tftp server name |
532 | +# bootfile - the bootfile name |
533 | + |
534 | +PATH=/usr/sbin:/usr/bin:/sbin:/bin |
535 | + |
536 | +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
537 | +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh |
538 | + |
539 | +# We already need a set netif here |
540 | +netif="${interface}" |
541 | + |
542 | +# Huh? Interface configured? |
543 | +[ -f "/tmp/net.$netif.up" ] && exit 0 |
544 | + |
545 | +# renew dhcp leases |
546 | +bound() |
547 | +{ |
548 | + local RESOLV_CONF="/etc/resolv.conf" |
549 | + local BROADCAST |
550 | + local NETMASK |
551 | + local i |
552 | + |
553 | + [[ -n ${broadcast} ]] && BROADCAST="broadcast ${broadcast}" |
554 | + [[ -n ${subnet} ]] && NETMASK="netmask ${subnet}" |
555 | + |
556 | + /sbin/ifconfig ${interface} ${ip} ${BROADCAST} ${NETMASK} |
557 | + |
558 | + if [ -n "${router}" ] |
559 | + then |
560 | + echo "deleting routers" |
561 | + while /sbin/route del default gw 0.0.0.0 dev ${interface} |
562 | + do : |
563 | + done |
564 | + |
565 | + metric=0 |
566 | + for i in ${router} |
567 | + do |
568 | + /sbin/route add default gw ${i} dev ${interface} metric $((metric++)) |
569 | + done |
570 | + fi |
571 | + |
572 | + echo -n > ${RESOLV_CONF} |
573 | + [[ -n ${domain} ]] && echo "domain ${domain}" >> ${RESOLV_CONF} |
574 | + for i in ${dns} |
575 | + do |
576 | + echo adding dns ${i} |
577 | + echo "nameserver ${i}" >> ${RESOLV_CONF} |
578 | + done |
579 | + |
580 | + if [ -n "${hostname}" ] |
581 | + then |
582 | + echo "echo ${hostname%.${domain}}${domain:+.${domain}} > /proc/sys/kernel/hostname" > /tmp/net.${netif}.hostname |
583 | + fi |
584 | + |
585 | + set | while read line; do |
586 | + [ "${line#new_}" = "$line" ] && continue |
587 | + echo "$line" |
588 | + done >/tmp/udhcpc.$netif.dhcpopts |
589 | + |
590 | + { |
591 | + echo '. /lib/net-lib.sh' |
592 | + echo "setup_net $netif" |
593 | + echo "source_hook initqueue/online $netif" |
594 | + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" |
595 | + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" |
596 | + } > $hookdir/initqueue/setup_net_$netif.sh |
597 | + |
598 | + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh |
599 | + >/tmp/net.$netif.up |
600 | +} |
601 | + |
602 | +renew() |
603 | +{ |
604 | + # same as bound() |
605 | + bound |
606 | +} |
607 | + |
608 | +deconfig() |
609 | +{ |
610 | + /sbin/ifconfig ${interface} 0.0.0.0 |
611 | +} |
612 | + |
613 | +# what to do if a dhcp request failed |
614 | +nak() |
615 | +{ |
616 | + echo "Received a NAK: ${message}" |
617 | +} |
618 | + |
619 | + |
620 | +case $1 in |
621 | + bound) bound ;; |
622 | + renew) renew ;; |
623 | + deconfig) deconfig ;; |
624 | + nak) nak ;; |
625 | +esac |