-#!/sbin/runscript
+#!/sbin/openrc-run
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Copyright (c) 2010-2016 Gentoo Foundation
# Released under the 2-clause BSD license.
+SHDIR="/lib/netifrc/sh"
MODULESDIR="/lib/netifrc/net"
MODULESLIST="${RC_SVCDIR}/nettree"
-_config_vars="config routes"
+_config_vars="config metric routes"
[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO"
# Handy var so we don't have to embed new lines everywhere for array splitting
__IFS="
"
+
+# Set the INIT to be openrc if this file is called directly
+: ${INIT:=openrc}
+
+if [ -f "$SHDIR/functions.sh" ]; then
+ . "$SHDIR/functions.sh"
+else
+ echo "$SHDIR/functions.sh missing. Exiting"
+ exit 1
+fi
+
depend()
{
- local IFACE=${RC_SVCNAME#*.}
+ local IFACE=$(get_interface)
local IFVAR=$(shell_var "${IFACE}")
- need localmount
if [ "$RC_UNAME" = Linux -a "$IFACE" != lo ]; then
need sysfs
+ after modules
fi
after bootmisc
keyword -jail -prefix -vserver
lo|lo0) ;;
*)
after net.lo net.lo0 dbus
+ need localmount
provide net
;;
esac
_wait_for_carrier()
{
- local timeout= efunc=einfon
+ local timeout=
_has_carrier && return 0
# Incase users don't want this nice feature ...
[ ${timeout} -le 0 ] && return 0
- yesno ${RC_PARALLEL} && efunc=einfo
- ${efunc} "Waiting for carrier (${timeout} seconds) "
+ einfon "Waiting for carrier (${timeout} seconds) "
while [ ${timeout} -gt 0 ]; do
if _has_carrier; then
- [ "${efunc}" = "einfon" ] && echo
+ echo
eend 0
return 0
fi
sleep 1
: $(( timeout -= 1 ))
- [ "${efunc}" = "einfon" ] && printf "."
+ printf "."
done
- [ "${efunc}" = "einfon" ] && echo
+ echo
eend 1
return 1
}
/*) [ -x "${x}" ] && break;;
*) type "${x}" >/dev/null 2>&1 && break;;
esac
- unset x
+ x=
done
[ -n "${x}" ] && echo $x && return 0
return 1
einfo "received address $(_get_inet_address "${IFACE}")"
}
+# Allow custom error handling behavior to be set by the user.
+# Known used combinations, with defaults
+# errh_IFVAR_address_EEXIST=warn
+# errh_IFVAR_route_EEXIST=warn
+_get_errorhandler_behavior() {
+ IFVAR="$1"
+ object="$2"
+ error="$3"
+ fallback="$4"
+ value=
+ for key in \
+ "errh_${IFVAR}_${object}_${error}" \
+ "errh_${IFVAR}_${object}_DEFAULT" \
+ "errh_${IFVAR}_DEFAULT_${error}" \
+ "errh_${IFVAR}_DEFAULT_DEFAULT" \
+ "errh_DEFAULT_${object}_${error}" \
+ "errh_DEFAULT_${object}_DEFAULT" \
+ "errh_DEFAULT_DEFAULT_${error}" \
+ "errh_DEFAULT_DEFAULT_DEFAULT" \
+ "errh" \
+ "fallback" ; do
+ eval value="\${${key}}"
+ if [ -n "$value" ]; then
+ echo "$value" && break
+ fi
+ done
+}
+
# Basically sorts our modules into order and saves the list
_gen_module_list()
{
local x= f= force=$1
- if ! ${force} && [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then
- local update=false
- for x in "${MODULESDIR}"/*.sh; do
- [ -e "${x}" ] || continue
- if [ "${x}" -nt "${MODULESLIST}" ]; then
- update=true
- break
- fi
- done
- ${update} || return 0
+ if ! ${force} ; then
+ if [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt /proc/$$/status ]; then
+ ewarn "Discarding cached module list ($MODULESLIST) as it's newer current time!"
+ elif [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then
+ local update=false
+ for x in "${MODULESDIR}"/*.sh; do
+ [ -e "${x}" ] || continue
+ if [ "${x}" -nt "${MODULESLIST}" ]; then
+ update=true
+ break
+ fi
+ done
+ ${update} || return 0
+ fi
fi
einfo "Caching network module dependencies"
{
_run_if _down "$@"
}
+set_interface_type()
+{
+ service_set_value iface_type "$@"
+}
+get_interface_type()
+{
+ ( RC_SVCNAME="net.$IFACE" service_get_value iface_type )
+}
+is_interface_type()
+{
+ [ "$(get_interface_type)" = "$1" ]
+}
start()
{
- local IFACE=${RC_SVCNAME#*.} oneworked=false fallback=false module=
+ local IFACE=$(get_interface) oneworked=false fallback=false module=
local IFVAR=$(shell_var "${IFACE}") cmd= our_metric=
local metric=0 _up_before_preup
eval _up_before_preup="\$up_before_preup_${IFVAR}"
return 1
fi
- local hideFirstroute=false first=true routes=
+ local first=true routes=
if ${fallback}; then
routes="$(_get_array "fallback_routes_${IFVAR}")"
fi
if [ "${config_0}" != "null" ]; then
routes="127.0.0.0/8 via 127.0.0.1
${routes}"
- hideFirstroute=true
fi
fi
*:*/*) cmd="-net ${cmd}";;
*) cmd="-host ${cmd}";;
esac
- if ${hideFirstroute}; then
- _add_route ${fam} ${cmd} >/dev/null 2>&1
- hideFirstroute=false
- else
- _add_route ${fam} ${cmd} >/dev/null
- fi
+ _add_route ${fam} ${cmd}
eend $?
eoutdent
done
# correctly if we go back to multiuser.
yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0
- local IFACE=${RC_SVCNAME#*.} module=
+ local IFACE=$(get_interface) module=
local IFVAR=$(shell_var "${IFACE}") opts=
einfo "Bringing down interface ${IFACE}"
return 0
}
+
+# vim:filetype=gentoo-init-d: