aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/bash-completion
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-07-10 17:43:07 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-11 16:13:34 -0400
commit3ff5a4dc5d890963e669fc99cc62ee07d1da24e8 (patch)
tree227ec4a474eaa03236f5ce8df1df25d890846ee4 /tools/bpf/bpftool/bash-completion
parent26736eb9a483715c2e971a8866f55fbb156903e2 (diff)
tools: bpftool: allow reuse of maps with bpftool prog load
Add map parameter to prog load which will allow reuse of existing maps instead of creating new ones. We need feature detection and compat code for reallocarray, since it's not available in many libc versions. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf/bpftool/bash-completion')
-rw-r--r--tools/bpf/bpftool/bash-completion/bpftool67
1 files changed, 61 insertions, 6 deletions
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index caf8711993be..598066c40191 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -99,6 +99,29 @@ _bpftool_get_prog_tags()
99 command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) ) 99 command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
100} 100}
101 101
102_bpftool_get_obj_map_names()
103{
104 local obj
105
106 obj=$1
107
108 maps=$(objdump -j maps -t $obj 2>/dev/null | \
109 command awk '/g . maps/ {print $NF}')
110
111 COMPREPLY+=( $( compgen -W "$maps" -- "$cur" ) )
112}
113
114_bpftool_get_obj_map_idxs()
115{
116 local obj
117
118 obj=$1
119
120 nmaps=$(objdump -j maps -t $obj 2>/dev/null | grep -c 'g . maps')
121
122 COMPREPLY+=( $( compgen -W "$(seq 0 $((nmaps - 1)))" -- "$cur" ) )
123}
124
102_sysfs_get_netdevs() 125_sysfs_get_netdevs()
103{ 126{
104 COMPREPLY+=( $( compgen -W "$( ls /sys/class/net 2>/dev/null )" -- \ 127 COMPREPLY+=( $( compgen -W "$( ls /sys/class/net 2>/dev/null )" -- \
@@ -220,12 +243,14 @@ _bpftool()
220 # Completion depends on object and command in use 243 # Completion depends on object and command in use
221 case $object in 244 case $object in
222 prog) 245 prog)
223 case $prev in 246 if [[ $command != "load" ]]; then
224 id) 247 case $prev in
225 _bpftool_get_prog_ids 248 id)
226 return 0 249 _bpftool_get_prog_ids
227 ;; 250 return 0
228 esac 251 ;;
252 esac
253 fi
229 254
230 local PROG_TYPE='id pinned tag' 255 local PROG_TYPE='id pinned tag'
231 case $command in 256 case $command in
@@ -268,22 +293,52 @@ _bpftool()
268 return 0 293 return 0
269 ;; 294 ;;
270 load) 295 load)
296 local obj
297
271 if [[ ${#words[@]} -lt 6 ]]; then 298 if [[ ${#words[@]} -lt 6 ]]; then
272 _filedir 299 _filedir
273 return 0 300 return 0
274 fi 301 fi
275 302
303 obj=${words[3]}
304
305 if [[ ${words[-4]} == "map" ]]; then
306 COMPREPLY=( $( compgen -W "id pinned" -- "$cur" ) )
307 return 0
308 fi
309 if [[ ${words[-3]} == "map" ]]; then
310 if [[ ${words[-2]} == "idx" ]]; then
311 _bpftool_get_obj_map_idxs $obj
312 elif [[ ${words[-2]} == "name" ]]; then
313 _bpftool_get_obj_map_names $obj
314 fi
315 return 0
316 fi
317 if [[ ${words[-2]} == "map" ]]; then
318 COMPREPLY=( $( compgen -W "idx name" -- "$cur" ) )
319 return 0
320 fi
321
276 case $prev in 322 case $prev in
277 type) 323 type)
278 COMPREPLY=( $( compgen -W "socket kprobe kretprobe classifier 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" -- \ 324 COMPREPLY=( $( compgen -W "socket kprobe kretprobe classifier 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" -- \
279 "$cur" ) ) 325 "$cur" ) )
280 return 0 326 return 0
281 ;; 327 ;;
328 id)
329 _bpftool_get_map_ids
330 return 0
331 ;;
332 pinned)
333 _filedir
334 return 0
335 ;;
282 dev) 336 dev)
283 _sysfs_get_netdevs 337 _sysfs_get_netdevs
284 return 0 338 return 0
285 ;; 339 ;;
286 *) 340 *)
341 COMPREPLY=( $( compgen -W "map" -- "$cur" ) )
287 _bpftool_once_attr 'type' 342 _bpftool_once_attr 'type'
288 _bpftool_once_attr 'dev' 343 _bpftool_once_attr 'dev'
289 return 0 344 return 0