#!/bin/sh # # Solaris Ethernet Link Checker # Prints the configuration of the interface instance and the # status of the link. # AUTHOR="Mike Arnold " VERSION=200210171231 # # Tested with eri, hme, and qfe. Need to test ge. # #set -x # Check for root priv's if [ ! `/usr/xpg4/bin/id -u` -eq 0 ]; then echo " You must have root priviledges to run this program." exit 2 fi # Function that returns the interface instance. which_inst () { case $1 in ge*) echo $1 | sed 's/ge//';; eri*) echo $1 | sed 's/eri//';; hme*) echo $1 | sed 's/hme//';; qfe*) echo $1 | sed 's/qfe//';; esac } # Function to query the device driver and pretty-print the results. query_print () { DRIVER_VAR="$1" LINE0="$2" LINE1="$3" LINEPRE="$4" RESULT=`ndd /dev/$DEV $DRIVER_VAR` if [ $RESULT -eq 0 ]; then echo "$LINEPRE$LINE0" elif [ $RESULT -eq 1 ]; then echo "$LINEPRE$LINE1" fi } # Function to test the output of which_inst and make sure it is correct. sanity_chk () { echo "$INST" | grep -v "[^0-9]" > /dev/null 2>&1 # If value returned is not a numeral, exit. if [ "$?" -eq 1 ]; then echo "Invalid argument: Device instance is not numeric." exit 3 fi # If value returned is null, exit. if [ -z "$INST" ]; then echo "Invalid argument: Device instance is null." exit 4 fi ndd -set /dev/$DEV instance $INST 2>&1 | grep . > /dev/null 2>&1 # If any output from ndd, exit. if [ "$?" -eq 0 ]; then echo "Invalid interface instance: Do you have one of those?" exit 5 fi } # Function to print link information of the interface. print_link () { query_print link_status "down" "up" " Link Status is " case $DEV in ge) query_print link_speed "0 Mbps" "1000 Mbps" " Link Speed is ";; *) query_print link_speed "10 Mbps" "100 Mbps" " Link Speed is ";; esac query_print link_mode "Half Duplex" "Full Duplex" " Link Mode is " } # Function to consolidate the repetitions in the fast ethernet drivers. print_fasteth () { echo "Checking ${DEV}${INST}: " query_print adv_autoneg_cap "off" "on" " Autonegotiation capability is " query_print adv_100fdx_cap "off" "on" " 100 Mbps Full Duplex capability is " query_print adv_100hdx_cap "off" "on" " 100 Mbps Half Duplex capability is " query_print adv_10fdx_cap "off" "on" " 10 Mbps Full Duplex capability is " query_print adv_10hdx_cap "off" "on" " 10 Mbps Half Duplex capability is " } # Function to print the help screen. print_help () { echo "Usage: `basename $0` " echo " ex. `basename $0` hme1" echo " Only ge, eri, hme, and qfe are supported." exit 1 } # Figure out what we have been fed and act. case $1 in ge*) DEV=ge INST=`which_inst $1` sanity_chk echo "Checking ${DEV}${INST}: " query_print adv_1000autoneg_cap "off" "on" \ " Autonegotiation capability is " query_print adv_1000fdx_cap "off" "on" \ " 1000 Mbps Full Duplex capability is " query_print adv_1000hdx_cap "off" "on" \ " 1000 Mbps Half Duplex capability is " query_print adv_pauseTX "off" "on" \ " Pause TX capability is " query_print adv_pauseRX "off" "on" \ " Pause RX capability is " print_link ;; eri*) DEV=eri INST=`which_inst $1` sanity_chk print_fasteth print_link ;; hme*) DEV=hme INST=`which_inst $1` sanity_chk print_fasteth query_print adv_100T4_cap "off" "on" \ " 100BASE-T4 capability is " query_print use_int_xcvr "off" "on" \ " Force Internal Transceiver option is " query_print transceiver_inuse \ " Internal Transceiver is in use" \ " External Transceiver is in use" print_link ;; qfe*) DEV=qfe INST=`which_inst $1` sanity_chk print_fasteth print_link ;; -h|--help) print_help ;; -v|--version) echo "\tSolaris Ethernet Link Checker" echo "\tVersion: $VERSION" echo "\tWritten by: $AUTHOR" exit 0 ;; *) print_help ;; esac exit 0