Cleanup leftover libs.
[dragonfly.git] / sys / netproto / key / key_debug.c
blob7b8f56c9754330c6970a02c2245d2ded9755a0d4
1 /* $FreeBSD: src/sys/netkey/key_debug.c,v 1.10.2.5 2002/04/28 05:40:28 suz Exp $ */
2 /* $KAME: key_debug.c,v 1.26 2001/06/27 10:46:50 sakane Exp $ */
4 /*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
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.
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.
33 #ifdef _KERNEL
34 #include "opt_inet.h"
35 #include "opt_inet6.h"
36 #include "opt_ipsec.h"
37 #endif
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>
48 #include <net/route.h>
50 #include "key_var.h"
51 #include "key_debug.h"
53 #include <netinet/in.h>
54 #include <netinet6/ipsec.h>
56 #ifndef _KERNEL
57 #include <ctype.h>
58 #include <stdio.h>
59 #include <stdlib.h>
60 #endif /* !_KERNEL */
62 static void kdebug_sadb_prop (struct sadb_ext *);
63 static void kdebug_sadb_identity (struct sadb_ext *);
64 static void kdebug_sadb_supported (struct sadb_ext *);
65 static void kdebug_sadb_lifetime (struct sadb_ext *);
66 static void kdebug_sadb_sa (struct sadb_ext *);
67 static void kdebug_sadb_address (struct sadb_ext *);
68 static void kdebug_sadb_key (struct sadb_ext *);
69 static void kdebug_sadb_x_sa2 (struct sadb_ext *);
71 #ifdef _KERNEL
72 static void kdebug_secreplay (struct secreplay *);
73 #endif
75 #ifndef _KERNEL
76 #define kprintf printf
77 #define panic(param) { printf(param); exit(-1); }
78 #endif
80 /* NOTE: host byte order */
82 /* %%%: about struct sadb_msg */
83 void
84 kdebug_sadb(struct sadb_msg *base)
86 struct sadb_ext *ext;
87 int tlen, extlen;
89 /* sanity check */
90 if (base == NULL)
91 panic("kdebug_sadb: NULL pointer was passed.");
93 kprintf("sadb_msg{ version=%u type=%u errno=%u satype=%u\n",
94 base->sadb_msg_version, base->sadb_msg_type,
95 base->sadb_msg_errno, base->sadb_msg_satype);
96 kprintf(" len=%u reserved=%u seq=%u pid=%u\n",
97 base->sadb_msg_len, base->sadb_msg_reserved,
98 base->sadb_msg_seq, base->sadb_msg_pid);
100 tlen = PFKEY_UNUNIT64(base->sadb_msg_len) - sizeof(struct sadb_msg);
101 ext = (struct sadb_ext *)((caddr_t)base + sizeof(struct sadb_msg));
103 while (tlen > 0) {
104 kprintf("sadb_ext{ len=%u type=%u }\n",
105 ext->sadb_ext_len, ext->sadb_ext_type);
107 if (ext->sadb_ext_len == 0) {
108 kprintf("kdebug_sadb: invalid ext_len=0 was passed.\n");
109 return;
111 if (ext->sadb_ext_len > tlen) {
112 kprintf("kdebug_sadb: ext_len exceeds end of buffer.\n");
113 return;
116 switch (ext->sadb_ext_type) {
117 case SADB_EXT_SA:
118 kdebug_sadb_sa(ext);
119 break;
120 case SADB_EXT_LIFETIME_CURRENT:
121 case SADB_EXT_LIFETIME_HARD:
122 case SADB_EXT_LIFETIME_SOFT:
123 kdebug_sadb_lifetime(ext);
124 break;
125 case SADB_EXT_ADDRESS_SRC:
126 case SADB_EXT_ADDRESS_DST:
127 case SADB_EXT_ADDRESS_PROXY:
128 kdebug_sadb_address(ext);
129 break;
130 case SADB_EXT_KEY_AUTH:
131 case SADB_EXT_KEY_ENCRYPT:
132 kdebug_sadb_key(ext);
133 break;
134 case SADB_EXT_IDENTITY_SRC:
135 case SADB_EXT_IDENTITY_DST:
136 kdebug_sadb_identity(ext);
137 break;
138 case SADB_EXT_SENSITIVITY:
139 break;
140 case SADB_EXT_PROPOSAL:
141 kdebug_sadb_prop(ext);
142 break;
143 case SADB_EXT_SUPPORTED_AUTH:
144 case SADB_EXT_SUPPORTED_ENCRYPT:
145 kdebug_sadb_supported(ext);
146 break;
147 case SADB_EXT_SPIRANGE:
148 case SADB_X_EXT_KMPRIVATE:
149 break;
150 case SADB_X_EXT_POLICY:
151 kdebug_sadb_x_policy(ext);
152 break;
153 case SADB_X_EXT_SA2:
154 kdebug_sadb_x_sa2(ext);
155 break;
156 default:
157 kprintf("kdebug_sadb: invalid ext_type %u was passed.\n",
158 ext->sadb_ext_type);
159 return;
162 extlen = PFKEY_UNUNIT64(ext->sadb_ext_len);
163 tlen -= extlen;
164 ext = (struct sadb_ext *)((caddr_t)ext + extlen);
167 return;
170 static void
171 kdebug_sadb_prop(struct sadb_ext *ext)
173 struct sadb_prop *prop = (struct sadb_prop *)ext;
174 struct sadb_comb *comb;
175 int len;
177 /* sanity check */
178 if (ext == NULL)
179 panic("kdebug_sadb_prop: NULL pointer was passed.");
181 len = (PFKEY_UNUNIT64(prop->sadb_prop_len) - sizeof(*prop))
182 / sizeof(*comb);
183 comb = (struct sadb_comb *)(prop + 1);
184 kprintf("sadb_prop{ replay=%u\n", prop->sadb_prop_replay);
186 while (len--) {
187 kprintf("sadb_comb{ auth=%u encrypt=%u "
188 "flags=0x%04x reserved=0x%08x\n",
189 comb->sadb_comb_auth, comb->sadb_comb_encrypt,
190 comb->sadb_comb_flags, comb->sadb_comb_reserved);
192 kprintf(" auth_minbits=%u auth_maxbits=%u "
193 "encrypt_minbits=%u encrypt_maxbits=%u\n",
194 comb->sadb_comb_auth_minbits,
195 comb->sadb_comb_auth_maxbits,
196 comb->sadb_comb_encrypt_minbits,
197 comb->sadb_comb_encrypt_maxbits);
199 kprintf(" soft_alloc=%u hard_alloc=%u "
200 "soft_bytes=%lu hard_bytes=%lu\n",
201 comb->sadb_comb_soft_allocations,
202 comb->sadb_comb_hard_allocations,
203 (unsigned long)comb->sadb_comb_soft_bytes,
204 (unsigned long)comb->sadb_comb_hard_bytes);
206 kprintf(" soft_alloc=%lu hard_alloc=%lu "
207 "soft_bytes=%lu hard_bytes=%lu }\n",
208 (unsigned long)comb->sadb_comb_soft_addtime,
209 (unsigned long)comb->sadb_comb_hard_addtime,
210 (unsigned long)comb->sadb_comb_soft_usetime,
211 (unsigned long)comb->sadb_comb_hard_usetime);
212 comb++;
214 kprintf("}\n");
216 return;
219 static void
220 kdebug_sadb_identity(struct sadb_ext *ext)
222 struct sadb_ident *id = (struct sadb_ident *)ext;
223 int len;
225 /* sanity check */
226 if (ext == NULL)
227 panic("kdebug_sadb_identity: NULL pointer was passed.");
229 len = PFKEY_UNUNIT64(id->sadb_ident_len) - sizeof(*id);
230 kprintf("sadb_ident_%s{",
231 id->sadb_ident_exttype == SADB_EXT_IDENTITY_SRC ? "src" : "dst");
232 switch (id->sadb_ident_type) {
233 default:
234 kprintf(" type=%d id=%lu",
235 id->sadb_ident_type, (u_long)id->sadb_ident_id);
236 if (len) {
237 #ifdef _KERNEL
238 ipsec_hexdump((caddr_t)(id + 1), len); /*XXX cast ?*/
239 #else
240 char *p, *ep;
241 kprintf("\n str=\"");
242 p = (char *)(id + 1);
243 ep = p + len;
244 for (/*nothing*/; *p && p < ep; p++) {
245 if (isprint(*p))
246 kprintf("%c", *p & 0xff);
247 else
248 kprintf("\\%03o", *p & 0xff);
250 #endif
251 kprintf("\"");
253 break;
256 kprintf(" }\n");
258 return;
261 static void
262 kdebug_sadb_supported(struct sadb_ext *ext)
264 struct sadb_supported *sup = (struct sadb_supported *)ext;
265 struct sadb_alg *alg;
266 int len;
268 /* sanity check */
269 if (ext == NULL)
270 panic("kdebug_sadb_supported: NULL pointer was passed.");
272 len = (PFKEY_UNUNIT64(sup->sadb_supported_len) - sizeof(*sup))
273 / sizeof(*alg);
274 alg = (struct sadb_alg *)(sup + 1);
275 kprintf("sadb_sup{\n");
276 while (len--) {
277 kprintf(" { id=%d ivlen=%d min=%d max=%d }\n",
278 alg->sadb_alg_id, alg->sadb_alg_ivlen,
279 alg->sadb_alg_minbits, alg->sadb_alg_maxbits);
280 alg++;
282 kprintf("}\n");
284 return;
287 static void
288 kdebug_sadb_lifetime(struct sadb_ext *ext)
290 struct sadb_lifetime *lft = (struct sadb_lifetime *)ext;
292 /* sanity check */
293 if (ext == NULL)
294 panic("kdebug_sadb_lifetime: NULL pointer was passed.");
296 kprintf("sadb_lifetime{ alloc=%u, bytes=%u\n",
297 lft->sadb_lifetime_allocations,
298 (u_int32_t)lft->sadb_lifetime_bytes);
299 kprintf(" addtime=%u, usetime=%u }\n",
300 (u_int32_t)lft->sadb_lifetime_addtime,
301 (u_int32_t)lft->sadb_lifetime_usetime);
303 return;
306 static void
307 kdebug_sadb_sa(struct sadb_ext *ext)
309 struct sadb_sa *sa = (struct sadb_sa *)ext;
311 /* sanity check */
312 if (ext == NULL)
313 panic("kdebug_sadb_sa: NULL pointer was passed.");
315 kprintf("sadb_sa{ spi=%u replay=%u state=%u\n",
316 (u_int32_t)ntohl(sa->sadb_sa_spi), sa->sadb_sa_replay,
317 sa->sadb_sa_state);
318 kprintf(" auth=%u encrypt=%u flags=0x%08x }\n",
319 sa->sadb_sa_auth, sa->sadb_sa_encrypt, sa->sadb_sa_flags);
321 return;
324 static void
325 kdebug_sadb_address(struct sadb_ext *ext)
327 struct sadb_address *addr = (struct sadb_address *)ext;
329 /* sanity check */
330 if (ext == NULL)
331 panic("kdebug_sadb_address: NULL pointer was passed.");
333 kprintf("sadb_address{ proto=%u prefixlen=%u reserved=0x%02x%02x }\n",
334 addr->sadb_address_proto, addr->sadb_address_prefixlen,
335 ((u_char *)&addr->sadb_address_reserved)[0],
336 ((u_char *)&addr->sadb_address_reserved)[1]);
338 kdebug_sockaddr((struct sockaddr *)((caddr_t)ext + sizeof(*addr)));
340 return;
343 static void
344 kdebug_sadb_key(struct sadb_ext *ext)
346 struct sadb_key *key = (struct sadb_key *)ext;
348 /* sanity check */
349 if (ext == NULL)
350 panic("kdebug_sadb_key: NULL pointer was passed.");
352 kprintf("sadb_key{ bits=%u reserved=%u\n",
353 key->sadb_key_bits, key->sadb_key_reserved);
354 kprintf(" key=");
356 /* sanity check 2 */
357 if ((key->sadb_key_bits >> 3) >
358 (PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key))) {
359 kprintf("kdebug_sadb_key: key length mismatch, bit:%d len:%ld.\n",
360 key->sadb_key_bits >> 3,
361 (long)PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key));
364 ipsec_hexdump((caddr_t)key + sizeof(struct sadb_key),
365 key->sadb_key_bits >> 3);
366 kprintf(" }\n");
367 return;
370 static void
371 kdebug_sadb_x_sa2(struct sadb_ext *ext)
373 struct sadb_x_sa2 *sa2 = (struct sadb_x_sa2 *)ext;
375 /* sanity check */
376 if (ext == NULL)
377 panic("kdebug_sadb_x_sa2: NULL pointer was passed.");
379 kprintf("sadb_x_sa2{ mode=%u reqid=%u\n",
380 sa2->sadb_x_sa2_mode, sa2->sadb_x_sa2_reqid);
381 kprintf(" reserved1=%u reserved2=%u sequence=%u }\n",
382 sa2->sadb_x_sa2_reserved1, sa2->sadb_x_sa2_reserved2,
383 sa2->sadb_x_sa2_sequence);
385 return;
388 void
389 kdebug_sadb_x_policy(struct sadb_ext *ext)
391 struct sadb_x_policy *xpl = (struct sadb_x_policy *)ext;
392 struct sockaddr *addr;
394 /* sanity check */
395 if (ext == NULL)
396 panic("kdebug_sadb_x_policy: NULL pointer was passed.");
398 kprintf("sadb_x_policy{ type=%u dir=%u id=%x }\n",
399 xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir,
400 xpl->sadb_x_policy_id);
402 if (xpl->sadb_x_policy_type == IPSEC_POLICY_IPSEC) {
403 int tlen;
404 struct sadb_x_ipsecrequest *xisr;
406 tlen = PFKEY_UNUNIT64(xpl->sadb_x_policy_len) - sizeof(*xpl);
407 xisr = (struct sadb_x_ipsecrequest *)(xpl + 1);
409 while (tlen > 0) {
410 kprintf(" { len=%u proto=%u mode=%u level=%u reqid=%u\n",
411 xisr->sadb_x_ipsecrequest_len,
412 xisr->sadb_x_ipsecrequest_proto,
413 xisr->sadb_x_ipsecrequest_mode,
414 xisr->sadb_x_ipsecrequest_level,
415 xisr->sadb_x_ipsecrequest_reqid);
417 if (xisr->sadb_x_ipsecrequest_len > sizeof(*xisr)) {
418 addr = (struct sockaddr *)(xisr + 1);
419 kdebug_sockaddr(addr);
420 addr = (struct sockaddr *)((caddr_t)addr
421 + addr->sa_len);
422 kdebug_sockaddr(addr);
425 kprintf(" }\n");
427 /* prevent infinite loop */
428 if (xisr->sadb_x_ipsecrequest_len <= 0) {
429 kprintf("kdebug_sadb_x_policy: wrong policy struct.\n");
430 return;
432 /* prevent overflow */
433 if (xisr->sadb_x_ipsecrequest_len > tlen) {
434 kprintf("invalid ipsec policy length\n");
435 return;
438 tlen -= xisr->sadb_x_ipsecrequest_len;
440 xisr = (struct sadb_x_ipsecrequest *)((caddr_t)xisr
441 + xisr->sadb_x_ipsecrequest_len);
444 if (tlen != 0)
445 panic("kdebug_sadb_x_policy: wrong policy struct.");
448 return;
451 #ifdef _KERNEL
452 /* %%%: about SPD and SAD */
453 void
454 kdebug_secpolicy(struct secpolicy *sp)
456 /* sanity check */
457 if (sp == NULL)
458 panic("kdebug_secpolicy: NULL pointer was passed.");
460 kprintf("secpolicy{ refcnt=%u state=%u policy=%u\n",
461 sp->refcnt, sp->state, sp->policy);
463 kdebug_secpolicyindex(&sp->spidx);
465 switch (sp->policy) {
466 case IPSEC_POLICY_DISCARD:
467 kprintf(" type=discard }\n");
468 break;
469 case IPSEC_POLICY_NONE:
470 kprintf(" type=none }\n");
471 break;
472 case IPSEC_POLICY_IPSEC:
474 struct ipsecrequest *isr;
475 for (isr = sp->req; isr != NULL; isr = isr->next) {
477 kprintf(" level=%u\n", isr->level);
478 kdebug_secasindex(&isr->saidx);
480 if (isr->sav != NULL)
481 kdebug_secasv(isr->sav);
483 kprintf(" }\n");
485 break;
486 case IPSEC_POLICY_BYPASS:
487 kprintf(" type=bypass }\n");
488 break;
489 case IPSEC_POLICY_ENTRUST:
490 kprintf(" type=entrust }\n");
491 break;
492 default:
493 kprintf("kdebug_secpolicy: Invalid policy found. %d\n",
494 sp->policy);
495 break;
498 return;
501 void
502 kdebug_secpolicyindex(struct secpolicyindex *spidx)
504 /* sanity check */
505 if (spidx == NULL)
506 panic("kdebug_secpolicyindex: NULL pointer was passed.");
508 kprintf("secpolicyindex{ dir=%u prefs=%u prefd=%u ul_proto=%u\n",
509 spidx->dir, spidx->prefs, spidx->prefd, spidx->ul_proto);
511 ipsec_hexdump((caddr_t)&spidx->src,
512 ((struct sockaddr *)&spidx->src)->sa_len);
513 kprintf("\n");
514 ipsec_hexdump((caddr_t)&spidx->dst,
515 ((struct sockaddr *)&spidx->dst)->sa_len);
516 kprintf("}\n");
518 return;
521 void
522 kdebug_secasindex(struct secasindex *saidx)
524 /* sanity check */
525 if (saidx == NULL)
526 panic("kdebug_secpolicyindex: NULL pointer was passed.");
528 kprintf("secasindex{ mode=%u proto=%u\n",
529 saidx->mode, saidx->proto);
531 ipsec_hexdump((caddr_t)&saidx->src,
532 ((struct sockaddr *)&saidx->src)->sa_len);
533 kprintf("\n");
534 ipsec_hexdump((caddr_t)&saidx->dst,
535 ((struct sockaddr *)&saidx->dst)->sa_len);
536 kprintf("\n");
538 return;
541 void
542 kdebug_secasv(struct secasvar *sav)
544 /* sanity check */
545 if (sav == NULL)
546 panic("kdebug_secasv: NULL pointer was passed.");
548 kprintf("secas{");
549 kdebug_secasindex(&sav->sah->saidx);
551 kprintf(" refcnt=%u state=%u auth=%u enc=%u\n",
552 sav->refcnt, sav->state, sav->alg_auth, sav->alg_enc);
553 kprintf(" spi=%u flags=%u\n",
554 (u_int32_t)ntohl(sav->spi), sav->flags);
556 if (sav->key_auth != NULL)
557 kdebug_sadb_key((struct sadb_ext *)sav->key_auth);
558 if (sav->key_enc != NULL)
559 kdebug_sadb_key((struct sadb_ext *)sav->key_enc);
560 if (sav->iv != NULL) {
561 kprintf(" iv=");
562 ipsec_hexdump(sav->iv, sav->ivlen ? sav->ivlen : 8);
563 kprintf("\n");
566 if (sav->replay != NULL)
567 kdebug_secreplay(sav->replay);
568 if (sav->lft_c != NULL)
569 kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_c);
570 if (sav->lft_h != NULL)
571 kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_h);
572 if (sav->lft_s != NULL)
573 kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_s);
575 #if 0 /* notyet */
576 /* XXX: misc[123] ? */
577 #endif
579 return;
582 static void
583 kdebug_secreplay(struct secreplay *rpl)
585 int len, l;
587 /* sanity check */
588 if (rpl == NULL)
589 panic("kdebug_secreplay: NULL pointer was passed.");
591 kprintf(" secreplay{ count=%u wsize=%u seq=%u lastseq=%u",
592 rpl->count, rpl->wsize, rpl->seq, rpl->lastseq);
594 if (rpl->bitmap == NULL) {
595 kprintf(" }\n");
596 return;
599 kprintf("\n bitmap { ");
601 for (len = 0; len < rpl->wsize; len++) {
602 for (l = 7; l >= 0; l--)
603 kprintf("%u", (((rpl->bitmap)[len] >> l) & 1) ? 1 : 0);
605 kprintf(" }\n");
607 return;
610 void
611 kdebug_mbufhdr(struct mbuf *m)
613 /* sanity check */
614 if (m == NULL)
615 return;
617 kprintf("mbuf(%p){ m_next:%p m_nextpkt:%p m_data:%p "
618 "m_len:%d m_type:0x%02x m_flags:0x%02x }\n",
619 m, m->m_next, m->m_nextpkt, m->m_data,
620 m->m_len, m->m_type, m->m_flags);
622 if (m->m_flags & M_PKTHDR) {
623 kprintf(" m_pkthdr{ len:%d rcvif:%p }\n",
624 m->m_pkthdr.len, m->m_pkthdr.rcvif);
627 if (m->m_flags & M_EXT) {
628 kprintf(" m_ext{ ext_buf:%p ext_free:%p "
629 "ext_size:%u ext_ref:%p }\n",
630 m->m_ext.ext_buf, m->m_ext.ext_free,
631 m->m_ext.ext_size, m->m_ext.ext_ref);
634 return;
637 void
638 kdebug_mbuf(struct mbuf *m0)
640 struct mbuf *m = m0;
641 int i, j;
643 for (j = 0; m; m = m->m_next) {
644 kdebug_mbufhdr(m);
645 kprintf(" m_data:\n");
646 for (i = 0; i < m->m_len; i++) {
647 if (i && i % 32 == 0)
648 kprintf("\n");
649 if (i % 4 == 0)
650 kprintf(" ");
651 kprintf("%02x", mtod(m, u_char *)[i]);
652 j++;
654 kprintf("\n");
657 return;
659 #endif /* _KERNEL */
661 void
662 kdebug_sockaddr(struct sockaddr *addr)
664 struct sockaddr_in *sin4;
665 #ifdef INET6
666 struct sockaddr_in6 *sin6;
667 #endif
669 /* sanity check */
670 if (addr == NULL)
671 panic("kdebug_sockaddr: NULL pointer was passed.");
673 /* NOTE: We deal with port number as host byte order. */
674 kprintf("sockaddr{ len=%u family=%u", addr->sa_len, addr->sa_family);
676 switch (addr->sa_family) {
677 case AF_INET:
678 sin4 = (struct sockaddr_in *)addr;
679 kprintf(" port=%u\n", ntohs(sin4->sin_port));
680 ipsec_hexdump((caddr_t)&sin4->sin_addr, sizeof(sin4->sin_addr));
681 break;
682 #ifdef INET6
683 case AF_INET6:
684 sin6 = (struct sockaddr_in6 *)addr;
685 kprintf(" port=%u\n", ntohs(sin6->sin6_port));
686 kprintf(" flowinfo=0x%08x, scope_id=0x%08x\n",
687 sin6->sin6_flowinfo, sin6->sin6_scope_id);
688 ipsec_hexdump((caddr_t)&sin6->sin6_addr,
689 sizeof(sin6->sin6_addr));
690 break;
691 #endif
694 kprintf(" }\n");
696 return;
699 void
700 ipsec_bindump(caddr_t buf, int len)
702 int i;
704 for (i = 0; i < len; i++)
705 kprintf("%c", (unsigned char)buf[i]);
707 return;
711 void
712 ipsec_hexdump(caddr_t buf, int len)
714 int i;
716 for (i = 0; i < len; i++) {
717 if (i != 0 && i % 32 == 0) kprintf("\n");
718 if (i % 4 == 0) kprintf(" ");
719 kprintf("%02x", (unsigned char)buf[i]);
721 #if 0
722 if (i % 32 != 0) kprintf("\n");
723 #endif
725 return;