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