]> git.ipfire.org Git - people/stevee/network.git/blobdiff - hooks/ports/bonding
bonding: Update bonding drivers.
[people/stevee/network.git] / hooks / ports / bonding
index 892e884039553ab49777837c1457458d51599415..3d8b987e2e8ac0eceff780a00c92d5c7334759b1 100755 (executable)
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="HOOK DEVICE_MAC MIIMON MODE SLAVES"
+HOOK_SETTINGS="HOOK ADDRESS MIIMON MODE SLAVES"
 
-PORT_CHILDREN_VAR="SLAVES"
-
-DEVICE_MAC=$(mac_generate)
+ADDRESS=$(mac_generate)
+SLAVES=""
 MIIMON=100
 
 function _check() {
-       assert isset DEVICE_MAC
-       assert ismac DEVICE_MAC
+       assert isset ADDRESS
+       assert ismac ADDRESS
 
        #assert isset SLAVES
        assert isinteger MIIMON
@@ -42,22 +41,23 @@ function _create() {
 
 function _edit() {
        local port=${1}
+       assert isset port
        shift
 
        while [ $# -gt 0 ]; do
                case "${1}" in
-                       --mac=*)
-                               DEVICE_MAC=${1#--mac=}
+                       --address=*)
+                               ADDRESS=$(cli_get_val ${1})
                                ;;
                        --miimon=*)
-                               MIIMON=${1#--miimon=}
+                               MIIMON=$(cli_get_val ${1})
                                ;;
                        --mode=*)
-                               MODE=${1#--mode=}
+                               MODE=$(cli_get_val ${1})
                                ;;
                        --slave=*)
-                               slave=${1#--slave=}
-                               SLAVES="${SLAVES} $(macify ${slave})"
+                               slave=$(cli_get_val ${1})
+                               SLAVES="${SLAVES} ${slave}"
                                ;;
                        *)
                                warning "Unknown argument '${1}'"
@@ -80,8 +80,8 @@ function _edit() {
        fi
 
        local slave
-       for slave in ${SLAVES}; do
-               if ! device_is_ethernet $(devicify ${slave}); then
+       for slave in $(unquote ${SLAVES}); do
+               if ! device_is_ethernet ${slave}; then
                        error "Slave device '${slave}' is not an ethernet device."
                        exit ${EXIT_ERROR}
                fi
@@ -90,48 +90,47 @@ function _edit() {
        # Remove any whitespace
        SLAVES=$(echo ${SLAVES})
 
-       config_write $(port_file ${port}) ${HOOK_SETTINGS}
+       port_config_write ${port} ${HOOK_SETTINGS}
 
        exit ${EXIT_OK}
 }
 
 function _up() {
        local device=${1}
+       assert isset device
 
-       config_read $(port_file ${device})
+       port_config_read ${device}
 
        if device_exists ${device}; then
                log DEBUG "Bonding device '${device}' does already exist."
 
-               device_set_address ${DEVICE_MAC}
+               device_set_address ${device} ${ADDRESS}
                device_set_up ${device}
 
                exit ${EXIT_OK}
        fi
 
-       bonding_create ${device} ${DEVICE_MAC}
-       assert device_exists ${device}
+       bonding_create ${device} --address="${ADDRESS}" --mode="${MODE}"
+       local ret=$?
 
-       if [ -n "${MODE}" ]; then
-               bonding_set_mode ${device} ${MODE}
-       fi
+       [ ${ret} -eq ${EXIT_OK} ] || exit ${EXIT_ERROR}
 
        bonding_set_miimon ${device} ${MIIMON}
        device_set_up ${device}
 
        local slave
-       for slave in ${SLAVES}; do
-               if ! device_exists $(devicify ${slave}); then
+       for slave in $(unquote ${SLAVES}); do
+               if ! device_exists ${slave}; then
                        warning_log "${device}: configured slave '${slave}' is not available."
                        continue
                fi
-               
-               slave=$(devicify ${slave})
-               assert isset slave
 
                bonding_enslave_device ${device} ${slave}
        done
 
+       # Bring up the device.
+       device_set_up ${device}
+
        exit ${EXIT_OK}
 }
 
@@ -147,60 +146,3 @@ function _down() {
 
        exit ${EXIT_OK}
 }
-
-function _status() {
-        local port=${1}
-        shift
-
-        assert isset port
-
-        echo "${port}"
-
-        local status=$(device_get_status ${port})
-       # XXX STATUS_COLOUR AND STATUS_TEXT DO NOT EXIST ANYMORE
-        printf "${DEVICE_PRINT_LINE1}" "Status:" "$(echo -ne ${STATUS_COLOUR[${status}]}${STATUS_TEXT[${status}]}${COLOUR_NORMAL})"
-
-        cli_headline "  Ethernet information:"
-        printf "${DEVICE_PRINT_LINE1}" "Address:" $(device_get_address ${port})
-        printf "${DEVICE_PRINT_LINE1}" "MTU:" $(device_get_mtu ${port})
-        printf "${DEVICE_PRINT_LINE1}" "Promisc mode:" $(device_is_promisc ${port} && echo "yes" || echo "no")
-
-        if device_is_bonded ${port}; then
-                cli_headline "  Bonding information:"
-
-                local master=$(bonding_slave_get_master ${port})
-                printf "${DEVICE_PRINT_LINE1}" "Master:" "${master}"
-
-                local active
-                if [ "$(bonding_get_active_slave ${master})" = "${port}" ]; then
-                        active="yes"
-                else
-                        active="no"
-                fi
-                printf "${DEVICE_PRINT_LINE1}" "Active slave:" "${active}"
-        fi
-
-       if device_is_bonding ${port}; then
-               cli_headline "  Bonding information:"
-
-               printf "${DEVICE_PRINT_LINE1}" "Mode:" "$(bonding_get_mode ${port})"
-               # XXX lacp rate
-               echo
-
-               local slave
-               local slave_active=$(bonding_get_active_slave ${port})
-               for slave in $(bonding_get_slaves ${port}); do
-                       printf "${DEVICE_PRINT_LINE1}" "Slave$([ "${slave}" = "${slave_active}" ] && echo " (active)"):" "${slave}"
-               done
-       fi
-
-        cli_headline "  Statistics:"
-        printf "${DEVICE_PRINT_LINE1}" "Received:" \
-                "$(beautify_bytes $(device_get_rx_bytes ${port})) ($(device_get_rx_packets ${port}) packets)"
-        printf "${DEVICE_PRINT_LINE1}" "Sent:" \
-                "$(beautify_bytes $(device_get_tx_bytes ${port})) ($(device_get_tx_packets ${port}) packets)"
-
-        echo
-
-        exit ${EXIT_OK}
-}