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.8 1999-11-21 09:36:54 fenner Exp $ (LBL)";
42 #include <sys/param.h>
44 #include <sys/socket.h>
52 #include <netinet/in.h>
53 #include <netinet/if_ether.h>
54 #include <netinet/in_systm.h>
55 #include <netinet/ip.h>
56 #include <netinet/ip_var.h>
57 #include <netinet/udp.h>
58 #include <netinet/udp_var.h>
59 #include <netinet/tcp.h>
62 #include <netinet/ip6.h>
69 #include "ipsec_doi.h"
71 #include "interface.h"
72 #include "addrtoname.h"
73 #include "extract.h" /* must come after interface.h */
75 #ifndef HAVE_SOCKADDR_STORAGE
76 #define sockaddr_storage sockaddr
79 static u_char
*isakmp_sa_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
));
81 static u_char
*isakmp_p_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
82 u_int32_t
, u_int32_t
));
83 static u_char
*isakmp_t_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
84 u_int32_t
, u_int32_t
));
85 static u_char
*isakmp_ke_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
86 u_int32_t
, u_int32_t
));
87 static u_char
*isakmp_id_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
88 u_int32_t
, u_int32_t
));
89 static u_char
*isakmp_hash_print
__P((struct isakmp_gen
*, u_char
*,
90 u_int32_t
, u_int32_t
, u_int32_t
));
91 static u_char
*isakmp_nonce_print
__P((struct isakmp_gen
*, u_char
*,
92 u_int32_t
, u_int32_t
, u_int32_t
));
93 static u_char
*isakmp_n_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
94 u_int32_t
, u_int32_t
));
95 static u_char
*isakmp_d_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
96 u_int32_t
, u_int32_t
));
97 static u_char
*isakmp_vid_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
98 u_int32_t
, u_int32_t
));
99 static u_char
*isakmp_sub0_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
100 u_int32_t
, u_int32_t
, u_int32_t
));
101 static u_char
*isakmp_sub_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
102 u_int32_t
, u_int32_t
, u_int32_t
));
103 static char *numstr
__P((int));
105 #define MAXINITIATORS 20
109 struct sockaddr_storage iaddr
;
110 struct sockaddr_storage raddr
;
111 } cookiecache
[MAXINITIATORS
];
114 static char *protoidstr
[] = {
115 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
119 static char *npstr
[] = {
120 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
121 "sig", "nonce", "n", "d", "vid"
125 static u_char
*(*npfunc
[]) __P((struct isakmp_gen
*, u_char
*, u_int32_t
,
126 u_int32_t
, u_int32_t
)) = {
144 static char *etypestr
[] = {
145 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
146 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
147 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
148 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
149 "oakley-quick", "oakley-newgroup",
152 #define STR_OR_ID(x, tab) \
153 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
154 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
155 #define NPSTR(x) STR_OR_ID(x, npstr)
156 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
159 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
160 ? npfunc[(x)] : NULL)
163 iszero(u_char
*p
, size_t l
)
172 /* find cookie from initiator cache */
174 cookie_find(cookie_t
*in
)
178 for (i
= 0; i
< MAXINITIATORS
; i
++) {
179 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
186 /* record initiator */
188 cookie_record(cookie_t
*in
, const u_char
*bp2
)
192 struct sockaddr_in
*sin
;
195 struct sockaddr_in6
*sin6
;
200 ninitiator
= (i
+ 1) % MAXINITIATORS
;
204 ip
= (struct ip
*)bp2
;
207 memset(&cookiecache
[ninitiator
].iaddr
, 0,
208 sizeof(cookiecache
[ninitiator
].iaddr
));
209 memset(&cookiecache
[ninitiator
].raddr
, 0,
210 sizeof(cookiecache
[ninitiator
].raddr
));
212 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
213 #ifdef HAVE_SOCKADDR_SA_LEN
214 sin
->sin_len
= sizeof(struct sockaddr_in
);
216 sin
->sin_family
= AF_INET
;
217 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
218 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
219 #ifdef HAVE_SOCKADDR_SA_LEN
220 sin
->sin_len
= sizeof(struct sockaddr_in
);
222 sin
->sin_family
= AF_INET
;
223 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
227 memset(&cookiecache
[ninitiator
].iaddr
, 0,
228 sizeof(cookiecache
[ninitiator
].iaddr
));
229 memset(&cookiecache
[ninitiator
].raddr
, 0,
230 sizeof(cookiecache
[ninitiator
].raddr
));
232 ip6
= (struct ip6_hdr
*)bp2
;
233 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
234 #ifdef HAVE_SOCKADDR_SA_LEN
235 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
237 sin6
->sin6_family
= AF_INET6
;
238 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
239 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
240 #ifdef HAVE_SOCKADDR_SA_LEN
241 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
243 sin6
->sin6_family
= AF_INET6
;
244 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
250 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
251 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
254 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
255 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
257 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
259 struct sockaddr_storage ss
;
262 struct sockaddr_in
*sin
;
265 struct sockaddr_in6
*sin6
;
269 memset(&ss
, 0, sizeof(ss
));
270 ip
= (struct ip
*)bp2
;
273 sin
= (struct sockaddr_in
*)&ss
;
274 #ifdef HAVE_SOCKADDR_SA_LEN
275 sin
->sin_len
= sizeof(struct sockaddr_in
);
277 sin
->sin_family
= AF_INET
;
278 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
282 ip6
= (struct ip6_hdr
*)bp2
;
283 sin6
= (struct sockaddr_in6
*)&ss
;
284 #ifdef HAVE_SOCKADDR_SA_LEN
285 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
287 sin6
->sin6_family
= AF_INET6
;
288 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
295 sa
= (struct sockaddr
*)&ss
;
297 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
299 #ifdef HAVE_SOCKADDR_SA_LEN
303 if (sa
->sa_family
== AF_INET6
)
304 salen
= sizeof(struct sockaddr_in6
);
306 salen
= sizeof(struct sockaddr
);
308 salen
= sizeof(struct sockaddr
);
311 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
314 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
316 #ifdef HAVE_SOCKADDR_SA_LEN
320 if (sa
->sa_family
== AF_INET6
)
321 salen
= sizeof(struct sockaddr_in6
);
323 salen
= sizeof(struct sockaddr
);
325 salen
= sizeof(struct sockaddr
);
328 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
335 rawprint(caddr_t loc
, size_t len
)
341 for (i
= 0; i
< len
; i
++)
342 printf("%02x", p
[i
] & 0xff);
348 char *value
[30]; /*XXX*/
352 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
362 totlen
= 4 + ntohs(q
[1]);
363 if (ep
< p
+ totlen
) {
369 t
= ntohs(q
[0]) & 0x7fff;
370 if (map
&& t
< nmap
&& map
[t
].type
)
371 printf("type=%s ", map
[t
].type
);
373 printf("type=#%d ", t
);
377 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
378 printf("%s", map
[t
].value
[v
]);
380 rawprint((caddr_t
)&q
[1], 2);
382 printf("len=%d value=", ntohs(q
[1]));
383 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
390 isakmp_attr_print(u_char
*p
, u_char
*ep
)
400 totlen
= 4 + ntohs(q
[1]);
401 if (ep
< p
+ totlen
) {
407 t
= ntohs(q
[0]) & 0x7fff;
408 printf("type=#%d ", t
);
412 rawprint((caddr_t
)&q
[1], 2);
414 printf("len=%d value=", ntohs(q
[1]));
415 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
422 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
423 u_int32_t doi0
, u_int32_t proto0
)
425 struct isakmp_pl_sa
*p
;
432 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
434 p
= (struct isakmp_pl_sa
*)ext
;
437 printf(" doi=%d", doi
);
438 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
439 return (u_char
*)(p
+ 1);
442 printf(" doi=ipsec");
443 q
= (u_int32_t
*)&p
->sit
;
444 printf(" situation=");
446 if (ntohl(*q
) & 0x01) {
450 if (ntohl(*q
) & 0x02) {
451 printf("%ssecrecy", t
? "+" : "");
454 if (ntohl(*q
) & 0x04)
455 printf("%sintegrity", t
? "+" : "");
459 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
461 ext
= (struct isakmp_gen
*)q
;
463 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
469 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
470 u_int32_t doi0
, u_int32_t proto0
)
472 struct isakmp_pl_p
*p
;
475 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
477 p
= (struct isakmp_pl_p
*)ext
;
478 printf(" #%d protoid=%s transform=%d",
479 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
482 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
485 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
487 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
493 static char *isakmp_p_map
[] = {
497 static char *ah_p_map
[] = {
498 NULL
, "md5", "sha", "1des",
501 static char *esp_p_map
[] = {
502 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
503 "blowfish", "3idea", "1des-iv32", "rc4", "null"
506 static char *ipcomp_p_map
[] = {
507 NULL
, "oui", "deflate", "lzs",
510 struct attrmap ipsec_t_map
[] = {
512 { "lifetype", 3, { NULL
, "sec", "kb", }, },
514 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
516 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
517 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
524 struct attrmap oakley_t_map
[] = {
526 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
528 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
529 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
530 "rsa enc revised", }, },
531 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
533 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
534 { "group prime", 0, },
535 { "group gen1", 0, },
536 { "group gen2", 0, },
537 { "group curve A", 0, },
538 { "group curve B", 0, },
539 { "lifetype", 3, { NULL
, "sec", "kb", }, },
540 { "lifeduration", 0, },
548 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
549 u_int32_t doi
, u_int32_t proto
)
551 struct isakmp_pl_t
*p
;
558 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
560 p
= (struct isakmp_pl_t
*)ext
;
564 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
566 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
569 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
571 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
574 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
576 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
579 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
581 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
591 printf(" #%d id=%s ", p
->t_no
, idstr
);
593 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
594 cp
= (u_char
*)(p
+ 1);
595 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
596 while (cp
< ep
&& cp
< ep2
) {
598 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
601 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
609 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
610 u_int32_t doi
, u_int32_t proto
)
612 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
614 printf(" key len=%d", ntohs(ext
->len
) - 4);
615 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
617 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
619 return (u_char
*)ext
+ ntohs(ext
->len
);
623 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
624 u_int32_t doi
, u_int32_t proto
)
626 #define USE_IPSECDOI_IN_PHASE1 1
627 struct isakmp_pl_id
*p
;
628 static char *idtypestr
[] = {
629 "IPv4", "IPv4net", "IPv6", "IPv6net",
631 static char *ipsecidtypestr
[] = {
632 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
633 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
639 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
641 p
= (struct isakmp_pl_id
*)ext
;
642 if (sizeof(*p
) < ext
->len
)
643 data
= (u_char
*)(p
+ 1);
646 len
= ntohs(ext
->len
) - sizeof(*p
);
649 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
652 #ifndef USE_IPSECDOI_IN_PHASE1
656 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
657 printf(" doi_data=%u",
658 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
661 #ifdef USE_IPSECDOI_IN_PHASE1
666 struct ipsecdoi_id
*p
;
669 p
= (struct ipsecdoi_id
*)ext
;
670 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
672 pe
= getprotobynumber(p
->proto_id
);
674 printf(" protoid=%s", pe
->p_name
);
676 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
678 printf(" port=%d", ntohs(p
->port
));
682 case IPSECDOI_ID_IPV4_ADDR
:
683 printf(" len=%d %s", len
, ipaddr_string(data
));
686 case IPSECDOI_ID_FQDN
:
687 case IPSECDOI_ID_USER_FQDN
:
690 printf(" len=%d ", len
);
691 for (i
= 0; i
< len
; i
++) {
692 if (isprint(data
[i
]))
693 printf("%c", data
[i
]);
695 printf("\\%03o", data
[i
]);
700 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
703 mask
= data
+ sizeof(struct in_addr
);
704 printf(" len=%d %s/%u.%u.%u.%u", len
,
706 mask
[0], mask
[1], mask
[2], mask
[3]);
711 case IPSECDOI_ID_IPV6_ADDR
:
712 printf(" len=%d %s", len
, ip6addr_string(data
));
715 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
718 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
720 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
721 ip6addr_string(data
),
722 mask
[0], mask
[1], mask
[2], mask
[3]);
727 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
728 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
729 ipaddr_string(data
+ sizeof(struct in_addr
)));
733 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
734 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
735 ip6addr_string(data
+ sizeof(struct in6_addr
)));
739 case IPSECDOI_ID_DER_ASN1_DN
:
740 case IPSECDOI_ID_DER_ASN1_GN
:
741 case IPSECDOI_ID_KEY_ID
:
749 printf(" len=%d", len
);
752 rawprint((caddr_t
)data
, len
);
755 return (u_char
*)ext
+ ntohs(ext
->len
);
759 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
760 u_int32_t doi
, u_int32_t proto
)
762 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
764 printf(" len=%d", ntohs(ext
->len
) - 4);
765 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
767 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
769 return (u_char
*)ext
+ ntohs(ext
->len
);
773 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
774 u_int32_t doi
, u_int32_t proto
)
776 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
778 printf(" n len=%d", ntohs(ext
->len
) - 4);
779 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
781 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
783 return (u_char
*)ext
+ ntohs(ext
->len
);
787 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
788 u_int32_t doi0
, u_int32_t proto0
)
790 struct isakmp_pl_n
*p
;
795 static char *notifystr
[] = {
796 NULL
, "INVALID-PAYLOAD-TYPE",
797 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
798 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
799 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
800 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
801 "INVALID-PROTOCOL-ID", "INVALID-SPI",
802 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
803 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
804 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
805 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
806 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
807 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
808 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
809 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
810 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
811 "UNEQUAL-PAYLOAD-LENGTHS",
813 static char *ipsecnotifystr
[] = {
814 "RESPONDER-LIFETIME", "REPLAY-STATUS",
817 /* NOTE: these macro must be called with x in proper range */
818 #define NOTIFYSTR(x) \
819 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
820 #define IPSECNOTIFYSTR(x) \
821 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
823 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
825 p
= (struct isakmp_pl_n
*)ext
;
829 printf(" doi=%d", doi
);
830 printf(" proto=%d", proto
);
831 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
834 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
836 return (u_char
*)(p
+ 1) + p
->spi_size
;
839 printf(" doi=ipsec");
840 printf(" proto=%s", PROTOIDSTR(proto
));
841 if (ntohs(p
->type
) < 8192)
842 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
843 else if (ntohs(p
->type
) < 16384)
844 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
845 else if (ntohs(p
->type
) < 24576)
846 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
847 else if (ntohs(p
->type
) < 40960)
848 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
850 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
853 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
856 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
857 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
861 switch (ntohs(p
->type
)) {
862 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
864 struct attrmap
*map
= oakley_t_map
;
865 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
866 while (cp
< ep
&& cp
< ep2
) {
867 cp
= isakmp_attrmap_print(cp
,
868 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
872 case IPSECDOI_NTYPE_REPLAY_STATUS
:
873 printf("replay detection %sabled",
874 (*(u_int32_t
*)cp
) ? "en" : "dis");
876 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
877 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
878 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
883 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
888 return (u_char
*)ext
+ ntohs(ext
->len
);
892 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
893 u_int32_t doi0
, u_int32_t proto0
)
895 struct isakmp_pl_d
*p
;
901 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
903 p
= (struct isakmp_pl_d
*)ext
;
907 printf(" doi=%u", doi
);
908 printf(" proto=%u", proto
);
910 printf(" doi=ipsec");
911 printf(" proto=%s", PROTOIDSTR(proto
));
913 printf(" spilen=%u", p
->spi_size
);
914 printf(" nspi=%u", ntohs(p
->num_spi
));
916 q
= (u_int8_t
*)(p
+ 1);
917 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
920 rawprint((caddr_t
)q
, p
->spi_size
);
927 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
928 u_int32_t doi
, u_int32_t proto
)
930 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
932 printf(" len=%d", ntohs(ext
->len
) - 4);
933 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
935 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
937 return (u_char
*)ext
+ ntohs(ext
->len
);
941 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
942 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
949 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
951 printf("%s", NPSTR(np
));
952 cp
+= ntohs(ext
->len
);
958 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
959 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
962 static int depth
= 0;
968 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
969 printf(" [|%s]", NPSTR(np
));
975 for (i
= 0; i
< depth
; i
++)
978 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
983 ext
= (struct isakmp_gen
*)cp
;
992 sprintf(buf
, "#%d", x
);
997 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1005 base
= (struct isakmp
*)bp
;
1006 ep
= (u_char
*)snapend
;
1008 if ((struct isakmp
*)ep
< base
+ 1) {
1009 printf("[|isakmp]");
1015 printf(" %d.%d", base
->v_maj
, base
->v_min
);
1019 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1024 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1026 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1030 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1032 printf(" phase %d", phase
);
1034 printf(" phase %d/others", phase
);
1036 i
= cookie_find(&base
->i_ck
);
1038 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1039 /* the first packet */
1042 cookie_record(&base
->i_ck
, bp2
);
1046 if (bp2
&& cookie_isinitiator(i
, bp2
))
1048 else if (bp2
&& cookie_isresponder(i
, bp2
))
1054 printf(" %s", ETYPESTR(base
->etype
));
1056 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1057 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1062 struct isakmp_gen
*ext
;
1065 #define CHECKLEN(p, np) \
1066 if (ep < (u_char *)(p)) { \
1067 printf(" [|%s]", NPSTR(np)); \
1071 /* regardless of phase... */
1072 if (base
->flags
& ISAKMP_FLAG_E
) {
1074 * encrypted, nothing we can do right now.
1075 * we hope to decrypt the packet in the future...
1077 printf(" [|%s]", NPSTR(base
->np
));
1082 CHECKLEN(base
+ 1, base
->np
)
1085 ext
= (struct isakmp_gen
*)(base
+ 1);
1086 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1091 if (ntohl(base
->len
) != length
) {
1092 printf(" (len mismatch: isakmp %u/ip %d)",
1093 (u_int32_t
)ntohl(base
->len
), length
);