]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/ports/batman-adv
Fix hook settings writing and checking
[people/stevee/network.git] / src / hooks / ports / batman-adv
index 27cfd9f374c74cd327fbe6bae2902bac421a036d..40b9735f69c2922ae4ac164e64cfb143079eac5d 100644 (file)
@@ -28,12 +28,12 @@ PORT_CHILDREN_VAR="SLAVES"
 ADDRESS=$(mac_generate)
 SLAVES=
 
-function hook_check() {
+function hook_check_settings() {
        assert isset ADDRESS
        assert ismac ADDRESS
 }
 
-function hook_create() {
+function hook_new() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --address=*)
@@ -94,57 +94,78 @@ function hook_edit() {
        exit ${EXIT_OK}
 }
 
-function hook_up() {
-       local port=${1}
+function hook_create() {
+       local port="${1}"
        assert isset port
 
        port_settings_read "${port}" ${HOOK_SETTINGS}
 
-       # 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
-
-       # 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}
+function hook_remove() {
+       local port="${1}"
        assert isset port
 
-       port_settings_read "${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}
+       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() {