Correct tabs

This commit is contained in:
Roy Marples 2007-05-02 11:04:52 +00:00
parent 82361c0feb
commit d599a40680

482
sh/net.sh
View File

@ -9,13 +9,13 @@ _config_vars="config routes"
[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND=false [ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND=false
depend() { depend() {
local IFACE=${SVCNAME#*.} local IFACE=${SVCNAME#*.}
local IFVAR=$(echo -n "${IFACE}" | sed -e 's/[^[:alnum:]]/_/g') local IFVAR=$(echo -n "${IFACE}" | sed -e 's/[^[:alnum:]]/_/g')
need localmount need localmount
after bootmisc after bootmisc
provide net provide net
case "${IFACE}" in case "${IFACE}" in
lo|lo0) ;; lo|lo0) ;;
*) *)
after net.lo net.lo0 after net.lo net.lo0
@ -31,189 +31,189 @@ depend() {
eval prov=\$RC_PROVIDE_${IFVAR} eval prov=\$RC_PROVIDE_${IFVAR}
[ -n "${prov}" ] && provide ${prov} [ -n "${prov}" ] && provide ${prov}
;; ;;
esac esac
} }
_shell_var() { _shell_var() {
echo -n "$1" | sed -e 's/[^[:alnum:]]/_/g' echo -n "$1" | sed -e 's/[^[:alnum:]]/_/g'
} }
# Credit to David Leverton for this function which handily maps a bash array # Credit to David Leverton for this function which handily maps a bash array
# structure to positional parameters so existing configs work :) # structure to positional parameters so existing configs work :)
# We'll deprecate arrays at some point though. # We'll deprecate arrays at some point though.
_get_array() { _get_array() {
if [ -n "${BASH}" ] ; then if [ -n "${BASH}" ] ; then
case "$(declare -p "$1" 2>/dev/null)" in case "$(declare -p "$1" 2>/dev/null)" in
"declare -a "*) "declare -a "*)
echo "set -- \"\${$1[@]}\"" echo "set -- \"\${$1[@]}\""
return return
;; ;;
esac esac
fi fi
echo "eval set -- \"\$$1\"" echo "eval set -- \"\$$1\""
} }
_wait_for_carrier() { _wait_for_carrier() {
local timeout= efunc=einfon local timeout= efunc=einfon
_has_carrier && return 0 _has_carrier && return 0
eval timeout=\$carrier_timeout_${IFVAR} eval timeout=\$carrier_timeout_${IFVAR}
timeout=${timeout:-${carrier_timeout:-5}} timeout=${timeout:-${carrier_timeout:-5}}
# Incase users don't want this nice feature ... # Incase users don't want this nice feature ...
[ ${timeout} -le 0 ] && return 0 [ ${timeout} -le 0 ] && return 0
[ -n "${RC_EBUFFER}" -o "${RC_PREFIX}" = "yes" ] && efunc=einfo [ -n "${RC_EBUFFER}" -o "${RC_PREFIX}" = "yes" ] && efunc=einfo
${efunc} "Waiting for carrier (${timeout} seconds) " ${efunc} "Waiting for carrier (${timeout} seconds) "
while [ ${timeout} -gt 0 ] ; do while [ ${timeout} -gt 0 ] ; do
sleep 1 sleep 1
if _has_carrier ; then if _has_carrier ; then
[ -z "${RC_EBUFFER}" ] && echo [ -z "${RC_EBUFFER}" ] && echo
eend 0 eend 0
return 0 return 0
fi fi
timeout=$((${timeout} - 1)) timeout=$((${timeout} - 1))
[ -z "${RC_EBUFFER}" -a "${RC_PREFIX}" != "yes" ] && printf "." [ -z "${RC_EBUFFER}" -a "${RC_PREFIX}" != "yes" ] && printf "."
done done
[ -z "${RC_EBUFFER}" -a "${RC_PREFIX}" != "yes" ] && echo [ -z "${RC_EBUFFER}" -a "${RC_PREFIX}" != "yes" ] && echo
eend 1 eend 1
return 1 return 1
} }
_netmask2cidr() { _netmask2cidr() {
local i= len=0 local i= len=0
local IFS=. local IFS=.
for i in $1; do for i in $1; do
while [ ${i} != "0" ] ; do while [ ${i} != "0" ] ; do
len=$((${len} + ${i} % 2)) len=$((${len} + ${i} % 2))
i=$((${i} >> 1)) i=$((${i} >> 1))
done done
done done
echo "${len}" echo "${len}"
} }
_configure_variables() { _configure_variables() {
local var= v= t= local var= v= t=
for var in ${_config_vars} ; do for var in ${_config_vars} ; do
local v= local v=
for t in "$@" ; do for t in "$@" ; do
eval v=\$${var}_${t} eval v=\$${var}_${t}
if [ -n "${v}" ] ; then if [ -n "${v}" ] ; then
eval ${var}_${IFVAR}=\$${var}_${t} eval ${var}_${IFVAR}=\$${var}_${t}
continue 2 continue 2
fi fi
done done
done done
} }
_show_address() { _show_address() {
einfo "received address $(_get_inet_address "${IFACE}")" einfo "received address $(_get_inet_address "${IFACE}")"
} }
# Basically sorts our modules into order and saves the list # Basically sorts our modules into order and saves the list
_gen_module_list() { _gen_module_list() {
local x= f= local x= f=
if [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ] ; then if [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ] ; then
local update=false local update=false
for x in "${MODULESDIR}"/* ; do for x in "${MODULESDIR}"/* ; do
[ -e "${x}" ] || continue [ -e "${x}" ] || continue
if [ "${x}" -nt "${MODULESLIST}" ] ; then if [ "${x}" -nt "${MODULESLIST}" ] ; then
update=true update=true
break break
fi fi
done done
${update} || return 0 ${update} || return 0
fi fi
einfo "Caching network module dependencies" einfo "Caching network module dependencies"
# Run in a subshell to protect the main script # Run in a subshell to protect the main script
( (
after() { after() {
eval ${MODULE}_after="\"\${${MODULE}_after}\${${MODULE}_after:+ }$*\"" eval ${MODULE}_after="\"\${${MODULE}_after}\${${MODULE}_after:+ }$*\""
} }
before() { before() {
local mod=${MODULE} local mod=${MODULE}
local MODULE= local MODULE=
for MODULE in "$@" ; do for MODULE in "$@" ; do
after "${mod}" after "${mod}"
done done
} }
program() { program() {
if [ "$1" = "start" -o "$1" = "stop" ] ; then if [ "$1" = "start" -o "$1" = "stop" ] ; then
local s="$1" local s="$1"
shift shift
eval ${MODULE}_program_${s}="\"\${${MODULE}_program_${s}}\${${MODULE}_program_${s}:+ }$*\"" eval ${MODULE}_program_${s}="\"\${${MODULE}_program_${s}}\${${MODULE}_program_${s}:+ }$*\""
else else
eval ${MODULE}_program="\"\${${MODULE}_program}\${${MODULE}_program:+ }$*\"" eval ${MODULE}_program="\"\${${MODULE}_program}\${${MODULE}_program:+ }$*\""
fi fi
} }
provide() { provide() {
eval ${MODULE}_provide="\"\${${MODULE}_provide}\${${MODULE}_provide:+ }$*\"" eval ${MODULE}_provide="\"\${${MODULE}_provide}\${${MODULE}_provide:+ }$*\""
local x local x
for x in $* ; do for x in $* ; do
eval ${x}_providedby="\"\${${MODULE}_providedby}\${${MODULE}_providedby:+ }${MODULE}\"" eval ${x}_providedby="\"\${${MODULE}_providedby}\${${MODULE}_providedby:+ }${MODULE}\""
done done
} }
for MODULE in "${MODULESDIR}"/* ; do for MODULE in "${MODULESDIR}"/* ; do
sh -n "${MODULE}" || continue sh -n "${MODULE}" || continue
. "${MODULE}" || continue . "${MODULE}" || continue
MODULE=${MODULE#${MODULESDIR}/} MODULE=${MODULE#${MODULESDIR}/}
MODULE=${MODULE%.sh} MODULE=${MODULE%.sh}
eval ${MODULE}_depend eval ${MODULE}_depend
MODULES="${MODULES} ${MODULE}" MODULES="${MODULES} ${MODULE}"
done done
VISITED= VISITED=
SORTED= SORTED=
visit() { visit() {
case " ${VISITED} " in case " ${VISITED} " in
*" $1 "*) return ;; *" $1 "*) return ;;
esac esac
VISITED="${VISITED} $1" VISITED="${VISITED} $1"
eval AFTER=\$${1}_after eval AFTER=\$${1}_after
for MODULE in ${AFTER} ; do for MODULE in ${AFTER} ; do
eval PROVIDEDBY=\$${MODULE}_providedby eval PROVIDEDBY=\$${MODULE}_providedby
if [ -n "${PROVIDEDBY}" ] ; then if [ -n "${PROVIDEDBY}" ] ; then
for MODULE in ${PROVIDEDBY} ; do for MODULE in ${PROVIDEDBY} ; do
visit "${MODULE}" visit "${MODULE}"
done done
else else
visit "${MODULE}" visit "${MODULE}"
fi fi
done done
eval PROVIDE=\$${1}_provide eval PROVIDE=\$${1}_provide
for MODULE in ${PROVIDE} ; do for MODULE in ${PROVIDE} ; do
visit "${MODULE}" visit "${MODULE}"
done done
eval PROVIDEDBY=\$${1}_providedby eval PROVIDEDBY=\$${1}_providedby
[ -z "${PROVIDEDBY}" ] && SORTED="${SORTED} $1" [ -z "${PROVIDEDBY}" ] && SORTED="${SORTED} $1"
} }
for MODULE in ${MODULES} ; do for MODULE in ${MODULES} ; do
visit "${MODULE}" visit "${MODULE}"
done done
> "${MODULESLIST}" > "${MODULESLIST}"
i=0 i=0
for MODULE in ${SORTED} ; do for MODULE in ${SORTED} ; do
eval PROGRAM=\$${MODULE}_program eval PROGRAM=\$${MODULE}_program
eval PROGRAM_START=\$${MODULE}_program_start eval PROGRAM_START=\$${MODULE}_program_start
eval PROGRAM_STOP=\$${MODULE}_program_stop eval PROGRAM_STOP=\$${MODULE}_program_stop
#for x in ${PROGRAM} ; do #for x in ${PROGRAM} ; do
# [ -x "${x}" ] || continue 2 # [ -x "${x}" ] || continue 2
#done #done
eval PROVIDE=\$${MODULE}_provide eval PROVIDE=\$${MODULE}_provide
echo "module_${i}='${MODULE}'" >> "${MODULESLIST}" echo "module_${i}='${MODULE}'" >> "${MODULESLIST}"
@ -222,41 +222,41 @@ _gen_module_list() {
echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}" echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}"
echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}" echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}"
i=$((${i} + 1)) i=$((${i} + 1))
done done
echo "module_${i}=" >> "${MODULESLIST}" echo "module_${i}=" >> "${MODULESLIST}"
) )
return 0 return 0
} }
_load_modules() { _load_modules() {
# Ensure our list is up to date # Ensure our list is up to date
_gen_module_list _gen_module_list
local starting=$1 mymods= local starting=$1 mymods=
MODULES= MODULES=
if [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] ; then if [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] ; then
eval mymods=\$modules_${IFVAR} eval mymods=\$modules_${IFVAR}
[ -z "${mymods}" ] && mymods=${modules} [ -z "${mymods}" ] && mymods=${modules}
fi fi
. "${MODULESLIST}" . "${MODULESLIST}"
local i=-1 x= mod= f= provides= local i=-1 x= mod= f= provides=
while true ; do while true ; do
i=$((${i} + 1)) i=$((${i} + 1))
eval mod=\$module_${i} eval mod=\$module_${i}
[ -z "${mod}" ] && break [ -z "${mod}" ] && break
[ -e "${MODULESDIR}/${mod}.sh" ] || continue [ -e "${MODULESDIR}/${mod}.sh" ] || continue
eval set -- \$module_${i}_program eval set -- \$module_${i}_program
if [ -n "$1" ] ; then if [ -n "$1" ] ; then
x= x=
for x in "$@" ; do for x in "$@" ; do
[ -x "${x}" ] && break [ -x "${x}" ] && break
done done
[ -x "${x}" ] || continue [ -x "${x}" ] || continue
fi fi
if ${starting} ; then if ${starting} ; then
eval set -- \$module_${i}_program_start eval set -- \$module_${i}_program_start
else else
@ -268,21 +268,21 @@ _load_modules() {
[ -x "${x}" ] && break [ -x "${x}" ] && break
done done
[ -x "${x}" ] || continue [ -x "${x}" ] || continue
fi fi
eval provides=\$module_${i}_provide eval provides=\$module_${i}_provide
if ${starting} ; then if ${starting} ; then
case " ${mymods} " in case " ${mymods} " in
*" !${mod} "*) continue ;; *" !${mod} "*) continue ;;
*" !${provides} "*) [ -n "${provides}" ] && continue ;; *" !${provides} "*) [ -n "${provides}" ] && continue ;;
esac esac
fi fi
MODULES="${MODULES}${MODULES:+ }${mod}" MODULES="${MODULES}${MODULES:+ }${mod}"
# Now load and wrap our functions # Now load and wrap our functions
if ! . "${MODULESDIR}/${mod}.sh" ; then if ! . "${MODULESDIR}/${mod}.sh" ; then
eend 1 "${SVCNAME}: error loading module \`${mod}'" eend 1 "${SVCNAME}: error loading module \`${mod}'"
exit 1 exit 1
fi fi
[ -z "${provides}" ] && continue [ -z "${provides}" ] && continue
@ -290,112 +290,112 @@ _load_modules() {
# Wrap our provides # Wrap our provides
local f= local f=
for f in pre_start start post_start ; do for f in pre_start start post_start ; do
eval "${provides}_${f}() { type ${mod}_${f} >/dev/null 2>/dev/null || return 0; ${mod}_${f} \"\$@\"; }" eval "${provides}_${f}() { type ${mod}_${f} >/dev/null 2>/dev/null || return 0; ${mod}_${f} \"\$@\"; }"
done done
eval module_${mod}_provides="${provides}" eval module_${mod}_provides="${provides}"
eval module_${provides}_providedby="${mod}" eval module_${provides}_providedby="${mod}"
done done
# Wrap our preferred modules # Wrap our preferred modules
for mod in ${mymods} ; do for mod in ${mymods} ; do
case " ${MODULES} " in case " ${MODULES} " in
*" ${mod} "*) *" ${mod} "*)
eval x=\$module_${mod}_provides eval x=\$module_${mod}_provides
[ -z "${x}" ] && continue [ -z "${x}" ] && continue
for f in pre_start start post_start ; do for f in pre_start start post_start ; do
eval "${x}_${f}() { type ${mod}_${f} >/dev/null 2>/dev/null || return 0; ${mod}_${f} \"\$@\"; }" eval "${x}_${f}() { type ${mod}_${f} >/dev/null 2>/dev/null || return 0; ${mod}_${f} \"\$@\"; }"
done done
eval module_${x}_providedby="${mod}" eval module_${x}_providedby="${mod}"
;; ;;
esac esac
done done
# Finally remove any duplicated provides from our list if we're starting # Finally remove any duplicated provides from our list if we're starting
# Otherwise reverse the list # Otherwise reverse the list
local LIST="${MODULES}" p= local LIST="${MODULES}" p=
MODULES= MODULES=
if ${starting} ; then if ${starting} ; then
for mod in ${LIST} ; do for mod in ${LIST} ; do
eval x=\$module_${mod}_provides eval x=\$module_${mod}_provides
if [ -n "${x}" ] ; then if [ -n "${x}" ] ; then
eval p=\$module_${x}_providedby eval p=\$module_${x}_providedby
[ "${mod}" != "${p}" ] && continue [ "${mod}" != "${p}" ] && continue
fi fi
MODULES="${MODULES}${MODULES:+ }${mod}" MODULES="${MODULES}${MODULES:+ }${mod}"
done done
else else
for mod in ${LIST} ; do for mod in ${LIST} ; do
MODULES="${mod}${MODULES:+ }${MODULES}" MODULES="${mod}${MODULES:+ }${MODULES}"
done done
fi fi
veinfo "Loaded modules: ${MODULES}" veinfo "Loaded modules: ${MODULES}"
} }
_load_config() { _load_config() {
eval "$(_get_array "config_${IFVAR}")" eval "$(_get_array "config_${IFVAR}")"
if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] ; then if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] ; then
set -- "127.0.0.1/8" "$@" set -- "127.0.0.1/8" "$@"
else else
if [ $# -eq 0 ] ; then if [ $# -eq 0 ] ; then
ewarn "No configuration specified; defaulting to DHCP" ewarn "No configuration specified; defaulting to DHCP"
set -- "dhcp" set -- "dhcp"
fi fi
fi fi
# We store our config in an array like vars # We store our config in an array like vars
# so modules can influence it # so modules can influence it
config_index=0 config_index=0
for cmd in "$@" ; do for cmd in "$@" ; do
eval config_${config_index}="'${cmd}'" eval config_${config_index}="'${cmd}'"
config_index=$((${config_index} + 1)) config_index=$((${config_index} + 1))
done done
# Terminate the list # Terminate the list
eval config_${config_index}= eval config_${config_index}=
config_index=0 config_index=0
eval $(_get_array fallback_${IFVAR}) eval $(_get_array fallback_${IFVAR})
for cmd in "$@" ; do for cmd in "$@" ; do
eval fallback_${config_index}="'${cmd}'" eval fallback_${config_index}="'${cmd}'"
config_index=$((${config_index} + 1)) config_index=$((${config_index} + 1))
done done
# Terminate the list # Terminate the list
eval fallback_${config_index}= eval fallback_${config_index}=
# Don't set to zero, so any net modules don't have to do anything extra # Don't set to zero, so any net modules don't have to do anything extra
config_index=-1 config_index=-1
} }
start() { start() {
local IFACE=${SVCNAME#*.} oneworked=false module= local IFACE=${SVCNAME#*.} oneworked=false module=
local IFVAR=$(_shell_var "${IFACE}") cmd= metric=0 our_metric=$metric local IFVAR=$(_shell_var "${IFACE}") cmd= metric=0 our_metric=$metric
einfo "Bringing up interface ${IFACE}" einfo "Bringing up interface ${IFACE}"
eindent eindent
if [ -z "${MODULES}" ] ; then if [ -z "${MODULES}" ] ; then
local MODULES= local MODULES=
_load_modules true _load_modules true
fi fi
_up 2>/dev/null _up 2>/dev/null
if type preup >/dev/null 2>/dev/null ; then if type preup >/dev/null 2>/dev/null ; then
ebegin "Running preup" ebegin "Running preup"
eindent eindent
preup || return 1 preup || return 1
eoutdent eoutdent
fi fi
for module in ${MODULES} ; do for module in ${MODULES} ; do
if type "${module}_pre_start" >/dev/null 2>/dev/null ; then if type "${module}_pre_start" >/dev/null 2>/dev/null ; then
if ! ${module}_pre_start ; then if ! ${module}_pre_start ; then
eend 1 eend 1
exit 1 exit 1
fi fi
fi fi
done done
if ! _exists ; then if ! _exists ; then
eerror "ERROR: interface ${IFACE} does not exist" eerror "ERROR: interface ${IFACE} does not exist"
@ -413,17 +413,17 @@ start() {
return 1 return 1
fi fi
local config= config_index= local config= config_index=
_load_config _load_config
config_index=0 config_index=0
if [ -n "${our_metric}" ] ; then if [ -n "${our_metric}" ] ; then
metric=${our_metric} metric=${our_metric}
elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] ; then elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] ; then
metric=$((${metric} + $(_ifindex))) metric=$((${metric} + $(_ifindex)))
fi fi
while true ; do while true ; do
eval config=\$config_${config_index} eval config=\$config_${config_index}
[ -z "${config}" ] && break [ -z "${config}" ] && break
@ -431,160 +431,160 @@ start() {
ebegin "$1" ebegin "$1"
eindent eindent
case "$1" in case "$1" in
noop) noop)
if [ -n "$(_get_inet_address)" ] ; then if [ -n "$(_get_inet_address)" ] ; then
oneworked=true oneworked=true
break break
fi fi
;; ;;
null) : ;; null) : ;;
[0-9]*|*:*) _add_address ${config} ;; [0-9]*|*:*) _add_address ${config} ;;
*) *)
if type "${config}_start" >/dev/null 2>/dev/null ; then if type "${config}_start" >/dev/null 2>/dev/null ; then
"${config}"_start "${config}"_start
else else
eerror "nothing provides \`${config}'" eerror "nothing provides \`${config}'"
fi fi
;; ;;
esac esac
if eend $? ; then if eend $? ; then
oneworked=true oneworked=true
else else
eval config=\$fallback_${IFVAR} eval config=\$fallback_${IFVAR}
if [ -n "${config}" ] ; then if [ -n "${config}" ] ; then
einfo "Trying fallback configuration" einfo "Trying fallback configuration"
eval config_${config_index}=\$fallback_${IFVAR} eval config_${config_index}=\$fallback_${IFVAR}
eval fallback_${config_index}= eval fallback_${config_index}=
config_index=$((${config_index} - 1)) config_index=$((${config_index} - 1))
fi fi
fi fi
eoutdent eoutdent
config_index=$((${config_index} + 1)) config_index=$((${config_index} + 1))
done done
if ! ${oneworked} ; then if ! ${oneworked} ; then
if type failup >/dev/null 2>/dev/null ; then if type failup >/dev/null 2>/dev/null ; then
ebegin "Running failup" ebegin "Running failup"
eindent eindent
failup failup
eoutdent eoutdent
fi fi
return 1 return 1
fi fi
local hidefirstroute=false first=true routes= local hidefirstroute=false first=true routes=
eval "$(_get_array "routes_${IFVAR}")" eval "$(_get_array "routes_${IFVAR}")"
if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] ; then if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] ; then
set -- "127.0.0.0/8 via 127.0.0.1" "$@" set -- "127.0.0.0/8 via 127.0.0.1" "$@"
hidefirstroute=true hidefirstroute=true
fi fi
for cmd in "$@" ; do for cmd in "$@" ; do
if ${first} ; then if ${first} ; then
first=false first=false
einfo "Adding routes" einfo "Adding routes"
fi fi
eindent eindent
ebegin "${cmd}" ebegin "${cmd}"
# Work out if we're a host or a net if not told # Work out if we're a host or a net if not told
case "${cmd}" in case "${cmd}" in
*" -net "*|*" -host "*) ;; *" -net "*|*" -host "*) ;;
*" netmask "*) cmd="-net ${cmd}" ;; *" netmask "*) cmd="-net ${cmd}" ;;
*) *)
case "${cmd%% *}" in case "${cmd%% *}" in
*.*.*.*/32) cmd="-host ${cmd}" ;; *.*.*.*/32) cmd="-host ${cmd}" ;;
*.*.*.*/*|0.0.0.0|default) cmd="-net ${cmd}" ;; *.*.*.*/*|0.0.0.0|default) cmd="-net ${cmd}" ;;
*) cmd="-host ${cmd}" ;; *) cmd="-host ${cmd}" ;;
esac esac
;; ;;
esac esac
if ${hidefirstroute} ; then if ${hidefirstroute} ; then
_add_route ${cmd} >/dev/null 2>/dev/null _add_route ${cmd} >/dev/null 2>/dev/null
hidefirstroute=false hidefirstroute=false
else else
_add_route ${cmd} >/dev/null _add_route ${cmd} >/dev/null
fi fi
eend $? eend $?
eoutdent eoutdent
done done
for module in ${MODULES} ; do for module in ${MODULES} ; do
if type "${module}_post_start" >/dev/null 2>/dev/null ; then if type "${module}_post_start" >/dev/null 2>/dev/null ; then
if ! ${module}_post_start ; then if ! ${module}_post_start ; then
eend 1 eend 1
exit 1 exit 1
fi fi
fi fi
done done
if type postup >/dev/null 2>/dev/null ; then if type postup >/dev/null 2>/dev/null ; then
ebegin "Running postup" ebegin "Running postup"
eindent eindent
postup postup
eoutdent eoutdent
fi fi
return 0 return 0
} }
stop() { stop() {
local IFACE=${SVCNAME#*.} module= local IFACE=${SVCNAME#*.} module=
local IFVAR=$(_shell_var "${IFACE}") opts= local IFVAR=$(_shell_var "${IFACE}") opts=
einfo "Bringing down interface ${IFACE}" einfo "Bringing down interface ${IFACE}"
eindent eindent
if [ -z "${MODULES}" ] ; then if [ -z "${MODULES}" ] ; then
local MODULES= local MODULES=
_load_modules false _load_modules false
fi fi
if type predown >/dev/null 2>/dev/null ; then if type predown >/dev/null 2>/dev/null ; then
ebegin "Running predown" ebegin "Running predown"
eindent eindent
predown || return 1 predown || return 1
eoutdent eoutdent
fi
for module in ${MODULES} ; do
if type "${module}_pre_stop" >/dev/null 2>/dev/null ; then
if ! ${module}_pre_stop ; then
eend 1
exit 1
fi
fi fi
done
for module in ${MODULES} ; do for module in ${MODULES} ; do
if type "${module}_stop" >/dev/null 2>/dev/null ; then if type "${module}_pre_stop" >/dev/null 2>/dev/null ; then
${module}_stop if ! ${module}_pre_stop ; then
eend 1
exit 1
fi
fi fi
done done
for module in ${MODULES} ; do
if type "${module}_stop" >/dev/null 2>/dev/null ; then
${module}_stop
fi
done
# Only delete addresses for non PPP interfaces # Only delete addresses for non PPP interfaces
if ! type is_ppp >/dev/null 2>/dev/null || ! is_ppp ; then if ! type is_ppp >/dev/null 2>/dev/null || ! is_ppp ; then
_delete_addresses "${IFACE}" _delete_addresses "${IFACE}"
fi fi
for module in ${MODULES} ; do for module in ${MODULES} ; do
if type "${module}_post_stop" >/dev/null 2>/dev/null ; then if type "${module}_post_stop" >/dev/null 2>/dev/null ; then
${module}_post_stop ${module}_post_stop
fi fi
done done
[ "${IN_BACKGROUND}" != "true" ] && \ [ "${IN_BACKGROUND}" != "true" ] && \
[ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] && \ [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] && \
_down 2>/dev/null _down 2>/dev/null
[ -x /sbin/resolvconf ] && resolvconf -d "${IFACE}" [ -x /sbin/resolvconf ] && resolvconf -d "${IFACE}"
if type postdown >/dev/null 2>/dev/null ; then if type postdown >/dev/null 2>/dev/null ; then
ebegin "Running postdown" ebegin "Running postdown"
eindent eindent
postdown postdown
eoutdent eoutdent
fi fi
return 0 return 0
} }
# vim: set ts=4 : # vim: set ts=4 sw=4 :