]>
Commit | Line | Data |
---|---|---|
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 |
58 | static void kdebug_sadb_prop(struct sadb_ext *); |
59 | static void kdebug_sadb_identity(struct sadb_ext *); | |
60 | static void kdebug_sadb_supported(struct sadb_ext *); | |
61 | static void kdebug_sadb_lifetime(struct sadb_ext *); | |
62 | static void kdebug_sadb_sa(struct sadb_ext *); | |
63 | static void kdebug_sadb_address(struct sadb_ext *); | |
64 | static void kdebug_sadb_key(struct sadb_ext *); | |
65 | static void kdebug_sadb_x_sa2(struct sadb_ext *); | |
1c79356b A |
66 | |
67 | #ifdef KERNEL | |
91447636 | 68 | static 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 */ | |
78 | void | |
79 | kdebug_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; | |
1c79356b A |
152 | default: |
153 | printf("kdebug_sadb: invalid ext_type %u was passed.\n", | |
154 | ext->sadb_ext_type); | |
155 | return; | |
156 | } | |
157 | ||
158 | extlen = PFKEY_UNUNIT64(ext->sadb_ext_len); | |
159 | tlen -= extlen; | |
160 | ext = (struct sadb_ext *)((caddr_t)ext + extlen); | |
161 | } | |
162 | ||
163 | return; | |
164 | } | |
165 | ||
166 | static void | |
167 | kdebug_sadb_prop(ext) | |
168 | struct sadb_ext *ext; | |
169 | { | |
170 | struct sadb_prop *prop = (struct sadb_prop *)ext; | |
171 | struct sadb_comb *comb; | |
172 | int len; | |
173 | ||
174 | /* sanity check */ | |
175 | if (ext == NULL) | |
176 | panic("kdebug_sadb_prop: NULL pointer was passed.\n"); | |
177 | ||
178 | len = (PFKEY_UNUNIT64(prop->sadb_prop_len) - sizeof(*prop)) | |
179 | / sizeof(*comb); | |
180 | comb = (struct sadb_comb *)(prop + 1); | |
181 | printf("sadb_prop{ replay=%u\n", prop->sadb_prop_replay); | |
182 | ||
183 | while (len--) { | |
184 | printf("sadb_comb{ auth=%u encrypt=%u " | |
185 | "flags=0x%04x reserved=0x%08x\n", | |
186 | comb->sadb_comb_auth, comb->sadb_comb_encrypt, | |
187 | comb->sadb_comb_flags, comb->sadb_comb_reserved); | |
188 | ||
189 | printf(" auth_minbits=%u auth_maxbits=%u " | |
190 | "encrypt_minbits=%u encrypt_maxbits=%u\n", | |
191 | comb->sadb_comb_auth_minbits, | |
192 | comb->sadb_comb_auth_maxbits, | |
193 | comb->sadb_comb_encrypt_minbits, | |
194 | comb->sadb_comb_encrypt_maxbits); | |
195 | ||
196 | printf(" soft_alloc=%u hard_alloc=%u " | |
197 | "soft_bytes=%lu hard_bytes=%lu\n", | |
198 | comb->sadb_comb_soft_allocations, | |
199 | comb->sadb_comb_hard_allocations, | |
200 | (unsigned long)comb->sadb_comb_soft_bytes, | |
201 | (unsigned long)comb->sadb_comb_hard_bytes); | |
202 | ||
203 | printf(" soft_alloc=%lu hard_alloc=%lu " | |
204 | "soft_bytes=%lu hard_bytes=%lu }\n", | |
205 | (unsigned long)comb->sadb_comb_soft_addtime, | |
206 | (unsigned long)comb->sadb_comb_hard_addtime, | |
207 | (unsigned long)comb->sadb_comb_soft_usetime, | |
208 | (unsigned long)comb->sadb_comb_hard_usetime); | |
209 | comb++; | |
210 | } | |
211 | printf("}\n"); | |
212 | ||
213 | return; | |
214 | } | |
215 | ||
216 | static void | |
217 | kdebug_sadb_identity(ext) | |
218 | struct sadb_ext *ext; | |
219 | { | |
220 | struct sadb_ident *id = (struct sadb_ident *)ext; | |
221 | int len; | |
1c79356b A |
222 | |
223 | /* sanity check */ | |
224 | if (ext == NULL) | |
225 | panic("kdebug_sadb_identity: NULL pointer was passed.\n"); | |
226 | ||
227 | len = PFKEY_UNUNIT64(id->sadb_ident_len) - sizeof(*id); | |
228 | printf("sadb_ident_%s{", | |
229 | id->sadb_ident_exttype == SADB_EXT_IDENTITY_SRC ? "src" : "dst"); | |
230 | switch (id->sadb_ident_type) { | |
1c79356b A |
231 | default: |
232 | printf(" type=%d id=%lu", | |
233 | id->sadb_ident_type, (u_long)id->sadb_ident_id); | |
234 | if (len) { | |
235 | #ifdef KERNEL | |
236 | ipsec_hexdump((caddr_t)(id + 1), len); /*XXX cast ?*/ | |
237 | #else | |
238 | char *p, *ep; | |
239 | printf("\n str=\""); | |
240 | p = (char *)(id + 1); | |
241 | ep = p + len; | |
242 | for (/*nothing*/; *p && p < ep; p++) { | |
243 | if (isprint(*p)) | |
244 | printf("%c", *p & 0xff); | |
245 | else | |
246 | printf("\\%03o", *p & 0xff); | |
247 | } | |
248 | #endif | |
249 | printf("\""); | |
250 | } | |
251 | break; | |
252 | } | |
253 | ||
254 | printf(" }\n"); | |
255 | ||
256 | return; | |
257 | } | |
258 | ||
259 | static void | |
260 | kdebug_sadb_supported(ext) | |
261 | struct sadb_ext *ext; | |
262 | { | |
263 | struct sadb_supported *sup = (struct sadb_supported *)ext; | |
264 | struct sadb_alg *alg; | |
265 | int len; | |
266 | ||
267 | /* sanity check */ | |
268 | if (ext == NULL) | |
269 | panic("kdebug_sadb_supported: NULL pointer was passed.\n"); | |
270 | ||
271 | len = (PFKEY_UNUNIT64(sup->sadb_supported_len) - sizeof(*sup)) | |
272 | / sizeof(*alg); | |
273 | alg = (struct sadb_alg *)(sup + 1); | |
274 | printf("sadb_sup{\n"); | |
275 | while (len--) { | |
276 | printf(" { id=%d ivlen=%d min=%d max=%d }\n", | |
277 | alg->sadb_alg_id, alg->sadb_alg_ivlen, | |
278 | alg->sadb_alg_minbits, alg->sadb_alg_maxbits); | |
279 | alg++; | |
280 | } | |
281 | printf("}\n"); | |
282 | ||
283 | return; | |
284 | } | |
285 | ||
286 | static void | |
287 | kdebug_sadb_lifetime(ext) | |
288 | struct sadb_ext *ext; | |
289 | { | |
290 | struct sadb_lifetime *lft = (struct sadb_lifetime *)ext; | |
291 | ||
292 | /* sanity check */ | |
293 | if (ext == NULL) | |
294 | printf("kdebug_sadb_lifetime: NULL pointer was passed.\n"); | |
295 | ||
296 | printf("sadb_lifetime{ alloc=%u, bytes=%u\n", | |
297 | lft->sadb_lifetime_allocations, | |
298 | (u_int32_t)lft->sadb_lifetime_bytes); | |
299 | printf(" addtime=%u, usetime=%u }\n", | |
300 | (u_int32_t)lft->sadb_lifetime_addtime, | |
301 | (u_int32_t)lft->sadb_lifetime_usetime); | |
302 | ||
303 | return; | |
304 | } | |
305 | ||
306 | static void | |
307 | kdebug_sadb_sa(ext) | |
308 | struct sadb_ext *ext; | |
309 | { | |
310 | struct sadb_sa *sa = (struct sadb_sa *)ext; | |
311 | ||
312 | /* sanity check */ | |
313 | if (ext == NULL) | |
314 | panic("kdebug_sadb_sa: NULL pointer was passed.\n"); | |
315 | ||
316 | printf("sadb_sa{ spi=%u replay=%u state=%u\n", | |
317 | (u_int32_t)ntohl(sa->sadb_sa_spi), sa->sadb_sa_replay, | |
318 | sa->sadb_sa_state); | |
319 | printf(" auth=%u encrypt=%u flags=0x%08x }\n", | |
320 | sa->sadb_sa_auth, sa->sadb_sa_encrypt, sa->sadb_sa_flags); | |
321 | ||
322 | return; | |
323 | } | |
324 | ||
325 | static void | |
326 | kdebug_sadb_address(ext) | |
327 | struct sadb_ext *ext; | |
328 | { | |
329 | struct sadb_address *addr = (struct sadb_address *)ext; | |
330 | ||
331 | /* sanity check */ | |
332 | if (ext == NULL) | |
333 | panic("kdebug_sadb_address: NULL pointer was passed.\n"); | |
334 | ||
335 | printf("sadb_address{ proto=%u prefixlen=%u reserved=0x%02x%02x }\n", | |
336 | addr->sadb_address_proto, addr->sadb_address_prefixlen, | |
337 | ((u_char *)&addr->sadb_address_reserved)[0], | |
338 | ((u_char *)&addr->sadb_address_reserved)[1]); | |
339 | ||
340 | kdebug_sockaddr((struct sockaddr *)((caddr_t)ext + sizeof(*addr))); | |
341 | ||
342 | return; | |
343 | } | |
344 | ||
345 | static void | |
346 | kdebug_sadb_key(ext) | |
347 | struct sadb_ext *ext; | |
348 | { | |
349 | struct sadb_key *key = (struct sadb_key *)ext; | |
350 | ||
351 | /* sanity check */ | |
352 | if (ext == NULL) | |
353 | panic("kdebug_sadb_key: NULL pointer was passed.\n"); | |
354 | ||
355 | printf("sadb_key{ bits=%u reserved=%u\n", | |
356 | key->sadb_key_bits, key->sadb_key_reserved); | |
357 | printf(" key="); | |
358 | ||
359 | /* sanity check 2 */ | |
360 | if ((key->sadb_key_bits >> 3) > | |
361 | (PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key))) { | |
362 | printf("kdebug_sadb_key: key length mismatch, bit:%d len:%ld.\n", | |
363 | key->sadb_key_bits >> 3, | |
364 | (long)PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key)); | |
365 | } | |
366 | ||
367 | ipsec_hexdump((caddr_t)key + sizeof(struct sadb_key), | |
368 | key->sadb_key_bits >> 3); | |
369 | printf(" }\n"); | |
370 | return; | |
371 | } | |
372 | ||
9bccf70c A |
373 | static void |
374 | kdebug_sadb_x_sa2(ext) | |
375 | struct sadb_ext *ext; | |
376 | { | |
377 | struct sadb_x_sa2 *sa2 = (struct sadb_x_sa2 *)ext; | |
378 | ||
379 | /* sanity check */ | |
380 | if (ext == NULL) | |
381 | panic("kdebug_sadb_x_sa2: NULL pointer was passed.\n"); | |
382 | ||
383 | printf("sadb_x_sa2{ mode=%u reqid=%u\n", | |
384 | sa2->sadb_x_sa2_mode, sa2->sadb_x_sa2_reqid); | |
55e303ae A |
385 | printf(" reserved1=%u reserved2=%u sequence=%u }\n", |
386 | sa2->sadb_x_sa2_reserved1, sa2->sadb_x_sa2_reserved2, | |
387 | sa2->sadb_x_sa2_sequence); | |
9bccf70c A |
388 | |
389 | return; | |
390 | } | |
391 | ||
1c79356b A |
392 | void |
393 | kdebug_sadb_x_policy(ext) | |
394 | struct sadb_ext *ext; | |
395 | { | |
396 | struct sadb_x_policy *xpl = (struct sadb_x_policy *)ext; | |
397 | struct sockaddr *addr; | |
398 | ||
399 | /* sanity check */ | |
400 | if (ext == NULL) | |
401 | panic("kdebug_sadb_x_policy: NULL pointer was passed.\n"); | |
402 | ||
9bccf70c | 403 | printf("sadb_x_policy{ type=%u dir=%u id=%x }\n", |
1c79356b | 404 | xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir, |
9bccf70c | 405 | xpl->sadb_x_policy_id); |
1c79356b A |
406 | |
407 | if (xpl->sadb_x_policy_type == IPSEC_POLICY_IPSEC) { | |
408 | int tlen; | |
409 | struct sadb_x_ipsecrequest *xisr; | |
410 | ||
411 | tlen = PFKEY_UNUNIT64(xpl->sadb_x_policy_len) - sizeof(*xpl); | |
412 | xisr = (struct sadb_x_ipsecrequest *)(xpl + 1); | |
413 | ||
414 | while (tlen > 0) { | |
415 | printf(" { len=%u proto=%u mode=%u level=%u reqid=%u\n", | |
416 | xisr->sadb_x_ipsecrequest_len, | |
417 | xisr->sadb_x_ipsecrequest_proto, | |
418 | xisr->sadb_x_ipsecrequest_mode, | |
419 | xisr->sadb_x_ipsecrequest_level, | |
420 | xisr->sadb_x_ipsecrequest_reqid); | |
421 | ||
422 | if (xisr->sadb_x_ipsecrequest_len > sizeof(*xisr)) { | |
423 | addr = (struct sockaddr *)(xisr + 1); | |
424 | kdebug_sockaddr(addr); | |
425 | addr = (struct sockaddr *)((caddr_t)addr | |
426 | + addr->sa_len); | |
427 | kdebug_sockaddr(addr); | |
428 | } | |
429 | ||
430 | printf(" }\n"); | |
431 | ||
432 | /* prevent infinite loop */ | |
433 | if (xisr->sadb_x_ipsecrequest_len <= 0) { | |
434 | printf("kdebug_sadb_x_policy: wrong policy struct.\n"); | |
435 | return; | |
436 | } | |
437 | /* prevent overflow */ | |
438 | if (xisr->sadb_x_ipsecrequest_len > tlen) { | |
439 | printf("invalid ipsec policy length\n"); | |
440 | return; | |
441 | } | |
442 | ||
443 | tlen -= xisr->sadb_x_ipsecrequest_len; | |
444 | ||
445 | xisr = (struct sadb_x_ipsecrequest *)((caddr_t)xisr | |
446 | + xisr->sadb_x_ipsecrequest_len); | |
447 | } | |
448 | ||
449 | if (tlen != 0) | |
450 | panic("kdebug_sadb_x_policy: wrong policy struct.\n"); | |
451 | } | |
452 | ||
453 | return; | |
454 | } | |
455 | ||
456 | #ifdef KERNEL | |
457 | /* %%%: about SPD and SAD */ | |
458 | void | |
459 | kdebug_secpolicy(sp) | |
460 | struct secpolicy *sp; | |
461 | { | |
462 | /* sanity check */ | |
463 | if (sp == NULL) | |
464 | panic("kdebug_secpolicy: NULL pointer was passed.\n"); | |
465 | ||
466 | printf("secpolicy{ refcnt=%u state=%u policy=%u\n", | |
467 | sp->refcnt, sp->state, sp->policy); | |
468 | ||
469 | kdebug_secpolicyindex(&sp->spidx); | |
470 | ||
471 | switch (sp->policy) { | |
472 | case IPSEC_POLICY_DISCARD: | |
473 | printf(" type=discard }\n"); | |
474 | break; | |
475 | case IPSEC_POLICY_NONE: | |
476 | printf(" type=none }\n"); | |
477 | break; | |
478 | case IPSEC_POLICY_IPSEC: | |
479 | { | |
480 | struct ipsecrequest *isr; | |
481 | for (isr = sp->req; isr != NULL; isr = isr->next) { | |
482 | ||
483 | printf(" level=%u\n", isr->level); | |
484 | kdebug_secasindex(&isr->saidx); | |
485 | ||
486 | if (isr->sav != NULL) | |
487 | kdebug_secasv(isr->sav); | |
488 | } | |
489 | printf(" }\n"); | |
490 | } | |
491 | break; | |
492 | case IPSEC_POLICY_BYPASS: | |
493 | printf(" type=bypass }\n"); | |
494 | break; | |
495 | case IPSEC_POLICY_ENTRUST: | |
496 | printf(" type=entrust }\n"); | |
497 | break; | |
498 | default: | |
499 | printf("kdebug_secpolicy: Invalid policy found. %d\n", | |
500 | sp->policy); | |
501 | break; | |
502 | } | |
503 | ||
504 | return; | |
505 | } | |
506 | ||
507 | void | |
508 | kdebug_secpolicyindex(spidx) | |
509 | struct secpolicyindex *spidx; | |
510 | { | |
511 | /* sanity check */ | |
512 | if (spidx == NULL) | |
513 | panic("kdebug_secpolicyindex: NULL pointer was passed.\n"); | |
514 | ||
515 | printf("secpolicyindex{ dir=%u prefs=%u prefd=%u ul_proto=%u\n", | |
516 | spidx->dir, spidx->prefs, spidx->prefd, spidx->ul_proto); | |
517 | ||
518 | ipsec_hexdump((caddr_t)&spidx->src, | |
519 | ((struct sockaddr *)&spidx->src)->sa_len); | |
520 | printf("\n"); | |
521 | ipsec_hexdump((caddr_t)&spidx->dst, | |
522 | ((struct sockaddr *)&spidx->dst)->sa_len); | |
523 | printf("}\n"); | |
524 | ||
525 | return; | |
526 | } | |
527 | ||
528 | void | |
529 | kdebug_secasindex(saidx) | |
530 | struct secasindex *saidx; | |
531 | { | |
532 | /* sanity check */ | |
533 | if (saidx == NULL) | |
534 | panic("kdebug_secpolicyindex: NULL pointer was passed.\n"); | |
535 | ||
536 | printf("secasindex{ mode=%u proto=%u\n", | |
537 | saidx->mode, saidx->proto); | |
538 | ||
539 | ipsec_hexdump((caddr_t)&saidx->src, | |
540 | ((struct sockaddr *)&saidx->src)->sa_len); | |
541 | printf("\n"); | |
542 | ipsec_hexdump((caddr_t)&saidx->dst, | |
543 | ((struct sockaddr *)&saidx->dst)->sa_len); | |
544 | printf("\n"); | |
545 | ||
546 | return; | |
547 | } | |
548 | ||
549 | void | |
550 | kdebug_secasv(sav) | |
551 | struct secasvar *sav; | |
552 | { | |
553 | /* sanity check */ | |
554 | if (sav == NULL) | |
555 | panic("kdebug_secasv: NULL pointer was passed.\n"); | |
556 | ||
557 | printf("secas{"); | |
558 | kdebug_secasindex(&sav->sah->saidx); | |
559 | ||
560 | printf(" refcnt=%u state=%u auth=%u enc=%u\n", | |
561 | sav->refcnt, sav->state, sav->alg_auth, sav->alg_enc); | |
562 | printf(" spi=%u flags=%u\n", | |
563 | (u_int32_t)ntohl(sav->spi), sav->flags); | |
564 | ||
565 | if (sav->key_auth != NULL) | |
566 | kdebug_sadb_key((struct sadb_ext *)sav->key_auth); | |
567 | if (sav->key_enc != NULL) | |
568 | kdebug_sadb_key((struct sadb_ext *)sav->key_enc); | |
569 | if (sav->iv != NULL) { | |
570 | printf(" iv="); | |
571 | ipsec_hexdump(sav->iv, sav->ivlen ? sav->ivlen : 8); | |
572 | printf("\n"); | |
573 | } | |
574 | ||
575 | if (sav->replay != NULL) | |
576 | kdebug_secreplay(sav->replay); | |
577 | if (sav->lft_c != NULL) | |
578 | kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_c); | |
579 | if (sav->lft_h != NULL) | |
580 | kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_h); | |
581 | if (sav->lft_s != NULL) | |
582 | kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_s); | |
583 | ||
584 | #if notyet | |
585 | /* XXX: misc[123] ? */ | |
586 | #endif | |
587 | ||
588 | return; | |
589 | } | |
590 | ||
591 | static void | |
592 | kdebug_secreplay(rpl) | |
593 | struct secreplay *rpl; | |
594 | { | |
595 | int len, l; | |
596 | ||
597 | /* sanity check */ | |
598 | if (rpl == NULL) | |
599 | panic("kdebug_secreplay: NULL pointer was passed.\n"); | |
600 | ||
601 | printf(" secreplay{ count=%u wsize=%u seq=%u lastseq=%u", | |
602 | rpl->count, rpl->wsize, rpl->seq, rpl->lastseq); | |
603 | ||
604 | if (rpl->bitmap == NULL) { | |
605 | printf(" }\n"); | |
606 | return; | |
607 | } | |
608 | ||
9bccf70c | 609 | printf("\n bitmap { "); |
1c79356b A |
610 | |
611 | for (len = 0; len < rpl->wsize; len++) { | |
612 | for (l = 7; l >= 0; l--) | |
613 | printf("%u", (((rpl->bitmap)[len] >> l) & 1) ? 1 : 0); | |
614 | } | |
615 | printf(" }\n"); | |
616 | ||
617 | return; | |
618 | } | |
619 | ||
620 | void | |
621 | kdebug_mbufhdr(m) | |
622 | struct mbuf *m; | |
623 | { | |
624 | /* sanity check */ | |
625 | if (m == NULL) | |
9bccf70c | 626 | return; |
1c79356b A |
627 | |
628 | printf("mbuf(%p){ m_next:%p m_nextpkt:%p m_data:%p " | |
629 | "m_len:%d m_type:0x%02x m_flags:0x%02x }\n", | |
630 | m, m->m_next, m->m_nextpkt, m->m_data, | |
631 | m->m_len, m->m_type, m->m_flags); | |
632 | ||
633 | if (m->m_flags & M_PKTHDR) { | |
634 | printf(" m_pkthdr{ len:%d rcvif:%p }\n", | |
635 | m->m_pkthdr.len, m->m_pkthdr.rcvif); | |
636 | } | |
637 | ||
1c79356b A |
638 | if (m->m_flags & M_EXT) { |
639 | printf(" m_ext{ ext_buf:%p ext_free:%p " | |
640 | "ext_size:%u ext_ref:%p }\n", | |
641 | m->m_ext.ext_buf, m->m_ext.ext_free, | |
9bccf70c | 642 | m->m_ext.ext_size, m->m_ext.ext_refs); |
1c79356b | 643 | } |
1c79356b A |
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 | ||
1c79356b | 655 | for (j = 0; m; m = m->m_next) { |
9bccf70c A |
656 | kdebug_mbufhdr(m); |
657 | printf(" m_data:\n"); | |
1c79356b | 658 | for (i = 0; i < m->m_len; i++) { |
9bccf70c A |
659 | if (i && i % 32 == 0) |
660 | printf("\n"); | |
661 | if (i % 4 == 0) | |
662 | printf(" "); | |
1c79356b A |
663 | printf("%02x", mtod(m, u_char *)[i]); |
664 | j++; | |
665 | } | |
9bccf70c | 666 | printf("\n"); |
1c79356b A |
667 | } |
668 | ||
1c79356b A |
669 | return; |
670 | } | |
671 | #endif /* KERNEL */ | |
672 | ||
673 | void | |
674 | kdebug_sockaddr(addr) | |
675 | struct sockaddr *addr; | |
676 | { | |
55e303ae | 677 | struct sockaddr_in *sin4; |
9bccf70c A |
678 | #ifdef INET6 |
679 | struct sockaddr_in6 *sin6; | |
680 | #endif | |
681 | ||
1c79356b A |
682 | /* sanity check */ |
683 | if (addr == NULL) | |
684 | panic("kdebug_sockaddr: NULL pointer was passed.\n"); | |
685 | ||
686 | /* NOTE: We deal with port number as host byte order. */ | |
9bccf70c | 687 | printf("sockaddr{ len=%u family=%u", addr->sa_len, addr->sa_family); |
1c79356b | 688 | |
9bccf70c A |
689 | switch (addr->sa_family) { |
690 | case AF_INET: | |
55e303ae A |
691 | sin4 = (struct sockaddr_in *)addr; |
692 | printf(" port=%u\n", ntohs(sin4->sin_port)); | |
693 | ipsec_hexdump((caddr_t)&sin4->sin_addr, sizeof(sin4->sin_addr)); | |
9bccf70c | 694 | break; |
1c79356b | 695 | #ifdef INET6 |
9bccf70c A |
696 | case AF_INET6: |
697 | sin6 = (struct sockaddr_in6 *)addr; | |
698 | printf(" port=%u\n", ntohs(sin6->sin6_port)); | |
1c79356b | 699 | printf(" flowinfo=0x%08x, scope_id=0x%08x\n", |
9bccf70c A |
700 | sin6->sin6_flowinfo, sin6->sin6_scope_id); |
701 | ipsec_hexdump((caddr_t)&sin6->sin6_addr, | |
702 | sizeof(sin6->sin6_addr)); | |
703 | break; | |
1c79356b | 704 | #endif |
9bccf70c | 705 | } |
1c79356b A |
706 | |
707 | printf(" }\n"); | |
708 | ||
709 | return; | |
710 | } | |
711 | ||
1c79356b A |
712 | void |
713 | ipsec_bindump(buf, len) | |
714 | caddr_t buf; | |
715 | int len; | |
716 | { | |
717 | int i; | |
718 | ||
719 | for (i = 0; i < len; i++) | |
720 | printf("%c", (unsigned char)buf[i]); | |
721 | ||
722 | return; | |
723 | } | |
724 | ||
725 | ||
726 | void | |
727 | ipsec_hexdump(buf, len) | |
728 | caddr_t buf; | |
729 | int len; | |
730 | { | |
731 | int i; | |
732 | ||
733 | for (i = 0; i < len; i++) { | |
734 | if (i != 0 && i % 32 == 0) printf("\n"); | |
735 | if (i % 4 == 0) printf(" "); | |
736 | printf("%02x", (unsigned char)buf[i]); | |
737 | } | |
738 | #if 0 | |
739 | if (i % 32 != 0) printf("\n"); | |
740 | #endif | |
741 | ||
742 | return; | |
743 | } | |
744 | ||
9bccf70c | 745 | #endif /* !defined(KERNEL) || (defined(KERNEL) && defined(IPSEC_DEBUG)) */ |