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