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
35 /* The functions from print-esp.c used in this file are only defined when both
36 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
38 #ifndef HAVE_OPENSSL_EVP_H
42 #include <netdissect-stdinc.h>
46 #include "netdissect.h"
47 #include "addrtoname.h"
53 /* refer to RFC 2408 */
55 typedef u_char cookie_t
[8];
56 typedef u_char msgid_t
[4];
58 #define PORT_ISAKMP 500
60 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
61 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
62 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 cookie_t i_ck
; /* Initiator Cookie */
78 cookie_t r_ck
; /* Responder Cookie */
79 uint8_t np
; /* Next Payload Type */
81 #define ISAKMP_VERS_MAJOR 0xf0
82 #define ISAKMP_VERS_MAJOR_SHIFT 4
83 #define ISAKMP_VERS_MINOR 0x0f
84 #define ISAKMP_VERS_MINOR_SHIFT 0
85 uint8_t etype
; /* Exchange Type */
86 uint8_t flags
; /* Flags */
88 uint32_t len
; /* Length */
91 /* Next Payload Type */
92 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
93 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
94 #define ISAKMP_NPTYPE_P 2 /* Proposal */
95 #define ISAKMP_NPTYPE_T 3 /* Transform */
96 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
97 #define ISAKMP_NPTYPE_ID 5 /* Identification */
98 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
99 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
100 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
101 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
102 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
103 #define ISAKMP_NPTYPE_N 11 /* Notification */
104 #define ISAKMP_NPTYPE_D 12 /* Delete */
105 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
106 #define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
108 #define IKEv1_MAJOR_VERSION 1
109 #define IKEv1_MINOR_VERSION 0
111 #define IKEv2_MAJOR_VERSION 2
112 #define IKEv2_MINOR_VERSION 0
115 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
116 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
117 #define ISAKMP_FLAG_extra 0x04
120 #define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
121 #define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
122 #define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
125 /* 3.2 Payload Generic Header
126 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
127 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 ! Next Payload ! RESERVED ! Payload Length !
129 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132 uint8_t np
; /* Next Payload */
133 uint8_t critical
; /* bit 7 - critical, rest is RESERVED */
134 uint16_t len
; /* Payload Length */
137 /* 3.3 Data Attributes
138 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
139 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 !A! Attribute Type ! AF=0 Attribute Length !
141 !F! ! AF=1 Attribute Value !
142 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 . AF=0 Attribute Value .
144 . AF=1 Not Transmitted .
145 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 uint16_t type
; /* defined by DOI-spec, and Attribute Format */
149 uint16_t lorv
; /* if f equal 1, Attribute Length */
150 /* if f equal 0, Attribute Value */
151 /* if f equal 1, Attribute Value */
154 /* 3.4 Security Association Payload */
155 /* MAY NOT be used, because of being defined in ipsec-doi. */
157 If the current payload is the last in the message,
158 then the value of the next payload field will be 0.
159 This field MUST NOT contain the
160 values for the Proposal or Transform payloads as they are considered
161 part of the security association negotiation. For example, this
162 field would contain the value "10" (Nonce payload) in the first
163 message of a Base Exchange (see Section 4.4) and the value "0" in the
164 first message of an Identity Protect Exchange (see Section 4.5).
168 uint32_t doi
; /* Domain of Interpretation */
169 uint32_t sit
; /* Situation */
172 /* 3.5 Proposal Payload */
174 The value of the next payload field MUST only contain the value "2"
175 or "0". If there are additional Proposal payloads in the message,
176 then this field will be 2. If the current Proposal payload is the
177 last within the security association proposal, then this field will
182 uint8_t p_no
; /* Proposal # */
183 uint8_t prot_id
; /* Protocol */
184 uint8_t spi_size
; /* SPI Size */
185 uint8_t num_t
; /* Number of Transforms */
189 /* 3.6 Transform Payload */
191 The value of the next payload field MUST only contain the value "3"
192 or "0". If there are additional Transform payloads in the proposal,
193 then this field will be 3. If the current Transform payload is the
194 last within the proposal, then this field will be 0.
198 uint8_t t_no
; /* Transform # */
199 uint8_t t_id
; /* Transform-Id */
200 uint16_t reserved
; /* RESERVED2 */
204 /* 3.7 Key Exchange Payload */
207 /* Key Exchange Data */
210 /* 3.8 Identification Payload */
211 /* MUST NOT to be used, because of being defined in ipsec-doi. */
215 uint8_t id_type
; /* ID Type */
216 uint32_t doi_data
; /* DOI Specific ID Data */
218 /* Identification Data */
221 /* 3.9 Certificate Payload */
222 struct ikev1_pl_cert
{
224 uint8_t encode
; /* Cert Encoding */
225 char cert
; /* Certificate Data */
227 This field indicates the type of
228 certificate or certificate-related information contained in the
229 Certificate Data field.
233 /* 3.10 Certificate Request Payload */
236 uint8_t num_cert
; /* # Cert. Types */
238 Certificate Types (variable length)
239 -- Contains a list of the types of certificates requested,
240 sorted in order of preference. Each individual certificate
241 type is 1 octet. This field is NOT requiredo
243 /* # Certificate Authorities (1 octet) */
244 /* Certificate Authorities (variable length) */
247 /* 3.11 Hash Payload */
248 /* may not be used, because of having only data. */
249 struct ikev1_pl_hash
{
254 /* 3.12 Signature Payload */
255 /* may not be used, because of having only data. */
256 struct ikev1_pl_sig
{
261 /* 3.13 Nonce Payload */
262 /* may not be used, because of having only data. */
263 struct ikev1_pl_nonce
{
268 /* 3.14 Notification Payload */
271 uint32_t doi
; /* Domain of Interpretation */
272 uint8_t prot_id
; /* Protocol-ID */
273 uint8_t spi_size
; /* SPI Size */
274 uint16_t type
; /* Notify Message Type */
276 /* Notification Data */
279 /* 3.14.1 Notify Message Types */
280 /* NOTIFY MESSAGES - ERROR TYPES */
281 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
282 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
283 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
284 #define ISAKMP_NTYPE_INVALID_COOKIE 4
285 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
286 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
287 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
288 #define ISAKMP_NTYPE_INVALID_FLAGS 8
289 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
290 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
291 #define ISAKMP_NTYPE_INVALID_SPI 11
292 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
293 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
294 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
295 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
296 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
297 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
298 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
299 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
300 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
301 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
302 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
303 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
304 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
305 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
306 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
308 /* 3.15 Delete Payload */
311 uint32_t doi
; /* Domain of Interpretation */
312 uint8_t prot_id
; /* Protocol-Id */
313 uint8_t spi_size
; /* SPI Size */
314 uint16_t num_spi
; /* # of SPIs */
318 struct ikev1_ph1tab
{
319 struct ikev1_ph1
*head
;
320 struct ikev1_ph1
*tail
;
324 struct isakmp_ph2tab
{
325 struct ikev1_ph2
*head
;
326 struct ikev1_ph2
*tail
;
330 /* IKEv2 (RFC4306) */
332 /* 3.3 Security Association Payload -- generic header */
333 /* 3.3.1. Proposal Substructure */
336 uint8_t p_no
; /* Proposal # */
337 uint8_t prot_id
; /* Protocol */
338 uint8_t spi_size
; /* SPI Size */
339 uint8_t num_t
; /* Number of Transforms */
342 /* 3.3.2. Transform Substructure */
345 uint8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
346 uint8_t res2
; /* reserved byte */
347 uint16_t t_id
; /* Transform ID */
358 /* 3.4. Key Exchange Payload */
367 /* 3.5. Identification Payloads */
379 uint8_t type
; /* ID type */
383 /* Notification Data */
386 /* 3.10 Notification Payload */
389 uint8_t prot_id
; /* Protocol-ID */
390 uint8_t spi_size
; /* SPI Size */
391 uint16_t type
; /* Notify Message Type */
395 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
396 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
397 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
398 IV2_NOTIFY_INVALID_SYNTAX
= 7,
399 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
400 IV2_NOTIFY_INVALID_SPI
=11,
401 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
402 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
403 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
404 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
405 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
406 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
407 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
408 IV2_NOTIFY_INVALID_SELECTORS
=39,
409 IV2_NOTIFY_INITIAL_CONTACT
=16384,
410 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
411 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
412 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
413 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
414 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
415 IV2_NOTIFY_COOKIE
=16390,
416 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
417 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
418 IV2_NOTIFY_REKEY_SA
=16393,
419 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
420 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
423 struct notify_messages
{
428 /* 3.8 Notification Payload */
431 uint8_t auth_method
; /* Protocol-ID */
433 /* authentication data */
436 enum ikev2_auth_type
{
442 /* refer to RFC 2409 */
445 /* isakmp sa structure */
447 uint8_t proto_id
; /* OAKLEY */
448 vchar_t
*spi
; /* spi */
449 uint8_t dhgrp
; /* DH; group */
450 uint8_t auth_t
; /* method of authentication */
451 uint8_t prf_t
; /* type of prf */
452 uint8_t hash_t
; /* type of hash */
453 uint8_t enc_t
; /* type of cipher */
454 uint8_t life_t
; /* type of duration of lifetime */
455 uint32_t ldur
; /* life duration */
459 /* refer to RFC 2407 */
463 /* 4.2 IPSEC Situation Definition */
464 #define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
465 #define IPSECDOI_SIT_SECRECY 0x00000002
466 #define IPSECDOI_SIT_INTEGRITY 0x00000004
468 /* 4.4.1 IPSEC Security Protocol Identifiers */
469 /* 4.4.2 IPSEC ISAKMP Transform Values */
470 #define IPSECDOI_PROTO_ISAKMP 1
471 #define IPSECDOI_KEY_IKE 1
473 /* 4.4.1 IPSEC Security Protocol Identifiers */
474 #define IPSECDOI_PROTO_IPSEC_AH 2
475 /* 4.4.3 IPSEC AH Transform Values */
476 #define IPSECDOI_AH_MD5 2
477 #define IPSECDOI_AH_SHA 3
478 #define IPSECDOI_AH_DES 4
479 #define IPSECDOI_AH_SHA2_256 5
480 #define IPSECDOI_AH_SHA2_384 6
481 #define IPSECDOI_AH_SHA2_512 7
483 /* 4.4.1 IPSEC Security Protocol Identifiers */
484 #define IPSECDOI_PROTO_IPSEC_ESP 3
485 /* 4.4.4 IPSEC ESP Transform Identifiers */
486 #define IPSECDOI_ESP_DES_IV64 1
487 #define IPSECDOI_ESP_DES 2
488 #define IPSECDOI_ESP_3DES 3
489 #define IPSECDOI_ESP_RC5 4
490 #define IPSECDOI_ESP_IDEA 5
491 #define IPSECDOI_ESP_CAST 6
492 #define IPSECDOI_ESP_BLOWFISH 7
493 #define IPSECDOI_ESP_3IDEA 8
494 #define IPSECDOI_ESP_DES_IV32 9
495 #define IPSECDOI_ESP_RC4 10
496 #define IPSECDOI_ESP_NULL 11
497 #define IPSECDOI_ESP_RIJNDAEL 12
498 #define IPSECDOI_ESP_AES 12
500 /* 4.4.1 IPSEC Security Protocol Identifiers */
501 #define IPSECDOI_PROTO_IPCOMP 4
502 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
503 #define IPSECDOI_IPCOMP_OUI 1
504 #define IPSECDOI_IPCOMP_DEFLATE 2
505 #define IPSECDOI_IPCOMP_LZS 3
507 /* 4.5 IPSEC Security Association Attributes */
508 #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
509 #define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
510 #define IPSECDOI_ATTR_SA_LTYPE_SEC 1
511 #define IPSECDOI_ATTR_SA_LTYPE_KB 2
512 #define IPSECDOI_ATTR_SA_LDUR 2 /* V */
513 #define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
514 #define IPSECDOI_ATTR_GRP_DESC 3 /* B */
515 #define IPSECDOI_ATTR_ENC_MODE 4 /* B */
516 /* default value: host dependent */
517 #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
518 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2
519 #define IPSECDOI_ATTR_AUTH 5 /* B */
520 /* 0 means not to use authentication. */
521 #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
522 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
523 #define IPSECDOI_ATTR_AUTH_DES_MAC 3
524 #define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
526 * When negotiating ESP without authentication, the Auth
527 * Algorithm attribute MUST NOT be included in the proposal.
528 * When negotiating ESP without confidentiality, the Auth
529 * Algorithm attribute MUST be included in the proposal and
530 * the ESP transform ID must be ESP_NULL.
532 #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
533 #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
534 #define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
535 #define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
537 /* 4.6.1 Security Association Payload */
540 uint32_t doi
; /* Domain of Interpretation */
541 uint32_t sit
; /* Situation */
544 struct ipsecdoi_secrecy_h
{
549 /* 4.6.2.1 Identification Type Values */
552 uint8_t type
; /* ID Type */
553 uint8_t proto_id
; /* Protocol ID */
554 uint16_t port
; /* Port */
555 /* Identification Data */
558 #define IPSECDOI_ID_IPV4_ADDR 1
559 #define IPSECDOI_ID_FQDN 2
560 #define IPSECDOI_ID_USER_FQDN 3
561 #define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
562 #define IPSECDOI_ID_IPV6_ADDR 5
563 #define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
564 #define IPSECDOI_ID_IPV4_ADDR_RANGE 7
565 #define IPSECDOI_ID_IPV6_ADDR_RANGE 8
566 #define IPSECDOI_ID_DER_ASN1_DN 9
567 #define IPSECDOI_ID_DER_ASN1_GN 10
568 #define IPSECDOI_ID_KEY_ID 11
570 /* 4.6.3 IPSEC DOI Notify Message Types */
571 /* Notify Messages - Status Types */
572 #define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
573 #define IPSECDOI_NTYPE_REPLAY_STATUS 24577
574 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
576 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
577 netdissect_options *ndo, u_char tpay, \
578 const struct isakmp_gen *ext, \
580 const u_char *end_pointer, \
583 uint32_t proto0, int depth)
585 DECLARE_PRINTER(v1_sa
);
586 DECLARE_PRINTER(v1_p
);
587 DECLARE_PRINTER(v1_t
);
588 DECLARE_PRINTER(v1_ke
);
589 DECLARE_PRINTER(v1_id
);
590 DECLARE_PRINTER(v1_cert
);
591 DECLARE_PRINTER(v1_cr
);
592 DECLARE_PRINTER(v1_sig
);
593 DECLARE_PRINTER(v1_hash
);
594 DECLARE_PRINTER(v1_nonce
);
595 DECLARE_PRINTER(v1_n
);
596 DECLARE_PRINTER(v1_d
);
597 DECLARE_PRINTER(v1_vid
);
599 DECLARE_PRINTER(v2_sa
);
600 DECLARE_PRINTER(v2_ke
);
601 DECLARE_PRINTER(v2_ID
);
602 DECLARE_PRINTER(v2_cert
);
603 DECLARE_PRINTER(v2_cr
);
604 DECLARE_PRINTER(v2_auth
);
605 DECLARE_PRINTER(v2_nonce
);
606 DECLARE_PRINTER(v2_n
);
607 DECLARE_PRINTER(v2_d
);
608 DECLARE_PRINTER(v2_vid
);
609 DECLARE_PRINTER(v2_TS
);
610 DECLARE_PRINTER(v2_cp
);
611 DECLARE_PRINTER(v2_eap
);
613 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
616 const struct isakmp_gen
*ext
,
618 const u_char
*end_pointer
,
621 uint32_t proto0
, int depth
);
624 static const u_char
*ike_sub0_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
625 const u_char
*, uint32_t, uint32_t, uint32_t, int);
626 static const u_char
*ikev1_sub_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
627 const u_char
*, uint32_t, uint32_t, uint32_t, int);
629 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
631 u_char np
, const struct isakmp_gen
*ext
,
632 const u_char
*ep
, uint32_t phase
,
633 uint32_t doi
, uint32_t proto
,
637 static char *numstr(int);
640 ikev1_print(netdissect_options
*ndo
,
641 const u_char
*bp
, u_int length
,
642 const u_char
*bp2
, struct isakmp
*base
);
644 #define MAXINITIATORS 20
653 union inaddr_u iaddr
;
654 union inaddr_u raddr
;
655 } cookiecache
[MAXINITIATORS
];
658 static const char *protoidstr
[] = {
659 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
663 static const char *npstr
[] = {
664 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
665 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
666 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
667 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
668 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
669 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
670 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
671 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
672 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
678 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
679 const struct isakmp_gen
*ext
,
681 const u_char
*end_pointer
,
684 uint32_t proto0
, int depth
) = {
698 ikev1_vid_print
, /* 13 */
699 NULL
, NULL
, NULL
, NULL
, NULL
, /* 14- 18 */
700 NULL
, NULL
, NULL
, NULL
, NULL
, /* 19- 23 */
701 NULL
, NULL
, NULL
, NULL
, NULL
, /* 24- 28 */
702 NULL
, NULL
, NULL
, NULL
, /* 29- 32 */
703 ikev2_sa_print
, /* 33 */
704 ikev2_ke_print
, /* 34 */
705 ikev2_ID_print
, /* 35 */
706 ikev2_ID_print
, /* 36 */
707 ikev2_cert_print
, /* 37 */
708 ikev2_cr_print
, /* 38 */
709 ikev2_auth_print
, /* 39 */
710 ikev2_nonce_print
, /* 40 */
711 ikev2_n_print
, /* 41 */
712 ikev2_d_print
, /* 42 */
713 ikev2_vid_print
, /* 43 */
714 ikev2_TS_print
, /* 44 */
715 ikev2_TS_print
, /* 45 */
716 NULL
, /* ikev2_e_print,*/ /* 46 - special */
717 ikev2_cp_print
, /* 47 */
718 ikev2_eap_print
, /* 48 */
722 static const char *etypestr
[] = {
723 /* IKEv1 exchange types */
724 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
, /* 0-7 */
725 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 8-15 */
726 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 16-23 */
727 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 24-31 */
728 "oakley-quick", "oakley-newgroup", /* 32-33 */
729 /* IKEv2 exchange types */
730 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
733 #define STR_OR_ID(x, tab) \
734 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
735 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
736 #define NPSTR(x) STR_OR_ID(x, npstr)
737 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
739 #define CHECKLEN(p, np) \
740 if (ep < (const u_char *)(p)) { \
741 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
747 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
748 ? npfunc[(x)] : NULL)
751 iszero(const u_char
*p
, size_t l
)
760 /* find cookie from initiator cache */
762 cookie_find(cookie_t
*in
)
766 for (i
= 0; i
< MAXINITIATORS
; i
++) {
767 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
774 /* record initiator */
776 cookie_record(cookie_t
*in
, const u_char
*bp2
)
780 const struct ip6_hdr
*ip6
;
784 ninitiator
= (i
+ 1) % MAXINITIATORS
;
788 ip
= (const struct ip
*)bp2
;
791 cookiecache
[ninitiator
].version
= 4;
792 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in4
, &ip
->ip_src
, sizeof(struct in_addr
));
793 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in4
, &ip
->ip_dst
, sizeof(struct in_addr
));
796 ip6
= (const struct ip6_hdr
*)bp2
;
797 cookiecache
[ninitiator
].version
= 6;
798 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in6
, &ip6
->ip6_src
, sizeof(struct in6_addr
));
799 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in6
, &ip6
->ip6_dst
, sizeof(struct in6_addr
));
804 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
805 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
808 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
809 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
811 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
814 const struct ip6_hdr
*ip6
;
816 ip
= (const struct ip
*)bp2
;
819 if (cookiecache
[i
].version
!= 4)
822 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &cookiecache
[i
].iaddr
.in4
, sizeof(struct in_addr
)) == 0)
825 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &cookiecache
[i
].raddr
.in4
, sizeof(struct in_addr
)) == 0)
830 if (cookiecache
[i
].version
!= 6)
832 ip6
= (const struct ip6_hdr
*)bp2
;
834 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &cookiecache
[i
].iaddr
.in6
, sizeof(struct in6_addr
)) == 0)
837 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &cookiecache
[i
].raddr
.in6
, sizeof(struct in6_addr
)) == 0)
849 hexprint(netdissect_options
*ndo
, const uint8_t *loc
, size_t len
)
855 for (i
= 0; i
< len
; i
++)
856 ND_PRINT((ndo
,"%02x", p
[i
] & 0xff));
860 rawprint(netdissect_options
*ndo
, const uint8_t *loc
, size_t len
)
862 ND_TCHECK2(*loc
, len
);
864 hexprint(ndo
, loc
, len
);
872 * returns false if we run out of data buffer
874 static int ike_show_somedata(netdissect_options
*ndo
,
875 const u_char
*cp
, const u_char
*ep
)
877 /* there is too much data, just show some of it */
878 const u_char
*end
= ep
- 20;
885 /* really shouldn't happen because of above */
891 ND_PRINT((ndo
," data=("));
892 if(!rawprint(ndo
, (const uint8_t *)(cp
), len
)) goto trunc
;
893 ND_PRINT((ndo
, "..."));
895 if(!rawprint(ndo
, (const uint8_t *)(end
), elen
)) goto trunc
;
907 const char *value
[30]; /*XXX*/
910 static const u_char
*
911 ikev1_attrmap_print(netdissect_options
*ndo
,
912 const u_char
*p
, const u_char
*ep
,
913 const struct attrmap
*map
, size_t nmap
)
921 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
922 if (ep
< p
+ totlen
) {
923 ND_PRINT((ndo
,"[|attr]"));
928 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
929 if (map
&& t
< nmap
&& map
[t
].type
)
930 ND_PRINT((ndo
,"type=%s ", map
[t
].type
));
932 ND_PRINT((ndo
,"type=#%d ", t
));
934 ND_PRINT((ndo
,"value="));
935 v
= EXTRACT_16BITS(&p
[2]);
936 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
937 ND_PRINT((ndo
,"%s", map
[t
].value
[v
]));
939 rawprint(ndo
, (const uint8_t *)&p
[2], 2);
941 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
942 rawprint(ndo
, (const uint8_t *)&p
[4], EXTRACT_16BITS(&p
[2]));
948 static const u_char
*
949 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep
)
957 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
958 if (ep
< p
+ totlen
) {
959 ND_PRINT((ndo
,"[|attr]"));
964 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
965 ND_PRINT((ndo
,"type=#%d ", t
));
967 ND_PRINT((ndo
,"value="));
969 rawprint(ndo
, (const uint8_t *)&p
[2], 2);
971 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
972 rawprint(ndo
, (const uint8_t *)&p
[4], EXTRACT_16BITS(&p
[2]));
978 static const u_char
*
979 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
980 const struct isakmp_gen
*ext
,
982 const u_char
*ep
, uint32_t phase
, uint32_t doi0 _U_
,
983 uint32_t proto0
, int depth
)
985 const struct ikev1_pl_sa
*p
;
986 struct ikev1_pl_sa sa
;
987 uint32_t doi
, sit
, ident
;
988 const u_char
*cp
, *np
;
991 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SA
)));
993 p
= (const struct ikev1_pl_sa
*)ext
;
995 UNALIGNED_MEMCPY(&sa
, ext
, sizeof(sa
));
999 ND_PRINT((ndo
," doi=%d", doi
));
1000 ND_PRINT((ndo
," situation=%u", (uint32_t)ntohl(sa
.sit
)));
1001 return (const u_char
*)(p
+ 1);
1004 ND_PRINT((ndo
," doi=ipsec"));
1005 ND_PRINT((ndo
," situation="));
1008 ND_PRINT((ndo
,"identity"));
1012 ND_PRINT((ndo
,"%ssecrecy", t
? "+" : ""));
1016 ND_PRINT((ndo
,"%sintegrity", t
? "+" : ""));
1018 np
= (const u_char
*)ext
+ sizeof(sa
);
1020 ND_TCHECK2(*(ext
+ 1), sizeof(ident
));
1021 UNALIGNED_MEMCPY(&ident
, ext
+ 1, sizeof(ident
));
1022 ND_PRINT((ndo
," ident=%u", (uint32_t)ntohl(ident
)));
1023 np
+= sizeof(ident
);
1026 ext
= (const struct isakmp_gen
*)np
;
1029 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
1034 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SA
)));
1038 static const u_char
*
1039 ikev1_p_print(netdissect_options
*ndo
, u_char tpay _U_
,
1040 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1041 const u_char
*ep
, uint32_t phase
, uint32_t doi0
,
1042 uint32_t proto0 _U_
, int depth
)
1044 const struct ikev1_pl_p
*p
;
1045 struct ikev1_pl_p prop
;
1048 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_P
)));
1050 p
= (const struct ikev1_pl_p
*)ext
;
1052 UNALIGNED_MEMCPY(&prop
, ext
, sizeof(prop
));
1053 ND_PRINT((ndo
," #%d protoid=%s transform=%d",
1054 prop
.p_no
, PROTOIDSTR(prop
.prot_id
), prop
.num_t
));
1055 if (prop
.spi_size
) {
1056 ND_PRINT((ndo
," spi="));
1057 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), prop
.spi_size
))
1061 ext
= (const struct isakmp_gen
*)((const u_char
*)(p
+ 1) + prop
.spi_size
);
1064 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1065 prop
.prot_id
, depth
);
1069 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1073 static const char *ikev1_p_map
[] = {
1077 static const char *ikev2_t_type_map
[]={
1078 NULL
, "encr", "prf", "integ", "dh", "esn"
1081 static const char *ah_p_map
[] = {
1082 NULL
, "(reserved)", "md5", "sha", "1des",
1083 "sha2-256", "sha2-384", "sha2-512",
1086 static const char *prf_p_map
[] = {
1087 NULL
, "hmac-md5", "hmac-sha", "hmac-tiger",
1091 static const char *integ_p_map
[] = {
1092 NULL
, "hmac-md5", "hmac-sha", "dec-mac",
1093 "kpdk-md5", "aes-xcbc"
1096 static const char *esn_p_map
[] = {
1100 static const char *dh_p_map
[] = {
1102 "modp1024", /* group 2 */
1103 "EC2N 2^155", /* group 3 */
1104 "EC2N 2^185", /* group 4 */
1105 "modp1536", /* group 5 */
1106 "iana-grp06", "iana-grp07", /* reserved */
1107 "iana-grp08", "iana-grp09",
1108 "iana-grp10", "iana-grp11",
1109 "iana-grp12", "iana-grp13",
1110 "modp2048", /* group 14 */
1111 "modp3072", /* group 15 */
1112 "modp4096", /* group 16 */
1113 "modp6144", /* group 17 */
1114 "modp8192", /* group 18 */
1117 static const char *esp_p_map
[] = {
1118 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1119 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1122 static const char *ipcomp_p_map
[] = {
1123 NULL
, "oui", "deflate", "lzs",
1126 static const struct attrmap ipsec_t_map
[] = {
1127 { NULL
, 0, { NULL
} },
1128 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1129 { "life", 0, { NULL
} },
1130 { "group desc", 18, { NULL
, "modp768",
1131 "modp1024", /* group 2 */
1132 "EC2N 2^155", /* group 3 */
1133 "EC2N 2^185", /* group 4 */
1134 "modp1536", /* group 5 */
1135 "iana-grp06", "iana-grp07", /* reserved */
1136 "iana-grp08", "iana-grp09",
1137 "iana-grp10", "iana-grp11",
1138 "iana-grp12", "iana-grp13",
1139 "modp2048", /* group 14 */
1140 "modp3072", /* group 15 */
1141 "modp4096", /* group 16 */
1142 "modp6144", /* group 17 */
1143 "modp8192", /* group 18 */
1145 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
1146 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1147 { "keylen", 0, { NULL
} },
1148 { "rounds", 0, { NULL
} },
1149 { "dictsize", 0, { NULL
} },
1150 { "privalg", 0, { NULL
} },
1153 static const struct attrmap encr_t_map
[] = {
1154 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 0, 1 */
1155 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 2, 3 */
1156 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 4, 5 */
1157 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 6, 7 */
1158 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 8, 9 */
1159 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 10,11*/
1160 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 12,13*/
1161 { "keylen", 14, { NULL
}},
1164 static const struct attrmap oakley_t_map
[] = {
1165 { NULL
, 0, { NULL
} },
1166 { "enc", 8, { NULL
, "1des", "idea", "blowfish", "rc5",
1167 "3des", "cast", "aes", }, },
1168 { "hash", 7, { NULL
, "md5", "sha1", "tiger",
1169 "sha2-256", "sha2-384", "sha2-512", }, },
1170 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
1171 "rsa enc revised", }, },
1172 { "group desc", 18, { NULL
, "modp768",
1173 "modp1024", /* group 2 */
1174 "EC2N 2^155", /* group 3 */
1175 "EC2N 2^185", /* group 4 */
1176 "modp1536", /* group 5 */
1177 "iana-grp06", "iana-grp07", /* reserved */
1178 "iana-grp08", "iana-grp09",
1179 "iana-grp10", "iana-grp11",
1180 "iana-grp12", "iana-grp13",
1181 "modp2048", /* group 14 */
1182 "modp3072", /* group 15 */
1183 "modp4096", /* group 16 */
1184 "modp6144", /* group 17 */
1185 "modp8192", /* group 18 */
1187 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
1188 { "group prime", 0, { NULL
} },
1189 { "group gen1", 0, { NULL
} },
1190 { "group gen2", 0, { NULL
} },
1191 { "group curve A", 0, { NULL
} },
1192 { "group curve B", 0, { NULL
} },
1193 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1194 { "lifeduration", 0, { NULL
} },
1195 { "prf", 0, { NULL
} },
1196 { "keylen", 0, { NULL
} },
1197 { "field", 0, { NULL
} },
1198 { "order", 0, { NULL
} },
1201 static const u_char
*
1202 ikev1_t_print(netdissect_options
*ndo
, u_char tpay _U_
,
1203 const struct isakmp_gen
*ext
, u_int item_len
,
1204 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi _U_
,
1205 uint32_t proto
, int depth _U_
)
1207 const struct ikev1_pl_t
*p
;
1208 struct ikev1_pl_t t
;
1211 const struct attrmap
*map
;
1215 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_T
)));
1217 p
= (const struct ikev1_pl_t
*)ext
;
1219 UNALIGNED_MEMCPY(&t
, ext
, sizeof(t
));
1223 idstr
= STR_OR_ID(t
.t_id
, ikev1_p_map
);
1225 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1228 idstr
= STR_OR_ID(t
.t_id
, ah_p_map
);
1230 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1233 idstr
= STR_OR_ID(t
.t_id
, esp_p_map
);
1235 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1238 idstr
= STR_OR_ID(t
.t_id
, ipcomp_p_map
);
1240 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1250 ND_PRINT((ndo
," #%d id=%s ", t
.t_no
, idstr
));
1252 ND_PRINT((ndo
," #%d id=%d ", t
.t_no
, t
.t_id
));
1253 cp
= (const u_char
*)(p
+ 1);
1254 ep2
= (const u_char
*)p
+ item_len
;
1255 while (cp
< ep
&& cp
< ep2
) {
1257 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1260 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1263 ND_PRINT((ndo
,"..."));
1266 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1270 static const u_char
*
1271 ikev1_ke_print(netdissect_options
*ndo
, u_char tpay _U_
,
1272 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1273 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1274 uint32_t proto _U_
, int depth _U_
)
1276 struct isakmp_gen e
;
1278 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_KE
)));
1281 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1282 ND_PRINT((ndo
," key len=%d", ntohs(e
.len
) - 4));
1283 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1284 ND_PRINT((ndo
," "));
1285 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
1288 return (const u_char
*)ext
+ ntohs(e
.len
);
1290 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_KE
)));
1294 static const u_char
*
1295 ikev1_id_print(netdissect_options
*ndo
, u_char tpay _U_
,
1296 const struct isakmp_gen
*ext
, u_int item_len
,
1297 const u_char
*ep _U_
, uint32_t phase
, uint32_t doi _U_
,
1298 uint32_t proto _U_
, int depth _U_
)
1300 #define USE_IPSECDOI_IN_PHASE1 1
1301 const struct ikev1_pl_id
*p
;
1302 struct ikev1_pl_id id
;
1303 static const char *idtypestr
[] = {
1304 "IPv4", "IPv4net", "IPv6", "IPv6net",
1306 static const char *ipsecidtypestr
[] = {
1307 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1308 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1314 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_ID
)));
1316 p
= (const struct ikev1_pl_id
*)ext
;
1318 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
1319 if (sizeof(*p
) < item_len
) {
1320 data
= (const u_char
*)(p
+ 1);
1321 len
= item_len
- sizeof(*p
);
1328 ND_PRINT((ndo
," [phase=%d doi=%d proto=%d]", phase
, doi
, proto
));
1331 #ifndef USE_IPSECDOI_IN_PHASE1
1335 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.d
.id_type
, idtypestr
)));
1336 ND_PRINT((ndo
," doi_data=%u",
1337 (uint32_t)(ntohl(id
.d
.doi_data
) & 0xffffff)));
1340 #ifdef USE_IPSECDOI_IN_PHASE1
1345 const struct ipsecdoi_id
*doi_p
;
1346 struct ipsecdoi_id doi_id
;
1347 struct protoent
*pe
;
1349 doi_p
= (const struct ipsecdoi_id
*)ext
;
1351 UNALIGNED_MEMCPY(&doi_id
, ext
, sizeof(doi_id
));
1352 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(doi_id
.type
, ipsecidtypestr
)));
1353 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
1354 pe
= doi_id
.proto_id
? getprotobynumber(doi_id
.proto_id
) : NULL
;
1356 ND_PRINT((ndo
," protoid=%s", pe
->p_name
));
1358 ND_PRINT((ndo
," protoid=%u", doi_id
.proto_id
));
1359 ND_PRINT((ndo
," port=%d", ntohs(doi_id
.port
)));
1364 ND_TCHECK2(*data
, len
);
1365 switch (doi_id
.type
) {
1366 case IPSECDOI_ID_IPV4_ADDR
:
1368 ND_PRINT((ndo
," len=%d [bad: < 4]", len
));
1370 ND_PRINT((ndo
," len=%d %s", len
, ipaddr_string(ndo
, data
)));
1373 case IPSECDOI_ID_FQDN
:
1374 case IPSECDOI_ID_USER_FQDN
:
1377 ND_PRINT((ndo
," len=%d ", len
));
1378 for (i
= 0; i
< len
; i
++)
1379 safeputchar(ndo
, data
[i
]);
1383 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
1387 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1389 mask
= data
+ sizeof(struct in_addr
);
1390 ND_PRINT((ndo
," len=%d %s/%u.%u.%u.%u", len
,
1391 ipaddr_string(ndo
, data
),
1392 mask
[0], mask
[1], mask
[2], mask
[3]));
1397 case IPSECDOI_ID_IPV6_ADDR
:
1399 ND_PRINT((ndo
," len=%d [bad: < 16]", len
));
1401 ND_PRINT((ndo
," len=%d %s", len
, ip6addr_string(ndo
, data
)));
1404 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
1408 ND_PRINT((ndo
," len=%d [bad: < 20]", len
));
1410 mask
= (const u_char
*)(data
+ sizeof(struct in6_addr
));
1412 ND_PRINT((ndo
," len=%d %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len
,
1413 ip6addr_string(ndo
, data
),
1414 mask
[0], mask
[1], mask
[2], mask
[3],
1415 mask
[4], mask
[5], mask
[6], mask
[7],
1416 mask
[8], mask
[9], mask
[10], mask
[11],
1417 mask
[12], mask
[13], mask
[14], mask
[15]));
1422 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1424 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1426 ND_PRINT((ndo
," len=%d %s-%s", len
,
1427 ipaddr_string(ndo
, data
),
1428 ipaddr_string(ndo
, data
+ sizeof(struct in_addr
))));
1432 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1434 ND_PRINT((ndo
," len=%d [bad: < 32]", len
));
1436 ND_PRINT((ndo
," len=%d %s-%s", len
,
1437 ip6addr_string(ndo
, data
),
1438 ip6addr_string(ndo
, data
+ sizeof(struct in6_addr
))));
1442 case IPSECDOI_ID_DER_ASN1_DN
:
1443 case IPSECDOI_ID_DER_ASN1_GN
:
1444 case IPSECDOI_ID_KEY_ID
:
1451 ND_PRINT((ndo
," len=%d", len
));
1452 if (2 < ndo
->ndo_vflag
) {
1453 ND_PRINT((ndo
," "));
1454 if (!rawprint(ndo
, (const uint8_t *)data
, len
))
1458 return (const u_char
*)ext
+ item_len
;
1460 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_ID
)));
1464 static const u_char
*
1465 ikev1_cert_print(netdissect_options
*ndo
, u_char tpay _U_
,
1466 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1467 const u_char
*ep _U_
, uint32_t phase _U_
,
1469 uint32_t proto0 _U_
, int depth _U_
)
1471 const struct ikev1_pl_cert
*p
;
1472 struct ikev1_pl_cert cert
;
1473 static const char *certstr
[] = {
1474 "none", "pkcs7", "pgp", "dns",
1475 "x509sign", "x509ke", "kerberos", "crl",
1476 "arl", "spki", "x509attr",
1479 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CERT
)));
1481 p
= (const struct ikev1_pl_cert
*)ext
;
1483 UNALIGNED_MEMCPY(&cert
, ext
, sizeof(cert
));
1484 ND_PRINT((ndo
," len=%d", item_len
- 4));
1485 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1486 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1487 ND_PRINT((ndo
," "));
1488 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1491 return (const u_char
*)ext
+ item_len
;
1493 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
)));
1497 static const u_char
*
1498 ikev1_cr_print(netdissect_options
*ndo
, u_char tpay _U_
,
1499 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1500 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1501 uint32_t proto0 _U_
, int depth _U_
)
1503 const struct ikev1_pl_cert
*p
;
1504 struct ikev1_pl_cert cert
;
1505 static const char *certstr
[] = {
1506 "none", "pkcs7", "pgp", "dns",
1507 "x509sign", "x509ke", "kerberos", "crl",
1508 "arl", "spki", "x509attr",
1511 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CR
)));
1513 p
= (const struct ikev1_pl_cert
*)ext
;
1515 UNALIGNED_MEMCPY(&cert
, ext
, sizeof(cert
));
1516 ND_PRINT((ndo
," len=%d", item_len
- 4));
1517 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1518 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1519 ND_PRINT((ndo
," "));
1520 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), item_len
- 4))
1523 return (const u_char
*)ext
+ item_len
;
1525 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CR
)));
1529 static const u_char
*
1530 ikev1_hash_print(netdissect_options
*ndo
, u_char tpay _U_
,
1531 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1532 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1533 uint32_t proto _U_
, int depth _U_
)
1535 struct isakmp_gen e
;
1537 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_HASH
)));
1540 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1541 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1542 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1543 ND_PRINT((ndo
," "));
1544 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
1547 return (const u_char
*)ext
+ ntohs(e
.len
);
1549 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
)));
1553 static const u_char
*
1554 ikev1_sig_print(netdissect_options
*ndo
, u_char tpay _U_
,
1555 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1556 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi _U_
,
1557 uint32_t proto _U_
, int depth _U_
)
1559 struct isakmp_gen e
;
1561 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SIG
)));
1564 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1565 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1566 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1567 ND_PRINT((ndo
," "));
1568 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
1571 return (const u_char
*)ext
+ ntohs(e
.len
);
1573 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
)));
1577 static const u_char
*
1578 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1579 const struct isakmp_gen
*ext
,
1581 const u_char
*ep _U_
,
1582 uint32_t phase _U_
, uint32_t doi _U_
,
1583 uint32_t proto _U_
, int depth _U_
)
1585 struct isakmp_gen e
;
1587 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1590 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1591 ND_PRINT((ndo
," n len=%d", ntohs(e
.len
) - 4));
1592 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1593 ND_PRINT((ndo
," "));
1594 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
1596 } else if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1597 ND_PRINT((ndo
," "));
1598 if (!ike_show_somedata(ndo
, (const u_char
*)(const uint8_t *)(ext
+ 1), ep
))
1601 return (const u_char
*)ext
+ ntohs(e
.len
);
1603 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1607 static const u_char
*
1608 ikev1_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
1609 const struct isakmp_gen
*ext
, u_int item_len
,
1610 const u_char
*ep
, uint32_t phase
, uint32_t doi0 _U_
,
1611 uint32_t proto0 _U_
, int depth
)
1613 const struct ikev1_pl_n
*p
;
1614 struct ikev1_pl_n n
;
1619 static const char *notify_error_str
[] = {
1620 NULL
, "INVALID-PAYLOAD-TYPE",
1621 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1622 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1623 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1624 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1625 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1626 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1627 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1628 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1629 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1630 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1631 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1632 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1633 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1634 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1635 "UNEQUAL-PAYLOAD-LENGTHS",
1637 static const char *ipsec_notify_error_str
[] = {
1640 static const char *notify_status_str
[] = {
1643 static const char *ipsec_notify_status_str
[] = {
1644 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1647 /* NOTE: these macro must be called with x in proper range */
1650 #define NOTIFY_ERROR_STR(x) \
1651 STR_OR_ID((x), notify_error_str)
1654 #define IPSEC_NOTIFY_ERROR_STR(x) \
1655 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1658 #define NOTIFY_STATUS_STR(x) \
1659 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1662 #define IPSEC_NOTIFY_STATUS_STR(x) \
1663 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1665 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_N
)));
1667 p
= (const struct ikev1_pl_n
*)ext
;
1669 UNALIGNED_MEMCPY(&n
, ext
, sizeof(n
));
1673 ND_PRINT((ndo
," doi=%d", doi
));
1674 ND_PRINT((ndo
," proto=%d", proto
));
1675 if (ntohs(n
.type
) < 8192)
1676 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1677 else if (ntohs(n
.type
) < 16384)
1678 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1679 else if (ntohs(n
.type
) < 24576)
1680 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1682 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1684 ND_PRINT((ndo
," spi="));
1685 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), n
.spi_size
))
1688 return (const u_char
*)(p
+ 1) + n
.spi_size
;
1691 ND_PRINT((ndo
," doi=ipsec"));
1692 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1693 if (ntohs(n
.type
) < 8192)
1694 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1695 else if (ntohs(n
.type
) < 16384)
1696 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n
.type
))));
1697 else if (ntohs(n
.type
) < 24576)
1698 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1699 else if (ntohs(n
.type
) < 32768)
1700 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n
.type
))));
1702 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1704 ND_PRINT((ndo
," spi="));
1705 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), n
.spi_size
))
1709 cp
= (const u_char
*)(p
+ 1) + n
.spi_size
;
1710 ep2
= (const u_char
*)p
+ item_len
;
1713 ND_PRINT((ndo
," orig=("));
1714 switch (ntohs(n
.type
)) {
1715 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
1717 const struct attrmap
*map
= oakley_t_map
;
1718 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1719 while (cp
< ep
&& cp
< ep2
) {
1720 cp
= ikev1_attrmap_print(ndo
, cp
,
1721 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
1725 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1726 ND_PRINT((ndo
,"replay detection %sabled",
1727 EXTRACT_32BITS(cp
) ? "en" : "dis"));
1729 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
1730 if (ikev1_sub_print(ndo
, ISAKMP_NPTYPE_SA
,
1731 (const struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
,
1737 isakmp_print(ndo
, cp
,
1738 item_len
- sizeof(*p
) - n
.spi_size
,
1741 ND_PRINT((ndo
,")"));
1743 return (const u_char
*)ext
+ item_len
;
1745 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
1749 static const u_char
*
1750 ikev1_d_print(netdissect_options
*ndo
, u_char tpay _U_
,
1751 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1752 const u_char
*ep _U_
, uint32_t phase _U_
, uint32_t doi0 _U_
,
1753 uint32_t proto0 _U_
, int depth _U_
)
1755 const struct ikev1_pl_d
*p
;
1756 struct ikev1_pl_d d
;
1762 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_D
)));
1764 p
= (const struct ikev1_pl_d
*)ext
;
1766 UNALIGNED_MEMCPY(&d
, ext
, sizeof(d
));
1770 ND_PRINT((ndo
," doi=%u", doi
));
1771 ND_PRINT((ndo
," proto=%u", proto
));
1773 ND_PRINT((ndo
," doi=ipsec"));
1774 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1776 ND_PRINT((ndo
," spilen=%u", d
.spi_size
));
1777 ND_PRINT((ndo
," nspi=%u", ntohs(d
.num_spi
)));
1778 ND_PRINT((ndo
," spi="));
1779 q
= (const uint8_t *)(p
+ 1);
1780 for (i
= 0; i
< ntohs(d
.num_spi
); i
++) {
1782 ND_PRINT((ndo
,","));
1783 if (!rawprint(ndo
, (const uint8_t *)q
, d
.spi_size
))
1789 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_D
)));
1793 static const u_char
*
1794 ikev1_vid_print(netdissect_options
*ndo
, u_char tpay _U_
,
1795 const struct isakmp_gen
*ext
,
1796 u_int item_len _U_
, const u_char
*ep _U_
,
1797 uint32_t phase _U_
, uint32_t doi _U_
,
1798 uint32_t proto _U_
, int depth _U_
)
1800 struct isakmp_gen e
;
1802 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_VID
)));
1805 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1806 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1807 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1808 ND_PRINT((ndo
," "));
1809 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
1812 return (const u_char
*)ext
+ ntohs(e
.len
);
1814 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_VID
)));
1818 /************************************************************/
1820 /* IKE v2 - rfc4306 - dissector */
1822 /************************************************************/
1825 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, int critical
)
1827 ND_PRINT((ndo
,"%s%s:", payname
, critical
&0x80 ? "[C]" : ""));
1830 static const u_char
*
1831 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1832 const struct isakmp_gen
*ext
)
1834 struct isakmp_gen e
;
1837 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1838 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
1840 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1841 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1842 ND_PRINT((ndo
," "));
1843 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
1846 return (const u_char
*)ext
+ ntohs(e
.len
);
1848 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
1852 static const u_char
*
1853 ikev2_t_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount
,
1854 const struct isakmp_gen
*ext
, u_int item_len
,
1855 const u_char
*ep
, uint32_t phase _U_
, uint32_t doi _U_
,
1856 uint32_t proto _U_
, int depth _U_
)
1858 const struct ikev2_t
*p
;
1863 const struct attrmap
*map
;
1867 p
= (const struct ikev2_t
*)ext
;
1869 UNALIGNED_MEMCPY(&t
, ext
, sizeof(t
));
1870 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), t
.h
.critical
);
1872 t_id
= ntohs(t
.t_id
);
1879 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1881 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1885 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1889 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1893 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1897 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1906 ND_PRINT((ndo
," #%u type=%s id=%s ", pcount
,
1907 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1910 ND_PRINT((ndo
," #%u type=%s id=%u ", pcount
,
1911 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1913 cp
= (const u_char
*)(p
+ 1);
1914 ep2
= (const u_char
*)p
+ item_len
;
1915 while (cp
< ep
&& cp
< ep2
) {
1917 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1920 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1923 ND_PRINT((ndo
,"..."));
1926 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1930 static const u_char
*
1931 ikev2_p_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount _U_
,
1932 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1933 const u_char
*ep
, uint32_t phase
, uint32_t doi0
,
1934 uint32_t proto0 _U_
, int depth
)
1936 const struct ikev2_p
*p
;
1937 struct ikev2_p prop
;
1940 p
= (const struct ikev2_p
*)ext
;
1942 UNALIGNED_MEMCPY(&prop
, ext
, sizeof(prop
));
1943 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), prop
.h
.critical
);
1945 ND_PRINT((ndo
," #%u protoid=%s transform=%d len=%u",
1946 prop
.p_no
, PROTOIDSTR(prop
.prot_id
),
1947 prop
.num_t
, ntohs(prop
.h
.len
)));
1948 if (prop
.spi_size
) {
1949 ND_PRINT((ndo
," spi="));
1950 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), prop
.spi_size
))
1954 ext
= (const struct isakmp_gen
*)((const u_char
*)(p
+ 1) + prop
.spi_size
);
1957 cp
= ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1958 prop
.prot_id
, depth
);
1962 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1966 static const u_char
*
1967 ikev2_sa_print(netdissect_options
*ndo
, u_char tpay
,
1968 const struct isakmp_gen
*ext1
,
1969 u_int item_len _U_
, const u_char
*ep _U_
,
1970 uint32_t phase _U_
, uint32_t doi _U_
,
1971 uint32_t proto _U_
, int depth _U_
)
1973 struct isakmp_gen e
;
1974 int osa_length
, sa_length
;
1977 UNALIGNED_MEMCPY(&e
, ext1
, sizeof(e
));
1978 ikev2_pay_print(ndo
, "sa", e
.critical
);
1980 osa_length
= ntohs(e
.len
);
1981 sa_length
= osa_length
- 4;
1982 ND_PRINT((ndo
," len=%d", sa_length
));
1984 ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_P
,
1988 return (const u_char
*)ext1
+ osa_length
;
1990 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
1994 static const u_char
*
1995 ikev2_ke_print(netdissect_options
*ndo
, u_char tpay
,
1996 const struct isakmp_gen
*ext
,
1997 u_int item_len _U_
, const u_char
*ep _U_
,
1998 uint32_t phase _U_
, uint32_t doi _U_
,
1999 uint32_t proto _U_
, int depth _U_
)
2002 const struct ikev2_ke
*k
;
2004 k
= (const struct ikev2_ke
*)ext
;
2006 UNALIGNED_MEMCPY(&ke
, ext
, sizeof(ke
));
2007 ikev2_pay_print(ndo
, NPSTR(tpay
), ke
.h
.critical
);
2009 ND_PRINT((ndo
," len=%u group=%s", ntohs(ke
.h
.len
) - 8,
2010 STR_OR_ID(ntohs(ke
.ke_group
), dh_p_map
)));
2012 if (2 < ndo
->ndo_vflag
&& 8 < ntohs(ke
.h
.len
)) {
2013 ND_PRINT((ndo
," "));
2014 if (!rawprint(ndo
, (const uint8_t *)(k
+ 1), ntohs(ke
.h
.len
) - 8))
2017 return (const u_char
*)ext
+ ntohs(ke
.h
.len
);
2019 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2023 static const u_char
*
2024 ikev2_ID_print(netdissect_options
*ndo
, u_char tpay
,
2025 const struct isakmp_gen
*ext
,
2026 u_int item_len _U_
, const u_char
*ep _U_
,
2027 uint32_t phase _U_
, uint32_t doi _U_
,
2028 uint32_t proto _U_
, int depth _U_
)
2031 int id_len
, idtype_len
, i
;
2032 unsigned int dumpascii
, dumphex
;
2033 const unsigned char *typedata
;
2036 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
2037 ikev2_pay_print(ndo
, NPSTR(tpay
), id
.h
.critical
);
2039 id_len
= ntohs(id
.h
.len
);
2041 ND_PRINT((ndo
," len=%d", id_len
- 4));
2042 if (2 < ndo
->ndo_vflag
&& 4 < id_len
) {
2043 ND_PRINT((ndo
," "));
2044 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), id_len
- 4))
2048 idtype_len
=id_len
- sizeof(struct ikev2_id
);
2051 typedata
= (const unsigned char *)(ext
)+sizeof(struct ikev2_id
);
2055 ND_PRINT((ndo
, " ipv4:"));
2059 ND_PRINT((ndo
, " fqdn:"));
2062 case ID_RFC822_ADDR
:
2063 ND_PRINT((ndo
, " rfc822:"));
2067 ND_PRINT((ndo
, " ipv6:"));
2070 case ID_DER_ASN1_DN
:
2071 ND_PRINT((ndo
, " dn:"));
2074 case ID_DER_ASN1_GN
:
2075 ND_PRINT((ndo
, " gn:"));
2079 ND_PRINT((ndo
, " keyid:"));
2085 ND_TCHECK2(*typedata
, idtype_len
);
2086 for(i
=0; i
<idtype_len
; i
++) {
2087 if(ND_ISPRINT(typedata
[i
])) {
2088 ND_PRINT((ndo
, "%c", typedata
[i
]));
2090 ND_PRINT((ndo
, "."));
2095 if (!rawprint(ndo
, (const uint8_t *)typedata
, idtype_len
))
2099 return (const u_char
*)ext
+ id_len
;
2101 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2105 static const u_char
*
2106 ikev2_cert_print(netdissect_options
*ndo
, u_char tpay
,
2107 const struct isakmp_gen
*ext
,
2108 u_int item_len _U_
, const u_char
*ep _U_
,
2109 uint32_t phase _U_
, uint32_t doi _U_
,
2110 uint32_t proto _U_
, int depth _U_
)
2112 return ikev2_gen_print(ndo
, tpay
, ext
);
2115 static const u_char
*
2116 ikev2_cr_print(netdissect_options
*ndo
, u_char tpay
,
2117 const struct isakmp_gen
*ext
,
2118 u_int item_len _U_
, const u_char
*ep _U_
,
2119 uint32_t phase _U_
, uint32_t doi _U_
,
2120 uint32_t proto _U_
, int depth _U_
)
2122 return ikev2_gen_print(ndo
, tpay
, ext
);
2125 static const u_char
*
2126 ikev2_auth_print(netdissect_options
*ndo
, u_char tpay
,
2127 const struct isakmp_gen
*ext
,
2128 u_int item_len _U_
, const u_char
*ep _U_
,
2129 uint32_t phase _U_
, uint32_t doi _U_
,
2130 uint32_t proto _U_
, int depth _U_
)
2132 struct ikev2_auth a
;
2133 const char *v2_auth
[]={ "invalid", "rsasig",
2134 "shared-secret", "dsssig" };
2135 const u_char
*authdata
= (const u_char
*)ext
+ sizeof(a
);
2139 UNALIGNED_MEMCPY(&a
, ext
, sizeof(a
));
2140 ikev2_pay_print(ndo
, NPSTR(tpay
), a
.h
.critical
);
2141 len
= ntohs(a
.h
.len
);
2143 ND_PRINT((ndo
," len=%d method=%s", len
-4,
2144 STR_OR_ID(a
.auth_method
, v2_auth
)));
2146 if (1 < ndo
->ndo_vflag
&& 4 < len
) {
2147 ND_PRINT((ndo
," authdata=("));
2148 if (!rawprint(ndo
, (const uint8_t *)authdata
, len
- sizeof(a
)))
2150 ND_PRINT((ndo
,") "));
2151 } else if(ndo
->ndo_vflag
&& 4 < len
) {
2152 if(!ike_show_somedata(ndo
, authdata
, ep
)) goto trunc
;
2155 return (const u_char
*)ext
+ len
;
2157 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2161 static const u_char
*
2162 ikev2_nonce_print(netdissect_options
*ndo
, u_char tpay
,
2163 const struct isakmp_gen
*ext
,
2164 u_int item_len _U_
, const u_char
*ep _U_
,
2165 uint32_t phase _U_
, uint32_t doi _U_
,
2166 uint32_t proto _U_
, int depth _U_
)
2168 struct isakmp_gen e
;
2171 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2172 ikev2_pay_print(ndo
, "nonce", e
.critical
);
2174 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
2175 if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2176 ND_PRINT((ndo
," nonce=("));
2177 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
2179 ND_PRINT((ndo
,") "));
2180 } else if(ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2181 if(!ike_show_somedata(ndo
, (const u_char
*)(ext
+1), ep
)) goto trunc
;
2184 return (const u_char
*)ext
+ ntohs(e
.len
);
2186 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2190 /* notify payloads */
2191 static const u_char
*
2192 ikev2_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
2193 const struct isakmp_gen
*ext
,
2194 u_int item_len _U_
, 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_n
*p
;
2201 u_char showspi
, showdata
, showsomedata
;
2202 const char *notify_name
;
2205 p
= (const struct ikev2_n
*)ext
;
2207 UNALIGNED_MEMCPY(&n
, ext
, sizeof(n
));
2208 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), n
.h
.critical
);
2215 ND_PRINT((ndo
," prot_id=%s", PROTOIDSTR(n
.prot_id
)));
2217 type
= ntohs(n
.type
);
2219 /* notify space is annoying sparse */
2221 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
2222 notify_name
= "unsupported_critical_payload";
2226 case IV2_NOTIFY_INVALID_IKE_SPI
:
2227 notify_name
= "invalid_ike_spi";
2231 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
2232 notify_name
= "invalid_major_version";
2236 case IV2_NOTIFY_INVALID_SYNTAX
:
2237 notify_name
= "invalid_syntax";
2241 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
2242 notify_name
= "invalid_message_id";
2246 case IV2_NOTIFY_INVALID_SPI
:
2247 notify_name
= "invalid_spi";
2251 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
2252 notify_name
= "no_protocol_chosen";
2256 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
2257 notify_name
= "invalid_ke_payload";
2261 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
2262 notify_name
= "authentication_failed";
2266 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
2267 notify_name
= "single_pair_required";
2271 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
2272 notify_name
= "no_additional_sas";
2276 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
2277 notify_name
= "internal_address_failure";
2281 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
2282 notify_name
= "failed:cp_required";
2286 case IV2_NOTIFY_INVALID_SELECTORS
:
2287 notify_name
= "invalid_selectors";
2291 case IV2_NOTIFY_INITIAL_CONTACT
:
2292 notify_name
= "initial_contact";
2296 case IV2_NOTIFY_SET_WINDOW_SIZE
:
2297 notify_name
= "set_window_size";
2301 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
2302 notify_name
= "additional_ts_possible";
2306 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
2307 notify_name
= "ipcomp_supported";
2311 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
2312 notify_name
= "nat_detection_source_ip";
2316 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
2317 notify_name
= "nat_detection_destination_ip";
2321 case IV2_NOTIFY_COOKIE
:
2322 notify_name
= "cookie";
2328 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
2329 notify_name
= "use_transport_mode";
2333 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
2334 notify_name
= "http_cert_lookup_supported";
2338 case IV2_NOTIFY_REKEY_SA
:
2339 notify_name
= "rekey_sa";
2343 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
2344 notify_name
= "tfc_padding_not_supported";
2348 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
2349 notify_name
= "non_first_fragment_also";
2355 notify_name
="error";
2356 } else if(type
< 16384) {
2357 notify_name
="private-error";
2358 } else if(type
< 40960) {
2359 notify_name
="status";
2361 notify_name
="private-status";
2366 ND_PRINT((ndo
," type=%u(%s)", type
, notify_name
));
2370 if (showspi
&& n
.spi_size
) {
2371 ND_PRINT((ndo
," spi="));
2372 if (!rawprint(ndo
, (const uint8_t *)(p
+ 1), n
.spi_size
))
2376 cp
= (const u_char
*)(p
+ 1) + n
.spi_size
;
2378 if(3 < ndo
->ndo_vflag
) {
2382 if ((showdata
|| (showsomedata
&& ep
-cp
< 30)) && cp
< ep
) {
2383 ND_PRINT((ndo
," data=("));
2384 if (!rawprint(ndo
, (const uint8_t *)(cp
), ep
- cp
))
2387 ND_PRINT((ndo
,")"));
2389 } else if(showsomedata
&& cp
< ep
) {
2390 if(!ike_show_somedata(ndo
, cp
, ep
)) goto trunc
;
2393 return (const u_char
*)ext
+ item_len
;
2395 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
2399 static const u_char
*
2400 ikev2_d_print(netdissect_options
*ndo
, u_char tpay
,
2401 const struct isakmp_gen
*ext
,
2402 u_int item_len _U_
, const u_char
*ep _U_
,
2403 uint32_t phase _U_
, uint32_t doi _U_
,
2404 uint32_t proto _U_
, int depth _U_
)
2406 return ikev2_gen_print(ndo
, tpay
, ext
);
2409 static const u_char
*
2410 ikev2_vid_print(netdissect_options
*ndo
, u_char tpay
,
2411 const struct isakmp_gen
*ext
,
2412 u_int item_len _U_
, const u_char
*ep _U_
,
2413 uint32_t phase _U_
, uint32_t doi _U_
,
2414 uint32_t proto _U_
, int depth _U_
)
2416 struct isakmp_gen e
;
2421 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2422 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2423 ND_PRINT((ndo
," len=%d vid=", ntohs(e
.len
) - 4));
2425 vid
= (const u_char
*)(ext
+1);
2426 len
= ntohs(e
.len
) - 4;
2427 ND_TCHECK2(*vid
, len
);
2428 for(i
=0; i
<len
; i
++) {
2429 if(ND_ISPRINT(vid
[i
])) ND_PRINT((ndo
, "%c", vid
[i
]));
2430 else ND_PRINT((ndo
, "."));
2432 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2433 ND_PRINT((ndo
," "));
2434 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), ntohs(e
.len
) - 4))
2437 return (const u_char
*)ext
+ ntohs(e
.len
);
2439 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2443 static const u_char
*
2444 ikev2_TS_print(netdissect_options
*ndo
, u_char tpay
,
2445 const struct isakmp_gen
*ext
,
2446 u_int item_len _U_
, const u_char
*ep _U_
,
2447 uint32_t phase _U_
, uint32_t doi _U_
,
2448 uint32_t proto _U_
, int depth _U_
)
2450 return ikev2_gen_print(ndo
, tpay
, ext
);
2453 static const u_char
*
2454 ikev2_e_print(netdissect_options
*ndo
,
2455 #ifndef HAVE_LIBCRYPTO
2458 struct isakmp
*base
,
2460 const struct isakmp_gen
*ext
,
2461 u_int item_len _U_
, const u_char
*ep _U_
,
2462 #ifndef HAVE_LIBCRYPTO
2466 #ifndef HAVE_LIBCRYPTO
2470 #ifndef HAVE_LIBCRYPTO
2474 #ifndef HAVE_LIBCRYPTO
2479 struct isakmp_gen e
;
2484 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2485 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2487 dlen
= ntohs(e
.len
)-4;
2489 ND_PRINT((ndo
," len=%d", dlen
));
2490 if (2 < ndo
->ndo_vflag
&& 4 < dlen
) {
2491 ND_PRINT((ndo
," "));
2492 if (!rawprint(ndo
, (const uint8_t *)(ext
+ 1), dlen
))
2496 dat
= (const u_char
*)(ext
+1);
2497 ND_TCHECK2(*dat
, dlen
);
2499 #ifdef HAVE_LIBCRYPTO
2500 /* try to decypt it! */
2501 if(esp_print_decrypt_buffer_by_ikev2(ndo
,
2502 base
->flags
& ISAKMP_FLAG_I
,
2503 base
->i_ck
, base
->r_ck
,
2506 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
2508 /* got it decrypted, print stuff inside. */
2509 ikev2_sub_print(ndo
, base
, e
.np
, ext
, ndo
->ndo_snapend
,
2510 phase
, doi
, proto
, depth
+1);
2515 /* always return NULL, because E must be at end, and NP refers
2516 * to what was inside.
2520 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2524 static const u_char
*
2525 ikev2_cp_print(netdissect_options
*ndo
, u_char tpay
,
2526 const struct isakmp_gen
*ext
,
2527 u_int item_len _U_
, const u_char
*ep _U_
,
2528 uint32_t phase _U_
, uint32_t doi _U_
,
2529 uint32_t proto _U_
, int depth _U_
)
2531 return ikev2_gen_print(ndo
, tpay
, ext
);
2534 static const u_char
*
2535 ikev2_eap_print(netdissect_options
*ndo
, u_char tpay
,
2536 const struct isakmp_gen
*ext
,
2537 u_int item_len _U_
, const u_char
*ep _U_
,
2538 uint32_t phase _U_
, uint32_t doi _U_
,
2539 uint32_t proto _U_
, int depth _U_
)
2541 return ikev2_gen_print(ndo
, tpay
, ext
);
2544 static const u_char
*
2545 ike_sub0_print(netdissect_options
*ndo
,
2546 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2548 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2551 struct isakmp_gen e
;
2554 cp
= (const u_char
*)ext
;
2556 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2559 * Since we can't have a payload length of less than 4 bytes,
2560 * we need to bail out here if the generic header is nonsensical
2561 * or truncated, otherwise we could loop forever processing
2562 * zero-length items or otherwise misdissect the packet.
2564 item_len
= ntohs(e
.len
);
2570 * XXX - what if item_len is too short, or too long,
2571 * for this payload type?
2573 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2575 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2581 ND_PRINT((ndo
," [|isakmp]"));
2585 static const u_char
*
2586 ikev1_sub_print(netdissect_options
*ndo
,
2587 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2588 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2592 struct isakmp_gen e
;
2594 cp
= (const u_char
*)ext
;
2599 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2601 ND_TCHECK2(*ext
, ntohs(e
.len
));
2604 ND_PRINT((ndo
,"\n"));
2605 for (i
= 0; i
< depth
; i
++)
2606 ND_PRINT((ndo
," "));
2607 ND_PRINT((ndo
,"("));
2608 cp
= ike_sub0_print(ndo
, np
, ext
, ep
, phase
, doi
, proto
, depth
);
2609 ND_PRINT((ndo
,")"));
2613 /* Zero-length subitem */
2618 ext
= (const struct isakmp_gen
*)cp
;
2622 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2629 static char buf
[20];
2630 snprintf(buf
, sizeof(buf
), "#%d", x
);
2635 ikev1_print(netdissect_options
*ndo
,
2636 const u_char
*bp
, u_int length
,
2637 const u_char
*bp2
, struct isakmp
*base
)
2639 const struct isakmp
*p
;
2645 p
= (const struct isakmp
*)bp
;
2646 ep
= ndo
->ndo_snapend
;
2648 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2650 ND_PRINT((ndo
," phase %d", phase
));
2652 ND_PRINT((ndo
," phase %d/others", phase
));
2654 i
= cookie_find(&base
->i_ck
);
2656 if (iszero((const u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
2657 /* the first packet */
2658 ND_PRINT((ndo
," I"));
2660 cookie_record(&base
->i_ck
, bp2
);
2662 ND_PRINT((ndo
," ?"));
2664 if (bp2
&& cookie_isinitiator(i
, bp2
))
2665 ND_PRINT((ndo
," I"));
2666 else if (bp2
&& cookie_isresponder(i
, bp2
))
2667 ND_PRINT((ndo
," R"));
2669 ND_PRINT((ndo
," ?"));
2672 ND_PRINT((ndo
," %s", ETYPESTR(base
->etype
)));
2674 ND_PRINT((ndo
,"[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
2675 base
->flags
& ISAKMP_FLAG_C
? "C" : ""));
2678 if (ndo
->ndo_vflag
) {
2679 const struct isakmp_gen
*ext
;
2681 ND_PRINT((ndo
,":"));
2683 /* regardless of phase... */
2684 if (base
->flags
& ISAKMP_FLAG_E
) {
2686 * encrypted, nothing we can do right now.
2687 * we hope to decrypt the packet in the future...
2689 ND_PRINT((ndo
," [encrypted %s]", NPSTR(base
->np
)));
2693 CHECKLEN(p
+ 1, base
->np
);
2695 ext
= (const struct isakmp_gen
*)(p
+ 1);
2696 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
2700 if (ndo
->ndo_vflag
) {
2701 if (ntohl(base
->len
) != length
) {
2702 ND_PRINT((ndo
," (len mismatch: isakmp %u/ip %u)",
2703 (uint32_t)ntohl(base
->len
), length
));
2708 static const u_char
*
2709 ikev2_sub0_print(netdissect_options
*ndo
, struct isakmp
*base
,
2710 u_char np
, int pcount
,
2711 const struct isakmp_gen
*ext
, const u_char
*ep
,
2712 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2715 struct isakmp_gen e
;
2718 cp
= (const u_char
*)ext
;
2720 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2723 * Since we can't have a payload length of less than 4 bytes,
2724 * we need to bail out here if the generic header is nonsensical
2725 * or truncated, otherwise we could loop forever processing
2726 * zero-length items or otherwise misdissect the packet.
2728 item_len
= ntohs(e
.len
);
2732 if(np
== ISAKMP_NPTYPE_P
) {
2733 cp
= ikev2_p_print(ndo
, np
, pcount
, ext
, item_len
,
2734 ep
, phase
, doi
, proto
, depth
);
2735 } else if(np
== ISAKMP_NPTYPE_T
) {
2736 cp
= ikev2_t_print(ndo
, np
, pcount
, ext
, item_len
,
2737 ep
, phase
, doi
, proto
, depth
);
2738 } else if(np
== ISAKMP_NPTYPE_v2E
) {
2739 cp
= ikev2_e_print(ndo
, base
, np
, ext
, item_len
,
2740 ep
, phase
, doi
, proto
, depth
);
2741 } else if (NPFUNC(np
)) {
2743 * XXX - what if item_len is too short, or too long,
2744 * for this payload type?
2746 cp
= (*npfunc
[np
])(ndo
, np
, /*pcount,*/ ext
, item_len
,
2747 ep
, phase
, doi
, proto
, depth
);
2749 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2755 ND_PRINT((ndo
," [|isakmp]"));
2759 static const u_char
*
2760 ikev2_sub_print(netdissect_options
*ndo
,
2761 struct isakmp
*base
,
2762 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2763 uint32_t phase
, uint32_t doi
, uint32_t proto
, int depth
)
2768 struct isakmp_gen e
;
2770 cp
= (const u_char
*)ext
;
2776 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2778 ND_TCHECK2(*ext
, ntohs(e
.len
));
2781 ND_PRINT((ndo
,"\n"));
2782 for (i
= 0; i
< depth
; i
++)
2783 ND_PRINT((ndo
," "));
2784 ND_PRINT((ndo
,"("));
2785 cp
= ikev2_sub0_print(ndo
, base
, np
, pcount
,
2786 ext
, ep
, phase
, doi
, proto
, depth
);
2787 ND_PRINT((ndo
,")"));
2791 /* Zero-length subitem */
2796 ext
= (const struct isakmp_gen
*)cp
;
2800 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2805 ikev2_print(netdissect_options
*ndo
,
2806 const u_char
*bp
, u_int length
,
2807 const u_char
*bp2 _U_
, struct isakmp
*base
)
2809 const struct isakmp
*p
;
2814 p
= (const struct isakmp
*)bp
;
2815 ep
= ndo
->ndo_snapend
;
2817 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2819 ND_PRINT((ndo
, " parent_sa"));
2821 ND_PRINT((ndo
, " child_sa "));
2823 ND_PRINT((ndo
, " %s", ETYPESTR(base
->etype
)));
2825 ND_PRINT((ndo
, "[%s%s%s]",
2826 base
->flags
& ISAKMP_FLAG_I
? "I" : "",
2827 base
->flags
& ISAKMP_FLAG_V
? "V" : "",
2828 base
->flags
& ISAKMP_FLAG_R
? "R" : ""));
2831 if (ndo
->ndo_vflag
) {
2832 const struct isakmp_gen
*ext
;
2834 ND_PRINT((ndo
, ":"));
2836 /* regardless of phase... */
2837 if (base
->flags
& ISAKMP_FLAG_E
) {
2839 * encrypted, nothing we can do right now.
2840 * we hope to decrypt the packet in the future...
2842 ND_PRINT((ndo
, " [encrypted %s]", NPSTR(base
->np
)));
2846 CHECKLEN(p
+ 1, base
->np
)
2849 ext
= (const struct isakmp_gen
*)(p
+ 1);
2850 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
2854 if (ndo
->ndo_vflag
) {
2855 if (ntohl(base
->len
) != length
) {
2856 ND_PRINT((ndo
, " (len mismatch: isakmp %u/ip %u)",
2857 (uint32_t)ntohl(base
->len
), length
));
2863 isakmp_print(netdissect_options
*ndo
,
2864 const u_char
*bp
, u_int length
,
2867 const struct isakmp
*p
;
2872 #ifdef HAVE_LIBCRYPTO
2873 /* initialize SAs */
2874 if (ndo
->ndo_sa_list_head
== NULL
) {
2875 if (ndo
->ndo_espsecret
)
2876 esp_print_decodesecret(ndo
);
2880 p
= (const struct isakmp
*)bp
;
2881 ep
= ndo
->ndo_snapend
;
2883 if ((const struct isakmp
*)ep
< p
+ 1) {
2884 ND_PRINT((ndo
,"[|isakmp]"));
2888 UNALIGNED_MEMCPY(&base
, p
, sizeof(base
));
2890 ND_PRINT((ndo
,"isakmp"));
2891 major
= (base
.vers
& ISAKMP_VERS_MAJOR
)
2892 >> ISAKMP_VERS_MAJOR_SHIFT
;
2893 minor
= (base
.vers
& ISAKMP_VERS_MINOR
)
2894 >> ISAKMP_VERS_MINOR_SHIFT
;
2896 if (ndo
->ndo_vflag
) {
2897 ND_PRINT((ndo
," %d.%d", major
, minor
));
2900 if (ndo
->ndo_vflag
) {
2901 ND_PRINT((ndo
," msgid "));
2902 hexprint(ndo
, (const uint8_t *)&base
.msgid
, sizeof(base
.msgid
));
2905 if (1 < ndo
->ndo_vflag
) {
2906 ND_PRINT((ndo
," cookie "));
2907 hexprint(ndo
, (const uint8_t *)&base
.i_ck
, sizeof(base
.i_ck
));
2908 ND_PRINT((ndo
,"->"));
2909 hexprint(ndo
, (const uint8_t *)&base
.r_ck
, sizeof(base
.r_ck
));
2911 ND_PRINT((ndo
,":"));
2914 case IKEv1_MAJOR_VERSION
:
2915 ikev1_print(ndo
, bp
, length
, bp2
, &base
);
2918 case IKEv2_MAJOR_VERSION
:
2919 ikev2_print(ndo
, bp
, length
, bp2
, &base
);
2925 isakmp_rfc3948_print(netdissect_options
*ndo
,
2926 const u_char
*bp
, u_int length
,
2930 if(length
== 1 && bp
[0]==0xff) {
2931 ND_PRINT((ndo
, "isakmp-nat-keep-alive"));
2940 * see if this is an IKE packet
2942 if(bp
[0]==0 && bp
[1]==0 && bp
[2]==0 && bp
[3]==0) {
2943 ND_PRINT((ndo
, "NONESP-encap: "));
2944 isakmp_print(ndo
, bp
+4, length
-4, bp2
);
2948 /* must be an ESP packet */
2950 int nh
, enh
, padlen
;
2953 ND_PRINT((ndo
, "UDP-encap: "));
2955 advance
= esp_print(ndo
, bp
, length
, bp2
, &enh
, &padlen
);
2960 length
-= advance
+ padlen
;
2963 ip_print_inner(ndo
, bp
, length
, nh
, bp2
);
2968 ND_PRINT((ndo
,"[|isakmp]"));
2974 * c-style: whitesmith