summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2016-01-15 11:21:59 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2016-01-15 11:21:59 +0000
commitb894a0eb230529198fafa120e7b042ab3ea573f8 (patch)
tree4cc2b42ea50f9ef5134f487b2ffcf5e538387c5f
parent24c4f587dd183708bc5cd6d94572fd17f974f0ef (diff)
add a "show socket" command to ddb
should help inspecting socket issues in the future. enthusiasm from mpi@ bluhm@ deraadt@
-rw-r--r--sys/ddb/db_command.c10
-rw-r--r--sys/ddb/db_interface.h5
-rw-r--r--sys/kern/subr_pool.c10
-rw-r--r--sys/kern/uipc_socket.c88
4 files changed, 106 insertions, 7 deletions
diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c
index f972d6f23b7..ef9d3709d0b 100644
--- a/sys/ddb/db_command.c
+++ b/sys/ddb/db_command.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_command.c,v 1.66 2015/12/23 01:39:02 mmcc Exp $ */
+/* $OpenBSD: db_command.c,v 1.67 2016/01/15 11:21:58 dlg Exp $ */
/* $NetBSD: db_command.c,v 1.20 1996/03/30 22:30:05 christos Exp $ */
/*
@@ -330,6 +330,13 @@ db_mbuf_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
/*ARGSUSED*/
void
+db_socket_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
+{
+ so_print((void *)addr, db_printf);
+}
+
+/*ARGSUSED*/
+void
db_mount_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
boolean_t full = FALSE;
@@ -533,6 +540,7 @@ 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 },
+ { "socket", db_socket_print_cmd, 0, NULL },
#ifdef DDB_STRUCT
{ "struct", db_struct_layout_cmd, CS_OWN, NULL },
#endif
diff --git a/sys/ddb/db_interface.h b/sys/ddb/db_interface.h
index bcd4956975b..77602d2cc98 100644
--- a/sys/ddb/db_interface.h
+++ b/sys/ddb/db_interface.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_interface.h,v 1.16 2010/11/05 15:17:50 claudio Exp $ */
+/* $OpenBSD: db_interface.h,v 1.17 2016/01/15 11:21:58 dlg Exp $ */
/* $NetBSD: db_interface.h,v 1.1 1996/02/05 01:57:03 christos Exp $ */
/*
@@ -58,6 +58,9 @@ void db_show_all_pools(db_expr_t, int, db_expr_t, char *);
/* kern/uipc_mbuf.c */
void m_print(void *, int (*)(const char *, ...));
+/* kern/uipc_socket.c */
+void so_print(void *, int (*)(const char *, ...));
+
/* 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/kern/subr_pool.c b/sys/kern/subr_pool.c
index 757381b77f7..043cc8b27b7 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_pool.c,v 1.193 2015/09/11 09:26:13 kettenis Exp $ */
+/* $OpenBSD: subr_pool.c,v 1.194 2016/01/15 11:21:58 dlg Exp $ */
/* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */
/*-
@@ -703,9 +703,11 @@ pool_put(struct pool *pp, void *v)
if (freeph != NULL)
pool_p_free(pp, freeph);
- mtx_enter(&pp->pr_requests_mtx);
- pool_runqueue(pp, PR_NOWAIT);
- mtx_leave(&pp->pr_requests_mtx);
+ if (!TAILQ_EMPTY(&pp->pr_requests)) {
+ mtx_enter(&pp->pr_requests_mtx);
+ pool_runqueue(pp, PR_NOWAIT);
+ mtx_leave(&pp->pr_requests_mtx);
+ }
}
/*
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 024426831c1..7cbeb42085e 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.146 2016/01/13 21:39:39 bluhm Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.147 2016/01/15 11:21:58 dlg Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -50,6 +50,10 @@
#include <net/if.h>
#include <sys/pool.h>
+#ifdef DDB
+#include <machine/db_machdep.h>
+#endif
+
void sbsync(struct sockbuf *, struct mbuf *);
int sosplice(struct socket *, int, off_t, struct timeval *);
@@ -1893,3 +1897,85 @@ filt_solisten(struct knote *kn, long hint)
kn->kn_data = so->so_qlen;
return (so->so_qlen != 0);
}
+
+#ifdef DDB
+void
+sobuf_print(struct sockbuf *,
+ int (*)(const char *, ...) __attribute__((__format__(__kprintf__,1,2))));
+
+void
+sobuf_print(struct sockbuf *sb,
+ int (*pr)(const char *, ...) __attribute__((__format__(__kprintf__,1,2))))
+{
+ (*pr)("\tsb_cc: %lu\n", sb->sb_cc);
+ (*pr)("\tsb_datacc: %lu\n", sb->sb_datacc);
+ (*pr)("\tsb_hiwat: %lu\n", sb->sb_hiwat);
+ (*pr)("\tsb_wat: %lu\n", sb->sb_wat);
+ (*pr)("\tsb_mbcnt: %lu\n", sb->sb_mbcnt);
+ (*pr)("\tsb_mbmax: %lu\n", sb->sb_mbmax);
+ (*pr)("\tsb_lowat: %ld\n", sb->sb_lowat);
+ (*pr)("\tsb_mb: %p\n", sb->sb_mb);
+ (*pr)("\tsb_mbtail: %p\n", sb->sb_mbtail);
+ (*pr)("\tsb_lastrecord: %p\n", sb->sb_lastrecord);
+ (*pr)("\tsb_sel: ...\n");
+ (*pr)("\tsb_flagsintr: %d\n", sb->sb_flagsintr);
+ (*pr)("\tsb_flags: %i\n", sb->sb_flags);
+ (*pr)("\tsb_timeo: %i\n", sb->sb_timeo);
+}
+
+void
+so_print(void *v,
+ int (*pr)(const char *, ...) __attribute__((__format__(__kprintf__,1,2))))
+{
+ struct socket *so = v;
+
+ (*pr)("socket %p\n", so);
+ (*pr)("so_type: %i\n", so->so_type);
+ (*pr)("so_options: 0x%04x\n", so->so_options); /* %b */
+ (*pr)("so_linger: %i\n", so->so_linger);
+ (*pr)("so_state: %i\n", so->so_state);
+ (*pr)("so_pcb: %p\n", so->so_pcb);
+ (*pr)("so_proto: %p\n", so->so_proto);
+
+ (*pr)("so_head: %p\n", so->so_head);
+ (*pr)("so_onq: %p\n", so->so_onq);
+ (*pr)("so_q0: @%p first: %p\n", &so->so_q0, TAILQ_FIRST(&so->so_q0));
+ (*pr)("so_q: @%p first: %p\n", &so->so_q, TAILQ_FIRST(&so->so_q));
+ (*pr)("so_q0len: %i\n", so->so_q0len);
+ (*pr)("so_qlen: %i\n", so->so_qlen);
+ (*pr)("so_qlimit: %i\n", so->so_qlimit);
+ (*pr)("so_timeo: %i\n", so->so_timeo);
+ (*pr)("so_pgid: %i\n", so->so_pgid);
+ (*pr)("so_siguid: %i\n", so->so_siguid);
+ (*pr)("so_sigeuid: %i\n", so->so_sigeuid);
+ (*pr)("so_obmark: %lu\n", so->so_oobmark);
+
+ (*pr)("so_sp: %p\n", so->so_sp);
+ if (so->so_sp != NULL) {
+ (*pr)("\tssp_socket: %p\n", so->so_sp->ssp_socket);
+ (*pr)("\tssp_soback: %p\n", so->so_sp->ssp_soback);
+ (*pr)("\tssp_len: %lld\n",
+ (unsigned long long)so->so_sp->ssp_len);
+ (*pr)("\tssp_max: %lld\n",
+ (unsigned long long)so->so_sp->ssp_max);
+ (*pr)("\tssp_idletv: %lld %ldn", so->so_sp->ssp_idletv.tv_sec,
+ so->so_sp->ssp_idletv.tv_usec);
+ (*pr)("\tssp_idleto: %spending (@%i)\n",
+ timeout_pending(&so->so_sp->ssp_idleto) ? "" : "not ",
+ so->so_sp->ssp_idleto.to_time);
+ }
+
+ (*pr)("so_rcv:\n");
+ sobuf_print(&so->so_rcv, pr);
+ (*pr)("so_snd:\n");
+ sobuf_print(&so->so_snd, pr);
+
+ (*pr)("so_upcall: %p so_upcallarg: %p\n",
+ so->so_upcall, so->so_upcallarg);
+
+ (*pr)("so_euid: %d so_ruid: %d\n", so->so_euid, so->so_ruid);
+ (*pr)("so_egid: %d so_rgid: %d\n", so->so_egid, so->so_rgid);
+ (*pr)("so_cpid: %d\n", so->so_cpid);
+}
+#endif
+