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.6 1999-10-30 07:36:37 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 #ifdef HAVE_SOCKADDR_SA_LEN
210 sin
->sin_len
= sizeof(struct sockaddr_in
);
212 sin
->sin_family
= AF_INET
;
213 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
214 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
215 #ifdef HAVE_SOCKADDR_SA_LEN
216 sin
->sin_len
= sizeof(struct sockaddr_in
);
218 sin
->sin_family
= AF_INET
;
219 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
223 memset(&cookiecache
[ninitiator
].iaddr
, 0,
224 sizeof(cookiecache
[ninitiator
].iaddr
));
225 memset(&cookiecache
[ninitiator
].raddr
, 0,
226 sizeof(cookiecache
[ninitiator
].raddr
));
228 ip6
= (struct ip6_hdr
*)bp2
;
229 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
230 #ifdef HAVE_SOCKADDR_SA_LEN
231 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
233 sin6
->sin6_family
= AF_INET6
;
234 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
235 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
236 #ifdef HAVE_SOCKADDR_SA_LEN
237 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
239 sin6
->sin6_family
= AF_INET6
;
240 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
246 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
247 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
250 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
251 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
253 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
255 struct sockaddr_storage ss
;
258 struct sockaddr_in
*sin
;
261 struct sockaddr_in6
*sin6
;
265 memset(&ss
, 0, sizeof(ss
));
266 ip
= (struct ip
*)bp2
;
269 sin
= (struct sockaddr_in
*)&ss
;
270 #ifdef HAVE_SOCKADDR_SA_LEN
271 sin
->sin_len
= sizeof(struct sockaddr_in
);
273 sin
->sin_family
= AF_INET
;
274 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
278 ip6
= (struct ip6_hdr
*)bp2
;
279 sin6
= (struct sockaddr_in6
*)&ss
;
280 #ifdef HAVE_SOCKADDR_SA_LEN
281 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
283 sin6
->sin6_family
= AF_INET6
;
284 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
291 sa
= (struct sockaddr
*)&ss
;
293 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
295 #ifdef HAVE_SOCKADDR_SA_LEN
299 if (sa
->sa_family
== AF_INET6
)
300 salen
= sizeof(struct sockaddr_in6
);
302 salen
= sizeof(struct sockaddr
);
304 salen
= sizeof(struct sockaddr
);
307 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
310 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
312 #ifdef HAVE_SOCKADDR_SA_LEN
316 if (sa
->sa_family
== AF_INET6
)
317 salen
= sizeof(struct sockaddr_in6
);
319 salen
= sizeof(struct sockaddr
);
321 salen
= sizeof(struct sockaddr
);
324 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
331 rawprint(caddr_t loc
, size_t len
)
337 for (i
= 0; i
< len
; i
++)
338 printf("%02x", p
[i
] & 0xff);
344 char *value
[30]; /*XXX*/
348 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
358 totlen
= 4 + ntohs(q
[1]);
359 if (ep
< p
+ totlen
) {
365 t
= ntohs(q
[0]) & 0x7fff;
366 if (map
&& t
< nmap
&& map
[t
].type
)
367 printf("type=%s ", map
[t
].type
);
369 printf("type=#%d ", t
);
373 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
374 printf("%s", map
[t
].value
[v
]);
376 rawprint((caddr_t
)&q
[1], 2);
378 printf("len=%d value=", ntohs(q
[1]));
379 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
386 isakmp_attr_print(u_char
*p
, u_char
*ep
)
396 totlen
= 4 + ntohs(q
[1]);
397 if (ep
< p
+ totlen
) {
403 t
= ntohs(q
[0]) & 0x7fff;
404 printf("type=#%d ", t
);
408 rawprint((caddr_t
)&q
[1], 2);
410 printf("len=%d value=", ntohs(q
[1]));
411 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
418 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
419 u_int32_t doi0
, u_int32_t proto0
)
421 struct isakmp_pl_sa
*p
;
428 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
430 p
= (struct isakmp_pl_sa
*)ext
;
433 printf(" doi=%d", doi
);
434 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
435 return (u_char
*)(p
+ 1);
438 printf(" doi=ipsec");
439 q
= (u_int32_t
*)&p
->sit
;
440 printf(" situation=");
442 if (ntohl(*q
) & 0x01) {
446 if (ntohl(*q
) & 0x02) {
447 printf("%ssecrecy", t
? "+" : "");
450 if (ntohl(*q
) & 0x04)
451 printf("%sintegrity", t
? "+" : "");
455 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
457 ext
= (struct isakmp_gen
*)q
;
459 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
465 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
466 u_int32_t doi0
, u_int32_t proto0
)
468 struct isakmp_pl_p
*p
;
471 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
473 p
= (struct isakmp_pl_p
*)ext
;
474 printf(" #%d protoid=%s transform=%d",
475 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
478 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
481 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
483 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
489 static char *isakmp_p_map
[] = {
493 static char *ah_p_map
[] = {
494 NULL
, "md5", "sha", "1des",
497 static char *esp_p_map
[] = {
498 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
499 "blowfish", "3idea", "1des-iv32", "rc4", "null"
502 static char *ipcomp_p_map
[] = {
503 NULL
, "oui", "deflate", "lzs",
506 struct attrmap ipsec_t_map
[] = {
508 { "lifetype", 3, { NULL
, "sec", "kb", }, },
510 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
512 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
513 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
520 struct attrmap oakley_t_map
[] = {
522 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
524 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
525 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
526 "rsa enc revised", }, },
527 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
529 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
530 { "group prime", 0, },
531 { "group gen1", 0, },
532 { "group gen2", 0, },
533 { "group curve A", 0, },
534 { "group curve B", 0, },
535 { "lifetype", 3, { NULL
, "sec", "kb", }, },
536 { "lifeduration", 0, },
544 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
545 u_int32_t doi
, u_int32_t proto
)
547 struct isakmp_pl_t
*p
;
554 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
556 p
= (struct isakmp_pl_t
*)ext
;
560 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
562 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
565 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
567 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
570 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
572 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
575 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
577 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
587 printf(" #%d id=%s ", p
->t_no
, idstr
);
589 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
590 cp
= (u_char
*)(p
+ 1);
591 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
592 while (cp
< ep
&& cp
< ep2
) {
594 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
597 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
605 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
606 u_int32_t doi
, u_int32_t proto
)
608 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
610 printf(" key len=%d", ntohs(ext
->len
) - 4);
611 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
613 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
615 return (u_char
*)ext
+ ntohs(ext
->len
);
619 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
620 u_int32_t doi
, u_int32_t proto
)
622 #define USE_IPSECDOI_IN_PHASE1 1
623 struct isakmp_pl_id
*p
;
624 static char *idtypestr
[] = {
625 "IPv4", "IPv4net", "IPv6", "IPv6net",
627 static char *ipsecidtypestr
[] = {
628 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
629 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
635 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
637 p
= (struct isakmp_pl_id
*)ext
;
638 if (sizeof(*p
) < ext
->len
)
639 data
= (u_char
*)(p
+ 1);
642 len
= ntohs(ext
->len
) - sizeof(*p
);
645 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
648 #ifndef USE_IPSECDOI_IN_PHASE1
652 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
653 printf(" doi_data=%u",
654 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
657 #ifdef USE_IPSECDOI_IN_PHASE1
662 struct ipsecdoi_id
*p
;
665 p
= (struct ipsecdoi_id
*)ext
;
666 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
668 pe
= getprotobynumber(p
->proto_id
);
670 printf(" protoid=%s", pe
->p_name
);
672 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
674 printf(" port=%d", ntohs(p
->port
));
678 case IPSECDOI_ID_IPV4_ADDR
:
679 printf(" len=%d %s", len
, ipaddr_string(data
));
682 case IPSECDOI_ID_FQDN
:
683 case IPSECDOI_ID_USER_FQDN
:
686 printf(" len=%d ", len
);
687 for (i
= 0; i
< len
; i
++) {
688 if (isprint(data
[i
]))
689 printf("%c", data
[i
]);
691 printf("\\%03o", data
[i
]);
696 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
699 mask
= data
+ sizeof(struct in_addr
);
700 printf(" len=%d %s/%u.%u.%u.%u", len
,
702 mask
[0], mask
[1], mask
[2], mask
[3]);
707 case IPSECDOI_ID_IPV6_ADDR
:
708 printf(" len=%d %s", len
, ip6addr_string(data
));
711 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
714 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
716 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
717 ip6addr_string(data
),
718 mask
[0], mask
[1], mask
[2], mask
[3]);
723 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
724 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
725 ipaddr_string(data
+ sizeof(struct in_addr
)));
729 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
730 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
731 ip6addr_string(data
+ sizeof(struct in6_addr
)));
735 case IPSECDOI_ID_DER_ASN1_DN
:
736 case IPSECDOI_ID_DER_ASN1_GN
:
737 case IPSECDOI_ID_KEY_ID
:
745 printf(" len=%d", len
);
748 rawprint((caddr_t
)data
, len
);
751 return (u_char
*)ext
+ ntohs(ext
->len
);
755 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
756 u_int32_t doi
, u_int32_t proto
)
758 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
760 printf(" len=%d", ntohs(ext
->len
) - 4);
761 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
763 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
765 return (u_char
*)ext
+ ntohs(ext
->len
);
769 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
770 u_int32_t doi
, u_int32_t proto
)
772 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
774 printf(" n len=%d", ntohs(ext
->len
) - 4);
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_n_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_n
*p
;
791 static char *notifystr
[] = {
792 NULL
, "INVALID-PAYLOAD-TYPE",
793 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
794 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
795 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
796 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
797 "INVALID-PROTOCOL-ID", "INVALID-SPI",
798 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
799 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
800 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
801 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
802 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
803 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
804 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
805 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
806 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
807 "UNEQUAL-PAYLOAD-LENGTHS",
809 static char *ipsecnotifystr
[] = {
810 "RESPONDER-LIFETIME", "REPLAY-STATUS",
813 /* NOTE: these macro must be called with x in proper range */
814 #define NOTIFYSTR(x) \
815 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
816 #define IPSECNOTIFYSTR(x) \
817 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
819 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
821 p
= (struct isakmp_pl_n
*)ext
;
825 printf(" doi=%d", doi
);
826 printf(" proto=%d", proto
);
827 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
830 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
832 return (u_char
*)(p
+ 1) + p
->spi_size
;
835 printf(" doi=ipsec");
836 printf(" proto=%s", PROTOIDSTR(proto
));
837 if (ntohs(p
->type
) < 8192)
838 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
839 else if (ntohs(p
->type
) < 16384)
840 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
841 else if (ntohs(p
->type
) < 24576)
842 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
843 else if (ntohs(p
->type
) < 40960)
844 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
846 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
849 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
852 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
853 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
857 switch (ntohs(p
->type
)) {
858 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
860 struct attrmap
*map
= oakley_t_map
;
861 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
862 while (cp
< ep
&& cp
< ep2
) {
863 cp
= isakmp_attrmap_print(cp
,
864 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
868 case IPSECDOI_NTYPE_REPLAY_STATUS
:
869 printf("replay detection %sabled",
870 (*(u_int32_t
*)cp
) ? "en" : "dis");
872 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
873 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
874 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
879 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
884 return (u_char
*)ext
+ ntohs(ext
->len
);
888 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
889 u_int32_t doi0
, u_int32_t proto0
)
891 struct isakmp_pl_d
*p
;
897 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
899 p
= (struct isakmp_pl_d
*)ext
;
903 printf(" doi=%u", doi
);
904 printf(" proto=%u", proto
);
906 printf(" doi=ipsec");
907 printf(" proto=%s", PROTOIDSTR(proto
));
909 printf(" spilen=%u", p
->spi_size
);
910 printf(" nspi=%u", ntohs(p
->num_spi
));
912 q
= (u_int8_t
*)(p
+ 1);
913 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
916 rawprint((caddr_t
)q
, p
->spi_size
);
923 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
924 u_int32_t doi
, u_int32_t proto
)
926 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
928 printf(" len=%d", ntohs(ext
->len
) - 4);
929 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
931 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
933 return (u_char
*)ext
+ ntohs(ext
->len
);
937 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
938 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
945 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
947 printf("%s", NPSTR(np
));
948 cp
+= ntohs(ext
->len
);
954 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
955 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
958 static int depth
= 0;
964 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
965 printf(" [|%s]", NPSTR(np
));
971 for (i
= 0; i
< depth
; i
++)
974 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
979 ext
= (struct isakmp_gen
*)cp
;
988 snprintf(buf
, sizeof(buf
), "#%d", x
);
993 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1001 base
= (struct isakmp
*)bp
;
1002 ep
= (u_char
*)snapend
;
1004 if ((struct isakmp
*)ep
< base
+ 1) {
1005 printf("[|isakmp]");
1011 printf(" %d.%d", base
->v_maj
, base
->v_min
);
1015 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1020 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1022 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1026 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1028 printf(" phase %d", phase
);
1030 printf(" phase %d/others", phase
);
1032 i
= cookie_find(&base
->i_ck
);
1034 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1035 /* the first packet */
1038 cookie_record(&base
->i_ck
, bp2
);
1042 if (bp2
&& cookie_isinitiator(i
, bp2
))
1044 else if (bp2
&& cookie_isresponder(i
, bp2
))
1050 printf(" %s", ETYPESTR(base
->etype
));
1052 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1053 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1058 struct isakmp_gen
*ext
;
1061 #define CHECKLEN(p, np) \
1062 if (ep < (u_char *)(p)) { \
1063 printf(" [|%s]", NPSTR(np)); \
1067 /* regardless of phase... */
1068 if (base
->flags
& ISAKMP_FLAG_E
) {
1070 * encrypted, nothing we can do right now.
1071 * we hope to decrypt the packet in the future...
1073 printf(" [|%s]", NPSTR(base
->np
));
1078 CHECKLEN(base
+ 1, base
->np
)
1081 ext
= (struct isakmp_gen
*)(base
+ 1);
1082 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1087 if (ntohl(base
->len
) != length
) {
1088 printf(" (len mismatch: isakmp %u/ip %d)",
1089 (u_int32_t
)ntohl(base
->len
), length
);