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
[] =
33 "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.22 2000-10-03 02:54:59 itojun Exp $ (LBL)";
42 #include <sys/param.h>
44 #include <sys/socket.h>
49 #include <netinet/in.h>
52 #include <netinet/ip6.h>
59 #include "ipsec_doi.h"
61 #include "interface.h"
62 #include "addrtoname.h"
63 #include "extract.h" /* must come after interface.h */
67 #ifndef HAVE_SOCKADDR_STORAGE
68 #define sockaddr_storage sockaddr
71 static u_char
*isakmp_sa_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
72 u_int32_t
, u_int32_t
);
73 static u_char
*isakmp_p_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
74 u_int32_t
, u_int32_t
);
75 static u_char
*isakmp_t_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
76 u_int32_t
, u_int32_t
);
77 static u_char
*isakmp_ke_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
78 u_int32_t
, u_int32_t
);
79 static u_char
*isakmp_id_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
);
81 static u_char
*isakmp_cert_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
82 u_int32_t
, u_int32_t
);
83 static u_char
*isakmp_cr_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
84 u_int32_t
, u_int32_t
);
85 static u_char
*isakmp_sig_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
86 u_int32_t
, u_int32_t
);
87 static u_char
*isakmp_hash_print(struct isakmp_gen
*, u_char
*,
88 u_int32_t
, u_int32_t
, u_int32_t
);
89 static u_char
*isakmp_nonce_print(struct isakmp_gen
*, u_char
*,
90 u_int32_t
, u_int32_t
, u_int32_t
);
91 static u_char
*isakmp_n_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
92 u_int32_t
, u_int32_t
);
93 static u_char
*isakmp_d_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
94 u_int32_t
, u_int32_t
);
95 static u_char
*isakmp_vid_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
96 u_int32_t
, u_int32_t
);
97 static u_char
*isakmp_sub0_print(u_char
, struct isakmp_gen
*, u_char
*,
98 u_int32_t
, u_int32_t
, u_int32_t
);
99 static u_char
*isakmp_sub_print(u_char
, struct isakmp_gen
*, u_char
*,
100 u_int32_t
, u_int32_t
, u_int32_t
);
101 static char *numstr(int);
103 #define MAXINITIATORS 20
107 struct sockaddr_storage iaddr
;
108 struct sockaddr_storage raddr
;
109 } cookiecache
[MAXINITIATORS
];
112 static char *protoidstr
[] = {
113 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
117 static char *npstr
[] = {
118 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
119 "sig", "nonce", "n", "d", "vid"
123 static u_char
*(*npfunc
[])(struct isakmp_gen
*, u_char
*, u_int32_t
,
124 u_int32_t
, u_int32_t
) = {
142 static char *etypestr
[] = {
143 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
144 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
145 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
146 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
147 "oakley-quick", "oakley-newgroup",
150 #define STR_OR_ID(x, tab) \
151 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
152 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
153 #define NPSTR(x) STR_OR_ID(x, npstr)
154 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
157 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
158 ? npfunc[(x)] : NULL)
161 iszero(u_char
*p
, size_t l
)
170 /* find cookie from initiator cache */
172 cookie_find(cookie_t
*in
)
176 for (i
= 0; i
< MAXINITIATORS
; i
++) {
177 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
184 /* record initiator */
186 cookie_record(cookie_t
*in
, const u_char
*bp2
)
190 struct sockaddr_in
*sin
;
193 struct sockaddr_in6
*sin6
;
198 ninitiator
= (i
+ 1) % MAXINITIATORS
;
202 ip
= (struct ip
*)bp2
;
205 memset(&cookiecache
[ninitiator
].iaddr
, 0,
206 sizeof(cookiecache
[ninitiator
].iaddr
));
207 memset(&cookiecache
[ninitiator
].raddr
, 0,
208 sizeof(cookiecache
[ninitiator
].raddr
));
210 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
211 #ifdef HAVE_SOCKADDR_SA_LEN
212 sin
->sin_len
= sizeof(struct sockaddr_in
);
214 sin
->sin_family
= AF_INET
;
215 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
216 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
217 #ifdef HAVE_SOCKADDR_SA_LEN
218 sin
->sin_len
= sizeof(struct sockaddr_in
);
220 sin
->sin_family
= AF_INET
;
221 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
225 memset(&cookiecache
[ninitiator
].iaddr
, 0,
226 sizeof(cookiecache
[ninitiator
].iaddr
));
227 memset(&cookiecache
[ninitiator
].raddr
, 0,
228 sizeof(cookiecache
[ninitiator
].raddr
));
230 ip6
= (struct ip6_hdr
*)bp2
;
231 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
232 #ifdef HAVE_SOCKADDR_SA_LEN
233 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
235 sin6
->sin6_family
= AF_INET6
;
236 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
237 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
238 #ifdef HAVE_SOCKADDR_SA_LEN
239 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
241 sin6
->sin6_family
= AF_INET6
;
242 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
248 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
249 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
252 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
253 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
255 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
257 struct sockaddr_storage ss
;
260 struct sockaddr_in
*sin
;
263 struct sockaddr_in6
*sin6
;
267 memset(&ss
, 0, sizeof(ss
));
268 ip
= (struct ip
*)bp2
;
271 sin
= (struct sockaddr_in
*)&ss
;
272 #ifdef HAVE_SOCKADDR_SA_LEN
273 sin
->sin_len
= sizeof(struct sockaddr_in
);
275 sin
->sin_family
= AF_INET
;
276 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
280 ip6
= (struct ip6_hdr
*)bp2
;
281 sin6
= (struct sockaddr_in6
*)&ss
;
282 #ifdef HAVE_SOCKADDR_SA_LEN
283 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
285 sin6
->sin6_family
= AF_INET6
;
286 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
293 sa
= (struct sockaddr
*)&ss
;
295 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
297 #ifdef HAVE_SOCKADDR_SA_LEN
301 if (sa
->sa_family
== AF_INET6
)
302 salen
= sizeof(struct sockaddr_in6
);
304 salen
= sizeof(struct sockaddr
);
306 salen
= sizeof(struct sockaddr
);
309 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
312 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
314 #ifdef HAVE_SOCKADDR_SA_LEN
318 if (sa
->sa_family
== AF_INET6
)
319 salen
= sizeof(struct sockaddr_in6
);
321 salen
= sizeof(struct sockaddr
);
323 salen
= sizeof(struct sockaddr
);
326 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
333 rawprint(caddr_t loc
, size_t len
)
339 for (i
= 0; i
< len
; i
++)
340 printf("%02x", p
[i
] & 0xff);
346 char *value
[30]; /*XXX*/
350 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
360 totlen
= 4 + ntohs(q
[1]);
361 if (ep
< p
+ totlen
) {
367 t
= ntohs(q
[0]) & 0x7fff;
368 if (map
&& t
< nmap
&& map
[t
].type
)
369 printf("type=%s ", map
[t
].type
);
371 printf("type=#%d ", t
);
375 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
376 printf("%s", map
[t
].value
[v
]);
378 rawprint((caddr_t
)&q
[1], 2);
380 printf("len=%d value=", ntohs(q
[1]));
381 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
388 isakmp_attr_print(u_char
*p
, u_char
*ep
)
398 totlen
= 4 + ntohs(q
[1]);
399 if (ep
< p
+ totlen
) {
405 t
= ntohs(q
[0]) & 0x7fff;
406 printf("type=#%d ", t
);
410 rawprint((caddr_t
)&q
[1], 2);
412 printf("len=%d value=", ntohs(q
[1]));
413 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
420 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
421 u_int32_t doi0
, u_int32_t proto0
)
423 struct isakmp_pl_sa
*p
;
430 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
432 p
= (struct isakmp_pl_sa
*)ext
;
435 printf(" doi=%d", doi
);
436 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
437 return (u_char
*)(p
+ 1);
440 printf(" doi=ipsec");
441 q
= (u_int32_t
*)&p
->sit
;
442 printf(" situation=");
444 if (ntohl(*q
) & 0x01) {
448 if (ntohl(*q
) & 0x02) {
449 printf("%ssecrecy", t
? "+" : "");
452 if (ntohl(*q
) & 0x04)
453 printf("%sintegrity", t
? "+" : "");
457 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
459 ext
= (struct isakmp_gen
*)q
;
461 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
467 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
468 u_int32_t doi0
, u_int32_t proto0
)
470 struct isakmp_pl_p
*p
;
473 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
475 p
= (struct isakmp_pl_p
*)ext
;
476 printf(" #%d protoid=%s transform=%d",
477 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
480 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
483 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
485 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
491 static char *isakmp_p_map
[] = {
495 static char *ah_p_map
[] = {
496 NULL
, "(reserved)", "md5", "sha", "1des",
499 static char *esp_p_map
[] = {
500 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
501 "blowfish", "3idea", "1des-iv32", "rc4", "null"
504 static char *ipcomp_p_map
[] = {
505 NULL
, "oui", "deflate", "lzs",
508 struct attrmap ipsec_t_map
[] = {
510 { "lifetype", 3, { NULL
, "sec", "kb", }, },
512 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
514 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
515 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
522 struct attrmap oakley_t_map
[] = {
524 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
526 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
527 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
528 "rsa enc revised", }, },
529 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
531 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
532 { "group prime", 0, },
533 { "group gen1", 0, },
534 { "group gen2", 0, },
535 { "group curve A", 0, },
536 { "group curve B", 0, },
537 { "lifetype", 3, { NULL
, "sec", "kb", }, },
538 { "lifeduration", 0, },
546 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
547 u_int32_t doi
, u_int32_t proto
)
549 struct isakmp_pl_t
*p
;
556 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
558 p
= (struct isakmp_pl_t
*)ext
;
562 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
564 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
567 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
569 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
572 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
574 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
577 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
579 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
589 printf(" #%d id=%s ", p
->t_no
, idstr
);
591 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
592 cp
= (u_char
*)(p
+ 1);
593 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
594 while (cp
< ep
&& cp
< ep2
) {
596 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
599 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
607 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
608 u_int32_t doi
, u_int32_t proto
)
610 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
612 printf(" key len=%d", ntohs(ext
->len
) - 4);
613 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
615 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
617 return (u_char
*)ext
+ ntohs(ext
->len
);
621 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
622 u_int32_t doi
, u_int32_t proto
)
624 #define USE_IPSECDOI_IN_PHASE1 1
625 struct isakmp_pl_id
*p
;
626 static char *idtypestr
[] = {
627 "IPv4", "IPv4net", "IPv6", "IPv6net",
629 static char *ipsecidtypestr
[] = {
630 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
631 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
637 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
639 p
= (struct isakmp_pl_id
*)ext
;
640 if (sizeof(*p
) < ext
->len
)
641 data
= (u_char
*)(p
+ 1);
644 len
= ntohs(ext
->len
) - sizeof(*p
);
647 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
650 #ifndef USE_IPSECDOI_IN_PHASE1
654 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
655 printf(" doi_data=%u",
656 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
659 #ifdef USE_IPSECDOI_IN_PHASE1
664 struct ipsecdoi_id
*p
;
667 p
= (struct ipsecdoi_id
*)ext
;
668 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
671 pe
= getprotobynumber(p
->proto_id
);
673 printf(" protoid=%s", pe
->p_name
);
676 /* it DOES NOT mean IPPROTO_IP! */
677 printf(" protoid=%s", "0");
679 printf(" port=%d", ntohs(p
->port
));
683 case IPSECDOI_ID_IPV4_ADDR
:
684 printf(" len=%d %s", len
, ipaddr_string(data
));
687 case IPSECDOI_ID_FQDN
:
688 case IPSECDOI_ID_USER_FQDN
:
691 printf(" len=%d ", len
);
692 for (i
= 0; i
< len
; i
++) {
693 if (isprint(data
[i
]))
694 printf("%c", data
[i
]);
696 printf("\\%03o", data
[i
]);
701 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
704 mask
= data
+ sizeof(struct in_addr
);
705 printf(" len=%d %s/%u.%u.%u.%u", len
,
707 mask
[0], mask
[1], mask
[2], mask
[3]);
712 case IPSECDOI_ID_IPV6_ADDR
:
713 printf(" len=%d %s", len
, ip6addr_string(data
));
716 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
719 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
721 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
722 ip6addr_string(data
),
723 mask
[0], mask
[1], mask
[2], mask
[3]);
728 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
729 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
730 ipaddr_string(data
+ sizeof(struct in_addr
)));
734 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
735 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
736 ip6addr_string(data
+ sizeof(struct in6_addr
)));
740 case IPSECDOI_ID_DER_ASN1_DN
:
741 case IPSECDOI_ID_DER_ASN1_GN
:
742 case IPSECDOI_ID_KEY_ID
:
750 printf(" len=%d", len
);
753 rawprint((caddr_t
)data
, len
);
756 return (u_char
*)ext
+ ntohs(ext
->len
);
760 isakmp_cert_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
761 u_int32_t doi0
, u_int32_t proto0
)
763 struct isakmp_pl_cert
*p
;
764 static char *certstr
[] = {
765 "none", "pkcs7", "pgp", "dns",
766 "x509sign", "x509ke", "kerberos", "crl",
767 "arl", "spki", "x509attr",
770 printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
772 p
= (struct isakmp_pl_cert
*)ext
;
773 printf(" len=%d", ntohs(ext
->len
) - 4);
774 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
775 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
777 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
779 return (u_char
*)ext
+ ntohs(ext
->len
);
783 isakmp_cr_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
784 u_int32_t doi0
, u_int32_t proto0
)
786 struct isakmp_pl_cert
*p
;
787 static char *certstr
[] = {
788 "none", "pkcs7", "pgp", "dns",
789 "x509sign", "x509ke", "kerberos", "crl",
790 "arl", "spki", "x509attr",
793 printf("%s:", NPSTR(ISAKMP_NPTYPE_CR
));
795 p
= (struct isakmp_pl_cert
*)ext
;
796 printf(" len=%d", ntohs(ext
->len
) - 4);
797 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
798 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
800 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
802 return (u_char
*)ext
+ ntohs(ext
->len
);
806 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
807 u_int32_t doi
, u_int32_t proto
)
809 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
811 printf(" len=%d", ntohs(ext
->len
) - 4);
812 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
814 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
816 return (u_char
*)ext
+ ntohs(ext
->len
);
820 isakmp_sig_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
821 u_int32_t doi
, u_int32_t proto
)
823 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
825 printf(" len=%d", ntohs(ext
->len
) - 4);
826 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
828 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
830 return (u_char
*)ext
+ ntohs(ext
->len
);
834 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
835 u_int32_t doi
, u_int32_t proto
)
837 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
839 printf(" n len=%d", ntohs(ext
->len
) - 4);
840 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
842 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
844 return (u_char
*)ext
+ ntohs(ext
->len
);
848 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
849 u_int32_t doi0
, u_int32_t proto0
)
851 struct isakmp_pl_n
*p
;
856 static char *notifystr
[] = {
857 NULL
, "INVALID-PAYLOAD-TYPE",
858 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
859 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
860 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
861 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
862 "INVALID-PROTOCOL-ID", "INVALID-SPI",
863 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
864 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
865 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
866 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
867 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
868 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
869 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
870 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
871 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
872 "UNEQUAL-PAYLOAD-LENGTHS",
874 static char *ipsecnotifystr
[] = {
875 "RESPONDER-LIFETIME", "REPLAY-STATUS",
878 /* NOTE: these macro must be called with x in proper range */
879 #define NOTIFYSTR(x) \
880 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
881 #define IPSECNOTIFYSTR(x) \
882 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
884 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
886 p
= (struct isakmp_pl_n
*)ext
;
890 printf(" doi=%d", doi
);
891 printf(" proto=%d", proto
);
892 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
895 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
897 return (u_char
*)(p
+ 1) + p
->spi_size
;
900 printf(" doi=ipsec");
901 printf(" proto=%s", PROTOIDSTR(proto
));
902 if (ntohs(p
->type
) < 8192)
903 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
904 else if (ntohs(p
->type
) < 16384)
905 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
906 else if (ntohs(p
->type
) < 24576)
907 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
908 else if (ntohs(p
->type
) < 40960)
909 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
911 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
914 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
917 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
918 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
922 switch (ntohs(p
->type
)) {
923 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
925 struct attrmap
*map
= oakley_t_map
;
926 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
927 while (cp
< ep
&& cp
< ep2
) {
928 cp
= isakmp_attrmap_print(cp
,
929 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
933 case IPSECDOI_NTYPE_REPLAY_STATUS
:
934 printf("replay detection %sabled",
935 (*(u_int32_t
*)cp
) ? "en" : "dis");
937 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
938 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
939 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
944 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
949 return (u_char
*)ext
+ ntohs(ext
->len
);
953 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
954 u_int32_t doi0
, u_int32_t proto0
)
956 struct isakmp_pl_d
*p
;
962 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
964 p
= (struct isakmp_pl_d
*)ext
;
968 printf(" doi=%u", doi
);
969 printf(" proto=%u", proto
);
971 printf(" doi=ipsec");
972 printf(" proto=%s", PROTOIDSTR(proto
));
974 printf(" spilen=%u", p
->spi_size
);
975 printf(" nspi=%u", ntohs(p
->num_spi
));
977 q
= (u_int8_t
*)(p
+ 1);
978 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
981 rawprint((caddr_t
)q
, p
->spi_size
);
988 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
989 u_int32_t doi
, u_int32_t proto
)
991 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
993 printf(" len=%d", ntohs(ext
->len
) - 4);
994 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
996 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
998 return (u_char
*)ext
+ ntohs(ext
->len
);
1002 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1003 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1010 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
1012 printf("%s", NPSTR(np
));
1013 cp
+= ntohs(ext
->len
);
1019 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1020 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1023 static int depth
= 0;
1029 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
1030 printf(" [|%s]", NPSTR(np
));
1036 for (i
= 0; i
< depth
; i
++)
1039 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
1044 ext
= (struct isakmp_gen
*)cp
;
1052 static char buf
[20];
1053 snprintf(buf
, sizeof(buf
), "#%d", x
);
1058 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1060 struct isakmp
*base
;
1067 base
= (struct isakmp
*)bp
;
1068 ep
= (u_char
*)snapend
;
1070 if ((struct isakmp
*)ep
< base
+ 1) {
1071 printf("[|isakmp]");
1077 major
= (base
->vers
& ISAKMP_VERS_MAJOR
)
1078 >> ISAKMP_VERS_MAJOR_SHIFT
;
1079 minor
= (base
->vers
& ISAKMP_VERS_MINOR
)
1080 >> ISAKMP_VERS_MINOR_SHIFT
;
1081 printf(" %d.%d", major
, minor
);
1086 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1091 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1093 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1097 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1099 printf(" phase %d", phase
);
1101 printf(" phase %d/others", phase
);
1103 i
= cookie_find(&base
->i_ck
);
1105 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1106 /* the first packet */
1109 cookie_record(&base
->i_ck
, bp2
);
1113 if (bp2
&& cookie_isinitiator(i
, bp2
))
1115 else if (bp2
&& cookie_isresponder(i
, bp2
))
1121 printf(" %s", ETYPESTR(base
->etype
));
1123 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1124 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1129 struct isakmp_gen
*ext
;
1132 #define CHECKLEN(p, np) \
1133 if (ep < (u_char *)(p)) { \
1134 printf(" [|%s]", NPSTR(np)); \
1138 /* regardless of phase... */
1139 if (base
->flags
& ISAKMP_FLAG_E
) {
1141 * encrypted, nothing we can do right now.
1142 * we hope to decrypt the packet in the future...
1144 printf(" [|%s]", NPSTR(base
->np
));
1149 CHECKLEN(base
+ 1, base
->np
)
1152 ext
= (struct isakmp_gen
*)(base
+ 1);
1153 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1158 if (ntohl(base
->len
) != length
) {
1159 printf(" (len mismatch: isakmp %u/ip %d)",
1160 (u_int32_t
)ntohl(base
->len
), length
);