git: 1d5633bdb56f - stable/13 - routing: add debug printing helpers for rtentry and RTM* cmds.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Jan 2023 21:24:50 UTC
The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=1d5633bdb56fb98ce75c55ceb3dd5699be5da487 commit 1d5633bdb56fb98ce75c55ceb3dd5699be5da487 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2022-07-31 09:00:42 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-01-13 21:18:25 +0000 routing: add debug printing helpers for rtentry and RTM* cmds. MFC after: 2 weeks (cherry picked from commit 27f107e1b434aae073a0bffebdf426125e7d83aa) --- sys/net/route/route_debug.h | 3 +++ sys/net/route/route_helpers.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/sys/net/route/route_debug.h b/sys/net/route/route_debug.h index b2bb8426a816..30d2a1c9a99f 100644 --- a/sys/net/route/route_debug.h +++ b/sys/net/route/route_debug.h @@ -152,6 +152,7 @@ struct nhop_object; struct nhgrp_object; struct llentry; struct nhop_neigh; +struct rtentry; #define NHOP_PRINT_BUFSIZE 48 char *nhop_print_buf(const struct nhop_object *nh, char *buf, size_t bufsize); @@ -161,5 +162,7 @@ char *llentry_print_buf(const struct llentry *lle, struct ifnet *ifp, int family size_t bufsize); char *llentry_print_buf_lltable(const struct llentry *lle, char *buf, size_t bufsize); char *neigh_print_buf(const struct nhop_neigh *nn, char *buf, size_t bufsize); +char *rt_print_buf(const struct rtentry *rt, char *buf, size_t bufsize); +const char *rib_print_cmd(int rib_cmd); #endif diff --git a/sys/net/route/route_helpers.c b/sys/net/route/route_helpers.c index ff6688a8434f..001ebc5e388b 100644 --- a/sys/net/route/route_helpers.c +++ b/sys/net/route/route_helpers.c @@ -565,3 +565,60 @@ rt_get_inet6_parent(uint32_t fibnum, const struct in6_addr *paddr, int plen) return (NULL); } #endif + +/* + * Prints rtentry @rt data in the provided @buf. + * Example: rt/192.168.0.0/24 + */ +char * +rt_print_buf(const struct rtentry *rt, char *buf, size_t bufsize) +{ + char abuf[INET6_ADDRSTRLEN]; + uint32_t scopeid; + int plen; + + switch (rt_get_family(rt)) { +#ifdef INET + case AF_INET: + { + struct in_addr addr4; + rt_get_inet_prefix_plen(rt, &addr4, &plen, &scopeid); + inet_ntop(AF_INET, &addr4, abuf, sizeof(abuf)); + snprintf(buf, bufsize, "rt/%s/%d", abuf, plen); + } + break; +#endif +#ifdef INET6 + case AF_INET6: + { + struct in6_addr addr6; + rt_get_inet6_prefix_plen(rt, &addr6, &plen, &scopeid); + inet_ntop(AF_INET6, &addr6, abuf, sizeof(abuf)); + snprintf(buf, bufsize, "rt/%s/%d", abuf, plen); + } + break; +#endif + default: + snprintf(buf, bufsize, "rt/unknown_af#%d", rt_get_family(rt)); + break; + } + + return (buf); +} + +const char * +rib_print_cmd(int rib_cmd) +{ + switch (rib_cmd) { + case RTM_ADD: + return ("RTM_ADD"); + case RTM_CHANGE: + return ("RTM_CHANGE"); + case RTM_DELETE: + return ("RTM_DELETE"); + case RTM_GET: + return ("RTM_GET"); + } + + return ("UNKNOWN"); +}