2 * SPDX-License-Identifier: BSD-2-Clause
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>
36 #include <sys/param.h>
37 #include <sys/domain.h>
38 #include <sys/kernel.h>
39 #include <sys/protosw.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
47 db_print_sotype(short so_type)
52 db_printf("SOCK_STREAM");
56 db_printf("SOCK_DGRAM");
60 db_printf("SOCK_RAW");
64 db_printf("SOCK_RDM");
68 db_printf("SOCK_SEQPACKET");
78 db_print_sooptions(int so_options)
83 if (so_options & SO_DEBUG) {
84 db_printf("%sSO_DEBUG", comma ? ", " : "");
87 if (so_options & SO_ACCEPTCONN) {
88 db_printf("%sSO_ACCEPTCONN", comma ? ", " : "");
91 if (so_options & SO_REUSEADDR) {
92 db_printf("%sSO_REUSEADDR", comma ? ", " : "");
95 if (so_options & SO_KEEPALIVE) {
96 db_printf("%sSO_KEEPALIVE", comma ? ", " : "");
99 if (so_options & SO_DONTROUTE) {
100 db_printf("%sSO_DONTROUTE", comma ? ", " : "");
103 if (so_options & SO_BROADCAST) {
104 db_printf("%sSO_BROADCAST", comma ? ", " : "");
107 if (so_options & SO_USELOOPBACK) {
108 db_printf("%sSO_USELOOPBACK", comma ? ", " : "");
111 if (so_options & SO_LINGER) {
112 db_printf("%sSO_LINGER", comma ? ", " : "");
115 if (so_options & SO_OOBINLINE) {
116 db_printf("%sSO_OOBINLINE", comma ? ", " : "");
119 if (so_options & SO_REUSEPORT) {
120 db_printf("%sSO_REUSEPORT", comma ? ", " : "");
123 if (so_options & SO_REUSEPORT_LB) {
124 db_printf("%sSO_REUSEPORT_LB", comma ? ", " : "");
127 if (so_options & SO_TIMESTAMP) {
128 db_printf("%sSO_TIMESTAMP", comma ? ", " : "");
131 if (so_options & SO_NOSIGPIPE) {
132 db_printf("%sSO_NOSIGPIPE", comma ? ", " : "");
135 if (so_options & SO_ACCEPTFILTER) {
136 db_printf("%sSO_ACCEPTFILTER", comma ? ", " : "");
139 if (so_options & SO_BINTIME) {
140 db_printf("%sSO_BINTIME", comma ? ", " : "");
143 if (so_options & SO_NO_OFFLOAD) {
144 db_printf("%sSO_NO_OFFLOAD", comma ? ", " : "");
147 if (so_options & SO_NO_DDP) {
148 db_printf("%sSO_NO_DDP", comma ? ", " : "");
154 db_print_sostate(short so_state)
159 if (so_state & SS_ISCONNECTED) {
160 db_printf("%sSS_ISCONNECTED", comma ? ", " : "");
163 if (so_state & SS_ISCONNECTING) {
164 db_printf("%sSS_ISCONNECTING", comma ? ", " : "");
167 if (so_state & SS_ISDISCONNECTING) {
168 db_printf("%sSS_ISDISCONNECTING", comma ? ", " : "");
171 if (so_state & SS_NBIO) {
172 db_printf("%sSS_NBIO", comma ? ", " : "");
175 if (so_state & SS_ASYNC) {
176 db_printf("%sSS_ASYNC", comma ? ", " : "");
179 if (so_state & SS_ISCONFIRMING) {
180 db_printf("%sSS_ISCONFIRMING", comma ? ", " : "");
186 db_print_soqstate(int so_qstate)
191 if (so_qstate & SQ_INCOMP) {
192 db_printf("%sSQ_INCOMP", comma ? ", " : "");
195 if (so_qstate & SQ_COMP) {
196 db_printf("%sSQ_COMP", comma ? ", " : "");
202 db_print_sbstate(short sb_state)
207 if (sb_state & SBS_CANTSENDMORE) {
208 db_printf("%sSBS_CANTSENDMORE", comma ? ", " : "");
211 if (sb_state & SBS_CANTRCVMORE) {
212 db_printf("%sSBS_CANTRCVMORE", comma ? ", " : "");
215 if (sb_state & SBS_RCVATMARK) {
216 db_printf("%sSBS_RCVATMARK", comma ? ", " : "");
222 db_print_indent(int indent)
226 for (i = 0; i < indent; i++)
231 db_print_domain(struct domain *d, const char *domain_name, int indent)
234 db_print_indent(indent);
235 db_printf("%s at %p\n", domain_name, d);
239 db_print_indent(indent);
240 db_printf("dom_family: %d ", d->dom_family);
241 db_printf("dom_name: %s\n", d->dom_name);
243 db_print_indent(indent);
244 db_printf("dom_externalize: %p ", d->dom_externalize);
246 db_print_indent(indent);
247 db_printf("dom_protosw: %p ", d->dom_protosw);
248 db_printf("dom_next: %p\n", d->dom_next.sle_next);
250 db_print_indent(indent);
251 db_printf("dom_rtattach: %p ", d->dom_rtattach);
253 db_print_indent(indent);
254 db_printf("dom_ifattach: %p ", d->dom_ifattach);
255 db_printf("dom_ifdetach: %p\n", d->dom_ifdetach);
259 db_print_prflags(short pr_flags)
264 if (pr_flags & PR_ATOMIC) {
265 db_printf("%sPR_ATOMIC", comma ? ", " : "");
268 if (pr_flags & PR_ADDR) {
269 db_printf("%sPR_ADDR", comma ? ", " : "");
272 if (pr_flags & PR_CONNREQUIRED) {
273 db_printf("%sPR_CONNREQUIRED", comma ? ", " : "");
276 if (pr_flags & PR_WANTRCVD) {
277 db_printf("%sPR_WANTRCVD", comma ? ", " : "");
280 if (pr_flags & PR_IMPLOPCL) {
281 db_printf("%sPR_IMPLOPCL", comma ? ", " : "");
287 db_print_protosw(struct protosw *pr, const char *prname, int indent)
290 db_print_indent(indent);
291 db_printf("%s at %p\n", prname, pr);
295 db_print_indent(indent);
296 db_printf("pr_type: %d ", pr->pr_type);
297 db_printf("pr_domain: %p\n", pr->pr_domain);
298 if (pr->pr_domain != NULL)
299 db_print_domain(pr->pr_domain, "pr_domain", indent);
301 db_print_indent(indent);
302 db_printf("pr_protocol: %d\n", pr->pr_protocol);
304 db_print_indent(indent);
305 db_printf("pr_flags: %d (", pr->pr_flags);
306 db_print_prflags(pr->pr_flags);
309 db_print_indent(indent);
310 db_printf("pr_ctloutput: %p ", pr->pr_ctloutput);
314 db_print_sbflags(short sb_flags)
319 if (sb_flags & SB_WAIT) {
320 db_printf("%sSB_WAIT", comma ? ", " : "");
323 if (sb_flags & SB_SEL) {
324 db_printf("%sSB_SEL", comma ? ", " : "");
327 if (sb_flags & SB_ASYNC) {
328 db_printf("%sSB_ASYNC", comma ? ", " : "");
331 if (sb_flags & SB_UPCALL) {
332 db_printf("%sSB_UPCALL", comma ? ", " : "");
335 if (sb_flags & SB_NOINTR) {
336 db_printf("%sSB_NOINTR", comma ? ", " : "");
339 if (sb_flags & SB_AIO) {
340 db_printf("%sSB_AIO", comma ? ", " : "");
343 if (sb_flags & SB_KNOTE) {
344 db_printf("%sSB_KNOTE", comma ? ", " : "");
347 if (sb_flags & SB_AUTOSIZE) {
348 db_printf("%sSB_AUTOSIZE", comma ? ", " : "");
354 db_print_sockbuf(struct sockbuf *sb, const char *sockbufname, int indent)
357 db_print_indent(indent);
358 db_printf("%s at %p\n", sockbufname, sb);
362 db_print_indent(indent);
363 db_printf("sb_state: 0x%x (", sb->sb_state);
364 db_print_sbstate(sb->sb_state);
367 db_print_indent(indent);
368 db_printf("sb_mb: %p ", sb->sb_mb);
369 db_printf("sb_mbtail: %p ", sb->sb_mbtail);
370 db_printf("sb_lastrecord: %p\n", sb->sb_lastrecord);
372 db_print_indent(indent);
373 db_printf("sb_sndptr: %p ", sb->sb_sndptr);
374 db_printf("sb_sndptroff: %u\n", sb->sb_sndptroff);
376 db_print_indent(indent);
377 db_printf("sb_acc: %u ", sb->sb_acc);
378 db_printf("sb_ccc: %u ", sb->sb_ccc);
379 db_printf("sb_hiwat: %u ", sb->sb_hiwat);
380 db_printf("sb_mbcnt: %u ", sb->sb_mbcnt);
381 db_printf("sb_mbmax: %u\n", sb->sb_mbmax);
383 db_print_indent(indent);
384 db_printf("sb_ctl: %u ", sb->sb_ctl);
385 db_printf("sb_lowat: %d ", sb->sb_lowat);
386 db_printf("sb_timeo: %jd\n", sb->sb_timeo);
388 db_print_indent(indent);
389 db_printf("sb_flags: 0x%x (", sb->sb_flags);
390 db_print_sbflags(sb->sb_flags);
393 db_print_indent(indent);
394 db_printf("sb_aiojobq first: %p\n", TAILQ_FIRST(&sb->sb_aiojobq));
398 db_print_socket(struct socket *so, const char *socketname, int indent)
401 db_print_indent(indent);
402 db_printf("%s at %p\n", socketname, so);
406 db_print_indent(indent);
407 db_printf("so_count: %d ", so->so_count);
408 db_printf("so_type: %d (", so->so_type);
409 db_print_sotype(so->so_type);
412 db_print_indent(indent);
413 db_printf("so_options: 0x%x (", so->so_options);
414 db_print_sooptions(so->so_options);
417 db_print_indent(indent);
418 db_printf("so_linger: %d ", so->so_linger);
419 db_printf("so_state: 0x%x (", so->so_state);
420 db_print_sostate(so->so_state);
423 db_print_indent(indent);
424 db_printf("so_pcb: %p ", so->so_pcb);
425 db_printf("so_proto: %p\n", so->so_proto);
427 if (so->so_proto != NULL)
428 db_print_protosw(so->so_proto, "so_proto", indent);
430 db_print_indent(indent);
431 if (so->so_options & SO_ACCEPTCONN) {
432 db_printf("sol_incomp first: %p ",
433 TAILQ_FIRST(&so->sol_incomp));
434 db_printf("sol_comp first: %p\n", TAILQ_FIRST(&so->sol_comp));
435 db_printf("sol_qlen: %d ", so->sol_qlen);
436 db_printf("sol_incqlen: %d ", so->sol_incqlen);
437 db_printf("sol_qlimit: %d ", so->sol_qlimit);
439 db_printf("so_qstate: 0x%x (", so->so_qstate);
440 db_print_soqstate(so->so_qstate);
442 db_printf("so_listen: %p ", so->so_listen);
443 /* so_list skipped */
444 db_printf("so_timeo: %d ", so->so_timeo);
445 db_printf("so_error: %d\n", so->so_error);
447 db_print_indent(indent);
448 db_printf("so_sigio: %p ", so->so_sigio);
449 db_printf("so_oobmark: %lu\n", so->so_oobmark);
451 db_print_sockbuf(&so->so_rcv, "so_rcv", indent);
452 db_print_sockbuf(&so->so_snd, "so_snd", indent);
456 DB_SHOW_COMMAND(socket, db_show_socket)
461 db_printf("usage: show socket <addr>\n");
464 so = (struct socket *)addr;
466 db_print_socket(so, "socket", 0);
469 DB_SHOW_COMMAND(sockbuf, db_show_sockbuf)
474 db_printf("usage: show sockbuf <addr>\n");
477 sb = (struct sockbuf *)addr;
479 db_print_sockbuf(sb, "sockbuf", 0);
482 DB_SHOW_COMMAND(protosw, db_show_protosw)
487 db_printf("usage: show protosw <addr>\n");
490 pr = (struct protosw *)addr;
492 db_print_protosw(pr, "protosw", 0);
495 DB_SHOW_COMMAND(domain, db_show_domain)
500 db_printf("usage: show protosw <addr>\n");
503 d = (struct domain *)addr;
505 db_print_domain(d, "domain", 0);