ADDRESS=$(mac_generate)
SLAVES=
-function hook_check() {
+hook_check_settings() {
assert isset ADDRESS
assert ismac ADDRESS
}
-function hook_create() {
+hook_new() {
while [ $# -gt 0 ]; do
case "${1}" in
--address=*)
exit ${EXIT_OK}
}
-function hook_edit() {
+hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function hook_up() {
- local port=${1}
+hook_create() {
+ local port="${1}"
assert isset port
port_settings_read "${port}" ${HOOK_SETTINGS}
- # Create batman device if it does not exist, yet.
- if ! device_exists "${port}"; then
- batman_adv_add "${port}"
- fi
+ # Create a new batman-adv device
+ batman_adv_add "${port}" || exit ${?}
# Set the address.
device_set_address "${port}" "${ADDRESS}"
- # Bring up the port
- device_set_up "${port}"
-
exit ${EXIT_OK}
}
-function hook_down() {
- local port=${1}
+hook_remove() {
+ local port="${1}"
assert isset port
- port_settings_read "${port}"
-
- local slave
- for slave in ${SLAVES}; do
- port_down "${slave}"
- done
+ port_settings_read "${port}" ${HOOK_SETTINGS}
- # Remove the batman device
- device_exists "${port}" && batman_adv_delete "${port}"
+ # Remove the batman-adv device
+ batman_adv_delete "${port}"
exit ${EXIT_OK}
}
-function hook_hotplug() {
+hook_hotplug() {
local port="${1}"
assert isset port
case "$(hotplug_action)" in
add)
- # Don't handle this event if the batman
- # device has not been started, yet.
- #if ! device_exists "${port}"; then
- # exit ${EXIT_NOT_HANDLED}
- #fi
-
# Handle events of the same interface
if hotplug_event_port_is_interface "${port}"; then
- # Read configuration
- port_settings_read "${port}"
-
# Bring up all slaves
# They will be attached by their own hotplug event
local slave
- for slave in ${SLAVES}; do
- if port_exists "${slave}"; then
- port_up "${slave}"
- fi
+ for slave in $(port_get_slaves "${port}"); do
+ port_create "${slave}"
done
exit ${EXIT_OK}
# Handle slave devices that have just been created and
# attach them.
elif hotplug_event_interface_is_slave_of_port "${port}"; then
- device_exists "${port}" || port_up "${port}"
-
batman_adv_attach "${port}" "${INTERFACE}"
+
+ # If the batman-adv is already up, we will bring
+ # up the slave we just added as well.
+ if port_is_up "${port}"; then
+ port_up "${INTERFACE}"
+ fi
fi
exit ${EXIT_OK}
;;
remove)
- # Bring down all slaves when the batman device went down
- local slave
- for slave in ${SLAVES}; do
- port_down "${slave}"
- done
-
- exit ${EXIT_OK}
- ;;
+ if hotplug_event_port_is_interface "${port}"; then
+ # Bring down all slaves when the batman device went down
+ local slave
+ for slave in $(port_get_slaves "${port}"); do
+ port_remove "${slave}"
+ done
- *)
- exit ${EXIT_NOT_HANDLED}
+ exit ${EXIT_OK}
+ fi
;;
esac
+ exit ${EXIT_NOT_HANDLED}
}
-function hook_status() {
+hook_status() {
local port=${1}
assert isset port