summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2011-04-26 11:05:19 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2011-04-26 15:25:08 -0500
commitb712a9161f3d51566f44d48909776649d70116d0 (patch)
tree8f4c8dfa07da605e21242e142ab4f3dc929d6dc5
parent8202e7dce4065b79c272dc11941b371a9c4f99fc (diff)
downloadopenrc-b712a9161f3d51566f44d48909776649d70116d0.tar.gz
openrc-b712a9161f3d51566f44d48909776649d70116d0.tar.bz2
openrc-b712a9161f3d51566f44d48909776649d70116d0.tar.xz
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
-rw-r--r--doc/net.example.Linux.in2
-rw-r--r--net/udhcpc.sh37
-rw-r--r--sh/.gitignore1
-rw-r--r--sh/Makefile.Linux4
-rw-r--r--sh/udhcpc-hook.sh.in117
5 files changed, 142 insertions, 19 deletions
diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 5d7c49f..952f8eb 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -414,7 +414,7 @@
# dhclient: emerge net-misc/dhcp
# dhcpcd: emerge net-misc/dhcpcd
# 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
# one to use - otherwise we default to dhcpcd if available.
diff --git a/net/udhcpc.sh b/net/udhcpc.sh
index 75cbf09..bb4238a 100644
--- a/net/udhcpc.sh
+++ b/net/udhcpc.sh
@@ -3,14 +3,13 @@
udhcpc_depend()
{
- program start /sbin/udhcpc
+ program start /bin/busybox
after interface
provide dhcp
}
_config_vars="$_config_vars dhcp udhcpc"
-# WARNING:- The relies heavily on Gentoo patches and scripts for udhcpc
udhcpc_start()
{
local args= opt= opts= pidfile="/var/run/udhcpc-${IFACE}.pid"
@@ -22,17 +21,22 @@ udhcpc_start()
eval opts=\$dhcp_${IFVAR}
[ -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
for opt in ${opts}; do
case "${opt}" in
- nodns) args="${args} --env PEER_DNS=no";;
- nontp) args="${args} --env PEER_NTP=no";;
- nogateway) args="${args} --env PEER_ROUTERS=no";;
+ nodns) echo "PEER_DNS=no" >>"$conf" ;;
+ nontp) echo "PEER_NTP=no" >>"$conf" ;;
+ nogateway) echo "PEER_ROUTERS=no" >>"$conf" ;;
nosendhost) sendhost=false;
esac
done
- [ "${metric:-0}" != "0" ] && args="${args} --env IF_METRIC=${metric}"
+ [ "${metric:-0}" != "0" ] && echo "IF_METRIC=${metric}" >>"$conf"
ebegin "Running udhcpc"
@@ -51,9 +55,9 @@ udhcpc_start()
fi
case " ${args} " in
- *" --quit "*|*" -q "*) x="/sbin/udhcpc";;
- *) x="start-stop-daemon --start --exec /sbin/udhcpc \
- --pidfile \"${pidfile}\" --";;
+ *" --quit "*|*" -q "*) x="/bin/busybox udhcpc";;
+ *) x="start-stop-daemon --start --exec /bin/busybox \
+ --pidfile \"${pidfile}\" -- udhcpc";;
esac
case " ${args} " in
@@ -68,11 +72,8 @@ udhcpc_start()
;;
esac
- local script="${RC_LIBEXECDIR}"/sh/udhcpc.h
- [ -x "${script}" ] || script=/lib/rcscripts/sh/udhcpc.sh
-
eval "${x}" "${args}" --interface="${IFACE}" --now \
- --script="${script}" \
+ --script="${RC_LIBEXECDIR}/sh/udhcpc-hook.sh" \
--pidfile="${pidfile}" >/dev/null
eend $? || return 1
@@ -92,14 +93,18 @@ udhcpc_stop()
ebegin "Stopping udhcpc on ${IFACE}"
case " ${opts} " in
*" release "*)
- start-stop-daemon --stop --quiet --oknodo --signal USR2 \
- --exec /sbin/udhcpc --pidfile "${pidfile}"
+ start-stop-daemon --stop --quiet --signal USR2 \
+ --exec /bin/busybox --pidfile "${pidfile}"
if [ -f /var/cache/udhcpc-"${IFACE}".lease ]; then
rm -f /var/cache/udhcpc-"${IFACE}".lease
fi
;;
esac
- start-stop-daemon --stop --exec /sbin/udhcpc --pidfile "${pidfile}"
+ start-stop-daemon --stop --exec /bin/busybox --pidfile "${pidfile}"
eend $?
+
+ if [ -e "/var/run/udhcpc-${IFACE}.conf" ]; then
+ rm -f "/var/run/udhcpc-${IFACE}.conf"
+ fi
}
diff --git a/sh/.gitignore b/sh/.gitignore
index f416d5b..bc5c074 100644
--- a/sh/.gitignore
+++ b/sh/.gitignore
@@ -7,3 +7,4 @@ init.sh
init-early.sh
ifwatchd-carrier.sh
ifwatchd-nocarrier.sh
+udhcpc-hook.sh
diff --git a/sh/Makefile.Linux b/sh/Makefile.Linux
index bb48f42..fb9208c 100644
--- a/sh/Makefile.Linux
+++ b/sh/Makefile.Linux
@@ -1,5 +1,5 @@
-SRCS+= init.sh.in init-early.sh.in
-BIN+= init-early.sh
+SRCS+= init.sh.in init-early.sh.in udhcpc-hook.sh.in
+BIN+= init-early.sh udhcpc-hook.sh
.SUFFIXES: .sh.Linux.in
.sh.Linux.in.sh:
diff --git a/sh/udhcpc-hook.sh.in b/sh/udhcpc-hook.sh.in
new file mode 100644
index 0000000..a14cac9
--- /dev/null
+++ b/sh/udhcpc-hook.sh.in
@@ -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