From d06d27a760a60fa720f760cd1c42247d24874d5f Mon Sep 17 00:00:00 2001 From: bluhm Date: Thu, 28 Jul 2022 22:19:09 +0000 Subject: [PATCH] In the kernel exist functions to print routes, but they were not accessible from ddb. Implement "show all routes" to print routing tables, and "show route 0xfffffd807e9b0000" for a single route entry. Note that the rtable id is not part of a route entry, so it makes no sense to print it there. OK deraadt@ --- share/man/man4/ddb.4 | 30 ++++++++++++++++++++++++++++-- sys/ddb/db_command.c | 29 ++++++++++++++++++++++++++++- sys/ddb/db_interface.h | 6 +++++- sys/net/route.c | 25 +++++++++++-------------- 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4 index 5f8a27db355..52decfcd4a6 100644 --- a/share/man/man4/ddb.4 +++ b/share/man/man4/ddb.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ddb.4,v 1.101 2022/03/31 17:27:20 naddy Exp $ +.\" $OpenBSD: ddb.4,v 1.102 2022/07/28 22:19:09 bluhm Exp $ .\" $NetBSD: ddb.4,v 1.5 1994/11/30 16:22:09 jtc Exp $ .\" .\" Mach Operating System @@ -25,7 +25,7 @@ .\" any improvements or extensions that they make and grant Carnegie Mellon .\" the rights to redistribute these changes. .\" -.Dd $Mdocdate: March 31 2022 $ +.Dd $Mdocdate: July 28 2022 $ .Dt DDB 4 .Os .Sh NAME @@ -791,6 +791,12 @@ Note: The modifier is not supported on every machine, in which case incorrect information may be displayed. .\" -------------------- +.It Ic show route Ar addr +Prints the +.Li struct rtentry +at +.Ar addr . +.\" -------------------- .It Ic show socket Ar addr Prints the .Li struct socket @@ -954,6 +960,26 @@ See the command for more information. .El .\" -------------------- +.It Xo +.Ic show all routes +.Op Cm /iI +.Op Ar rtableid +.Op Ic \&, Ns Ar count +.Xc +Show internet routing tables. +Default for +.Ar rtableid +is 0 and +.Ar count +is 1. +.Pp +.Bl -tag -width foo -compact +.It Cm /i +Restrict to AF_INET. +.It Cm /I +Restrict to AF_INET6. +.El +.\" -------------------- .It Ic show all tdbs Op Cm /f Display information about all IPsec SAs in the system. .Pp diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index d6e5a20fc16..8f560afbd7d 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_command.c,v 1.94 2022/04/14 19:47:12 naddy Exp $ */ +/* $OpenBSD: db_command.c,v 1.95 2022/07/28 22:19:09 bluhm Exp $ */ /* $NetBSD: db_command.c,v 1.20 1996/03/30 22:30:05 christos Exp $ */ /* @@ -418,6 +418,31 @@ db_show_all_tdbs(db_expr_t addr, int have_addr, db_expr_t count, char *modif) } #endif +void +db_show_all_routes(db_expr_t addr, int have_addr, db_expr_t count, char *modif) +{ + u_int rtableid = 0; + + if (have_addr) + rtableid = addr; + if (count == -1) + count = 1; + + while (count--) { + if (modif[0] != 'I') + db_show_rtable(AF_INET, rtableid); + if (modif[0] != 'i') + db_show_rtable(AF_INET6, rtableid); + rtableid++; + } +} + +void +db_show_route(db_expr_t addr, int have_addr, db_expr_t count, char *modif) +{ + db_show_rtentry((void *)addr, NULL, -1); +} + /*ARGSUSED*/ void db_object_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif) @@ -568,6 +593,7 @@ const struct db_command db_show_all_cmds[] = { { "mounts", db_show_all_mounts, 0, NULL }, { "vnodes", db_show_all_vnodes, 0, NULL }, { "bufs", db_show_all_bufs, 0, NULL }, + { "routes", db_show_all_routes, 0, NULL }, #ifdef NFSCLIENT { "nfsreqs", db_show_all_nfsreqs, 0, NULL }, { "nfsnodes", db_show_all_nfsnodes, 0, NULL }, @@ -604,6 +630,7 @@ const struct db_command db_show_cmds[] = { { "pool", db_pool_print_cmd, 0, NULL }, { "proc", db_proc_print_cmd, 0, NULL }, { "registers", db_show_regs, 0, NULL }, + { "route", db_show_route, 0, NULL }, { "socket", db_socket_print_cmd, 0, NULL }, { "struct", db_ctf_show_struct, CS_OWN, NULL }, #ifdef IPSEC diff --git a/sys/ddb/db_interface.h b/sys/ddb/db_interface.h index d290d35d813..e66dc8c9eda 100644 --- a/sys/ddb/db_interface.h +++ b/sys/ddb/db_interface.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.h,v 1.22 2019/11/07 13:16:25 mpi Exp $ */ +/* $OpenBSD: db_interface.h,v 1.23 2022/07/28 22:19:09 bluhm Exp $ */ /* $NetBSD: db_interface.h,v 1.1 1996/02/05 01:57:03 christos Exp $ */ /* @@ -62,6 +62,10 @@ void m_print(void *, int (*)(const char *, ...)); /* kern/uipc_socket.c */ void so_print(void *, int (*)(const char *, ...)); +struct rtentry; +int db_show_rtentry(struct rtentry *, void *, unsigned int); +int db_show_rtable(int, unsigned int); + /* nfs/nfs_debug.c */ void db_show_all_nfsreqs(db_expr_t, int, db_expr_t, char *); void nfs_request_print(void *, int, int (*)(const char *, ...)); diff --git a/sys/net/route.c b/sys/net/route.c index bafadfd9e7c..7d1aeeca26a 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.412 2022/06/28 10:01:13 bluhm Exp $ */ +/* $OpenBSD: route.c,v 1.413 2022/07/28 22:19:09 bluhm Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -161,12 +161,6 @@ int rt_clone(struct rtentry **, struct sockaddr *, unsigned int); struct sockaddr *rt_plentosa(sa_family_t, int, struct sockaddr_in6 *); static int rt_copysa(struct sockaddr *, struct sockaddr *, struct sockaddr **); -#ifdef DDB -void db_print_sa(struct sockaddr *); -void db_print_ifa(struct ifaddr *); -int db_show_rtentry(struct rtentry *, void *, unsigned int); -#endif - #define LABELID_MAX 50000 struct rt_label { @@ -1825,6 +1819,9 @@ rt_plen2mask(struct rtentry *rt, struct sockaddr_in6 *sa_mask) #include #include +void db_print_sa(struct sockaddr *); +void db_print_ifa(struct ifaddr *); + void db_print_sa(struct sockaddr *sa) { @@ -1873,8 +1870,8 @@ db_show_rtentry(struct rtentry *rt, void *w, unsigned int id) { db_printf("rtentry=%p", rt); - db_printf(" flags=0x%x refcnt=%u use=%llu expire=%lld rtableid=%u\n", - rt->rt_flags, rt->rt_refcnt.r_refs, rt->rt_use, rt->rt_expire, id); + db_printf(" flags=0x%x refcnt=%u use=%llu expire=%lld\n", + rt->rt_flags, rt->rt_refcnt.r_refs, rt->rt_use, rt->rt_expire); db_printf(" key="); db_print_sa(rt_key(rt)); db_printf(" plen=%d", rt_plen(rt)); @@ -1883,19 +1880,19 @@ db_show_rtentry(struct rtentry *rt, void *w, unsigned int id) db_printf(" ifa=%p\n", rt->rt_ifa); db_print_ifa(rt->rt_ifa); - db_printf(" gwroute=%p llinfo=%p\n", rt->rt_gwroute, rt->rt_llinfo); + db_printf(" gwroute=%p llinfo=%p priority=%d\n", + rt->rt_gwroute, rt->rt_llinfo, rt->rt_priority); return (0); } /* * Function to print all the route trees. - * Use this from ddb: "call db_show_arptab" */ int -db_show_arptab(void) +db_show_rtable(int af, unsigned int rtableid) { - db_printf("Route tree for AF_INET\n"); - rtable_walk(0, AF_INET, NULL, db_show_rtentry, NULL); + db_printf("Route tree for af %d, rtableid %u\n", af, rtableid); + rtable_walk(rtableid, af, NULL, db_show_rtentry, NULL); return (0); } #endif /* DDB */ -- 2.20.1