hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/tools/bpf/bpftool/bash-completion/bpftool
....@@ -1,36 +1,7 @@
11 # bpftool(8) bash completion -*- shell-script -*-
22 #
3
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
34 # Copyright (C) 2017-2018 Netronome Systems, Inc.
4
-#
5
-# This software is dual licensed under the GNU General License
6
-# Version 2, June 1991 as shown in the file COPYING in the top-level
7
-# directory of this source tree or the BSD 2-Clause License provided
8
-# below. You have the option to license this software under the
9
-# complete terms of either license.
10
-#
11
-# The BSD 2-Clause License:
12
-#
13
-# Redistribution and use in source and binary forms, with or
14
-# without modification, are permitted provided that the following
15
-# conditions are met:
16
-#
17
-# 1. Redistributions of source code must retain the above
18
-# copyright notice, this list of conditions and the following
19
-# disclaimer.
20
-#
21
-# 2. Redistributions in binary form must reproduce the above
22
-# copyright notice, this list of conditions and the following
23
-# disclaimer in the documentation and/or other materials
24
-# provided with the distribution.
25
-#
26
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30
-# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32
-# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
-# SOFTWARE.
345 #
356 # Author: Quentin Monnet <quentin.monnet@netronome.com>
367
....@@ -79,13 +50,29 @@
7950 command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
8051 }
8152
82
-_bpftool_get_perf_map_ids()
53
+# Takes map type and adds matching map ids to the list of suggestions.
54
+_bpftool_get_map_ids_for_type()
8355 {
56
+ local type="$1"
8457 COMPREPLY+=( $( compgen -W "$( bpftool -jp map 2>&1 | \
85
- command grep -C2 perf_event_array | \
58
+ command grep -C2 "$type" | \
8659 command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
8760 }
8861
62
+_bpftool_get_map_names()
63
+{
64
+ COMPREPLY+=( $( compgen -W "$( bpftool -jp map 2>&1 | \
65
+ command sed -n 's/.*"name": \(.*\),$/\1/p' )" -- "$cur" ) )
66
+}
67
+
68
+# Takes map type and adds matching map names to the list of suggestions.
69
+_bpftool_get_map_names_for_type()
70
+{
71
+ local type="$1"
72
+ COMPREPLY+=( $( compgen -W "$( bpftool -jp map 2>&1 | \
73
+ command grep -C2 "$type" | \
74
+ command sed -n 's/.*"name": \(.*\),$/\1/p' )" -- "$cur" ) )
75
+}
8976
9077 _bpftool_get_prog_ids()
9178 {
....@@ -97,6 +84,24 @@
9784 {
9885 COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
9986 command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
87
+}
88
+
89
+_bpftool_get_prog_names()
90
+{
91
+ COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
92
+ command sed -n 's/.*"name": "\(.*\)",$/\1/p' )" -- "$cur" ) )
93
+}
94
+
95
+_bpftool_get_btf_ids()
96
+{
97
+ COMPREPLY+=( $( compgen -W "$( bpftool -jp btf 2>&1 | \
98
+ command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
99
+}
100
+
101
+_bpftool_get_link_ids()
102
+{
103
+ COMPREPLY+=( $( compgen -W "$( bpftool -jp link 2>&1 | \
104
+ command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
100105 }
101106
102107 _bpftool_get_obj_map_names()
....@@ -128,15 +133,25 @@
128133 "$cur" ) )
129134 }
130135
131
-# For bpftool map update: retrieve type of the map to update.
132
-_bpftool_map_update_map_type()
136
+# Retrieve type of the map that we are operating on.
137
+_bpftool_map_guess_map_type()
133138 {
134139 local keyword ref
135140 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
136
- if [[ ${words[$((idx-2))]} == "update" ]]; then
137
- keyword=${words[$((idx-1))]}
138
- ref=${words[$((idx))]}
139
- fi
141
+ case "${words[$((idx-2))]}" in
142
+ lookup|update)
143
+ keyword=${words[$((idx-1))]}
144
+ ref=${words[$((idx))]}
145
+ ;;
146
+ push)
147
+ printf "stack"
148
+ return 0
149
+ ;;
150
+ enqueue)
151
+ printf "queue"
152
+ return 0
153
+ ;;
154
+ esac
140155 done
141156 [[ -z $ref ]] && return 0
142157
....@@ -148,6 +163,8 @@
148163
149164 _bpftool_map_update_get_id()
150165 {
166
+ local command="$1"
167
+
151168 # Is it the map to update, or a map to insert into the map to update?
152169 # Search for "value" keyword.
153170 local idx value
....@@ -157,11 +174,24 @@
157174 break
158175 fi
159176 done
160
- [[ $value -eq 0 ]] && _bpftool_get_map_ids && return 0
177
+ if [[ $value -eq 0 ]]; then
178
+ case "$command" in
179
+ push)
180
+ _bpftool_get_map_ids_for_type stack
181
+ ;;
182
+ enqueue)
183
+ _bpftool_get_map_ids_for_type queue
184
+ ;;
185
+ *)
186
+ _bpftool_get_map_ids
187
+ ;;
188
+ esac
189
+ return 0
190
+ fi
161191
162192 # Id to complete is for a value. It can be either prog id or map id. This
163193 # depends on the type of the map to update.
164
- local type=$(_bpftool_map_update_map_type)
194
+ local type=$(_bpftool_map_guess_map_type)
165195 case $type in
166196 array_of_maps|hash_of_maps)
167197 _bpftool_get_map_ids
....@@ -177,6 +207,52 @@
177207 esac
178208 }
179209
210
+_bpftool_map_update_get_name()
211
+{
212
+ local command="$1"
213
+
214
+ # Is it the map to update, or a map to insert into the map to update?
215
+ # Search for "value" keyword.
216
+ local idx value
217
+ for (( idx=7; idx < ${#words[@]}-1; idx++ )); do
218
+ if [[ ${words[idx]} == "value" ]]; then
219
+ value=1
220
+ break
221
+ fi
222
+ done
223
+ if [[ $value -eq 0 ]]; then
224
+ case "$command" in
225
+ push)
226
+ _bpftool_get_map_names_for_type stack
227
+ ;;
228
+ enqueue)
229
+ _bpftool_get_map_names_for_type queue
230
+ ;;
231
+ *)
232
+ _bpftool_get_map_names
233
+ ;;
234
+ esac
235
+ return 0
236
+ fi
237
+
238
+ # Name to complete is for a value. It can be either prog name or map name. This
239
+ # depends on the type of the map to update.
240
+ local type=$(_bpftool_map_guess_map_type)
241
+ case $type in
242
+ array_of_maps|hash_of_maps)
243
+ _bpftool_get_map_names
244
+ return 0
245
+ ;;
246
+ prog_array)
247
+ _bpftool_get_prog_names
248
+ return 0
249
+ ;;
250
+ *)
251
+ return 0
252
+ ;;
253
+ esac
254
+}
255
+
180256 _bpftool()
181257 {
182258 local cur prev words objword
....@@ -184,18 +260,22 @@
184260
185261 # Deal with options
186262 if [[ ${words[cword]} == -* ]]; then
187
- local c='--version --json --pretty --bpffs'
263
+ local c='--version --json --pretty --bpffs --mapcompat --debug'
188264 COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
189265 return 0
190266 fi
191267
192268 # Deal with simplest keywords
193269 case $prev in
194
- help|hex|opcodes|visual)
270
+ help|hex|opcodes|visual|linum)
195271 return 0
196272 ;;
197273 tag)
198274 _bpftool_get_prog_tags
275
+ return 0
276
+ ;;
277
+ dev)
278
+ _sysfs_get_netdevs
199279 return 0
200280 ;;
201281 file|pinned)
....@@ -220,6 +300,7 @@
220300 done
221301 cur=${words[cword]}
222302 prev=${words[cword - 1]}
303
+ pprev=${words[cword - 2]}
223304
224305 local object=${words[1]} command=${words[2]}
225306
....@@ -243,16 +324,26 @@
243324 # Completion depends on object and command in use
244325 case $object in
245326 prog)
246
- if [[ $command != "load" ]]; then
247
- case $prev in
248
- id)
249
- _bpftool_get_prog_ids
250
- return 0
251
- ;;
252
- esac
253
- fi
327
+ # Complete id and name, only for subcommands that use prog (but no
328
+ # map) ids/names.
329
+ case $command in
330
+ show|list|dump|pin)
331
+ case $prev in
332
+ id)
333
+ _bpftool_get_prog_ids
334
+ return 0
335
+ ;;
336
+ name)
337
+ _bpftool_get_prog_names
338
+ return 0
339
+ ;;
340
+ esac
341
+ ;;
342
+ esac
254343
255
- local PROG_TYPE='id pinned tag'
344
+ local PROG_TYPE='id pinned tag name'
345
+ local MAP_TYPE='id pinned name'
346
+ local METRIC_TYPE='cycles instructions l1d_loads llc_misses'
256347 case $command in
257348 show|list)
258349 [[ $prev != "$command" ]] && return 0
....@@ -271,17 +362,17 @@
271362 "$cur" ) )
272363 return 0
273364 ;;
274
- *)
275
- _bpftool_once_attr 'file'
276
- if _bpftool_search_list 'xlated'; then
277
- COMPREPLY+=( $( compgen -W 'opcodes visual' -- \
278
- "$cur" ) )
279
- else
280
- COMPREPLY+=( $( compgen -W 'opcodes' -- \
281
- "$cur" ) )
282
- fi
283
- return 0
284
- ;;
365
+ *)
366
+ _bpftool_once_attr 'file'
367
+ if _bpftool_search_list 'xlated'; then
368
+ COMPREPLY+=( $( compgen -W 'opcodes visual linum' -- \
369
+ "$cur" ) )
370
+ else
371
+ COMPREPLY+=( $( compgen -W 'opcodes linum' -- \
372
+ "$cur" ) )
373
+ fi
374
+ return 0
375
+ ;;
285376 esac
286377 ;;
287378 pin)
....@@ -292,8 +383,60 @@
292383 fi
293384 return 0
294385 ;;
295
- load)
386
+ attach|detach)
387
+ case $cword in
388
+ 3)
389
+ COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
390
+ return 0
391
+ ;;
392
+ 4)
393
+ case $prev in
394
+ id)
395
+ _bpftool_get_prog_ids
396
+ ;;
397
+ name)
398
+ _bpftool_get_prog_names
399
+ ;;
400
+ pinned)
401
+ _filedir
402
+ ;;
403
+ esac
404
+ return 0
405
+ ;;
406
+ 5)
407
+ COMPREPLY=( $( compgen -W 'msg_verdict stream_verdict \
408
+ stream_parser flow_dissector' -- "$cur" ) )
409
+ return 0
410
+ ;;
411
+ 6)
412
+ COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
413
+ return 0
414
+ ;;
415
+ 7)
416
+ case $prev in
417
+ id)
418
+ _bpftool_get_map_ids
419
+ ;;
420
+ name)
421
+ _bpftool_get_map_names
422
+ ;;
423
+ pinned)
424
+ _filedir
425
+ ;;
426
+ esac
427
+ return 0
428
+ ;;
429
+ esac
430
+ ;;
431
+ load|loadall)
296432 local obj
433
+
434
+ # Propose "load/loadall" to complete "bpftool prog load",
435
+ # or bash tries to complete "load" as a filename below.
436
+ if [[ ${#words[@]} -eq 3 ]]; then
437
+ COMPREPLY=( $( compgen -W "load loadall" -- "$cur" ) )
438
+ return 0
439
+ fi
297440
298441 if [[ ${#words[@]} -lt 6 ]]; then
299442 _filedir
....@@ -321,7 +464,22 @@
321464
322465 case $prev in
323466 type)
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" -- \
467
+ COMPREPLY=( $( compgen -W "socket kprobe \
468
+ kretprobe classifier flow_dissector \
469
+ action tracepoint raw_tracepoint \
470
+ xdp perf_event cgroup/skb cgroup/sock \
471
+ cgroup/dev lwt_in lwt_out lwt_xmit \
472
+ lwt_seg6local sockops sk_skb sk_msg \
473
+ lirc_mode2 cgroup/bind4 cgroup/bind6 \
474
+ cgroup/connect4 cgroup/connect6 \
475
+ cgroup/getpeername4 cgroup/getpeername6 \
476
+ cgroup/getsockname4 cgroup/getsockname6 \
477
+ cgroup/sendmsg4 cgroup/sendmsg6 \
478
+ cgroup/recvmsg4 cgroup/recvmsg6 \
479
+ cgroup/post_bind4 cgroup/post_bind6 \
480
+ cgroup/sysctl cgroup/getsockopt \
481
+ cgroup/setsockopt cgroup/sock_release struct_ops \
482
+ fentry fexit freplace sk_lookup" -- \
325483 "$cur" ) )
326484 return 0
327485 ;;
....@@ -329,43 +487,259 @@
329487 _bpftool_get_map_ids
330488 return 0
331489 ;;
332
- pinned)
333
- _filedir
490
+ name)
491
+ _bpftool_get_map_names
334492 return 0
335493 ;;
336
- dev)
337
- _sysfs_get_netdevs
494
+ pinned|pinmaps)
495
+ _filedir
338496 return 0
339497 ;;
340498 *)
341499 COMPREPLY=( $( compgen -W "map" -- "$cur" ) )
342500 _bpftool_once_attr 'type'
343501 _bpftool_once_attr 'dev'
502
+ _bpftool_once_attr 'pinmaps'
503
+ return 0
504
+ ;;
505
+ esac
506
+ ;;
507
+ tracelog)
508
+ return 0
509
+ ;;
510
+ profile)
511
+ case $cword in
512
+ 3)
513
+ COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
514
+ return 0
515
+ ;;
516
+ 4)
517
+ case $prev in
518
+ id)
519
+ _bpftool_get_prog_ids
520
+ ;;
521
+ name)
522
+ _bpftool_get_prog_names
523
+ ;;
524
+ pinned)
525
+ _filedir
526
+ ;;
527
+ esac
528
+ return 0
529
+ ;;
530
+ 5)
531
+ COMPREPLY=( $( compgen -W "$METRIC_TYPE duration" -- "$cur" ) )
532
+ return 0
533
+ ;;
534
+ 6)
535
+ case $prev in
536
+ duration)
537
+ return 0
538
+ ;;
539
+ *)
540
+ COMPREPLY=( $( compgen -W "$METRIC_TYPE" -- "$cur" ) )
541
+ return 0
542
+ ;;
543
+ esac
544
+ return 0
545
+ ;;
546
+ *)
547
+ COMPREPLY=( $( compgen -W "$METRIC_TYPE" -- "$cur" ) )
548
+ return 0
549
+ ;;
550
+ esac
551
+ ;;
552
+ run)
553
+ if [[ ${#words[@]} -eq 4 ]]; then
554
+ COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
555
+ return 0
556
+ fi
557
+ case $prev in
558
+ id)
559
+ _bpftool_get_prog_ids
560
+ return 0
561
+ ;;
562
+ name)
563
+ _bpftool_get_prog_names
564
+ return 0
565
+ ;;
566
+ data_in|data_out|ctx_in|ctx_out)
567
+ _filedir
568
+ return 0
569
+ ;;
570
+ repeat|data_size_out|ctx_size_out)
571
+ return 0
572
+ ;;
573
+ *)
574
+ _bpftool_once_attr 'data_in data_out data_size_out \
575
+ ctx_in ctx_out ctx_size_out repeat'
344576 return 0
345577 ;;
346578 esac
347579 ;;
348580 *)
349581 [[ $prev == $object ]] && \
350
- COMPREPLY=( $( compgen -W 'dump help pin load \
351
- show list' -- "$cur" ) )
582
+ COMPREPLY=( $( compgen -W 'dump help pin attach detach \
583
+ load loadall show list tracelog run profile' -- "$cur" ) )
584
+ ;;
585
+ esac
586
+ ;;
587
+ struct_ops)
588
+ local STRUCT_OPS_TYPE='id name'
589
+ case $command in
590
+ show|list|dump|unregister)
591
+ case $prev in
592
+ $command)
593
+ COMPREPLY=( $( compgen -W "$STRUCT_OPS_TYPE" -- "$cur" ) )
594
+ ;;
595
+ id)
596
+ _bpftool_get_map_ids_for_type struct_ops
597
+ ;;
598
+ name)
599
+ _bpftool_get_map_names_for_type struct_ops
600
+ ;;
601
+ esac
602
+ return 0
603
+ ;;
604
+ register)
605
+ _filedir
606
+ return 0
607
+ ;;
608
+ *)
609
+ [[ $prev == $object ]] && \
610
+ COMPREPLY=( $( compgen -W 'register unregister show list dump help' \
611
+ -- "$cur" ) )
612
+ ;;
613
+ esac
614
+ ;;
615
+ iter)
616
+ case $command in
617
+ pin)
618
+ case $prev in
619
+ $command)
620
+ _filedir
621
+ ;;
622
+ id)
623
+ _bpftool_get_map_ids
624
+ ;;
625
+ name)
626
+ _bpftool_get_map_names
627
+ ;;
628
+ pinned)
629
+ _filedir
630
+ ;;
631
+ *)
632
+ _bpftool_one_of_list $MAP_TYPE
633
+ ;;
634
+ esac
635
+ return 0
636
+ ;;
637
+ *)
638
+ [[ $prev == $object ]] && \
639
+ COMPREPLY=( $( compgen -W 'pin help' \
640
+ -- "$cur" ) )
352641 ;;
353642 esac
354643 ;;
355644 map)
356
- local MAP_TYPE='id pinned'
645
+ local MAP_TYPE='id pinned name'
357646 case $command in
358
- show|list|dump)
647
+ show|list|dump|peek|pop|dequeue|freeze)
359648 case $prev in
360649 $command)
361650 COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
362651 return 0
363652 ;;
364653 id)
365
- _bpftool_get_map_ids
654
+ case "$command" in
655
+ peek)
656
+ _bpftool_get_map_ids_for_type stack
657
+ _bpftool_get_map_ids_for_type queue
658
+ ;;
659
+ pop)
660
+ _bpftool_get_map_ids_for_type stack
661
+ ;;
662
+ dequeue)
663
+ _bpftool_get_map_ids_for_type queue
664
+ ;;
665
+ *)
666
+ _bpftool_get_map_ids
667
+ ;;
668
+ esac
669
+ return 0
670
+ ;;
671
+ name)
672
+ case "$command" in
673
+ peek)
674
+ _bpftool_get_map_names_for_type stack
675
+ _bpftool_get_map_names_for_type queue
676
+ ;;
677
+ pop)
678
+ _bpftool_get_map_names_for_type stack
679
+ ;;
680
+ dequeue)
681
+ _bpftool_get_map_names_for_type queue
682
+ ;;
683
+ *)
684
+ _bpftool_get_map_names
685
+ ;;
686
+ esac
366687 return 0
367688 ;;
368689 *)
690
+ return 0
691
+ ;;
692
+ esac
693
+ ;;
694
+ create)
695
+ case $prev in
696
+ $command)
697
+ _filedir
698
+ return 0
699
+ ;;
700
+ type)
701
+ COMPREPLY=( $( compgen -W 'hash array prog_array \
702
+ perf_event_array percpu_hash percpu_array \
703
+ stack_trace cgroup_array lru_hash \
704
+ lru_percpu_hash lpm_trie array_of_maps \
705
+ hash_of_maps devmap devmap_hash sockmap cpumap \
706
+ xskmap sockhash cgroup_storage reuseport_sockarray \
707
+ percpu_cgroup_storage queue stack sk_storage \
708
+ struct_ops inode_storage' -- \
709
+ "$cur" ) )
710
+ return 0
711
+ ;;
712
+ key|value|flags|entries)
713
+ return 0
714
+ ;;
715
+ inner_map)
716
+ COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
717
+ return 0
718
+ ;;
719
+ id)
720
+ _bpftool_get_map_ids
721
+ ;;
722
+ name)
723
+ case $pprev in
724
+ inner_map)
725
+ _bpftool_get_map_names
726
+ ;;
727
+ *)
728
+ return 0
729
+ ;;
730
+ esac
731
+ ;;
732
+ *)
733
+ _bpftool_once_attr 'type'
734
+ _bpftool_once_attr 'key'
735
+ _bpftool_once_attr 'value'
736
+ _bpftool_once_attr 'entries'
737
+ _bpftool_once_attr 'name'
738
+ _bpftool_once_attr 'flags'
739
+ if _bpftool_search_list 'array_of_maps' 'hash_of_maps'; then
740
+ _bpftool_once_attr 'inner_map'
741
+ fi
742
+ _bpftool_once_attr 'dev'
369743 return 0
370744 ;;
371745 esac
....@@ -380,23 +754,37 @@
380754 _bpftool_get_map_ids
381755 return 0
382756 ;;
757
+ name)
758
+ _bpftool_get_map_names
759
+ return 0
760
+ ;;
383761 key)
384762 COMPREPLY+=( $( compgen -W 'hex' -- "$cur" ) )
385763 ;;
386764 *)
765
+ case $(_bpftool_map_guess_map_type) in
766
+ queue|stack)
767
+ return 0
768
+ ;;
769
+ esac
770
+
387771 _bpftool_once_attr 'key'
388772 return 0
389773 ;;
390774 esac
391775 ;;
392
- update)
776
+ update|push|enqueue)
393777 case $prev in
394778 $command)
395779 COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
396780 return 0
397781 ;;
398782 id)
399
- _bpftool_map_update_get_id
783
+ _bpftool_map_update_get_id $command
784
+ return 0
785
+ ;;
786
+ name)
787
+ _bpftool_map_update_get_name $command
400788 return 0
401789 ;;
402790 key)
....@@ -405,15 +793,15 @@
405793 value)
406794 # We can have bytes, or references to a prog or a
407795 # map, depending on the type of the map to update.
408
- case $(_bpftool_map_update_map_type) in
796
+ case "$(_bpftool_map_guess_map_type)" in
409797 array_of_maps|hash_of_maps)
410
- local MAP_TYPE='id pinned'
798
+ local MAP_TYPE='id pinned name'
411799 COMPREPLY+=( $( compgen -W "$MAP_TYPE" \
412800 -- "$cur" ) )
413801 return 0
414802 ;;
415803 prog_array)
416
- local PROG_TYPE='id pinned tag'
804
+ local PROG_TYPE='id pinned tag name'
417805 COMPREPLY+=( $( compgen -W "$PROG_TYPE" \
418806 -- "$cur" ) )
419807 return 0
....@@ -427,6 +815,13 @@
427815 return 0
428816 ;;
429817 *)
818
+ case $(_bpftool_map_guess_map_type) in
819
+ queue|stack)
820
+ _bpftool_once_attr 'value'
821
+ return 0;
822
+ ;;
823
+ esac
824
+
430825 _bpftool_once_attr 'key'
431826 local UPDATE_FLAGS='any exist noexist'
432827 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
....@@ -445,16 +840,23 @@
445840 return 0
446841 fi
447842 done
843
+
448844 return 0
449845 ;;
450846 esac
451847 ;;
452848 pin)
453
- if [[ $prev == "$command" ]]; then
454
- COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
455
- else
456
- _filedir
457
- fi
849
+ case $prev in
850
+ $command)
851
+ COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
852
+ ;;
853
+ id)
854
+ _bpftool_get_map_ids
855
+ ;;
856
+ name)
857
+ _bpftool_get_map_names
858
+ ;;
859
+ esac
458860 return 0
459861 ;;
460862 event_pipe)
....@@ -464,7 +866,11 @@
464866 return 0
465867 ;;
466868 id)
467
- _bpftool_get_perf_map_ids
869
+ _bpftool_get_map_ids_for_type perf_event_array
870
+ return 0
871
+ ;;
872
+ name)
873
+ _bpftool_get_map_names_for_type perf_event_array
468874 return 0
469875 ;;
470876 cpu)
....@@ -483,35 +889,137 @@
483889 *)
484890 [[ $prev == $object ]] && \
485891 COMPREPLY=( $( compgen -W 'delete dump getnext help \
486
- lookup pin event_pipe show list update' -- \
892
+ lookup pin event_pipe show list update create \
893
+ peek push enqueue pop dequeue freeze' -- \
487894 "$cur" ) )
895
+ ;;
896
+ esac
897
+ ;;
898
+ btf)
899
+ local PROG_TYPE='id pinned tag name'
900
+ local MAP_TYPE='id pinned name'
901
+ case $command in
902
+ dump)
903
+ case $prev in
904
+ $command)
905
+ COMPREPLY+=( $( compgen -W "id map prog file" -- \
906
+ "$cur" ) )
907
+ return 0
908
+ ;;
909
+ prog)
910
+ COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
911
+ return 0
912
+ ;;
913
+ map)
914
+ COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
915
+ return 0
916
+ ;;
917
+ id)
918
+ case $pprev in
919
+ prog)
920
+ _bpftool_get_prog_ids
921
+ ;;
922
+ map)
923
+ _bpftool_get_map_ids
924
+ ;;
925
+ $command)
926
+ _bpftool_get_btf_ids
927
+ ;;
928
+ esac
929
+ return 0
930
+ ;;
931
+ name)
932
+ case $pprev in
933
+ prog)
934
+ _bpftool_get_prog_names
935
+ ;;
936
+ map)
937
+ _bpftool_get_map_names
938
+ ;;
939
+ esac
940
+ return 0
941
+ ;;
942
+ format)
943
+ COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) )
944
+ ;;
945
+ *)
946
+ # emit extra options
947
+ case ${words[3]} in
948
+ id|file)
949
+ _bpftool_once_attr 'format'
950
+ ;;
951
+ map|prog)
952
+ if [[ ${words[3]} == "map" ]] && [[ $cword == 6 ]]; then
953
+ COMPREPLY+=( $( compgen -W "key value kv all" -- "$cur" ) )
954
+ fi
955
+ _bpftool_once_attr 'format'
956
+ ;;
957
+ *)
958
+ ;;
959
+ esac
960
+ return 0
961
+ ;;
962
+ esac
963
+ ;;
964
+ show|list)
965
+ case $prev in
966
+ $command)
967
+ COMPREPLY+=( $( compgen -W "id" -- "$cur" ) )
968
+ ;;
969
+ id)
970
+ _bpftool_get_btf_ids
971
+ ;;
972
+ esac
973
+ return 0
974
+ ;;
975
+ *)
976
+ [[ $prev == $object ]] && \
977
+ COMPREPLY=( $( compgen -W 'dump help show list' \
978
+ -- "$cur" ) )
979
+ ;;
980
+ esac
981
+ ;;
982
+ gen)
983
+ case $command in
984
+ skeleton)
985
+ _filedir
986
+ ;;
987
+ *)
988
+ [[ $prev == $object ]] && \
989
+ COMPREPLY=( $( compgen -W 'skeleton help' -- "$cur" ) )
488990 ;;
489991 esac
490992 ;;
491993 cgroup)
492994 case $command in
493
- show|list)
494
- _filedir
995
+ show|list|tree)
996
+ case $cword in
997
+ 3)
998
+ _filedir
999
+ ;;
1000
+ 4)
1001
+ COMPREPLY=( $( compgen -W 'effective' -- "$cur" ) )
1002
+ ;;
1003
+ esac
4951004 return 0
4961005 ;;
497
- tree)
498
- _filedir
499
- return 0
500
- ;;
5011006 attach|detach)
5021007 local ATTACH_TYPES='ingress egress sock_create sock_ops \
503
- device bind4 bind6 post_bind4 post_bind6 connect4 \
504
- connect6 sendmsg4 sendmsg6'
1008
+ device bind4 bind6 post_bind4 post_bind6 connect4 connect6 \
1009
+ getpeername4 getpeername6 getsockname4 getsockname6 \
1010
+ sendmsg4 sendmsg6 recvmsg4 recvmsg6 sysctl getsockopt \
1011
+ setsockopt sock_release'
5051012 local ATTACH_FLAGS='multi override'
506
- local PROG_TYPE='id pinned tag'
1013
+ local PROG_TYPE='id pinned tag name'
5071014 case $prev in
5081015 $command)
5091016 _filedir
5101017 return 0
5111018 ;;
5121019 ingress|egress|sock_create|sock_ops|device|bind4|bind6|\
513
- post_bind4|post_bind6|connect4|connect6|sendmsg4|\
514
- sendmsg6)
1020
+ post_bind4|post_bind6|connect4|connect6|getpeername4|\
1021
+ getpeername6|getsockname4|getsockname6|sendmsg4|sendmsg6|\
1022
+ recvmsg4|recvmsg6|sysctl|getsockopt|setsockopt|sock_release)
5151023 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
5161024 "$cur" ) )
5171025 return 0
....@@ -527,7 +1035,7 @@
5271035 elif [[ "$command" == "attach" ]]; then
5281036 # We have an attach type on the command line,
5291037 # but it is not the previous word, or
530
- # "id|pinned|tag" (we already checked for
1038
+ # "id|pinned|tag|name" (we already checked for
5311039 # that). This should only leave the case when
5321040 # we need attach flags for "attach" commamnd.
5331041 _bpftool_one_of_list "$ATTACH_FLAGS"
....@@ -552,6 +1060,120 @@
5521060 ;;
5531061 esac
5541062 ;;
1063
+ net)
1064
+ local PROG_TYPE='id pinned tag name'
1065
+ local ATTACH_TYPES='xdp xdpgeneric xdpdrv xdpoffload'
1066
+ case $command in
1067
+ show|list)
1068
+ [[ $prev != "$command" ]] && return 0
1069
+ COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) )
1070
+ return 0
1071
+ ;;
1072
+ attach)
1073
+ case $cword in
1074
+ 3)
1075
+ COMPREPLY=( $( compgen -W "$ATTACH_TYPES" -- "$cur" ) )
1076
+ return 0
1077
+ ;;
1078
+ 4)
1079
+ COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
1080
+ return 0
1081
+ ;;
1082
+ 5)
1083
+ case $prev in
1084
+ id)
1085
+ _bpftool_get_prog_ids
1086
+ ;;
1087
+ name)
1088
+ _bpftool_get_prog_names
1089
+ ;;
1090
+ pinned)
1091
+ _filedir
1092
+ ;;
1093
+ esac
1094
+ return 0
1095
+ ;;
1096
+ 6)
1097
+ COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) )
1098
+ return 0
1099
+ ;;
1100
+ 8)
1101
+ _bpftool_once_attr 'overwrite'
1102
+ return 0
1103
+ ;;
1104
+ esac
1105
+ ;;
1106
+ detach)
1107
+ case $cword in
1108
+ 3)
1109
+ COMPREPLY=( $( compgen -W "$ATTACH_TYPES" -- "$cur" ) )
1110
+ return 0
1111
+ ;;
1112
+ 4)
1113
+ COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) )
1114
+ return 0
1115
+ ;;
1116
+ esac
1117
+ ;;
1118
+ *)
1119
+ [[ $prev == $object ]] && \
1120
+ COMPREPLY=( $( compgen -W 'help \
1121
+ show list attach detach' -- "$cur" ) )
1122
+ ;;
1123
+ esac
1124
+ ;;
1125
+ feature)
1126
+ case $command in
1127
+ probe)
1128
+ [[ $prev == "prefix" ]] && return 0
1129
+ if _bpftool_search_list 'macros'; then
1130
+ _bpftool_once_attr 'prefix'
1131
+ else
1132
+ COMPREPLY+=( $( compgen -W 'macros' -- "$cur" ) )
1133
+ fi
1134
+ _bpftool_one_of_list 'kernel dev'
1135
+ _bpftool_once_attr 'full unprivileged'
1136
+ return 0
1137
+ ;;
1138
+ *)
1139
+ [[ $prev == $object ]] && \
1140
+ COMPREPLY=( $( compgen -W 'help probe' -- "$cur" ) )
1141
+ ;;
1142
+ esac
1143
+ ;;
1144
+ link)
1145
+ case $command in
1146
+ show|list|pin|detach)
1147
+ case $prev in
1148
+ id)
1149
+ _bpftool_get_link_ids
1150
+ return 0
1151
+ ;;
1152
+ esac
1153
+ ;;
1154
+ esac
1155
+
1156
+ local LINK_TYPE='id pinned'
1157
+ case $command in
1158
+ show|list)
1159
+ [[ $prev != "$command" ]] && return 0
1160
+ COMPREPLY=( $( compgen -W "$LINK_TYPE" -- "$cur" ) )
1161
+ return 0
1162
+ ;;
1163
+ pin|detach)
1164
+ if [[ $prev == "$command" ]]; then
1165
+ COMPREPLY=( $( compgen -W "$LINK_TYPE" -- "$cur" ) )
1166
+ else
1167
+ _filedir
1168
+ fi
1169
+ return 0
1170
+ ;;
1171
+ *)
1172
+ [[ $prev == $object ]] && \
1173
+ COMPREPLY=( $( compgen -W 'help pin show list' -- "$cur" ) )
1174
+ ;;
1175
+ esac
1176
+ ;;
5551177 esac
5561178 } &&
5571179 complete -F _bpftool bpftool