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.20 2000-09-28 06:43:01 guy Exp $ (LBL)";
42 #include <sys/param.h>
44 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
53 #include <netinet/ip6.h>
60 #include "ipsec_doi.h"
62 #include "interface.h"
63 #include "addrtoname.h"
64 #include "extract.h" /* must come after interface.h */
68 #ifndef HAVE_SOCKADDR_STORAGE
69 #define sockaddr_storage sockaddr
72 static u_char
*isakmp_sa_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
73 u_int32_t
, u_int32_t
);
74 static u_char
*isakmp_p_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
75 u_int32_t
, u_int32_t
);
76 static u_char
*isakmp_t_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
77 u_int32_t
, u_int32_t
);
78 static u_char
*isakmp_ke_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
79 u_int32_t
, u_int32_t
);
80 static u_char
*isakmp_id_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
81 u_int32_t
, u_int32_t
);
82 static u_char
*isakmp_cert_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
83 u_int32_t
, u_int32_t
);
84 static u_char
*isakmp_cr_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
85 u_int32_t
, u_int32_t
);
86 static u_char
*isakmp_sig_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
87 u_int32_t
, u_int32_t
);
88 static u_char
*isakmp_hash_print(struct isakmp_gen
*, u_char
*,
89 u_int32_t
, u_int32_t
, u_int32_t
);
90 static u_char
*isakmp_nonce_print(struct isakmp_gen
*, u_char
*,
91 u_int32_t
, u_int32_t
, u_int32_t
);
92 static u_char
*isakmp_n_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
93 u_int32_t
, u_int32_t
);
94 static u_char
*isakmp_d_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
95 u_int32_t
, u_int32_t
);
96 static u_char
*isakmp_vid_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
97 u_int32_t
, u_int32_t
);
98 static u_char
*isakmp_sub0_print(u_char
, struct isakmp_gen
*, u_char
*,
99 u_int32_t
, u_int32_t
, u_int32_t
);
100 static u_char
*isakmp_sub_print(u_char
, struct isakmp_gen
*, u_char
*,
101 u_int32_t
, u_int32_t
, u_int32_t
);
102 static char *numstr(int);
104 #define MAXINITIATORS 20
108 struct sockaddr_storage iaddr
;
109 struct sockaddr_storage raddr
;
110 } cookiecache
[MAXINITIATORS
];
113 static char *protoidstr
[] = {
114 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
118 static char *npstr
[] = {
119 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
120 "sig", "nonce", "n", "d", "vid"
124 static u_char
*(*npfunc
[])(struct isakmp_gen
*, u_char
*, u_int32_t
,
125 u_int32_t
, u_int32_t
) = {
143 static char *etypestr
[] = {
144 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
145 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
146 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
147 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
148 "oakley-quick", "oakley-newgroup",
151 #define STR_OR_ID(x, tab) \
152 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
153 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
154 #define NPSTR(x) STR_OR_ID(x, npstr)
155 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
158 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
159 ? npfunc[(x)] : NULL)
162 iszero(u_char
*p
, size_t l
)
171 /* find cookie from initiator cache */
173 cookie_find(cookie_t
*in
)
177 for (i
= 0; i
< MAXINITIATORS
; i
++) {
178 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
185 /* record initiator */
187 cookie_record(cookie_t
*in
, const u_char
*bp2
)
191 struct sockaddr_in
*sin
;
194 struct sockaddr_in6
*sin6
;
199 ninitiator
= (i
+ 1) % MAXINITIATORS
;
203 ip
= (struct ip
*)bp2
;
206 memset(&cookiecache
[ninitiator
].iaddr
, 0,
207 sizeof(cookiecache
[ninitiator
].iaddr
));
208 memset(&cookiecache
[ninitiator
].raddr
, 0,
209 sizeof(cookiecache
[ninitiator
].raddr
));
211 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
212 #ifdef HAVE_SOCKADDR_SA_LEN
213 sin
->sin_len
= sizeof(struct sockaddr_in
);
215 sin
->sin_family
= AF_INET
;
216 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
217 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
218 #ifdef HAVE_SOCKADDR_SA_LEN
219 sin
->sin_len
= sizeof(struct sockaddr_in
);
221 sin
->sin_family
= AF_INET
;
222 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
226 memset(&cookiecache
[ninitiator
].iaddr
, 0,
227 sizeof(cookiecache
[ninitiator
].iaddr
));
228 memset(&cookiecache
[ninitiator
].raddr
, 0,
229 sizeof(cookiecache
[ninitiator
].raddr
));
231 ip6
= (struct ip6_hdr
*)bp2
;
232 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
233 #ifdef HAVE_SOCKADDR_SA_LEN
234 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
236 sin6
->sin6_family
= AF_INET6
;
237 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
238 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
239 #ifdef HAVE_SOCKADDR_SA_LEN
240 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
242 sin6
->sin6_family
= AF_INET6
;
243 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
249 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
250 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
253 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
254 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
256 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
258 struct sockaddr_storage ss
;
261 struct sockaddr_in
*sin
;
264 struct sockaddr_in6
*sin6
;
268 memset(&ss
, 0, sizeof(ss
));
269 ip
= (struct ip
*)bp2
;
272 sin
= (struct sockaddr_in
*)&ss
;
273 #ifdef HAVE_SOCKADDR_SA_LEN
274 sin
->sin_len
= sizeof(struct sockaddr_in
);
276 sin
->sin_family
= AF_INET
;
277 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
281 ip6
= (struct ip6_hdr
*)bp2
;
282 sin6
= (struct sockaddr_in6
*)&ss
;
283 #ifdef HAVE_SOCKADDR_SA_LEN
284 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
286 sin6
->sin6_family
= AF_INET6
;
287 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
294 sa
= (struct sockaddr
*)&ss
;
296 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
298 #ifdef HAVE_SOCKADDR_SA_LEN
302 if (sa
->sa_family
== AF_INET6
)
303 salen
= sizeof(struct sockaddr_in6
);
305 salen
= sizeof(struct sockaddr
);
307 salen
= sizeof(struct sockaddr
);
310 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
313 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
315 #ifdef HAVE_SOCKADDR_SA_LEN
319 if (sa
->sa_family
== AF_INET6
)
320 salen
= sizeof(struct sockaddr_in6
);
322 salen
= sizeof(struct sockaddr
);
324 salen
= sizeof(struct sockaddr
);
327 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
334 rawprint(caddr_t loc
, size_t len
)
340 for (i
= 0; i
< len
; i
++)
341 printf("%02x", p
[i
] & 0xff);
347 char *value
[30]; /*XXX*/
351 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
361 totlen
= 4 + ntohs(q
[1]);
362 if (ep
< p
+ totlen
) {
368 t
= ntohs(q
[0]) & 0x7fff;
369 if (map
&& t
< nmap
&& map
[t
].type
)
370 printf("type=%s ", map
[t
].type
);
372 printf("type=#%d ", t
);
376 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
377 printf("%s", map
[t
].value
[v
]);
379 rawprint((caddr_t
)&q
[1], 2);
381 printf("len=%d value=", ntohs(q
[1]));
382 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
389 isakmp_attr_print(u_char
*p
, u_char
*ep
)
399 totlen
= 4 + ntohs(q
[1]);
400 if (ep
< p
+ totlen
) {
406 t
= ntohs(q
[0]) & 0x7fff;
407 printf("type=#%d ", t
);
411 rawprint((caddr_t
)&q
[1], 2);
413 printf("len=%d value=", ntohs(q
[1]));
414 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
421 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
422 u_int32_t doi0
, u_int32_t proto0
)
424 struct isakmp_pl_sa
*p
;
431 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
433 p
= (struct isakmp_pl_sa
*)ext
;
436 printf(" doi=%d", doi
);
437 printf(" situation=%u", (u_int32_t
)ntohl(p
->sit
));
438 return (u_char
*)(p
+ 1);
441 printf(" doi=ipsec");
442 q
= (u_int32_t
*)&p
->sit
;
443 printf(" situation=");
445 if (ntohl(*q
) & 0x01) {
449 if (ntohl(*q
) & 0x02) {
450 printf("%ssecrecy", t
? "+" : "");
453 if (ntohl(*q
) & 0x04)
454 printf("%sintegrity", t
? "+" : "");
458 printf(" ident=%u", (u_int32_t
)ntohl(*q
++));
460 ext
= (struct isakmp_gen
*)q
;
462 cp
= isakmp_sub_print(ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
);
468 isakmp_p_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
469 u_int32_t doi0
, u_int32_t proto0
)
471 struct isakmp_pl_p
*p
;
474 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
476 p
= (struct isakmp_pl_p
*)ext
;
477 printf(" #%d protoid=%s transform=%d",
478 p
->p_no
, PROTOIDSTR(p
->prot_id
), p
->num_t
);
481 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
484 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + p
->spi_size
);
486 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
492 static char *isakmp_p_map
[] = {
496 static char *ah_p_map
[] = {
497 NULL
, "(reserved)", "md5", "sha", "1des",
500 static char *esp_p_map
[] = {
501 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
502 "blowfish", "3idea", "1des-iv32", "rc4", "null"
505 static char *ipcomp_p_map
[] = {
506 NULL
, "oui", "deflate", "lzs",
509 struct attrmap ipsec_t_map
[] = {
511 { "lifetype", 3, { NULL
, "sec", "kb", }, },
513 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
515 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
516 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
523 struct attrmap oakley_t_map
[] = {
525 { "enc", 7, { NULL
, "1des", "idea", "blowfish", "rc5",
527 { "hash", 4, { NULL
, "md5", "sha1", "tiger", }, },
528 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
529 "rsa enc revised", }, },
530 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
532 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
533 { "group prime", 0, },
534 { "group gen1", 0, },
535 { "group gen2", 0, },
536 { "group curve A", 0, },
537 { "group curve B", 0, },
538 { "lifetype", 3, { NULL
, "sec", "kb", }, },
539 { "lifeduration", 0, },
547 isakmp_t_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
548 u_int32_t doi
, u_int32_t proto
)
550 struct isakmp_pl_t
*p
;
557 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
559 p
= (struct isakmp_pl_t
*)ext
;
563 idstr
= STR_OR_ID(p
->t_id
, isakmp_p_map
);
565 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
568 idstr
= STR_OR_ID(p
->t_id
, ah_p_map
);
570 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
573 idstr
= STR_OR_ID(p
->t_id
, esp_p_map
);
575 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
578 idstr
= STR_OR_ID(p
->t_id
, ipcomp_p_map
);
580 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
590 printf(" #%d id=%s ", p
->t_no
, idstr
);
592 printf(" #%d id=%d ", p
->t_no
, p
->t_id
);
593 cp
= (u_char
*)(p
+ 1);
594 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
595 while (cp
< ep
&& cp
< ep2
) {
597 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
600 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
608 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
609 u_int32_t doi
, u_int32_t proto
)
611 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
613 printf(" key len=%d", ntohs(ext
->len
) - 4);
614 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
616 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
618 return (u_char
*)ext
+ ntohs(ext
->len
);
622 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
623 u_int32_t doi
, u_int32_t proto
)
625 #define USE_IPSECDOI_IN_PHASE1 1
626 struct isakmp_pl_id
*p
;
627 static char *idtypestr
[] = {
628 "IPv4", "IPv4net", "IPv6", "IPv6net",
630 static char *ipsecidtypestr
[] = {
631 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
632 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
638 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
640 p
= (struct isakmp_pl_id
*)ext
;
641 if (sizeof(*p
) < ext
->len
)
642 data
= (u_char
*)(p
+ 1);
645 len
= ntohs(ext
->len
) - sizeof(*p
);
648 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
651 #ifndef USE_IPSECDOI_IN_PHASE1
655 printf(" idtype=%s", STR_OR_ID(p
->d
.id_type
, idtypestr
));
656 printf(" doi_data=%u",
657 (u_int32_t
)(ntohl(p
->d
.doi_data
) & 0xffffff));
660 #ifdef USE_IPSECDOI_IN_PHASE1
665 struct ipsecdoi_id
*p
;
668 p
= (struct ipsecdoi_id
*)ext
;
669 printf(" idtype=%s", STR_OR_ID(p
->type
, ipsecidtypestr
));
672 pe
= getprotobynumber(p
->proto_id
);
674 printf(" protoid=%s", pe
->p_name
);
677 /* it DOES NOT mean IPPROTO_IP! */
678 printf(" protoid=%s", "0");
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_cr_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
785 u_int32_t doi0
, u_int32_t proto0
)
787 struct isakmp_pl_cert
*p
;
788 static char *certstr
[] = {
789 "none", "pkcs7", "pgp", "dns",
790 "x509sign", "x509ke", "kerberos", "crl",
791 "arl", "spki", "x509attr",
794 printf("%s:", NPSTR(ISAKMP_NPTYPE_CR
));
796 p
= (struct isakmp_pl_cert
*)ext
;
797 printf(" len=%d", ntohs(ext
->len
) - 4);
798 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
799 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
801 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
803 return (u_char
*)ext
+ ntohs(ext
->len
);
807 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
808 u_int32_t doi
, u_int32_t proto
)
810 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
812 printf(" len=%d", ntohs(ext
->len
) - 4);
813 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
815 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
817 return (u_char
*)ext
+ ntohs(ext
->len
);
821 isakmp_sig_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
822 u_int32_t doi
, u_int32_t proto
)
824 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
826 printf(" len=%d", ntohs(ext
->len
) - 4);
827 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
829 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
831 return (u_char
*)ext
+ ntohs(ext
->len
);
835 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
836 u_int32_t doi
, u_int32_t proto
)
838 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
840 printf(" n len=%d", ntohs(ext
->len
) - 4);
841 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
843 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
845 return (u_char
*)ext
+ ntohs(ext
->len
);
849 isakmp_n_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_n
*p
;
857 static char *notifystr
[] = {
858 NULL
, "INVALID-PAYLOAD-TYPE",
859 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
860 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
861 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
862 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
863 "INVALID-PROTOCOL-ID", "INVALID-SPI",
864 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
865 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
866 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
867 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
868 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
869 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
870 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
871 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
872 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
873 "UNEQUAL-PAYLOAD-LENGTHS",
875 static char *ipsecnotifystr
[] = {
876 "RESPONDER-LIFETIME", "REPLAY-STATUS",
879 /* NOTE: these macro must be called with x in proper range */
880 #define NOTIFYSTR(x) \
881 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
882 #define IPSECNOTIFYSTR(x) \
883 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
885 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
887 p
= (struct isakmp_pl_n
*)ext
;
891 printf(" doi=%d", doi
);
892 printf(" proto=%d", proto
);
893 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
896 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
898 return (u_char
*)(p
+ 1) + p
->spi_size
;
901 printf(" doi=ipsec");
902 printf(" proto=%s", PROTOIDSTR(proto
));
903 if (ntohs(p
->type
) < 8192)
904 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
905 else if (ntohs(p
->type
) < 16384)
906 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
907 else if (ntohs(p
->type
) < 24576)
908 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
909 else if (ntohs(p
->type
) < 40960)
910 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
912 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
915 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
918 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
919 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
923 switch (ntohs(p
->type
)) {
924 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
926 struct attrmap
*map
= oakley_t_map
;
927 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
928 while (cp
< ep
&& cp
< ep2
) {
929 cp
= isakmp_attrmap_print(cp
,
930 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
934 case IPSECDOI_NTYPE_REPLAY_STATUS
:
935 printf("replay detection %sabled",
936 (*(u_int32_t
*)cp
) ? "en" : "dis");
938 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
939 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
940 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
945 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
950 return (u_char
*)ext
+ ntohs(ext
->len
);
954 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
955 u_int32_t doi0
, u_int32_t proto0
)
957 struct isakmp_pl_d
*p
;
963 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
965 p
= (struct isakmp_pl_d
*)ext
;
969 printf(" doi=%u", doi
);
970 printf(" proto=%u", proto
);
972 printf(" doi=ipsec");
973 printf(" proto=%s", PROTOIDSTR(proto
));
975 printf(" spilen=%u", p
->spi_size
);
976 printf(" nspi=%u", ntohs(p
->num_spi
));
978 q
= (u_int8_t
*)(p
+ 1);
979 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
982 rawprint((caddr_t
)q
, p
->spi_size
);
989 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
990 u_int32_t doi
, u_int32_t proto
)
992 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
994 printf(" len=%d", ntohs(ext
->len
) - 4);
995 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
997 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
999 return (u_char
*)ext
+ ntohs(ext
->len
);
1003 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1004 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1011 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
1013 printf("%s", NPSTR(np
));
1014 cp
+= ntohs(ext
->len
);
1020 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1021 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1024 static int depth
= 0;
1030 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
1031 printf(" [|%s]", NPSTR(np
));
1037 for (i
= 0; i
< depth
; i
++)
1040 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
1045 ext
= (struct isakmp_gen
*)cp
;
1053 static char buf
[20];
1054 snprintf(buf
, sizeof(buf
), "#%d", x
);
1059 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1061 struct isakmp
*base
;
1068 base
= (struct isakmp
*)bp
;
1069 ep
= (u_char
*)snapend
;
1071 if ((struct isakmp
*)ep
< base
+ 1) {
1072 printf("[|isakmp]");
1078 major
= (base
->vers
& ISAKMP_VERS_MAJOR
)
1079 >> ISAKMP_VERS_MAJOR_SHIFT
;
1080 minor
= (base
->vers
& ISAKMP_VERS_MINOR
)
1081 >> ISAKMP_VERS_MINOR_SHIFT
;
1082 printf(" %d.%d", major
, minor
);
1087 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1092 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1094 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1098 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1100 printf(" phase %d", phase
);
1102 printf(" phase %d/others", phase
);
1104 i
= cookie_find(&base
->i_ck
);
1106 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1107 /* the first packet */
1110 cookie_record(&base
->i_ck
, bp2
);
1114 if (bp2
&& cookie_isinitiator(i
, bp2
))
1116 else if (bp2
&& cookie_isresponder(i
, bp2
))
1122 printf(" %s", ETYPESTR(base
->etype
));
1124 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1125 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1130 struct isakmp_gen
*ext
;
1133 #define CHECKLEN(p, np) \
1134 if (ep < (u_char *)(p)) { \
1135 printf(" [|%s]", NPSTR(np)); \
1139 /* regardless of phase... */
1140 if (base
->flags
& ISAKMP_FLAG_E
) {
1142 * encrypted, nothing we can do right now.
1143 * we hope to decrypt the packet in the future...
1145 printf(" [|%s]", NPSTR(base
->np
));
1150 CHECKLEN(base
+ 1, base
->np
)
1153 ext
= (struct isakmp_gen
*)(base
+ 1);
1154 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1159 if (ntohl(base
->len
) != length
) {
1160 printf(" (len mismatch: isakmp %u/ip %d)",
1161 (u_int32_t
)ntohl(base
->len
), length
);