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.3 1999-10-30 05:11:17 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 static u_char
*isakmp_sa_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
72 u_int32_t
, u_int32_t
));
73 static u_char
*isakmp_p_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
74 u_int32_t
, u_int32_t
));
75 static u_char
*isakmp_t_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
76 u_int32_t
, u_int32_t
));
77 static u_char
*isakmp_ke_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
78 u_int32_t
, u_int32_t
));
79 static u_char
*isakmp_id_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
));
81 static u_char
*isakmp_hash_print
__P((struct isakmp_gen
*, u_char
*,
82 u_int32_t
, u_int32_t
, u_int32_t
));
83 static u_char
*isakmp_nonce_print
__P((struct isakmp_gen
*, u_char
*,
84 u_int32_t
, u_int32_t
, u_int32_t
));
85 static u_char
*isakmp_n_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
86 u_int32_t
, u_int32_t
));
87 static u_char
*isakmp_d_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
88 u_int32_t
, u_int32_t
));
89 static u_char
*isakmp_vid_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
90 u_int32_t
, u_int32_t
));
91 static u_char
*isakmp_sub0_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
92 u_int32_t
, u_int32_t
, u_int32_t
));
93 static u_char
*isakmp_sub_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
94 u_int32_t
, u_int32_t
, u_int32_t
));
95 static char *numstr
__P((int));
97 #define MAXINITIATORS 20
101 struct sockaddr_storage iaddr
;
102 struct sockaddr_storage raddr
;
103 } cookiecache
[MAXINITIATORS
];
106 static char *protoidstr
[] = {
107 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
111 static char *npstr
[] = {
112 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
113 "sig", "nonce", "n", "d", "vid"
117 static u_char
*(*npfunc
[]) __P((struct isakmp_gen
*, u_char
*, u_int32_t
,
118 u_int32_t
, u_int32_t
)) = {
136 static char *etypestr
[] = {
137 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
138 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
139 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
140 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
141 "oakley-quick", "oakley-newgroup",
144 #define STR_OR_ID(x, tab) \
145 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
146 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
147 #define NPSTR(x) STR_OR_ID(x, npstr)
148 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
151 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
152 ? npfunc[(x)] : NULL)
155 iszero(u_char
*p
, size_t l
)
164 /* find cookie from initiator cache */
166 cookie_find(cookie_t
*in
)
170 for (i
= 0; i
< MAXINITIATORS
; i
++) {
171 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
178 /* record initiator */
180 cookie_record(cookie_t
*in
, const u_char
*bp2
)
184 struct sockaddr_in
*sin
;
187 struct sockaddr_in6
*sin6
;
192 ninitiator
= (i
+ 1) % MAXINITIATORS
;
196 ip
= (struct ip
*)bp2
;
199 memset(&cookiecache
[ninitiator
].iaddr
, 0,
200 sizeof(cookiecache
[ninitiator
].iaddr
));
201 memset(&cookiecache
[ninitiator
].raddr
, 0,
202 sizeof(cookiecache
[ninitiator
].raddr
));
204 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
205 sin
->sin_len
= sizeof(struct sockaddr_in
);
206 sin
->sin_family
= AF_INET
;
207 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
208 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
209 sin
->sin_len
= sizeof(struct sockaddr_in
);
210 sin
->sin_family
= AF_INET
;
211 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
215 memset(&cookiecache
[ninitiator
].iaddr
, 0,
216 sizeof(cookiecache
[ninitiator
].iaddr
));
217 memset(&cookiecache
[ninitiator
].raddr
, 0,
218 sizeof(cookiecache
[ninitiator
].raddr
));
220 ip6
= (struct ip6_hdr
*)bp2
;
221 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
222 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
223 sin6
->sin6_family
= AF_INET6
;
224 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
225 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
226 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
227 sin6
->sin6_family
= AF_INET6
;
228 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
234 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
235 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
238 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
239 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
241 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
243 struct sockaddr_storage ss
;
245 struct sockaddr_in
*sin
;
248 struct sockaddr_in6
*sin6
;
251 memset(&ss
, 0, sizeof(ss
));
252 ip
= (struct ip
*)bp2
;
255 sin
= (struct sockaddr_in
*)&ss
;
256 sin
->sin_len
= sizeof(struct sockaddr_in
);
257 sin
->sin_family
= AF_INET
;
258 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
262 ip6
= (struct ip6_hdr
*)bp2
;
263 sin6
= (struct sockaddr_in6
*)&ss
;
264 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
265 sin6
->sin6_family
= AF_INET6
;
266 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
274 if (ss
.__ss_family
!= cookiecache
[i
].iaddr
.__ss_family
)
276 if (ss
.__ss_len
!= cookiecache
[i
].iaddr
.__ss_len
)
278 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, ss
.__ss_len
) == 0)
281 if (ss
.__ss_family
!= cookiecache
[i
].raddr
.__ss_family
)
283 if (ss
.__ss_len
!= cookiecache
[i
].raddr
.__ss_len
)
285 if (memcmp(&ss
, &cookiecache
[i
].raddr
, ss
.__ss_len
) == 0)
292 rawprint(caddr_t loc
, size_t len
)
298 for (i
= 0; i
< len
; i
++)
299 printf("%02x", p
[i
] & 0xff);
305 char *value
[30]; /*XXX*/
309 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
319 totlen
= 4 + ntohs(q
[1]);
320 if (ep
< p
+ totlen
) {
326 t
= ntohs(q
[0]) & 0x7fff;
327 if (map
&& t
< nmap
&& map
[t
].type
)
328 printf("type=%s ", map
[t
].type
);
330 printf("type=#%d ", t
);
334 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
335 printf("%s", map
[t
].value
[v
]);
337 rawprint((caddr_t
)&q
[1], 2);
339 printf("len=%d value=", ntohs(q
[1]));
340 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
347 isakmp_attr_print(u_char
*p
, u_char
*ep
)
357 totlen
= 4 + ntohs(q
[1]);
358 if (ep
< p
+ totlen
) {
364 t
= ntohs(q
[0]) & 0x7fff;
365 printf("type=#%d ", t
);
369 rawprint((caddr_t
)&q
[1], 2);
371 printf("len=%d value=", ntohs(q
[1]));
372 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
379 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
380 u_int32_t doi0
, u_int32_t proto0
)
382 struct isakmp_pl_sa
*p
;
389 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
391 p
= (struct isakmp_pl_sa
*)ext
;
394 printf(" doi=%d", doi
);
395 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
396 return (u_char
*)(p
+ 1);
399 printf(" doi=ipsec");
400 q
= (u_int32_t
*)&p
->sit
;
401 printf(" situation=");
403 if (ntohl(*q
) & 0x01) {
407 if (ntohl(*q
) & 0x02) {
408 printf("%ssecrecy", t
? "+" : "");
411 if (ntohl(*q
) & 0x04)
412 printf("%sintegrity", t
? "+" : "");
416 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
418 ext
= (struct isakmp_gen
*)q
;
420 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
426 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
427 u_int32_t doi0
, u_int32_t proto0
)
429 struct isakmp_pl_p
*p
;
432 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
434 p
= (struct isakmp_pl_p
*)ext
;
435 printf(" #%d protoid=%s transform=%d",
436 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
439 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
442 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
444 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
450 static char *isakmp_p_map
[] = {
454 static char *ah_p_map
[] = {
455 NULL
, "md5", "sha", "1des",
458 static char *esp_p_map
[] = {
459 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
460 "blowfish", "3idea", "1des-iv32", "rc4", "null"
463 static char *ipcomp_p_map
[] = {
464 NULL
, "oui", "deflate", "lzs",
467 struct attrmap ipsec_t_map
[] = {
469 { "lifetype", 3, { NULL
, "sec", "kb", }, },
471 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
473 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
474 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
481 struct attrmap oakley_t_map
[] = {
483 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
485 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
486 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
487 "rsa enc revised", }, },
488 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
490 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
491 { "group prime", 0, },
492 { "group gen1", 0, },
493 { "group gen2", 0, },
494 { "group curve A", 0, },
495 { "group curve B", 0, },
496 { "lifetype", 3, { NULL
, "sec", "kb", }, },
497 { "lifeduration", 0, },
505 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
506 u_int32_t doi
, u_int32_t proto
)
508 struct isakmp_pl_t
*p
;
515 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
517 p
= (struct isakmp_pl_t
*)ext
;
521 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
523 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
526 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
528 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
531 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
533 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
536 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
538 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
548 printf(" #%d id=%s ", p
->t_no
, idstr
);
550 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
551 cp
= (u_char
*)(p
+ 1);
552 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
553 while (cp
< ep
&& cp
< ep2
) {
555 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
558 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
566 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
567 u_int32_t doi
, u_int32_t proto
)
569 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
571 printf(" key len=%d", ntohs(ext
->len
) - 4);
572 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
574 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
576 return (u_char
*)ext
+ ntohs(ext
->len
);
580 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
581 u_int32_t doi
, u_int32_t proto
)
583 #define USE_IPSECDOI_IN_PHASE1 1
584 struct isakmp_pl_id
*p
;
585 static char *idtypestr
[] = {
586 "IPv4", "IPv4net", "IPv6", "IPv6net",
588 static char *ipsecidtypestr
[] = {
589 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
590 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
596 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
598 p
= (struct isakmp_pl_id
*)ext
;
599 if (sizeof(*p
) < ext
->len
)
600 data
= (u_char
*)(p
+ 1);
603 len
= ntohs(ext
->len
) - sizeof(*p
);
606 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
609 #ifndef USE_IPSECDOI_IN_PHASE1
613 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
614 printf(" doi_data=%u",
615 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
618 #ifdef USE_IPSECDOI_IN_PHASE1
623 struct ipsecdoi_id
*p
;
626 p
= (struct ipsecdoi_id
*)ext
;
627 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
629 pe
= getprotobynumber(p
->proto_id
);
631 printf(" protoid=%s", pe
->p_name
);
633 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
635 printf(" port=%d", ntohs(p
->port
));
639 case IPSECDOI_ID_IPV4_ADDR
:
640 printf(" len=%d %s", len
, ipaddr_string(data
));
643 case IPSECDOI_ID_FQDN
:
644 case IPSECDOI_ID_USER_FQDN
:
647 printf(" len=%d ", len
);
648 for (i
= 0; i
< len
; i
++) {
649 if (isprint(data
[i
]))
650 printf("%c", data
[i
]);
652 printf("\\%03o", data
[i
]);
657 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
660 mask
= data
+ sizeof(struct in_addr
);
661 printf(" len=%d %s/%u.%u.%u.%u", len
,
663 mask
[0], mask
[1], mask
[2], mask
[3]);
668 case IPSECDOI_ID_IPV6_ADDR
:
669 printf(" len=%d %s", len
, ip6addr_string(data
));
672 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
675 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
677 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
678 ip6addr_string(data
),
679 mask
[0], mask
[1], mask
[2], mask
[3]);
684 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
685 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
686 ipaddr_string(data
+ sizeof(struct in_addr
)));
690 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
691 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
692 ip6addr_string(data
+ sizeof(struct in6_addr
)));
696 case IPSECDOI_ID_DER_ASN1_DN
:
697 case IPSECDOI_ID_DER_ASN1_GN
:
698 case IPSECDOI_ID_KEY_ID
:
706 printf(" len=%d", len
);
709 rawprint((caddr_t
)data
, len
);
712 return (u_char
*)ext
+ ntohs(ext
->len
);
716 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
717 u_int32_t doi
, u_int32_t proto
)
719 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
721 printf(" len=%d", ntohs(ext
->len
) - 4);
722 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
724 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
726 return (u_char
*)ext
+ ntohs(ext
->len
);
730 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
731 u_int32_t doi
, u_int32_t proto
)
733 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
735 printf(" n len=%d", ntohs(ext
->len
) - 4);
736 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
738 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
740 return (u_char
*)ext
+ ntohs(ext
->len
);
744 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
745 u_int32_t doi0
, u_int32_t proto0
)
747 struct isakmp_pl_n
*p
;
752 static char *notifystr
[] = {
753 NULL
, "INVALID-PAYLOAD-TYPE",
754 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
755 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
756 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
757 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
758 "INVALID-PROTOCOL-ID", "INVALID-SPI",
759 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
760 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
761 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
762 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
763 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
764 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
765 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
766 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
767 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
768 "UNEQUAL-PAYLOAD-LENGTHS",
770 static char *ipsecnotifystr
[] = {
771 "RESPONDER-LIFETIME", "REPLAY-STATUS",
774 /* NOTE: these macro must be called with x in proper range */
775 #define NOTIFYSTR(x) \
776 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
777 #define IPSECNOTIFYSTR(x) \
778 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
780 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
782 p
= (struct isakmp_pl_n
*)ext
;
786 printf(" doi=%d", doi
);
787 printf(" proto=%d", proto
);
788 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
791 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
793 return (u_char
*)(p
+ 1) + p
->spi_size
;
796 printf(" doi=ipsec");
797 printf(" proto=%s", PROTOIDSTR(proto
));
798 if (ntohs(p
->type
) < 8192)
799 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
800 else if (ntohs(p
->type
) < 16384)
801 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
802 else if (ntohs(p
->type
) < 24576)
803 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
804 else if (ntohs(p
->type
) < 40960)
805 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
807 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
810 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
813 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
814 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
818 switch (ntohs(p
->type
)) {
819 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
821 struct attrmap
*map
= oakley_t_map
;
822 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
823 while (cp
< ep
&& cp
< ep2
) {
824 cp
= isakmp_attrmap_print(cp
,
825 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
829 case IPSECDOI_NTYPE_REPLAY_STATUS
:
830 printf("replay detection %sabled",
831 (*(u_int32_t
*)cp
) ? "en" : "dis");
833 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
834 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
835 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
840 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
845 return (u_char
*)ext
+ ntohs(ext
->len
);
849 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
850 u_int32_t doi0
, u_int32_t proto0
)
852 struct isakmp_pl_d
*p
;
858 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
860 p
= (struct isakmp_pl_d
*)ext
;
864 printf(" doi=%u", doi
);
865 printf(" proto=%u", proto
);
867 printf(" doi=ipsec");
868 printf(" proto=%s", PROTOIDSTR(proto
));
870 printf(" spilen=%u", p
->spi_size
);
871 printf(" nspi=%u", ntohs(p
->num_spi
));
873 q
= (u_int8_t
*)(p
+ 1);
874 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
877 rawprint((caddr_t
)q
, p
->spi_size
);
884 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
885 u_int32_t doi
, u_int32_t proto
)
887 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
889 printf(" len=%d", ntohs(ext
->len
) - 4);
890 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
892 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
894 return (u_char
*)ext
+ ntohs(ext
->len
);
898 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
899 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
906 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
908 printf("%s", NPSTR(np
));
909 cp
+= ntohs(ext
->len
);
915 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
916 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
919 static int depth
= 0;
925 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
926 printf(" [|%s]", NPSTR(np
));
932 for (i
= 0; i
< depth
; i
++)
935 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
940 ext
= (struct isakmp_gen
*)cp
;
949 snprintf(buf
, sizeof(buf
), "#%d", x
);
954 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
962 base
= (struct isakmp
*)bp
;
963 ep
= (u_char
*)snapend
;
965 if ((struct isakmp
*)ep
< base
+ 1) {
972 printf(" %d.%d", base
->v_maj
, base
->v_min
);
976 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
981 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
983 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
987 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
989 printf(" phase %d", phase
);
991 printf(" phase %d/others", phase
);
993 i
= cookie_find(&base
->i_ck
);
995 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
996 /* the first packet */
999 cookie_record(&base
->i_ck
, bp2
);
1003 if (bp2
&& cookie_isinitiator(i
, bp2
))
1005 else if (bp2
&& cookie_isresponder(i
, bp2
))
1011 printf(" %s", ETYPESTR(base
->etype
));
1013 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1014 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1019 struct isakmp_gen
*ext
;
1022 #define CHECKLEN(p, np) \
1023 if (ep < (u_char *)(p)) { \
1024 printf(" [|%s]", NPSTR(np)); \
1028 /* regardless of phase... */
1029 if (base
->flags
& ISAKMP_FLAG_E
) {
1031 * encrypted, nothing we can do right now.
1032 * we hope to decrypt the packet in the future...
1034 printf(" [|%s]", NPSTR(base
->np
));
1039 CHECKLEN(base
+ 1, base
->np
)
1042 ext
= (struct isakmp_gen
*)(base
+ 1);
1043 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1048 if (ntohl(base
->len
) != length
) {
1049 printf(" (len mismatch: isakmp %u/ip %d)",
1050 (u_int32_t
)ntohl(base
->len
), length
);