1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
|
#!/bin/bash
########################################################################
# File...........: lsqeth
# Author(s)......: Steffen Thoss <thoss@de.ibm.com>
# Copyright IBM Corp. 2004, 2006.
#
# History of changes:
#
# This shell script displays all QETH devices out of the sys filesystem
# on one page
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
########################################################################
#Globael variables
version="1.0"
script_name=${0##*/} # name of this script
format=0
device=0 # device name specified by user
sysfs_mp=`mount |grep -m1 "type sysfs" | cut -f 3 -d " "`
proc_mp=`mount |grep -m1 "type proc" | cut -f 3 -d " "`
device_dir="$sysfs_mp/bus/ccwgroup/drivers/qeth" # sysfs entry
interface_dir="$sysfs_mp/class/net/" # sysfs entry
qeth_devices=0 # includes all qeth based devices
device_list=0 # list of available devices
QETHCONF="/sbin/qethconf"
# Array for format (/proc/qeth like) output
format_array=( cdev0 cdev1 cdev2
chpid
if_name
card_type
portno
checksumming
priority_queueing
route4 route6
n/a
buffer_count )
# Array for normal output (only for sysfs systems)
output_array=( if_name
card_type
cdev0 cdev1 cdev2
chpid
online portname
portno
route4 route6
checksumming
state
priority_queueing
detach_state
fake_ll fake_broadcast
buffer_count
add_hhlen
layer2
large_send )
# Array for sysfs values
sysfs_entries=( "sw checksumming" "hw checksumming" "no checksumming"
"always queue 0" "always queue 1"
"always queue 2" "always queue 3"
"by precedence" "by type of service"
"primary router" "secondary router"
"primary connector+" "primary connector"
"secondary connector+" "secondary connector"
"multicast router+" "multicast router" )
# Array for ipa entries
ipa_array=0
# Array for vipa entries
vipa_array=0
# Array for parp entries
parp_array=0
#
# what is the kernel version we are on ?
#
kernel_version=`uname -r`
if [ "${kernel_version:2:1}" \> 4 ]; then
kernel_version=2.6
else
kernel_version=2.4
fi
#---------------------------------------
# -- functions --
#---------------------------------------
function PrintVersion
{
echo "$script_name: version %S390_TOOLS_VERSION% ($version)."
echo "Copyright IBM Corp. 2003, 2006."
}
#
# exit script on error and print usage hint
#
function __exit_on_error
{
echo "Try '$script_name --help' for more information."
exit 1
}
function __no_such_device
{
echo "$script_name: $1 no such device"
exit 1
}
function __no_such_parameter
{
echo "$script_name: wrong parameter $1"
__usage
exit 1
}
#
# function for printing the usage message
#
function __usage
{
printf '%s %s %s\n\n' "Usage:" $script_name "[-p] [--help] [<INTERFACE>]"
printf ' %s\n' "Description:"
printf ' \t\t%s\n\n' "The shell script list all QETH based networking devices."
printf ' %s\n' "Parameter: The following parameter is only available on kernel 2.6"
printf ' %s\n\n' " based systems."
printf '\t\t%s\n\n' "-p | --proc: list all devices in /proc/qeth format"
printf ' %s\n' "<INTERFACE>: List only attributes of specified interface."
exit 1
}
#
# check given parameters
#
function __check_input_parameter
{
if [ "$#" -gt 2 ]; then
echo "$script_name: invalid number of parameters specified"
__exit_on_error
fi
if [ "$#" -ne 0 ]; then
case "$1" in
--help | -h ) __usage;;
-p | --proc ) format=1
if [ "$#" -eq 2 ];then
if [ -d $interface_dir$2 ];then
device=$2
else
__no_such_device $2
fi
fi;;
-v | --version ) PrintVersion
exit 1;;
-* ) echo "$script_name: Invalid option $1"
__exit_on_error;;
* ) format=0
if [ "$#" -eq 2 ]; then
__no_such_parameter "$1"
elif [ "$#" -eq 1 ]; then
if [ -d $interface_dir$1 ];then
device=$1
else
__no_such_device $1
fi
fi;;
esac
fi
}
#
# search value in format_array
#
function __array_pos
{
if [ -z "$1" ];then
return 100
fi
case "$2" in
0 | 2 ) temp_array=( ${output_array[@]} );;
1 ) temp_array=( ${format_array[@]} );;
esac
local k=0
while [ $k -lt ${#temp_array[@]} ];
do
if [ $1 = ${temp_array[$k]} ]; then
return $k
fi
k=$((k+1))
done
return 100
}
#
# format output cat /$proc_mp/qeth like
#
function __print_proc_format
{
local count=0
local countb=0
local countc=3
#
# include all /$proc_mp/qeth entries
#
procfs_entries=( "sw" "hw" "no" "always_q_0" "always_q_1"
"always_q_2" "always_q_3" "by_prec." "by_ToS"
"pri" "sec" "p+c" "p.c" "s+c" "s.c" "mc+" "mc" )
for i in 7 8 9 10
do
count="${#sysfs_entries[*]}"
countb=0
while [ "$count" -gt 0 ]
do
if [ "${sysfs_entries[$countb]}" = "${format_array_print[$i]}" ]; then
format_array_print[$i]=${procfs_entries[$countb]}
fi
count=$((count-1))
countb=$((countb+1))
done
done
# print device data
printf '%-27s' "${format_array_print[0]}/${format_array_print[1]}/${format_array_print[2]}"
for j in 6 11 15 5 7 11 5 5 6 5
do
if [ "$countc" -eq 3 ]; then
printf "%-${j}s" "x${format_array_print[$countc]}"
else
if [ "${format_array_print[$countc]}" = '' ]; then
format_array_print[$countc]='n/a'
fi
printf "%-${j}s" "${format_array_print[$countc]}"
fi
countc=$((countc+1))
done
printf '\n'
}
#
# print new format output
#
function __print_normal_format
{
local count=0
local countc=1
local countb=0
local countd=0
local temp=0
local m
local is_in_layer2_list=0
local rc=0
countd=${#output_array[@]}
countd=$((countd-1))
printf 'Device name\t\t\t: %-20s\n' "${format_array_print[0]}"
echo '---------------------------------------------'
while [ "$countc" -le "$countd" ]
do
if [ -e "$interface_dir$1/device/layer2" ]; then
if [ `cat "$interface_dir$1/device/layer2"` = 1 ]; then
__layer2_print ${output_array[$countc]} $1
rc=$?
fi
fi
if [ "${format_array_print[$countc]}" != '' ] && [ "$rc" = 0 ]; then
printf '\t%-20s\t: %s\n' "${output_array[$countc]}" "${format_array_print[$countc]}"
fi
countc=$((countc+1))
done
for k in 'ipa' 'vipa' 'parp'
do
case "$k" in
ipa ) temp=( ${ipa_array[@]} )
m="ipa";;
vipa ) temp=( ${vipa_array[@]} )
m="vipa";;
parp ) temp=( ${parp_array[@]} )
m="parp";;
esac
if [ "$temp" != 0 ];then
count=0
countb=0
while [ "$count" -lt ${#temp[*]} ]
do
if [ "$countb" -gt 0 ]; then
printf '\t\t\t\t: %s\n' "${temp[$count]}"
else
printf '\t%-20s\t: %s\n' $m "${temp[$count]}"
fi
count=$(($count+1))
countb=$(($countb+1))
done
fi
done
}
#
# check if value should be printed because layer2 is enabled
#
function __layer2_print
{
del_layer2=( route4 route6
fake_ll fake_broadcast )
for l in ${del_layer2[@]}
do
if [ "$1" = "$l" ]; then
return 1
fi
done
return 0
}
#---------------------------------------
# -- main --
#---------------------------------------
__check_input_parameter "$@"
#
# Check if qethconf is installed
#
if [ ! -e "$QETHCONF" ] && [ $format != 1 ]; then
echo "WARNING: Qethconf is not installed !"
echo " No ipa_takeover, vipa or parp entries will be displayed."
echo ""
fi
#
# get device list
#
if [ $device != 0 ]; then
device_list="`ls -ld $interface_dir$device/device/cdev0`"
device_list="${device_list##*/}"
else
device_list="`ls $device_dir | grep [?\.?\.*]`"
fi
device_list_temp="`ls $interface_dir`"
#
# if kernel version 2.4 issue cat /$proc_mp/qeth
#
if [ "$kernel_version" = 2.4 ]; then
if [ $device != 0 ]; then
cat /$proc_mp/qeth | head -2
cat /$proc_mp/qeth | sed -e '1,2D' | grep $device
else
cat /$proc_mp/qeth
fi
exit
fi
if [ $format = 1 ]; then
echo "devices CHPID interface cardtype port chksum prio-q'ing rtr4 rtr6 fsz cnt"
echo "-------------------------- ----- ---------- -------------- ---- ------ ---------- ---- ---- ----- -----"
fi
#
# list entries for device
#
for k in ${device_list}
do
if_name="`cat $device_dir/$k/if_name`"
if [ -z "$if_name" ]; then
if_name=0
fi
__array_pos "$if_name" "$format"
rc=$?
if [ $rc != 100 ];then
format_array_print[$rc]=${device_temp##*/}
fi
for i in `ls $device_dir/$k`
do
# is file a directory (in our case this is happen for the cuu)
if [ -h $device_dir/$k/$i ]; then
device_temp="`ls -ld $device_dir/$k/$i`"
__array_pos "$i" "$format"
rc=$?
if [ $rc != 100 ];then
format_array_print[$rc]="${device_temp##*/}"
fi
# call qethconf if ipa/vipa/parp
elif [ "$i" = 'ipa_takeover' ] || [ "$i" = 'rxip' ] || [ "$i" = 'vipa' ]; then
if [ $format = 0 ] || [ $format = 2 ]; then
if [ "$i" = 'ipa_takeover' ] && [ -e "$QETHCONF" ]; then
i='ipa'
ipa_array=( `$QETHCONF list_all | grep $if_name | grep ^$i | \
sed -e s/$if_name//g | sed -e s/add//g | sed -e s/[' '$i]//g` )
elif [ "$i" = 'rxip' ] && [ -e "$QETHCONF" ]; then
i='parp'
parp_array=( `$QETHCONF list_all | grep $if_name | grep ^$i | \
sed -e s/$if_name//g | sed -e s/add//g | sed -e s/[' '$i]//g` )
elif [ -e "$QETHCONF" ]; then
vipa_array=( `$QETHCONF list_all | grep $if_name | grep ^$i | \
sed -e s/$if_name//g | sed -e s/add//g | sed -e s/[' '$i]//g` )
fi
fi
else
# show all other entries if the are not n/a
# and readable
device_temp="`cat $device_dir/$k/$i 2> /dev/null`"
if [ "$?" -eq 0 ]; then
if [ "$device_temp" = 'n/a' ] && [ "$i" = 'route6' ]; then
format_array_print[10]="no"
elif [ "$device_temp" != 'n/a' ];then
__array_pos "$i" "$format"
rc=$?
if [ $rc != 100 ];then
format_array_print[$rc]=${device_temp##*/}
fi
fi
fi
fi
#
# There is no entry for buffersize in sysfs
# therefore n/a
#
if [ $format = 1 ]; then
format_array_print[11]="n/a"
fi
done
case "$format" in
1 ) __print_proc_format;;
0 ) __print_normal_format $if_name
echo '';;
esac
done
|