#!/sbin/runscript # Copyright (c) 2004-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header$ # Contributed by Roy Marples (uberlord@gentoo.org) # Many thanks to Aron Griffis (agriffis@gentoo.org) # for help, ideas and patches #NB: Config is in /etc/conf.d/net if [[ -n ${NET_DEBUG} ]]; then set -x devnull=/dev/stderr else devnull=/dev/null fi # For pcmcia users. note that pcmcia must be added to the same # runlevel as the net.* script that needs it. depend() { use coldplug hotplug pcmcia usb isdn wlan # Load any custom depend functions for the given interface # For example, br0 may need eth0 and eth1 local iface=${myservice##*.} [[ $( type -t depend_${iface} ) == "function" ]] && depend_${iface} } # Define where our modules are MODULES_DIR=/lib/rcscripts/net.modules.d # Load some functions shared between ourselves and our dhcp helpers source ${MODULES_DIR}/helpers.d/functions # Make some wrappers to fudge after/before/need/use depend flags. # These are callbacks so mods[i] will be set. after() { local x="$*" [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs ) eval "${MODULE}_after() { echo \"$x\"; }" } before() { local x="$*" [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs ) eval "${MODULE}_before() { echo \"$x\"; }" } need() { local x="$*" [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs ) eval "${MODULE}_need() { echo \"$x\"; }" } installed() { local x="$*" [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs ) # We deliberately misspell this as _installed will probably be used # at some point eval "${MODULE}_instlled() { echo \"$x\"; }" } sort() { LC_ALL=C /bin/sort "$@" } # void module_class_wrap(char *module, char *provides) # Setup class wrappers: interface_up -> iproute2_up, for example module_class_wrap() { local module=${1} provides=${2} x # Don't wrap functions if another module already has [[ $( type -t ${provides}_provides ) == function ]] && return for x in $( typeset -f | grep -o ^${module}_'[^ ]*' ); do eval "${provides}${x#${module}}() { ${x} \"\$@\"; }" done } # bool module_load_minimum(char *module) # # Does the minimum checking on a module - even when forcing module_load_minimum() { local f=${1} MODULE=${1##*/} if [[ ! -f ${f} ]]; then eerror "${f} does not exist" return 1 fi if ! source ${f} ; then eerror "${MODULE} failed a sanity check" return 1 fi for f in check_installed provides check_depends depend; do [[ $( type -t ${MODULE}_${f} ) == function ]] && continue eerror "${MODULE} does not support the required function ${f}" return 1 done # Wrap our before/after/need/use functions ${MODULE}_depend return 0 } # bool modules_load_auto() # # Load and check each module for sanity # If the module is not installed, the functions are to be removed modules_load_auto() { local e f i j beforefuncs afterfuncs diffs unload # Populate the MODULES array MODULES=( $( find ${MODULES_DIR}/ -maxdepth 1 -type f ! -name ".*" | sort ) ) # Each of these sources into the global namespace, so it's # important that module functions and variables are prefixed with # the module name, for example iproute2_ beforefuncs="$( typeset -F )" j=${#MODULES[@]} loaded_interface=false for (( i=0; i