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.15 2000-09-23 04:43:42 itojun 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_cr_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
90 u_int32_t
, u_int32_t
));
91 static u_char
*isakmp_sig_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
92 u_int32_t
, u_int32_t
));
93 static u_char
*isakmp_hash_print
__P((struct isakmp_gen
*, u_char
*,
94 u_int32_t
, u_int32_t
, u_int32_t
));
95 static u_char
*isakmp_nonce_print
__P((struct isakmp_gen
*, u_char
*,
96 u_int32_t
, u_int32_t
, u_int32_t
));
97 static u_char
*isakmp_n_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
98 u_int32_t
, u_int32_t
));
99 static u_char
*isakmp_d_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
100 u_int32_t
, u_int32_t
));
101 static u_char
*isakmp_vid_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
102 u_int32_t
, u_int32_t
));
103 static u_char
*isakmp_sub0_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
104 u_int32_t
, u_int32_t
, u_int32_t
));
105 static u_char
*isakmp_sub_print
__P((u_char
, struct isakmp_gen
*, u_char
*,
106 u_int32_t
, u_int32_t
, u_int32_t
));
107 static char *numstr
__P((int));
109 #define MAXINITIATORS 20
113 struct sockaddr_storage iaddr
;
114 struct sockaddr_storage raddr
;
115 } cookiecache
[MAXINITIATORS
];
118 static char *protoidstr
[] = {
119 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
123 static char *npstr
[] = {
124 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
125 "sig", "nonce", "n", "d", "vid"
129 static u_char
*(*npfunc
[]) __P((struct isakmp_gen
*, u_char
*, u_int32_t
,
130 u_int32_t
, u_int32_t
)) = {
148 static char *etypestr
[] = {
149 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
150 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
151 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
152 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
153 "oakley-quick", "oakley-newgroup",
156 #define STR_OR_ID(x, tab) \
157 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
158 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
159 #define NPSTR(x) STR_OR_ID(x, npstr)
160 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
163 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
164 ? npfunc[(x)] : NULL)
167 iszero(u_char
*p
, size_t l
)
176 /* find cookie from initiator cache */
178 cookie_find(cookie_t
*in
)
182 for (i
= 0; i
< MAXINITIATORS
; i
++) {
183 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
190 /* record initiator */
192 cookie_record(cookie_t
*in
, const u_char
*bp2
)
196 struct sockaddr_in
*sin
;
199 struct sockaddr_in6
*sin6
;
204 ninitiator
= (i
+ 1) % MAXINITIATORS
;
208 ip
= (struct ip
*)bp2
;
211 memset(&cookiecache
[ninitiator
].iaddr
, 0,
212 sizeof(cookiecache
[ninitiator
].iaddr
));
213 memset(&cookiecache
[ninitiator
].raddr
, 0,
214 sizeof(cookiecache
[ninitiator
].raddr
));
216 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
217 #ifdef HAVE_SOCKADDR_SA_LEN
218 sin
->sin_len
= sizeof(struct sockaddr_in
);
220 sin
->sin_family
= AF_INET
;
221 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
222 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
223 #ifdef HAVE_SOCKADDR_SA_LEN
224 sin
->sin_len
= sizeof(struct sockaddr_in
);
226 sin
->sin_family
= AF_INET
;
227 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
231 memset(&cookiecache
[ninitiator
].iaddr
, 0,
232 sizeof(cookiecache
[ninitiator
].iaddr
));
233 memset(&cookiecache
[ninitiator
].raddr
, 0,
234 sizeof(cookiecache
[ninitiator
].raddr
));
236 ip6
= (struct ip6_hdr
*)bp2
;
237 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
238 #ifdef HAVE_SOCKADDR_SA_LEN
239 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
241 sin6
->sin6_family
= AF_INET6
;
242 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
243 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
244 #ifdef HAVE_SOCKADDR_SA_LEN
245 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
247 sin6
->sin6_family
= AF_INET6
;
248 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
254 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
255 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
258 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
259 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
261 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
263 struct sockaddr_storage ss
;
266 struct sockaddr_in
*sin
;
269 struct sockaddr_in6
*sin6
;
273 memset(&ss
, 0, sizeof(ss
));
274 ip
= (struct ip
*)bp2
;
277 sin
= (struct sockaddr_in
*)&ss
;
278 #ifdef HAVE_SOCKADDR_SA_LEN
279 sin
->sin_len
= sizeof(struct sockaddr_in
);
281 sin
->sin_family
= AF_INET
;
282 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
286 ip6
= (struct ip6_hdr
*)bp2
;
287 sin6
= (struct sockaddr_in6
*)&ss
;
288 #ifdef HAVE_SOCKADDR_SA_LEN
289 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
291 sin6
->sin6_family
= AF_INET6
;
292 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
299 sa
= (struct sockaddr
*)&ss
;
301 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
303 #ifdef HAVE_SOCKADDR_SA_LEN
307 if (sa
->sa_family
== AF_INET6
)
308 salen
= sizeof(struct sockaddr_in6
);
310 salen
= sizeof(struct sockaddr
);
312 salen
= sizeof(struct sockaddr
);
315 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
318 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
320 #ifdef HAVE_SOCKADDR_SA_LEN
324 if (sa
->sa_family
== AF_INET6
)
325 salen
= sizeof(struct sockaddr_in6
);
327 salen
= sizeof(struct sockaddr
);
329 salen
= sizeof(struct sockaddr
);
332 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
339 rawprint(caddr_t loc
, size_t len
)
345 for (i
= 0; i
< len
; i
++)
346 printf("%02x", p
[i
] & 0xff);
352 char *value
[30]; /*XXX*/
356 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
366 totlen
= 4 + ntohs(q
[1]);
367 if (ep
< p
+ totlen
) {
373 t
= ntohs(q
[0]) & 0x7fff;
374 if (map
&& t
< nmap
&& map
[t
].type
)
375 printf("type=%s ", map
[t
].type
);
377 printf("type=#%d ", t
);
381 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
382 printf("%s", map
[t
].value
[v
]);
384 rawprint((caddr_t
)&q
[1], 2);
386 printf("len=%d value=", ntohs(q
[1]));
387 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
394 isakmp_attr_print(u_char
*p
, u_char
*ep
)
404 totlen
= 4 + ntohs(q
[1]);
405 if (ep
< p
+ totlen
) {
411 t
= ntohs(q
[0]) & 0x7fff;
412 printf("type=#%d ", t
);
416 rawprint((caddr_t
)&q
[1], 2);
418 printf("len=%d value=", ntohs(q
[1]));
419 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
426 isakmp_sa_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_sa
*p
;
436 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
438 p
= (struct isakmp_pl_sa
*)ext
;
441 printf(" doi=%d", doi
);
442 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
443 return (u_char
*)(p
+ 1);
446 printf(" doi=ipsec");
447 q
= (u_int32_t
*)&p
->sit
;
448 printf(" situation=");
450 if (ntohl(*q
) & 0x01) {
454 if (ntohl(*q
) & 0x02) {
455 printf("%ssecrecy", t
? "+" : "");
458 if (ntohl(*q
) & 0x04)
459 printf("%sintegrity", t
? "+" : "");
463 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
465 ext
= (struct isakmp_gen
*)q
;
467 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
473 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
474 u_int32_t doi0
, u_int32_t proto0
)
476 struct isakmp_pl_p
*p
;
479 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
481 p
= (struct isakmp_pl_p
*)ext
;
482 printf(" #%d protoid=%s transform=%d",
483 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
486 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
489 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
491 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
497 static char *isakmp_p_map
[] = {
501 static char *ah_p_map
[] = {
502 NULL
, "(reserved)", "md5", "sha", "1des",
505 static char *esp_p_map
[] = {
506 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
507 "blowfish", "3idea", "1des-iv32", "rc4", "null"
510 static char *ipcomp_p_map
[] = {
511 NULL
, "oui", "deflate", "lzs",
514 struct attrmap ipsec_t_map
[] = {
516 { "lifetype", 3, { NULL
, "sec", "kb", }, },
518 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
520 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
521 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
528 struct attrmap oakley_t_map
[] = {
530 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
532 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
533 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
534 "rsa enc revised", }, },
535 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
537 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
538 { "group prime", 0, },
539 { "group gen1", 0, },
540 { "group gen2", 0, },
541 { "group curve A", 0, },
542 { "group curve B", 0, },
543 { "lifetype", 3, { NULL
, "sec", "kb", }, },
544 { "lifeduration", 0, },
552 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
553 u_int32_t doi
, u_int32_t proto
)
555 struct isakmp_pl_t
*p
;
562 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
564 p
= (struct isakmp_pl_t
*)ext
;
568 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
570 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
573 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
575 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
578 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
580 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
583 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
585 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
595 printf(" #%d id=%s ", p
->t_no
, idstr
);
597 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
598 cp
= (u_char
*)(p
+ 1);
599 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
600 while (cp
< ep
&& cp
< ep2
) {
602 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
605 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
613 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
614 u_int32_t doi
, u_int32_t proto
)
616 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
618 printf(" key len=%d", ntohs(ext
->len
) - 4);
619 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
621 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
623 return (u_char
*)ext
+ ntohs(ext
->len
);
627 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
628 u_int32_t doi
, u_int32_t proto
)
630 #define USE_IPSECDOI_IN_PHASE1 1
631 struct isakmp_pl_id
*p
;
632 static char *idtypestr
[] = {
633 "IPv4", "IPv4net", "IPv6", "IPv6net",
635 static char *ipsecidtypestr
[] = {
636 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
637 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
643 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
645 p
= (struct isakmp_pl_id
*)ext
;
646 if (sizeof(*p
) < ext
->len
)
647 data
= (u_char
*)(p
+ 1);
650 len
= ntohs(ext
->len
) - sizeof(*p
);
653 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
656 #ifndef USE_IPSECDOI_IN_PHASE1
660 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
661 printf(" doi_data=%u",
662 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
665 #ifdef USE_IPSECDOI_IN_PHASE1
670 struct ipsecdoi_id
*p
;
673 p
= (struct ipsecdoi_id
*)ext
;
674 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
677 pe
= getprotobynumber(p
->proto_id
);
679 printf(" protoid=%s", pe
->p_name
);
682 /* it DOES NOT mean IPPROTO_IP! */
683 printf(" protoid=%s", "0");
685 printf(" port=%d", ntohs(p
->port
));
689 case IPSECDOI_ID_IPV4_ADDR
:
690 printf(" len=%d %s", len
, ipaddr_string(data
));
693 case IPSECDOI_ID_FQDN
:
694 case IPSECDOI_ID_USER_FQDN
:
697 printf(" len=%d ", len
);
698 for (i
= 0; i
< len
; i
++) {
699 if (isprint(data
[i
]))
700 printf("%c", data
[i
]);
702 printf("\\%03o", data
[i
]);
707 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
710 mask
= data
+ sizeof(struct in_addr
);
711 printf(" len=%d %s/%u.%u.%u.%u", len
,
713 mask
[0], mask
[1], mask
[2], mask
[3]);
718 case IPSECDOI_ID_IPV6_ADDR
:
719 printf(" len=%d %s", len
, ip6addr_string(data
));
722 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
725 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
727 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
728 ip6addr_string(data
),
729 mask
[0], mask
[1], mask
[2], mask
[3]);
734 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
735 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
736 ipaddr_string(data
+ sizeof(struct in_addr
)));
740 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
741 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
742 ip6addr_string(data
+ sizeof(struct in6_addr
)));
746 case IPSECDOI_ID_DER_ASN1_DN
:
747 case IPSECDOI_ID_DER_ASN1_GN
:
748 case IPSECDOI_ID_KEY_ID
:
756 printf(" len=%d", len
);
759 rawprint((caddr_t
)data
, len
);
762 return (u_char
*)ext
+ ntohs(ext
->len
);
766 isakmp_cert_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
767 u_int32_t doi0
, u_int32_t proto0
)
769 struct isakmp_pl_cert
*p
;
770 static char *certstr
[] = {
771 "none", "pkcs7", "pgp", "dns",
772 "x509sign", "x509ke", "kerberos", "crl",
773 "arl", "spki", "x509attr",
776 printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
778 p
= (struct isakmp_pl_cert
*)ext
;
779 printf(" len=%d", ntohs(ext
->len
) - 4);
780 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
781 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
783 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
785 return (u_char
*)ext
+ ntohs(ext
->len
);
789 isakmp_cr_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
790 u_int32_t doi0
, u_int32_t proto0
)
792 struct isakmp_pl_cert
*p
;
793 static char *certstr
[] = {
794 "none", "pkcs7", "pgp", "dns",
795 "x509sign", "x509ke", "kerberos", "crl",
796 "arl", "spki", "x509attr",
799 printf("%s:", NPSTR(ISAKMP_NPTYPE_CR
));
801 p
= (struct isakmp_pl_cert
*)ext
;
802 printf(" len=%d", ntohs(ext
->len
) - 4);
803 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
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_hash_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_HASH
));
817 printf(" 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_sig_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
827 u_int32_t doi
, u_int32_t proto
)
829 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
831 printf(" len=%d", ntohs(ext
->len
) - 4);
832 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
834 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
836 return (u_char
*)ext
+ ntohs(ext
->len
);
840 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
841 u_int32_t doi
, u_int32_t proto
)
843 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
845 printf(" n len=%d", ntohs(ext
->len
) - 4);
846 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
848 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
850 return (u_char
*)ext
+ ntohs(ext
->len
);
854 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
855 u_int32_t doi0
, u_int32_t proto0
)
857 struct isakmp_pl_n
*p
;
862 static char *notifystr
[] = {
863 NULL
, "INVALID-PAYLOAD-TYPE",
864 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
865 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
866 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
867 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
868 "INVALID-PROTOCOL-ID", "INVALID-SPI",
869 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
870 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
871 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
872 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
873 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
874 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
875 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
876 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
877 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
878 "UNEQUAL-PAYLOAD-LENGTHS",
880 static char *ipsecnotifystr
[] = {
881 "RESPONDER-LIFETIME", "REPLAY-STATUS",
884 /* NOTE: these macro must be called with x in proper range */
885 #define NOTIFYSTR(x) \
886 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
887 #define IPSECNOTIFYSTR(x) \
888 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
890 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
892 p
= (struct isakmp_pl_n
*)ext
;
896 printf(" doi=%d", doi
);
897 printf(" proto=%d", proto
);
898 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
901 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
903 return (u_char
*)(p
+ 1) + p
->spi_size
;
906 printf(" doi=ipsec");
907 printf(" proto=%s", PROTOIDSTR(proto
));
908 if (ntohs(p
->type
) < 8192)
909 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
910 else if (ntohs(p
->type
) < 16384)
911 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
912 else if (ntohs(p
->type
) < 24576)
913 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
914 else if (ntohs(p
->type
) < 40960)
915 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
917 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
920 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
923 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
924 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
928 switch (ntohs(p
->type
)) {
929 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
931 struct attrmap
*map
= oakley_t_map
;
932 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
933 while (cp
< ep
&& cp
< ep2
) {
934 cp
= isakmp_attrmap_print(cp
,
935 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
939 case IPSECDOI_NTYPE_REPLAY_STATUS
:
940 printf("replay detection %sabled",
941 (*(u_int32_t
*)cp
) ? "en" : "dis");
943 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
944 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
945 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
950 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
955 return (u_char
*)ext
+ ntohs(ext
->len
);
959 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
960 u_int32_t doi0
, u_int32_t proto0
)
962 struct isakmp_pl_d
*p
;
968 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
970 p
= (struct isakmp_pl_d
*)ext
;
974 printf(" doi=%u", doi
);
975 printf(" proto=%u", proto
);
977 printf(" doi=ipsec");
978 printf(" proto=%s", PROTOIDSTR(proto
));
980 printf(" spilen=%u", p
->spi_size
);
981 printf(" nspi=%u", ntohs(p
->num_spi
));
983 q
= (u_int8_t
*)(p
+ 1);
984 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
987 rawprint((caddr_t
)q
, p
->spi_size
);
994 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
995 u_int32_t doi
, u_int32_t proto
)
997 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
999 printf(" len=%d", ntohs(ext
->len
) - 4);
1000 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
1002 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
1004 return (u_char
*)ext
+ ntohs(ext
->len
);
1008 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1009 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1016 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
1018 printf("%s", NPSTR(np
));
1019 cp
+= ntohs(ext
->len
);
1025 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1026 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1029 static int depth
= 0;
1035 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
1036 printf(" [|%s]", NPSTR(np
));
1042 for (i
= 0; i
< depth
; i
++)
1045 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
1050 ext
= (struct isakmp_gen
*)cp
;
1058 static char buf
[20];
1059 snprintf(buf
, sizeof(buf
), "#%d", x
);
1064 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1066 struct isakmp
*base
;
1073 base
= (struct isakmp
*)bp
;
1074 ep
= (u_char
*)snapend
;
1076 if ((struct isakmp
*)ep
< base
+ 1) {
1077 printf("[|isakmp]");
1083 major
= (base
->vers
& ISAKMP_VERS_MAJOR
)
1084 >> ISAKMP_VERS_MAJOR_SHIFT
;
1085 minor
= (base
->vers
& ISAKMP_VERS_MINOR
)
1086 >> ISAKMP_VERS_MINOR_SHIFT
;
1087 printf(" %d.%d", major
, minor
);
1092 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1097 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1099 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1103 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1105 printf(" phase %d", phase
);
1107 printf(" phase %d/others", phase
);
1109 i
= cookie_find(&base
->i_ck
);
1111 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1112 /* the first packet */
1115 cookie_record(&base
->i_ck
, bp2
);
1119 if (bp2
&& cookie_isinitiator(i
, bp2
))
1121 else if (bp2
&& cookie_isresponder(i
, bp2
))
1127 printf(" %s", ETYPESTR(base
->etype
));
1129 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1130 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1135 struct isakmp_gen
*ext
;
1138 #define CHECKLEN(p, np) \
1139 if (ep < (u_char *)(p)) { \
1140 printf(" [|%s]", NPSTR(np)); \
1144 /* regardless of phase... */
1145 if (base
->flags
& ISAKMP_FLAG_E
) {
1147 * encrypted, nothing we can do right now.
1148 * we hope to decrypt the packet in the future...
1150 printf(" [|%s]", NPSTR(base
->np
));
1155 CHECKLEN(base
+ 1, base
->np
)
1158 ext
= (struct isakmp_gen
*)(base
+ 1);
1159 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1164 if (ntohl(base
->len
) != length
) {
1165 printf(" (len mismatch: isakmp %u/ip %d)",
1166 (u_int32_t
)ntohl(base
->len
), length
);