]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: nexthop: add a helper which retrieves and prints cached nh entry
authorNikolay Aleksandrov <nikolay@nvidia.com>
Thu, 30 Sep 2021 11:38:42 +0000 (14:38 +0300)
committerDavid Ahern <dsahern@kernel.org>
Mon, 4 Oct 2021 00:24:51 +0000 (18:24 -0600)
Add a helper which looks for a nexthop in the cache and if not found
reads the entry from the kernel and caches it. Finally the entry is
printed.

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipnexthop.c
ip/nh_common.h

index e0f0f78460c9a2a2454e4266afb0e229e81946d0..31462c57d29910da845a6f5403d4dbb05fe70385 100644 (file)
@@ -602,6 +602,22 @@ static void ipnh_cache_del(struct nh_entry *nhe)
        free(nhe);
 }
 
+void print_cache_nexthop_id(FILE *fp, const char *fp_prefix, const char *jsobj,
+                           __u32 nh_id)
+{
+       struct nh_entry *nhe = ipnh_cache_get(nh_id);
+
+       if (!nhe) {
+               nhe = ipnh_cache_add(nh_id);
+               if (!nhe)
+                       return;
+       }
+
+       if (fp_prefix)
+               print_string(PRINT_FP, NULL, "%s", fp_prefix);
+       __print_nexthop_entry(fp, jsobj, nhe, false);
+}
+
 int print_nexthop(struct nlmsghdr *n, void *arg)
 {
        struct nhmsg *nhm = NLMSG_DATA(n);
index ee84d968d8dd605c522ec594e8736248bb0c60fc..b448f1b5530bf418801ef92d3936c87e267fbd04 100644 (file)
@@ -46,4 +46,7 @@ struct nh_entry {
        struct nexthop_grp      *nh_groups;
 };
 
+void print_cache_nexthop_id(FILE *fp, const char *fp_prefix, const char *jsobj,
+                           __u32 nh_id);
+
 #endif /* __NH_COMMON_H__ */