return ${EXIT_ERROR}
}
+function cli_zone_headline() {
+ local zone=${1}
+
+ cli_status_headline ${zone}
+}
+
function cli_status_headline() {
local zone=${1}
}
function cli_headline() {
- echo
- echo -e "${COLOUR_BOLD}$@${COLOUR_NORMAL}"
+ local level=${1}
+ shift
+
+ local message="$@"
+ local ident=$(cli_ident ${level})
+
+ printf "${ident}${COLOUR_BOLD}$@${COLOUR_NORMAL}\n"
+}
+
+function cli_print() {
+ local level=${1}
+ local format=${2}
+ shift 2
+
+ local ident=$(cli_ident $(( ${level} + 1 )))
+
+ local out
+ printf -v out "${ident}${format}\n" "$@"
+ printf "${out}"
+}
+
+function cli_print_fmt1() {
+ local level=${1}
+ shift
+
+ local space=$(( 30 - (${level} * 4) ))
+ local format="%-${space}s %s"
+
+ cli_print ${level} "${format}" "$@"
+}
+
+function cli_print_bool() {
+ if [ "${1}" = "${EXIT_TRUE}" ]; then
+ echo "true"
+ else
+ echo "false"
+ fi
+}
+
+function cli_print_yesno() {
+ if [ "${1}" = "${EXIT_TRUE}" ]; then
+ echo "yes"
+ else
+ echo "false"
+ fi
+}
+
+function cli_space() {
+ printf "\n"
+}
+
+function cli_ident() {
+ local level=${1}
+ shift
+
+ local ident=""
+ while [ ${level} -gt 1 ]; do
+ ident="${ident} "
+ level=$(( ${level} - 1 ))
+ done
+
+ echo "${ident}"
}
function cli_yesno() {
local device=${1}
if device_is_virtual ${device}; then
- return 1
+ return ${EXIT_FALSE}
fi
- if [ ! -e "/proc/net/vlan/config" ]; then
- return 1
- fi
- grep -q "${1}$" /proc/net/vlan/config
+ local virtuals=$(device_get_virtuals ${device})
+ [ -n "${virtuals}" ] && return ${EXIT_OK} || return ${EXIT_ERROR}
+}
+
+function device_get_virtuals() {
+ local device=${1}
+
+ local dev spacer1 id spacer2 parent
+ while read dev spacer1 id spacer2 parent; do
+ [ "${parent}" = "${device}" ] && echo "${dev}"
+ done < /proc/net/vlan/config | sort
}
# Check if the device is a ppp device
}
# Check if the device is a physical network interface
-function device_is_real() {
+function device_is_ethernet() {
local device=${1}
device_is_loopback ${device} && \
elif device_is_wireless ${device}; then
echo "wireless"
- elif device_is_real ${device}; then
- echo "real"
+ elif device_is_ethernet ${device}; then
+ echo "ethernet"
else
echo "unknown"
local device=${1}
assert isset device
- [ "$(<${SYS_CLASS_NET}/${device}/carrier)" = "1" ]
+ local carrier=$(__device_get_file ${device} carrier)
+ [ "${carrier}" = "1" ]
}
function device_is_promisc() {
__device_get_file ${device} statistics/tx_errors
}
+
+function device_get_speed() {
+ local device=${1}
+
+ __device_get_file ${device} speed
+}
+
+function device_get_duplex() {
+ local device=${1}
+
+ __device_get_file ${device} duplex
+}
local slave
for slave in ${SLAVES}; do
- if ! device_is_real $(devicify ${slave}); then
+ if ! device_is_ethernet $(devicify ${slave}); then
error "Slave device '${slave}' is not an ethernet device."
exit ${EXIT_ERROR}
fi
MANPAGES8 = \
network.8 \
network-config.8 \
+ network-device.8 \
network-zone.8
.PHONY: all
@: # Do nothing.
# Replace all placeholders.
-$(MANPAGES): Makefile $(MANPAGES_IN)
+$(MANPAGES): ../Makeconfig Makefile $(MANPAGES_IN)
sed \
-e "s/@VERSION@/$(PACKAGE_VERSION)/g" \
< $@.in > $@
--- /dev/null
+.TH network-device 8 "6 Jun 2012" "@VERSION@" "network man page"
+
+.SH NAME
+network-device \- Network Configuration Control Program
+
+.SH SYNOPSIS
+\fBnetwork [OPTIONS] device <device> [status|discover] ...\fR
+
+.SH DESCRIPTION
+By the device subcommands, it is very easy to get status information
+about network devices and do some more things.
+
+.SH OPTIONS
+The \fBnetwork device\fR command offers various commands:
+
+\fB<device> status\fR
+.RS 4
+This will show you very detailed information about the given device.
+.PP
+This is all about the ethernet parts of the device and does not contain
+any IP information as this is defined as a zone (\fBnetwork-zone\fR(8)).
+.RE
+.PP
+
+\fB<device> discover\fR
+.RS 4
+Runs a discovery for many hooks on the given device. This will check
+if the hook can find for example a DHCP server or DSLAM and thus predict
+for what the device should be used.
+.RE
+.PP
+
+.SH SEE ALSO
+network(8)
+
+.SH AUTHOR
+Michael Tremer (michael.tremer@ipfire.org)
local action=${2}
shift 2
- assert device_exists ${device}
-
- if zone_exists ${device} || port_exists ${device}; then
- error "The device '${device}' has already been configured."
- error "You cannot do a device action."
+ if ! isset device; then
+ cli_show_man network-device
return ${EXIT_ERROR}
fi
+ assert device_exists ${device}
+
case "${action}" in
discover)
- echo "# XXX need to implement --raw here"
cli_device_discover ${device} $@
;;
-
- show|"")
- # XXX device_show needs to be implemented
- device_show ${device}
+ status)
+ cli_device_status ${device}
;;
*)
cli_show_man network-device
;;
esac
+
+ return ${EXIT_OK}
+}
+
+function cli_device_status() {
+ local device=${1}
+ assert device_exists ${device}
+
+ # Save the type of the device for later.
+ local type=$(device_get_type ${device})
+
+ cli_headline 1 "Device status: ${device}"
+ cli_print_fmt1 1 "Name" "${device}"
+
+ # Print the device status.
+ device_is_up ${device} &>/dev/null
+ local status=$?
+
+ case "${status}" in
+ ${EXIT_TRUE})
+ status="${COLOUR_GREEN}UP${COLOUR_NORMAL}"
+ ;;
+ ${EXIT_FALSE})
+ status="${COLOUR_RED}DOWN${COLOUR_NORMAL}"
+ ;;
+ esac
+
+ cli_print_fmt1 1 "Status" "${status}"
+ cli_print_fmt1 1 "Type" "${type}"
+ cli_print_fmt1 1 "Address" "$(device_get_address ${device})"
+ cli_space
+
+ # Print the link speed for ethernet devices.
+ case "${type}" in
+ ethernet)
+ cli_print_fmt1 1 "Link" \
+ "$(device_get_speed ${device}) MBit/s $(device_get_duplex ${device}) duplex"
+ ;;
+ esac
+
+ 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 some more information.
+ device_has_carrier ${device} &>/dev/null
+ cli_print_fmt1 1 "Has carrier?" "$(cli_print_bool $?)"
+
+ device_is_promisc ${device} &>/dev/null
+ cli_print_fmt1 1 "Promisc" "$(cli_print_bool $?)"
+ cli_space
+
+ # Print all virtual devices.
+ local virtuals=$(device_get_virtuals ${device})
+ if [ -n "${virtuals}" ]; then
+ cli_headline 2 "Virtual devices"
+
+ local virtual
+ for virtual in ${virtuals}; do
+ cli_print 2 "* %-6s - %s" "${virtual}" "$(device_get_address ${virtual})"
+ done
+ cli_space
+ fi
+
}
function cli_device_discover() {
# Check, if the device is a physical network interface and
# if we can handle it.
if device_exists ${INTERFACE}; then
- if ! device_is_real ${INTERFACE}; then
+ if ! device_is_ethernet ${INTERFACE}; then
log DEBUG "Called for interface '${INTERFACE}' which is a virtual interface. Exiting."
exit ${EXIT_OK}
fi