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>
49 #include "interface.h"
50 #include "addrtoname.h"
51 #include "extract.h" /* must come after interface.h */
58 /* refer to RFC 2408 */
60 typedef u_char cookie_t
[8];
61 typedef u_char msgid_t
[4];
63 #define PORT_ISAKMP 500
65 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
66 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 cookie_t i_ck
; /* Initiator Cookie */
83 cookie_t r_ck
; /* Responder Cookie */
84 u_int8_t np
; /* Next Payload Type */
86 #define ISAKMP_VERS_MAJOR 0xf0
87 #define ISAKMP_VERS_MAJOR_SHIFT 4
88 #define ISAKMP_VERS_MINOR 0x0f
89 #define ISAKMP_VERS_MINOR_SHIFT 0
90 u_int8_t etype
; /* Exchange Type */
91 u_int8_t flags
; /* Flags */
93 u_int32_t len
; /* Length */
96 /* Next Payload Type */
97 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
98 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
99 #define ISAKMP_NPTYPE_P 2 /* Proposal */
100 #define ISAKMP_NPTYPE_T 3 /* Transform */
101 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
102 #define ISAKMP_NPTYPE_ID 5 /* Identification */
103 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
104 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
105 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
106 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
107 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
108 #define ISAKMP_NPTYPE_N 11 /* Notification */
109 #define ISAKMP_NPTYPE_D 12 /* Delete */
110 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
111 #define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
113 #define IKEv1_MAJOR_VERSION 1
114 #define IKEv1_MINOR_VERSION 0
116 #define IKEv2_MAJOR_VERSION 2
117 #define IKEv2_MINOR_VERSION 0
120 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
121 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
122 #define ISAKMP_FLAG_extra 0x04
125 #define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
126 #define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
127 #define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
130 /* 3.2 Payload Generic Header
131 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
132 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133 ! Next Payload ! RESERVED ! Payload Length !
134 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
137 u_int8_t np
; /* Next Payload */
138 u_int8_t critical
; /* bit 7 - critical, rest is RESERVED */
139 u_int16_t len
; /* Payload Length */
142 /* 3.3 Data Attributes
143 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
144 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 !A! Attribute Type ! AF=0 Attribute Length !
146 !F! ! AF=1 Attribute Value !
147 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 . AF=0 Attribute Value .
149 . AF=1 Not Transmitted .
150 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 u_int16_t type
; /* defined by DOI-spec, and Attribute Format */
154 u_int16_t lorv
; /* if f equal 1, Attribute Length */
155 /* if f equal 0, Attribute Value */
156 /* if f equal 1, Attribute Value */
159 /* 3.4 Security Association Payload */
160 /* MAY NOT be used, because of being defined in ipsec-doi. */
162 If the current payload is the last in the message,
163 then the value of the next payload field will be 0.
164 This field MUST NOT contain the
165 values for the Proposal or Transform payloads as they are considered
166 part of the security association negotiation. For example, this
167 field would contain the value "10" (Nonce payload) in the first
168 message of a Base Exchange (see Section 4.4) and the value "0" in the
169 first message of an Identity Protect Exchange (see Section 4.5).
173 u_int32_t doi
; /* Domain of Interpretation */
174 u_int32_t sit
; /* Situation */
177 /* 3.5 Proposal Payload */
179 The value of the next payload field MUST only contain the value "2"
180 or "0". If there are additional Proposal payloads in the message,
181 then this field will be 2. If the current Proposal payload is the
182 last within the security association proposal, then this field will
187 u_int8_t p_no
; /* Proposal # */
188 u_int8_t prot_id
; /* Protocol */
189 u_int8_t spi_size
; /* SPI Size */
190 u_int8_t num_t
; /* Number of Transforms */
194 /* 3.6 Transform Payload */
196 The value of the next payload field MUST only contain the value "3"
197 or "0". If there are additional Transform payloads in the proposal,
198 then this field will be 3. If the current Transform payload is the
199 last within the proposal, then this field will be 0.
203 u_int8_t t_no
; /* Transform # */
204 u_int8_t t_id
; /* Transform-Id */
205 u_int16_t reserved
; /* RESERVED2 */
209 /* 3.7 Key Exchange Payload */
212 /* Key Exchange Data */
215 /* 3.8 Identification Payload */
216 /* MUST NOT to be used, because of being defined in ipsec-doi. */
220 u_int8_t id_type
; /* ID Type */
221 u_int32_t doi_data
; /* DOI Specific ID Data */
223 /* Identification Data */
226 /* 3.9 Certificate Payload */
227 struct ikev1_pl_cert
{
229 u_int8_t encode
; /* Cert Encoding */
230 char cert
; /* Certificate Data */
232 This field indicates the type of
233 certificate or certificate-related information contained in the
234 Certificate Data field.
238 /* 3.10 Certificate Request Payload */
241 u_int8_t num_cert
; /* # Cert. Types */
243 Certificate Types (variable length)
244 -- Contains a list of the types of certificates requested,
245 sorted in order of preference. Each individual certificate
246 type is 1 octet. This field is NOT requiredo
248 /* # Certificate Authorities (1 octet) */
249 /* Certificate Authorities (variable length) */
252 /* 3.11 Hash Payload */
253 /* may not be used, because of having only data. */
254 struct ikev1_pl_hash
{
259 /* 3.12 Signature Payload */
260 /* may not be used, because of having only data. */
261 struct ikev1_pl_sig
{
266 /* 3.13 Nonce Payload */
267 /* may not be used, because of having only data. */
268 struct ikev1_pl_nonce
{
273 /* 3.14 Notification Payload */
276 u_int32_t doi
; /* Domain of Interpretation */
277 u_int8_t prot_id
; /* Protocol-ID */
278 u_int8_t spi_size
; /* SPI Size */
279 u_int16_t type
; /* Notify Message Type */
281 /* Notification Data */
284 /* 3.14.1 Notify Message Types */
285 /* NOTIFY MESSAGES - ERROR TYPES */
286 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
287 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
288 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
289 #define ISAKMP_NTYPE_INVALID_COOKIE 4
290 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
291 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
292 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
293 #define ISAKMP_NTYPE_INVALID_FLAGS 8
294 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
295 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
296 #define ISAKMP_NTYPE_INVALID_SPI 11
297 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
298 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
299 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
300 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
301 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
302 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
303 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
304 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
305 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
306 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
307 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
308 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
309 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
310 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
311 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
313 /* 3.15 Delete Payload */
316 u_int32_t doi
; /* Domain of Interpretation */
317 u_int8_t prot_id
; /* Protocol-Id */
318 u_int8_t spi_size
; /* SPI Size */
319 u_int16_t num_spi
; /* # of SPIs */
323 struct ikev1_ph1tab
{
324 struct ikev1_ph1
*head
;
325 struct ikev1_ph1
*tail
;
329 struct isakmp_ph2tab
{
330 struct ikev1_ph2
*head
;
331 struct ikev1_ph2
*tail
;
335 /* IKEv2 (RFC4306) */
337 /* 3.3 Security Association Payload -- generic header */
338 /* 3.3.1. Proposal Substructure */
341 u_int8_t p_no
; /* Proposal # */
342 u_int8_t prot_id
; /* Protocol */
343 u_int8_t spi_size
; /* SPI Size */
344 u_int8_t num_t
; /* Number of Transforms */
347 /* 3.3.2. Transform Substructure */
350 u_int8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
351 u_int8_t res2
; /* reserved byte */
352 u_int16_t t_id
; /* Transform ID */
363 /* 3.4. Key Exchange Payload */
372 /* 3.5. Identification Payloads */
384 u_int8_t type
; /* ID type */
388 /* Notification Data */
391 /* 3.10 Notification Payload */
394 u_int8_t prot_id
; /* Protocol-ID */
395 u_int8_t spi_size
; /* SPI Size */
396 u_int16_t type
; /* Notify Message Type */
400 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
401 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
402 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
403 IV2_NOTIFY_INVALID_SYNTAX
= 7,
404 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
405 IV2_NOTIFY_INVALID_SPI
=11,
406 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
407 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
408 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
409 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
410 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
411 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
412 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
413 IV2_NOTIFY_INVALID_SELECTORS
=39,
414 IV2_NOTIFY_INITIAL_CONTACT
=16384,
415 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
416 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
417 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
418 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
419 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
420 IV2_NOTIFY_COOKIE
=16390,
421 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
422 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
423 IV2_NOTIFY_REKEY_SA
=16393,
424 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
425 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
428 struct notify_messages
{
433 /* 3.8 Notification Payload */
436 u_int8_t auth_method
; /* Protocol-ID */
437 u_int8_t reserved
[3];
438 /* authentication data */
441 enum ikev2_auth_type
{
447 /* refer to RFC 2409 */
450 /* isakmp sa structure */
452 u_int8_t proto_id
; /* OAKLEY */
453 vchar_t
*spi
; /* spi */
454 u_int8_t dhgrp
; /* DH; group */
455 u_int8_t auth_t
; /* method of authentication */
456 u_int8_t prf_t
; /* type of prf */
457 u_int8_t hash_t
; /* type of hash */
458 u_int8_t enc_t
; /* type of cipher */
459 u_int8_t life_t
; /* type of duration of lifetime */
460 u_int32_t ldur
; /* life duration */
464 /* refer to RFC 2407 */
468 /* 4.2 IPSEC Situation Definition */
469 #define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
470 #define IPSECDOI_SIT_SECRECY 0x00000002
471 #define IPSECDOI_SIT_INTEGRITY 0x00000004
473 /* 4.4.1 IPSEC Security Protocol Identifiers */
474 /* 4.4.2 IPSEC ISAKMP Transform Values */
475 #define IPSECDOI_PROTO_ISAKMP 1
476 #define IPSECDOI_KEY_IKE 1
478 /* 4.4.1 IPSEC Security Protocol Identifiers */
479 #define IPSECDOI_PROTO_IPSEC_AH 2
480 /* 4.4.3 IPSEC AH Transform Values */
481 #define IPSECDOI_AH_MD5 2
482 #define IPSECDOI_AH_SHA 3
483 #define IPSECDOI_AH_DES 4
484 #define IPSECDOI_AH_SHA2_256 5
485 #define IPSECDOI_AH_SHA2_384 6
486 #define IPSECDOI_AH_SHA2_512 7
488 /* 4.4.1 IPSEC Security Protocol Identifiers */
489 #define IPSECDOI_PROTO_IPSEC_ESP 3
490 /* 4.4.4 IPSEC ESP Transform Identifiers */
491 #define IPSECDOI_ESP_DES_IV64 1
492 #define IPSECDOI_ESP_DES 2
493 #define IPSECDOI_ESP_3DES 3
494 #define IPSECDOI_ESP_RC5 4
495 #define IPSECDOI_ESP_IDEA 5
496 #define IPSECDOI_ESP_CAST 6
497 #define IPSECDOI_ESP_BLOWFISH 7
498 #define IPSECDOI_ESP_3IDEA 8
499 #define IPSECDOI_ESP_DES_IV32 9
500 #define IPSECDOI_ESP_RC4 10
501 #define IPSECDOI_ESP_NULL 11
502 #define IPSECDOI_ESP_RIJNDAEL 12
503 #define IPSECDOI_ESP_AES 12
505 /* 4.4.1 IPSEC Security Protocol Identifiers */
506 #define IPSECDOI_PROTO_IPCOMP 4
507 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
508 #define IPSECDOI_IPCOMP_OUI 1
509 #define IPSECDOI_IPCOMP_DEFLATE 2
510 #define IPSECDOI_IPCOMP_LZS 3
512 /* 4.5 IPSEC Security Association Attributes */
513 #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
514 #define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
515 #define IPSECDOI_ATTR_SA_LTYPE_SEC 1
516 #define IPSECDOI_ATTR_SA_LTYPE_KB 2
517 #define IPSECDOI_ATTR_SA_LDUR 2 /* V */
518 #define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
519 #define IPSECDOI_ATTR_GRP_DESC 3 /* B */
520 #define IPSECDOI_ATTR_ENC_MODE 4 /* B */
521 /* default value: host dependent */
522 #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
523 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2
524 #define IPSECDOI_ATTR_AUTH 5 /* B */
525 /* 0 means not to use authentication. */
526 #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
527 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
528 #define IPSECDOI_ATTR_AUTH_DES_MAC 3
529 #define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
531 * When negotiating ESP without authentication, the Auth
532 * Algorithm attribute MUST NOT be included in the proposal.
533 * When negotiating ESP without confidentiality, the Auth
534 * Algorithm attribute MUST be included in the proposal and
535 * the ESP transform ID must be ESP_NULL.
537 #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
538 #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
539 #define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
540 #define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
542 /* 4.6.1 Security Association Payload */
545 u_int32_t doi
; /* Domain of Interpretation */
546 u_int32_t sit
; /* Situation */
549 struct ipsecdoi_secrecy_h
{
554 /* 4.6.2.1 Identification Type Values */
557 u_int8_t type
; /* ID Type */
558 u_int8_t proto_id
; /* Protocol ID */
559 u_int16_t port
; /* Port */
560 /* Identification Data */
563 #define IPSECDOI_ID_IPV4_ADDR 1
564 #define IPSECDOI_ID_FQDN 2
565 #define IPSECDOI_ID_USER_FQDN 3
566 #define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
567 #define IPSECDOI_ID_IPV6_ADDR 5
568 #define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
569 #define IPSECDOI_ID_IPV4_ADDR_RANGE 7
570 #define IPSECDOI_ID_IPV6_ADDR_RANGE 8
571 #define IPSECDOI_ID_DER_ASN1_DN 9
572 #define IPSECDOI_ID_DER_ASN1_GN 10
573 #define IPSECDOI_ID_KEY_ID 11
575 /* 4.6.3 IPSEC DOI Notify Message Types */
576 /* Notify Messages - Status Types */
577 #define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
578 #define IPSECDOI_NTYPE_REPLAY_STATUS 24577
579 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
581 #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
582 netdissect_options *ndo, u_char tpay, \
583 const struct isakmp_gen *ext, \
585 const u_char *end_pointer, \
588 u_int32_t proto0, int depth)
590 DECLARE_PRINTER(v1_sa
);
591 DECLARE_PRINTER(v1_p
);
592 DECLARE_PRINTER(v1_t
);
593 DECLARE_PRINTER(v1_ke
);
594 DECLARE_PRINTER(v1_id
);
595 DECLARE_PRINTER(v1_cert
);
596 DECLARE_PRINTER(v1_cr
);
597 DECLARE_PRINTER(v1_sig
);
598 DECLARE_PRINTER(v1_hash
);
599 DECLARE_PRINTER(v1_nonce
);
600 DECLARE_PRINTER(v1_n
);
601 DECLARE_PRINTER(v1_d
);
602 DECLARE_PRINTER(v1_vid
);
604 DECLARE_PRINTER(v2_sa
);
605 DECLARE_PRINTER(v2_ke
);
606 DECLARE_PRINTER(v2_ID
);
607 DECLARE_PRINTER(v2_cert
);
608 DECLARE_PRINTER(v2_cr
);
609 DECLARE_PRINTER(v2_auth
);
610 DECLARE_PRINTER(v2_nonce
);
611 DECLARE_PRINTER(v2_n
);
612 DECLARE_PRINTER(v2_d
);
613 DECLARE_PRINTER(v2_vid
);
614 DECLARE_PRINTER(v2_TS
);
615 DECLARE_PRINTER(v2_cp
);
616 DECLARE_PRINTER(v2_eap
);
618 static const u_char
*ikev2_e_print(netdissect_options
*ndo
,
621 const struct isakmp_gen
*ext
,
623 const u_char
*end_pointer
,
626 u_int32_t proto0
, int depth
);
629 static const u_char
*ike_sub0_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
630 const u_char
*, u_int32_t
, u_int32_t
, u_int32_t
, int);
631 static const u_char
*ikev1_sub_print(netdissect_options
*ndo
,u_char
, const struct isakmp_gen
*,
632 const u_char
*, u_int32_t
, u_int32_t
, u_int32_t
, int);
634 static const u_char
*ikev2_sub_print(netdissect_options
*ndo
,
636 u_char np
, const struct isakmp_gen
*ext
,
637 const u_char
*ep
, u_int32_t phase
,
638 u_int32_t doi
, u_int32_t proto
,
642 static char *numstr(int);
645 ikev1_print(netdissect_options
*ndo
,
646 const u_char
*bp
, u_int length
,
647 const u_char
*bp2
, struct isakmp
*base
);
649 #define MAXINITIATORS 20
660 union inaddr_u iaddr
;
661 union inaddr_u raddr
;
662 } cookiecache
[MAXINITIATORS
];
665 static const char *protoidstr
[] = {
666 NULL
, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
670 static const char *npstr
[] = {
671 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
672 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
673 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
674 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
675 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
676 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
677 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
678 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
679 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
685 static const u_char
*(*npfunc
[])(netdissect_options
*ndo
, u_char tpay
,
686 const struct isakmp_gen
*ext
,
688 const u_char
*end_pointer
,
691 u_int32_t proto0
, int depth
) = {
705 ikev1_vid_print
, /* 13 */
706 NULL
, NULL
, NULL
, NULL
, NULL
, /* 14- 18 */
707 NULL
, NULL
, NULL
, NULL
, NULL
, /* 19- 23 */
708 NULL
, NULL
, NULL
, NULL
, NULL
, /* 24- 28 */
709 NULL
, NULL
, NULL
, NULL
, /* 29- 32 */
710 ikev2_sa_print
, /* 33 */
711 ikev2_ke_print
, /* 34 */
712 ikev2_ID_print
, /* 35 */
713 ikev2_ID_print
, /* 36 */
714 ikev2_cert_print
, /* 37 */
715 ikev2_cr_print
, /* 38 */
716 ikev2_auth_print
, /* 39 */
717 ikev2_nonce_print
, /* 40 */
718 ikev2_n_print
, /* 41 */
719 ikev2_d_print
, /* 42 */
720 ikev2_vid_print
, /* 43 */
721 ikev2_TS_print
, /* 44 */
722 ikev2_TS_print
, /* 45 */
723 NULL
, /* ikev2_e_print,*/ /* 46 - special */
724 ikev2_cp_print
, /* 47 */
725 ikev2_eap_print
, /* 48 */
729 static const char *etypestr
[] = {
730 /* IKEv1 exchange types */
731 "none", "base", "ident", "auth", "agg", "inf", NULL
, NULL
, /* 0-7 */
732 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 8-15 */
733 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 16-23 */
734 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 24-31 */
735 "oakley-quick", "oakley-newgroup", /* 32-33 */
736 /* IKEv2 exchange types */
737 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
740 #define STR_OR_ID(x, tab) \
741 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
742 #define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
743 #define NPSTR(x) STR_OR_ID(x, npstr)
744 #define ETYPESTR(x) STR_OR_ID(x, etypestr)
746 #define CHECKLEN(p, np) \
747 if (ep < (u_char *)(p)) { \
748 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
754 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
755 ? npfunc[(x)] : NULL)
758 iszero(u_char
*p
, size_t l
)
767 /* find cookie from initiator cache */
769 cookie_find(cookie_t
*in
)
773 for (i
= 0; i
< MAXINITIATORS
; i
++) {
774 if (memcmp(in
, &cookiecache
[i
].initiator
, sizeof(*in
)) == 0)
781 /* record initiator */
783 cookie_record(cookie_t
*in
, const u_char
*bp2
)
793 ninitiator
= (i
+ 1) % MAXINITIATORS
;
797 ip
= (struct ip
*)bp2
;
800 cookiecache
[ninitiator
].version
= 4;
801 unaligned_memcpy(&cookiecache
[ninitiator
].iaddr
.in4
, &ip
->ip_src
, sizeof(struct in_addr
));
802 unaligned_memcpy(&cookiecache
[ninitiator
].raddr
.in4
, &ip
->ip_dst
, sizeof(struct in_addr
));
806 ip6
= (struct ip6_hdr
*)bp2
;
807 cookiecache
[ninitiator
].version
= 6;
808 unaligned_memcpy(&cookiecache
[ninitiator
].iaddr
.in6
, &ip6
->ip6_src
, sizeof(struct in6_addr
));
809 unaligned_memcpy(&cookiecache
[ninitiator
].raddr
.in6
, &ip6
->ip6_dst
, sizeof(struct in6_addr
));
815 unaligned_memcpy(&cookiecache
[ninitiator
].initiator
, in
, sizeof(*in
));
816 ninitiator
= (ninitiator
+ 1) % MAXINITIATORS
;
819 #define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
820 #define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
822 cookie_sidecheck(int i
, const u_char
*bp2
, int initiator
)
829 ip
= (struct ip
*)bp2
;
832 if (cookiecache
[i
].version
!= 4)
835 if (unaligned_memcmp(&ip
->ip_src
, &cookiecache
[i
].iaddr
.in4
, sizeof(struct in_addr
)) == 0)
838 if (unaligned_memcmp(&ip
->ip_src
, &cookiecache
[i
].raddr
.in4
, sizeof(struct in_addr
)) == 0)
844 if (cookiecache
[i
].version
!= 6)
846 ip6
= (struct ip6_hdr
*)bp2
;
848 if (unaligned_memcmp(&ip6
->ip6_src
, &cookiecache
[i
].iaddr
.in6
, sizeof(struct in6_addr
)) == 0)
851 if (unaligned_memcmp(&ip6
->ip6_src
, &cookiecache
[i
].raddr
.in6
, sizeof(struct in6_addr
)) == 0)
864 hexprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
870 for (i
= 0; i
< len
; i
++)
871 ND_PRINT((ndo
,"%02x", p
[i
] & 0xff));
875 rawprint(netdissect_options
*ndo
, caddr_t loc
, size_t len
)
877 ND_TCHECK2(*loc
, len
);
879 hexprint(ndo
, loc
, len
);
887 * returns false if we run out of data buffer
889 static int ike_show_somedata(struct netdissect_options
*ndo
,
890 const u_char
*cp
, const u_char
*ep
)
892 /* there is too much data, just show some of it */
893 const u_char
*end
= ep
- 20;
900 /* really shouldn't happen because of above */
906 ND_PRINT((ndo
," data=("));
907 if(!rawprint(ndo
, (caddr_t
)(cp
), len
)) goto trunc
;
908 ND_PRINT((ndo
, "..."));
910 if(!rawprint(ndo
, (caddr_t
)(end
), elen
)) goto trunc
;
922 const char *value
[30]; /*XXX*/
925 static const u_char
*
926 ikev1_attrmap_print(netdissect_options
*ndo
,
927 const u_char
*p
, const u_char
*ep
,
928 const struct attrmap
*map
, size_t nmap
)
936 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
937 if (ep
< p
+ totlen
) {
938 ND_PRINT((ndo
,"[|attr]"));
943 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
944 if (map
&& t
< nmap
&& map
[t
].type
)
945 ND_PRINT((ndo
,"type=%s ", map
[t
].type
));
947 ND_PRINT((ndo
,"type=#%d ", t
));
949 ND_PRINT((ndo
,"value="));
950 v
= EXTRACT_16BITS(&p
[2]);
951 if (map
&& t
< nmap
&& v
< map
[t
].nvalue
&& map
[t
].value
[v
])
952 ND_PRINT((ndo
,"%s", map
[t
].value
[v
]));
954 rawprint(ndo
, (caddr_t
)&p
[2], 2);
956 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
957 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&p
[2]));
963 static const u_char
*
964 ikev1_attr_print(netdissect_options
*ndo
, const u_char
*p
, const u_char
*ep
)
972 totlen
= 4 + EXTRACT_16BITS(&p
[2]);
973 if (ep
< p
+ totlen
) {
974 ND_PRINT((ndo
,"[|attr]"));
979 t
= EXTRACT_16BITS(&p
[0]) & 0x7fff;
980 ND_PRINT((ndo
,"type=#%d ", t
));
982 ND_PRINT((ndo
,"value="));
984 rawprint(ndo
, (caddr_t
)&p
[2], 2);
986 ND_PRINT((ndo
,"len=%d value=", EXTRACT_16BITS(&p
[2])));
987 rawprint(ndo
, (caddr_t
)&p
[4], EXTRACT_16BITS(&p
[2]));
993 static const u_char
*
994 ikev1_sa_print(netdissect_options
*ndo
, u_char tpay _U_
,
995 const struct isakmp_gen
*ext
,
997 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0 _U_
,
998 u_int32_t proto0
, int depth
)
1000 const struct ikev1_pl_sa
*p
;
1001 struct ikev1_pl_sa sa
;
1002 u_int32_t doi
, sit
, ident
;
1003 const u_char
*cp
, *np
;
1006 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SA
)));
1008 p
= (struct ikev1_pl_sa
*)ext
;
1010 unaligned_memcpy(&sa
, ext
, sizeof(sa
));
1011 doi
= ntohl(sa
.doi
);
1012 sit
= ntohl(sa
.sit
);
1014 ND_PRINT((ndo
," doi=%d", doi
));
1015 ND_PRINT((ndo
," situation=%u", (u_int32_t
)ntohl(sa
.sit
)));
1016 return (u_char
*)(p
+ 1);
1019 ND_PRINT((ndo
," doi=ipsec"));
1020 ND_PRINT((ndo
," situation="));
1023 ND_PRINT((ndo
,"identity"));
1027 ND_PRINT((ndo
,"%ssecrecy", t
? "+" : ""));
1031 ND_PRINT((ndo
,"%sintegrity", t
? "+" : ""));
1033 np
= (u_char
*)ext
+ sizeof(sa
);
1035 ND_TCHECK2(*(ext
+ 1), sizeof(ident
));
1036 unaligned_memcpy(&ident
, ext
+ 1, sizeof(ident
));
1037 ND_PRINT((ndo
," ident=%u", (u_int32_t
)ntohl(ident
)));
1038 np
+= sizeof(ident
);
1041 ext
= (struct isakmp_gen
*)np
;
1044 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_P
, ext
, ep
, phase
, doi
, proto0
,
1049 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SA
)));
1053 static const u_char
*
1054 ikev1_p_print(netdissect_options
*ndo
, u_char tpay _U_
,
1055 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1056 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0
,
1057 u_int32_t proto0 _U_
, int depth
)
1059 const struct ikev1_pl_p
*p
;
1060 struct ikev1_pl_p prop
;
1063 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_P
)));
1065 p
= (struct ikev1_pl_p
*)ext
;
1067 unaligned_memcpy(&prop
, ext
, sizeof(prop
));
1068 ND_PRINT((ndo
," #%d protoid=%s transform=%d",
1069 prop
.p_no
, PROTOIDSTR(prop
.prot_id
), prop
.num_t
));
1070 if (prop
.spi_size
) {
1071 ND_PRINT((ndo
," spi="));
1072 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
1076 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1079 cp
= ikev1_sub_print(ndo
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1080 prop
.prot_id
, depth
);
1084 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1088 static const char *ikev1_p_map
[] = {
1092 static const char *ikev2_t_type_map
[]={
1093 NULL
, "encr", "prf", "integ", "dh", "esn"
1096 static const char *ah_p_map
[] = {
1097 NULL
, "(reserved)", "md5", "sha", "1des",
1098 "sha2-256", "sha2-384", "sha2-512",
1101 static const char *prf_p_map
[] = {
1102 NULL
, "hmac-md5", "hmac-sha", "hmac-tiger",
1106 static const char *integ_p_map
[] = {
1107 NULL
, "hmac-md5", "hmac-sha", "dec-mac",
1108 "kpdk-md5", "aes-xcbc"
1111 static const char *esn_p_map
[] = {
1115 static const char *dh_p_map
[] = {
1117 "modp1024", /* group 2 */
1118 "EC2N 2^155", /* group 3 */
1119 "EC2N 2^185", /* group 4 */
1120 "modp1536", /* group 5 */
1121 "iana-grp06", "iana-grp07", /* reserved */
1122 "iana-grp08", "iana-grp09",
1123 "iana-grp10", "iana-grp11",
1124 "iana-grp12", "iana-grp13",
1125 "modp2048", /* group 14 */
1126 "modp3072", /* group 15 */
1127 "modp4096", /* group 16 */
1128 "modp6144", /* group 17 */
1129 "modp8192", /* group 18 */
1132 static const char *esp_p_map
[] = {
1133 NULL
, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1134 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1137 static const char *ipcomp_p_map
[] = {
1138 NULL
, "oui", "deflate", "lzs",
1141 static const struct attrmap ipsec_t_map
[] = {
1142 { NULL
, 0, { NULL
} },
1143 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1144 { "life", 0, { NULL
} },
1145 { "group desc", 18, { NULL
, "modp768",
1146 "modp1024", /* group 2 */
1147 "EC2N 2^155", /* group 3 */
1148 "EC2N 2^185", /* group 4 */
1149 "modp1536", /* group 5 */
1150 "iana-grp06", "iana-grp07", /* reserved */
1151 "iana-grp08", "iana-grp09",
1152 "iana-grp10", "iana-grp11",
1153 "iana-grp12", "iana-grp13",
1154 "modp2048", /* group 14 */
1155 "modp3072", /* group 15 */
1156 "modp4096", /* group 16 */
1157 "modp6144", /* group 17 */
1158 "modp8192", /* group 18 */
1160 { "enc mode", 3, { NULL
, "tunnel", "transport", }, },
1161 { "auth", 5, { NULL
, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1162 { "keylen", 0, { NULL
} },
1163 { "rounds", 0, { NULL
} },
1164 { "dictsize", 0, { NULL
} },
1165 { "privalg", 0, { NULL
} },
1168 static const struct attrmap encr_t_map
[] = {
1169 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 0, 1 */
1170 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 2, 3 */
1171 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 4, 5 */
1172 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 6, 7 */
1173 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 8, 9 */
1174 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 10,11*/
1175 { NULL
, 0, { NULL
} }, { NULL
, 0, { NULL
} }, /* 12,13*/
1176 { "keylen", 14, { NULL
}},
1179 static const struct attrmap oakley_t_map
[] = {
1180 { NULL
, 0, { NULL
} },
1181 { "enc", 8, { NULL
, "1des", "idea", "blowfish", "rc5",
1182 "3des", "cast", "aes", }, },
1183 { "hash", 7, { NULL
, "md5", "sha1", "tiger",
1184 "sha2-256", "sha2-384", "sha2-512", }, },
1185 { "auth", 6, { NULL
, "preshared", "dss", "rsa sig", "rsa enc",
1186 "rsa enc revised", }, },
1187 { "group desc", 18, { NULL
, "modp768",
1188 "modp1024", /* group 2 */
1189 "EC2N 2^155", /* group 3 */
1190 "EC2N 2^185", /* group 4 */
1191 "modp1536", /* group 5 */
1192 "iana-grp06", "iana-grp07", /* reserved */
1193 "iana-grp08", "iana-grp09",
1194 "iana-grp10", "iana-grp11",
1195 "iana-grp12", "iana-grp13",
1196 "modp2048", /* group 14 */
1197 "modp3072", /* group 15 */
1198 "modp4096", /* group 16 */
1199 "modp6144", /* group 17 */
1200 "modp8192", /* group 18 */
1202 { "group type", 4, { NULL
, "MODP", "ECP", "EC2N", }, },
1203 { "group prime", 0, { NULL
} },
1204 { "group gen1", 0, { NULL
} },
1205 { "group gen2", 0, { NULL
} },
1206 { "group curve A", 0, { NULL
} },
1207 { "group curve B", 0, { NULL
} },
1208 { "lifetype", 3, { NULL
, "sec", "kb", }, },
1209 { "lifeduration", 0, { NULL
} },
1210 { "prf", 0, { NULL
} },
1211 { "keylen", 0, { NULL
} },
1212 { "field", 0, { NULL
} },
1213 { "order", 0, { NULL
} },
1216 static const u_char
*
1217 ikev1_t_print(netdissect_options
*ndo
, u_char tpay _U_
,
1218 const struct isakmp_gen
*ext
, u_int item_len
,
1219 const u_char
*ep
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1220 u_int32_t proto
, int depth _U_
)
1222 const struct ikev1_pl_t
*p
;
1223 struct ikev1_pl_t t
;
1226 const struct attrmap
*map
;
1230 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_T
)));
1232 p
= (struct ikev1_pl_t
*)ext
;
1234 unaligned_memcpy(&t
, ext
, sizeof(t
));
1238 idstr
= STR_OR_ID(t
.t_id
, ikev1_p_map
);
1240 nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1243 idstr
= STR_OR_ID(t
.t_id
, ah_p_map
);
1245 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1248 idstr
= STR_OR_ID(t
.t_id
, esp_p_map
);
1250 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1253 idstr
= STR_OR_ID(t
.t_id
, ipcomp_p_map
);
1255 nmap
= sizeof(ipsec_t_map
)/sizeof(ipsec_t_map
[0]);
1265 ND_PRINT((ndo
," #%d id=%s ", t
.t_no
, idstr
));
1267 ND_PRINT((ndo
," #%d id=%d ", t
.t_no
, t
.t_id
));
1268 cp
= (u_char
*)(p
+ 1);
1269 ep2
= (u_char
*)p
+ item_len
;
1270 while (cp
< ep
&& cp
< ep2
) {
1272 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1275 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1278 ND_PRINT((ndo
,"..."));
1281 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1285 static const u_char
*
1286 ikev1_ke_print(netdissect_options
*ndo
, u_char tpay _U_
,
1287 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1288 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1289 u_int32_t proto _U_
, int depth _U_
)
1291 struct isakmp_gen e
;
1293 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_KE
)));
1296 unaligned_memcpy(&e
, ext
, sizeof(e
));
1297 ND_PRINT((ndo
," key len=%d", ntohs(e
.len
) - 4));
1298 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1299 ND_PRINT((ndo
," "));
1300 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1303 return (u_char
*)ext
+ ntohs(e
.len
);
1305 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_KE
)));
1309 static const u_char
*
1310 ikev1_id_print(netdissect_options
*ndo
, u_char tpay _U_
,
1311 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1312 const u_char
*ep _U_
, u_int32_t phase
, u_int32_t doi _U_
,
1313 u_int32_t proto _U_
, int depth _U_
)
1315 #define USE_IPSECDOI_IN_PHASE1 1
1316 const struct ikev1_pl_id
*p
;
1317 struct ikev1_pl_id id
;
1318 static const char *idtypestr
[] = {
1319 "IPv4", "IPv4net", "IPv6", "IPv6net",
1321 static const char *ipsecidtypestr
[] = {
1322 NULL
, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1323 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1329 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_ID
)));
1331 p
= (struct ikev1_pl_id
*)ext
;
1333 unaligned_memcpy(&id
, ext
, sizeof(id
));
1334 if (sizeof(*p
) < item_len
) {
1335 data
= (u_char
*)(p
+ 1);
1336 len
= item_len
- sizeof(*p
);
1343 ND_PRINT((ndo
," [phase=%d doi=%d proto=%d]", phase
, doi
, proto
));
1346 #ifndef USE_IPSECDOI_IN_PHASE1
1350 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.d
.id_type
, idtypestr
)));
1351 ND_PRINT((ndo
," doi_data=%u",
1352 (u_int32_t
)(ntohl(id
.d
.doi_data
) & 0xffffff)));
1355 #ifdef USE_IPSECDOI_IN_PHASE1
1360 const struct ipsecdoi_id
*p
;
1361 struct ipsecdoi_id id
;
1362 struct protoent
*pe
;
1364 p
= (struct ipsecdoi_id
*)ext
;
1366 unaligned_memcpy(&id
, ext
, sizeof(id
));
1367 ND_PRINT((ndo
," idtype=%s", STR_OR_ID(id
.type
, ipsecidtypestr
)));
1372 pe
= getprotobynumber(id
.proto_id
);
1374 ND_PRINT((ndo
," protoid=%s", pe
->p_name
));
1379 /* it DOES NOT mean IPPROTO_IP! */
1380 ND_PRINT((ndo
," protoid=%s", "0"));
1382 ND_PRINT((ndo
," port=%d", ntohs(id
.port
)));
1387 ND_TCHECK2(*data
, len
);
1389 case IPSECDOI_ID_IPV4_ADDR
:
1391 ND_PRINT((ndo
," len=%d [bad: < 4]", len
));
1393 ND_PRINT((ndo
," len=%d %s", len
, ipaddr_string(data
)));
1396 case IPSECDOI_ID_FQDN
:
1397 case IPSECDOI_ID_USER_FQDN
:
1400 ND_PRINT((ndo
," len=%d ", len
));
1401 for (i
= 0; i
< len
; i
++)
1402 safeputchar(data
[i
]);
1406 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
1410 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1412 mask
= data
+ sizeof(struct in_addr
);
1413 ND_PRINT((ndo
," len=%d %s/%u.%u.%u.%u", len
,
1414 ipaddr_string(data
),
1415 mask
[0], mask
[1], mask
[2], mask
[3]));
1421 case IPSECDOI_ID_IPV6_ADDR
:
1423 ND_PRINT((ndo
," len=%d [bad: < 16]", len
));
1425 ND_PRINT((ndo
," len=%d %s", len
, ip6addr_string(data
)));
1428 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
1432 ND_PRINT((ndo
," len=%d [bad: < 20]", len
));
1434 mask
= (u_char
*)(data
+ sizeof(struct in6_addr
));
1436 ND_PRINT((ndo
," len=%d %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len
,
1437 ip6addr_string(data
),
1438 mask
[0], mask
[1], mask
[2], mask
[3],
1439 mask
[4], mask
[5], mask
[6], mask
[7],
1440 mask
[8], mask
[9], mask
[10], mask
[11],
1441 mask
[12], mask
[13], mask
[14], mask
[15]));
1447 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
1449 ND_PRINT((ndo
," len=%d [bad: < 8]", len
));
1451 ND_PRINT((ndo
," len=%d %s-%s", len
,
1452 ipaddr_string(data
),
1453 ipaddr_string(data
+ sizeof(struct in_addr
))));
1458 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
1460 ND_PRINT((ndo
," len=%d [bad: < 32]", len
));
1462 ND_PRINT((ndo
," len=%d %s-%s", len
,
1463 ip6addr_string(data
),
1464 ip6addr_string(data
+ sizeof(struct in6_addr
))));
1469 case IPSECDOI_ID_DER_ASN1_DN
:
1470 case IPSECDOI_ID_DER_ASN1_GN
:
1471 case IPSECDOI_ID_KEY_ID
:
1478 ND_PRINT((ndo
," len=%d", len
));
1479 if (2 < ndo
->ndo_vflag
) {
1480 ND_PRINT((ndo
," "));
1481 if (!rawprint(ndo
, (caddr_t
)data
, len
))
1485 return (u_char
*)ext
+ item_len
;
1487 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_ID
)));
1491 static const u_char
*
1492 ikev1_cert_print(netdissect_options
*ndo
, u_char tpay _U_
,
1493 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1494 const u_char
*ep _U_
, u_int32_t phase _U_
,
1496 u_int32_t proto0 _U_
, int depth _U_
)
1498 const struct ikev1_pl_cert
*p
;
1499 struct ikev1_pl_cert cert
;
1500 static const char *certstr
[] = {
1501 "none", "pkcs7", "pgp", "dns",
1502 "x509sign", "x509ke", "kerberos", "crl",
1503 "arl", "spki", "x509attr",
1506 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CERT
)));
1508 p
= (struct ikev1_pl_cert
*)ext
;
1510 unaligned_memcpy(&cert
, ext
, sizeof(cert
));
1511 ND_PRINT((ndo
," len=%d", item_len
- 4));
1512 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1513 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1514 ND_PRINT((ndo
," "));
1515 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), item_len
- 4))
1518 return (u_char
*)ext
+ item_len
;
1520 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT
)));
1524 static const u_char
*
1525 ikev1_cr_print(netdissect_options
*ndo
, u_char tpay _U_
,
1526 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1527 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi0 _U_
,
1528 u_int32_t proto0 _U_
, int depth _U_
)
1530 const struct ikev1_pl_cert
*p
;
1531 struct ikev1_pl_cert cert
;
1532 static const char *certstr
[] = {
1533 "none", "pkcs7", "pgp", "dns",
1534 "x509sign", "x509ke", "kerberos", "crl",
1535 "arl", "spki", "x509attr",
1538 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_CR
)));
1540 p
= (struct ikev1_pl_cert
*)ext
;
1542 unaligned_memcpy(&cert
, ext
, sizeof(cert
));
1543 ND_PRINT((ndo
," len=%d", item_len
- 4));
1544 ND_PRINT((ndo
," type=%s", STR_OR_ID((cert
.encode
), certstr
)));
1545 if (2 < ndo
->ndo_vflag
&& 4 < item_len
) {
1546 ND_PRINT((ndo
," "));
1547 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), item_len
- 4))
1550 return (u_char
*)ext
+ item_len
;
1552 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_CR
)));
1556 static const u_char
*
1557 ikev1_hash_print(netdissect_options
*ndo
, u_char tpay _U_
,
1558 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1559 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1560 u_int32_t proto _U_
, int depth _U_
)
1562 struct isakmp_gen e
;
1564 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_HASH
)));
1567 unaligned_memcpy(&e
, ext
, sizeof(e
));
1568 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1569 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1570 ND_PRINT((ndo
," "));
1571 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1574 return (u_char
*)ext
+ ntohs(e
.len
);
1576 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH
)));
1580 static const u_char
*
1581 ikev1_sig_print(netdissect_options
*ndo
, u_char tpay _U_
,
1582 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1583 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1584 u_int32_t proto _U_
, int depth _U_
)
1586 struct isakmp_gen e
;
1588 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_SIG
)));
1591 unaligned_memcpy(&e
, ext
, sizeof(e
));
1592 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1593 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1594 ND_PRINT((ndo
," "));
1595 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1598 return (u_char
*)ext
+ ntohs(e
.len
);
1600 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG
)));
1604 static const u_char
*
1605 ikev1_nonce_print(netdissect_options
*ndo
, u_char tpay _U_
,
1606 const struct isakmp_gen
*ext
,
1608 const u_char
*ep _U_
,
1609 u_int32_t phase _U_
, u_int32_t doi _U_
,
1610 u_int32_t proto _U_
, int depth _U_
)
1612 struct isakmp_gen e
;
1614 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1617 unaligned_memcpy(&e
, ext
, sizeof(e
));
1618 ND_PRINT((ndo
," n len=%d", ntohs(e
.len
) - 4));
1619 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1620 ND_PRINT((ndo
," "));
1621 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1623 } else if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1624 ND_PRINT((ndo
," "));
1625 if (!ike_show_somedata(ndo
, (u_char
*)(caddr_t
)(ext
+ 1), ep
))
1628 return (u_char
*)ext
+ ntohs(e
.len
);
1630 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE
)));
1634 static const u_char
*
1635 ikev1_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
1636 const struct isakmp_gen
*ext
, u_int item_len
,
1637 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0 _U_
,
1638 u_int32_t proto0 _U_
, int depth
)
1640 struct ikev1_pl_n
*p
, n
;
1645 static const char *notify_error_str
[] = {
1646 NULL
, "INVALID-PAYLOAD-TYPE",
1647 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1648 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1649 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1650 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1651 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1652 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1653 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1654 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1655 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1656 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1657 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1658 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1659 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1660 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1661 "UNEQUAL-PAYLOAD-LENGTHS",
1663 static const char *ipsec_notify_error_str
[] = {
1666 static const char *notify_status_str
[] = {
1669 static const char *ipsec_notify_status_str
[] = {
1670 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1673 /* NOTE: these macro must be called with x in proper range */
1676 #define NOTIFY_ERROR_STR(x) \
1677 STR_OR_ID((x), notify_error_str)
1680 #define IPSEC_NOTIFY_ERROR_STR(x) \
1681 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1684 #define NOTIFY_STATUS_STR(x) \
1685 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1688 #define IPSEC_NOTIFY_STATUS_STR(x) \
1689 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1691 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_N
)));
1693 p
= (struct ikev1_pl_n
*)ext
;
1695 unaligned_memcpy(&n
, ext
, sizeof(n
));
1699 ND_PRINT((ndo
," doi=%d", doi
));
1700 ND_PRINT((ndo
," proto=%d", proto
));
1701 if (ntohs(n
.type
) < 8192)
1702 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1703 else if (ntohs(n
.type
) < 16384)
1704 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1705 else if (ntohs(n
.type
) < 24576)
1706 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1708 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1710 ND_PRINT((ndo
," spi="));
1711 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1714 return (u_char
*)(p
+ 1) + n
.spi_size
;
1717 ND_PRINT((ndo
," doi=ipsec"));
1718 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1719 if (ntohs(n
.type
) < 8192)
1720 ND_PRINT((ndo
," type=%s", NOTIFY_ERROR_STR(ntohs(n
.type
))));
1721 else if (ntohs(n
.type
) < 16384)
1722 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n
.type
))));
1723 else if (ntohs(n
.type
) < 24576)
1724 ND_PRINT((ndo
," type=%s", NOTIFY_STATUS_STR(ntohs(n
.type
))));
1725 else if (ntohs(n
.type
) < 32768)
1726 ND_PRINT((ndo
," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n
.type
))));
1728 ND_PRINT((ndo
," type=%s", numstr(ntohs(n
.type
))));
1730 ND_PRINT((ndo
," spi="));
1731 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
1735 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
1736 ep2
= (u_char
*)p
+ item_len
;
1739 ND_PRINT((ndo
," orig=("));
1740 switch (ntohs(n
.type
)) {
1741 case IPSECDOI_NTYPE_RESPONDER_LIFETIME
:
1743 const struct attrmap
*map
= oakley_t_map
;
1744 size_t nmap
= sizeof(oakley_t_map
)/sizeof(oakley_t_map
[0]);
1745 while (cp
< ep
&& cp
< ep2
) {
1746 cp
= ikev1_attrmap_print(ndo
, cp
,
1747 (ep
< ep2
) ? ep
: ep2
, map
, nmap
);
1751 case IPSECDOI_NTYPE_REPLAY_STATUS
:
1752 ND_PRINT((ndo
,"replay detection %sabled",
1753 EXTRACT_32BITS(cp
) ? "en" : "dis"));
1755 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN
:
1756 if (ikev1_sub_print(ndo
, ISAKMP_NPTYPE_SA
,
1757 (struct isakmp_gen
*)cp
, ep
, phase
, doi
, proto
,
1763 isakmp_print(ndo
, cp
,
1764 item_len
- sizeof(*p
) - n
.spi_size
,
1767 ND_PRINT((ndo
,")"));
1769 return (u_char
*)ext
+ item_len
;
1771 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
1775 static const u_char
*
1776 ikev1_d_print(netdissect_options
*ndo
, u_char tpay _U_
,
1777 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1778 const u_char
*ep _U_
, u_int32_t phase _U_
, u_int32_t doi0 _U_
,
1779 u_int32_t proto0 _U_
, int depth _U_
)
1781 const struct ikev1_pl_d
*p
;
1782 struct ikev1_pl_d d
;
1788 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_D
)));
1790 p
= (struct ikev1_pl_d
*)ext
;
1792 unaligned_memcpy(&d
, ext
, sizeof(d
));
1796 ND_PRINT((ndo
," doi=%u", doi
));
1797 ND_PRINT((ndo
," proto=%u", proto
));
1799 ND_PRINT((ndo
," doi=ipsec"));
1800 ND_PRINT((ndo
," proto=%s", PROTOIDSTR(proto
)));
1802 ND_PRINT((ndo
," spilen=%u", d
.spi_size
));
1803 ND_PRINT((ndo
," nspi=%u", ntohs(d
.num_spi
)));
1804 ND_PRINT((ndo
," spi="));
1805 q
= (u_int8_t
*)(p
+ 1);
1806 for (i
= 0; i
< ntohs(d
.num_spi
); i
++) {
1808 ND_PRINT((ndo
,","));
1809 if (!rawprint(ndo
, (caddr_t
)q
, d
.spi_size
))
1815 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_D
)));
1819 static const u_char
*
1820 ikev1_vid_print(netdissect_options
*ndo
, u_char tpay _U_
,
1821 const struct isakmp_gen
*ext
,
1822 u_int item_len _U_
, const u_char
*ep _U_
,
1823 u_int32_t phase _U_
, u_int32_t doi _U_
,
1824 u_int32_t proto _U_
, int depth _U_
)
1826 struct isakmp_gen e
;
1828 ND_PRINT((ndo
,"%s:", NPSTR(ISAKMP_NPTYPE_VID
)));
1831 unaligned_memcpy(&e
, ext
, sizeof(e
));
1832 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1833 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1834 ND_PRINT((ndo
," "));
1835 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1838 return (u_char
*)ext
+ ntohs(e
.len
);
1840 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_VID
)));
1844 /************************************************************/
1846 /* IKE v2 - rfc4306 - dissector */
1848 /************************************************************/
1851 ikev2_pay_print(netdissect_options
*ndo
, const char *payname
, int critical
)
1853 ND_PRINT((ndo
,"%s%s:", payname
, critical
&0x80 ? "[C]" : ""));
1856 static const u_char
*
1857 ikev2_gen_print(netdissect_options
*ndo
, u_char tpay
,
1858 const struct isakmp_gen
*ext
)
1860 struct isakmp_gen e
;
1863 unaligned_memcpy(&e
, ext
, sizeof(e
));
1864 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
1866 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
1867 if (2 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
1868 ND_PRINT((ndo
," "));
1869 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
1872 return (u_char
*)ext
+ ntohs(e
.len
);
1874 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
1878 static const u_char
*
1879 ikev2_t_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount
,
1880 const struct isakmp_gen
*ext
, u_int item_len
,
1881 const u_char
*ep
, u_int32_t phase _U_
, u_int32_t doi _U_
,
1882 u_int32_t proto _U_
, int depth _U_
)
1884 const struct ikev2_t
*p
;
1889 const struct attrmap
*map
;
1893 p
= (struct ikev2_t
*)ext
;
1895 unaligned_memcpy(&t
, ext
, sizeof(t
));
1896 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_T
), t
.h
.critical
);
1898 t_id
= ntohs(t
.t_id
);
1905 idstr
= STR_OR_ID(t_id
, esp_p_map
);
1907 nmap
= sizeof(encr_t_map
)/sizeof(encr_t_map
[0]);
1911 idstr
= STR_OR_ID(t_id
, prf_p_map
);
1915 idstr
= STR_OR_ID(t_id
, integ_p_map
);
1919 idstr
= STR_OR_ID(t_id
, dh_p_map
);
1923 idstr
= STR_OR_ID(t_id
, esn_p_map
);
1932 ND_PRINT((ndo
," #%u type=%s id=%s ", pcount
,
1933 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1936 ND_PRINT((ndo
," #%u type=%s id=%u ", pcount
,
1937 STR_OR_ID(t
.t_type
, ikev2_t_type_map
),
1939 cp
= (u_char
*)(p
+ 1);
1940 ep2
= (u_char
*)p
+ item_len
;
1941 while (cp
< ep
&& cp
< ep2
) {
1943 cp
= ikev1_attrmap_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
,
1946 cp
= ikev1_attr_print(ndo
, cp
, (ep
< ep2
) ? ep
: ep2
);
1949 ND_PRINT((ndo
,"..."));
1952 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_T
)));
1956 static const u_char
*
1957 ikev2_p_print(netdissect_options
*ndo
, u_char tpay _U_
, int pcount _U_
,
1958 const struct isakmp_gen
*ext
, u_int item_len _U_
,
1959 const u_char
*ep
, u_int32_t phase
, u_int32_t doi0
,
1960 u_int32_t proto0 _U_
, int depth
)
1962 const struct ikev2_p
*p
;
1963 struct ikev2_p prop
;
1966 p
= (struct ikev2_p
*)ext
;
1968 unaligned_memcpy(&prop
, ext
, sizeof(prop
));
1969 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_P
), prop
.h
.critical
);
1971 ND_PRINT((ndo
," #%u protoid=%s transform=%d len=%u",
1972 prop
.p_no
, PROTOIDSTR(prop
.prot_id
),
1973 prop
.num_t
, ntohs(prop
.h
.len
)));
1974 if (prop
.spi_size
) {
1975 ND_PRINT((ndo
," spi="));
1976 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), prop
.spi_size
))
1980 ext
= (struct isakmp_gen
*)((u_char
*)(p
+ 1) + prop
.spi_size
);
1983 cp
= ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_T
, ext
, ep
, phase
, doi0
,
1984 prop
.prot_id
, depth
);
1988 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_P
)));
1992 static const u_char
*
1993 ikev2_sa_print(netdissect_options
*ndo
, u_char tpay
,
1994 const struct isakmp_gen
*ext1
,
1995 u_int item_len _U_
, const u_char
*ep _U_
,
1996 u_int32_t phase _U_
, u_int32_t doi _U_
,
1997 u_int32_t proto _U_
, int depth _U_
)
1999 struct isakmp_gen e
;
2000 int osa_length
, sa_length
;
2003 unaligned_memcpy(&e
, ext1
, sizeof(e
));
2004 ikev2_pay_print(ndo
, "sa", e
.critical
);
2006 osa_length
= ntohs(e
.len
);
2007 sa_length
= osa_length
- 4;
2008 ND_PRINT((ndo
," len=%d", sa_length
));
2010 ikev2_sub_print(ndo
, NULL
, ISAKMP_NPTYPE_P
,
2014 return (u_char
*)ext1
+ osa_length
;
2016 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2020 static const u_char
*
2021 ikev2_ke_print(netdissect_options
*ndo
, u_char tpay
,
2022 const struct isakmp_gen
*ext
,
2023 u_int item_len _U_
, const u_char
*ep _U_
,
2024 u_int32_t phase _U_
, u_int32_t doi _U_
,
2025 u_int32_t proto _U_
, int depth _U_
)
2030 k
= (struct ikev2_ke
*)ext
;
2032 unaligned_memcpy(&ke
, ext
, sizeof(ke
));
2033 ikev2_pay_print(ndo
, NPSTR(tpay
), ke
.h
.critical
);
2035 ND_PRINT((ndo
," len=%u group=%s", ntohs(ke
.h
.len
) - 8,
2036 STR_OR_ID(ntohs(ke
.ke_group
), dh_p_map
)));
2038 if (2 < ndo
->ndo_vflag
&& 8 < ntohs(ke
.h
.len
)) {
2039 ND_PRINT((ndo
," "));
2040 if (!rawprint(ndo
, (caddr_t
)(k
+ 1), ntohs(ke
.h
.len
) - 8))
2043 return (u_char
*)ext
+ ntohs(ke
.h
.len
);
2045 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2049 static const u_char
*
2050 ikev2_ID_print(netdissect_options
*ndo
, u_char tpay
,
2051 const struct isakmp_gen
*ext
,
2052 u_int item_len _U_
, const u_char
*ep _U_
,
2053 u_int32_t phase _U_
, u_int32_t doi _U_
,
2054 u_int32_t proto _U_
, int depth _U_
)
2057 int id_len
, idtype_len
, i
;
2058 unsigned int dumpascii
, dumphex
;
2059 unsigned char *typedata
;
2062 unaligned_memcpy(&id
, ext
, sizeof(id
));
2063 ikev2_pay_print(ndo
, NPSTR(tpay
), id
.h
.critical
);
2065 id_len
= ntohs(id
.h
.len
);
2067 ND_PRINT((ndo
," len=%d", id_len
- 4));
2068 if (2 < ndo
->ndo_vflag
&& 4 < id_len
) {
2069 ND_PRINT((ndo
," "));
2070 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), id_len
- 4))
2074 idtype_len
=id_len
- sizeof(struct ikev2_id
);
2077 typedata
= (unsigned char *)(ext
)+sizeof(struct ikev2_id
);
2081 ND_PRINT((ndo
, " ipv4:"));
2085 ND_PRINT((ndo
, " fqdn:"));
2088 case ID_RFC822_ADDR
:
2089 ND_PRINT((ndo
, " rfc822:"));
2093 ND_PRINT((ndo
, " ipv6:"));
2096 case ID_DER_ASN1_DN
:
2097 ND_PRINT((ndo
, " dn:"));
2100 case ID_DER_ASN1_GN
:
2101 ND_PRINT((ndo
, " gn:"));
2105 ND_PRINT((ndo
, " keyid:"));
2111 ND_TCHECK2(*typedata
, idtype_len
);
2112 for(i
=0; i
<idtype_len
; i
++) {
2113 if(isprint(typedata
[i
])) {
2114 ND_PRINT((ndo
, "%c", typedata
[i
]));
2116 ND_PRINT((ndo
, "."));
2121 if (!rawprint(ndo
, (caddr_t
)typedata
, idtype_len
))
2125 return (u_char
*)ext
+ id_len
;
2127 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2131 static const u_char
*
2132 ikev2_cert_print(netdissect_options
*ndo
, u_char tpay
,
2133 const struct isakmp_gen
*ext
,
2134 u_int item_len _U_
, const u_char
*ep _U_
,
2135 u_int32_t phase _U_
, u_int32_t doi _U_
,
2136 u_int32_t proto _U_
, int depth _U_
)
2138 return ikev2_gen_print(ndo
, tpay
, ext
);
2141 static const u_char
*
2142 ikev2_cr_print(netdissect_options
*ndo
, u_char tpay
,
2143 const struct isakmp_gen
*ext
,
2144 u_int item_len _U_
, const u_char
*ep _U_
,
2145 u_int32_t phase _U_
, u_int32_t doi _U_
,
2146 u_int32_t proto _U_
, int depth _U_
)
2148 return ikev2_gen_print(ndo
, tpay
, ext
);
2151 static const u_char
*
2152 ikev2_auth_print(netdissect_options
*ndo
, u_char tpay
,
2153 const struct isakmp_gen
*ext
,
2154 u_int item_len _U_
, const u_char
*ep _U_
,
2155 u_int32_t phase _U_
, u_int32_t doi _U_
,
2156 u_int32_t proto _U_
, int depth _U_
)
2158 struct ikev2_auth a
;
2159 const char *v2_auth
[]={ "invalid", "rsasig",
2160 "shared-secret", "dsssig" };
2161 u_char
*authdata
= (u_char
*)ext
+ sizeof(a
);
2165 unaligned_memcpy(&a
, ext
, sizeof(a
));
2166 ikev2_pay_print(ndo
, NPSTR(tpay
), a
.h
.critical
);
2167 len
= ntohs(a
.h
.len
);
2169 ND_PRINT((ndo
," len=%d method=%s", len
-4,
2170 STR_OR_ID(a
.auth_method
, v2_auth
)));
2172 if (1 < ndo
->ndo_vflag
&& 4 < len
) {
2173 ND_PRINT((ndo
," authdata=("));
2174 if (!rawprint(ndo
, (caddr_t
)authdata
, len
- sizeof(a
)))
2176 ND_PRINT((ndo
,") "));
2177 } else if(ndo
->ndo_vflag
&& 4 < len
) {
2178 if(!ike_show_somedata(ndo
, authdata
, ep
)) goto trunc
;
2181 return (u_char
*)ext
+ len
;
2183 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2187 static const u_char
*
2188 ikev2_nonce_print(netdissect_options
*ndo
, u_char tpay
,
2189 const struct isakmp_gen
*ext
,
2190 u_int item_len _U_
, const u_char
*ep _U_
,
2191 u_int32_t phase _U_
, u_int32_t doi _U_
,
2192 u_int32_t proto _U_
, int depth _U_
)
2194 struct isakmp_gen e
;
2197 unaligned_memcpy(&e
, ext
, sizeof(e
));
2198 ikev2_pay_print(ndo
, "nonce", e
.critical
);
2200 ND_PRINT((ndo
," len=%d", ntohs(e
.len
) - 4));
2201 if (1 < ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2202 ND_PRINT((ndo
," nonce=("));
2203 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2205 ND_PRINT((ndo
,") "));
2206 } else if(ndo
->ndo_vflag
&& 4 < ntohs(e
.len
)) {
2207 if(!ike_show_somedata(ndo
, (const u_char
*)(ext
+1), ep
)) goto trunc
;
2210 return (u_char
*)ext
+ ntohs(e
.len
);
2212 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2216 /* notify payloads */
2217 static const u_char
*
2218 ikev2_n_print(netdissect_options
*ndo
, u_char tpay _U_
,
2219 const struct isakmp_gen
*ext
,
2220 u_int item_len _U_
, const u_char
*ep _U_
,
2221 u_int32_t phase _U_
, u_int32_t doi _U_
,
2222 u_int32_t proto _U_
, int depth _U_
)
2224 struct ikev2_n
*p
, n
;
2226 u_char showspi
, showdata
, showsomedata
;
2227 const char *notify_name
;
2230 p
= (struct ikev2_n
*)ext
;
2232 unaligned_memcpy(&n
, ext
, sizeof(n
));
2233 ikev2_pay_print(ndo
, NPSTR(ISAKMP_NPTYPE_N
), n
.h
.critical
);
2240 ND_PRINT((ndo
," prot_id=%s", PROTOIDSTR(n
.prot_id
)));
2242 type
= ntohs(n
.type
);
2244 /* notify space is annoying sparse */
2246 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
:
2247 notify_name
= "unsupported_critical_payload";
2251 case IV2_NOTIFY_INVALID_IKE_SPI
:
2252 notify_name
= "invalid_ike_spi";
2256 case IV2_NOTIFY_INVALID_MAJOR_VERSION
:
2257 notify_name
= "invalid_major_version";
2261 case IV2_NOTIFY_INVALID_SYNTAX
:
2262 notify_name
= "invalid_syntax";
2266 case IV2_NOTIFY_INVALID_MESSAGE_ID
:
2267 notify_name
= "invalid_message_id";
2271 case IV2_NOTIFY_INVALID_SPI
:
2272 notify_name
= "invalid_spi";
2276 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN
:
2277 notify_name
= "no_protocol_chosen";
2281 case IV2_NOTIFY_INVALID_KE_PAYLOAD
:
2282 notify_name
= "invalid_ke_payload";
2286 case IV2_NOTIFY_AUTHENTICATION_FAILED
:
2287 notify_name
= "authentication_failed";
2291 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED
:
2292 notify_name
= "single_pair_required";
2296 case IV2_NOTIFY_NO_ADDITIONAL_SAS
:
2297 notify_name
= "no_additional_sas";
2301 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
:
2302 notify_name
= "internal_address_failure";
2306 case IV2_NOTIFY_FAILED_CP_REQUIRED
:
2307 notify_name
= "failed:cp_required";
2311 case IV2_NOTIFY_INVALID_SELECTORS
:
2312 notify_name
= "invalid_selectors";
2316 case IV2_NOTIFY_INITIAL_CONTACT
:
2317 notify_name
= "initial_contact";
2321 case IV2_NOTIFY_SET_WINDOW_SIZE
:
2322 notify_name
= "set_window_size";
2326 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
:
2327 notify_name
= "additional_ts_possible";
2331 case IV2_NOTIFY_IPCOMP_SUPPORTED
:
2332 notify_name
= "ipcomp_supported";
2336 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
:
2337 notify_name
= "nat_detection_source_ip";
2341 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
:
2342 notify_name
= "nat_detection_destination_ip";
2346 case IV2_NOTIFY_COOKIE
:
2347 notify_name
= "cookie";
2353 case IV2_NOTIFY_USE_TRANSPORT_MODE
:
2354 notify_name
= "use_transport_mode";
2358 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
:
2359 notify_name
= "http_cert_lookup_supported";
2363 case IV2_NOTIFY_REKEY_SA
:
2364 notify_name
= "rekey_sa";
2368 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
:
2369 notify_name
= "tfc_padding_not_supported";
2373 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
:
2374 notify_name
= "non_first_fragment_also";
2380 notify_name
="error";
2381 } else if(type
< 16384) {
2382 notify_name
="private-error";
2383 } else if(type
< 40960) {
2384 notify_name
="status";
2386 notify_name
="private-status";
2391 ND_PRINT((ndo
," type=%u(%s)", type
, notify_name
));
2395 if (showspi
&& n
.spi_size
) {
2396 ND_PRINT((ndo
," spi="));
2397 if (!rawprint(ndo
, (caddr_t
)(p
+ 1), n
.spi_size
))
2401 cp
= (u_char
*)(p
+ 1) + n
.spi_size
;
2403 if(3 < ndo
->ndo_vflag
) {
2407 if ((showdata
|| (showsomedata
&& ep
-cp
< 30)) && cp
< ep
) {
2408 ND_PRINT((ndo
," data=("));
2409 if (!rawprint(ndo
, (caddr_t
)(cp
), ep
- cp
))
2412 ND_PRINT((ndo
,")"));
2414 } else if(showsomedata
&& cp
< ep
) {
2415 if(!ike_show_somedata(ndo
, cp
, ep
)) goto trunc
;
2418 return (u_char
*)ext
+ item_len
;
2420 ND_PRINT((ndo
," [|%s]", NPSTR(ISAKMP_NPTYPE_N
)));
2424 static const u_char
*
2425 ikev2_d_print(netdissect_options
*ndo
, u_char tpay
,
2426 const struct isakmp_gen
*ext
,
2427 u_int item_len _U_
, const u_char
*ep _U_
,
2428 u_int32_t phase _U_
, u_int32_t doi _U_
,
2429 u_int32_t proto _U_
, int depth _U_
)
2431 return ikev2_gen_print(ndo
, tpay
, ext
);
2434 static const u_char
*
2435 ikev2_vid_print(netdissect_options
*ndo
, u_char tpay
,
2436 const struct isakmp_gen
*ext
,
2437 u_int item_len _U_
, const u_char
*ep _U_
,
2438 u_int32_t phase _U_
, u_int32_t doi _U_
,
2439 u_int32_t proto _U_
, int depth _U_
)
2441 struct isakmp_gen e
;
2446 unaligned_memcpy(&e
, ext
, sizeof(e
));
2447 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2448 ND_PRINT((ndo
," len=%d vid=", ntohs(e
.len
) - 4));
2450 vid
= (const u_char
*)(ext
+1);
2451 len
= ntohs(e
.len
) - 4;
2452 ND_TCHECK2(*vid
, len
);
2453 for(i
=0; i
<len
; i
++) {
2454 if(isprint(vid
[i
])) ND_PRINT((ndo
, "%c", vid
[i
]));
2455 else ND_PRINT((ndo
, "."));
2457 if (2 < ndo
->ndo_vflag
&& 4 < len
) {
2458 ND_PRINT((ndo
," "));
2459 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), ntohs(e
.len
) - 4))
2462 return (u_char
*)ext
+ ntohs(e
.len
);
2464 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2468 static const u_char
*
2469 ikev2_TS_print(netdissect_options
*ndo
, u_char tpay
,
2470 const struct isakmp_gen
*ext
,
2471 u_int item_len _U_
, const u_char
*ep _U_
,
2472 u_int32_t phase _U_
, u_int32_t doi _U_
,
2473 u_int32_t proto _U_
, int depth _U_
)
2475 return ikev2_gen_print(ndo
, tpay
, ext
);
2478 static const u_char
*
2479 ikev2_e_print(netdissect_options
*ndo
,
2480 #ifndef HAVE_LIBCRYPTO
2483 struct isakmp
*base
,
2485 const struct isakmp_gen
*ext
,
2486 u_int item_len _U_
, const u_char
*ep _U_
,
2487 #ifndef HAVE_LIBCRYPTO
2491 #ifndef HAVE_LIBCRYPTO
2495 #ifndef HAVE_LIBCRYPTO
2499 #ifndef HAVE_LIBCRYPTO
2504 struct isakmp_gen e
;
2509 unaligned_memcpy(&e
, ext
, sizeof(e
));
2510 ikev2_pay_print(ndo
, NPSTR(tpay
), e
.critical
);
2512 dlen
= ntohs(e
.len
)-4;
2514 ND_PRINT((ndo
," len=%d", dlen
));
2515 if (2 < ndo
->ndo_vflag
&& 4 < dlen
) {
2516 ND_PRINT((ndo
," "));
2517 if (!rawprint(ndo
, (caddr_t
)(ext
+ 1), dlen
))
2521 dat
= (u_char
*)(ext
+1);
2522 ND_TCHECK2(*dat
, dlen
);
2524 #ifdef HAVE_LIBCRYPTO
2525 /* try to decypt it! */
2526 if(esp_print_decrypt_buffer_by_ikev2(ndo
,
2527 base
->flags
& ISAKMP_FLAG_I
,
2528 base
->i_ck
, base
->r_ck
,
2531 ext
= (const struct isakmp_gen
*)ndo
->ndo_packetp
;
2533 /* got it decrypted, print stuff inside. */
2534 ikev2_sub_print(ndo
, base
, e
.np
, ext
, ndo
->ndo_snapend
,
2535 phase
, doi
, proto
, depth
+1);
2540 /* always return NULL, because E must be at end, and NP refers
2541 * to what was inside.
2545 ND_PRINT((ndo
," [|%s]", NPSTR(tpay
)));
2549 static const u_char
*
2550 ikev2_cp_print(netdissect_options
*ndo
, u_char tpay
,
2551 const struct isakmp_gen
*ext
,
2552 u_int item_len _U_
, const u_char
*ep _U_
,
2553 u_int32_t phase _U_
, u_int32_t doi _U_
,
2554 u_int32_t proto _U_
, int depth _U_
)
2556 return ikev2_gen_print(ndo
, tpay
, ext
);
2559 static const u_char
*
2560 ikev2_eap_print(netdissect_options
*ndo
, u_char tpay
,
2561 const struct isakmp_gen
*ext
,
2562 u_int item_len _U_
, const u_char
*ep _U_
,
2563 u_int32_t phase _U_
, u_int32_t doi _U_
,
2564 u_int32_t proto _U_
, int depth _U_
)
2566 return ikev2_gen_print(ndo
, tpay
, ext
);
2569 static const u_char
*
2570 ike_sub0_print(netdissect_options
*ndo
,
2571 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2573 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2576 struct isakmp_gen e
;
2581 unaligned_memcpy(&e
, ext
, sizeof(e
));
2584 * Since we can't have a payload length of less than 4 bytes,
2585 * we need to bail out here if the generic header is nonsensical
2586 * or truncated, otherwise we could loop forever processing
2587 * zero-length items or otherwise misdissect the packet.
2589 item_len
= ntohs(e
.len
);
2595 * XXX - what if item_len is too short, or too long,
2596 * for this payload type?
2598 cp
= (*npfunc
[np
])(ndo
, np
, ext
, item_len
, ep
, phase
, doi
, proto
, depth
);
2600 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2606 ND_PRINT((ndo
," [|isakmp]"));
2610 static const u_char
*
2611 ikev1_sub_print(netdissect_options
*ndo
,
2612 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2613 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2617 struct isakmp_gen e
;
2619 cp
= (const u_char
*)ext
;
2624 unaligned_memcpy(&e
, ext
, sizeof(e
));
2626 ND_TCHECK2(*ext
, ntohs(e
.len
));
2629 ND_PRINT((ndo
,"\n"));
2630 for (i
= 0; i
< depth
; i
++)
2631 ND_PRINT((ndo
," "));
2632 ND_PRINT((ndo
,"("));
2633 cp
= ike_sub0_print(ndo
, np
, ext
, ep
, phase
, doi
, proto
, depth
);
2634 ND_PRINT((ndo
,")"));
2638 /* Zero-length subitem */
2643 ext
= (struct isakmp_gen
*)cp
;
2647 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2654 static char buf
[20];
2655 snprintf(buf
, sizeof(buf
), "#%d", x
);
2660 ikev1_print(netdissect_options
*ndo
,
2661 const u_char
*bp
, u_int length
,
2662 const u_char
*bp2
, struct isakmp
*base
)
2664 const struct isakmp
*p
;
2670 p
= (const struct isakmp
*)bp
;
2671 ep
= ndo
->ndo_snapend
;
2673 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2675 ND_PRINT((ndo
," phase %d", phase
));
2677 ND_PRINT((ndo
," phase %d/others", phase
));
2679 i
= cookie_find(&base
->i_ck
);
2681 if (iszero((u_char
*)&base
->r_ck
, sizeof(base
->r_ck
))) {
2682 /* the first packet */
2683 ND_PRINT((ndo
," I"));
2685 cookie_record(&base
->i_ck
, bp2
);
2687 ND_PRINT((ndo
," ?"));
2689 if (bp2
&& cookie_isinitiator(i
, bp2
))
2690 ND_PRINT((ndo
," I"));
2691 else if (bp2
&& cookie_isresponder(i
, bp2
))
2692 ND_PRINT((ndo
," R"));
2694 ND_PRINT((ndo
," ?"));
2697 ND_PRINT((ndo
," %s", ETYPESTR(base
->etype
)));
2699 ND_PRINT((ndo
,"[%s%s]", base
->flags
& ISAKMP_FLAG_E
? "E" : "",
2700 base
->flags
& ISAKMP_FLAG_C
? "C" : ""));
2703 if (ndo
->ndo_vflag
) {
2704 const struct isakmp_gen
*ext
;
2706 ND_PRINT((ndo
,":"));
2708 /* regardless of phase... */
2709 if (base
->flags
& ISAKMP_FLAG_E
) {
2711 * encrypted, nothing we can do right now.
2712 * we hope to decrypt the packet in the future...
2714 ND_PRINT((ndo
," [encrypted %s]", NPSTR(base
->np
)));
2718 CHECKLEN(p
+ 1, base
->np
);
2720 ext
= (struct isakmp_gen
*)(p
+ 1);
2721 ikev1_sub_print(ndo
, np
, ext
, ep
, phase
, 0, 0, 0);
2725 if (ndo
->ndo_vflag
) {
2726 if (ntohl(base
->len
) != length
) {
2727 ND_PRINT((ndo
," (len mismatch: isakmp %u/ip %u)",
2728 (u_int32_t
)ntohl(base
->len
), length
));
2733 static const u_char
*
2734 ikev2_sub0_print(netdissect_options
*ndo
, struct isakmp
*base
,
2735 u_char np
, int pcount
,
2736 const struct isakmp_gen
*ext
, const u_char
*ep
,
2737 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2740 struct isakmp_gen e
;
2745 unaligned_memcpy(&e
, ext
, sizeof(e
));
2748 * Since we can't have a payload length of less than 4 bytes,
2749 * we need to bail out here if the generic header is nonsensical
2750 * or truncated, otherwise we could loop forever processing
2751 * zero-length items or otherwise misdissect the packet.
2753 item_len
= ntohs(e
.len
);
2757 if(np
== ISAKMP_NPTYPE_P
) {
2758 cp
= ikev2_p_print(ndo
, np
, pcount
, ext
, item_len
,
2759 ep
, phase
, doi
, proto
, depth
);
2760 } else if(np
== ISAKMP_NPTYPE_T
) {
2761 cp
= ikev2_t_print(ndo
, np
, pcount
, ext
, item_len
,
2762 ep
, phase
, doi
, proto
, depth
);
2763 } else if(np
== ISAKMP_NPTYPE_v2E
) {
2764 cp
= ikev2_e_print(ndo
, base
, np
, ext
, item_len
,
2765 ep
, phase
, doi
, proto
, depth
);
2766 } else if (NPFUNC(np
)) {
2768 * XXX - what if item_len is too short, or too long,
2769 * for this payload type?
2771 cp
= (*npfunc
[np
])(ndo
, np
, /*pcount,*/ ext
, item_len
,
2772 ep
, phase
, doi
, proto
, depth
);
2774 ND_PRINT((ndo
,"%s", NPSTR(np
)));
2780 ND_PRINT((ndo
," [|isakmp]"));
2784 static const u_char
*
2785 ikev2_sub_print(netdissect_options
*ndo
,
2786 struct isakmp
*base
,
2787 u_char np
, const struct isakmp_gen
*ext
, const u_char
*ep
,
2788 u_int32_t phase
, u_int32_t doi
, u_int32_t proto
, int depth
)
2793 struct isakmp_gen e
;
2795 cp
= (const u_char
*)ext
;
2801 unaligned_memcpy(&e
, ext
, sizeof(e
));
2803 ND_TCHECK2(*ext
, ntohs(e
.len
));
2806 ND_PRINT((ndo
,"\n"));
2807 for (i
= 0; i
< depth
; i
++)
2808 ND_PRINT((ndo
," "));
2809 ND_PRINT((ndo
,"("));
2810 cp
= ikev2_sub0_print(ndo
, base
, np
, pcount
,
2811 ext
, ep
, phase
, doi
, proto
, depth
);
2812 ND_PRINT((ndo
,")"));
2816 /* Zero-length subitem */
2821 ext
= (struct isakmp_gen
*)cp
;
2825 ND_PRINT((ndo
," [|%s]", NPSTR(np
)));
2830 ikev2_print(netdissect_options
*ndo
,
2831 const u_char
*bp
, u_int length
,
2832 const u_char
*bp2 _U_
, struct isakmp
*base
)
2834 const struct isakmp
*p
;
2839 p
= (const struct isakmp
*)bp
;
2840 ep
= ndo
->ndo_snapend
;
2842 phase
= (EXTRACT_32BITS(base
->msgid
) == 0) ? 1 : 2;
2844 ND_PRINT((ndo
, " parent_sa"));
2846 ND_PRINT((ndo
, " child_sa "));
2848 ND_PRINT((ndo
, " %s", ETYPESTR(base
->etype
)));
2850 ND_PRINT((ndo
, "[%s%s%s]",
2851 base
->flags
& ISAKMP_FLAG_I
? "I" : "",
2852 base
->flags
& ISAKMP_FLAG_V
? "V" : "",
2853 base
->flags
& ISAKMP_FLAG_R
? "R" : ""));
2856 if (ndo
->ndo_vflag
) {
2857 const struct isakmp_gen
*ext
;
2859 ND_PRINT((ndo
, ":"));
2861 /* regardless of phase... */
2862 if (base
->flags
& ISAKMP_FLAG_E
) {
2864 * encrypted, nothing we can do right now.
2865 * we hope to decrypt the packet in the future...
2867 ND_PRINT((ndo
, " [encrypted %s]", NPSTR(base
->np
)));
2871 CHECKLEN(p
+ 1, base
->np
)
2874 ext
= (struct isakmp_gen
*)(p
+ 1);
2875 ikev2_sub_print(ndo
, base
, np
, ext
, ep
, phase
, 0, 0, 0);
2879 if (ndo
->ndo_vflag
) {
2880 if (ntohl(base
->len
) != length
) {
2881 ND_PRINT((ndo
, " (len mismatch: isakmp %u/ip %u)",
2882 (u_int32_t
)ntohl(base
->len
), length
));
2888 isakmp_print(netdissect_options
*ndo
,
2889 const u_char
*bp
, u_int length
,
2892 const struct isakmp
*p
;
2897 #ifdef HAVE_LIBCRYPTO
2898 /* initialize SAs */
2899 if (ndo
->ndo_sa_list_head
== NULL
) {
2900 if (ndo
->ndo_espsecret
)
2901 esp_print_decodesecret(ndo
);
2905 p
= (const struct isakmp
*)bp
;
2906 ep
= ndo
->ndo_snapend
;
2908 if ((struct isakmp
*)ep
< p
+ 1) {
2909 ND_PRINT((ndo
,"[|isakmp]"));
2913 unaligned_memcpy(&base
, p
, sizeof(base
));
2915 ND_PRINT((ndo
,"isakmp"));
2916 major
= (base
.vers
& ISAKMP_VERS_MAJOR
)
2917 >> ISAKMP_VERS_MAJOR_SHIFT
;
2918 minor
= (base
.vers
& ISAKMP_VERS_MINOR
)
2919 >> ISAKMP_VERS_MINOR_SHIFT
;
2921 if (ndo
->ndo_vflag
) {
2922 ND_PRINT((ndo
," %d.%d", major
, minor
));
2925 if (ndo
->ndo_vflag
) {
2926 ND_PRINT((ndo
," msgid "));
2927 hexprint(ndo
, (caddr_t
)&base
.msgid
, sizeof(base
.msgid
));
2930 if (1 < ndo
->ndo_vflag
) {
2931 ND_PRINT((ndo
," cookie "));
2932 hexprint(ndo
, (caddr_t
)&base
.i_ck
, sizeof(base
.i_ck
));
2933 ND_PRINT((ndo
,"->"));
2934 hexprint(ndo
, (caddr_t
)&base
.r_ck
, sizeof(base
.r_ck
));
2936 ND_PRINT((ndo
,":"));
2939 case IKEv1_MAJOR_VERSION
:
2940 ikev1_print(ndo
, bp
, length
, bp2
, &base
);
2943 case IKEv2_MAJOR_VERSION
:
2944 ikev2_print(ndo
, bp
, length
, bp2
, &base
);
2950 isakmp_rfc3948_print(netdissect_options
*ndo
,
2951 const u_char
*bp
, u_int length
,
2955 if(length
== 1 && bp
[0]==0xff) {
2956 ND_PRINT((ndo
, "isakmp-nat-keep-alive"));
2965 * see if this is an IKE packet
2967 if(bp
[0]==0 && bp
[1]==0 && bp
[2]==0 && bp
[3]==0) {
2968 ND_PRINT((ndo
, "NONESP-encap: "));
2969 isakmp_print(ndo
, bp
+4, length
-4, bp2
);
2973 /* must be an ESP packet */
2975 int nh
, enh
, padlen
;
2978 ND_PRINT((ndo
, "UDP-encap: "));
2980 advance
= esp_print(ndo
, bp
, length
, bp2
, &enh
, &padlen
);
2985 length
-= advance
+ padlen
;
2988 ip_print_inner(ndo
, bp
, length
, nh
, bp2
);
2993 ND_PRINT((ndo
,"[|isakmp]"));
2999 * c-style: whitesmith