All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: roopa@nvidia.com, donaldsharp72@gmail.com, dsahern@gmail.com,
	idosch@idosch.org, Nikolay Aleksandrov <nikolay@nvidia.com>
Subject: [PATCH iproute2-next 04/12] ip: nexthop: split print_nh_res_group into parse and print parts
Date: Thu, 30 Sep 2021 14:38:36 +0300	[thread overview]
Message-ID: <20210930113844.1829373-5-razor@blackwall.org> (raw)
In-Reply-To: <20210930113844.1829373-1-razor@blackwall.org>

From: Nikolay Aleksandrov <nikolay@nvidia.com>

Now that we have resilient group structure split print_nh_res_group into
a parse and print functions, print_nexthop calls the parse function
first to parse the attributes into the structure and then uses the print
function to print the parsed structure.

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
 ip/ipnexthop.c | 48 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index a4048d803325..7094d6cbb5e6 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -13,6 +13,7 @@
 
 #include "utils.h"
 #include "ip_common.h"
+#include "nh_common.h"
 
 static struct {
 	unsigned int flushed;
@@ -264,39 +265,50 @@ static void print_nh_group_type(FILE *fp, const struct rtattr *grp_type_attr)
 	print_string(PRINT_ANY, "type", "type %s ", nh_group_type_name(type));
 }
 
-static void print_nh_res_group(FILE *fp, const struct rtattr *res_grp_attr)
+static void parse_nh_res_group_rta(const struct rtattr *res_grp_attr,
+				   struct nha_res_grp *res_grp)
 {
 	struct rtattr *tb[NHA_RES_GROUP_MAX + 1];
 	struct rtattr *rta;
-	struct timeval tv;
 
+	memset(res_grp, 0, sizeof(*res_grp));
 	parse_rtattr_nested(tb, NHA_RES_GROUP_MAX, res_grp_attr);
 
-	open_json_object("resilient_args");
-
 	if (tb[NHA_RES_GROUP_BUCKETS])
-		print_uint(PRINT_ANY, "buckets", "buckets %u ",
-			   rta_getattr_u16(tb[NHA_RES_GROUP_BUCKETS]));
+		res_grp->buckets = rta_getattr_u16(tb[NHA_RES_GROUP_BUCKETS]);
 
 	if (tb[NHA_RES_GROUP_IDLE_TIMER]) {
 		rta = tb[NHA_RES_GROUP_IDLE_TIMER];
-		__jiffies_to_tv(&tv, rta_getattr_u32(rta));
-		print_tv(PRINT_ANY, "idle_timer", "idle_timer %g ", &tv);
+		res_grp->idle_timer = rta_getattr_u32(rta);
 	}
 
 	if (tb[NHA_RES_GROUP_UNBALANCED_TIMER]) {
 		rta = tb[NHA_RES_GROUP_UNBALANCED_TIMER];
-		__jiffies_to_tv(&tv, rta_getattr_u32(rta));
-		print_tv(PRINT_ANY, "unbalanced_timer", "unbalanced_timer %g ",
-			 &tv);
+		res_grp->unbalanced_timer = rta_getattr_u32(rta);
 	}
 
 	if (tb[NHA_RES_GROUP_UNBALANCED_TIME]) {
 		rta = tb[NHA_RES_GROUP_UNBALANCED_TIME];
-		__jiffies_to_tv(&tv, rta_getattr_u32(rta));
-		print_tv(PRINT_ANY, "unbalanced_time", "unbalanced_time %g ",
-			 &tv);
+		res_grp->unbalanced_time = rta_getattr_u64(rta);
 	}
+}
+
+static void print_nh_res_group(const struct nha_res_grp *res_grp)
+{
+	struct timeval tv;
+
+	open_json_object("resilient_args");
+
+	print_uint(PRINT_ANY, "buckets", "buckets %u ", res_grp->buckets);
+
+	 __jiffies_to_tv(&tv, res_grp->idle_timer);
+	print_tv(PRINT_ANY, "idle_timer", "idle_timer %g ", &tv);
+
+	__jiffies_to_tv(&tv, res_grp->unbalanced_timer);
+	print_tv(PRINT_ANY, "unbalanced_timer", "unbalanced_timer %g ", &tv);
+
+	__jiffies_to_tv(&tv, res_grp->unbalanced_time);
+	print_tv(PRINT_ANY, "unbalanced_time", "unbalanced_time %g ", &tv);
 
 	close_json_object();
 }
@@ -371,8 +383,12 @@ int print_nexthop(struct nlmsghdr *n, void *arg)
 	if (tb[NHA_GROUP_TYPE])
 		print_nh_group_type(fp, tb[NHA_GROUP_TYPE]);
 
-	if (tb[NHA_RES_GROUP])
-		print_nh_res_group(fp, tb[NHA_RES_GROUP]);
+	if (tb[NHA_RES_GROUP]) {
+		struct nha_res_grp res_grp;
+
+		parse_nh_res_group_rta(tb[NHA_RES_GROUP], &res_grp);
+		print_nh_res_group(&res_grp);
+	}
 
 	if (tb[NHA_ENCAP])
 		lwt_print_encap(fp, tb[NHA_ENCAP_TYPE], tb[NHA_ENCAP]);
-- 
2.31.1


  parent reply	other threads:[~2021-09-30 11:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 11:38 [PATCH iproute2-next 00/12] ip: nexthop: cache nexthops and print routes' nh info Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 01/12] ip: print_rta_if takes ifindex as device argument instead of attribute Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 02/12] ip: export print_rta_gateway version which outputs prepared gateway string Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 03/12] ip: nexthop: add resilient group structure Nikolay Aleksandrov
2021-09-30 11:38 ` Nikolay Aleksandrov [this message]
2021-09-30 11:38 ` [PATCH iproute2-next 05/12] ip: nexthop: add nh entry structure Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 06/12] ip: nexthop: parse attributes into nh entry structure before printing Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 07/12] ip: nexthop: factor out print_nexthop's nh entry printing Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 08/12] ip: nexthop: factor out ipnh_get_id rtnl talk into a helper Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 09/12] ip: nexthop: add cache helpers Nikolay Aleksandrov
2021-10-04  0:33   ` David Ahern
2021-10-04  9:03     ` [PATCH iproute2-next] ip: nexthop: keep cache netlink socket open Nikolay Aleksandrov
2021-10-05 14:35       ` David Ahern
2021-09-30 11:38 ` [PATCH iproute2-next 10/12] ip: nexthop: add a helper which retrieves and prints cached nh entry Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 11/12] ip: route: print and cache detailed nexthop information when requested Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 12/12] ip: nexthop: add print_cache_nexthop which prints and manages the nh cache Nikolay Aleksandrov
2021-10-04  0:40 ` [PATCH iproute2-next 00/12] ip: nexthop: cache nexthops and print routes' nh info patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210930113844.1829373-5-razor@blackwall.org \
    --to=razor@blackwall.org \
    --cc=donaldsharp72@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=idosch@idosch.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@nvidia.com \
    --cc=roopa@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.