diff -Naur dracut-034/modules.d/40network/ifup.sh dracut-034-udhcpc/modules.d/40network/ifup.sh --- dracut-034/modules.d/40network/ifup.sh 2013-10-08 07:55:26.000000000 +0000 +++ dracut-034-udhcpc/modules.d/40network/ifup.sh 2014-01-17 12:49:15.467000000 +0000 @@ -12,6 +12,23 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh +# load magellan settings +[ -f /etc/conf.d/network ] && . /etc/conf.d/network +# some sane defaults +if [[ -n ${DEFAULT_DHCP_PROG} ]] +then + DHCP_PROG="${DEFAULT_DHCP_PROG}" +else + DHCP_PROG="/sbin/dhcpcd" +fi +if [[ -n ${DEFAULT_DHCP_START} ]] +then + DHCP_START="${DEFAULT_DHCP_START}" +else + DHCP_START="-t 10" +fi +DHCP_PROG_NAME="${DHCP_PROG##*/}" + # Huh? No $1? [ -z "$1" ] && exit 1 @@ -84,12 +101,39 @@ # Run dhclient do_dhcp() { - # dhclient-script will mark the netif up and generate the online - # event for nfsroot - # XXX add -V vendor class and option parsing per kernel + local opts + echo "Starting dhcp for interface $netif" - dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \ - || echo "dhcp failed" + case ${DHCP_PROG_NAME} in + dhclient) + opts="$@ -1 -q" + opts+=" -cf /etc/dhclient.conf" + opts+=" -pf /tmp/${DHCP_PROG_NAME}.$netif.pid" + opts+=" -lf /tmp/${DHCP_PROG_NAME}.$netif.lease" + ;; + + dhcpcd) + opts="$@ -q" + ;; + + udhcpc) + opts="-q" + opts+=" -p /tmp/${DHCP_PROG_NAME}.$netif.pid" + ;; + esac + + if iface_wait_online 5 $netif + then + ifconfig $netif up + if iface_has_link $netif + then + $DHCP_PROG $opts $DHCP_START $netif || echo "dhcp failed" + else + echo "Interface $netif has no link. Not running $DHCP_PROG." + fi + else + echo "Device $netif does not exist. Doing nothing." + fi } load_ipv6() { diff -Naur dracut-034/modules.d/40network/kill-dhcpcd.sh dracut-034-udhcpc/modules.d/40network/kill-dhcpcd.sh --- dracut-034/modules.d/40network/kill-dhcpcd.sh 1970-01-01 00:00:00.000000000 +0000 +++ dracut-034-udhcpc/modules.d/40network/kill-dhcpcd.sh 2014-01-17 12:09:06.153000000 +0000 @@ -0,0 +1,18 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +for f in /run/dhcpcd.*.pid /run/dhcpcd.pid; do + [ -e $f ] || continue + read PID < $f; + kill $PID >/dev/null 2>&1 +done + +sleep 0.1 + +for f in /run/dhcpcd.*.pid /run/dhcpcd.pid; do + [ -e $f ] || continue + read PID < $f; + kill -9 $PID >/dev/null 2>&1 +done + diff -Naur dracut-034/modules.d/40network/kill-udhcpc.sh dracut-034-udhcpc/modules.d/40network/kill-udhcpc.sh --- dracut-034/modules.d/40network/kill-udhcpc.sh 1970-01-01 00:00:00.000000000 +0000 +++ dracut-034-udhcpc/modules.d/40network/kill-udhcpc.sh 2014-01-17 12:07:55.368000000 +0000 @@ -0,0 +1,17 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +for f in /tmp/udhcpc.*.pid; do + [ -e $f ] || continue + read PID < $f; + kill $PID >/dev/null 2>&1 +done + +sleep 0.1 + +for f in /tmp/udhcpc.*.pid; do + [ -e $f ] || continue + read PID < $f; + kill -9 $PID >/dev/null 2>&1 +done diff -Naur dracut-034/modules.d/40network/module-setup.sh dracut-034-udhcpc/modules.d/40network/module-setup.sh --- dracut-034/modules.d/40network/module-setup.sh 2013-10-08 07:55:26.000000000 +0000 +++ dracut-034-udhcpc/modules.d/40network/module-setup.sh 2014-01-17 12:46:37.210000000 +0000 @@ -4,8 +4,9 @@ check() { local _program + . /etc/conf.d/network - for _program in ip arping dhclient ; do + for _program in ip ifconfig route arping ${DEFAULT_DHCP_PROG} ; do if ! type -P $_program >/dev/null; then derror "Could not find program \"$_program\" required by network." return 1 @@ -69,16 +70,19 @@ install() { local _arch _i _dir - inst_multiple ip arping dhclient sed + local dhcp_prog_name + . /etc/conf.d/network + dhcp_prog_name="${DEFAULT_DHCP_PROG##*/}" + + inst_multiple ip arping ${dhcp_prog_name} sed + inst_multiple ifconfig route inst_multiple -o ping ping6 inst_multiple -o brctl inst_multiple -o teamd teamdctl teamnl inst_simple /etc/libnl/classid inst_script "$moddir/ifup.sh" "/sbin/ifup" inst_script "$moddir/netroot.sh" "/sbin/netroot" - inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh" - inst_simple "$moddir/dhclient.conf" "/etc/dhclient.conf" inst_hook pre-udev 50 "$moddir/ifname-genrules.sh" inst_hook pre-udev 60 "$moddir/net-genrules.sh" inst_hook cmdline 91 "$moddir/dhcp-root.sh" @@ -89,7 +93,35 @@ inst_hook cmdline 97 "$moddir/parse-bridge.sh" inst_hook cmdline 98 "$moddir/parse-ip-opts.sh" inst_hook cmdline 99 "$moddir/parse-ifname.sh" - inst_hook cleanup 10 "$moddir/kill-dhclient.sh" + case $dhcp_prog_name in + dhclient) + inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" + inst_simple "$moddir/dhclient.conf" "/etc/dhclient.conf" + inst_hook cleanup 10 "$moddir/kill-dhclient.sh" + ;; + + udhcpc) + inst_script /usr/share/udhcpc/default.script + inst_hook cleanup 10 "$moddir/kill-udhcpc.sh" + ;; + + dhcpcd) + inst_simple /etc/dhcpcd.conf + inst_script -o /usr/lib/dhcpcd/dhcpcd-run-hooks + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/01-test + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/02-dump + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/10-mtu + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/15-timezone + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/20-resolv.conf + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/29-lookup-hostname + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/30-hostname + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/50-dhcpcd-compat + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/50-ntp.conf + inst_script -o /usr/lib/dhcpcd/dhcpcd-hooks/50-yp.conf + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh" + ;; + esac + inst_simple /etc/conf.d/network _arch=$(uname -m) diff -Naur dracut-034/modules.d/40network/net-lib.sh dracut-034-udhcpc/modules.d/40network/net-lib.sh --- dracut-034/modules.d/40network/net-lib.sh 2013-10-08 07:55:26.000000000 +0000 +++ dracut-034-udhcpc/modules.d/40network/net-lib.sh 2014-01-17 12:37:07.880000000 +0000 @@ -119,6 +119,8 @@ [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts # set up resolv.conf [ -e /tmp/net.$netif.resolv.conf ] && \ cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf @@ -166,6 +168,15 @@ for f in /tmp/dhclient.$i.*; do [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.} done + for f in /tmp/udhcpc.$i.*; do + [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/udhcpc.} + done + for f in /run/dhcpcd.$i.*; do + [ -f $f ] && cp -f $f /tmp/net.${f#/run/dhcpcd.} + done + for f in /var/lib/dhcpcd/dhcpcd.$i.*; do + [ -f $f ] && cp -f $f /tmp/net.${f#/var/lib/dhcpcd/dhcpcd.} + done done echo $IFACES > /tmp/.net.ifaces.new mv /tmp/.net.ifaces.new /tmp/net.ifaces @@ -483,3 +494,20 @@ hostname() { cat /proc/sys/kernel/hostname } + +iface_wait_online() +{ + local timeout="$1" + local iface="$2" + + (( timeout *= 10 )) + + while [ ! -e /sys/class/net/$iface ] + do + (( timeout-- > 0 )) || return 1 + echo "Waiting 0.1 seconds for device '$iface' -- timeout->'$timeout'" + sleep 0.1 + done + + return 0 +} diff -Naur dracut-034/modules.d/40network/netroot.sh dracut-034-udhcpc/modules.d/40network/netroot.sh --- dracut-034/modules.d/40network/netroot.sh 2013-10-08 07:55:26.000000000 +0000 +++ dracut-034-udhcpc/modules.d/40network/netroot.sh 2014-01-17 12:38:05.832000000 +0000 @@ -38,6 +38,8 @@ if [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] ; then # Load dhcp options [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts + [ -e /tmp/udhcpc.$netif.dhcpopts ] && . /tmp/udhcpc.$netif.dhcpopts + [ -e /tmp/dhcpcd.$netif.dhcpopts ] && . /tmp/dhcpcd.$netif.dhcpopts # If we have a specific bootdev with no dhcpoptions or empty root-path, # we die. Otherwise we just warn