diff mbox series

[RESEND,iproute2-next,2/2] tc: implement support for terse dump

Message ID 20200930073651.31247-3-vladbu@nvidia.com
State New
Headers show
Series Implement filter terse dump mode support | expand

Commit Message

Vlad Buslov Sept. 30, 2020, 7:36 a.m. UTC
From: Vlad Buslov <vladbu@mellanox.com>

Implement support for classifier/action terse dump using new TCA_DUMP_FLAGS
tlv with only available flag value TCA_DUMP_FLAGS_TERSE. Set the flag when
user requested it with following example CLI:

> tc -s filter show terse dev ens1f0 ingress

In terse mode dump only outputs essential data needed to identify the
filter and action (handle, cookie, etc.) and stats, if requested by the
user. The intention is to significantly improve rule dump rate by omitting
all static data that do not change after rule is created.

Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
---
 tc/tc_filter.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

David Ahern Sept. 30, 2020, 3:57 p.m. UTC | #1
On 9/30/20 12:36 AM, Vlad Buslov wrote:
> From: Vlad Buslov <vladbu@mellanox.com>
> 
> Implement support for classifier/action terse dump using new TCA_DUMP_FLAGS
> tlv with only available flag value TCA_DUMP_FLAGS_TERSE. Set the flag when
> user requested it with following example CLI:
> 
>> tc -s filter show terse dev ens1f0 ingress

this should be consistent with ip command which has -br for 'brief'
output. so this should be

   tc -s -br filter show dev ens1f0 ingress

Other tc maintainers should weigh in on what data should be presented
for this mode.


> 
> In terse mode dump only outputs essential data needed to identify the
> filter and action (handle, cookie, etc.) and stats, if requested by the
> user. The intention is to significantly improve rule dump rate by omitting
> all static data that do not change after rule is created.
> 
> Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
> Reviewed-by: Jiri Pirko <jiri@mellanox.com>
> ---
>  tc/tc_filter.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/tc/tc_filter.c b/tc/tc_filter.c
> index c591a19f3123..6a82f9bb42fb 100644
> --- a/tc/tc_filter.c
> +++ b/tc/tc_filter.c
> @@ -595,6 +595,7 @@ static int tc_filter_list(int cmd, int argc, char **argv)
>  		.t.tcm_parent = TC_H_UNSPEC,
>  		.t.tcm_family = AF_UNSPEC,
>  	};
> +	bool terse_dump = false;
>  	char d[IFNAMSIZ] = {};
>  	__u32 prio = 0;
>  	__u32 protocol = 0;
> @@ -687,6 +688,8 @@ static int tc_filter_list(int cmd, int argc, char **argv)
>  				invarg("invalid chain index value", *argv);
>  			filter_chain_index_set = 1;
>  			filter_chain_index = chain_index;
> +		} else if (matches(*argv, "terse") == 0) {
> +			terse_dump = true;
>  		} else if (matches(*argv, "help") == 0) {
>  			usage();
>  		} else {
> @@ -721,6 +724,15 @@ static int tc_filter_list(int cmd, int argc, char **argv)
>  	if (filter_chain_index_set)
>  		addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
>  
> +	if (terse_dump) {
> +		struct nla_bitfield32 flags = {
> +			.value = TCA_DUMP_FLAGS_TERSE,
> +			.selector = TCA_DUMP_FLAGS_TERSE
> +		};
> +
> +		addattr_l(&req.n, MAX_MSG, TCA_DUMP_FLAGS, &flags, sizeof(flags));
> +	}
> +
>  	if (rtnl_dump_request_n(&rth, &req.n) < 0) {
>  		perror("Cannot send dump request");
>  		return 1;
>
Vlad Buslov Sept. 30, 2020, 5:02 p.m. UTC | #2
On Wed 30 Sep 2020 at 18:57, David Ahern <dsahern@gmail.com> wrote:
> On 9/30/20 12:36 AM, Vlad Buslov wrote:
>> From: Vlad Buslov <vladbu@mellanox.com>
>> 
>> Implement support for classifier/action terse dump using new TCA_DUMP_FLAGS
>> tlv with only available flag value TCA_DUMP_FLAGS_TERSE. Set the flag when
>> user requested it with following example CLI:
>> 
>>> tc -s filter show terse dev ens1f0 ingress
>
> this should be consistent with ip command which has -br for 'brief'
> output. so this should be
>
>    tc -s -br filter show dev ens1f0 ingress
>
> Other tc maintainers should weigh in on what data should be presented
> for this mode.

Thanks for the feedback, David! I've just sent V2 with -br option.

[...]
Stephen Hemminger Sept. 30, 2020, 5:33 p.m. UTC | #3
On Wed, 30 Sep 2020 08:57:20 -0700
David Ahern <dsahern@gmail.com> wrote:

> On 9/30/20 12:36 AM, Vlad Buslov wrote:
> > From: Vlad Buslov <vladbu@mellanox.com>
> > 
> > Implement support for classifier/action terse dump using new TCA_DUMP_FLAGS
> > tlv with only available flag value TCA_DUMP_FLAGS_TERSE. Set the flag when
> > user requested it with following example CLI:
> >   
> >> tc -s filter show terse dev ens1f0 ingress  
> 
> this should be consistent with ip command which has -br for 'brief'
> output. so this should be
> 
>    tc -s -br filter show dev ens1f0 ingress
> 
> Other tc maintainers should weigh in on what data should be presented
> for this mode.

Current ip brief mode is good, one line per interface. Something similar with tc
would be best.
Vlad Buslov Sept. 30, 2020, 8:11 p.m. UTC | #4
On Wed 30 Sep 2020 at 20:33, Stephen Hemminger <stephen@networkplumber.org> wrote:
> On Wed, 30 Sep 2020 08:57:20 -0700
> David Ahern <dsahern@gmail.com> wrote:
>
>> On 9/30/20 12:36 AM, Vlad Buslov wrote:
>> > From: Vlad Buslov <vladbu@mellanox.com>
>> > 
>> > Implement support for classifier/action terse dump using new TCA_DUMP_FLAGS
>> > tlv with only available flag value TCA_DUMP_FLAGS_TERSE. Set the flag when
>> > user requested it with following example CLI:
>> >   
>> >> tc -s filter show terse dev ens1f0 ingress  
>> 
>> this should be consistent with ip command which has -br for 'brief'
>> output. so this should be
>> 
>>    tc -s -br filter show dev ens1f0 ingress
>> 
>> Other tc maintainers should weigh in on what data should be presented
>> for this mode.
>
> Current ip brief mode is good, one line per interface. Something similar with tc
> would be best.

Hi Stephen,

My proposed implementation is very simple because it relies on existing
infrastructure that omits printing data that is not included in the
netlink packet. Making terse/brief dump output one line per filter would
require extending every single classifier with either standalone
callback for such print or dedicated block in existing print_op().
Moreover, it would be complicated for me to decide what should be
included in such output for many classifiers that I don't have
experience using.

Do you think complicating implementation like that is worth it?

Regards,
Vlad
diff mbox series

Patch

diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index c591a19f3123..6a82f9bb42fb 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -595,6 +595,7 @@  static int tc_filter_list(int cmd, int argc, char **argv)
 		.t.tcm_parent = TC_H_UNSPEC,
 		.t.tcm_family = AF_UNSPEC,
 	};
+	bool terse_dump = false;
 	char d[IFNAMSIZ] = {};
 	__u32 prio = 0;
 	__u32 protocol = 0;
@@ -687,6 +688,8 @@  static int tc_filter_list(int cmd, int argc, char **argv)
 				invarg("invalid chain index value", *argv);
 			filter_chain_index_set = 1;
 			filter_chain_index = chain_index;
+		} else if (matches(*argv, "terse") == 0) {
+			terse_dump = true;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
@@ -721,6 +724,15 @@  static int tc_filter_list(int cmd, int argc, char **argv)
 	if (filter_chain_index_set)
 		addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
 
+	if (terse_dump) {
+		struct nla_bitfield32 flags = {
+			.value = TCA_DUMP_FLAGS_TERSE,
+			.selector = TCA_DUMP_FLAGS_TERSE
+		};
+
+		addattr_l(&req.n, MAX_MSG, TCA_DUMP_FLAGS, &flags, sizeof(flags));
+	}
+
 	if (rtnl_dump_request_n(&rth, &req.n) < 0) {
 		perror("Cannot send dump request");
 		return 1;