2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2007 Robert N. M. Watson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Debugger routines relating to sockets, protocols, etc, for use in DDB.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/domain.h>
40 #include <sys/kernel.h>
41 #include <sys/protosw.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
49 db_print_sotype(short so_type)
54 db_printf("SOCK_STREAM");
58 db_printf("SOCK_DGRAM");
62 db_printf("SOCK_RAW");
66 db_printf("SOCK_RDM");
70 db_printf("SOCK_SEQPACKET");
80 db_print_sooptions(int so_options)
85 if (so_options & SO_DEBUG) {
86 db_printf("%sSO_DEBUG", comma ? ", " : "");
89 if (so_options & SO_ACCEPTCONN) {
90 db_printf("%sSO_ACCEPTCONN", comma ? ", " : "");
93 if (so_options & SO_REUSEADDR) {
94 db_printf("%sSO_REUSEADDR", comma ? ", " : "");
97 if (so_options & SO_KEEPALIVE) {
98 db_printf("%sSO_KEEPALIVE", comma ? ", " : "");
101 if (so_options & SO_DONTROUTE) {
102 db_printf("%sSO_DONTROUTE", comma ? ", " : "");
105 if (so_options & SO_BROADCAST) {
106 db_printf("%sSO_BROADCAST", comma ? ", " : "");
109 if (so_options & SO_USELOOPBACK) {
110 db_printf("%sSO_USELOOPBACK", comma ? ", " : "");
113 if (so_options & SO_LINGER) {
114 db_printf("%sSO_LINGER", comma ? ", " : "");
117 if (so_options & SO_OOBINLINE) {
118 db_printf("%sSO_OOBINLINE", comma ? ", " : "");
121 if (so_options & SO_REUSEPORT) {
122 db_printf("%sSO_REUSEPORT", comma ? ", " : "");
125 if (so_options & SO_REUSEPORT_LB) {
126 db_printf("%sSO_REUSEPORT_LB", comma ? ", " : "");
129 if (so_options & SO_TIMESTAMP) {
130 db_printf("%sSO_TIMESTAMP", comma ? ", " : "");
133 if (so_options & SO_NOSIGPIPE) {
134 db_printf("%sSO_NOSIGPIPE", comma ? ", " : "");
137 if (so_options & SO_ACCEPTFILTER) {
138 db_printf("%sSO_ACCEPTFILTER", comma ? ", " : "");
141 if (so_options & SO_BINTIME) {
142 db_printf("%sSO_BINTIME", comma ? ", " : "");
145 if (so_options & SO_NO_OFFLOAD) {
146 db_printf("%sSO_NO_OFFLOAD", comma ? ", " : "");
149 if (so_options & SO_NO_DDP) {
150 db_printf("%sSO_NO_DDP", comma ? ", " : "");
156 db_print_sostate(short so_state)
161 if (so_state & SS_ISCONNECTED) {
162 db_printf("%sSS_ISCONNECTED", comma ? ", " : "");
165 if (so_state & SS_ISCONNECTING) {
166 db_printf("%sSS_ISCONNECTING", comma ? ", " : "");
169 if (so_state & SS_ISDISCONNECTING) {
170 db_printf("%sSS_ISDISCONNECTING", comma ? ", " : "");
173 if (so_state & SS_NBIO) {
174 db_printf("%sSS_NBIO", comma ? ", " : "");
177 if (so_state & SS_ASYNC) {
178 db_printf("%sSS_ASYNC", comma ? ", " : "");
181 if (so_state & SS_ISCONFIRMING) {
182 db_printf("%sSS_ISCONFIRMING", comma ? ", " : "");
188 db_print_soqstate(int so_qstate)
193 if (so_qstate & SQ_INCOMP) {
194 db_printf("%sSQ_INCOMP", comma ? ", " : "");
197 if (so_qstate & SQ_COMP) {
198 db_printf("%sSQ_COMP", comma ? ", " : "");
204 db_print_sbstate(short sb_state)
209 if (sb_state & SBS_CANTSENDMORE) {
210 db_printf("%sSBS_CANTSENDMORE", comma ? ", " : "");
213 if (sb_state & SBS_CANTRCVMORE) {
214 db_printf("%sSBS_CANTRCVMORE", comma ? ", " : "");
217 if (sb_state & SBS_RCVATMARK) {
218 db_printf("%sSBS_RCVATMARK", comma ? ", " : "");
224 db_print_indent(int indent)
228 for (i = 0; i < indent; i++)
233 db_print_domain(struct domain *d, const char *domain_name, int indent)
236 db_print_indent(indent);
237 db_printf("%s at %p\n", domain_name, d);
241 db_print_indent(indent);
242 db_printf("dom_family: %d ", d->dom_family);
243 db_printf("dom_name: %s\n", d->dom_name);
245 db_print_indent(indent);
246 db_printf("dom_externalize: %p ", d->dom_externalize);
247 db_printf("dom_dispose: %p\n", d->dom_dispose);
249 db_print_indent(indent);
250 db_printf("dom_protosw: %p ", d->dom_protosw);
251 db_printf("dom_next: %p\n", d->dom_next);
253 db_print_indent(indent);
254 db_printf("dom_rtattach: %p ", d->dom_rtattach);
256 db_print_indent(indent);
257 db_printf("dom_ifattach: %p ", d->dom_ifattach);
258 db_printf("dom_ifdetach: %p\n", d->dom_ifdetach);
262 db_print_prflags(short pr_flags)
267 if (pr_flags & PR_ATOMIC) {
268 db_printf("%sPR_ATOMIC", comma ? ", " : "");
271 if (pr_flags & PR_ADDR) {
272 db_printf("%sPR_ADDR", comma ? ", " : "");
275 if (pr_flags & PR_CONNREQUIRED) {
276 db_printf("%sPR_CONNREQUIRED", comma ? ", " : "");
279 if (pr_flags & PR_WANTRCVD) {
280 db_printf("%sPR_WANTRCVD", comma ? ", " : "");
283 if (pr_flags & PR_RIGHTS) {
284 db_printf("%sPR_RIGHTS", comma ? ", " : "");
287 if (pr_flags & PR_IMPLOPCL) {
288 db_printf("%sPR_IMPLOPCL", comma ? ", " : "");
294 db_print_protosw(struct protosw *pr, const char *prname, int indent)
297 db_print_indent(indent);
298 db_printf("%s at %p\n", prname, pr);
302 db_print_indent(indent);
303 db_printf("pr_type: %d ", pr->pr_type);
304 db_printf("pr_domain: %p\n", pr->pr_domain);
305 if (pr->pr_domain != NULL)
306 db_print_domain(pr->pr_domain, "pr_domain", indent);
308 db_print_indent(indent);
309 db_printf("pr_protocol: %d\n", pr->pr_protocol);
311 db_print_indent(indent);
312 db_printf("pr_flags: %d (", pr->pr_flags);
313 db_print_prflags(pr->pr_flags);
316 db_print_indent(indent);
317 db_printf("pr_input: %p ", pr->pr_input);
318 db_printf("pr_ctlinput: %p\n", pr->pr_ctlinput);
319 db_printf("pr_ctloutput: %p ", pr->pr_ctloutput);
321 db_print_indent(indent);
322 db_printf("pr_fasttimo: %p ", pr->pr_fasttimo);
323 db_printf("pr_slowtimo: %p ", pr->pr_slowtimo);
324 db_printf("pr_drain: %p\n", pr->pr_drain);
328 db_print_sbflags(short sb_flags)
333 if (sb_flags & SB_WAIT) {
334 db_printf("%sSB_WAIT", comma ? ", " : "");
337 if (sb_flags & SB_SEL) {
338 db_printf("%sSB_SEL", comma ? ", " : "");
341 if (sb_flags & SB_ASYNC) {
342 db_printf("%sSB_ASYNC", comma ? ", " : "");
345 if (sb_flags & SB_UPCALL) {
346 db_printf("%sSB_UPCALL", comma ? ", " : "");
349 if (sb_flags & SB_NOINTR) {
350 db_printf("%sSB_NOINTR", comma ? ", " : "");
353 if (sb_flags & SB_AIO) {
354 db_printf("%sSB_AIO", comma ? ", " : "");
357 if (sb_flags & SB_KNOTE) {
358 db_printf("%sSB_KNOTE", comma ? ", " : "");
361 if (sb_flags & SB_AUTOSIZE) {
362 db_printf("%sSB_AUTOSIZE", comma ? ", " : "");
368 db_print_sockbuf(struct sockbuf *sb, const char *sockbufname, int indent)
371 db_print_indent(indent);
372 db_printf("%s at %p\n", sockbufname, sb);
376 db_print_indent(indent);
377 db_printf("sb_state: 0x%x (", sb->sb_state);
378 db_print_sbstate(sb->sb_state);
381 db_print_indent(indent);
382 db_printf("sb_mb: %p ", sb->sb_mb);
383 db_printf("sb_mbtail: %p ", sb->sb_mbtail);
384 db_printf("sb_lastrecord: %p\n", sb->sb_lastrecord);
386 db_print_indent(indent);
387 db_printf("sb_sndptr: %p ", sb->sb_sndptr);
388 db_printf("sb_sndptroff: %u\n", sb->sb_sndptroff);
390 db_print_indent(indent);
391 db_printf("sb_acc: %u ", sb->sb_acc);
392 db_printf("sb_ccc: %u ", sb->sb_ccc);
393 db_printf("sb_hiwat: %u ", sb->sb_hiwat);
394 db_printf("sb_mbcnt: %u ", sb->sb_mbcnt);
395 db_printf("sb_mbmax: %u\n", sb->sb_mbmax);
397 db_print_indent(indent);
398 db_printf("sb_ctl: %u ", sb->sb_ctl);
399 db_printf("sb_lowat: %d ", sb->sb_lowat);
400 db_printf("sb_timeo: %jd\n", sb->sb_timeo);
402 db_print_indent(indent);
403 db_printf("sb_flags: 0x%x (", sb->sb_flags);
404 db_print_sbflags(sb->sb_flags);
407 db_print_indent(indent);
408 db_printf("sb_aiojobq first: %p\n", TAILQ_FIRST(&sb->sb_aiojobq));
412 db_print_socket(struct socket *so, const char *socketname, int indent)
415 db_print_indent(indent);
416 db_printf("%s at %p\n", socketname, so);
420 db_print_indent(indent);
421 db_printf("so_count: %d ", so->so_count);
422 db_printf("so_type: %d (", so->so_type);
423 db_print_sotype(so->so_type);
426 db_print_indent(indent);
427 db_printf("so_options: 0x%x (", so->so_options);
428 db_print_sooptions(so->so_options);
431 db_print_indent(indent);
432 db_printf("so_linger: %d ", so->so_linger);
433 db_printf("so_state: 0x%x (", so->so_state);
434 db_print_sostate(so->so_state);
437 db_print_indent(indent);
438 db_printf("so_pcb: %p ", so->so_pcb);
439 db_printf("so_proto: %p\n", so->so_proto);
441 if (so->so_proto != NULL)
442 db_print_protosw(so->so_proto, "so_proto", indent);
444 db_print_indent(indent);
445 if (so->so_options & SO_ACCEPTCONN) {
446 db_printf("sol_incomp first: %p ",
447 TAILQ_FIRST(&so->sol_incomp));
448 db_printf("sol_comp first: %p\n", TAILQ_FIRST(&so->sol_comp));
449 db_printf("sol_qlen: %d ", so->sol_qlen);
450 db_printf("sol_incqlen: %d ", so->sol_incqlen);
451 db_printf("sol_qlimit: %d ", so->sol_qlimit);
453 db_printf("so_qstate: 0x%x (", so->so_qstate);
454 db_print_soqstate(so->so_qstate);
456 db_printf("so_listen: %p ", so->so_listen);
457 /* so_list skipped */
458 db_printf("so_timeo: %d ", so->so_timeo);
459 db_printf("so_error: %d\n", so->so_error);
461 db_print_indent(indent);
462 db_printf("so_sigio: %p ", so->so_sigio);
463 db_printf("so_oobmark: %lu\n", so->so_oobmark);
465 db_print_sockbuf(&so->so_rcv, "so_rcv", indent);
466 db_print_sockbuf(&so->so_snd, "so_snd", indent);
470 DB_SHOW_COMMAND(socket, db_show_socket)
475 db_printf("usage: show socket <addr>\n");
478 so = (struct socket *)addr;
480 db_print_socket(so, "socket", 0);
483 DB_SHOW_COMMAND(sockbuf, db_show_sockbuf)
488 db_printf("usage: show sockbuf <addr>\n");
491 sb = (struct sockbuf *)addr;
493 db_print_sockbuf(sb, "sockbuf", 0);
496 DB_SHOW_COMMAND(protosw, db_show_protosw)
501 db_printf("usage: show protosw <addr>\n");
504 pr = (struct protosw *)addr;
506 db_print_protosw(pr, "protosw", 0);
509 DB_SHOW_COMMAND(domain, db_show_domain)
514 db_printf("usage: show protosw <addr>\n");
517 d = (struct domain *)addr;
519 db_print_domain(d, "domain", 0);