]> git.ipfire.org Git - network.git/blobdiff - hooks/zones/bridge.ports/ethernet
STP: Rewrite most of the functions to get rid of brctl.
[network.git] / hooks / zones / bridge.ports / ethernet
index d25448854bf9a69505b456078d1b93db466e866b..4ff10a36c80224dec25ac99e1e1e555cf66d8995 100755 (executable)
 #                                                                             #
 ###############################################################################
 
-. /lib/network/header-port
+. /usr/lib/network/header-port
 
-HOOK_SETTINGS="HOOK DEVICE"
+HOOK_SETTINGS="COST PRIORITY"
 
 function _check() {
-       assert isset DEVICE
-       assert ismac DEVICE
+       local i
+       for i in COST PRIORITY; do
+               if isset ${i}; then
+                       assert isinteger ${i}
+               fi
+       done
 }
 
-function _create() {
+function _add() {
        local zone=${1}
-       local device=${2}
+       local port=${2}
        shift 2
 
-       if [ -z "${device}" ]; then
-               error "No device given."
+       assert isset zone
+       assert isset port
+
+       if ! port_exists ${port}; then
+               error "Port '${port}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       if ! device_exists ${device}; then
-               warning "Device does not exist."
-       fi
+       config_read $(zone_dir ${zone})/ports/${port}
 
-       DEVICE=$(macify ${device})
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --priority=*)
+                               PRIORITY=${1#--priority=}
+                               ;;
+                       --cost=*)
+                               COST=${1#--cost=}
+                               ;;
+               esac
+               shift
+       done
 
-       config_write $(zone_dir ${zone})/port.${HOOK}.$(device_hash ${device}) ${HOOK_SETTINGS}
+       config_write $(zone_dir ${zone})/ports/${port} ${HOOK_SETTINGS}
 
        exit ${EXIT_OK}
 }
 
-function _up() {
+function _edit() {
+       _add $@
+}
+
+function _rem() {
        local zone=${1}
        local port=${2}
 
-       config_read $(zone_dir ${zone})/${port}
+       assert isset zone
+       assert isset port
 
-       local device=$(devicify ${DEVICE})
+       assert zone_exists ${zone}
 
-       if ! device_exists ${device}; then
-               warning "Device '${DEVICE}' does not exist."
+       if ! listmatch ${port} $(zone_get_ports ${zone}); then
+               error "Port '${port}' does not belong to '${zone}'."
+               error "Won't remove anything."
                exit ${EXIT_ERROR}
        fi
 
+       if port_exists ${port}; then
+               ( _down ${zone} ${port} )
+       fi
+
+       rm -f $(zone_dir ${zone})/ports/${port}
+
+       exit ${EXIT_OK}
+}
+
+function _up() {
+       local zone=${1}
+       local port=${2}
+
+       assert isset zone
+       assert isset port
+
+       assert zone_exists ${zone}
+       assert port_exists ${port}
+
+       port_up ${port}
+
        # Set same MTU to device that the bridge has got
-       device_set_mtu ${device} $(device_get_mtu ${zone})
+       device_set_mtu ${port} $(device_get_mtu ${zone})
 
-       device_set_up ${device}
+       bridge_attach_device ${zone} ${port}
 
-       bridge_attach_device ${zone} ${device}
+       # XXX must set cost and prio here
 
        exit ${EXIT_OK}
 }
@@ -76,18 +118,15 @@ function _down() {
        local zone=${1}
        local port=${2}
 
-       config_read $(zone_dir ${zone})/${port}
+       assert isset zone
+       assert isset port
 
-       local device=$(devicify ${DEVICE})
+       assert zone_exists ${zone}
+       assert port_exists ${port}
 
-       if ! device_exists ${device}; then
-               warning "Device '${DEVICE}' does not exist."
-               exit ${EXIT_ERROR}
-       fi
-
-       bridge_detach_device ${zone} ${device}
+       bridge_detach_device ${zone} ${port}
 
-       device_set_down ${device}
+       port_down ${port}
 
        exit ${EXIT_OK}
 }
@@ -96,24 +135,31 @@ function _status() {
        local zone=${1}
        local port=${2}
 
-       config_read $(zone_dir ${zone})/${port}
+       # Do nothing for devices which are not up and running.
+       device_exists ${port} || exit ${EXIT_OK}
+
+       local status
 
-       local device=$(devicify ${DEVICE})
+       # Check if the device is down.
+       if ! device_is_up ${port}; then
+               status=${MSG_DEVICE_STATUS_DOWN}
 
-       printf "        %-10s - " "${device}"
-       if ! device_is_up ${device}; then
-               echo -ne "${COLOUR_DOWN}   DOWN   ${COLOUR_NORMAL}"
+       # Check if the device has no carrier.
+       elif ! device_has_carrier ${port}; then
+               status=${MSG_DEVICE_STATUS_NOCARRIER}
+
+       # Check for STP information.
+       elif stp_is_enabled ${zone}; then
+               local state=$(stp_port_get_state ${zone} ${port})
+               state="MSG_STP_${state}"
+               status="${!state}"
+
+               status="${status} - DSR: $(stp_port_get_designated_root ${zone} ${port})"
+               status="${status} - Cost: $(stp_port_get_cost ${zone} ${port})"
        else
-               local state=$(stp_port_state ${zone} ${device})
-               local colour="COLOUR_STP_${state}"
-               printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
+               status=${MSG_DEVICE_STATUS_UP}
        fi
-       
-       echo -n " - DSR: $(stp_port_designated_root ${zone} ${device})"
-       echo -n " - Cost: $(stp_port_pathcost ${zone} ${device})"
-       echo
+       cli_statusline 3 "${port}" "${status}"
 
        exit ${EXIT_OK}
 }
-
-run $@