* [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features
@ 2017-02-07 13:50 Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 1/5] tc: bash-completion: Add the _from variant to _tc_one* funcs Yotam Gigi
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Yotam Gigi @ 2017-02-07 13:50 UTC (permalink / raw)
To: netdev, stephen, eladr, idosch, jiri, jhs, mrv; +Cc: Yotam Gigi
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next/iproute v2 1/5] tc: bash-completion: Add the _from variant to _tc_one* funcs
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
@ 2017-02-07 13:50 ` Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 2/5] tc: bash-completion: Prepare action autocomplete to support several actions Yotam Gigi
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yotam Gigi @ 2017-02-07 13:50 UTC (permalink / raw)
To: netdev, stephen, eladr, idosch, jiri, jhs, mrv; +Cc: Yotam Gigi
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 <yotamg@mellanox.com>
---
bash-completion/tc | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/bash-completion/tc b/bash-completion/tc
index ed2796d..04f969e 100644
--- a/bash-completion/tc
+++ b/bash-completion/tc
@@ -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()
{
--
2.4.11
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next/iproute v2 2/5] tc: bash-completion: Prepare action autocomplete to support several actions
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 1/5] tc: bash-completion: Add the _from variant to _tc_one* funcs Yotam Gigi
@ 2017-02-07 13:50 ` Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 3/5] tc: bash-completion: Make the *_KIND variables global Yotam Gigi
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yotam Gigi @ 2017-02-07 13:50 UTC (permalink / raw)
To: netdev, stephen, eladr, idosch, jiri, jhs, mrv; +Cc: Yotam Gigi
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 <yotamg@mellanox.com>
---
bash-completion/tc | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/bash-completion/tc b/bash-completion/tc
index 04f969e..c854dc0 100644
--- a/bash-completion/tc
+++ b/bash-completion/tc
@@ -454,26 +454,28 @@ _tc_filter_options()
# Returns 0 is completion should stop after running this function, 1 otherwise.
_tc_action_options()
{
- case $1 in
+ local from=$1
+ local action=${words[from]}
+ case $action in
bpf)
_tc_bpf_options
return 0
;;
mirred)
- _tc_one_of_list 'ingress egress'
- _tc_one_of_list 'mirror redirect'
- _tc_once_attr 'index dev'
+ _tc_one_of_list_from $from 'ingress egress'
+ _tc_one_of_list_from $from 'mirror redirect'
+ _tc_once_attr_from $from 'index dev'
return 0
;;
sample)
- _tc_once_attr 'rate'
- _tc_once_attr 'trunc'
- _tc_once_attr 'group'
+ _tc_once_attr_from $from 'rate'
+ _tc_once_attr_from $from 'trunc'
+ _tc_once_attr_from $from 'group'
return 0
;;
gact)
- _tc_one_of_list 'reclassify drop continue pass'
- _tc_once_attr 'random'
+ _tc_one_of_list_from $from 'reclassify drop continue pass'
+ _tc_once_attr_from $from 'random'
return 0
;;
esac
@@ -715,8 +717,7 @@ _tc()
local action acwd ACTION_KIND=' gact mirred bpf sample '
for ((acwd=$subcword; acwd < ${#words[@]}-1; acwd++)); do
if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then
- action=${words[acwd]}
- _tc_action_options $action && return 0
+ _tc_action_options $acwd && return 0
fi
done
_tc_one_of_list $ACTION_KIND
--
2.4.11
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next/iproute v2 3/5] tc: bash-completion: Make the *_KIND variables global
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 1/5] tc: bash-completion: Add the _from variant to _tc_one* funcs Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 2/5] tc: bash-completion: Prepare action autocomplete to support several actions Yotam Gigi
@ 2017-02-07 13:50 ` Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 4/5] tc: bash-completion: Add support for filter actions Yotam Gigi
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yotam Gigi @ 2017-02-07 13:50 UTC (permalink / raw)
To: netdev, stephen, eladr, idosch, jiri, jhs, mrv; +Cc: Yotam Gigi
The QDISC_KIND, FILTER_KIND, ACTION_KIND variables may be used by other
routines, thus make them global variables.
Signed-off-by: Yotam Gigi <yotamg@mellanox.com>
---
bash-completion/tc | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/bash-completion/tc b/bash-completion/tc
index c854dc0..e23f69c 100644
--- a/bash-completion/tc
+++ b/bash-completion/tc
@@ -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
--
2.4.11
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next/iproute v2 4/5] tc: bash-completion: Add support for filter actions
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
` (2 preceding siblings ...)
2017-02-07 13:50 ` [PATCH net-next/iproute v2 3/5] tc: bash-completion: Make the *_KIND variables global Yotam Gigi
@ 2017-02-07 13:50 ` Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 5/5] tc: bash-completion: Add support for matchall Yotam Gigi
2017-02-07 19:54 ` [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Stephen Hemminger
5 siblings, 0 replies; 7+ messages in thread
From: Yotam Gigi @ 2017-02-07 13:50 UTC (permalink / raw)
To: netdev, stephen, eladr, idosch, jiri, jhs, mrv; +Cc: Yotam Gigi
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 <yotamg@mellanox.com>
---
bash-completion/tc | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/bash-completion/tc b/bash-completion/tc
index e23f69c..e4c6804 100644
--- a/bash-completion/tc
+++ b/bash-completion/tc
@@ -386,11 +386,44 @@ _tc_bpf_options()
return 0
}
+# Complete with options names for filter actions.
+# This function is recursive, thus allowing multiple actions statement to be
+# parsed.
+# Returns 0 is completion should stop after running this function, 1 otherwise.
+_tc_filter_action_options()
+{
+ for ((acwd=$1; acwd < ${#words[@]}-1; acwd++));
+ do
+ if [[ action == ${words[acwd]} ]]; then
+ _tc_filter_action_options $((acwd+1)) && return 0
+ fi
+ done
+
+ local action acwd
+ for ((acwd=$1; acwd < ${#words[@]}-1; acwd++)); do
+ if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then
+ _tc_one_of_list_from $acwd action
+ _tc_action_options $acwd && return 0
+ fi
+ done
+ _tc_one_of_list_from $acwd $ACTION_KIND
+ return 0
+}
+
# Complete with options names for filters.
# Returns 0 is completion should stop after running this function, 1 otherwise.
_tc_filter_options()
{
- case $1 in
+
+ for ((acwd=$1; acwd < ${#words[@]}-1; acwd++));
+ do
+ if [[ action == ${words[acwd]} ]]; then
+ _tc_filter_action_options $((acwd+1)) && return 0
+ fi
+ done
+
+ filter=${words[$1]}
+ case $filter in
basic)
_tc_once_attr 'match action classid'
return 0
@@ -685,8 +718,7 @@ _tc()
for ((fltwd=$subcword; fltwd < ${#words[@]}-1; fltwd++));
do
if [[ $FILTER_KIND =~ ' '${words[fltwd]}' ' ]]; then
- filter=${words[fltwd]}
- _tc_filter_options $filter && return 0
+ _tc_filter_options $fltwd && return 0
fi
done
_tc_one_of_list $FILTER_KIND
--
2.4.11
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next/iproute v2 5/5] tc: bash-completion: Add support for matchall
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
` (3 preceding siblings ...)
2017-02-07 13:50 ` [PATCH net-next/iproute v2 4/5] tc: bash-completion: Add support for filter actions Yotam Gigi
@ 2017-02-07 13:50 ` Yotam Gigi
2017-02-07 19:54 ` [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Stephen Hemminger
5 siblings, 0 replies; 7+ messages in thread
From: Yotam Gigi @ 2017-02-07 13:50 UTC (permalink / raw)
To: netdev, stephen, eladr, idosch, jiri, jhs, mrv; +Cc: Yotam Gigi
Add support for the matchall classifier and its parameters.
Signed-off-by: Yotam Gigi <yotamg@mellanox.com>
---
bash-completion/tc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/bash-completion/tc b/bash-completion/tc
index e4c6804..80d1297 100644
--- a/bash-completion/tc
+++ b/bash-completion/tc
@@ -5,7 +5,7 @@
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 '
+FILTER_KIND=' basic bpf cgroup flow flower fw route rsvp tcindex u32 matchall '
ACTION_KIND=' gact mirred bpf sample '
# Takes a list of words in argument; each one of them is added to COMPREPLY if
@@ -449,6 +449,10 @@ _tc_filter_options()
_tc_once_attr 'map hash divisor baseclass match action'
return 0
;;
+ matchall)
+ _tc_once_attr 'action skip_sw skip_hw'
+ return 0
+ ;;
flower)
_tc_once_attr 'action classid indev dst_mac src_mac eth_type \
ip_proto dst_ip src_ip dst_port src_port'
--
2.4.11
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
` (4 preceding siblings ...)
2017-02-07 13:50 ` [PATCH net-next/iproute v2 5/5] tc: bash-completion: Add support for matchall Yotam Gigi
@ 2017-02-07 19:54 ` Stephen Hemminger
5 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2017-02-07 19:54 UTC (permalink / raw)
To: Yotam Gigi; +Cc: netdev, eladr, idosch, jiri, jhs, mrv
On Tue, 7 Feb 2017 15:50:47 +0200
Yotam Gigi <yotamg@mellanox.com> 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(-)
>
Applied to net-next
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-02-07 19:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-07 13:50 [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 1/5] tc: bash-completion: Add the _from variant to _tc_one* funcs Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 2/5] tc: bash-completion: Prepare action autocomplete to support several actions Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 3/5] tc: bash-completion: Make the *_KIND variables global Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 4/5] tc: bash-completion: Add support for filter actions Yotam Gigi
2017-02-07 13:50 ` [PATCH net-next/iproute v2 5/5] tc: bash-completion: Add support for matchall Yotam Gigi
2017-02-07 19:54 ` [PATCH net-next/iproute v2 0/5] tc: bash-completion: Add features Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).