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.11 2000-04-24 12:49:11 itojun Exp $ (LBL)";
42 #include <sys/param.h>
44 #include <sys/socket.h>
52 #include <netinet/in.h>
53 #include <netinet/if_ether.h>
54 #include <netinet/in_systm.h>
55 #include <netinet/ip.h>
56 #include <netinet/ip_var.h>
57 #include <netinet/udp.h>
58 #include <netinet/udp_var.h>
59 #include <netinet/tcp.h>
62 #include <netinet/ip6.h>
69 #include "ipsec_doi.h"
71 #include "interface.h"
72 #include "addrtoname.h"
73 #include "extract.h" /* must come after interface.h */
75 #ifndef HAVE_SOCKADDR_STORAGE
76 #define sockaddr_storage sockaddr
79 static u_char
*isakmp_sa_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
));
81 static u_char
*isakmp_p_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
82 u_int32_t
, u_int32_t
));
83 static u_char
*isakmp_t_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
84 u_int32_t
, u_int32_t
));
85 static u_char
*isakmp_ke_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
86 u_int32_t
, u_int32_t
));
87 static u_char
*isakmp_id_print
__P((struct isakmp_gen
*, u_char
*, u_int32_t
,
88 u_int32_t
, u_int32_t
));
89 static u_char
*isakmp_cert_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
));
676 pe
= getprotobynumber(p
->proto_id
);
678 printf(" protoid=%s", pe
->p_name
);
680 printf(" protoid=%s", PROTOIDSTR(p
->proto_id
));
682 printf(" port=%d", ntohs(p
->port
));
686 case IPSECDOI_ID_IPV4_ADDR
:
687 printf(" len=%d %s", len
, ipaddr_string(data
));
690 case IPSECDOI_ID_FQDN
:
691 case IPSECDOI_ID_USER_FQDN
:
694 printf(" len=%d ", len
);
695 for (i
= 0; i
< len
; i
++) {
696 if (isprint(data
[i
]))
697 printf("%c", data
[i
]);
699 printf("\\%03o", data
[i
]);
704 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
707 mask
= data
+ sizeof(struct in_addr
);
708 printf(" len=%d %s/%u.%u.%u.%u", len
,
710 mask
[0], mask
[1], mask
[2], mask
[3]);
715 case IPSECDOI_ID_IPV6_ADDR
:
716 printf(" len=%d %s", len
, ip6addr_string(data
));
719 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
722 mask
= (u_int32_t
*)(data
+ sizeof(struct in6_addr
));
724 printf(" len=%d %s/0x%08x%08x%08x%08x", len
,
725 ip6addr_string(data
),
726 mask
[0], mask
[1], mask
[2], mask
[3]);
731 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
732 printf(" len=%d %s-%s", len
, ipaddr_string(data
),
733 ipaddr_string(data
+ sizeof(struct in_addr
)));
737 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
738 printf(" len=%d %s-%s", len
, ip6addr_string(data
),
739 ip6addr_string(data
+ sizeof(struct in6_addr
)));
743 case IPSECDOI_ID_DER_ASN1_DN
:
744 case IPSECDOI_ID_DER_ASN1_GN
:
745 case IPSECDOI_ID_KEY_ID
:
753 printf(" len=%d", len
);
756 rawprint((caddr_t
)data
, len
);
759 return (u_char
*)ext
+ ntohs(ext
->len
);
763 isakmp_cert_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
764 u_int32_t doi0
, u_int32_t proto0
)
766 struct isakmp_pl_cert
*p
;
767 static char *certstr
[] = {
768 "none", "pkcs7", "pgp", "dns",
769 "x509sign", "x509ke", "kerberos", "crl",
770 "arl", "spki", "x509attr",
773 printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
775 p
= (struct isakmp_pl_cert
*)ext
;
776 printf(" len=%d", ntohs(ext
->len
) - 4);
777 printf(" type=%s", STR_OR_ID((p
->encode
), certstr
));
778 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
780 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
782 return (u_char
*)ext
+ ntohs(ext
->len
);
786 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
787 u_int32_t doi
, u_int32_t proto
)
789 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
791 printf(" len=%d", ntohs(ext
->len
) - 4);
792 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
794 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
796 return (u_char
*)ext
+ ntohs(ext
->len
);
800 isakmp_sig_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
801 u_int32_t doi
, u_int32_t proto
)
803 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
805 printf(" len=%d", ntohs(ext
->len
) - 4);
806 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
808 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
810 return (u_char
*)ext
+ ntohs(ext
->len
);
814 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
815 u_int32_t doi
, u_int32_t proto
)
817 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
819 printf(" n len=%d", ntohs(ext
->len
) - 4);
820 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
822 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
824 return (u_char
*)ext
+ ntohs(ext
->len
);
828 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
829 u_int32_t doi0
, u_int32_t proto0
)
831 struct isakmp_pl_n
*p
;
836 static char *notifystr
[] = {
837 NULL
, "INVALID-PAYLOAD-TYPE",
838 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
839 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
840 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
841 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
842 "INVALID-PROTOCOL-ID", "INVALID-SPI",
843 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
844 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
845 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
846 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
847 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
848 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
849 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
850 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
851 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
852 "UNEQUAL-PAYLOAD-LENGTHS",
854 static char *ipsecnotifystr
[] = {
855 "RESPONDER-LIFETIME", "REPLAY-STATUS",
858 /* NOTE: these macro must be called with x in proper range */
859 #define NOTIFYSTR(x) \
860 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
861 #define IPSECNOTIFYSTR(x) \
862 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
864 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
866 p
= (struct isakmp_pl_n
*)ext
;
870 printf(" doi=%d", doi
);
871 printf(" proto=%d", proto
);
872 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
875 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
877 return (u_char
*)(p
+ 1) + p
->spi_size
;
880 printf(" doi=ipsec");
881 printf(" proto=%s", PROTOIDSTR(proto
));
882 if (ntohs(p
->type
) < 8192)
883 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
884 else if (ntohs(p
->type
) < 16384)
885 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
886 else if (ntohs(p
->type
) < 24576)
887 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
888 else if (ntohs(p
->type
) < 40960)
889 printf(" type=%s", IPSECNOTIFYSTR(ntohs(p
->type
)));
891 printf(" type=%s", NOTIFYSTR(ntohs(p
->type
)));
894 rawprint((caddr_t
)(p
+ 1), p
->spi_size
);
897 cp
= (u_char
*)(p
+ 1) + p
->spi_size
;
898 ep2
= (u_char
*)p
+ ntohs(ext
->len
);
902 switch (ntohs(p
->type
)) {
903 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
905 struct attrmap
*map
= oakley_t_map
;
906 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
907 while (cp
< ep
&& cp
< ep2
) {
908 cp
= isakmp_attrmap_print(cp
,
909 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
913 case IPSECDOI_NTYPE_REPLAY_STATUS
:
914 printf("replay detection %sabled",
915 (*(u_int32_t
*)cp
) ? "en" : "dis");
917 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
918 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
919 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
924 ntohs(ext
->len
) - sizeof(*p
) - p
->spi_size
,
929 return (u_char
*)ext
+ ntohs(ext
->len
);
933 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
934 u_int32_t doi0
, u_int32_t proto0
)
936 struct isakmp_pl_d
*p
;
942 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
944 p
= (struct isakmp_pl_d
*)ext
;
948 printf(" doi=%u", doi
);
949 printf(" proto=%u", proto
);
951 printf(" doi=ipsec");
952 printf(" proto=%s", PROTOIDSTR(proto
));
954 printf(" spilen=%u", p
->spi_size
);
955 printf(" nspi=%u", ntohs(p
->num_spi
));
957 q
= (u_int8_t
*)(p
+ 1);
958 for (i
= 0; i
< ntohs(p
->num_spi
); i
++) {
961 rawprint((caddr_t
)q
, p
->spi_size
);
968 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
969 u_int32_t doi
, u_int32_t proto
)
971 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
973 printf(" len=%d", ntohs(ext
->len
) - 4);
974 if (2 < vflag
&& 4 < ntohs(ext
->len
)) {
976 rawprint((caddr_t
)(ext
+ 1), ntohs(ext
->len
) - 4);
978 return (u_char
*)ext
+ ntohs(ext
->len
);
982 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
983 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
990 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
992 printf("%s", NPSTR(np
));
993 cp
+= ntohs(ext
->len
);
999 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1000 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1003 static int depth
= 0;
1009 if (ep
< (u_char
*)ext
+ ntohs(ext
->len
)) {
1010 printf(" [|%s]", NPSTR(np
));
1016 for (i
= 0; i
< depth
; i
++)
1019 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
1024 ext
= (struct isakmp_gen
*)cp
;
1032 static char buf
[20];
1033 snprintf(buf
, sizeof(buf
), "#%d", x
);
1038 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1040 struct isakmp
*base
;
1047 base
= (struct isakmp
*)bp
;
1048 ep
= (u_char
*)snapend
;
1050 if ((struct isakmp
*)ep
< base
+ 1) {
1051 printf("[|isakmp]");
1057 major
= (base
->vers
& ISAKMP_VERS_MAJOR
)
1058 >> ISAKMP_VERS_MAJOR_SHIFT
;
1059 minor
= (base
->vers
& ISAKMP_VERS_MINOR
)
1060 >> ISAKMP_VERS_MINOR_SHIFT
;
1061 printf(" %d.%d", major
, minor
);
1066 rawprint((caddr_t
)&base
->msgid
, sizeof(base
->msgid
));
1071 rawprint((caddr_t
)&base
->i_ck
, sizeof(base
->i_ck
));
1073 rawprint((caddr_t
)&base
->r_ck
, sizeof(base
->r_ck
));
1077 phase
= (*(u_int32_t
*)base
->msgid
== 0) ? 1 : 2;
1079 printf(" phase %d", phase
);
1081 printf(" phase %d/others", phase
);
1083 i
= cookie_find(&base
->i_ck
);
1085 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
1086 /* the first packet */
1089 cookie_record(&base
->i_ck
, bp2
);
1093 if (bp2
&& cookie_isinitiator(i
, bp2
))
1095 else if (bp2
&& cookie_isresponder(i
, bp2
))
1101 printf(" %s", ETYPESTR(base
->etype
));
1103 printf("[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
1104 base
->flags
& ISAKMP_FLAG_C
? "C" : "");
1109 struct isakmp_gen
*ext
;
1112 #define CHECKLEN(p, np) \
1113 if (ep < (u_char *)(p)) { \
1114 printf(" [|%s]", NPSTR(np)); \
1118 /* regardless of phase... */
1119 if (base
->flags
& ISAKMP_FLAG_E
) {
1121 * encrypted, nothing we can do right now.
1122 * we hope to decrypt the packet in the future...
1124 printf(" [|%s]", NPSTR(base
->np
));
1129 CHECKLEN(base
+ 1, base
->np
)
1132 ext
= (struct isakmp_gen
*)(base
+ 1);
1133 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1138 if (ntohl(base
->len
) != length
) {
1139 printf(" (len mismatch: isakmp %u/ip %d)",
1140 (u_int32_t
)ntohl(base
->len
), length
);