Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2588 - (hide annotations) (download)
Fri Jun 19 13:05:22 2015 UTC (8 years, 11 months ago) by niro
File size: 16384 byte(s)
-re-worked for 043
1 niro 2588 diff -Naur dracut-043/modules.d/40network/dhcpcd-script.sh dracut-043-udhcpc/modules.d/40network/dhcpcd-script.sh
2     --- dracut-043/modules.d/40network/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100
3     +++ dracut-043-udhcpc/modules.d/40network/dhcpcd-script.sh 2015-06-18 15:29:28.147842659 +0200
4     @@ -0,0 +1,161 @@
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     +# Huh? Interface configured?
16     +[ -f "/tmp/net.$netif.up" ] && exit 0
17     +
18     +setup_interface() {
19     + ip=$new_ip_address
20     + mtu=$new_interface_mtu
21     + mask=$new_subnet_mask
22     + bcast=$new_broadcast_address
23     + gw=${new_routers%%,*}
24     + domain=$new_domain_name
25     + search=$(printf -- "$new_domain_search")
26     + namesrv=$new_domain_name_servers
27     + hostname=$new_host_name
28     + lease_time=$new_dhcp_lease_time
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} \
47     + valid_lft ${lease_time} preferred_lft ${lease_time} \
48     + dev $netif
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     + echo ip route replace default via $gw dev $netif >> /tmp/net.$netif.gw
56     + fi
57     +
58     + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
59     + if [ -n "$namesrv" ] ; then
60     + for s in $namesrv; do
61     + echo nameserver $s
62     + done
63     + fi >> /tmp/net.$netif.resolv.conf
64     +
65     + # Note: hostname can be fqdn OR short hostname, so chop off any
66     + # trailing domain name and explicity add any domain if set.
67     + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
68     +}
69     +
70     +setup_interface6() {
71     + domain=$new_domain_name
72     + search=$(printf -- "$new_domain_search")
73     + namesrv=$new_domain_name_servers
74     + hostname=$new_host_name
75     + [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
76     + [ -n "$new_max_life" ] && lease_time=$new_max_life
77     + preferred_lft=$lease_time
78     + [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
79     +
80     + [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
81     +
82     + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
83     + dev ${netif} scope global \
84     + ${lease_time:+valid_lft $lease_time} \
85     + ${preferred_lft:+preferred_lft ${preferred_lft}}
86     +
87     + [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
88     + if [ -n "$namesrv" ] ; then
89     + for s in $namesrv; do
90     + echo nameserver $s
91     + done
92     + fi >> /tmp/net.$netif.resolv.conf
93     +
94     + # Note: hostname can be fqdn OR short hostname, so chop off any
95     + # trailing domain name and explicity add any domain if set.
96     + [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
97     +}
98     +
99     +case $reason in
100     + PREINIT)
101     + echo "dhcp: PREINIT $netif up"
102     + linkup $netif
103     + ;;
104     +
105     + PREINIT6)
106     + echo "dhcp: PREINIT6 $netif up"
107     + linkup $netif
108     + wait_for_ipv6_dad $netif
109     + ;;
110     +
111     + BOUND)
112     + echo "dhcp: BOND setting $netif"
113     + unset layer2
114     + if [ -f /sys/class/net/$netif/device/layer2 ]; then
115     + read layer2 < /sys/class/net/$netif/device/layer2
116     + fi
117     + if [ "$layer2" != "0" ]; then
118     + if ! arping -q -D -c 2 -I $netif $new_ip_address ; then
119     + warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
120     + exit 1
121     + fi
122     + fi
123     + unset layer2
124     + setup_interface
125     + set | while read line || [ -n "$line" ]; do
126     + [ "${line#new_}" = "$line" ] && continue
127     + echo "$line"
128     + done >/tmp/dhcpcd.$netif.dhcpopts
129     +
130     + {
131     + echo '. /lib/net-lib.sh'
132     + echo "setup_net $netif"
133     + echo "source_hook initqueue/online $netif"
134     + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
135     + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
136     + } > $hookdir/initqueue/setup_net_$netif.sh
137     +
138     + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh
139     + >/tmp/net.$netif.up
140     + ;;
141     +
142     + BOUND6)
143     + echo "dhcp: BOND6 setting $netif"
144     + setup_interface6
145     +
146     + set | while read line || [ -n "$line" ]; do
147     + [ "${line#new_}" = "$line" ] && continue
148     + echo "$line"
149     + done >/tmp/dhcpcd.$netif.dhcpopts
150     +
151     + {
152     + echo '. /lib/net-lib.sh'
153     + echo "setup_net $netif"
154     + echo "source_hook initqueue/online $netif"
155     + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
156     + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
157     + } > $hookdir/initqueue/setup_net_$netif.sh
158     +
159     + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh
160     + >/tmp/net.$netif.up
161     + ;;
162     + *) echo "dhcp: $reason";;
163     +esac
164     +
165     +exit 0
166     diff -Naur dracut-043/modules.d/40network/ifup.sh dracut-043-udhcpc/modules.d/40network/ifup.sh
167     --- dracut-043/modules.d/40network/ifup.sh 2015-06-15 12:27:21.000000000 +0200
168     +++ dracut-043-udhcpc/modules.d/40network/ifup.sh 2015-06-18 15:33:15.498572679 +0200
169     @@ -10,6 +10,23 @@
170     type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
171     type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
172    
173     +# load magellan settings
174     +[ -f /etc/conf.d/network ] && . /etc/conf.d/network
175     +# some sane defaults
176     +if [[ -n $DEFAULT_DHCP_PROG ]]
177     +then
178     + DHCP_PROG="$DEFAULT_DHCP_PROG"
179     +else
180     + DHCP_PROG="/sbin/dhcpcd"
181     +fi
182     +if [[ -n $DEFAULT_DHCP_START ]]
183     +then
184     + DHCP_START="$DEFAULT_DHCP_START"
185     +else
186     + DHCP_START="-t 10"
187     +fi
188     +DHCP_PROG_NAME="${DHCP_PROG##*/}"
189     +
190     # Huh? No $1?
191     [ -z "$1" ] && exit 1
192    
193     @@ -88,6 +105,8 @@
194    
195     # Run dhclient
196     do_dhcp() {
197     + local opts
198     +
199     # dhclient-script will mark the netif up and generate the online
200     # event for nfsroot
201     # XXX add -V vendor class and option parsing per kernel
202     @@ -98,9 +117,27 @@
203     echo "No carrier detected"
204     return 1
205     fi
206     - echo "Starting dhcp for interface $netif"
207     - dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
208     - || echo "dhcp failed"
209     +
210     + case $DHCP_PROG_NAME in
211     + dhclient)
212     + opts="$@ -1 -q"
213     + opts+=" -cf /etc/dhclient.conf"
214     + opts+=" -pf /tmp/$DHCP_PROG_NAME.$netif.pid"
215     + opts+=" -lf /tmp/$DHCP_PROG_NAME.$netif.lease"
216     + ;;
217     +
218     + dhcpcd)
219     + opts="$@ -q"
220     + ;;
221     +
222     + udhcpc)
223     + opts="-q"
224     + opts+=" -p /tmp/$DHCP_PROG_NAME.$netif.pid"
225     + ;;
226     + esac
227     +
228     + echo "Starting dhcp ($DHCP_PROG_NAME) for interface $netif"
229     + $DHCP_PROG $opts $DHCP_START $netif || echo "dhcp failed"
230     }
231    
232     load_ipv6() {
233     diff -Naur dracut-043/modules.d/40network/kill-dhcpcd.sh dracut-043-udhcpc/modules.d/40network/kill-dhcpcd.sh
234     --- dracut-043/modules.d/40network/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100
235     +++ dracut-043-udhcpc/modules.d/40network/kill-dhcpcd.sh 2015-06-18 15:35:31.898205094 +0200
236     @@ -0,0 +1,15 @@
237     +#!/bin/sh
238     +
239     +for f in /run/dhcpcd.*.pid /run/dhcpcd.pid; do
240     + [ -e $f ] || continue
241     + read PID < $f;
242     + kill $PID >/dev/null 2>&1
243     +done
244     +
245     +sleep 0.1
246     +
247     +for f in /tmp/dhcpcd.*.pid /run/dhcpcd.pid; do
248     + [ -e $f ] || continue
249     + read PID < $f;
250     + kill -9 $PID >/dev/null 2>&1
251     +done
252     diff -Naur dracut-043/modules.d/40network/kill-udhcpc.sh dracut-043-udhcpc/modules.d/40network/kill-udhcpc.sh
253     --- dracut-043/modules.d/40network/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100
254     +++ dracut-043-udhcpc/modules.d/40network/kill-udhcpc.sh 2015-06-18 15:37:39.388924036 +0200
255     @@ -0,0 +1,15 @@
256     +#!/bin/sh
257     +
258     +for f in /tmp/udhcpc.*.pid; do
259     + [ -e $f ] || continue
260     + read PID < $f;
261     + kill $PID >/dev/null 2>&1
262     +done
263     +
264     +sleep 0.1
265     +
266     +for f in /tmp/udhcpc.*.pid; do
267     + [ -e $f ] || continue
268     + read PID < $f;
269     + kill -9 $PID >/dev/null 2>&1
270     +done
271     diff -Naur dracut-043/modules.d/40network/module-setup.sh dracut-043-udhcpc/modules.d/40network/module-setup.sh
272     --- dracut-043/modules.d/40network/module-setup.sh 2015-06-15 12:27:21.000000000 +0200
273     +++ dracut-043-udhcpc/modules.d/40network/module-setup.sh 2015-06-18 15:43:49.200197822 +0200
274     @@ -3,8 +3,9 @@
275     # called by dracut
276     check() {
277     local _program
278     + . /etc/conf.d/network
279    
280     - require_binaries ip arping dhclient || return 1
281     + require_binaries ip ifconfig route arping $DEFAULT_DHCP_PROG || return 1
282    
283     return 255
284     }
285     @@ -23,17 +24,20 @@
286     # called by dracut
287     install() {
288     local _arch _i _dir
289     - inst_multiple ip arping dhclient sed
290     + local _dhcp_prog_name
291     + local _file
292     + . /etc/conf.d/network
293     + _dhcp_prog_name="${DEFAULT_DHCP_PROG##*/}"
294     +
295     + inst_multiple ip arping $_dhcp_prog_name sed
296     + inst_multiple ifconfig route
297     inst_multiple -o ping ping6
298     inst_multiple -o brctl
299     inst_multiple -o teamd teamdctl teamnl
300     inst_simple /etc/libnl/classid
301     inst_script "$moddir/ifup.sh" "/sbin/ifup"
302     inst_script "$moddir/netroot.sh" "/sbin/netroot"
303     - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
304     inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh"
305     - inst_simple -H "/etc/dhclient.conf"
306     - cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf"
307     inst_hook pre-udev 50 "$moddir/ifname-genrules.sh"
308     inst_hook pre-udev 60 "$moddir/net-genrules.sh"
309     inst_hook cmdline 91 "$moddir/dhcp-root.sh"
310     @@ -44,7 +48,30 @@
311     inst_hook cmdline 97 "$moddir/parse-bridge.sh"
312     inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
313     inst_hook cmdline 99 "$moddir/parse-ifname.sh"
314     - inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
315     + case $_dhcp_prog_name in
316     + dhclient)
317     + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
318     + inst_simple -H "/etc/dhclient.conf"
319     + cat "$moddir/dhclient.conf" >> "${initdir}/etc/dhclient.conf"
320     + inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
321     + ;;
322     +
323     + udhcpc)
324     + inst_script "$moddir/udhcpc-script.sh" "/usr/share/udhcpc/default.script"
325     + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh"
326     + ;;
327     +
328     + dhcpcd)
329     + inst_simple "/etc/dhcpcd.conf"
330     + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks
331     + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do
332     + inst_simple -o $_file
333     + done
334     + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot"
335     + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh"
336     + ;;
337     + esac
338     + inst_simple /etc/conf.d/network
339    
340     _arch=$(uname -m)
341    
342     diff -Naur dracut-043/modules.d/40network/net-lib.sh dracut-043-udhcpc/modules.d/40network/net-lib.sh
343     --- dracut-043/modules.d/40network/net-lib.sh 2015-06-15 12:27:21.000000000 +0200
344     +++ dracut-043-udhcpc/modules.d/40network/net-lib.sh 2015-06-18 15:46:26.655608268 +0200
345     @@ -97,6 +97,8 @@
346     [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname
347     [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
348     [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
349     + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts
350     + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts
351     # set up resolv.conf
352     [ -e /tmp/net.$netif.resolv.conf ] && \
353     cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf
354     @@ -161,6 +163,12 @@
355     for f in /tmp/dhclient.$i.*; do
356     [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.}
357     done
358     + for f in /tmp/udhcpc.$i.*; do
359     + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/udhcpc.}
360     + done
361     + for f in /tmp/dhcpcd.$i.*; do
362     + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhcpcd.}
363     + done
364     done
365     echo $IFACES > /tmp/.net.ifaces.new
366     mv /tmp/.net.ifaces.new /tmp/net.ifaces
367     diff -Naur dracut-043/modules.d/40network/netroot.sh dracut-043-udhcpc/modules.d/40network/netroot.sh
368     --- dracut-043/modules.d/40network/netroot.sh 2015-06-15 12:27:21.000000000 +0200
369     +++ dracut-043-udhcpc/modules.d/40network/netroot.sh 2015-06-18 15:47:30.014968301 +0200
370     @@ -36,6 +36,8 @@
371     if [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] ; then
372     # Load dhcp options
373     [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
374     + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts
375     + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts
376    
377     # If we have a specific bootdev with no dhcpoptions or empty root-path,
378     # we die. Otherwise we just warn
379     diff -Naur dracut-043/modules.d/40network/udhcpc-script.sh dracut-043-udhcpc/modules.d/40network/udhcpc-script.sh
380     --- dracut-043/modules.d/40network/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100
381     +++ dracut-043-udhcpc/modules.d/40network/udhcpc-script.sh 2015-06-18 15:51:55.653283630 +0200
382     @@ -0,0 +1,102 @@
383     +#!/bin/sh
384     +
385     +# global options passed by udhcpc
386     +# what to run
387     +# $1 - which command to run, possible are: bound|deconfig|nak|renew
388     +# router - routers address
389     +# subnet - the subnet
390     +# dhcptype - type of dhcp
391     +# interface - which iface gets configured
392     +# serverid - ip of the dhcd server
393     +# dns - dns to use
394     +# ip - ip-address to use
395     +# lease - lease time of a dhcp configuration
396     +# mask - network mask to use
397     +
398     +PATH=/usr/sbin:/usr/bin:/sbin:/bin
399     +
400     +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
401     +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
402     +
403     +# We already need a set netif here
404     +netif="${interface}"
405     +
406     +# Huh? Interface configured?
407     +[ -f "/tmp/net.$netif.up" ] && exit 0
408     +
409     +# renew dhcp leases
410     +bound()
411     +{
412     + local RESOLV_CONF="/etc/resolv.conf"
413     + local BROADCAST
414     + local NETMASK
415     + local i
416     +
417     + [[ -n ${broadcast} ]] && BROADCAST="broadcast ${broadcast}"
418     + [[ -n ${subnet} ]] && NETMASK="netmask ${subnet}"
419     +
420     + /sbin/ifconfig ${interface} ${ip} ${BROADCAST} ${NETMASK}
421     +
422     + if [ -n "${router}" ]
423     + then
424     + echo "deleting routers"
425     + while /sbin/route del default gw 0.0.0.0 dev ${interface}
426     + do :
427     + done
428     +
429     + metric=0
430     + for i in ${router}
431     + do
432     + /sbin/route add default gw ${i} dev ${interface} metric $((metric++))
433     + done
434     + fi
435     +
436     + echo -n > ${RESOLV_CONF}
437     + [[ -n ${domain} ]] && echo "domain ${domain}" >> ${RESOLV_CONF}
438     + for i in ${dns}
439     + do
440     + echo adding dns ${i}
441     + echo "nameserver ${i}" >> ${RESOLV_CONF}
442     + done
443     +
444     + set | while read line; do
445     + [ "${line#new_}" = "$line" ] && continue
446     + echo "$line"
447     + done >/tmp/udhcpc.$netif.dhcpopts
448     +
449     + {
450     + echo '. /lib/net-lib.sh'
451     + echo "setup_net $netif"
452     + echo "source_hook initqueue/online $netif"
453     + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
454     + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
455     + } > $hookdir/initqueue/setup_net_$netif.sh
456     +
457     + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh
458     + >/tmp/net.$netif.up
459     +}
460     +
461     +renew()
462     +{
463     + # same as bound()
464     + bound
465     +}
466     +
467     +deconfig()
468     +{
469     + /sbin/ifconfig ${interface} 0.0.0.0
470     +}
471     +
472     +# what to do if a dhcp request failed
473     +nak()
474     +{
475     + echo "Received a NAK: ${message}"
476     +}
477     +
478     +
479     +case $1 in
480     + bound) bound ;;
481     + renew) renew ;;
482     + deconfig) deconfig ;;
483     + nak) nak ;;
484     +esac