forked from Mellanox/ibdump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpi_tcpdump
executable file
·131 lines (111 loc) · 2.76 KB
/
vpi_tcpdump
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
#!/bin/bash
set -o noglob
# vpi_tcpdump
# requirements
#
# -i <interface> must be provided
# rest of the opts go to tcpdump
#
# Flow:
# run ibdev2netdev on the input interface to get ib dev and port
# Found eth - run with tcpdump
# Found ib - run with tshark
# not found - error
# check tool in the path before execution
dumptool="tcpdump"
usage() {
script=$(basename $0)
echo "Usage: $script <-i interface> [--version] [tcpdump options]"
echo " Dump traffic from Mellanox ConnectX-3 adapters."
echo " A target interface <-i option> must be provided."
echo " In current version:"
echo " - Only RX traffic is captured."
echo " - Only Ethernet interfaces are supported (run 'ibdump' to capture from InfiniBand ports)."
echo " Please refer to tcpdump documentation for tcpdump options."
exit 1
}
versions() {
tcpdump -V 2>&1 | grep version
ibdump -v
exit 0
}
# Returns a list of lists in format "ibv_dev port eth_dev status"
get_devs_list() {
dev_list=`(
ibdev2netdev | while read line; do
dev_entry=$(echo $line | awk '{print $1 " " $3 " " $5 " " $6}')
#dev_list="$dev_list \"$dev_entry\""
echo -n "\"$dev_entry\" "
done
)`
echo "$dev_list"
}
#get_devs_list
#exit
print_devs() {
devs=$(get_devs_list)
eval set -- $devs
idx=1
for d in "$@"; do
echo $idx.`echo $d | awk '{print $3 " " $4}'`
idx=$((idx + 1))
done
exit 0
}
get_ib_dev() {
dump_ifc=$1
devs=$(get_devs_list)
eval set -- $devs
for d in "$@"; do
ifc=`echo $d | awk '{print $3}'`
if [ "x$dump_ifc" == "x$ifc" ]
then
echo $d | awk '{print " -d " $1 " -i " $2}'
return
fi
done
exit 1
}
ibdump_opts=""
tcpdump_opts=""
target_netdev=""
while [ -n "$1" ]; do
case $1 in
-h*|--h*)
usage
;;
-i)
dump_ifc="$2"
shift 2
;;
-D)
print_devs
shift 1
;;
--version)
versions
shift 1
;;
*)
tcpdump_opts+=" $1"
shift 1
;;
esac
done
if [ "x$dump_ifc" == "x" ]; then
echo "-E- An interface must be provided (-i flag)"
exit 1
fi
# Worakround for tcpdump not being in path.
if type $dumptool &>/dev/null; then
true
else
echo "-E- $dumptool not found. Please make sure $dumptool is in the PATH"
exit 1
fi
ibdump_opts="$ibdump_opts -w - $(get_ib_dev $dump_ifc)"
if [ $? != 0 ]; then
echo "-E- Unknown interface given ($dump_ifc). Run \"`basename $0` -D\" to list available interfaces"
exit 1
fi
ibdump $ibdump_opts | ( setsid $dumptool -r - $tcpdump_opts || kill -HUP $$ )