Magellan Linux

Annotation of /trunk/dracut/patches/dracut-047-network-support-udhcpc-dhcpcd.patch

Parent Directory Parent Directory | Revision Log Revision Log


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