#!/bin/bash
# -------------------------------------------------------------------
# Script to read tso attribute for an interface
#
# The interface tso setting is stored in an if-up script which 
# gets executed if the network or system is restarted. 
#
# The if-up script is located in /etc/sysconfig/network/if-up.d
# and should contain a line similar to the following:
#
#         ethtool -K eth0 tso off
#
# Usage:  getInterfaceTSO <interface name>
# Returns: tso attribute value
# Return code:  0 = successful
#               1 = IF-IP script directory not found
#               2 = IF-IP script file not found
#               3 = IP-IP script file does not contain tso value
# -------------------------------------------------------------------

myName=`basename $0`
LOG=/var/hsc/log/$myName.log
IFUP_DIR=/etc/sysconfig/network/if-up.d
FNAME=$1-settso
tso=""
    
echo "$(date +%F" "%T.%3N) getInterfaceTSO invoked for interface=$1" > $LOG

# check if the IF-UP script directory exists
if [ ! -d $IFUP_DIR ]; then
    echo "$(date +%F" "%T.%3N) IF-UP script directory ($IFUP_DIR) does not exist." >> $LOG
    rc=1
else
    # check if the IF-UP tso script file exists for interface
    if [ ! -e $IFUP_DIR/$1-settso ]; then
        echo "$(date +%F" "%T.%3N) IF-UP script file ($IFUP_DIR/$FNAME) does not exist." >> $LOG
        rc=2
    else
        echo "$(date +%F" "%T.%3N) Reading IF-UP script to get tso value" >> $LOG
        tso=`cat $IFUP_DIR/$FNAME | /usr/bin/grep "tso" | cut -d" " -f5`
        if [ "$tso" != "" ]; then
           echo "$(date +%F" "%T.%3N) Results: tso=$tso" >> $LOG
           echo $tso
           rc=0
        else
           echo "$(date +%F" "%T.%3N) No tso value found in IF-UP script ($IFUP_DIR/$FNAME)." >> $LOG
           rc=3
        fi
    fi
fi

echo "$(date +%F" "%T.%3N) exiting getInterfaceTSO script, rc=$rc" >> $LOG
exit $rc
