#!/sbin/runscript #NB: Config is in /etc/conf.d/ifplugd #From /etc/init.d/net.eth0: if [[ -n "$NET_DEBUG" ]]; then set -x devnull=/dev/stderr else devnull=/dev/null fi #From /etc/init.d/net.eth0: # Fix bug 50039 (init.d/net.eth0 localization) # Some other commands in this script might need to be wrapped, but # we'll get them one-by-one. Note that LC_ALL trumps LC_anything_else # according to locale(7) ifconfig() { LC_ALL=C /sbin/ifconfig "$@" } # ifplugd_preup: If the interface is being managed by ifplugd, then it has # been left up, but unconfigured. We bring it down here to ensure that it gets # assigned the proper default IPV6 address and to ensure that it gets # configured properly. ifplugd_preup() { local IFACE=${1} status_iface # Unlike status_IFACE in net.eth0, for ifplugd interfaces, they are # only considered up if they have an address. We check here for such # interfaces and leave them up if they are already configured. status_iface="$(ifconfig ${1} 2>${devnull} | \ gawk '/addr:/{a=1}/ UP /{ if (a == 1) print "up"}')" if [[ status_iface != "up" && -r /etc/conf.d/ifplugd && \ -x /etc/init.d/ifplugd ]] && service_started ifplugd ; then . /etc/conf.d/ifplugd if [[ "${INTERFACES}" = "auto" || \ "${INTERFACES/.*${IFACE}.*}" = "${IFACE}" ]] ; then if [[ "${2}" != "-q" ]] ; then ebegin "Taking ${IFACE} down to be configured" fi ifconfig ${IFACE} down if [[ "${2}" != "-q" ]] ; then eend $? fi fi fi } # ifplugd_postdown: After an interface is brought down, if the interface is # being managed by ifplugd, and ifplugd is running, then we leave it up, but # unconfigured, so that ifplugd can receive events from it. ifplugd_postdown() { local IFACE="${1}" inet6 x if [[ -r /etc/conf.d/ifplugd && -x /etc/init.d/ifplugd ]] && \ service_started ifplugd ; then . /etc/conf.d/ifplugd if [[ "${INTERFACES}" = "auto" || \ "${INTERFACES/.*${IFACE}.*}" = "${IFACE}" ]] ; then if [[ "${2}" != "-q" ]] ; then ebegin "Bringing ${IFACE} up unconfigured to \ listen for link beat events" fi ifconfig "${IFACE}" 0.0.0.0 ifconfig "${IFACE}" up # Delete the default inet6 address for this interface. inet6="$(ifconfig ${IFACE} | \ awk '$1 == "inet6" {print $3}')" if [[ -n "${inet6}" ]]; then for x in ${inet6}; do ifconfig "${IFACE}" inet6 del "${x}" done fi if [[ "${2}" != "-q" ]] ; then # Report success if the interface is up. [[ "$(ifconfig ${IFACE} 2>${devnull} | \ gawk '$1 == "UP" {print "up"}')" = "up" ]] eend $? fi fi fi }