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=*)
- ADDRESS="$(cli_get_val ${1})"
+ ADDRESS="$(cli_get_val "${1}")"
;;
--slaves=*)
- SLAVES="$(cli_get_val ${1})"
+ SLAVES="$(cli_get_val "${1}")"
;;
*)
warning "Ignoring unknown argument '${1}'"
local port=$(port_find_free ${PORT_PATTERN_BATMAN_ADV})
assert isset port
- config_write $(port_file ${port}) ${HOOK_SETTINGS}
+ port_settings_write "${port}" ${HOOK_SETTINGS}
exit ${EXIT_OK}
}
-function hook_edit() {
+hook_edit() {
local port=${1}
assert isset port
shift
- config_read $(port_file ${port})
+ port_settings_read "${port}"
while [ $# -gt 0 ]; do
case "${1}" in
--address=*)
- ADDRESS="$(cli_get_val ${1})"
+ ADDRESS="$(cli_get_val "${1}")"
;;
--add-slave=*)
- SLAVES="${SLAVES} $(cli_get_val ${1})"
+ SLAVES="${SLAVES} $(cli_get_val "${1}")"
;;
--del-slave=*)
- local slave="$(cli_get_val ${1})"
+ local slave="$(cli_get_val "${1}")"
local s slaves
for s in ${SLAVES}; do
shift
done
- config_write $(port_file ${port}) ${HOOK_SETTINGS}
+ port_settings_write "${port}" ${HOOK_SETTINGS}
exit ${EXIT_OK}
}
-function hook_up() {
- local port=${1}
+hook_create() {
+ local port="${1}"
assert isset port
- config_read $(port_file ${port})
-
- # This cannot be started manually, but is created automatically
- # when a slave device is brought up and set up by _hotplug.
-
- local slave
- for slave in ${SLAVES}; do
- port_up "${slave}"
- done
+ port_settings_read "${port}" ${HOOK_SETTINGS}
- # If the port has been created (does not happen, when there are
- # no slaves), we bring it up.
- if device_exists "${port}"; then
- # Set the address.
- device_set_address "${port}" "${ADDRESS}"
+ # Create a new batman-adv device
+ batman_adv_add "${port}" || exit ${?}
- device_set_up "${port}"
- fi
+ # Set the address.
+ device_set_address "${port}" "${ADDRESS}"
exit ${EXIT_OK}
}
-function hook_down() {
- local port=${1}
+hook_remove() {
+ local port="${1}"
assert isset port
- config_read $(port_file ${port})
+ port_settings_read "${port}" ${HOOK_SETTINGS}
- local slave
- for slave in ${SLAVES}; do
- port_down "${slave}"
- done
+ # Remove the batman-adv device
+ batman_adv_delete "${port}"
exit ${EXIT_OK}
}
-function hook_hotplug() {
- local port=${1}
+hook_hotplug() {
+ local port="${1}"
assert isset port
- local phy=${2}
- assert isset phy
+ case "$(hotplug_action)" in
+ add)
+ # Handle events of the same interface
+ if hotplug_event_port_is_interface "${port}"; then
+ # Bring up all slaves
+ # They will be attached by their own hotplug event
+ local slave
+ for slave in $(port_get_slaves "${port}"); do
+ port_create "${slave}"
+ done
- # Bring up the device.
- port_up "${port}"
+ exit ${EXIT_OK}
+
+ # Handle slave devices that have just been created and
+ # attach them.
+ elif hotplug_event_interface_is_slave_of_port "${port}"; then
+ 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)
+ 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_OK}
+ exit ${EXIT_OK}
+ fi
+ ;;
+ esac
+ exit ${EXIT_NOT_HANDLED}
}
-function hook_status() {
+hook_status() {
local port=${1}
assert isset port