# Copyright 2004-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Contributed by Roy Marples (uberlord@gentoo.org) # Fix any potential localisation problems # Note that LC_ALL trumps LC_anything_else according to locale(7) udhcpc() { LC_ALL=C /bin/busybox udhcpc "$@" } # void busybox_depend(void) # # Sets up the dependancies for the module busybox_depend() { after interface provide dhcp functions interface_exists interface_get_address } # void busybox_expose(void) # # Expose variables that can be configured busybox_expose() { variables busybox dhcp } # bool busybox_check_installed(void) # # Returns 1 if busybox is installed, otherwise 0 busybox_check_installed() { [[ -x /bin/busybox ]] && /bin/busybox | grep -q udhcpc && return 0 ${1:-false} && eerror "For DHCP (busybox) support, emerge sys-apps/busybox with udhcpc built-in" return 1 } # bool busybox_stop(char *iface) # # Stops busybox running on an interface # Return 1 if we fail to stop busybox (if it's running) otherwise 0 busybox_stop() { local iface="$1" pidfile="/var/run/busybox-udhcpc-$1.pid" d= [[ ! -f ${pidfile} ]] && return 0 ebegin "Stopping busybox on ${iface}" local pid=$(<"${pidfile}") e=true local ifvar=$(bash_variable "${iface}") d="dhcp_${ifvar}" [[ -z ${!d} ]] && d="dhcp" if [[ " ${!d} " == *" release "* ]]; then kill -s USR2 "${pid}" &>/dev/null [[ -f "/var/cache/busybox-udhcpc-${iface}.lease" ]] \ && rm "/var/cache/busybox-udhcpc-${iface}.lease" fi start-stop-daemon --stop --exec /bin/busybox --pidfile "${pidfile}" eend $? || return 1 [[ -e /var/run/busybox-udhcpc-"${iface}".conf ]] \ && rm -f /var/run/busybox-udhcpc-"${iface}".conf return 0 } # bool busybox_start(char *iface) # # Start DHCP on an interface by calling busybox $iface $options # # Returns 0 (true) when a DHCP address is obtained, otherwise 1 busybox_start() { local iface="$1" opts= pidfile="/var/run/busybox-udhcpc-$1.pid" local cachefile="/var/cache/busybox-udhcpc-$1.lease" d interface_exists "${iface}" true || return 1 local ifvar=$(bash_variable "${iface}" ) opts= opts="busybox_${ifvar}" opts="${busybox} ${!opts}" d="dhcp_${ifvar}" [[ -z ${!d} ]] && d="dhcp" if [[ " ${!d} " != *" nosendhost "* ]]; then if [[ " ${opts} " != *" -"[hH]" "* && " ${opts} " != *" --hostname="* ]] ; then local hname=$(hostname) [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \ && opts="${opts} --hostname=${hname}" fi fi # Use legacy stuff to pass extra configurations. # As this doesn't require the Gentoo specific patch to busybox. local conf=/var/run/busybox-udhcpc-"${iface}".conf echo -n >"$conf" if [[ " ${!d} " == *" nogateway "* ]] ; then echo "PEER_ROUTERS=no" >>"$conf" else echo "PEER_ROUTERS=yes" >>"$conf" fi if [[ " ${!d} " == *" nodns "* ]] ; then echo "PEER_DNS=no" >>"$conf" else echo "PEER_DNS=yes" >>"$conf" fi if [[ " ${!d} " == *" nontp "* ]] ; then echo "PEER_NTP=no" >>"$conf" else echo "PEER_NTP=yes" >>"$conf" fi local metric="metric_${ifvar}" if [[ -n ${!metric} ]] ; then echo "IF_METRIC=${!metric}" >>"$conf" fi # Bring up DHCP for this interface (or alias) ebegin "Running busybox udhcpc" # Try and load the cache if it exists if [[ -f ${cachefile} ]]; then if [[ " ${opts}" != *" --request="* && " ${opts} " != *" -r "* ]]; then local x=$(<"${cachefile}") # Check for a valid ip [[ ${x} == *.*.*.* ]] && opts="${opts} --request=${x}" fi fi # Don't use s-s-d if the user wants to quit on lease. if [[ " ${opts} " == *" -q "* || " ${opts} " == *" --quit "* ]]; then x="/bin/busybox udhcpc" else x="start-stop-daemon --start --exec /bin/busybox \ --pidfile \"${pidfile}\" -- udhcpc" fi eval "${x}" "${opts}" --interface="${iface}" --now \ --script=/lib/rcscripts/sh/udhcpc.sh \ --pidfile="${pidfile}" >/dev/null eend $? || return 1 # DHCP succeeded, show address retrieved local addr=$(interface_get_address "${iface}") einfo "${iface} received address ${addr}" return 0 } # vim: set ts=4 :