show: add support for port classification and "show port NAME"

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-12-08 11:29:58 +01:00
parent e2f3e43461
commit c2c45026d0
+51 -4
View File
@@ -1,5 +1,6 @@
#!/bin/sh
# Displays basic information about the system
# shellcheck disable=SC2048,SC2086
. /etc/os-release
opt="-br"
@@ -20,6 +21,7 @@ options:
-h Show this help text
commands:
port PORT Show port configuration and link information
ports Show ports available for bridging
vlans Show port groups in bridge
ifaces Show interfaces and their addresses
@@ -33,8 +35,53 @@ commands:
EOF
}
# Update port classification, new ports may have been probed
update_port_group()
{
if ! grep -q port /etc/iproute2/group; then
mkdir -p /etc/iproute2
echo "1 port" >> /etc/iproute2/group
fi
# Clear port group
ifaces=$(command ip -br link | awk '{print $1}' | sed 's/@.*//g')
for iface in $ifaces; do
ip link set "$iface" group default
done
ports=$(devlink port 2>/dev/null | awk '/flavour physical/{print $5}')
for iface in $ports; do
ip link set "$iface" group port
done
# Fallback: check if user has configured any bridge ports
if [ -z "$ports" ]; then
for iface in $ifaces; do
if [ -d "/sys/class/net/$iface/brport" ]; then
ip link set "$iface" group port
fi
done
fi
}
# Usage 1: show port eth0
# Usage 2: show port
# Usage 3: show ports
#
# The first show ethtool output for 'eth0' (in this case). The latter
# two are the same, showing a summary of all interfaces classified as
# access ports.
ports()
{
if [ $# -gt 0 ] && [ -e "/sys/class/net/$1" ]; then
for port in $*; do
ethtool "$port"
done
return
fi
update_port_group
printf "\e[7mPORT STATE ADDRESS <FLAGS> \e[0m\n"
if grep -q port /etc/iproute2/group && [ -z "$all" ]; then
ip $opt link show group port
@@ -167,7 +214,7 @@ case $cmd in
usage
;;
port*)
ports
ports $*
;;
vlan*)
vlans
@@ -192,7 +239,7 @@ case $cmd in
routes
;;
igmp*)
igmp "$*"
igmp $*
;;
*)
usage
@@ -200,10 +247,10 @@ case $cmd in
esac
;;
log)
log "$1"
log $1
;;
rmon)
rmon "$*"
rmon $*
;;
route*)
routes