2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
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)";
36 #define NETDISSECT_REWORKED
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.
44 #ifndef HAVE_OPENSSL_EVP_H
48 #include <tcpdump-stdinc.h>
55 #include "ipsec_doi.h"
57 #include "interface.h"
58 #include "addrtoname.h"
59 #include "extract.h" /* must come after interface.h */
66 #ifndef HAVE_SOCKADDR_STORAGE
67 #define sockaddr_storage sockaddr
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, \
74 const u_char *end_pointer, \
77 u_int32_t proto0, int depth)
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
);
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
);
107 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
110 const struct isakmp_gen
*ext
,
112 const u_char
*end_pointer
,
115 u_int32_t proto0
, int depth
);
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);
123 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
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
,
131 static char *numstr(int);
132 static void safememcpy(void *, const void *, size_t);
135 ikev1_print(netdissect_options
*ndo
,
136 const u_char
*bp
, u_int length
,
137 const u_char
*bp2
, struct isakmp
*base
);
139 #define MAXINITIATORS 20
143 struct sockaddr_storage iaddr
;
144 struct sockaddr_storage raddr
;
145 } cookiecache
[MAXINITIATORS
];
148 static const char *protoidstr
[] = {
149 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
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 */
168 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
169 const struct isakmp_gen
*ext
,
171 const u_char
*end_pointer
,
174 u_int32_t proto0
, int depth
) = {
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 */
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 */
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)
229 #define CHECKLEN(p, np) \
230 if (ep < (u_char *)(p)) { \
231 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
237 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
238 ? npfunc[(x)] : NULL)
241 iszero(u_char
*p
, size_t l
)
250 /* find cookie from initiator cache */
252 cookie_find(cookie_t
*in
)
256 for (i
= 0; i
< MAXINITIATORS
; i
++) {
257 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
264 /* record initiator */
266 cookie_record(cookie_t
*in
, const u_char
*bp2
)
270 struct sockaddr_in
*sin
;
273 struct sockaddr_in6
*sin6
;
278 ninitiator
= (i
+ 1) % MAXINITIATORS
;
282 ip
= (struct ip
*)bp2
;
285 memset(&cookiecache
[ninitiator
].iaddr
, 0,
286 sizeof(cookiecache
[ninitiator
].iaddr
));
287 memset(&cookiecache
[ninitiator
].raddr
, 0,
288 sizeof(cookiecache
[ninitiator
].raddr
));
290 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
291 #ifdef HAVE_SOCKADDR_SA_LEN
292 sin
->sin_len
= sizeof(struct sockaddr_in
);
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
);
300 sin
->sin_family
= AF_INET
;
301 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
305 memset(&cookiecache
[ninitiator
].iaddr
, 0,
306 sizeof(cookiecache
[ninitiator
].iaddr
));
307 memset(&cookiecache
[ninitiator
].raddr
, 0,
308 sizeof(cookiecache
[ninitiator
].raddr
));
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
);
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
);
321 sin6
->sin6_family
= AF_INET6
;
322 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
328 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
329 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
332 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
333 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
335 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
337 struct sockaddr_storage ss
;
340 struct sockaddr_in
*sin
;
343 struct sockaddr_in6
*sin6
;
347 memset(&ss
, 0, sizeof(ss
));
348 ip
= (struct ip
*)bp2
;
351 sin
= (struct sockaddr_in
*)&ss
;
352 #ifdef HAVE_SOCKADDR_SA_LEN
353 sin
->sin_len
= sizeof(struct sockaddr_in
);
355 sin
->sin_family
= AF_INET
;
356 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
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
);
365 sin6
->sin6_family
= AF_INET6
;
366 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
373 sa
= (struct sockaddr
*)&ss
;
375 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
377 #ifdef HAVE_SOCKADDR_SA_LEN
381 if (sa
->sa_family
== AF_INET6
)
382 salen
= sizeof(struct sockaddr_in6
);
384 salen
= sizeof(struct sockaddr
);
386 salen
= sizeof(struct sockaddr
);
389 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
392 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
394 #ifdef HAVE_SOCKADDR_SA_LEN
398 if (sa
->sa_family
== AF_INET6
)
399 salen
= sizeof(struct sockaddr_in6
);
401 salen
= sizeof(struct sockaddr
);
403 salen
= sizeof(struct sockaddr
);
406 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
413 hexprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
419 for (i
= 0; i
< len
; i
++)
420 ND_PRINT((ndo
,"%02x", p
[i
] & 0xff));
424 rawprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
426 ND_TCHECK2(*loc
, len
);
428 hexprint(ndo
, loc
, len
);
436 * returns false if we run out of data buffer
438 static int ike_show_somedata(struct netdissect_options
*ndo
,
439 const u_char
*cp
, const u_char
*ep
)
441 /* there is too much data, just show some of it */
442 const u_char
*end
= ep
- 20;
449 /* really shouldn't happen because of above */
455 ND_PRINT((ndo
," data=("));
456 if(!rawprint(ndo
, (caddr_t
)(cp
), len
)) goto trunc
;
457 ND_PRINT((ndo
, "..."));
459 if(!rawprint(ndo
, (caddr_t
)(end
), elen
)) goto trunc
;
471 const char *value
[30]; /*XXX*/
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
)
487 totlen
= 4 + EXTRACT_16BITS(&q
[1]);
488 if (ep
< p
+ totlen
) {
489 ND_PRINT((ndo
,"[|attr]"));
494 t
= EXTRACT_16BITS(&q
[0]) & 0x7fff;
495 if (map
&& t
< nmap
&& map
[t
].type
)
496 ND_PRINT((ndo
,"type=%s ", map
[t
].type
));
498 ND_PRINT((ndo
,"type=#%d ", t
));
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
]));
505 rawprint(ndo
, (caddr_t
)&q
[1], 2);
507 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&q
[1])));
508 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&q
[1]));
514 static const u_char
*
515 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep
)
525 totlen
= 4 + EXTRACT_16BITS(&q
[1]);
526 if (ep
< p
+ totlen
) {
527 ND_PRINT((ndo
,"[|attr]"));
532 t
= EXTRACT_16BITS(&q
[0]) & 0x7fff;
533 ND_PRINT((ndo
,"type=#%d ", t
));
535 ND_PRINT((ndo
,"value="));
537 rawprint(ndo
, (caddr_t
)&q
[1], 2);
539 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&q
[1])));
540 rawprint(ndo
, (caddr_t
)&p
[2], EXTRACT_16BITS(&q
[1]));
546 static const u_char
*
547 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
548 const struct isakmp_gen
*ext
,
550 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0 _U_
,
551 u_int32_t proto0
, int depth
)
553 const struct ikev1_pl_sa
*p
;
554 struct ikev1_pl_sa sa
;
556 u_int32_t doi
, sit
, ident
;
557 const u_char
*cp
, *np
;
560 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SA
)));
562 p
= (struct ikev1_pl_sa
*)ext
;
564 safememcpy(&sa
, ext
, sizeof(sa
));
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);
573 ND_PRINT((ndo
," doi=ipsec"));
574 q
= (u_int32_t
*)&sa
.sit
;
575 ND_PRINT((ndo
," situation="));
578 ND_PRINT((ndo
,"identity"));
582 ND_PRINT((ndo
,"%ssecrecy", t
? "+" : ""));
586 ND_PRINT((ndo
,"%sintegrity", t
? "+" : ""));
588 np
= (u_char
*)ext
+ sizeof(sa
);
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
)));
596 ext
= (struct isakmp_gen
*)np
;
599 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
604 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SA
)));
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
)
614 const struct ikev1_pl_p
*p
;
615 struct ikev1_pl_p prop
;
618 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_P
)));
620 p
= (struct ikev1_pl_p
*)ext
;
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
));
626 ND_PRINT((ndo
," spi="));
627 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
631 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
634 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
635 prop
.prot_id
, depth
);
639 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
643 static const char *ikev1_p_map
[] = {
647 static const char *ikev2_t_type_map
[]={
648 NULL
, "encr", "prf", "integ", "dh", "esn"
651 static const char *ah_p_map
[] = {
652 NULL
, "(reserved)", "md5", "sha", "1des",
653 "sha2-256", "sha2-384", "sha2-512",
656 static const char *prf_p_map
[] = {
657 NULL
, "hmac-md5", "hmac-sha", "hmac-tiger",
661 static const char *integ_p_map
[] = {
662 NULL
, "hmac-md5", "hmac-sha", "dec-mac",
663 "kpdk-md5", "aes-xcbc"
666 static const char *esn_p_map
[] = {
670 static const char *dh_p_map
[] = {
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 */
687 static const char *esp_p_map
[] = {
688 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
689 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
692 static const char *ipcomp_p_map
[] = {
693 NULL
, "oui", "deflate", "lzs",
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 */
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
} },
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
}},
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 */
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
} },
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_
)
777 const struct ikev1_pl_t
*p
;
781 const struct attrmap
*map
;
785 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_T
)));
787 p
= (struct ikev1_pl_t
*)ext
;
789 safememcpy(&t
, ext
, sizeof(t
));
793 idstr
= STR_OR_ID(t
.t_id
, ikev1_p_map
);
795 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
798 idstr
= STR_OR_ID(t
.t_id
, ah_p_map
);
800 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
803 idstr
= STR_OR_ID(t
.t_id
, esp_p_map
);
805 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
808 idstr
= STR_OR_ID(t
.t_id
, ipcomp_p_map
);
810 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
820 ND_PRINT((ndo
," #%d id=%s ", t
.t_no
, idstr
));
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
) {
827 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
830 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
833 ND_PRINT((ndo
,"..."));
836 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
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_
)
848 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_KE
)));
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
)) {
855 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
858 return (u_char
*)ext
+ ntohs(e
.len
);
860 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_KE
)));
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_
)
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",
876 static const char *ipsecidtypestr
[] = {
877 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
878 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
884 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_ID
)));
886 p
= (struct ikev1_pl_id
*)ext
;
888 safememcpy(&id
, ext
, sizeof(id
));
889 if (sizeof(*p
) < item_len
) {
890 data
= (u_char
*)(p
+ 1);
891 len
= item_len
- sizeof(*p
);
898 ND_PRINT((ndo
," [phase=%d doi=%d proto=%d]", phase
, doi
, proto
));
901 #ifndef USE_IPSECDOI_IN_PHASE1
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)));
910 #ifdef USE_IPSECDOI_IN_PHASE1
915 const struct ipsecdoi_id
*p
;
916 struct ipsecdoi_id id
;
919 p
= (struct ipsecdoi_id
*)ext
;
921 safememcpy(&id
, ext
, sizeof(id
));
922 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.type
, ipsecidtypestr
)));
927 pe
= getprotobynumber(id
.proto_id
);
929 ND_PRINT((ndo
," protoid=%s", pe
->p_name
));
934 /* it DOES NOT mean IPPROTO_IP! */
935 ND_PRINT((ndo
," protoid=%s", "0"));
937 ND_PRINT((ndo
," port=%d", ntohs(id
.port
)));
942 ND_TCHECK2(*data
, len
);
944 case IPSECDOI_ID_IPV4_ADDR
:
946 ND_PRINT((ndo
," len=%d [bad: < 4]", len
));
948 ND_PRINT((ndo
," len=%d %s", len
, ipaddr_string(data
)));
951 case IPSECDOI_ID_FQDN
:
952 case IPSECDOI_ID_USER_FQDN
:
955 ND_PRINT((ndo
," len=%d ", len
));
956 for (i
= 0; i
< len
; i
++)
957 safeputchar(data
[i
]);
961 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
965 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
967 mask
= data
+ sizeof(struct in_addr
);
968 ND_PRINT((ndo
," len=%d %s/%u.%u.%u.%u", len
,
970 mask
[0], mask
[1], mask
[2], mask
[3]));
976 case IPSECDOI_ID_IPV6_ADDR
:
978 ND_PRINT((ndo
," len=%d [bad: < 16]", len
));
980 ND_PRINT((ndo
," len=%d %s", len
, ip6addr_string(data
)));
983 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
985 const u_int32_t
*mask
;
987 ND_PRINT((ndo
," len=%d [bad: < 20]", len
));
989 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
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]));
999 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1001 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1003 ND_PRINT((ndo
," len=%d %s-%s", len
,
1004 ipaddr_string(data
),
1005 ipaddr_string(data
+ sizeof(struct in_addr
))));
1010 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1012 ND_PRINT((ndo
," len=%d [bad: < 32]", len
));
1014 ND_PRINT((ndo
," len=%d %s-%s", len
,
1015 ip6addr_string(data
),
1016 ip6addr_string(data
+ sizeof(struct in6_addr
))));
1021 case IPSECDOI_ID_DER_ASN1_DN
:
1022 case IPSECDOI_ID_DER_ASN1_GN
:
1023 case IPSECDOI_ID_KEY_ID
:
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
))
1037 return (u_char
*)ext
+ item_len
;
1039 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_ID
)));
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_
,
1048 u_int32_t proto0 _U_
, int depth _U_
)
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",
1058 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CERT
)));
1060 p
= (struct ikev1_pl_cert
*)ext
;
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))
1070 return (u_char
*)ext
+ item_len
;
1072 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
)));
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_
)
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",
1090 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CR
)));
1092 p
= (struct ikev1_pl_cert
*)ext
;
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))
1102 return (u_char
*)ext
+ item_len
;
1104 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CR
)));
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_
)
1114 struct isakmp_gen e
;
1116 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_HASH
)));
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))
1126 return (u_char
*)ext
+ ntohs(e
.len
);
1128 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
)));
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_
)
1138 struct isakmp_gen e
;
1140 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SIG
)));
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))
1150 return (u_char
*)ext
+ ntohs(e
.len
);
1152 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
)));
1156 static const u_char
*
1157 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1158 const struct isakmp_gen
*ext
,
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_
)
1164 struct isakmp_gen e
;
1166 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE
)));
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))
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
))
1180 return (u_char
*)ext
+ ntohs(e
.len
);
1182 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
)));
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
)
1192 struct ikev1_pl_n
*p
, n
;
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",
1215 static const char *ipsec_notify_error_str
[] = {
1218 static const char *notify_status_str
[] = {
1221 static const char *ipsec_notify_status_str
[] = {
1222 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1225 /* NOTE: these macro must be called with x in proper range */
1228 #define NOTIFY_ERROR_STR(x) \
1229 STR_OR_ID((x), notify_error_str)
1232 #define IPSEC_NOTIFY_ERROR_STR(x) \
1233 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1236 #define NOTIFY_STATUS_STR(x) \
1237 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1240 #define IPSEC_NOTIFY_STATUS_STR(x) \
1241 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1243 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_N
)));
1245 p
= (struct ikev1_pl_n
*)ext
;
1247 safememcpy(&n
, ext
, sizeof(n
));
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
))));
1260 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1262 ND_PRINT((ndo
," spi="));
1263 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1266 return (u_char
*)(p
+ 1) + n
.spi_size
;
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
))));
1280 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1282 ND_PRINT((ndo
," spi="));
1283 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1287 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
1288 ep2
= (u_char
*)p
+ item_len
;
1291 ND_PRINT((ndo
," orig=("));
1292 switch (ntohs(n
.type
)) {
1293 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
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
);
1303 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1304 ND_PRINT((ndo
,"replay detection %sabled",
1305 (*(u_int32_t
*)cp
) ? "en" : "dis"));
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
,
1315 isakmp_print(ndo
, cp
,
1316 item_len
- sizeof(*p
) - n
.spi_size
,
1319 ND_PRINT((ndo
,")"));
1321 return (u_char
*)ext
+ item_len
;
1323 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
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_
)
1333 const struct ikev1_pl_d
*p
;
1334 struct ikev1_pl_d d
;
1340 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_D
)));
1342 p
= (struct ikev1_pl_d
*)ext
;
1344 safememcpy(&d
, ext
, sizeof(d
));
1348 ND_PRINT((ndo
," doi=%u", doi
));
1349 ND_PRINT((ndo
," proto=%u", proto
));
1351 ND_PRINT((ndo
," doi=ipsec"));
1352 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
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
++) {
1360 ND_PRINT((ndo
,","));
1361 if (!rawprint(ndo
, (caddr_t
)q
, d
.spi_size
))
1367 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_D
)));
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_
)
1378 struct isakmp_gen e
;
1380 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_VID
)));
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))
1390 return (u_char
*)ext
+ ntohs(e
.len
);
1392 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_VID
)));
1396 /************************************************************/
1398 /* IKE v2 - rfc4306 - dissector */
1400 /************************************************************/
1403 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, int critical
)
1405 ND_PRINT((ndo
,"%s%s:", payname
, critical
&0x80 ? "[C]" : ""));
1408 static const u_char
*
1409 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1410 const struct isakmp_gen
*ext
)
1412 struct isakmp_gen e
;
1415 safememcpy(&e
, ext
, sizeof(e
));
1416 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
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))
1424 return (u_char
*)ext
+ ntohs(e
.len
);
1426 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
1436 const struct ikev2_t
*p
;
1441 const struct attrmap
*map
;
1445 p
= (struct ikev2_t
*)ext
;
1447 safememcpy(&t
, ext
, sizeof(t
));
1448 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), t
.h
.critical
);
1450 t_id
= ntohs(t
.t_id
);
1457 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1459 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1463 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1467 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1471 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1475 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1484 ND_PRINT((ndo
," #%u type=%s id=%s ", pcount
,
1485 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1488 ND_PRINT((ndo
," #%u type=%s id=%u ", pcount
,
1489 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1491 cp
= (u_char
*)(p
+ 1);
1492 ep2
= (u_char
*)p
+ item_len
;
1493 while (cp
< ep
&& cp
< ep2
) {
1495 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1498 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1501 ND_PRINT((ndo
,"..."));
1504 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
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
)
1514 const struct ikev2_p
*p
;
1515 struct ikev2_p prop
;
1518 p
= (struct ikev2_p
*)ext
;
1520 safememcpy(&prop
, ext
, sizeof(prop
));
1521 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), prop
.h
.critical
);
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
))
1532 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1535 cp
= ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1536 prop
.prot_id
, depth
);
1540 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
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_
)
1551 struct isakmp_gen e
;
1552 int osa_length
, sa_length
;
1555 safememcpy(&e
, ext1
, sizeof(e
));
1556 ikev2_pay_print(ndo
, "sa", e
.critical
);
1558 osa_length
= ntohs(e
.len
);
1559 sa_length
= osa_length
- 4;
1560 ND_PRINT((ndo
," len=%d", sa_length
));
1562 ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_P
,
1566 return (u_char
*)ext1
+ osa_length
;
1568 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
1582 k
= (struct ikev2_ke
*)ext
;
1584 safememcpy(&ke
, ext
, sizeof(ke
));
1585 ikev2_pay_print(ndo
, NPSTR(tpay
), ke
.h
.critical
);
1587 ND_PRINT((ndo
," len=%u group=%s", ntohs(ke
.h
.len
) - 8,
1588 STR_OR_ID(ntohs(ke
.ke_group
), dh_p_map
)));
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))
1595 return (u_char
*)ext
+ ntohs(ke
.h
.len
);
1597 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
1609 int id_len
, idtype_len
, i
;
1610 unsigned int dumpascii
, dumphex
;
1611 unsigned char *typedata
;
1614 safememcpy(&id
, ext
, sizeof(id
));
1615 ikev2_pay_print(ndo
, NPSTR(tpay
), id
.h
.critical
);
1617 id_len
= ntohs(id
.h
.len
);
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))
1626 idtype_len
=id_len
- sizeof(struct ikev2_id
);
1629 typedata
= (unsigned char *)(ext
)+sizeof(struct ikev2_id
);
1633 ND_PRINT((ndo
, " ipv4:"));
1637 ND_PRINT((ndo
, " fqdn:"));
1640 case ID_RFC822_ADDR
:
1641 ND_PRINT((ndo
, " rfc822:"));
1645 ND_PRINT((ndo
, " ipv6:"));
1648 case ID_DER_ASN1_DN
:
1649 ND_PRINT((ndo
, " dn:"));
1652 case ID_DER_ASN1_GN
:
1653 ND_PRINT((ndo
, " gn:"));
1657 ND_PRINT((ndo
, " keyid:"));
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
]));
1668 ND_PRINT((ndo
, "."));
1673 if (!rawprint(ndo
, (caddr_t
)typedata
, idtype_len
))
1677 return (u_char
*)ext
+ id_len
;
1679 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
1690 return ikev2_gen_print(ndo
, tpay
, ext
);
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_
)
1700 return ikev2_gen_print(ndo
, tpay
, ext
);
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_
)
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
);
1717 safememcpy(&a
, ext
, sizeof(a
));
1718 ikev2_pay_print(ndo
, NPSTR(tpay
), a
.h
.critical
);
1719 len
= ntohs(a
.h
.len
);
1721 ND_PRINT((ndo
," len=%d method=%s", len
-4,
1722 STR_OR_ID(a
.auth_method
, v2_auth
)));
1724 if (1 < ndo
->ndo_vflag
&& 4 < len
) {
1725 ND_PRINT((ndo
," authdata=("));
1726 if (!rawprint(ndo
, (caddr_t
)authdata
, len
- sizeof(a
)))
1728 ND_PRINT((ndo
,") "));
1729 } else if(ndo
->ndo_vflag
&& 4 < len
) {
1730 if(!ike_show_somedata(ndo
, authdata
, ep
)) goto trunc
;
1733 return (u_char
*)ext
+ len
;
1735 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
1746 struct isakmp_gen e
;
1749 safememcpy(&e
, ext
, sizeof(e
));
1750 ikev2_pay_print(ndo
, "nonce", e
.critical
);
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))
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
;
1762 return (u_char
*)ext
+ ntohs(e
.len
);
1764 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
1776 struct ikev2_n
*p
, n
;
1779 u_char showspi
, showdata
, showsomedata
;
1780 const char *notify_name
;
1783 p
= (struct ikev2_n
*)ext
;
1785 safememcpy(&n
, ext
, sizeof(n
));
1786 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), n
.h
.critical
);
1793 ND_PRINT((ndo
," prot_id=%s", PROTOIDSTR(n
.prot_id
)));
1795 type
= ntohs(n
.type
);
1797 /* notify space is annoying sparse */
1799 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
1800 notify_name
= "unsupported_critical_payload";
1804 case IV2_NOTIFY_INVALID_IKE_SPI
:
1805 notify_name
= "invalid_ike_spi";
1809 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
1810 notify_name
= "invalid_major_version";
1814 case IV2_NOTIFY_INVALID_SYNTAX
:
1815 notify_name
= "invalid_syntax";
1819 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
1820 notify_name
= "invalid_message_id";
1824 case IV2_NOTIFY_INVALID_SPI
:
1825 notify_name
= "invalid_spi";
1829 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
1830 notify_name
= "no_protocol_chosen";
1834 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
1835 notify_name
= "invalid_ke_payload";
1839 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
1840 notify_name
= "authentication_failed";
1844 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
1845 notify_name
= "single_pair_required";
1849 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
1850 notify_name
= "no_additional_sas";
1854 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
1855 notify_name
= "internal_address_failure";
1859 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
1860 notify_name
= "failed:cp_required";
1864 case IV2_NOTIFY_INVALID_SELECTORS
:
1865 notify_name
= "invalid_selectors";
1869 case IV2_NOTIFY_INITIAL_CONTACT
:
1870 notify_name
= "initial_contact";
1874 case IV2_NOTIFY_SET_WINDOW_SIZE
:
1875 notify_name
= "set_window_size";
1879 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
1880 notify_name
= "additional_ts_possible";
1884 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
1885 notify_name
= "ipcomp_supported";
1889 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
1890 notify_name
= "nat_detection_source_ip";
1894 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
1895 notify_name
= "nat_detection_destination_ip";
1899 case IV2_NOTIFY_COOKIE
:
1900 notify_name
= "cookie";
1906 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
1907 notify_name
= "use_transport_mode";
1911 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
1912 notify_name
= "http_cert_lookup_supported";
1916 case IV2_NOTIFY_REKEY_SA
:
1917 notify_name
= "rekey_sa";
1921 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
1922 notify_name
= "tfc_padding_not_supported";
1926 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
1927 notify_name
= "non_first_fragment_also";
1933 notify_name
="error";
1934 } else if(type
< 16384) {
1935 notify_name
="private-error";
1936 } else if(type
< 40960) {
1937 notify_name
="status";
1939 notify_name
="private-status";
1944 ND_PRINT((ndo
," type=%u(%s)", type
, notify_name
));
1948 if (showspi
&& n
.spi_size
) {
1949 ND_PRINT((ndo
," spi="));
1950 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1954 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
1955 ep2
= (u_char
*)p
+ item_len
;
1957 if(3 < ndo
->ndo_vflag
) {
1961 if ((showdata
|| (showsomedata
&& ep
-cp
< 30)) && cp
< ep
) {
1962 ND_PRINT((ndo
," data=("));
1963 if (!rawprint(ndo
, (caddr_t
)(cp
), ep
- cp
))
1966 ND_PRINT((ndo
,")"));
1968 } else if(showsomedata
&& cp
< ep
) {
1969 if(!ike_show_somedata(ndo
, cp
, ep
)) goto trunc
;
1972 return (u_char
*)ext
+ item_len
;
1974 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
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_
)
1985 return ikev2_gen_print(ndo
, tpay
, ext
);
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_
)
1995 struct isakmp_gen e
;
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));
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
, "."));
2011 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2012 ND_PRINT((ndo
," "));
2013 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2016 return (u_char
*)ext
+ ntohs(e
.len
);
2018 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
2029 return ikev2_gen_print(ndo
, tpay
, ext
);
2032 static const u_char
*
2033 ikev2_e_print(netdissect_options
*ndo
,
2034 #ifndef HAVE_LIBCRYPTO
2037 struct isakmp
*base
,
2039 const struct isakmp_gen
*ext
,
2040 u_int item_len _U_
, const u_char
*ep _U_
,
2041 #ifndef HAVE_LIBCRYPTO
2045 #ifndef HAVE_LIBCRYPTO
2049 #ifndef HAVE_LIBCRYPTO
2053 #ifndef HAVE_LIBCRYPTO
2058 struct isakmp_gen e
;
2063 safememcpy(&e
, ext
, sizeof(e
));
2064 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2066 dlen
= ntohs(e
.len
)-4;
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
))
2075 dat
= (u_char
*)(ext
+1);
2076 ND_TCHECK2(*dat
, dlen
);
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
,
2085 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
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);
2094 /* always return NULL, because E must be at end, and NP refers
2095 * to what was inside.
2099 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
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_
)
2110 return ikev2_gen_print(ndo
, tpay
, ext
);
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_
)
2120 return ikev2_gen_print(ndo
, tpay
, ext
);
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
,
2127 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2130 struct isakmp_gen e
;
2135 safememcpy(&e
, ext
, sizeof(e
));
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.
2143 item_len
= ntohs(e
.len
);
2149 * XXX - what if item_len is too short, or too long,
2150 * for this payload type?
2152 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2154 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2160 ND_PRINT((ndo
," [|isakmp]"));
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
)
2171 struct isakmp_gen e
;
2173 cp
= (const u_char
*)ext
;
2178 safememcpy(&e
, ext
, sizeof(e
));
2180 ND_TCHECK2(*ext
, ntohs(e
.len
));
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
,")"));
2192 /* Zero-length subitem */
2197 ext
= (struct isakmp_gen
*)cp
;
2201 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2208 static char buf
[20];
2209 snprintf(buf
, sizeof(buf
), "#%d", x
);
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
2219 safememcpy(void *p
, const void *q
, size_t l
)
2225 ikev1_print(netdissect_options
*ndo
,
2226 const u_char
*bp
, u_int length
,
2227 const u_char
*bp2
, struct isakmp
*base
)
2229 const struct isakmp
*p
;
2235 p
= (const struct isakmp
*)bp
;
2236 ep
= ndo
->ndo_snapend
;
2238 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
2240 ND_PRINT((ndo
," phase %d", phase
));
2242 ND_PRINT((ndo
," phase %d/others", phase
));
2244 i
= cookie_find(&base
->i_ck
);
2246 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
2247 /* the first packet */
2248 ND_PRINT((ndo
," I"));
2250 cookie_record(&base
->i_ck
, bp2
);
2252 ND_PRINT((ndo
," ?"));
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"));
2259 ND_PRINT((ndo
," ?"));
2262 ND_PRINT((ndo
," %s", ETYPESTR(base
->etype
)));
2264 ND_PRINT((ndo
,"[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
2265 base
->flags
& ISAKMP_FLAG_C
? "C" : ""));
2268 if (ndo
->ndo_vflag
) {
2269 const struct isakmp_gen
*ext
;
2272 ND_PRINT((ndo
,":"));
2274 /* regardless of phase... */
2275 if (base
->flags
& ISAKMP_FLAG_E
) {
2277 * encrypted, nothing we can do right now.
2278 * we hope to decrypt the packet in the future...
2280 ND_PRINT((ndo
," [encrypted %s]", NPSTR(base
->np
)));
2285 CHECKLEN(p
+ 1, base
->np
);
2287 ext
= (struct isakmp_gen
*)(p
+ 1);
2288 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
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
));
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
)
2307 struct isakmp_gen e
;
2312 safememcpy(&e
, ext
, sizeof(e
));
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.
2320 item_len
= ntohs(e
.len
);
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
)) {
2335 * XXX - what if item_len is too short, or too long,
2336 * for this payload type?
2338 cp
= (*npfunc
[np
])(ndo
, np
, /*pcount,*/ ext
, item_len
,
2339 ep
, phase
, doi
, proto
, depth
);
2341 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2347 ND_PRINT((ndo
," [|isakmp]"));
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
)
2360 struct isakmp_gen e
;
2362 cp
= (const u_char
*)ext
;
2368 safememcpy(&e
, ext
, sizeof(e
));
2370 ND_TCHECK2(*ext
, ntohs(e
.len
));
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
,")"));
2383 /* Zero-length subitem */
2388 ext
= (struct isakmp_gen
*)cp
;
2392 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2397 ikev2_print(netdissect_options
*ndo
,
2398 const u_char
*bp
, u_int length
,
2399 const u_char
*bp2 _U_
, struct isakmp
*base
)
2401 const struct isakmp
*p
;
2406 p
= (const struct isakmp
*)bp
;
2407 ep
= ndo
->ndo_snapend
;
2409 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
2411 ND_PRINT((ndo
, " parent_sa"));
2413 ND_PRINT((ndo
, " child_sa "));
2415 ND_PRINT((ndo
, " %s", ETYPESTR(base
->etype
)));
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" : ""));
2423 if (ndo
->ndo_vflag
) {
2424 const struct isakmp_gen
*ext
;
2427 ND_PRINT((ndo
, ":"));
2429 /* regardless of phase... */
2430 if (base
->flags
& ISAKMP_FLAG_E
) {
2432 * encrypted, nothing we can do right now.
2433 * we hope to decrypt the packet in the future...
2435 ND_PRINT((ndo
, " [encrypted %s]", NPSTR(base
->np
)));
2440 CHECKLEN(p
+ 1, base
->np
)
2443 ext
= (struct isakmp_gen
*)(p
+ 1);
2444 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
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
));
2457 isakmp_print(netdissect_options
*ndo
,
2458 const u_char
*bp
, u_int length
,
2461 const struct isakmp
*p
;
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
);
2474 p
= (const struct isakmp
*)bp
;
2475 ep
= ndo
->ndo_snapend
;
2477 if ((struct isakmp
*)ep
< p
+ 1) {
2478 ND_PRINT((ndo
,"[|isakmp]"));
2482 safememcpy(&base
, p
, sizeof(base
));
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
;
2490 if (ndo
->ndo_vflag
) {
2491 ND_PRINT((ndo
," %d.%d", major
, minor
));
2494 if (ndo
->ndo_vflag
) {
2495 ND_PRINT((ndo
," msgid "));
2496 hexprint(ndo
, (caddr_t
)&base
.msgid
, sizeof(base
.msgid
));
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
));
2505 ND_PRINT((ndo
,":"));
2508 case IKEv1_MAJOR_VERSION
:
2509 ikev1_print(ndo
, bp
, length
, bp2
, &base
);
2512 case IKEv2_MAJOR_VERSION
:
2513 ikev2_print(ndo
, bp
, length
, bp2
, &base
);
2519 isakmp_rfc3948_print(netdissect_options
*ndo
,
2520 const u_char
*bp
, u_int length
,
2524 ep
= ndo
->ndo_snapend
;
2526 if(length
== 1 && bp
[0]==0xff) {
2527 ND_PRINT((ndo
, "isakmp-nat-keep-alive"));
2536 * see if this is an IKE packet
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
);
2544 /* must be an ESP packet */
2546 int nh
, enh
, padlen
;
2549 ND_PRINT((ndo
, "UDP-encap: "));
2551 advance
= esp_print(ndo
, bp
, length
, bp2
, &enh
, &padlen
);
2556 length
-= advance
+ padlen
;
2559 ip_print_inner(ndo
, bp
, length
, nh
, bp2
);
2564 ND_PRINT((ndo
,"[|isakmp]"));
2570 * c-style: whitesmith