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 /* \summary: Internet Security Association and Key Management Protocol (ISAKMP) printer */
33 /* specification: RFC 2407, RFC 2408, RFC 5996 */
39 /* The functions from print-esp.c used in this file are only defined when both
40 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
42 #ifndef HAVE_OPENSSL_EVP_H
46 #include "netdissect-stdinc.h"
50 #include "netdissect-ctype.h"
52 #include "netdissect.h"
53 #include "addrtoname.h"
60 typedef nd_byte cookie_t
[8];
61 typedef nd_byte msgid_t
[4];
63 #define PORT_ISAKMP 500
65 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
66 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
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 cookie_t i_ck
; /* Initiator Cookie */
83 cookie_t r_ck
; /* Responder Cookie */
84 nd_uint8_t np
; /* Next Payload Type */
86 #define ISAKMP_VERS_MAJOR 0xf0
87 #define ISAKMP_VERS_MAJOR_SHIFT 4
88 #define ISAKMP_VERS_MINOR 0x0f
89 #define ISAKMP_VERS_MINOR_SHIFT 0
90 nd_uint8_t etype
; /* Exchange Type */
91 nd_uint8_t flags
; /* Flags */
93 nd_uint32_t len
; /* Length */
96 /* Next Payload Type */
97 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
98 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
99 #define ISAKMP_NPTYPE_P 2 /* Proposal */
100 #define ISAKMP_NPTYPE_T 3 /* Transform */
101 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
102 #define ISAKMP_NPTYPE_ID 5 /* Identification */
103 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
104 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
105 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
106 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
107 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
108 #define ISAKMP_NPTYPE_N 11 /* Notification */
109 #define ISAKMP_NPTYPE_D 12 /* Delete */
110 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
111 #define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
113 #define IKEv1_MAJOR_VERSION 1
114 #define IKEv1_MINOR_VERSION 0
116 #define IKEv2_MAJOR_VERSION 2
117 #define IKEv2_MINOR_VERSION 0
120 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
121 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
122 #define ISAKMP_FLAG_extra 0x04
125 #define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
126 #define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
127 #define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
130 /* 3.2 Payload Generic Header
131 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
132 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133 ! Next Payload ! RESERVED ! Payload Length !
134 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
137 nd_uint8_t np
; /* Next Payload */
138 nd_uint8_t critical
; /* bit 7 - critical, rest is RESERVED */
139 nd_uint16_t len
; /* Payload Length */
142 /* 3.3 Data Attributes
143 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
144 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 !A! Attribute Type ! AF=0 Attribute Length !
146 !F! ! AF=1 Attribute Value !
147 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 . AF=0 Attribute Value .
149 . AF=1 Not Transmitted .
150 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 nd_uint16_t type
; /* defined by DOI-spec, and Attribute Format */
154 nd_uint16_t lorv
; /* if f equal 1, Attribute Length */
155 /* if f equal 0, Attribute Value */
156 /* if f equal 1, Attribute Value */
159 /* 3.4 Security Association Payload */
160 /* MAY NOT be used, because of being defined in ipsec-doi. */
162 If the current payload is the last in the message,
163 then the value of the next payload field will be 0.
164 This field MUST NOT contain the
165 values for the Proposal or Transform payloads as they are considered
166 part of the security association negotiation. For example, this
167 field would contain the value "10" (Nonce payload) in the first
168 message of a Base Exchange (see Section 4.4) and the value "0" in the
169 first message of an Identity Protect Exchange (see Section 4.5).
173 nd_uint32_t doi
; /* Domain of Interpretation */
174 nd_uint32_t sit
; /* Situation */
177 /* 3.5 Proposal Payload */
179 The value of the next payload field MUST only contain the value "2"
180 or "0". If there are additional Proposal payloads in the message,
181 then this field will be 2. If the current Proposal payload is the
182 last within the security association proposal, then this field will
187 nd_uint8_t p_no
; /* Proposal # */
188 nd_uint8_t prot_id
; /* Protocol */
189 nd_uint8_t spi_size
; /* SPI Size */
190 nd_uint8_t num_t
; /* Number of Transforms */
194 /* 3.6 Transform Payload */
196 The value of the next payload field MUST only contain the value "3"
197 or "0". If there are additional Transform payloads in the proposal,
198 then this field will be 3. If the current Transform payload is the
199 last within the proposal, then this field will be 0.
203 nd_uint8_t t_no
; /* Transform # */
204 nd_uint8_t t_id
; /* Transform-Id */
205 nd_byte reserved
[2]; /* RESERVED2 */
209 /* 3.7 Key Exchange Payload */
212 /* Key Exchange Data */
215 /* 3.8 Identification Payload */
216 /* MUST NOT to be used, because of being defined in ipsec-doi. */
220 nd_uint8_t id_type
; /* ID Type */
221 nd_uint32_t doi_data
; /* DOI Specific ID Data */
223 /* Identification Data */
226 /* 3.9 Certificate Payload */
227 struct ikev1_pl_cert
{
229 nd_uint8_t encode
; /* Cert Encoding */
230 nd_uint8_t cert
; /* Certificate Data */
232 This field indicates the type of
233 certificate or certificate-related information contained in the
234 Certificate Data field.
238 /* 3.10 Certificate Request Payload */
241 nd_uint8_t num_cert
; /* # Cert. Types */
243 Certificate Types (variable length)
244 -- Contains a list of the types of certificates requested,
245 sorted in order of preference. Each individual certificate
246 type is 1 octet. This field is NOT requiredo
248 /* # Certificate Authorities (1 octet) */
249 /* Certificate Authorities (variable length) */
252 /* 3.11 Hash Payload */
253 /* may not be used, because of having only data. */
254 struct ikev1_pl_hash
{
259 /* 3.12 Signature Payload */
260 /* may not be used, because of having only data. */
261 struct ikev1_pl_sig
{
266 /* 3.13 Nonce Payload */
267 /* may not be used, because of having only data. */
268 struct ikev1_pl_nonce
{
273 /* 3.14 Notification Payload */
276 nd_uint32_t doi
; /* Domain of Interpretation */
277 nd_uint8_t prot_id
; /* Protocol-ID */
278 nd_uint8_t spi_size
; /* SPI Size */
279 nd_uint16_t type
; /* Notify Message Type */
281 /* Notification Data */
284 /* 3.14.1 Notify Message Types */
285 /* NOTIFY MESSAGES - ERROR TYPES */
286 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
287 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
288 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
289 #define ISAKMP_NTYPE_INVALID_COOKIE 4
290 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
291 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
292 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
293 #define ISAKMP_NTYPE_INVALID_FLAGS 8
294 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
295 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
296 #define ISAKMP_NTYPE_INVALID_SPI 11
297 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
298 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
299 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
300 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
301 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
302 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
303 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
304 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
305 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
306 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
307 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
308 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
309 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
310 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
311 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
313 /* 3.15 Delete Payload */
316 nd_uint32_t doi
; /* Domain of Interpretation */
317 nd_uint8_t prot_id
; /* Protocol-Id */
318 nd_uint8_t spi_size
; /* SPI Size */
319 nd_uint16_t num_spi
; /* # of SPIs */
323 /* IKEv2 (RFC4306) */
325 /* 3.3 Security Association Payload -- generic header */
326 /* 3.3.1. Proposal Substructure */
329 nd_uint8_t p_no
; /* Proposal # */
330 nd_uint8_t prot_id
; /* Protocol */
331 nd_uint8_t spi_size
; /* SPI Size */
332 nd_uint8_t num_t
; /* Number of Transforms */
335 /* 3.3.2. Transform Substructure */
338 nd_uint8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
339 nd_byte res2
; /* reserved byte */
340 nd_uint16_t t_id
; /* Transform ID */
351 /* 3.4. Key Exchange Payload */
354 nd_uint16_t ke_group
;
360 /* 3.5. Identification Payloads */
372 nd_uint8_t type
; /* ID type */
376 /* Notification Data */
379 /* 3.10 Notification Payload */
382 nd_uint8_t prot_id
; /* Protocol-ID */
383 nd_uint8_t spi_size
; /* SPI Size */
384 nd_uint16_t type
; /* Notify Message Type */
388 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
389 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
390 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
391 IV2_NOTIFY_INVALID_SYNTAX
= 7,
392 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
393 IV2_NOTIFY_INVALID_SPI
=11,
394 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
395 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
396 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
397 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
398 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
399 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
400 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
401 IV2_NOTIFY_INVALID_SELECTORS
=39,
402 IV2_NOTIFY_INITIAL_CONTACT
=16384,
403 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
404 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
405 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
406 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
407 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
408 IV2_NOTIFY_COOKIE
=16390,
409 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
410 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
411 IV2_NOTIFY_REKEY_SA
=16393,
412 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
413 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
416 struct notify_messages
{
421 /* 3.8 Authentication Payload */
424 nd_uint8_t auth_method
; /* Protocol-ID */
426 /* authentication data */
429 enum ikev2_auth_type
{
435 /* refer to RFC 2409 */
438 /* isakmp sa structure */
440 uint8_t proto_id
; /* OAKLEY */
441 vchar_t
*spi
; /* spi */
442 uint8_t dhgrp
; /* DH; group */
443 uint8_t auth_t
; /* method of authentication */
444 uint8_t prf_t
; /* type of prf */
445 uint8_t hash_t
; /* type of hash */
446 uint8_t enc_t
; /* type of cipher */
447 uint8_t life_t
; /* type of duration of lifetime */
448 uint32_t ldur
; /* life duration */
452 /* refer to RFC 2407 */
456 /* 4.2 IPSEC Situation Definition */
457 #define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
458 #define IPSECDOI_SIT_SECRECY 0x00000002
459 #define IPSECDOI_SIT_INTEGRITY 0x00000004
461 /* 4.4.1 IPSEC Security Protocol Identifiers */
462 /* 4.4.2 IPSEC ISAKMP Transform Values */
463 #define IPSECDOI_PROTO_ISAKMP 1
464 #define IPSECDOI_KEY_IKE 1
466 /* 4.4.1 IPSEC Security Protocol Identifiers */
467 #define IPSECDOI_PROTO_IPSEC_AH 2
468 /* 4.4.3 IPSEC AH Transform Values */
469 #define IPSECDOI_AH_MD5 2
470 #define IPSECDOI_AH_SHA 3
471 #define IPSECDOI_AH_DES 4
472 #define IPSECDOI_AH_SHA2_256 5
473 #define IPSECDOI_AH_SHA2_384 6
474 #define IPSECDOI_AH_SHA2_512 7
476 /* 4.4.1 IPSEC Security Protocol Identifiers */
477 #define IPSECDOI_PROTO_IPSEC_ESP 3
478 /* 4.4.4 IPSEC ESP Transform Identifiers */
479 #define IPSECDOI_ESP_DES_IV64 1
480 #define IPSECDOI_ESP_DES 2
481 #define IPSECDOI_ESP_3DES 3
482 #define IPSECDOI_ESP_RC5 4
483 #define IPSECDOI_ESP_IDEA 5
484 #define IPSECDOI_ESP_CAST 6
485 #define IPSECDOI_ESP_BLOWFISH 7
486 #define IPSECDOI_ESP_3IDEA 8
487 #define IPSECDOI_ESP_DES_IV32 9
488 #define IPSECDOI_ESP_RC4 10
489 #define IPSECDOI_ESP_NULL 11
490 #define IPSECDOI_ESP_RIJNDAEL 12
491 #define IPSECDOI_ESP_AES 12
493 /* 4.4.1 IPSEC Security Protocol Identifiers */
494 #define IPSECDOI_PROTO_IPCOMP 4
495 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
496 #define IPSECDOI_IPCOMP_OUI 1
497 #define IPSECDOI_IPCOMP_DEFLATE 2
498 #define IPSECDOI_IPCOMP_LZS 3
500 /* 4.5 IPSEC Security Association Attributes */
501 #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
502 #define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
503 #define IPSECDOI_ATTR_SA_LTYPE_SEC 1
504 #define IPSECDOI_ATTR_SA_LTYPE_KB 2
505 #define IPSECDOI_ATTR_SA_LDUR 2 /* V */
506 #define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
507 #define IPSECDOI_ATTR_GRP_DESC 3 /* B */
508 #define IPSECDOI_ATTR_ENC_MODE 4 /* B */
509 /* default value: host dependent */
510 #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
511 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2
512 #define IPSECDOI_ATTR_AUTH 5 /* B */
513 /* 0 means not to use authentication. */
514 #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
515 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
516 #define IPSECDOI_ATTR_AUTH_DES_MAC 3
517 #define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
519 * When negotiating ESP without authentication, the Auth
520 * Algorithm attribute MUST NOT be included in the proposal.
521 * When negotiating ESP without confidentiality, the Auth
522 * Algorithm attribute MUST be included in the proposal and
523 * the ESP transform ID must be ESP_NULL.
525 #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
526 #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
527 #define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
528 #define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
530 /* 4.6.1 Security Association Payload */
533 nd_uint32_t doi
; /* Domain of Interpretation */
534 nd_uint32_t sit
; /* Situation */
537 struct ipsecdoi_secrecy_h
{
539 nd_uint16_t reserved
;
542 /* 4.6.2.1 Identification Type Values */
545 nd_uint8_t type
; /* ID Type */
546 nd_uint8_t proto_id
; /* Protocol ID */
547 nd_uint16_t port
; /* Port */
548 /* Identification Data */
551 #define IPSECDOI_ID_IPV4_ADDR 1
552 #define IPSECDOI_ID_FQDN 2
553 #define IPSECDOI_ID_USER_FQDN 3
554 #define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
555 #define IPSECDOI_ID_IPV6_ADDR 5
556 #define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
557 #define IPSECDOI_ID_IPV4_ADDR_RANGE 7
558 #define IPSECDOI_ID_IPV6_ADDR_RANGE 8
559 #define IPSECDOI_ID_DER_ASN1_DN 9
560 #define IPSECDOI_ID_DER_ASN1_GN 10
561 #define IPSECDOI_ID_KEY_ID 11
563 /* 4.6.3 IPSEC DOI Notify Message Types */
564 /* Notify Messages - Status Types */
565 #define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
566 #define IPSECDOI_NTYPE_REPLAY_STATUS 24577
567 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
569 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
570 netdissect_options *ndo, u_char tpay, \
571 const struct isakmp_gen *ext, \
573 const u_char *end_pointer, \
576 uint32_t proto0, int depth)
578 DECLARE_PRINTER(v1_sa
);
579 DECLARE_PRINTER(v1_p
);
580 DECLARE_PRINTER(v1_t
);
581 DECLARE_PRINTER(v1_ke
);
582 DECLARE_PRINTER(v1_id
);
583 DECLARE_PRINTER(v1_cert
);
584 DECLARE_PRINTER(v1_cr
);
585 DECLARE_PRINTER(v1_sig
);
586 DECLARE_PRINTER(v1_hash
);
587 DECLARE_PRINTER(v1_nonce
);
588 DECLARE_PRINTER(v1_n
);
589 DECLARE_PRINTER(v1_d
);
590 DECLARE_PRINTER(v1_vid
);
592 DECLARE_PRINTER(v2_sa
);
593 DECLARE_PRINTER(v2_ke
);
594 DECLARE_PRINTER(v2_ID
);
595 DECLARE_PRINTER(v2_cert
);
596 DECLARE_PRINTER(v2_cr
);
597 DECLARE_PRINTER(v2_auth
);
598 DECLARE_PRINTER(v2_nonce
);
599 DECLARE_PRINTER(v2_n
);
600 DECLARE_PRINTER(v2_d
);
601 DECLARE_PRINTER(v2_vid
);
602 DECLARE_PRINTER(v2_TS
);
603 DECLARE_PRINTER(v2_cp
);
604 DECLARE_PRINTER(v2_eap
);
606 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
607 const struct isakmp
*base
,
609 const struct isakmp_gen
*ext
,
611 const u_char
*end_pointer
,
614 uint32_t proto0
, int depth
);
617 static const u_char
*ike_sub0_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
618 const u_char
*, uint32_t, uint32_t, uint32_t, int);
619 static const u_char
*ikev1_sub_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
620 const u_char
*, uint32_t, uint32_t, uint32_t, int);
622 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
623 const struct isakmp
*base
,
624 u_char np
, const struct isakmp_gen
*ext
,
625 const u_char
*ep
, uint32_t phase
,
626 uint32_t doi
, uint32_t proto
,
630 static char *numstr(u_int
);
633 ikev1_print(netdissect_options
*ndo
,
634 const u_char
*bp
, u_int length
,
635 const u_char
*bp2
, const struct isakmp
*base
);
637 #define MAXINITIATORS 20
638 static int ninitiator
= 0;
646 union inaddr_u iaddr
;
647 union inaddr_u raddr
;
648 } cookiecache
[MAXINITIATORS
];
651 static const char *protoidstr
[] = {
652 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
656 static const char *npstr
[] = {
657 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
658 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
659 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
660 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
661 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
662 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
663 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
664 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
665 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
671 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
672 const struct isakmp_gen
*ext
,
674 const u_char
*end_pointer
,
677 uint32_t proto0
, int depth
) = {
691 ikev1_vid_print
, /* 13 */
692 NULL
, NULL
, NULL
, NULL
, NULL
, /* 14- 18 */
693 NULL
, NULL
, NULL
, NULL
, NULL
, /* 19- 23 */
694 NULL
, NULL
, NULL
, NULL
, NULL
, /* 24- 28 */
695 NULL
, NULL
, NULL
, NULL
, /* 29- 32 */
696 ikev2_sa_print
, /* 33 */
697 ikev2_ke_print
, /* 34 */
698 ikev2_ID_print
, /* 35 */
699 ikev2_ID_print
, /* 36 */
700 ikev2_cert_print
, /* 37 */
701 ikev2_cr_print
, /* 38 */
702 ikev2_auth_print
, /* 39 */
703 ikev2_nonce_print
, /* 40 */
704 ikev2_n_print
, /* 41 */
705 ikev2_d_print
, /* 42 */
706 ikev2_vid_print
, /* 43 */
707 ikev2_TS_print
, /* 44 */
708 ikev2_TS_print
, /* 45 */
709 NULL
, /* ikev2_e_print,*/ /* 46 - special */
710 ikev2_cp_print
, /* 47 */
711 ikev2_eap_print
, /* 48 */
715 static const char *etypestr
[] = {
716 /* IKEv1 exchange types */
717 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
, /* 0-7 */
718 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 8-15 */
719 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 16-23 */
720 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 24-31 */
721 "oakley-quick", "oakley-newgroup", /* 32-33 */
722 /* IKEv2 exchange types */
723 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
726 #define STR_OR_ID(x, tab) \
727 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
728 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
729 #define NPSTR(x) STR_OR_ID(x, npstr)
730 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
732 #define CHECKLEN(p, np) \
733 if (ep < (const u_char *)(p)) { \
734 ND_PRINT(" [|%s]", NPSTR(np)); \
740 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
741 ? npfunc[(x)] : NULL)
744 iszero(netdissect_options
*ndo
, const u_char
*p
, size_t l
)
755 /* find cookie from initiator cache */
757 cookie_find(const cookie_t
*in
)
761 for (i
= 0; i
< MAXINITIATORS
; i
++) {
762 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
769 /* record initiator */
771 cookie_record(netdissect_options
*ndo
, const cookie_t
*in
, const u_char
*bp2
)
775 const struct ip6_hdr
*ip6
;
779 ninitiator
= (i
+ 1) % MAXINITIATORS
;
783 ip
= (const struct ip
*)bp2
;
786 cookiecache
[ninitiator
].version
= 4;
787 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in4
,
788 ip
->ip_src
, sizeof(nd_ipv4
));
789 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in4
,
790 ip
->ip_dst
, sizeof(nd_ipv4
));
793 ip6
= (const struct ip6_hdr
*)bp2
;
794 cookiecache
[ninitiator
].version
= 6;
795 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in6
,
796 ip6
->ip6_src
, sizeof(nd_ipv6
));
797 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in6
,
798 ip6
->ip6_dst
, sizeof(nd_ipv6
));
803 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
804 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
807 #define cookie_isinitiator(ndo, x, y) cookie_sidecheck(ndo, (x), (y), 1)
808 #define cookie_isresponder(ndo, x, y) cookie_sidecheck(ndo, (x), (y), 0)
810 cookie_sidecheck(netdissect_options
*ndo
, int i
, const u_char
*bp2
, int initiator
)
813 const struct ip6_hdr
*ip6
;
815 ip
= (const struct ip
*)bp2
;
818 if (cookiecache
[i
].version
!= 4)
821 if (UNALIGNED_MEMCMP(ip
->ip_src
, &cookiecache
[i
].iaddr
.in4
, sizeof(nd_ipv4
)) == 0)
824 if (UNALIGNED_MEMCMP(ip
->ip_src
, &cookiecache
[i
].raddr
.in4
, sizeof(nd_ipv4
)) == 0)
829 if (cookiecache
[i
].version
!= 6)
831 ip6
= (const struct ip6_hdr
*)bp2
;
833 if (UNALIGNED_MEMCMP(ip6
->ip6_src
, &cookiecache
[i
].iaddr
.in6
, sizeof(nd_ipv6
)) == 0)
836 if (UNALIGNED_MEMCMP(ip6
->ip6_src
, &cookiecache
[i
].raddr
.in6
, sizeof(nd_ipv6
)) == 0)
848 hexprint(netdissect_options
*ndo
, const uint8_t *loc
, size_t len
)
854 for (i
= 0; i
< len
; i
++)
855 ND_PRINT("%02x", p
[i
] & 0xff);
859 rawprint(netdissect_options
*ndo
, const uint8_t *loc
, size_t len
)
861 ND_TCHECK_LEN(loc
, len
);
863 hexprint(ndo
, loc
, len
);
871 * returns false if we run out of data buffer
873 static int ike_show_somedata(netdissect_options
*ndo
,
874 const u_char
*cp
, const u_char
*ep
)
876 /* there is too much data, just show some of it */
877 const u_char
*end
= ep
- 20;
879 size_t len
= ep
- cp
;
884 /* really shouldn't happen because of above */
891 if(!rawprint(ndo
, (const uint8_t *)(cp
), len
)) goto trunc
;
894 if(!rawprint(ndo
, (const uint8_t *)(end
), elen
)) goto trunc
;
906 const char *value
[30]; /*XXX*/
909 static const u_char
*
910 ikev1_attrmap_print(netdissect_options
*ndo
,
911 const u_char
*p
, const u_char
*ep2
,
912 const struct attrmap
*map
, size_t nmap
)
917 if (GET_U_1(p
) & 0x80)
920 totlen
= 4 + GET_BE_U_2(p
+ 2);
922 if (ep2
< p
+ totlen
) {
928 t
= GET_BE_U_2(p
) & 0x7fff;
929 if (map
&& t
< nmap
&& map
[t
].type
)
930 ND_PRINT("type=%s ", map
[t
].type
);
932 ND_PRINT("type=#%u ", t
);
933 if (GET_U_1(p
) & 0x80) {
935 v
= GET_BE_U_2(p
+ 2);
936 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
937 ND_PRINT("%s", map
[t
].value
[v
]);
939 if (!rawprint(ndo
, (const uint8_t *)(p
+ 2), 2)) {
945 ND_PRINT("len=%u value=", totlen
- 4);
946 if (!rawprint(ndo
, (const uint8_t *)(p
+ 4), totlen
- 4)) {
958 static const u_char
*
959 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep2
)
964 if (GET_U_1(p
) & 0x80)
967 totlen
= 4 + GET_BE_U_2(p
+ 2);
969 if (ep2
< p
+ totlen
) {
975 t
= GET_BE_U_2(p
) & 0x7fff;
976 ND_PRINT("type=#%u ", t
);
977 if (GET_U_1(p
) & 0x80) {
980 if (!rawprint(ndo
, (const uint8_t *)(p
+ 2), 2)) {
985 ND_PRINT("len=%u value=", totlen
- 4);
986 if (!rawprint(ndo
, (const uint8_t *)(p
+ 4), totlen
- 4)) {
998 static const u_char
*
999 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
1000 const struct isakmp_gen
*ext
,
1002 const u_char
*ep
, uint32_t phase
, uint32_t doi0 _U_
,
1003 uint32_t proto0
, int depth
)
1005 const struct ikev1_pl_sa
*p
;
1006 uint32_t doi
, sit
, ident
;
1007 const u_char
*cp
, *np
;
1010 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
1012 p
= (const struct ikev1_pl_sa
*)ext
;
1014 doi
= GET_BE_U_4(p
->doi
);
1015 sit
= GET_BE_U_4(p
->sit
);
1017 ND_PRINT(" doi=%u", doi
);
1018 ND_PRINT(" situation=%u", sit
);
1019 return (const u_char
*)(p
+ 1);
1022 ND_PRINT(" doi=ipsec");
1023 ND_PRINT(" situation=");
1026 ND_PRINT("identity");
1030 ND_PRINT("%ssecrecy", t
? "+" : "");
1034 ND_PRINT("%sintegrity", t
? "+" : "");
1036 np
= (const u_char
*)ext
+ sizeof(struct ikev1_pl_sa
);
1038 ident
= GET_BE_U_4(ext
+ 1);
1039 ND_PRINT(" ident=%u", ident
);
1040 np
+= sizeof(ident
);
1043 ext
= (const struct isakmp_gen
*)np
;
1044 ND_TCHECK_SIZE(ext
);
1046 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
1051 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA
));
1055 static const u_char
*
1056 ikev1_p_print(netdissect_options
*ndo
, u_char tpay _U_
,
1057 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1058 const u_char
*ep
, uint32_t phase
, uint32_t doi0
,
1059 uint32_t proto0 _U_
, int depth
)
1061 const struct ikev1_pl_p
*p
;
1065 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_P
));
1067 p
= (const struct ikev1_pl_p
*)ext
;
1069 ND_PRINT(" #%u protoid=%s transform=%u",
1070 GET_U_1(p
->p_no
), PROTOIDSTR(GET_U_1(p
->prot_id
)),
1072 spi_size
= GET_U_1(p
->spi_size
);
1075 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
1079 ext
= (const struct isakmp_gen
*)((const u_char
*)(p
+ 1) + spi_size
);
1080 ND_TCHECK_SIZE(ext
);
1082 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1083 GET_U_1(p
->prot_id
), depth
);
1087 ND_PRINT(" [|%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
;
1228 const struct attrmap
*map
;
1232 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_T
));
1234 p
= (const struct ikev1_pl_t
*)ext
;
1239 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), ikev1_p_map
);
1241 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1244 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), ah_p_map
);
1246 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1249 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), esp_p_map
);
1251 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1254 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), ipcomp_p_map
);
1256 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1266 ND_PRINT(" #%u id=%s ", GET_U_1(p
->t_no
), idstr
);
1268 ND_PRINT(" #%u id=%u ", GET_U_1(p
->t_no
), GET_U_1(p
->t_id
));
1269 cp
= (const u_char
*)(p
+ 1);
1270 ep2
= (const u_char
*)p
+ item_len
;
1271 while (cp
< ep
&& cp
< ep2
) {
1273 cp
= ikev1_attrmap_print(ndo
, cp
, ep2
, map
, nmap
);
1275 cp
= ikev1_attr_print(ndo
, cp
, ep2
);
1283 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T
));
1287 static const u_char
*
1288 ikev1_ke_print(netdissect_options
*ndo
, u_char tpay _U_
,
1289 const struct isakmp_gen
*ext
, u_int item_len
,
1290 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1291 uint32_t proto _U_
, int depth _U_
)
1293 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
1295 ND_TCHECK_SIZE(ext
);
1297 * Our caller has ensured that the length is >= 4.
1299 ND_PRINT(" key len=%u", item_len
- 4);
1300 if (2 < ndo
->ndo_vflag
&& item_len
> 4) {
1301 /* Print the entire payload in hex */
1303 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1306 return (const u_char
*)ext
+ item_len
;
1308 ND_PRINT(" [|%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 static const char *idtypestr
[] = {
1321 "IPv4", "IPv4net", "IPv6", "IPv6net",
1323 static const char *ipsecidtypestr
[] = {
1324 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1325 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1331 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
1333 p
= (const struct ikev1_pl_id
*)ext
;
1335 if (sizeof(*p
) < item_len
) {
1336 data
= (const u_char
*)(p
+ 1);
1337 len
= item_len
- sizeof(*p
);
1344 ND_PRINT(" [phase=%u doi=%u proto=%u]", phase
, doi
, proto
);
1347 #ifndef USE_IPSECDOI_IN_PHASE1
1351 ND_PRINT(" idtype=%s",
1352 STR_OR_ID(GET_U_1(p
->d
.id_type
), idtypestr
));
1353 ND_PRINT(" doi_data=%u",
1354 GET_BE_U_4(p
->d
.doi_data
) & 0xffffff);
1357 #ifdef USE_IPSECDOI_IN_PHASE1
1362 const struct ipsecdoi_id
*doi_p
;
1364 uint8_t type
, proto_id
;
1366 doi_p
= (const struct ipsecdoi_id
*)ext
;
1367 ND_TCHECK_SIZE(doi_p
);
1368 type
= GET_U_1(doi_p
->type
);
1369 ND_PRINT(" idtype=%s", STR_OR_ID(type
, ipsecidtypestr
));
1370 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
1371 proto_id
= GET_U_1(doi_p
->proto_id
);
1372 if (!ndo
->ndo_nflag
&& proto_id
&& (p_name
= netdb_protoname(proto_id
)) != NULL
)
1373 ND_PRINT(" protoid=%s", p_name
);
1375 ND_PRINT(" protoid=%u", proto_id
);
1376 ND_PRINT(" port=%u", GET_BE_U_2(doi_p
->port
));
1381 ND_TCHECK_LEN(data
, len
);
1383 case IPSECDOI_ID_IPV4_ADDR
:
1385 ND_PRINT(" len=%u [bad: < 4]", len
);
1387 ND_PRINT(" len=%u %s", len
, GET_IPADDR_STRING(data
));
1390 case IPSECDOI_ID_FQDN
:
1391 case IPSECDOI_ID_USER_FQDN
:
1394 ND_PRINT(" len=%u ", len
);
1395 for (i
= 0; i
< len
; i
++)
1396 fn_print_char(ndo
, GET_U_1(data
+ i
));
1400 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
1404 ND_PRINT(" len=%u [bad: < 8]", len
);
1406 mask
= data
+ sizeof(nd_ipv4
);
1407 ND_PRINT(" len=%u %s/%u.%u.%u.%u", len
,
1408 GET_IPADDR_STRING(data
),
1409 GET_U_1(mask
), GET_U_1(mask
+ 1),
1416 case IPSECDOI_ID_IPV6_ADDR
:
1418 ND_PRINT(" len=%u [bad: < 16]", len
);
1420 ND_PRINT(" len=%u %s", len
, GET_IP6ADDR_STRING(data
));
1423 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
1427 ND_PRINT(" len=%u [bad: < 32]", len
);
1429 mask
= (const u_char
*)(data
+ sizeof(nd_ipv6
));
1431 ND_PRINT(" len=%u %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len
,
1432 GET_IP6ADDR_STRING(data
),
1433 GET_U_1(mask
), GET_U_1(mask
+ 1),
1447 GET_U_1(mask
+ 15));
1452 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1454 ND_PRINT(" len=%u [bad: < 8]", len
);
1456 ND_PRINT(" len=%u %s-%s", len
,
1457 GET_IPADDR_STRING(data
),
1458 GET_IPADDR_STRING(data
+ sizeof(nd_ipv4
)));
1462 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1464 ND_PRINT(" len=%u [bad: < 32]", len
);
1466 ND_PRINT(" len=%u %s-%s", len
,
1467 GET_IP6ADDR_STRING(data
),
1468 GET_IP6ADDR_STRING(data
+ sizeof(nd_ipv6
)));
1472 case IPSECDOI_ID_DER_ASN1_DN
:
1473 case IPSECDOI_ID_DER_ASN1_GN
:
1474 case IPSECDOI_ID_KEY_ID
:
1481 ND_PRINT(" len=%u", len
);
1482 if (2 < ndo
->ndo_vflag
) {
1484 if (!rawprint(ndo
, (const uint8_t *)data
, len
))
1488 return (const u_char
*)ext
+ item_len
;
1490 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID
));
1494 static const u_char
*
1495 ikev1_cert_print(netdissect_options
*ndo
, u_char tpay _U_
,
1496 const struct isakmp_gen
*ext
, u_int item_len
,
1497 const u_char
*ep _U_
, uint32_t phase _U_
,
1499 uint32_t proto0 _U_
, int depth _U_
)
1501 const struct ikev1_pl_cert
*p
;
1502 static const char *certstr
[] = {
1503 "none", "pkcs7", "pgp", "dns",
1504 "x509sign", "x509ke", "kerberos", "crl",
1505 "arl", "spki", "x509attr",
1508 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
1510 p
= (const struct ikev1_pl_cert
*)ext
;
1513 * Our caller has ensured that the length is >= 4.
1515 ND_PRINT(" len=%u", item_len
- 4);
1516 ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p
->encode
), certstr
));
1517 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1518 /* Print the entire payload in hex */
1520 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1523 return (const u_char
*)ext
+ item_len
;
1525 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
));
1529 static const u_char
*
1530 ikev1_cr_print(netdissect_options
*ndo
, u_char tpay _U_
,
1531 const struct isakmp_gen
*ext
, u_int item_len
,
1532 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1533 uint32_t proto0 _U_
, int depth _U_
)
1535 const struct ikev1_pl_cert
*p
;
1536 static const char *certstr
[] = {
1537 "none", "pkcs7", "pgp", "dns",
1538 "x509sign", "x509ke", "kerberos", "crl",
1539 "arl", "spki", "x509attr",
1542 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CR
));
1544 p
= (const struct ikev1_pl_cert
*)ext
;
1547 * Our caller has ensured that the length is >= 4.
1549 ND_PRINT(" len=%u", item_len
- 4);
1550 ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p
->encode
), certstr
));
1551 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1552 /* Print the entire payload in hex */
1554 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1557 return (const u_char
*)ext
+ item_len
;
1559 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CR
));
1563 static const u_char
*
1564 ikev1_hash_print(netdissect_options
*ndo
, u_char tpay _U_
,
1565 const struct isakmp_gen
*ext
, u_int item_len
,
1566 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1567 uint32_t proto _U_
, int depth _U_
)
1569 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
1571 ND_TCHECK_SIZE(ext
);
1573 * Our caller has ensured that the length is >= 4.
1575 ND_PRINT(" len=%u", item_len
- 4);
1576 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1577 /* Print the entire payload in hex */
1579 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1582 return (const u_char
*)ext
+ item_len
;
1584 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
));
1588 static const u_char
*
1589 ikev1_sig_print(netdissect_options
*ndo
, u_char tpay _U_
,
1590 const struct isakmp_gen
*ext
, u_int item_len
,
1591 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1592 uint32_t proto _U_
, int depth _U_
)
1594 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
1596 ND_TCHECK_SIZE(ext
);
1598 * Our caller has ensured that the length is >= 4.
1600 ND_PRINT(" len=%u", item_len
- 4);
1601 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1602 /* Print the entire payload in hex */
1604 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1607 return (const u_char
*)ext
+ item_len
;
1609 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
));
1613 static const u_char
*
1614 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1615 const struct isakmp_gen
*ext
,
1618 uint32_t phase _U_
, uint32_t doi _U_
,
1619 uint32_t proto _U_
, int depth _U_
)
1621 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
1623 ND_TCHECK_SIZE(ext
);
1625 * Our caller has ensured that the length is >= 4.
1627 ND_PRINT(" n len=%u", item_len
- 4);
1629 if (ndo
->ndo_vflag
> 2) {
1631 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1633 } else if (ndo
->ndo_vflag
> 1) {
1635 if (!ike_show_somedata(ndo
, (const u_char
*)(ext
+ 1), ep
))
1639 return (const u_char
*)ext
+ item_len
;
1641 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
));
1645 static const u_char
*
1646 ikev1_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
1647 const struct isakmp_gen
*ext
, u_int item_len
,
1648 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1649 uint32_t proto0 _U_
, int depth _U_
)
1651 const struct ikev1_pl_n
*p
;
1658 static const char *notify_error_str
[] = {
1659 NULL
, "INVALID-PAYLOAD-TYPE",
1660 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1661 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1662 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1663 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1664 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1665 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1666 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1667 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1668 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1669 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1670 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1671 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1672 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1673 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1674 "UNEQUAL-PAYLOAD-LENGTHS",
1676 static const char *ipsec_notify_error_str
[] = {
1679 static const char *notify_status_str
[] = {
1682 static const char *ipsec_notify_status_str
[] = {
1683 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1686 /* NOTE: these macro must be called with x in proper range */
1689 #define NOTIFY_ERROR_STR(x) \
1690 STR_OR_ID((x), notify_error_str)
1693 #define IPSEC_NOTIFY_ERROR_STR(x) \
1694 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1697 #define NOTIFY_STATUS_STR(x) \
1698 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1701 #define IPSEC_NOTIFY_STATUS_STR(x) \
1702 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1704 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_N
));
1706 p
= (const struct ikev1_pl_n
*)ext
;
1708 doi
= GET_BE_U_4(p
->doi
);
1709 proto
= GET_U_1(p
->prot_id
);
1711 ND_PRINT(" doi=%u", doi
);
1712 ND_PRINT(" proto=%u", proto
);
1713 type
= GET_BE_U_2(p
->type
);
1715 ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type
));
1716 else if (type
< 16384)
1717 ND_PRINT(" type=%s", numstr(type
));
1718 else if (type
< 24576)
1719 ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type
));
1721 ND_PRINT(" type=%s", numstr(type
));
1722 spi_size
= GET_U_1(p
->spi_size
);
1725 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
1728 return (const u_char
*)(p
+ 1) + spi_size
;
1731 ND_PRINT(" doi=ipsec");
1732 ND_PRINT(" proto=%s", PROTOIDSTR(proto
));
1733 type
= GET_BE_U_2(p
->type
);
1735 ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type
));
1736 else if (type
< 16384)
1737 ND_PRINT(" type=%s", IPSEC_NOTIFY_ERROR_STR(type
));
1738 else if (type
< 24576)
1739 ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type
));
1740 else if (type
< 32768)
1741 ND_PRINT(" type=%s", IPSEC_NOTIFY_STATUS_STR(type
));
1743 ND_PRINT(" type=%s", numstr(type
));
1744 spi_size
= GET_U_1(p
->spi_size
);
1747 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
1751 cp
= (const u_char
*)(p
+ 1) + spi_size
;
1752 ep2
= (const u_char
*)p
+ item_len
;
1756 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
1758 const struct attrmap
*map
= oakley_t_map
;
1759 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1760 ND_PRINT(" attrs=(");
1761 while (cp
< ep
&& cp
< ep2
) {
1762 cp
= ikev1_attrmap_print(ndo
, cp
, ep2
, map
, nmap
);
1771 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1772 ND_PRINT(" status=(");
1773 ND_PRINT("replay detection %sabled",
1774 GET_BE_U_4(cp
) ? "en" : "dis");
1779 * XXX - fill in more types here; see, for example,
1780 * draft-ietf-ipsec-notifymsg-04.
1782 if (ndo
->ndo_vflag
> 3) {
1783 ND_PRINT(" data=(");
1784 if (!rawprint(ndo
, (const uint8_t *)(cp
), ep
- cp
))
1788 if (!ike_show_somedata(ndo
, cp
, ep
))
1794 return (const u_char
*)ext
+ item_len
;
1796 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N
));
1800 static const u_char
*
1801 ikev1_d_print(netdissect_options
*ndo
, u_char tpay _U_
,
1802 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1803 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1804 uint32_t proto0 _U_
, int depth _U_
)
1806 const struct ikev1_pl_d
*p
;
1814 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_D
));
1816 p
= (const struct ikev1_pl_d
*)ext
;
1818 doi
= GET_BE_U_4(p
->doi
);
1819 proto
= GET_U_1(p
->prot_id
);
1821 ND_PRINT(" doi=%u", doi
);
1822 ND_PRINT(" proto=%u", proto
);
1824 ND_PRINT(" doi=ipsec");
1825 ND_PRINT(" proto=%s", PROTOIDSTR(proto
));
1827 spi_size
= GET_U_1(p
->spi_size
);
1828 ND_PRINT(" spilen=%u", spi_size
);
1829 num_spi
= GET_BE_U_2(p
->num_spi
);
1830 ND_PRINT(" nspi=%u", num_spi
);
1831 q
= (const uint8_t *)(p
+ 1);
1834 for (i
= 0; i
< num_spi
; i
++) {
1837 if (!rawprint(ndo
, (const uint8_t *)q
, spi_size
))
1844 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_D
));
1848 static const u_char
*
1849 ikev1_vid_print(netdissect_options
*ndo
, u_char tpay _U_
,
1850 const struct isakmp_gen
*ext
,
1851 u_int item_len
, const u_char
*ep _U_
,
1852 uint32_t phase _U_
, uint32_t doi _U_
,
1853 uint32_t proto _U_
, int depth _U_
)
1855 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
1857 ND_TCHECK_SIZE(ext
);
1859 * Our caller has ensured that the length is >= 4.
1861 ND_PRINT(" len=%u", item_len
- 4);
1862 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1863 /* Print the entire payload in hex */
1865 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1868 return (const u_char
*)ext
+ item_len
;
1870 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID
));
1874 /************************************************************/
1876 /* IKE v2 - rfc4306 - dissector */
1878 /************************************************************/
1881 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, uint8_t critical
)
1883 ND_PRINT("%s%s:", payname
, critical
&0x80 ? "[C]" : "");
1886 static const u_char
*
1887 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1888 const struct isakmp_gen
*ext
, u_int item_len
)
1890 const struct isakmp_gen
*p
= (const struct isakmp_gen
*)ext
;
1892 ND_TCHECK_SIZE(ext
);
1893 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(p
->critical
));
1896 * Our caller has ensured that the length is >= 4.
1898 ND_PRINT(" len=%u", item_len
- 4);
1899 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1900 /* Print the entire payload in hex */
1902 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1905 return (const u_char
*)ext
+ item_len
;
1907 ND_PRINT(" [|%s]", NPSTR(tpay
));
1911 static const u_char
*
1912 ikev2_t_print(netdissect_options
*ndo
, int tcount
,
1913 const struct isakmp_gen
*ext
, u_int item_len
,
1916 const struct ikev2_t
*p
;
1921 const struct attrmap
*map
;
1925 p
= (const struct ikev2_t
*)ext
;
1927 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), GET_U_1(p
->h
.critical
));
1929 t_id
= GET_BE_U_2(p
->t_id
);
1934 t_type
= GET_U_1(p
->t_type
);
1937 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1939 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1943 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1947 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1951 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1955 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1964 ND_PRINT(" #%u type=%s id=%s ", tcount
,
1965 STR_OR_ID(t_type
, ikev2_t_type_map
),
1968 ND_PRINT(" #%u type=%s id=%u ", tcount
,
1969 STR_OR_ID(t_type
, ikev2_t_type_map
),
1971 cp
= (const u_char
*)(p
+ 1);
1972 ep2
= (const u_char
*)p
+ item_len
;
1973 while (cp
< ep
&& cp
< ep2
) {
1975 cp
= ikev1_attrmap_print(ndo
, cp
, ep2
, map
, nmap
);
1977 cp
= ikev1_attr_print(ndo
, cp
, ep2
);
1985 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T
));
1989 static const u_char
*
1990 ikev2_p_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount _U_
,
1991 const struct isakmp_gen
*ext
, u_int oprop_length
,
1992 const u_char
*ep
, int depth
)
1994 const struct ikev2_p
*p
;
2003 p
= (const struct ikev2_p
*)ext
;
2006 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), GET_U_1(p
->h
.critical
));
2009 * ikev2_sa_print() guarantees that this is >= 4.
2011 prop_length
= oprop_length
- 4;
2012 ND_PRINT(" #%u protoid=%s transform=%u len=%u",
2013 GET_U_1(p
->p_no
), PROTOIDSTR(GET_U_1(p
->prot_id
)),
2014 GET_U_1(p
->num_t
), oprop_length
);
2015 cp
= (const u_char
*)(p
+ 1);
2017 spi_size
= GET_U_1(p
->spi_size
);
2019 if (prop_length
< spi_size
)
2022 if (!rawprint(ndo
, (const uint8_t *)cp
, spi_size
))
2025 prop_length
-= spi_size
;
2029 * Print the transforms.
2032 for (np
= ISAKMP_NPTYPE_T
; np
!= 0; np
= GET_U_1(ext
->np
)) {
2034 ext
= (const struct isakmp_gen
*)cp
;
2035 if (prop_length
< sizeof(*ext
))
2037 ND_TCHECK_SIZE(ext
);
2040 * Since we can't have a payload length of less than 4 bytes,
2041 * we need to bail out here if the generic header is nonsensical
2042 * or truncated, otherwise we could loop forever processing
2043 * zero-length items or otherwise misdissect the packet.
2045 item_len
= GET_BE_U_2(ext
->len
);
2049 if (prop_length
< item_len
)
2051 ND_TCHECK_LEN(cp
, item_len
);
2055 for (i
= 0; i
< depth
; i
++)
2058 if (np
== ISAKMP_NPTYPE_T
) {
2059 cp
= ikev2_t_print(ndo
, tcount
, ext
, item_len
, ep
);
2061 /* error, already reported */
2065 ND_PRINT("%s", NPSTR(np
));
2070 prop_length
-= item_len
;
2075 * Skip the rest of the proposal.
2078 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P
));
2081 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P
));
2085 static const u_char
*
2086 ikev2_sa_print(netdissect_options
*ndo
, u_char tpay
,
2087 const struct isakmp_gen
*ext1
,
2088 u_int osa_length
, const u_char
*ep
,
2089 uint32_t phase _U_
, uint32_t doi _U_
,
2090 uint32_t proto _U_
, int depth
)
2092 const struct isakmp_gen
*ext
;
2100 ND_TCHECK_SIZE(ext1
);
2101 ikev2_pay_print(ndo
, "sa", GET_U_1(ext1
->critical
));
2104 * ikev2_sub0_print() guarantees that this is >= 4.
2106 osa_length
= GET_BE_U_2(ext1
->len
);
2107 sa_length
= osa_length
- 4;
2108 ND_PRINT(" len=%u", sa_length
);
2111 * Print the payloads.
2113 cp
= (const u_char
*)(ext1
+ 1);
2115 for (np
= ISAKMP_NPTYPE_P
; np
!= 0; np
= GET_U_1(ext
->np
)) {
2117 ext
= (const struct isakmp_gen
*)cp
;
2118 if (sa_length
< sizeof(*ext
))
2120 ND_TCHECK_SIZE(ext
);
2123 * Since we can't have a payload length of less than 4 bytes,
2124 * we need to bail out here if the generic header is nonsensical
2125 * or truncated, otherwise we could loop forever processing
2126 * zero-length items or otherwise misdissect the packet.
2128 item_len
= GET_BE_U_2(ext
->len
);
2132 if (sa_length
< item_len
)
2134 ND_TCHECK_LEN(cp
, item_len
);
2138 for (i
= 0; i
< depth
; i
++)
2141 if (np
== ISAKMP_NPTYPE_P
) {
2142 cp
= ikev2_p_print(ndo
, np
, pcount
, ext
, item_len
,
2145 /* error, already reported */
2149 ND_PRINT("%s", NPSTR(np
));
2154 sa_length
-= item_len
;
2159 * Skip the rest of the SA.
2162 ND_PRINT(" [|%s]", NPSTR(tpay
));
2165 ND_PRINT(" [|%s]", NPSTR(tpay
));
2169 static const u_char
*
2170 ikev2_ke_print(netdissect_options
*ndo
, u_char tpay
,
2171 const struct isakmp_gen
*ext
,
2172 u_int item_len
, const u_char
*ep _U_
,
2173 uint32_t phase _U_
, uint32_t doi _U_
,
2174 uint32_t proto _U_
, int depth _U_
)
2176 const struct ikev2_ke
*k
;
2178 k
= (const struct ikev2_ke
*)ext
;
2180 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(k
->h
.critical
));
2183 ND_PRINT(" len=%u < 8", item_len
);
2184 return (const u_char
*)ext
+ item_len
;
2186 ND_PRINT(" len=%u group=%s", item_len
- 8,
2187 STR_OR_ID(GET_BE_U_2(k
->ke_group
), dh_p_map
));
2189 if (2 < ndo
->ndo_vflag
&& 8 < item_len
) {
2191 if (!rawprint(ndo
, (const uint8_t *)(k
+ 1), item_len
- 8))
2194 return (const u_char
*)ext
+ item_len
;
2196 ND_PRINT(" [|%s]", NPSTR(tpay
));
2200 static const u_char
*
2201 ikev2_ID_print(netdissect_options
*ndo
, u_char tpay
,
2202 const struct isakmp_gen
*ext
,
2203 u_int item_len
, const u_char
*ep _U_
,
2204 uint32_t phase _U_
, uint32_t doi _U_
,
2205 uint32_t proto _U_
, int depth _U_
)
2207 const struct ikev2_id
*idp
;
2208 u_int idtype_len
, i
;
2209 unsigned int dumpascii
, dumphex
;
2210 const unsigned char *typedata
;
2212 idp
= (const struct ikev2_id
*)ext
;
2213 ND_TCHECK_SIZE(idp
);
2214 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(idp
->h
.critical
));
2217 * Our caller has ensured that the length is >= 4.
2219 ND_PRINT(" len=%u", item_len
- 4);
2220 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
2221 /* Print the entire payload in hex */
2223 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
2227 idtype_len
=item_len
- sizeof(struct ikev2_id
);
2230 typedata
= (const unsigned char *)(ext
)+sizeof(struct ikev2_id
);
2232 switch(GET_U_1(idp
->type
)) {
2241 case ID_RFC822_ADDR
:
2242 ND_PRINT(" rfc822:");
2249 case ID_DER_ASN1_DN
:
2253 case ID_DER_ASN1_GN
:
2258 ND_PRINT(" keyid:");
2264 ND_TCHECK_LEN(typedata
, idtype_len
);
2265 for(i
=0; i
<idtype_len
; i
++) {
2266 if(ND_ASCII_ISPRINT(GET_U_1(typedata
+ i
))) {
2267 ND_PRINT("%c", GET_U_1(typedata
+ i
));
2274 if (!rawprint(ndo
, (const uint8_t *)typedata
, idtype_len
))
2278 return (const u_char
*)ext
+ item_len
;
2280 ND_PRINT(" [|%s]", NPSTR(tpay
));
2284 static const u_char
*
2285 ikev2_cert_print(netdissect_options
*ndo
, u_char tpay
,
2286 const struct isakmp_gen
*ext
,
2287 u_int item_len
, const u_char
*ep _U_
,
2288 uint32_t phase _U_
, uint32_t doi _U_
,
2289 uint32_t proto _U_
, int depth _U_
)
2291 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2294 static const u_char
*
2295 ikev2_cr_print(netdissect_options
*ndo
, u_char tpay
,
2296 const struct isakmp_gen
*ext
,
2297 u_int item_len
, const u_char
*ep _U_
,
2298 uint32_t phase _U_
, uint32_t doi _U_
,
2299 uint32_t proto _U_
, int depth _U_
)
2301 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2304 static const u_char
*
2305 ikev2_auth_print(netdissect_options
*ndo
, u_char tpay
,
2306 const struct isakmp_gen
*ext
,
2307 u_int item_len
, const u_char
*ep
,
2308 uint32_t phase _U_
, uint32_t doi _U_
,
2309 uint32_t proto _U_
, int depth _U_
)
2311 const struct ikev2_auth
*p
;
2312 const char *v2_auth
[]={ "invalid", "rsasig",
2313 "shared-secret", "dsssig" };
2314 const u_char
*authdata
= (const u_char
*)ext
+ sizeof(struct ikev2_auth
);
2316 ND_TCHECK_LEN(ext
, sizeof(struct ikev2_auth
));
2317 p
= (const struct ikev2_auth
*)ext
;
2318 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(p
->h
.critical
));
2321 * Our caller has ensured that the length is >= 4.
2323 ND_PRINT(" len=%u method=%s", item_len
-4,
2324 STR_OR_ID(GET_U_1(p
->auth_method
), v2_auth
));
2326 if (ndo
->ndo_vflag
> 1) {
2327 ND_PRINT(" authdata=(");
2328 if (!rawprint(ndo
, (const uint8_t *)authdata
, item_len
- sizeof(struct ikev2_auth
)))
2331 } else if (ndo
->ndo_vflag
) {
2332 if (!ike_show_somedata(ndo
, authdata
, ep
))
2337 return (const u_char
*)ext
+ item_len
;
2339 ND_PRINT(" [|%s]", NPSTR(tpay
));
2343 static const u_char
*
2344 ikev2_nonce_print(netdissect_options
*ndo
, u_char tpay
,
2345 const struct isakmp_gen
*ext
,
2346 u_int item_len
, const u_char
*ep
,
2347 uint32_t phase _U_
, uint32_t doi _U_
,
2348 uint32_t proto _U_
, int depth _U_
)
2350 ND_TCHECK_SIZE(ext
);
2351 ikev2_pay_print(ndo
, "nonce", GET_U_1(ext
->critical
));
2354 * Our caller has ensured that the length is >= 4.
2356 ND_PRINT(" len=%u", item_len
- 4);
2357 if (1 < ndo
->ndo_vflag
&& 4 < item_len
) {
2358 ND_PRINT(" nonce=(");
2359 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
2362 } else if(ndo
->ndo_vflag
&& 4 < item_len
) {
2363 if(!ike_show_somedata(ndo
, (const u_char
*)(ext
+1), ep
)) goto trunc
;
2366 return (const u_char
*)ext
+ item_len
;
2368 ND_PRINT(" [|%s]", NPSTR(tpay
));
2372 /* notify payloads */
2373 static const u_char
*
2374 ikev2_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
2375 const struct isakmp_gen
*ext
,
2376 u_int item_len
, const u_char
*ep
,
2377 uint32_t phase _U_
, uint32_t doi _U_
,
2378 uint32_t proto _U_
, int depth _U_
)
2380 const struct ikev2_n
*p
;
2384 u_char showspi
, showsomedata
;
2385 const char *notify_name
;
2387 p
= (const struct ikev2_n
*)ext
;
2389 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), GET_U_1(p
->h
.critical
));
2395 ND_PRINT(" prot_id=%s", PROTOIDSTR(GET_U_1(p
->prot_id
)));
2397 type
= GET_BE_U_2(p
->type
);
2399 /* notify space is annoying sparse */
2401 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
2402 notify_name
= "unsupported_critical_payload";
2406 case IV2_NOTIFY_INVALID_IKE_SPI
:
2407 notify_name
= "invalid_ike_spi";
2411 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
2412 notify_name
= "invalid_major_version";
2416 case IV2_NOTIFY_INVALID_SYNTAX
:
2417 notify_name
= "invalid_syntax";
2421 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
2422 notify_name
= "invalid_message_id";
2426 case IV2_NOTIFY_INVALID_SPI
:
2427 notify_name
= "invalid_spi";
2431 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
2432 notify_name
= "no_protocol_chosen";
2436 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
2437 notify_name
= "invalid_ke_payload";
2441 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
2442 notify_name
= "authentication_failed";
2446 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
2447 notify_name
= "single_pair_required";
2451 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
2452 notify_name
= "no_additional_sas";
2456 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
2457 notify_name
= "internal_address_failure";
2461 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
2462 notify_name
= "failed:cp_required";
2466 case IV2_NOTIFY_INVALID_SELECTORS
:
2467 notify_name
= "invalid_selectors";
2471 case IV2_NOTIFY_INITIAL_CONTACT
:
2472 notify_name
= "initial_contact";
2476 case IV2_NOTIFY_SET_WINDOW_SIZE
:
2477 notify_name
= "set_window_size";
2481 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
2482 notify_name
= "additional_ts_possible";
2486 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
2487 notify_name
= "ipcomp_supported";
2491 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
2492 notify_name
= "nat_detection_source_ip";
2496 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
2497 notify_name
= "nat_detection_destination_ip";
2501 case IV2_NOTIFY_COOKIE
:
2502 notify_name
= "cookie";
2507 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
2508 notify_name
= "use_transport_mode";
2512 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
2513 notify_name
= "http_cert_lookup_supported";
2517 case IV2_NOTIFY_REKEY_SA
:
2518 notify_name
= "rekey_sa";
2522 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
2523 notify_name
= "tfc_padding_not_supported";
2527 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
2528 notify_name
= "non_first_fragment_also";
2534 notify_name
="error";
2535 } else if(type
< 16384) {
2536 notify_name
="private-error";
2537 } else if(type
< 40960) {
2538 notify_name
="status";
2540 notify_name
="private-status";
2545 ND_PRINT(" type=%u(%s)", type
, notify_name
);
2549 spi_size
= GET_U_1(p
->spi_size
);
2550 if (showspi
&& spi_size
) {
2552 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
2556 cp
= (const u_char
*)(p
+ 1) + spi_size
;
2559 if (ndo
->ndo_vflag
> 3 || (showsomedata
&& ep
-cp
< 30)) {
2560 ND_PRINT(" data=(");
2561 if (!rawprint(ndo
, (const uint8_t *)(cp
), ep
- cp
))
2565 } else if (showsomedata
) {
2566 if (!ike_show_somedata(ndo
, cp
, ep
))
2571 return (const u_char
*)ext
+ item_len
;
2573 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N
));
2577 static const u_char
*
2578 ikev2_d_print(netdissect_options
*ndo
, u_char tpay
,
2579 const struct isakmp_gen
*ext
,
2580 u_int item_len
, const u_char
*ep _U_
,
2581 uint32_t phase _U_
, uint32_t doi _U_
,
2582 uint32_t proto _U_
, int depth _U_
)
2584 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2587 static const u_char
*
2588 ikev2_vid_print(netdissect_options
*ndo
, u_char tpay
,
2589 const struct isakmp_gen
*ext
,
2590 u_int item_len
, const u_char
*ep _U_
,
2591 uint32_t phase _U_
, uint32_t doi _U_
,
2592 uint32_t proto _U_
, int depth _U_
)
2597 ND_TCHECK_SIZE(ext
);
2598 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(ext
->critical
));
2601 * Our caller has ensured that the length is >= 4.
2603 ND_PRINT(" len=%u vid=", item_len
- 4);
2605 vid
= (const u_char
*)(ext
+1);
2607 ND_TCHECK_LEN(vid
, len
);
2608 for(i
=0; i
<len
; i
++) {
2609 if(ND_ASCII_ISPRINT(GET_U_1(vid
+ i
)))
2610 ND_PRINT("%c", GET_U_1(vid
+ i
));
2613 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2614 /* Print the entire payload in hex */
2616 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
2619 return (const u_char
*)ext
+ item_len
;
2621 ND_PRINT(" [|%s]", NPSTR(tpay
));
2625 static const u_char
*
2626 ikev2_TS_print(netdissect_options
*ndo
, u_char tpay
,
2627 const struct isakmp_gen
*ext
,
2628 u_int item_len
, const u_char
*ep _U_
,
2629 uint32_t phase _U_
, uint32_t doi _U_
,
2630 uint32_t proto _U_
, int depth _U_
)
2632 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2635 static const u_char
*
2636 ikev2_e_print(netdissect_options
*ndo
,
2637 #ifndef HAVE_LIBCRYPTO
2640 const struct isakmp
*base
,
2642 const struct isakmp_gen
*ext
,
2643 u_int item_len
, const u_char
*ep _U_
,
2644 #ifndef HAVE_LIBCRYPTO
2648 #ifndef HAVE_LIBCRYPTO
2652 #ifndef HAVE_LIBCRYPTO
2656 #ifndef HAVE_LIBCRYPTO
2663 #ifdef HAVE_LIBCRYPTO
2667 ND_TCHECK_SIZE(ext
);
2668 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(ext
->critical
));
2672 ND_PRINT(" len=%u", dlen
);
2673 if (2 < ndo
->ndo_vflag
&& 4 < dlen
) {
2675 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), dlen
))
2679 dat
= (const u_char
*)(ext
+1);
2680 ND_TCHECK_LEN(dat
, dlen
);
2682 #ifdef HAVE_LIBCRYPTO
2683 np
= GET_U_1(ext
->np
);
2685 /* try to decrypt it! */
2686 if(esp_decrypt_buffer_by_ikev2_print(ndo
,
2687 GET_U_1(base
->flags
) & ISAKMP_FLAG_I
,
2688 base
->i_ck
, base
->r_ck
,
2691 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
2693 /* got it decrypted, print stuff inside. */
2694 ikev2_sub_print(ndo
, base
, np
, ext
,
2695 ndo
->ndo_snapend
, phase
, doi
, proto
, depth
+1);
2698 * esp_decrypt_buffer_by_ikev2_print pushed information
2699 * on the buffer stack; we're done with the buffer, so
2700 * pop it (which frees the buffer)
2702 nd_pop_packet_info(ndo
);
2707 /* always return NULL, because E must be at end, and NP refers
2708 * to what was inside.
2712 ND_PRINT(" [|%s]", NPSTR(tpay
));
2716 static const u_char
*
2717 ikev2_cp_print(netdissect_options
*ndo
, u_char tpay
,
2718 const struct isakmp_gen
*ext
,
2719 u_int item_len
, const u_char
*ep _U_
,
2720 uint32_t phase _U_
, uint32_t doi _U_
,
2721 uint32_t proto _U_
, int depth _U_
)
2723 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2726 static const u_char
*
2727 ikev2_eap_print(netdissect_options
*ndo
, u_char tpay
,
2728 const struct isakmp_gen
*ext
,
2729 u_int item_len
, const u_char
*ep _U_
,
2730 uint32_t phase _U_
, uint32_t doi _U_
,
2731 uint32_t proto _U_
, int depth _U_
)
2733 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2736 static const u_char
*
2737 ike_sub0_print(netdissect_options
*ndo
,
2738 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2740 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2745 cp
= (const u_char
*)ext
;
2746 ND_TCHECK_SIZE(ext
);
2749 * Since we can't have a payload length of less than 4 bytes,
2750 * we need to bail out here if the generic header is nonsensical
2751 * or truncated, otherwise we could loop forever processing
2752 * zero-length items or otherwise misdissect the packet.
2754 item_len
= GET_BE_U_2(ext
->len
);
2760 * XXX - what if item_len is too short, or too long,
2761 * for this payload type?
2763 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2765 ND_PRINT("%s", NPSTR(np
));
2771 nd_print_trunc(ndo
);
2775 static const u_char
*
2776 ikev1_sub_print(netdissect_options
*ndo
,
2777 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2778 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2784 cp
= (const u_char
*)ext
;
2787 ND_TCHECK_SIZE(ext
);
2789 item_len
= GET_BE_U_2(ext
->len
);
2790 ND_TCHECK_LEN(ext
, item_len
);
2794 for (i
= 0; i
< depth
; i
++)
2797 cp
= ike_sub0_print(ndo
, np
, ext
, ep
, phase
, doi
, proto
, depth
);
2802 /* Zero-length subitem */
2806 np
= GET_U_1(ext
->np
);
2807 ext
= (const struct isakmp_gen
*)cp
;
2811 ND_PRINT(" [|%s]", NPSTR(np
));
2818 static char buf
[20];
2819 snprintf(buf
, sizeof(buf
), "#%u", x
);
2824 ikev1_print(netdissect_options
*ndo
,
2825 const u_char
*bp
, u_int length
,
2826 const u_char
*bp2
, const struct isakmp
*base
)
2828 const struct isakmp
*p
;
2835 p
= (const struct isakmp
*)bp
;
2836 ep
= ndo
->ndo_snapend
;
2838 phase
= (GET_BE_U_4(base
->msgid
) == 0) ? 1 : 2;
2840 ND_PRINT(" phase %u", phase
);
2842 ND_PRINT(" phase %u/others", phase
);
2844 i
= cookie_find(&base
->i_ck
);
2846 if (iszero(ndo
, base
->r_ck
, sizeof(base
->r_ck
))) {
2847 /* the first packet */
2850 cookie_record(ndo
, &base
->i_ck
, bp2
);
2854 if (bp2
&& cookie_isinitiator(ndo
, i
, bp2
))
2856 else if (bp2
&& cookie_isresponder(ndo
, i
, bp2
))
2862 ND_PRINT(" %s", ETYPESTR(GET_U_1(base
->etype
)));
2863 flags
= GET_U_1(base
->flags
);
2865 ND_PRINT("[%s%s]", flags
& ISAKMP_FLAG_E
? "E" : "",
2866 flags
& ISAKMP_FLAG_C
? "C" : "");
2869 if (ndo
->ndo_vflag
) {
2870 const struct isakmp_gen
*ext
;
2874 np
= GET_U_1(base
->np
);
2876 /* regardless of phase... */
2877 if (flags
& ISAKMP_FLAG_E
) {
2879 * encrypted, nothing we can do right now.
2880 * we hope to decrypt the packet in the future...
2882 ND_PRINT(" [encrypted %s]", NPSTR(np
));
2886 CHECKLEN(p
+ 1, np
);
2887 ext
= (const struct isakmp_gen
*)(p
+ 1);
2888 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
2892 if (ndo
->ndo_vflag
) {
2893 if (GET_BE_U_4(base
->len
) != length
) {
2894 ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
2895 GET_BE_U_4(base
->len
), length
);
2900 static const u_char
*
2901 ikev2_sub0_print(netdissect_options
*ndo
, const struct isakmp
*base
,
2903 const struct isakmp_gen
*ext
, const u_char
*ep
,
2904 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2909 cp
= (const u_char
*)ext
;
2910 ND_TCHECK_SIZE(ext
);
2913 * Since we can't have a payload length of less than 4 bytes,
2914 * we need to bail out here if the generic header is nonsensical
2915 * or truncated, otherwise we could loop forever processing
2916 * zero-length items or otherwise misdissect the packet.
2918 item_len
= GET_BE_U_2(ext
->len
);
2922 if (np
== ISAKMP_NPTYPE_v2E
) {
2923 cp
= ikev2_e_print(ndo
, base
, np
, ext
, item_len
,
2924 ep
, phase
, doi
, proto
, depth
);
2925 } else if (NPFUNC(np
)) {
2927 * XXX - what if item_len is too short, or too long,
2928 * for this payload type?
2930 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
,
2931 ep
, phase
, doi
, proto
, depth
);
2933 ND_PRINT("%s", NPSTR(np
));
2939 nd_print_trunc(ndo
);
2943 static const u_char
*
2944 ikev2_sub_print(netdissect_options
*ndo
,
2945 const struct isakmp
*base
,
2946 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2947 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2952 cp
= (const u_char
*)ext
;
2954 ND_TCHECK_SIZE(ext
);
2956 ND_TCHECK_LEN(ext
, GET_BE_U_2(ext
->len
));
2960 for (i
= 0; i
< depth
; i
++)
2963 cp
= ikev2_sub0_print(ndo
, base
, np
,
2964 ext
, ep
, phase
, doi
, proto
, depth
);
2969 /* Zero-length subitem */
2973 np
= GET_U_1(ext
->np
);
2974 ext
= (const struct isakmp_gen
*)cp
;
2978 ND_PRINT(" [|%s]", NPSTR(np
));
2983 ikev2_print(netdissect_options
*ndo
,
2984 const u_char
*bp
, u_int length
,
2985 const u_char
*bp2 _U_
, const struct isakmp
*base
)
2987 const struct isakmp
*p
;
2993 p
= (const struct isakmp
*)bp
;
2994 ep
= ndo
->ndo_snapend
;
2996 phase
= (GET_BE_U_4(base
->msgid
) == 0) ? 1 : 2;
2998 ND_PRINT(" parent_sa");
3000 ND_PRINT(" child_sa ");
3002 ND_PRINT(" %s", ETYPESTR(GET_U_1(base
->etype
)));
3003 flags
= GET_U_1(base
->flags
);
3005 ND_PRINT("[%s%s%s]",
3006 flags
& ISAKMP_FLAG_I
? "I" : "",
3007 flags
& ISAKMP_FLAG_V
? "V" : "",
3008 flags
& ISAKMP_FLAG_R
? "R" : "");
3011 if (ndo
->ndo_vflag
) {
3012 const struct isakmp_gen
*ext
;
3016 np
= GET_U_1(base
->np
);
3018 /* regardless of phase... */
3019 if (flags
& ISAKMP_FLAG_E
) {
3021 * encrypted, nothing we can do right now.
3022 * we hope to decrypt the packet in the future...
3024 ND_PRINT(" [encrypted %s]", NPSTR(np
));
3029 ext
= (const struct isakmp_gen
*)(p
+ 1);
3030 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
3034 if (ndo
->ndo_vflag
) {
3035 if (GET_BE_U_4(base
->len
) != length
) {
3036 ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
3037 GET_BE_U_4(base
->len
), length
);
3043 isakmp_print(netdissect_options
*ndo
,
3044 const u_char
*bp
, u_int length
,
3047 const struct isakmp
*p
;
3051 ndo
->ndo_protocol
= "isakmp";
3052 #ifdef HAVE_LIBCRYPTO
3053 /* initialize SAs */
3054 if (ndo
->ndo_sa_list_head
== NULL
) {
3055 if (ndo
->ndo_espsecret
)
3056 esp_decodesecret_print(ndo
);
3060 p
= (const struct isakmp
*)bp
;
3061 ep
= ndo
->ndo_snapend
;
3063 if ((const struct isakmp
*)ep
< p
+ 1) {
3064 nd_print_trunc(ndo
);
3069 major
= (GET_U_1(p
->vers
) & ISAKMP_VERS_MAJOR
)
3070 >> ISAKMP_VERS_MAJOR_SHIFT
;
3071 minor
= (GET_U_1(p
->vers
) & ISAKMP_VERS_MINOR
)
3072 >> ISAKMP_VERS_MINOR_SHIFT
;
3074 if (ndo
->ndo_vflag
) {
3075 ND_PRINT(" %u.%u", major
, minor
);
3078 if (ndo
->ndo_vflag
) {
3079 ND_PRINT(" msgid ");
3080 hexprint(ndo
, p
->msgid
, sizeof(p
->msgid
));
3083 if (1 < ndo
->ndo_vflag
) {
3084 ND_PRINT(" cookie ");
3085 hexprint(ndo
, p
->i_ck
, sizeof(p
->i_ck
));
3087 hexprint(ndo
, p
->r_ck
, sizeof(p
->r_ck
));
3092 case IKEv1_MAJOR_VERSION
:
3093 ikev1_print(ndo
, bp
, length
, bp2
, p
);
3096 case IKEv2_MAJOR_VERSION
:
3097 ikev2_print(ndo
, bp
, length
, bp2
, p
);
3103 isakmp_rfc3948_print(netdissect_options
*ndo
,
3104 const u_char
*bp
, u_int length
,
3105 const u_char
*bp2
, int ver
, int fragmented
, u_int ttl_hl
)
3107 ndo
->ndo_protocol
= "isakmp_rfc3948";
3108 if(length
== 1 && GET_U_1(bp
)==0xff) {
3109 ND_PRINT("isakmp-nat-keep-alive");
3118 * see if this is an IKE packet
3120 if (GET_BE_U_4(bp
) == 0) {
3121 ND_PRINT("NONESP-encap: ");
3122 isakmp_print(ndo
, bp
+4, length
-4, bp2
);
3126 /* must be an ESP packet */
3128 ND_PRINT("UDP-encap: ");
3130 esp_print(ndo
, bp
, length
, bp2
, ver
, fragmented
, ttl_hl
);
3133 * Either this has decrypted the payload and
3134 * printed it, in which case there's nothing more
3135 * to do, or it hasn't, in which case there's
3136 * nothing more to do.
3142 nd_print_trunc(ndo
);