1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <sys/stream.h> 31 #include <sys/mdb_modapi.h> 32 #include <sys/socket.h> 33 #include <sys/list.h> 34 #include <sys/strsun.h> 35 36 #include <mdb/mdb_stdlib.h> 37 38 #include <netinet/in.h> 39 #include <netinet/ip6.h> 40 #include <netinet/sctp.h> 41 42 #include <inet/common.h> 43 #include <inet/ip.h> 44 #include <inet/ip6.h> 45 #include <inet/ipclassifier.h> 46 47 #include <sctp/sctp_impl.h> 48 #include <sctp/sctp_addr.h> 49 50 #define MDB_SCTP_SHOW_FLAGS 0x1 51 #define MDB_SCTP_DUMP_ADDRS 0x2 52 #define MDB_SCTP_SHOW_HASH 0x4 53 #define MDB_SCTP_SHOW_OUT 0x8 54 #define MDB_SCTP_SHOW_IN 0x10 55 #define MDB_SCTP_SHOW_MISC 0x20 56 #define MDB_SCTP_SHOW_RTT 0x40 57 #define MDB_SCTP_SHOW_STATS 0x80 58 #define MDB_SCTP_SHOW_FLOW 0x100 59 #define MDB_SCTP_SHOW_HDR 0x200 60 #define MDB_SCTP_SHOW_PMTUD 0x400 61 #define MDB_SCTP_SHOW_RXT 0x800 62 #define MDB_SCTP_SHOW_CONN 0x1000 63 #define MDB_SCTP_SHOW_CLOSE 0x2000 64 #define MDB_SCTP_SHOW_EXT 0x4000 65 66 #define MDB_SCTP_SHOW_ALL 0xffffffff 67 68 /* 69 * Copy from usr/src/uts/common/os/list.c. Should we have a generic 70 * mdb list walker? 71 */ 72 #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset)) 73 74 static int 75 ns_to_stackid(uintptr_t kaddr) 76 { 77 netstack_t nss; 78 79 if (mdb_vread(&nss, sizeof (nss), kaddr) == -1) { 80 mdb_warn("failed to read netdstack info %p", kaddr); 81 return (0); 82 } 83 return (nss.netstack_stackid); 84 } 85 86 int 87 sctp_stacks_walk_init(mdb_walk_state_t *wsp) 88 { 89 if (mdb_layered_walk("netstack", wsp) == -1) { 90 mdb_warn("can't walk 'netstack'"); 91 return (WALK_ERR); 92 } 93 return (WALK_NEXT); 94 } 95 96 int 97 sctp_stacks_walk_step(mdb_walk_state_t *wsp) 98 { 99 uintptr_t kaddr; 100 netstack_t nss; 101 102 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) { 103 mdb_warn("can't read netstack at %p", wsp->walk_addr); 104 return (WALK_ERR); 105 } 106 kaddr = (uintptr_t)nss.netstack_modules[NS_SCTP]; 107 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata)); 108 } 109 110 static char * 111 sctp_faddr_state(int state) 112 { 113 char *statestr; 114 115 switch (state) { 116 case SCTP_FADDRS_UNREACH: 117 statestr = "Unreachable"; 118 break; 119 case SCTP_FADDRS_DOWN: 120 statestr = "Down"; 121 break; 122 case SCTP_FADDRS_ALIVE: 123 statestr = "Alive"; 124 break; 125 case SCTP_FADDRS_UNCONFIRMED: 126 statestr = "Unconfirmed"; 127 break; 128 default: 129 statestr = "Unknown"; 130 break; 131 } 132 return (statestr); 133 } 134 135 /* ARGSUSED */ 136 static int 137 sctp_faddr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 138 { 139 sctp_faddr_t fa[1]; 140 char *statestr; 141 142 if (!(flags & DCMD_ADDRSPEC)) 143 return (DCMD_USAGE); 144 145 if (mdb_vread(fa, sizeof (*fa), addr) == -1) { 146 mdb_warn("cannot read fadder at %p", addr); 147 return (DCMD_ERR); 148 } 149 150 statestr = sctp_faddr_state(fa->state); 151 mdb_printf("%<u>%p\t%<b>%N%</b>\t%s%</u>\n", addr, &fa->faddr, 152 statestr); 153 mdb_printf("next\t\t%?p\tsaddr\t%N\n", fa->next, &fa->saddr); 154 mdb_printf("rto\t\t%?d\tsrtt\t\t%?d\n", fa->rto, fa->srtt); 155 mdb_printf("rttvar\t\t%?d\trtt_updates\t%?u\n", fa->rttvar, 156 fa->rtt_updates); 157 mdb_printf("strikes\t\t%?d\tmax_retr\t%?d\n", fa->strikes, 158 fa->max_retr); 159 mdb_printf("hb_expiry\t%?ld\thb_interval\t%?u\n", fa->hb_expiry, 160 fa->hb_interval); 161 mdb_printf("pmss\t\t%?u\tcwnd\t\t%?u\n", fa->sfa_pmss, fa->cwnd); 162 mdb_printf("ssthresh\t%?u\tsuna\t\t%?u\n", fa->ssthresh, fa->suna); 163 mdb_printf("pba\t\t%?u\tacked\t\t%?u\n", fa->pba, fa->acked); 164 mdb_printf("lastactive\t%?ld\thb_secret\t%?#lx\n", fa->lastactive, 165 fa->hb_secret); 166 mdb_printf("rxt_unacked\t\t%?u\n", fa->rxt_unacked); 167 mdb_printf("timer_mp\t%?p\tire\t\t%?p\n", fa->timer_mp, fa->ire); 168 mdb_printf("hb_pending\t%?d\ttimer_running\t%?d\n" 169 "df\t\t%?d\tpmtu_discovered\t%?d\n" 170 "isv4\t\t%?d\tretransmissions\t%?u\n", 171 fa->hb_pending, fa->timer_running, fa->df, fa->pmtu_discovered, 172 fa->isv4, fa->T3expire); 173 174 return (DCMD_OK); 175 } 176 177 static void 178 print_set(sctp_set_t *sp) 179 { 180 mdb_printf("\tbegin\t%<b>%?x%</b>\t\tend\t%<b>%?x%</b>\n", 181 sp->begin, sp->end); 182 mdb_printf("\tnext\t%?p\tprev\t%?p\n", sp->next, sp->prev); 183 } 184 185 /* ARGSUSED */ 186 static int 187 sctp_set(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 188 { 189 sctp_set_t sp[1]; 190 191 if (!(flags & DCMD_ADDRSPEC)) 192 return (DCMD_USAGE); 193 194 if (mdb_vread(sp, sizeof (*sp), addr) == -1) 195 return (DCMD_ERR); 196 197 print_set(sp); 198 199 return (DCMD_OK); 200 } 201 202 static void 203 dump_sack_info(uintptr_t addr) 204 { 205 sctp_set_t sp[1]; 206 207 while (addr != 0) { 208 if (mdb_vread(sp, sizeof (*sp), addr) == -1) { 209 mdb_warn("failed to read sctp_set at %p", addr); 210 return; 211 } 212 213 addr = (uintptr_t)sp->next; 214 print_set(sp); 215 } 216 } 217 218 static int 219 dump_msghdr(mblk_t *meta) 220 { 221 sctp_msg_hdr_t smh; 222 223 if (mdb_vread(&smh, sizeof (smh), (uintptr_t)meta->b_rptr) == -1) 224 return (-1); 225 226 mdb_printf("%<u>msg_hdr_t at \t%?p\tsentto\t%?p%</u>\n", 227 meta->b_rptr, SCTP_CHUNK_DEST(meta)); 228 mdb_printf("\tttl\t%?ld\ttob\t%?ld\n", smh.smh_ttl, smh.smh_tob); 229 mdb_printf("\tsid\t%?u\tssn\t%?u\n", smh.smh_sid, smh.smh_ssn); 230 mdb_printf("\tppid\t%?u\tflags\t%?s\n", smh.smh_ppid, 231 smh.smh_flags & MSG_UNORDERED ? "unordered" : " "); 232 mdb_printf("\tcontext\t%?u\tmsglen\t%?d\n", smh.smh_context, 233 smh.smh_msglen); 234 235 return (0); 236 } 237 238 static int 239 dump_datahdr(mblk_t *mp) 240 { 241 sctp_data_hdr_t sdc; 242 uint16_t sdh_int16; 243 uint32_t sdh_int32; 244 245 if (mdb_vread(&sdc, sizeof (sdc), (uintptr_t)mp->b_rptr) == -1) 246 return (-1); 247 248 mdb_printf("%<u>data_chunk_t \t%?p\tsentto\t%?p%</u>\n", 249 mp->b_rptr, SCTP_CHUNK_DEST(mp)); 250 mdb_printf("\tsent\t%?d\t", SCTP_CHUNK_ISSENT(mp)?1:0); 251 mdb_printf("retrans\t%?d\n", SCTP_CHUNK_WANT_REXMIT(mp)?1:0); 252 mdb_printf("\tacked\t%?d\t", SCTP_CHUNK_ISACKED(mp)?1:0); 253 mdb_printf("sackcnt\t%?u\n", SCTP_CHUNK_SACKCNT(mp)); 254 255 mdb_nhconvert(&sdh_int16, &sdc.sdh_len, sizeof (sdc.sdh_len)); 256 mdb_printf("\tlen\t%?d\t", sdh_int16); 257 mdb_printf("BBIT=%d", SCTP_DATA_GET_BBIT(&sdc) == 0 ? 0 : 1); 258 mdb_printf("EBIT=%d", SCTP_DATA_GET_EBIT(&sdc) == 0 ? 0 : 1); 259 260 mdb_nhconvert(&sdh_int32, &sdc.sdh_tsn, sizeof (sdc.sdh_tsn)); 261 mdb_nhconvert(&sdh_int16, &sdc.sdh_sid, sizeof (sdc.sdh_sid)); 262 mdb_printf("\ttsn\t%?x\tsid\t%?hu\n", sdh_int32, sdh_int16); 263 264 mdb_nhconvert(&sdh_int16, &sdc.sdh_ssn, sizeof (sdc.sdh_ssn)); 265 mdb_nhconvert(&sdh_int32, &sdc.sdh_payload_id, 266 sizeof (sdc.sdh_payload_id)); 267 mdb_printf("\tssn\t%?hu\tppid\t%?d\n", sdh_int16, sdh_int32); 268 269 return (0); 270 } 271 272 static int 273 sctp_sent_list(mblk_t *addr) 274 { 275 mblk_t meta, mp; 276 277 if (!addr) 278 return (0); 279 280 if (mdb_vread(&meta, sizeof (meta), (uintptr_t)addr) == -1) 281 return (-1); 282 283 for (;;) { 284 dump_msghdr(&meta); 285 286 if (meta.b_cont == NULL) { 287 mdb_printf("No data chunks with message header!\n"); 288 return (-1); 289 } 290 if (mdb_vread(&mp, sizeof (mp), 291 (uintptr_t)meta.b_cont) == -1) { 292 return (-1); 293 } 294 for (;;) { 295 dump_datahdr(&mp); 296 if (!mp.b_next) 297 break; 298 299 if (mdb_vread(&mp, sizeof (mp), 300 (uintptr_t)(mp.b_next)) == -1) 301 return (-1); 302 } 303 if (meta.b_next == NULL) 304 break; 305 if (mdb_vread(&meta, sizeof (meta), 306 (uintptr_t)meta.b_next) == -1) 307 return (-1); 308 } 309 310 return (0); 311 } 312 313 static int 314 sctp_unsent_list(mblk_t *addr) 315 { 316 mblk_t meta; 317 318 if (!addr) 319 return (0); 320 321 if (mdb_vread(&meta, sizeof (meta), (uintptr_t)addr) == -1) 322 return (-1); 323 324 for (;;) { 325 dump_msghdr(&meta); 326 327 if (meta.b_next == NULL) 328 break; 329 330 if (mdb_vread(&meta, sizeof (meta), 331 (uintptr_t)meta.b_next) == -1) 332 return (-1); 333 } 334 335 return (0); 336 } 337 338 /* ARGSUSED */ 339 static int 340 sctp_xmit_list(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 341 { 342 sctp_t sctp; 343 344 if (!(flags & DCMD_ADDRSPEC)) 345 return (DCMD_USAGE); 346 347 if (mdb_vread(&sctp, sizeof (sctp), addr) == -1) 348 return (DCMD_ERR); 349 350 mdb_printf("%<b>Chunkified TX list%</b>\n"); 351 if (sctp_sent_list(sctp.sctp_xmit_head) < 0) 352 return (DCMD_ERR); 353 354 mdb_printf("%<b>Unchunkified TX list%</b>\n"); 355 if (sctp_unsent_list(sctp.sctp_xmit_unsent) < 0) 356 return (DCMD_ERR); 357 358 return (DCMD_OK); 359 } 360 361 /* ARGSUSED */ 362 static int 363 sctp_mdata_chunk(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 364 { 365 sctp_data_hdr_t dc; 366 mblk_t mp; 367 368 if (!(flags & DCMD_ADDRSPEC)) 369 return (DCMD_USAGE); 370 371 if (mdb_vread(&mp, sizeof (mp), addr) == -1) 372 return (DCMD_ERR); 373 374 if (mdb_vread(&dc, sizeof (dc), (uintptr_t)mp.b_rptr) == -1) 375 return (DCMD_ERR); 376 377 mdb_printf("%<b>%-?p%</b>tsn\t%?x\tsid\t%?hu\n", addr, 378 dc.sdh_tsn, dc.sdh_sid); 379 mdb_printf("%-?sssn\t%?hu\tppid\t%?x\n", "", dc.sdh_ssn, 380 dc.sdh_payload_id); 381 382 return (DCMD_OK); 383 } 384 385 /* ARGSUSED */ 386 static int 387 sctp_istr_msgs(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 388 { 389 mblk_t istrmp; 390 mblk_t dmp; 391 sctp_data_hdr_t dp; 392 uintptr_t daddr; 393 uintptr_t chaddr; 394 boolean_t bbit; 395 boolean_t ebit; 396 397 if (!(flags & DCMD_ADDRSPEC)) 398 return (DCMD_USAGE); 399 400 do { 401 if (mdb_vread(&istrmp, sizeof (istrmp), addr) == -1) 402 return (DCMD_ERR); 403 404 mdb_printf("\tistr mblk at %p: next: %?p\n" 405 "\t\tprev: %?p\tcont: %?p\n", addr, istrmp.b_next, 406 istrmp.b_prev, istrmp.b_cont); 407 daddr = (uintptr_t)&istrmp; 408 do { 409 if (mdb_vread(&dmp, sizeof (dmp), daddr) == -1) 410 break; 411 chaddr = (uintptr_t)dmp.b_rptr; 412 if (mdb_vread(&dp, sizeof (dp), chaddr) == -1) 413 break; 414 415 bbit = (SCTP_DATA_GET_BBIT(&dp) != 0); 416 ebit = (SCTP_DATA_GET_EBIT(&dp) != 0); 417 418 mdb_printf("\t\t\ttsn: %x bbit: %d ebit: %d\n", 419 dp.sdh_tsn, bbit, ebit); 420 421 422 daddr = (uintptr_t)dmp.b_cont; 423 } while (daddr != NULL); 424 425 addr = (uintptr_t)istrmp.b_next; 426 } while (addr != NULL); 427 428 return (DCMD_OK); 429 } 430 431 /* ARGSUSED */ 432 static int 433 sctp_reass_list(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 434 { 435 sctp_reass_t srp; 436 mblk_t srpmp; 437 sctp_data_hdr_t dp; 438 mblk_t dmp; 439 uintptr_t daddr; 440 uintptr_t chaddr; 441 boolean_t bbit, ebit; 442 443 if (!(flags & DCMD_ADDRSPEC)) 444 return (DCMD_USAGE); 445 446 do { 447 if (mdb_vread(&srpmp, sizeof (srpmp), addr) == -1) 448 return (DCMD_ERR); 449 450 if (mdb_vread(&srp, sizeof (srp), 451 (uintptr_t)srpmp.b_datap->db_base) == -1) 452 return (DCMD_ERR); 453 454 mdb_printf("\treassembly mblk at %p: next: %?p\n" 455 "\t\tprev: %?p\tcont: %?p\n", addr, srpmp.b_next, 456 srpmp.b_prev, srpmp.b_cont); 457 mdb_printf("\t\tssn: %hu\tneeded: %hu\tgot: %hu\ttail: %?p\n" 458 "\t\tpartial_delivered: %s\n", srp.ssn, srp.needed, 459 srp.got, srp.tail, srp.partial_delivered ? "TRUE" : 460 "FALSE"); 461 462 /* display the contents of this ssn's reassemby list */ 463 daddr = DB_TYPE(&srpmp) == M_CTL ? (uintptr_t)srpmp.b_cont : 464 (uintptr_t)&srpmp; 465 do { 466 if (mdb_vread(&dmp, sizeof (dmp), daddr) == -1) 467 break; 468 chaddr = (uintptr_t)dmp.b_rptr; 469 if (mdb_vread(&dp, sizeof (dp), chaddr) == -1) 470 break; 471 472 bbit = (SCTP_DATA_GET_BBIT(&dp) != 0); 473 ebit = (SCTP_DATA_GET_EBIT(&dp) != 0); 474 475 mdb_printf("\t\t\ttsn: %x bbit: %d ebit: %d\n", 476 dp.sdh_tsn, bbit, ebit); 477 478 daddr = (uintptr_t)dmp.b_cont; 479 } while (daddr != NULL); 480 481 addr = (uintptr_t)srpmp.b_next; 482 } while (addr != NULL); 483 484 return (DCMD_OK); 485 } 486 487 /* ARGSUSED */ 488 static int 489 sctp_uo_reass_list(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 490 { 491 sctp_data_hdr_t dp; 492 mblk_t dmp; 493 uintptr_t chaddr; 494 boolean_t bbit; 495 boolean_t ebit; 496 boolean_t ubit; 497 498 if (!(flags & DCMD_ADDRSPEC)) 499 return (DCMD_USAGE); 500 501 do { 502 if (mdb_vread(&dmp, sizeof (dmp), addr) == -1) 503 return (DCMD_ERR); 504 505 mdb_printf("\treassembly mblk at %p: next: %?p\n" 506 "\t\tprev: %?p\n", addr, dmp.b_next, dmp.b_prev); 507 508 chaddr = (uintptr_t)dmp.b_rptr; 509 if (mdb_vread(&dp, sizeof (dp), chaddr) == -1) 510 break; 511 512 bbit = (SCTP_DATA_GET_BBIT(&dp) != 0); 513 ebit = (SCTP_DATA_GET_EBIT(&dp) != 0); 514 ubit = (SCTP_DATA_GET_UBIT(&dp) != 0); 515 516 mdb_printf("\t\t\tsid: %hu ssn: %hu tsn: %x " 517 "flags: %x (U=%d B=%d E=%d)\n", dp.sdh_sid, dp.sdh_ssn, 518 dp.sdh_tsn, dp.sdh_flags, ubit, bbit, ebit); 519 520 addr = (uintptr_t)dmp.b_next; 521 } while (addr != NULL); 522 523 return (DCMD_OK); 524 } 525 526 static int 527 sctp_instr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 528 { 529 sctp_instr_t sip; 530 531 if (!(flags & DCMD_ADDRSPEC)) 532 return (DCMD_USAGE); 533 534 if (mdb_vread(&sip, sizeof (sip), addr) == -1) 535 return (DCMD_ERR); 536 537 mdb_printf("%<b>%-?p%</b>\n\tmsglist\t%?p\tnmsgs\t%?d\n" 538 "\tnextseq\t%?d\treass\t%?p\n", addr, sip.istr_msgs, 539 sip.istr_nmsgs, sip.nextseq, sip.istr_reass); 540 mdb_set_dot(addr + sizeof (sip)); 541 542 return (sctp_reass_list((uintptr_t)sip.istr_reass, flags, ac, av)); 543 } 544 545 static const char * 546 state2str(sctp_t *sctp) 547 { 548 switch (sctp->sctp_state) { 549 case SCTPS_IDLE: return ("SCTPS_IDLE"); 550 case SCTPS_BOUND: return ("SCTPS_BOUND"); 551 case SCTPS_LISTEN: return ("SCTPS_LISTEN"); 552 case SCTPS_COOKIE_WAIT: return ("SCTPS_COOKIE_WAIT"); 553 case SCTPS_COOKIE_ECHOED: return ("SCTPS_COOKIE_ECHOED"); 554 case SCTPS_ESTABLISHED: return ("SCTPS_ESTABLISHED"); 555 case SCTPS_SHUTDOWN_PENDING: return ("SCTPS_SHUTDOWN_PENDING"); 556 case SCTPS_SHUTDOWN_SENT: return ("SCTPS_SHUTDOWN_SENT"); 557 case SCTPS_SHUTDOWN_RECEIVED: return ("SCTPS_SHUTDOWN_RECEIVED"); 558 case SCTPS_SHUTDOWN_ACK_SENT: return ("SCTPS_SHUTDOWN_ACK_SENT"); 559 default: return ("UNKNOWN STATE"); 560 } 561 } 562 563 static void 564 show_sctp_flags(sctp_t *sctp) 565 { 566 mdb_printf("\tunderstands_asconf\t%d\n", 567 sctp->sctp_understands_asconf); 568 mdb_printf("\tdebug\t\t\t%d\n", sctp->sctp_debug); 569 mdb_printf("\tcchunk_pend\t\t%d\n", sctp->sctp_cchunk_pend); 570 mdb_printf("\tdgram_errind\t\t%d\n", sctp->sctp_dgram_errind); 571 572 mdb_printf("\tlinger\t\t\t%d\n", sctp->sctp_linger); 573 if (sctp->sctp_lingering) 574 return; 575 mdb_printf("\tlingering\t\t%d\n", sctp->sctp_lingering); 576 mdb_printf("\tloopback\t\t%d\n", sctp->sctp_loopback); 577 mdb_printf("\tforce_sack\t\t%d\n", sctp->sctp_force_sack); 578 579 mdb_printf("\tack_timer_runing\t%d\n", sctp->sctp_ack_timer_running); 580 mdb_printf("\trecvdstaddr\t\t%d\n", sctp->sctp_recvdstaddr); 581 mdb_printf("\thwcksum\t\t\t%d\n", sctp->sctp_hwcksum); 582 mdb_printf("\tunderstands_addip\t%d\n", sctp->sctp_understands_addip); 583 584 mdb_printf("\tbound_to_all\t\t%d\n", sctp->sctp_bound_to_all); 585 mdb_printf("\tcansleep\t\t%d\n", sctp->sctp_cansleep); 586 mdb_printf("\tdetached\t\t%d\n", sctp->sctp_detached); 587 mdb_printf("\tsend_adaption\t\t%d\n", sctp->sctp_send_adaption); 588 589 mdb_printf("\trecv_adaption\t\t%d\n", sctp->sctp_recv_adaption); 590 mdb_printf("\tndelay\t\t\t%d\n", sctp->sctp_ndelay); 591 mdb_printf("\tcondemned\t\t%d\n", sctp->sctp_condemned); 592 mdb_printf("\tchk_fast_rexmit\t\t%d\n", sctp->sctp_chk_fast_rexmit); 593 594 mdb_printf("\tprsctp_aware\t\t%d\n", sctp->sctp_prsctp_aware); 595 mdb_printf("\tlinklocal\t\t%d\n", sctp->sctp_linklocal); 596 mdb_printf("\trexmitting\t\t%d\n", sctp->sctp_rexmitting); 597 mdb_printf("\tzero_win_probe\t\t%d\n", sctp->sctp_zero_win_probe); 598 599 mdb_printf("\trecvsndrcvinfo\t\t%d\n", sctp->sctp_recvsndrcvinfo); 600 mdb_printf("\trecvassocevnt\t\t%d\n", sctp->sctp_recvassocevnt); 601 mdb_printf("\trecvpathevnt\t\t%d\n", sctp->sctp_recvpathevnt); 602 mdb_printf("\trecvsendfailevnt\t%d\n", sctp->sctp_recvsendfailevnt); 603 604 mdb_printf("\trecvpeerevnt\t\t%d\n", sctp->sctp_recvpeererr); 605 mdb_printf("\trecvchutdownevnt\t%d\n", sctp->sctp_recvshutdownevnt); 606 mdb_printf("\trecvcpdnevnt\t\t%d\n", sctp->sctp_recvpdevnt); 607 mdb_printf("\trecvcalevnt\t\t%d\n\n", sctp->sctp_recvalevnt); 608 } 609 610 /* 611 * Given a sctp_saddr_ipif_t, print out its address. This assumes 612 * that addr contains the sctp_addr_ipif_t structure already and this 613 * function does not need to read it in. 614 */ 615 /* ARGSUSED */ 616 static int 617 print_saddr(uintptr_t ptr, const void *addr, void *cbdata) 618 { 619 sctp_saddr_ipif_t *saddr = (sctp_saddr_ipif_t *)addr; 620 sctp_ipif_t ipif; 621 char *statestr; 622 623 /* Read in the sctp_ipif object */ 624 if (mdb_vread(&ipif, sizeof (ipif), (uintptr_t)saddr->saddr_ipifp) == 625 -1) { 626 mdb_warn("cannot read ipif at %p", saddr->saddr_ipifp); 627 return (WALK_ERR); 628 } 629 630 switch (ipif.sctp_ipif_state) { 631 case SCTP_IPIFS_CONDEMNED: 632 statestr = "Condemned"; 633 break; 634 case SCTP_IPIFS_INVALID: 635 statestr = "Invalid"; 636 break; 637 case SCTP_IPIFS_DOWN: 638 statestr = "Down"; 639 break; 640 case SCTP_IPIFS_UP: 641 statestr = "Up"; 642 break; 643 default: 644 statestr = "Unknown"; 645 break; 646 } 647 mdb_printf("\t%p\t%N% (%s", saddr->saddr_ipifp, &ipif.sctp_ipif_saddr, 648 statestr); 649 if (saddr->saddr_ipif_dontsrc == 1) 650 mdb_printf("/Dontsrc"); 651 if (saddr->saddr_ipif_unconfirmed == 1) 652 mdb_printf("/Unconfirmed"); 653 if (saddr->saddr_ipif_delete_pending == 1) 654 mdb_printf("/DeletePending"); 655 mdb_printf(")\n"); 656 mdb_printf("\t\t\tMTU %d id %d zoneid %d IPIF flags %x\n", 657 ipif.sctp_ipif_mtu, ipif.sctp_ipif_id, 658 ipif.sctp_ipif_zoneid, ipif.sctp_ipif_flags); 659 return (WALK_NEXT); 660 } 661 662 /* 663 * Given a sctp_faddr_t, print out its address. This assumes that 664 * addr contains the sctp_faddr_t structure already and this function 665 * does not need to read it in. 666 */ 667 static int 668 print_faddr(uintptr_t ptr, const void *addr, void *cbdata) 669 { 670 char *statestr; 671 sctp_faddr_t *faddr = (sctp_faddr_t *)addr; 672 int *i = cbdata; 673 674 statestr = sctp_faddr_state(faddr->state); 675 676 mdb_printf("\t%d:\t%N\t%?p (%s)\n", (*i)++, &faddr->faddr, ptr, 677 statestr); 678 return (WALK_NEXT); 679 } 680 681 int 682 sctp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 683 { 684 sctp_t sctp; 685 conn_t connp; 686 int i; 687 uint_t opts = 0; 688 uint_t paddr = 0; 689 in_port_t lport, fport; 690 691 if (!(flags & DCMD_ADDRSPEC)) 692 return (DCMD_USAGE); 693 694 if (mdb_vread(&sctp, sizeof (sctp), addr) == -1) { 695 mdb_warn("failed to read sctp_t at: %p\n", addr); 696 return (DCMD_ERR); 697 } 698 if (mdb_vread(&connp, sizeof (connp), 699 (uintptr_t)sctp.sctp_connp) == -1) { 700 mdb_warn("failed to read conn_t at: %p\n", sctp.sctp_connp); 701 return (DCMD_ERR); 702 } 703 704 if (mdb_getopts(argc, argv, 705 'a', MDB_OPT_SETBITS, MDB_SCTP_SHOW_ALL, &opts, 706 'f', MDB_OPT_SETBITS, MDB_SCTP_SHOW_FLAGS, &opts, 707 'h', MDB_OPT_SETBITS, MDB_SCTP_SHOW_HASH, &opts, 708 'o', MDB_OPT_SETBITS, MDB_SCTP_SHOW_OUT, &opts, 709 'i', MDB_OPT_SETBITS, MDB_SCTP_SHOW_IN, &opts, 710 'm', MDB_OPT_SETBITS, MDB_SCTP_SHOW_MISC, &opts, 711 'r', MDB_OPT_SETBITS, MDB_SCTP_SHOW_RTT, &opts, 712 'S', MDB_OPT_SETBITS, MDB_SCTP_SHOW_STATS, &opts, 713 'F', MDB_OPT_SETBITS, MDB_SCTP_SHOW_FLOW, &opts, 714 'H', MDB_OPT_SETBITS, MDB_SCTP_SHOW_HDR, &opts, 715 'p', MDB_OPT_SETBITS, MDB_SCTP_SHOW_PMTUD, &opts, 716 'R', MDB_OPT_SETBITS, MDB_SCTP_SHOW_RXT, &opts, 717 'C', MDB_OPT_SETBITS, MDB_SCTP_SHOW_CONN, &opts, 718 'c', MDB_OPT_SETBITS, MDB_SCTP_SHOW_CLOSE, &opts, 719 'e', MDB_OPT_SETBITS, MDB_SCTP_SHOW_EXT, &opts, 720 'P', MDB_OPT_SETBITS, 1, &paddr, 721 'd', MDB_OPT_SETBITS, MDB_SCTP_DUMP_ADDRS, &opts) != argc) { 722 return (DCMD_USAGE); 723 } 724 725 /* non-verbose faddrs, suitable for pipelines to sctp_faddr */ 726 if (paddr != 0) { 727 sctp_faddr_t faddr, *fp; 728 for (fp = sctp.sctp_faddrs; fp != NULL; fp = faddr.next) { 729 if (mdb_vread(&faddr, sizeof (faddr), (uintptr_t)fp) 730 == -1) { 731 mdb_warn("failed to read faddr at %p", 732 fp); 733 return (DCMD_ERR); 734 } 735 mdb_printf("%p\n", fp); 736 } 737 return (DCMD_OK); 738 } 739 740 mdb_nhconvert(&lport, &sctp.sctp_lport, sizeof (lport)); 741 mdb_nhconvert(&fport, &sctp.sctp_fport, sizeof (fport)); 742 mdb_printf("%<u>%p% %22s S=%-6hu D=%-6hu% STACK=%d ZONE=%d%</u>", addr, 743 state2str(&sctp), lport, fport, 744 ns_to_stackid((uintptr_t)connp.conn_netstack), connp.conn_zoneid); 745 746 if (sctp.sctp_faddrs) { 747 sctp_faddr_t faddr; 748 if (mdb_vread(&faddr, sizeof (faddr), 749 (uintptr_t)sctp.sctp_faddrs) != -1) 750 mdb_printf("%<u> %N%</u>", &faddr.faddr); 751 } 752 mdb_printf("\n"); 753 754 if (opts & MDB_SCTP_DUMP_ADDRS) { 755 mdb_printf("%<b>Local and Peer Addresses%</b>\n"); 756 757 /* Display source addresses */ 758 mdb_printf("nsaddrs\t\t%?d\n", sctp.sctp_nsaddrs); 759 (void) mdb_pwalk("sctp_walk_saddr", print_saddr, NULL, addr); 760 761 /* Display peer addresses */ 762 mdb_printf("nfaddrs\t\t%?d\n", sctp.sctp_nfaddrs); 763 i = 1; 764 (void) mdb_pwalk("sctp_walk_faddr", print_faddr, &i, addr); 765 766 mdb_printf("lastfaddr\t%?p\tprimary\t\t%?p\n", 767 sctp.sctp_lastfaddr, sctp.sctp_primary); 768 mdb_printf("current\t\t%?p\tlastdata\t%?p\n", 769 sctp.sctp_current, sctp.sctp_lastdata); 770 } 771 772 if (opts & MDB_SCTP_SHOW_OUT) { 773 mdb_printf("%<b>Outbound Data%</b>\n"); 774 mdb_printf("xmit_head\t%?p\txmit_tail\t%?p\n", 775 sctp.sctp_xmit_head, sctp.sctp_xmit_tail); 776 mdb_printf("xmit_unsent\t%?p\txmit_unsent_tail%?p\n", 777 sctp.sctp_xmit_unsent, sctp.sctp_xmit_unsent_tail); 778 mdb_printf("xmit_unacked\t%?p\n", sctp.sctp_xmit_unacked); 779 mdb_printf("unacked\t\t%?u\tunsent\t\t%?ld\n", 780 sctp.sctp_unacked, sctp.sctp_unsent); 781 mdb_printf("ltsn\t\t%?x\tlastack_rxd\t%?x\n", 782 sctp.sctp_ltsn, sctp.sctp_lastack_rxd); 783 mdb_printf("recovery_tsn\t%?x\tadv_pap\t\t%?x\n", 784 sctp.sctp_recovery_tsn, sctp.sctp_adv_pap); 785 mdb_printf("num_ostr\t%?hu\tostrcntrs\t%?p\n", 786 sctp.sctp_num_ostr, sctp.sctp_ostrcntrs); 787 mdb_printf("pad_mp\t\t%?p\n", sctp.sctp_pad_mp); 788 789 mdb_printf("%<b>Default Send Parameters%</b>\n"); 790 mdb_printf("def_stream\t%?u\tdef_flags\t%?x\n", 791 sctp.sctp_def_stream, sctp.sctp_def_flags); 792 mdb_printf("def_ppid\t%?x\tdef_context\t%?x\n", 793 sctp.sctp_def_ppid, sctp.sctp_def_context); 794 mdb_printf("def_timetolive\t%?u\n", 795 sctp.sctp_def_timetolive); 796 } 797 798 if (opts & MDB_SCTP_SHOW_IN) { 799 mdb_printf("%<b>Inbound Data%</b>\n"); 800 mdb_printf("sack_info\t%?p\tsack_gaps\t%?d\n", 801 sctp.sctp_sack_info, sctp.sctp_sack_gaps); 802 dump_sack_info((uintptr_t)sctp.sctp_sack_info); 803 mdb_printf("ftsn\t\t%?x\tlastacked\t%?x\n", 804 sctp.sctp_ftsn, sctp.sctp_lastacked); 805 mdb_printf("istr_nmsgs\t%?d\tsack_toggle\t%?d\n", 806 sctp.sctp_istr_nmsgs, sctp.sctp_sack_toggle); 807 mdb_printf("ack_mp\t\t%?p\n", sctp.sctp_ack_mp); 808 mdb_printf("num_istr\t%?hu\tinstr\t\t%?p\n", 809 sctp.sctp_num_istr, sctp.sctp_instr); 810 mdb_printf("unord_reass\t%?p\n", sctp.sctp_uo_frags); 811 } 812 813 if (opts & MDB_SCTP_SHOW_RTT) { 814 mdb_printf("%<b>RTT Tracking%</b>\n"); 815 mdb_printf("rtt_tsn\t\t%?x\tout_time\t%?ld\n", 816 sctp.sctp_rtt_tsn, sctp.sctp_out_time); 817 } 818 819 if (opts & MDB_SCTP_SHOW_FLOW) { 820 mdb_printf("%<b>Flow Control%</b>\n"); 821 mdb_printf("txmit_hiwater\t%?d\n" 822 "xmit_lowater\t%?d\tfrwnd\t\t%?u\n" 823 "rwnd\t\t%?u\tinitial rwnd\t%?u\n" 824 "rxqueued\t%?u\tcwnd_max\t%?u\n", sctp.sctp_xmit_hiwater, 825 sctp.sctp_xmit_lowater, sctp.sctp_frwnd, 826 sctp.sctp_rwnd, sctp.sctp_irwnd, sctp.sctp_rxqueued, 827 sctp.sctp_cwnd_max); 828 } 829 830 if (opts & MDB_SCTP_SHOW_HDR) { 831 mdb_printf("%<b>Composite Headers%</b>\n"); 832 mdb_printf("iphc\t\t%?p\tiphc6\t\t%?p\n" 833 "iphc_len\t%?d\tiphc6_len\t%?d\n" 834 "hdr_len\t\t%?d\thdr6_len\t%?d\n" 835 "ipha\t\t%?p\tip6h\t\t%?p\n" 836 "ip_hdr_len\t%?d\tip_hdr6_len\t%?d\n" 837 "sctph\t\t%?p\tsctph6\t\t%?p\n" 838 "lvtag\t\t%?x\tfvtag\t\t%?x\n", sctp.sctp_iphc, 839 sctp.sctp_iphc6, sctp.sctp_iphc_len, 840 sctp.sctp_iphc6_len, sctp.sctp_hdr_len, 841 sctp.sctp_hdr6_len, sctp.sctp_ipha, sctp.sctp_ip6h, 842 sctp.sctp_ip_hdr_len, sctp.sctp_ip_hdr6_len, 843 sctp.sctp_sctph, sctp.sctp_sctph6, sctp.sctp_lvtag, 844 sctp.sctp_fvtag); 845 } 846 847 if (opts & MDB_SCTP_SHOW_PMTUD) { 848 mdb_printf("%<b>PMTUd%</b>\n"); 849 mdb_printf("last_mtu_probe\t%?ld\tmtu_probe_intvl\t%?ld\n" 850 "mss\t\t%?u\n", 851 sctp.sctp_last_mtu_probe, sctp.sctp_mtu_probe_intvl, 852 sctp.sctp_mss); 853 } 854 855 if (opts & MDB_SCTP_SHOW_RXT) { 856 mdb_printf("%<b>Retransmit Info%</b>\n"); 857 mdb_printf("cookie_mp\t%?p\tstrikes\t\t%?d\n" 858 "max_init_rxt\t%?d\tpa_max_rxt\t%?d\n" 859 "pp_max_rxt\t%?d\trto_max\t\t%?u\n" 860 "rto_min\t\t%?u\trto_initial\t%?u\n" 861 "init_rto_max\t%?u\n" 862 "rxt_nxttsn\t%?u\trxt_maxtsn\t%?u\n", sctp.sctp_cookie_mp, 863 sctp.sctp_strikes, sctp.sctp_max_init_rxt, 864 sctp.sctp_pa_max_rxt, sctp.sctp_pp_max_rxt, 865 sctp.sctp_rto_max, sctp.sctp_rto_min, 866 sctp.sctp_rto_initial, sctp.sctp_init_rto_max, 867 sctp.sctp_rxt_nxttsn, sctp.sctp_rxt_maxtsn); 868 } 869 870 if (opts & MDB_SCTP_SHOW_CONN) { 871 mdb_printf("%<b>Connection State%</b>\n"); 872 mdb_printf("last_secret_update%?ld\n", 873 sctp.sctp_last_secret_update); 874 875 mdb_printf("secret\t\t"); 876 for (i = 0; i < SCTP_SECRET_LEN; i++) { 877 if (i % 2 == 0) 878 mdb_printf("0x%02x", sctp.sctp_secret[i]); 879 else 880 mdb_printf("%02x ", sctp.sctp_secret[i]); 881 } 882 mdb_printf("\n"); 883 mdb_printf("old_secret\t"); 884 for (i = 0; i < SCTP_SECRET_LEN; i++) { 885 if (i % 2 == 0) 886 mdb_printf("0x%02x", sctp.sctp_old_secret[i]); 887 else 888 mdb_printf("%02x ", sctp.sctp_old_secret[i]); 889 } 890 mdb_printf("\n"); 891 } 892 893 if (opts & MDB_SCTP_SHOW_STATS) { 894 mdb_printf("%<b>Stats Counters%</b>\n"); 895 mdb_printf("opkts\t\t%?llu\tobchunks\t%?llu\n" 896 "odchunks\t%?llu\toudchunks\t%?llu\n" 897 "rxtchunks\t%?llu\tT1expire\t%?lu\n" 898 "T2expire\t%?lu\tT3expire\t%?lu\n" 899 "msgcount\t%?llu\tprsctpdrop\t%?llu\n" 900 "AssocStartTime\t%?lu\n", 901 sctp.sctp_opkts, sctp.sctp_obchunks, 902 sctp.sctp_odchunks, sctp.sctp_oudchunks, 903 sctp.sctp_rxtchunks, sctp.sctp_T1expire, 904 sctp.sctp_T2expire, sctp.sctp_T3expire, 905 sctp.sctp_msgcount, sctp.sctp_prsctpdrop, 906 sctp.sctp_assoc_start_time); 907 mdb_printf("ipkts\t\t%?llu\tibchunks\t%?llu\n" 908 "idchunks\t%?llu\tiudchunks\t%?llu\n" 909 "fragdmsgs\t%?llu\treassmsgs\t%?llu\n", 910 sctp.sctp_ipkts, sctp.sctp_ibchunks, 911 sctp.sctp_idchunks, sctp.sctp_iudchunks, 912 sctp.sctp_fragdmsgs, sctp.sctp_reassmsgs); 913 } 914 915 if (opts & MDB_SCTP_SHOW_HASH) { 916 mdb_printf("%<b>Hash Tables%</b>\n"); 917 mdb_printf("conn_hash_next\t%?p\t", sctp.sctp_conn_hash_next); 918 mdb_printf("conn_hash_prev\t%?p\n", sctp.sctp_conn_hash_prev); 919 920 mdb_printf("listen_hash_next%?p\t", 921 sctp.sctp_listen_hash_next); 922 mdb_printf("listen_hash_prev%?p\n", 923 sctp.sctp_listen_hash_prev); 924 mdb_nhconvert(&lport, &sctp.sctp_lport, sizeof (lport)); 925 mdb_printf("[ listen_hash bucket\t%?d ]\n", 926 SCTP_LISTEN_HASH(lport)); 927 928 mdb_printf("conn_tfp\t%?p\t", sctp.sctp_conn_tfp); 929 mdb_printf("listen_tfp\t%?p\n", sctp.sctp_listen_tfp); 930 931 mdb_printf("bind_hash\t%?p\tptpbhn\t\t%?p\n", 932 sctp.sctp_bind_hash, sctp.sctp_ptpbhn); 933 mdb_printf("bind_lockp\t%?p\n", 934 sctp.sctp_bind_lockp); 935 mdb_printf("[ bind_hash bucket\t%?d ]\n", 936 SCTP_BIND_HASH(lport)); 937 } 938 939 if (opts & MDB_SCTP_SHOW_CLOSE) { 940 mdb_printf("%<b>Cleanup / Close%</b>\n"); 941 mdb_printf("shutdown_faddr\t%?p\tclient_errno\t%?d\n" 942 "lingertime\t%?d\trefcnt\t\t%?hu\n", 943 sctp.sctp_shutdown_faddr, sctp.sctp_client_errno, 944 sctp.sctp_lingertime, sctp.sctp_refcnt); 945 } 946 947 if (opts & MDB_SCTP_SHOW_MISC) { 948 mdb_printf("%<b>Miscellaneous%</b>\n"); 949 mdb_printf("bound_if\t%?u\theartbeat_mp\t%?p\n" 950 "family\t\t%?u\tipversion\t%?hu\n" 951 "hb_interval\t%?u\tautoclose\t%?d\n" 952 "active\t\t%?ld\ttx_adaption_code%?x\n" 953 "rx_adaption_code%?x\ttimer_mp\t%?p\n" 954 "partial_delivery_point\t%?d\n", 955 sctp.sctp_bound_if, sctp.sctp_heartbeat_mp, 956 sctp.sctp_family, sctp.sctp_ipversion, 957 sctp.sctp_hb_interval, sctp.sctp_autoclose, 958 sctp.sctp_active, sctp.sctp_tx_adaption_code, 959 sctp.sctp_rx_adaption_code, sctp.sctp_timer_mp, 960 sctp.sctp_pd_point); 961 } 962 963 if (opts & MDB_SCTP_SHOW_EXT) { 964 mdb_printf("%<b>Extensions and Reliable Ctl Chunks%</b>\n"); 965 mdb_printf("cxmit_list\t%?p\tlcsn\t\t%?x\n" 966 "fcsn\t\t%?x\n", sctp.sctp_cxmit_list, sctp.sctp_lcsn, 967 sctp.sctp_fcsn); 968 } 969 970 if (opts & MDB_SCTP_SHOW_FLAGS) { 971 mdb_printf("%<b>Flags%</b>\n"); 972 show_sctp_flags(&sctp); 973 } 974 975 return (DCMD_OK); 976 } 977 978 typedef struct fanout_walk_data { 979 int index; 980 int size; 981 uintptr_t sctp; 982 sctp_tf_t *fanout; 983 uintptr_t (*getnext)(sctp_t *); 984 } fanout_walk_data_t; 985 986 typedef struct fanout_init { 987 const char *nested_walker_name; 988 size_t offset; /* for what used to be a symbol */ 989 int (*getsize)(sctp_stack_t *); 990 uintptr_t (*getnext)(sctp_t *); 991 } fanout_init_t; 992 993 static uintptr_t 994 listen_next(sctp_t *sctp) 995 { 996 return ((uintptr_t)sctp->sctp_listen_hash_next); 997 } 998 999 /* ARGSUSED */ 1000 static int 1001 listen_size(sctp_stack_t *sctps) 1002 { 1003 return (SCTP_LISTEN_FANOUT_SIZE); 1004 } 1005 1006 static uintptr_t 1007 conn_next(sctp_t *sctp) 1008 { 1009 return ((uintptr_t)sctp->sctp_conn_hash_next); 1010 } 1011 1012 static int 1013 conn_size(sctp_stack_t *sctps) 1014 { 1015 int size; 1016 uintptr_t kaddr; 1017 1018 kaddr = (uintptr_t)&sctps->sctps_conn_hash_size; 1019 1020 if (mdb_vread(&size, sizeof (size), kaddr) == -1) { 1021 mdb_warn("can't read 'sctps_conn_hash_size' at %p", kaddr); 1022 return (1); 1023 } 1024 return (size); 1025 } 1026 1027 static uintptr_t 1028 bind_next(sctp_t *sctp) 1029 { 1030 return ((uintptr_t)sctp->sctp_bind_hash); 1031 } 1032 1033 /* ARGSUSED */ 1034 static int 1035 bind_size(sctp_stack_t *sctps) 1036 { 1037 return (SCTP_BIND_FANOUT_SIZE); 1038 } 1039 1040 static intptr_t 1041 find_next_hash_item(fanout_walk_data_t *fw) 1042 { 1043 sctp_tf_t tf; 1044 sctp_t sctp; 1045 1046 /* first try to continue down the hash chain */ 1047 if (fw->sctp != NULL) { 1048 /* try to get next in hash chain */ 1049 if (mdb_vread(&sctp, sizeof (sctp), fw->sctp) == -1) { 1050 mdb_warn("failed to read sctp at %p", fw->sctp); 1051 return (NULL); 1052 } 1053 fw->sctp = fw->getnext(&sctp); 1054 if (fw->sctp != NULL) 1055 return (fw->sctp); 1056 else 1057 /* end of chain; go to next bucket */ 1058 fw->index++; 1059 } 1060 1061 /* find a new hash chain, traversing the buckets */ 1062 for (; fw->index < fw->size; fw->index++) { 1063 /* read the current hash line for an sctp */ 1064 if (mdb_vread(&tf, sizeof (tf), 1065 (uintptr_t)(fw->fanout + fw->index)) == -1) { 1066 mdb_warn("failed to read tf at %p", 1067 fw->fanout + fw->index); 1068 return (NULL); 1069 } 1070 if (tf.tf_sctp != NULL) { 1071 /* start of a new chain */ 1072 fw->sctp = (uintptr_t)tf.tf_sctp; 1073 return (fw->sctp); 1074 } 1075 } 1076 return (NULL); 1077 } 1078 1079 static int 1080 fanout_stack_walk_init(mdb_walk_state_t *wsp) 1081 { 1082 fanout_walk_data_t *lw; 1083 fanout_init_t *fi = wsp->walk_arg; 1084 sctp_stack_t *sctps = (sctp_stack_t *)wsp->walk_addr; 1085 uintptr_t kaddr; 1086 1087 if (mdb_vread(&kaddr, sizeof (kaddr), 1088 wsp->walk_addr + fi->offset) == -1) { 1089 mdb_warn("can't read sctp fanout at %p", 1090 wsp->walk_addr + fi->offset); 1091 return (WALK_ERR); 1092 } 1093 1094 lw = mdb_alloc(sizeof (*lw), UM_SLEEP); 1095 lw->index = 0; 1096 lw->size = fi->getsize(sctps); 1097 lw->sctp = NULL; 1098 lw->fanout = (sctp_tf_t *)kaddr; 1099 lw->getnext = fi->getnext; 1100 1101 if ((wsp->walk_addr = find_next_hash_item(lw)) == NULL) { 1102 return (WALK_DONE); 1103 } 1104 wsp->walk_data = lw; 1105 return (WALK_NEXT); 1106 } 1107 1108 static int 1109 fanout_stack_walk_step(mdb_walk_state_t *wsp) 1110 { 1111 fanout_walk_data_t *fw = wsp->walk_data; 1112 uintptr_t addr = wsp->walk_addr; 1113 sctp_t sctp; 1114 int status; 1115 1116 if (mdb_vread(&sctp, sizeof (sctp), addr) == -1) { 1117 mdb_warn("failed to read sctp at %p", addr); 1118 return (WALK_DONE); 1119 } 1120 1121 status = wsp->walk_callback(addr, &sctp, wsp->walk_cbdata); 1122 if (status != WALK_NEXT) 1123 return (status); 1124 1125 if ((wsp->walk_addr = find_next_hash_item(fw)) == NULL) 1126 return (WALK_DONE); 1127 1128 return (WALK_NEXT); 1129 } 1130 1131 static void 1132 fanout_stack_walk_fini(mdb_walk_state_t *wsp) 1133 { 1134 fanout_walk_data_t *fw = wsp->walk_data; 1135 1136 mdb_free(fw, sizeof (*fw)); 1137 } 1138 1139 int 1140 fanout_walk_init(mdb_walk_state_t *wsp) 1141 { 1142 if (mdb_layered_walk("sctp_stacks", wsp) == -1) { 1143 mdb_warn("can't walk 'sctp_stacks'"); 1144 return (WALK_ERR); 1145 } 1146 1147 return (WALK_NEXT); 1148 } 1149 1150 int 1151 fanout_walk_step(mdb_walk_state_t *wsp) 1152 { 1153 fanout_init_t *fi = wsp->walk_arg; 1154 1155 if (mdb_pwalk(fi->nested_walker_name, wsp->walk_callback, 1156 wsp->walk_cbdata, wsp->walk_addr) == -1) { 1157 mdb_warn("couldn't walk '%s'for address %p", 1158 fi->nested_walker_name, wsp->walk_addr); 1159 return (WALK_ERR); 1160 } 1161 return (WALK_NEXT); 1162 } 1163 1164 int 1165 sctps_walk_init(mdb_walk_state_t *wsp) 1166 { 1167 1168 if (mdb_layered_walk("sctp_stacks", wsp) == -1) { 1169 mdb_warn("can't walk 'sctp_stacks'"); 1170 return (WALK_ERR); 1171 } 1172 1173 return (WALK_NEXT); 1174 } 1175 1176 int 1177 sctps_walk_step(mdb_walk_state_t *wsp) 1178 { 1179 uintptr_t kaddr; 1180 1181 kaddr = wsp->walk_addr + OFFSETOF(sctp_stack_t, sctps_g_list); 1182 if (mdb_pwalk("list", wsp->walk_callback, 1183 wsp->walk_cbdata, kaddr) == -1) { 1184 mdb_warn("couldn't walk 'list' for address %p", kaddr); 1185 return (WALK_ERR); 1186 } 1187 return (WALK_NEXT); 1188 } 1189 1190 static int 1191 sctp_walk_faddr_init(mdb_walk_state_t *wsp) 1192 { 1193 sctp_t sctp; 1194 1195 if (wsp->walk_addr == NULL) 1196 return (WALK_ERR); 1197 1198 if (mdb_vread(&sctp, sizeof (sctp), wsp->walk_addr) == -1) { 1199 mdb_warn("failed to read sctp at %p", wsp->walk_addr); 1200 return (WALK_ERR); 1201 } 1202 if ((wsp->walk_addr = (uintptr_t)sctp.sctp_faddrs) != NULL) 1203 return (WALK_NEXT); 1204 else 1205 return (WALK_DONE); 1206 } 1207 1208 static int 1209 sctp_walk_faddr_step(mdb_walk_state_t *wsp) 1210 { 1211 uintptr_t faddr_ptr = wsp->walk_addr; 1212 sctp_faddr_t sctp_faddr; 1213 int status; 1214 1215 if (mdb_vread(&sctp_faddr, sizeof (sctp_faddr_t), faddr_ptr) == -1) { 1216 mdb_warn("failed to read sctp_faddr_t at %p", faddr_ptr); 1217 return (WALK_ERR); 1218 } 1219 status = wsp->walk_callback(faddr_ptr, &sctp_faddr, wsp->walk_cbdata); 1220 if (status != WALK_NEXT) 1221 return (status); 1222 if ((faddr_ptr = (uintptr_t)sctp_faddr.next) == NULL) { 1223 return (WALK_DONE); 1224 } else { 1225 wsp->walk_addr = faddr_ptr; 1226 return (WALK_NEXT); 1227 } 1228 } 1229 1230 /* 1231 * Helper structure for sctp_walk_saddr. It stores the sctp_t being walked, 1232 * the current index to the sctp_saddrs[], and the current count of the 1233 * sctp_saddr_ipif_t list. 1234 */ 1235 typedef struct { 1236 sctp_t sctp; 1237 int hash_index; 1238 int cur_cnt; 1239 } saddr_walk_t; 1240 1241 static int 1242 sctp_walk_saddr_init(mdb_walk_state_t *wsp) 1243 { 1244 sctp_t *sctp; 1245 int i; 1246 saddr_walk_t *swalker; 1247 1248 if (wsp->walk_addr == NULL) 1249 return (WALK_ERR); 1250 1251 swalker = mdb_alloc(sizeof (saddr_walk_t), UM_SLEEP); 1252 sctp = &swalker->sctp; 1253 if (mdb_vread(sctp, sizeof (sctp_t), wsp->walk_addr) == -1) { 1254 mdb_warn("failed to read sctp at %p", wsp->walk_addr); 1255 mdb_free(swalker, sizeof (saddr_walk_t)); 1256 return (WALK_ERR); 1257 } 1258 1259 /* Find the first source address. */ 1260 for (i = 0; i < SCTP_IPIF_HASH; i++) { 1261 if (sctp->sctp_saddrs[i].ipif_count > 0) { 1262 list_t *addr_list; 1263 1264 addr_list = &sctp->sctp_saddrs[i].sctp_ipif_list; 1265 wsp->walk_addr = (uintptr_t)list_object(addr_list, 1266 addr_list->list_head.list_next); 1267 1268 /* Recode the current info */ 1269 swalker->hash_index = i; 1270 swalker->cur_cnt = 1; 1271 wsp->walk_data = swalker; 1272 1273 return (WALK_NEXT); 1274 } 1275 } 1276 return (WALK_DONE); 1277 } 1278 1279 static int 1280 sctp_walk_saddr_step(mdb_walk_state_t *wsp) 1281 { 1282 uintptr_t saddr_ptr = wsp->walk_addr; 1283 sctp_saddr_ipif_t saddr; 1284 saddr_walk_t *swalker; 1285 sctp_t *sctp; 1286 int status; 1287 int i, j; 1288 1289 if (mdb_vread(&saddr, sizeof (sctp_saddr_ipif_t), saddr_ptr) == -1) { 1290 mdb_warn("failed to read sctp_saddr_ipif_t at %p", saddr_ptr); 1291 return (WALK_ERR); 1292 } 1293 status = wsp->walk_callback(saddr_ptr, &saddr, wsp->walk_cbdata); 1294 if (status != WALK_NEXT) 1295 return (status); 1296 1297 swalker = (saddr_walk_t *)wsp->walk_data; 1298 sctp = &swalker->sctp; 1299 i = swalker->hash_index; 1300 j = swalker->cur_cnt; 1301 1302 /* 1303 * If there is still a source address in the current list, return it. 1304 * Otherwise, go to the next list in the sctp_saddrs[]. 1305 */ 1306 if (j++ < sctp->sctp_saddrs[i].ipif_count) { 1307 wsp->walk_addr = (uintptr_t)saddr.saddr_ipif.list_next; 1308 swalker->cur_cnt = j; 1309 return (WALK_NEXT); 1310 } else { 1311 list_t *lst; 1312 1313 for (i = i + 1; i < SCTP_IPIF_HASH; i++) { 1314 if (sctp->sctp_saddrs[i].ipif_count > 0) { 1315 lst = &sctp->sctp_saddrs[i].sctp_ipif_list; 1316 wsp->walk_addr = (uintptr_t)list_object( 1317 lst, lst->list_head.list_next); 1318 swalker->hash_index = i; 1319 swalker->cur_cnt = 1; 1320 return (WALK_NEXT); 1321 } 1322 } 1323 } 1324 return (WALK_DONE); 1325 } 1326 1327 static void 1328 sctp_walk_saddr_fini(mdb_walk_state_t *wsp) 1329 { 1330 saddr_walk_t *swalker = (saddr_walk_t *)wsp->walk_data; 1331 1332 mdb_free(swalker, sizeof (saddr_walk_t)); 1333 } 1334 1335 1336 typedef struct ill_walk_data { 1337 sctp_ill_hash_t ills[SCTP_ILL_HASH]; 1338 uint32_t count; 1339 } ill_walk_data_t; 1340 1341 typedef struct ipuf_walk_data { 1342 sctp_ipif_hash_t ipifs[SCTP_IPIF_HASH]; 1343 uint32_t count; 1344 } ipif_walk_data_t; 1345 1346 1347 int 1348 sctp_ill_walk_init(mdb_walk_state_t *wsp) 1349 { 1350 if (mdb_layered_walk("sctp_stacks", wsp) == -1) { 1351 mdb_warn("can't walk 'sctp_stacks'"); 1352 return (WALK_ERR); 1353 } 1354 1355 return (WALK_NEXT); 1356 } 1357 1358 int 1359 sctp_ill_walk_step(mdb_walk_state_t *wsp) 1360 { 1361 if (mdb_pwalk("sctp_stack_walk_ill", wsp->walk_callback, 1362 wsp->walk_cbdata, wsp->walk_addr) == -1) { 1363 mdb_warn("couldn't walk 'sctp_stack_walk_ill' for addr %p", 1364 wsp->walk_addr); 1365 return (WALK_ERR); 1366 } 1367 return (WALK_NEXT); 1368 } 1369 1370 /* 1371 * wsp->walk_addr is the address of sctps_ill_list 1372 */ 1373 static int 1374 sctp_stack_ill_walk_init(mdb_walk_state_t *wsp) 1375 { 1376 ill_walk_data_t iw; 1377 intptr_t i; 1378 uintptr_t kaddr, uaddr; 1379 size_t offset; 1380 1381 kaddr = wsp->walk_addr + OFFSETOF(sctp_stack_t, sctps_ills_count); 1382 if (mdb_vread(&iw.count, sizeof (iw.count), kaddr) == -1) { 1383 mdb_warn("can't read sctps_ills_count at %p", kaddr); 1384 return (WALK_ERR); 1385 } 1386 kaddr = wsp->walk_addr + OFFSETOF(sctp_stack_t, sctps_g_ills); 1387 1388 if (mdb_vread(&kaddr, sizeof (kaddr), kaddr) == -1) { 1389 mdb_warn("can't read scpts_g_ills %p", kaddr); 1390 return (WALK_ERR); 1391 } 1392 if (mdb_vread(&iw.ills, sizeof (iw.ills), kaddr) == -1) { 1393 mdb_warn("failed to read 'sctps_g_ills'"); 1394 return (NULL); 1395 } 1396 1397 /* Find the first ill. */ 1398 for (i = 0; i < SCTP_ILL_HASH; i++) { 1399 if (iw.ills[i].ill_count > 0) { 1400 uaddr = (uintptr_t)&iw.ills[i].sctp_ill_list; 1401 offset = uaddr - (uintptr_t)&iw.ills; 1402 if (mdb_pwalk("list", wsp->walk_callback, 1403 wsp->walk_cbdata, kaddr+offset) == -1) { 1404 mdb_warn("couldn't walk 'list' for address %p", 1405 kaddr); 1406 return (WALK_ERR); 1407 } 1408 } 1409 } 1410 return (WALK_DONE); 1411 } 1412 1413 static int 1414 sctp_stack_ill_walk_step(mdb_walk_state_t *wsp) 1415 { 1416 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 1417 wsp->walk_cbdata)); 1418 } 1419 1420 int 1421 sctp_ipif_walk_init(mdb_walk_state_t *wsp) 1422 { 1423 if (mdb_layered_walk("sctp_stacks", wsp) == -1) { 1424 mdb_warn("can't walk 'sctp_stacks'"); 1425 return (WALK_ERR); 1426 } 1427 return (WALK_NEXT); 1428 } 1429 1430 int 1431 sctp_ipif_walk_step(mdb_walk_state_t *wsp) 1432 { 1433 if (mdb_pwalk("sctp_stack_walk_ipif", wsp->walk_callback, 1434 wsp->walk_cbdata, wsp->walk_addr) == -1) { 1435 mdb_warn("couldn't walk 'sctp_stack_walk_ipif' for addr %p", 1436 wsp->walk_addr); 1437 return (WALK_ERR); 1438 } 1439 return (WALK_NEXT); 1440 } 1441 1442 /* 1443 * wsp->walk_addr is the address of sctps_ipif_list 1444 */ 1445 static int 1446 sctp_stack_ipif_walk_init(mdb_walk_state_t *wsp) 1447 { 1448 ipif_walk_data_t iw; 1449 intptr_t i; 1450 uintptr_t kaddr, uaddr; 1451 size_t offset; 1452 1453 kaddr = wsp->walk_addr + OFFSETOF(sctp_stack_t, sctps_g_ipifs_count); 1454 if (mdb_vread(&iw.count, sizeof (iw.count), kaddr) == -1) { 1455 mdb_warn("can't read sctps_g_ipifs_count at %p", kaddr); 1456 return (WALK_ERR); 1457 } 1458 kaddr = wsp->walk_addr + OFFSETOF(sctp_stack_t, sctps_g_ipifs); 1459 1460 if (mdb_vread(&kaddr, sizeof (kaddr), kaddr) == -1) { 1461 mdb_warn("can't read scpts_g_ipifs %p", kaddr); 1462 return (WALK_ERR); 1463 } 1464 if (mdb_vread(&iw.ipifs, sizeof (iw.ipifs), kaddr) == -1) { 1465 mdb_warn("failed to read 'sctps_g_ipifs'"); 1466 return (NULL); 1467 } 1468 1469 /* Find the first ipif. */ 1470 for (i = 0; i < SCTP_IPIF_HASH; i++) { 1471 if (iw.ipifs[i].ipif_count > 0) { 1472 uaddr = (uintptr_t)&iw.ipifs[i].sctp_ipif_list; 1473 offset = uaddr - (uintptr_t)&iw.ipifs; 1474 if (mdb_pwalk("list", wsp->walk_callback, 1475 wsp->walk_cbdata, kaddr+offset) == -1) { 1476 mdb_warn("couldn't walk 'list' for address %p", 1477 kaddr); 1478 return (WALK_ERR); 1479 } 1480 } 1481 } 1482 return (WALK_DONE); 1483 } 1484 1485 static int 1486 sctp_stack_ipif_walk_step(mdb_walk_state_t *wsp) 1487 { 1488 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 1489 wsp->walk_cbdata)); 1490 } 1491 1492 static void 1493 sctp_help(void) 1494 { 1495 mdb_printf("Print information for a given SCTP sctp_t\n\n"); 1496 mdb_printf("Options:\n"); 1497 mdb_printf("\t-a\t All the information\n"); 1498 mdb_printf("\t-f\t Flags\n"); 1499 mdb_printf("\t-h\t Hash Tables\n"); 1500 mdb_printf("\t-o\t Outbound Data\n"); 1501 mdb_printf("\t-i\t Inbound Data\n"); 1502 mdb_printf("\t-m\t Miscellaneous Information\n"); 1503 mdb_printf("\t-r\t RTT Tracking\n"); 1504 mdb_printf("\t-S\t Stats Counters\n"); 1505 mdb_printf("\t-F\t Flow Control\n"); 1506 mdb_printf("\t-H\t Composite Headers\n"); 1507 mdb_printf("\t-p\t PMTUD\n"); 1508 mdb_printf("\t-R\t Retransmit Information\n"); 1509 mdb_printf("\t-C\t Connection State\n"); 1510 mdb_printf("\t-c\t Cleanup / Close\n"); 1511 mdb_printf("\t-e\t Extensions and Reliable Control Chunks\n"); 1512 mdb_printf("\t-d\t Local and Peer addresses\n"); 1513 mdb_printf("\t-P\t Peer addresses\n"); 1514 } 1515 static const mdb_dcmd_t dcmds[] = { 1516 { "sctp", ":[-afhoimrSFHpRCcedP]", 1517 "display sctp control structure", sctp, sctp_help }, 1518 { "sctp_set", ":", "display a SCTP set", sctp_set }, 1519 { "sctp_faddr", ":", "display a faddr", sctp_faddr }, 1520 { "sctp_istr_msgs", ":", "display msg list on an instream", 1521 sctp_istr_msgs }, 1522 { "sctp_mdata_chunk", ":", "display a data chunk in an mblk", 1523 sctp_mdata_chunk }, 1524 { "sctp_xmit_list", ":", "display sctp xmit lists", sctp_xmit_list }, 1525 { "sctp_instr", ":", "display instr", sctp_instr }, 1526 { "sctp_reass_list", ":", "display reass list", sctp_reass_list }, 1527 { "sctp_uo_reass_list", ":", "display un-ordered reass list", 1528 sctp_uo_reass_list }, 1529 { NULL } 1530 }; 1531 1532 static const fanout_init_t listen_fanout_init = { 1533 "sctp_stack_listen_fanout", OFFSETOF(sctp_stack_t, sctps_listen_fanout), 1534 listen_size, listen_next 1535 }; 1536 1537 static const fanout_init_t conn_fanout_init = { 1538 "sctp_stack_conn_fanout", OFFSETOF(sctp_stack_t, sctps_conn_fanout), 1539 conn_size, conn_next 1540 }; 1541 1542 static const fanout_init_t bind_fanout_init = { 1543 "sctp_stack_bind_fanout", OFFSETOF(sctp_stack_t, sctps_bind_fanout), 1544 bind_size, bind_next 1545 }; 1546 1547 static const mdb_walker_t walkers[] = { 1548 { "sctps", "walk the full chain of sctps for all stacks", 1549 sctps_walk_init, sctps_walk_step, NULL }, 1550 { "sctp_listen_fanout", "walk the sctp listen fanout for all stacks", 1551 fanout_walk_init, fanout_walk_step, NULL, 1552 (void *)&listen_fanout_init }, 1553 { "sctp_conn_fanout", "walk the sctp conn fanout for all stacks", 1554 fanout_walk_init, fanout_walk_step, NULL, 1555 (void *)&conn_fanout_init }, 1556 { "sctp_bind_fanout", "walk the sctp bind fanout for all stacks", 1557 fanout_walk_init, fanout_walk_step, NULL, 1558 (void *)&bind_fanout_init }, 1559 { "sctp_stack_listen_fanout", 1560 "walk the sctp listen fanout for one stack", 1561 fanout_stack_walk_init, fanout_stack_walk_step, 1562 fanout_stack_walk_fini, 1563 (void *)&listen_fanout_init }, 1564 { "sctp_stack_conn_fanout", "walk the sctp conn fanout for one stack", 1565 fanout_stack_walk_init, fanout_stack_walk_step, 1566 fanout_stack_walk_fini, 1567 (void *)&conn_fanout_init }, 1568 { "sctp_stack_bind_fanout", "walk the sctp bind fanoutfor one stack", 1569 fanout_stack_walk_init, fanout_stack_walk_step, 1570 fanout_stack_walk_fini, 1571 (void *)&bind_fanout_init }, 1572 { "sctp_walk_faddr", "walk the peer address list of a given sctp_t", 1573 sctp_walk_faddr_init, sctp_walk_faddr_step, NULL }, 1574 { "sctp_walk_saddr", "walk the local address list of a given sctp_t", 1575 sctp_walk_saddr_init, sctp_walk_saddr_step, sctp_walk_saddr_fini }, 1576 { "sctp_walk_ill", "walk the sctp_g_ills list for all stacks", 1577 sctp_ill_walk_init, sctp_ill_walk_step, NULL }, 1578 { "sctp_walk_ipif", "walk the sctp_g_ipif list for all stacks", 1579 sctp_ipif_walk_init, sctp_ipif_walk_step, NULL }, 1580 { "sctp_stack_walk_ill", "walk the sctp_g_ills list for one stack", 1581 sctp_stack_ill_walk_init, sctp_stack_ill_walk_step, NULL }, 1582 { "sctp_stack_walk_ipif", "walk the sctp_g_ipif list for one stack", 1583 sctp_stack_ipif_walk_init, sctp_stack_ipif_walk_step, NULL }, 1584 { "sctp_stacks", "walk all the sctp_stack_t", 1585 sctp_stacks_walk_init, sctp_stacks_walk_step, NULL }, 1586 { NULL } 1587 }; 1588 1589 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 1590 1591 const mdb_modinfo_t * 1592 _mdb_init(void) 1593 { 1594 return (&modinfo); 1595 } 1596