[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210415142311.4e43a637@hermes.local>
Date: Thu, 15 Apr 2021 14:23:11 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: Paolo Lungaroni <paolo.lungaroni@...roma2.it>
Cc: David Ahern <dsahern@...nel.org>, netdev@...r.kernel.org,
Jakub Kicinski <kuba@...nel.org>,
Stefano Salsano <stefano.salsano@...roma2.it>,
Ahmed Abdelsalam <ahabdels.dev@...il.com>,
Andrea Mayer <andrea.mayer@...roma2.it>
Subject: Re: [RFC iproute2-next v2] seg6: add counters support for SRv6
Behaviors
On Thu, 15 Apr 2021 20:06:43 +0200
Paolo Lungaroni <paolo.lungaroni@...roma2.it> wrote:
> + if (is_json_context())
> + open_json_object("stats64");
> +
> + if (tb[SEG6_LOCAL_CNT_PACKETS]) {
> + packets = rta_getattr_u64(tb[SEG6_LOCAL_CNT_PACKETS]);
> + if (is_json_context()) {
> + print_u64(PRINT_JSON, "packets", NULL, packets);
> + } else {
> + print_string(PRINT_FP, NULL, "%s ", "packets");
> + print_num(fp, 1, packets);
> + }
> + }
> +
> + if (tb[SEG6_LOCAL_CNT_BYTES]) {
> + bytes = rta_getattr_u64(tb[SEG6_LOCAL_CNT_BYTES]);
> + if (is_json_context()) {
> + print_u64(PRINT_JSON, "bytes", NULL, bytes);
> + } else {
> + print_string(PRINT_FP, NULL, "%s ", "bytes");
> + print_num(fp, 1, bytes);
> + }
> + }
> +
> + if (tb[SEG6_LOCAL_CNT_ERRORS]) {
> + errors = rta_getattr_u64(tb[SEG6_LOCAL_CNT_ERRORS]);
> + if (is_json_context()) {
> + print_u64(PRINT_JSON, "errors", NULL, errors);
> + } else {
> + print_string(PRINT_FP, NULL, "%s ", "errors");
> + print_num(fp, 1, errors);
> + }
> + }
> +
> + if (is_json_context())
> + close_json_object();
The code would be cleaner with doing if (is_json_context()) once at outer loop.
See print_vf_stats64.
Powered by blists - more mailing lists