aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/bash-completion
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2018-02-07 23:27:17 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-02-08 05:59:50 -0500
commita827a164b98be2acba6a2e7559643ac9a5745086 (patch)
tree921ff83162854c3a7cdfbd6664dafd83d023c6a1 /tools/bpf/bpftool/bash-completion
parent55f3538c4923e9dfca132e99ebec370e8094afda (diff)
tools: bpftool: add bash completion for cgroup commands
Add bash completion for "bpftool cgroup" command family. While at it, also fix the formatting of some keywords in the man page for cgroups. Fixes: 5ccda64d38cc ("bpftool: implement cgroup bpf operations") Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf/bpftool/bash-completion')
-rw-r--r--tools/bpf/bpftool/bash-completion/bpftool64
1 files changed, 60 insertions, 4 deletions
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 17d246418348..08719c54a614 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -52,16 +52,24 @@ _bpftool_once_attr()
52 done 52 done
53} 53}
54 54
55# Takes a list of words in argument; adds them all to COMPREPLY if none of them 55# Takes a list of words as argument; if any of those words is present on the
56# is already present on the command line. Returns no value. 56# command line, return 0. Otherwise, return 1.
57_bpftool_one_of_list() 57_bpftool_search_list()
58{ 58{
59 local w idx 59 local w idx
60 for w in $*; do 60 for w in $*; do
61 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do 61 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
62 [[ $w == ${words[idx]} ]] && return 1 62 [[ $w == ${words[idx]} ]] && return 0
63 done 63 done
64 done 64 done
65 return 1
66}
67
68# Takes a list of words in argument; adds them all to COMPREPLY if none of them
69# is already present on the command line. Returns no value.
70_bpftool_one_of_list()
71{
72 _bpftool_search_list $* && return 1
65 COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) ) 73 COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
66} 74}
67 75
@@ -351,6 +359,54 @@ _bpftool()
351 ;; 359 ;;
352 esac 360 esac
353 ;; 361 ;;
362 cgroup)
363 case $command in
364 show|list)
365 _filedir
366 return 0
367 ;;
368 attach|detach)
369 local ATTACH_TYPES='ingress egress sock_create sock_ops \
370 device'
371 local ATTACH_FLAGS='multi override'
372 local PROG_TYPE='id pinned tag'
373 case $prev in
374 $command)
375 _filedir
376 return 0
377 ;;
378 ingress|egress|sock_create|sock_ops|device)
379 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
380 "$cur" ) )
381 return 0
382 ;;
383 id)
384 _bpftool_get_prog_ids
385 return 0
386 ;;
387 *)
388 if ! _bpftool_search_list "$ATTACH_TYPES"; then
389 COMPREPLY=( $( compgen -W "$ATTACH_TYPES" -- \
390 "$cur" ) )
391 elif [[ "$command" == "attach" ]]; then
392 # We have an attach type on the command line,
393 # but it is not the previous word, or
394 # "id|pinned|tag" (we already checked for
395 # that). This should only leave the case when
396 # we need attach flags for "attach" commamnd.
397 _bpftool_one_of_list "$ATTACH_FLAGS"
398 fi
399 return 0
400 ;;
401 esac
402 ;;
403 *)
404 [[ $prev == $object ]] && \
405 COMPREPLY=( $( compgen -W 'help attach detach \
406 show list' -- "$cur" ) )
407 ;;
408 esac
409 ;;
354 esac 410 esac
355} && 411} &&
356complete -F _bpftool bpftool 412complete -F _bpftool bpftool