Skip to content

Commit

Permalink
Merge pull request #148 from mtomaschewski/ibft
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Feb 4, 2014
2 parents f3ce037 + 80591c4 commit 8552602
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions extensions/ibft
Expand Up @@ -4,6 +4,21 @@ shopt -s nullglob

err_base="extensions/ibft"

function do_readlink
{
local opt link tool
case $1 in
-f) opt=$1 ; shift ;;
esac
link=$1
tool=`type -P readlink 2>/dev/null`
if test -x "$tool" ; then
readlink $opt "$link" 2>/dev/null
else
cd -P "$link" 2>/dev/null && echo $PWD
fi
}

function glob_first
{
local pattern="$1"
Expand Down Expand Up @@ -99,19 +114,28 @@ function get_vlan_ifname
opt_rootdir=""
# relative ibft node
opt_fw_path=""
# load iscsi_ibft
opt_modprobe=""
# list only mode
opt_listonly="no"
#set -- `getopt r:p: "$@"`
while [ $# -gt 0 -a "$1" != "--" ]; do
opt=$1; shift;
case $opt in
-r) opt_rootdir=$1; shift;;
-p) opt_fw_path=$1; shift;;
-r) opt_rootdir=$1; shift;;
-p) opt_fw_path=$1; shift;;
-m) opt_modprobe=${1:-iscsi_ibft}; shift;;
-l) opt_listonly=yes ;;
*) echo "$err_base: Bad command line option \"$opt\"" >&2; exit 1;;
esac
done

IBFT_NICS="ethernet"
IBFT_PATH="/sys/firmware/ibft"
IBFT_ROOT="${opt_rootdir}/sys/firmware/ibft"
if test ! -d "$IBFT_ROOT" -a "X$opt_modprobe" != "X" ; then
modprobe -qs ${opt_modprobe} &>/dev/null || :
fi
for nicpath in "${IBFT_ROOT}/${IBFT_NICS}"*; do
[ "X$nicpath" != "X" -a -d "$nicpath" ] || continue

Expand All @@ -127,7 +151,7 @@ for nicpath in "${IBFT_ROOT}/${IBFT_NICS}"*; do
nic_flags=`ibft_getattr "$nicpath/flags"`
[ -n "$nic_flags" ] && ((nic_flags & 0x01)) || continue

devpath=`readlink -f $nicpath/device`
devpath=`do_readlink -f $nicpath/device`
[ -n "$devpath" ] || continue

set -- `ibft_get_ifindex $devpath`
Expand All @@ -137,8 +161,20 @@ for nicpath in "${IBFT_ROOT}/${IBFT_NICS}"*; do
nic_name=$2

nic_vlan=`ibft_getattr "$nicpath/vlan"`
nic_mac=`ibft_getattr "$nicpath/mac"`
if [ "X$opt_listonly" = "Xyes" ] ; then
if [ -n "$nic_vlan" -a $((nic_vlan)) -gt 0 ]; then
vlan_ifname=`get_vlan_ifname "$nic_vlan" "$nic_name" 2>/dev/null`
if test "x$vlan_ifname" = x ; then
vlan_ifname="${nic_name}.${nic_vlan}"
fi
echo "$vlan_ifname $nic_name"
else
echo "$nic_name"
fi
continue
fi

nic_mac=`ibft_getattr "$nicpath/mac"`
nic_ipaddr=`ibft_getattr "$nicpath/ip-addr"`
nic_prefixlen=""

Expand Down

0 comments on commit 8552602

Please sign in to comment.