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