return ${EXIT_ERROR}
}
-function cli_zone_headline() {
- local zone=${1}
+function cli_device_headline() {
+ local device=${1}
+ assert isset device
+
+ local type
+ if zone_exists ${device}; then
+ type="zone"
+ elif port_exists ${device}; then
+ type="port"
+ else
+ type="unknown"
+ fi
+
+ local headline_prefix
+ case "${type}" in
+ zone)
+ headline_prefix="Zone ${device}"
+ ;;
+ port)
+ headline_prefix="Port ${device}"
+ ;;
+ *)
+ headline_prefix="Device ${device}"
+ ;;
+ esac
+
+ cli_headline 1 "${headline_prefix}:"
+
+ # Print the hook for all zones.
+ if [ "${type}" = "zone" ]; then
+ cli_print_fmt1 1 "Hook" "$(zone_get_hook ${device})"
+ fi
+
+ # Print the device status.
+ local status=$(device_get_status ${device})
+ cli_print_fmt1 1 "Status" "${STATUS_COLOUR[${status}]}${STATUS_TEXT[${status}]}${COLOUR_NORMAL}"
+ if device_is_up ${device}; then
+ cli_print_fmt1 1 "MTU" "$(device_get_mtu ${device})"
+ fi
+
+ cli_space
- cli_status_headline ${zone}
+ # Print the device stats.
+ device_is_up ${device} && cli_device_stats 2 ${device}
+}
+
+function cli_device_stats() {
+ local level=${1}
+ local device=${2}
+
+ # This section will print statistical data from the device.
+ local packets bytes errors
+
+ cli_headline ${level} "Statistics"
+ local format="%-10s %9d packets %6s (%d errors)"
+
+ # RX
+ packets=$(device_get_rx_packets ${device})
+ bytes=$(device_get_rx_bytes ${device})
+ errors=$(device_get_rx_errors ${device})
+
+ cli_print ${level} "${format}" "Received" "${packets}" "$(beautify_bytes ${bytes})" "${errors}"
+
+ # TX
+ packets=$(device_get_tx_packets ${device})
+ bytes=$(device_get_tx_bytes ${device})
+ errors=$(device_get_tx_errors ${device})
+
+ cli_print ${level} "${format}" "Sent" "${packets}" "$(beautify_bytes ${bytes})" "${errors}"
+ cli_space
}
function cli_status_headline() {
+ echo "XXX THIS FUNCTION IS DEPRECATED"
+
local zone=${1}
local state="${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
fi
}
+function cli_print_warning() {
+ local level=${1}
+ shift
+
+ cli_print ${level} "${COLOUR_WARN}%s${COLOUR_NORMAL}" "$@"
+}
+
function cli_space() {
printf "\n"
}
function device_get_status() {
local device=${1}
-
assert isset device
- local status=${STATUS_UNKNOWN}
+ local status=${STATUS_DOWN}
- if ! device_has_carrier ${device}; then
- status=${STATUS_NOCARRIER}
- elif device_is_up ${device}; then
+ if device_is_up ${device}; then
status=${STATUS_UP}
- elif device_is_down ${device}; then
- status=${STATUS_DOWN}
- fi
- assert isset status
+ if ! device_has_carrier ${device}; then
+ status=${STATUS_NOCARRIER}
+ fi
+ fi
echo "${status}"
}
brctl stp ${bridge} off
}
+function stp_is_enabled() {
+ local bridge=${1}
+ assert isset bridge
+
+ local state=$(__device_get_file ${bridge} bridge/stp_state)
+
+ case "${state}" in
+ 0)
+ return ${EXIT_FALSE}
+ ;;
+ *)
+ return ${EXIT_TRUE}
+ ;;
+ esac
+}
+
function stp_get_name() {
local proto=${1}
local zone=${1}
assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
zone_config_read ${zone}
server_line="${server_line} (Hostname: ${server_hostname})"
fi
- cli_headline " Configuration:"
- printf "${DEVICE_PRINT_LINE1}" "Server:" "${server_line}"
- printf "${DEVICE_PRINT_LINE1}" "Endpoint IPv4 address:" "${LOCAL_ADDRESS}"
- printf "${DEVICE_PRINT_LINE1}" "Endpoint IPv6 address:" "${LOCAL_ADDRESS6}"
- echo
+ cli_headline 2 "Configuration"
+ cli_print_fmt1 2 "Server" "${server_line}"
+ cli_print_fmt1 2 "Endpoint IPv4 address" "${LOCAL_ADDRESS}"
+ cli_print_fmt1 2 "Endpoint IPv6 address" "${LOCAL_ADDRESS6}"
+ cli_space
exit ${EXIT_OK}
}
function _status() {
local zone=${1}
-
assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
zone_config_read ${zone}
- cli_headline " Configuration:"
- printf "${DEVICE_PRINT_LINE1}" "User:" "${USER}"
- printf "${DEVICE_PRINT_LINE1}" "Secret:" "<hidden>"
- echo
- printf "${DEVICE_PRINT_LINE1}" "Server:" "${SERVER}"
- printf "${DEVICE_PRINT_LINE1}" "Protocol:" "${PROTOCOL}"
+ cli_headline 2 "Configuration"
+ cli_print_fmt1 2 "User" "${USER}"
+ cli_print_fmt1 2 "Secret" "<hidden>"
+ cli_space
+ cli_print_fmt1 2 "Server" "${SERVER}"
+ cli_print_fmt1 2 "Protocol" "${PROTOCOL}"
if isset TUNNEL_ID; then
- echo
- printf "${DEVICE_PRINT_LINE1}" "Tunnel ID:" "${TUNNEL_ID}"
- fi
- echo
- printf "${DEVICE_PRINT_LINE1}" "Use default route?" "$(enabled DEFAULTROUTE && echo "enabled" || echo "disabled")"
- printf "${DEVICE_PRINT_LINE1}" "Use peer DNS?" "$(enabled PEERDNS && echo "enabled" || echo "disabled")"
-
- # Exit if zone is down
- if ! zone_is_up ${zone}; then
- echo # Empty line
- exit ${EXIT_ERROR}
+ cli_space
+ cli_print_fmt1 2 "Tunnel ID" "${TUNNEL_ID}"
fi
-
- cli_headline " Protocol information:"
- printf "${DEVICE_PRINT_LINE1}" "MTU:" "$(device_get_mtu ${zone})"
- echo
+ cli_space
exit ${EXIT_OK}
}
function _status() {
local zone=${1}
+ assert isset zone
- cli_status_headline ${zone}
+ # Print the default header.
+ cli_device_headline ${zone}
# Exit if zone is down
if ! zone_is_up ${zone}; then
exit ${EXIT_ERROR}
fi
- cli_headline " Spanning Tree Protocol information:"
- local proto=$(stp_bridge_get_protocol ${zone})
- local ret=$?
+ cli_headline 2 "Spanning Tree Protocol information"
+ if stp_is_enabled ${zone}; then
+ local proto=$(stp_bridge_get_protocol ${zone})
- if [ ${ret} -eq 0 ]; then
- printf "${DEVICE_PRINT_LINE1}" "Version:" "$(stp_get_name ${proto})"
- printf "${DEVICE_PRINT_LINE1}" "ID:" $(stp_bridge_get_id ${zone})
- printf "${DEVICE_PRINT_LINE1}" "Priority:" $(stp_bridge_get_priority ${zone})
+ cli_print_fmt1 2 "Version" "$(stp_get_name ${proto})"
+ cli_print_fmt1 2 "ID" "$(stp_bridge_get_id ${zone})"
+ cli_print_fmt1 2 "Priority" "$(stp_bridge_get_priority ${zone})"
if stp_bridge_is_root ${zone}; then
- echo -e " ${COLOUR_BOLD}This bridge is root.${COLOUR_NORMAL}"
+ cli_print 2 "This bridge is root."
else
- printf "${DEVICE_PRINT_LINE1}" "Designated root:" $(stp_bridge_get_designated_root ${zone})
- printf "${DEVICE_PRINT_LINE1}" "Root path cost:" $(stp_bridge_get_root_path_cost ${zone})
+ cli_print_fmt1 2 "Designated root" \
+ "$(stp_bridge_get_designated_root ${zone})"
+ cli_print_fmt1 2 "Root path cost" \
+ "$(stp_bridge_get_root_path_cost ${zone})"
fi
- echo # Empty line
+ cli_space
# Topology information
- printf "${DEVICE_PRINT_LINE1}" "Topology changing:" $(stp_bridge_get_topology_change_detected ${zone})
- printf "${DEVICE_PRINT_LINE1}" "Topology change time:" $(beautify_time $(stp_bridge_get_topology_change_timer ${zone}))
- printf "${DEVICE_PRINT_LINE1}" "Topology change count:" $(stp_bridge_get_topology_change_count ${zone})
+ cli_print_fmt1 2 "Topology changing" \
+ "$(stp_bridge_get_topology_change_detected ${zone})"
+ cli_print_fmt1 2 "Topology change time" \
+ "$(beautify_time $(stp_bridge_get_topology_change_timer ${zone}))"
+ cli_print_fmt1 2 "Topology change count" \
+ "$(stp_bridge_get_topology_change_count ${zone})"
+ cli_space
else
- echo -e " ${COLOUR_BOLD}STP is disabled.${COLOUR_NORMAL}"
+ cli_print 2 "Disabled"
+ cli_space
fi
- cli_headline " Ports:"
+ cli_headline 2 "Ports:"
zone_ports_status ${zone}
- cli_headline " Configurations:"
+ cli_headline 2 "Configurations:"
zone_configs_cmd status ${zone}
- echo # Empty line
+ cli_space
exit ${EXIT_OK}
}
function _status() {
local zone=${1}
-
assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
zone_config_read ${zone}
- cli_headline " Configuration:"
- printf "${DEVICE_PRINT_LINE1}" "User:" "${USER}"
- printf "${DEVICE_PRINT_LINE1}" "Secret:" "<hidden>"
- echo
- printf "${DEVICE_PRINT_LINE1}" "MTU:" "${MTU}"
- printf "${DEVICE_PRINT_LINE1}" "Use default route?" "$(enabled DEFAULTROUTE && echo "enabled" || echo "disabled")"
- printf "${DEVICE_PRINT_LINE1}" "Use peer DNS?" "$(enabled PEERDNS && echo "enabled" || echo "disabled")"
- echo
+ cli_headline 2 "Configuration:"
+ cli_print_fmt1 2 "User" "${USER}"
+ cli_print_fmt1 2 "Secret" "<hidden>"
+ cli_space
if device_exists ${zone}; then
- cli_headline " ISDN information:"
- printf "${DEVICE_PRINT_LINE1}" "L2 protocol:" "$(isdn_get_l2proto ${zone})"
- printf "${DEVICE_PRINT_LINE1}" "L3 protocol:" "$(isdn_get_l3proto ${zone})"
- printf "${DEVICE_PRINT_LINE1}" "Encapsulation:" "$(isdn_get_encap ${zone})"
- echo
+ cli_headline 3 "ISDN information:"
+ cli_print_fmt1 3 "L2 protocol" "$(isdn_get_l2proto ${zone})"
+ cli_print_fmt1 3 "L3 protocol" "$(isdn_get_l3proto ${zone})"
+ cli_print_fmt1 3 "Encapsulation" "$(isdn_get_encap ${zone})"
+ cli_space
fi
# Exit if zone is down
- if ! zone_is_up ${zone}; then
- echo # Empty line
- exit ${EXIT_ERROR}
- fi
+ zone_is_up ${zone} || exit ${EXIT_ERROR}
# XXX display time since connection started
- cli_headline " Point-to-Point-over-Ethernet protocol:"
- echo " IP-Address : $(routing_db_get ${zone} local-ip-address)"
- echo " Gateway : $(routing_db_get ${zone} remote-ip-address)"
- echo " DNS-Server : $(routing_db_get ${zone} dns)"
- echo
- echo " MAC-Remote : $(routing_db_get ${zone} remote-address)"
- echo
- echo " MTU : $(device_get_mtu ${zone})"
- echo # Empty line
+ cli_headline 2 "Point-to-Point protocol"
+ cli_print_fmt1 2 "IP address" "$(routing_db_get ${zone} local-ip-address)"
+ cli_print_fmt1 2 "Gateway" "$(routing_db_get ${zone} remote-ip-address)"
+ cli_print_fmt1 2 "DNS servers" "$(routing_db_get ${zone} dns)"
+ cli_space
+
exit ${EXIT_OK}
}
function _status() {
local zone=${1}
-
assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
zone_config_read ${zone}
function _status() {
local zone=${1}
-
assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
zone_config_read ${zone}
function _status() {
local zone=${1}
-
assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
zone_config_read ${zone}
- cli_headline " Configuration:"
- printf "${DEVICE_PRINT_LINE1}" "User:" "${USER}"
- printf "${DEVICE_PRINT_LINE1}" "Secret:" "<hidden>"
- echo
- printf "${DEVICE_PRINT_LINE1}" "MTU:" "${MTU}"
- printf "${DEVICE_PRINT_LINE1}" "IPv6:" "$(enabled IPV6 && echo "enabled" || echo "disabled")"
- printf "${DEVICE_PRINT_LINE1}" "Use default route?" "$(enabled DEFAULTROUTE && echo "enabled" || echo "disabled")"
- printf "${DEVICE_PRINT_LINE1}" "Use peer DNS?" "$(enabled PEERDNS && echo "enabled" || echo "disabled")"
- echo
- cli_headline " Ports:"
+ cli_headline 2 "Configuration"
+ cli_print_fmt1 2 "User" "${USER}"
+ cli_print_fmt1 2 "Secret" "<hidden>"
+ cli_space
+
+ enabled IPV6 &>/dev/null
+ local ipv6_enabled=$?
+ cli_print_fmt1 2 "IPv6?" "$(cli_print_bool ${ipv6_enabled})"
+
+ cli_headline 2 "Ports"
zone_ports_status ${zone}
if [ -z "$(zone_get_ports ${zone})" ]; then
- echo -e " ${COLOUR_WARN}No ports attached. Won't be able to start.${COLOUR_NORMAL}"
+ cli_print_warning "No ports attached. Won't be able to start."
+ cli_space
fi
# Exit if zone is down
# XXX display time since connection started
- cli_headline " Point-to-Point-over-Ethernet protocol:"
+ cli_headline 2 "Point-to-Point-over-Ethernet protocol"
local proto
for proto in ${IP_SUPPORTED_PROTOCOLS}; do
routing_db_exists ${zone} ${proto} || continue
- if [ "${proto}" = "ipv6" ]; then
- echo " Internet Protocol Version 6:"
- elif [ "${proto}" = "ipv4" ]; then
- echo " Internet Protocol Version 4:"
- fi
- echo " IP-Address : $(routing_db_get ${zone} ${proto} local-ip-address)"
- echo " Gateway : $(routing_db_get ${zone} ${proto} remote-ip-address)"
- echo " DNS-Server : $(routing_db_get ${zone} ${proto} dns)"
- echo
- echo " MAC-Remote : $(routing_db_get ${zone} ${proto} remote-address)"
- echo
+
+ local headline
+ case "${proto}" in
+ ipv6)
+ headline="Internet Protocol Version 6"
+ ;;
+ ipv4)
+ headline="Internet Protocol Version 4"
+ ;;
+ *)
+ headline="Unkown protocol"
+ ;;
+ esac
+ cli_headline 3 "${headline}"
+
+ cli_print_fmt1 3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)"
+ cli_print_fmt1 3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)"
+ cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
+ cli_space
+ cli_print_fmt1 3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)"
+ cli_space
done
- echo " MTU : $(device_get_mtu ${zone})"
- echo # Empty line
+
exit ${EXIT_OK}
}
function _status() {
local zone=${1}
-
assert isset zone
- cli_status_headline ${zone}
+ # Print a nice header.
+ cli_device_headline ${zone}
zone_config_read ${zone}
- cli_headline " Configuration:"
- printf "${DEVICE_PRINT_LINE1}" "Server:" "${SERVER}"
+ cli_headline 2 "Configuration"
+ cli_print_fmt1 2 "Server" "${SERVER}"
# Exit if zone is down
if ! zone_is_up ${zone}; then
- echo # Empty line
+ cli_space
exit ${EXIT_ERROR}
fi
- cli_headline " Protocol information:"
- printf "${DEVICE_PRINT_LINE1}" "MTU:" "$(device_get_mtu ${zone})"
- echo
+ cli_headline 2 "Protocol information"
+ cli_print_fmt1 2 "MTU" "$(device_get_mtu ${zone})"
+ cli_space
exit ${EXIT_OK}
}
function _status() {
local zone=${1}
+ assert isset zone
- cli_status_headline ${zone}
+ cli_device_headline ${zone}
# Exit if zone is down
if ! zone_is_up ${zone}; then
cli_print_fmt1 1 "MTU" "$(device_get_mtu ${device})"
cli_space
- # This section will print statistical data from the device.
- local packets bytes errors
-
- cli_headline 2 "Statistics"
- local format="%-10s %9d packets %6s (%d errors)"
-
- # RX
- packets=$(device_get_rx_packets ${device})
- bytes=$(device_get_rx_bytes ${device})
- errors=$(device_get_rx_errors ${device})
-
- cli_print 2 "${format}" "Received" "${packets}" "$(beautify_bytes ${bytes})" "${errors}"
-
- # TX
- packets=$(device_get_tx_packets ${device})
- bytes=$(device_get_tx_bytes ${device})
- errors=$(device_get_tx_errors ${device})
-
- cli_print 2 "${format}" "Sent" "${packets}" "$(beautify_bytes ${bytes})" "${errors}"
- cli_space
+ # Print device statistics.
+ cli_device_stats 2 ${device}
# Print some more information.
device_has_carrier ${device} &>/dev/null