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"
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
;;
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() {
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}
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}
}
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}
}
exit ${ERROR_OK}
}
+
+function _status() {
+ local port=${1}
+ assert isset port
+
+ cli_device_headline ${port} --long
+ exit ${EXIT_OK}
+}
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}
-}
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}
-}
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}