1 /* $FreeBSD$ */ 2 /* $KAME: key_debug.c,v 1.26 2001/06/27 10:46:50 sakane Exp $ */ 3 4 /*- 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifdef _KERNEL 34 #include "opt_inet.h" 35 #include "opt_inet6.h" 36 #include "opt_ipsec.h" 37 #endif 38 39 #include <sys/types.h> 40 #include <sys/param.h> 41 #ifdef _KERNEL 42 #include <sys/systm.h> 43 #include <sys/mbuf.h> 44 #include <sys/queue.h> 45 #endif 46 #include <sys/socket.h> 47 48 #include <net/route.h> 49 50 #include <netipsec/key_var.h> 51 #include <netipsec/key_debug.h> 52 53 #include <netinet/in.h> 54 #include <netipsec/ipsec.h> 55 #ifdef _KERNEL 56 #include <netipsec/keydb.h> 57 #endif 58 59 #ifndef _KERNEL 60 #include <ctype.h> 61 #include <stdio.h> 62 #include <stdlib.h> 63 #endif /* !_KERNEL */ 64 65 static void kdebug_sadb_prop __P((struct sadb_ext *)); 66 static void kdebug_sadb_identity __P((struct sadb_ext *)); 67 static void kdebug_sadb_supported __P((struct sadb_ext *)); 68 static void kdebug_sadb_lifetime __P((struct sadb_ext *)); 69 static void kdebug_sadb_sa __P((struct sadb_ext *)); 70 static void kdebug_sadb_address __P((struct sadb_ext *)); 71 static void kdebug_sadb_key __P((struct sadb_ext *)); 72 static void kdebug_sadb_x_sa2 __P((struct sadb_ext *)); 73 74 #ifdef _KERNEL 75 static void kdebug_secreplay __P((struct secreplay *)); 76 #endif 77 78 #ifndef _KERNEL 79 #define panic(fmt, ...) { printf(fmt, ## __VA_ARGS__); exit(-1); } 80 #endif 81 82 /* NOTE: host byte order */ 83 84 /* %%%: about struct sadb_msg */ 85 void 86 kdebug_sadb(base) 87 struct sadb_msg *base; 88 { 89 struct sadb_ext *ext; 90 int tlen, extlen; 91 92 /* sanity check */ 93 if (base == NULL) 94 panic("%s: NULL pointer was passed.\n", __func__); 95 96 printf("sadb_msg{ version=%u type=%u errno=%u satype=%u\n", 97 base->sadb_msg_version, base->sadb_msg_type, 98 base->sadb_msg_errno, base->sadb_msg_satype); 99 printf(" len=%u reserved=%u seq=%u pid=%u\n", 100 base->sadb_msg_len, base->sadb_msg_reserved, 101 base->sadb_msg_seq, base->sadb_msg_pid); 102 103 tlen = PFKEY_UNUNIT64(base->sadb_msg_len) - sizeof(struct sadb_msg); 104 ext = (struct sadb_ext *)((caddr_t)base + sizeof(struct sadb_msg)); 105 106 while (tlen > 0) { 107 printf("sadb_ext{ len=%u type=%u }\n", 108 ext->sadb_ext_len, ext->sadb_ext_type); 109 110 if (ext->sadb_ext_len == 0) { 111 printf("%s: invalid ext_len=0 was passed.\n", __func__); 112 return; 113 } 114 if (ext->sadb_ext_len > tlen) { 115 printf("%s: ext_len too big (%u > %u).\n", 116 __func__, ext->sadb_ext_len, tlen); 117 return; 118 } 119 120 switch (ext->sadb_ext_type) { 121 case SADB_EXT_SA: 122 kdebug_sadb_sa(ext); 123 break; 124 case SADB_EXT_LIFETIME_CURRENT: 125 case SADB_EXT_LIFETIME_HARD: 126 case SADB_EXT_LIFETIME_SOFT: 127 kdebug_sadb_lifetime(ext); 128 break; 129 case SADB_EXT_ADDRESS_SRC: 130 case SADB_EXT_ADDRESS_DST: 131 case SADB_EXT_ADDRESS_PROXY: 132 kdebug_sadb_address(ext); 133 break; 134 case SADB_EXT_KEY_AUTH: 135 case SADB_EXT_KEY_ENCRYPT: 136 kdebug_sadb_key(ext); 137 break; 138 case SADB_EXT_IDENTITY_SRC: 139 case SADB_EXT_IDENTITY_DST: 140 kdebug_sadb_identity(ext); 141 break; 142 case SADB_EXT_SENSITIVITY: 143 break; 144 case SADB_EXT_PROPOSAL: 145 kdebug_sadb_prop(ext); 146 break; 147 case SADB_EXT_SUPPORTED_AUTH: 148 case SADB_EXT_SUPPORTED_ENCRYPT: 149 kdebug_sadb_supported(ext); 150 break; 151 case SADB_EXT_SPIRANGE: 152 case SADB_X_EXT_KMPRIVATE: 153 break; 154 case SADB_X_EXT_POLICY: 155 kdebug_sadb_x_policy(ext); 156 break; 157 case SADB_X_EXT_SA2: 158 kdebug_sadb_x_sa2(ext); 159 break; 160 default: 161 printf("%s: invalid ext_type %u\n", __func__, 162 ext->sadb_ext_type); 163 return; 164 } 165 166 extlen = PFKEY_UNUNIT64(ext->sadb_ext_len); 167 tlen -= extlen; 168 ext = (struct sadb_ext *)((caddr_t)ext + extlen); 169 } 170 171 return; 172 } 173 174 static void 175 kdebug_sadb_prop(ext) 176 struct sadb_ext *ext; 177 { 178 struct sadb_prop *prop = (struct sadb_prop *)ext; 179 struct sadb_comb *comb; 180 int len; 181 182 /* sanity check */ 183 if (ext == NULL) 184 panic("%s: NULL pointer was passed.\n", __func__); 185 186 len = (PFKEY_UNUNIT64(prop->sadb_prop_len) - sizeof(*prop)) 187 / sizeof(*comb); 188 comb = (struct sadb_comb *)(prop + 1); 189 printf("sadb_prop{ replay=%u\n", prop->sadb_prop_replay); 190 191 while (len--) { 192 printf("sadb_comb{ auth=%u encrypt=%u " 193 "flags=0x%04x reserved=0x%08x\n", 194 comb->sadb_comb_auth, comb->sadb_comb_encrypt, 195 comb->sadb_comb_flags, comb->sadb_comb_reserved); 196 197 printf(" auth_minbits=%u auth_maxbits=%u " 198 "encrypt_minbits=%u encrypt_maxbits=%u\n", 199 comb->sadb_comb_auth_minbits, 200 comb->sadb_comb_auth_maxbits, 201 comb->sadb_comb_encrypt_minbits, 202 comb->sadb_comb_encrypt_maxbits); 203 204 printf(" soft_alloc=%u hard_alloc=%u " 205 "soft_bytes=%lu hard_bytes=%lu\n", 206 comb->sadb_comb_soft_allocations, 207 comb->sadb_comb_hard_allocations, 208 (unsigned long)comb->sadb_comb_soft_bytes, 209 (unsigned long)comb->sadb_comb_hard_bytes); 210 211 printf(" soft_alloc=%lu hard_alloc=%lu " 212 "soft_bytes=%lu hard_bytes=%lu }\n", 213 (unsigned long)comb->sadb_comb_soft_addtime, 214 (unsigned long)comb->sadb_comb_hard_addtime, 215 (unsigned long)comb->sadb_comb_soft_usetime, 216 (unsigned long)comb->sadb_comb_hard_usetime); 217 comb++; 218 } 219 printf("}\n"); 220 221 return; 222 } 223 224 static void 225 kdebug_sadb_identity(ext) 226 struct sadb_ext *ext; 227 { 228 struct sadb_ident *id = (struct sadb_ident *)ext; 229 int len; 230 231 /* sanity check */ 232 if (ext == NULL) 233 panic("%s: NULL pointer was passed.\n", __func__); 234 235 len = PFKEY_UNUNIT64(id->sadb_ident_len) - sizeof(*id); 236 printf("sadb_ident_%s{", 237 id->sadb_ident_exttype == SADB_EXT_IDENTITY_SRC ? "src" : "dst"); 238 switch (id->sadb_ident_type) { 239 default: 240 printf(" type=%d id=%lu", 241 id->sadb_ident_type, (u_long)id->sadb_ident_id); 242 if (len) { 243 #ifdef _KERNEL 244 ipsec_hexdump((caddr_t)(id + 1), len); /*XXX cast ?*/ 245 #else 246 char *p, *ep; 247 printf("\n str=\""); 248 p = (char *)(id + 1); 249 ep = p + len; 250 for (/*nothing*/; *p && p < ep; p++) { 251 if (isprint(*p)) 252 printf("%c", *p & 0xff); 253 else 254 printf("\\%03o", *p & 0xff); 255 } 256 #endif 257 printf("\""); 258 } 259 break; 260 } 261 262 printf(" }\n"); 263 264 return; 265 } 266 267 static void 268 kdebug_sadb_supported(ext) 269 struct sadb_ext *ext; 270 { 271 struct sadb_supported *sup = (struct sadb_supported *)ext; 272 struct sadb_alg *alg; 273 int len; 274 275 /* sanity check */ 276 if (ext == NULL) 277 panic("%s: NULL pointer was passed.\n", __func__); 278 279 len = (PFKEY_UNUNIT64(sup->sadb_supported_len) - sizeof(*sup)) 280 / sizeof(*alg); 281 alg = (struct sadb_alg *)(sup + 1); 282 printf("sadb_sup{\n"); 283 while (len--) { 284 printf(" { id=%d ivlen=%d min=%d max=%d }\n", 285 alg->sadb_alg_id, alg->sadb_alg_ivlen, 286 alg->sadb_alg_minbits, alg->sadb_alg_maxbits); 287 alg++; 288 } 289 printf("}\n"); 290 291 return; 292 } 293 294 static void 295 kdebug_sadb_lifetime(ext) 296 struct sadb_ext *ext; 297 { 298 struct sadb_lifetime *lft = (struct sadb_lifetime *)ext; 299 300 /* sanity check */ 301 if (ext == NULL) 302 panic("%s: NULL pointer was passed.\n", __func__); 303 304 printf("sadb_lifetime{ alloc=%u, bytes=%u\n", 305 lft->sadb_lifetime_allocations, 306 (u_int32_t)lft->sadb_lifetime_bytes); 307 printf(" addtime=%u, usetime=%u }\n", 308 (u_int32_t)lft->sadb_lifetime_addtime, 309 (u_int32_t)lft->sadb_lifetime_usetime); 310 311 return; 312 } 313 314 static void 315 kdebug_sadb_sa(ext) 316 struct sadb_ext *ext; 317 { 318 struct sadb_sa *sa = (struct sadb_sa *)ext; 319 320 /* sanity check */ 321 if (ext == NULL) 322 panic("%s: NULL pointer was passed.\n", __func__); 323 324 printf("sadb_sa{ spi=%u replay=%u state=%u\n", 325 (u_int32_t)ntohl(sa->sadb_sa_spi), sa->sadb_sa_replay, 326 sa->sadb_sa_state); 327 printf(" auth=%u encrypt=%u flags=0x%08x }\n", 328 sa->sadb_sa_auth, sa->sadb_sa_encrypt, sa->sadb_sa_flags); 329 330 return; 331 } 332 333 static void 334 kdebug_sadb_address(ext) 335 struct sadb_ext *ext; 336 { 337 struct sadb_address *addr = (struct sadb_address *)ext; 338 339 /* sanity check */ 340 if (ext == NULL) 341 panic("%s: NULL pointer was passed.\n", __func__); 342 343 printf("sadb_address{ proto=%u prefixlen=%u reserved=0x%02x%02x }\n", 344 addr->sadb_address_proto, addr->sadb_address_prefixlen, 345 ((u_char *)&addr->sadb_address_reserved)[0], 346 ((u_char *)&addr->sadb_address_reserved)[1]); 347 348 kdebug_sockaddr((struct sockaddr *)((caddr_t)ext + sizeof(*addr))); 349 350 return; 351 } 352 353 static void 354 kdebug_sadb_key(ext) 355 struct sadb_ext *ext; 356 { 357 struct sadb_key *key = (struct sadb_key *)ext; 358 359 /* sanity check */ 360 if (ext == NULL) 361 panic("%s: NULL pointer was passed.\n", __func__); 362 363 printf("sadb_key{ bits=%u reserved=%u\n", 364 key->sadb_key_bits, key->sadb_key_reserved); 365 printf(" key="); 366 367 /* sanity check 2 */ 368 if ((key->sadb_key_bits >> 3) > 369 (PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key))) { 370 printf("%s: key length mismatch, bit:%d len:%ld.\n", 371 __func__, 372 key->sadb_key_bits >> 3, 373 (long)PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key)); 374 } 375 376 ipsec_hexdump((caddr_t)key + sizeof(struct sadb_key), 377 key->sadb_key_bits >> 3); 378 printf(" }\n"); 379 return; 380 } 381 382 static void 383 kdebug_sadb_x_sa2(ext) 384 struct sadb_ext *ext; 385 { 386 struct sadb_x_sa2 *sa2 = (struct sadb_x_sa2 *)ext; 387 388 /* sanity check */ 389 if (ext == NULL) 390 panic("%s: NULL pointer was passed.\n", __func__); 391 392 printf("sadb_x_sa2{ mode=%u reqid=%u\n", 393 sa2->sadb_x_sa2_mode, sa2->sadb_x_sa2_reqid); 394 printf(" reserved1=%u reserved2=%u sequence=%u }\n", 395 sa2->sadb_x_sa2_reserved1, sa2->sadb_x_sa2_reserved2, 396 sa2->sadb_x_sa2_sequence); 397 398 return; 399 } 400 401 void 402 kdebug_sadb_x_policy(ext) 403 struct sadb_ext *ext; 404 { 405 struct sadb_x_policy *xpl = (struct sadb_x_policy *)ext; 406 struct sockaddr *addr; 407 408 /* sanity check */ 409 if (ext == NULL) 410 panic("%s: NULL pointer was passed.\n", __func__); 411 412 printf("sadb_x_policy{ type=%u dir=%u id=%x }\n", 413 xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir, 414 xpl->sadb_x_policy_id); 415 416 if (xpl->sadb_x_policy_type == IPSEC_POLICY_IPSEC) { 417 int tlen; 418 struct sadb_x_ipsecrequest *xisr; 419 420 tlen = PFKEY_UNUNIT64(xpl->sadb_x_policy_len) - sizeof(*xpl); 421 xisr = (struct sadb_x_ipsecrequest *)(xpl + 1); 422 423 while (tlen > 0) { 424 printf(" { len=%u proto=%u mode=%u level=%u reqid=%u\n", 425 xisr->sadb_x_ipsecrequest_len, 426 xisr->sadb_x_ipsecrequest_proto, 427 xisr->sadb_x_ipsecrequest_mode, 428 xisr->sadb_x_ipsecrequest_level, 429 xisr->sadb_x_ipsecrequest_reqid); 430 431 if (xisr->sadb_x_ipsecrequest_len > sizeof(*xisr)) { 432 addr = (struct sockaddr *)(xisr + 1); 433 kdebug_sockaddr(addr); 434 addr = (struct sockaddr *)((caddr_t)addr 435 + addr->sa_len); 436 kdebug_sockaddr(addr); 437 } 438 439 printf(" }\n"); 440 441 /* prevent infinite loop */ 442 if (xisr->sadb_x_ipsecrequest_len <= 0) { 443 printf("%s: wrong policy struct.\n", __func__); 444 return; 445 } 446 /* prevent overflow */ 447 if (xisr->sadb_x_ipsecrequest_len > tlen) { 448 printf("%s: invalid ipsec policy length " 449 "(%u > %u)\n", __func__, 450 xisr->sadb_x_ipsecrequest_len, tlen); 451 return; 452 } 453 454 tlen -= xisr->sadb_x_ipsecrequest_len; 455 456 xisr = (struct sadb_x_ipsecrequest *)((caddr_t)xisr 457 + xisr->sadb_x_ipsecrequest_len); 458 } 459 460 if (tlen != 0) 461 panic("%s: wrong policy struct.\n", __func__); 462 } 463 464 return; 465 } 466 467 #ifdef _KERNEL 468 /* %%%: about SPD and SAD */ 469 void 470 kdebug_secpolicy(sp) 471 struct secpolicy *sp; 472 { 473 /* sanity check */ 474 if (sp == NULL) 475 panic("%s: NULL pointer was passed.\n", __func__); 476 477 printf("secpolicy{ refcnt=%u state=%u policy=%u\n", 478 sp->refcnt, sp->state, sp->policy); 479 480 kdebug_secpolicyindex(&sp->spidx); 481 482 switch (sp->policy) { 483 case IPSEC_POLICY_DISCARD: 484 printf(" type=discard }\n"); 485 break; 486 case IPSEC_POLICY_NONE: 487 printf(" type=none }\n"); 488 break; 489 case IPSEC_POLICY_IPSEC: 490 { 491 struct ipsecrequest *isr; 492 for (isr = sp->req; isr != NULL; isr = isr->next) { 493 494 printf(" level=%u\n", isr->level); 495 kdebug_secasindex(&isr->saidx); 496 497 if (isr->sav != NULL) 498 kdebug_secasv(isr->sav); 499 } 500 printf(" }\n"); 501 } 502 break; 503 case IPSEC_POLICY_BYPASS: 504 printf(" type=bypass }\n"); 505 break; 506 case IPSEC_POLICY_ENTRUST: 507 printf(" type=entrust }\n"); 508 break; 509 default: 510 printf("%s: Invalid policy found. %d\n", __func__, sp->policy); 511 break; 512 } 513 514 return; 515 } 516 517 void 518 kdebug_secpolicyindex(spidx) 519 struct secpolicyindex *spidx; 520 { 521 /* sanity check */ 522 if (spidx == NULL) 523 panic("%s: NULL pointer was passed.\n", __func__); 524 525 printf("secpolicyindex{ dir=%u prefs=%u prefd=%u ul_proto=%u\n", 526 spidx->dir, spidx->prefs, spidx->prefd, spidx->ul_proto); 527 528 ipsec_hexdump((caddr_t)&spidx->src, 529 ((struct sockaddr *)&spidx->src)->sa_len); 530 printf("\n"); 531 ipsec_hexdump((caddr_t)&spidx->dst, 532 ((struct sockaddr *)&spidx->dst)->sa_len); 533 printf("}\n"); 534 535 return; 536 } 537 538 void 539 kdebug_secasindex(saidx) 540 struct secasindex *saidx; 541 { 542 /* sanity check */ 543 if (saidx == NULL) 544 panic("%s: NULL pointer was passed.\n", __func__); 545 546 printf("secasindex{ mode=%u proto=%u\n", 547 saidx->mode, saidx->proto); 548 549 ipsec_hexdump((caddr_t)&saidx->src, 550 ((struct sockaddr *)&saidx->src)->sa_len); 551 printf("\n"); 552 ipsec_hexdump((caddr_t)&saidx->dst, 553 ((struct sockaddr *)&saidx->dst)->sa_len); 554 printf("\n"); 555 556 return; 557 } 558 559 static void 560 kdebug_sec_lifetime(struct seclifetime *lft) 561 { 562 /* sanity check */ 563 if (lft == NULL) 564 panic("%s: NULL pointer was passed.\n", __func__); 565 566 printf("sec_lifetime{ alloc=%u, bytes=%u\n", 567 lft->allocations, (u_int32_t)lft->bytes); 568 printf(" addtime=%u, usetime=%u }\n", 569 (u_int32_t)lft->addtime, (u_int32_t)lft->usetime); 570 571 return; 572 } 573 574 void 575 kdebug_secasv(sav) 576 struct secasvar *sav; 577 { 578 /* sanity check */ 579 if (sav == NULL) 580 panic("%s: NULL pointer was passed.\n", __func__); 581 582 printf("secas{"); 583 kdebug_secasindex(&sav->sah->saidx); 584 585 printf(" refcnt=%u state=%u auth=%u enc=%u\n", 586 sav->refcnt, sav->state, sav->alg_auth, sav->alg_enc); 587 printf(" spi=%u flags=%u\n", 588 (u_int32_t)ntohl(sav->spi), sav->flags); 589 590 if (sav->key_auth != NULL) 591 kdebug_sadb_key((struct sadb_ext *)sav->key_auth); 592 if (sav->key_enc != NULL) 593 kdebug_sadb_key((struct sadb_ext *)sav->key_enc); 594 if (sav->iv != NULL) { 595 printf(" iv="); 596 ipsec_hexdump(sav->iv, sav->ivlen ? sav->ivlen : 8); 597 printf("\n"); 598 } 599 600 if (sav->replay != NULL) 601 kdebug_secreplay(sav->replay); 602 if (sav->lft_c != NULL) 603 kdebug_sec_lifetime(sav->lft_c); 604 if (sav->lft_h != NULL) 605 kdebug_sec_lifetime(sav->lft_h); 606 if (sav->lft_s != NULL) 607 kdebug_sec_lifetime(sav->lft_s); 608 609 #ifdef notyet 610 /* XXX: misc[123] ? */ 611 #endif 612 613 return; 614 } 615 616 static void 617 kdebug_secreplay(rpl) 618 struct secreplay *rpl; 619 { 620 int len, l; 621 622 /* sanity check */ 623 if (rpl == NULL) 624 panic("%s: NULL pointer was passed.\n", __func__); 625 626 printf(" secreplay{ count=%u wsize=%u seq=%u lastseq=%u", 627 rpl->count, rpl->wsize, rpl->seq, rpl->lastseq); 628 629 if (rpl->bitmap == NULL) { 630 printf(" }\n"); 631 return; 632 } 633 634 printf("\n bitmap { "); 635 636 for (len = 0; len < rpl->wsize; len++) { 637 for (l = 7; l >= 0; l--) 638 printf("%u", (((rpl->bitmap)[len] >> l) & 1) ? 1 : 0); 639 } 640 printf(" }\n"); 641 642 return; 643 } 644 645 void 646 kdebug_mbufhdr(m) 647 struct mbuf *m; 648 { 649 /* sanity check */ 650 if (m == NULL) 651 return; 652 653 printf("mbuf(%p){ m_next:%p m_nextpkt:%p m_data:%p " 654 "m_len:%d m_type:0x%02x m_flags:0x%02x }\n", 655 m, m->m_next, m->m_nextpkt, m->m_data, 656 m->m_len, m->m_type, m->m_flags); 657 658 if (m->m_flags & M_PKTHDR) { 659 printf(" m_pkthdr{ len:%d rcvif:%p }\n", 660 m->m_pkthdr.len, m->m_pkthdr.rcvif); 661 } 662 663 if (m->m_flags & M_EXT) { 664 printf(" m_ext{ ext_buf:%p ext_free:%p " 665 "ext_size:%u ref_cnt:%p }\n", 666 m->m_ext.ext_buf, m->m_ext.ext_free, 667 m->m_ext.ext_size, m->m_ext.ref_cnt); 668 } 669 670 return; 671 } 672 673 void 674 kdebug_mbuf(m0) 675 struct mbuf *m0; 676 { 677 struct mbuf *m = m0; 678 int i, j; 679 680 for (j = 0; m; m = m->m_next) { 681 kdebug_mbufhdr(m); 682 printf(" m_data:\n"); 683 for (i = 0; i < m->m_len; i++) { 684 if (i && i % 32 == 0) 685 printf("\n"); 686 if (i % 4 == 0) 687 printf(" "); 688 printf("%02x", mtod(m, u_char *)[i]); 689 j++; 690 } 691 printf("\n"); 692 } 693 694 return; 695 } 696 #endif /* _KERNEL */ 697 698 void 699 kdebug_sockaddr(addr) 700 struct sockaddr *addr; 701 { 702 struct sockaddr_in *sin4; 703 #ifdef INET6 704 struct sockaddr_in6 *sin6; 705 #endif 706 707 /* sanity check */ 708 if (addr == NULL) 709 panic("%s: NULL pointer was passed.\n", __func__); 710 711 /* NOTE: We deal with port number as host byte order. */ 712 printf("sockaddr{ len=%u family=%u", addr->sa_len, addr->sa_family); 713 714 switch (addr->sa_family) { 715 case AF_INET: 716 sin4 = (struct sockaddr_in *)addr; 717 printf(" port=%u\n", ntohs(sin4->sin_port)); 718 ipsec_hexdump((caddr_t)&sin4->sin_addr, sizeof(sin4->sin_addr)); 719 break; 720 #ifdef INET6 721 case AF_INET6: 722 sin6 = (struct sockaddr_in6 *)addr; 723 printf(" port=%u\n", ntohs(sin6->sin6_port)); 724 printf(" flowinfo=0x%08x, scope_id=0x%08x\n", 725 sin6->sin6_flowinfo, sin6->sin6_scope_id); 726 ipsec_hexdump((caddr_t)&sin6->sin6_addr, 727 sizeof(sin6->sin6_addr)); 728 break; 729 #endif 730 } 731 732 printf(" }\n"); 733 734 return; 735 } 736 737 void 738 ipsec_bindump(buf, len) 739 caddr_t buf; 740 int len; 741 { 742 int i; 743 744 for (i = 0; i < len; i++) 745 printf("%c", (unsigned char)buf[i]); 746 747 return; 748 } 749 750 751 void 752 ipsec_hexdump(buf, len) 753 caddr_t buf; 754 int len; 755 { 756 int i; 757 758 for (i = 0; i < len; i++) { 759 if (i != 0 && i % 32 == 0) printf("\n"); 760 if (i % 4 == 0) printf(" "); 761 printf("%02x", (unsigned char)buf[i]); 762 } 763 #if 0 764 if (i % 32 != 0) printf("\n"); 765 #endif 766 767 return; 768 } 769