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