The first 4 patches add support for autompletion of filter actions, thus
allowing the following tab completions:
$ tc filter add dev eth0 u32 [...] action <TAB>
bpf gact mirred sample
$ tc filter add dev eth0 u32 [...] action sample <TAB>
action group rate trunc
$ tc filter add dev eth0 u32 [...] \
action sample group 10 rate 10 action mirred <TAB>
action dev egress index ingress mirror redirect
Finally, the last patch adds support in matchall autocompletion.
v1->v2:
- Rebased on top of net-next tree
Yotam Gigi (5):
tc: bash-completion: Add the _from variant to _tc_one* funcs
tc: bash-completion: Prepare action autocomplete to support several
actions
tc: bash-completion: Make the *_KIND variables global
tc: bash-completion: Add support for filter actions
tc: bash-completion: Add support for matchall
bash-completion/tc | 121 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 96 insertions(+), 25 deletions(-)
--
2.4.11
The action autocomplete routine (_tc_action_options) currently does not
support several actions statements in one tc command line as it uses the
_tc_once_attr and _tc_one_from_list.
For example, in that case:
$ tc filter add dev eth0 handle ffff: u32 [...] \
action sample group 5 rate 12 \
action sample <TAB>
the _tc_once_attr function, when invoked with "group rate" will not
suggest those as they already exist on the command line.
Fix the function to use the _from variant, thus allowing each action
autocomplete start from the action keyword, and not from the beginning of
the command line.
Signed-off-by: Yotam Gigi <redacted>
---
bash-completion/tc | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
Previously, the autocomplete routine did not complete actions after a
filter keyword, for example:
$ tc filter add dev eth0 u32 [...] action <TAB>
did not suggest the actions list, and:
$ tc filter add dev eth0 u32 [...] action mirred <TAB>
did not suggest the specific mirred parameters. Add the support for this
kind of completion by adding the _tc_filter_action_options routine and
invoking it from inside _tc_filter_options.
Signed-off-by: Yotam Gigi <redacted>
---
bash-completion/tc | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
Add support for the matchall classifier and its parameters.
Signed-off-by: Yotam Gigi <redacted>
---
bash-completion/tc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
The QDISC_KIND, FILTER_KIND, ACTION_KIND variables may be used by other
routines, thus make them global variables.
Signed-off-by: Yotam Gigi <redacted>
---
bash-completion/tc | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
@@ -2,6 +2,12 @@ # Copyright 2016 6WIND S.A. # Copyright 2016 Quentin Monnet <quentin.monnet@6wind.com>+QDISC_KIND=' choke codel bfifo pfifo pfifo_head_drop fq fq_codel gred hhf \+ mqprio multiq netem pfifo_fast pie red rr sfb sfq tbf atm cbq drr \+ dsmark hfsc htb prio qfq '+FILTER_KIND=' basic bpf cgroup flow flower fw route rsvp tcindex u32 '+ACTION_KIND=' gact mirred bpf sample '+ # Takes a list of words in argument; each one of them is added to COMPREPLY if # it is not already present on the command line. Returns no value. _tc_once_attr()
@@ -605,10 +611,7 @@ _tc() COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) ) return 0 fi- local qdisc qdwd QDISC_KIND=' choke codel bfifo pfifo \- pfifo_head_drop fq fq_codel gred hhf mqprio multiq \- netem pfifo_fast pie red rr sfb sfq tbf atm cbq drr \- dsmark hfsc htb prio qfq '+ local qdisc qdwd for ((qdwd=$subcword; qdwd < ${#words[@]}-1; qdwd++)); do if [[ $QDISC_KIND =~ ' '${words[qdwd]}' ' ]]; then qdisc=${words[qdwd]}
@@ -643,10 +646,7 @@ _tc() COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) ) return 0 fi- local qdisc qdwd QDISC_KIND=' choke codel bfifo pfifo \- pfifo_head_drop fq fq_codel gred hhf mqprio multiq \- netem pfifo_fast pie red rr sfb sfq tbf atm cbq drr \- dsmark hfsc htb prio qfq '+ local qdisc qdwd for ((qdwd=$subcword; qdwd < ${#words[@]}-1; qdwd++)); do if [[ $QDISC_KIND =~ ' '${words[qdwd]}' ' ]]; then qdisc=${words[qdwd]}
@@ -681,8 +681,7 @@ _tc() COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) ) return 0 fi- local filter fltwd FILTER_KIND=' basic bpf cgroup flow \- flower fw route rsvp tcindex u32 '+ local filter fltwd for ((fltwd=$subcword; fltwd < ${#words[@]}-1; fltwd++)); do if [[ $FILTER_KIND =~ ' '${words[fltwd]}' ' ]]; then
@@ -714,7 +713,7 @@ _tc() action) case $subcmd in add|change|replace)- local action acwd ACTION_KIND=' gact mirred bpf sample '+ local action acwd for ((acwd=$subcword; acwd < ${#words[@]}-1; acwd++)); do if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then _tc_action_options $acwd && return 0
The _tc_one_of_list and _tc_once_attr functions simplfy the bash
completion task by validating each attr exist only once on the command
line.
For example, for the command line:
$ a b c d e
and the call to _tc_once_attr with "a f g", the function will suggest
"f g" as "a" existed in the command line in args 0.
Add the _from variant to those functions, which allows having the command
line option once from a specified index. In the previous example, calling
_tc_once_attr with 4 and "a f g" will suggest "a f g".
Signed-off-by: Yotam Gigi <redacted>
---
bash-completion/tc | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
@@ -20,6 +20,26 @@ _tc_once_attr() done }+# Takes a list of words in argument; each one of them is added to COMPREPLY if+# it is not already present on the command line from the provided index. Returns+# no value.+_tc_once_attr_from()+{+ local w subcword found from=$1+ shift+ for w in $*; do+ found=0+ for (( subcword=$from; subcword < ${#words[@]}-1; subcword++ )); do+ if [[ $w == ${words[subcword]} ]]; then+ found=1+ break+ fi+ done+ [[ $found -eq 0 ]] && \+ COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )+ done+}+ # Takes a list of words in argument; adds them all to COMPREPLY if none of them # is already present on the command line. Returns no value. _tc_one_of_list()
@@ -33,6 +53,21 @@ _tc_one_of_list() COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) ) }+# Takes a list of words in argument; adds them all to COMPREPLY if none of them+# is already present on the command line from the provided index. Returns no+# value.+_tc_one_of_list_from()+{+ local w subcword from=$1+ shift+ for w in $*; do+ for (( subcword=$from; subcword < ${#words[@]}-1; subcword++ )); do+ [[ $w == ${words[subcword]} ]] && return 1+ done+ done+ COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )+}+ # Returns "$cur ${cur}arg1 ${cur}arg2 ..." _tc_expand_units() {
From: Stephen Hemminger <stephen@networkplumber.org> Date: 2017-02-07 19:55:16
On Tue, 7 Feb 2017 15:50:47 +0200
Yotam Gigi [off-list ref] wrote:
The first 4 patches add support for autompletion of filter actions, thus
allowing the following tab completions:
$ tc filter add dev eth0 u32 [...] action <TAB>
bpf gact mirred sample
$ tc filter add dev eth0 u32 [...] action sample <TAB>
action group rate trunc
$ tc filter add dev eth0 u32 [...] \
action sample group 10 rate 10 action mirred <TAB>
action dev egress index ingress mirror redirect
Finally, the last patch adds support in matchall autocompletion.
v1->v2:
- Rebased on top of net-next tree
Yotam Gigi (5):
tc: bash-completion: Add the _from variant to _tc_one* funcs
tc: bash-completion: Prepare action autocomplete to support several
actions
tc: bash-completion: Make the *_KIND variables global
tc: bash-completion: Add support for filter actions
tc: bash-completion: Add support for matchall
bash-completion/tc | 121 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 96 insertions(+), 25 deletions(-)