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 #define NETDISSECT_REWORKED
36 /* The functions from print-esp.c used in this file are only defined when both
37 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
39 #ifndef HAVE_OPENSSL_EVP_H
43 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "addrtoname.h"
49 #include "extract.h" /* must come after interface.h */
56 /* refer to RFC 2408 */
58 typedef u_char cookie_t
[8];
59 typedef u_char msgid_t
[4];
61 #define PORT_ISAKMP 500
63 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
64 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
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 cookie_t i_ck
; /* Initiator Cookie */
81 cookie_t r_ck
; /* Responder Cookie */
82 u_int8_t np
; /* Next Payload Type */
84 #define ISAKMP_VERS_MAJOR 0xf0
85 #define ISAKMP_VERS_MAJOR_SHIFT 4
86 #define ISAKMP_VERS_MINOR 0x0f
87 #define ISAKMP_VERS_MINOR_SHIFT 0
88 u_int8_t etype
; /* Exchange Type */
89 u_int8_t flags
; /* Flags */
91 u_int32_t len
; /* Length */
94 /* Next Payload Type */
95 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
96 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
97 #define ISAKMP_NPTYPE_P 2 /* Proposal */
98 #define ISAKMP_NPTYPE_T 3 /* Transform */
99 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
100 #define ISAKMP_NPTYPE_ID 5 /* Identification */
101 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
102 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
103 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
104 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
105 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
106 #define ISAKMP_NPTYPE_N 11 /* Notification */
107 #define ISAKMP_NPTYPE_D 12 /* Delete */
108 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
109 #define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
111 #define IKEv1_MAJOR_VERSION 1
112 #define IKEv1_MINOR_VERSION 0
114 #define IKEv2_MAJOR_VERSION 2
115 #define IKEv2_MINOR_VERSION 0
118 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
119 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
120 #define ISAKMP_FLAG_extra 0x04
123 #define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
124 #define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
125 #define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
128 /* 3.2 Payload Generic Header
129 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
130 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131 ! Next Payload ! RESERVED ! Payload Length !
132 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135 u_int8_t np
; /* Next Payload */
136 u_int8_t critical
; /* bit 7 - critical, rest is RESERVED */
137 u_int16_t len
; /* Payload Length */
140 /* 3.3 Data Attributes
141 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
142 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 !A! Attribute Type ! AF=0 Attribute Length !
144 !F! ! AF=1 Attribute Value !
145 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146 . AF=0 Attribute Value .
147 . AF=1 Not Transmitted .
148 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151 u_int16_t type
; /* defined by DOI-spec, and Attribute Format */
152 u_int16_t lorv
; /* if f equal 1, Attribute Length */
153 /* if f equal 0, Attribute Value */
154 /* if f equal 1, Attribute Value */
157 /* 3.4 Security Association Payload */
158 /* MAY NOT be used, because of being defined in ipsec-doi. */
160 If the current payload is the last in the message,
161 then the value of the next payload field will be 0.
162 This field MUST NOT contain the
163 values for the Proposal or Transform payloads as they are considered
164 part of the security association negotiation. For example, this
165 field would contain the value "10" (Nonce payload) in the first
166 message of a Base Exchange (see Section 4.4) and the value "0" in the
167 first message of an Identity Protect Exchange (see Section 4.5).
171 u_int32_t doi
; /* Domain of Interpretation */
172 u_int32_t sit
; /* Situation */
175 /* 3.5 Proposal Payload */
177 The value of the next payload field MUST only contain the value "2"
178 or "0". If there are additional Proposal payloads in the message,
179 then this field will be 2. If the current Proposal payload is the
180 last within the security association proposal, then this field will
185 u_int8_t p_no
; /* Proposal # */
186 u_int8_t prot_id
; /* Protocol */
187 u_int8_t spi_size
; /* SPI Size */
188 u_int8_t num_t
; /* Number of Transforms */
192 /* 3.6 Transform Payload */
194 The value of the next payload field MUST only contain the value "3"
195 or "0". If there are additional Transform payloads in the proposal,
196 then this field will be 3. If the current Transform payload is the
197 last within the proposal, then this field will be 0.
201 u_int8_t t_no
; /* Transform # */
202 u_int8_t t_id
; /* Transform-Id */
203 u_int16_t reserved
; /* RESERVED2 */
207 /* 3.7 Key Exchange Payload */
210 /* Key Exchange Data */
213 /* 3.8 Identification Payload */
214 /* MUST NOT to be used, because of being defined in ipsec-doi. */
218 u_int8_t id_type
; /* ID Type */
219 u_int32_t doi_data
; /* DOI Specific ID Data */
221 /* Identification Data */
224 /* 3.9 Certificate Payload */
225 struct ikev1_pl_cert
{
227 u_int8_t encode
; /* Cert Encoding */
228 char cert
; /* Certificate Data */
230 This field indicates the type of
231 certificate or certificate-related information contained in the
232 Certificate Data field.
236 /* 3.10 Certificate Request Payload */
239 u_int8_t num_cert
; /* # Cert. Types */
241 Certificate Types (variable length)
242 -- Contains a list of the types of certificates requested,
243 sorted in order of preference. Each individual certificate
244 type is 1 octet. This field is NOT requiredo
246 /* # Certificate Authorities (1 octet) */
247 /* Certificate Authorities (variable length) */
250 /* 3.11 Hash Payload */
251 /* may not be used, because of having only data. */
252 struct ikev1_pl_hash
{
257 /* 3.12 Signature Payload */
258 /* may not be used, because of having only data. */
259 struct ikev1_pl_sig
{
264 /* 3.13 Nonce Payload */
265 /* may not be used, because of having only data. */
266 struct ikev1_pl_nonce
{
271 /* 3.14 Notification Payload */
274 u_int32_t doi
; /* Domain of Interpretation */
275 u_int8_t prot_id
; /* Protocol-ID */
276 u_int8_t spi_size
; /* SPI Size */
277 u_int16_t type
; /* Notify Message Type */
279 /* Notification Data */
282 /* 3.14.1 Notify Message Types */
283 /* NOTIFY MESSAGES - ERROR TYPES */
284 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
285 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
286 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
287 #define ISAKMP_NTYPE_INVALID_COOKIE 4
288 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
289 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
290 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
291 #define ISAKMP_NTYPE_INVALID_FLAGS 8
292 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
293 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
294 #define ISAKMP_NTYPE_INVALID_SPI 11
295 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
296 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
297 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
298 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
299 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
300 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
301 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
302 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
303 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
304 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
305 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
306 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
307 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
308 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
309 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
311 /* 3.15 Delete Payload */
314 u_int32_t doi
; /* Domain of Interpretation */
315 u_int8_t prot_id
; /* Protocol-Id */
316 u_int8_t spi_size
; /* SPI Size */
317 u_int16_t num_spi
; /* # of SPIs */
321 struct ikev1_ph1tab
{
322 struct ikev1_ph1
*head
;
323 struct ikev1_ph1
*tail
;
327 struct isakmp_ph2tab
{
328 struct ikev1_ph2
*head
;
329 struct ikev1_ph2
*tail
;
333 /* IKEv2 (RFC4306) */
335 /* 3.3 Security Association Payload -- generic header */
336 /* 3.3.1. Proposal Substructure */
339 u_int8_t p_no
; /* Proposal # */
340 u_int8_t prot_id
; /* Protocol */
341 u_int8_t spi_size
; /* SPI Size */
342 u_int8_t num_t
; /* Number of Transforms */
345 /* 3.3.2. Transform Substructure */
348 u_int8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
349 u_int8_t res2
; /* reserved byte */
350 u_int16_t t_id
; /* Transform ID */
361 /* 3.4. Key Exchange Payload */
370 /* 3.5. Identification Payloads */
382 u_int8_t type
; /* ID type */
386 /* Notification Data */
389 /* 3.10 Notification Payload */
392 u_int8_t prot_id
; /* Protocol-ID */
393 u_int8_t spi_size
; /* SPI Size */
394 u_int16_t type
; /* Notify Message Type */
398 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
399 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
400 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
401 IV2_NOTIFY_INVALID_SYNTAX
= 7,
402 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
403 IV2_NOTIFY_INVALID_SPI
=11,
404 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
405 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
406 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
407 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
408 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
409 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
410 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
411 IV2_NOTIFY_INVALID_SELECTORS
=39,
412 IV2_NOTIFY_INITIAL_CONTACT
=16384,
413 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
414 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
415 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
416 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
417 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
418 IV2_NOTIFY_COOKIE
=16390,
419 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
420 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
421 IV2_NOTIFY_REKEY_SA
=16393,
422 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
423 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
426 struct notify_messages
{
431 /* 3.8 Notification Payload */
434 u_int8_t auth_method
; /* Protocol-ID */
435 u_int8_t reserved
[3];
436 /* authentication data */
439 enum ikev2_auth_type
{
445 /* refer to RFC 2409 */
448 /* isakmp sa structure */
450 u_int8_t proto_id
; /* OAKLEY */
451 vchar_t
*spi
; /* spi */
452 u_int8_t dhgrp
; /* DH; group */
453 u_int8_t auth_t
; /* method of authentication */
454 u_int8_t prf_t
; /* type of prf */
455 u_int8_t hash_t
; /* type of hash */
456 u_int8_t enc_t
; /* type of cipher */
457 u_int8_t life_t
; /* type of duration of lifetime */
458 u_int32_t ldur
; /* life duration */
462 /* refer to RFC 2407 */
466 /* 4.2 IPSEC Situation Definition */
467 #define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
468 #define IPSECDOI_SIT_SECRECY 0x00000002
469 #define IPSECDOI_SIT_INTEGRITY 0x00000004
471 /* 4.4.1 IPSEC Security Protocol Identifiers */
472 /* 4.4.2 IPSEC ISAKMP Transform Values */
473 #define IPSECDOI_PROTO_ISAKMP 1
474 #define IPSECDOI_KEY_IKE 1
476 /* 4.4.1 IPSEC Security Protocol Identifiers */
477 #define IPSECDOI_PROTO_IPSEC_AH 2
478 /* 4.4.3 IPSEC AH Transform Values */
479 #define IPSECDOI_AH_MD5 2
480 #define IPSECDOI_AH_SHA 3
481 #define IPSECDOI_AH_DES 4
482 #define IPSECDOI_AH_SHA2_256 5
483 #define IPSECDOI_AH_SHA2_384 6
484 #define IPSECDOI_AH_SHA2_512 7
486 /* 4.4.1 IPSEC Security Protocol Identifiers */
487 #define IPSECDOI_PROTO_IPSEC_ESP 3
488 /* 4.4.4 IPSEC ESP Transform Identifiers */
489 #define IPSECDOI_ESP_DES_IV64 1
490 #define IPSECDOI_ESP_DES 2
491 #define IPSECDOI_ESP_3DES 3
492 #define IPSECDOI_ESP_RC5 4
493 #define IPSECDOI_ESP_IDEA 5
494 #define IPSECDOI_ESP_CAST 6
495 #define IPSECDOI_ESP_BLOWFISH 7
496 #define IPSECDOI_ESP_3IDEA 8
497 #define IPSECDOI_ESP_DES_IV32 9
498 #define IPSECDOI_ESP_RC4 10
499 #define IPSECDOI_ESP_NULL 11
500 #define IPSECDOI_ESP_RIJNDAEL 12
501 #define IPSECDOI_ESP_AES 12
503 /* 4.4.1 IPSEC Security Protocol Identifiers */
504 #define IPSECDOI_PROTO_IPCOMP 4
505 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
506 #define IPSECDOI_IPCOMP_OUI 1
507 #define IPSECDOI_IPCOMP_DEFLATE 2
508 #define IPSECDOI_IPCOMP_LZS 3
510 /* 4.5 IPSEC Security Association Attributes */
511 #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
512 #define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
513 #define IPSECDOI_ATTR_SA_LTYPE_SEC 1
514 #define IPSECDOI_ATTR_SA_LTYPE_KB 2
515 #define IPSECDOI_ATTR_SA_LDUR 2 /* V */
516 #define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
517 #define IPSECDOI_ATTR_GRP_DESC 3 /* B */
518 #define IPSECDOI_ATTR_ENC_MODE 4 /* B */
519 /* default value: host dependent */
520 #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
521 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2
522 #define IPSECDOI_ATTR_AUTH 5 /* B */
523 /* 0 means not to use authentication. */
524 #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
525 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
526 #define IPSECDOI_ATTR_AUTH_DES_MAC 3
527 #define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
529 * When negotiating ESP without authentication, the Auth
530 * Algorithm attribute MUST NOT be included in the proposal.
531 * When negotiating ESP without confidentiality, the Auth
532 * Algorithm attribute MUST be included in the proposal and
533 * the ESP transform ID must be ESP_NULL.
535 #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
536 #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
537 #define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
538 #define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
540 /* 4.6.1 Security Association Payload */
543 u_int32_t doi
; /* Domain of Interpretation */
544 u_int32_t sit
; /* Situation */
547 struct ipsecdoi_secrecy_h
{
552 /* 4.6.2.1 Identification Type Values */
555 u_int8_t type
; /* ID Type */
556 u_int8_t proto_id
; /* Protocol ID */
557 u_int16_t port
; /* Port */
558 /* Identification Data */
561 #define IPSECDOI_ID_IPV4_ADDR 1
562 #define IPSECDOI_ID_FQDN 2
563 #define IPSECDOI_ID_USER_FQDN 3
564 #define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
565 #define IPSECDOI_ID_IPV6_ADDR 5
566 #define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
567 #define IPSECDOI_ID_IPV4_ADDR_RANGE 7
568 #define IPSECDOI_ID_IPV6_ADDR_RANGE 8
569 #define IPSECDOI_ID_DER_ASN1_DN 9
570 #define IPSECDOI_ID_DER_ASN1_GN 10
571 #define IPSECDOI_ID_KEY_ID 11
573 /* 4.6.3 IPSEC DOI Notify Message Types */
574 /* Notify Messages - Status Types */
575 #define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
576 #define IPSECDOI_NTYPE_REPLAY_STATUS 24577
577 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
579 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
580 netdissect_options *ndo, u_char tpay, \
581 const struct isakmp_gen *ext, \
583 const u_char *end_pointer, \
586 u_int32_t proto0, int depth)
588 DECLARE_PRINTER(v1_sa
);
589 DECLARE_PRINTER(v1_p
);
590 DECLARE_PRINTER(v1_t
);
591 DECLARE_PRINTER(v1_ke
);
592 DECLARE_PRINTER(v1_id
);
593 DECLARE_PRINTER(v1_cert
);
594 DECLARE_PRINTER(v1_cr
);
595 DECLARE_PRINTER(v1_sig
);
596 DECLARE_PRINTER(v1_hash
);
597 DECLARE_PRINTER(v1_nonce
);
598 DECLARE_PRINTER(v1_n
);
599 DECLARE_PRINTER(v1_d
);
600 DECLARE_PRINTER(v1_vid
);
602 DECLARE_PRINTER(v2_sa
);
603 DECLARE_PRINTER(v2_ke
);
604 DECLARE_PRINTER(v2_ID
);
605 DECLARE_PRINTER(v2_cert
);
606 DECLARE_PRINTER(v2_cr
);
607 DECLARE_PRINTER(v2_auth
);
608 DECLARE_PRINTER(v2_nonce
);
609 DECLARE_PRINTER(v2_n
);
610 DECLARE_PRINTER(v2_d
);
611 DECLARE_PRINTER(v2_vid
);
612 DECLARE_PRINTER(v2_TS
);
613 DECLARE_PRINTER(v2_cp
);
614 DECLARE_PRINTER(v2_eap
);
616 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
619 const struct isakmp_gen
*ext
,
621 const u_char
*end_pointer
,
624 u_int32_t proto0
, int depth
);
627 static const u_char
*ike_sub0_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
628 const u_char
*, u_int32_t
, u_int32_t
, u_int32_t
, int);
629 static const u_char
*ikev1_sub_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
630 const u_char
*, u_int32_t
, u_int32_t
, u_int32_t
, int);
632 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
634 u_char np
, const struct isakmp_gen
*ext
,
635 const u_char
*ep
, u_int32_t phase
,
636 u_int32_t doi
, u_int32_t proto
,
640 static char *numstr(int);
643 ikev1_print(netdissect_options
*ndo
,
644 const u_char
*bp
, u_int length
,
645 const u_char
*bp2
, struct isakmp
*base
);
647 #define MAXINITIATORS 20
658 union inaddr_u iaddr
;
659 union inaddr_u raddr
;
660 } cookiecache
[MAXINITIATORS
];
663 static const char *protoidstr
[] = {
664 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
668 static const char *npstr
[] = {
669 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
670 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
671 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
672 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
673 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
674 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
675 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
676 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
677 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
683 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
684 const struct isakmp_gen
*ext
,
686 const u_char
*end_pointer
,
689 u_int32_t proto0
, int depth
) = {
703 ikev1_vid_print
, /* 13 */
704 NULL
, NULL
, NULL
, NULL
, NULL
, /* 14- 18 */
705 NULL
, NULL
, NULL
, NULL
, NULL
, /* 19- 23 */
706 NULL
, NULL
, NULL
, NULL
, NULL
, /* 24- 28 */
707 NULL
, NULL
, NULL
, NULL
, /* 29- 32 */
708 ikev2_sa_print
, /* 33 */
709 ikev2_ke_print
, /* 34 */
710 ikev2_ID_print
, /* 35 */
711 ikev2_ID_print
, /* 36 */
712 ikev2_cert_print
, /* 37 */
713 ikev2_cr_print
, /* 38 */
714 ikev2_auth_print
, /* 39 */
715 ikev2_nonce_print
, /* 40 */
716 ikev2_n_print
, /* 41 */
717 ikev2_d_print
, /* 42 */
718 ikev2_vid_print
, /* 43 */
719 ikev2_TS_print
, /* 44 */
720 ikev2_TS_print
, /* 45 */
721 NULL
, /* ikev2_e_print,*/ /* 46 - special */
722 ikev2_cp_print
, /* 47 */
723 ikev2_eap_print
, /* 48 */
727 static const char *etypestr
[] = {
728 /* IKEv1 exchange types */
729 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
, /* 0-7 */
730 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 8-15 */
731 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 16-23 */
732 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 24-31 */
733 "oakley-quick", "oakley-newgroup", /* 32-33 */
734 /* IKEv2 exchange types */
735 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
738 #define STR_OR_ID(x, tab) \
739 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
740 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
741 #define NPSTR(x) STR_OR_ID(x, npstr)
742 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
744 #define CHECKLEN(p, np) \
745 if (ep < (u_char *)(p)) { \
746 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
752 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
753 ? npfunc[(x)] : NULL)
756 iszero(u_char
*p
, size_t l
)
765 /* find cookie from initiator cache */
767 cookie_find(cookie_t
*in
)
771 for (i
= 0; i
< MAXINITIATORS
; i
++) {
772 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
779 /* record initiator */
781 cookie_record(cookie_t
*in
, const u_char
*bp2
)
791 ninitiator
= (i
+ 1) % MAXINITIATORS
;
795 ip
= (struct ip
*)bp2
;
798 cookiecache
[ninitiator
].version
= 4;
799 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in4
, &ip
->ip_src
, sizeof(struct in_addr
));
800 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in4
, &ip
->ip_dst
, sizeof(struct in_addr
));
804 ip6
= (struct ip6_hdr
*)bp2
;
805 cookiecache
[ninitiator
].version
= 6;
806 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].iaddr
.in6
, &ip6
->ip6_src
, sizeof(struct in6_addr
));
807 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].raddr
.in6
, &ip6
->ip6_dst
, sizeof(struct in6_addr
));
813 UNALIGNED_MEMCPY(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
814 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
817 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
818 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
820 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
827 ip
= (struct ip
*)bp2
;
830 if (cookiecache
[i
].version
!= 4)
833 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &cookiecache
[i
].iaddr
.in4
, sizeof(struct in_addr
)) == 0)
836 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &cookiecache
[i
].raddr
.in4
, sizeof(struct in_addr
)) == 0)
842 if (cookiecache
[i
].version
!= 6)
844 ip6
= (struct ip6_hdr
*)bp2
;
846 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &cookiecache
[i
].iaddr
.in6
, sizeof(struct in6_addr
)) == 0)
849 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &cookiecache
[i
].raddr
.in6
, sizeof(struct in6_addr
)) == 0)
862 hexprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
868 for (i
= 0; i
< len
; i
++)
869 ND_PRINT((ndo
,"%02x", p
[i
] & 0xff));
873 rawprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
875 ND_TCHECK2(*loc
, len
);
877 hexprint(ndo
, loc
, len
);
885 * returns false if we run out of data buffer
887 static int ike_show_somedata(struct netdissect_options
*ndo
,
888 const u_char
*cp
, const u_char
*ep
)
890 /* there is too much data, just show some of it */
891 const u_char
*end
= ep
- 20;
898 /* really shouldn't happen because of above */
904 ND_PRINT((ndo
," data=("));
905 if(!rawprint(ndo
, (caddr_t
)(cp
), len
)) goto trunc
;
906 ND_PRINT((ndo
, "..."));
908 if(!rawprint(ndo
, (caddr_t
)(end
), elen
)) goto trunc
;
920 const char *value
[30]; /*XXX*/
923 static const u_char
*
924 ikev1_attrmap_print(netdissect_options
*ndo
,
925 const u_char
*p
, const u_char
*ep
,
926 const struct attrmap
*map
, size_t nmap
)
934 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
935 if (ep
< p
+ totlen
) {
936 ND_PRINT((ndo
,"[|attr]"));
941 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
942 if (map
&& t
< nmap
&& map
[t
].type
)
943 ND_PRINT((ndo
,"type=%s ", map
[t
].type
));
945 ND_PRINT((ndo
,"type=#%d ", t
));
947 ND_PRINT((ndo
,"value="));
948 v
= EXTRACT_16BITS(&p
[2]);
949 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
950 ND_PRINT((ndo
,"%s", map
[t
].value
[v
]));
952 rawprint(ndo
, (caddr_t
)&p
[2], 2);
954 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
955 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&p
[2]));
961 static const u_char
*
962 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep
)
970 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
971 if (ep
< p
+ totlen
) {
972 ND_PRINT((ndo
,"[|attr]"));
977 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
978 ND_PRINT((ndo
,"type=#%d ", t
));
980 ND_PRINT((ndo
,"value="));
982 rawprint(ndo
, (caddr_t
)&p
[2], 2);
984 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
985 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&p
[2]));
991 static const u_char
*
992 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
993 const struct isakmp_gen
*ext
,
995 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0 _U_
,
996 u_int32_t proto0
, int depth
)
998 const struct ikev1_pl_sa
*p
;
999 struct ikev1_pl_sa sa
;
1000 u_int32_t doi
, sit
, ident
;
1001 const u_char
*cp
, *np
;
1004 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SA
)));
1006 p
= (struct ikev1_pl_sa
*)ext
;
1008 UNALIGNED_MEMCPY(&sa
, ext
, sizeof(sa
));
1009 doi
= ntohl(sa
.doi
);
1010 sit
= ntohl(sa
.sit
);
1012 ND_PRINT((ndo
," doi=%d", doi
));
1013 ND_PRINT((ndo
," situation=%u", (u_int32_t
)ntohl(sa
.sit
)));
1014 return (u_char
*)(p
+ 1);
1017 ND_PRINT((ndo
," doi=ipsec"));
1018 ND_PRINT((ndo
," situation="));
1021 ND_PRINT((ndo
,"identity"));
1025 ND_PRINT((ndo
,"%ssecrecy", t
? "+" : ""));
1029 ND_PRINT((ndo
,"%sintegrity", t
? "+" : ""));
1031 np
= (u_char
*)ext
+ sizeof(sa
);
1033 ND_TCHECK2(*(ext
+ 1), sizeof(ident
));
1034 UNALIGNED_MEMCPY(&ident
, ext
+ 1, sizeof(ident
));
1035 ND_PRINT((ndo
," ident=%u", (u_int32_t
)ntohl(ident
)));
1036 np
+= sizeof(ident
);
1039 ext
= (struct isakmp_gen
*)np
;
1042 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
1047 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SA
)));
1051 static const u_char
*
1052 ikev1_p_print(netdissect_options
*ndo
, u_char tpay _U_
,
1053 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1054 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0
,
1055 u_int32_t proto0 _U_
, int depth
)
1057 const struct ikev1_pl_p
*p
;
1058 struct ikev1_pl_p prop
;
1061 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_P
)));
1063 p
= (struct ikev1_pl_p
*)ext
;
1065 UNALIGNED_MEMCPY(&prop
, ext
, sizeof(prop
));
1066 ND_PRINT((ndo
," #%d protoid=%s transform=%d",
1067 prop
.p_no
, PROTOIDSTR(prop
.prot_id
), prop
.num_t
));
1068 if (prop
.spi_size
) {
1069 ND_PRINT((ndo
," spi="));
1070 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
1074 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1077 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1078 prop
.prot_id
, depth
);
1082 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1086 static const char *ikev1_p_map
[] = {
1090 static const char *ikev2_t_type_map
[]={
1091 NULL
, "encr", "prf", "integ", "dh", "esn"
1094 static const char *ah_p_map
[] = {
1095 NULL
, "(reserved)", "md5", "sha", "1des",
1096 "sha2-256", "sha2-384", "sha2-512",
1099 static const char *prf_p_map
[] = {
1100 NULL
, "hmac-md5", "hmac-sha", "hmac-tiger",
1104 static const char *integ_p_map
[] = {
1105 NULL
, "hmac-md5", "hmac-sha", "dec-mac",
1106 "kpdk-md5", "aes-xcbc"
1109 static const char *esn_p_map
[] = {
1113 static const char *dh_p_map
[] = {
1115 "modp1024", /* group 2 */
1116 "EC2N 2^155", /* group 3 */
1117 "EC2N 2^185", /* group 4 */
1118 "modp1536", /* group 5 */
1119 "iana-grp06", "iana-grp07", /* reserved */
1120 "iana-grp08", "iana-grp09",
1121 "iana-grp10", "iana-grp11",
1122 "iana-grp12", "iana-grp13",
1123 "modp2048", /* group 14 */
1124 "modp3072", /* group 15 */
1125 "modp4096", /* group 16 */
1126 "modp6144", /* group 17 */
1127 "modp8192", /* group 18 */
1130 static const char *esp_p_map
[] = {
1131 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1132 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1135 static const char *ipcomp_p_map
[] = {
1136 NULL
, "oui", "deflate", "lzs",
1139 static const struct attrmap ipsec_t_map
[] = {
1140 { NULL
, 0, { NULL
} },
1141 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1142 { "life", 0, { NULL
} },
1143 { "group desc", 18, { NULL
, "modp768",
1144 "modp1024", /* group 2 */
1145 "EC2N 2^155", /* group 3 */
1146 "EC2N 2^185", /* group 4 */
1147 "modp1536", /* group 5 */
1148 "iana-grp06", "iana-grp07", /* reserved */
1149 "iana-grp08", "iana-grp09",
1150 "iana-grp10", "iana-grp11",
1151 "iana-grp12", "iana-grp13",
1152 "modp2048", /* group 14 */
1153 "modp3072", /* group 15 */
1154 "modp4096", /* group 16 */
1155 "modp6144", /* group 17 */
1156 "modp8192", /* group 18 */
1158 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
1159 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1160 { "keylen", 0, { NULL
} },
1161 { "rounds", 0, { NULL
} },
1162 { "dictsize", 0, { NULL
} },
1163 { "privalg", 0, { NULL
} },
1166 static const struct attrmap encr_t_map
[] = {
1167 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 0, 1 */
1168 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 2, 3 */
1169 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 4, 5 */
1170 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 6, 7 */
1171 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 8, 9 */
1172 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 10,11*/
1173 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 12,13*/
1174 { "keylen", 14, { NULL
}},
1177 static const struct attrmap oakley_t_map
[] = {
1178 { NULL
, 0, { NULL
} },
1179 { "enc", 8, { NULL
, "1des", "idea", "blowfish", "rc5",
1180 "3des", "cast", "aes", }, },
1181 { "hash", 7, { NULL
, "md5", "sha1", "tiger",
1182 "sha2-256", "sha2-384", "sha2-512", }, },
1183 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
1184 "rsa enc revised", }, },
1185 { "group desc", 18, { NULL
, "modp768",
1186 "modp1024", /* group 2 */
1187 "EC2N 2^155", /* group 3 */
1188 "EC2N 2^185", /* group 4 */
1189 "modp1536", /* group 5 */
1190 "iana-grp06", "iana-grp07", /* reserved */
1191 "iana-grp08", "iana-grp09",
1192 "iana-grp10", "iana-grp11",
1193 "iana-grp12", "iana-grp13",
1194 "modp2048", /* group 14 */
1195 "modp3072", /* group 15 */
1196 "modp4096", /* group 16 */
1197 "modp6144", /* group 17 */
1198 "modp8192", /* group 18 */
1200 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
1201 { "group prime", 0, { NULL
} },
1202 { "group gen1", 0, { NULL
} },
1203 { "group gen2", 0, { NULL
} },
1204 { "group curve A", 0, { NULL
} },
1205 { "group curve B", 0, { NULL
} },
1206 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1207 { "lifeduration", 0, { NULL
} },
1208 { "prf", 0, { NULL
} },
1209 { "keylen", 0, { NULL
} },
1210 { "field", 0, { NULL
} },
1211 { "order", 0, { NULL
} },
1214 static const u_char
*
1215 ikev1_t_print(netdissect_options
*ndo
, u_char tpay _U_
,
1216 const struct isakmp_gen
*ext
, u_int item_len
,
1217 const u_char
*ep
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1218 u_int32_t proto
, int depth _U_
)
1220 const struct ikev1_pl_t
*p
;
1221 struct ikev1_pl_t t
;
1224 const struct attrmap
*map
;
1228 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_T
)));
1230 p
= (struct ikev1_pl_t
*)ext
;
1232 UNALIGNED_MEMCPY(&t
, ext
, sizeof(t
));
1236 idstr
= STR_OR_ID(t
.t_id
, ikev1_p_map
);
1238 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1241 idstr
= STR_OR_ID(t
.t_id
, ah_p_map
);
1243 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1246 idstr
= STR_OR_ID(t
.t_id
, esp_p_map
);
1248 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1251 idstr
= STR_OR_ID(t
.t_id
, ipcomp_p_map
);
1253 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1263 ND_PRINT((ndo
," #%d id=%s ", t
.t_no
, idstr
));
1265 ND_PRINT((ndo
," #%d id=%d ", t
.t_no
, t
.t_id
));
1266 cp
= (u_char
*)(p
+ 1);
1267 ep2
= (u_char
*)p
+ item_len
;
1268 while (cp
< ep
&& cp
< ep2
) {
1270 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1273 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1276 ND_PRINT((ndo
,"..."));
1279 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1283 static const u_char
*
1284 ikev1_ke_print(netdissect_options
*ndo
, u_char tpay _U_
,
1285 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1286 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1287 u_int32_t proto _U_
, int depth _U_
)
1289 struct isakmp_gen e
;
1291 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_KE
)));
1294 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1295 ND_PRINT((ndo
," key len=%d", ntohs(e
.len
) - 4));
1296 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1297 ND_PRINT((ndo
," "));
1298 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1301 return (u_char
*)ext
+ ntohs(e
.len
);
1303 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_KE
)));
1307 static const u_char
*
1308 ikev1_id_print(netdissect_options
*ndo
, u_char tpay _U_
,
1309 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1310 const u_char
*ep _U_
, u_int32_t phase
, u_int32_t doi _U_
,
1311 u_int32_t proto _U_
, int depth _U_
)
1313 #define USE_IPSECDOI_IN_PHASE1 1
1314 const struct ikev1_pl_id
*p
;
1315 struct ikev1_pl_id id
;
1316 static const char *idtypestr
[] = {
1317 "IPv4", "IPv4net", "IPv6", "IPv6net",
1319 static const char *ipsecidtypestr
[] = {
1320 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1321 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1327 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_ID
)));
1329 p
= (struct ikev1_pl_id
*)ext
;
1331 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
1332 if (sizeof(*p
) < item_len
) {
1333 data
= (u_char
*)(p
+ 1);
1334 len
= item_len
- sizeof(*p
);
1341 ND_PRINT((ndo
," [phase=%d doi=%d proto=%d]", phase
, doi
, proto
));
1344 #ifndef USE_IPSECDOI_IN_PHASE1
1348 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.d
.id_type
, idtypestr
)));
1349 ND_PRINT((ndo
," doi_data=%u",
1350 (u_int32_t
)(ntohl(id
.d
.doi_data
) & 0xffffff)));
1353 #ifdef USE_IPSECDOI_IN_PHASE1
1358 const struct ipsecdoi_id
*p
;
1359 struct ipsecdoi_id id
;
1360 struct protoent
*pe
;
1362 p
= (struct ipsecdoi_id
*)ext
;
1364 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
1365 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.type
, ipsecidtypestr
)));
1370 pe
= getprotobynumber(id
.proto_id
);
1372 ND_PRINT((ndo
," protoid=%s", pe
->p_name
));
1377 /* it DOES NOT mean IPPROTO_IP! */
1378 ND_PRINT((ndo
," protoid=%s", "0"));
1380 ND_PRINT((ndo
," port=%d", ntohs(id
.port
)));
1385 ND_TCHECK2(*data
, len
);
1387 case IPSECDOI_ID_IPV4_ADDR
:
1389 ND_PRINT((ndo
," len=%d [bad: < 4]", len
));
1391 ND_PRINT((ndo
," len=%d %s", len
, ipaddr_string(data
)));
1394 case IPSECDOI_ID_FQDN
:
1395 case IPSECDOI_ID_USER_FQDN
:
1398 ND_PRINT((ndo
," len=%d ", len
));
1399 for (i
= 0; i
< len
; i
++)
1400 safeputchar(data
[i
]);
1404 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
1408 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1410 mask
= data
+ sizeof(struct in_addr
);
1411 ND_PRINT((ndo
," len=%d %s/%u.%u.%u.%u", len
,
1412 ipaddr_string(data
),
1413 mask
[0], mask
[1], mask
[2], mask
[3]));
1419 case IPSECDOI_ID_IPV6_ADDR
:
1421 ND_PRINT((ndo
," len=%d [bad: < 16]", len
));
1423 ND_PRINT((ndo
," len=%d %s", len
, ip6addr_string(data
)));
1426 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
1430 ND_PRINT((ndo
," len=%d [bad: < 20]", len
));
1432 mask
= (u_char
*)(data
+ sizeof(struct in6_addr
));
1434 ND_PRINT((ndo
," len=%d %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len
,
1435 ip6addr_string(data
),
1436 mask
[0], mask
[1], mask
[2], mask
[3],
1437 mask
[4], mask
[5], mask
[6], mask
[7],
1438 mask
[8], mask
[9], mask
[10], mask
[11],
1439 mask
[12], mask
[13], mask
[14], mask
[15]));
1445 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1447 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1449 ND_PRINT((ndo
," len=%d %s-%s", len
,
1450 ipaddr_string(data
),
1451 ipaddr_string(data
+ sizeof(struct in_addr
))));
1456 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1458 ND_PRINT((ndo
," len=%d [bad: < 32]", len
));
1460 ND_PRINT((ndo
," len=%d %s-%s", len
,
1461 ip6addr_string(data
),
1462 ip6addr_string(data
+ sizeof(struct in6_addr
))));
1467 case IPSECDOI_ID_DER_ASN1_DN
:
1468 case IPSECDOI_ID_DER_ASN1_GN
:
1469 case IPSECDOI_ID_KEY_ID
:
1476 ND_PRINT((ndo
," len=%d", len
));
1477 if (2 < ndo
->ndo_vflag
) {
1478 ND_PRINT((ndo
," "));
1479 if (!rawprint(ndo
, (caddr_t
)data
, len
))
1483 return (u_char
*)ext
+ item_len
;
1485 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_ID
)));
1489 static const u_char
*
1490 ikev1_cert_print(netdissect_options
*ndo
, u_char tpay _U_
,
1491 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1492 const u_char
*ep _U_
, u_int32_t phase _U_
,
1494 u_int32_t proto0 _U_
, int depth _U_
)
1496 const struct ikev1_pl_cert
*p
;
1497 struct ikev1_pl_cert cert
;
1498 static const char *certstr
[] = {
1499 "none", "pkcs7", "pgp", "dns",
1500 "x509sign", "x509ke", "kerberos", "crl",
1501 "arl", "spki", "x509attr",
1504 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CERT
)));
1506 p
= (struct ikev1_pl_cert
*)ext
;
1508 UNALIGNED_MEMCPY(&cert
, ext
, sizeof(cert
));
1509 ND_PRINT((ndo
," len=%d", item_len
- 4));
1510 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1511 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1512 ND_PRINT((ndo
," "));
1513 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), item_len
- 4))
1516 return (u_char
*)ext
+ item_len
;
1518 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
)));
1522 static const u_char
*
1523 ikev1_cr_print(netdissect_options
*ndo
, u_char tpay _U_
,
1524 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1525 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi0 _U_
,
1526 u_int32_t proto0 _U_
, int depth _U_
)
1528 const struct ikev1_pl_cert
*p
;
1529 struct ikev1_pl_cert cert
;
1530 static const char *certstr
[] = {
1531 "none", "pkcs7", "pgp", "dns",
1532 "x509sign", "x509ke", "kerberos", "crl",
1533 "arl", "spki", "x509attr",
1536 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CR
)));
1538 p
= (struct ikev1_pl_cert
*)ext
;
1540 UNALIGNED_MEMCPY(&cert
, ext
, sizeof(cert
));
1541 ND_PRINT((ndo
," len=%d", item_len
- 4));
1542 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1543 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1544 ND_PRINT((ndo
," "));
1545 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), item_len
- 4))
1548 return (u_char
*)ext
+ item_len
;
1550 ND_PRINT((ndo
," [|%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 _U_
,
1557 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1558 u_int32_t proto _U_
, int depth _U_
)
1560 struct isakmp_gen e
;
1562 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_HASH
)));
1565 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1566 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1567 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1568 ND_PRINT((ndo
," "));
1569 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1572 return (u_char
*)ext
+ ntohs(e
.len
);
1574 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
)));
1578 static const u_char
*
1579 ikev1_sig_print(netdissect_options
*ndo
, u_char tpay _U_
,
1580 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1581 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1582 u_int32_t proto _U_
, int depth _U_
)
1584 struct isakmp_gen e
;
1586 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SIG
)));
1589 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1590 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1591 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1592 ND_PRINT((ndo
," "));
1593 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1596 return (u_char
*)ext
+ ntohs(e
.len
);
1598 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
)));
1602 static const u_char
*
1603 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1604 const struct isakmp_gen
*ext
,
1606 const u_char
*ep _U_
,
1607 u_int32_t phase _U_
, u_int32_t doi _U_
,
1608 u_int32_t proto _U_
, int depth _U_
)
1610 struct isakmp_gen e
;
1612 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1615 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1616 ND_PRINT((ndo
," n len=%d", ntohs(e
.len
) - 4));
1617 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1618 ND_PRINT((ndo
," "));
1619 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1621 } else if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1622 ND_PRINT((ndo
," "));
1623 if (!ike_show_somedata(ndo
, (u_char
*)(caddr_t
)(ext
+ 1), ep
))
1626 return (u_char
*)ext
+ ntohs(e
.len
);
1628 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1632 static const u_char
*
1633 ikev1_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
1634 const struct isakmp_gen
*ext
, u_int item_len
,
1635 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0 _U_
,
1636 u_int32_t proto0 _U_
, int depth
)
1638 struct ikev1_pl_n
*p
, n
;
1643 static const char *notify_error_str
[] = {
1644 NULL
, "INVALID-PAYLOAD-TYPE",
1645 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1646 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1647 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1648 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1649 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1650 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1651 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1652 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1653 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1654 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1655 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1656 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1657 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1658 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1659 "UNEQUAL-PAYLOAD-LENGTHS",
1661 static const char *ipsec_notify_error_str
[] = {
1664 static const char *notify_status_str
[] = {
1667 static const char *ipsec_notify_status_str
[] = {
1668 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1671 /* NOTE: these macro must be called with x in proper range */
1674 #define NOTIFY_ERROR_STR(x) \
1675 STR_OR_ID((x), notify_error_str)
1678 #define IPSEC_NOTIFY_ERROR_STR(x) \
1679 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1682 #define NOTIFY_STATUS_STR(x) \
1683 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1686 #define IPSEC_NOTIFY_STATUS_STR(x) \
1687 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1689 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_N
)));
1691 p
= (struct ikev1_pl_n
*)ext
;
1693 UNALIGNED_MEMCPY(&n
, ext
, sizeof(n
));
1697 ND_PRINT((ndo
," doi=%d", doi
));
1698 ND_PRINT((ndo
," proto=%d", proto
));
1699 if (ntohs(n
.type
) < 8192)
1700 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1701 else if (ntohs(n
.type
) < 16384)
1702 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1703 else if (ntohs(n
.type
) < 24576)
1704 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1706 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1708 ND_PRINT((ndo
," spi="));
1709 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1712 return (u_char
*)(p
+ 1) + n
.spi_size
;
1715 ND_PRINT((ndo
," doi=ipsec"));
1716 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1717 if (ntohs(n
.type
) < 8192)
1718 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1719 else if (ntohs(n
.type
) < 16384)
1720 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n
.type
))));
1721 else if (ntohs(n
.type
) < 24576)
1722 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1723 else if (ntohs(n
.type
) < 32768)
1724 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n
.type
))));
1726 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1728 ND_PRINT((ndo
," spi="));
1729 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1733 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
1734 ep2
= (u_char
*)p
+ item_len
;
1737 ND_PRINT((ndo
," orig=("));
1738 switch (ntohs(n
.type
)) {
1739 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
1741 const struct attrmap
*map
= oakley_t_map
;
1742 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1743 while (cp
< ep
&& cp
< ep2
) {
1744 cp
= ikev1_attrmap_print(ndo
, cp
,
1745 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
1749 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1750 ND_PRINT((ndo
,"replay detection %sabled",
1751 EXTRACT_32BITS(cp
) ? "en" : "dis"));
1753 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
1754 if (ikev1_sub_print(ndo
, ISAKMP_NPTYPE_SA
,
1755 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
,
1761 isakmp_print(ndo
, cp
,
1762 item_len
- sizeof(*p
) - n
.spi_size
,
1765 ND_PRINT((ndo
,")"));
1767 return (u_char
*)ext
+ item_len
;
1769 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
1773 static const u_char
*
1774 ikev1_d_print(netdissect_options
*ndo
, u_char tpay _U_
,
1775 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1776 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi0 _U_
,
1777 u_int32_t proto0 _U_
, int depth _U_
)
1779 const struct ikev1_pl_d
*p
;
1780 struct ikev1_pl_d d
;
1786 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_D
)));
1788 p
= (struct ikev1_pl_d
*)ext
;
1790 UNALIGNED_MEMCPY(&d
, ext
, sizeof(d
));
1794 ND_PRINT((ndo
," doi=%u", doi
));
1795 ND_PRINT((ndo
," proto=%u", proto
));
1797 ND_PRINT((ndo
," doi=ipsec"));
1798 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1800 ND_PRINT((ndo
," spilen=%u", d
.spi_size
));
1801 ND_PRINT((ndo
," nspi=%u", ntohs(d
.num_spi
)));
1802 ND_PRINT((ndo
," spi="));
1803 q
= (u_int8_t
*)(p
+ 1);
1804 for (i
= 0; i
< ntohs(d
.num_spi
); i
++) {
1806 ND_PRINT((ndo
,","));
1807 if (!rawprint(ndo
, (caddr_t
)q
, d
.spi_size
))
1813 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_D
)));
1817 static const u_char
*
1818 ikev1_vid_print(netdissect_options
*ndo
, u_char tpay _U_
,
1819 const struct isakmp_gen
*ext
,
1820 u_int item_len _U_
, const u_char
*ep _U_
,
1821 u_int32_t phase _U_
, u_int32_t doi _U_
,
1822 u_int32_t proto _U_
, int depth _U_
)
1824 struct isakmp_gen e
;
1826 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_VID
)));
1829 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1830 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1831 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1832 ND_PRINT((ndo
," "));
1833 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1836 return (u_char
*)ext
+ ntohs(e
.len
);
1838 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_VID
)));
1842 /************************************************************/
1844 /* IKE v2 - rfc4306 - dissector */
1846 /************************************************************/
1849 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, int critical
)
1851 ND_PRINT((ndo
,"%s%s:", payname
, critical
&0x80 ? "[C]" : ""));
1854 static const u_char
*
1855 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1856 const struct isakmp_gen
*ext
)
1858 struct isakmp_gen e
;
1861 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
1862 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
1864 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1865 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1866 ND_PRINT((ndo
," "));
1867 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1870 return (u_char
*)ext
+ ntohs(e
.len
);
1872 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
1876 static const u_char
*
1877 ikev2_t_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount
,
1878 const struct isakmp_gen
*ext
, u_int item_len
,
1879 const u_char
*ep
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1880 u_int32_t proto _U_
, int depth _U_
)
1882 const struct ikev2_t
*p
;
1887 const struct attrmap
*map
;
1891 p
= (struct ikev2_t
*)ext
;
1893 UNALIGNED_MEMCPY(&t
, ext
, sizeof(t
));
1894 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), t
.h
.critical
);
1896 t_id
= ntohs(t
.t_id
);
1903 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1905 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1909 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1913 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1917 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1921 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1930 ND_PRINT((ndo
," #%u type=%s id=%s ", pcount
,
1931 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1934 ND_PRINT((ndo
," #%u type=%s id=%u ", pcount
,
1935 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1937 cp
= (u_char
*)(p
+ 1);
1938 ep2
= (u_char
*)p
+ item_len
;
1939 while (cp
< ep
&& cp
< ep2
) {
1941 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1944 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1947 ND_PRINT((ndo
,"..."));
1950 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1954 static const u_char
*
1955 ikev2_p_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount _U_
,
1956 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1957 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0
,
1958 u_int32_t proto0 _U_
, int depth
)
1960 const struct ikev2_p
*p
;
1961 struct ikev2_p prop
;
1964 p
= (struct ikev2_p
*)ext
;
1966 UNALIGNED_MEMCPY(&prop
, ext
, sizeof(prop
));
1967 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), prop
.h
.critical
);
1969 ND_PRINT((ndo
," #%u protoid=%s transform=%d len=%u",
1970 prop
.p_no
, PROTOIDSTR(prop
.prot_id
),
1971 prop
.num_t
, ntohs(prop
.h
.len
)));
1972 if (prop
.spi_size
) {
1973 ND_PRINT((ndo
," spi="));
1974 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
1978 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1981 cp
= ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1982 prop
.prot_id
, depth
);
1986 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1990 static const u_char
*
1991 ikev2_sa_print(netdissect_options
*ndo
, u_char tpay
,
1992 const struct isakmp_gen
*ext1
,
1993 u_int item_len _U_
, const u_char
*ep _U_
,
1994 u_int32_t phase _U_
, u_int32_t doi _U_
,
1995 u_int32_t proto _U_
, int depth _U_
)
1997 struct isakmp_gen e
;
1998 int osa_length
, sa_length
;
2001 UNALIGNED_MEMCPY(&e
, ext1
, sizeof(e
));
2002 ikev2_pay_print(ndo
, "sa", e
.critical
);
2004 osa_length
= ntohs(e
.len
);
2005 sa_length
= osa_length
- 4;
2006 ND_PRINT((ndo
," len=%d", sa_length
));
2008 ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_P
,
2012 return (u_char
*)ext1
+ osa_length
;
2014 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2018 static const u_char
*
2019 ikev2_ke_print(netdissect_options
*ndo
, u_char tpay
,
2020 const struct isakmp_gen
*ext
,
2021 u_int item_len _U_
, const u_char
*ep _U_
,
2022 u_int32_t phase _U_
, u_int32_t doi _U_
,
2023 u_int32_t proto _U_
, int depth _U_
)
2028 k
= (struct ikev2_ke
*)ext
;
2030 UNALIGNED_MEMCPY(&ke
, ext
, sizeof(ke
));
2031 ikev2_pay_print(ndo
, NPSTR(tpay
), ke
.h
.critical
);
2033 ND_PRINT((ndo
," len=%u group=%s", ntohs(ke
.h
.len
) - 8,
2034 STR_OR_ID(ntohs(ke
.ke_group
), dh_p_map
)));
2036 if (2 < ndo
->ndo_vflag
&& 8 < ntohs(ke
.h
.len
)) {
2037 ND_PRINT((ndo
," "));
2038 if (!rawprint(ndo
, (caddr_t
)(k
+ 1), ntohs(ke
.h
.len
) - 8))
2041 return (u_char
*)ext
+ ntohs(ke
.h
.len
);
2043 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2047 static const u_char
*
2048 ikev2_ID_print(netdissect_options
*ndo
, u_char tpay
,
2049 const struct isakmp_gen
*ext
,
2050 u_int item_len _U_
, const u_char
*ep _U_
,
2051 u_int32_t phase _U_
, u_int32_t doi _U_
,
2052 u_int32_t proto _U_
, int depth _U_
)
2055 int id_len
, idtype_len
, i
;
2056 unsigned int dumpascii
, dumphex
;
2057 unsigned char *typedata
;
2060 UNALIGNED_MEMCPY(&id
, ext
, sizeof(id
));
2061 ikev2_pay_print(ndo
, NPSTR(tpay
), id
.h
.critical
);
2063 id_len
= ntohs(id
.h
.len
);
2065 ND_PRINT((ndo
," len=%d", id_len
- 4));
2066 if (2 < ndo
->ndo_vflag
&& 4 < id_len
) {
2067 ND_PRINT((ndo
," "));
2068 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), id_len
- 4))
2072 idtype_len
=id_len
- sizeof(struct ikev2_id
);
2075 typedata
= (unsigned char *)(ext
)+sizeof(struct ikev2_id
);
2079 ND_PRINT((ndo
, " ipv4:"));
2083 ND_PRINT((ndo
, " fqdn:"));
2086 case ID_RFC822_ADDR
:
2087 ND_PRINT((ndo
, " rfc822:"));
2091 ND_PRINT((ndo
, " ipv6:"));
2094 case ID_DER_ASN1_DN
:
2095 ND_PRINT((ndo
, " dn:"));
2098 case ID_DER_ASN1_GN
:
2099 ND_PRINT((ndo
, " gn:"));
2103 ND_PRINT((ndo
, " keyid:"));
2109 ND_TCHECK2(*typedata
, idtype_len
);
2110 for(i
=0; i
<idtype_len
; i
++) {
2111 if(ND_ISPRINT(typedata
[i
])) {
2112 ND_PRINT((ndo
, "%c", typedata
[i
]));
2114 ND_PRINT((ndo
, "."));
2119 if (!rawprint(ndo
, (caddr_t
)typedata
, idtype_len
))
2123 return (u_char
*)ext
+ id_len
;
2125 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2129 static const u_char
*
2130 ikev2_cert_print(netdissect_options
*ndo
, u_char tpay
,
2131 const struct isakmp_gen
*ext
,
2132 u_int item_len _U_
, const u_char
*ep _U_
,
2133 u_int32_t phase _U_
, u_int32_t doi _U_
,
2134 u_int32_t proto _U_
, int depth _U_
)
2136 return ikev2_gen_print(ndo
, tpay
, ext
);
2139 static const u_char
*
2140 ikev2_cr_print(netdissect_options
*ndo
, u_char tpay
,
2141 const struct isakmp_gen
*ext
,
2142 u_int item_len _U_
, const u_char
*ep _U_
,
2143 u_int32_t phase _U_
, u_int32_t doi _U_
,
2144 u_int32_t proto _U_
, int depth _U_
)
2146 return ikev2_gen_print(ndo
, tpay
, ext
);
2149 static const u_char
*
2150 ikev2_auth_print(netdissect_options
*ndo
, u_char tpay
,
2151 const struct isakmp_gen
*ext
,
2152 u_int item_len _U_
, const u_char
*ep _U_
,
2153 u_int32_t phase _U_
, u_int32_t doi _U_
,
2154 u_int32_t proto _U_
, int depth _U_
)
2156 struct ikev2_auth a
;
2157 const char *v2_auth
[]={ "invalid", "rsasig",
2158 "shared-secret", "dsssig" };
2159 u_char
*authdata
= (u_char
*)ext
+ sizeof(a
);
2163 UNALIGNED_MEMCPY(&a
, ext
, sizeof(a
));
2164 ikev2_pay_print(ndo
, NPSTR(tpay
), a
.h
.critical
);
2165 len
= ntohs(a
.h
.len
);
2167 ND_PRINT((ndo
," len=%d method=%s", len
-4,
2168 STR_OR_ID(a
.auth_method
, v2_auth
)));
2170 if (1 < ndo
->ndo_vflag
&& 4 < len
) {
2171 ND_PRINT((ndo
," authdata=("));
2172 if (!rawprint(ndo
, (caddr_t
)authdata
, len
- sizeof(a
)))
2174 ND_PRINT((ndo
,") "));
2175 } else if(ndo
->ndo_vflag
&& 4 < len
) {
2176 if(!ike_show_somedata(ndo
, authdata
, ep
)) goto trunc
;
2179 return (u_char
*)ext
+ len
;
2181 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2185 static const u_char
*
2186 ikev2_nonce_print(netdissect_options
*ndo
, u_char tpay
,
2187 const struct isakmp_gen
*ext
,
2188 u_int item_len _U_
, const u_char
*ep _U_
,
2189 u_int32_t phase _U_
, u_int32_t doi _U_
,
2190 u_int32_t proto _U_
, int depth _U_
)
2192 struct isakmp_gen e
;
2195 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2196 ikev2_pay_print(ndo
, "nonce", e
.critical
);
2198 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
2199 if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2200 ND_PRINT((ndo
," nonce=("));
2201 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2203 ND_PRINT((ndo
,") "));
2204 } else if(ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2205 if(!ike_show_somedata(ndo
, (const u_char
*)(ext
+1), ep
)) goto trunc
;
2208 return (u_char
*)ext
+ ntohs(e
.len
);
2210 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2214 /* notify payloads */
2215 static const u_char
*
2216 ikev2_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
2217 const struct isakmp_gen
*ext
,
2218 u_int item_len _U_
, const u_char
*ep _U_
,
2219 u_int32_t phase _U_
, u_int32_t doi _U_
,
2220 u_int32_t proto _U_
, int depth _U_
)
2222 struct ikev2_n
*p
, n
;
2224 u_char showspi
, showdata
, showsomedata
;
2225 const char *notify_name
;
2228 p
= (struct ikev2_n
*)ext
;
2230 UNALIGNED_MEMCPY(&n
, ext
, sizeof(n
));
2231 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), n
.h
.critical
);
2238 ND_PRINT((ndo
," prot_id=%s", PROTOIDSTR(n
.prot_id
)));
2240 type
= ntohs(n
.type
);
2242 /* notify space is annoying sparse */
2244 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
2245 notify_name
= "unsupported_critical_payload";
2249 case IV2_NOTIFY_INVALID_IKE_SPI
:
2250 notify_name
= "invalid_ike_spi";
2254 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
2255 notify_name
= "invalid_major_version";
2259 case IV2_NOTIFY_INVALID_SYNTAX
:
2260 notify_name
= "invalid_syntax";
2264 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
2265 notify_name
= "invalid_message_id";
2269 case IV2_NOTIFY_INVALID_SPI
:
2270 notify_name
= "invalid_spi";
2274 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
2275 notify_name
= "no_protocol_chosen";
2279 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
2280 notify_name
= "invalid_ke_payload";
2284 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
2285 notify_name
= "authentication_failed";
2289 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
2290 notify_name
= "single_pair_required";
2294 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
2295 notify_name
= "no_additional_sas";
2299 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
2300 notify_name
= "internal_address_failure";
2304 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
2305 notify_name
= "failed:cp_required";
2309 case IV2_NOTIFY_INVALID_SELECTORS
:
2310 notify_name
= "invalid_selectors";
2314 case IV2_NOTIFY_INITIAL_CONTACT
:
2315 notify_name
= "initial_contact";
2319 case IV2_NOTIFY_SET_WINDOW_SIZE
:
2320 notify_name
= "set_window_size";
2324 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
2325 notify_name
= "additional_ts_possible";
2329 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
2330 notify_name
= "ipcomp_supported";
2334 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
2335 notify_name
= "nat_detection_source_ip";
2339 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
2340 notify_name
= "nat_detection_destination_ip";
2344 case IV2_NOTIFY_COOKIE
:
2345 notify_name
= "cookie";
2351 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
2352 notify_name
= "use_transport_mode";
2356 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
2357 notify_name
= "http_cert_lookup_supported";
2361 case IV2_NOTIFY_REKEY_SA
:
2362 notify_name
= "rekey_sa";
2366 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
2367 notify_name
= "tfc_padding_not_supported";
2371 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
2372 notify_name
= "non_first_fragment_also";
2378 notify_name
="error";
2379 } else if(type
< 16384) {
2380 notify_name
="private-error";
2381 } else if(type
< 40960) {
2382 notify_name
="status";
2384 notify_name
="private-status";
2389 ND_PRINT((ndo
," type=%u(%s)", type
, notify_name
));
2393 if (showspi
&& n
.spi_size
) {
2394 ND_PRINT((ndo
," spi="));
2395 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
2399 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
2401 if(3 < ndo
->ndo_vflag
) {
2405 if ((showdata
|| (showsomedata
&& ep
-cp
< 30)) && cp
< ep
) {
2406 ND_PRINT((ndo
," data=("));
2407 if (!rawprint(ndo
, (caddr_t
)(cp
), ep
- cp
))
2410 ND_PRINT((ndo
,")"));
2412 } else if(showsomedata
&& cp
< ep
) {
2413 if(!ike_show_somedata(ndo
, cp
, ep
)) goto trunc
;
2416 return (u_char
*)ext
+ item_len
;
2418 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
2422 static const u_char
*
2423 ikev2_d_print(netdissect_options
*ndo
, u_char tpay
,
2424 const struct isakmp_gen
*ext
,
2425 u_int item_len _U_
, const u_char
*ep _U_
,
2426 u_int32_t phase _U_
, u_int32_t doi _U_
,
2427 u_int32_t proto _U_
, int depth _U_
)
2429 return ikev2_gen_print(ndo
, tpay
, ext
);
2432 static const u_char
*
2433 ikev2_vid_print(netdissect_options
*ndo
, u_char tpay
,
2434 const struct isakmp_gen
*ext
,
2435 u_int item_len _U_
, const u_char
*ep _U_
,
2436 u_int32_t phase _U_
, u_int32_t doi _U_
,
2437 u_int32_t proto _U_
, int depth _U_
)
2439 struct isakmp_gen e
;
2444 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2445 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2446 ND_PRINT((ndo
," len=%d vid=", ntohs(e
.len
) - 4));
2448 vid
= (const u_char
*)(ext
+1);
2449 len
= ntohs(e
.len
) - 4;
2450 ND_TCHECK2(*vid
, len
);
2451 for(i
=0; i
<len
; i
++) {
2452 if(ND_ISPRINT(vid
[i
])) ND_PRINT((ndo
, "%c", vid
[i
]));
2453 else ND_PRINT((ndo
, "."));
2455 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2456 ND_PRINT((ndo
," "));
2457 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2460 return (u_char
*)ext
+ ntohs(e
.len
);
2462 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2466 static const u_char
*
2467 ikev2_TS_print(netdissect_options
*ndo
, u_char tpay
,
2468 const struct isakmp_gen
*ext
,
2469 u_int item_len _U_
, const u_char
*ep _U_
,
2470 u_int32_t phase _U_
, u_int32_t doi _U_
,
2471 u_int32_t proto _U_
, int depth _U_
)
2473 return ikev2_gen_print(ndo
, tpay
, ext
);
2476 static const u_char
*
2477 ikev2_e_print(netdissect_options
*ndo
,
2478 #ifndef HAVE_LIBCRYPTO
2481 struct isakmp
*base
,
2483 const struct isakmp_gen
*ext
,
2484 u_int item_len _U_
, const u_char
*ep _U_
,
2485 #ifndef HAVE_LIBCRYPTO
2489 #ifndef HAVE_LIBCRYPTO
2493 #ifndef HAVE_LIBCRYPTO
2497 #ifndef HAVE_LIBCRYPTO
2502 struct isakmp_gen e
;
2507 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2508 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2510 dlen
= ntohs(e
.len
)-4;
2512 ND_PRINT((ndo
," len=%d", dlen
));
2513 if (2 < ndo
->ndo_vflag
&& 4 < dlen
) {
2514 ND_PRINT((ndo
," "));
2515 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), dlen
))
2519 dat
= (u_char
*)(ext
+1);
2520 ND_TCHECK2(*dat
, dlen
);
2522 #ifdef HAVE_LIBCRYPTO
2523 /* try to decypt it! */
2524 if(esp_print_decrypt_buffer_by_ikev2(ndo
,
2525 base
->flags
& ISAKMP_FLAG_I
,
2526 base
->i_ck
, base
->r_ck
,
2529 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
2531 /* got it decrypted, print stuff inside. */
2532 ikev2_sub_print(ndo
, base
, e
.np
, ext
, ndo
->ndo_snapend
,
2533 phase
, doi
, proto
, depth
+1);
2538 /* always return NULL, because E must be at end, and NP refers
2539 * to what was inside.
2543 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2547 static const u_char
*
2548 ikev2_cp_print(netdissect_options
*ndo
, u_char tpay
,
2549 const struct isakmp_gen
*ext
,
2550 u_int item_len _U_
, const u_char
*ep _U_
,
2551 u_int32_t phase _U_
, u_int32_t doi _U_
,
2552 u_int32_t proto _U_
, int depth _U_
)
2554 return ikev2_gen_print(ndo
, tpay
, ext
);
2557 static const u_char
*
2558 ikev2_eap_print(netdissect_options
*ndo
, u_char tpay
,
2559 const struct isakmp_gen
*ext
,
2560 u_int item_len _U_
, const u_char
*ep _U_
,
2561 u_int32_t phase _U_
, u_int32_t doi _U_
,
2562 u_int32_t proto _U_
, int depth _U_
)
2564 return ikev2_gen_print(ndo
, tpay
, ext
);
2567 static const u_char
*
2568 ike_sub0_print(netdissect_options
*ndo
,
2569 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2571 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2574 struct isakmp_gen e
;
2579 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2582 * Since we can't have a payload length of less than 4 bytes,
2583 * we need to bail out here if the generic header is nonsensical
2584 * or truncated, otherwise we could loop forever processing
2585 * zero-length items or otherwise misdissect the packet.
2587 item_len
= ntohs(e
.len
);
2593 * XXX - what if item_len is too short, or too long,
2594 * for this payload type?
2596 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2598 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2604 ND_PRINT((ndo
," [|isakmp]"));
2608 static const u_char
*
2609 ikev1_sub_print(netdissect_options
*ndo
,
2610 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2611 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2615 struct isakmp_gen e
;
2617 cp
= (const u_char
*)ext
;
2622 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2624 ND_TCHECK2(*ext
, ntohs(e
.len
));
2627 ND_PRINT((ndo
,"\n"));
2628 for (i
= 0; i
< depth
; i
++)
2629 ND_PRINT((ndo
," "));
2630 ND_PRINT((ndo
,"("));
2631 cp
= ike_sub0_print(ndo
, np
, ext
, ep
, phase
, doi
, proto
, depth
);
2632 ND_PRINT((ndo
,")"));
2636 /* Zero-length subitem */
2641 ext
= (struct isakmp_gen
*)cp
;
2645 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2652 static char buf
[20];
2653 snprintf(buf
, sizeof(buf
), "#%d", x
);
2658 ikev1_print(netdissect_options
*ndo
,
2659 const u_char
*bp
, u_int length
,
2660 const u_char
*bp2
, struct isakmp
*base
)
2662 const struct isakmp
*p
;
2668 p
= (const struct isakmp
*)bp
;
2669 ep
= ndo
->ndo_snapend
;
2671 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2673 ND_PRINT((ndo
," phase %d", phase
));
2675 ND_PRINT((ndo
," phase %d/others", phase
));
2677 i
= cookie_find(&base
->i_ck
);
2679 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
2680 /* the first packet */
2681 ND_PRINT((ndo
," I"));
2683 cookie_record(&base
->i_ck
, bp2
);
2685 ND_PRINT((ndo
," ?"));
2687 if (bp2
&& cookie_isinitiator(i
, bp2
))
2688 ND_PRINT((ndo
," I"));
2689 else if (bp2
&& cookie_isresponder(i
, bp2
))
2690 ND_PRINT((ndo
," R"));
2692 ND_PRINT((ndo
," ?"));
2695 ND_PRINT((ndo
," %s", ETYPESTR(base
->etype
)));
2697 ND_PRINT((ndo
,"[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
2698 base
->flags
& ISAKMP_FLAG_C
? "C" : ""));
2701 if (ndo
->ndo_vflag
) {
2702 const struct isakmp_gen
*ext
;
2704 ND_PRINT((ndo
,":"));
2706 /* regardless of phase... */
2707 if (base
->flags
& ISAKMP_FLAG_E
) {
2709 * encrypted, nothing we can do right now.
2710 * we hope to decrypt the packet in the future...
2712 ND_PRINT((ndo
," [encrypted %s]", NPSTR(base
->np
)));
2716 CHECKLEN(p
+ 1, base
->np
);
2718 ext
= (struct isakmp_gen
*)(p
+ 1);
2719 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
2723 if (ndo
->ndo_vflag
) {
2724 if (ntohl(base
->len
) != length
) {
2725 ND_PRINT((ndo
," (len mismatch: isakmp %u/ip %u)",
2726 (u_int32_t
)ntohl(base
->len
), length
));
2731 static const u_char
*
2732 ikev2_sub0_print(netdissect_options
*ndo
, struct isakmp
*base
,
2733 u_char np
, int pcount
,
2734 const struct isakmp_gen
*ext
, const u_char
*ep
,
2735 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2738 struct isakmp_gen e
;
2743 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2746 * Since we can't have a payload length of less than 4 bytes,
2747 * we need to bail out here if the generic header is nonsensical
2748 * or truncated, otherwise we could loop forever processing
2749 * zero-length items or otherwise misdissect the packet.
2751 item_len
= ntohs(e
.len
);
2755 if(np
== ISAKMP_NPTYPE_P
) {
2756 cp
= ikev2_p_print(ndo
, np
, pcount
, ext
, item_len
,
2757 ep
, phase
, doi
, proto
, depth
);
2758 } else if(np
== ISAKMP_NPTYPE_T
) {
2759 cp
= ikev2_t_print(ndo
, np
, pcount
, ext
, item_len
,
2760 ep
, phase
, doi
, proto
, depth
);
2761 } else if(np
== ISAKMP_NPTYPE_v2E
) {
2762 cp
= ikev2_e_print(ndo
, base
, np
, ext
, item_len
,
2763 ep
, phase
, doi
, proto
, depth
);
2764 } else if (NPFUNC(np
)) {
2766 * XXX - what if item_len is too short, or too long,
2767 * for this payload type?
2769 cp
= (*npfunc
[np
])(ndo
, np
, /*pcount,*/ ext
, item_len
,
2770 ep
, phase
, doi
, proto
, depth
);
2772 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2778 ND_PRINT((ndo
," [|isakmp]"));
2782 static const u_char
*
2783 ikev2_sub_print(netdissect_options
*ndo
,
2784 struct isakmp
*base
,
2785 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2786 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2791 struct isakmp_gen e
;
2793 cp
= (const u_char
*)ext
;
2799 UNALIGNED_MEMCPY(&e
, ext
, sizeof(e
));
2801 ND_TCHECK2(*ext
, ntohs(e
.len
));
2804 ND_PRINT((ndo
,"\n"));
2805 for (i
= 0; i
< depth
; i
++)
2806 ND_PRINT((ndo
," "));
2807 ND_PRINT((ndo
,"("));
2808 cp
= ikev2_sub0_print(ndo
, base
, np
, pcount
,
2809 ext
, ep
, phase
, doi
, proto
, depth
);
2810 ND_PRINT((ndo
,")"));
2814 /* Zero-length subitem */
2819 ext
= (struct isakmp_gen
*)cp
;
2823 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2828 ikev2_print(netdissect_options
*ndo
,
2829 const u_char
*bp
, u_int length
,
2830 const u_char
*bp2 _U_
, struct isakmp
*base
)
2832 const struct isakmp
*p
;
2837 p
= (const struct isakmp
*)bp
;
2838 ep
= ndo
->ndo_snapend
;
2840 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2842 ND_PRINT((ndo
, " parent_sa"));
2844 ND_PRINT((ndo
, " child_sa "));
2846 ND_PRINT((ndo
, " %s", ETYPESTR(base
->etype
)));
2848 ND_PRINT((ndo
, "[%s%s%s]",
2849 base
->flags
& ISAKMP_FLAG_I
? "I" : "",
2850 base
->flags
& ISAKMP_FLAG_V
? "V" : "",
2851 base
->flags
& ISAKMP_FLAG_R
? "R" : ""));
2854 if (ndo
->ndo_vflag
) {
2855 const struct isakmp_gen
*ext
;
2857 ND_PRINT((ndo
, ":"));
2859 /* regardless of phase... */
2860 if (base
->flags
& ISAKMP_FLAG_E
) {
2862 * encrypted, nothing we can do right now.
2863 * we hope to decrypt the packet in the future...
2865 ND_PRINT((ndo
, " [encrypted %s]", NPSTR(base
->np
)));
2869 CHECKLEN(p
+ 1, base
->np
)
2872 ext
= (struct isakmp_gen
*)(p
+ 1);
2873 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
2877 if (ndo
->ndo_vflag
) {
2878 if (ntohl(base
->len
) != length
) {
2879 ND_PRINT((ndo
, " (len mismatch: isakmp %u/ip %u)",
2880 (u_int32_t
)ntohl(base
->len
), length
));
2886 isakmp_print(netdissect_options
*ndo
,
2887 const u_char
*bp
, u_int length
,
2890 const struct isakmp
*p
;
2895 #ifdef HAVE_LIBCRYPTO
2896 /* initialize SAs */
2897 if (ndo
->ndo_sa_list_head
== NULL
) {
2898 if (ndo
->ndo_espsecret
)
2899 esp_print_decodesecret(ndo
);
2903 p
= (const struct isakmp
*)bp
;
2904 ep
= ndo
->ndo_snapend
;
2906 if ((struct isakmp
*)ep
< p
+ 1) {
2907 ND_PRINT((ndo
,"[|isakmp]"));
2911 UNALIGNED_MEMCPY(&base
, p
, sizeof(base
));
2913 ND_PRINT((ndo
,"isakmp"));
2914 major
= (base
.vers
& ISAKMP_VERS_MAJOR
)
2915 >> ISAKMP_VERS_MAJOR_SHIFT
;
2916 minor
= (base
.vers
& ISAKMP_VERS_MINOR
)
2917 >> ISAKMP_VERS_MINOR_SHIFT
;
2919 if (ndo
->ndo_vflag
) {
2920 ND_PRINT((ndo
," %d.%d", major
, minor
));
2923 if (ndo
->ndo_vflag
) {
2924 ND_PRINT((ndo
," msgid "));
2925 hexprint(ndo
, (caddr_t
)&base
.msgid
, sizeof(base
.msgid
));
2928 if (1 < ndo
->ndo_vflag
) {
2929 ND_PRINT((ndo
," cookie "));
2930 hexprint(ndo
, (caddr_t
)&base
.i_ck
, sizeof(base
.i_ck
));
2931 ND_PRINT((ndo
,"->"));
2932 hexprint(ndo
, (caddr_t
)&base
.r_ck
, sizeof(base
.r_ck
));
2934 ND_PRINT((ndo
,":"));
2937 case IKEv1_MAJOR_VERSION
:
2938 ikev1_print(ndo
, bp
, length
, bp2
, &base
);
2941 case IKEv2_MAJOR_VERSION
:
2942 ikev2_print(ndo
, bp
, length
, bp2
, &base
);
2948 isakmp_rfc3948_print(netdissect_options
*ndo
,
2949 const u_char
*bp
, u_int length
,
2953 if(length
== 1 && bp
[0]==0xff) {
2954 ND_PRINT((ndo
, "isakmp-nat-keep-alive"));
2963 * see if this is an IKE packet
2965 if(bp
[0]==0 && bp
[1]==0 && bp
[2]==0 && bp
[3]==0) {
2966 ND_PRINT((ndo
, "NONESP-encap: "));
2967 isakmp_print(ndo
, bp
+4, length
-4, bp2
);
2971 /* must be an ESP packet */
2973 int nh
, enh
, padlen
;
2976 ND_PRINT((ndo
, "UDP-encap: "));
2978 advance
= esp_print(ndo
, bp
, length
, bp2
, &enh
, &padlen
);
2983 length
-= advance
+ padlen
;
2986 ip_print_inner(ndo
, bp
, length
, nh
, bp2
);
2991 ND_PRINT((ndo
,"[|isakmp]"));
2997 * c-style: whitesmith