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.13 2000-07-01 03:39:05 assar Exp $ (LBL)";
42 #include <sys/param.h>
44 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <netinet/if_ether.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip_var.h>
55 #include <netinet/udp.h>
56 #include <netinet/udp_var.h>
57 #include <netinet/tcp.h>
60 #include <netinet/ip6.h>
67 #include "ipsec_doi.h"
69 #include "interface.h"
70 #include "addrtoname.h"
71 #include "extract.h" /* must come after interface.h */
73 #ifndef HAVE_SOCKADDR_STORAGE
74 #define sockaddr_storage sockaddr
77 static u_char
*isakmp_sa_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
78 u_int32_t
, u_int32_t
));
79 static u_char
*isakmp_p_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
));
81 static u_char
*isakmp_t_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
82 u_int32_t
, u_int32_t
));
83 static u_char
*isakmp_ke_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
84 u_int32_t
, u_int32_t
));
85 static u_char
*isakmp_id_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
86 u_int32_t
, u_int32_t
));
87 static u_char
*isakmp_cert_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
88 u_int32_t
, u_int32_t
));
89 static u_char
*isakmp_sig_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
90 u_int32_t
, u_int32_t
));
91 static u_char
*isakmp_hash_print
__P((struct isakmp_gen
*, u_char
*,
92 u_int32_t
, u_int32_t
, u_int32_t
));
93 static u_char
*isakmp_nonce_print
__P((struct isakmp_gen
*, u_char
*,
94 u_int32_t
, u_int32_t
, u_int32_t
));
95 static u_char
*isakmp_n_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
96 u_int32_t
, u_int32_t
));
97 static u_char
*isakmp_d_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
98 u_int32_t
, u_int32_t
));
99 static u_char
*isakmp_vid_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
100 u_int32_t
, u_int32_t
));
101 static u_char
*isakmp_sub0_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
102 u_int32_t
, u_int32_t
, u_int32_t
));
103 static u_char
*isakmp_sub_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
104 u_int32_t
, u_int32_t
, u_int32_t
));
105 static char *numstr
__P((int));
107 #define MAXINITIATORS 20
111 struct sockaddr_storage iaddr
;
112 struct sockaddr_storage raddr
;
113 } cookiecache
[MAXINITIATORS
];
116 static char *protoidstr
[] = {
117 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
121 static char *npstr
[] = {
122 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
123 "sig", "nonce", "n", "d", "vid"
127 static u_char
*(*npfunc
[]) __P((struct isakmp_gen
*, u_char
*, u_int32_t
,
128 u_int32_t
, u_int32_t
)) = {
146 static char *etypestr
[] = {
147 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
148 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
149 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
150 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
151 "oakley-quick", "oakley-newgroup",
154 #define STR_OR_ID(x, tab) \
155 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
156 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
157 #define NPSTR(x) STR_OR_ID(x, npstr)
158 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
161 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
162 ? npfunc[(x)] : NULL)
165 iszero(u_char
*p
, size_t l
)
174 /* find cookie from initiator cache */
176 cookie_find(cookie_t
*in
)
180 for (i
= 0; i
< MAXINITIATORS
; i
++) {
181 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
188 /* record initiator */
190 cookie_record(cookie_t
*in
, const u_char
*bp2
)
194 struct sockaddr_in
*sin
;
197 struct sockaddr_in6
*sin6
;
202 ninitiator
= (i
+ 1) % MAXINITIATORS
;
206 ip
= (struct ip
*)bp2
;
209 memset(&cookiecache
[ninitiator
].iaddr
, 0,
210 sizeof(cookiecache
[ninitiator
].iaddr
));
211 memset(&cookiecache
[ninitiator
].raddr
, 0,
212 sizeof(cookiecache
[ninitiator
].raddr
));
214 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
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_src
, sizeof(ip
->ip_src
));
220 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
221 #ifdef HAVE_SOCKADDR_SA_LEN
222 sin
->sin_len
= sizeof(struct sockaddr_in
);
224 sin
->sin_family
= AF_INET
;
225 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
229 memset(&cookiecache
[ninitiator
].iaddr
, 0,
230 sizeof(cookiecache
[ninitiator
].iaddr
));
231 memset(&cookiecache
[ninitiator
].raddr
, 0,
232 sizeof(cookiecache
[ninitiator
].raddr
));
234 ip6
= (struct ip6_hdr
*)bp2
;
235 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
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_src
, sizeof(ip6
->ip6_src
));
241 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
242 #ifdef HAVE_SOCKADDR_SA_LEN
243 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
245 sin6
->sin6_family
= AF_INET6
;
246 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
252 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
253 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
256 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
257 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
259 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
261 struct sockaddr_storage ss
;
264 struct sockaddr_in
*sin
;
267 struct sockaddr_in6
*sin6
;
271 memset(&ss
, 0, sizeof(ss
));
272 ip
= (struct ip
*)bp2
;
275 sin
= (struct sockaddr_in
*)&ss
;
276 #ifdef HAVE_SOCKADDR_SA_LEN
277 sin
->sin_len
= sizeof(struct sockaddr_in
);
279 sin
->sin_family
= AF_INET
;
280 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
284 ip6
= (struct ip6_hdr
*)bp2
;
285 sin6
= (struct sockaddr_in6
*)&ss
;
286 #ifdef HAVE_SOCKADDR_SA_LEN
287 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
289 sin6
->sin6_family
= AF_INET6
;
290 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
297 sa
= (struct sockaddr
*)&ss
;
299 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
301 #ifdef HAVE_SOCKADDR_SA_LEN
305 if (sa
->sa_family
== AF_INET6
)
306 salen
= sizeof(struct sockaddr_in6
);
308 salen
= sizeof(struct sockaddr
);
310 salen
= sizeof(struct sockaddr
);
313 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
316 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
318 #ifdef HAVE_SOCKADDR_SA_LEN
322 if (sa
->sa_family
== AF_INET6
)
323 salen
= sizeof(struct sockaddr_in6
);
325 salen
= sizeof(struct sockaddr
);
327 salen
= sizeof(struct sockaddr
);
330 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
337 rawprint(caddr_t loc
, size_t len
)
343 for (i
= 0; i
< len
; i
++)
344 printf("%02x", p
[i
] & 0xff);
350 char *value
[30]; /*XXX*/
354 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
364 totlen
= 4 + ntohs(q
[1]);
365 if (ep
< p
+ totlen
) {
371 t
= ntohs(q
[0]) & 0x7fff;
372 if (map
&& t
< nmap
&& map
[t
].type
)
373 printf("type=%s ", map
[t
].type
);
375 printf("type=#%d ", t
);
379 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
380 printf("%s", map
[t
].value
[v
]);
382 rawprint((caddr_t
)&q
[1], 2);
384 printf("len=%d value=", ntohs(q
[1]));
385 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
392 isakmp_attr_print(u_char
*p
, u_char
*ep
)
402 totlen
= 4 + ntohs(q
[1]);
403 if (ep
< p
+ totlen
) {
409 t
= ntohs(q
[0]) & 0x7fff;
410 printf("type=#%d ", t
);
414 rawprint((caddr_t
)&q
[1], 2);
416 printf("len=%d value=", ntohs(q
[1]));
417 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
424 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
425 u_int32_t doi0
, u_int32_t proto0
)
427 struct isakmp_pl_sa
*p
;
434 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
436 p
= (struct isakmp_pl_sa
*)ext
;
439 printf(" doi=%d", doi
);
440 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
441 return (u_char
*)(p
+ 1);
444 printf(" doi=ipsec");
445 q
= (u_int32_t
*)&p
->sit
;
446 printf(" situation=");
448 if (ntohl(*q
) & 0x01) {
452 if (ntohl(*q
) & 0x02) {
453 printf("%ssecrecy", t
? "+" : "");
456 if (ntohl(*q
) & 0x04)
457 printf("%sintegrity", t
? "+" : "");
461 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
463 ext
= (struct isakmp_gen
*)q
;
465 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
471 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
472 u_int32_t doi0
, u_int32_t proto0
)
474 struct isakmp_pl_p
*p
;
477 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
479 p
= (struct isakmp_pl_p
*)ext
;
480 printf(" #%d protoid=%s transform=%d",
481 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
484 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
487 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
489 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
495 static char *isakmp_p_map
[] = {
499 static char *ah_p_map
[] = {
500 NULL
, "(reserved)", "md5", "sha", "1des",
503 static char *esp_p_map
[] = {
504 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
505 "blowfish", "3idea", "1des-iv32", "rc4", "null"
508 static char *ipcomp_p_map
[] = {
509 NULL
, "oui", "deflate", "lzs",
512 struct attrmap ipsec_t_map
[] = {
514 { "lifetype", 3, { NULL
, "sec", "kb", }, },
516 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
518 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
519 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
526 struct attrmap oakley_t_map
[] = {
528 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
530 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
531 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
532 "rsa enc revised", }, },
533 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
535 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
536 { "group prime", 0, },
537 { "group gen1", 0, },
538 { "group gen2", 0, },
539 { "group curve A", 0, },
540 { "group curve B", 0, },
541 { "lifetype", 3, { NULL
, "sec", "kb", }, },
542 { "lifeduration", 0, },
550 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
551 u_int32_t doi
, u_int32_t proto
)
553 struct isakmp_pl_t
*p
;
560 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
562 p
= (struct isakmp_pl_t
*)ext
;
566 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
568 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
571 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
573 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
576 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
578 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
581 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
583 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
593 printf(" #%d id=%s ", p
->t_no
, idstr
);
595 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
596 cp
= (u_char
*)(p
+ 1);
597 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
598 while (cp
< ep
&& cp
< ep2
) {
600 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
603 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
611 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
612 u_int32_t doi
, u_int32_t proto
)
614 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
616 printf(" key len=%d", ntohs(ext
->len
) - 4);
617 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
619 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
621 return (u_char
*)ext
+ ntohs(ext
->len
);
625 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
626 u_int32_t doi
, u_int32_t proto
)
628 #define USE_IPSECDOI_IN_PHASE1 1
629 struct isakmp_pl_id
*p
;
630 static char *idtypestr
[] = {
631 "IPv4", "IPv4net", "IPv6", "IPv6net",
633 static char *ipsecidtypestr
[] = {
634 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
635 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
641 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
643 p
= (struct isakmp_pl_id
*)ext
;
644 if (sizeof(*p
) < ext
->len
)
645 data
= (u_char
*)(p
+ 1);
648 len
= ntohs(ext
->len
) - sizeof(*p
);
651 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
654 #ifndef USE_IPSECDOI_IN_PHASE1
658 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
659 printf(" doi_data=%u",
660 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
663 #ifdef USE_IPSECDOI_IN_PHASE1
668 struct ipsecdoi_id
*p
;
671 p
= (struct ipsecdoi_id
*)ext
;
672 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
674 pe
= getprotobynumber(p
->proto_id
);
676 printf(" protoid=%s", pe
->p_name
);
678 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
680 printf(" port=%d", ntohs(p
->port
));
684 case IPSECDOI_ID_IPV4_ADDR
:
685 printf(" len=%d %s", len
, ipaddr_string(data
));
688 case IPSECDOI_ID_FQDN
:
689 case IPSECDOI_ID_USER_FQDN
:
692 printf(" len=%d ", len
);
693 for (i
= 0; i
< len
; i
++) {
694 if (isprint(data
[i
]))
695 printf("%c", data
[i
]);
697 printf("\\%03o", data
[i
]);
702 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
705 mask
= data
+ sizeof(struct in_addr
);
706 printf(" len=%d %s/%u.%u.%u.%u", len
,
708 mask
[0], mask
[1], mask
[2], mask
[3]);
713 case IPSECDOI_ID_IPV6_ADDR
:
714 printf(" len=%d %s", len
, ip6addr_string(data
));
717 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
720 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
722 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
723 ip6addr_string(data
),
724 mask
[0], mask
[1], mask
[2], mask
[3]);
729 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
730 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
731 ipaddr_string(data
+ sizeof(struct in_addr
)));
735 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
736 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
737 ip6addr_string(data
+ sizeof(struct in6_addr
)));
741 case IPSECDOI_ID_DER_ASN1_DN
:
742 case IPSECDOI_ID_DER_ASN1_GN
:
743 case IPSECDOI_ID_KEY_ID
:
751 printf(" len=%d", len
);
754 rawprint((caddr_t
)data
, len
);
757 return (u_char
*)ext
+ ntohs(ext
->len
);
761 isakmp_cert_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
762 u_int32_t doi0
, u_int32_t proto0
)
764 struct isakmp_pl_cert
*p
;
765 static char *certstr
[] = {
766 "none", "pkcs7", "pgp", "dns",
767 "x509sign", "x509ke", "kerberos", "crl",
768 "arl", "spki", "x509attr",
771 printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
773 p
= (struct isakmp_pl_cert
*)ext
;
774 printf(" len=%d", ntohs(ext
->len
) - 4);
775 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
776 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
778 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
780 return (u_char
*)ext
+ ntohs(ext
->len
);
784 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
785 u_int32_t doi
, u_int32_t proto
)
787 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
789 printf(" len=%d", ntohs(ext
->len
) - 4);
790 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
792 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
794 return (u_char
*)ext
+ ntohs(ext
->len
);
798 isakmp_sig_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
799 u_int32_t doi
, u_int32_t proto
)
801 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
803 printf(" len=%d", ntohs(ext
->len
) - 4);
804 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
806 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
808 return (u_char
*)ext
+ ntohs(ext
->len
);
812 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
813 u_int32_t doi
, u_int32_t proto
)
815 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
817 printf(" n len=%d", ntohs(ext
->len
) - 4);
818 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
820 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
822 return (u_char
*)ext
+ ntohs(ext
->len
);
826 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
827 u_int32_t doi0
, u_int32_t proto0
)
829 struct isakmp_pl_n
*p
;
834 static char *notifystr
[] = {
835 NULL
, "INVALID-PAYLOAD-TYPE",
836 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
837 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
838 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
839 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
840 "INVALID-PROTOCOL-ID", "INVALID-SPI",
841 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
842 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
843 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
844 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
845 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
846 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
847 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
848 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
849 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
850 "UNEQUAL-PAYLOAD-LENGTHS",
852 static char *ipsecnotifystr
[] = {
853 "RESPONDER-LIFETIME", "REPLAY-STATUS",
856 /* NOTE: these macro must be called with x in proper range */
857 #define NOTIFYSTR(x) \
858 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
859 #define IPSECNOTIFYSTR(x) \
860 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
862 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
864 p
= (struct isakmp_pl_n
*)ext
;
868 printf(" doi=%d", doi
);
869 printf(" proto=%d", proto
);
870 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
873 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
875 return (u_char
*)(p
+ 1) + p
->spi_size
;
878 printf(" doi=ipsec");
879 printf(" proto=%s", PROTOIDSTR(proto
));
880 if (ntohs(p
->type
) < 8192)
881 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
882 else if (ntohs(p
->type
) < 16384)
883 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
884 else if (ntohs(p
->type
) < 24576)
885 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
886 else if (ntohs(p
->type
) < 40960)
887 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
889 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
892 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
895 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
896 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
900 switch (ntohs(p
->type
)) {
901 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
903 struct attrmap
*map
= oakley_t_map
;
904 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
905 while (cp
< ep
&& cp
< ep2
) {
906 cp
= isakmp_attrmap_print(cp
,
907 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
911 case IPSECDOI_NTYPE_REPLAY_STATUS
:
912 printf("replay detection %sabled",
913 (*(u_int32_t
*)cp
) ? "en" : "dis");
915 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
916 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
917 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
922 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
927 return (u_char
*)ext
+ ntohs(ext
->len
);
931 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
932 u_int32_t doi0
, u_int32_t proto0
)
934 struct isakmp_pl_d
*p
;
940 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
942 p
= (struct isakmp_pl_d
*)ext
;
946 printf(" doi=%u", doi
);
947 printf(" proto=%u", proto
);
949 printf(" doi=ipsec");
950 printf(" proto=%s", PROTOIDSTR(proto
));
952 printf(" spilen=%u", p
->spi_size
);
953 printf(" nspi=%u", ntohs(p
->num_spi
));
955 q
= (u_int8_t
*)(p
+ 1);
956 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
959 rawprint((caddr_t
)q
, p
->spi_size
);
966 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
967 u_int32_t doi
, u_int32_t proto
)
969 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
971 printf(" len=%d", ntohs(ext
->len
) - 4);
972 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
974 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
976 return (u_char
*)ext
+ ntohs(ext
->len
);
980 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
981 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
988 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
990 printf("%s", NPSTR(np
));
991 cp
+= ntohs(ext
->len
);
997 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
998 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1001 static int depth
= 0;
1007 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
1008 printf(" [|%s]", NPSTR(np
));
1014 for (i
= 0; i
< depth
; i
++)
1017 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
1022 ext
= (struct isakmp_gen
*)cp
;
1030 static char buf
[20];
1031 snprintf(buf
, sizeof(buf
), "#%d", x
);
1036 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1038 struct isakmp
*base
;
1045 base
= (struct isakmp
*)bp
;
1046 ep
= (u_char
*)snapend
;
1048 if ((struct isakmp
*)ep
< base
+ 1) {
1049 printf("[|isakmp]");
1055 major
= (base
->vers
& ISAKMP_VERS_MAJOR
)
1056 >> ISAKMP_VERS_MAJOR_SHIFT
;
1057 minor
= (base
->vers
& ISAKMP_VERS_MINOR
)
1058 >> ISAKMP_VERS_MINOR_SHIFT
;
1059 printf(" %d.%d", major
, minor
);
1064 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1069 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1071 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1075 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1077 printf(" phase %d", phase
);
1079 printf(" phase %d/others", phase
);
1081 i
= cookie_find(&base
->i_ck
);
1083 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1084 /* the first packet */
1087 cookie_record(&base
->i_ck
, bp2
);
1091 if (bp2
&& cookie_isinitiator(i
, bp2
))
1093 else if (bp2
&& cookie_isresponder(i
, bp2
))
1099 printf(" %s", ETYPESTR(base
->etype
));
1101 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1102 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1107 struct isakmp_gen
*ext
;
1110 #define CHECKLEN(p, np) \
1111 if (ep < (u_char *)(p)) { \
1112 printf(" [|%s]", NPSTR(np)); \
1116 /* regardless of phase... */
1117 if (base
->flags
& ISAKMP_FLAG_E
) {
1119 * encrypted, nothing we can do right now.
1120 * we hope to decrypt the packet in the future...
1122 printf(" [|%s]", NPSTR(base
->np
));
1127 CHECKLEN(base
+ 1, base
->np
)
1130 ext
= (struct isakmp_gen
*)(base
+ 1);
1131 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1136 if (ntohl(base
->len
) != length
) {
1137 printf(" (len mismatch: isakmp %u/ip %d)",
1138 (u_int32_t
)ntohl(base
->len
), length
);