commit c9c021cd85516e17a640a8475007368b66b44b1c Author: Ryota Ozaki Date: Wed Mar 30 19:49:58 2016 +0900 Move db_show_arptab from if_arp.c to route.c with renamed to db_show_routes diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4 index 2d18af0..b52127d 100644 --- a/share/man/man4/ddb.4 +++ b/share/man/man4/ddb.4 @@ -56,7 +56,7 @@ .\" any improvements or extensions that they make and grant Carnegie Mellon .\" the rights to redistribute these changes. .\" -.Dd November 13, 2015 +.Dd April 12, 2016 .Dt DDB 4 .Os .Sh NAME @@ -602,11 +602,11 @@ LWP name and wait channel message. LWPs currently running on a CPU are marked with the '\&>' sign. This is the default. .El -.It Ic show arptab +.It Ic show routes Dump the entire .Dv AF_INET routing table. -This command is available only on systems which support inet and ARP. +This command is available only on systems which support inet. .It Ic show breaks Display all breakpoints. .It Ic show buf Ns Oo Cm /f Oc Ar address diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index a2101d0..5004f98 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -71,7 +71,6 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.146 2016/04/06 21:56:24 skrll Exp $ #include "opt_kernhist.h" #include "opt_ddbparam.h" #include "opt_multiprocessor.h" -#include "arp.h" #endif #include @@ -99,6 +98,8 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.146 2016/04/06 21:56:24 skrll Exp $ #include #include +#include + /* * Results of command search. */ @@ -229,8 +230,8 @@ static const struct db_command db_show_cmds[] = { #endif { DDB_ADD_CMD("all", NULL, CS_COMPAT, NULL,NULL,NULL) }, -#if defined(INET) && (NARP > 0) - { DDB_ADD_CMD("arptab", db_show_arptab, 0,NULL,NULL,NULL) }, +#if defined(INET) + { DDB_ADD_CMD("routes", db_show_routes, 0,NULL,NULL,NULL) }, #endif #ifdef _KERNEL { DDB_ADD_CMD("breaks", db_listbreak_cmd, 0, diff --git a/sys/ddb/db_interface.h b/sys/ddb/db_interface.h index 61ff018..482b756 100644 --- a/sys/ddb/db_interface.h +++ b/sys/ddb/db_interface.h @@ -58,8 +58,8 @@ void db_show_callout(db_expr_t, bool, db_expr_t, const char *); /* kern/subr_log.c */ void db_dmesg(db_expr_t, bool, db_expr_t, const char *); -/* netinet/if_arp.c */ -void db_show_arptab(db_expr_t, bool, db_expr_t, const char *); +/* net/route.c */ +void db_show_routes(db_expr_t, bool, db_expr_t, const char *); /* kern/vfs_aio.c */ void db_show_aio_jobs(db_expr_t, bool, db_expr_t, const char *); diff --git a/sys/net/route.c b/sys/net/route.c index 708d5d5..e110be3 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -152,6 +152,12 @@ static void rt_maskedcopy(const struct sockaddr *, static void rtcache_clear(struct route *); static void rtcache_invalidate(struct dom_rtlist *); +#ifdef DDB +static void db_print_sa(const struct sockaddr *); +static void db_print_ifa(struct ifaddr *); +static int db_show_rtentry(struct rtentry *, void *); +#endif + #ifdef RTFLUSH_DEBUG static void sysctl_net_rtcache_setup(struct sysctllog **); static void @@ -1493,3 +1499,94 @@ rt_gettag(struct rtentry *rt) { return rt->rt_tag; } + +#ifdef DDB + +#include +#include +#include + +#define rt_expire rt_rmx.rmx_expire + +static void +db_print_sa(const struct sockaddr *sa) +{ + int len; + const u_char *p; + + if (sa == NULL) { + db_printf("[NULL]"); + return; + } + + p = (const u_char *)sa; + len = sa->sa_len; + db_printf("["); + while (len > 0) { + db_printf("%d", *p); + p++; len--; + if (len) db_printf(","); + } + db_printf("]\n"); +} + +static void +db_print_ifa(struct ifaddr *ifa) +{ + if (ifa == NULL) + return; + db_printf(" ifa_addr="); + db_print_sa(ifa->ifa_addr); + db_printf(" ifa_dsta="); + db_print_sa(ifa->ifa_dstaddr); + db_printf(" ifa_mask="); + db_print_sa(ifa->ifa_netmask); + db_printf(" flags=0x%x,refcnt=%d,metric=%d\n", + ifa->ifa_flags, + ifa->ifa_refcnt, + ifa->ifa_metric); +} + +/* + * Function to pass to rt_walktree(). + * Return non-zero error to abort walk. + */ +static int +db_show_rtentry(struct rtentry *rt, void *w) +{ + db_printf("rtentry=%p", rt); + + db_printf(" flags=0x%x refcnt=%d use=%"PRId64" expire=%"PRId64"\n", + rt->rt_flags, rt->rt_refcnt, + rt->rt_use, (uint64_t)rt->rt_expire); + + db_printf(" key="); db_print_sa(rt_getkey(rt)); + db_printf(" mask="); db_print_sa(rt_mask(rt)); + db_printf(" gw="); db_print_sa(rt->rt_gateway); + + db_printf(" ifp=%p ", rt->rt_ifp); + if (rt->rt_ifp) + db_printf("(%s)", rt->rt_ifp->if_xname); + else + db_printf("(NULL)"); + + 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); + + return 0; +} + +/* + * Function to print all the route trees. + * Use this from ddb: "show routes" + */ +void +db_show_routes(db_expr_t addr, bool have_addr, + db_expr_t count, const char *modif) +{ + rt_walktree(AF_INET, db_show_rtentry, NULL); +} +#endif diff --git a/sys/netinet/if_arp.c b/sys/netinet/if_arp.c index 23695a1..e931b49 100644 --- a/sys/netinet/if_arp.c +++ b/sys/netinet/if_arp.c @@ -205,13 +205,6 @@ static int myip_initialized = 0; static int revarp_in_progress = 0; static struct ifnet *myip_ifp = NULL; -#ifdef DDB -static void db_print_sa(const struct sockaddr *); -static void db_print_ifa(struct ifaddr *); -static void db_print_llinfo(struct llentry *); -static int db_show_rtentry(struct rtentry *, void *); -#endif - static int arp_drainwanted; static int log_movements = 1; @@ -1920,107 +1913,6 @@ revarpwhoarewe(struct ifnet *ifp, struct in_addr *serv_in, return 0; } - - -#ifdef DDB - -#include -#include -#include - -static void -db_print_sa(const struct sockaddr *sa) -{ - int len; - const u_char *p; - - if (sa == NULL) { - db_printf("[NULL]"); - return; - } - - p = (const u_char *)sa; - len = sa->sa_len; - db_printf("["); - while (len > 0) { - db_printf("%d", *p); - p++; len--; - if (len) db_printf(","); - } - db_printf("]\n"); -} - -static void -db_print_ifa(struct ifaddr *ifa) -{ - if (ifa == NULL) - return; - db_printf(" ifa_addr="); - db_print_sa(ifa->ifa_addr); - db_printf(" ifa_dsta="); - db_print_sa(ifa->ifa_dstaddr); - db_printf(" ifa_mask="); - db_print_sa(ifa->ifa_netmask); - db_printf(" flags=0x%x,refcnt=%d,metric=%d\n", - ifa->ifa_flags, - ifa->ifa_refcnt, - ifa->ifa_metric); -} - -static void -db_print_llinfo(struct llentry *la) -{ - if (la == NULL) - return; - db_printf(" la_hold=%p, la_asked=%d\n", la->la_hold, la->la_asked); - db_printf(" la_flags=0x%x\n", la->la_flags); -} - -/* - * Function to pass to rt_walktree(). - * Return non-zero error to abort walk. - */ -static int -db_show_rtentry(struct rtentry *rt, void *w) -{ - db_printf("rtentry=%p", rt); - - db_printf(" flags=0x%x refcnt=%d use=%"PRId64" expire=%"PRId64"\n", - rt->rt_flags, rt->rt_refcnt, - rt->rt_use, (uint64_t)rt->rt_expire); - - db_printf(" key="); db_print_sa(rt_getkey(rt)); - db_printf(" mask="); db_print_sa(rt_mask(rt)); - db_printf(" gw="); db_print_sa(rt->rt_gateway); - - db_printf(" ifp=%p ", rt->rt_ifp); - if (rt->rt_ifp) - db_printf("(%s)", rt->rt_ifp->if_xname); - else - db_printf("(NULL)"); - - 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_print_llinfo(rt->rt_llinfo); - - return 0; -} - -/* - * Function to print all the route trees. - * Use this from ddb: "show arptab" - */ -void -db_show_arptab(db_expr_t addr, bool have_addr, - db_expr_t count, const char *modif) -{ - rt_walktree(AF_INET, db_show_rtentry, NULL); -} -#endif - void arp_stat_add(int type, uint64_t count) {