2 * Copyright (c) 2007 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Debugger routines relating to sockets, protocols, etc, for use in DDB.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
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(short 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_TIMESTAMP) {
124 db_printf("%sSO_TIMESTAMP", comma ? ", " : "");
127 if (so_options & SO_NOSIGPIPE) {
128 db_printf("%sSO_NOSIGPIPE", comma ? ", " : "");
131 if (so_options & SO_ACCEPTFILTER) {
132 db_printf("%sSO_ACCEPTFILTER", comma ? ", " : "");
135 if (so_options & SO_BINTIME) {
136 db_printf("%sSO_BINTIME", comma ? ", " : "");
139 if (so_options & SO_NO_OFFLOAD) {
140 db_printf("%sSO_NO_OFFLOAD", comma ? ", " : "");
143 if (so_options & SO_NO_DDP) {
144 db_printf("%sSO_NO_DDP", comma ? ", " : "");
150 db_print_sostate(short so_state)
155 if (so_state & SS_NOFDREF) {
156 db_printf("%sSS_NOFDREF", comma ? ", " : "");
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 ? ", " : "");
183 if (so_state & SS_PROTOREF) {
184 db_printf("%sSS_PROTOREF", comma ? ", " : "");
190 db_print_soqstate(int so_qstate)
195 if (so_qstate & SQ_INCOMP) {
196 db_printf("%sSQ_INCOMP", comma ? ", " : "");
199 if (so_qstate & SQ_COMP) {
200 db_printf("%sSQ_COMP", comma ? ", " : "");
206 db_print_sbstate(short sb_state)
211 if (sb_state & SBS_CANTSENDMORE) {
212 db_printf("%sSS_CANTSENDMORE", comma ? ", " : "");
215 if (sb_state & SBS_CANTRCVMORE) {
216 db_printf("%sSS_CANTRCVMORE", comma ? ", " : "");
219 if (sb_state & SBS_RCVATMARK) {
220 db_printf("%sSS_RCVATMARK", comma ? ", " : "");
226 db_print_indent(int indent)
230 for (i = 0; i < indent; i++)
235 db_print_domain(struct domain *d, const char *domain_name, int indent)
238 db_print_indent(indent);
239 db_printf("%s at %p\n", domain_name, d);
243 db_print_indent(indent);
244 db_printf("dom_family: %d ", d->dom_family);
245 db_printf("dom_name: %s\n", d->dom_name);
247 db_print_indent(indent);
248 db_printf("dom_init: %p ", d->dom_init);
249 db_printf("dom_externalize: %p ", d->dom_externalize);
250 db_printf("dom_dispose: %p\n", d->dom_dispose);
252 db_print_indent(indent);
253 db_printf("dom_protosw: %p ", d->dom_protosw);
254 db_printf("dom_next: %p\n", d->dom_next);
256 db_print_indent(indent);
257 db_printf("dom_rtattach: %p ", d->dom_rtattach);
258 db_printf("dom_rtoffset: %d ", d->dom_rtoffset);
259 db_printf("dom_maxrtkey: %d\n", d->dom_maxrtkey);
261 db_print_indent(indent);
262 db_printf("dom_ifattach: %p ", d->dom_ifattach);
263 db_printf("dom_ifdetach: %p\n", d->dom_ifdetach);
267 db_print_prflags(short pr_flags)
272 if (pr_flags & PR_ATOMIC) {
273 db_printf("%sPR_ATOMIC", comma ? ", " : "");
276 if (pr_flags & PR_ADDR) {
277 db_printf("%sPR_ADDR", comma ? ", " : "");
280 if (pr_flags & PR_CONNREQUIRED) {
281 db_printf("%sPR_CONNREQUIRED", comma ? ", " : "");
284 if (pr_flags & PR_WANTRCVD) {
285 db_printf("%sPR_WANTRCVD", comma ? ", " : "");
288 if (pr_flags & PR_RIGHTS) {
289 db_printf("%sPR_RIGHTS", comma ? ", " : "");
292 if (pr_flags & PR_IMPLOPCL) {
293 db_printf("%sPR_IMPLOPCL", comma ? ", " : "");
296 if (pr_flags & PR_LASTHDR) {
297 db_printf("%sPR_LASTHDR", comma ? ", " : "");
303 db_print_protosw(struct protosw *pr, const char *prname, int indent)
306 db_print_indent(indent);
307 db_printf("%s at %p\n", prname, pr);
311 db_print_indent(indent);
312 db_printf("pr_type: %d ", pr->pr_type);
313 db_printf("pr_domain: %p\n", pr->pr_domain);
314 if (pr->pr_domain != NULL)
315 db_print_domain(pr->pr_domain, "pr_domain", indent);
317 db_print_indent(indent);
318 db_printf("pr_protocol: %d\n", pr->pr_protocol);
320 db_print_indent(indent);
321 db_printf("pr_flags: %d (", pr->pr_flags);
322 db_print_prflags(pr->pr_flags);
325 db_print_indent(indent);
326 db_printf("pr_input: %p ", pr->pr_input);
327 db_printf("pr_output: %p ", pr->pr_output);
328 db_printf("pr_ctlinput: %p\n", pr->pr_ctlinput);
330 db_print_indent(indent);
331 db_printf("pr_ctloutput: %p ", pr->pr_ctloutput);
332 db_printf("pr_init: %p\n", pr->pr_init);
334 db_print_indent(indent);
335 db_printf("pr_fasttimo: %p ", pr->pr_fasttimo);
336 db_printf("pr_slowtimo: %p ", pr->pr_slowtimo);
337 db_printf("pr_drain: %p\n", pr->pr_drain);
339 db_print_indent(indent);
343 db_print_sbflags(short sb_flags)
348 if (sb_flags & SB_WAIT) {
349 db_printf("%sSB_WAIT", comma ? ", " : "");
352 if (sb_flags & SB_SEL) {
353 db_printf("%sSB_SEL", comma ? ", " : "");
356 if (sb_flags & SB_ASYNC) {
357 db_printf("%sSB_ASYNC", comma ? ", " : "");
360 if (sb_flags & SB_UPCALL) {
361 db_printf("%sSB_UPCALL", comma ? ", " : "");
364 if (sb_flags & SB_NOINTR) {
365 db_printf("%sSB_NOINTR", comma ? ", " : "");
368 if (sb_flags & SB_AIO) {
369 db_printf("%sSB_AIO", comma ? ", " : "");
372 if (sb_flags & SB_KNOTE) {
373 db_printf("%sSB_KNOTE", comma ? ", " : "");
376 if (sb_flags & SB_AUTOSIZE) {
377 db_printf("%sSB_AUTOSIZE", comma ? ", " : "");
383 db_print_sockbuf(struct sockbuf *sb, const char *sockbufname, int indent)
386 db_print_indent(indent);
387 db_printf("%s at %p\n", sockbufname, sb);
391 db_print_indent(indent);
392 db_printf("sb_state: 0x%x (", sb->sb_state);
393 db_print_sbstate(sb->sb_state);
396 db_print_indent(indent);
397 db_printf("sb_mb: %p ", sb->sb_mb);
398 db_printf("sb_mbtail: %p ", sb->sb_mbtail);
399 db_printf("sb_lastrecord: %p\n", sb->sb_lastrecord);
401 db_print_indent(indent);
402 db_printf("sb_sndptr: %p ", sb->sb_sndptr);
403 db_printf("sb_sndptroff: %u\n", sb->sb_sndptroff);
405 db_print_indent(indent);
406 db_printf("sb_cc: %u ", sb->sb_cc);
407 db_printf("sb_hiwat: %u ", sb->sb_hiwat);
408 db_printf("sb_mbcnt: %u ", sb->sb_mbcnt);
409 db_printf("sb_mbmax: %u\n", sb->sb_mbmax);
411 db_print_indent(indent);
412 db_printf("sb_ctl: %u ", sb->sb_ctl);
413 db_printf("sb_lowat: %d ", sb->sb_lowat);
414 db_printf("sb_timeo: %d\n", sb->sb_timeo);
416 db_print_indent(indent);
417 db_printf("sb_flags: 0x%x (", sb->sb_flags);
418 db_print_sbflags(sb->sb_flags);
423 db_print_socket(struct socket *so, const char *socketname, int indent)
426 db_print_indent(indent);
427 db_printf("%s at %p\n", socketname, so);
431 db_print_indent(indent);
432 db_printf("so_count: %d ", so->so_count);
433 db_printf("so_type: %d (", so->so_type);
434 db_print_sotype(so->so_type);
437 db_print_indent(indent);
438 db_printf("so_options: 0x%x (", so->so_options);
439 db_print_sooptions(so->so_options);
442 db_print_indent(indent);
443 db_printf("so_linger: %d ", so->so_linger);
444 db_printf("so_state: 0x%x (", so->so_state);
445 db_print_sostate(so->so_state);
448 db_print_indent(indent);
449 db_printf("so_qstate: 0x%x (", so->so_qstate);
450 db_print_soqstate(so->so_qstate);
452 db_printf("so_pcb: %p ", so->so_pcb);
453 db_printf("so_proto: %p\n", so->so_proto);
455 if (so->so_proto != NULL)
456 db_print_protosw(so->so_proto, "so_proto", indent);
458 db_print_indent(indent);
459 db_printf("so_head: %p ", so->so_head);
460 db_printf("so_incomp first: %p ", TAILQ_FIRST(&so->so_incomp));
461 db_printf("so_comp first: %p\n", TAILQ_FIRST(&so->so_comp));
463 db_print_indent(indent);
464 /* so_list skipped */
465 db_printf("so_qlen: %d ", so->so_qlen);
466 db_printf("so_incqlen: %d ", so->so_incqlen);
467 db_printf("so_qlimit: %d ", so->so_qlimit);
468 db_printf("so_timeo: %d ", so->so_timeo);
469 db_printf("so_error: %d\n", so->so_error);
471 db_print_indent(indent);
472 db_printf("so_sigio: %p ", so->so_sigio);
473 db_printf("so_oobmark: %lu ", so->so_oobmark);
474 db_printf("so_aiojobq first: %p\n", TAILQ_FIRST(&so->so_aiojobq));
476 db_print_sockbuf(&so->so_rcv, "so_rcv", indent);
477 db_print_sockbuf(&so->so_snd, "so_snd", indent);
480 DB_SHOW_COMMAND(socket, db_show_socket)
485 db_printf("usage: show socket <addr>\n");
488 so = (struct socket *)addr;
490 db_print_socket(so, "socket", 0);
493 DB_SHOW_COMMAND(sockbuf, db_show_sockbuf)
498 db_printf("usage: show sockbuf <addr>\n");
501 sb = (struct sockbuf *)addr;
503 db_print_sockbuf(sb, "sockbuf", 0);
506 DB_SHOW_COMMAND(protosw, db_show_protosw)
511 db_printf("usage: show protosw <addr>\n");
514 pr = (struct protosw *)addr;
516 db_print_protosw(pr, "protosw", 0);
519 DB_SHOW_COMMAND(domain, db_show_domain)
524 db_printf("usage: show protosw <addr>\n");
527 d = (struct domain *)addr;
529 db_print_domain(d, "domain", 0);