2007-04-05 16:48:42 +05:30
|
|
|
#!/sbin/runscript
|
|
|
|
# Copyright 1999-2007 Gentoo Foundation
|
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
|
|
|
|
|
|
|
MODULESDIR="${RC_LIBDIR}/net"
|
|
|
|
MODULESLIST="${RC_SVCDIR}/nettree"
|
2007-04-10 00:26:26 +05:30
|
|
|
_config_vars="config routes"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND=false
|
|
|
|
|
2007-07-11 00:39:41 +05:30
|
|
|
description="Configures network interfaces."
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
depend() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local IFACE=${SVCNAME#*.}
|
|
|
|
local IFVAR=$(echo -n "${IFACE}" | sed -e 's/[^[:alnum:]]/_/g')
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
need localmount
|
2007-04-05 16:48:42 +05:30
|
|
|
after bootmisc
|
2007-05-02 16:34:52 +05:30
|
|
|
provide net
|
|
|
|
case "${IFACE}" in
|
2007-04-05 16:48:42 +05:30
|
|
|
lo|lo0) ;;
|
|
|
|
*)
|
|
|
|
after net.lo net.lo0
|
|
|
|
local prov=
|
|
|
|
eval prov=\$RC_NEED_${IFVAR}
|
|
|
|
[ -n "${prov}" ] && need ${prov}
|
|
|
|
eval prov=\$RC_USE_${IFVAR}
|
|
|
|
[ -n "${prov}" ] && use ${prov}
|
|
|
|
eval prov=\$RC_BEFORE_${IFVAR}
|
|
|
|
[ -n "${prov}" ] && before ${prov}
|
|
|
|
eval prov=\$RC_AFTER_${IFVAR}
|
|
|
|
[ -n "${prov}" ] && after ${prov}
|
|
|
|
eval prov=\$RC_PROVIDE_${IFVAR}
|
|
|
|
[ -n "${prov}" ] && provide ${prov}
|
|
|
|
;;
|
2007-05-02 16:34:52 +05:30
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_shell_var() {
|
2007-05-02 16:34:52 +05:30
|
|
|
echo -n "$1" | sed -e 's/[^[:alnum:]]/_/g'
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
# Credit to David Leverton for this function which handily maps a bash array
|
|
|
|
# structure to positional parameters so existing configs work :)
|
|
|
|
# We'll deprecate arrays at some point though.
|
|
|
|
_get_array() {
|
2007-05-02 16:34:52 +05:30
|
|
|
if [ -n "${BASH}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
case "$(declare -p "$1" 2>/dev/null)" in
|
2007-05-02 16:34:52 +05:30
|
|
|
"declare -a "*)
|
|
|
|
echo "set -- \"\${$1[@]}\""
|
|
|
|
return
|
|
|
|
;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
echo "eval set -- \"\$$1\""
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_wait_for_carrier() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local timeout= efunc=einfon
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
_has_carrier && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
eval timeout=\$carrier_timeout_${IFVAR}
|
|
|
|
timeout=${timeout:-${carrier_timeout:-5}}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-30 18:47:28 +05:30
|
|
|
# Incase users don't want this nice feature ...
|
|
|
|
[ ${timeout} -le 0 ] && return 0
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
[ -n "${RC_EBUFFER}" -o "${RC_PREFIX}" = "yes" ] && efunc=einfo
|
|
|
|
${efunc} "Waiting for carrier (${timeout} seconds) "
|
|
|
|
while [ ${timeout} -gt 0 ] ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
sleep 1
|
|
|
|
if _has_carrier ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
[ -z "${RC_EBUFFER}" ] && echo
|
2007-04-11 16:10:53 +05:30
|
|
|
eend 0
|
2007-05-02 16:34:52 +05:30
|
|
|
return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
timeout=$((${timeout} - 1))
|
2007-04-30 18:47:28 +05:30
|
|
|
[ -z "${RC_EBUFFER}" -a "${RC_PREFIX}" != "yes" ] && printf "."
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
[ -z "${RC_EBUFFER}" -a "${RC_PREFIX}" != "yes" ] && echo
|
2007-04-11 16:10:53 +05:30
|
|
|
eend 1
|
2007-05-02 16:34:52 +05:30
|
|
|
return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_netmask2cidr() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local i= len=0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
local IFS=.
|
|
|
|
for i in $1; do
|
2007-04-05 16:48:42 +05:30
|
|
|
while [ ${i} != "0" ] ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
len=$((${len} + ${i} % 2))
|
|
|
|
i=$((${i} >> 1))
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
echo "${len}"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_configure_variables() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local var= v= t=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for var in ${_config_vars} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
local v=
|
|
|
|
for t in "$@" ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
eval v=\$${var}_${t}
|
|
|
|
if [ -n "${v}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eval ${var}_${IFVAR}=\$${var}_${t}
|
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_show_address() {
|
2007-05-02 16:34:52 +05:30
|
|
|
einfo "received address $(_get_inet_address "${IFACE}")"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
# Basically sorts our modules into order and saves the list
|
|
|
|
_gen_module_list() {
|
2007-05-19 01:39:10 +05:30
|
|
|
local x= f= force=$1
|
|
|
|
if ! ${force} && [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
local update=false
|
|
|
|
for x in "${MODULESDIR}"/* ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
[ -e "${x}" ] || continue
|
|
|
|
if [ "${x}" -nt "${MODULESLIST}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
update=true
|
|
|
|
break
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
${update} || return 0
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
einfo "Caching network module dependencies"
|
|
|
|
# Run in a subshell to protect the main script
|
|
|
|
(
|
|
|
|
after() {
|
2007-04-05 16:48:42 +05:30
|
|
|
eval ${MODULE}_after="\"\${${MODULE}_after}\${${MODULE}_after:+ }$*\""
|
2007-05-02 16:34:52 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
before() {
|
2007-04-05 16:48:42 +05:30
|
|
|
local mod=${MODULE}
|
|
|
|
local MODULE=
|
|
|
|
for MODULE in "$@" ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
after "${mod}"
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
program() {
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ "$1" = "start" -o "$1" = "stop" ] ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
local s="$1"
|
|
|
|
shift
|
|
|
|
eval ${MODULE}_program_${s}="\"\${${MODULE}_program_${s}}\${${MODULE}_program_${s}:+ }$*\""
|
2007-04-05 16:48:42 +05:30
|
|
|
else
|
2007-05-02 16:34:52 +05:30
|
|
|
eval ${MODULE}_program="\"\${${MODULE}_program}\${${MODULE}_program:+ }$*\""
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-05-02 16:34:52 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
provide() {
|
2007-04-05 16:48:42 +05:30
|
|
|
eval ${MODULE}_provide="\"\${${MODULE}_provide}\${${MODULE}_provide:+ }$*\""
|
|
|
|
local x
|
|
|
|
for x in $* ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
eval ${x}_providedby="\"\${${MODULE}_providedby}\${${MODULE}_providedby:+ }${MODULE}\""
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for MODULE in "${MODULESDIR}"/* ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
sh -n "${MODULE}" || continue
|
|
|
|
. "${MODULE}" || continue
|
|
|
|
MODULE=${MODULE#${MODULESDIR}/}
|
|
|
|
MODULE=${MODULE%.sh}
|
|
|
|
eval ${MODULE}_depend
|
|
|
|
MODULES="${MODULES} ${MODULE}"
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
VISITED=
|
|
|
|
SORTED=
|
|
|
|
visit() {
|
2007-04-05 16:48:42 +05:30
|
|
|
case " ${VISITED} " in
|
2007-05-02 16:34:52 +05:30
|
|
|
*" $1 "*) return ;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
VISITED="${VISITED} $1"
|
|
|
|
|
|
|
|
eval AFTER=\$${1}_after
|
|
|
|
for MODULE in ${AFTER} ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
eval PROVIDEDBY=\$${MODULE}_providedby
|
|
|
|
if [ -n "${PROVIDEDBY}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
for MODULE in ${PROVIDEDBY} ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
visit "${MODULE}"
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
else
|
2007-04-05 16:48:42 +05:30
|
|
|
visit "${MODULE}"
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
|
|
|
|
eval PROVIDE=\$${1}_provide
|
|
|
|
for MODULE in ${PROVIDE} ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
visit "${MODULE}"
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
|
|
|
|
eval PROVIDEDBY=\$${1}_providedby
|
|
|
|
[ -z "${PROVIDEDBY}" ] && SORTED="${SORTED} $1"
|
2007-05-02 16:34:52 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for MODULE in ${MODULES} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
visit "${MODULE}"
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
> "${MODULESLIST}"
|
|
|
|
i=0
|
|
|
|
for MODULE in ${SORTED} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
eval PROGRAM=\$${MODULE}_program
|
|
|
|
eval PROGRAM_START=\$${MODULE}_program_start
|
|
|
|
eval PROGRAM_STOP=\$${MODULE}_program_stop
|
|
|
|
#for x in ${PROGRAM} ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
# [ -x "${x}" ] || continue 2
|
2007-04-05 16:48:42 +05:30
|
|
|
#done
|
|
|
|
eval PROVIDE=\$${MODULE}_provide
|
|
|
|
echo "module_${i}='${MODULE}'" >> "${MODULESLIST}"
|
|
|
|
echo "module_${i}_program='${PROGRAM}'" >> "${MODULESLIST}"
|
|
|
|
echo "module_${i}_program_start='${PROGRAM_START}'" >> "${MODULESLIST}"
|
|
|
|
echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}"
|
|
|
|
echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}"
|
|
|
|
i=$((${i} + 1))
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
|
|
|
echo "module_${i}=" >> "${MODULESLIST}"
|
|
|
|
)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_load_modules() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local starting=$1 mymods=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-19 01:39:10 +05:30
|
|
|
# Ensure our list is up to date
|
|
|
|
_gen_module_list false
|
|
|
|
if ! . "${MODULESLIST}" ; then
|
|
|
|
_gen_module_list true
|
|
|
|
. "${MODULESLIST}"
|
|
|
|
fi
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
MODULES=
|
|
|
|
if [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eval mymods=\$modules_${IFVAR}
|
|
|
|
[ -z "${mymods}" ] && mymods=${modules}
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
local i=-1 x= mod= f= provides=
|
|
|
|
while true ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
i=$((${i} + 1))
|
|
|
|
eval mod=\$module_${i}
|
|
|
|
[ -z "${mod}" ] && break
|
|
|
|
[ -e "${MODULESDIR}/${mod}.sh" ] || continue
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
eval set -- \$module_${i}_program
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ -n "$1" ] ; then
|
|
|
|
x=
|
|
|
|
for x in "$@" ; do
|
|
|
|
[ -x "${x}" ] && break
|
|
|
|
done
|
|
|
|
[ -x "${x}" ] || continue
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
if ${starting} ; then
|
|
|
|
eval set -- \$module_${i}_program_start
|
|
|
|
else
|
|
|
|
eval set -- \$module_${i}_program_stop
|
|
|
|
fi
|
|
|
|
if [ -n "$1" ] ; then
|
|
|
|
x=
|
|
|
|
for x in "$@" ; do
|
|
|
|
[ -x "${x}" ] && break
|
|
|
|
done
|
|
|
|
[ -x "${x}" ] || continue
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
eval provides=\$module_${i}_provide
|
|
|
|
if ${starting} ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
case " ${mymods} " in
|
2007-04-05 16:48:42 +05:30
|
|
|
*" !${mod} "*) continue ;;
|
|
|
|
*" !${provides} "*) [ -n "${provides}" ] && continue ;;
|
2007-05-02 16:34:52 +05:30
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
MODULES="${MODULES}${MODULES:+ }${mod}"
|
|
|
|
|
|
|
|
# Now load and wrap our functions
|
|
|
|
if ! . "${MODULESDIR}/${mod}.sh" ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
eend 1 "${SVCNAME}: error loading module \`${mod}'"
|
|
|
|
exit 1
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
[ -z "${provides}" ] && continue
|
|
|
|
|
|
|
|
# Wrap our provides
|
|
|
|
local f=
|
|
|
|
for f in pre_start start post_start ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
eval "${provides}_${f}() { type ${mod}_${f} >/dev/null 2>/dev/null || return 0; ${mod}_${f} \"\$@\"; }"
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
|
|
|
|
eval module_${mod}_provides="${provides}"
|
|
|
|
eval module_${provides}_providedby="${mod}"
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
# Wrap our preferred modules
|
|
|
|
for mod in ${mymods} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
case " ${MODULES} " in
|
2007-05-02 16:34:52 +05:30
|
|
|
*" ${mod} "*)
|
|
|
|
eval x=\$module_${mod}_provides
|
|
|
|
[ -z "${x}" ] && continue
|
|
|
|
for f in pre_start start post_start ; do
|
|
|
|
eval "${x}_${f}() { type ${mod}_${f} >/dev/null 2>/dev/null || return 0; ${mod}_${f} \"\$@\"; }"
|
|
|
|
done
|
|
|
|
eval module_${x}_providedby="${mod}"
|
|
|
|
;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
# Finally remove any duplicated provides from our list if we're starting
|
|
|
|
# Otherwise reverse the list
|
|
|
|
local LIST="${MODULES}" p=
|
|
|
|
MODULES=
|
|
|
|
if ${starting} ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
for mod in ${LIST} ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
eval x=\$module_${mod}_provides
|
|
|
|
if [ -n "${x}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eval p=\$module_${x}_providedby
|
|
|
|
[ "${mod}" != "${p}" ] && continue
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
|
|
|
MODULES="${MODULES}${MODULES:+ }${mod}"
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
else
|
2007-04-05 16:48:42 +05:30
|
|
|
for mod in ${LIST} ; do
|
2007-05-02 16:34:52 +05:30
|
|
|
MODULES="${mod}${MODULES:+ }${MODULES}"
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
veinfo "Loaded modules: ${MODULES}"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_load_config() {
|
2007-05-02 16:34:52 +05:30
|
|
|
eval "$(_get_array "config_${IFVAR}")"
|
|
|
|
if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
set -- "127.0.0.1/8" "$@"
|
2007-05-02 16:34:52 +05:30
|
|
|
else
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ $# -eq 0 ] ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
ewarn "No configuration specified; defaulting to DHCP"
|
|
|
|
set -- "dhcp"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
# We store our config in an array like vars
|
|
|
|
# so modules can influence it
|
|
|
|
config_index=0
|
|
|
|
for cmd in "$@" ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
eval config_${config_index}="'${cmd}'"
|
|
|
|
config_index=$((${config_index} + 1))
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
|
|
|
# Terminate the list
|
|
|
|
eval config_${config_index}=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
config_index=0
|
|
|
|
eval $(_get_array fallback_${IFVAR})
|
|
|
|
for cmd in "$@" ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
eval fallback_${config_index}="'${cmd}'"
|
|
|
|
config_index=$((${config_index} + 1))
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
|
|
|
# Terminate the list
|
|
|
|
eval fallback_${config_index}=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Don't set to zero, so any net modules don't have to do anything extra
|
2007-05-02 16:34:52 +05:30
|
|
|
config_index=-1
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local IFACE=${SVCNAME#*.} oneworked=false module=
|
|
|
|
local IFVAR=$(_shell_var "${IFACE}") cmd= metric=0 our_metric=$metric
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
einfo "Bringing up interface ${IFACE}"
|
|
|
|
eindent
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
if [ -z "${MODULES}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
local MODULES=
|
|
|
|
_load_modules true
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-07-04 19:51:24 +05:30
|
|
|
# We up the iface twice if we have a preup to ensure it's up if
|
|
|
|
# available in preup and afterwards incase the user inadvertently
|
|
|
|
# brings it down
|
2007-05-02 16:34:52 +05:30
|
|
|
if type preup >/dev/null 2>/dev/null ; then
|
2007-07-04 19:51:24 +05:30
|
|
|
_up 2>/dev/null
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Running preup"
|
|
|
|
eindent
|
|
|
|
preup || return 1
|
|
|
|
eoutdent
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-07-04 19:51:24 +05:30
|
|
|
_up 2>/dev/null
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for module in ${MODULES} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if type "${module}_pre_start" >/dev/null 2>/dev/null ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
if ! ${module}_pre_start ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eend 1
|
|
|
|
exit 1
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-19 12:16:29 +05:30
|
|
|
if ! _exists ; then
|
|
|
|
eerror "ERROR: interface ${IFACE} does not exist"
|
|
|
|
eerror "Ensure that you have loaded the correct kernel module for your hardware"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-04-11 16:10:53 +05:30
|
|
|
if ! _wait_for_carrier ; then
|
|
|
|
if service_started devd ; then
|
|
|
|
ewarn "no carrier, but devd will start us when we have one"
|
|
|
|
mark_service_inactive "${SVCNAME}"
|
|
|
|
else
|
|
|
|
eerror "no carrier"
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
local config= config_index=
|
|
|
|
_load_config
|
2007-04-05 16:48:42 +05:30
|
|
|
config_index=0
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
if [ -n "${our_metric}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
metric=${our_metric}
|
2007-05-02 16:34:52 +05:30
|
|
|
elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
metric=$((${metric} + $(_ifindex)))
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
while true ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
eval config=\$config_${config_index}
|
|
|
|
[ -z "${config}" ] && break
|
|
|
|
|
|
|
|
set -- "${config}"
|
|
|
|
ebegin "$1"
|
|
|
|
eindent
|
|
|
|
case "$1" in
|
2007-05-02 16:34:52 +05:30
|
|
|
noop)
|
|
|
|
if [ -n "$(_get_inet_address)" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
oneworked=true
|
|
|
|
break
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
|
|
|
;;
|
|
|
|
null) : ;;
|
|
|
|
[0-9]*|*:*) _add_address ${config} ;;
|
|
|
|
*)
|
|
|
|
if type "${config}_start" >/dev/null 2>/dev/null ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
"${config}"_start
|
2007-05-02 16:34:52 +05:30
|
|
|
else
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "nothing provides \`${config}'"
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
|
|
|
;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
if eend $? ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
oneworked=true
|
2007-04-05 16:48:42 +05:30
|
|
|
else
|
2007-05-02 16:34:52 +05:30
|
|
|
eval config=\$fallback_${IFVAR}
|
|
|
|
if [ -n "${config}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "Trying fallback configuration"
|
|
|
|
eval config_${config_index}=\$fallback_${IFVAR}
|
|
|
|
eval fallback_${config_index}=
|
|
|
|
config_index=$((${config_index} - 1))
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
eoutdent
|
|
|
|
config_index=$((${config_index} + 1))
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
if ! ${oneworked} ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
if type failup >/dev/null 2>/dev/null ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Running failup"
|
|
|
|
eindent
|
|
|
|
failup
|
|
|
|
eoutdent
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
local hidefirstroute=false first=true routes=
|
|
|
|
eval "$(_get_array "routes_${IFVAR}")"
|
|
|
|
if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
set -- "127.0.0.0/8 via 127.0.0.1" "$@"
|
|
|
|
hidefirstroute=true
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
|
|
|
for cmd in "$@" ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if ${first} ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
first=false
|
|
|
|
einfo "Adding routes"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
eindent
|
|
|
|
ebegin "${cmd}"
|
|
|
|
# Work out if we're a host or a net if not told
|
|
|
|
case "${cmd}" in
|
2007-05-02 16:34:52 +05:30
|
|
|
*" -net "*|*" -host "*) ;;
|
|
|
|
*" netmask "*) cmd="-net ${cmd}" ;;
|
|
|
|
*)
|
|
|
|
case "${cmd%% *}" in
|
2007-04-05 16:48:42 +05:30
|
|
|
*.*.*.*/32) cmd="-host ${cmd}" ;;
|
|
|
|
*.*.*.*/*|0.0.0.0|default) cmd="-net ${cmd}" ;;
|
|
|
|
*) cmd="-host ${cmd}" ;;
|
2007-05-02 16:34:52 +05:30
|
|
|
esac
|
|
|
|
;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
if ${hidefirstroute} ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
_add_route ${cmd} >/dev/null 2>/dev/null
|
|
|
|
hidefirstroute=false
|
2007-04-05 16:48:42 +05:30
|
|
|
else
|
2007-05-02 16:34:52 +05:30
|
|
|
_add_route ${cmd} >/dev/null
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
eend $?
|
|
|
|
eoutdent
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for module in ${MODULES} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if type "${module}_post_start" >/dev/null 2>/dev/null ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
if ! ${module}_post_start ; then
|
|
|
|
eend 1
|
|
|
|
exit 1
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
if type postup >/dev/null 2>/dev/null ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Running postup"
|
|
|
|
eindent
|
|
|
|
postup
|
|
|
|
eoutdent
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2007-05-02 16:34:52 +05:30
|
|
|
local IFACE=${SVCNAME#*.} module=
|
|
|
|
local IFVAR=$(_shell_var "${IFACE}") opts=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
einfo "Bringing down interface ${IFACE}"
|
|
|
|
eindent
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
if [ -z "${MODULES}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
local MODULES=
|
|
|
|
_load_modules false
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
if type predown >/dev/null 2>/dev/null ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Running predown"
|
|
|
|
eindent
|
|
|
|
predown || return 1
|
|
|
|
eoutdent
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for module in ${MODULES} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if type "${module}_pre_stop" >/dev/null 2>/dev/null ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
if ! ${module}_pre_stop ; then
|
|
|
|
eend 1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for module in ${MODULES} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if type "${module}_stop" >/dev/null 2>/dev/null ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
${module}_stop
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:29:34 +05:30
|
|
|
# Only delete addresses for non PPP interfaces
|
|
|
|
if ! type is_ppp >/dev/null 2>/dev/null || ! is_ppp ; then
|
|
|
|
_delete_addresses "${IFACE}"
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
for module in ${MODULES} ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if type "${module}_post_stop" >/dev/null 2>/dev/null ; then
|
2007-05-02 16:34:52 +05:30
|
|
|
${module}_post_stop
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-05-02 16:34:52 +05:30
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
[ "${IN_BACKGROUND}" != "true" ] && \
|
|
|
|
[ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] && \
|
|
|
|
_down 2>/dev/null
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
[ -x /sbin/resolvconf ] && resolvconf -d "${IFACE}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
if type postdown >/dev/null 2>/dev/null ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Running postdown"
|
|
|
|
eindent
|
|
|
|
postdown
|
|
|
|
eoutdent
|
2007-05-02 16:34:52 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-05-02 16:34:52 +05:30
|
|
|
# vim: set ts=4 sw=4 :
|