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