Commit cad49773 authored by Quentin Monnet's avatar Quentin Monnet Committed by Alexei Starovoitov

tools: bpftool: fix bash completion for bpftool prog (attach|detach)

Fix bash completion for "bpftool prog (attach|detach) PROG TYPE MAP" so
that the list of indices proposed for MAP are map indices, and not PROG
indices. Also use variables for map and prog reference types ("id",
"pinned", and "tag" for programs).

Fixes: b7d3826c ("bpf: bpftool, add support for attaching programs to maps")
Signed-off-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 327e5dab
...@@ -243,16 +243,20 @@ _bpftool() ...@@ -243,16 +243,20 @@ _bpftool()
# Completion depends on object and command in use # Completion depends on object and command in use
case $object in case $object in
prog) prog)
if [[ $command != "load" && $command != "loadall" ]]; then # Complete id, only for subcommands that use prog (but no map) ids
case $prev in case $command in
id) show|list|dump|pin)
_bpftool_get_prog_ids case $prev in
return 0 id)
;; _bpftool_get_prog_ids
esac return 0
fi ;;
esac
;;
esac
local PROG_TYPE='id pinned tag' local PROG_TYPE='id pinned tag'
local MAP_TYPE='id pinned'
case $command in case $command in
show|list) show|list)
[[ $prev != "$command" ]] && return 0 [[ $prev != "$command" ]] && return 0
...@@ -293,22 +297,43 @@ _bpftool() ...@@ -293,22 +297,43 @@ _bpftool()
return 0 return 0
;; ;;
attach|detach) attach|detach)
if [[ ${#words[@]} == 7 ]]; then case $cword in
COMPREPLY=( $( compgen -W "id pinned" -- "$cur" ) ) 3)
return 0 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
fi return 0
;;
if [[ ${#words[@]} == 6 ]]; then 4)
COMPREPLY=( $( compgen -W "msg_verdict skb_verdict \ case $prev in
skb_parse flow_dissector" -- "$cur" ) ) id)
return 0 _bpftool_get_prog_ids
fi ;;
pinned)
if [[ $prev == "$command" ]]; then _filedir
COMPREPLY=( $( compgen -W "id pinned" -- "$cur" ) ) ;;
return 0 esac
fi return 0
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
;; ;;
load|loadall) load|loadall)
local obj local obj
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment