routing: add debug printing helpers for rtentry and RTM* cmds.

MFC after:	2 weeks
This commit is contained in:
Alexander V. Chernikov 2022-07-31 09:00:42 +00:00
parent a4181a3ec3
commit 27f107e1b4
2 changed files with 60 additions and 0 deletions

View File

@ -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

View File

@ -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");
}