Annotation of /trunk/dracut/patches/dracut-045-network-support-udhcpc-dhcpcd.patch
Parent Directory | Revision Log
Revision 2904 -
(hide annotations)
(download)
Tue Apr 4 15:29:31 2017 UTC (7 years, 5 months ago) by niro
File size: 27984 byte(s)
Tue Apr 4 15:29:31 2017 UTC (7 years, 5 months ago) by niro
File size: 27984 byte(s)
-re-diffed udhcpc/dhcpc patch for 045
1 | niro | 2904 | 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-04 17:15:27.311213904 +0200 | ||
496 | @@ -0,0 +1,258 @@ | ||
497 | +#!/bin/sh | ||
498 | + | ||
499 | +PATH=/usr/sbin:/usr/bin:/sbin:/bin | ||
500 | + | ||
501 | +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh | ||
502 | +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh | ||
503 | + | ||
504 | +# We already need a set netif here | ||
505 | +netif=$interface | ||
506 | + | ||
507 | +setup_interface() { | ||
508 | + ip=$new_ip_address | ||
509 | + mtu=$new_interface_mtu | ||
510 | + mask=$new_subnet_mask | ||
511 | + bcast=$new_broadcast_address | ||
512 | + gw=${new_routers%%,*} | ||
513 | + domain=$new_domain_name | ||
514 | + search=$(printf -- "$new_domain_search") | ||
515 | + namesrv=$new_domain_name_servers | ||
516 | + hostname=$new_host_name | ||
517 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time | ||
518 | + [ -n "$new_max_life" ] && lease_time=$new_max_life | ||
519 | + preferred_lft=$lease_time | ||
520 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life | ||
521 | + | ||
522 | + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override | ||
523 | + | ||
524 | + # Taken from debian dhclient-script: | ||
525 | + # The 576 MTU is only used for X.25 and dialup connections | ||
526 | + # where the admin wants low latency. Such a low MTU can cause | ||
527 | + # problems with UDP traffic, among other things. As such, | ||
528 | + # disallow MTUs from 576 and below by default, so that broken | ||
529 | + # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). | ||
530 | + if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then | ||
531 | + if ! ip link set $netif mtu $mtu ; then | ||
532 | + ip link set $netif down | ||
533 | + ip link set $netif mtu $mtu | ||
534 | + linkup $netif | ||
535 | + fi | ||
536 | + fi | ||
537 | + | ||
538 | + ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif \ | ||
539 | + ${lease_time:+valid_lft $lease_time} \ | ||
540 | + ${preferred_lft:+preferred_lft ${preferred_lft}} | ||
541 | + | ||
542 | + if [ -n "$gw" ] ; then | ||
543 | + if [ "$mask" = "255.255.255.255" ] ; then | ||
544 | + # point-to-point connection => set explicit route to gateway | ||
545 | + echo ip route add $gw dev $netif > /tmp/net.$netif.gw | ||
546 | + fi | ||
547 | + | ||
548 | + echo "$gw" | { | ||
549 | + IFS=' ' read -r main_gw other_gw | ||
550 | + echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw | ||
551 | + if [ -n "$other_gw" ] ; then | ||
552 | + for g in $other_gw; do | ||
553 | + echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw | ||
554 | + done | ||
555 | + fi | ||
556 | + } | ||
557 | + fi | ||
558 | + | ||
559 | + if getargbool 1 rd.peerdns; then | ||
560 | + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf | ||
561 | + if [ -n "$namesrv" ] ; then | ||
562 | + for s in $namesrv; do | ||
563 | + echo nameserver $s | ||
564 | + done | ||
565 | + fi >> /tmp/net.$netif.resolv.conf | ||
566 | + fi | ||
567 | + # Note: hostname can be fqdn OR short hostname, so chop off any | ||
568 | + # trailing domain name and explicity add any domain if set. | ||
569 | + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname | ||
570 | +} | ||
571 | + | ||
572 | +setup_interface6() { | ||
573 | + domain=$new_domain_name | ||
574 | + search=$(printf -- "$new_domain_search") | ||
575 | + namesrv=$new_domain_name_servers | ||
576 | + hostname=$new_host_name | ||
577 | + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time | ||
578 | + [ -n "$new_max_life" ] && lease_time=$new_max_life | ||
579 | + preferred_lft=$lease_time | ||
580 | + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life | ||
581 | + | ||
582 | + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override | ||
583 | + | ||
584 | + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \ | ||
585 | + dev ${netif} scope global \ | ||
586 | + ${lease_time:+valid_lft $lease_time} \ | ||
587 | + ${preferred_lft:+preferred_lft ${preferred_lft}} | ||
588 | + | ||
589 | + if getargbool 1 rd.peerdns; then | ||
590 | + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf | ||
591 | + if [ -n "$namesrv" ] ; then | ||
592 | + for s in $namesrv; do | ||
593 | + echo nameserver $s | ||
594 | + done | ||
595 | + fi >> /tmp/net.$netif.resolv.conf | ||
596 | + fi | ||
597 | + | ||
598 | + # Note: hostname can be fqdn OR short hostname, so chop off any | ||
599 | + # trailing domain name and explicity add any domain if set. | ||
600 | + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname | ||
601 | +} | ||
602 | + | ||
603 | +parse_option_121() { | ||
604 | + while [ $# -ne 0 ]; do | ||
605 | + mask="$1" | ||
606 | + shift | ||
607 | + | ||
608 | + # Is the destination a multicast group? | ||
609 | + if [ $1 -ge 224 -a $1 -lt 240 ]; then | ||
610 | + multicast=1 | ||
611 | + else | ||
612 | + multicast=0 | ||
613 | + fi | ||
614 | + | ||
615 | + # Parse the arguments into a CIDR net/mask string | ||
616 | + if [ $mask -gt 24 ]; then | ||
617 | + destination="$1.$2.$3.$4/$mask" | ||
618 | + shift; shift; shift; shift | ||
619 | + elif [ $mask -gt 16 ]; then | ||
620 | + destination="$1.$2.$3.0/$mask" | ||
621 | + shift; shift; shift | ||
622 | + elif [ $mask -gt 8 ]; then | ||
623 | + destination="$1.$2.0.0/$mask" | ||
624 | + shift; shift | ||
625 | + else | ||
626 | + destination="$1.0.0.0/$mask" | ||
627 | + shift | ||
628 | + fi | ||
629 | + | ||
630 | + # Read the gateway | ||
631 | + gateway="$1.$2.$3.$4" | ||
632 | + shift; shift; shift; shift | ||
633 | + | ||
634 | + # Multicast routing on Linux | ||
635 | + # - If you set a next-hop address for a multicast group, this breaks with Cisco switches | ||
636 | + # - If you simply leave it link-local and attach it to an interface, it works fine. | ||
637 | + if [ $multicast -eq 1 ]; then | ||
638 | + temp_result="$destination dev $interface" | ||
639 | + else | ||
640 | + temp_result="$destination via $gateway dev $interface" | ||
641 | + fi | ||
642 | + | ||
643 | + echo "/sbin/ip route add $temp_result" | ||
644 | + done | ||
645 | +} | ||
646 | + | ||
647 | + | ||
648 | +case $reason in | ||
649 | + PREINIT) | ||
650 | + echo "dhcp: PREINIT $netif up" | ||
651 | + linkup $netif | ||
652 | + ;; | ||
653 | + | ||
654 | + PREINIT6) | ||
655 | + echo "dhcp: PREINIT6 $netif up" | ||
656 | + linkup $netif | ||
657 | + wait_for_ipv6_dad_link $netif | ||
658 | + ;; | ||
659 | + | ||
660 | + BOUND) | ||
661 | + echo "dhcp: BOND setting $netif" | ||
662 | + unset layer2 | ||
663 | + if [ -f /sys/class/net/$netif/device/layer2 ]; then | ||
664 | + read layer2 < /sys/class/net/$netif/device/layer2 | ||
665 | + fi | ||
666 | + if [ "$layer2" != "0" ]; then | ||
667 | + if command -v arping2 >/dev/null; then | ||
668 | + if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address ; then | ||
669 | + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" | ||
670 | + exit 1 | ||
671 | + fi | ||
672 | + else | ||
673 | + if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then | ||
674 | + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" | ||
675 | + exit 1 | ||
676 | + fi | ||
677 | + fi | ||
678 | + fi | ||
679 | + unset layer2 | ||
680 | + setup_interface | ||
681 | + set | while read line || [ -n "$line" ]; do | ||
682 | + [ "${line#new_}" = "$line" ] && continue | ||
683 | + echo "$line" | ||
684 | + done >/tmp/udhcpc.$netif.dhcpopts | ||
685 | + | ||
686 | + { | ||
687 | + echo '. /lib/net-lib.sh' | ||
688 | + echo "setup_net $netif" | ||
689 | + if [ -n "$new_classless_static_routes" ]; then | ||
690 | + modify_routes add "$(parse_option_121 $new_classless_static_routes)" | ||
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|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) | ||
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|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 |