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.31 2002-06-11 17:08:50 itojun Exp $ (LBL)";
42 #include <sys/param.h>
44 #include <sys/socket.h>
46 #include <netinet/in.h>
52 #include "ipsec_doi.h"
54 #include "interface.h"
55 #include "addrtoname.h"
56 #include "extract.h" /* must come after interface.h */
63 #ifndef HAVE_SOCKADDR_STORAGE
64 #define sockaddr_storage sockaddr
67 static u_char
*isakmp_sa_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
68 u_int32_t
, u_int32_t
);
69 static u_char
*isakmp_p_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
70 u_int32_t
, u_int32_t
);
71 static u_char
*isakmp_t_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
72 u_int32_t
, u_int32_t
);
73 static u_char
*isakmp_ke_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
74 u_int32_t
, u_int32_t
);
75 static u_char
*isakmp_id_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
76 u_int32_t
, u_int32_t
);
77 static u_char
*isakmp_cert_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
78 u_int32_t
, u_int32_t
);
79 static u_char
*isakmp_cr_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
80 u_int32_t
, u_int32_t
);
81 static u_char
*isakmp_sig_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
82 u_int32_t
, u_int32_t
);
83 static u_char
*isakmp_hash_print(struct isakmp_gen
*, u_char
*,
84 u_int32_t
, u_int32_t
, u_int32_t
);
85 static u_char
*isakmp_nonce_print(struct isakmp_gen
*, u_char
*,
86 u_int32_t
, u_int32_t
, u_int32_t
);
87 static u_char
*isakmp_n_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
88 u_int32_t
, u_int32_t
);
89 static u_char
*isakmp_d_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
90 u_int32_t
, u_int32_t
);
91 static u_char
*isakmp_vid_print(struct isakmp_gen
*, u_char
*, u_int32_t
,
92 u_int32_t
, u_int32_t
);
93 static u_char
*isakmp_sub0_print(u_char
, struct isakmp_gen
*, u_char
*,
94 u_int32_t
, u_int32_t
, u_int32_t
);
95 static u_char
*isakmp_sub_print(u_char
, struct isakmp_gen
*, u_char
*,
96 u_int32_t
, u_int32_t
, u_int32_t
);
97 static char *numstr(int);
98 static void safememcpy(void *, void *, size_t);
100 #define MAXINITIATORS 20
104 struct sockaddr_storage iaddr
;
105 struct sockaddr_storage raddr
;
106 } cookiecache
[MAXINITIATORS
];
109 static char *protoidstr
[] = {
110 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
114 static char *npstr
[] = {
115 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash",
116 "sig", "nonce", "n", "d", "vid"
120 static u_char
*(*npfunc
[])(struct isakmp_gen
*, u_char
*, u_int32_t
,
121 u_int32_t
, u_int32_t
) = {
139 static char *etypestr
[] = {
140 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
,
141 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
142 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
143 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
144 "oakley-quick", "oakley-newgroup",
147 #define STR_OR_ID(x, tab) \
148 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
149 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
150 #define NPSTR(x) STR_OR_ID(x, npstr)
151 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
154 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
155 ? npfunc[(x)] : NULL)
158 iszero(u_char
*p
, size_t l
)
167 /* find cookie from initiator cache */
169 cookie_find(cookie_t
*in
)
173 for (i
= 0; i
< MAXINITIATORS
; i
++) {
174 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
181 /* record initiator */
183 cookie_record(cookie_t
*in
, const u_char
*bp2
)
187 struct sockaddr_in
*sin
;
190 struct sockaddr_in6
*sin6
;
195 ninitiator
= (i
+ 1) % MAXINITIATORS
;
199 ip
= (struct ip
*)bp2
;
202 memset(&cookiecache
[ninitiator
].iaddr
, 0,
203 sizeof(cookiecache
[ninitiator
].iaddr
));
204 memset(&cookiecache
[ninitiator
].raddr
, 0,
205 sizeof(cookiecache
[ninitiator
].raddr
));
207 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].iaddr
;
208 #ifdef HAVE_SOCKADDR_SA_LEN
209 sin
->sin_len
= sizeof(struct sockaddr_in
);
211 sin
->sin_family
= AF_INET
;
212 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
213 sin
= (struct sockaddr_in
*)&cookiecache
[ninitiator
].raddr
;
214 #ifdef HAVE_SOCKADDR_SA_LEN
215 sin
->sin_len
= sizeof(struct sockaddr_in
);
217 sin
->sin_family
= AF_INET
;
218 memcpy(&sin
->sin_addr
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
222 memset(&cookiecache
[ninitiator
].iaddr
, 0,
223 sizeof(cookiecache
[ninitiator
].iaddr
));
224 memset(&cookiecache
[ninitiator
].raddr
, 0,
225 sizeof(cookiecache
[ninitiator
].raddr
));
227 ip6
= (struct ip6_hdr
*)bp2
;
228 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].iaddr
;
229 #ifdef HAVE_SOCKADDR_SA_LEN
230 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
232 sin6
->sin6_family
= AF_INET6
;
233 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
234 sin6
= (struct sockaddr_in6
*)&cookiecache
[ninitiator
].raddr
;
235 #ifdef HAVE_SOCKADDR_SA_LEN
236 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
238 sin6
->sin6_family
= AF_INET6
;
239 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
245 memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
246 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
249 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
250 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
252 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
254 struct sockaddr_storage ss
;
257 struct sockaddr_in
*sin
;
260 struct sockaddr_in6
*sin6
;
264 memset(&ss
, 0, sizeof(ss
));
265 ip
= (struct ip
*)bp2
;
268 sin
= (struct sockaddr_in
*)&ss
;
269 #ifdef HAVE_SOCKADDR_SA_LEN
270 sin
->sin_len
= sizeof(struct sockaddr_in
);
272 sin
->sin_family
= AF_INET
;
273 memcpy(&sin
->sin_addr
, &ip
->ip_src
, sizeof(ip
->ip_src
));
277 ip6
= (struct ip6_hdr
*)bp2
;
278 sin6
= (struct sockaddr_in6
*)&ss
;
279 #ifdef HAVE_SOCKADDR_SA_LEN
280 sin6
->sin6_len
= sizeof(struct sockaddr_in6
);
282 sin6
->sin6_family
= AF_INET6
;
283 memcpy(&sin6
->sin6_addr
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
290 sa
= (struct sockaddr
*)&ss
;
292 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].iaddr
)->sa_family
)
294 #ifdef HAVE_SOCKADDR_SA_LEN
298 if (sa
->sa_family
== AF_INET6
)
299 salen
= sizeof(struct sockaddr_in6
);
301 salen
= sizeof(struct sockaddr
);
303 salen
= sizeof(struct sockaddr
);
306 if (memcmp(&ss
, &cookiecache
[i
].iaddr
, salen
) == 0)
309 if (sa
->sa_family
!= ((struct sockaddr
*)&cookiecache
[i
].raddr
)->sa_family
)
311 #ifdef HAVE_SOCKADDR_SA_LEN
315 if (sa
->sa_family
== AF_INET6
)
316 salen
= sizeof(struct sockaddr_in6
);
318 salen
= sizeof(struct sockaddr
);
320 salen
= sizeof(struct sockaddr
);
323 if (memcmp(&ss
, &cookiecache
[i
].raddr
, salen
) == 0)
330 rawprint(caddr_t loc
, size_t len
)
336 for (i
= 0; i
< len
; i
++)
337 printf("%02x", p
[i
] & 0xff);
343 char *value
[30]; /*XXX*/
347 isakmp_attrmap_print(u_char
*p
, u_char
*ep
, struct attrmap
*map
, size_t nmap
)
357 totlen
= 4 + ntohs(q
[1]);
358 if (ep
< p
+ totlen
) {
364 t
= ntohs(q
[0]) & 0x7fff;
365 if (map
&& t
< nmap
&& map
[t
].type
)
366 printf("type=%s ", map
[t
].type
);
368 printf("type=#%d ", t
);
372 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
373 printf("%s", map
[t
].value
[v
]);
375 rawprint((caddr_t
)&q
[1], 2);
377 printf("len=%d value=", ntohs(q
[1]));
378 rawprint((caddr_t
)&p
[4], ntohs(q
[1]));
385 isakmp_attr_print(u_char
*p
, u_char
*ep
)
395 totlen
= 4 + ntohs(q
[1]);
396 if (ep
< p
+ totlen
) {
402 t
= ntohs(q
[0]) & 0x7fff;
403 printf("type=#%d ", t
);
407 rawprint((caddr_t
)&q
[1], 2);
409 printf("len=%d value=", ntohs(q
[1]));
410 rawprint((caddr_t
)&p
[2], ntohs(q
[1]));
417 isakmp_sa_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
418 u_int32_t doi0
, u_int32_t proto0
)
420 struct isakmp_pl_sa
*p
, sa
;
422 u_int32_t doi
, sit
, ident
;
426 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
428 p
= (struct isakmp_pl_sa
*)ext
;
429 safememcpy(&sa
, ext
, sizeof(sa
));
433 printf(" doi=%d", doi
);
434 printf(" situation=%u", (u_int32_t
)ntohl(sa
.sit
));
435 return (u_char
*)(p
+ 1);
438 printf(" doi=ipsec");
439 q
= (u_int32_t
*)&sa
.sit
;
440 printf(" situation=");
447 printf("%ssecrecy", t
? "+" : "");
451 printf("%sintegrity", t
? "+" : "");
453 np
= (u_char
*)ext
+ sizeof(sa
);
455 safememcpy(&ident
, ext
+ 1, sizeof(ident
));
456 printf(" ident=%u", (u_int32_t
)ntohl(ident
));
460 ext
= (struct isakmp_gen
*)np
;
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
, prop
;
474 printf("%s:", NPSTR(ISAKMP_NPTYPE_P
));
476 p
= (struct isakmp_pl_p
*)ext
;
477 safememcpy(&prop
, ext
, sizeof(prop
));
478 printf(" #%d protoid=%s transform=%d",
479 prop
.p_no
, PROTOIDSTR(prop
.prot_id
), prop
.num_t
);
482 rawprint((caddr_t
)(p
+ 1), prop
.spi_size
);
485 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
487 cp
= isakmp_sub_print(ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
493 static char *isakmp_p_map
[] = {
497 static char *ah_p_map
[] = {
498 NULL
, "(reserved)", "md5", "sha", "1des",
499 "sha2-256", "sha2-384", "sha2-512",
502 static char *esp_p_map
[] = {
503 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
504 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
507 static char *ipcomp_p_map
[] = {
508 NULL
, "oui", "deflate", "lzs",
511 struct attrmap ipsec_t_map
[] = {
513 { "lifetype", 3, { NULL
, "sec", "kb", }, },
515 { "group desc", 5, { NULL
, "modp768", "modp1024", "EC2N 2^155",
517 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
518 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
525 struct attrmap oakley_t_map
[] = {
527 { "enc", 8, { NULL
, "1des", "idea", "blowfish", "rc5",
528 "3des", "cast", "aes", }, },
529 { "hash", 7, { NULL
, "md5", "sha1", "tiger",
530 "sha2-256", "sha2-384", "sha2-512", }, },
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
, t
;
560 printf("%s:", NPSTR(ISAKMP_NPTYPE_T
));
562 p
= (struct isakmp_pl_t
*)ext
;
563 safememcpy(&t
, ext
, sizeof(t
));
567 idstr
= STR_OR_ID(t
.t_id
, isakmp_p_map
);
569 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
572 idstr
= STR_OR_ID(t
.t_id
, ah_p_map
);
574 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
577 idstr
= STR_OR_ID(t
.t_id
, esp_p_map
);
579 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
582 idstr
= STR_OR_ID(t
.t_id
, ipcomp_p_map
);
584 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
594 printf(" #%d id=%s ", t
.t_no
, idstr
);
596 printf(" #%d id=%d ", t
.t_no
, t
.t_id
);
597 cp
= (u_char
*)(p
+ 1);
598 ep2
= (u_char
*)p
+ ntohs(t
.h
.len
);
599 while (cp
< ep
&& cp
< ep2
) {
601 cp
= isakmp_attrmap_print(cp
, (ep
< ep2
) ? ep
: ep2
,
604 cp
= isakmp_attr_print(cp
, (ep
< ep2
) ? ep
: ep2
);
612 isakmp_ke_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
613 u_int32_t doi
, u_int32_t proto
)
617 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
619 safememcpy(&e
, ext
, sizeof(e
));
620 printf(" key len=%d", ntohs(e
.len
) - 4);
621 if (2 < vflag
&& 4 < ntohs(e
.len
)) {
623 rawprint((caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4);
625 return (u_char
*)ext
+ ntohs(e
.len
);
629 isakmp_id_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
630 u_int32_t doi
, u_int32_t proto
)
632 #define USE_IPSECDOI_IN_PHASE1 1
633 struct isakmp_pl_id
*p
, id
;
634 static char *idtypestr
[] = {
635 "IPv4", "IPv4net", "IPv6", "IPv6net",
637 static char *ipsecidtypestr
[] = {
638 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
639 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
645 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
647 p
= (struct isakmp_pl_id
*)ext
;
648 safememcpy(&id
, ext
, sizeof(id
));
649 if (sizeof(*p
) < id
.h
.len
)
650 data
= (u_char
*)(p
+ 1);
653 len
= ntohs(id
.h
.len
) - sizeof(*p
);
656 printf(" [phase=%d doi=%d proto=%d]", phase
, doi
, proto
);
659 #ifndef USE_IPSECDOI_IN_PHASE1
663 printf(" idtype=%s", STR_OR_ID(id
.d
.id_type
, idtypestr
));
664 printf(" doi_data=%u",
665 (u_int32_t
)(ntohl(id
.d
.doi_data
) & 0xffffff));
668 #ifdef USE_IPSECDOI_IN_PHASE1
673 struct ipsecdoi_id
*p
, id
;
676 p
= (struct ipsecdoi_id
*)ext
;
677 safememcpy(&id
, ext
, sizeof(id
));
678 printf(" idtype=%s", STR_OR_ID(id
.type
, ipsecidtypestr
));
681 pe
= getprotobynumber(id
.proto_id
);
683 printf(" protoid=%s", pe
->p_name
);
686 /* it DOES NOT mean IPPROTO_IP! */
687 printf(" protoid=%s", "0");
689 printf(" port=%d", ntohs(id
.port
));
693 case IPSECDOI_ID_IPV4_ADDR
:
694 printf(" len=%d %s", len
, ipaddr_string(data
));
697 case IPSECDOI_ID_FQDN
:
698 case IPSECDOI_ID_USER_FQDN
:
701 printf(" len=%d ", len
);
702 for (i
= 0; i
< len
; i
++)
703 safeputchar(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
:
755 printf(" len=%d", len
);
758 rawprint((caddr_t
)data
, len
);
761 return (u_char
*)ext
+ ntohs(id
.h
.len
);
765 isakmp_cert_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
766 u_int32_t doi0
, u_int32_t proto0
)
768 struct isakmp_pl_cert
*p
, cert
;
769 static char *certstr
[] = {
770 "none", "pkcs7", "pgp", "dns",
771 "x509sign", "x509ke", "kerberos", "crl",
772 "arl", "spki", "x509attr",
775 printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
777 p
= (struct isakmp_pl_cert
*)ext
;
778 safememcpy(&cert
, ext
, sizeof(cert
));
779 printf(" len=%d", ntohs(cert
.h
.len
) - 4);
780 printf(" type=%s", STR_OR_ID((cert
.encode
), certstr
));
781 if (2 < vflag
&& 4 < ntohs(cert
.h
.len
)) {
783 rawprint((caddr_t
)(ext
+ 1), ntohs(cert
.h
.len
) - 4);
785 return (u_char
*)ext
+ ntohs(cert
.h
.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
, cert
;
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 safememcpy(&cert
, ext
, sizeof(cert
));
803 printf(" len=%d", ntohs(cert
.h
.len
) - 4);
804 printf(" type=%s", STR_OR_ID((cert
.encode
), certstr
));
805 if (2 < vflag
&& 4 < ntohs(cert
.h
.len
)) {
807 rawprint((caddr_t
)(ext
+ 1), ntohs(cert
.h
.len
) - 4);
809 return (u_char
*)ext
+ ntohs(cert
.h
.len
);
813 isakmp_hash_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
814 u_int32_t doi
, u_int32_t proto
)
818 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
820 safememcpy(&e
, ext
, sizeof(e
));
821 printf(" len=%d", ntohs(e
.len
) - 4);
822 if (2 < vflag
&& 4 < ntohs(e
.len
)) {
824 rawprint((caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4);
826 return (u_char
*)ext
+ ntohs(e
.len
);
830 isakmp_sig_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
831 u_int32_t doi
, u_int32_t proto
)
835 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
837 safememcpy(&e
, ext
, sizeof(e
));
838 printf(" len=%d", ntohs(e
.len
) - 4);
839 if (2 < vflag
&& 4 < ntohs(e
.len
)) {
841 rawprint((caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4);
843 return (u_char
*)ext
+ ntohs(e
.len
);
847 isakmp_nonce_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
848 u_int32_t doi
, u_int32_t proto
)
852 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
854 safememcpy(&e
, ext
, sizeof(e
));
855 printf(" n len=%d", ntohs(e
.len
) - 4);
856 if (2 < vflag
&& 4 < ntohs(e
.len
)) {
858 rawprint((caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4);
860 return (u_char
*)ext
+ ntohs(e
.len
);
864 isakmp_n_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
865 u_int32_t doi0
, u_int32_t proto0
)
867 struct isakmp_pl_n
*p
, n
;
872 static char *notifystr
[] = {
873 NULL
, "INVALID-PAYLOAD-TYPE",
874 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
875 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
876 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
877 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
878 "INVALID-PROTOCOL-ID", "INVALID-SPI",
879 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
880 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
881 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
882 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
883 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
884 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
885 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
886 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
887 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
888 "UNEQUAL-PAYLOAD-LENGTHS",
890 static char *ipsecnotifystr
[] = {
891 "RESPONDER-LIFETIME", "REPLAY-STATUS",
894 /* NOTE: these macro must be called with x in proper range */
895 #define NOTIFYSTR(x) \
896 (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr))
897 #define IPSECNOTIFYSTR(x) \
898 (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr))
900 printf("%s:", NPSTR(ISAKMP_NPTYPE_N
));
902 p
= (struct isakmp_pl_n
*)ext
;
903 safememcpy(&n
, ext
, sizeof(n
));
907 printf(" doi=%d", doi
);
908 printf(" proto=%d", proto
);
909 printf(" type=%s", NOTIFYSTR(ntohs(n
.type
)));
912 rawprint((caddr_t
)(p
+ 1), n
.spi_size
);
914 return (u_char
*)(p
+ 1) + n
.spi_size
;
917 printf(" doi=ipsec");
918 printf(" proto=%s", PROTOIDSTR(proto
));
919 if (ntohs(n
.type
) < 8192)
920 printf(" type=%s", NOTIFYSTR(ntohs(n
.type
)));
921 else if (ntohs(n
.type
) < 16384)
922 printf(" type=%s", IPSECNOTIFYSTR(ntohs(n
.type
)));
923 else if (ntohs(n
.type
) < 24576)
924 printf(" type=%s", NOTIFYSTR(ntohs(n
.type
)));
925 else if (ntohs(n
.type
) < 40960)
926 printf(" type=%s", IPSECNOTIFYSTR(ntohs(n
.type
)));
928 printf(" type=%s", NOTIFYSTR(ntohs(n
.type
)));
931 rawprint((caddr_t
)(p
+ 1), n
.spi_size
);
934 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
935 ep2
= (u_char
*)p
+ ntohs(n
.h
.len
);
939 switch (ntohs(n
.type
)) {
940 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
942 struct attrmap
*map
= oakley_t_map
;
943 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
944 while (cp
< ep
&& cp
< ep2
) {
945 cp
= isakmp_attrmap_print(cp
,
946 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
950 case IPSECDOI_NTYPE_REPLAY_STATUS
:
951 printf("replay detection %sabled",
952 (*(u_int32_t
*)cp
) ? "en" : "dis");
954 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
955 isakmp_sub_print(ISAKMP_NPTYPE_SA
,
956 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
);
961 ntohs(n
.h
.len
) - sizeof(*p
) - n
.spi_size
,
966 return (u_char
*)ext
+ ntohs(n
.h
.len
);
970 isakmp_d_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
971 u_int32_t doi0
, u_int32_t proto0
)
973 struct isakmp_pl_d
*p
, d
;
979 printf("%s:", NPSTR(ISAKMP_NPTYPE_D
));
981 p
= (struct isakmp_pl_d
*)ext
;
982 safememcpy(&d
, ext
, sizeof(d
));
986 printf(" doi=%u", doi
);
987 printf(" proto=%u", proto
);
989 printf(" doi=ipsec");
990 printf(" proto=%s", PROTOIDSTR(proto
));
992 printf(" spilen=%u", d
.spi_size
);
993 printf(" nspi=%u", ntohs(d
.num_spi
));
995 q
= (u_int8_t
*)(p
+ 1);
996 for (i
= 0; i
< ntohs(d
.num_spi
); i
++) {
999 rawprint((caddr_t
)q
, d
.spi_size
);
1006 isakmp_vid_print(struct isakmp_gen
*ext
, u_char
*ep
, u_int32_t phase
,
1007 u_int32_t doi
, u_int32_t proto
)
1009 struct isakmp_gen e
;
1011 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
1013 safememcpy(&e
, ext
, sizeof(e
));
1014 printf(" len=%d", ntohs(e
.len
) - 4);
1015 if (2 < vflag
&& 4 < ntohs(e
.len
)) {
1017 rawprint((caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4);
1019 return (u_char
*)ext
+ ntohs(e
.len
);
1023 isakmp_sub0_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1024 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1027 struct isakmp_gen e
;
1030 safememcpy(&e
, ext
, sizeof(e
));
1033 cp
= (*NPFUNC(np
))(ext
, ep
, phase
, doi
, proto
);
1035 printf("%s", NPSTR(np
));
1042 isakmp_sub_print(u_char np
, struct isakmp_gen
*ext
, u_char
*ep
,
1043 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
)
1046 static int depth
= 0;
1048 struct isakmp_gen e
;
1053 safememcpy(&e
, ext
, sizeof(e
));
1055 if (ep
< (u_char
*)ext
+ ntohs(e
.len
)) {
1056 printf(" [|%s]", NPSTR(np
));
1062 for (i
= 0; i
< depth
; i
++)
1065 cp
= isakmp_sub0_print(np
, ext
, ep
, phase
, doi
, proto
);
1070 ext
= (struct isakmp_gen
*)cp
;
1078 static char buf
[20];
1079 snprintf(buf
, sizeof(buf
), "#%d", x
);
1084 * some compiler tries to optimize memcpy(), using the alignment constraint
1085 * on the argument pointer type. by using this function, we try to avoid the
1089 safememcpy(void *p
, void *q
, size_t l
)
1095 isakmp_print(const u_char
*bp
, u_int length
, const u_char
*bp2
)
1097 struct isakmp
*p
, base
;
1104 p
= (struct isakmp
*)bp
;
1105 ep
= (u_char
*)snapend
;
1107 if ((struct isakmp
*)ep
< p
+ 1) {
1108 printf("[|isakmp]");
1112 safememcpy(&base
, p
, sizeof(base
));
1116 major
= (base
.vers
& ISAKMP_VERS_MAJOR
)
1117 >> ISAKMP_VERS_MAJOR_SHIFT
;
1118 minor
= (base
.vers
& ISAKMP_VERS_MINOR
)
1119 >> ISAKMP_VERS_MINOR_SHIFT
;
1120 printf(" %d.%d", major
, minor
);
1125 rawprint((caddr_t
)&base
.msgid
, sizeof(base
.msgid
));
1130 rawprint((caddr_t
)&base
.i_ck
, sizeof(base
.i_ck
));
1132 rawprint((caddr_t
)&base
.r_ck
, sizeof(base
.r_ck
));
1136 phase
= (*(u_int32_t
*)base
.msgid
== 0) ? 1 : 2;
1138 printf(" phase %d", phase
);
1140 printf(" phase %d/others", phase
);
1142 i
= cookie_find(&base
.i_ck
);
1144 if (iszero((u_char
*)&base
.r_ck
, sizeof(base
.r_ck
))) {
1145 /* the first packet */
1148 cookie_record(&base
.i_ck
, bp2
);
1152 if (bp2
&& cookie_isinitiator(i
, bp2
))
1154 else if (bp2
&& cookie_isresponder(i
, bp2
))
1160 printf(" %s", ETYPESTR(base
.etype
));
1162 printf("[%s%s]", base
.flags
& ISAKMP_FLAG_E
? "E" : "",
1163 base
.flags
& ISAKMP_FLAG_C
? "C" : "");
1168 struct isakmp_gen
*ext
;
1171 #define CHECKLEN(p, np) \
1172 if (ep < (u_char *)(p)) { \
1173 printf(" [|%s]", NPSTR(np)); \
1177 /* regardless of phase... */
1178 if (base
.flags
& ISAKMP_FLAG_E
) {
1180 * encrypted, nothing we can do right now.
1181 * we hope to decrypt the packet in the future...
1183 printf(" [encrypted %s]", NPSTR(base
.np
));
1188 CHECKLEN(p
+ 1, base
.np
)
1191 ext
= (struct isakmp_gen
*)(p
+ 1);
1192 isakmp_sub_print(np
, ext
, ep
, phase
, 0, 0);
1197 if (ntohl(base
.len
) != length
) {
1198 printf(" (len mismatch: isakmp %u/ip %d)",
1199 (u_int32_t
)ntohl(base
.len
), length
);