diff -Naur dracut-037/modules.d/40network/dhcpcd-script.sh dracut-037-udhcpc/modules.d/40network/dhcpcd-script.sh --- dracut-037/modules.d/40network/dhcpcd-script.sh 1970-01-01 01:00:00.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/dhcpcd-script.sh 2014-07-11 18:22:19.200620077 +0200 @@ -0,0 +1,30 @@ +# start netroot + +PATH=/usr/sbin:/usr/bin:/sbin:/bin + +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh + +# We already need a set netif here +netif="$interface" + +# Huh? Interface configured? +[ -f "/tmp/net.$netif.up" ] && exit 0 + +if [ "$reason" = "BOUND" ]; then + set | while read line; do + [ "${line#new_}" = "$line" ] && continue + echo "$line" + done >/tmp/dhcpcd.$netif.dhcpopts + + { + echo '. /lib/net-lib.sh' + echo "setup_net $netif" + echo "source_hook initqueue/online $netif" + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" + } > $hookdir/initqueue/setup_net_$netif.sh + + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhcpcd-$netif.sh + >/tmp/net.$netif.up +fi diff -Naur dracut-037/modules.d/40network/ifup.sh dracut-037-udhcpc/modules.d/40network/ifup.sh --- dracut-037/modules.d/40network/ifup.sh 2014-03-19 17:16:08.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/ifup.sh 2014-07-11 18:21:46.055620310 +0200 @@ -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 @@ -90,6 +107,8 @@ # Run dhclient do_dhcp() { + local opts + # dhclient-script will mark the netif up and generate the online # event for nfsroot # XXX add -V vendor class and option parsing per kernel @@ -100,9 +119,27 @@ echo "No carrier detected" return 1 fi - 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 + + echo "Starting dhcp ($DHCP_PROG_NAME) for interface $netif" + $DHCP_PROG $opts $DHCP_START $netif || echo "dhcp failed" } load_ipv6() { diff -Naur dracut-037/modules.d/40network/kill-dhcpcd.sh dracut-037-udhcpc/modules.d/40network/kill-dhcpcd.sh --- dracut-037/modules.d/40network/kill-dhcpcd.sh 1970-01-01 01:00:00.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/kill-dhcpcd.sh 2014-07-11 18:21:46.056620310 +0200 @@ -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 /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 /tmp/dhcpcd.*.pid /run/dhcpcd.pid; do + [ -e $f ] || continue + read PID < $f; + kill -9 $PID >/dev/null 2>&1 +done diff -Naur dracut-037/modules.d/40network/kill-udhcpc.sh dracut-037-udhcpc/modules.d/40network/kill-udhcpc.sh --- dracut-037/modules.d/40network/kill-udhcpc.sh 1970-01-01 01:00:00.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/kill-udhcpc.sh 2014-07-11 18:21:46.056620310 +0200 @@ -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-037/modules.d/40network/module-setup.sh dracut-037-udhcpc/modules.d/40network/module-setup.sh --- dracut-037/modules.d/40network/module-setup.sh 2014-03-19 17:16:08.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/module-setup.sh 2014-07-11 18:24:15.631619260 +0200 @@ -5,8 +5,9 @@ # called by dracut check() { local _program + . /etc/conf.d/network - require_binaries ip arping dhclient || return 1 + require_binaries ip ifconfig route arping $DEFAULT_DHCP_PROG || return 1 return 255 } @@ -72,16 +73,20 @@ # called by dracut install() { local _arch _i _dir - inst_multiple ip arping dhclient sed + local _dhcp_prog_name + local _file + . /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" @@ -92,7 +97,29 @@ 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 "$moddir/udhcpc-script.sh" "/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 + for _file in $(find /usr/lib/dhcpcd/dhcpcd-hooks -type f); do + inst_simple -o $_file + done + inst_simple "$moddir/dhcpcd-script.sh" "/usr/lib/dhcpcd/dhcpcd-hooks/90-netroot" + inst_hook cleanup 10 "$moddir/kill-dhcpcd.sh" + ;; + esac + inst_simple /etc/conf.d/network _arch=$(uname -m) diff -Naur dracut-037/modules.d/40network/net-lib.sh dracut-037-udhcpc/modules.d/40network/net-lib.sh --- dracut-037/modules.d/40network/net-lib.sh 2014-03-19 17:16:08.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/net-lib.sh 2014-07-11 18:21:46.057620310 +0200 @@ -99,6 +99,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 @@ -148,6 +150,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 diff -Naur dracut-037/modules.d/40network/netroot.sh dracut-037-udhcpc/modules.d/40network/netroot.sh --- dracut-037/modules.d/40network/netroot.sh 2014-03-19 17:16:08.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/netroot.sh 2014-07-11 18:21:46.057620310 +0200 @@ -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 diff -Naur dracut-037/modules.d/40network/udhcpc-script.sh dracut-037-udhcpc/modules.d/40network/udhcpc-script.sh --- dracut-037/modules.d/40network/udhcpc-script.sh 1970-01-01 01:00:00.000000000 +0100 +++ dracut-037-udhcpc/modules.d/40network/udhcpc-script.sh 2014-07-11 18:22:16.296620098 +0200 @@ -0,0 +1,100 @@ +#!/bin/sh + +# global options passed by udhcpc +# what to run +# $1 - which command to run, possible are: bound|deconfig|nak|renew +# router - routers address +# subnet - the subnet +# dhcptype - type of dhcp +# interface - which iface gets configured +# serverid - ip of the dhcd server +# dns - dns to use +# ip - ip-address to use +# lease - lease time of a dhcp configuration +# mask - network mask to use + +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh + +# We already need a set netif here +netif="${interface}" + +# Huh? Interface configured? + [ -f "/tmp/net.$netif.up" ] && exit 0 + +# renew dhcp leases +bound() +{ + local RESOLV_CONF="/etc/resolv.conf" + local BROADCAST + local NETMASK + local i + + [[ -n ${broadcast} ]] && BROADCAST="broadcast ${broadcast}" + [[ -n ${subnet} ]] && NETMASK="netmask ${subnet}" + + /sbin/ifconfig ${interface} ${ip} ${BROADCAST} ${NETMASK} + + if [ -n "${router}" ] + then + echo "deleting routers" + while /sbin/route del default gw 0.0.0.0 dev ${interface} + do : + done + + metric=0 + for i in ${router} + do + /sbin/route add default gw ${i} dev ${interface} metric $((metric++)) + done + fi + + echo -n > ${RESOLV_CONF} + [[ -n ${domain} ]] && echo "domain ${domain}" >> ${RESOLV_CONF} + for i in ${dns} + do + echo adding dns ${i} + echo "nameserver ${i}" >> ${RESOLV_CONF} + done + + set | while read line; do + [ "${line#new_}" = "$line" ] && continue + echo "$line" + done >/tmp/udhcpc.$netif.dhcpopts + + { + echo '. /lib/net-lib.sh' + echo "setup_net $netif" + echo "source_hook initqueue/online $netif" + [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" + echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh" + } > $hookdir/initqueue/setup_net_$netif.sh + + echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/udhcpc-$netif.sh + >/tmp/net.$netif.up +} + +renew() +{ + # same as bound() + bound +} + +deconfig() +{ + /sbin/ifconfig ${interface} 0.0.0.0 +} + +# what to do if a dhcp request failed +nak() +{ + echo "Received a NAK: ${message}" +} + + +case $1 in + bound) bound ;; + renew) renew ;; + deconfig) deconfig ;; + nak) nak ;; +esac