]> The Tcpdump Group git mirrors - tcpdump/blob - print-isakmp.c
finalize the evp.h bugfix (#46)
[tcpdump] / print-isakmp.c
1 /*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
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.
16 *
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 */
30
31 #ifndef lint
32 static const char rcsid[] _U_ =
33 "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.61 2008-02-05 19:34:25 guy Exp $ (LBL)";
34 #endif
35
36 #define NETDISSECT_REWORKED
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 /* The functions from print-esp.c used in this file are only defined when both
42 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
43 */
44 #ifndef HAVE_OPENSSL_EVP_H
45 #undef HAVE_LIBCRYPTO
46 #endif
47
48 #include <tcpdump-stdinc.h>
49
50 #include <string.h>
51
52 #include <stdio.h>
53
54 #include "isakmp.h"
55 #include "ipsec_doi.h"
56 #include "oakley.h"
57 #include "interface.h"
58 #include "addrtoname.h"
59 #include "extract.h" /* must come after interface.h */
60
61 #include "ip.h"
62 #ifdef INET6
63 #include "ip6.h"
64 #endif
65
66 #ifndef HAVE_SOCKADDR_STORAGE
67 #define sockaddr_storage sockaddr
68 #endif
69
70 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
71 netdissect_options *ndo, u_char tpay, \
72 const struct isakmp_gen *ext, \
73 u_int item_len, \
74 const u_char *end_pointer, \
75 u_int32_t phase,\
76 u_int32_t doi0, \
77 u_int32_t proto0, int depth)
78
79 DECLARE_PRINTER(v1_sa);
80 DECLARE_PRINTER(v1_p);
81 DECLARE_PRINTER(v1_t);
82 DECLARE_PRINTER(v1_ke);
83 DECLARE_PRINTER(v1_id);
84 DECLARE_PRINTER(v1_cert);
85 DECLARE_PRINTER(v1_cr);
86 DECLARE_PRINTER(v1_sig);
87 DECLARE_PRINTER(v1_hash);
88 DECLARE_PRINTER(v1_nonce);
89 DECLARE_PRINTER(v1_n);
90 DECLARE_PRINTER(v1_d);
91 DECLARE_PRINTER(v1_vid);
92
93 DECLARE_PRINTER(v2_sa);
94 DECLARE_PRINTER(v2_ke);
95 DECLARE_PRINTER(v2_ID);
96 DECLARE_PRINTER(v2_cert);
97 DECLARE_PRINTER(v2_cr);
98 DECLARE_PRINTER(v2_auth);
99 DECLARE_PRINTER(v2_nonce);
100 DECLARE_PRINTER(v2_n);
101 DECLARE_PRINTER(v2_d);
102 DECLARE_PRINTER(v2_vid);
103 DECLARE_PRINTER(v2_TS);
104 DECLARE_PRINTER(v2_cp);
105 DECLARE_PRINTER(v2_eap);
106
107 static const u_char *ikev2_e_print(netdissect_options *ndo,
108 struct isakmp *base,
109 u_char tpay,
110 const struct isakmp_gen *ext,
111 u_int item_len,
112 const u_char *end_pointer,
113 u_int32_t phase,
114 u_int32_t doi0,
115 u_int32_t proto0, int depth);
116
117
118 static const u_char *ike_sub0_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
119 const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
120 static const u_char *ikev1_sub_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
121 const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
122
123 static const u_char *ikev2_sub_print(netdissect_options *ndo,
124 struct isakmp *base,
125 u_char np, const struct isakmp_gen *ext,
126 const u_char *ep, u_int32_t phase,
127 u_int32_t doi, u_int32_t proto,
128 int depth);
129
130
131 static char *numstr(int);
132 static void safememcpy(void *, const void *, size_t);
133
134 static void
135 ikev1_print(netdissect_options *ndo,
136 const u_char *bp, u_int length,
137 const u_char *bp2, struct isakmp *base);
138
139 #define MAXINITIATORS 20
140 int ninitiator = 0;
141 struct {
142 cookie_t initiator;
143 struct sockaddr_storage iaddr;
144 struct sockaddr_storage raddr;
145 } cookiecache[MAXINITIATORS];
146
147 /* protocol id */
148 static const char *protoidstr[] = {
149 NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
150 };
151
152 /* isakmp->np */
153 static const char *npstr[] = {
154 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
155 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
156 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
157 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
158 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
159 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
160 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
161 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
162 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
163 "v2eap", /* 48 */
164
165 };
166
167 /* isakmp->np */
168 static const u_char *(*npfunc[])(netdissect_options *ndo, u_char tpay,
169 const struct isakmp_gen *ext,
170 u_int item_len,
171 const u_char *end_pointer,
172 u_int32_t phase,
173 u_int32_t doi0,
174 u_int32_t proto0, int depth) = {
175 NULL,
176 ikev1_sa_print,
177 ikev1_p_print,
178 ikev1_t_print,
179 ikev1_ke_print,
180 ikev1_id_print,
181 ikev1_cert_print,
182 ikev1_cr_print,
183 ikev1_hash_print,
184 ikev1_sig_print,
185 ikev1_nonce_print,
186 ikev1_n_print,
187 ikev1_d_print,
188 ikev1_vid_print, /* 13 */
189 NULL, NULL, NULL, NULL, NULL, /* 14- 18 */
190 NULL, NULL, NULL, NULL, NULL, /* 19- 23 */
191 NULL, NULL, NULL, NULL, NULL, /* 24- 28 */
192 NULL, NULL, NULL, NULL, /* 29- 32 */
193 ikev2_sa_print, /* 33 */
194 ikev2_ke_print, /* 34 */
195 ikev2_ID_print, /* 35 */
196 ikev2_ID_print, /* 36 */
197 ikev2_cert_print, /* 37 */
198 ikev2_cr_print, /* 38 */
199 ikev2_auth_print, /* 39 */
200 ikev2_nonce_print, /* 40 */
201 ikev2_n_print, /* 41 */
202 ikev2_d_print, /* 42 */
203 ikev2_vid_print, /* 43 */
204 ikev2_TS_print, /* 44 */
205 ikev2_TS_print, /* 45 */
206 NULL, /* ikev2_e_print,*/ /* 46 - special */
207 ikev2_cp_print, /* 47 */
208 ikev2_eap_print, /* 48 */
209 };
210
211 /* isakmp->etype */
212 static const char *etypestr[] = {
213 /* IKEv1 exchange types */
214 "none", "base", "ident", "auth", "agg", "inf", NULL, NULL, /* 0-7 */
215 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 8-15 */
216 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 16-23 */
217 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 24-31 */
218 "oakley-quick", "oakley-newgroup", /* 32-33 */
219 /* IKEv2 exchange types */
220 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
221 };
222
223 #define STR_OR_ID(x, tab) \
224 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
225 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
226 #define NPSTR(x) STR_OR_ID(x, npstr)
227 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
228
229 #define CHECKLEN(p, np) \
230 if (ep < (u_char *)(p)) { \
231 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
232 goto done; \
233 }
234
235
236 #define NPFUNC(x) \
237 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
238 ? npfunc[(x)] : NULL)
239
240 static int
241 iszero(u_char *p, size_t l)
242 {
243 while (l--) {
244 if (*p++)
245 return 0;
246 }
247 return 1;
248 }
249
250 /* find cookie from initiator cache */
251 static int
252 cookie_find(cookie_t *in)
253 {
254 int i;
255
256 for (i = 0; i < MAXINITIATORS; i++) {
257 if (memcmp(in, &cookiecache[i].initiator, sizeof(*in)) == 0)
258 return i;
259 }
260
261 return -1;
262 }
263
264 /* record initiator */
265 static void
266 cookie_record(cookie_t *in, const u_char *bp2)
267 {
268 int i;
269 struct ip *ip;
270 struct sockaddr_in *sin;
271 #ifdef INET6
272 struct ip6_hdr *ip6;
273 struct sockaddr_in6 *sin6;
274 #endif
275
276 i = cookie_find(in);
277 if (0 <= i) {
278 ninitiator = (i + 1) % MAXINITIATORS;
279 return;
280 }
281
282 ip = (struct ip *)bp2;
283 switch (IP_V(ip)) {
284 case 4:
285 memset(&cookiecache[ninitiator].iaddr, 0,
286 sizeof(cookiecache[ninitiator].iaddr));
287 memset(&cookiecache[ninitiator].raddr, 0,
288 sizeof(cookiecache[ninitiator].raddr));
289
290 sin = (struct sockaddr_in *)&cookiecache[ninitiator].iaddr;
291 #ifdef HAVE_SOCKADDR_SA_LEN
292 sin->sin_len = sizeof(struct sockaddr_in);
293 #endif
294 sin->sin_family = AF_INET;
295 memcpy(&sin->sin_addr, &ip->ip_src, sizeof(ip->ip_src));
296 sin = (struct sockaddr_in *)&cookiecache[ninitiator].raddr;
297 #ifdef HAVE_SOCKADDR_SA_LEN
298 sin->sin_len = sizeof(struct sockaddr_in);
299 #endif
300 sin->sin_family = AF_INET;
301 memcpy(&sin->sin_addr, &ip->ip_dst, sizeof(ip->ip_dst));
302 break;
303 #ifdef INET6
304 case 6:
305 memset(&cookiecache[ninitiator].iaddr, 0,
306 sizeof(cookiecache[ninitiator].iaddr));
307 memset(&cookiecache[ninitiator].raddr, 0,
308 sizeof(cookiecache[ninitiator].raddr));
309
310 ip6 = (struct ip6_hdr *)bp2;
311 sin6 = (struct sockaddr_in6 *)&cookiecache[ninitiator].iaddr;
312 #ifdef HAVE_SOCKADDR_SA_LEN
313 sin6->sin6_len = sizeof(struct sockaddr_in6);
314 #endif
315 sin6->sin6_family = AF_INET6;
316 memcpy(&sin6->sin6_addr, &ip6->ip6_src, sizeof(ip6->ip6_src));
317 sin6 = (struct sockaddr_in6 *)&cookiecache[ninitiator].raddr;
318 #ifdef HAVE_SOCKADDR_SA_LEN
319 sin6->sin6_len = sizeof(struct sockaddr_in6);
320 #endif
321 sin6->sin6_family = AF_INET6;
322 memcpy(&sin6->sin6_addr, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
323 break;
324 #endif
325 default:
326 return;
327 }
328 memcpy(&cookiecache[ninitiator].initiator, in, sizeof(*in));
329 ninitiator = (ninitiator + 1) % MAXINITIATORS;
330 }
331
332 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
333 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
334 static int
335 cookie_sidecheck(int i, const u_char *bp2, int initiator)
336 {
337 struct sockaddr_storage ss;
338 struct sockaddr *sa;
339 struct ip *ip;
340 struct sockaddr_in *sin;
341 #ifdef INET6
342 struct ip6_hdr *ip6;
343 struct sockaddr_in6 *sin6;
344 #endif
345 int salen;
346
347 memset(&ss, 0, sizeof(ss));
348 ip = (struct ip *)bp2;
349 switch (IP_V(ip)) {
350 case 4:
351 sin = (struct sockaddr_in *)&ss;
352 #ifdef HAVE_SOCKADDR_SA_LEN
353 sin->sin_len = sizeof(struct sockaddr_in);
354 #endif
355 sin->sin_family = AF_INET;
356 memcpy(&sin->sin_addr, &ip->ip_src, sizeof(ip->ip_src));
357 break;
358 #ifdef INET6
359 case 6:
360 ip6 = (struct ip6_hdr *)bp2;
361 sin6 = (struct sockaddr_in6 *)&ss;
362 #ifdef HAVE_SOCKADDR_SA_LEN
363 sin6->sin6_len = sizeof(struct sockaddr_in6);
364 #endif
365 sin6->sin6_family = AF_INET6;
366 memcpy(&sin6->sin6_addr, &ip6->ip6_src, sizeof(ip6->ip6_src));
367 break;
368 #endif
369 default:
370 return 0;
371 }
372
373 sa = (struct sockaddr *)&ss;
374 if (initiator) {
375 if (sa->sa_family != ((struct sockaddr *)&cookiecache[i].iaddr)->sa_family)
376 return 0;
377 #ifdef HAVE_SOCKADDR_SA_LEN
378 salen = sa->sa_len;
379 #else
380 #ifdef INET6
381 if (sa->sa_family == AF_INET6)
382 salen = sizeof(struct sockaddr_in6);
383 else
384 salen = sizeof(struct sockaddr);
385 #else
386 salen = sizeof(struct sockaddr);
387 #endif
388 #endif
389 if (memcmp(&ss, &cookiecache[i].iaddr, salen) == 0)
390 return 1;
391 } else {
392 if (sa->sa_family != ((struct sockaddr *)&cookiecache[i].raddr)->sa_family)
393 return 0;
394 #ifdef HAVE_SOCKADDR_SA_LEN
395 salen = sa->sa_len;
396 #else
397 #ifdef INET6
398 if (sa->sa_family == AF_INET6)
399 salen = sizeof(struct sockaddr_in6);
400 else
401 salen = sizeof(struct sockaddr);
402 #else
403 salen = sizeof(struct sockaddr);
404 #endif
405 #endif
406 if (memcmp(&ss, &cookiecache[i].raddr, salen) == 0)
407 return 1;
408 }
409 return 0;
410 }
411
412 static void
413 hexprint(netdissect_options *ndo, caddr_t loc, size_t len)
414 {
415 u_char *p;
416 size_t i;
417
418 p = (u_char *)loc;
419 for (i = 0; i < len; i++)
420 ND_PRINT((ndo,"%02x", p[i] & 0xff));
421 }
422
423 static int
424 rawprint(netdissect_options *ndo, caddr_t loc, size_t len)
425 {
426 ND_TCHECK2(*loc, len);
427
428 hexprint(ndo, loc, len);
429 return 1;
430 trunc:
431 return 0;
432 }
433
434
435 /*
436 * returns false if we run out of data buffer
437 */
438 static int ike_show_somedata(struct netdissect_options *ndo,
439 const u_char *cp, const u_char *ep)
440 {
441 /* there is too much data, just show some of it */
442 const u_char *end = ep - 20;
443 int elen = 20;
444 int len = ep - cp;
445 if(len > 10) {
446 len = 10;
447 }
448
449 /* really shouldn't happen because of above */
450 if(end < cp + len) {
451 end = cp+len;
452 elen = ep - end;
453 }
454
455 ND_PRINT((ndo," data=("));
456 if(!rawprint(ndo, (caddr_t)(cp), len)) goto trunc;
457 ND_PRINT((ndo, "..."));
458 if(elen) {
459 if(!rawprint(ndo, (caddr_t)(end), elen)) goto trunc;
460 }
461 ND_PRINT((ndo,")"));
462 return 1;
463
464 trunc:
465 return 0;
466 }
467
468 struct attrmap {
469 const char *type;
470 u_int nvalue;
471 const char *value[30]; /*XXX*/
472 };
473
474 static const u_char *
475 ikev1_attrmap_print(netdissect_options *ndo,
476 const u_char *p, const u_char *ep,
477 const struct attrmap *map, size_t nmap)
478 {
479 u_int16_t *q;
480 int totlen;
481 u_int32_t t, v;
482
483 q = (u_int16_t *)p;
484 if (p[0] & 0x80)
485 totlen = 4;
486 else
487 totlen = 4 + EXTRACT_16BITS(&q[1]);
488 if (ep < p + totlen) {
489 ND_PRINT((ndo,"[|attr]"));
490 return ep + 1;
491 }
492
493 ND_PRINT((ndo,"("));
494 t = EXTRACT_16BITS(&q[0]) & 0x7fff;
495 if (map && t < nmap && map[t].type)
496 ND_PRINT((ndo,"type=%s ", map[t].type));
497 else
498 ND_PRINT((ndo,"type=#%d ", t));
499 if (p[0] & 0x80) {
500 ND_PRINT((ndo,"value="));
501 v = EXTRACT_16BITS(&q[1]);
502 if (map && t < nmap && v < map[t].nvalue && map[t].value[v])
503 ND_PRINT((ndo,"%s", map[t].value[v]));
504 else
505 rawprint(ndo, (caddr_t)&q[1], 2);
506 } else {
507 ND_PRINT((ndo,"len=%d value=", EXTRACT_16BITS(&q[1])));
508 rawprint(ndo, (caddr_t)&p[4], EXTRACT_16BITS(&q[1]));
509 }
510 ND_PRINT((ndo,")"));
511 return p + totlen;
512 }
513
514 static const u_char *
515 ikev1_attr_print(netdissect_options *ndo, const u_char *p, const u_char *ep)
516 {
517 u_int16_t *q;
518 int totlen;
519 u_int32_t t;
520
521 q = (u_int16_t *)p;
522 if (p[0] & 0x80)
523 totlen = 4;
524 else
525 totlen = 4 + EXTRACT_16BITS(&q[1]);
526 if (ep < p + totlen) {
527 ND_PRINT((ndo,"[|attr]"));
528 return ep + 1;
529 }
530
531 ND_PRINT((ndo,"("));
532 t = EXTRACT_16BITS(&q[0]) & 0x7fff;
533 ND_PRINT((ndo,"type=#%d ", t));
534 if (p[0] & 0x80) {
535 ND_PRINT((ndo,"value="));
536 t = q[1];
537 rawprint(ndo, (caddr_t)&q[1], 2);
538 } else {
539 ND_PRINT((ndo,"len=%d value=", EXTRACT_16BITS(&q[1])));
540 rawprint(ndo, (caddr_t)&p[2], EXTRACT_16BITS(&q[1]));
541 }
542 ND_PRINT((ndo,")"));
543 return p + totlen;
544 }
545
546 static const u_char *
547 ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_,
548 const struct isakmp_gen *ext,
549 u_int item_len _U_,
550 const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_,
551 u_int32_t proto0, int depth)
552 {
553 const struct ikev1_pl_sa *p;
554 struct ikev1_pl_sa sa;
555 const u_int32_t *q;
556 u_int32_t doi, sit, ident;
557 const u_char *cp, *np;
558 int t;
559
560 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SA)));
561
562 p = (struct ikev1_pl_sa *)ext;
563 ND_TCHECK(*p);
564 safememcpy(&sa, ext, sizeof(sa));
565 doi = ntohl(sa.doi);
566 sit = ntohl(sa.sit);
567 if (doi != 1) {
568 ND_PRINT((ndo," doi=%d", doi));
569 ND_PRINT((ndo," situation=%u", (u_int32_t)ntohl(sa.sit)));
570 return (u_char *)(p + 1);
571 }
572
573 ND_PRINT((ndo," doi=ipsec"));
574 q = (u_int32_t *)&sa.sit;
575 ND_PRINT((ndo," situation="));
576 t = 0;
577 if (sit & 0x01) {
578 ND_PRINT((ndo,"identity"));
579 t++;
580 }
581 if (sit & 0x02) {
582 ND_PRINT((ndo,"%ssecrecy", t ? "+" : ""));
583 t++;
584 }
585 if (sit & 0x04)
586 ND_PRINT((ndo,"%sintegrity", t ? "+" : ""));
587
588 np = (u_char *)ext + sizeof(sa);
589 if (sit != 0x01) {
590 ND_TCHECK2(*(ext + 1), sizeof(ident));
591 safememcpy(&ident, ext + 1, sizeof(ident));
592 ND_PRINT((ndo," ident=%u", (u_int32_t)ntohl(ident)));
593 np += sizeof(ident);
594 }
595
596 ext = (struct isakmp_gen *)np;
597 ND_TCHECK(*ext);
598
599 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
600 depth);
601
602 return cp;
603 trunc:
604 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_SA)));
605 return NULL;
606 }
607
608 static const u_char *
609 ikev1_p_print(netdissect_options *ndo, u_char tpay _U_,
610 const struct isakmp_gen *ext, u_int item_len _U_,
611 const u_char *ep, u_int32_t phase, u_int32_t doi0,
612 u_int32_t proto0 _U_, int depth)
613 {
614 const struct ikev1_pl_p *p;
615 struct ikev1_pl_p prop;
616 const u_char *cp;
617
618 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_P)));
619
620 p = (struct ikev1_pl_p *)ext;
621 ND_TCHECK(*p);
622 safememcpy(&prop, ext, sizeof(prop));
623 ND_PRINT((ndo," #%d protoid=%s transform=%d",
624 prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t));
625 if (prop.spi_size) {
626 ND_PRINT((ndo," spi="));
627 if (!rawprint(ndo, (caddr_t)(p + 1), prop.spi_size))
628 goto trunc;
629 }
630
631 ext = (struct isakmp_gen *)((u_char *)(p + 1) + prop.spi_size);
632 ND_TCHECK(*ext);
633
634 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
635 prop.prot_id, depth);
636
637 return cp;
638 trunc:
639 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
640 return NULL;
641 }
642
643 static const char *ikev1_p_map[] = {
644 NULL, "ike",
645 };
646
647 static const char *ikev2_t_type_map[]={
648 NULL, "encr", "prf", "integ", "dh", "esn"
649 };
650
651 static const char *ah_p_map[] = {
652 NULL, "(reserved)", "md5", "sha", "1des",
653 "sha2-256", "sha2-384", "sha2-512",
654 };
655
656 static const char *prf_p_map[] = {
657 NULL, "hmac-md5", "hmac-sha", "hmac-tiger",
658 "aes128_xcbc"
659 };
660
661 static const char *integ_p_map[] = {
662 NULL, "hmac-md5", "hmac-sha", "dec-mac",
663 "kpdk-md5", "aes-xcbc"
664 };
665
666 static const char *esn_p_map[] = {
667 "no-esn", "esn"
668 };
669
670 static const char *dh_p_map[] = {
671 NULL, "modp768",
672 "modp1024", /* group 2 */
673 "EC2N 2^155", /* group 3 */
674 "EC2N 2^185", /* group 4 */
675 "modp1536", /* group 5 */
676 "iana-grp06", "iana-grp07", /* reserved */
677 "iana-grp08", "iana-grp09",
678 "iana-grp10", "iana-grp11",
679 "iana-grp12", "iana-grp13",
680 "modp2048", /* group 14 */
681 "modp3072", /* group 15 */
682 "modp4096", /* group 16 */
683 "modp6144", /* group 17 */
684 "modp8192", /* group 18 */
685 };
686
687 static const char *esp_p_map[] = {
688 NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
689 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
690 };
691
692 static const char *ipcomp_p_map[] = {
693 NULL, "oui", "deflate", "lzs",
694 };
695
696 const struct attrmap ipsec_t_map[] = {
697 { NULL, 0, { NULL } },
698 { "lifetype", 3, { NULL, "sec", "kb", }, },
699 { "life", 0, { NULL } },
700 { "group desc", 18, { NULL, "modp768",
701 "modp1024", /* group 2 */
702 "EC2N 2^155", /* group 3 */
703 "EC2N 2^185", /* group 4 */
704 "modp1536", /* group 5 */
705 "iana-grp06", "iana-grp07", /* reserved */
706 "iana-grp08", "iana-grp09",
707 "iana-grp10", "iana-grp11",
708 "iana-grp12", "iana-grp13",
709 "modp2048", /* group 14 */
710 "modp3072", /* group 15 */
711 "modp4096", /* group 16 */
712 "modp6144", /* group 17 */
713 "modp8192", /* group 18 */
714 }, },
715 { "enc mode", 3, { NULL, "tunnel", "transport", }, },
716 { "auth", 5, { NULL, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
717 { "keylen", 0, { NULL } },
718 { "rounds", 0, { NULL } },
719 { "dictsize", 0, { NULL } },
720 { "privalg", 0, { NULL } },
721 };
722
723 const struct attrmap encr_t_map[] = {
724 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 0, 1 */
725 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 2, 3 */
726 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 4, 5 */
727 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 6, 7 */
728 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 8, 9 */
729 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 10,11*/
730 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 12,13*/
731 { "keylen", 14, { NULL }},
732 };
733
734 const struct attrmap oakley_t_map[] = {
735 { NULL, 0, { NULL } },
736 { "enc", 8, { NULL, "1des", "idea", "blowfish", "rc5",
737 "3des", "cast", "aes", }, },
738 { "hash", 7, { NULL, "md5", "sha1", "tiger",
739 "sha2-256", "sha2-384", "sha2-512", }, },
740 { "auth", 6, { NULL, "preshared", "dss", "rsa sig", "rsa enc",
741 "rsa enc revised", }, },
742 { "group desc", 18, { NULL, "modp768",
743 "modp1024", /* group 2 */
744 "EC2N 2^155", /* group 3 */
745 "EC2N 2^185", /* group 4 */
746 "modp1536", /* group 5 */
747 "iana-grp06", "iana-grp07", /* reserved */
748 "iana-grp08", "iana-grp09",
749 "iana-grp10", "iana-grp11",
750 "iana-grp12", "iana-grp13",
751 "modp2048", /* group 14 */
752 "modp3072", /* group 15 */
753 "modp4096", /* group 16 */
754 "modp6144", /* group 17 */
755 "modp8192", /* group 18 */
756 }, },
757 { "group type", 4, { NULL, "MODP", "ECP", "EC2N", }, },
758 { "group prime", 0, { NULL } },
759 { "group gen1", 0, { NULL } },
760 { "group gen2", 0, { NULL } },
761 { "group curve A", 0, { NULL } },
762 { "group curve B", 0, { NULL } },
763 { "lifetype", 3, { NULL, "sec", "kb", }, },
764 { "lifeduration", 0, { NULL } },
765 { "prf", 0, { NULL } },
766 { "keylen", 0, { NULL } },
767 { "field", 0, { NULL } },
768 { "order", 0, { NULL } },
769 };
770
771 static const u_char *
772 ikev1_t_print(netdissect_options *ndo, u_char tpay _U_,
773 const struct isakmp_gen *ext, u_int item_len,
774 const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
775 u_int32_t proto, int depth _U_)
776 {
777 const struct ikev1_pl_t *p;
778 struct ikev1_pl_t t;
779 const u_char *cp;
780 const char *idstr;
781 const struct attrmap *map;
782 size_t nmap;
783 const u_char *ep2;
784
785 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_T)));
786
787 p = (struct ikev1_pl_t *)ext;
788 ND_TCHECK(*p);
789 safememcpy(&t, ext, sizeof(t));
790
791 switch (proto) {
792 case 1:
793 idstr = STR_OR_ID(t.t_id, ikev1_p_map);
794 map = oakley_t_map;
795 nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
796 break;
797 case 2:
798 idstr = STR_OR_ID(t.t_id, ah_p_map);
799 map = ipsec_t_map;
800 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
801 break;
802 case 3:
803 idstr = STR_OR_ID(t.t_id, esp_p_map);
804 map = ipsec_t_map;
805 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
806 break;
807 case 4:
808 idstr = STR_OR_ID(t.t_id, ipcomp_p_map);
809 map = ipsec_t_map;
810 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
811 break;
812 default:
813 idstr = NULL;
814 map = NULL;
815 nmap = 0;
816 break;
817 }
818
819 if (idstr)
820 ND_PRINT((ndo," #%d id=%s ", t.t_no, idstr));
821 else
822 ND_PRINT((ndo," #%d id=%d ", t.t_no, t.t_id));
823 cp = (u_char *)(p + 1);
824 ep2 = (u_char *)p + item_len;
825 while (cp < ep && cp < ep2) {
826 if (map && nmap) {
827 cp = ikev1_attrmap_print(ndo, cp, (ep < ep2) ? ep : ep2,
828 map, nmap);
829 } else
830 cp = ikev1_attr_print(ndo, cp, (ep < ep2) ? ep : ep2);
831 }
832 if (ep < ep2)
833 ND_PRINT((ndo,"..."));
834 return cp;
835 trunc:
836 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_T)));
837 return NULL;
838 }
839
840 static const u_char *
841 ikev1_ke_print(netdissect_options *ndo, u_char tpay _U_,
842 const struct isakmp_gen *ext, u_int item_len _U_,
843 const u_char *ep _U_, u_int32_t phase _U_, u_int32_t doi _U_,
844 u_int32_t proto _U_, int depth _U_)
845 {
846 struct isakmp_gen e;
847
848 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_KE)));
849
850 ND_TCHECK(*ext);
851 safememcpy(&e, ext, sizeof(e));
852 ND_PRINT((ndo," key len=%d", ntohs(e.len) - 4));
853 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
854 ND_PRINT((ndo," "));
855 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
856 goto trunc;
857 }
858 return (u_char *)ext + ntohs(e.len);
859 trunc:
860 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_KE)));
861 return NULL;
862 }
863
864 static const u_char *
865 ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
866 const struct isakmp_gen *ext, u_int item_len _U_,
867 const u_char *ep _U_, u_int32_t phase, u_int32_t doi _U_,
868 u_int32_t proto _U_, int depth _U_)
869 {
870 #define USE_IPSECDOI_IN_PHASE1 1
871 const struct ikev1_pl_id *p;
872 struct ikev1_pl_id id;
873 static const char *idtypestr[] = {
874 "IPv4", "IPv4net", "IPv6", "IPv6net",
875 };
876 static const char *ipsecidtypestr[] = {
877 NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
878 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
879 "keyid",
880 };
881 int len;
882 const u_char *data;
883
884 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_ID)));
885
886 p = (struct ikev1_pl_id *)ext;
887 ND_TCHECK(*p);
888 safememcpy(&id, ext, sizeof(id));
889 if (sizeof(*p) < item_len) {
890 data = (u_char *)(p + 1);
891 len = item_len - sizeof(*p);
892 } else {
893 data = NULL;
894 len = 0;
895 }
896
897 #if 0 /*debug*/
898 ND_PRINT((ndo," [phase=%d doi=%d proto=%d]", phase, doi, proto));
899 #endif
900 switch (phase) {
901 #ifndef USE_IPSECDOI_IN_PHASE1
902 case 1:
903 #endif
904 default:
905 ND_PRINT((ndo," idtype=%s", STR_OR_ID(id.d.id_type, idtypestr)));
906 ND_PRINT((ndo," doi_data=%u",
907 (u_int32_t)(ntohl(id.d.doi_data) & 0xffffff)));
908 break;
909
910 #ifdef USE_IPSECDOI_IN_PHASE1
911 case 1:
912 #endif
913 case 2:
914 {
915 const struct ipsecdoi_id *p;
916 struct ipsecdoi_id id;
917 struct protoent *pe;
918
919 p = (struct ipsecdoi_id *)ext;
920 ND_TCHECK(*p);
921 safememcpy(&id, ext, sizeof(id));
922 ND_PRINT((ndo," idtype=%s", STR_OR_ID(id.type, ipsecidtypestr)));
923 if (id.proto_id) {
924 #ifndef WIN32
925 setprotoent(1);
926 #endif /* WIN32 */
927 pe = getprotobynumber(id.proto_id);
928 if (pe)
929 ND_PRINT((ndo," protoid=%s", pe->p_name));
930 #ifndef WIN32
931 endprotoent();
932 #endif /* WIN32 */
933 } else {
934 /* it DOES NOT mean IPPROTO_IP! */
935 ND_PRINT((ndo," protoid=%s", "0"));
936 }
937 ND_PRINT((ndo," port=%d", ntohs(id.port)));
938 if (!len)
939 break;
940 if (data == NULL)
941 goto trunc;
942 ND_TCHECK2(*data, len);
943 switch (id.type) {
944 case IPSECDOI_ID_IPV4_ADDR:
945 if (len < 4)
946 ND_PRINT((ndo," len=%d [bad: < 4]", len));
947 else
948 ND_PRINT((ndo," len=%d %s", len, ipaddr_string(data)));
949 len = 0;
950 break;
951 case IPSECDOI_ID_FQDN:
952 case IPSECDOI_ID_USER_FQDN:
953 {
954 int i;
955 ND_PRINT((ndo," len=%d ", len));
956 for (i = 0; i < len; i++)
957 safeputchar(data[i]);
958 len = 0;
959 break;
960 }
961 case IPSECDOI_ID_IPV4_ADDR_SUBNET:
962 {
963 const u_char *mask;
964 if (len < 8)
965 ND_PRINT((ndo," len=%d [bad: < 8]", len));
966 else {
967 mask = data + sizeof(struct in_addr);
968 ND_PRINT((ndo," len=%d %s/%u.%u.%u.%u", len,
969 ipaddr_string(data),
970 mask[0], mask[1], mask[2], mask[3]));
971 }
972 len = 0;
973 break;
974 }
975 #ifdef INET6
976 case IPSECDOI_ID_IPV6_ADDR:
977 if (len < 16)
978 ND_PRINT((ndo," len=%d [bad: < 16]", len));
979 else
980 ND_PRINT((ndo," len=%d %s", len, ip6addr_string(data)));
981 len = 0;
982 break;
983 case IPSECDOI_ID_IPV6_ADDR_SUBNET:
984 {
985 const u_int32_t *mask;
986 if (len < 20)
987 ND_PRINT((ndo," len=%d [bad: < 20]", len));
988 else {
989 mask = (u_int32_t *)(data + sizeof(struct in6_addr));
990 /*XXX*/
991 ND_PRINT((ndo," len=%d %s/0x%08x%08x%08x%08x", len,
992 ip6addr_string(data),
993 mask[0], mask[1], mask[2], mask[3]));
994 }
995 len = 0;
996 break;
997 }
998 #endif /*INET6*/
999 case IPSECDOI_ID_IPV4_ADDR_RANGE:
1000 if (len < 8)
1001 ND_PRINT((ndo," len=%d [bad: < 8]", len));
1002 else {
1003 ND_PRINT((ndo," len=%d %s-%s", len,
1004 ipaddr_string(data),
1005 ipaddr_string(data + sizeof(struct in_addr))));
1006 }
1007 len = 0;
1008 break;
1009 #ifdef INET6
1010 case IPSECDOI_ID_IPV6_ADDR_RANGE:
1011 if (len < 32)
1012 ND_PRINT((ndo," len=%d [bad: < 32]", len));
1013 else {
1014 ND_PRINT((ndo," len=%d %s-%s", len,
1015 ip6addr_string(data),
1016 ip6addr_string(data + sizeof(struct in6_addr))));
1017 }
1018 len = 0;
1019 break;
1020 #endif /*INET6*/
1021 case IPSECDOI_ID_DER_ASN1_DN:
1022 case IPSECDOI_ID_DER_ASN1_GN:
1023 case IPSECDOI_ID_KEY_ID:
1024 break;
1025 }
1026 break;
1027 }
1028 }
1029 if (data && len) {
1030 ND_PRINT((ndo," len=%d", len));
1031 if (2 < ndo->ndo_vflag) {
1032 ND_PRINT((ndo," "));
1033 if (!rawprint(ndo, (caddr_t)data, len))
1034 goto trunc;
1035 }
1036 }
1037 return (u_char *)ext + item_len;
1038 trunc:
1039 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_ID)));
1040 return NULL;
1041 }
1042
1043 static const u_char *
1044 ikev1_cert_print(netdissect_options *ndo, u_char tpay _U_,
1045 const struct isakmp_gen *ext, u_int item_len _U_,
1046 const u_char *ep _U_, u_int32_t phase _U_,
1047 u_int32_t doi0 _U_,
1048 u_int32_t proto0 _U_, int depth _U_)
1049 {
1050 const struct ikev1_pl_cert *p;
1051 struct ikev1_pl_cert cert;
1052 static const char *certstr[] = {
1053 "none", "pkcs7", "pgp", "dns",
1054 "x509sign", "x509ke", "kerberos", "crl",
1055 "arl", "spki", "x509attr",
1056 };
1057
1058 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_CERT)));
1059
1060 p = (struct ikev1_pl_cert *)ext;
1061 ND_TCHECK(*p);
1062 safememcpy(&cert, ext, sizeof(cert));
1063 ND_PRINT((ndo," len=%d", item_len - 4));
1064 ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr)));
1065 if (2 < ndo->ndo_vflag && 4 < item_len) {
1066 ND_PRINT((ndo," "));
1067 if (!rawprint(ndo, (caddr_t)(ext + 1), item_len - 4))
1068 goto trunc;
1069 }
1070 return (u_char *)ext + item_len;
1071 trunc:
1072 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT)));
1073 return NULL;
1074 }
1075
1076 static const u_char *
1077 ikev1_cr_print(netdissect_options *ndo, u_char tpay _U_,
1078 const struct isakmp_gen *ext, u_int item_len _U_,
1079 const u_char *ep _U_, u_int32_t phase _U_, u_int32_t doi0 _U_,
1080 u_int32_t proto0 _U_, int depth _U_)
1081 {
1082 const struct ikev1_pl_cert *p;
1083 struct ikev1_pl_cert cert;
1084 static const char *certstr[] = {
1085 "none", "pkcs7", "pgp", "dns",
1086 "x509sign", "x509ke", "kerberos", "crl",
1087 "arl", "spki", "x509attr",
1088 };
1089
1090 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_CR)));
1091
1092 p = (struct ikev1_pl_cert *)ext;
1093 ND_TCHECK(*p);
1094 safememcpy(&cert, ext, sizeof(cert));
1095 ND_PRINT((ndo," len=%d", item_len - 4));
1096 ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr)));
1097 if (2 < ndo->ndo_vflag && 4 < item_len) {
1098 ND_PRINT((ndo," "));
1099 if (!rawprint(ndo, (caddr_t)(ext + 1), item_len - 4))
1100 goto trunc;
1101 }
1102 return (u_char *)ext + item_len;
1103 trunc:
1104 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_CR)));
1105 return NULL;
1106 }
1107
1108 static const u_char *
1109 ikev1_hash_print(netdissect_options *ndo, u_char tpay _U_,
1110 const struct isakmp_gen *ext, u_int item_len _U_,
1111 const u_char *ep _U_, u_int32_t phase _U_, u_int32_t doi _U_,
1112 u_int32_t proto _U_, int depth _U_)
1113 {
1114 struct isakmp_gen e;
1115
1116 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_HASH)));
1117
1118 ND_TCHECK(*ext);
1119 safememcpy(&e, ext, sizeof(e));
1120 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1121 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1122 ND_PRINT((ndo," "));
1123 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
1124 goto trunc;
1125 }
1126 return (u_char *)ext + ntohs(e.len);
1127 trunc:
1128 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH)));
1129 return NULL;
1130 }
1131
1132 static const u_char *
1133 ikev1_sig_print(netdissect_options *ndo, u_char tpay _U_,
1134 const struct isakmp_gen *ext, u_int item_len _U_,
1135 const u_char *ep _U_, u_int32_t phase _U_, u_int32_t doi _U_,
1136 u_int32_t proto _U_, int depth _U_)
1137 {
1138 struct isakmp_gen e;
1139
1140 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SIG)));
1141
1142 ND_TCHECK(*ext);
1143 safememcpy(&e, ext, sizeof(e));
1144 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1145 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1146 ND_PRINT((ndo," "));
1147 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
1148 goto trunc;
1149 }
1150 return (u_char *)ext + ntohs(e.len);
1151 trunc:
1152 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG)));
1153 return NULL;
1154 }
1155
1156 static const u_char *
1157 ikev1_nonce_print(netdissect_options *ndo, u_char tpay _U_,
1158 const struct isakmp_gen *ext,
1159 u_int item_len _U_,
1160 const u_char *ep _U_,
1161 u_int32_t phase _U_, u_int32_t doi _U_,
1162 u_int32_t proto _U_, int depth _U_)
1163 {
1164 struct isakmp_gen e;
1165
1166 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE)));
1167
1168 ND_TCHECK(*ext);
1169 safememcpy(&e, ext, sizeof(e));
1170 ND_PRINT((ndo," n len=%d", ntohs(e.len) - 4));
1171 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1172 ND_PRINT((ndo," "));
1173 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
1174 goto trunc;
1175 } else if (1 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1176 ND_PRINT((ndo," "));
1177 if (!ike_show_somedata(ndo, (u_char *)(caddr_t)(ext + 1), ep))
1178 goto trunc;
1179 }
1180 return (u_char *)ext + ntohs(e.len);
1181 trunc:
1182 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE)));
1183 return NULL;
1184 }
1185
1186 static const u_char *
1187 ikev1_n_print(netdissect_options *ndo, u_char tpay _U_,
1188 const struct isakmp_gen *ext, u_int item_len,
1189 const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_,
1190 u_int32_t proto0 _U_, int depth)
1191 {
1192 struct ikev1_pl_n *p, n;
1193 const u_char *cp;
1194 u_char *ep2;
1195 u_int32_t doi;
1196 u_int32_t proto;
1197 static const char *notify_error_str[] = {
1198 NULL, "INVALID-PAYLOAD-TYPE",
1199 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1200 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1201 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1202 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1203 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1204 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1205 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1206 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1207 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1208 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1209 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1210 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1211 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1212 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1213 "UNEQUAL-PAYLOAD-LENGTHS",
1214 };
1215 static const char *ipsec_notify_error_str[] = {
1216 "RESERVED",
1217 };
1218 static const char *notify_status_str[] = {
1219 "CONNECTED",
1220 };
1221 static const char *ipsec_notify_status_str[] = {
1222 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1223 "INITIAL-CONTACT",
1224 };
1225 /* NOTE: these macro must be called with x in proper range */
1226
1227 /* 0 - 8191 */
1228 #define NOTIFY_ERROR_STR(x) \
1229 STR_OR_ID((x), notify_error_str)
1230
1231 /* 8192 - 16383 */
1232 #define IPSEC_NOTIFY_ERROR_STR(x) \
1233 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1234
1235 /* 16384 - 24575 */
1236 #define NOTIFY_STATUS_STR(x) \
1237 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1238
1239 /* 24576 - 32767 */
1240 #define IPSEC_NOTIFY_STATUS_STR(x) \
1241 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1242
1243 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_N)));
1244
1245 p = (struct ikev1_pl_n *)ext;
1246 ND_TCHECK(*p);
1247 safememcpy(&n, ext, sizeof(n));
1248 doi = ntohl(n.doi);
1249 proto = n.prot_id;
1250 if (doi != 1) {
1251 ND_PRINT((ndo," doi=%d", doi));
1252 ND_PRINT((ndo," proto=%d", proto));
1253 if (ntohs(n.type) < 8192)
1254 ND_PRINT((ndo," type=%s", NOTIFY_ERROR_STR(ntohs(n.type))));
1255 else if (ntohs(n.type) < 16384)
1256 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
1257 else if (ntohs(n.type) < 24576)
1258 ND_PRINT((ndo," type=%s", NOTIFY_STATUS_STR(ntohs(n.type))));
1259 else
1260 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
1261 if (n.spi_size) {
1262 ND_PRINT((ndo," spi="));
1263 if (!rawprint(ndo, (caddr_t)(p + 1), n.spi_size))
1264 goto trunc;
1265 }
1266 return (u_char *)(p + 1) + n.spi_size;
1267 }
1268
1269 ND_PRINT((ndo," doi=ipsec"));
1270 ND_PRINT((ndo," proto=%s", PROTOIDSTR(proto)));
1271 if (ntohs(n.type) < 8192)
1272 ND_PRINT((ndo," type=%s", NOTIFY_ERROR_STR(ntohs(n.type))));
1273 else if (ntohs(n.type) < 16384)
1274 ND_PRINT((ndo," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n.type))));
1275 else if (ntohs(n.type) < 24576)
1276 ND_PRINT((ndo," type=%s", NOTIFY_STATUS_STR(ntohs(n.type))));
1277 else if (ntohs(n.type) < 32768)
1278 ND_PRINT((ndo," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n.type))));
1279 else
1280 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
1281 if (n.spi_size) {
1282 ND_PRINT((ndo," spi="));
1283 if (!rawprint(ndo, (caddr_t)(p + 1), n.spi_size))
1284 goto trunc;
1285 }
1286
1287 cp = (u_char *)(p + 1) + n.spi_size;
1288 ep2 = (u_char *)p + item_len;
1289
1290 if (cp < ep) {
1291 ND_PRINT((ndo," orig=("));
1292 switch (ntohs(n.type)) {
1293 case IPSECDOI_NTYPE_RESPONDER_LIFETIME:
1294 {
1295 const struct attrmap *map = oakley_t_map;
1296 size_t nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
1297 while (cp < ep && cp < ep2) {
1298 cp = ikev1_attrmap_print(ndo, cp,
1299 (ep < ep2) ? ep : ep2, map, nmap);
1300 }
1301 break;
1302 }
1303 case IPSECDOI_NTYPE_REPLAY_STATUS:
1304 ND_PRINT((ndo,"replay detection %sabled",
1305 (*(u_int32_t *)cp) ? "en" : "dis"));
1306 break;
1307 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN:
1308 if (ikev1_sub_print(ndo, ISAKMP_NPTYPE_SA,
1309 (struct isakmp_gen *)cp, ep, phase, doi, proto,
1310 depth) == NULL)
1311 return NULL;
1312 break;
1313 default:
1314 /* NULL is dummy */
1315 isakmp_print(ndo, cp,
1316 item_len - sizeof(*p) - n.spi_size,
1317 NULL);
1318 }
1319 ND_PRINT((ndo,")"));
1320 }
1321 return (u_char *)ext + item_len;
1322 trunc:
1323 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_N)));
1324 return NULL;
1325 }
1326
1327 static const u_char *
1328 ikev1_d_print(netdissect_options *ndo, u_char tpay _U_,
1329 const struct isakmp_gen *ext, u_int item_len _U_,
1330 const u_char *ep _U_, u_int32_t phase _U_, u_int32_t doi0 _U_,
1331 u_int32_t proto0 _U_, int depth _U_)
1332 {
1333 const struct ikev1_pl_d *p;
1334 struct ikev1_pl_d d;
1335 const u_int8_t *q;
1336 u_int32_t doi;
1337 u_int32_t proto;
1338 int i;
1339
1340 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_D)));
1341
1342 p = (struct ikev1_pl_d *)ext;
1343 ND_TCHECK(*p);
1344 safememcpy(&d, ext, sizeof(d));
1345 doi = ntohl(d.doi);
1346 proto = d.prot_id;
1347 if (doi != 1) {
1348 ND_PRINT((ndo," doi=%u", doi));
1349 ND_PRINT((ndo," proto=%u", proto));
1350 } else {
1351 ND_PRINT((ndo," doi=ipsec"));
1352 ND_PRINT((ndo," proto=%s", PROTOIDSTR(proto)));
1353 }
1354 ND_PRINT((ndo," spilen=%u", d.spi_size));
1355 ND_PRINT((ndo," nspi=%u", ntohs(d.num_spi)));
1356 ND_PRINT((ndo," spi="));
1357 q = (u_int8_t *)(p + 1);
1358 for (i = 0; i < ntohs(d.num_spi); i++) {
1359 if (i != 0)
1360 ND_PRINT((ndo,","));
1361 if (!rawprint(ndo, (caddr_t)q, d.spi_size))
1362 goto trunc;
1363 q += d.spi_size;
1364 }
1365 return q;
1366 trunc:
1367 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_D)));
1368 return NULL;
1369 }
1370
1371 static const u_char *
1372 ikev1_vid_print(netdissect_options *ndo, u_char tpay _U_,
1373 const struct isakmp_gen *ext,
1374 u_int item_len _U_, const u_char *ep _U_,
1375 u_int32_t phase _U_, u_int32_t doi _U_,
1376 u_int32_t proto _U_, int depth _U_)
1377 {
1378 struct isakmp_gen e;
1379
1380 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_VID)));
1381
1382 ND_TCHECK(*ext);
1383 safememcpy(&e, ext, sizeof(e));
1384 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1385 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1386 ND_PRINT((ndo," "));
1387 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
1388 goto trunc;
1389 }
1390 return (u_char *)ext + ntohs(e.len);
1391 trunc:
1392 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_VID)));
1393 return NULL;
1394 }
1395
1396 /************************************************************/
1397 /* */
1398 /* IKE v2 - rfc4306 - dissector */
1399 /* */
1400 /************************************************************/
1401
1402 static void
1403 ikev2_pay_print(netdissect_options *ndo, const char *payname, int critical)
1404 {
1405 ND_PRINT((ndo,"%s%s:", payname, critical&0x80 ? "[C]" : ""));
1406 }
1407
1408 static const u_char *
1409 ikev2_gen_print(netdissect_options *ndo, u_char tpay,
1410 const struct isakmp_gen *ext)
1411 {
1412 struct isakmp_gen e;
1413
1414 ND_TCHECK(*ext);
1415 safememcpy(&e, ext, sizeof(e));
1416 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
1417
1418 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1419 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1420 ND_PRINT((ndo," "));
1421 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
1422 goto trunc;
1423 }
1424 return (u_char *)ext + ntohs(e.len);
1425 trunc:
1426 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
1427 return NULL;
1428 }
1429
1430 static const u_char *
1431 ikev2_t_print(netdissect_options *ndo, u_char tpay _U_, int pcount,
1432 const struct isakmp_gen *ext, u_int item_len,
1433 const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
1434 u_int32_t proto _U_, int depth _U_)
1435 {
1436 const struct ikev2_t *p;
1437 struct ikev2_t t;
1438 u_int16_t t_id;
1439 const u_char *cp;
1440 const char *idstr;
1441 const struct attrmap *map;
1442 size_t nmap;
1443 const u_char *ep2;
1444
1445 p = (struct ikev2_t *)ext;
1446 ND_TCHECK(*p);
1447 safememcpy(&t, ext, sizeof(t));
1448 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_T), t.h.critical);
1449
1450 t_id = ntohs(t.t_id);
1451
1452 map = NULL;
1453 nmap = 0;
1454
1455 switch (t.t_type) {
1456 case IV2_T_ENCR:
1457 idstr = STR_OR_ID(t_id, esp_p_map);
1458 map = encr_t_map;
1459 nmap = sizeof(encr_t_map)/sizeof(encr_t_map[0]);
1460 break;
1461
1462 case IV2_T_PRF:
1463 idstr = STR_OR_ID(t_id, prf_p_map);
1464 break;
1465
1466 case IV2_T_INTEG:
1467 idstr = STR_OR_ID(t_id, integ_p_map);
1468 break;
1469
1470 case IV2_T_DH:
1471 idstr = STR_OR_ID(t_id, dh_p_map);
1472 break;
1473
1474 case IV2_T_ESN:
1475 idstr = STR_OR_ID(t_id, esn_p_map);
1476 break;
1477
1478 default:
1479 idstr = NULL;
1480 break;
1481 }
1482
1483 if (idstr)
1484 ND_PRINT((ndo," #%u type=%s id=%s ", pcount,
1485 STR_OR_ID(t.t_type, ikev2_t_type_map),
1486 idstr));
1487 else
1488 ND_PRINT((ndo," #%u type=%s id=%u ", pcount,
1489 STR_OR_ID(t.t_type, ikev2_t_type_map),
1490 t.t_id));
1491 cp = (u_char *)(p + 1);
1492 ep2 = (u_char *)p + item_len;
1493 while (cp < ep && cp < ep2) {
1494 if (map && nmap) {
1495 cp = ikev1_attrmap_print(ndo, cp, (ep < ep2) ? ep : ep2,
1496 map, nmap);
1497 } else
1498 cp = ikev1_attr_print(ndo, cp, (ep < ep2) ? ep : ep2);
1499 }
1500 if (ep < ep2)
1501 ND_PRINT((ndo,"..."));
1502 return cp;
1503 trunc:
1504 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_T)));
1505 return NULL;
1506 }
1507
1508 static const u_char *
1509 ikev2_p_print(netdissect_options *ndo, u_char tpay _U_, int pcount _U_,
1510 const struct isakmp_gen *ext, u_int item_len _U_,
1511 const u_char *ep, u_int32_t phase, u_int32_t doi0,
1512 u_int32_t proto0 _U_, int depth)
1513 {
1514 const struct ikev2_p *p;
1515 struct ikev2_p prop;
1516 const u_char *cp;
1517
1518 p = (struct ikev2_p *)ext;
1519 ND_TCHECK(*p);
1520 safememcpy(&prop, ext, sizeof(prop));
1521 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_P), prop.h.critical);
1522
1523 ND_PRINT((ndo," #%u protoid=%s transform=%d len=%u",
1524 prop.p_no, PROTOIDSTR(prop.prot_id),
1525 prop.num_t, ntohs(prop.h.len)));
1526 if (prop.spi_size) {
1527 ND_PRINT((ndo," spi="));
1528 if (!rawprint(ndo, (caddr_t)(p + 1), prop.spi_size))
1529 goto trunc;
1530 }
1531
1532 ext = (struct isakmp_gen *)((u_char *)(p + 1) + prop.spi_size);
1533 ND_TCHECK(*ext);
1534
1535 cp = ikev2_sub_print(ndo, NULL, ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
1536 prop.prot_id, depth);
1537
1538 return cp;
1539 trunc:
1540 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
1541 return NULL;
1542 }
1543
1544 static const u_char *
1545 ikev2_sa_print(netdissect_options *ndo, u_char tpay,
1546 const struct isakmp_gen *ext1,
1547 u_int item_len _U_, const u_char *ep _U_,
1548 u_int32_t phase _U_, u_int32_t doi _U_,
1549 u_int32_t proto _U_, int depth _U_)
1550 {
1551 struct isakmp_gen e;
1552 int osa_length, sa_length;
1553
1554 ND_TCHECK(*ext1);
1555 safememcpy(&e, ext1, sizeof(e));
1556 ikev2_pay_print(ndo, "sa", e.critical);
1557
1558 osa_length= ntohs(e.len);
1559 sa_length = osa_length - 4;
1560 ND_PRINT((ndo," len=%d", sa_length));
1561
1562 ikev2_sub_print(ndo, NULL, ISAKMP_NPTYPE_P,
1563 ext1+1, ep,
1564 0, 0, 0, depth);
1565
1566 return (u_char *)ext1 + osa_length;
1567 trunc:
1568 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
1569 return NULL;
1570 }
1571
1572 static const u_char *
1573 ikev2_ke_print(netdissect_options *ndo, u_char tpay,
1574 const struct isakmp_gen *ext,
1575 u_int item_len _U_, const u_char *ep _U_,
1576 u_int32_t phase _U_, u_int32_t doi _U_,
1577 u_int32_t proto _U_, int depth _U_)
1578 {
1579 struct ikev2_ke ke;
1580 struct ikev2_ke *k;
1581
1582 k = (struct ikev2_ke *)ext;
1583 ND_TCHECK(*ext);
1584 safememcpy(&ke, ext, sizeof(ke));
1585 ikev2_pay_print(ndo, NPSTR(tpay), ke.h.critical);
1586
1587 ND_PRINT((ndo," len=%u group=%s", ntohs(ke.h.len) - 8,
1588 STR_OR_ID(ntohs(ke.ke_group), dh_p_map)));
1589
1590 if (2 < ndo->ndo_vflag && 8 < ntohs(ke.h.len)) {
1591 ND_PRINT((ndo," "));
1592 if (!rawprint(ndo, (caddr_t)(k + 1), ntohs(ke.h.len) - 8))
1593 goto trunc;
1594 }
1595 return (u_char *)ext + ntohs(ke.h.len);
1596 trunc:
1597 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
1598 return NULL;
1599 }
1600
1601 static const u_char *
1602 ikev2_ID_print(netdissect_options *ndo, u_char tpay,
1603 const struct isakmp_gen *ext,
1604 u_int item_len _U_, const u_char *ep _U_,
1605 u_int32_t phase _U_, u_int32_t doi _U_,
1606 u_int32_t proto _U_, int depth _U_)
1607 {
1608 struct ikev2_id id;
1609 int id_len, idtype_len, i;
1610 unsigned int dumpascii, dumphex;
1611 unsigned char *typedata;
1612
1613 ND_TCHECK(*ext);
1614 safememcpy(&id, ext, sizeof(id));
1615 ikev2_pay_print(ndo, NPSTR(tpay), id.h.critical);
1616
1617 id_len = ntohs(id.h.len);
1618
1619 ND_PRINT((ndo," len=%d", id_len - 4));
1620 if (2 < ndo->ndo_vflag && 4 < id_len) {
1621 ND_PRINT((ndo," "));
1622 if (!rawprint(ndo, (caddr_t)(ext + 1), id_len - 4))
1623 goto trunc;
1624 }
1625
1626 idtype_len =id_len - sizeof(struct ikev2_id);
1627 dumpascii = 0;
1628 dumphex = 0;
1629 typedata = (unsigned char *)(ext)+sizeof(struct ikev2_id);
1630
1631 switch(id.type) {
1632 case ID_IPV4_ADDR:
1633 ND_PRINT((ndo, " ipv4:"));
1634 dumphex=1;
1635 break;
1636 case ID_FQDN:
1637 ND_PRINT((ndo, " fqdn:"));
1638 dumpascii=1;
1639 break;
1640 case ID_RFC822_ADDR:
1641 ND_PRINT((ndo, " rfc822:"));
1642 dumpascii=1;
1643 break;
1644 case ID_IPV6_ADDR:
1645 ND_PRINT((ndo, " ipv6:"));
1646 dumphex=1;
1647 break;
1648 case ID_DER_ASN1_DN:
1649 ND_PRINT((ndo, " dn:"));
1650 dumphex=1;
1651 break;
1652 case ID_DER_ASN1_GN:
1653 ND_PRINT((ndo, " gn:"));
1654 dumphex=1;
1655 break;
1656 case ID_KEY_ID:
1657 ND_PRINT((ndo, " keyid:"));
1658 dumphex=1;
1659 break;
1660 }
1661
1662 if(dumpascii) {
1663 ND_TCHECK2(*typedata, idtype_len);
1664 for(i=0; i<idtype_len; i++) {
1665 if(isprint(typedata[i])) {
1666 ND_PRINT((ndo, "%c", typedata[i]));
1667 } else {
1668 ND_PRINT((ndo, "."));
1669 }
1670 }
1671 }
1672 if(dumphex) {
1673 if (!rawprint(ndo, (caddr_t)typedata, idtype_len))
1674 goto trunc;
1675 }
1676
1677 return (u_char *)ext + id_len;
1678 trunc:
1679 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
1680 return NULL;
1681 }
1682
1683 static const u_char *
1684 ikev2_cert_print(netdissect_options *ndo, u_char tpay,
1685 const struct isakmp_gen *ext,
1686 u_int item_len _U_, const u_char *ep _U_,
1687 u_int32_t phase _U_, u_int32_t doi _U_,
1688 u_int32_t proto _U_, int depth _U_)
1689 {
1690 return ikev2_gen_print(ndo, tpay, ext);
1691 }
1692
1693 static const u_char *
1694 ikev2_cr_print(netdissect_options *ndo, u_char tpay,
1695 const struct isakmp_gen *ext,
1696 u_int item_len _U_, const u_char *ep _U_,
1697 u_int32_t phase _U_, u_int32_t doi _U_,
1698 u_int32_t proto _U_, int depth _U_)
1699 {
1700 return ikev2_gen_print(ndo, tpay, ext);
1701 }
1702
1703 static const u_char *
1704 ikev2_auth_print(netdissect_options *ndo, u_char tpay,
1705 const struct isakmp_gen *ext,
1706 u_int item_len _U_, const u_char *ep _U_,
1707 u_int32_t phase _U_, u_int32_t doi _U_,
1708 u_int32_t proto _U_, int depth _U_)
1709 {
1710 struct ikev2_auth a;
1711 const char *v2_auth[]={ "invalid", "rsasig",
1712 "shared-secret", "dsssig" };
1713 u_char *authdata = (u_char*)ext + sizeof(a);
1714 unsigned int len;
1715
1716 ND_TCHECK(*ext);
1717 safememcpy(&a, ext, sizeof(a));
1718 ikev2_pay_print(ndo, NPSTR(tpay), a.h.critical);
1719 len = ntohs(a.h.len);
1720
1721 ND_PRINT((ndo," len=%d method=%s", len-4,
1722 STR_OR_ID(a.auth_method, v2_auth)));
1723
1724 if (1 < ndo->ndo_vflag && 4 < len) {
1725 ND_PRINT((ndo," authdata=("));
1726 if (!rawprint(ndo, (caddr_t)authdata, len - sizeof(a)))
1727 goto trunc;
1728 ND_PRINT((ndo,") "));
1729 } else if(ndo->ndo_vflag && 4 < len) {
1730 if(!ike_show_somedata(ndo, authdata, ep)) goto trunc;
1731 }
1732
1733 return (u_char *)ext + len;
1734 trunc:
1735 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
1736 return NULL;
1737 }
1738
1739 static const u_char *
1740 ikev2_nonce_print(netdissect_options *ndo, u_char tpay,
1741 const struct isakmp_gen *ext,
1742 u_int item_len _U_, const u_char *ep _U_,
1743 u_int32_t phase _U_, u_int32_t doi _U_,
1744 u_int32_t proto _U_, int depth _U_)
1745 {
1746 struct isakmp_gen e;
1747
1748 ND_TCHECK(*ext);
1749 safememcpy(&e, ext, sizeof(e));
1750 ikev2_pay_print(ndo, "nonce", e.critical);
1751
1752 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1753 if (1 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1754 ND_PRINT((ndo," nonce=("));
1755 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
1756 goto trunc;
1757 ND_PRINT((ndo,") "));
1758 } else if(ndo->ndo_vflag && 4 < ntohs(e.len)) {
1759 if(!ike_show_somedata(ndo, (const u_char *)(ext+1), ep)) goto trunc;
1760 }
1761
1762 return (u_char *)ext + ntohs(e.len);
1763 trunc:
1764 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
1765 return NULL;
1766 }
1767
1768 /* notify payloads */
1769 static const u_char *
1770 ikev2_n_print(netdissect_options *ndo, u_char tpay _U_,
1771 const struct isakmp_gen *ext,
1772 u_int item_len _U_, const u_char *ep _U_,
1773 u_int32_t phase _U_, u_int32_t doi _U_,
1774 u_int32_t proto _U_, int depth _U_)
1775 {
1776 struct ikev2_n *p, n;
1777 const u_char *cp;
1778 u_char *ep2;
1779 u_char showspi, showdata, showsomedata;
1780 const char *notify_name;
1781 u_int32_t type;
1782
1783 p = (struct ikev2_n *)ext;
1784 ND_TCHECK(*p);
1785 safememcpy(&n, ext, sizeof(n));
1786 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_N), n.h.critical);
1787
1788 showspi = 1;
1789 showdata = 0;
1790 showsomedata=0;
1791 notify_name=NULL;
1792
1793 ND_PRINT((ndo," prot_id=%s", PROTOIDSTR(n.prot_id)));
1794
1795 type = ntohs(n.type);
1796
1797 /* notify space is annoying sparse */
1798 switch(type) {
1799 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD:
1800 notify_name = "unsupported_critical_payload";
1801 showspi = 0;
1802 break;
1803
1804 case IV2_NOTIFY_INVALID_IKE_SPI:
1805 notify_name = "invalid_ike_spi";
1806 showspi = 1;
1807 break;
1808
1809 case IV2_NOTIFY_INVALID_MAJOR_VERSION:
1810 notify_name = "invalid_major_version";
1811 showspi = 0;
1812 break;
1813
1814 case IV2_NOTIFY_INVALID_SYNTAX:
1815 notify_name = "invalid_syntax";
1816 showspi = 1;
1817 break;
1818
1819 case IV2_NOTIFY_INVALID_MESSAGE_ID:
1820 notify_name = "invalid_message_id";
1821 showspi = 1;
1822 break;
1823
1824 case IV2_NOTIFY_INVALID_SPI:
1825 notify_name = "invalid_spi";
1826 showspi = 1;
1827 break;
1828
1829 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN:
1830 notify_name = "no_protocol_chosen";
1831 showspi = 1;
1832 break;
1833
1834 case IV2_NOTIFY_INVALID_KE_PAYLOAD:
1835 notify_name = "invalid_ke_payload";
1836 showspi = 1;
1837 break;
1838
1839 case IV2_NOTIFY_AUTHENTICATION_FAILED:
1840 notify_name = "authentication_failed";
1841 showspi = 1;
1842 break;
1843
1844 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED:
1845 notify_name = "single_pair_required";
1846 showspi = 1;
1847 break;
1848
1849 case IV2_NOTIFY_NO_ADDITIONAL_SAS:
1850 notify_name = "no_additional_sas";
1851 showspi = 0;
1852 break;
1853
1854 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE:
1855 notify_name = "internal_address_failure";
1856 showspi = 0;
1857 break;
1858
1859 case IV2_NOTIFY_FAILED_CP_REQUIRED:
1860 notify_name = "failed:cp_required";
1861 showspi = 0;
1862 break;
1863
1864 case IV2_NOTIFY_INVALID_SELECTORS:
1865 notify_name = "invalid_selectors";
1866 showspi = 0;
1867 break;
1868
1869 case IV2_NOTIFY_INITIAL_CONTACT:
1870 notify_name = "initial_contact";
1871 showspi = 0;
1872 break;
1873
1874 case IV2_NOTIFY_SET_WINDOW_SIZE:
1875 notify_name = "set_window_size";
1876 showspi = 0;
1877 break;
1878
1879 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE:
1880 notify_name = "additional_ts_possible";
1881 showspi = 0;
1882 break;
1883
1884 case IV2_NOTIFY_IPCOMP_SUPPORTED:
1885 notify_name = "ipcomp_supported";
1886 showspi = 0;
1887 break;
1888
1889 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP:
1890 notify_name = "nat_detection_source_ip";
1891 showspi = 1;
1892 break;
1893
1894 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP:
1895 notify_name = "nat_detection_destination_ip";
1896 showspi = 1;
1897 break;
1898
1899 case IV2_NOTIFY_COOKIE:
1900 notify_name = "cookie";
1901 showspi = 1;
1902 showsomedata= 1;
1903 showdata= 0;
1904 break;
1905
1906 case IV2_NOTIFY_USE_TRANSPORT_MODE:
1907 notify_name = "use_transport_mode";
1908 showspi = 0;
1909 break;
1910
1911 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED:
1912 notify_name = "http_cert_lookup_supported";
1913 showspi = 0;
1914 break;
1915
1916 case IV2_NOTIFY_REKEY_SA:
1917 notify_name = "rekey_sa";
1918 showspi = 1;
1919 break;
1920
1921 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED:
1922 notify_name = "tfc_padding_not_supported";
1923 showspi = 0;
1924 break;
1925
1926 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO:
1927 notify_name = "non_first_fragment_also";
1928 showspi = 0;
1929 break;
1930
1931 default:
1932 if (type < 8192) {
1933 notify_name="error";
1934 } else if(type < 16384) {
1935 notify_name="private-error";
1936 } else if(type < 40960) {
1937 notify_name="status";
1938 } else {
1939 notify_name="private-status";
1940 }
1941 }
1942
1943 if(notify_name) {
1944 ND_PRINT((ndo," type=%u(%s)", type, notify_name));
1945 }
1946
1947
1948 if (showspi && n.spi_size) {
1949 ND_PRINT((ndo," spi="));
1950 if (!rawprint(ndo, (caddr_t)(p + 1), n.spi_size))
1951 goto trunc;
1952 }
1953
1954 cp = (u_char *)(p + 1) + n.spi_size;
1955 ep2 = (u_char *)p + item_len;
1956
1957 if(3 < ndo->ndo_vflag) {
1958 showdata = 1;
1959 }
1960
1961 if ((showdata || (showsomedata && ep-cp < 30)) && cp < ep) {
1962 ND_PRINT((ndo," data=("));
1963 if (!rawprint(ndo, (caddr_t)(cp), ep - cp))
1964 goto trunc;
1965
1966 ND_PRINT((ndo,")"));
1967
1968 } else if(showsomedata && cp < ep) {
1969 if(!ike_show_somedata(ndo, cp, ep)) goto trunc;
1970 }
1971
1972 return (u_char *)ext + item_len;
1973 trunc:
1974 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_N)));
1975 return NULL;
1976 }
1977
1978 static const u_char *
1979 ikev2_d_print(netdissect_options *ndo, u_char tpay,
1980 const struct isakmp_gen *ext,
1981 u_int item_len _U_, const u_char *ep _U_,
1982 u_int32_t phase _U_, u_int32_t doi _U_,
1983 u_int32_t proto _U_, int depth _U_)
1984 {
1985 return ikev2_gen_print(ndo, tpay, ext);
1986 }
1987
1988 static const u_char *
1989 ikev2_vid_print(netdissect_options *ndo, u_char tpay,
1990 const struct isakmp_gen *ext,
1991 u_int item_len _U_, const u_char *ep _U_,
1992 u_int32_t phase _U_, u_int32_t doi _U_,
1993 u_int32_t proto _U_, int depth _U_)
1994 {
1995 struct isakmp_gen e;
1996 const u_char *vid;
1997 int i, len;
1998
1999 ND_TCHECK(*ext);
2000 safememcpy(&e, ext, sizeof(e));
2001 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
2002 ND_PRINT((ndo," len=%d vid=", ntohs(e.len) - 4));
2003
2004 vid = (const u_char *)(ext+1);
2005 len = ntohs(e.len) - 4;
2006 ND_TCHECK2(*vid, len);
2007 for(i=0; i<len; i++) {
2008 if(isprint(vid[i])) ND_PRINT((ndo, "%c", vid[i]));
2009 else ND_PRINT((ndo, "."));
2010 }
2011 if (2 < ndo->ndo_vflag && 4 < len) {
2012 ND_PRINT((ndo," "));
2013 if (!rawprint(ndo, (caddr_t)(ext + 1), ntohs(e.len) - 4))
2014 goto trunc;
2015 }
2016 return (u_char *)ext + ntohs(e.len);
2017 trunc:
2018 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2019 return NULL;
2020 }
2021
2022 static const u_char *
2023 ikev2_TS_print(netdissect_options *ndo, u_char tpay,
2024 const struct isakmp_gen *ext,
2025 u_int item_len _U_, const u_char *ep _U_,
2026 u_int32_t phase _U_, u_int32_t doi _U_,
2027 u_int32_t proto _U_, int depth _U_)
2028 {
2029 return ikev2_gen_print(ndo, tpay, ext);
2030 }
2031
2032 static const u_char *
2033 ikev2_e_print(netdissect_options *ndo,
2034 #ifndef HAVE_LIBCRYPTO
2035 _U_
2036 #endif
2037 struct isakmp *base,
2038 u_char tpay,
2039 const struct isakmp_gen *ext,
2040 u_int item_len _U_, const u_char *ep _U_,
2041 #ifndef HAVE_LIBCRYPTO
2042 _U_
2043 #endif
2044 u_int32_t phase,
2045 #ifndef HAVE_LIBCRYPTO
2046 _U_
2047 #endif
2048 u_int32_t doi,
2049 #ifndef HAVE_LIBCRYPTO
2050 _U_
2051 #endif
2052 u_int32_t proto,
2053 #ifndef HAVE_LIBCRYPTO
2054 _U_
2055 #endif
2056 int depth)
2057 {
2058 struct isakmp_gen e;
2059 u_char *dat;
2060 volatile int dlen;
2061
2062 ND_TCHECK(*ext);
2063 safememcpy(&e, ext, sizeof(e));
2064 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
2065
2066 dlen = ntohs(e.len)-4;
2067
2068 ND_PRINT((ndo," len=%d", dlen));
2069 if (2 < ndo->ndo_vflag && 4 < dlen) {
2070 ND_PRINT((ndo," "));
2071 if (!rawprint(ndo, (caddr_t)(ext + 1), dlen))
2072 goto trunc;
2073 }
2074
2075 dat = (u_char *)(ext+1);
2076 ND_TCHECK2(*dat, dlen);
2077
2078 #ifdef HAVE_LIBCRYPTO
2079 /* try to decypt it! */
2080 if(esp_print_decrypt_buffer_by_ikev2(ndo,
2081 base->flags & ISAKMP_FLAG_I,
2082 base->i_ck, base->r_ck,
2083 dat, dat+dlen)) {
2084
2085 ext = (const struct isakmp_gen *)ndo->ndo_packetp;
2086
2087 /* got it decrypted, print stuff inside. */
2088 ikev2_sub_print(ndo, base, e.np, ext, ndo->ndo_snapend,
2089 phase, doi, proto, depth+1);
2090 }
2091 #endif
2092
2093
2094 /* always return NULL, because E must be at end, and NP refers
2095 * to what was inside.
2096 */
2097 return NULL;
2098 trunc:
2099 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2100 return NULL;
2101 }
2102
2103 static const u_char *
2104 ikev2_cp_print(netdissect_options *ndo, u_char tpay,
2105 const struct isakmp_gen *ext,
2106 u_int item_len _U_, const u_char *ep _U_,
2107 u_int32_t phase _U_, u_int32_t doi _U_,
2108 u_int32_t proto _U_, int depth _U_)
2109 {
2110 return ikev2_gen_print(ndo, tpay, ext);
2111 }
2112
2113 static const u_char *
2114 ikev2_eap_print(netdissect_options *ndo, u_char tpay,
2115 const struct isakmp_gen *ext,
2116 u_int item_len _U_, const u_char *ep _U_,
2117 u_int32_t phase _U_, u_int32_t doi _U_,
2118 u_int32_t proto _U_, int depth _U_)
2119 {
2120 return ikev2_gen_print(ndo, tpay, ext);
2121 }
2122
2123 static const u_char *
2124 ike_sub0_print(netdissect_options *ndo,
2125 u_char np, const struct isakmp_gen *ext, const u_char *ep,
2126
2127 u_int32_t phase, u_int32_t doi, u_int32_t proto, int depth)
2128 {
2129 const u_char *cp;
2130 struct isakmp_gen e;
2131 u_int item_len;
2132
2133 cp = (u_char *)ext;
2134 ND_TCHECK(*ext);
2135 safememcpy(&e, ext, sizeof(e));
2136
2137 /*
2138 * Since we can't have a payload length of less than 4 bytes,
2139 * we need to bail out here if the generic header is nonsensical
2140 * or truncated, otherwise we could loop forever processing
2141 * zero-length items or otherwise misdissect the packet.
2142 */
2143 item_len = ntohs(e.len);
2144 if (item_len <= 4)
2145 return NULL;
2146
2147 if (NPFUNC(np)) {
2148 /*
2149 * XXX - what if item_len is too short, or too long,
2150 * for this payload type?
2151 */
2152 cp = (*npfunc[np])(ndo, np, ext, item_len, ep, phase, doi, proto, depth);
2153 } else {
2154 ND_PRINT((ndo,"%s", NPSTR(np)));
2155 cp += item_len;
2156 }
2157
2158 return cp;
2159 trunc:
2160 ND_PRINT((ndo," [|isakmp]"));
2161 return NULL;
2162 }
2163
2164 static const u_char *
2165 ikev1_sub_print(netdissect_options *ndo,
2166 u_char np, const struct isakmp_gen *ext, const u_char *ep,
2167 u_int32_t phase, u_int32_t doi, u_int32_t proto, int depth)
2168 {
2169 const u_char *cp;
2170 int i;
2171 struct isakmp_gen e;
2172
2173 cp = (const u_char *)ext;
2174
2175 while (np) {
2176 ND_TCHECK(*ext);
2177
2178 safememcpy(&e, ext, sizeof(e));
2179
2180 ND_TCHECK2(*ext, ntohs(e.len));
2181
2182 depth++;
2183 ND_PRINT((ndo,"\n"));
2184 for (i = 0; i < depth; i++)
2185 ND_PRINT((ndo," "));
2186 ND_PRINT((ndo,"("));
2187 cp = ike_sub0_print(ndo, np, ext, ep, phase, doi, proto, depth);
2188 ND_PRINT((ndo,")"));
2189 depth--;
2190
2191 if (cp == NULL) {
2192 /* Zero-length subitem */
2193 return NULL;
2194 }
2195
2196 np = e.np;
2197 ext = (struct isakmp_gen *)cp;
2198 }
2199 return cp;
2200 trunc:
2201 ND_PRINT((ndo," [|%s]", NPSTR(np)));
2202 return NULL;
2203 }
2204
2205 static char *
2206 numstr(int x)
2207 {
2208 static char buf[20];
2209 snprintf(buf, sizeof(buf), "#%d", x);
2210 return buf;
2211 }
2212
2213 /*
2214 * some compiler tries to optimize memcpy(), using the alignment constraint
2215 * on the argument pointer type. by using this function, we try to avoid the
2216 * optimization.
2217 */
2218 static void
2219 safememcpy(void *p, const void *q, size_t l)
2220 {
2221 memcpy(p, q, l);
2222 }
2223
2224 static void
2225 ikev1_print(netdissect_options *ndo,
2226 const u_char *bp, u_int length,
2227 const u_char *bp2, struct isakmp *base)
2228 {
2229 const struct isakmp *p;
2230 const u_char *ep;
2231 u_char np;
2232 int i;
2233 int phase;
2234
2235 p = (const struct isakmp *)bp;
2236 ep = ndo->ndo_snapend;
2237
2238 phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2;
2239 if (phase == 1)
2240 ND_PRINT((ndo," phase %d", phase));
2241 else
2242 ND_PRINT((ndo," phase %d/others", phase));
2243
2244 i = cookie_find(&base->i_ck);
2245 if (i < 0) {
2246 if (iszero((u_char *)&base->r_ck, sizeof(base->r_ck))) {
2247 /* the first packet */
2248 ND_PRINT((ndo," I"));
2249 if (bp2)
2250 cookie_record(&base->i_ck, bp2);
2251 } else
2252 ND_PRINT((ndo," ?"));
2253 } else {
2254 if (bp2 && cookie_isinitiator(i, bp2))
2255 ND_PRINT((ndo," I"));
2256 else if (bp2 && cookie_isresponder(i, bp2))
2257 ND_PRINT((ndo," R"));
2258 else
2259 ND_PRINT((ndo," ?"));
2260 }
2261
2262 ND_PRINT((ndo," %s", ETYPESTR(base->etype)));
2263 if (base->flags) {
2264 ND_PRINT((ndo,"[%s%s]", base->flags & ISAKMP_FLAG_E ? "E" : "",
2265 base->flags & ISAKMP_FLAG_C ? "C" : ""));
2266 }
2267
2268 if (ndo->ndo_vflag) {
2269 const struct isakmp_gen *ext;
2270 int nparen;
2271
2272 ND_PRINT((ndo,":"));
2273
2274 /* regardless of phase... */
2275 if (base->flags & ISAKMP_FLAG_E) {
2276 /*
2277 * encrypted, nothing we can do right now.
2278 * we hope to decrypt the packet in the future...
2279 */
2280 ND_PRINT((ndo," [encrypted %s]", NPSTR(base->np)));
2281 goto done;
2282 }
2283
2284 nparen = 0;
2285 CHECKLEN(p + 1, base->np);
2286 np = base->np;
2287 ext = (struct isakmp_gen *)(p + 1);
2288 ikev1_sub_print(ndo, np, ext, ep, phase, 0, 0, 0);
2289 }
2290
2291 done:
2292 if (ndo->ndo_vflag) {
2293 if (ntohl(base->len) != length) {
2294 ND_PRINT((ndo," (len mismatch: isakmp %u/ip %u)",
2295 (u_int32_t)ntohl(base->len), length));
2296 }
2297 }
2298 }
2299
2300 static const u_char *
2301 ikev2_sub0_print(netdissect_options *ndo, struct isakmp *base,
2302 u_char np, int pcount,
2303 const struct isakmp_gen *ext, const u_char *ep,
2304 u_int32_t phase, u_int32_t doi, u_int32_t proto, int depth)
2305 {
2306 const u_char *cp;
2307 struct isakmp_gen e;
2308 u_int item_len;
2309
2310 cp = (u_char *)ext;
2311 ND_TCHECK(*ext);
2312 safememcpy(&e, ext, sizeof(e));
2313
2314 /*
2315 * Since we can't have a payload length of less than 4 bytes,
2316 * we need to bail out here if the generic header is nonsensical
2317 * or truncated, otherwise we could loop forever processing
2318 * zero-length items or otherwise misdissect the packet.
2319 */
2320 item_len = ntohs(e.len);
2321 if (item_len <= 4)
2322 return NULL;
2323
2324 if(np == ISAKMP_NPTYPE_P) {
2325 cp = ikev2_p_print(ndo, np, pcount, ext, item_len,
2326 ep, phase, doi, proto, depth);
2327 } else if(np == ISAKMP_NPTYPE_T) {
2328 cp = ikev2_t_print(ndo, np, pcount, ext, item_len,
2329 ep, phase, doi, proto, depth);
2330 } else if(np == ISAKMP_NPTYPE_v2E) {
2331 cp = ikev2_e_print(ndo, base, np, ext, item_len,
2332 ep, phase, doi, proto, depth);
2333 } else if (NPFUNC(np)) {
2334 /*
2335 * XXX - what if item_len is too short, or too long,
2336 * for this payload type?
2337 */
2338 cp = (*npfunc[np])(ndo, np, /*pcount,*/ ext, item_len,
2339 ep, phase, doi, proto, depth);
2340 } else {
2341 ND_PRINT((ndo,"%s", NPSTR(np)));
2342 cp += item_len;
2343 }
2344
2345 return cp;
2346 trunc:
2347 ND_PRINT((ndo," [|isakmp]"));
2348 return NULL;
2349 }
2350
2351 static const u_char *
2352 ikev2_sub_print(netdissect_options *ndo,
2353 struct isakmp *base,
2354 u_char np, const struct isakmp_gen *ext, const u_char *ep,
2355 u_int32_t phase, u_int32_t doi, u_int32_t proto, int depth)
2356 {
2357 const u_char *cp;
2358 int i;
2359 int pcount;
2360 struct isakmp_gen e;
2361
2362 cp = (const u_char *)ext;
2363 pcount = 0;
2364 while (np) {
2365 pcount++;
2366 ND_TCHECK(*ext);
2367
2368 safememcpy(&e, ext, sizeof(e));
2369
2370 ND_TCHECK2(*ext, ntohs(e.len));
2371
2372 depth++;
2373 ND_PRINT((ndo,"\n"));
2374 for (i = 0; i < depth; i++)
2375 ND_PRINT((ndo," "));
2376 ND_PRINT((ndo,"("));
2377 cp = ikev2_sub0_print(ndo, base, np, pcount,
2378 ext, ep, phase, doi, proto, depth);
2379 ND_PRINT((ndo,")"));
2380 depth--;
2381
2382 if (cp == NULL) {
2383 /* Zero-length subitem */
2384 return NULL;
2385 }
2386
2387 np = e.np;
2388 ext = (struct isakmp_gen *)cp;
2389 }
2390 return cp;
2391 trunc:
2392 ND_PRINT((ndo," [|%s]", NPSTR(np)));
2393 return NULL;
2394 }
2395
2396 static void
2397 ikev2_print(netdissect_options *ndo,
2398 const u_char *bp, u_int length,
2399 const u_char *bp2 _U_, struct isakmp *base)
2400 {
2401 const struct isakmp *p;
2402 const u_char *ep;
2403 u_char np;
2404 int phase;
2405
2406 p = (const struct isakmp *)bp;
2407 ep = ndo->ndo_snapend;
2408
2409 phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2;
2410 if (phase == 1)
2411 ND_PRINT((ndo, " parent_sa"));
2412 else
2413 ND_PRINT((ndo, " child_sa "));
2414
2415 ND_PRINT((ndo, " %s", ETYPESTR(base->etype)));
2416 if (base->flags) {
2417 ND_PRINT((ndo, "[%s%s%s]",
2418 base->flags & ISAKMP_FLAG_I ? "I" : "",
2419 base->flags & ISAKMP_FLAG_V ? "V" : "",
2420 base->flags & ISAKMP_FLAG_R ? "R" : ""));
2421 }
2422
2423 if (ndo->ndo_vflag) {
2424 const struct isakmp_gen *ext;
2425 int nparen;
2426
2427 ND_PRINT((ndo, ":"));
2428
2429 /* regardless of phase... */
2430 if (base->flags & ISAKMP_FLAG_E) {
2431 /*
2432 * encrypted, nothing we can do right now.
2433 * we hope to decrypt the packet in the future...
2434 */
2435 ND_PRINT((ndo, " [encrypted %s]", NPSTR(base->np)));
2436 goto done;
2437 }
2438
2439 nparen = 0;
2440 CHECKLEN(p + 1, base->np)
2441
2442 np = base->np;
2443 ext = (struct isakmp_gen *)(p + 1);
2444 ikev2_sub_print(ndo, base, np, ext, ep, phase, 0, 0, 0);
2445 }
2446
2447 done:
2448 if (ndo->ndo_vflag) {
2449 if (ntohl(base->len) != length) {
2450 ND_PRINT((ndo, " (len mismatch: isakmp %u/ip %u)",
2451 (u_int32_t)ntohl(base->len), length));
2452 }
2453 }
2454 }
2455
2456 void
2457 isakmp_print(netdissect_options *ndo,
2458 const u_char *bp, u_int length,
2459 const u_char *bp2)
2460 {
2461 const struct isakmp *p;
2462 struct isakmp base;
2463 const u_char *ep;
2464 int major, minor;
2465
2466 #ifdef HAVE_LIBCRYPTO
2467 /* initialize SAs */
2468 if (ndo->ndo_sa_list_head == NULL) {
2469 if (ndo->ndo_espsecret)
2470 esp_print_decodesecret(ndo);
2471 }
2472 #endif
2473
2474 p = (const struct isakmp *)bp;
2475 ep = ndo->ndo_snapend;
2476
2477 if ((struct isakmp *)ep < p + 1) {
2478 ND_PRINT((ndo,"[|isakmp]"));
2479 return;
2480 }
2481
2482 safememcpy(&base, p, sizeof(base));
2483
2484 ND_PRINT((ndo,"isakmp"));
2485 major = (base.vers & ISAKMP_VERS_MAJOR)
2486 >> ISAKMP_VERS_MAJOR_SHIFT;
2487 minor = (base.vers & ISAKMP_VERS_MINOR)
2488 >> ISAKMP_VERS_MINOR_SHIFT;
2489
2490 if (ndo->ndo_vflag) {
2491 ND_PRINT((ndo," %d.%d", major, minor));
2492 }
2493
2494 if (ndo->ndo_vflag) {
2495 ND_PRINT((ndo," msgid "));
2496 hexprint(ndo, (caddr_t)&base.msgid, sizeof(base.msgid));
2497 }
2498
2499 if (1 < ndo->ndo_vflag) {
2500 ND_PRINT((ndo," cookie "));
2501 hexprint(ndo, (caddr_t)&base.i_ck, sizeof(base.i_ck));
2502 ND_PRINT((ndo,"->"));
2503 hexprint(ndo, (caddr_t)&base.r_ck, sizeof(base.r_ck));
2504 }
2505 ND_PRINT((ndo,":"));
2506
2507 switch(major) {
2508 case IKEv1_MAJOR_VERSION:
2509 ikev1_print(ndo, bp, length, bp2, &base);
2510 break;
2511
2512 case IKEv2_MAJOR_VERSION:
2513 ikev2_print(ndo, bp, length, bp2, &base);
2514 break;
2515 }
2516 }
2517
2518 void
2519 isakmp_rfc3948_print(netdissect_options *ndo,
2520 const u_char *bp, u_int length,
2521 const u_char *bp2)
2522 {
2523 const u_char *ep;
2524 ep = ndo->ndo_snapend;
2525
2526 if(length == 1 && bp[0]==0xff) {
2527 ND_PRINT((ndo, "isakmp-nat-keep-alive"));
2528 return;
2529 }
2530
2531 if(length < 4) {
2532 goto trunc;
2533 }
2534
2535 /*
2536 * see if this is an IKE packet
2537 */
2538 if(bp[0]==0 && bp[1]==0 && bp[2]==0 && bp[3]==0) {
2539 ND_PRINT((ndo, "NONESP-encap: "));
2540 isakmp_print(ndo, bp+4, length-4, bp2);
2541 return;
2542 }
2543
2544 /* must be an ESP packet */
2545 {
2546 int nh, enh, padlen;
2547 int advance;
2548
2549 ND_PRINT((ndo, "UDP-encap: "));
2550
2551 advance = esp_print(ndo, bp, length, bp2, &enh, &padlen);
2552 if(advance <= 0)
2553 return;
2554
2555 bp += advance;
2556 length -= advance + padlen;
2557 nh = enh & 0xff;
2558
2559 ip_print_inner(ndo, bp, length, nh, bp2);
2560 return;
2561 }
2562
2563 trunc:
2564 ND_PRINT((ndo,"[|isakmp]"));
2565 return;
2566 }
2567
2568 /*
2569 * Local Variables:
2570 * c-style: whitesmith
2571 * c-basic-offset: 8
2572 * End:
2573 */
2574
2575
2576
2577