EXIT_CONF_ERROR=2
EXIT_ERROR_ASSERT=3
+EXIT_TRUE=0
+EXIT_FALSE=1
+
STATUS_UP=0
STATUS_DOWN=1
STATUS_NOCARRIER=2
__device_get_file ${device} statistics/tx_errors
}
-
-function device_hotplug() {
- local device=${1}
- shift
-
- assert isset device
-
- # Just check if the device has already vanished.
- device_exists ${device} || return ${EXIT_ERROR}
-
- if ! device_is_free ${device}; then
- log ERROR "The device '${device}' is in use."
- return ${EXIT_ERROR}
- fi
-
- if ! device_is_real ${device}; then
- log DEBUG "Don't rename any virtual devices."
- return ${EXIT_OK}
- fi
-
- for port in $(ports_get_all); do
- port_cmd hotplug ${port} ${device}
- if [ $? -eq ${EXIT_OK} ]; then
- echo "${port}"
- return ${EXIT_OK}
- fi
- done
-
- # If no port configuration could be found, we search for the next
- # unused name and return that.
- local port=$(port_find_free ${PORT_PATTERN})
-
- log DEBUG "Could not find an existing port configuration for '${device}'."
- log DEBUG "${device} --> ${port}"
-
- echo "${port}"
- return ${EXIT_OK}
-}
# #
###############################################################################
-. /lib/network/functions
+. /usr/lib/network/functions
HOOK=$(basename ${0})
INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
function run() {
case "${action}" in
- edit|add|create|rem|up|down|status|info|hotplug)
+ edit|add|create|rem|up|down|status|info|hotplug|hotplug_rename)
_${action} $@
;;
esac
exit ${EXIT_ERROR}
}
+# This function is called after a device has been plugged
+# into the system and got its correct name.
+# The function is intended to create child ports and things
+# like that.
function _hotplug() {
- exit ${EXIT_ERROR}
+ exit ${EXIT_OK}
+}
+
+# This function gets called when a device is plugged in
+# to determine the right name.
+# The first argument is the port which should be tested
+# against the second argument which is the device that
+# has been plugged in.
+function _hotplug_rename() {
+ exit ${EXIT_FALSE}
}
function _info() {
exit ${EXIT_OK}
}
-function _hotplug() {
+function _hotplug_rename() {
local port=${1}
local device=${2}
# Log what we are doing here.
log DEBUG "Called for interface '${INTERFACE}'."
+# Just check if the device has already vanished.
+device_exists ${INTERFACE} || exit ${EXIT_ERROR}
+
# Acquiring lock for this operation.
lock_acquire ${LOCKFILE}
-# Get the name of that device from the configuration
-# or return a new one if it is unknown.
-device_hotplug ${INTERFACE}
+# Check if the device is already in use and
+# prevent the script to touch it in any way.
+if ! device_is_free ${INTERFACE}; then
+ log ERROR "The device '${INTERFACE}' is in use."
+ exit ${EXIT_ERROR}
+fi
+
+# Determine the type of the device and then see what
+# we need to do with it.
+type=$(device_get_type ${INTERFACE})
+log DEBUG "Interface '${INTERFACE}' is of type '${type}'."
+
+case "${type}" in
+ ethernet|real)
+ # Search within all the port configurations
+ # if this port has already been configured.
+ for port in $(ports_get_all); do
+ port_cmd hotplug_rename ${port} ${INTERFACE} &>/dev/null
+ if [ $? -eq ${EXIT_TRUE} ]; then
+ echo "${port}"
+ exit ${EXIT_OK}
+ fi
+ done
+
+ # If no port configuration could be found,
+ # we search for the next unused name and return that.
+ port=$(port_find_free ${PORT_PATTERN})
+ echo "${port}"
+
+ log DEBUG "Could not find an existing port configuration for '${INTERFACE}'."
+ log DEBUG "${INTERFACE} --> ${port}"
+ ;;
+esac
-exit $?
+exit ${EXIT_OK}