change udhcpc support to busybox udhcpc

This updates the udhcpc support to use busybox's udhcpc instead of the
stand alone version.

I would like to thank jackieku <kjackie@gmail.com> for assisting with
this update.

X-Gentoo-Bug: 205286
X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=205286
This commit is contained in:
William Hubbs 2011-04-26 11:05:19 -05:00
parent 8202e7dce4
commit b712a9161f
5 changed files with 142 additions and 19 deletions

View File

@ -414,7 +414,7 @@
# dhclient: emerge net-misc/dhcp # dhclient: emerge net-misc/dhcp
# dhcpcd: emerge net-misc/dhcpcd # dhcpcd: emerge net-misc/dhcpcd
# pump: emerge net-misc/pump # pump: emerge net-misc/pump
# udhcpc: emerge net-misc/udhcp # udhcpc: emerge sys-apps/busybox
# If you have more than one DHCP client installed, you need to specify which # If you have more than one DHCP client installed, you need to specify which
# one to use - otherwise we default to dhcpcd if available. # one to use - otherwise we default to dhcpcd if available.

View File

@ -3,14 +3,13 @@
udhcpc_depend() udhcpc_depend()
{ {
program start /sbin/udhcpc program start /bin/busybox
after interface after interface
provide dhcp provide dhcp
} }
_config_vars="$_config_vars dhcp udhcpc" _config_vars="$_config_vars dhcp udhcpc"
# WARNING:- The relies heavily on Gentoo patches and scripts for udhcpc
udhcpc_start() udhcpc_start()
{ {
local args= opt= opts= pidfile="/var/run/udhcpc-${IFACE}.pid" local args= opt= opts= pidfile="/var/run/udhcpc-${IFACE}.pid"
@ -22,17 +21,22 @@ udhcpc_start()
eval opts=\$dhcp_${IFVAR} eval opts=\$dhcp_${IFVAR}
[ -z "${opts}" ] && opts=${dhcp} [ -z "${opts}" ] && opts=${dhcp}
# This omits the Gentoo specific patch to busybox,
# but it creates temporary files.
# We can move this stuff to udhcpc hook script to avoid that, should we do?
local conf="/var/run/udhcpc-${IFACE}.conf"
echo -n >"$conf"
# Map some generic options to dhcpcd # Map some generic options to dhcpcd
for opt in ${opts}; do for opt in ${opts}; do
case "${opt}" in case "${opt}" in
nodns) args="${args} --env PEER_DNS=no";; nodns) echo "PEER_DNS=no" >>"$conf" ;;
nontp) args="${args} --env PEER_NTP=no";; nontp) echo "PEER_NTP=no" >>"$conf" ;;
nogateway) args="${args} --env PEER_ROUTERS=no";; nogateway) echo "PEER_ROUTERS=no" >>"$conf" ;;
nosendhost) sendhost=false; nosendhost) sendhost=false;
esac esac
done done
[ "${metric:-0}" != "0" ] && args="${args} --env IF_METRIC=${metric}" [ "${metric:-0}" != "0" ] && echo "IF_METRIC=${metric}" >>"$conf"
ebegin "Running udhcpc" ebegin "Running udhcpc"
@ -51,9 +55,9 @@ udhcpc_start()
fi fi
case " ${args} " in case " ${args} " in
*" --quit "*|*" -q "*) x="/sbin/udhcpc";; *" --quit "*|*" -q "*) x="/bin/busybox udhcpc";;
*) x="start-stop-daemon --start --exec /sbin/udhcpc \ *) x="start-stop-daemon --start --exec /bin/busybox \
--pidfile \"${pidfile}\" --";; --pidfile \"${pidfile}\" -- udhcpc";;
esac esac
case " ${args} " in case " ${args} " in
@ -68,11 +72,8 @@ udhcpc_start()
;; ;;
esac esac
local script="${RC_LIBEXECDIR}"/sh/udhcpc.h
[ -x "${script}" ] || script=/lib/rcscripts/sh/udhcpc.sh
eval "${x}" "${args}" --interface="${IFACE}" --now \ eval "${x}" "${args}" --interface="${IFACE}" --now \
--script="${script}" \ --script="${RC_LIBEXECDIR}/sh/udhcpc-hook.sh" \
--pidfile="${pidfile}" >/dev/null --pidfile="${pidfile}" >/dev/null
eend $? || return 1 eend $? || return 1
@ -92,14 +93,18 @@ udhcpc_stop()
ebegin "Stopping udhcpc on ${IFACE}" ebegin "Stopping udhcpc on ${IFACE}"
case " ${opts} " in case " ${opts} " in
*" release "*) *" release "*)
start-stop-daemon --stop --quiet --oknodo --signal USR2 \ start-stop-daemon --stop --quiet --signal USR2 \
--exec /sbin/udhcpc --pidfile "${pidfile}" --exec /bin/busybox --pidfile "${pidfile}"
if [ -f /var/cache/udhcpc-"${IFACE}".lease ]; then if [ -f /var/cache/udhcpc-"${IFACE}".lease ]; then
rm -f /var/cache/udhcpc-"${IFACE}".lease rm -f /var/cache/udhcpc-"${IFACE}".lease
fi fi
;; ;;
esac esac
start-stop-daemon --stop --exec /sbin/udhcpc --pidfile "${pidfile}" start-stop-daemon --stop --exec /bin/busybox --pidfile "${pidfile}"
eend $? eend $?
if [ -e "/var/run/udhcpc-${IFACE}.conf" ]; then
rm -f "/var/run/udhcpc-${IFACE}.conf"
fi
} }

1
sh/.gitignore vendored
View File

@ -7,3 +7,4 @@ init.sh
init-early.sh init-early.sh
ifwatchd-carrier.sh ifwatchd-carrier.sh
ifwatchd-nocarrier.sh ifwatchd-nocarrier.sh
udhcpc-hook.sh

View File

@ -1,5 +1,5 @@
SRCS+= init.sh.in init-early.sh.in SRCS+= init.sh.in init-early.sh.in udhcpc-hook.sh.in
BIN+= init-early.sh BIN+= init-early.sh udhcpc-hook.sh
.SUFFIXES: .sh.Linux.in .SUFFIXES: .sh.Linux.in
.sh.Linux.in.sh: .sh.Linux.in.sh:

117
sh/udhcpc-hook.sh.in Normal file
View File

@ -0,0 +1,117 @@
#!@SHELL@
# busybox udhcp setup script
PATH=/bin:/usr/bin:/sbin:/usr/sbin
peer_var()
{
[ -n "$1" ] && [ "$1" != "yes" ]
}
update_dns()
{
peer_var "${PEER_DNS}" && return
[ -z "${domain}" ] && [ -z "${dns}" ] && return
conf="# Generated by udhcpc for ${interface}\n"
[ -n "${domain}" ] && conf="${conf}search ${domain}\n"
for i in ${dns} ; do
conf="${conf}nameserver ${i}\n"
done
if [ -x /sbin/resolvconf ] ; then
printf "${conf}" | resolvconf -a ${interface}
else
printf "${conf}" > /etc/resolv.conf
chmod 644 /etc/resolv.conf
fi
}
update_ntp()
{
peer_var "${PEER_NTP}" && return
[ -z "${ntpsrv}" ] && return
conf="# Generated by udhcpc for interface ${interface}\n"
conf="${conf}restrict default noquery notrust nomodify\n"
conf="${conf}restrict 127.0.0.1\n"
for i in ${ntpsrv} ; do
conf="${conf}restrict ${i} nomodify notrap noquery\n"
conf="${conf}server ${i}\n"
done
conf="${conf}driftfile /var/lib/ntp/ntp.drift\n"
conf="${conf}logfile /var/log/ntp.log\n"
printf "${conf}" > /etc/ntp.conf
chmod 644 /etc/ntp.conf
}
update_hostname()
{
peer_var "${PEER_HOSTNAME}" && return
[ -z "${hostname}" ] && return
myhost="$(hostname)"
[ -z "${myhost}" ] || [ "${myhost}" = "(none)" ] && hostname "${hostname}"
}
update_interface()
{
[ -n "${broadcast}" ] && broadcast="broadcast ${broadcast}"
[ -n "${subnet}" ] && netmask="netmask ${subnet}"
[ -n "${mtu}" ] && mtu="mtu ${mtu}"
ifconfig "${interface}" ${ip} ${broadcast} ${netmask} ${mtu}
}
update_routes()
{
peer_var "${PEER_ROUTERS}" && return
if [ -n "${router}" ] ; then
metric=
[ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}"
for i in ${router} ; do
route add default gw "${i}" ${metric} dev "${interface}"
done
fi
}
deconfig()
{
ifconfig "${interface}" 0.0.0.0
if ! peer_var "${PEER_ROUTERS}" ; then
while route del default dev "${interface}" >& /dev/null; do
:
done
fi
if ! peer_var "${PEER_DNS}" ; then
[ -x /sbin/resolvconf ] && resolvconf -d "${interface}"
fi
}
if [ -r "/var/run/udhcpc-${interface}.conf" ]; then
. "/var/run/udhcpc-${interface}.conf"
fi
case "$1" in
bound|renew)
update_hostname
update_interface
update_routes
update_dns
update_ntp
;;
deconfig|leasefail)
deconfig
;;
nak)
echo "nak: ${message}"
;;
*)
echo "unknown option $1" >&2
echo "Usage: $0 {bound|deconfig|leasefail|nak|renew}" >&2
exit 1
;;
esac
exit 0