]> git.ipfire.org Git - people/ms/network.git/commitdiff
Create status output for ports.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 17 Jun 2012 23:42:01 +0000 (23:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 17 Jun 2012 23:42:01 +0000 (23:42 +0000)
functions.cli
functions.virtual
header-port
hooks/ports/ethernet
hooks/ports/virtual
hooks/ports/wireless-ap

index 34bfd71409b5a84e979e865a5e14ff9393759af0..d98b51305f1f33c93af4e450a5f2125ce77b88ca 100644 (file)
@@ -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}
index 5fed694498fda90e8619c14724a8f1fdda9827da..bf13809e384ad4fbe23d481130b5b986fdc08513 100644 (file)
@@ -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}
 }
index ae12047357bcd0daf6c67912319daeba19a38397..b07c99c5b4da1830906fa0cddc4417951a47c635 100644 (file)
@@ -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}
+}
index 5647e45caa118c96652a92c64dfdc60fcec4d299..d74c2df5331d68ef5cead943a988cc7ca37bc9fd 100755 (executable)
@@ -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}
-}
index 69d71b638e9b1bb70f8bd20ed9f0931a185873f7..4117c2fd4ee6889e2efb3c7e423801c91b422b66 100755 (executable)
@@ -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}
-}
index 3be46898b5fd0e0c74a0eb6464e54082ec403dc6..7ff695263735d3890248685857d4c5c1991400ef 100755 (executable)
@@ -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}