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