Almroth.com




[Home] [Software] [Projects] [Documents] [Links] [Photos] [Contact us]

#!/bin/ksh
# Network interface checkup script
# Works for hme and eri interfaces
#
# Copyright (C) 2002 Andreas Almroth
#
# Arguments:
# status - Report status for each interface
# cap - Report capabilities for each interface
# all - Dump of all variables for each interface
#
# Option: -v for more verbose output
#
# Version 0.2 10/10/2002
# Changed the way detecting interfaces to support hme,eri,qfe
#
# Version 0.1 06/07/2002
# Support for eri and hme interfaces
#
# TODO: Add full support for ge (Gigabit Ethernet) adapter
#

VARS="transceiver_inuse link_status link_speed link_mode ipg1 ipg2 use_int_xcvr pace_size adv_autoneg_cap adv_100T4_cap adv_100fdx_cap adv_100hdx_cap adv_10fdx_cap adv_10hdx_cap autoneg_cap 100T4_cap 100fdx_cap 100hdx_cap 10fdx_cap 10hdx_cap lp_autoneg_cap lp_100T4_cap lp_100fdx_cap lp_100hdx_cap lp_10fdx_cap lp_10hdx_cap instance lance_mode ipg0" GEM_VARS="transceiver_inuse link_status link_speed link_mode ipg1 ipg2 adv_1000autoneg_cap adv_1000fdx_cap adv_1000hdx_cap 1000autoneg_cap 1000fdx_cap 1000hdx_cap lp_1000autoneg_cap lp_1000fdx_cap lp_1000hdx_cap instance lance_mode ipg0 adv_pauseTX adv_pauseRX asm_dir_cap pause_cap lp_asm_dir_cap lp_pause_cap"

HOST=`/bin/uname -n`a
PLATFORM=`/bin/uname -i`
VERBOSE=0

if [ $# -gt 1 ]; then
if [ $2 = "-v" ]; then
VERBOSE=1
fi
fi

if [ `id | cut -b5` != "0" ]; then
echo "Not logged in as root, exiting."
exit 1
fi

# Test if interfaces are loaded
# First, good ol' hme
if [ `prtconf -D | grep -c 'hme)'` -gt 0 ]; then
IF="hme"
fi
#Then, check eri
# SunFire V880
if [ `prtconf -D | grep -c 'eri)'` -gt 0 ]; then
IF=$IF" eri"
fi
#Then qfe
# Quad Fast Ethernet I/O board
if [ `prtconf -D | grep -c 'qfe)'` -gt 0 ]; then
IF=$IF" qfe"
fi
#Then dmfe
# Netra X1, SunFire V100
if [ `prtconf -D | grep -c 'dmfe)'` -gt 0 ]; then
IF=$IF" dmfe"
fi
#Then ge
# Gigbit Ethernet
#if [ `prtconf -D | grep -c 'ge)'` -gt 0 ]; then
# IF=$IF" ge"
#fi

case "$1" in
'status')
for q in $IF;
do
INSTANCES=`grep \"$q\" /etc/path_to_inst | cut -d' ' -f2 | sort`

for i in $INSTANCES;
do
/usr/sbin/ndd -set /dev/$q instance $i
RES=`/usr/sbin/ndd /dev/$q link_status`
if [ $RES -eq 1 ]; then
STATUS="Link is up"

RES=`/usr/sbin/ndd /dev/$q link_speed`
if [ $RES -eq 1 ]; then
if [ $q = "ge" ]; then
SPEED="1000Mbit"
else
SPEED="100Mbit"
fi
else
SPEED="10Mbit"
fi

RES=`/usr/sbin/ndd /dev/$q link_mode`
if [ $RES -eq 1 ]; then
MODE="full duplex"
else
MODE="half duplex"
fi

echo "$q$i: $STATUS, configured for $SPEED with $MODE."
else
STATUS="Link is down"
echo "$q$i: $STATUS."
fi

if [ $VERBOSE -eq 1 ]; then
ifconfig $q$i >/dev/null 2>&1
if [ $? -eq 0 ]; then
IFINET=`ifconfig $q$i | grep inet | cut -d' ' -f2`
IFNAME=`grep $IFINET /etc/hosts | awk '{print $2}'`
MAC=`arp -a | grep $IFNAME | awk '{print $5}'`
echo "$q$i: Plumbed with IP address $IFINET and MAC address $MAC"
else
echo "$q$i: Not plumbed"
fi
fi

done

done

;;

'cap')

echo "=========================================================="

echo "Capabilites report for interfaces on $HOST"

echo "=========================================================="

echo " "

for q in $IF;

do

INSTANCES=`grep \"$q\" /etc/path_to_inst | cut -d' ' -f2 | sort`

for i in $INSTANCES;

do

/usr/sbin/ndd -set /dev/$q instance $i

echo "Interface $q$i:"

echo "Running configuration;"

RES=`/usr/sbin/ndd /dev/$q autoneg_cap`

if [ $RES -eq 1 ]; then

echo "Auto negotiation capable"

else

echo "Not capable of auto-negotiation"

fi

RES=`/usr/sbin/ndd /dev/$q 100T4_cap`

if [ $RES -eq 1 ]; then

echo "100BASE-T4 capable"

else

echo "Not 100BASE-T4 capable"

fi

RES=`/usr/sbin/ndd /dev/$q 100fdx_cap`

if [ $RES -eq 1 ]; then

echo "100 Mbit/sec full-duplex capable"

else

echo "Not 100 Mbit/sec full-duplex capable"

fi

RES=`/usr/sbin/ndd /dev/$q 100hdx_cap`

if [ $RES -eq 1 ]; then

echo "100 Mbit/sec half-duplex capable"

else

echo "Not 100 Mbit/sec half-duplex capable"

fi

RES=`/usr/sbin/ndd /dev/$q 10fdx_cap`

if [ $RES -eq 1 ]; then

echo "10 Mbit/sec full-duplex capable"

else

echo "Not 10 Mbit/sec full-duplex capable"

fi

RES=`/usr/sbin/ndd /dev/$q 10hdx_cap`

if [ $RES -eq 1 ]; then

echo "10 Mbit/sec half-duplex capable"

else

echo "Not 10 Mbit/sec half-duplex capable"

fi

echo " "

echo "Advertising following capabilities;"

RES=`/usr/sbin/ndd /dev/$q adv_autoneg_cap`

if [ $RES -eq 1 ]; then

echo "Auto-negotiation"

else

echo "Forced mode"

fi

RES=`/usr/sbin/ndd /dev/$q adv_100T4_cap`

if [ $RES -eq 1 ]; then

echo "100BASE-T4 capable"

else

echo "Not 100BASE-T4 capable"

fi

RES=`/usr/sbin/ndd /dev/$q adv_100fdx_cap`

if [ $RES -eq 1 ]; then

echo "100 Mbit/sec full-duplex capable"

else

echo "Not 100 Mbit/sec full-duplex capable"

fi

RES=`/usr/sbin/ndd /dev/$q adv_100hdx_cap`

if [ $RES -eq 1 ]; then

echo "100 Mbit/sec half-duplex capable"

else

echo "Not 100 Mbit/sec half-duplex capable"

fi

RES=`/usr/sbin/ndd /dev/$q adv_10fdx_cap`

if [ $RES -eq 1 ]; then

echo "10 Mbit/sec full-duplex capable"

else

echo "Not 10 Mbit/sec full-duplex capable"

fi

RES=`/usr/sbin/ndd /dev/$q adv_10hdx_cap`

if [ $RES -eq 1 ]; then

echo "10 Mbit/sec half-duplex capable"

else

echo "Not 10 Mbit/sec half-duplex capable"

fi

echo "---------------------------------------------------------------"

done

done

;;

'all')

echo "=========================================================="

echo "Variables report for interfaces on $HOST"

echo "=========================================================="

echo " "

for q in $IF;

do

INSTANCES=`grep \"$q\" /etc/path_to_inst | cut -d' ' -f2 | sort`

for x in $INSTANCES;

do

/usr/sbin/ndd -set /dev/$IF instance $x

echo "Interface $IF$x:"

for i in $VARS;

do

RES=`/usr/sbin/ndd /dev/$IF $i`

echo $i "=" $RES

done

echo "------------------------------------------"

done

done

;;

*)

echo "Usage: $0 <status | cap | all> [ -v ]"

exit 1

;;

esac


Copyright (c) 2004 Andreas Almroth

Modified 2004/12/05