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