From: Michael Tremer Date: Sun, 17 Jun 2012 23:42:01 +0000 (+0000) Subject: Create status output for ports. X-Git-Tag: 004~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe8e6d696976cdedec94b5acb3649573e4ce6b27;p=network.git Create status output for ports. --- diff --git a/functions.cli b/functions.cli index 34bfd714..d98b5130 100644 --- a/functions.cli +++ b/functions.cli @@ -35,6 +35,17 @@ function cli_device_headline() { local device=${1} assert isset device + local long=0 + shift + while [ $# -gt 0 ]; do + case "${1}" in + --long) + long=1 + ;; + esac + shift + done + local type if zone_exists ${device}; then type="zone" @@ -50,10 +61,10 @@ function cli_device_headline() { headline_prefix="Zone ${device}" ;; port) - headline_prefix="Port ${device}" + headline_prefix="Port ${device} ($(device_get_type ${device}))" ;; *) - headline_prefix="Device ${device}" + headline_prefix="Device ${device} ($(device_get_type ${device}))" ;; esac @@ -80,14 +91,32 @@ function cli_device_headline() { ;; esac cli_print_fmt1 1 "Status" "${status}" + if enabled ${long}; then + cli_print_fmt1 1 "Address" "$(device_get_address ${device})" + fi if device_is_up ${device}; then cli_print_fmt1 1 "MTU" "$(device_get_mtu ${device})" fi + if enabled ${long}; then + device_is_promisc ${device} &>/dev/null + cli_print_fmt1 1 "Promisc" "$(cli_print_bool $?)" + fi cli_space # Print the device stats. device_is_up ${device} && cli_device_stats 2 ${device} + + if enabled ${long}; then + # Virtual devices. + device_is_virtual ${device} && cli_device_virtual ${device} + + # Bonded devices. + device_is_bonded ${device} && cli_device_bonded ${device} + + # Bonding devices. + device_is_bonding ${device} && cli_device_bonding ${device} + fi } function cli_device_stats() { @@ -116,6 +145,52 @@ function cli_device_stats() { cli_space } +function cli_device_virtual() { + local device=${1} + + cli_headline 2 "VLAN" + + cli_print_fmt1 2 "Parent" "$(virtual_get_parent ${device})" + cli_print_fmt1 2 "VID" "$(virtual_get_id ${device})" + cli_space +} + +function cli_device_bonded() { + local device=${1} + + cli_headline 2 "Bonding information" + + local master=$(bonding_slave_get_master ${port}) + cli_print_fmt1 2 "Master" "${master}" + + local active + [ "$(bonding_get_active_slave ${master})" = "${port}" ] + cli_print_fmt1 2 "Active slave" "$(cli_print_yesno $?)" + cli_space +} + +function cli_device_bonding() { + local device=${1} + + cli_headline 2 "Bonding information" + + cli_print_fmt1 2 "Mode" "$(bonding_get_mode ${port})" + # XXX lacp rate + cli_space + + local slave slave_prefix + local slave_active=$(bonding_get_active_slave ${device}) + for slave in $(bonding_get_slaves ${device}); do + if [ "${slave_active}" = "${slave}" ]; then + slave_prefix="Slave (active)" + else + slave_prefix="Slave" + fi + cli_print_fmt1 2 "${slave_prefix}" "${slave}" + done + cli_space +} + function cli_headline() { local level=${1} local format=${2} diff --git a/functions.virtual b/functions.virtual index 5fed6944..bf13809e 100644 --- a/functions.virtual +++ b/functions.virtual @@ -144,12 +144,27 @@ function virtual_remove() { function virtual_get_parent() { local device=${1} - local parent=$(grep "^${device}" < /proc/net/vlan/config | awk '{ print $NF }') + local dev spacer1 id spacer2 parent + while read dev spacer1 id spacer2 parent; do + if [ "${device}" = "${dev}" ]; then + echo "${parent}" + return ${EXIT_OK} + fi + done < /proc/net/vlan/config - if device_exists ${parent}; then - echo "${parent}" - return ${EXIT_OK} - fi + return ${EXIT_ERROR} +} + +function virtual_get_id() { + local device=${1} + + local dev spacer1 id spacer2 parent + while read dev spacer1 id spacer2 parent; do + if [ "${device}" = "${dev}" ]; then + echo "${id}" + return ${EXIT_OK} + fi + done < /proc/net/vlan/config return ${EXIT_ERROR} } @@ -161,19 +176,15 @@ function virtual_get_by_parent_and_vid() { assert isset parent assert isset vid - local v_port - local v_id - local v_parent - assert [ -e "/proc/net/vlan/config" ] - fgrep '|' < /proc/net/vlan/config | tr -d '|' | \ - while read v_port v_id v_parent; do - if [ "${v_parent}" = "${parent}" ] && [ "${v_id}" = "${vid}" ]; then - echo "${v_port}" - return ${EXIT_OK} - fi - done + local dev spacer1 id spacer2 par + while read dev spacer1 id spacer2 par; do + if [ "${parent}" = "${par}" ] && [ "${vid}" = "${id}" ]; then + echo "${dev}" + return ${EXIT_OK} + fi + done < /proc/net/vlan/config return ${EXIT_ERROR} } diff --git a/header-port b/header-port index ae120473..b07c99c5 100644 --- a/header-port +++ b/header-port @@ -60,3 +60,11 @@ function _info() { exit ${ERROR_OK} } + +function _status() { + local port=${1} + assert isset port + + cli_device_headline ${port} --long + exit ${EXIT_OK} +} diff --git a/hooks/ports/ethernet b/hooks/ports/ethernet index 5647e45c..d74c2df5 100755 --- a/hooks/ports/ethernet +++ b/hooks/ports/ethernet @@ -77,45 +77,3 @@ function _hotplug_rename() { log DEBUG "Device '${device}' does not equal port '${port}'." exit ${EXIT_ERROR} } - -function _status() { - local port=${1} - shift - - assert isset port - - echo "${port}" - - local status=$(device_get_status ${port}) - 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 - - 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} -} diff --git a/hooks/ports/virtual b/hooks/ports/virtual index 69d71b63..4117c2fd 100755 --- a/hooks/ports/virtual +++ b/hooks/ports/virtual @@ -126,27 +126,3 @@ function _down() { exit ${EXIT_OK} } - -function _status() { - local zone=${1} - local port=${2} - - config_read $(zone_dir ${zone})/${port} - - local device=$(devicify ${ADDRESS}) - - printf " %-10s - " "${device}" - if ! device_is_up ${device}; then - echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}" - else - local state=$(stp_port_state ${zone} ${device}) - local colour="COLOUR_STP_${state}" - printf "${!colour}%10s${COLOUR_NORMAL}" ${state} - fi - - echo -n " - DSR: $(stp_port_designated_root ${zone} ${device})" - echo -n " - Cost: $(stp_port_pathcost ${zone} ${device})" - echo - - exit ${EXIT_OK} -} diff --git a/hooks/ports/wireless-ap b/hooks/ports/wireless-ap index 3be46898..7ff69526 100755 --- a/hooks/ports/wireless-ap +++ b/hooks/ports/wireless-ap @@ -172,30 +172,6 @@ function _down() { exit ${EXIT_OK} } -function _status() { - local zone=${1} - local port=${2} - -config_read $(zone_dir ${zone})/${port} - - local device=$(devicify ${DEVICE_MAC}) - - printf " %-10s - " "${device}" - if ! device_is_up ${device}; then - echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}" - else - local state=$(stp_port_state ${zone} ${device}) - local colour="COLOUR_STP_${state}" - printf "${!colour}%10s${COLOUR_NORMAL}" ${state} - fi - - echo -n " - DSR: $(stp_port_designated_root ${zone} ${device})" - echo -n " - Cost: $(stp_port_pathcost ${zone} ${device})" - echo - - exit ${EXIT_OK} -} - function _hotplug() { local port=${1} local phy=${2}