Commit 510b4d4c authored by Quentin Monnet's avatar Quentin Monnet Committed by Andrii Nakryiko

tools: bpftool: Slightly ease bash completion updates

Bash completion for bpftool gets two minor improvements in this patch.

Move the detection of attach types for "bpftool cgroup attach" outside
of the "case/esac" bloc, where we cannot reuse our variable holding the
list of supported attach types as a pattern list. After the change, we
have only one list of cgroup attach types to update when new types are
added, instead of the former two lists.

Also rename the variables holding lists of names for program types, map
types, and attach types, to make them more unique. This can make it
slightly easier to point people to the relevant variables to update, but
the main objective here is to help run a script to check that bash
completion is up-to-date with bpftool's source code.
Signed-off-by: default avatarQuentin Monnet <quentin@isovalent.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210730215435.7095-2-quentin@isovalent.com
parent 0b846445
...@@ -404,8 +404,9 @@ _bpftool() ...@@ -404,8 +404,9 @@ _bpftool()
return 0 return 0
;; ;;
5) 5)
COMPREPLY=( $( compgen -W 'msg_verdict stream_verdict \ local BPFTOOL_PROG_ATTACH_TYPES='msg_verdict \
stream_parser flow_dissector' -- "$cur" ) ) stream_verdict stream_parser flow_dissector'
COMPREPLY=( $( compgen -W "$BPFTOOL_PROG_ATTACH_TYPES" -- "$cur" ) )
return 0 return 0
;; ;;
6) 6)
...@@ -464,7 +465,7 @@ _bpftool() ...@@ -464,7 +465,7 @@ _bpftool()
case $prev in case $prev in
type) type)
COMPREPLY=( $( compgen -W "socket kprobe \ local BPFTOOL_PROG_LOAD_TYPES='socket kprobe \
kretprobe classifier flow_dissector \ kretprobe classifier flow_dissector \
action tracepoint raw_tracepoint \ action tracepoint raw_tracepoint \
xdp perf_event cgroup/skb cgroup/sock \ xdp perf_event cgroup/skb cgroup/sock \
...@@ -479,8 +480,8 @@ _bpftool() ...@@ -479,8 +480,8 @@ _bpftool()
cgroup/post_bind4 cgroup/post_bind6 \ cgroup/post_bind4 cgroup/post_bind6 \
cgroup/sysctl cgroup/getsockopt \ cgroup/sysctl cgroup/getsockopt \
cgroup/setsockopt cgroup/sock_release struct_ops \ cgroup/setsockopt cgroup/sock_release struct_ops \
fentry fexit freplace sk_lookup" -- \ fentry fexit freplace sk_lookup'
"$cur" ) ) COMPREPLY=( $( compgen -W "$BPFTOOL_PROG_LOAD_TYPES" -- "$cur" ) )
return 0 return 0
;; ;;
id) id)
...@@ -698,15 +699,15 @@ _bpftool() ...@@ -698,15 +699,15 @@ _bpftool()
return 0 return 0
;; ;;
type) type)
COMPREPLY=( $( compgen -W 'hash array prog_array \ local BPFTOOL_MAP_CREATE_TYPES='hash array \
perf_event_array percpu_hash percpu_array \ prog_array perf_event_array percpu_hash \
stack_trace cgroup_array lru_hash \ percpu_array stack_trace cgroup_array lru_hash \
lru_percpu_hash lpm_trie array_of_maps \ lru_percpu_hash lpm_trie array_of_maps \
hash_of_maps devmap devmap_hash sockmap cpumap \ hash_of_maps devmap devmap_hash sockmap cpumap \
xskmap sockhash cgroup_storage reuseport_sockarray \ xskmap sockhash cgroup_storage reuseport_sockarray \
percpu_cgroup_storage queue stack sk_storage \ percpu_cgroup_storage queue stack sk_storage \
struct_ops inode_storage task_storage' -- \ struct_ops inode_storage task_storage'
"$cur" ) ) COMPREPLY=( $( compgen -W "$BPFTOOL_MAP_CREATE_TYPES" -- "$cur" ) )
return 0 return 0
;; ;;
key|value|flags|entries) key|value|flags|entries)
...@@ -1017,34 +1018,37 @@ _bpftool() ...@@ -1017,34 +1018,37 @@ _bpftool()
return 0 return 0
;; ;;
attach|detach) attach|detach)
local ATTACH_TYPES='ingress egress sock_create sock_ops \ local BPFTOOL_CGROUP_ATTACH_TYPES='ingress egress \
device bind4 bind6 post_bind4 post_bind6 connect4 connect6 \ sock_create sock_ops device \
bind4 bind6 post_bind4 post_bind6 connect4 connect6 \
getpeername4 getpeername6 getsockname4 getsockname6 \ getpeername4 getpeername6 getsockname4 getsockname6 \
sendmsg4 sendmsg6 recvmsg4 recvmsg6 sysctl getsockopt \ sendmsg4 sendmsg6 recvmsg4 recvmsg6 sysctl getsockopt \
setsockopt sock_release' setsockopt sock_release'
local ATTACH_FLAGS='multi override' local ATTACH_FLAGS='multi override'
local PROG_TYPE='id pinned tag name' local PROG_TYPE='id pinned tag name'
case $prev in # Check for $prev = $command first
$command) if [ $prev = $command ]; then
_filedir _filedir
return 0 return 0
;; # Then check for attach type. This is done outside of the
ingress|egress|sock_create|sock_ops|device|bind4|bind6|\ # "case $prev in" to avoid writing the whole list of attach
post_bind4|post_bind6|connect4|connect6|getpeername4|\ # types again as pattern to match (where we cannot reuse
getpeername6|getsockname4|getsockname6|sendmsg4|sendmsg6|\ # our variable).
recvmsg4|recvmsg6|sysctl|getsockopt|setsockopt|sock_release) elif [[ $BPFTOOL_CGROUP_ATTACH_TYPES =~ $prev ]]; then
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \ COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
"$cur" ) ) "$cur" ) )
return 0 return 0
;; fi
# case/esac for the other cases
case $prev in
id) id)
_bpftool_get_prog_ids _bpftool_get_prog_ids
return 0 return 0
;; ;;
*) *)
if ! _bpftool_search_list "$ATTACH_TYPES"; then if ! _bpftool_search_list "$BPFTOOL_CGROUP_ATTACH_TYPES"; then
COMPREPLY=( $( compgen -W "$ATTACH_TYPES" -- \ COMPREPLY=( $( compgen -W \
"$cur" ) ) "$BPFTOOL_CGROUP_ATTACH_TYPES" -- "$cur" ) )
elif [[ "$command" == "attach" ]]; then elif [[ "$command" == "attach" ]]; then
# We have an attach type on the command line, # We have an attach type on the command line,
# but it is not the previous word, or # but it is not the previous word, or
......
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