aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2022-07-31 09:00:42 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2022-07-31 09:01:42 +0000
commit27f107e1b434aae073a0bffebdf426125e7d83aa (patch)
tree4baec357f75a4a1656cc8aefac3a7a3b1cc84a6f
parenta4181a3ec3ee1df198dd54383d96d02ba646c48d (diff)
downloadsrc-27f107e1b434aae073a0bffebdf426125e7d83aa.tar.gz
src-27f107e1b434aae073a0bffebdf426125e7d83aa.zip
routing: add debug printing helpers for rtentry and RTM* cmds.
MFC after: 2 weeks
-rw-r--r--sys/net/route/route_debug.h3
-rw-r--r--sys/net/route/route_helpers.c57
2 files changed, 60 insertions, 0 deletions
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");
+}