2017-10-26 14:16:05 -07:00
|
|
|
# bpftool(8) bash completion -*- shell-script -*-
|
|
|
|
|
#
|
2018-12-12 19:59:25 -08:00
|
|
|
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
2018-05-03 18:37:16 -07:00
|
|
|
# Copyright (C) 2017-2018 Netronome Systems, Inc.
|
2017-10-26 14:16:05 -07:00
|
|
|
#
|
|
|
|
|
# Author: Quentin Monnet <quentin.monnet@netronome.com>
|
|
|
|
|
|
|
|
|
|
# Takes a list of words in argument; each one of them is added to COMPREPLY if
|
|
|
|
|
# it is not already present on the command line. Returns no value.
|
|
|
|
|
_bpftool_once_attr()
|
|
|
|
|
{
|
|
|
|
|
local w idx found
|
|
|
|
|
for w in $*; do
|
|
|
|
|
found=0
|
|
|
|
|
for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
|
|
|
|
|
if [[ $w == ${words[idx]} ]]; then
|
|
|
|
|
found=1
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
[[ $found -eq 0 ]] && \
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 20:27:17 -08:00
|
|
|
# Takes a list of words as argument; if any of those words is present on the
|
|
|
|
|
# command line, return 0. Otherwise, return 1.
|
|
|
|
|
_bpftool_search_list()
|
2017-10-26 14:16:05 -07:00
|
|
|
{
|
|
|
|
|
local w idx
|
|
|
|
|
for w in $*; do
|
|
|
|
|
for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
|
2018-02-07 20:27:17 -08:00
|
|
|
[[ $w == ${words[idx]} ]] && return 0
|
2017-10-26 14:16:05 -07:00
|
|
|
done
|
|
|
|
|
done
|
2018-02-07 20:27:17 -08:00
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Takes a list of words in argument; adds them all to COMPREPLY if none of them
|
|
|
|
|
# is already present on the command line. Returns no value.
|
|
|
|
|
_bpftool_one_of_list()
|
|
|
|
|
{
|
|
|
|
|
_bpftool_search_list $* && return 1
|
2017-10-26 14:16:05 -07:00
|
|
|
COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bpftool_get_map_ids()
|
|
|
|
|
{
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$( bpftool -jp map 2>&1 | \
|
|
|
|
|
command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 11:10:05 -08:00
|
|
|
# Takes map type and adds matching map ids to the list of suggestions.
|
|
|
|
|
_bpftool_get_map_ids_for_type()
|
2018-05-03 18:37:16 -07:00
|
|
|
{
|
2019-01-16 11:10:05 -08:00
|
|
|
local type="$1"
|
2018-05-03 18:37:16 -07:00
|
|
|
COMPREPLY+=( $( compgen -W "$( bpftool -jp map 2>&1 | \
|
2019-01-16 11:10:05 -08:00
|
|
|
command grep -C2 "$type" | \
|
2018-05-03 18:37:16 -07:00
|
|
|
command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-26 14:16:05 -07:00
|
|
|
_bpftool_get_prog_ids()
|
|
|
|
|
{
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
|
|
|
|
|
command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bpftool_get_prog_tags()
|
|
|
|
|
{
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
|
|
|
|
|
command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 14:43:07 -07:00
|
|
|
_bpftool_get_obj_map_names()
|
|
|
|
|
{
|
|
|
|
|
local obj
|
|
|
|
|
|
|
|
|
|
obj=$1
|
|
|
|
|
|
|
|
|
|
maps=$(objdump -j maps -t $obj 2>/dev/null | \
|
|
|
|
|
command awk '/g . maps/ {print $NF}')
|
|
|
|
|
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$maps" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bpftool_get_obj_map_idxs()
|
|
|
|
|
{
|
|
|
|
|
local obj
|
|
|
|
|
|
|
|
|
|
obj=$1
|
|
|
|
|
|
|
|
|
|
nmaps=$(objdump -j maps -t $obj 2>/dev/null | grep -c 'g . maps')
|
|
|
|
|
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$(seq 0 $((nmaps - 1)))" -- "$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 14:42:58 -07:00
|
|
|
_sysfs_get_netdevs()
|
|
|
|
|
{
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$( ls /sys/class/net 2>/dev/null )" -- \
|
|
|
|
|
"$cur" ) )
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 11:10:05 -08:00
|
|
|
# Retrieve type of the map that we are operating on.
|
|
|
|
|
_bpftool_map_guess_map_type()
|
2017-10-26 14:16:05 -07:00
|
|
|
{
|
|
|
|
|
local keyword ref
|
|
|
|
|
for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
|
2019-01-16 11:10:05 -08:00
|
|
|
case "${words[$((idx-2))]}" in
|
|
|
|
|
lookup|update)
|
|
|
|
|
keyword=${words[$((idx-1))]}
|
|
|
|
|
ref=${words[$((idx))]}
|
|
|
|
|
;;
|
|
|
|
|
push)
|
|
|
|
|
printf "stack"
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
enqueue)
|
|
|
|
|
printf "queue"
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2017-10-26 14:16:05 -07:00
|
|
|
done
|
|
|
|
|
[[ -z $ref ]] && return 0
|
|
|
|
|
|
|
|
|
|
local type
|
|
|
|
|
type=$(bpftool -jp map show $keyword $ref | \
|
|
|
|
|
command sed -n 's/.*"type": "\(.*\)",$/\1/p')
|
2018-10-20 23:01:50 +01:00
|
|
|
[[ -n $type ]] && printf $type
|
2017-10-26 14:16:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bpftool_map_update_get_id()
|
|
|
|
|
{
|
2019-01-16 11:10:05 -08:00
|
|
|
local command="$1"
|
|
|
|
|
|
2017-10-26 14:16:05 -07:00
|
|
|
# Is it the map to update, or a map to insert into the map to update?
|
|
|
|
|
# Search for "value" keyword.
|
|
|
|
|
local idx value
|
|
|
|
|
for (( idx=7; idx < ${#words[@]}-1; idx++ )); do
|
|
|
|
|
if [[ ${words[idx]} == "value" ]]; then
|
|
|
|
|
value=1
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
2019-01-16 11:10:05 -08:00
|
|
|
if [[ $value -eq 0 ]]; then
|
|
|
|
|
case "$command" in
|
|
|
|
|
push)
|
|
|
|
|
_bpftool_get_map_ids_for_type stack
|
|
|
|
|
;;
|
|
|
|
|
enqueue)
|
|
|
|
|
_bpftool_get_map_ids_for_type queue
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_bpftool_get_map_ids
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
2017-10-26 14:16:05 -07:00
|
|
|
|
|
|
|
|
# Id to complete is for a value. It can be either prog id or map id. This
|
|
|
|
|
# depends on the type of the map to update.
|
2019-01-16 11:10:05 -08:00
|
|
|
local type=$(_bpftool_map_guess_map_type)
|
2017-10-26 14:16:05 -07:00
|
|
|
case $type in
|
|
|
|
|
array_of_maps|hash_of_maps)
|
|
|
|
|
_bpftool_get_map_ids
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
prog_array)
|
|
|
|
|
_bpftool_get_prog_ids
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bpftool()
|
|
|
|
|
{
|
|
|
|
|
local cur prev words objword
|
|
|
|
|
_init_completion || return
|
|
|
|
|
|
2018-06-28 14:41:42 -07:00
|
|
|
# Deal with options
|
|
|
|
|
if [[ ${words[cword]} == -* ]]; then
|
2018-10-15 11:19:55 -07:00
|
|
|
local c='--version --json --pretty --bpffs --mapcompat'
|
2018-06-28 14:41:42 -07:00
|
|
|
COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2017-10-26 14:16:05 -07:00
|
|
|
# Deal with simplest keywords
|
|
|
|
|
case $prev in
|
bpf: libbpf: bpftool: Print bpf_line_info during prog dump
This patch adds print bpf_line_info function in 'prog dump jitted'
and 'prog dump xlated':
[root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv
[...]
int test_long_fname_2(struct dummy_tracepoint_args * arg):
bpf_prog_44a040bf25481309_test_long_fname_2:
; static int test_long_fname_2(struct dummy_tracepoint_args *arg)
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x30,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
17: mov %r14,0x10(%rbp)
1b: mov %r15,0x18(%rbp)
1f: xor %eax,%eax
21: mov %rax,0x20(%rbp)
25: xor %esi,%esi
; int key = 0;
27: mov %esi,-0x4(%rbp)
; if (!arg->sock)
2a: mov 0x8(%rdi),%rdi
; if (!arg->sock)
2e: cmp $0x0,%rdi
32: je 0x0000000000000070
34: mov %rbp,%rsi
; counts = bpf_map_lookup_elem(&btf_map, &key);
37: add $0xfffffffffffffffc,%rsi
3b: movabs $0xffff8881139d7480,%rdi
45: add $0x110,%rdi
4c: mov 0x0(%rsi),%eax
4f: cmp $0x4,%rax
53: jae 0x000000000000005e
55: shl $0x3,%rax
59: add %rdi,%rax
5c: jmp 0x0000000000000060
5e: xor %eax,%eax
; if (!counts)
60: cmp $0x0,%rax
64: je 0x0000000000000070
; counts->v6++;
66: mov 0x4(%rax),%edi
69: add $0x1,%rdi
6d: mov %edi,0x4(%rax)
70: mov 0x0(%rbp),%rbx
74: mov 0x8(%rbp),%r13
78: mov 0x10(%rbp),%r14
7c: mov 0x18(%rbp),%r15
80: add $0x28,%rbp
84: leaveq
85: retq
[...]
With linum:
[root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv linum
int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
bpf_prog_b07ccb89267cf242__dummy_tracepoint:
; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:9]
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x28,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
17: mov %r14,0x10(%rbp)
1b: mov %r15,0x18(%rbp)
1f: xor %eax,%eax
21: mov %rax,0x20(%rbp)
25: callq 0x000000000000851e
; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:2]
2a: xor %eax,%eax
2c: mov 0x0(%rbp),%rbx
30: mov 0x8(%rbp),%r13
34: mov 0x10(%rbp),%r14
38: mov 0x18(%rbp),%r15
3c: add $0x28,%rbp
40: leaveq
41: retq
[...]
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-12-07 16:42:32 -08:00
|
|
|
help|hex|opcodes|visual|linum)
|
2017-10-26 14:16:05 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
tag)
|
|
|
|
|
_bpftool_get_prog_tags
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
file|pinned)
|
|
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
batch)
|
|
|
|
|
COMPREPLY=( $( compgen -W 'file' -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2018-06-28 14:41:42 -07:00
|
|
|
# Remove all options so completions don't have to deal with them.
|
|
|
|
|
local i
|
|
|
|
|
for (( i=1; i < ${#words[@]}; )); do
|
|
|
|
|
if [[ ${words[i]::1} == - ]]; then
|
|
|
|
|
words=( "${words[@]:0:i}" "${words[@]:i+1}" )
|
|
|
|
|
[[ $i -le $cword ]] && cword=$(( cword - 1 ))
|
|
|
|
|
else
|
|
|
|
|
i=$(( ++i ))
|
|
|
|
|
fi
|
2017-10-26 14:16:05 -07:00
|
|
|
done
|
2018-06-28 14:41:42 -07:00
|
|
|
cur=${words[cword]}
|
|
|
|
|
prev=${words[cword - 1]}
|
2017-10-26 14:16:05 -07:00
|
|
|
|
2018-06-28 14:41:42 -07:00
|
|
|
local object=${words[1]} command=${words[2]}
|
|
|
|
|
|
|
|
|
|
if [[ -z $object || $cword -eq 1 ]]; then
|
2017-10-26 14:16:05 -07:00
|
|
|
case $cur in
|
|
|
|
|
*)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$( bpftool help 2>&1 | \
|
|
|
|
|
command sed \
|
|
|
|
|
-e '/OBJECT := /!d' \
|
|
|
|
|
-e 's/.*{//' \
|
|
|
|
|
-e 's/}.*//' \
|
|
|
|
|
-e 's/|//g' )" -- "$cur" ) )
|
|
|
|
|
COMPREPLY+=( $( compgen -W 'batch help' -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[[ $command == help ]] && return 0
|
|
|
|
|
|
|
|
|
|
# Completion depends on object and command in use
|
|
|
|
|
case $object in
|
|
|
|
|
prog)
|
2018-11-30 16:25:45 +00:00
|
|
|
# Complete id, only for subcommands that use prog (but no map) ids
|
|
|
|
|
case $command in
|
|
|
|
|
show|list|dump|pin)
|
|
|
|
|
case $prev in
|
|
|
|
|
id)
|
|
|
|
|
_bpftool_get_prog_ids
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2017-10-26 14:16:05 -07:00
|
|
|
|
|
|
|
|
local PROG_TYPE='id pinned tag'
|
2018-11-30 16:25:45 +00:00
|
|
|
local MAP_TYPE='id pinned'
|
2017-10-26 14:16:05 -07:00
|
|
|
case $command in
|
2018-01-02 14:48:36 -08:00
|
|
|
show|list)
|
2017-10-26 14:16:05 -07:00
|
|
|
[[ $prev != "$command" ]] && return 0
|
|
|
|
|
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
dump)
|
|
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
COMPREPLY+=( $( compgen -W "xlated jited" -- \
|
|
|
|
|
"$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
xlated|jited)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
|
|
|
|
|
"$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2018-03-01 18:01:23 -08:00
|
|
|
_bpftool_once_attr 'file'
|
|
|
|
|
if _bpftool_search_list 'xlated'; then
|
bpf: libbpf: bpftool: Print bpf_line_info during prog dump
This patch adds print bpf_line_info function in 'prog dump jitted'
and 'prog dump xlated':
[root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv
[...]
int test_long_fname_2(struct dummy_tracepoint_args * arg):
bpf_prog_44a040bf25481309_test_long_fname_2:
; static int test_long_fname_2(struct dummy_tracepoint_args *arg)
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x30,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
17: mov %r14,0x10(%rbp)
1b: mov %r15,0x18(%rbp)
1f: xor %eax,%eax
21: mov %rax,0x20(%rbp)
25: xor %esi,%esi
; int key = 0;
27: mov %esi,-0x4(%rbp)
; if (!arg->sock)
2a: mov 0x8(%rdi),%rdi
; if (!arg->sock)
2e: cmp $0x0,%rdi
32: je 0x0000000000000070
34: mov %rbp,%rsi
; counts = bpf_map_lookup_elem(&btf_map, &key);
37: add $0xfffffffffffffffc,%rsi
3b: movabs $0xffff8881139d7480,%rdi
45: add $0x110,%rdi
4c: mov 0x0(%rsi),%eax
4f: cmp $0x4,%rax
53: jae 0x000000000000005e
55: shl $0x3,%rax
59: add %rdi,%rax
5c: jmp 0x0000000000000060
5e: xor %eax,%eax
; if (!counts)
60: cmp $0x0,%rax
64: je 0x0000000000000070
; counts->v6++;
66: mov 0x4(%rax),%edi
69: add $0x1,%rdi
6d: mov %edi,0x4(%rax)
70: mov 0x0(%rbp),%rbx
74: mov 0x8(%rbp),%r13
78: mov 0x10(%rbp),%r14
7c: mov 0x18(%rbp),%r15
80: add $0x28,%rbp
84: leaveq
85: retq
[...]
With linum:
[root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv linum
int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
bpf_prog_b07ccb89267cf242__dummy_tracepoint:
; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:9]
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x28,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
17: mov %r14,0x10(%rbp)
1b: mov %r15,0x18(%rbp)
1f: xor %eax,%eax
21: mov %rax,0x20(%rbp)
25: callq 0x000000000000851e
; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:2]
2a: xor %eax,%eax
2c: mov 0x0(%rbp),%rbx
30: mov 0x8(%rbp),%r13
34: mov 0x10(%rbp),%r14
38: mov 0x18(%rbp),%r15
3c: add $0x28,%rbp
40: leaveq
41: retq
[...]
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-12-07 16:42:32 -08:00
|
|
|
COMPREPLY+=( $( compgen -W 'opcodes visual linum' -- \
|
2018-03-01 18:01:23 -08:00
|
|
|
"$cur" ) )
|
|
|
|
|
else
|
bpf: libbpf: bpftool: Print bpf_line_info during prog dump
This patch adds print bpf_line_info function in 'prog dump jitted'
and 'prog dump xlated':
[root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv
[...]
int test_long_fname_2(struct dummy_tracepoint_args * arg):
bpf_prog_44a040bf25481309_test_long_fname_2:
; static int test_long_fname_2(struct dummy_tracepoint_args *arg)
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x30,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
17: mov %r14,0x10(%rbp)
1b: mov %r15,0x18(%rbp)
1f: xor %eax,%eax
21: mov %rax,0x20(%rbp)
25: xor %esi,%esi
; int key = 0;
27: mov %esi,-0x4(%rbp)
; if (!arg->sock)
2a: mov 0x8(%rdi),%rdi
; if (!arg->sock)
2e: cmp $0x0,%rdi
32: je 0x0000000000000070
34: mov %rbp,%rsi
; counts = bpf_map_lookup_elem(&btf_map, &key);
37: add $0xfffffffffffffffc,%rsi
3b: movabs $0xffff8881139d7480,%rdi
45: add $0x110,%rdi
4c: mov 0x0(%rsi),%eax
4f: cmp $0x4,%rax
53: jae 0x000000000000005e
55: shl $0x3,%rax
59: add %rdi,%rax
5c: jmp 0x0000000000000060
5e: xor %eax,%eax
; if (!counts)
60: cmp $0x0,%rax
64: je 0x0000000000000070
; counts->v6++;
66: mov 0x4(%rax),%edi
69: add $0x1,%rdi
6d: mov %edi,0x4(%rax)
70: mov 0x0(%rbp),%rbx
74: mov 0x8(%rbp),%r13
78: mov 0x10(%rbp),%r14
7c: mov 0x18(%rbp),%r15
80: add $0x28,%rbp
84: leaveq
85: retq
[...]
With linum:
[root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv linum
int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
bpf_prog_b07ccb89267cf242__dummy_tracepoint:
; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:9]
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x28,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
17: mov %r14,0x10(%rbp)
1b: mov %r15,0x18(%rbp)
1f: xor %eax,%eax
21: mov %rax,0x20(%rbp)
25: callq 0x000000000000851e
; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:2]
2a: xor %eax,%eax
2c: mov 0x0(%rbp),%rbx
30: mov 0x8(%rbp),%r13
34: mov 0x10(%rbp),%r14
38: mov 0x18(%rbp),%r15
3c: add $0x28,%rbp
40: leaveq
41: retq
[...]
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-12-07 16:42:32 -08:00
|
|
|
COMPREPLY+=( $( compgen -W 'opcodes linum' -- \
|
2017-10-26 14:16:05 -07:00
|
|
|
"$cur" ) )
|
2018-03-01 18:01:23 -08:00
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2017-10-26 14:16:05 -07:00
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
pin)
|
|
|
|
|
if [[ $prev == "$command" ]]; then
|
|
|
|
|
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
|
|
|
|
|
else
|
|
|
|
|
_filedir
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-10-15 11:19:50 -07:00
|
|
|
attach|detach)
|
2018-11-30 16:25:45 +00:00
|
|
|
case $cword in
|
|
|
|
|
3)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
4)
|
|
|
|
|
case $prev in
|
|
|
|
|
id)
|
|
|
|
|
_bpftool_get_prog_ids
|
|
|
|
|
;;
|
|
|
|
|
pinned)
|
|
|
|
|
_filedir
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
5)
|
|
|
|
|
COMPREPLY=( $( compgen -W 'msg_verdict skb_verdict \
|
|
|
|
|
skb_parse flow_dissector' -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
6)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
7)
|
|
|
|
|
case $prev in
|
|
|
|
|
id)
|
|
|
|
|
_bpftool_get_map_ids
|
|
|
|
|
;;
|
|
|
|
|
pinned)
|
|
|
|
|
_filedir
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2018-10-15 11:19:50 -07:00
|
|
|
;;
|
2018-11-09 08:21:44 -08:00
|
|
|
load|loadall)
|
2018-07-10 14:43:07 -07:00
|
|
|
local obj
|
|
|
|
|
|
2018-07-10 14:42:58 -07:00
|
|
|
if [[ ${#words[@]} -lt 6 ]]; then
|
|
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2018-07-10 14:43:07 -07:00
|
|
|
obj=${words[3]}
|
|
|
|
|
|
|
|
|
|
if [[ ${words[-4]} == "map" ]]; then
|
|
|
|
|
COMPREPLY=( $( compgen -W "id pinned" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
if [[ ${words[-3]} == "map" ]]; then
|
|
|
|
|
if [[ ${words[-2]} == "idx" ]]; then
|
|
|
|
|
_bpftool_get_obj_map_idxs $obj
|
|
|
|
|
elif [[ ${words[-2]} == "name" ]]; then
|
|
|
|
|
_bpftool_get_obj_map_names $obj
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
if [[ ${words[-2]} == "map" ]]; then
|
|
|
|
|
COMPREPLY=( $( compgen -W "idx name" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2018-07-10 14:42:58 -07:00
|
|
|
case $prev in
|
2018-07-10 14:43:00 -07:00
|
|
|
type)
|
2018-11-09 08:21:46 -08:00
|
|
|
COMPREPLY=( $( compgen -W "socket kprobe \
|
|
|
|
|
kretprobe classifier flow_dissector \
|
|
|
|
|
action tracepoint raw_tracepoint \
|
|
|
|
|
xdp perf_event cgroup/skb cgroup/sock \
|
|
|
|
|
cgroup/dev lwt_in lwt_out lwt_xmit \
|
|
|
|
|
lwt_seg6local sockops sk_skb sk_msg \
|
|
|
|
|
lirc_mode2 cgroup/bind4 cgroup/bind6 \
|
|
|
|
|
cgroup/connect4 cgroup/connect6 \
|
|
|
|
|
cgroup/sendmsg4 cgroup/sendmsg6 \
|
|
|
|
|
cgroup/post_bind4 cgroup/post_bind6" -- \
|
2018-07-10 14:43:00 -07:00
|
|
|
"$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-07-10 14:43:07 -07:00
|
|
|
id)
|
|
|
|
|
_bpftool_get_map_ids
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-11-09 08:21:45 -08:00
|
|
|
pinned|pinmaps)
|
2018-07-10 14:43:07 -07:00
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-07-10 14:42:58 -07:00
|
|
|
dev)
|
|
|
|
|
_sysfs_get_netdevs
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2018-07-10 14:43:07 -07:00
|
|
|
COMPREPLY=( $( compgen -W "map" -- "$cur" ) )
|
2018-07-10 14:43:00 -07:00
|
|
|
_bpftool_once_attr 'type'
|
2018-07-10 14:42:58 -07:00
|
|
|
_bpftool_once_attr 'dev'
|
2018-11-09 08:21:45 -08:00
|
|
|
_bpftool_once_attr 'pinmaps'
|
2018-07-10 14:42:58 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2018-02-07 20:27:16 -08:00
|
|
|
;;
|
2018-12-05 10:28:24 +00:00
|
|
|
tracelog)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2017-10-26 14:16:05 -07:00
|
|
|
*)
|
|
|
|
|
[[ $prev == $object ]] && \
|
2018-10-15 11:19:50 -07:00
|
|
|
COMPREPLY=( $( compgen -W 'dump help pin attach detach load \
|
2018-12-05 10:28:24 +00:00
|
|
|
show list tracelog' -- "$cur" ) )
|
2017-10-26 14:16:05 -07:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
map)
|
|
|
|
|
local MAP_TYPE='id pinned'
|
|
|
|
|
case $command in
|
2019-01-16 11:10:05 -08:00
|
|
|
show|list|dump|peek|pop|dequeue)
|
2017-10-26 14:16:05 -07:00
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
id)
|
2019-01-16 11:10:05 -08:00
|
|
|
case "$command" in
|
|
|
|
|
peek)
|
|
|
|
|
_bpftool_get_map_ids_for_type stack
|
|
|
|
|
_bpftool_get_map_ids_for_type queue
|
|
|
|
|
;;
|
|
|
|
|
pop)
|
|
|
|
|
_bpftool_get_map_ids_for_type stack
|
|
|
|
|
;;
|
|
|
|
|
dequeue)
|
|
|
|
|
_bpftool_get_map_ids_for_type queue
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_bpftool_get_map_ids
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2017-10-26 14:16:05 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2018-10-15 16:30:36 -07:00
|
|
|
create)
|
|
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
type)
|
|
|
|
|
COMPREPLY=( $( compgen -W 'hash array prog_array \
|
|
|
|
|
perf_event_array percpu_hash percpu_array \
|
|
|
|
|
stack_trace cgroup_array lru_hash \
|
|
|
|
|
lru_percpu_hash lpm_trie array_of_maps \
|
|
|
|
|
hash_of_maps devmap sockmap cpumap xskmap \
|
|
|
|
|
sockhash cgroup_storage reuseport_sockarray \
|
2018-11-30 16:25:46 +00:00
|
|
|
percpu_cgroup_storage queue stack' -- \
|
2018-10-15 16:30:36 -07:00
|
|
|
"$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
key|value|flags|name|entries)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
dev)
|
|
|
|
|
_sysfs_get_netdevs
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_bpftool_once_attr 'type'
|
|
|
|
|
_bpftool_once_attr 'key'
|
|
|
|
|
_bpftool_once_attr 'value'
|
|
|
|
|
_bpftool_once_attr 'entries'
|
|
|
|
|
_bpftool_once_attr 'name'
|
|
|
|
|
_bpftool_once_attr 'flags'
|
|
|
|
|
_bpftool_once_attr 'dev'
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2017-10-26 14:16:05 -07:00
|
|
|
lookup|getnext|delete)
|
|
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
id)
|
|
|
|
|
_bpftool_get_map_ids
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
key)
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-17 19:46:34 -07:00
|
|
|
COMPREPLY+=( $( compgen -W 'hex' -- "$cur" ) )
|
2017-10-26 14:16:05 -07:00
|
|
|
;;
|
|
|
|
|
*)
|
2019-01-16 11:10:05 -08:00
|
|
|
case $(_bpftool_map_guess_map_type) in
|
|
|
|
|
queue|stack)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2017-10-26 14:16:05 -07:00
|
|
|
_bpftool_once_attr 'key'
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2019-01-16 11:10:05 -08:00
|
|
|
update|push|enqueue)
|
2017-10-26 14:16:05 -07:00
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
id)
|
2019-01-16 11:10:05 -08:00
|
|
|
_bpftool_map_update_get_id $command
|
2017-10-26 14:16:05 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
key)
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-17 19:46:34 -07:00
|
|
|
COMPREPLY+=( $( compgen -W 'hex' -- "$cur" ) )
|
2017-10-26 14:16:05 -07:00
|
|
|
;;
|
|
|
|
|
value)
|
|
|
|
|
# We can have bytes, or references to a prog or a
|
|
|
|
|
# map, depending on the type of the map to update.
|
2019-01-16 11:10:05 -08:00
|
|
|
case "$(_bpftool_map_guess_map_type)" in
|
2017-10-26 14:16:05 -07:00
|
|
|
array_of_maps|hash_of_maps)
|
|
|
|
|
local MAP_TYPE='id pinned'
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$MAP_TYPE" \
|
|
|
|
|
-- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
prog_array)
|
|
|
|
|
local PROG_TYPE='id pinned tag'
|
|
|
|
|
COMPREPLY+=( $( compgen -W "$PROG_TYPE" \
|
|
|
|
|
-- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-17 19:46:34 -07:00
|
|
|
COMPREPLY+=( $( compgen -W 'hex' \
|
|
|
|
|
-- "$cur" ) )
|
2017-10-26 14:16:05 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2019-01-16 11:10:05 -08:00
|
|
|
case $(_bpftool_map_guess_map_type) in
|
|
|
|
|
queue|stack)
|
|
|
|
|
_bpftool_once_attr 'value'
|
|
|
|
|
return 0;
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2017-10-26 14:16:05 -07:00
|
|
|
_bpftool_once_attr 'key'
|
|
|
|
|
local UPDATE_FLAGS='any exist noexist'
|
|
|
|
|
for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
|
|
|
|
|
if [[ ${words[idx]} == 'value' ]]; then
|
|
|
|
|
# 'value' is present, but is not the last
|
|
|
|
|
# word i.e. we can now have UPDATE_FLAGS.
|
|
|
|
|
_bpftool_one_of_list "$UPDATE_FLAGS"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
|
|
|
|
|
if [[ ${words[idx]} == 'key' ]]; then
|
|
|
|
|
# 'key' is present, but is not the last
|
|
|
|
|
# word i.e. we can now have 'value'.
|
|
|
|
|
_bpftool_once_attr 'value'
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
done
|
2019-01-16 11:10:05 -08:00
|
|
|
|
2017-10-26 14:16:05 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
pin)
|
|
|
|
|
if [[ $prev == "$command" ]]; then
|
|
|
|
|
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
|
|
|
|
|
else
|
|
|
|
|
_filedir
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-05-03 18:37:16 -07:00
|
|
|
event_pipe)
|
|
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
id)
|
2019-01-16 11:10:05 -08:00
|
|
|
_bpftool_get_map_ids_for_type perf_event_array
|
2018-05-03 18:37:16 -07:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
cpu)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
index)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_bpftool_once_attr 'cpu'
|
|
|
|
|
_bpftool_once_attr 'index'
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2017-10-26 14:16:05 -07:00
|
|
|
*)
|
|
|
|
|
[[ $prev == $object ]] && \
|
|
|
|
|
COMPREPLY=( $( compgen -W 'delete dump getnext help \
|
2019-01-16 11:10:05 -08:00
|
|
|
lookup pin event_pipe show list update create \
|
|
|
|
|
peek push enqueue pop dequeue' -- \
|
2018-05-03 18:37:16 -07:00
|
|
|
"$cur" ) )
|
2017-10-26 14:16:05 -07:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2018-02-07 20:27:17 -08:00
|
|
|
cgroup)
|
|
|
|
|
case $command in
|
|
|
|
|
show|list)
|
|
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
tools/bpf: bpftool: add net support
Add "bpftool net" support. Networking devices are enumerated
to dump device index/name associated with xdp progs.
For each networking device, tc classes and qdiscs are enumerated
in order to check their bpf filters.
In addition, root handle and clsact ingress/egress are also checked for
bpf filters. Not all filter information is printed out. Only ifindex,
kind, filter name, prog_id and tag are printed out, which are good
enough to show attachment information. If the filter action
is a bpf action, its bpf program id, bpf name and tag will be
printed out as well.
For example,
$ ./bpftool net
xdp [
ifindex 2 devname eth0 prog_id 198
]
tc_filters [
ifindex 2 kind qdisc_htb name prefix_matcher.o:[cls_prefix_matcher_htb]
prog_id 111727 tag d08fe3b4319bc2fd act []
ifindex 2 kind qdisc_clsact_ingress name fbflow_icmp
prog_id 130246 tag 3f265c7f26db62c9 act []
ifindex 2 kind qdisc_clsact_egress name prefix_matcher.o:[cls_prefix_matcher_clsact]
prog_id 111726 tag 99a197826974c876
ifindex 2 kind qdisc_clsact_egress name cls_fg_dscp
prog_id 108619 tag dc4630674fd72dcc act []
ifindex 2 kind qdisc_clsact_egress name fbflow_egress
prog_id 130245 tag 72d2d830d6888d2c
]
$ ./bpftool -jp net
[{
"xdp": [{
"ifindex": 2,
"devname": "eth0",
"prog_id": 198
}
],
"tc_filters": [{
"ifindex": 2,
"kind": "qdisc_htb",
"name": "prefix_matcher.o:[cls_prefix_matcher_htb]",
"prog_id": 111727,
"tag": "d08fe3b4319bc2fd",
"act": []
},{
"ifindex": 2,
"kind": "qdisc_clsact_ingress",
"name": "fbflow_icmp",
"prog_id": 130246,
"tag": "3f265c7f26db62c9",
"act": []
},{
"ifindex": 2,
"kind": "qdisc_clsact_egress",
"name": "prefix_matcher.o:[cls_prefix_matcher_clsact]",
"prog_id": 111726,
"tag": "99a197826974c876"
},{
"ifindex": 2,
"kind": "qdisc_clsact_egress",
"name": "cls_fg_dscp",
"prog_id": 108619,
"tag": "dc4630674fd72dcc",
"act": []
},{
"ifindex": 2,
"kind": "qdisc_clsact_egress",
"name": "fbflow_egress",
"prog_id": 130245,
"tag": "72d2d830d6888d2c"
}
]
}
]
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-09-05 16:58:06 -07:00
|
|
|
tree)
|
|
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-02-07 20:27:17 -08:00
|
|
|
attach|detach)
|
|
|
|
|
local ATTACH_TYPES='ingress egress sock_create sock_ops \
|
2018-04-17 10:28:44 -07:00
|
|
|
device bind4 bind6 post_bind4 post_bind6 connect4 \
|
2018-05-29 13:29:31 -07:00
|
|
|
connect6 sendmsg4 sendmsg6'
|
2018-02-07 20:27:17 -08:00
|
|
|
local ATTACH_FLAGS='multi override'
|
|
|
|
|
local PROG_TYPE='id pinned tag'
|
|
|
|
|
case $prev in
|
|
|
|
|
$command)
|
|
|
|
|
_filedir
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2018-04-17 10:28:44 -07:00
|
|
|
ingress|egress|sock_create|sock_ops|device|bind4|bind6|\
|
2018-05-29 13:29:31 -07:00
|
|
|
post_bind4|post_bind6|connect4|connect6|sendmsg4|\
|
|
|
|
|
sendmsg6)
|
2018-02-07 20:27:17 -08:00
|
|
|
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
|
|
|
|
|
"$cur" ) )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
id)
|
|
|
|
|
_bpftool_get_prog_ids
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
if ! _bpftool_search_list "$ATTACH_TYPES"; then
|
|
|
|
|
COMPREPLY=( $( compgen -W "$ATTACH_TYPES" -- \
|
|
|
|
|
"$cur" ) )
|
|
|
|
|
elif [[ "$command" == "attach" ]]; then
|
|
|
|
|
# We have an attach type on the command line,
|
|
|
|
|
# but it is not the previous word, or
|
|
|
|
|
# "id|pinned|tag" (we already checked for
|
|
|
|
|
# that). This should only leave the case when
|
|
|
|
|
# we need attach flags for "attach" commamnd.
|
|
|
|
|
_bpftool_one_of_list "$ATTACH_FLAGS"
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
[[ $prev == $object ]] && \
|
|
|
|
|
COMPREPLY=( $( compgen -W 'help attach detach \
|
2018-07-06 14:28:16 -07:00
|
|
|
show list tree' -- "$cur" ) )
|
2018-02-07 20:27:17 -08:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
tools/bpftool: add perf subcommand
The new command "bpftool perf [show | list]" will traverse
all processes under /proc, and if any fd is associated
with a perf event, it will print out related perf event
information. Documentation is also added.
Below is an example to show the results using bcc commands.
Running the following 4 bcc commands:
kprobe: trace.py '__x64_sys_nanosleep'
kretprobe: trace.py 'r::__x64_sys_nanosleep'
tracepoint: trace.py 't:syscalls:sys_enter_nanosleep'
uprobe: trace.py 'p:/home/yhs/a.out:main'
The bpftool command line and result:
$ bpftool perf
pid 21711 fd 5: prog_id 5 kprobe func __x64_sys_write offset 0
pid 21765 fd 5: prog_id 7 kretprobe func __x64_sys_nanosleep offset 0
pid 21767 fd 5: prog_id 8 tracepoint sys_enter_nanosleep
pid 21800 fd 5: prog_id 9 uprobe filename /home/yhs/a.out offset 1159
$ bpftool -j perf
[{"pid":21711,"fd":5,"prog_id":5,"fd_type":"kprobe","func":"__x64_sys_write","offset":0}, \
{"pid":21765,"fd":5,"prog_id":7,"fd_type":"kretprobe","func":"__x64_sys_nanosleep","offset":0}, \
{"pid":21767,"fd":5,"prog_id":8,"fd_type":"tracepoint","tracepoint":"sys_enter_nanosleep"}, \
{"pid":21800,"fd":5,"prog_id":9,"fd_type":"uprobe","filename":"/home/yhs/a.out","offset":1159}]
$ bpftool prog
5: kprobe name probe___x64_sys tag e495a0c82f2c7a8d gpl
loaded_at 2018-05-15T04:46:37-0700 uid 0
xlated 200B not jited memlock 4096B map_ids 4
7: kprobe name probe___x64_sys tag f2fdee479a503abf gpl
loaded_at 2018-05-15T04:48:32-0700 uid 0
xlated 200B not jited memlock 4096B map_ids 7
8: tracepoint name tracepoint__sys tag 5390badef2395fcf gpl
loaded_at 2018-05-15T04:48:48-0700 uid 0
xlated 200B not jited memlock 4096B map_ids 8
9: kprobe name probe_main_1 tag 0a87bdc2e2953b6d gpl
loaded_at 2018-05-15T04:49:52-0700 uid 0
xlated 200B not jited memlock 4096B map_ids 9
$ ps ax | grep "python ./trace.py"
21711 pts/0 T 0:03 python ./trace.py __x64_sys_write
21765 pts/0 S+ 0:00 python ./trace.py r::__x64_sys_nanosleep
21767 pts/2 S+ 0:00 python ./trace.py t:syscalls:sys_enter_nanosleep
21800 pts/3 S+ 0:00 python ./trace.py p:/home/yhs/a.out:main
22374 pts/1 S+ 0:00 grep --color=auto python ./trace.py
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-05-24 11:21:58 -07:00
|
|
|
perf)
|
|
|
|
|
case $command in
|
|
|
|
|
*)
|
|
|
|
|
[[ $prev == $object ]] && \
|
|
|
|
|
COMPREPLY=( $( compgen -W 'help \
|
|
|
|
|
show list' -- "$cur" ) )
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
tools/bpf: bpftool: add net support
Add "bpftool net" support. Networking devices are enumerated
to dump device index/name associated with xdp progs.
For each networking device, tc classes and qdiscs are enumerated
in order to check their bpf filters.
In addition, root handle and clsact ingress/egress are also checked for
bpf filters. Not all filter information is printed out. Only ifindex,
kind, filter name, prog_id and tag are printed out, which are good
enough to show attachment information. If the filter action
is a bpf action, its bpf program id, bpf name and tag will be
printed out as well.
For example,
$ ./bpftool net
xdp [
ifindex 2 devname eth0 prog_id 198
]
tc_filters [
ifindex 2 kind qdisc_htb name prefix_matcher.o:[cls_prefix_matcher_htb]
prog_id 111727 tag d08fe3b4319bc2fd act []
ifindex 2 kind qdisc_clsact_ingress name fbflow_icmp
prog_id 130246 tag 3f265c7f26db62c9 act []
ifindex 2 kind qdisc_clsact_egress name prefix_matcher.o:[cls_prefix_matcher_clsact]
prog_id 111726 tag 99a197826974c876
ifindex 2 kind qdisc_clsact_egress name cls_fg_dscp
prog_id 108619 tag dc4630674fd72dcc act []
ifindex 2 kind qdisc_clsact_egress name fbflow_egress
prog_id 130245 tag 72d2d830d6888d2c
]
$ ./bpftool -jp net
[{
"xdp": [{
"ifindex": 2,
"devname": "eth0",
"prog_id": 198
}
],
"tc_filters": [{
"ifindex": 2,
"kind": "qdisc_htb",
"name": "prefix_matcher.o:[cls_prefix_matcher_htb]",
"prog_id": 111727,
"tag": "d08fe3b4319bc2fd",
"act": []
},{
"ifindex": 2,
"kind": "qdisc_clsact_ingress",
"name": "fbflow_icmp",
"prog_id": 130246,
"tag": "3f265c7f26db62c9",
"act": []
},{
"ifindex": 2,
"kind": "qdisc_clsact_egress",
"name": "prefix_matcher.o:[cls_prefix_matcher_clsact]",
"prog_id": 111726,
"tag": "99a197826974c876"
},{
"ifindex": 2,
"kind": "qdisc_clsact_egress",
"name": "cls_fg_dscp",
"prog_id": 108619,
"tag": "dc4630674fd72dcc",
"act": []
},{
"ifindex": 2,
"kind": "qdisc_clsact_egress",
"name": "fbflow_egress",
"prog_id": 130245,
"tag": "72d2d830d6888d2c"
}
]
}
]
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-09-05 16:58:06 -07:00
|
|
|
net)
|
|
|
|
|
case $command in
|
|
|
|
|
*)
|
|
|
|
|
[[ $prev == $object ]] && \
|
|
|
|
|
COMPREPLY=( $( compgen -W 'help \
|
|
|
|
|
show list' -- "$cur" ) )
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2017-10-26 14:16:05 -07:00
|
|
|
esac
|
|
|
|
|
} &&
|
|
|
|
|
complete -F _bpftool bpftool
|
|
|
|
|
|
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|