diff options
author | Nikolay Aleksandrov <nikolay@nvidia.com> | 2021-09-30 14:38:42 +0300 |
---|---|---|
committer | David Ahern <dsahern@kernel.org> | 2021-10-03 18:24:51 -0600 |
commit | cb3d18c29e20fa95bd98a614cc5a86f9a1336115 (patch) | |
tree | 541acf3e51c0e1ad939da348b23bcb7e1eb31ffa /ip/ipnexthop.c | |
parent | 60a97030328805101c469f05cad12c0b5b2b6a82 (diff) |
ip: nexthop: add a helper which retrieves and prints cached nh entry
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>
Diffstat (limited to 'ip/ipnexthop.c')
-rw-r--r-- | ip/ipnexthop.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index e0f0f784..31462c57 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -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); |