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 */
37 #include "netdissect-stdinc.h"
41 #include "netdissect-ctype.h"
43 #include "netdissect.h"
44 #include "addrtoname.h"
51 typedef nd_byte cookie_t
[8];
52 typedef nd_byte msgid_t
[4];
54 #define PORT_ISAKMP 500
56 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
57 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
58 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
66 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 cookie_t i_ck
; /* Initiator Cookie */
74 cookie_t r_ck
; /* Responder Cookie */
75 nd_uint8_t np
; /* Next Payload Type */
77 #define ISAKMP_VERS_MAJOR 0xf0
78 #define ISAKMP_VERS_MAJOR_SHIFT 4
79 #define ISAKMP_VERS_MINOR 0x0f
80 #define ISAKMP_VERS_MINOR_SHIFT 0
81 nd_uint8_t etype
; /* Exchange Type */
82 nd_uint8_t flags
; /* Flags */
84 nd_uint32_t len
; /* Length */
87 /* Next Payload Type */
88 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
89 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
90 #define ISAKMP_NPTYPE_P 2 /* Proposal */
91 #define ISAKMP_NPTYPE_T 3 /* Transform */
92 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
93 #define ISAKMP_NPTYPE_ID 5 /* Identification */
94 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
95 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
96 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
97 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
98 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
99 #define ISAKMP_NPTYPE_N 11 /* Notification */
100 #define ISAKMP_NPTYPE_D 12 /* Delete */
101 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
102 #define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
104 #define IKEv1_MAJOR_VERSION 1
105 #define IKEv1_MINOR_VERSION 0
107 #define IKEv2_MAJOR_VERSION 2
108 #define IKEv2_MINOR_VERSION 0
111 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
112 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
113 #define ISAKMP_FLAG_extra 0x04
116 #define ISAKMP_FLAG_I (1 << 3) /* Initiator */
117 #define ISAKMP_FLAG_V (1 << 4) /* Version */
118 #define ISAKMP_FLAG_R (1 << 5) /* Response */
121 /* 3.2 Payload Generic Header
122 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
123 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
124 ! Next Payload ! RESERVED ! Payload Length !
125 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 nd_uint8_t np
; /* Next Payload */
129 nd_uint8_t critical
; /* bit 7 - critical, rest is RESERVED */
130 nd_uint16_t len
; /* Payload Length */
133 /* 3.3 Data Attributes
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 !A! Attribute Type ! AF=0 Attribute Length !
137 !F! ! AF=1 Attribute Value !
138 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
139 . AF=0 Attribute Value .
140 . AF=1 Not Transmitted .
141 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144 nd_uint16_t type
; /* defined by DOI-spec, and Attribute Format */
145 nd_uint16_t lorv
; /* if f equal 1, Attribute Length */
146 /* if f equal 0, Attribute Value */
147 /* if f equal 1, Attribute Value */
150 /* 3.4 Security Association Payload */
151 /* MAY NOT be used, because of being defined in ipsec-doi. */
153 If the current payload is the last in the message,
154 then the value of the next payload field will be 0.
155 This field MUST NOT contain the
156 values for the Proposal or Transform payloads as they are considered
157 part of the security association negotiation. For example, this
158 field would contain the value "10" (Nonce payload) in the first
159 message of a Base Exchange (see Section 4.4) and the value "0" in the
160 first message of an Identity Protect Exchange (see Section 4.5).
164 nd_uint32_t doi
; /* Domain of Interpretation */
165 nd_uint32_t sit
; /* Situation */
168 /* 3.5 Proposal Payload */
170 The value of the next payload field MUST only contain the value "2"
171 or "0". If there are additional Proposal payloads in the message,
172 then this field will be 2. If the current Proposal payload is the
173 last within the security association proposal, then this field will
178 nd_uint8_t p_no
; /* Proposal # */
179 nd_uint8_t prot_id
; /* Protocol */
180 nd_uint8_t spi_size
; /* SPI Size */
181 nd_uint8_t num_t
; /* Number of Transforms */
185 /* 3.6 Transform Payload */
187 The value of the next payload field MUST only contain the value "3"
188 or "0". If there are additional Transform payloads in the proposal,
189 then this field will be 3. If the current Transform payload is the
190 last within the proposal, then this field will be 0.
194 nd_uint8_t t_no
; /* Transform # */
195 nd_uint8_t t_id
; /* Transform-Id */
196 nd_byte reserved
[2]; /* RESERVED2 */
200 /* 3.7 Key Exchange Payload */
203 /* Key Exchange Data */
206 /* 3.8 Identification Payload */
207 /* MUST NOT to be used, because of being defined in ipsec-doi. */
211 nd_uint8_t id_type
; /* ID Type */
212 nd_uint32_t doi_data
; /* DOI Specific ID Data */
214 /* Identification Data */
217 /* 3.9 Certificate Payload */
218 struct ikev1_pl_cert
{
220 nd_uint8_t encode
; /* Cert Encoding */
221 nd_uint8_t cert
; /* Certificate Data */
223 This field indicates the type of
224 certificate or certificate-related information contained in the
225 Certificate Data field.
229 /* 3.10 Certificate Request Payload */
232 nd_uint8_t num_cert
; /* # Cert. Types */
234 Certificate Types (variable length)
235 -- Contains a list of the types of certificates requested,
236 sorted in order of preference. Each individual certificate
237 type is 1 octet. This field is NOT required.
239 /* # Certificate Authorities (1 octet) */
240 /* Certificate Authorities (variable length) */
243 /* 3.11 Hash Payload */
244 /* may not be used, because of having only data. */
245 struct ikev1_pl_hash
{
250 /* 3.12 Signature Payload */
251 /* may not be used, because of having only data. */
252 struct ikev1_pl_sig
{
257 /* 3.13 Nonce Payload */
258 /* may not be used, because of having only data. */
259 struct ikev1_pl_nonce
{
264 /* 3.14 Notification Payload */
267 nd_uint32_t doi
; /* Domain of Interpretation */
268 nd_uint8_t prot_id
; /* Protocol-ID */
269 nd_uint8_t spi_size
; /* SPI Size */
270 nd_uint16_t type
; /* Notify Message Type */
272 /* Notification Data */
275 /* 3.14.1 Notify Message Types */
276 /* NOTIFY MESSAGES - ERROR TYPES */
277 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
278 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
279 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
280 #define ISAKMP_NTYPE_INVALID_COOKIE 4
281 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
282 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
283 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
284 #define ISAKMP_NTYPE_INVALID_FLAGS 8
285 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
286 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
287 #define ISAKMP_NTYPE_INVALID_SPI 11
288 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
289 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
290 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
291 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
292 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
293 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
294 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
295 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
296 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
297 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
298 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
299 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
300 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
301 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
302 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
304 /* 3.15 Delete Payload */
307 nd_uint32_t doi
; /* Domain of Interpretation */
308 nd_uint8_t prot_id
; /* Protocol-Id */
309 nd_uint8_t spi_size
; /* SPI Size */
310 nd_uint16_t num_spi
; /* # of SPIs */
314 /* IKEv2 (RFC4306) */
316 /* 3.3 Security Association Payload -- generic header */
317 /* 3.3.1. Proposal Substructure */
320 nd_uint8_t p_no
; /* Proposal # */
321 nd_uint8_t prot_id
; /* Protocol */
322 nd_uint8_t spi_size
; /* SPI Size */
323 nd_uint8_t num_t
; /* Number of Transforms */
326 /* 3.3.2. Transform Substructure */
329 nd_uint8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
330 nd_byte res2
; /* reserved byte */
331 nd_uint16_t t_id
; /* Transform ID */
342 /* 3.4. Key Exchange Payload */
345 nd_uint16_t ke_group
;
351 /* 3.5. Identification Payloads */
363 nd_uint8_t type
; /* ID type */
367 /* Notification Data */
370 /* 3.10 Notification Payload */
373 nd_uint8_t prot_id
; /* Protocol-ID */
374 nd_uint8_t spi_size
; /* SPI Size */
375 nd_uint16_t type
; /* Notify Message Type */
379 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
380 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
381 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
382 IV2_NOTIFY_INVALID_SYNTAX
= 7,
383 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
384 IV2_NOTIFY_INVALID_SPI
=11,
385 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
386 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
387 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
388 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
389 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
390 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
391 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
392 IV2_NOTIFY_INVALID_SELECTORS
=39,
393 IV2_NOTIFY_INITIAL_CONTACT
=16384,
394 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
395 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
396 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
397 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
398 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
399 IV2_NOTIFY_COOKIE
=16390,
400 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
401 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
402 IV2_NOTIFY_REKEY_SA
=16393,
403 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
404 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
407 struct notify_messages
{
412 /* 3.8 Authentication Payload */
415 nd_uint8_t auth_method
; /* Protocol-ID */
417 /* authentication data */
420 enum ikev2_auth_type
{
426 /* refer to RFC 2409 */
429 /* isakmp sa structure */
431 uint8_t proto_id
; /* OAKLEY */
432 vchar_t
*spi
; /* spi */
433 uint8_t dhgrp
; /* DH; group */
434 uint8_t auth_t
; /* method of authentication */
435 uint8_t prf_t
; /* type of prf */
436 uint8_t hash_t
; /* type of hash */
437 uint8_t enc_t
; /* type of cipher */
438 uint8_t life_t
; /* type of duration of lifetime */
439 uint32_t ldur
; /* life duration */
443 /* refer to RFC 2407 */
447 /* 4.2 IPSEC Situation Definition */
448 #define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
449 #define IPSECDOI_SIT_SECRECY 0x00000002
450 #define IPSECDOI_SIT_INTEGRITY 0x00000004
452 /* 4.4.1 IPSEC Security Protocol Identifiers */
453 /* 4.4.2 IPSEC ISAKMP Transform Values */
454 #define IPSECDOI_PROTO_ISAKMP 1
455 #define IPSECDOI_KEY_IKE 1
457 /* 4.4.1 IPSEC Security Protocol Identifiers */
458 #define IPSECDOI_PROTO_IPSEC_AH 2
459 /* 4.4.3 IPSEC AH Transform Values */
460 #define IPSECDOI_AH_MD5 2
461 #define IPSECDOI_AH_SHA 3
462 #define IPSECDOI_AH_DES 4
463 #define IPSECDOI_AH_SHA2_256 5
464 #define IPSECDOI_AH_SHA2_384 6
465 #define IPSECDOI_AH_SHA2_512 7
467 /* 4.4.1 IPSEC Security Protocol Identifiers */
468 #define IPSECDOI_PROTO_IPSEC_ESP 3
469 /* 4.4.4 IPSEC ESP Transform Identifiers */
470 #define IPSECDOI_ESP_DES_IV64 1
471 #define IPSECDOI_ESP_DES 2
472 #define IPSECDOI_ESP_3DES 3
473 #define IPSECDOI_ESP_RC5 4
474 #define IPSECDOI_ESP_IDEA 5
475 #define IPSECDOI_ESP_CAST 6
476 #define IPSECDOI_ESP_BLOWFISH 7
477 #define IPSECDOI_ESP_3IDEA 8
478 #define IPSECDOI_ESP_DES_IV32 9
479 #define IPSECDOI_ESP_RC4 10
480 #define IPSECDOI_ESP_NULL 11
481 #define IPSECDOI_ESP_RIJNDAEL 12
482 #define IPSECDOI_ESP_AES 12
484 /* 4.4.1 IPSEC Security Protocol Identifiers */
485 #define IPSECDOI_PROTO_IPCOMP 4
486 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
487 #define IPSECDOI_IPCOMP_OUI 1
488 #define IPSECDOI_IPCOMP_DEFLATE 2
489 #define IPSECDOI_IPCOMP_LZS 3
491 /* 4.5 IPSEC Security Association Attributes */
492 #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
493 #define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
494 #define IPSECDOI_ATTR_SA_LTYPE_SEC 1
495 #define IPSECDOI_ATTR_SA_LTYPE_KB 2
496 #define IPSECDOI_ATTR_SA_LDUR 2 /* V */
497 #define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
498 #define IPSECDOI_ATTR_GRP_DESC 3 /* B */
499 #define IPSECDOI_ATTR_ENC_MODE 4 /* B */
500 /* default value: host dependent */
501 #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
502 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2
503 #define IPSECDOI_ATTR_AUTH 5 /* B */
504 /* 0 means not to use authentication. */
505 #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
506 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
507 #define IPSECDOI_ATTR_AUTH_DES_MAC 3
508 #define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
510 * When negotiating ESP without authentication, the Auth
511 * Algorithm attribute MUST NOT be included in the proposal.
512 * When negotiating ESP without confidentiality, the Auth
513 * Algorithm attribute MUST be included in the proposal and
514 * the ESP transform ID must be ESP_NULL.
516 #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
517 #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
518 #define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
519 #define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
521 /* 4.6.1 Security Association Payload */
524 nd_uint32_t doi
; /* Domain of Interpretation */
525 nd_uint32_t sit
; /* Situation */
528 struct ipsecdoi_secrecy_h
{
530 nd_uint16_t reserved
;
533 /* 4.6.2.1 Identification Type Values */
536 nd_uint8_t type
; /* ID Type */
537 nd_uint8_t proto_id
; /* Protocol ID */
538 nd_uint16_t port
; /* Port */
539 /* Identification Data */
542 #define IPSECDOI_ID_IPV4_ADDR 1
543 #define IPSECDOI_ID_FQDN 2
544 #define IPSECDOI_ID_USER_FQDN 3
545 #define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
546 #define IPSECDOI_ID_IPV6_ADDR 5
547 #define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
548 #define IPSECDOI_ID_IPV4_ADDR_RANGE 7
549 #define IPSECDOI_ID_IPV6_ADDR_RANGE 8
550 #define IPSECDOI_ID_DER_ASN1_DN 9
551 #define IPSECDOI_ID_DER_ASN1_GN 10
552 #define IPSECDOI_ID_KEY_ID 11
554 /* 4.6.3 IPSEC DOI Notify Message Types */
555 /* Notify Messages - Status Types */
556 #define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
557 #define IPSECDOI_NTYPE_REPLAY_STATUS 24577
558 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
560 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
561 netdissect_options *ndo, u_char tpay, \
562 const struct isakmp_gen *ext, \
564 const u_char *end_pointer, \
567 uint32_t proto0, int depth)
569 DECLARE_PRINTER(v1_sa
);
570 DECLARE_PRINTER(v1_p
);
571 DECLARE_PRINTER(v1_t
);
572 DECLARE_PRINTER(v1_ke
);
573 DECLARE_PRINTER(v1_id
);
574 DECLARE_PRINTER(v1_cert
);
575 DECLARE_PRINTER(v1_cr
);
576 DECLARE_PRINTER(v1_sig
);
577 DECLARE_PRINTER(v1_hash
);
578 DECLARE_PRINTER(v1_nonce
);
579 DECLARE_PRINTER(v1_n
);
580 DECLARE_PRINTER(v1_d
);
581 DECLARE_PRINTER(v1_vid
);
583 DECLARE_PRINTER(v2_sa
);
584 DECLARE_PRINTER(v2_ke
);
585 DECLARE_PRINTER(v2_ID
);
586 DECLARE_PRINTER(v2_cert
);
587 DECLARE_PRINTER(v2_cr
);
588 DECLARE_PRINTER(v2_auth
);
589 DECLARE_PRINTER(v2_nonce
);
590 DECLARE_PRINTER(v2_n
);
591 DECLARE_PRINTER(v2_d
);
592 DECLARE_PRINTER(v2_vid
);
593 DECLARE_PRINTER(v2_TS
);
594 DECLARE_PRINTER(v2_cp
);
595 DECLARE_PRINTER(v2_eap
);
597 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
598 const struct isakmp
*base
,
600 const struct isakmp_gen
*ext
,
602 const u_char
*end_pointer
,
605 uint32_t proto0
, int depth
);
608 static const u_char
*ike_sub0_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
609 const u_char
*, uint32_t, uint32_t, uint32_t, int);
610 static const u_char
*ikev1_sub_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
611 const u_char
*, uint32_t, uint32_t, uint32_t, int);
613 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
614 const struct isakmp
*base
,
615 u_char np
, const struct isakmp_gen
*ext
,
616 const u_char
*ep
, uint32_t phase
,
617 uint32_t doi
, uint32_t proto
,
621 static char *numstr(u_int
);
624 ikev1_print(netdissect_options
*ndo
,
625 const u_char
*bp
, u_int length
,
626 const u_char
*bp2
, const struct isakmp
*base
);
628 #define MAXINITIATORS 20
629 static int ninitiator
= 0;
637 union inaddr_u iaddr
;
638 union inaddr_u raddr
;
639 } cookiecache
[MAXINITIATORS
];
642 static const char *protoidstr
[] = {
643 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
647 static const char *npstr
[] = {
648 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
649 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
650 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
651 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
652 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
653 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
654 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
655 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
656 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
662 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
663 const struct isakmp_gen
*ext
,
665 const u_char
*end_pointer
,
668 uint32_t proto0
, int depth
) = {
682 ikev1_vid_print
, /* 13 */
683 NULL
, NULL
, NULL
, NULL
, NULL
, /* 14- 18 */
684 NULL
, NULL
, NULL
, NULL
, NULL
, /* 19- 23 */
685 NULL
, NULL
, NULL
, NULL
, NULL
, /* 24- 28 */
686 NULL
, NULL
, NULL
, NULL
, /* 29- 32 */
687 ikev2_sa_print
, /* 33 */
688 ikev2_ke_print
, /* 34 */
689 ikev2_ID_print
, /* 35 */
690 ikev2_ID_print
, /* 36 */
691 ikev2_cert_print
, /* 37 */
692 ikev2_cr_print
, /* 38 */
693 ikev2_auth_print
, /* 39 */
694 ikev2_nonce_print
, /* 40 */
695 ikev2_n_print
, /* 41 */
696 ikev2_d_print
, /* 42 */
697 ikev2_vid_print
, /* 43 */
698 ikev2_TS_print
, /* 44 */
699 ikev2_TS_print
, /* 45 */
700 NULL
, /* ikev2_e_print,*/ /* 46 - special */
701 ikev2_cp_print
, /* 47 */
702 ikev2_eap_print
, /* 48 */
706 static const char *etypestr
[] = {
707 /* IKEv1 exchange types */
708 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
, /* 0-7 */
709 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 8-15 */
710 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 16-23 */
711 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 24-31 */
712 "oakley-quick", "oakley-newgroup", /* 32-33 */
713 /* IKEv2 exchange types */
714 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
717 #define STR_OR_ID(x, tab) \
718 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
719 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
720 #define NPSTR(x) STR_OR_ID(x, npstr)
721 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
723 #define CHECKLEN(p, np) \
724 if (ep < (const u_char *)(p)) { \
725 ND_PRINT(" [|%s]", NPSTR(np)); \
731 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
732 ? npfunc[(x)] : NULL)
735 iszero(netdissect_options
*ndo
, const u_char
*p
, size_t l
)
746 /* find cookie from initiator cache */
748 cookie_find(const cookie_t
*in
)
752 for (i
= 0; i
< MAXINITIATORS
; i
++) {
753 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
760 /* record initiator */
762 cookie_record(netdissect_options
*ndo
, const cookie_t
*in
, const u_char
*bp2
)
766 const struct ip6_hdr
*ip6
;
770 ninitiator
= (i
+ 1) % MAXINITIATORS
;
774 ip
= (const struct ip
*)bp2
;
777 cookiecache
[ninitiator
].version
= 4;
778 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in4
,
779 ip
->ip_src
, sizeof(nd_ipv4
));
780 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in4
,
781 ip
->ip_dst
, sizeof(nd_ipv4
));
784 ip6
= (const struct ip6_hdr
*)bp2
;
785 cookiecache
[ninitiator
].version
= 6;
786 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in6
,
787 ip6
->ip6_src
, sizeof(nd_ipv6
));
788 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in6
,
789 ip6
->ip6_dst
, sizeof(nd_ipv6
));
794 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
795 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
798 #define cookie_isinitiator(ndo, x, y) cookie_sidecheck(ndo, (x), (y), 1)
799 #define cookie_isresponder(ndo, x, y) cookie_sidecheck(ndo, (x), (y), 0)
801 cookie_sidecheck(netdissect_options
*ndo
, int i
, const u_char
*bp2
, int initiator
)
804 const struct ip6_hdr
*ip6
;
806 ip
= (const struct ip
*)bp2
;
809 if (cookiecache
[i
].version
!= 4)
812 if (UNALIGNED_MEMCMP(ip
->ip_src
, &cookiecache
[i
].iaddr
.in4
, sizeof(nd_ipv4
)) == 0)
815 if (UNALIGNED_MEMCMP(ip
->ip_src
, &cookiecache
[i
].raddr
.in4
, sizeof(nd_ipv4
)) == 0)
820 if (cookiecache
[i
].version
!= 6)
822 ip6
= (const struct ip6_hdr
*)bp2
;
824 if (UNALIGNED_MEMCMP(ip6
->ip6_src
, &cookiecache
[i
].iaddr
.in6
, sizeof(nd_ipv6
)) == 0)
827 if (UNALIGNED_MEMCMP(ip6
->ip6_src
, &cookiecache
[i
].raddr
.in6
, sizeof(nd_ipv6
)) == 0)
839 hexprint(netdissect_options
*ndo
, const uint8_t *loc
, size_t len
)
845 for (i
= 0; i
< len
; i
++)
846 ND_PRINT("%02x", p
[i
] & 0xff);
850 rawprint(netdissect_options
*ndo
, const uint8_t *loc
, size_t len
)
852 ND_TCHECK_LEN(loc
, len
);
854 hexprint(ndo
, loc
, len
);
862 * returns false if we run out of data buffer
864 static int ike_show_somedata(netdissect_options
*ndo
,
865 const u_char
*cp
, const u_char
*ep
)
867 /* there is too much data, just show some of it */
868 const u_char
*end
= ep
- 20;
870 size_t len
= ep
- cp
;
875 /* really shouldn't happen because of above */
882 if(!rawprint(ndo
, (const uint8_t *)(cp
), len
)) goto trunc
;
885 if(!rawprint(ndo
, (const uint8_t *)(end
), elen
)) goto trunc
;
897 const char *value
[30]; /*XXX*/
900 static const u_char
*
901 ikev1_attrmap_print(netdissect_options
*ndo
,
902 const u_char
*p
, const u_char
*ep2
,
903 const struct attrmap
*map
, size_t nmap
)
908 if (GET_U_1(p
) & 0x80)
911 totlen
= 4 + GET_BE_U_2(p
+ 2);
913 if (ep2
< p
+ totlen
) {
919 t
= GET_BE_U_2(p
) & 0x7fff;
920 if (map
&& t
< nmap
&& map
[t
].type
)
921 ND_PRINT("type=%s ", map
[t
].type
);
923 ND_PRINT("type=#%u ", t
);
924 if (GET_U_1(p
) & 0x80) {
926 v
= GET_BE_U_2(p
+ 2);
927 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
928 ND_PRINT("%s", map
[t
].value
[v
]);
930 if (!rawprint(ndo
, (const uint8_t *)(p
+ 2), 2)) {
936 ND_PRINT("len=%u value=", totlen
- 4);
937 if (!rawprint(ndo
, (const uint8_t *)(p
+ 4), totlen
- 4)) {
949 static const u_char
*
950 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep2
)
955 if (GET_U_1(p
) & 0x80)
958 totlen
= 4 + GET_BE_U_2(p
+ 2);
960 if (ep2
< p
+ totlen
) {
966 t
= GET_BE_U_2(p
) & 0x7fff;
967 ND_PRINT("type=#%u ", t
);
968 if (GET_U_1(p
) & 0x80) {
971 if (!rawprint(ndo
, (const uint8_t *)(p
+ 2), 2)) {
976 ND_PRINT("len=%u value=", totlen
- 4);
977 if (!rawprint(ndo
, (const uint8_t *)(p
+ 4), totlen
- 4)) {
989 static const u_char
*
990 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
991 const struct isakmp_gen
*ext
,
993 const u_char
*ep
, uint32_t phase
, uint32_t doi0 _U_
,
994 uint32_t proto0
, int depth
)
996 const struct ikev1_pl_sa
*p
;
997 uint32_t doi
, sit
, ident
;
998 const u_char
*cp
, *np
;
1001 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SA
));
1003 p
= (const struct ikev1_pl_sa
*)ext
;
1005 doi
= GET_BE_U_4(p
->doi
);
1006 sit
= GET_BE_U_4(p
->sit
);
1008 ND_PRINT(" doi=%u", doi
);
1009 ND_PRINT(" situation=%u", sit
);
1010 return (const u_char
*)(p
+ 1);
1013 ND_PRINT(" doi=ipsec");
1014 ND_PRINT(" situation=");
1017 ND_PRINT("identity");
1021 ND_PRINT("%ssecrecy", t
? "+" : "");
1025 ND_PRINT("%sintegrity", t
? "+" : "");
1027 np
= (const u_char
*)ext
+ sizeof(struct ikev1_pl_sa
);
1029 ident
= GET_BE_U_4(ext
+ 1);
1030 ND_PRINT(" ident=%u", ident
);
1031 np
+= sizeof(ident
);
1034 ext
= (const struct isakmp_gen
*)np
;
1035 ND_TCHECK_SIZE(ext
);
1037 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
1042 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA
));
1046 static const u_char
*
1047 ikev1_p_print(netdissect_options
*ndo
, u_char tpay _U_
,
1048 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1049 const u_char
*ep
, uint32_t phase
, uint32_t doi0
,
1050 uint32_t proto0 _U_
, int depth
)
1052 const struct ikev1_pl_p
*p
;
1056 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_P
));
1058 p
= (const struct ikev1_pl_p
*)ext
;
1060 ND_PRINT(" #%u protoid=%s transform=%u",
1061 GET_U_1(p
->p_no
), PROTOIDSTR(GET_U_1(p
->prot_id
)),
1063 spi_size
= GET_U_1(p
->spi_size
);
1066 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
1070 ext
= (const struct isakmp_gen
*)((const u_char
*)(p
+ 1) + spi_size
);
1071 ND_TCHECK_SIZE(ext
);
1073 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1074 GET_U_1(p
->prot_id
), depth
);
1078 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P
));
1082 static const char *ikev1_p_map
[] = {
1086 static const char *ikev2_t_type_map
[]={
1087 NULL
, "encr", "prf", "integ", "dh", "esn"
1090 static const char *ah_p_map
[] = {
1091 NULL
, "(reserved)", "md5", "sha", "1des",
1092 "sha2-256", "sha2-384", "sha2-512",
1095 static const char *prf_p_map
[] = {
1096 NULL
, "hmac-md5", "hmac-sha", "hmac-tiger",
1100 static const char *integ_p_map
[] = {
1101 NULL
, "hmac-md5", "hmac-sha", "dec-mac",
1102 "kpdk-md5", "aes-xcbc"
1105 static const char *esn_p_map
[] = {
1109 static const char *dh_p_map
[] = {
1111 "modp1024", /* group 2 */
1112 "EC2N 2^155", /* group 3 */
1113 "EC2N 2^185", /* group 4 */
1114 "modp1536", /* group 5 */
1115 "iana-grp06", "iana-grp07", /* reserved */
1116 "iana-grp08", "iana-grp09",
1117 "iana-grp10", "iana-grp11",
1118 "iana-grp12", "iana-grp13",
1119 "modp2048", /* group 14 */
1120 "modp3072", /* group 15 */
1121 "modp4096", /* group 16 */
1122 "modp6144", /* group 17 */
1123 "modp8192", /* group 18 */
1126 static const char *esp_p_map
[] = {
1127 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1128 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1131 static const char *ipcomp_p_map
[] = {
1132 NULL
, "oui", "deflate", "lzs",
1135 static const struct attrmap ipsec_t_map
[] = {
1136 { NULL
, 0, { NULL
} },
1137 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1138 { "life", 0, { NULL
} },
1139 { "group desc", 18, { NULL
, "modp768",
1140 "modp1024", /* group 2 */
1141 "EC2N 2^155", /* group 3 */
1142 "EC2N 2^185", /* group 4 */
1143 "modp1536", /* group 5 */
1144 "iana-grp06", "iana-grp07", /* reserved */
1145 "iana-grp08", "iana-grp09",
1146 "iana-grp10", "iana-grp11",
1147 "iana-grp12", "iana-grp13",
1148 "modp2048", /* group 14 */
1149 "modp3072", /* group 15 */
1150 "modp4096", /* group 16 */
1151 "modp6144", /* group 17 */
1152 "modp8192", /* group 18 */
1154 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
1155 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1156 { "keylen", 0, { NULL
} },
1157 { "rounds", 0, { NULL
} },
1158 { "dictsize", 0, { NULL
} },
1159 { "privalg", 0, { NULL
} },
1162 static const struct attrmap encr_t_map
[] = {
1163 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 0, 1 */
1164 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 2, 3 */
1165 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 4, 5 */
1166 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 6, 7 */
1167 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 8, 9 */
1168 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 10,11*/
1169 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 12,13*/
1170 { "keylen", 14, { NULL
}},
1173 static const struct attrmap oakley_t_map
[] = {
1174 { NULL
, 0, { NULL
} },
1175 { "enc", 8, { NULL
, "1des", "idea", "blowfish", "rc5",
1176 "3des", "cast", "aes", }, },
1177 { "hash", 7, { NULL
, "md5", "sha1", "tiger",
1178 "sha2-256", "sha2-384", "sha2-512", }, },
1179 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
1180 "rsa enc revised", }, },
1181 { "group desc", 18, { NULL
, "modp768",
1182 "modp1024", /* group 2 */
1183 "EC2N 2^155", /* group 3 */
1184 "EC2N 2^185", /* group 4 */
1185 "modp1536", /* group 5 */
1186 "iana-grp06", "iana-grp07", /* reserved */
1187 "iana-grp08", "iana-grp09",
1188 "iana-grp10", "iana-grp11",
1189 "iana-grp12", "iana-grp13",
1190 "modp2048", /* group 14 */
1191 "modp3072", /* group 15 */
1192 "modp4096", /* group 16 */
1193 "modp6144", /* group 17 */
1194 "modp8192", /* group 18 */
1196 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
1197 { "group prime", 0, { NULL
} },
1198 { "group gen1", 0, { NULL
} },
1199 { "group gen2", 0, { NULL
} },
1200 { "group curve A", 0, { NULL
} },
1201 { "group curve B", 0, { NULL
} },
1202 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1203 { "lifeduration", 0, { NULL
} },
1204 { "prf", 0, { NULL
} },
1205 { "keylen", 0, { NULL
} },
1206 { "field", 0, { NULL
} },
1207 { "order", 0, { NULL
} },
1210 static const u_char
*
1211 ikev1_t_print(netdissect_options
*ndo
, u_char tpay _U_
,
1212 const struct isakmp_gen
*ext
, u_int item_len
,
1213 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi _U_
,
1214 uint32_t proto
, int depth _U_
)
1216 const struct ikev1_pl_t
*p
;
1219 const struct attrmap
*map
;
1223 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_T
));
1225 p
= (const struct ikev1_pl_t
*)ext
;
1230 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), ikev1_p_map
);
1232 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1235 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), ah_p_map
);
1237 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1240 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), esp_p_map
);
1242 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1245 idstr
= STR_OR_ID(GET_U_1(p
->t_id
), ipcomp_p_map
);
1247 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1257 ND_PRINT(" #%u id=%s ", GET_U_1(p
->t_no
), idstr
);
1259 ND_PRINT(" #%u id=%u ", GET_U_1(p
->t_no
), GET_U_1(p
->t_id
));
1260 cp
= (const u_char
*)(p
+ 1);
1261 ep2
= (const u_char
*)p
+ item_len
;
1262 while (cp
< ep
&& cp
< ep2
) {
1264 cp
= ikev1_attrmap_print(ndo
, cp
, ep2
, map
, nmap
);
1266 cp
= ikev1_attr_print(ndo
, cp
, ep2
);
1274 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T
));
1278 static const u_char
*
1279 ikev1_ke_print(netdissect_options
*ndo
, u_char tpay _U_
,
1280 const struct isakmp_gen
*ext
, u_int item_len
,
1281 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1282 uint32_t proto _U_
, int depth _U_
)
1284 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_KE
));
1286 ND_TCHECK_SIZE(ext
);
1288 * Our caller has ensured that the length is >= 4.
1290 ND_PRINT(" key len=%u", item_len
- 4);
1291 if (2 < ndo
->ndo_vflag
&& item_len
> 4) {
1292 /* Print the entire payload in hex */
1294 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1297 return (const u_char
*)ext
+ item_len
;
1299 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_KE
));
1303 static const u_char
*
1304 ikev1_id_print(netdissect_options
*ndo
, u_char tpay _U_
,
1305 const struct isakmp_gen
*ext
, u_int item_len
,
1306 const u_char
*ep _U_
, uint32_t phase
, uint32_t doi _U_
,
1307 uint32_t proto _U_
, int depth _U_
)
1309 #define USE_IPSECDOI_IN_PHASE1 1
1310 const struct ikev1_pl_id
*p
;
1311 static const char *idtypestr
[] = {
1312 "IPv4", "IPv4net", "IPv6", "IPv6net",
1314 static const char *ipsecidtypestr
[] = {
1315 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1316 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1322 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_ID
));
1324 p
= (const struct ikev1_pl_id
*)ext
;
1326 if (sizeof(*p
) < item_len
) {
1327 data
= (const u_char
*)(p
+ 1);
1328 len
= item_len
- sizeof(*p
);
1335 ND_PRINT(" [phase=%u doi=%u proto=%u]", phase
, doi
, proto
);
1338 #ifndef USE_IPSECDOI_IN_PHASE1
1342 ND_PRINT(" idtype=%s",
1343 STR_OR_ID(GET_U_1(p
->d
.id_type
), idtypestr
));
1344 ND_PRINT(" doi_data=%u",
1345 GET_BE_U_4(p
->d
.doi_data
) & 0xffffff);
1348 #ifdef USE_IPSECDOI_IN_PHASE1
1353 const struct ipsecdoi_id
*doi_p
;
1355 uint8_t type
, proto_id
;
1357 doi_p
= (const struct ipsecdoi_id
*)ext
;
1358 ND_TCHECK_SIZE(doi_p
);
1359 type
= GET_U_1(doi_p
->type
);
1360 ND_PRINT(" idtype=%s", STR_OR_ID(type
, ipsecidtypestr
));
1361 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
1362 proto_id
= GET_U_1(doi_p
->proto_id
);
1363 if (!ndo
->ndo_nflag
&& proto_id
&& (p_name
= netdb_protoname(proto_id
)) != NULL
)
1364 ND_PRINT(" protoid=%s", p_name
);
1366 ND_PRINT(" protoid=%u", proto_id
);
1367 ND_PRINT(" port=%u", GET_BE_U_2(doi_p
->port
));
1372 ND_TCHECK_LEN(data
, len
);
1374 case IPSECDOI_ID_IPV4_ADDR
:
1376 ND_PRINT(" len=%u [bad: < 4]", len
);
1378 ND_PRINT(" len=%u %s", len
, GET_IPADDR_STRING(data
));
1381 case IPSECDOI_ID_FQDN
:
1382 case IPSECDOI_ID_USER_FQDN
:
1385 ND_PRINT(" len=%u ", len
);
1386 for (i
= 0; i
< len
; i
++)
1387 fn_print_char(ndo
, GET_U_1(data
+ i
));
1391 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
1395 ND_PRINT(" len=%u [bad: < 8]", len
);
1397 mask
= data
+ sizeof(nd_ipv4
);
1398 ND_PRINT(" len=%u %s/%u.%u.%u.%u", len
,
1399 GET_IPADDR_STRING(data
),
1400 GET_U_1(mask
), GET_U_1(mask
+ 1),
1407 case IPSECDOI_ID_IPV6_ADDR
:
1409 ND_PRINT(" len=%u [bad: < 16]", len
);
1411 ND_PRINT(" len=%u %s", len
, GET_IP6ADDR_STRING(data
));
1414 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
1418 ND_PRINT(" len=%u [bad: < 32]", len
);
1420 mask
= (const u_char
*)(data
+ sizeof(nd_ipv6
));
1422 ND_PRINT(" len=%u %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len
,
1423 GET_IP6ADDR_STRING(data
),
1424 GET_U_1(mask
), GET_U_1(mask
+ 1),
1438 GET_U_1(mask
+ 15));
1443 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1445 ND_PRINT(" len=%u [bad: < 8]", len
);
1447 ND_PRINT(" len=%u %s-%s", len
,
1448 GET_IPADDR_STRING(data
),
1449 GET_IPADDR_STRING(data
+ sizeof(nd_ipv4
)));
1453 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1455 ND_PRINT(" len=%u [bad: < 32]", len
);
1457 ND_PRINT(" len=%u %s-%s", len
,
1458 GET_IP6ADDR_STRING(data
),
1459 GET_IP6ADDR_STRING(data
+ sizeof(nd_ipv6
)));
1463 case IPSECDOI_ID_DER_ASN1_DN
:
1464 case IPSECDOI_ID_DER_ASN1_GN
:
1465 case IPSECDOI_ID_KEY_ID
:
1472 ND_PRINT(" len=%u", len
);
1473 if (2 < ndo
->ndo_vflag
) {
1475 if (!rawprint(ndo
, (const uint8_t *)data
, len
))
1479 return (const u_char
*)ext
+ item_len
;
1481 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID
));
1485 static const u_char
*
1486 ikev1_cert_print(netdissect_options
*ndo
, u_char tpay _U_
,
1487 const struct isakmp_gen
*ext
, u_int item_len
,
1488 const u_char
*ep _U_
, uint32_t phase _U_
,
1490 uint32_t proto0 _U_
, int depth _U_
)
1492 const struct ikev1_pl_cert
*p
;
1493 static const char *certstr
[] = {
1494 "none", "pkcs7", "pgp", "dns",
1495 "x509sign", "x509ke", "kerberos", "crl",
1496 "arl", "spki", "x509attr",
1499 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CERT
));
1501 p
= (const struct ikev1_pl_cert
*)ext
;
1504 * Our caller has ensured that the length is >= 4.
1506 ND_PRINT(" len=%u", item_len
- 4);
1507 ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p
->encode
), certstr
));
1508 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1509 /* Print the entire payload in hex */
1511 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1514 return (const u_char
*)ext
+ item_len
;
1516 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
));
1520 static const u_char
*
1521 ikev1_cr_print(netdissect_options
*ndo
, u_char tpay _U_
,
1522 const struct isakmp_gen
*ext
, u_int item_len
,
1523 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1524 uint32_t proto0 _U_
, int depth _U_
)
1526 const struct ikev1_pl_cert
*p
;
1527 static const char *certstr
[] = {
1528 "none", "pkcs7", "pgp", "dns",
1529 "x509sign", "x509ke", "kerberos", "crl",
1530 "arl", "spki", "x509attr",
1533 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CR
));
1535 p
= (const struct ikev1_pl_cert
*)ext
;
1538 * Our caller has ensured that the length is >= 4.
1540 ND_PRINT(" len=%u", item_len
- 4);
1541 ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p
->encode
), certstr
));
1542 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1543 /* Print the entire payload in hex */
1545 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1548 return (const u_char
*)ext
+ item_len
;
1550 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CR
));
1554 static const u_char
*
1555 ikev1_hash_print(netdissect_options
*ndo
, u_char tpay _U_
,
1556 const struct isakmp_gen
*ext
, u_int item_len
,
1557 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1558 uint32_t proto _U_
, int depth _U_
)
1560 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_HASH
));
1562 ND_TCHECK_SIZE(ext
);
1564 * Our caller has ensured that the length is >= 4.
1566 ND_PRINT(" len=%u", item_len
- 4);
1567 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1568 /* Print the entire payload in hex */
1570 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1573 return (const u_char
*)ext
+ item_len
;
1575 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
));
1579 static const u_char
*
1580 ikev1_sig_print(netdissect_options
*ndo
, u_char tpay _U_
,
1581 const struct isakmp_gen
*ext
, u_int item_len
,
1582 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1583 uint32_t proto _U_
, int depth _U_
)
1585 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SIG
));
1587 ND_TCHECK_SIZE(ext
);
1589 * Our caller has ensured that the length is >= 4.
1591 ND_PRINT(" len=%u", item_len
- 4);
1592 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1593 /* Print the entire payload in hex */
1595 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1598 return (const u_char
*)ext
+ item_len
;
1600 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
));
1604 static const u_char
*
1605 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1606 const struct isakmp_gen
*ext
,
1609 uint32_t phase _U_
, uint32_t doi _U_
,
1610 uint32_t proto _U_
, int depth _U_
)
1612 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_NONCE
));
1614 ND_TCHECK_SIZE(ext
);
1616 * Our caller has ensured that the length is >= 4.
1618 ND_PRINT(" n len=%u", item_len
- 4);
1620 if (ndo
->ndo_vflag
> 2) {
1622 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1624 } else if (ndo
->ndo_vflag
> 1) {
1626 if (!ike_show_somedata(ndo
, (const u_char
*)(ext
+ 1), ep
))
1630 return (const u_char
*)ext
+ item_len
;
1632 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
));
1636 static const u_char
*
1637 ikev1_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
1638 const struct isakmp_gen
*ext
, u_int item_len
,
1639 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1640 uint32_t proto0 _U_
, int depth _U_
)
1642 const struct ikev1_pl_n
*p
;
1649 static const char *notify_error_str
[] = {
1650 NULL
, "INVALID-PAYLOAD-TYPE",
1651 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1652 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1653 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1654 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1655 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1656 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1657 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1658 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1659 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1660 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1661 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1662 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1663 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1664 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1665 "UNEQUAL-PAYLOAD-LENGTHS",
1667 static const char *ipsec_notify_error_str
[] = {
1670 static const char *notify_status_str
[] = {
1673 static const char *ipsec_notify_status_str
[] = {
1674 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1677 /* NOTE: these macro must be called with x in proper range */
1680 #define NOTIFY_ERROR_STR(x) \
1681 STR_OR_ID((x), notify_error_str)
1684 #define IPSEC_NOTIFY_ERROR_STR(x) \
1685 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1688 #define NOTIFY_STATUS_STR(x) \
1689 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1692 #define IPSEC_NOTIFY_STATUS_STR(x) \
1693 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1695 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_N
));
1697 p
= (const struct ikev1_pl_n
*)ext
;
1699 doi
= GET_BE_U_4(p
->doi
);
1700 proto
= GET_U_1(p
->prot_id
);
1702 ND_PRINT(" doi=%u", doi
);
1703 ND_PRINT(" proto=%u", proto
);
1704 type
= GET_BE_U_2(p
->type
);
1706 ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type
));
1707 else if (type
< 16384)
1708 ND_PRINT(" type=%s", numstr(type
));
1709 else if (type
< 24576)
1710 ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type
));
1712 ND_PRINT(" type=%s", numstr(type
));
1713 spi_size
= GET_U_1(p
->spi_size
);
1716 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
1719 return (const u_char
*)(p
+ 1) + spi_size
;
1722 ND_PRINT(" doi=ipsec");
1723 ND_PRINT(" proto=%s", PROTOIDSTR(proto
));
1724 type
= GET_BE_U_2(p
->type
);
1726 ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type
));
1727 else if (type
< 16384)
1728 ND_PRINT(" type=%s", IPSEC_NOTIFY_ERROR_STR(type
));
1729 else if (type
< 24576)
1730 ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type
));
1731 else if (type
< 32768)
1732 ND_PRINT(" type=%s", IPSEC_NOTIFY_STATUS_STR(type
));
1734 ND_PRINT(" type=%s", numstr(type
));
1735 spi_size
= GET_U_1(p
->spi_size
);
1738 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
1742 cp
= (const u_char
*)(p
+ 1) + spi_size
;
1743 ep2
= (const u_char
*)p
+ item_len
;
1747 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
1749 const struct attrmap
*map
= oakley_t_map
;
1750 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1751 ND_PRINT(" attrs=(");
1752 while (cp
< ep
&& cp
< ep2
) {
1753 cp
= ikev1_attrmap_print(ndo
, cp
, ep2
, map
, nmap
);
1762 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1763 ND_PRINT(" status=(");
1764 ND_PRINT("replay detection %sabled",
1765 GET_BE_U_4(cp
) ? "en" : "dis");
1770 * XXX - fill in more types here; see, for example,
1771 * draft-ietf-ipsec-notifymsg-04.
1773 if (ndo
->ndo_vflag
> 3) {
1774 ND_PRINT(" data=(");
1775 if (!rawprint(ndo
, (const uint8_t *)(cp
), ep
- cp
))
1779 if (!ike_show_somedata(ndo
, cp
, ep
))
1785 return (const u_char
*)ext
+ item_len
;
1787 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N
));
1791 static const u_char
*
1792 ikev1_d_print(netdissect_options
*ndo
, u_char tpay _U_
,
1793 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1794 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1795 uint32_t proto0 _U_
, int depth _U_
)
1797 const struct ikev1_pl_d
*p
;
1805 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_D
));
1807 p
= (const struct ikev1_pl_d
*)ext
;
1809 doi
= GET_BE_U_4(p
->doi
);
1810 proto
= GET_U_1(p
->prot_id
);
1812 ND_PRINT(" doi=%u", doi
);
1813 ND_PRINT(" proto=%u", proto
);
1815 ND_PRINT(" doi=ipsec");
1816 ND_PRINT(" proto=%s", PROTOIDSTR(proto
));
1818 spi_size
= GET_U_1(p
->spi_size
);
1819 ND_PRINT(" spilen=%u", spi_size
);
1820 num_spi
= GET_BE_U_2(p
->num_spi
);
1821 ND_PRINT(" nspi=%u", num_spi
);
1822 q
= (const uint8_t *)(p
+ 1);
1825 for (i
= 0; i
< num_spi
; i
++) {
1828 if (!rawprint(ndo
, (const uint8_t *)q
, spi_size
))
1835 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_D
));
1839 static const u_char
*
1840 ikev1_vid_print(netdissect_options
*ndo
, u_char tpay _U_
,
1841 const struct isakmp_gen
*ext
,
1842 u_int item_len
, const u_char
*ep _U_
,
1843 uint32_t phase _U_
, uint32_t doi _U_
,
1844 uint32_t proto _U_
, int depth _U_
)
1846 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_VID
));
1848 ND_TCHECK_SIZE(ext
);
1850 * Our caller has ensured that the length is >= 4.
1852 ND_PRINT(" len=%u", item_len
- 4);
1853 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1854 /* Print the entire payload in hex */
1856 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1859 return (const u_char
*)ext
+ item_len
;
1861 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID
));
1865 /************************************************************/
1867 /* IKE v2 - rfc4306 - dissector */
1869 /************************************************************/
1872 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, uint8_t critical
)
1874 ND_PRINT("%s%s:", payname
, critical
&0x80 ? "[C]" : "");
1877 static const u_char
*
1878 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1879 const struct isakmp_gen
*ext
, u_int item_len
)
1881 const struct isakmp_gen
*p
= (const struct isakmp_gen
*)ext
;
1883 ND_TCHECK_SIZE(ext
);
1884 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(p
->critical
));
1887 * Our caller has ensured that the length is >= 4.
1889 ND_PRINT(" len=%u", item_len
- 4);
1890 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1891 /* Print the entire payload in hex */
1893 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1896 return (const u_char
*)ext
+ item_len
;
1898 ND_PRINT(" [|%s]", NPSTR(tpay
));
1902 static const u_char
*
1903 ikev2_t_print(netdissect_options
*ndo
, int tcount
,
1904 const struct isakmp_gen
*ext
, u_int item_len
,
1907 const struct ikev2_t
*p
;
1912 const struct attrmap
*map
;
1916 p
= (const struct ikev2_t
*)ext
;
1918 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), GET_U_1(p
->h
.critical
));
1920 t_id
= GET_BE_U_2(p
->t_id
);
1925 t_type
= GET_U_1(p
->t_type
);
1928 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1930 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1934 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1938 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1942 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1946 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1955 ND_PRINT(" #%u type=%s id=%s ", tcount
,
1956 STR_OR_ID(t_type
, ikev2_t_type_map
),
1959 ND_PRINT(" #%u type=%s id=%u ", tcount
,
1960 STR_OR_ID(t_type
, ikev2_t_type_map
),
1962 cp
= (const u_char
*)(p
+ 1);
1963 ep2
= (const u_char
*)p
+ item_len
;
1964 while (cp
< ep
&& cp
< ep2
) {
1966 cp
= ikev1_attrmap_print(ndo
, cp
, ep2
, map
, nmap
);
1968 cp
= ikev1_attr_print(ndo
, cp
, ep2
);
1976 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T
));
1980 static const u_char
*
1981 ikev2_p_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount _U_
,
1982 const struct isakmp_gen
*ext
, u_int oprop_length
,
1983 const u_char
*ep
, int depth
)
1985 const struct ikev2_p
*p
;
1994 p
= (const struct ikev2_p
*)ext
;
1997 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), GET_U_1(p
->h
.critical
));
2000 * ikev2_sa_print() guarantees that this is >= 4.
2002 prop_length
= oprop_length
- 4;
2003 ND_PRINT(" #%u protoid=%s transform=%u len=%u",
2004 GET_U_1(p
->p_no
), PROTOIDSTR(GET_U_1(p
->prot_id
)),
2005 GET_U_1(p
->num_t
), oprop_length
);
2006 cp
= (const u_char
*)(p
+ 1);
2008 spi_size
= GET_U_1(p
->spi_size
);
2010 if (prop_length
< spi_size
)
2013 if (!rawprint(ndo
, (const uint8_t *)cp
, spi_size
))
2016 prop_length
-= spi_size
;
2020 * Print the transforms.
2023 for (np
= ISAKMP_NPTYPE_T
; np
!= 0; np
= GET_U_1(ext
->np
)) {
2025 ext
= (const struct isakmp_gen
*)cp
;
2026 if (prop_length
< sizeof(*ext
))
2028 ND_TCHECK_SIZE(ext
);
2031 * Since we can't have a payload length of less than 4 bytes,
2032 * we need to bail out here if the generic header is nonsensical
2033 * or truncated, otherwise we could loop forever processing
2034 * zero-length items or otherwise misdissect the packet.
2036 item_len
= GET_BE_U_2(ext
->len
);
2040 if (prop_length
< item_len
)
2042 ND_TCHECK_LEN(cp
, item_len
);
2046 for (i
= 0; i
< depth
; i
++)
2049 if (np
== ISAKMP_NPTYPE_T
) {
2050 cp
= ikev2_t_print(ndo
, tcount
, ext
, item_len
, ep
);
2052 /* error, already reported */
2056 ND_PRINT("%s", NPSTR(np
));
2061 prop_length
-= item_len
;
2066 * Skip the rest of the proposal.
2069 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P
));
2072 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P
));
2076 static const u_char
*
2077 ikev2_sa_print(netdissect_options
*ndo
, u_char tpay
,
2078 const struct isakmp_gen
*ext1
,
2079 u_int osa_length
, const u_char
*ep
,
2080 uint32_t phase _U_
, uint32_t doi _U_
,
2081 uint32_t proto _U_
, int depth
)
2083 const struct isakmp_gen
*ext
;
2091 ND_TCHECK_SIZE(ext1
);
2092 ikev2_pay_print(ndo
, "sa", GET_U_1(ext1
->critical
));
2095 * ikev2_sub0_print() guarantees that this is >= 4.
2097 osa_length
= GET_BE_U_2(ext1
->len
);
2098 sa_length
= osa_length
- 4;
2099 ND_PRINT(" len=%u", sa_length
);
2102 * Print the payloads.
2104 cp
= (const u_char
*)(ext1
+ 1);
2106 for (np
= ISAKMP_NPTYPE_P
; np
!= 0; np
= GET_U_1(ext
->np
)) {
2108 ext
= (const struct isakmp_gen
*)cp
;
2109 if (sa_length
< sizeof(*ext
))
2111 ND_TCHECK_SIZE(ext
);
2114 * Since we can't have a payload length of less than 4 bytes,
2115 * we need to bail out here if the generic header is nonsensical
2116 * or truncated, otherwise we could loop forever processing
2117 * zero-length items or otherwise misdissect the packet.
2119 item_len
= GET_BE_U_2(ext
->len
);
2123 if (sa_length
< item_len
)
2125 ND_TCHECK_LEN(cp
, item_len
);
2129 for (i
= 0; i
< depth
; i
++)
2132 if (np
== ISAKMP_NPTYPE_P
) {
2133 cp
= ikev2_p_print(ndo
, np
, pcount
, ext
, item_len
,
2136 /* error, already reported */
2140 ND_PRINT("%s", NPSTR(np
));
2145 sa_length
-= item_len
;
2150 * Skip the rest of the SA.
2153 ND_PRINT(" [|%s]", NPSTR(tpay
));
2156 ND_PRINT(" [|%s]", NPSTR(tpay
));
2160 static const u_char
*
2161 ikev2_ke_print(netdissect_options
*ndo
, u_char tpay
,
2162 const struct isakmp_gen
*ext
,
2163 u_int item_len
, const u_char
*ep _U_
,
2164 uint32_t phase _U_
, uint32_t doi _U_
,
2165 uint32_t proto _U_
, int depth _U_
)
2167 const struct ikev2_ke
*k
;
2169 k
= (const struct ikev2_ke
*)ext
;
2171 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(k
->h
.critical
));
2174 ND_PRINT(" len=%u < 8", item_len
);
2175 return (const u_char
*)ext
+ item_len
;
2177 ND_PRINT(" len=%u group=%s", item_len
- 8,
2178 STR_OR_ID(GET_BE_U_2(k
->ke_group
), dh_p_map
));
2180 if (2 < ndo
->ndo_vflag
&& 8 < item_len
) {
2182 if (!rawprint(ndo
, (const uint8_t *)(k
+ 1), item_len
- 8))
2185 return (const u_char
*)ext
+ item_len
;
2187 ND_PRINT(" [|%s]", NPSTR(tpay
));
2191 static const u_char
*
2192 ikev2_ID_print(netdissect_options
*ndo
, u_char tpay
,
2193 const struct isakmp_gen
*ext
,
2194 u_int item_len
, const u_char
*ep _U_
,
2195 uint32_t phase _U_
, uint32_t doi _U_
,
2196 uint32_t proto _U_
, int depth _U_
)
2198 const struct ikev2_id
*idp
;
2199 u_int idtype_len
, i
;
2200 unsigned int dumpascii
, dumphex
;
2201 const unsigned char *typedata
;
2203 idp
= (const struct ikev2_id
*)ext
;
2204 ND_TCHECK_SIZE(idp
);
2205 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(idp
->h
.critical
));
2208 * Our caller has ensured that the length is >= 4.
2210 ND_PRINT(" len=%u", item_len
- 4);
2211 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
2212 /* Print the entire payload in hex */
2214 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
2218 idtype_len
=item_len
- sizeof(struct ikev2_id
);
2221 typedata
= (const unsigned char *)(ext
)+sizeof(struct ikev2_id
);
2223 switch(GET_U_1(idp
->type
)) {
2232 case ID_RFC822_ADDR
:
2233 ND_PRINT(" rfc822:");
2240 case ID_DER_ASN1_DN
:
2244 case ID_DER_ASN1_GN
:
2249 ND_PRINT(" keyid:");
2255 ND_TCHECK_LEN(typedata
, idtype_len
);
2256 for(i
=0; i
<idtype_len
; i
++) {
2257 if(ND_ASCII_ISPRINT(GET_U_1(typedata
+ i
))) {
2258 ND_PRINT("%c", GET_U_1(typedata
+ i
));
2265 if (!rawprint(ndo
, (const uint8_t *)typedata
, idtype_len
))
2269 return (const u_char
*)ext
+ item_len
;
2271 ND_PRINT(" [|%s]", NPSTR(tpay
));
2275 static const u_char
*
2276 ikev2_cert_print(netdissect_options
*ndo
, u_char tpay
,
2277 const struct isakmp_gen
*ext
,
2278 u_int item_len
, const u_char
*ep _U_
,
2279 uint32_t phase _U_
, uint32_t doi _U_
,
2280 uint32_t proto _U_
, int depth _U_
)
2282 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2285 static const u_char
*
2286 ikev2_cr_print(netdissect_options
*ndo
, u_char tpay
,
2287 const struct isakmp_gen
*ext
,
2288 u_int item_len
, const u_char
*ep _U_
,
2289 uint32_t phase _U_
, uint32_t doi _U_
,
2290 uint32_t proto _U_
, int depth _U_
)
2292 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2295 static const u_char
*
2296 ikev2_auth_print(netdissect_options
*ndo
, u_char tpay
,
2297 const struct isakmp_gen
*ext
,
2298 u_int item_len
, const u_char
*ep
,
2299 uint32_t phase _U_
, uint32_t doi _U_
,
2300 uint32_t proto _U_
, int depth _U_
)
2302 const struct ikev2_auth
*p
;
2303 const char *v2_auth
[]={ "invalid", "rsasig",
2304 "shared-secret", "dsssig" };
2305 const u_char
*authdata
= (const u_char
*)ext
+ sizeof(struct ikev2_auth
);
2307 ND_TCHECK_LEN(ext
, sizeof(struct ikev2_auth
));
2308 p
= (const struct ikev2_auth
*)ext
;
2309 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(p
->h
.critical
));
2312 * Our caller has ensured that the length is >= 4.
2314 ND_PRINT(" len=%u method=%s", item_len
-4,
2315 STR_OR_ID(GET_U_1(p
->auth_method
), v2_auth
));
2317 if (ndo
->ndo_vflag
> 1) {
2318 ND_PRINT(" authdata=(");
2319 if (!rawprint(ndo
, (const uint8_t *)authdata
, item_len
- sizeof(struct ikev2_auth
)))
2322 } else if (ndo
->ndo_vflag
) {
2323 if (!ike_show_somedata(ndo
, authdata
, ep
))
2328 return (const u_char
*)ext
+ item_len
;
2330 ND_PRINT(" [|%s]", NPSTR(tpay
));
2334 static const u_char
*
2335 ikev2_nonce_print(netdissect_options
*ndo
, u_char tpay
,
2336 const struct isakmp_gen
*ext
,
2337 u_int item_len
, const u_char
*ep
,
2338 uint32_t phase _U_
, uint32_t doi _U_
,
2339 uint32_t proto _U_
, int depth _U_
)
2341 ND_TCHECK_SIZE(ext
);
2342 ikev2_pay_print(ndo
, "nonce", GET_U_1(ext
->critical
));
2345 * Our caller has ensured that the length is >= 4.
2347 ND_PRINT(" len=%u", item_len
- 4);
2348 if (1 < ndo
->ndo_vflag
&& 4 < item_len
) {
2349 ND_PRINT(" nonce=(");
2350 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
2353 } else if(ndo
->ndo_vflag
&& 4 < item_len
) {
2354 if(!ike_show_somedata(ndo
, (const u_char
*)(ext
+1), ep
)) goto trunc
;
2357 return (const u_char
*)ext
+ item_len
;
2359 ND_PRINT(" [|%s]", NPSTR(tpay
));
2363 /* notify payloads */
2364 static const u_char
*
2365 ikev2_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
2366 const struct isakmp_gen
*ext
,
2367 u_int item_len
, const u_char
*ep
,
2368 uint32_t phase _U_
, uint32_t doi _U_
,
2369 uint32_t proto _U_
, int depth _U_
)
2371 const struct ikev2_n
*p
;
2375 u_char showspi
, showsomedata
;
2376 const char *notify_name
;
2378 p
= (const struct ikev2_n
*)ext
;
2380 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), GET_U_1(p
->h
.critical
));
2386 ND_PRINT(" prot_id=%s", PROTOIDSTR(GET_U_1(p
->prot_id
)));
2388 type
= GET_BE_U_2(p
->type
);
2390 /* notify space is annoying sparse */
2392 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
2393 notify_name
= "unsupported_critical_payload";
2397 case IV2_NOTIFY_INVALID_IKE_SPI
:
2398 notify_name
= "invalid_ike_spi";
2402 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
2403 notify_name
= "invalid_major_version";
2407 case IV2_NOTIFY_INVALID_SYNTAX
:
2408 notify_name
= "invalid_syntax";
2412 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
2413 notify_name
= "invalid_message_id";
2417 case IV2_NOTIFY_INVALID_SPI
:
2418 notify_name
= "invalid_spi";
2422 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
2423 notify_name
= "no_protocol_chosen";
2427 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
2428 notify_name
= "invalid_ke_payload";
2432 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
2433 notify_name
= "authentication_failed";
2437 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
2438 notify_name
= "single_pair_required";
2442 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
2443 notify_name
= "no_additional_sas";
2447 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
2448 notify_name
= "internal_address_failure";
2452 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
2453 notify_name
= "failed:cp_required";
2457 case IV2_NOTIFY_INVALID_SELECTORS
:
2458 notify_name
= "invalid_selectors";
2462 case IV2_NOTIFY_INITIAL_CONTACT
:
2463 notify_name
= "initial_contact";
2467 case IV2_NOTIFY_SET_WINDOW_SIZE
:
2468 notify_name
= "set_window_size";
2472 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
2473 notify_name
= "additional_ts_possible";
2477 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
2478 notify_name
= "ipcomp_supported";
2482 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
2483 notify_name
= "nat_detection_source_ip";
2487 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
2488 notify_name
= "nat_detection_destination_ip";
2492 case IV2_NOTIFY_COOKIE
:
2493 notify_name
= "cookie";
2498 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
2499 notify_name
= "use_transport_mode";
2503 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
2504 notify_name
= "http_cert_lookup_supported";
2508 case IV2_NOTIFY_REKEY_SA
:
2509 notify_name
= "rekey_sa";
2513 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
2514 notify_name
= "tfc_padding_not_supported";
2518 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
2519 notify_name
= "non_first_fragment_also";
2525 notify_name
="error";
2526 } else if(type
< 16384) {
2527 notify_name
="private-error";
2528 } else if(type
< 40960) {
2529 notify_name
="status";
2531 notify_name
="private-status";
2536 ND_PRINT(" type=%u(%s)", type
, notify_name
);
2540 spi_size
= GET_U_1(p
->spi_size
);
2541 if (showspi
&& spi_size
) {
2543 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), spi_size
))
2547 cp
= (const u_char
*)(p
+ 1) + spi_size
;
2550 if (ndo
->ndo_vflag
> 3 || (showsomedata
&& ep
-cp
< 30)) {
2551 ND_PRINT(" data=(");
2552 if (!rawprint(ndo
, (const uint8_t *)(cp
), ep
- cp
))
2556 } else if (showsomedata
) {
2557 if (!ike_show_somedata(ndo
, cp
, ep
))
2562 return (const u_char
*)ext
+ item_len
;
2564 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N
));
2568 static const u_char
*
2569 ikev2_d_print(netdissect_options
*ndo
, u_char tpay
,
2570 const struct isakmp_gen
*ext
,
2571 u_int item_len
, const u_char
*ep _U_
,
2572 uint32_t phase _U_
, uint32_t doi _U_
,
2573 uint32_t proto _U_
, int depth _U_
)
2575 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2578 static const u_char
*
2579 ikev2_vid_print(netdissect_options
*ndo
, u_char tpay
,
2580 const struct isakmp_gen
*ext
,
2581 u_int item_len
, const u_char
*ep _U_
,
2582 uint32_t phase _U_
, uint32_t doi _U_
,
2583 uint32_t proto _U_
, int depth _U_
)
2588 ND_TCHECK_SIZE(ext
);
2589 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(ext
->critical
));
2592 * Our caller has ensured that the length is >= 4.
2594 ND_PRINT(" len=%u vid=", item_len
- 4);
2596 vid
= (const u_char
*)(ext
+1);
2598 ND_TCHECK_LEN(vid
, len
);
2599 for(i
=0; i
<len
; i
++) {
2600 if(ND_ASCII_ISPRINT(GET_U_1(vid
+ i
)))
2601 ND_PRINT("%c", GET_U_1(vid
+ i
));
2604 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2605 /* Print the entire payload in hex */
2607 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
2610 return (const u_char
*)ext
+ item_len
;
2612 ND_PRINT(" [|%s]", NPSTR(tpay
));
2616 static const u_char
*
2617 ikev2_TS_print(netdissect_options
*ndo
, u_char tpay
,
2618 const struct isakmp_gen
*ext
,
2619 u_int item_len
, const u_char
*ep _U_
,
2620 uint32_t phase _U_
, uint32_t doi _U_
,
2621 uint32_t proto _U_
, int depth _U_
)
2623 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2626 static const u_char
*
2627 ikev2_e_print(netdissect_options
*ndo
,
2628 #ifndef HAVE_LIBCRYPTO
2631 const struct isakmp
*base
,
2633 const struct isakmp_gen
*ext
,
2634 u_int item_len
, const u_char
*ep _U_
,
2635 #ifndef HAVE_LIBCRYPTO
2639 #ifndef HAVE_LIBCRYPTO
2643 #ifndef HAVE_LIBCRYPTO
2647 #ifndef HAVE_LIBCRYPTO
2654 #ifdef HAVE_LIBCRYPTO
2658 ND_TCHECK_SIZE(ext
);
2659 ikev2_pay_print(ndo
, NPSTR(tpay
), GET_U_1(ext
->critical
));
2663 ND_PRINT(" len=%u", dlen
);
2664 if (2 < ndo
->ndo_vflag
&& 4 < dlen
) {
2666 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), dlen
))
2670 dat
= (const u_char
*)(ext
+1);
2671 ND_TCHECK_LEN(dat
, dlen
);
2673 #ifdef HAVE_LIBCRYPTO
2674 np
= GET_U_1(ext
->np
);
2676 /* try to decrypt it! */
2677 if(esp_decrypt_buffer_by_ikev2_print(ndo
,
2678 GET_U_1(base
->flags
) & ISAKMP_FLAG_I
,
2679 base
->i_ck
, base
->r_ck
,
2682 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
2684 /* got it decrypted, print stuff inside. */
2685 ikev2_sub_print(ndo
, base
, np
, ext
,
2686 ndo
->ndo_snapend
, phase
, doi
, proto
, depth
+1);
2689 * esp_decrypt_buffer_by_ikev2_print pushed information
2690 * on the buffer stack; we're done with the buffer, so
2691 * pop it (which frees the buffer)
2693 nd_pop_packet_info(ndo
);
2698 /* always return NULL, because E must be at end, and NP refers
2699 * to what was inside.
2703 ND_PRINT(" [|%s]", NPSTR(tpay
));
2707 static const u_char
*
2708 ikev2_cp_print(netdissect_options
*ndo
, u_char tpay
,
2709 const struct isakmp_gen
*ext
,
2710 u_int item_len
, const u_char
*ep _U_
,
2711 uint32_t phase _U_
, uint32_t doi _U_
,
2712 uint32_t proto _U_
, int depth _U_
)
2714 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2717 static const u_char
*
2718 ikev2_eap_print(netdissect_options
*ndo
, u_char tpay
,
2719 const struct isakmp_gen
*ext
,
2720 u_int item_len
, const u_char
*ep _U_
,
2721 uint32_t phase _U_
, uint32_t doi _U_
,
2722 uint32_t proto _U_
, int depth _U_
)
2724 return ikev2_gen_print(ndo
, tpay
, ext
, item_len
);
2727 static const u_char
*
2728 ike_sub0_print(netdissect_options
*ndo
,
2729 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2731 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2736 cp
= (const u_char
*)ext
;
2737 ND_TCHECK_SIZE(ext
);
2740 * Since we can't have a payload length of less than 4 bytes,
2741 * we need to bail out here if the generic header is nonsensical
2742 * or truncated, otherwise we could loop forever processing
2743 * zero-length items or otherwise misdissect the packet.
2745 item_len
= GET_BE_U_2(ext
->len
);
2751 * XXX - what if item_len is too short, or too long,
2752 * for this payload type?
2754 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2756 ND_PRINT("%s", NPSTR(np
));
2762 nd_print_trunc(ndo
);
2766 static const u_char
*
2767 ikev1_sub_print(netdissect_options
*ndo
,
2768 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2769 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2775 cp
= (const u_char
*)ext
;
2778 ND_TCHECK_SIZE(ext
);
2780 item_len
= GET_BE_U_2(ext
->len
);
2781 ND_TCHECK_LEN(ext
, item_len
);
2785 for (i
= 0; i
< depth
; i
++)
2788 cp
= ike_sub0_print(ndo
, np
, ext
, ep
, phase
, doi
, proto
, depth
);
2793 /* Zero-length subitem */
2797 np
= GET_U_1(ext
->np
);
2798 ext
= (const struct isakmp_gen
*)cp
;
2802 ND_PRINT(" [|%s]", NPSTR(np
));
2809 static char buf
[20];
2810 snprintf(buf
, sizeof(buf
), "#%u", x
);
2815 ikev1_print(netdissect_options
*ndo
,
2816 const u_char
*bp
, u_int length
,
2817 const u_char
*bp2
, const struct isakmp
*base
)
2819 const struct isakmp
*p
;
2826 p
= (const struct isakmp
*)bp
;
2827 ep
= ndo
->ndo_snapend
;
2829 phase
= (GET_BE_U_4(base
->msgid
) == 0) ? 1 : 2;
2831 ND_PRINT(" phase %u", phase
);
2833 ND_PRINT(" phase %u/others", phase
);
2835 i
= cookie_find(&base
->i_ck
);
2837 if (iszero(ndo
, base
->r_ck
, sizeof(base
->r_ck
))) {
2838 /* the first packet */
2841 cookie_record(ndo
, &base
->i_ck
, bp2
);
2845 if (bp2
&& cookie_isinitiator(ndo
, i
, bp2
))
2847 else if (bp2
&& cookie_isresponder(ndo
, i
, bp2
))
2853 ND_PRINT(" %s", ETYPESTR(GET_U_1(base
->etype
)));
2854 flags
= GET_U_1(base
->flags
);
2856 ND_PRINT("[%s%s]", flags
& ISAKMP_FLAG_E
? "E" : "",
2857 flags
& ISAKMP_FLAG_C
? "C" : "");
2860 if (ndo
->ndo_vflag
) {
2861 const struct isakmp_gen
*ext
;
2865 np
= GET_U_1(base
->np
);
2867 /* regardless of phase... */
2868 if (flags
& ISAKMP_FLAG_E
) {
2870 * encrypted, nothing we can do right now.
2871 * we hope to decrypt the packet in the future...
2873 ND_PRINT(" [encrypted %s]", NPSTR(np
));
2877 CHECKLEN(p
+ 1, np
);
2878 ext
= (const struct isakmp_gen
*)(p
+ 1);
2879 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
2883 if (ndo
->ndo_vflag
) {
2884 if (GET_BE_U_4(base
->len
) != length
) {
2885 ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
2886 GET_BE_U_4(base
->len
), length
);
2891 static const u_char
*
2892 ikev2_sub0_print(netdissect_options
*ndo
, const struct isakmp
*base
,
2894 const struct isakmp_gen
*ext
, const u_char
*ep
,
2895 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2900 cp
= (const u_char
*)ext
;
2901 ND_TCHECK_SIZE(ext
);
2904 * Since we can't have a payload length of less than 4 bytes,
2905 * we need to bail out here if the generic header is nonsensical
2906 * or truncated, otherwise we could loop forever processing
2907 * zero-length items or otherwise misdissect the packet.
2909 item_len
= GET_BE_U_2(ext
->len
);
2913 if (np
== ISAKMP_NPTYPE_v2E
) {
2914 cp
= ikev2_e_print(ndo
, base
, np
, ext
, item_len
,
2915 ep
, phase
, doi
, proto
, depth
);
2916 } else if (NPFUNC(np
)) {
2918 * XXX - what if item_len is too short, or too long,
2919 * for this payload type?
2921 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
,
2922 ep
, phase
, doi
, proto
, depth
);
2924 ND_PRINT("%s", NPSTR(np
));
2930 nd_print_trunc(ndo
);
2934 static const u_char
*
2935 ikev2_sub_print(netdissect_options
*ndo
,
2936 const struct isakmp
*base
,
2937 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2938 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2943 cp
= (const u_char
*)ext
;
2945 ND_TCHECK_SIZE(ext
);
2947 ND_TCHECK_LEN(ext
, GET_BE_U_2(ext
->len
));
2951 for (i
= 0; i
< depth
; i
++)
2954 cp
= ikev2_sub0_print(ndo
, base
, np
,
2955 ext
, ep
, phase
, doi
, proto
, depth
);
2960 /* Zero-length subitem */
2964 np
= GET_U_1(ext
->np
);
2965 ext
= (const struct isakmp_gen
*)cp
;
2969 ND_PRINT(" [|%s]", NPSTR(np
));
2974 ikev2_print(netdissect_options
*ndo
,
2975 const u_char
*bp
, u_int length
,
2976 const u_char
*bp2 _U_
, const struct isakmp
*base
)
2978 const struct isakmp
*p
;
2984 p
= (const struct isakmp
*)bp
;
2985 ep
= ndo
->ndo_snapend
;
2987 phase
= (GET_BE_U_4(base
->msgid
) == 0) ? 1 : 2;
2989 ND_PRINT(" parent_sa");
2991 ND_PRINT(" child_sa ");
2993 ND_PRINT(" %s", ETYPESTR(GET_U_1(base
->etype
)));
2994 flags
= GET_U_1(base
->flags
);
2996 ND_PRINT("[%s%s%s]",
2997 flags
& ISAKMP_FLAG_I
? "I" : "",
2998 flags
& ISAKMP_FLAG_V
? "V" : "",
2999 flags
& ISAKMP_FLAG_R
? "R" : "");
3002 if (ndo
->ndo_vflag
) {
3003 const struct isakmp_gen
*ext
;
3007 np
= GET_U_1(base
->np
);
3009 /* regardless of phase... */
3010 if (flags
& ISAKMP_FLAG_E
) {
3012 * encrypted, nothing we can do right now.
3013 * we hope to decrypt the packet in the future...
3015 ND_PRINT(" [encrypted %s]", NPSTR(np
));
3020 ext
= (const struct isakmp_gen
*)(p
+ 1);
3021 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
3025 if (ndo
->ndo_vflag
) {
3026 if (GET_BE_U_4(base
->len
) != length
) {
3027 ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
3028 GET_BE_U_4(base
->len
), length
);
3034 isakmp_print(netdissect_options
*ndo
,
3035 const u_char
*bp
, u_int length
,
3038 const struct isakmp
*p
;
3042 ndo
->ndo_protocol
= "isakmp";
3043 #ifdef HAVE_LIBCRYPTO
3044 /* initialize SAs */
3045 if (ndo
->ndo_sa_list_head
== NULL
) {
3046 if (ndo
->ndo_espsecret
)
3047 esp_decodesecret_print(ndo
);
3051 p
= (const struct isakmp
*)bp
;
3052 ep
= ndo
->ndo_snapend
;
3054 if ((const struct isakmp
*)ep
< p
+ 1) {
3055 nd_print_trunc(ndo
);
3060 major
= (GET_U_1(p
->vers
) & ISAKMP_VERS_MAJOR
)
3061 >> ISAKMP_VERS_MAJOR_SHIFT
;
3062 minor
= (GET_U_1(p
->vers
) & ISAKMP_VERS_MINOR
)
3063 >> ISAKMP_VERS_MINOR_SHIFT
;
3065 if (ndo
->ndo_vflag
) {
3066 ND_PRINT(" %u.%u", major
, minor
);
3069 if (ndo
->ndo_vflag
) {
3070 ND_PRINT(" msgid ");
3071 hexprint(ndo
, p
->msgid
, sizeof(p
->msgid
));
3074 if (1 < ndo
->ndo_vflag
) {
3075 ND_PRINT(" cookie ");
3076 hexprint(ndo
, p
->i_ck
, sizeof(p
->i_ck
));
3078 hexprint(ndo
, p
->r_ck
, sizeof(p
->r_ck
));
3083 case IKEv1_MAJOR_VERSION
:
3084 ikev1_print(ndo
, bp
, length
, bp2
, p
);
3087 case IKEv2_MAJOR_VERSION
:
3088 ikev2_print(ndo
, bp
, length
, bp2
, p
);
3094 isakmp_rfc3948_print(netdissect_options
*ndo
,
3095 const u_char
*bp
, u_int length
,
3096 const u_char
*bp2
, int ver
, int fragmented
, u_int ttl_hl
)
3098 ndo
->ndo_protocol
= "isakmp_rfc3948";
3099 if(length
== 1 && GET_U_1(bp
)==0xff) {
3100 ND_PRINT("isakmp-nat-keep-alive");
3109 * see if this is an IKE packet
3111 if (GET_BE_U_4(bp
) == 0) {
3112 ND_PRINT("NONESP-encap: ");
3113 isakmp_print(ndo
, bp
+4, length
-4, bp2
);
3117 /* must be an ESP packet */
3119 ND_PRINT("UDP-encap: ");
3121 esp_print(ndo
, bp
, length
, bp2
, ver
, fragmented
, ttl_hl
);
3124 * Either this has decrypted the payload and
3125 * printed it, in which case there's nothing more
3126 * to do, or it hasn't, in which case there's
3127 * nothing more to do.
3133 nd_print_trunc(ndo
);