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.5 1999-10-30 05:37:35 itojun Exp $ (LBL)";
38 #include <sys/param.h>
40 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <netinet/if_ether.h>
50 #include <netinet/in_systm.h>
51 #include <netinet/ip.h>
52 #include <netinet/ip_var.h>
53 #include <netinet/udp.h>
54 #include <netinet/udp_var.h>
55 #include <netinet/tcp.h>
58 #include <netinet/ip6.h>
65 #include "ipsec_doi.h"
67 #include "interface.h"
68 #include "addrtoname.h"
69 #include "extract.h" /* must come after interface.h */
71 #ifndef HAVE_SOCKADDR_STORAGE
72 #define sockaddr_storage sockaddr
75 static u_char
*isakmp_sa_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
76 u_int32_t
, u_int32_t
));
77 static u_char
*isakmp_p_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
78 u_int32_t
, u_int32_t
));
79 static u_char
*isakmp_t_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
));
81 static u_char
*isakmp_ke_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
82 u_int32_t
, u_int32_t
));
83 static u_char
*isakmp_id_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
84 u_int32_t
, u_int32_t
));
85 static u_char
*isakmp_hash_print
__P((struct isakmp_gen
*, u_char
*,
86 u_int32_t
, u_int32_t
, u_int32_t
));
87 static u_char
*isakmp_nonce_print
__P((struct isakmp_gen
*, u_char
*,
88 u_int32_t
, u_int32_t
, u_int32_t
));
89 static u_char
*isakmp_n_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
90 u_int32_t
, u_int32_t
));
91 static u_char
*isakmp_d_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
92 u_int32_t
, u_int32_t
));
93 static u_char
*isakmp_vid_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
94 u_int32_t
, u_int32_t
));
95 static u_char
*isakmp_sub0_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
96 u_int32_t
, u_int32_t
, u_int32_t
));
97 static u_char
*isakmp_sub_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
98 u_int32_t
, u_int32_t
, u_int32_t
));
99 static char *numstr
__P((int));
101 #define MAXINITIATORS 20
105 struct sockaddr_storage iaddr
;
106 struct sockaddr_storage raddr
;
107 } cookiecache
[MAXINITIATORS
];
110 static char *protoidstr
[] = {
111 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
115 static char *npstr
[] = {
116 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
117 "sig", "nonce", "n", "d", "vid"
121 static u_char
*(*npfunc
[]) __P((struct isakmp_gen
*, u_char
*, u_int32_t
,
122 u_int32_t
, u_int32_t
)) = {
140 static char *etypestr
[] = {
141 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
142 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
143 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
144 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
145 "oakley-quick", "oakley-newgroup",
148 #define STR_OR_ID(x, tab) \
149 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
150 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
151 #define NPSTR(x) STR_OR_ID(x, npstr)
152 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
155 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
156 ? npfunc[(x)] : NULL)
159 iszero(u_char
*p
, size_t l
)
168 /* find cookie from initiator cache */
170 cookie_find(cookie_t
*in
)
174 for (i
= 0; i
< MAXINITIATORS
; i
++) {
175 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
182 /* record initiator */
184 cookie_record(cookie_t
*in
, const u_char
*bp2
)
188 struct sockaddr_in
*sin
;
191 struct sockaddr_in6
*sin6
;
196 ninitiator
= (i
+ 1) % MAXINITIATORS
;
200 ip
= (struct ip
*)bp2
;
203 memset(&cookiecache
[ninitiator
].iaddr
, 0,
204 sizeof(cookiecache
[ninitiator
].iaddr
));
205 memset(&cookiecache
[ninitiator
].raddr
, 0,
206 sizeof(cookiecache
[ninitiator
].raddr
));
208 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
209 sin
->sin_len
= sizeof(struct sockaddr_in
);
210 sin
->sin_family
= AF_INET
;
211 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
212 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
213 sin
->sin_len
= sizeof(struct sockaddr_in
);
214 sin
->sin_family
= AF_INET
;
215 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
219 memset(&cookiecache
[ninitiator
].iaddr
, 0,
220 sizeof(cookiecache
[ninitiator
].iaddr
));
221 memset(&cookiecache
[ninitiator
].raddr
, 0,
222 sizeof(cookiecache
[ninitiator
].raddr
));
224 ip6
= (struct ip6_hdr
*)bp2
;
225 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
226 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
227 sin6
->sin6_family
= AF_INET6
;
228 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
229 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
230 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
231 sin6
->sin6_family
= AF_INET6
;
232 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
238 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
239 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
242 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
243 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
245 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
247 struct sockaddr_storage ss
;
250 struct sockaddr_in
*sin
;
253 struct sockaddr_in6
*sin6
;
257 memset(&ss
, 0, sizeof(ss
));
258 ip
= (struct ip
*)bp2
;
261 sin
= (struct sockaddr_in
*)&ss
;
262 sin
->sin_len
= sizeof(struct sockaddr_in
);
263 sin
->sin_family
= AF_INET
;
264 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
268 ip6
= (struct ip6_hdr
*)bp2
;
269 sin6
= (struct sockaddr_in6
*)&ss
;
270 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
271 sin6
->sin6_family
= AF_INET6
;
272 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
279 sa
= (struct sockaddr
*)&ss
;
281 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
283 #ifdef HAVE_SOCKADDR_SA_LEN
287 if (sa
->sa_family
== AF_INET6
)
288 salen
= sizeof(struct sockaddr_in6
);
290 salen
= sizeof(struct sockaddr
);
292 salen
= sizeof(struct sockaddr
);
295 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
298 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
300 #ifdef HAVE_SOCKADDR_SA_LEN
304 if (sa
->sa_family
== AF_INET6
)
305 salen
= sizeof(struct sockaddr_in6
);
307 salen
= sizeof(struct sockaddr
);
309 salen
= sizeof(struct sockaddr
);
312 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
319 rawprint(caddr_t loc
, size_t len
)
325 for (i
= 0; i
< len
; i
++)
326 printf("%02x", p
[i
] & 0xff);
332 char *value
[30]; /*XXX*/
336 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
346 totlen
= 4 + ntohs(q
[1]);
347 if (ep
< p
+ totlen
) {
353 t
= ntohs(q
[0]) & 0x7fff;
354 if (map
&& t
< nmap
&& map
[t
].type
)
355 printf("type=%s ", map
[t
].type
);
357 printf("type=#%d ", t
);
361 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
362 printf("%s", map
[t
].value
[v
]);
364 rawprint((caddr_t
)&q
[1], 2);
366 printf("len=%d value=", ntohs(q
[1]));
367 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
374 isakmp_attr_print(u_char
*p
, u_char
*ep
)
384 totlen
= 4 + ntohs(q
[1]);
385 if (ep
< p
+ totlen
) {
391 t
= ntohs(q
[0]) & 0x7fff;
392 printf("type=#%d ", t
);
396 rawprint((caddr_t
)&q
[1], 2);
398 printf("len=%d value=", ntohs(q
[1]));
399 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
406 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
407 u_int32_t doi0
, u_int32_t proto0
)
409 struct isakmp_pl_sa
*p
;
416 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
418 p
= (struct isakmp_pl_sa
*)ext
;
421 printf(" doi=%d", doi
);
422 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
423 return (u_char
*)(p
+ 1);
426 printf(" doi=ipsec");
427 q
= (u_int32_t
*)&p
->sit
;
428 printf(" situation=");
430 if (ntohl(*q
) & 0x01) {
434 if (ntohl(*q
) & 0x02) {
435 printf("%ssecrecy", t
? "+" : "");
438 if (ntohl(*q
) & 0x04)
439 printf("%sintegrity", t
? "+" : "");
443 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
445 ext
= (struct isakmp_gen
*)q
;
447 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
453 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
454 u_int32_t doi0
, u_int32_t proto0
)
456 struct isakmp_pl_p
*p
;
459 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
461 p
= (struct isakmp_pl_p
*)ext
;
462 printf(" #%d protoid=%s transform=%d",
463 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
466 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
469 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
471 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
477 static char *isakmp_p_map
[] = {
481 static char *ah_p_map
[] = {
482 NULL
, "md5", "sha", "1des",
485 static char *esp_p_map
[] = {
486 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
487 "blowfish", "3idea", "1des-iv32", "rc4", "null"
490 static char *ipcomp_p_map
[] = {
491 NULL
, "oui", "deflate", "lzs",
494 struct attrmap ipsec_t_map
[] = {
496 { "lifetype", 3, { NULL
, "sec", "kb", }, },
498 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
500 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
501 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
508 struct attrmap oakley_t_map
[] = {
510 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
512 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
513 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
514 "rsa enc revised", }, },
515 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
517 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
518 { "group prime", 0, },
519 { "group gen1", 0, },
520 { "group gen2", 0, },
521 { "group curve A", 0, },
522 { "group curve B", 0, },
523 { "lifetype", 3, { NULL
, "sec", "kb", }, },
524 { "lifeduration", 0, },
532 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
533 u_int32_t doi
, u_int32_t proto
)
535 struct isakmp_pl_t
*p
;
542 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
544 p
= (struct isakmp_pl_t
*)ext
;
548 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
550 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
553 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
555 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
558 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
560 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
563 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
565 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
575 printf(" #%d id=%s ", p
->t_no
, idstr
);
577 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
578 cp
= (u_char
*)(p
+ 1);
579 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
580 while (cp
< ep
&& cp
< ep2
) {
582 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
585 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
593 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
594 u_int32_t doi
, u_int32_t proto
)
596 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
598 printf(" key len=%d", ntohs(ext
->len
) - 4);
599 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
601 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
603 return (u_char
*)ext
+ ntohs(ext
->len
);
607 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
608 u_int32_t doi
, u_int32_t proto
)
610 #define USE_IPSECDOI_IN_PHASE1 1
611 struct isakmp_pl_id
*p
;
612 static char *idtypestr
[] = {
613 "IPv4", "IPv4net", "IPv6", "IPv6net",
615 static char *ipsecidtypestr
[] = {
616 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
617 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
623 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
625 p
= (struct isakmp_pl_id
*)ext
;
626 if (sizeof(*p
) < ext
->len
)
627 data
= (u_char
*)(p
+ 1);
630 len
= ntohs(ext
->len
) - sizeof(*p
);
633 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
636 #ifndef USE_IPSECDOI_IN_PHASE1
640 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
641 printf(" doi_data=%u",
642 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
645 #ifdef USE_IPSECDOI_IN_PHASE1
650 struct ipsecdoi_id
*p
;
653 p
= (struct ipsecdoi_id
*)ext
;
654 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
656 pe
= getprotobynumber(p
->proto_id
);
658 printf(" protoid=%s", pe
->p_name
);
660 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
662 printf(" port=%d", ntohs(p
->port
));
666 case IPSECDOI_ID_IPV4_ADDR
:
667 printf(" len=%d %s", len
, ipaddr_string(data
));
670 case IPSECDOI_ID_FQDN
:
671 case IPSECDOI_ID_USER_FQDN
:
674 printf(" len=%d ", len
);
675 for (i
= 0; i
< len
; i
++) {
676 if (isprint(data
[i
]))
677 printf("%c", data
[i
]);
679 printf("\\%03o", data
[i
]);
684 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
687 mask
= data
+ sizeof(struct in_addr
);
688 printf(" len=%d %s/%u.%u.%u.%u", len
,
690 mask
[0], mask
[1], mask
[2], mask
[3]);
695 case IPSECDOI_ID_IPV6_ADDR
:
696 printf(" len=%d %s", len
, ip6addr_string(data
));
699 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
702 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
704 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
705 ip6addr_string(data
),
706 mask
[0], mask
[1], mask
[2], mask
[3]);
711 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
712 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
713 ipaddr_string(data
+ sizeof(struct in_addr
)));
717 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
718 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
719 ip6addr_string(data
+ sizeof(struct in6_addr
)));
723 case IPSECDOI_ID_DER_ASN1_DN
:
724 case IPSECDOI_ID_DER_ASN1_GN
:
725 case IPSECDOI_ID_KEY_ID
:
733 printf(" len=%d", len
);
736 rawprint((caddr_t
)data
, len
);
739 return (u_char
*)ext
+ ntohs(ext
->len
);
743 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
744 u_int32_t doi
, u_int32_t proto
)
746 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
748 printf(" len=%d", ntohs(ext
->len
) - 4);
749 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
751 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
753 return (u_char
*)ext
+ ntohs(ext
->len
);
757 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
758 u_int32_t doi
, u_int32_t proto
)
760 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
762 printf(" n len=%d", ntohs(ext
->len
) - 4);
763 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
765 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
767 return (u_char
*)ext
+ ntohs(ext
->len
);
771 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
772 u_int32_t doi0
, u_int32_t proto0
)
774 struct isakmp_pl_n
*p
;
779 static char *notifystr
[] = {
780 NULL
, "INVALID-PAYLOAD-TYPE",
781 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
782 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
783 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
784 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
785 "INVALID-PROTOCOL-ID", "INVALID-SPI",
786 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
787 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
788 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
789 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
790 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
791 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
792 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
793 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
794 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
795 "UNEQUAL-PAYLOAD-LENGTHS",
797 static char *ipsecnotifystr
[] = {
798 "RESPONDER-LIFETIME", "REPLAY-STATUS",
801 /* NOTE: these macro must be called with x in proper range */
802 #define NOTIFYSTR(x) \
803 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
804 #define IPSECNOTIFYSTR(x) \
805 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
807 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
809 p
= (struct isakmp_pl_n
*)ext
;
813 printf(" doi=%d", doi
);
814 printf(" proto=%d", proto
);
815 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
818 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
820 return (u_char
*)(p
+ 1) + p
->spi_size
;
823 printf(" doi=ipsec");
824 printf(" proto=%s", PROTOIDSTR(proto
));
825 if (ntohs(p
->type
) < 8192)
826 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
827 else if (ntohs(p
->type
) < 16384)
828 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
829 else if (ntohs(p
->type
) < 24576)
830 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
831 else if (ntohs(p
->type
) < 40960)
832 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
834 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
837 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
840 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
841 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
845 switch (ntohs(p
->type
)) {
846 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
848 struct attrmap
*map
= oakley_t_map
;
849 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
850 while (cp
< ep
&& cp
< ep2
) {
851 cp
= isakmp_attrmap_print(cp
,
852 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
856 case IPSECDOI_NTYPE_REPLAY_STATUS
:
857 printf("replay detection %sabled",
858 (*(u_int32_t
*)cp
) ? "en" : "dis");
860 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
861 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
862 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
867 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
872 return (u_char
*)ext
+ ntohs(ext
->len
);
876 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
877 u_int32_t doi0
, u_int32_t proto0
)
879 struct isakmp_pl_d
*p
;
885 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
887 p
= (struct isakmp_pl_d
*)ext
;
891 printf(" doi=%u", doi
);
892 printf(" proto=%u", proto
);
894 printf(" doi=ipsec");
895 printf(" proto=%s", PROTOIDSTR(proto
));
897 printf(" spilen=%u", p
->spi_size
);
898 printf(" nspi=%u", ntohs(p
->num_spi
));
900 q
= (u_int8_t
*)(p
+ 1);
901 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
904 rawprint((caddr_t
)q
, p
->spi_size
);
911 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
912 u_int32_t doi
, u_int32_t proto
)
914 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
916 printf(" len=%d", ntohs(ext
->len
) - 4);
917 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
919 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
921 return (u_char
*)ext
+ ntohs(ext
->len
);
925 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
926 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
933 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
935 printf("%s", NPSTR(np
));
936 cp
+= ntohs(ext
->len
);
942 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
943 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
946 static int depth
= 0;
952 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
953 printf(" [|%s]", NPSTR(np
));
959 for (i
= 0; i
< depth
; i
++)
962 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
967 ext
= (struct isakmp_gen
*)cp
;
976 snprintf(buf
, sizeof(buf
), "#%d", x
);
981 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
989 base
= (struct isakmp
*)bp
;
990 ep
= (u_char
*)snapend
;
992 if ((struct isakmp
*)ep
< base
+ 1) {
999 printf(" %d.%d", base
->v_maj
, base
->v_min
);
1003 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1008 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1010 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1014 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1016 printf(" phase %d", phase
);
1018 printf(" phase %d/others", phase
);
1020 i
= cookie_find(&base
->i_ck
);
1022 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1023 /* the first packet */
1026 cookie_record(&base
->i_ck
, bp2
);
1030 if (bp2
&& cookie_isinitiator(i
, bp2
))
1032 else if (bp2
&& cookie_isresponder(i
, bp2
))
1038 printf(" %s", ETYPESTR(base
->etype
));
1040 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1041 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1046 struct isakmp_gen
*ext
;
1049 #define CHECKLEN(p, np) \
1050 if (ep < (u_char *)(p)) { \
1051 printf(" [|%s]", NPSTR(np)); \
1055 /* regardless of phase... */
1056 if (base
->flags
& ISAKMP_FLAG_E
) {
1058 * encrypted, nothing we can do right now.
1059 * we hope to decrypt the packet in the future...
1061 printf(" [|%s]", NPSTR(base
->np
));
1066 CHECKLEN(base
+ 1, base
->np
)
1069 ext
= (struct isakmp_gen
*)(base
+ 1);
1070 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1075 if (ntohl(base
->len
) != length
) {
1076 printf(" (len mismatch: isakmp %u/ip %d)",
1077 (u_int32_t
)ntohl(base
->len
), length
);