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
31 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: print-isakmp.c,v 1.7 2014/11/20 03:05:03 christos Exp $");
36 #define NETDISSECT_REWORKED
41 /* The functions from print-esp.c used in this file are only defined when both
42 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
44 #ifndef HAVE_OPENSSL_EVP_H
48 #include <tcpdump-stdinc.h>
52 #include "interface.h"
53 #include "addrtoname.h"
54 #include "extract.h" /* must come after interface.h */
61 /* refer to RFC 2408 */
63 typedef u_char cookie_t
[8];
64 typedef u_char msgid_t
[4];
66 #define PORT_ISAKMP 500
68 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
69 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
78 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 cookie_t i_ck
; /* Initiator Cookie */
86 cookie_t r_ck
; /* Responder Cookie */
87 uint8_t np
; /* Next Payload Type */
89 #define ISAKMP_VERS_MAJOR 0xf0
90 #define ISAKMP_VERS_MAJOR_SHIFT 4
91 #define ISAKMP_VERS_MINOR 0x0f
92 #define ISAKMP_VERS_MINOR_SHIFT 0
93 uint8_t etype
; /* Exchange Type */
94 uint8_t flags
; /* Flags */
96 uint32_t len
; /* Length */
99 /* Next Payload Type */
100 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
101 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
102 #define ISAKMP_NPTYPE_P 2 /* Proposal */
103 #define ISAKMP_NPTYPE_T 3 /* Transform */
104 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
105 #define ISAKMP_NPTYPE_ID 5 /* Identification */
106 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
107 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
108 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
109 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
110 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
111 #define ISAKMP_NPTYPE_N 11 /* Notification */
112 #define ISAKMP_NPTYPE_D 12 /* Delete */
113 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
114 #define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
116 #define IKEv1_MAJOR_VERSION 1
117 #define IKEv1_MINOR_VERSION 0
119 #define IKEv2_MAJOR_VERSION 2
120 #define IKEv2_MINOR_VERSION 0
123 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
124 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
125 #define ISAKMP_FLAG_extra 0x04
128 #define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
129 #define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
130 #define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
133 /* 3.2 Payload Generic Header
134 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
135 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136 ! Next Payload ! RESERVED ! Payload Length !
137 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 uint8_t np
; /* Next Payload */
141 uint8_t critical
; /* bit 7 - critical, rest is RESERVED */
142 uint16_t len
; /* Payload Length */
145 /* 3.3 Data Attributes
146 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
147 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 !A! Attribute Type ! AF=0 Attribute Length !
149 !F! ! AF=1 Attribute Value !
150 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151 . AF=0 Attribute Value .
152 . AF=1 Not Transmitted .
153 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
156 uint16_t type
; /* defined by DOI-spec, and Attribute Format */
157 uint16_t lorv
; /* if f equal 1, Attribute Length */
158 /* if f equal 0, Attribute Value */
159 /* if f equal 1, Attribute Value */
162 /* 3.4 Security Association Payload */
163 /* MAY NOT be used, because of being defined in ipsec-doi. */
165 If the current payload is the last in the message,
166 then the value of the next payload field will be 0.
167 This field MUST NOT contain the
168 values for the Proposal or Transform payloads as they are considered
169 part of the security association negotiation. For example, this
170 field would contain the value "10" (Nonce payload) in the first
171 message of a Base Exchange (see Section 4.4) and the value "0" in the
172 first message of an Identity Protect Exchange (see Section 4.5).
176 uint32_t doi
; /* Domain of Interpretation */
177 uint32_t sit
; /* Situation */
180 /* 3.5 Proposal Payload */
182 The value of the next payload field MUST only contain the value "2"
183 or "0". If there are additional Proposal payloads in the message,
184 then this field will be 2. If the current Proposal payload is the
185 last within the security association proposal, then this field will
190 uint8_t p_no
; /* Proposal # */
191 uint8_t prot_id
; /* Protocol */
192 uint8_t spi_size
; /* SPI Size */
193 uint8_t num_t
; /* Number of Transforms */
197 /* 3.6 Transform Payload */
199 The value of the next payload field MUST only contain the value "3"
200 or "0". If there are additional Transform payloads in the proposal,
201 then this field will be 3. If the current Transform payload is the
202 last within the proposal, then this field will be 0.
206 uint8_t t_no
; /* Transform # */
207 uint8_t t_id
; /* Transform-Id */
208 uint16_t reserved
; /* RESERVED2 */
212 /* 3.7 Key Exchange Payload */
215 /* Key Exchange Data */
218 /* 3.8 Identification Payload */
219 /* MUST NOT to be used, because of being defined in ipsec-doi. */
223 uint8_t id_type
; /* ID Type */
224 uint32_t doi_data
; /* DOI Specific ID Data */
226 /* Identification Data */
229 /* 3.9 Certificate Payload */
230 struct ikev1_pl_cert
{
232 uint8_t encode
; /* Cert Encoding */
233 char cert
; /* Certificate Data */
235 This field indicates the type of
236 certificate or certificate-related information contained in the
237 Certificate Data field.
241 /* 3.10 Certificate Request Payload */
244 uint8_t num_cert
; /* # Cert. Types */
246 Certificate Types (variable length)
247 -- Contains a list of the types of certificates requested,
248 sorted in order of preference. Each individual certificate
249 type is 1 octet. This field is NOT requiredo
251 /* # Certificate Authorities (1 octet) */
252 /* Certificate Authorities (variable length) */
255 /* 3.11 Hash Payload */
256 /* may not be used, because of having only data. */
257 struct ikev1_pl_hash
{
262 /* 3.12 Signature Payload */
263 /* may not be used, because of having only data. */
264 struct ikev1_pl_sig
{
269 /* 3.13 Nonce Payload */
270 /* may not be used, because of having only data. */
271 struct ikev1_pl_nonce
{
276 /* 3.14 Notification Payload */
279 uint32_t doi
; /* Domain of Interpretation */
280 uint8_t prot_id
; /* Protocol-ID */
281 uint8_t spi_size
; /* SPI Size */
282 uint16_t type
; /* Notify Message Type */
284 /* Notification Data */
287 /* 3.14.1 Notify Message Types */
288 /* NOTIFY MESSAGES - ERROR TYPES */
289 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
290 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
291 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
292 #define ISAKMP_NTYPE_INVALID_COOKIE 4
293 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
294 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
295 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
296 #define ISAKMP_NTYPE_INVALID_FLAGS 8
297 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
298 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
299 #define ISAKMP_NTYPE_INVALID_SPI 11
300 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
301 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
302 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
303 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
304 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
305 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
306 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
307 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
308 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
309 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
310 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
311 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
312 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
313 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
314 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
316 /* 3.15 Delete Payload */
319 uint32_t doi
; /* Domain of Interpretation */
320 uint8_t prot_id
; /* Protocol-Id */
321 uint8_t spi_size
; /* SPI Size */
322 uint16_t num_spi
; /* # of SPIs */
326 struct ikev1_ph1tab
{
327 struct ikev1_ph1
*head
;
328 struct ikev1_ph1
*tail
;
332 struct isakmp_ph2tab
{
333 struct ikev1_ph2
*head
;
334 struct ikev1_ph2
*tail
;
338 /* IKEv2 (RFC4306) */
340 /* 3.3 Security Association Payload -- generic header */
341 /* 3.3.1. Proposal Substructure */
344 uint8_t p_no
; /* Proposal # */
345 uint8_t prot_id
; /* Protocol */
346 uint8_t spi_size
; /* SPI Size */
347 uint8_t num_t
; /* Number of Transforms */
350 /* 3.3.2. Transform Substructure */
353 uint8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
354 uint8_t res2
; /* reserved byte */
355 uint16_t t_id
; /* Transform ID */
366 /* 3.4. Key Exchange Payload */
375 /* 3.5. Identification Payloads */
387 uint8_t type
; /* ID type */
391 /* Notification Data */
394 /* 3.10 Notification Payload */
397 uint8_t prot_id
; /* Protocol-ID */
398 uint8_t spi_size
; /* SPI Size */
399 uint16_t type
; /* Notify Message Type */
403 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
404 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
405 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
406 IV2_NOTIFY_INVALID_SYNTAX
= 7,
407 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
408 IV2_NOTIFY_INVALID_SPI
=11,
409 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
410 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
411 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
412 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
413 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
414 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
415 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
416 IV2_NOTIFY_INVALID_SELECTORS
=39,
417 IV2_NOTIFY_INITIAL_CONTACT
=16384,
418 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
419 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
420 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
421 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
422 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
423 IV2_NOTIFY_COOKIE
=16390,
424 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
425 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
426 IV2_NOTIFY_REKEY_SA
=16393,
427 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
428 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
431 struct notify_messages
{
436 /* 3.8 Notification Payload */
439 uint8_t auth_method
; /* Protocol-ID */
441 /* authentication data */
444 enum ikev2_auth_type
{
450 /* refer to RFC 2409 */
453 /* isakmp sa structure */
455 uint8_t proto_id
; /* OAKLEY */
456 vchar_t
*spi
; /* spi */
457 uint8_t dhgrp
; /* DH; group */
458 uint8_t auth_t
; /* method of authentication */
459 uint8_t prf_t
; /* type of prf */
460 uint8_t hash_t
; /* type of hash */
461 uint8_t enc_t
; /* type of cipher */
462 uint8_t life_t
; /* type of duration of lifetime */
463 uint32_t ldur
; /* life duration */
467 /* refer to RFC 2407 */
471 /* 4.2 IPSEC Situation Definition */
472 #define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
473 #define IPSECDOI_SIT_SECRECY 0x00000002
474 #define IPSECDOI_SIT_INTEGRITY 0x00000004
476 /* 4.4.1 IPSEC Security Protocol Identifiers */
477 /* 4.4.2 IPSEC ISAKMP Transform Values */
478 #define IPSECDOI_PROTO_ISAKMP 1
479 #define IPSECDOI_KEY_IKE 1
481 /* 4.4.1 IPSEC Security Protocol Identifiers */
482 #define IPSECDOI_PROTO_IPSEC_AH 2
483 /* 4.4.3 IPSEC AH Transform Values */
484 #define IPSECDOI_AH_MD5 2
485 #define IPSECDOI_AH_SHA 3
486 #define IPSECDOI_AH_DES 4
487 #define IPSECDOI_AH_SHA2_256 5
488 #define IPSECDOI_AH_SHA2_384 6
489 #define IPSECDOI_AH_SHA2_512 7
491 /* 4.4.1 IPSEC Security Protocol Identifiers */
492 #define IPSECDOI_PROTO_IPSEC_ESP 3
493 /* 4.4.4 IPSEC ESP Transform Identifiers */
494 #define IPSECDOI_ESP_DES_IV64 1
495 #define IPSECDOI_ESP_DES 2
496 #define IPSECDOI_ESP_3DES 3
497 #define IPSECDOI_ESP_RC5 4
498 #define IPSECDOI_ESP_IDEA 5
499 #define IPSECDOI_ESP_CAST 6
500 #define IPSECDOI_ESP_BLOWFISH 7
501 #define IPSECDOI_ESP_3IDEA 8
502 #define IPSECDOI_ESP_DES_IV32 9
503 #define IPSECDOI_ESP_RC4 10
504 #define IPSECDOI_ESP_NULL 11
505 #define IPSECDOI_ESP_RIJNDAEL 12
506 #define IPSECDOI_ESP_AES 12
508 /* 4.4.1 IPSEC Security Protocol Identifiers */
509 #define IPSECDOI_PROTO_IPCOMP 4
510 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
511 #define IPSECDOI_IPCOMP_OUI 1
512 #define IPSECDOI_IPCOMP_DEFLATE 2
513 #define IPSECDOI_IPCOMP_LZS 3
515 /* 4.5 IPSEC Security Association Attributes */
516 #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
517 #define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
518 #define IPSECDOI_ATTR_SA_LTYPE_SEC 1
519 #define IPSECDOI_ATTR_SA_LTYPE_KB 2
520 #define IPSECDOI_ATTR_SA_LDUR 2 /* V */
521 #define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
522 #define IPSECDOI_ATTR_GRP_DESC 3 /* B */
523 #define IPSECDOI_ATTR_ENC_MODE 4 /* B */
524 /* default value: host dependent */
525 #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
526 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2
527 #define IPSECDOI_ATTR_AUTH 5 /* B */
528 /* 0 means not to use authentication. */
529 #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
530 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
531 #define IPSECDOI_ATTR_AUTH_DES_MAC 3
532 #define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
534 * When negotiating ESP without authentication, the Auth
535 * Algorithm attribute MUST NOT be included in the proposal.
536 * When negotiating ESP without confidentiality, the Auth
537 * Algorithm attribute MUST be included in the proposal and
538 * the ESP transform ID must be ESP_NULL.
540 #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
541 #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
542 #define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
543 #define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
545 /* 4.6.1 Security Association Payload */
548 uint32_t doi
; /* Domain of Interpretation */
549 uint32_t sit
; /* Situation */
552 struct ipsecdoi_secrecy_h
{
557 /* 4.6.2.1 Identification Type Values */
560 uint8_t type
; /* ID Type */
561 uint8_t proto_id
; /* Protocol ID */
562 uint16_t port
; /* Port */
563 /* Identification Data */
566 #define IPSECDOI_ID_IPV4_ADDR 1
567 #define IPSECDOI_ID_FQDN 2
568 #define IPSECDOI_ID_USER_FQDN 3
569 #define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
570 #define IPSECDOI_ID_IPV6_ADDR 5
571 #define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
572 #define IPSECDOI_ID_IPV4_ADDR_RANGE 7
573 #define IPSECDOI_ID_IPV6_ADDR_RANGE 8
574 #define IPSECDOI_ID_DER_ASN1_DN 9
575 #define IPSECDOI_ID_DER_ASN1_GN 10
576 #define IPSECDOI_ID_KEY_ID 11
578 /* 4.6.3 IPSEC DOI Notify Message Types */
579 /* Notify Messages - Status Types */
580 #define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
581 #define IPSECDOI_NTYPE_REPLAY_STATUS 24577
582 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
584 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
585 netdissect_options *ndo, u_char tpay, \
586 const struct isakmp_gen *ext, \
588 const u_char *end_pointer, \
591 uint32_t proto0, int depth)
593 DECLARE_PRINTER(v1_sa
);
594 DECLARE_PRINTER(v1_p
);
595 DECLARE_PRINTER(v1_t
);
596 DECLARE_PRINTER(v1_ke
);
597 DECLARE_PRINTER(v1_id
);
598 DECLARE_PRINTER(v1_cert
);
599 DECLARE_PRINTER(v1_cr
);
600 DECLARE_PRINTER(v1_sig
);
601 DECLARE_PRINTER(v1_hash
);
602 DECLARE_PRINTER(v1_nonce
);
603 DECLARE_PRINTER(v1_n
);
604 DECLARE_PRINTER(v1_d
);
605 DECLARE_PRINTER(v1_vid
);
607 DECLARE_PRINTER(v2_sa
);
608 DECLARE_PRINTER(v2_ke
);
609 DECLARE_PRINTER(v2_ID
);
610 DECLARE_PRINTER(v2_cert
);
611 DECLARE_PRINTER(v2_cr
);
612 DECLARE_PRINTER(v2_auth
);
613 DECLARE_PRINTER(v2_nonce
);
614 DECLARE_PRINTER(v2_n
);
615 DECLARE_PRINTER(v2_d
);
616 DECLARE_PRINTER(v2_vid
);
617 DECLARE_PRINTER(v2_TS
);
618 DECLARE_PRINTER(v2_cp
);
619 DECLARE_PRINTER(v2_eap
);
621 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
624 const struct isakmp_gen
*ext
,
626 const u_char
*end_pointer
,
629 uint32_t proto0
, int depth
);
632 static const u_char
*ike_sub0_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
633 const u_char
*, uint32_t, uint32_t, uint32_t, int);
634 static const u_char
*ikev1_sub_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
635 const u_char
*, uint32_t, uint32_t, uint32_t, int);
637 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
639 u_char np
, const struct isakmp_gen
*ext
,
640 const u_char
*ep
, uint32_t phase
,
641 uint32_t doi
, uint32_t proto
,
645 static char *numstr(int);
648 ikev1_print(netdissect_options
*ndo
,
649 const u_char
*bp
, u_int length
,
650 const u_char
*bp2
, struct isakmp
*base
);
652 #define MAXINITIATORS 20
663 union inaddr_u iaddr
;
664 union inaddr_u raddr
;
665 } cookiecache
[MAXINITIATORS
];
668 static const char *protoidstr
[] = {
669 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
673 static const char *npstr
[] = {
674 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
675 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
676 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
677 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
678 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
679 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
680 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
681 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
682 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
688 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
689 const struct isakmp_gen
*ext
,
691 const u_char
*end_pointer
,
694 uint32_t proto0
, int depth
) = {
708 ikev1_vid_print
, /* 13 */
709 NULL
, NULL
, NULL
, NULL
, NULL
, /* 14- 18 */
710 NULL
, NULL
, NULL
, NULL
, NULL
, /* 19- 23 */
711 NULL
, NULL
, NULL
, NULL
, NULL
, /* 24- 28 */
712 NULL
, NULL
, NULL
, NULL
, /* 29- 32 */
713 ikev2_sa_print
, /* 33 */
714 ikev2_ke_print
, /* 34 */
715 ikev2_ID_print
, /* 35 */
716 ikev2_ID_print
, /* 36 */
717 ikev2_cert_print
, /* 37 */
718 ikev2_cr_print
, /* 38 */
719 ikev2_auth_print
, /* 39 */
720 ikev2_nonce_print
, /* 40 */
721 ikev2_n_print
, /* 41 */
722 ikev2_d_print
, /* 42 */
723 ikev2_vid_print
, /* 43 */
724 ikev2_TS_print
, /* 44 */
725 ikev2_TS_print
, /* 45 */
726 NULL
, /* ikev2_e_print,*/ /* 46 - special */
727 ikev2_cp_print
, /* 47 */
728 ikev2_eap_print
, /* 48 */
732 static const char *etypestr
[] = {
733 /* IKEv1 exchange types */
734 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
, /* 0-7 */
735 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 8-15 */
736 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 16-23 */
737 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 24-31 */
738 "oakley-quick", "oakley-newgroup", /* 32-33 */
739 /* IKEv2 exchange types */
740 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
743 #define STR_OR_ID(x, tab) \
744 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
745 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
746 #define NPSTR(x) STR_OR_ID(x, npstr)
747 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
749 #define CHECKLEN(p, np) \
750 if (ep < (u_char *)(p)) { \
751 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
757 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
758 ? npfunc[(x)] : NULL)
761 iszero(u_char
*p
, size_t l
)
770 /* find cookie from initiator cache */
772 cookie_find(cookie_t
*in
)
776 for (i
= 0; i
< MAXINITIATORS
; i
++) {
777 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
784 /* record initiator */
786 cookie_record(cookie_t
*in
, const u_char
*bp2
)
796 ninitiator
= (i
+ 1) % MAXINITIATORS
;
800 ip
= (struct ip
*)bp2
;
803 cookiecache
[ninitiator
].version
= 4;
804 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in4
, &ip
->ip_src
, sizeof(struct in_addr
));
805 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in4
, &ip
->ip_dst
, sizeof(struct in_addr
));
809 ip6
= (struct ip6_hdr
*)bp2
;
810 cookiecache
[ninitiator
].version
= 6;
811 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in6
, &ip6
->ip6_src
, sizeof(struct in6_addr
));
812 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in6
, &ip6
->ip6_dst
, sizeof(struct in6_addr
));
818 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
819 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
822 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
823 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
825 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
832 ip
= (struct ip
*)bp2
;
835 if (cookiecache
[i
].version
!= 4)
838 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &cookiecache
[i
].iaddr
.in4
, sizeof(struct in_addr
)) == 0)
841 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &cookiecache
[i
].raddr
.in4
, sizeof(struct in_addr
)) == 0)
847 if (cookiecache
[i
].version
!= 6)
849 ip6
= (struct ip6_hdr
*)bp2
;
851 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &cookiecache
[i
].iaddr
.in6
, sizeof(struct in6_addr
)) == 0)
854 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &cookiecache
[i
].raddr
.in6
, sizeof(struct in6_addr
)) == 0)
867 hexprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
873 for (i
= 0; i
< len
; i
++)
874 ND_PRINT((ndo
,"%02x", p
[i
] & 0xff));
878 rawprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
880 ND_TCHECK2(*loc
, len
);
882 hexprint(ndo
, loc
, len
);
890 * returns false if we run out of data buffer
892 static int ike_show_somedata(netdissect_options
*ndo
,
893 const u_char
*cp
, const u_char
*ep
)
895 /* there is too much data, just show some of it */
896 const u_char
*end
= ep
- 20;
903 /* really shouldn't happen because of above */
909 ND_PRINT((ndo
," data=("));
910 if(!rawprint(ndo
, (caddr_t
)(cp
), len
)) goto trunc
;
911 ND_PRINT((ndo
, "..."));
913 if(!rawprint(ndo
, (caddr_t
)(end
), elen
)) goto trunc
;
925 const char *value
[30]; /*XXX*/
928 static const u_char
*
929 ikev1_attrmap_print(netdissect_options
*ndo
,
930 const u_char
*p
, const u_char
*ep
,
931 const struct attrmap
*map
, size_t nmap
)
939 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
940 if (ep
< p
+ totlen
) {
941 ND_PRINT((ndo
,"[|attr]"));
946 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
947 if (map
&& t
< nmap
&& map
[t
].type
)
948 ND_PRINT((ndo
,"type=%s ", map
[t
].type
));
950 ND_PRINT((ndo
,"type=#%d ", t
));
952 ND_PRINT((ndo
,"value="));
953 v
= EXTRACT_16BITS(&p
[2]);
954 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
955 ND_PRINT((ndo
,"%s", map
[t
].value
[v
]));
957 rawprint(ndo
, (caddr_t
)&p
[2], 2);
959 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
960 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&p
[2]));
966 static const u_char
*
967 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep
)
975 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
976 if (ep
< p
+ totlen
) {
977 ND_PRINT((ndo
,"[|attr]"));
982 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
983 ND_PRINT((ndo
,"type=#%d ", t
));
985 ND_PRINT((ndo
,"value="));
987 rawprint(ndo
, (caddr_t
)&p
[2], 2);
989 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
990 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&p
[2]));
996 static const u_char
*
997 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
998 const struct isakmp_gen
*ext
,
1000 const u_char
*ep
, uint32_t phase
, uint32_t doi0 _U_
,
1001 uint32_t proto0
, int depth
)
1003 const struct ikev1_pl_sa
*p
;
1004 struct ikev1_pl_sa sa
;
1005 uint32_t doi
, sit
, ident
;
1006 const u_char
*cp
, *np
;
1009 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SA
)));
1011 p
= (struct ikev1_pl_sa
*)ext
;
1013 UNALIGNED_MEMCPY(&sa
, ext
, sizeof(sa
));
1014 doi
= ntohl(sa
.doi
);
1015 sit
= ntohl(sa
.sit
);
1017 ND_PRINT((ndo
," doi=%d", doi
));
1018 ND_PRINT((ndo
," situation=%u", (uint32_t)ntohl(sa
.sit
)));
1019 return (u_char
*)(p
+ 1);
1022 ND_PRINT((ndo
," doi=ipsec"));
1023 ND_PRINT((ndo
," situation="));
1026 ND_PRINT((ndo
,"identity"));
1030 ND_PRINT((ndo
,"%ssecrecy", t
? "+" : ""));
1034 ND_PRINT((ndo
,"%sintegrity", t
? "+" : ""));
1036 np
= (u_char
*)ext
+ sizeof(sa
);
1038 ND_TCHECK2(*(ext
+ 1), sizeof(ident
));
1039 UNALIGNED_MEMCPY(&ident
, ext
+ 1, sizeof(ident
));
1040 ND_PRINT((ndo
," ident=%u", (uint32_t)ntohl(ident
)));
1041 np
+= sizeof(ident
);
1044 ext
= (struct isakmp_gen
*)np
;
1047 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
1052 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SA
)));
1056 static const u_char
*
1057 ikev1_p_print(netdissect_options
*ndo
, u_char tpay _U_
,
1058 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1059 const u_char
*ep
, uint32_t phase
, uint32_t doi0
,
1060 uint32_t proto0 _U_
, int depth
)
1062 const struct ikev1_pl_p
*p
;
1063 struct ikev1_pl_p prop
;
1066 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_P
)));
1068 p
= (struct ikev1_pl_p
*)ext
;
1070 UNALIGNED_MEMCPY(&prop
, ext
, sizeof(prop
));
1071 ND_PRINT((ndo
," #%d protoid=%s transform=%d",
1072 prop
.p_no
, PROTOIDSTR(prop
.prot_id
), prop
.num_t
));
1073 if (prop
.spi_size
) {
1074 ND_PRINT((ndo
," spi="));
1075 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
1079 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1082 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1083 prop
.prot_id
, depth
);
1087 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1091 static const char *ikev1_p_map
[] = {
1095 static const char *ikev2_t_type_map
[]={
1096 NULL
, "encr", "prf", "integ", "dh", "esn"
1099 static const char *ah_p_map
[] = {
1100 NULL
, "(reserved)", "md5", "sha", "1des",
1101 "sha2-256", "sha2-384", "sha2-512",
1104 static const char *prf_p_map
[] = {
1105 NULL
, "hmac-md5", "hmac-sha", "hmac-tiger",
1109 static const char *integ_p_map
[] = {
1110 NULL
, "hmac-md5", "hmac-sha", "dec-mac",
1111 "kpdk-md5", "aes-xcbc"
1114 static const char *esn_p_map
[] = {
1118 static const char *dh_p_map
[] = {
1120 "modp1024", /* group 2 */
1121 "EC2N 2^155", /* group 3 */
1122 "EC2N 2^185", /* group 4 */
1123 "modp1536", /* group 5 */
1124 "iana-grp06", "iana-grp07", /* reserved */
1125 "iana-grp08", "iana-grp09",
1126 "iana-grp10", "iana-grp11",
1127 "iana-grp12", "iana-grp13",
1128 "modp2048", /* group 14 */
1129 "modp3072", /* group 15 */
1130 "modp4096", /* group 16 */
1131 "modp6144", /* group 17 */
1132 "modp8192", /* group 18 */
1135 static const char *esp_p_map
[] = {
1136 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1137 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1140 static const char *ipcomp_p_map
[] = {
1141 NULL
, "oui", "deflate", "lzs",
1144 static const struct attrmap ipsec_t_map
[] = {
1145 { NULL
, 0, { NULL
} },
1146 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1147 { "life", 0, { NULL
} },
1148 { "group desc", 18, { NULL
, "modp768",
1149 "modp1024", /* group 2 */
1150 "EC2N 2^155", /* group 3 */
1151 "EC2N 2^185", /* group 4 */
1152 "modp1536", /* group 5 */
1153 "iana-grp06", "iana-grp07", /* reserved */
1154 "iana-grp08", "iana-grp09",
1155 "iana-grp10", "iana-grp11",
1156 "iana-grp12", "iana-grp13",
1157 "modp2048", /* group 14 */
1158 "modp3072", /* group 15 */
1159 "modp4096", /* group 16 */
1160 "modp6144", /* group 17 */
1161 "modp8192", /* group 18 */
1163 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
1164 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1165 { "keylen", 0, { NULL
} },
1166 { "rounds", 0, { NULL
} },
1167 { "dictsize", 0, { NULL
} },
1168 { "privalg", 0, { NULL
} },
1171 static const struct attrmap encr_t_map
[] = {
1172 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 0, 1 */
1173 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 2, 3 */
1174 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 4, 5 */
1175 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 6, 7 */
1176 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 8, 9 */
1177 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 10,11*/
1178 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 12,13*/
1179 { "keylen", 14, { NULL
}},
1182 static const struct attrmap oakley_t_map
[] = {
1183 { NULL
, 0, { NULL
} },
1184 { "enc", 8, { NULL
, "1des", "idea", "blowfish", "rc5",
1185 "3des", "cast", "aes", }, },
1186 { "hash", 7, { NULL
, "md5", "sha1", "tiger",
1187 "sha2-256", "sha2-384", "sha2-512", }, },
1188 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
1189 "rsa enc revised", }, },
1190 { "group desc", 18, { NULL
, "modp768",
1191 "modp1024", /* group 2 */
1192 "EC2N 2^155", /* group 3 */
1193 "EC2N 2^185", /* group 4 */
1194 "modp1536", /* group 5 */
1195 "iana-grp06", "iana-grp07", /* reserved */
1196 "iana-grp08", "iana-grp09",
1197 "iana-grp10", "iana-grp11",
1198 "iana-grp12", "iana-grp13",
1199 "modp2048", /* group 14 */
1200 "modp3072", /* group 15 */
1201 "modp4096", /* group 16 */
1202 "modp6144", /* group 17 */
1203 "modp8192", /* group 18 */
1205 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
1206 { "group prime", 0, { NULL
} },
1207 { "group gen1", 0, { NULL
} },
1208 { "group gen2", 0, { NULL
} },
1209 { "group curve A", 0, { NULL
} },
1210 { "group curve B", 0, { NULL
} },
1211 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1212 { "lifeduration", 0, { NULL
} },
1213 { "prf", 0, { NULL
} },
1214 { "keylen", 0, { NULL
} },
1215 { "field", 0, { NULL
} },
1216 { "order", 0, { NULL
} },
1219 static const u_char
*
1220 ikev1_t_print(netdissect_options
*ndo
, u_char tpay _U_
,
1221 const struct isakmp_gen
*ext
, u_int item_len
,
1222 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi _U_
,
1223 uint32_t proto
, int depth _U_
)
1225 const struct ikev1_pl_t
*p
;
1226 struct ikev1_pl_t t
;
1229 const struct attrmap
*map
;
1233 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_T
)));
1235 p
= (struct ikev1_pl_t
*)ext
;
1237 UNALIGNED_MEMCPY(&t
, ext
, sizeof(t
));
1241 idstr
= STR_OR_ID(t
.t_id
, ikev1_p_map
);
1243 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1246 idstr
= STR_OR_ID(t
.t_id
, ah_p_map
);
1248 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1251 idstr
= STR_OR_ID(t
.t_id
, esp_p_map
);
1253 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1256 idstr
= STR_OR_ID(t
.t_id
, ipcomp_p_map
);
1258 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1268 ND_PRINT((ndo
," #%d id=%s ", t
.t_no
, idstr
));
1270 ND_PRINT((ndo
," #%d id=%d ", t
.t_no
, t
.t_id
));
1271 cp
= (u_char
*)(p
+ 1);
1272 ep2
= (u_char
*)p
+ item_len
;
1273 while (cp
< ep
&& cp
< ep2
) {
1275 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1278 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1281 ND_PRINT((ndo
,"..."));
1284 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1288 static const u_char
*
1289 ikev1_ke_print(netdissect_options
*ndo
, u_char tpay _U_
,
1290 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1291 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1292 uint32_t proto _U_
, int depth _U_
)
1294 struct isakmp_gen e
;
1296 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_KE
)));
1299 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1300 ND_PRINT((ndo
," key len=%d", ntohs(e
.len
) - 4));
1301 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1302 ND_PRINT((ndo
," "));
1303 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1306 return (u_char
*)ext
+ ntohs(e
.len
);
1308 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_KE
)));
1312 static const u_char
*
1313 ikev1_id_print(netdissect_options
*ndo
, u_char tpay _U_
,
1314 const struct isakmp_gen
*ext
, u_int item_len
,
1315 const u_char
*ep _U_
, uint32_t phase
, uint32_t doi _U_
,
1316 uint32_t proto _U_
, int depth _U_
)
1318 #define USE_IPSECDOI_IN_PHASE1 1
1319 const struct ikev1_pl_id
*p
;
1320 struct ikev1_pl_id id
;
1321 static const char *idtypestr
[] = {
1322 "IPv4", "IPv4net", "IPv6", "IPv6net",
1324 static const char *ipsecidtypestr
[] = {
1325 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1326 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1332 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_ID
)));
1334 p
= (struct ikev1_pl_id
*)ext
;
1336 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
1337 if (sizeof(*p
) < item_len
) {
1338 data
= (u_char
*)(p
+ 1);
1339 len
= item_len
- sizeof(*p
);
1346 ND_PRINT((ndo
," [phase=%d doi=%d proto=%d]", phase
, doi
, proto
));
1349 #ifndef USE_IPSECDOI_IN_PHASE1
1353 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.d
.id_type
, idtypestr
)));
1354 ND_PRINT((ndo
," doi_data=%u",
1355 (uint32_t)(ntohl(id
.d
.doi_data
) & 0xffffff)));
1358 #ifdef USE_IPSECDOI_IN_PHASE1
1363 const struct ipsecdoi_id
*p
;
1364 struct ipsecdoi_id id
;
1365 struct protoent
*pe
;
1367 p
= (struct ipsecdoi_id
*)ext
;
1369 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
1370 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.type
, ipsecidtypestr
)));
1371 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
1372 pe
= id
.proto_id
? getprotobynumber(id
.proto_id
) : NULL
;
1374 ND_PRINT((ndo
," protoid=%s", pe
->p_name
));
1376 ND_PRINT((ndo
," protoid=%u", id
.proto_id
));
1377 ND_PRINT((ndo
," port=%d", ntohs(id
.port
)));
1382 ND_TCHECK2(*data
, len
);
1384 case IPSECDOI_ID_IPV4_ADDR
:
1386 ND_PRINT((ndo
," len=%d [bad: < 4]", len
));
1388 ND_PRINT((ndo
," len=%d %s", len
, ipaddr_string(ndo
, data
)));
1391 case IPSECDOI_ID_FQDN
:
1392 case IPSECDOI_ID_USER_FQDN
:
1395 ND_PRINT((ndo
," len=%d ", len
));
1396 for (i
= 0; i
< len
; i
++)
1397 safeputchar(ndo
, data
[i
]);
1401 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
1405 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1407 mask
= data
+ sizeof(struct in_addr
);
1408 ND_PRINT((ndo
," len=%d %s/%u.%u.%u.%u", len
,
1409 ipaddr_string(ndo
, data
),
1410 mask
[0], mask
[1], mask
[2], mask
[3]));
1416 case IPSECDOI_ID_IPV6_ADDR
:
1418 ND_PRINT((ndo
," len=%d [bad: < 16]", len
));
1420 ND_PRINT((ndo
," len=%d %s", len
, ip6addr_string(ndo
, data
)));
1423 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
1427 ND_PRINT((ndo
," len=%d [bad: < 20]", len
));
1429 mask
= (u_char
*)(data
+ sizeof(struct in6_addr
));
1431 ND_PRINT((ndo
," len=%d %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len
,
1432 ip6addr_string(ndo
, data
),
1433 mask
[0], mask
[1], mask
[2], mask
[3],
1434 mask
[4], mask
[5], mask
[6], mask
[7],
1435 mask
[8], mask
[9], mask
[10], mask
[11],
1436 mask
[12], mask
[13], mask
[14], mask
[15]));
1442 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1444 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1446 ND_PRINT((ndo
," len=%d %s-%s", len
,
1447 ipaddr_string(ndo
, data
),
1448 ipaddr_string(ndo
, data
+ sizeof(struct in_addr
))));
1453 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1455 ND_PRINT((ndo
," len=%d [bad: < 32]", len
));
1457 ND_PRINT((ndo
," len=%d %s-%s", len
,
1458 ip6addr_string(ndo
, data
),
1459 ip6addr_string(ndo
, data
+ sizeof(struct in6_addr
))));
1464 case IPSECDOI_ID_DER_ASN1_DN
:
1465 case IPSECDOI_ID_DER_ASN1_GN
:
1466 case IPSECDOI_ID_KEY_ID
:
1473 ND_PRINT((ndo
," len=%d", len
));
1474 if (2 < ndo
->ndo_vflag
) {
1475 ND_PRINT((ndo
," "));
1476 if (!rawprint(ndo
, (caddr_t
)data
, len
))
1480 return (u_char
*)ext
+ item_len
;
1482 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_ID
)));
1486 static const u_char
*
1487 ikev1_cert_print(netdissect_options
*ndo
, u_char tpay _U_
,
1488 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1489 const u_char
*ep _U_
, uint32_t phase _U_
,
1491 uint32_t proto0 _U_
, int depth _U_
)
1493 const struct ikev1_pl_cert
*p
;
1494 struct ikev1_pl_cert cert
;
1495 static const char *certstr
[] = {
1496 "none", "pkcs7", "pgp", "dns",
1497 "x509sign", "x509ke", "kerberos", "crl",
1498 "arl", "spki", "x509attr",
1501 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CERT
)));
1503 p
= (struct ikev1_pl_cert
*)ext
;
1505 UNALIGNED_MEMCPY(&cert
, ext
, sizeof(cert
));
1506 ND_PRINT((ndo
," len=%d", item_len
- 4));
1507 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1508 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1509 ND_PRINT((ndo
," "));
1510 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), item_len
- 4))
1513 return (u_char
*)ext
+ item_len
;
1515 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
)));
1519 static const u_char
*
1520 ikev1_cr_print(netdissect_options
*ndo
, u_char tpay _U_
,
1521 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1522 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1523 uint32_t proto0 _U_
, int depth _U_
)
1525 const struct ikev1_pl_cert
*p
;
1526 struct ikev1_pl_cert cert
;
1527 static const char *certstr
[] = {
1528 "none", "pkcs7", "pgp", "dns",
1529 "x509sign", "x509ke", "kerberos", "crl",
1530 "arl", "spki", "x509attr",
1533 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CR
)));
1535 p
= (struct ikev1_pl_cert
*)ext
;
1537 UNALIGNED_MEMCPY(&cert
, ext
, sizeof(cert
));
1538 ND_PRINT((ndo
," len=%d", item_len
- 4));
1539 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1540 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1541 ND_PRINT((ndo
," "));
1542 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), item_len
- 4))
1545 return (u_char
*)ext
+ item_len
;
1547 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CR
)));
1551 static const u_char
*
1552 ikev1_hash_print(netdissect_options
*ndo
, u_char tpay _U_
,
1553 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1554 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1555 uint32_t proto _U_
, int depth _U_
)
1557 struct isakmp_gen e
;
1559 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_HASH
)));
1562 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1563 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1564 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1565 ND_PRINT((ndo
," "));
1566 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1569 return (u_char
*)ext
+ ntohs(e
.len
);
1571 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
)));
1575 static const u_char
*
1576 ikev1_sig_print(netdissect_options
*ndo
, u_char tpay _U_
,
1577 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1578 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1579 uint32_t proto _U_
, int depth _U_
)
1581 struct isakmp_gen e
;
1583 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SIG
)));
1586 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1587 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1588 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1589 ND_PRINT((ndo
," "));
1590 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1593 return (u_char
*)ext
+ ntohs(e
.len
);
1595 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
)));
1599 static const u_char
*
1600 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1601 const struct isakmp_gen
*ext
,
1603 const u_char
*ep _U_
,
1604 uint32_t phase _U_
, uint32_t doi _U_
,
1605 uint32_t proto _U_
, int depth _U_
)
1607 struct isakmp_gen e
;
1609 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1612 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1613 ND_PRINT((ndo
," n len=%d", ntohs(e
.len
) - 4));
1614 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1615 ND_PRINT((ndo
," "));
1616 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1618 } else if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1619 ND_PRINT((ndo
," "));
1620 if (!ike_show_somedata(ndo
, (u_char
*)(caddr_t
)(ext
+ 1), ep
))
1623 return (u_char
*)ext
+ ntohs(e
.len
);
1625 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1629 static const u_char
*
1630 ikev1_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
1631 const struct isakmp_gen
*ext
, u_int item_len
,
1632 const u_char
*ep
, uint32_t phase
, uint32_t doi0 _U_
,
1633 uint32_t proto0 _U_
, int depth
)
1635 struct ikev1_pl_n
*p
, n
;
1640 static const char *notify_error_str
[] = {
1641 NULL
, "INVALID-PAYLOAD-TYPE",
1642 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1643 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1644 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1645 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1646 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1647 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1648 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1649 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1650 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1651 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1652 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1653 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1654 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1655 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1656 "UNEQUAL-PAYLOAD-LENGTHS",
1658 static const char *ipsec_notify_error_str
[] = {
1661 static const char *notify_status_str
[] = {
1664 static const char *ipsec_notify_status_str
[] = {
1665 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1668 /* NOTE: these macro must be called with x in proper range */
1671 #define NOTIFY_ERROR_STR(x) \
1672 STR_OR_ID((x), notify_error_str)
1675 #define IPSEC_NOTIFY_ERROR_STR(x) \
1676 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1679 #define NOTIFY_STATUS_STR(x) \
1680 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1683 #define IPSEC_NOTIFY_STATUS_STR(x) \
1684 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1686 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_N
)));
1688 p
= (struct ikev1_pl_n
*)ext
;
1690 UNALIGNED_MEMCPY(&n
, ext
, sizeof(n
));
1694 ND_PRINT((ndo
," doi=%d", doi
));
1695 ND_PRINT((ndo
," proto=%d", proto
));
1696 if (ntohs(n
.type
) < 8192)
1697 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1698 else if (ntohs(n
.type
) < 16384)
1699 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1700 else if (ntohs(n
.type
) < 24576)
1701 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1703 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1705 ND_PRINT((ndo
," spi="));
1706 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1709 return (u_char
*)(p
+ 1) + n
.spi_size
;
1712 ND_PRINT((ndo
," doi=ipsec"));
1713 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1714 if (ntohs(n
.type
) < 8192)
1715 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1716 else if (ntohs(n
.type
) < 16384)
1717 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n
.type
))));
1718 else if (ntohs(n
.type
) < 24576)
1719 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1720 else if (ntohs(n
.type
) < 32768)
1721 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n
.type
))));
1723 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1725 ND_PRINT((ndo
," spi="));
1726 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1730 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
1731 ep2
= (u_char
*)p
+ item_len
;
1734 ND_PRINT((ndo
," orig=("));
1735 switch (ntohs(n
.type
)) {
1736 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
1738 const struct attrmap
*map
= oakley_t_map
;
1739 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1740 while (cp
< ep
&& cp
< ep2
) {
1741 cp
= ikev1_attrmap_print(ndo
, cp
,
1742 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
1746 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1747 ND_PRINT((ndo
,"replay detection %sabled",
1748 EXTRACT_32BITS(cp
) ? "en" : "dis"));
1750 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
1751 if (ikev1_sub_print(ndo
, ISAKMP_NPTYPE_SA
,
1752 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
,
1758 isakmp_print(ndo
, cp
,
1759 item_len
- sizeof(*p
) - n
.spi_size
,
1762 ND_PRINT((ndo
,")"));
1764 return (u_char
*)ext
+ item_len
;
1766 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
1770 static const u_char
*
1771 ikev1_d_print(netdissect_options
*ndo
, u_char tpay _U_
,
1772 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1773 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1774 uint32_t proto0 _U_
, int depth _U_
)
1776 const struct ikev1_pl_d
*p
;
1777 struct ikev1_pl_d d
;
1783 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_D
)));
1785 p
= (struct ikev1_pl_d
*)ext
;
1787 UNALIGNED_MEMCPY(&d
, ext
, sizeof(d
));
1791 ND_PRINT((ndo
," doi=%u", doi
));
1792 ND_PRINT((ndo
," proto=%u", proto
));
1794 ND_PRINT((ndo
," doi=ipsec"));
1795 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1797 ND_PRINT((ndo
," spilen=%u", d
.spi_size
));
1798 ND_PRINT((ndo
," nspi=%u", ntohs(d
.num_spi
)));
1799 ND_PRINT((ndo
," spi="));
1800 q
= (uint8_t *)(p
+ 1);
1801 for (i
= 0; i
< ntohs(d
.num_spi
); i
++) {
1803 ND_PRINT((ndo
,","));
1804 if (!rawprint(ndo
, (caddr_t
)q
, d
.spi_size
))
1810 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_D
)));
1814 static const u_char
*
1815 ikev1_vid_print(netdissect_options
*ndo
, u_char tpay _U_
,
1816 const struct isakmp_gen
*ext
,
1817 u_int item_len _U_
, const u_char
*ep _U_
,
1818 uint32_t phase _U_
, uint32_t doi _U_
,
1819 uint32_t proto _U_
, int depth _U_
)
1821 struct isakmp_gen e
;
1823 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_VID
)));
1826 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1827 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1828 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1829 ND_PRINT((ndo
," "));
1830 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1833 return (u_char
*)ext
+ ntohs(e
.len
);
1835 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_VID
)));
1839 /************************************************************/
1841 /* IKE v2 - rfc4306 - dissector */
1843 /************************************************************/
1846 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, int critical
)
1848 ND_PRINT((ndo
,"%s%s:", payname
, critical
&0x80 ? "[C]" : ""));
1851 static const u_char
*
1852 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1853 const struct isakmp_gen
*ext
)
1855 struct isakmp_gen e
;
1858 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1859 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
1861 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1862 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1863 ND_PRINT((ndo
," "));
1864 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1867 return (u_char
*)ext
+ ntohs(e
.len
);
1869 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
1873 static const u_char
*
1874 ikev2_t_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount
,
1875 const struct isakmp_gen
*ext
, u_int item_len
,
1876 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi _U_
,
1877 uint32_t proto _U_
, int depth _U_
)
1879 const struct ikev2_t
*p
;
1884 const struct attrmap
*map
;
1888 p
= (struct ikev2_t
*)ext
;
1890 UNALIGNED_MEMCPY(&t
, ext
, sizeof(t
));
1891 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), t
.h
.critical
);
1893 t_id
= ntohs(t
.t_id
);
1900 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1902 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1906 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1910 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1914 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1918 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1927 ND_PRINT((ndo
," #%u type=%s id=%s ", pcount
,
1928 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1931 ND_PRINT((ndo
," #%u type=%s id=%u ", pcount
,
1932 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1934 cp
= (u_char
*)(p
+ 1);
1935 ep2
= (u_char
*)p
+ item_len
;
1936 while (cp
< ep
&& cp
< ep2
) {
1938 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1941 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1944 ND_PRINT((ndo
,"..."));
1947 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1951 static const u_char
*
1952 ikev2_p_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount _U_
,
1953 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1954 const u_char
*ep
, uint32_t phase
, uint32_t doi0
,
1955 uint32_t proto0 _U_
, int depth
)
1957 const struct ikev2_p
*p
;
1958 struct ikev2_p prop
;
1961 p
= (struct ikev2_p
*)ext
;
1963 UNALIGNED_MEMCPY(&prop
, ext
, sizeof(prop
));
1964 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), prop
.h
.critical
);
1966 ND_PRINT((ndo
," #%u protoid=%s transform=%d len=%u",
1967 prop
.p_no
, PROTOIDSTR(prop
.prot_id
),
1968 prop
.num_t
, ntohs(prop
.h
.len
)));
1969 if (prop
.spi_size
) {
1970 ND_PRINT((ndo
," spi="));
1971 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
1975 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1978 cp
= ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1979 prop
.prot_id
, depth
);
1983 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1987 static const u_char
*
1988 ikev2_sa_print(netdissect_options
*ndo
, u_char tpay
,
1989 const struct isakmp_gen
*ext1
,
1990 u_int item_len _U_
, const u_char
*ep _U_
,
1991 uint32_t phase _U_
, uint32_t doi _U_
,
1992 uint32_t proto _U_
, int depth _U_
)
1994 struct isakmp_gen e
;
1995 int osa_length
, sa_length
;
1998 UNALIGNED_MEMCPY(&e
, ext1
, sizeof(e
));
1999 ikev2_pay_print(ndo
, "sa", e
.critical
);
2001 osa_length
= ntohs(e
.len
);
2002 sa_length
= osa_length
- 4;
2003 ND_PRINT((ndo
," len=%d", sa_length
));
2005 ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_P
,
2009 return (u_char
*)ext1
+ osa_length
;
2011 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2015 static const u_char
*
2016 ikev2_ke_print(netdissect_options
*ndo
, u_char tpay
,
2017 const struct isakmp_gen
*ext
,
2018 u_int item_len _U_
, const u_char
*ep _U_
,
2019 uint32_t phase _U_
, uint32_t doi _U_
,
2020 uint32_t proto _U_
, int depth _U_
)
2025 k
= (struct ikev2_ke
*)ext
;
2027 UNALIGNED_MEMCPY(&ke
, ext
, sizeof(ke
));
2028 ikev2_pay_print(ndo
, NPSTR(tpay
), ke
.h
.critical
);
2030 ND_PRINT((ndo
," len=%u group=%s", ntohs(ke
.h
.len
) - 8,
2031 STR_OR_ID(ntohs(ke
.ke_group
), dh_p_map
)));
2033 if (2 < ndo
->ndo_vflag
&& 8 < ntohs(ke
.h
.len
)) {
2034 ND_PRINT((ndo
," "));
2035 if (!rawprint(ndo
, (caddr_t
)(k
+ 1), ntohs(ke
.h
.len
) - 8))
2038 return (u_char
*)ext
+ ntohs(ke
.h
.len
);
2040 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2044 static const u_char
*
2045 ikev2_ID_print(netdissect_options
*ndo
, u_char tpay
,
2046 const struct isakmp_gen
*ext
,
2047 u_int item_len _U_
, const u_char
*ep _U_
,
2048 uint32_t phase _U_
, uint32_t doi _U_
,
2049 uint32_t proto _U_
, int depth _U_
)
2052 int id_len
, idtype_len
, i
;
2053 unsigned int dumpascii
, dumphex
;
2054 unsigned char *typedata
;
2057 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
2058 ikev2_pay_print(ndo
, NPSTR(tpay
), id
.h
.critical
);
2060 id_len
= ntohs(id
.h
.len
);
2062 ND_PRINT((ndo
," len=%d", id_len
- 4));
2063 if (2 < ndo
->ndo_vflag
&& 4 < id_len
) {
2064 ND_PRINT((ndo
," "));
2065 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), id_len
- 4))
2069 idtype_len
=id_len
- sizeof(struct ikev2_id
);
2072 typedata
= (unsigned char *)(ext
)+sizeof(struct ikev2_id
);
2076 ND_PRINT((ndo
, " ipv4:"));
2080 ND_PRINT((ndo
, " fqdn:"));
2083 case ID_RFC822_ADDR
:
2084 ND_PRINT((ndo
, " rfc822:"));
2088 ND_PRINT((ndo
, " ipv6:"));
2091 case ID_DER_ASN1_DN
:
2092 ND_PRINT((ndo
, " dn:"));
2095 case ID_DER_ASN1_GN
:
2096 ND_PRINT((ndo
, " gn:"));
2100 ND_PRINT((ndo
, " keyid:"));
2106 ND_TCHECK2(*typedata
, idtype_len
);
2107 for(i
=0; i
<idtype_len
; i
++) {
2108 if(ND_ISPRINT(typedata
[i
])) {
2109 ND_PRINT((ndo
, "%c", typedata
[i
]));
2111 ND_PRINT((ndo
, "."));
2116 if (!rawprint(ndo
, (caddr_t
)typedata
, idtype_len
))
2120 return (u_char
*)ext
+ id_len
;
2122 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2126 static const u_char
*
2127 ikev2_cert_print(netdissect_options
*ndo
, u_char tpay
,
2128 const struct isakmp_gen
*ext
,
2129 u_int item_len _U_
, const u_char
*ep _U_
,
2130 uint32_t phase _U_
, uint32_t doi _U_
,
2131 uint32_t proto _U_
, int depth _U_
)
2133 return ikev2_gen_print(ndo
, tpay
, ext
);
2136 static const u_char
*
2137 ikev2_cr_print(netdissect_options
*ndo
, u_char tpay
,
2138 const struct isakmp_gen
*ext
,
2139 u_int item_len _U_
, const u_char
*ep _U_
,
2140 uint32_t phase _U_
, uint32_t doi _U_
,
2141 uint32_t proto _U_
, int depth _U_
)
2143 return ikev2_gen_print(ndo
, tpay
, ext
);
2146 static const u_char
*
2147 ikev2_auth_print(netdissect_options
*ndo
, u_char tpay
,
2148 const struct isakmp_gen
*ext
,
2149 u_int item_len _U_
, const u_char
*ep _U_
,
2150 uint32_t phase _U_
, uint32_t doi _U_
,
2151 uint32_t proto _U_
, int depth _U_
)
2153 struct ikev2_auth a
;
2154 const char *v2_auth
[]={ "invalid", "rsasig",
2155 "shared-secret", "dsssig" };
2156 u_char
*authdata
= (u_char
*)ext
+ sizeof(a
);
2160 UNALIGNED_MEMCPY(&a
, ext
, sizeof(a
));
2161 ikev2_pay_print(ndo
, NPSTR(tpay
), a
.h
.critical
);
2162 len
= ntohs(a
.h
.len
);
2164 ND_PRINT((ndo
," len=%d method=%s", len
-4,
2165 STR_OR_ID(a
.auth_method
, v2_auth
)));
2167 if (1 < ndo
->ndo_vflag
&& 4 < len
) {
2168 ND_PRINT((ndo
," authdata=("));
2169 if (!rawprint(ndo
, (caddr_t
)authdata
, len
- sizeof(a
)))
2171 ND_PRINT((ndo
,") "));
2172 } else if(ndo
->ndo_vflag
&& 4 < len
) {
2173 if(!ike_show_somedata(ndo
, authdata
, ep
)) goto trunc
;
2176 return (u_char
*)ext
+ len
;
2178 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2182 static const u_char
*
2183 ikev2_nonce_print(netdissect_options
*ndo
, u_char tpay
,
2184 const struct isakmp_gen
*ext
,
2185 u_int item_len _U_
, const u_char
*ep _U_
,
2186 uint32_t phase _U_
, uint32_t doi _U_
,
2187 uint32_t proto _U_
, int depth _U_
)
2189 struct isakmp_gen e
;
2192 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2193 ikev2_pay_print(ndo
, "nonce", e
.critical
);
2195 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
2196 if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2197 ND_PRINT((ndo
," nonce=("));
2198 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2200 ND_PRINT((ndo
,") "));
2201 } else if(ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2202 if(!ike_show_somedata(ndo
, (const u_char
*)(ext
+1), ep
)) goto trunc
;
2205 return (u_char
*)ext
+ ntohs(e
.len
);
2207 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2211 /* notify payloads */
2212 static const u_char
*
2213 ikev2_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
2214 const struct isakmp_gen
*ext
,
2215 u_int item_len _U_
, const u_char
*ep _U_
,
2216 uint32_t phase _U_
, uint32_t doi _U_
,
2217 uint32_t proto _U_
, int depth _U_
)
2219 struct ikev2_n
*p
, n
;
2221 u_char showspi
, showdata
, showsomedata
;
2222 const char *notify_name
;
2225 p
= (struct ikev2_n
*)ext
;
2227 UNALIGNED_MEMCPY(&n
, ext
, sizeof(n
));
2228 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), n
.h
.critical
);
2235 ND_PRINT((ndo
," prot_id=%s", PROTOIDSTR(n
.prot_id
)));
2237 type
= ntohs(n
.type
);
2239 /* notify space is annoying sparse */
2241 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
2242 notify_name
= "unsupported_critical_payload";
2246 case IV2_NOTIFY_INVALID_IKE_SPI
:
2247 notify_name
= "invalid_ike_spi";
2251 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
2252 notify_name
= "invalid_major_version";
2256 case IV2_NOTIFY_INVALID_SYNTAX
:
2257 notify_name
= "invalid_syntax";
2261 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
2262 notify_name
= "invalid_message_id";
2266 case IV2_NOTIFY_INVALID_SPI
:
2267 notify_name
= "invalid_spi";
2271 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
2272 notify_name
= "no_protocol_chosen";
2276 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
2277 notify_name
= "invalid_ke_payload";
2281 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
2282 notify_name
= "authentication_failed";
2286 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
2287 notify_name
= "single_pair_required";
2291 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
2292 notify_name
= "no_additional_sas";
2296 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
2297 notify_name
= "internal_address_failure";
2301 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
2302 notify_name
= "failed:cp_required";
2306 case IV2_NOTIFY_INVALID_SELECTORS
:
2307 notify_name
= "invalid_selectors";
2311 case IV2_NOTIFY_INITIAL_CONTACT
:
2312 notify_name
= "initial_contact";
2316 case IV2_NOTIFY_SET_WINDOW_SIZE
:
2317 notify_name
= "set_window_size";
2321 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
2322 notify_name
= "additional_ts_possible";
2326 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
2327 notify_name
= "ipcomp_supported";
2331 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
2332 notify_name
= "nat_detection_source_ip";
2336 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
2337 notify_name
= "nat_detection_destination_ip";
2341 case IV2_NOTIFY_COOKIE
:
2342 notify_name
= "cookie";
2348 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
2349 notify_name
= "use_transport_mode";
2353 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
2354 notify_name
= "http_cert_lookup_supported";
2358 case IV2_NOTIFY_REKEY_SA
:
2359 notify_name
= "rekey_sa";
2363 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
2364 notify_name
= "tfc_padding_not_supported";
2368 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
2369 notify_name
= "non_first_fragment_also";
2375 notify_name
="error";
2376 } else if(type
< 16384) {
2377 notify_name
="private-error";
2378 } else if(type
< 40960) {
2379 notify_name
="status";
2381 notify_name
="private-status";
2386 ND_PRINT((ndo
," type=%u(%s)", type
, notify_name
));
2390 if (showspi
&& n
.spi_size
) {
2391 ND_PRINT((ndo
," spi="));
2392 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
2396 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
2398 if(3 < ndo
->ndo_vflag
) {
2402 if ((showdata
|| (showsomedata
&& ep
-cp
< 30)) && cp
< ep
) {
2403 ND_PRINT((ndo
," data=("));
2404 if (!rawprint(ndo
, (caddr_t
)(cp
), ep
- cp
))
2407 ND_PRINT((ndo
,")"));
2409 } else if(showsomedata
&& cp
< ep
) {
2410 if(!ike_show_somedata(ndo
, cp
, ep
)) goto trunc
;
2413 return (u_char
*)ext
+ item_len
;
2415 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
2419 static const u_char
*
2420 ikev2_d_print(netdissect_options
*ndo
, u_char tpay
,
2421 const struct isakmp_gen
*ext
,
2422 u_int item_len _U_
, const u_char
*ep _U_
,
2423 uint32_t phase _U_
, uint32_t doi _U_
,
2424 uint32_t proto _U_
, int depth _U_
)
2426 return ikev2_gen_print(ndo
, tpay
, ext
);
2429 static const u_char
*
2430 ikev2_vid_print(netdissect_options
*ndo
, u_char tpay
,
2431 const struct isakmp_gen
*ext
,
2432 u_int item_len _U_
, const u_char
*ep _U_
,
2433 uint32_t phase _U_
, uint32_t doi _U_
,
2434 uint32_t proto _U_
, int depth _U_
)
2436 struct isakmp_gen e
;
2441 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2442 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2443 ND_PRINT((ndo
," len=%d vid=", ntohs(e
.len
) - 4));
2445 vid
= (const u_char
*)(ext
+1);
2446 len
= ntohs(e
.len
) - 4;
2447 ND_TCHECK2(*vid
, len
);
2448 for(i
=0; i
<len
; i
++) {
2449 if(ND_ISPRINT(vid
[i
])) ND_PRINT((ndo
, "%c", vid
[i
]));
2450 else ND_PRINT((ndo
, "."));
2452 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2453 ND_PRINT((ndo
," "));
2454 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2457 return (u_char
*)ext
+ ntohs(e
.len
);
2459 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2463 static const u_char
*
2464 ikev2_TS_print(netdissect_options
*ndo
, u_char tpay
,
2465 const struct isakmp_gen
*ext
,
2466 u_int item_len _U_
, const u_char
*ep _U_
,
2467 uint32_t phase _U_
, uint32_t doi _U_
,
2468 uint32_t proto _U_
, int depth _U_
)
2470 return ikev2_gen_print(ndo
, tpay
, ext
);
2473 static const u_char
*
2474 ikev2_e_print(netdissect_options
*ndo
,
2475 #ifndef HAVE_LIBCRYPTO
2478 struct isakmp
*base
,
2480 const struct isakmp_gen
*ext
,
2481 u_int item_len _U_
, const u_char
*ep _U_
,
2482 #ifndef HAVE_LIBCRYPTO
2486 #ifndef HAVE_LIBCRYPTO
2490 #ifndef HAVE_LIBCRYPTO
2494 #ifndef HAVE_LIBCRYPTO
2499 struct isakmp_gen e
;
2504 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2505 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2507 dlen
= ntohs(e
.len
)-4;
2509 ND_PRINT((ndo
," len=%d", dlen
));
2510 if (2 < ndo
->ndo_vflag
&& 4 < dlen
) {
2511 ND_PRINT((ndo
," "));
2512 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), dlen
))
2516 dat
= (u_char
*)(ext
+1);
2517 ND_TCHECK2(*dat
, dlen
);
2519 #ifdef HAVE_LIBCRYPTO
2520 /* try to decypt it! */
2521 if(esp_print_decrypt_buffer_by_ikev2(ndo
,
2522 base
->flags
& ISAKMP_FLAG_I
,
2523 base
->i_ck
, base
->r_ck
,
2526 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
2528 /* got it decrypted, print stuff inside. */
2529 ikev2_sub_print(ndo
, base
, e
.np
, ext
, ndo
->ndo_snapend
,
2530 phase
, doi
, proto
, depth
+1);
2535 /* always return NULL, because E must be at end, and NP refers
2536 * to what was inside.
2540 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2544 static const u_char
*
2545 ikev2_cp_print(netdissect_options
*ndo
, u_char tpay
,
2546 const struct isakmp_gen
*ext
,
2547 u_int item_len _U_
, const u_char
*ep _U_
,
2548 uint32_t phase _U_
, uint32_t doi _U_
,
2549 uint32_t proto _U_
, int depth _U_
)
2551 return ikev2_gen_print(ndo
, tpay
, ext
);
2554 static const u_char
*
2555 ikev2_eap_print(netdissect_options
*ndo
, u_char tpay
,
2556 const struct isakmp_gen
*ext
,
2557 u_int item_len _U_
, const u_char
*ep _U_
,
2558 uint32_t phase _U_
, uint32_t doi _U_
,
2559 uint32_t proto _U_
, int depth _U_
)
2561 return ikev2_gen_print(ndo
, tpay
, ext
);
2564 static const u_char
*
2565 ike_sub0_print(netdissect_options
*ndo
,
2566 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2568 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2571 struct isakmp_gen e
;
2576 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2579 * Since we can't have a payload length of less than 4 bytes,
2580 * we need to bail out here if the generic header is nonsensical
2581 * or truncated, otherwise we could loop forever processing
2582 * zero-length items or otherwise misdissect the packet.
2584 item_len
= ntohs(e
.len
);
2590 * XXX - what if item_len is too short, or too long,
2591 * for this payload type?
2593 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2595 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2601 ND_PRINT((ndo
," [|isakmp]"));
2605 static const u_char
*
2606 ikev1_sub_print(netdissect_options
*ndo
,
2607 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2608 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2612 struct isakmp_gen e
;
2614 cp
= (const u_char
*)ext
;
2619 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2621 ND_TCHECK2(*ext
, ntohs(e
.len
));
2624 ND_PRINT((ndo
,"\n"));
2625 for (i
= 0; i
< depth
; i
++)
2626 ND_PRINT((ndo
," "));
2627 ND_PRINT((ndo
,"("));
2628 cp
= ike_sub0_print(ndo
, np
, ext
, ep
, phase
, doi
, proto
, depth
);
2629 ND_PRINT((ndo
,")"));
2633 /* Zero-length subitem */
2638 ext
= (struct isakmp_gen
*)cp
;
2642 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2649 static char buf
[20];
2650 snprintf(buf
, sizeof(buf
), "#%d", x
);
2655 ikev1_print(netdissect_options
*ndo
,
2656 const u_char
*bp
, u_int length
,
2657 const u_char
*bp2
, struct isakmp
*base
)
2659 const struct isakmp
*p
;
2665 p
= (const struct isakmp
*)bp
;
2666 ep
= ndo
->ndo_snapend
;
2668 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2670 ND_PRINT((ndo
," phase %d", phase
));
2672 ND_PRINT((ndo
," phase %d/others", phase
));
2674 i
= cookie_find(&base
->i_ck
);
2676 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
2677 /* the first packet */
2678 ND_PRINT((ndo
," I"));
2680 cookie_record(&base
->i_ck
, bp2
);
2682 ND_PRINT((ndo
," ?"));
2684 if (bp2
&& cookie_isinitiator(i
, bp2
))
2685 ND_PRINT((ndo
," I"));
2686 else if (bp2
&& cookie_isresponder(i
, bp2
))
2687 ND_PRINT((ndo
," R"));
2689 ND_PRINT((ndo
," ?"));
2692 ND_PRINT((ndo
," %s", ETYPESTR(base
->etype
)));
2694 ND_PRINT((ndo
,"[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
2695 base
->flags
& ISAKMP_FLAG_C
? "C" : ""));
2698 if (ndo
->ndo_vflag
) {
2699 const struct isakmp_gen
*ext
;
2701 ND_PRINT((ndo
,":"));
2703 /* regardless of phase... */
2704 if (base
->flags
& ISAKMP_FLAG_E
) {
2706 * encrypted, nothing we can do right now.
2707 * we hope to decrypt the packet in the future...
2709 ND_PRINT((ndo
," [encrypted %s]", NPSTR(base
->np
)));
2713 CHECKLEN(p
+ 1, base
->np
);
2715 ext
= (struct isakmp_gen
*)(p
+ 1);
2716 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
2720 if (ndo
->ndo_vflag
) {
2721 if (ntohl(base
->len
) != length
) {
2722 ND_PRINT((ndo
," (len mismatch: isakmp %u/ip %u)",
2723 (uint32_t)ntohl(base
->len
), length
));
2728 static const u_char
*
2729 ikev2_sub0_print(netdissect_options
*ndo
, struct isakmp
*base
,
2730 u_char np
, int pcount
,
2731 const struct isakmp_gen
*ext
, const u_char
*ep
,
2732 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2735 struct isakmp_gen e
;
2740 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2743 * Since we can't have a payload length of less than 4 bytes,
2744 * we need to bail out here if the generic header is nonsensical
2745 * or truncated, otherwise we could loop forever processing
2746 * zero-length items or otherwise misdissect the packet.
2748 item_len
= ntohs(e
.len
);
2752 if(np
== ISAKMP_NPTYPE_P
) {
2753 cp
= ikev2_p_print(ndo
, np
, pcount
, ext
, item_len
,
2754 ep
, phase
, doi
, proto
, depth
);
2755 } else if(np
== ISAKMP_NPTYPE_T
) {
2756 cp
= ikev2_t_print(ndo
, np
, pcount
, ext
, item_len
,
2757 ep
, phase
, doi
, proto
, depth
);
2758 } else if(np
== ISAKMP_NPTYPE_v2E
) {
2759 cp
= ikev2_e_print(ndo
, base
, np
, ext
, item_len
,
2760 ep
, phase
, doi
, proto
, depth
);
2761 } else if (NPFUNC(np
)) {
2763 * XXX - what if item_len is too short, or too long,
2764 * for this payload type?
2766 cp
= (*npfunc
[np
])(ndo
, np
, /*pcount,*/ ext
, item_len
,
2767 ep
, phase
, doi
, proto
, depth
);
2769 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2775 ND_PRINT((ndo
," [|isakmp]"));
2779 static const u_char
*
2780 ikev2_sub_print(netdissect_options
*ndo
,
2781 struct isakmp
*base
,
2782 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2783 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2788 struct isakmp_gen e
;
2790 cp
= (const u_char
*)ext
;
2796 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2798 ND_TCHECK2(*ext
, ntohs(e
.len
));
2801 ND_PRINT((ndo
,"\n"));
2802 for (i
= 0; i
< depth
; i
++)
2803 ND_PRINT((ndo
," "));
2804 ND_PRINT((ndo
,"("));
2805 cp
= ikev2_sub0_print(ndo
, base
, np
, pcount
,
2806 ext
, ep
, phase
, doi
, proto
, depth
);
2807 ND_PRINT((ndo
,")"));
2811 /* Zero-length subitem */
2816 ext
= (struct isakmp_gen
*)cp
;
2820 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2825 ikev2_print(netdissect_options
*ndo
,
2826 const u_char
*bp
, u_int length
,
2827 const u_char
*bp2 _U_
, struct isakmp
*base
)
2829 const struct isakmp
*p
;
2834 p
= (const struct isakmp
*)bp
;
2835 ep
= ndo
->ndo_snapend
;
2837 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2839 ND_PRINT((ndo
, " parent_sa"));
2841 ND_PRINT((ndo
, " child_sa "));
2843 ND_PRINT((ndo
, " %s", ETYPESTR(base
->etype
)));
2845 ND_PRINT((ndo
, "[%s%s%s]",
2846 base
->flags
& ISAKMP_FLAG_I
? "I" : "",
2847 base
->flags
& ISAKMP_FLAG_V
? "V" : "",
2848 base
->flags
& ISAKMP_FLAG_R
? "R" : ""));
2851 if (ndo
->ndo_vflag
) {
2852 const struct isakmp_gen
*ext
;
2854 ND_PRINT((ndo
, ":"));
2856 /* regardless of phase... */
2857 if (base
->flags
& ISAKMP_FLAG_E
) {
2859 * encrypted, nothing we can do right now.
2860 * we hope to decrypt the packet in the future...
2862 ND_PRINT((ndo
, " [encrypted %s]", NPSTR(base
->np
)));
2866 CHECKLEN(p
+ 1, base
->np
)
2869 ext
= (struct isakmp_gen
*)(p
+ 1);
2870 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
2874 if (ndo
->ndo_vflag
) {
2875 if (ntohl(base
->len
) != length
) {
2876 ND_PRINT((ndo
, " (len mismatch: isakmp %u/ip %u)",
2877 (uint32_t)ntohl(base
->len
), length
));
2883 isakmp_print(netdissect_options
*ndo
,
2884 const u_char
*bp
, u_int length
,
2887 const struct isakmp
*p
;
2892 #ifdef HAVE_LIBCRYPTO
2893 /* initialize SAs */
2894 if (ndo
->ndo_sa_list_head
== NULL
) {
2895 if (ndo
->ndo_espsecret
)
2896 esp_print_decodesecret(ndo
);
2900 p
= (const struct isakmp
*)bp
;
2901 ep
= ndo
->ndo_snapend
;
2903 if ((struct isakmp
*)ep
< p
+ 1) {
2904 ND_PRINT((ndo
,"[|isakmp]"));
2908 UNALIGNED_MEMCPY(&base
, p
, sizeof(base
));
2910 ND_PRINT((ndo
,"isakmp"));
2911 major
= (base
.vers
& ISAKMP_VERS_MAJOR
)
2912 >> ISAKMP_VERS_MAJOR_SHIFT
;
2913 minor
= (base
.vers
& ISAKMP_VERS_MINOR
)
2914 >> ISAKMP_VERS_MINOR_SHIFT
;
2916 if (ndo
->ndo_vflag
) {
2917 ND_PRINT((ndo
," %d.%d", major
, minor
));
2920 if (ndo
->ndo_vflag
) {
2921 ND_PRINT((ndo
," msgid "));
2922 hexprint(ndo
, (caddr_t
)&base
.msgid
, sizeof(base
.msgid
));
2925 if (1 < ndo
->ndo_vflag
) {
2926 ND_PRINT((ndo
," cookie "));
2927 hexprint(ndo
, (caddr_t
)&base
.i_ck
, sizeof(base
.i_ck
));
2928 ND_PRINT((ndo
,"->"));
2929 hexprint(ndo
, (caddr_t
)&base
.r_ck
, sizeof(base
.r_ck
));
2931 ND_PRINT((ndo
,":"));
2934 case IKEv1_MAJOR_VERSION
:
2935 ikev1_print(ndo
, bp
, length
, bp2
, &base
);
2938 case IKEv2_MAJOR_VERSION
:
2939 ikev2_print(ndo
, bp
, length
, bp2
, &base
);
2945 isakmp_rfc3948_print(netdissect_options
*ndo
,
2946 const u_char
*bp
, u_int length
,
2950 if(length
== 1 && bp
[0]==0xff) {
2951 ND_PRINT((ndo
, "isakmp-nat-keep-alive"));
2960 * see if this is an IKE packet
2962 if(bp
[0]==0 && bp
[1]==0 && bp
[2]==0 && bp
[3]==0) {
2963 ND_PRINT((ndo
, "NONESP-encap: "));
2964 isakmp_print(ndo
, bp
+4, length
-4, bp2
);
2968 /* must be an ESP packet */
2970 int nh
, enh
, padlen
;
2973 ND_PRINT((ndo
, "UDP-encap: "));
2975 advance
= esp_print(ndo
, bp
, length
, bp2
, &enh
, &padlen
);
2980 length
-= advance
+ padlen
;
2983 ip_print_inner(ndo
, bp
, length
, nh
, bp2
);
2988 ND_PRINT((ndo
,"[|isakmp]"));
2994 * c-style: whitesmith