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.4 1999-10-30 05:30:20 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
;
256 memset(&ss
, 0, sizeof(ss
));
257 ip
= (struct ip
*)bp2
;
260 sin
= (struct sockaddr_in
*)&ss
;
261 sin
->sin_len
= sizeof(struct sockaddr_in
);
262 sin
->sin_family
= AF_INET
;
263 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
267 ip6
= (struct ip6_hdr
*)bp2
;
268 sin6
= (struct sockaddr_in6
*)&ss
;
269 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
270 sin6
->sin6_family
= AF_INET6
;
271 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
278 sa
= (struct sockaddr
*)&ss
;
280 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
282 if (sa
->sa_len
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_len
)
284 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, sa
->sa_len
) == 0)
287 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
289 if (sa
->sa_len
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_len
)
291 if (memcmp(&ss
, &cookiecache
[i
].raddr
, sa
->sa_len
) == 0)
298 rawprint(caddr_t loc
, size_t len
)
304 for (i
= 0; i
< len
; i
++)
305 printf("%02x", p
[i
] & 0xff);
311 char *value
[30]; /*XXX*/
315 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
325 totlen
= 4 + ntohs(q
[1]);
326 if (ep
< p
+ totlen
) {
332 t
= ntohs(q
[0]) & 0x7fff;
333 if (map
&& t
< nmap
&& map
[t
].type
)
334 printf("type=%s ", map
[t
].type
);
336 printf("type=#%d ", t
);
340 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
341 printf("%s", map
[t
].value
[v
]);
343 rawprint((caddr_t
)&q
[1], 2);
345 printf("len=%d value=", ntohs(q
[1]));
346 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
353 isakmp_attr_print(u_char
*p
, u_char
*ep
)
363 totlen
= 4 + ntohs(q
[1]);
364 if (ep
< p
+ totlen
) {
370 t
= ntohs(q
[0]) & 0x7fff;
371 printf("type=#%d ", t
);
375 rawprint((caddr_t
)&q
[1], 2);
377 printf("len=%d value=", ntohs(q
[1]));
378 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
385 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
386 u_int32_t doi0
, u_int32_t proto0
)
388 struct isakmp_pl_sa
*p
;
395 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
397 p
= (struct isakmp_pl_sa
*)ext
;
400 printf(" doi=%d", doi
);
401 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
402 return (u_char
*)(p
+ 1);
405 printf(" doi=ipsec");
406 q
= (u_int32_t
*)&p
->sit
;
407 printf(" situation=");
409 if (ntohl(*q
) & 0x01) {
413 if (ntohl(*q
) & 0x02) {
414 printf("%ssecrecy", t
? "+" : "");
417 if (ntohl(*q
) & 0x04)
418 printf("%sintegrity", t
? "+" : "");
422 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
424 ext
= (struct isakmp_gen
*)q
;
426 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
432 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
433 u_int32_t doi0
, u_int32_t proto0
)
435 struct isakmp_pl_p
*p
;
438 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
440 p
= (struct isakmp_pl_p
*)ext
;
441 printf(" #%d protoid=%s transform=%d",
442 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
445 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
448 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
450 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
456 static char *isakmp_p_map
[] = {
460 static char *ah_p_map
[] = {
461 NULL
, "md5", "sha", "1des",
464 static char *esp_p_map
[] = {
465 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
466 "blowfish", "3idea", "1des-iv32", "rc4", "null"
469 static char *ipcomp_p_map
[] = {
470 NULL
, "oui", "deflate", "lzs",
473 struct attrmap ipsec_t_map
[] = {
475 { "lifetype", 3, { NULL
, "sec", "kb", }, },
477 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
479 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
480 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
487 struct attrmap oakley_t_map
[] = {
489 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
491 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
492 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
493 "rsa enc revised", }, },
494 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
496 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
497 { "group prime", 0, },
498 { "group gen1", 0, },
499 { "group gen2", 0, },
500 { "group curve A", 0, },
501 { "group curve B", 0, },
502 { "lifetype", 3, { NULL
, "sec", "kb", }, },
503 { "lifeduration", 0, },
511 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
512 u_int32_t doi
, u_int32_t proto
)
514 struct isakmp_pl_t
*p
;
521 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
523 p
= (struct isakmp_pl_t
*)ext
;
527 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
529 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
532 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
534 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
537 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
539 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
542 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
544 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
554 printf(" #%d id=%s ", p
->t_no
, idstr
);
556 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
557 cp
= (u_char
*)(p
+ 1);
558 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
559 while (cp
< ep
&& cp
< ep2
) {
561 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
564 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
572 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
573 u_int32_t doi
, u_int32_t proto
)
575 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
577 printf(" key len=%d", ntohs(ext
->len
) - 4);
578 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
580 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
582 return (u_char
*)ext
+ ntohs(ext
->len
);
586 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
587 u_int32_t doi
, u_int32_t proto
)
589 #define USE_IPSECDOI_IN_PHASE1 1
590 struct isakmp_pl_id
*p
;
591 static char *idtypestr
[] = {
592 "IPv4", "IPv4net", "IPv6", "IPv6net",
594 static char *ipsecidtypestr
[] = {
595 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
596 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
602 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
604 p
= (struct isakmp_pl_id
*)ext
;
605 if (sizeof(*p
) < ext
->len
)
606 data
= (u_char
*)(p
+ 1);
609 len
= ntohs(ext
->len
) - sizeof(*p
);
612 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
615 #ifndef USE_IPSECDOI_IN_PHASE1
619 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
620 printf(" doi_data=%u",
621 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
624 #ifdef USE_IPSECDOI_IN_PHASE1
629 struct ipsecdoi_id
*p
;
632 p
= (struct ipsecdoi_id
*)ext
;
633 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
635 pe
= getprotobynumber(p
->proto_id
);
637 printf(" protoid=%s", pe
->p_name
);
639 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
641 printf(" port=%d", ntohs(p
->port
));
645 case IPSECDOI_ID_IPV4_ADDR
:
646 printf(" len=%d %s", len
, ipaddr_string(data
));
649 case IPSECDOI_ID_FQDN
:
650 case IPSECDOI_ID_USER_FQDN
:
653 printf(" len=%d ", len
);
654 for (i
= 0; i
< len
; i
++) {
655 if (isprint(data
[i
]))
656 printf("%c", data
[i
]);
658 printf("\\%03o", data
[i
]);
663 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
666 mask
= data
+ sizeof(struct in_addr
);
667 printf(" len=%d %s/%u.%u.%u.%u", len
,
669 mask
[0], mask
[1], mask
[2], mask
[3]);
674 case IPSECDOI_ID_IPV6_ADDR
:
675 printf(" len=%d %s", len
, ip6addr_string(data
));
678 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
681 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
683 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
684 ip6addr_string(data
),
685 mask
[0], mask
[1], mask
[2], mask
[3]);
690 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
691 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
692 ipaddr_string(data
+ sizeof(struct in_addr
)));
696 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
697 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
698 ip6addr_string(data
+ sizeof(struct in6_addr
)));
702 case IPSECDOI_ID_DER_ASN1_DN
:
703 case IPSECDOI_ID_DER_ASN1_GN
:
704 case IPSECDOI_ID_KEY_ID
:
712 printf(" len=%d", len
);
715 rawprint((caddr_t
)data
, len
);
718 return (u_char
*)ext
+ ntohs(ext
->len
);
722 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
723 u_int32_t doi
, u_int32_t proto
)
725 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
727 printf(" len=%d", ntohs(ext
->len
) - 4);
728 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
730 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
732 return (u_char
*)ext
+ ntohs(ext
->len
);
736 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
737 u_int32_t doi
, u_int32_t proto
)
739 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
741 printf(" n len=%d", ntohs(ext
->len
) - 4);
742 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
744 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
746 return (u_char
*)ext
+ ntohs(ext
->len
);
750 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
751 u_int32_t doi0
, u_int32_t proto0
)
753 struct isakmp_pl_n
*p
;
758 static char *notifystr
[] = {
759 NULL
, "INVALID-PAYLOAD-TYPE",
760 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
761 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
762 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
763 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
764 "INVALID-PROTOCOL-ID", "INVALID-SPI",
765 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
766 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
767 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
768 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
769 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
770 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
771 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
772 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
773 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
774 "UNEQUAL-PAYLOAD-LENGTHS",
776 static char *ipsecnotifystr
[] = {
777 "RESPONDER-LIFETIME", "REPLAY-STATUS",
780 /* NOTE: these macro must be called with x in proper range */
781 #define NOTIFYSTR(x) \
782 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
783 #define IPSECNOTIFYSTR(x) \
784 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
786 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
788 p
= (struct isakmp_pl_n
*)ext
;
792 printf(" doi=%d", doi
);
793 printf(" proto=%d", proto
);
794 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
797 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
799 return (u_char
*)(p
+ 1) + p
->spi_size
;
802 printf(" doi=ipsec");
803 printf(" proto=%s", PROTOIDSTR(proto
));
804 if (ntohs(p
->type
) < 8192)
805 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
806 else if (ntohs(p
->type
) < 16384)
807 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
808 else if (ntohs(p
->type
) < 24576)
809 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
810 else if (ntohs(p
->type
) < 40960)
811 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
813 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
816 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
819 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
820 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
824 switch (ntohs(p
->type
)) {
825 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
827 struct attrmap
*map
= oakley_t_map
;
828 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
829 while (cp
< ep
&& cp
< ep2
) {
830 cp
= isakmp_attrmap_print(cp
,
831 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
835 case IPSECDOI_NTYPE_REPLAY_STATUS
:
836 printf("replay detection %sabled",
837 (*(u_int32_t
*)cp
) ? "en" : "dis");
839 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
840 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
841 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
846 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
851 return (u_char
*)ext
+ ntohs(ext
->len
);
855 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
856 u_int32_t doi0
, u_int32_t proto0
)
858 struct isakmp_pl_d
*p
;
864 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
866 p
= (struct isakmp_pl_d
*)ext
;
870 printf(" doi=%u", doi
);
871 printf(" proto=%u", proto
);
873 printf(" doi=ipsec");
874 printf(" proto=%s", PROTOIDSTR(proto
));
876 printf(" spilen=%u", p
->spi_size
);
877 printf(" nspi=%u", ntohs(p
->num_spi
));
879 q
= (u_int8_t
*)(p
+ 1);
880 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
883 rawprint((caddr_t
)q
, p
->spi_size
);
890 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
891 u_int32_t doi
, u_int32_t proto
)
893 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
895 printf(" len=%d", ntohs(ext
->len
) - 4);
896 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
898 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
900 return (u_char
*)ext
+ ntohs(ext
->len
);
904 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
905 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
912 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
914 printf("%s", NPSTR(np
));
915 cp
+= ntohs(ext
->len
);
921 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
922 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
925 static int depth
= 0;
931 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
932 printf(" [|%s]", NPSTR(np
));
938 for (i
= 0; i
< depth
; i
++)
941 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
946 ext
= (struct isakmp_gen
*)cp
;
955 snprintf(buf
, sizeof(buf
), "#%d", x
);
960 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
968 base
= (struct isakmp
*)bp
;
969 ep
= (u_char
*)snapend
;
971 if ((struct isakmp
*)ep
< base
+ 1) {
978 printf(" %d.%d", base
->v_maj
, base
->v_min
);
982 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
987 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
989 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
993 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
995 printf(" phase %d", phase
);
997 printf(" phase %d/others", phase
);
999 i
= cookie_find(&base
->i_ck
);
1001 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1002 /* the first packet */
1005 cookie_record(&base
->i_ck
, bp2
);
1009 if (bp2
&& cookie_isinitiator(i
, bp2
))
1011 else if (bp2
&& cookie_isresponder(i
, bp2
))
1017 printf(" %s", ETYPESTR(base
->etype
));
1019 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1020 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1025 struct isakmp_gen
*ext
;
1028 #define CHECKLEN(p, np) \
1029 if (ep < (u_char *)(p)) { \
1030 printf(" [|%s]", NPSTR(np)); \
1034 /* regardless of phase... */
1035 if (base
->flags
& ISAKMP_FLAG_E
) {
1037 * encrypted, nothing we can do right now.
1038 * we hope to decrypt the packet in the future...
1040 printf(" [|%s]", NPSTR(base
->np
));
1045 CHECKLEN(base
+ 1, base
->np
)
1048 ext
= (struct isakmp_gen
*)(base
+ 1);
1049 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1054 if (ntohl(base
->len
) != length
) {
1055 printf(" (len mismatch: isakmp %u/ip %d)",
1056 (u_int32_t
)ntohl(base
->len
), length
);