]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/batman-adv
Remove the function keyword which is a bashism
[people/ms/network.git] / src / hooks / ports / batman-adv
index 4dd1e9e89a65da732b5d856c11645bc721245860..4f1620199b47dfb9e84fbec5780ac3f76ea2aa85 100644 (file)
@@ -28,12 +28,12 @@ PORT_CHILDREN_VAR="SLAVES"
 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=*)
@@ -57,7 +57,7 @@ function hook_create() {
        exit ${EXIT_OK}
 }
 
-function hook_edit() {
+hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -94,67 +94,46 @@ function hook_edit() {
        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}
@@ -162,31 +141,34 @@ function hook_hotplug() {
                        # 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