xref: /dragonfly/contrib/tcpdump/print-isakmp.c (revision ed775ee7)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
341c99275SPeter Avalos  * All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that the following conditions
741c99275SPeter Avalos  * are met:
841c99275SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
941c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1041c99275SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1141c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1241c99275SPeter Avalos  *    documentation and/or other materials provided with the distribution.
1341c99275SPeter Avalos  * 3. Neither the name of the project nor the names of its contributors
1441c99275SPeter Avalos  *    may be used to endorse or promote products derived from this software
1541c99275SPeter Avalos  *    without specific prior written permission.
1641c99275SPeter Avalos  *
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1841c99275SPeter Avalos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1941c99275SPeter Avalos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2041c99275SPeter Avalos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2141c99275SPeter Avalos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2241c99275SPeter Avalos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2341c99275SPeter Avalos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2441c99275SPeter Avalos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2541c99275SPeter Avalos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2641c99275SPeter Avalos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2741c99275SPeter Avalos  * SUCH DAMAGE.
2841c99275SPeter Avalos  *
2941c99275SPeter Avalos  */
3041c99275SPeter Avalos 
31411677aeSAaron LI /* \summary: Internet Security Association and Key Management Protocol (ISAKMP) printer */
3241c99275SPeter Avalos 
33*ed775ee7SAntonio Huete Jimenez /* specification: RFC 2407, RFC 2408, RFC 5996 */
34*ed775ee7SAntonio Huete Jimenez 
3541c99275SPeter Avalos #ifdef HAVE_CONFIG_H
36*ed775ee7SAntonio Huete Jimenez #include <config.h>
3741c99275SPeter Avalos #endif
3841c99275SPeter Avalos 
39411677aeSAaron LI /* The functions from print-esp.c used in this file are only defined when both
40411677aeSAaron LI  * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
41411677aeSAaron LI  */
42411677aeSAaron LI #ifndef HAVE_OPENSSL_EVP_H
43411677aeSAaron LI #undef HAVE_LIBCRYPTO
44411677aeSAaron LI #endif
45411677aeSAaron LI 
46*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4741c99275SPeter Avalos 
4841c99275SPeter Avalos #include <string.h>
4941c99275SPeter Avalos 
50*ed775ee7SAntonio Huete Jimenez #include "netdissect-ctype.h"
51*ed775ee7SAntonio Huete Jimenez 
52411677aeSAaron LI #include "netdissect.h"
5341c99275SPeter Avalos #include "addrtoname.h"
54411677aeSAaron LI #include "extract.h"
5541c99275SPeter Avalos 
5641c99275SPeter Avalos #include "ip.h"
5741c99275SPeter Avalos #include "ip6.h"
58411677aeSAaron LI #include "ipproto.h"
59411677aeSAaron LI 
60*ed775ee7SAntonio Huete Jimenez typedef nd_byte cookie_t[8];
61*ed775ee7SAntonio Huete Jimenez typedef nd_byte msgid_t[4];
62411677aeSAaron LI 
63411677aeSAaron LI #define PORT_ISAKMP 500
64411677aeSAaron LI 
65411677aeSAaron LI /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
66411677aeSAaron LI          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
67411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68411677aeSAaron LI         !                          Initiator                            !
69411677aeSAaron LI         !                            Cookie                             !
70411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71411677aeSAaron LI         !                          Responder                            !
72411677aeSAaron LI         !                            Cookie                             !
73411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74411677aeSAaron LI         !  Next Payload ! MjVer ! MnVer ! Exchange Type !     Flags     !
75411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76411677aeSAaron LI         !                          Message ID                           !
77411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78411677aeSAaron LI         !                            Length                             !
79411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80411677aeSAaron LI */
81411677aeSAaron LI struct isakmp {
82411677aeSAaron LI 	cookie_t i_ck;		/* Initiator Cookie */
83411677aeSAaron LI 	cookie_t r_ck;		/* Responder Cookie */
84*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t np;		/* Next Payload Type */
85*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t vers;
86411677aeSAaron LI #define ISAKMP_VERS_MAJOR	0xf0
87411677aeSAaron LI #define ISAKMP_VERS_MAJOR_SHIFT	4
88411677aeSAaron LI #define ISAKMP_VERS_MINOR	0x0f
89411677aeSAaron LI #define ISAKMP_VERS_MINOR_SHIFT	0
90*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t etype;	/* Exchange Type */
91*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t flags;	/* Flags */
92411677aeSAaron LI 	msgid_t msgid;
93*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t len;	/* Length */
94411677aeSAaron LI };
95411677aeSAaron LI 
96411677aeSAaron LI /* Next Payload Type */
97411677aeSAaron LI #define ISAKMP_NPTYPE_NONE   0 /* NONE*/
98411677aeSAaron LI #define ISAKMP_NPTYPE_SA     1 /* Security Association */
99411677aeSAaron LI #define ISAKMP_NPTYPE_P      2 /* Proposal */
100411677aeSAaron LI #define ISAKMP_NPTYPE_T      3 /* Transform */
101411677aeSAaron LI #define ISAKMP_NPTYPE_KE     4 /* Key Exchange */
102411677aeSAaron LI #define ISAKMP_NPTYPE_ID     5 /* Identification */
103411677aeSAaron LI #define ISAKMP_NPTYPE_CERT   6 /* Certificate */
104411677aeSAaron LI #define ISAKMP_NPTYPE_CR     7 /* Certificate Request */
105411677aeSAaron LI #define ISAKMP_NPTYPE_HASH   8 /* Hash */
106411677aeSAaron LI #define ISAKMP_NPTYPE_SIG    9 /* Signature */
107411677aeSAaron LI #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
108411677aeSAaron LI #define ISAKMP_NPTYPE_N     11 /* Notification */
109411677aeSAaron LI #define ISAKMP_NPTYPE_D     12 /* Delete */
110411677aeSAaron LI #define ISAKMP_NPTYPE_VID   13 /* Vendor ID */
111411677aeSAaron LI #define ISAKMP_NPTYPE_v2E   46 /* v2 Encrypted payload */
112411677aeSAaron LI 
113411677aeSAaron LI #define IKEv1_MAJOR_VERSION  1
114411677aeSAaron LI #define IKEv1_MINOR_VERSION  0
115411677aeSAaron LI 
116411677aeSAaron LI #define IKEv2_MAJOR_VERSION  2
117411677aeSAaron LI #define IKEv2_MINOR_VERSION  0
118411677aeSAaron LI 
119411677aeSAaron LI /* Flags */
120411677aeSAaron LI #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
121411677aeSAaron LI #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
122411677aeSAaron LI #define ISAKMP_FLAG_extra 0x04
123411677aeSAaron LI 
124411677aeSAaron LI /* IKEv2 */
125411677aeSAaron LI #define ISAKMP_FLAG_I (1 << 3)  /* (I)nitiator */
126411677aeSAaron LI #define ISAKMP_FLAG_V (1 << 4)  /* (V)ersion   */
127411677aeSAaron LI #define ISAKMP_FLAG_R (1 << 5)  /* (R)esponse  */
128411677aeSAaron LI 
129411677aeSAaron LI 
130411677aeSAaron LI /* 3.2 Payload Generic Header
131411677aeSAaron LI          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
132411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133411677aeSAaron LI         ! Next Payload  !   RESERVED    !         Payload Length        !
134411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135411677aeSAaron LI */
136411677aeSAaron LI struct isakmp_gen {
137*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  np;       /* Next Payload */
138*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  critical; /* bit 7 - critical, rest is RESERVED */
139*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t len;      /* Payload Length */
140411677aeSAaron LI };
141411677aeSAaron LI 
142411677aeSAaron LI /* 3.3 Data Attributes
143411677aeSAaron LI          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
144411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145411677aeSAaron LI         !A!       Attribute Type        !    AF=0  Attribute Length     !
146411677aeSAaron LI         !F!                             !    AF=1  Attribute Value      !
147411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148411677aeSAaron LI         .                   AF=0  Attribute Value                       .
149411677aeSAaron LI         .                   AF=1  Not Transmitted                       .
150411677aeSAaron LI         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151411677aeSAaron LI */
152411677aeSAaron LI struct isakmp_data {
153*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t type;     /* defined by DOI-spec, and Attribute Format */
154*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t lorv;     /* if f equal 1, Attribute Length */
155411677aeSAaron LI 	                      /* if f equal 0, Attribute Value */
156411677aeSAaron LI 	/* if f equal 1, Attribute Value */
157411677aeSAaron LI };
158411677aeSAaron LI 
159411677aeSAaron LI /* 3.4 Security Association Payload */
160411677aeSAaron LI 	/* MAY NOT be used, because of being defined in ipsec-doi. */
161411677aeSAaron LI 	/*
162411677aeSAaron LI 	If the current payload is the last in the message,
163411677aeSAaron LI 	then the value of the next payload field will be 0.
164411677aeSAaron LI 	This field MUST NOT contain the
165411677aeSAaron LI 	values for the Proposal or Transform payloads as they are considered
166411677aeSAaron LI 	part of the security association negotiation.  For example, this
167411677aeSAaron LI 	field would contain the value "10" (Nonce payload) in the first
168411677aeSAaron LI 	message of a Base Exchange (see Section 4.4) and the value "0" in the
169411677aeSAaron LI 	first message of an Identity Protect Exchange (see Section 4.5).
170411677aeSAaron LI 	*/
171411677aeSAaron LI struct ikev1_pl_sa {
172411677aeSAaron LI 	struct isakmp_gen h;
173*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t doi; /* Domain of Interpretation */
174*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t sit; /* Situation */
175411677aeSAaron LI };
176411677aeSAaron LI 
177411677aeSAaron LI /* 3.5 Proposal Payload */
178411677aeSAaron LI 	/*
179411677aeSAaron LI 	The value of the next payload field MUST only contain the value "2"
180411677aeSAaron LI 	or "0".  If there are additional Proposal payloads in the message,
181411677aeSAaron LI 	then this field will be 2.  If the current Proposal payload is the
182411677aeSAaron LI 	last within the security association proposal, then this field will
183411677aeSAaron LI 	be 0.
184411677aeSAaron LI 	*/
185411677aeSAaron LI struct ikev1_pl_p {
186411677aeSAaron LI 	struct isakmp_gen h;
187*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t p_no;      /* Proposal # */
188*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t prot_id;   /* Protocol */
189*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t spi_size;  /* SPI Size */
190*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t num_t;     /* Number of Transforms */
191411677aeSAaron LI 	/* SPI */
192411677aeSAaron LI };
193411677aeSAaron LI 
194411677aeSAaron LI /* 3.6 Transform Payload */
195411677aeSAaron LI 	/*
196411677aeSAaron LI 	The value of the next payload field MUST only contain the value "3"
197411677aeSAaron LI 	or "0".  If there are additional Transform payloads in the proposal,
198411677aeSAaron LI 	then this field will be 3.  If the current Transform payload is the
199411677aeSAaron LI 	last within the proposal, then this field will be 0.
200411677aeSAaron LI 	*/
201411677aeSAaron LI struct ikev1_pl_t {
202411677aeSAaron LI 	struct isakmp_gen h;
203*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  t_no;        /* Transform # */
204*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  t_id;        /* Transform-Id */
205*ed775ee7SAntonio Huete Jimenez 	nd_byte     reserved[2]; /* RESERVED2 */
206411677aeSAaron LI 	/* SA Attributes */
207411677aeSAaron LI };
208411677aeSAaron LI 
209411677aeSAaron LI /* 3.7 Key Exchange Payload */
210411677aeSAaron LI struct ikev1_pl_ke {
211411677aeSAaron LI 	struct isakmp_gen h;
212411677aeSAaron LI 	/* Key Exchange Data */
213411677aeSAaron LI };
214411677aeSAaron LI 
215411677aeSAaron LI /* 3.8 Identification Payload */
216411677aeSAaron LI 	/* MUST NOT to be used, because of being defined in ipsec-doi. */
217411677aeSAaron LI struct ikev1_pl_id {
218411677aeSAaron LI 	struct isakmp_gen h;
219411677aeSAaron LI 	union {
220*ed775ee7SAntonio Huete Jimenez 		nd_uint8_t  id_type;   /* ID Type */
221*ed775ee7SAntonio Huete Jimenez 		nd_uint32_t doi_data;  /* DOI Specific ID Data */
222411677aeSAaron LI 	} d;
223411677aeSAaron LI 	/* Identification Data */
224411677aeSAaron LI };
225411677aeSAaron LI 
226411677aeSAaron LI /* 3.9 Certificate Payload */
227411677aeSAaron LI struct ikev1_pl_cert {
228411677aeSAaron LI 	struct isakmp_gen h;
229*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t encode; /* Cert Encoding */
230*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t cert;   /* Certificate Data */
231411677aeSAaron LI 		/*
232411677aeSAaron LI 		This field indicates the type of
233411677aeSAaron LI 		certificate or certificate-related information contained in the
234411677aeSAaron LI 		Certificate Data field.
235411677aeSAaron LI 		*/
236411677aeSAaron LI };
237411677aeSAaron LI 
238411677aeSAaron LI /* 3.10 Certificate Request Payload */
239411677aeSAaron LI struct ikev1_pl_cr {
240411677aeSAaron LI 	struct isakmp_gen h;
241*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t num_cert; /* # Cert. Types */
242411677aeSAaron LI 	/*
243411677aeSAaron LI 	Certificate Types (variable length)
244411677aeSAaron LI 	  -- Contains a list of the types of certificates requested,
245411677aeSAaron LI 	  sorted in order of preference.  Each individual certificate
246411677aeSAaron LI 	  type is 1 octet.  This field is NOT requiredo
247411677aeSAaron LI 	*/
248411677aeSAaron LI 	/* # Certificate Authorities (1 octet) */
249411677aeSAaron LI 	/* Certificate Authorities (variable length) */
250411677aeSAaron LI };
251411677aeSAaron LI 
252411677aeSAaron LI /* 3.11 Hash Payload */
253411677aeSAaron LI 	/* may not be used, because of having only data. */
254411677aeSAaron LI struct ikev1_pl_hash {
255411677aeSAaron LI 	struct isakmp_gen h;
256411677aeSAaron LI 	/* Hash Data */
257411677aeSAaron LI };
258411677aeSAaron LI 
259411677aeSAaron LI /* 3.12 Signature Payload */
260411677aeSAaron LI 	/* may not be used, because of having only data. */
261411677aeSAaron LI struct ikev1_pl_sig {
262411677aeSAaron LI 	struct isakmp_gen h;
263411677aeSAaron LI 	/* Signature Data */
264411677aeSAaron LI };
265411677aeSAaron LI 
266411677aeSAaron LI /* 3.13 Nonce Payload */
267411677aeSAaron LI 	/* may not be used, because of having only data. */
268411677aeSAaron LI struct ikev1_pl_nonce {
269411677aeSAaron LI 	struct isakmp_gen h;
270411677aeSAaron LI 	/* Nonce Data */
271411677aeSAaron LI };
272411677aeSAaron LI 
273411677aeSAaron LI /* 3.14 Notification Payload */
274411677aeSAaron LI struct ikev1_pl_n {
275411677aeSAaron LI 	struct isakmp_gen h;
276*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t doi;      /* Domain of Interpretation */
277*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  prot_id;  /* Protocol-ID */
278*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  spi_size; /* SPI Size */
279*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t type;     /* Notify Message Type */
280411677aeSAaron LI 	/* SPI */
281411677aeSAaron LI 	/* Notification Data */
282411677aeSAaron LI };
283411677aeSAaron LI 
284411677aeSAaron LI /* 3.14.1 Notify Message Types */
285411677aeSAaron LI /* NOTIFY MESSAGES - ERROR TYPES */
286411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE           1
287411677aeSAaron LI #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED              2
288411677aeSAaron LI #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED        3
289411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_COOKIE                 4
290411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION          5
291411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_MINOR_VERSION          6
292411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE          7
293411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_FLAGS                  8
294411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_MESSAGE_ID             9
295411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID            10
296411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_SPI                    11
297411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID           12
298411677aeSAaron LI #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED       13
299411677aeSAaron LI #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN             14
300411677aeSAaron LI #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX            15
301411677aeSAaron LI #define ISAKMP_NTYPE_PAYLOAD_MALFORMED              16
302411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION        17
303411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_ID_INFORMATION         18
304411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_CERT_ENCODING          19
305411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_CERTIFICATE            20
306411677aeSAaron LI #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX        21
307411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY         22
308411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION       23
309411677aeSAaron LI #define ISAKMP_NTYPE_AUTHENTICATION_FAILED          24
310411677aeSAaron LI #define ISAKMP_NTYPE_INVALID_SIGNATURE              25
311411677aeSAaron LI #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION           26
312411677aeSAaron LI 
313411677aeSAaron LI /* 3.15 Delete Payload */
314411677aeSAaron LI struct ikev1_pl_d {
315411677aeSAaron LI 	struct isakmp_gen h;
316*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t doi;      /* Domain of Interpretation */
317*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  prot_id;  /* Protocol-Id */
318*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  spi_size; /* SPI Size */
319*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t num_spi;  /* # of SPIs */
320411677aeSAaron LI 	/* SPI(es) */
321411677aeSAaron LI };
322411677aeSAaron LI 
323411677aeSAaron LI /* IKEv2 (RFC4306) */
324411677aeSAaron LI 
325411677aeSAaron LI /* 3.3  Security Association Payload -- generic header */
326411677aeSAaron LI /* 3.3.1.  Proposal Substructure */
327411677aeSAaron LI struct ikev2_p {
328411677aeSAaron LI 	struct isakmp_gen h;
329*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t p_no;      /* Proposal # */
330*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t prot_id;   /* Protocol */
331*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t spi_size;  /* SPI Size */
332*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t num_t;     /* Number of Transforms */
333411677aeSAaron LI };
334411677aeSAaron LI 
335411677aeSAaron LI /* 3.3.2.  Transform Substructure */
336411677aeSAaron LI struct ikev2_t {
337411677aeSAaron LI 	struct isakmp_gen h;
338*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  t_type;    /* Transform Type (ENCR,PRF,INTEG,etc.*/
339*ed775ee7SAntonio Huete Jimenez 	nd_byte     res2;      /* reserved byte */
340*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t t_id;     /* Transform ID */
341411677aeSAaron LI };
342411677aeSAaron LI 
343411677aeSAaron LI enum ikev2_t_type {
344411677aeSAaron LI 	IV2_T_ENCR = 1,
345411677aeSAaron LI 	IV2_T_PRF  = 2,
346411677aeSAaron LI 	IV2_T_INTEG= 3,
347411677aeSAaron LI 	IV2_T_DH   = 4,
348411677aeSAaron LI 	IV2_T_ESN  = 5
349411677aeSAaron LI };
350411677aeSAaron LI 
351411677aeSAaron LI /* 3.4.  Key Exchange Payload */
352411677aeSAaron LI struct ikev2_ke {
353411677aeSAaron LI 	struct isakmp_gen h;
354*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t  ke_group;
355*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t  ke_res1;
356411677aeSAaron LI 	/* KE data */
357411677aeSAaron LI };
358411677aeSAaron LI 
359411677aeSAaron LI 
360411677aeSAaron LI /* 3.5.  Identification Payloads */
361411677aeSAaron LI enum ikev2_id_type {
362411677aeSAaron LI 	ID_IPV4_ADDR=1,
363411677aeSAaron LI 	ID_FQDN=2,
364411677aeSAaron LI 	ID_RFC822_ADDR=3,
365411677aeSAaron LI 	ID_IPV6_ADDR=5,
366411677aeSAaron LI 	ID_DER_ASN1_DN=9,
367411677aeSAaron LI 	ID_DER_ASN1_GN=10,
368411677aeSAaron LI 	ID_KEY_ID=11
369411677aeSAaron LI };
370411677aeSAaron LI struct ikev2_id {
371411677aeSAaron LI 	struct isakmp_gen h;
372*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t type;        /* ID type */
373*ed775ee7SAntonio Huete Jimenez 	nd_byte    res1;
374*ed775ee7SAntonio Huete Jimenez 	nd_byte    res2[2];
375411677aeSAaron LI 	/* SPI */
376411677aeSAaron LI 	/* Notification Data */
377411677aeSAaron LI };
378411677aeSAaron LI 
379411677aeSAaron LI /* 3.10 Notification Payload */
380411677aeSAaron LI struct ikev2_n {
381411677aeSAaron LI 	struct isakmp_gen h;
382*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  prot_id;  /* Protocol-ID */
383*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  spi_size; /* SPI Size */
384*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t type;     /* Notify Message Type */
385411677aeSAaron LI };
386411677aeSAaron LI 
387411677aeSAaron LI enum ikev2_n_type {
388411677aeSAaron LI 	IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD            = 1,
389411677aeSAaron LI 	IV2_NOTIFY_INVALID_IKE_SPI                         = 4,
390411677aeSAaron LI 	IV2_NOTIFY_INVALID_MAJOR_VERSION                   = 5,
391411677aeSAaron LI 	IV2_NOTIFY_INVALID_SYNTAX                          = 7,
392411677aeSAaron LI 	IV2_NOTIFY_INVALID_MESSAGE_ID                      = 9,
393411677aeSAaron LI 	IV2_NOTIFY_INVALID_SPI                             =11,
394411677aeSAaron LI 	IV2_NOTIFY_NO_PROPOSAL_CHOSEN                      =14,
395411677aeSAaron LI 	IV2_NOTIFY_INVALID_KE_PAYLOAD                      =17,
396411677aeSAaron LI 	IV2_NOTIFY_AUTHENTICATION_FAILED                   =24,
397411677aeSAaron LI 	IV2_NOTIFY_SINGLE_PAIR_REQUIRED                    =34,
398411677aeSAaron LI 	IV2_NOTIFY_NO_ADDITIONAL_SAS                       =35,
399411677aeSAaron LI 	IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE                =36,
400411677aeSAaron LI 	IV2_NOTIFY_FAILED_CP_REQUIRED                      =37,
401411677aeSAaron LI 	IV2_NOTIFY_INVALID_SELECTORS                       =39,
402411677aeSAaron LI 	IV2_NOTIFY_INITIAL_CONTACT                         =16384,
403411677aeSAaron LI 	IV2_NOTIFY_SET_WINDOW_SIZE                         =16385,
404411677aeSAaron LI 	IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE                  =16386,
405411677aeSAaron LI 	IV2_NOTIFY_IPCOMP_SUPPORTED                        =16387,
406411677aeSAaron LI 	IV2_NOTIFY_NAT_DETECTION_SOURCE_IP                 =16388,
407411677aeSAaron LI 	IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP            =16389,
408411677aeSAaron LI 	IV2_NOTIFY_COOKIE                                  =16390,
409411677aeSAaron LI 	IV2_NOTIFY_USE_TRANSPORT_MODE                      =16391,
410411677aeSAaron LI 	IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED              =16392,
411411677aeSAaron LI 	IV2_NOTIFY_REKEY_SA                                =16393,
412411677aeSAaron LI 	IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED           =16394,
413411677aeSAaron LI 	IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO                =16395
414411677aeSAaron LI };
415411677aeSAaron LI 
416411677aeSAaron LI struct notify_messages {
417411677aeSAaron LI 	uint16_t type;
418411677aeSAaron LI 	char     *msg;
419411677aeSAaron LI };
420411677aeSAaron LI 
421411677aeSAaron LI /* 3.8 Authentication Payload */
422411677aeSAaron LI struct ikev2_auth {
423411677aeSAaron LI 	struct isakmp_gen h;
424*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  auth_method;  /* Protocol-ID */
425*ed775ee7SAntonio Huete Jimenez 	nd_byte     reserved[3];
426411677aeSAaron LI 	/* authentication data */
427411677aeSAaron LI };
428411677aeSAaron LI 
429411677aeSAaron LI enum ikev2_auth_type {
430411677aeSAaron LI 	IV2_RSA_SIG = 1,
431411677aeSAaron LI 	IV2_SHARED  = 2,
432411677aeSAaron LI 	IV2_DSS_SIG = 3
433411677aeSAaron LI };
434411677aeSAaron LI 
435411677aeSAaron LI /* refer to RFC 2409 */
436411677aeSAaron LI 
437411677aeSAaron LI #if 0
438411677aeSAaron LI /* isakmp sa structure */
439411677aeSAaron LI struct oakley_sa {
440411677aeSAaron LI 	uint8_t  proto_id;            /* OAKLEY */
441411677aeSAaron LI 	vchar_t   *spi;                /* spi */
442411677aeSAaron LI 	uint8_t  dhgrp;               /* DH; group */
443411677aeSAaron LI 	uint8_t  auth_t;              /* method of authentication */
444411677aeSAaron LI 	uint8_t  prf_t;               /* type of prf */
445411677aeSAaron LI 	uint8_t  hash_t;              /* type of hash */
446411677aeSAaron LI 	uint8_t  enc_t;               /* type of cipher */
447411677aeSAaron LI 	uint8_t  life_t;              /* type of duration of lifetime */
448411677aeSAaron LI 	uint32_t ldur;                /* life duration */
449411677aeSAaron LI };
45041c99275SPeter Avalos #endif
45141c99275SPeter Avalos 
452411677aeSAaron LI /* refer to RFC 2407 */
453411677aeSAaron LI 
454411677aeSAaron LI #define IPSEC_DOI 1
455411677aeSAaron LI 
456411677aeSAaron LI /* 4.2 IPSEC Situation Definition */
457411677aeSAaron LI #define IPSECDOI_SIT_IDENTITY_ONLY           0x00000001
458411677aeSAaron LI #define IPSECDOI_SIT_SECRECY                 0x00000002
459411677aeSAaron LI #define IPSECDOI_SIT_INTEGRITY               0x00000004
460411677aeSAaron LI 
461411677aeSAaron LI /* 4.4.1 IPSEC Security Protocol Identifiers */
462411677aeSAaron LI   /* 4.4.2 IPSEC ISAKMP Transform Values */
463411677aeSAaron LI #define IPSECDOI_PROTO_ISAKMP                        1
464411677aeSAaron LI #define   IPSECDOI_KEY_IKE                             1
465411677aeSAaron LI 
466411677aeSAaron LI /* 4.4.1 IPSEC Security Protocol Identifiers */
467411677aeSAaron LI #define IPSECDOI_PROTO_IPSEC_AH                      2
468411677aeSAaron LI   /* 4.4.3 IPSEC AH Transform Values */
469411677aeSAaron LI #define   IPSECDOI_AH_MD5                              2
470411677aeSAaron LI #define   IPSECDOI_AH_SHA                              3
471411677aeSAaron LI #define   IPSECDOI_AH_DES                              4
472411677aeSAaron LI #define   IPSECDOI_AH_SHA2_256                         5
473411677aeSAaron LI #define   IPSECDOI_AH_SHA2_384                         6
474411677aeSAaron LI #define   IPSECDOI_AH_SHA2_512                         7
475411677aeSAaron LI 
476411677aeSAaron LI /* 4.4.1 IPSEC Security Protocol Identifiers */
477411677aeSAaron LI #define IPSECDOI_PROTO_IPSEC_ESP                     3
478411677aeSAaron LI   /* 4.4.4 IPSEC ESP Transform Identifiers */
479411677aeSAaron LI #define   IPSECDOI_ESP_DES_IV64                        1
480411677aeSAaron LI #define   IPSECDOI_ESP_DES                             2
481411677aeSAaron LI #define   IPSECDOI_ESP_3DES                            3
482411677aeSAaron LI #define   IPSECDOI_ESP_RC5                             4
483411677aeSAaron LI #define   IPSECDOI_ESP_IDEA                            5
484411677aeSAaron LI #define   IPSECDOI_ESP_CAST                            6
485411677aeSAaron LI #define   IPSECDOI_ESP_BLOWFISH                        7
486411677aeSAaron LI #define   IPSECDOI_ESP_3IDEA                           8
487411677aeSAaron LI #define   IPSECDOI_ESP_DES_IV32                        9
488411677aeSAaron LI #define   IPSECDOI_ESP_RC4                            10
489411677aeSAaron LI #define   IPSECDOI_ESP_NULL                           11
490411677aeSAaron LI #define   IPSECDOI_ESP_RIJNDAEL				12
491411677aeSAaron LI #define   IPSECDOI_ESP_AES				12
492411677aeSAaron LI 
493411677aeSAaron LI /* 4.4.1 IPSEC Security Protocol Identifiers */
494411677aeSAaron LI #define IPSECDOI_PROTO_IPCOMP                        4
495411677aeSAaron LI   /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
496411677aeSAaron LI #define   IPSECDOI_IPCOMP_OUI                          1
497411677aeSAaron LI #define   IPSECDOI_IPCOMP_DEFLATE                      2
498411677aeSAaron LI #define   IPSECDOI_IPCOMP_LZS                          3
499411677aeSAaron LI 
500411677aeSAaron LI /* 4.5 IPSEC Security Association Attributes */
501411677aeSAaron LI #define IPSECDOI_ATTR_SA_LTYPE                1 /* B */
502411677aeSAaron LI #define   IPSECDOI_ATTR_SA_LTYPE_DEFAULT        1
503411677aeSAaron LI #define   IPSECDOI_ATTR_SA_LTYPE_SEC            1
504411677aeSAaron LI #define   IPSECDOI_ATTR_SA_LTYPE_KB             2
505411677aeSAaron LI #define IPSECDOI_ATTR_SA_LDUR                 2 /* V */
506411677aeSAaron LI #define   IPSECDOI_ATTR_SA_LDUR_DEFAULT         28800 /* 8 hours */
507411677aeSAaron LI #define IPSECDOI_ATTR_GRP_DESC                3 /* B */
508411677aeSAaron LI #define IPSECDOI_ATTR_ENC_MODE                4 /* B */
509411677aeSAaron LI 	/* default value: host dependent */
510411677aeSAaron LI #define   IPSECDOI_ATTR_ENC_MODE_TUNNEL         1
511411677aeSAaron LI #define   IPSECDOI_ATTR_ENC_MODE_TRNS           2
512411677aeSAaron LI #define IPSECDOI_ATTR_AUTH                    5 /* B */
513411677aeSAaron LI 	/* 0 means not to use authentication. */
514411677aeSAaron LI #define   IPSECDOI_ATTR_AUTH_HMAC_MD5           1
515411677aeSAaron LI #define   IPSECDOI_ATTR_AUTH_HMAC_SHA1          2
516411677aeSAaron LI #define   IPSECDOI_ATTR_AUTH_DES_MAC            3
517411677aeSAaron LI #define   IPSECDOI_ATTR_AUTH_KPDK               4 /*RFC-1826(Key/Pad/Data/Key)*/
518411677aeSAaron LI 	/*
519411677aeSAaron LI 	 * When negotiating ESP without authentication, the Auth
520411677aeSAaron LI 	 * Algorithm attribute MUST NOT be included in the proposal.
521411677aeSAaron LI 	 * When negotiating ESP without confidentiality, the Auth
522411677aeSAaron LI 	 * Algorithm attribute MUST be included in the proposal and
523411677aeSAaron LI 	 * the ESP transform ID must be ESP_NULL.
524411677aeSAaron LI 	*/
525411677aeSAaron LI #define IPSECDOI_ATTR_KEY_LENGTH              6 /* B */
526411677aeSAaron LI #define IPSECDOI_ATTR_KEY_ROUNDS              7 /* B */
527411677aeSAaron LI #define IPSECDOI_ATTR_COMP_DICT_SIZE          8 /* B */
528411677aeSAaron LI #define IPSECDOI_ATTR_COMP_PRIVALG            9 /* V */
529411677aeSAaron LI 
530411677aeSAaron LI /* 4.6.1 Security Association Payload */
531411677aeSAaron LI struct ipsecdoi_sa {
532411677aeSAaron LI 	struct isakmp_gen h;
533*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t doi; /* Domain of Interpretation */
534*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t sit; /* Situation */
535411677aeSAaron LI };
536411677aeSAaron LI 
537411677aeSAaron LI struct ipsecdoi_secrecy_h {
538*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t len;
539*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t reserved;
540411677aeSAaron LI };
541411677aeSAaron LI 
542411677aeSAaron LI /* 4.6.2.1 Identification Type Values */
543411677aeSAaron LI struct ipsecdoi_id {
544411677aeSAaron LI 	struct isakmp_gen h;
545*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  type;	/* ID Type */
546*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t  proto_id;	/* Protocol ID */
547*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t port;	/* Port */
548411677aeSAaron LI 	/* Identification Data */
549411677aeSAaron LI };
550411677aeSAaron LI 
551411677aeSAaron LI #define IPSECDOI_ID_IPV4_ADDR                        1
552411677aeSAaron LI #define IPSECDOI_ID_FQDN                             2
553411677aeSAaron LI #define IPSECDOI_ID_USER_FQDN                        3
554411677aeSAaron LI #define IPSECDOI_ID_IPV4_ADDR_SUBNET                 4
555411677aeSAaron LI #define IPSECDOI_ID_IPV6_ADDR                        5
556411677aeSAaron LI #define IPSECDOI_ID_IPV6_ADDR_SUBNET                 6
557411677aeSAaron LI #define IPSECDOI_ID_IPV4_ADDR_RANGE                  7
558411677aeSAaron LI #define IPSECDOI_ID_IPV6_ADDR_RANGE                  8
559411677aeSAaron LI #define IPSECDOI_ID_DER_ASN1_DN                      9
560411677aeSAaron LI #define IPSECDOI_ID_DER_ASN1_GN                      10
561411677aeSAaron LI #define IPSECDOI_ID_KEY_ID                           11
562411677aeSAaron LI 
563411677aeSAaron LI /* 4.6.3 IPSEC DOI Notify Message Types */
564411677aeSAaron LI /* Notify Messages - Status Types */
565411677aeSAaron LI #define IPSECDOI_NTYPE_RESPONDER_LIFETIME                  24576
566411677aeSAaron LI #define IPSECDOI_NTYPE_REPLAY_STATUS                       24577
567411677aeSAaron LI #define IPSECDOI_NTYPE_INITIAL_CONTACT                     24578
56841c99275SPeter Avalos 
569ea7b4bf5SPeter Avalos #define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
570ea7b4bf5SPeter Avalos 		netdissect_options *ndo, u_char tpay,	              \
571ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,			      \
572ea7b4bf5SPeter Avalos 		u_int item_len, \
573ea7b4bf5SPeter Avalos 		const u_char *end_pointer, \
574411677aeSAaron LI 		uint32_t phase,\
575411677aeSAaron LI 		uint32_t doi0, \
576411677aeSAaron LI 		uint32_t proto0, int depth)
577ea7b4bf5SPeter Avalos 
578ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_sa);
579ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_p);
580ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_t);
581ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_ke);
582ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_id);
583ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_cert);
584ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_cr);
585ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_sig);
586ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_hash);
587ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_nonce);
588ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_n);
589ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_d);
590ea7b4bf5SPeter Avalos DECLARE_PRINTER(v1_vid);
591ea7b4bf5SPeter Avalos 
592ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_sa);
593ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_ke);
594ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_ID);
595ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_cert);
596ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_cr);
597ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_auth);
598ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_nonce);
599ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_n);
600ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_d);
601ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_vid);
602ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_TS);
603ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_cp);
604ea7b4bf5SPeter Avalos DECLARE_PRINTER(v2_eap);
605ea7b4bf5SPeter Avalos 
60627bfbee1SPeter Avalos static const u_char *ikev2_e_print(netdissect_options *ndo,
607*ed775ee7SAntonio Huete Jimenez 				   const struct isakmp *base,
60827bfbee1SPeter Avalos 				   u_char tpay,
60927bfbee1SPeter Avalos 				   const struct isakmp_gen *ext,
61027bfbee1SPeter Avalos 				   u_int item_len,
61127bfbee1SPeter Avalos 				   const u_char *end_pointer,
612411677aeSAaron LI 				   uint32_t phase,
613411677aeSAaron LI 				   uint32_t doi0,
614411677aeSAaron LI 				   uint32_t proto0, int depth);
61527bfbee1SPeter Avalos 
61627bfbee1SPeter Avalos 
617ea7b4bf5SPeter Avalos static const u_char *ike_sub0_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
618411677aeSAaron LI 	const u_char *,	uint32_t, uint32_t, uint32_t, int);
619ea7b4bf5SPeter Avalos static const u_char *ikev1_sub_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
620411677aeSAaron LI 	const u_char *, uint32_t, uint32_t, uint32_t, int);
621ea7b4bf5SPeter Avalos 
622ea7b4bf5SPeter Avalos static const u_char *ikev2_sub_print(netdissect_options *ndo,
623*ed775ee7SAntonio Huete Jimenez 				     const struct isakmp *base,
624ea7b4bf5SPeter Avalos 				     u_char np, const struct isakmp_gen *ext,
625411677aeSAaron LI 				     const u_char *ep, uint32_t phase,
626411677aeSAaron LI 				     uint32_t doi, uint32_t proto,
627ea7b4bf5SPeter Avalos 				     int depth);
628ea7b4bf5SPeter Avalos 
629ea7b4bf5SPeter Avalos 
630*ed775ee7SAntonio Huete Jimenez static char *numstr(u_int);
63141c99275SPeter Avalos 
632ea7b4bf5SPeter Avalos static void
633ea7b4bf5SPeter Avalos ikev1_print(netdissect_options *ndo,
634ea7b4bf5SPeter Avalos 	    const u_char *bp,  u_int length,
635*ed775ee7SAntonio Huete Jimenez 	    const u_char *bp2, const struct isakmp *base);
636ea7b4bf5SPeter Avalos 
63741c99275SPeter Avalos #define MAXINITIATORS	20
638411677aeSAaron LI static int ninitiator = 0;
639411677aeSAaron LI union inaddr_u {
640*ed775ee7SAntonio Huete Jimenez 	nd_ipv4 in4;
641*ed775ee7SAntonio Huete Jimenez 	nd_ipv6 in6;
642411677aeSAaron LI };
643411677aeSAaron LI static struct {
64441c99275SPeter Avalos 	cookie_t initiator;
645411677aeSAaron LI 	u_int version;
646411677aeSAaron LI 	union inaddr_u iaddr;
647411677aeSAaron LI 	union inaddr_u raddr;
64841c99275SPeter Avalos } cookiecache[MAXINITIATORS];
64941c99275SPeter Avalos 
65041c99275SPeter Avalos /* protocol id */
65141c99275SPeter Avalos static const char *protoidstr[] = {
65241c99275SPeter Avalos 	NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
65341c99275SPeter Avalos };
65441c99275SPeter Avalos 
65541c99275SPeter Avalos /* isakmp->np */
65641c99275SPeter Avalos static const char *npstr[] = {
657ea7b4bf5SPeter Avalos 	"none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
658ea7b4bf5SPeter Avalos 	"sig", "nonce", "n", "d", "vid",      /* 9 - 13 */
659ea7b4bf5SPeter Avalos 	"pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
660ea7b4bf5SPeter Avalos 	"pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
661ea7b4bf5SPeter Avalos 	"pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
662ea7b4bf5SPeter Avalos 	"pay29", "pay30", "pay31", "pay32",          /* 29- 32 */
663ea7b4bf5SPeter Avalos 	"v2sa",  "v2ke",  "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
664ea7b4bf5SPeter Avalos 	"v2cr",  "v2auth","v2nonce", "v2n",   "v2d",   /* 38- 42 */
665ea7b4bf5SPeter Avalos 	"v2vid", "v2TSi", "v2TSr", "v2e",   "v2cp",  /* 43- 47 */
666ea7b4bf5SPeter Avalos 	"v2eap",                                     /* 48 */
667ea7b4bf5SPeter Avalos 
66841c99275SPeter Avalos };
66941c99275SPeter Avalos 
67041c99275SPeter Avalos /* isakmp->np */
671ea7b4bf5SPeter Avalos static const u_char *(*npfunc[])(netdissect_options *ndo, u_char tpay,
672ea7b4bf5SPeter Avalos 				 const struct isakmp_gen *ext,
673ea7b4bf5SPeter Avalos 				 u_int item_len,
674ea7b4bf5SPeter Avalos 				 const u_char *end_pointer,
675411677aeSAaron LI 				 uint32_t phase,
676411677aeSAaron LI 				 uint32_t doi0,
677411677aeSAaron LI 				 uint32_t proto0, int depth) = {
67841c99275SPeter Avalos 	NULL,
679ea7b4bf5SPeter Avalos 	ikev1_sa_print,
680ea7b4bf5SPeter Avalos 	ikev1_p_print,
681ea7b4bf5SPeter Avalos 	ikev1_t_print,
682ea7b4bf5SPeter Avalos 	ikev1_ke_print,
683ea7b4bf5SPeter Avalos 	ikev1_id_print,
684ea7b4bf5SPeter Avalos 	ikev1_cert_print,
685ea7b4bf5SPeter Avalos 	ikev1_cr_print,
686ea7b4bf5SPeter Avalos 	ikev1_hash_print,
687ea7b4bf5SPeter Avalos 	ikev1_sig_print,
688ea7b4bf5SPeter Avalos 	ikev1_nonce_print,
689ea7b4bf5SPeter Avalos 	ikev1_n_print,
690ea7b4bf5SPeter Avalos 	ikev1_d_print,
691ea7b4bf5SPeter Avalos 	ikev1_vid_print,                  /* 13 */
692ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL, NULL,     /* 14- 18 */
693ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL, NULL,     /* 19- 23 */
694ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL, NULL,     /* 24- 28 */
695ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL,           /* 29- 32 */
696ea7b4bf5SPeter Avalos 	ikev2_sa_print,                 /* 33 */
697ea7b4bf5SPeter Avalos 	ikev2_ke_print,                 /* 34 */
698ea7b4bf5SPeter Avalos 	ikev2_ID_print,                 /* 35 */
699ea7b4bf5SPeter Avalos 	ikev2_ID_print,                 /* 36 */
700ea7b4bf5SPeter Avalos 	ikev2_cert_print,               /* 37 */
701ea7b4bf5SPeter Avalos 	ikev2_cr_print,                 /* 38 */
702ea7b4bf5SPeter Avalos 	ikev2_auth_print,               /* 39 */
703ea7b4bf5SPeter Avalos 	ikev2_nonce_print,              /* 40 */
704ea7b4bf5SPeter Avalos 	ikev2_n_print,                  /* 41 */
705ea7b4bf5SPeter Avalos 	ikev2_d_print,                  /* 42 */
706ea7b4bf5SPeter Avalos 	ikev2_vid_print,                /* 43 */
707ea7b4bf5SPeter Avalos 	ikev2_TS_print,                 /* 44 */
708ea7b4bf5SPeter Avalos 	ikev2_TS_print,                 /* 45 */
70927bfbee1SPeter Avalos 	NULL, /* ikev2_e_print,*/       /* 46 - special */
710ea7b4bf5SPeter Avalos 	ikev2_cp_print,                 /* 47 */
711ea7b4bf5SPeter Avalos 	ikev2_eap_print,                /* 48 */
71241c99275SPeter Avalos };
71341c99275SPeter Avalos 
71441c99275SPeter Avalos /* isakmp->etype */
71541c99275SPeter Avalos static const char *etypestr[] = {
716ea7b4bf5SPeter Avalos /* IKEv1 exchange types */
717ea7b4bf5SPeter Avalos 	"none", "base", "ident", "auth", "agg", "inf", NULL, NULL,  /* 0-7 */
718ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,  /*  8-15 */
719ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,  /* 16-23 */
720ea7b4bf5SPeter Avalos 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,  /* 24-31 */
721ea7b4bf5SPeter Avalos 	"oakley-quick", "oakley-newgroup",               /* 32-33 */
722ea7b4bf5SPeter Avalos /* IKEv2 exchange types */
723ea7b4bf5SPeter Avalos 	"ikev2_init", "ikev2_auth", "child_sa", "inf2"   /* 34-37 */
72441c99275SPeter Avalos };
72541c99275SPeter Avalos 
72641c99275SPeter Avalos #define STR_OR_ID(x, tab) \
72741c99275SPeter Avalos 	(((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)])	? tab[(x)] : numstr(x))
72841c99275SPeter Avalos #define PROTOIDSTR(x)	STR_OR_ID(x, protoidstr)
72941c99275SPeter Avalos #define NPSTR(x)	STR_OR_ID(x, npstr)
73041c99275SPeter Avalos #define ETYPESTR(x)	STR_OR_ID(x, etypestr)
73141c99275SPeter Avalos 
732ea7b4bf5SPeter Avalos #define CHECKLEN(p, np)							\
733411677aeSAaron LI 		if (ep < (const u_char *)(p)) {				\
734*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" [|%s]", NPSTR(np));		\
735ea7b4bf5SPeter Avalos 			goto done;					\
736ea7b4bf5SPeter Avalos 		}
737ea7b4bf5SPeter Avalos 
738ea7b4bf5SPeter Avalos 
73941c99275SPeter Avalos #define NPFUNC(x) \
74041c99275SPeter Avalos 	(((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
74141c99275SPeter Avalos 		? npfunc[(x)] : NULL)
74241c99275SPeter Avalos 
74341c99275SPeter Avalos static int
iszero(const u_char * p,size_t l)744411677aeSAaron LI iszero(const u_char *p, size_t l)
74541c99275SPeter Avalos {
746*ed775ee7SAntonio Huete Jimenez 	while (l != 0) {
747*ed775ee7SAntonio Huete Jimenez 		if (*p)
74841c99275SPeter Avalos 			return 0;
749*ed775ee7SAntonio Huete Jimenez 		p++;
750*ed775ee7SAntonio Huete Jimenez 		l--;
75141c99275SPeter Avalos 	}
75241c99275SPeter Avalos 	return 1;
75341c99275SPeter Avalos }
75441c99275SPeter Avalos 
75541c99275SPeter Avalos /* find cookie from initiator cache */
75641c99275SPeter Avalos static int
cookie_find(const cookie_t * in)757*ed775ee7SAntonio Huete Jimenez cookie_find(const cookie_t *in)
75841c99275SPeter Avalos {
75941c99275SPeter Avalos 	int i;
76041c99275SPeter Avalos 
76141c99275SPeter Avalos 	for (i = 0; i < MAXINITIATORS; i++) {
76241c99275SPeter Avalos 		if (memcmp(in, &cookiecache[i].initiator, sizeof(*in)) == 0)
76341c99275SPeter Avalos 			return i;
76441c99275SPeter Avalos 	}
76541c99275SPeter Avalos 
76641c99275SPeter Avalos 	return -1;
76741c99275SPeter Avalos }
76841c99275SPeter Avalos 
76941c99275SPeter Avalos /* record initiator */
77041c99275SPeter Avalos static void
cookie_record(netdissect_options * ndo,const cookie_t * in,const u_char * bp2)771*ed775ee7SAntonio Huete Jimenez cookie_record(netdissect_options *ndo, const cookie_t *in, const u_char *bp2)
77241c99275SPeter Avalos {
77341c99275SPeter Avalos 	int i;
774411677aeSAaron LI 	const struct ip *ip;
775411677aeSAaron LI 	const struct ip6_hdr *ip6;
77641c99275SPeter Avalos 
77741c99275SPeter Avalos 	i = cookie_find(in);
77841c99275SPeter Avalos 	if (0 <= i) {
77941c99275SPeter Avalos 		ninitiator = (i + 1) % MAXINITIATORS;
78041c99275SPeter Avalos 		return;
78141c99275SPeter Avalos 	}
78241c99275SPeter Avalos 
783411677aeSAaron LI 	ip = (const struct ip *)bp2;
78441c99275SPeter Avalos 	switch (IP_V(ip)) {
78541c99275SPeter Avalos 	case 4:
786411677aeSAaron LI 		cookiecache[ninitiator].version = 4;
787*ed775ee7SAntonio Huete Jimenez 		UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in4,
788*ed775ee7SAntonio Huete Jimenez 				 ip->ip_src, sizeof(nd_ipv4));
789*ed775ee7SAntonio Huete Jimenez 		UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4,
790*ed775ee7SAntonio Huete Jimenez 				 ip->ip_dst, sizeof(nd_ipv4));
79141c99275SPeter Avalos 		break;
79241c99275SPeter Avalos 	case 6:
793411677aeSAaron LI 		ip6 = (const struct ip6_hdr *)bp2;
794411677aeSAaron LI 		cookiecache[ninitiator].version = 6;
795*ed775ee7SAntonio Huete Jimenez 		UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in6,
796*ed775ee7SAntonio Huete Jimenez 				 ip6->ip6_src, sizeof(nd_ipv6));
797*ed775ee7SAntonio Huete Jimenez 		UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6,
798*ed775ee7SAntonio Huete Jimenez 				 ip6->ip6_dst, sizeof(nd_ipv6));
79941c99275SPeter Avalos 		break;
80041c99275SPeter Avalos 	default:
80141c99275SPeter Avalos 		return;
80241c99275SPeter Avalos 	}
803411677aeSAaron LI 	UNALIGNED_MEMCPY(&cookiecache[ninitiator].initiator, in, sizeof(*in));
80441c99275SPeter Avalos 	ninitiator = (ninitiator + 1) % MAXINITIATORS;
80541c99275SPeter Avalos }
80641c99275SPeter Avalos 
807*ed775ee7SAntonio Huete Jimenez #define cookie_isinitiator(ndo, x, y)	cookie_sidecheck(ndo, (x), (y), 1)
808*ed775ee7SAntonio Huete Jimenez #define cookie_isresponder(ndo, x, y)	cookie_sidecheck(ndo, (x), (y), 0)
80941c99275SPeter Avalos static int
cookie_sidecheck(netdissect_options * ndo,int i,const u_char * bp2,int initiator)810*ed775ee7SAntonio Huete Jimenez cookie_sidecheck(netdissect_options *ndo, int i, const u_char *bp2, int initiator)
81141c99275SPeter Avalos {
812411677aeSAaron LI 	const struct ip *ip;
813411677aeSAaron LI 	const struct ip6_hdr *ip6;
81441c99275SPeter Avalos 
815411677aeSAaron LI 	ip = (const struct ip *)bp2;
81641c99275SPeter Avalos 	switch (IP_V(ip)) {
81741c99275SPeter Avalos 	case 4:
818411677aeSAaron LI 		if (cookiecache[i].version != 4)
81941c99275SPeter Avalos 			return 0;
82041c99275SPeter Avalos 		if (initiator) {
821*ed775ee7SAntonio Huete Jimenez 			if (UNALIGNED_MEMCMP(ip->ip_src, &cookiecache[i].iaddr.in4, sizeof(nd_ipv4)) == 0)
82241c99275SPeter Avalos 				return 1;
82341c99275SPeter Avalos 		} else {
824*ed775ee7SAntonio Huete Jimenez 			if (UNALIGNED_MEMCMP(ip->ip_src, &cookiecache[i].raddr.in4, sizeof(nd_ipv4)) == 0)
82541c99275SPeter Avalos 				return 1;
82641c99275SPeter Avalos 		}
827411677aeSAaron LI 		break;
828411677aeSAaron LI 	case 6:
829411677aeSAaron LI 		if (cookiecache[i].version != 6)
830411677aeSAaron LI 			return 0;
831411677aeSAaron LI 		ip6 = (const struct ip6_hdr *)bp2;
832411677aeSAaron LI 		if (initiator) {
833*ed775ee7SAntonio Huete Jimenez 			if (UNALIGNED_MEMCMP(ip6->ip6_src, &cookiecache[i].iaddr.in6, sizeof(nd_ipv6)) == 0)
834411677aeSAaron LI 				return 1;
835411677aeSAaron LI 		} else {
836*ed775ee7SAntonio Huete Jimenez 			if (UNALIGNED_MEMCMP(ip6->ip6_src, &cookiecache[i].raddr.in6, sizeof(nd_ipv6)) == 0)
837411677aeSAaron LI 				return 1;
838411677aeSAaron LI 		}
839411677aeSAaron LI 		break;
840411677aeSAaron LI 	default:
841411677aeSAaron LI 		break;
842411677aeSAaron LI 	}
843411677aeSAaron LI 
84441c99275SPeter Avalos 	return 0;
84541c99275SPeter Avalos }
84641c99275SPeter Avalos 
84727bfbee1SPeter Avalos static void
hexprint(netdissect_options * ndo,const uint8_t * loc,size_t len)848411677aeSAaron LI hexprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
84941c99275SPeter Avalos {
850411677aeSAaron LI 	const uint8_t *p;
85141c99275SPeter Avalos 	size_t i;
85241c99275SPeter Avalos 
853411677aeSAaron LI 	p = loc;
85441c99275SPeter Avalos 	for (i = 0; i < len; i++)
855*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("%02x", p[i] & 0xff);
85627bfbee1SPeter Avalos }
85727bfbee1SPeter Avalos 
85827bfbee1SPeter Avalos static int
rawprint(netdissect_options * ndo,const uint8_t * loc,size_t len)859411677aeSAaron LI rawprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
86027bfbee1SPeter Avalos {
861*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_LEN(loc, len);
86227bfbee1SPeter Avalos 
86327bfbee1SPeter Avalos 	hexprint(ndo, loc, len);
86441c99275SPeter Avalos 	return 1;
86541c99275SPeter Avalos trunc:
86641c99275SPeter Avalos 	return 0;
86741c99275SPeter Avalos }
86841c99275SPeter Avalos 
86927bfbee1SPeter Avalos 
870ea7b4bf5SPeter Avalos /*
871ea7b4bf5SPeter Avalos  * returns false if we run out of data buffer
872ea7b4bf5SPeter Avalos  */
ike_show_somedata(netdissect_options * ndo,const u_char * cp,const u_char * ep)873411677aeSAaron LI static int ike_show_somedata(netdissect_options *ndo,
874ea7b4bf5SPeter Avalos 			     const u_char *cp, const u_char *ep)
875ea7b4bf5SPeter Avalos {
876ea7b4bf5SPeter Avalos 	/* there is too much data, just show some of it */
877ea7b4bf5SPeter Avalos 	const u_char *end = ep - 20;
878*ed775ee7SAntonio Huete Jimenez 	size_t  elen = 20;
879*ed775ee7SAntonio Huete Jimenez 	size_t  len = ep - cp;
880ea7b4bf5SPeter Avalos 	if(len > 10) {
881ea7b4bf5SPeter Avalos 		len = 10;
882ea7b4bf5SPeter Avalos 	}
883ea7b4bf5SPeter Avalos 
884ea7b4bf5SPeter Avalos 	/* really shouldn't happen because of above */
885ea7b4bf5SPeter Avalos 	if(end < cp + len) {
886ea7b4bf5SPeter Avalos 		end = cp+len;
887ea7b4bf5SPeter Avalos 		elen = ep - end;
888ea7b4bf5SPeter Avalos 	}
889ea7b4bf5SPeter Avalos 
890*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" data=(");
891411677aeSAaron LI 	if(!rawprint(ndo, (const uint8_t *)(cp), len)) goto trunc;
892*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("...");
893ea7b4bf5SPeter Avalos 	if(elen) {
894411677aeSAaron LI 		if(!rawprint(ndo, (const uint8_t *)(end), elen)) goto trunc;
895ea7b4bf5SPeter Avalos 	}
896*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(")");
897ea7b4bf5SPeter Avalos 	return 1;
898ea7b4bf5SPeter Avalos 
899ea7b4bf5SPeter Avalos trunc:
900ea7b4bf5SPeter Avalos 	return 0;
901ea7b4bf5SPeter Avalos }
902ea7b4bf5SPeter Avalos 
90341c99275SPeter Avalos struct attrmap {
90441c99275SPeter Avalos 	const char *type;
90541c99275SPeter Avalos 	u_int nvalue;
90641c99275SPeter Avalos 	const char *value[30];	/*XXX*/
90741c99275SPeter Avalos };
90841c99275SPeter Avalos 
90941c99275SPeter Avalos static const u_char *
ikev1_attrmap_print(netdissect_options * ndo,const u_char * p,const u_char * ep2,const struct attrmap * map,size_t nmap)910ea7b4bf5SPeter Avalos ikev1_attrmap_print(netdissect_options *ndo,
911411677aeSAaron LI 		    const u_char *p, const u_char *ep2,
91241c99275SPeter Avalos 		    const struct attrmap *map, size_t nmap)
91341c99275SPeter Avalos {
914*ed775ee7SAntonio Huete Jimenez 	u_int totlen;
915411677aeSAaron LI 	uint32_t t, v;
91641c99275SPeter Avalos 
917*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(p) & 0x80)
91841c99275SPeter Avalos 		totlen = 4;
919411677aeSAaron LI 	else {
920*ed775ee7SAntonio Huete Jimenez 		totlen = 4 + GET_BE_U_2(p + 2);
921411677aeSAaron LI 	}
922411677aeSAaron LI 	if (ep2 < p + totlen) {
923*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[|attr]");
924411677aeSAaron LI 		return ep2 + 1;
92541c99275SPeter Avalos 	}
92641c99275SPeter Avalos 
927*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("(");
928*ed775ee7SAntonio Huete Jimenez 	t = GET_BE_U_2(p) & 0x7fff;
92941c99275SPeter Avalos 	if (map && t < nmap && map[t].type)
930*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("type=%s ", map[t].type);
93141c99275SPeter Avalos 	else
932*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("type=#%u ", t);
933*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(p) & 0x80) {
934*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("value=");
935*ed775ee7SAntonio Huete Jimenez 		v = GET_BE_U_2(p + 2);
93641c99275SPeter Avalos 		if (map && t < nmap && v < map[t].nvalue && map[t].value[v])
937*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%s", map[t].value[v]);
938411677aeSAaron LI 		else {
939*ed775ee7SAntonio Huete Jimenez 			if (!rawprint(ndo, (const uint8_t *)(p + 2), 2)) {
940*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(")");
941411677aeSAaron LI 				goto trunc;
942411677aeSAaron LI 			}
943411677aeSAaron LI 		}
94441c99275SPeter Avalos 	} else {
945*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("len=%u value=", totlen - 4);
946*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(p + 4), totlen - 4)) {
947*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(")");
948411677aeSAaron LI 			goto trunc;
949411677aeSAaron LI 		}
95041c99275SPeter Avalos 	}
951*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(")");
95241c99275SPeter Avalos 	return p + totlen;
953411677aeSAaron LI 
954411677aeSAaron LI trunc:
955411677aeSAaron LI 	return NULL;
95641c99275SPeter Avalos }
95741c99275SPeter Avalos 
95841c99275SPeter Avalos static const u_char *
ikev1_attr_print(netdissect_options * ndo,const u_char * p,const u_char * ep2)959411677aeSAaron LI ikev1_attr_print(netdissect_options *ndo, const u_char *p, const u_char *ep2)
96041c99275SPeter Avalos {
961*ed775ee7SAntonio Huete Jimenez 	u_int totlen;
962411677aeSAaron LI 	uint32_t t;
96341c99275SPeter Avalos 
964*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(p) & 0x80)
96541c99275SPeter Avalos 		totlen = 4;
966411677aeSAaron LI 	else {
967*ed775ee7SAntonio Huete Jimenez 		totlen = 4 + GET_BE_U_2(p + 2);
968411677aeSAaron LI 	}
969411677aeSAaron LI 	if (ep2 < p + totlen) {
970*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[|attr]");
971411677aeSAaron LI 		return ep2 + 1;
97241c99275SPeter Avalos 	}
97341c99275SPeter Avalos 
974*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("(");
975*ed775ee7SAntonio Huete Jimenez 	t = GET_BE_U_2(p) & 0x7fff;
976*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("type=#%u ", t);
977*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(p) & 0x80) {
978*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("value=");
979*ed775ee7SAntonio Huete Jimenez 		t = GET_U_1(p + 2);
980*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(p + 2), 2)) {
981*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(")");
982411677aeSAaron LI 			goto trunc;
983411677aeSAaron LI 		}
98441c99275SPeter Avalos 	} else {
985*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("len=%u value=", totlen - 4);
986*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(p + 4), totlen - 4)) {
987*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(")");
988411677aeSAaron LI 			goto trunc;
989411677aeSAaron LI 		}
99041c99275SPeter Avalos 	}
991*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(")");
99241c99275SPeter Avalos 	return p + totlen;
993411677aeSAaron LI 
994411677aeSAaron LI trunc:
995411677aeSAaron LI 	return NULL;
99641c99275SPeter Avalos }
99741c99275SPeter Avalos 
99841c99275SPeter Avalos static const u_char *
ikev1_sa_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len _U_,const u_char * ep,uint32_t phase,uint32_t doi0 _U_,uint32_t proto0,int depth)999ea7b4bf5SPeter Avalos ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_,
1000ea7b4bf5SPeter Avalos 	       const struct isakmp_gen *ext,
100141c99275SPeter Avalos 		u_int item_len _U_,
1002411677aeSAaron LI 		const u_char *ep, uint32_t phase, uint32_t doi0 _U_,
1003411677aeSAaron LI 		uint32_t proto0, int depth)
100441c99275SPeter Avalos {
1005ea7b4bf5SPeter Avalos 	const struct ikev1_pl_sa *p;
1006411677aeSAaron LI 	uint32_t doi, sit, ident;
100741c99275SPeter Avalos 	const u_char *cp, *np;
100841c99275SPeter Avalos 	int t;
100941c99275SPeter Avalos 
1010*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SA));
101141c99275SPeter Avalos 
1012411677aeSAaron LI 	p = (const struct ikev1_pl_sa *)ext;
1013*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1014*ed775ee7SAntonio Huete Jimenez 	doi = GET_BE_U_4(p->doi);
1015*ed775ee7SAntonio Huete Jimenez 	sit = GET_BE_U_4(p->sit);
101641c99275SPeter Avalos 	if (doi != 1) {
1017*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" doi=%u", doi);
1018*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" situation=%u", sit);
1019411677aeSAaron LI 		return (const u_char *)(p + 1);
102041c99275SPeter Avalos 	}
102141c99275SPeter Avalos 
1022*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" doi=ipsec");
1023*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" situation=");
102441c99275SPeter Avalos 	t = 0;
102541c99275SPeter Avalos 	if (sit & 0x01) {
1026*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("identity");
102741c99275SPeter Avalos 		t++;
102841c99275SPeter Avalos 	}
102941c99275SPeter Avalos 	if (sit & 0x02) {
1030*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("%ssecrecy", t ? "+" : "");
103141c99275SPeter Avalos 		t++;
103241c99275SPeter Avalos 	}
103341c99275SPeter Avalos 	if (sit & 0x04)
1034*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("%sintegrity", t ? "+" : "");
103541c99275SPeter Avalos 
1036*ed775ee7SAntonio Huete Jimenez 	np = (const u_char *)ext + sizeof(struct ikev1_pl_sa);
103741c99275SPeter Avalos 	if (sit != 0x01) {
1038*ed775ee7SAntonio Huete Jimenez 		ident = GET_BE_U_4(ext + 1);
1039*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ident=%u", ident);
104041c99275SPeter Avalos 		np += sizeof(ident);
104141c99275SPeter Avalos 	}
104241c99275SPeter Avalos 
1043411677aeSAaron LI 	ext = (const struct isakmp_gen *)np;
1044*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
104541c99275SPeter Avalos 
1046ea7b4bf5SPeter Avalos 	cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
104741c99275SPeter Avalos 		depth);
104841c99275SPeter Avalos 
104941c99275SPeter Avalos 	return cp;
105041c99275SPeter Avalos trunc:
1051*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA));
105241c99275SPeter Avalos 	return NULL;
105341c99275SPeter Avalos }
105441c99275SPeter Avalos 
105541c99275SPeter Avalos static const u_char *
ikev1_p_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len _U_,const u_char * ep,uint32_t phase,uint32_t doi0,uint32_t proto0 _U_,int depth)1056ea7b4bf5SPeter Avalos ikev1_p_print(netdissect_options *ndo, u_char tpay _U_,
1057ea7b4bf5SPeter Avalos 	      const struct isakmp_gen *ext, u_int item_len _U_,
1058411677aeSAaron LI 	       const u_char *ep, uint32_t phase, uint32_t doi0,
1059411677aeSAaron LI 	       uint32_t proto0 _U_, int depth)
106041c99275SPeter Avalos {
1061ea7b4bf5SPeter Avalos 	const struct ikev1_pl_p *p;
106241c99275SPeter Avalos 	const u_char *cp;
1063*ed775ee7SAntonio Huete Jimenez 	uint8_t spi_size;
106441c99275SPeter Avalos 
1065*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_P));
106641c99275SPeter Avalos 
1067411677aeSAaron LI 	p = (const struct ikev1_pl_p *)ext;
1068*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1069*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" #%u protoid=%s transform=%u",
1070*ed775ee7SAntonio Huete Jimenez 		  GET_U_1(p->p_no), PROTOIDSTR(GET_U_1(p->prot_id)),
1071*ed775ee7SAntonio Huete Jimenez 		  GET_U_1(p->num_t));
1072*ed775ee7SAntonio Huete Jimenez 	spi_size = GET_U_1(p->spi_size);
1073*ed775ee7SAntonio Huete Jimenez 	if (spi_size) {
1074*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" spi=");
1075*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
107641c99275SPeter Avalos 			goto trunc;
107741c99275SPeter Avalos 	}
107841c99275SPeter Avalos 
1079*ed775ee7SAntonio Huete Jimenez 	ext = (const struct isakmp_gen *)((const u_char *)(p + 1) + spi_size);
1080*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
108141c99275SPeter Avalos 
1082ea7b4bf5SPeter Avalos 	cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
1083*ed775ee7SAntonio Huete Jimenez 			     GET_U_1(p->prot_id), depth);
108441c99275SPeter Avalos 
108541c99275SPeter Avalos 	return cp;
108641c99275SPeter Avalos trunc:
1087*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
108841c99275SPeter Avalos 	return NULL;
108941c99275SPeter Avalos }
109041c99275SPeter Avalos 
1091ea7b4bf5SPeter Avalos static const char *ikev1_p_map[] = {
109241c99275SPeter Avalos 	NULL, "ike",
109341c99275SPeter Avalos };
109441c99275SPeter Avalos 
1095ea7b4bf5SPeter Avalos static const char *ikev2_t_type_map[]={
1096ea7b4bf5SPeter Avalos 	NULL, "encr", "prf", "integ", "dh", "esn"
1097ea7b4bf5SPeter Avalos };
1098ea7b4bf5SPeter Avalos 
109941c99275SPeter Avalos static const char *ah_p_map[] = {
110041c99275SPeter Avalos 	NULL, "(reserved)", "md5", "sha", "1des",
110141c99275SPeter Avalos 	"sha2-256", "sha2-384", "sha2-512",
110241c99275SPeter Avalos };
110341c99275SPeter Avalos 
1104ea7b4bf5SPeter Avalos static const char *prf_p_map[] = {
1105ea7b4bf5SPeter Avalos 	NULL, "hmac-md5", "hmac-sha", "hmac-tiger",
1106ea7b4bf5SPeter Avalos 	"aes128_xcbc"
1107ea7b4bf5SPeter Avalos };
1108ea7b4bf5SPeter Avalos 
1109ea7b4bf5SPeter Avalos static const char *integ_p_map[] = {
1110ea7b4bf5SPeter Avalos 	NULL, "hmac-md5", "hmac-sha", "dec-mac",
1111ea7b4bf5SPeter Avalos 	"kpdk-md5", "aes-xcbc"
1112ea7b4bf5SPeter Avalos };
1113ea7b4bf5SPeter Avalos 
1114ea7b4bf5SPeter Avalos static const char *esn_p_map[] = {
1115ea7b4bf5SPeter Avalos 	"no-esn", "esn"
1116ea7b4bf5SPeter Avalos };
1117ea7b4bf5SPeter Avalos 
1118ea7b4bf5SPeter Avalos static const char *dh_p_map[] = {
1119ea7b4bf5SPeter Avalos 	NULL, "modp768",
1120ea7b4bf5SPeter Avalos 	"modp1024",    /* group 2 */
1121ea7b4bf5SPeter Avalos 	"EC2N 2^155",  /* group 3 */
1122ea7b4bf5SPeter Avalos 	"EC2N 2^185",  /* group 4 */
1123ea7b4bf5SPeter Avalos 	"modp1536",    /* group 5 */
1124ea7b4bf5SPeter Avalos 	"iana-grp06", "iana-grp07", /* reserved */
1125ea7b4bf5SPeter Avalos 	"iana-grp08", "iana-grp09",
1126ea7b4bf5SPeter Avalos 	"iana-grp10", "iana-grp11",
1127ea7b4bf5SPeter Avalos 	"iana-grp12", "iana-grp13",
1128ea7b4bf5SPeter Avalos 	"modp2048",    /* group 14 */
1129ea7b4bf5SPeter Avalos 	"modp3072",    /* group 15 */
1130ea7b4bf5SPeter Avalos 	"modp4096",    /* group 16 */
1131ea7b4bf5SPeter Avalos 	"modp6144",    /* group 17 */
1132ea7b4bf5SPeter Avalos 	"modp8192",    /* group 18 */
1133ea7b4bf5SPeter Avalos };
1134ea7b4bf5SPeter Avalos 
113541c99275SPeter Avalos static const char *esp_p_map[] = {
113641c99275SPeter Avalos 	NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
113741c99275SPeter Avalos 	"blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
113841c99275SPeter Avalos };
113941c99275SPeter Avalos 
114041c99275SPeter Avalos static const char *ipcomp_p_map[] = {
114141c99275SPeter Avalos 	NULL, "oui", "deflate", "lzs",
114241c99275SPeter Avalos };
114341c99275SPeter Avalos 
1144411677aeSAaron LI static const struct attrmap ipsec_t_map[] = {
114541c99275SPeter Avalos 	{ NULL,	0, { NULL } },
114641c99275SPeter Avalos 	{ "lifetype", 3, { NULL, "sec", "kb", }, },
114741c99275SPeter Avalos 	{ "life", 0, { NULL } },
1148ea7b4bf5SPeter Avalos 	{ "group desc", 18,	{ NULL, "modp768",
1149ea7b4bf5SPeter Avalos 				  "modp1024",    /* group 2 */
1150ea7b4bf5SPeter Avalos 				  "EC2N 2^155",  /* group 3 */
1151ea7b4bf5SPeter Avalos 				  "EC2N 2^185",  /* group 4 */
1152ea7b4bf5SPeter Avalos 				  "modp1536",    /* group 5 */
1153ea7b4bf5SPeter Avalos 				  "iana-grp06", "iana-grp07", /* reserved */
1154ea7b4bf5SPeter Avalos 				  "iana-grp08", "iana-grp09",
1155ea7b4bf5SPeter Avalos 				  "iana-grp10", "iana-grp11",
1156ea7b4bf5SPeter Avalos 				  "iana-grp12", "iana-grp13",
1157ea7b4bf5SPeter Avalos 				  "modp2048",    /* group 14 */
1158ea7b4bf5SPeter Avalos 				  "modp3072",    /* group 15 */
1159ea7b4bf5SPeter Avalos 				  "modp4096",    /* group 16 */
1160ea7b4bf5SPeter Avalos 				  "modp6144",    /* group 17 */
1161ea7b4bf5SPeter Avalos 				  "modp8192",    /* group 18 */
1162ea7b4bf5SPeter Avalos 		}, },
116341c99275SPeter Avalos 	{ "enc mode", 3, { NULL, "tunnel", "transport", }, },
116441c99275SPeter Avalos 	{ "auth", 5, { NULL, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
116541c99275SPeter Avalos 	{ "keylen", 0, { NULL } },
116641c99275SPeter Avalos 	{ "rounds", 0, { NULL } },
116741c99275SPeter Avalos 	{ "dictsize", 0, { NULL } },
116841c99275SPeter Avalos 	{ "privalg", 0, { NULL } },
116941c99275SPeter Avalos };
117041c99275SPeter Avalos 
1171411677aeSAaron LI static const struct attrmap encr_t_map[] = {
1172ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 0, 1 */
1173ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 2, 3 */
1174ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 4, 5 */
1175ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 6, 7 */
1176ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 8, 9 */
1177ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 10,11*/
1178ea7b4bf5SPeter Avalos 	{ NULL,	0, { NULL } },	{ NULL,	0, { NULL } },  /* 12,13*/
1179ea7b4bf5SPeter Avalos 	{ "keylen", 14, { NULL }},
1180ea7b4bf5SPeter Avalos };
1181ea7b4bf5SPeter Avalos 
1182411677aeSAaron LI static const struct attrmap oakley_t_map[] = {
118341c99275SPeter Avalos 	{ NULL,	0, { NULL } },
118441c99275SPeter Avalos 	{ "enc", 8,	{ NULL, "1des", "idea", "blowfish", "rc5",
118541c99275SPeter Avalos 			  "3des", "cast", "aes", }, },
118641c99275SPeter Avalos 	{ "hash", 7,	{ NULL, "md5", "sha1", "tiger",
118741c99275SPeter Avalos 			  "sha2-256", "sha2-384", "sha2-512", }, },
118841c99275SPeter Avalos 	{ "auth", 6,	{ NULL, "preshared", "dss", "rsa sig", "rsa enc",
118941c99275SPeter Avalos 			  "rsa enc revised", }, },
1190ea7b4bf5SPeter Avalos 	{ "group desc", 18,	{ NULL, "modp768",
1191ea7b4bf5SPeter Avalos 				  "modp1024",    /* group 2 */
1192ea7b4bf5SPeter Avalos 				  "EC2N 2^155",  /* group 3 */
1193ea7b4bf5SPeter Avalos 				  "EC2N 2^185",  /* group 4 */
1194ea7b4bf5SPeter Avalos 				  "modp1536",    /* group 5 */
1195ea7b4bf5SPeter Avalos 				  "iana-grp06", "iana-grp07", /* reserved */
1196ea7b4bf5SPeter Avalos 				  "iana-grp08", "iana-grp09",
1197ea7b4bf5SPeter Avalos 				  "iana-grp10", "iana-grp11",
1198ea7b4bf5SPeter Avalos 				  "iana-grp12", "iana-grp13",
1199ea7b4bf5SPeter Avalos 				  "modp2048",    /* group 14 */
1200ea7b4bf5SPeter Avalos 				  "modp3072",    /* group 15 */
1201ea7b4bf5SPeter Avalos 				  "modp4096",    /* group 16 */
1202ea7b4bf5SPeter Avalos 				  "modp6144",    /* group 17 */
1203ea7b4bf5SPeter Avalos 				  "modp8192",    /* group 18 */
1204ea7b4bf5SPeter Avalos 		}, },
120541c99275SPeter Avalos 	{ "group type", 4,	{ NULL, "MODP", "ECP", "EC2N", }, },
120641c99275SPeter Avalos 	{ "group prime", 0, { NULL } },
120741c99275SPeter Avalos 	{ "group gen1", 0, { NULL } },
120841c99275SPeter Avalos 	{ "group gen2", 0, { NULL } },
120941c99275SPeter Avalos 	{ "group curve A", 0, { NULL } },
121041c99275SPeter Avalos 	{ "group curve B", 0, { NULL } },
121141c99275SPeter Avalos 	{ "lifetype", 3,	{ NULL, "sec", "kb", }, },
121241c99275SPeter Avalos 	{ "lifeduration", 0, { NULL } },
121341c99275SPeter Avalos 	{ "prf", 0, { NULL } },
121441c99275SPeter Avalos 	{ "keylen", 0, { NULL } },
121541c99275SPeter Avalos 	{ "field", 0, { NULL } },
121641c99275SPeter Avalos 	{ "order", 0, { NULL } },
121741c99275SPeter Avalos };
121841c99275SPeter Avalos 
121941c99275SPeter Avalos static const u_char *
ikev1_t_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto,int depth _U_)1220ea7b4bf5SPeter Avalos ikev1_t_print(netdissect_options *ndo, u_char tpay _U_,
1221ea7b4bf5SPeter Avalos 	      const struct isakmp_gen *ext, u_int item_len,
1222411677aeSAaron LI 	      const u_char *ep, uint32_t phase _U_, uint32_t doi _U_,
1223411677aeSAaron LI 	      uint32_t proto, int depth _U_)
122441c99275SPeter Avalos {
1225ea7b4bf5SPeter Avalos 	const struct ikev1_pl_t *p;
122641c99275SPeter Avalos 	const u_char *cp;
122741c99275SPeter Avalos 	const char *idstr;
122841c99275SPeter Avalos 	const struct attrmap *map;
122941c99275SPeter Avalos 	size_t nmap;
123041c99275SPeter Avalos 	const u_char *ep2;
123141c99275SPeter Avalos 
1232*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_T));
123341c99275SPeter Avalos 
1234411677aeSAaron LI 	p = (const struct ikev1_pl_t *)ext;
1235*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
123641c99275SPeter Avalos 
123741c99275SPeter Avalos 	switch (proto) {
123841c99275SPeter Avalos 	case 1:
1239*ed775ee7SAntonio Huete Jimenez 		idstr = STR_OR_ID(GET_U_1(p->t_id), ikev1_p_map);
124041c99275SPeter Avalos 		map = oakley_t_map;
124141c99275SPeter Avalos 		nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
124241c99275SPeter Avalos 		break;
124341c99275SPeter Avalos 	case 2:
1244*ed775ee7SAntonio Huete Jimenez 		idstr = STR_OR_ID(GET_U_1(p->t_id), ah_p_map);
124541c99275SPeter Avalos 		map = ipsec_t_map;
124641c99275SPeter Avalos 		nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
124741c99275SPeter Avalos 		break;
124841c99275SPeter Avalos 	case 3:
1249*ed775ee7SAntonio Huete Jimenez 		idstr = STR_OR_ID(GET_U_1(p->t_id), esp_p_map);
125041c99275SPeter Avalos 		map = ipsec_t_map;
125141c99275SPeter Avalos 		nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
125241c99275SPeter Avalos 		break;
125341c99275SPeter Avalos 	case 4:
1254*ed775ee7SAntonio Huete Jimenez 		idstr = STR_OR_ID(GET_U_1(p->t_id), ipcomp_p_map);
125541c99275SPeter Avalos 		map = ipsec_t_map;
125641c99275SPeter Avalos 		nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
125741c99275SPeter Avalos 		break;
125841c99275SPeter Avalos 	default:
125941c99275SPeter Avalos 		idstr = NULL;
126041c99275SPeter Avalos 		map = NULL;
126141c99275SPeter Avalos 		nmap = 0;
126241c99275SPeter Avalos 		break;
126341c99275SPeter Avalos 	}
126441c99275SPeter Avalos 
126541c99275SPeter Avalos 	if (idstr)
1266*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" #%u id=%s ", GET_U_1(p->t_no), idstr);
126741c99275SPeter Avalos 	else
1268*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" #%u id=%u ", GET_U_1(p->t_no), GET_U_1(p->t_id));
1269411677aeSAaron LI 	cp = (const u_char *)(p + 1);
1270411677aeSAaron LI 	ep2 = (const u_char *)p + item_len;
127141c99275SPeter Avalos 	while (cp < ep && cp < ep2) {
1272411677aeSAaron LI 		if (map && nmap)
1273411677aeSAaron LI 			cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1274411677aeSAaron LI 		else
1275411677aeSAaron LI 			cp = ikev1_attr_print(ndo, cp, ep2);
1276411677aeSAaron LI 		if (cp == NULL)
1277411677aeSAaron LI 			goto trunc;
127841c99275SPeter Avalos 	}
127941c99275SPeter Avalos 	if (ep < ep2)
1280*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("...");
128141c99275SPeter Avalos 	return cp;
128241c99275SPeter Avalos trunc:
1283*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T));
128441c99275SPeter Avalos 	return NULL;
128541c99275SPeter Avalos }
128641c99275SPeter Avalos 
128741c99275SPeter Avalos static const u_char *
ikev1_ke_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)1288ea7b4bf5SPeter Avalos ikev1_ke_print(netdissect_options *ndo, u_char tpay _U_,
1289*ed775ee7SAntonio Huete Jimenez 	       const struct isakmp_gen *ext, u_int item_len,
1290411677aeSAaron LI 	       const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1291411677aeSAaron LI 	       uint32_t proto _U_, int depth _U_)
129241c99275SPeter Avalos {
1293*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_KE));
129441c99275SPeter Avalos 
1295*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
1296*ed775ee7SAntonio Huete Jimenez 	/*
1297*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1298*ed775ee7SAntonio Huete Jimenez 	 */
1299*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" key len=%u", item_len - 4);
1300*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && item_len > 4) {
1301411677aeSAaron LI 		/* Print the entire payload in hex */
1302*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1303*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
130441c99275SPeter Avalos 			goto trunc;
130541c99275SPeter Avalos 	}
1306*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
130741c99275SPeter Avalos trunc:
1308*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_KE));
130941c99275SPeter Avalos 	return NULL;
131041c99275SPeter Avalos }
131141c99275SPeter Avalos 
131241c99275SPeter Avalos static const u_char *
ikev1_id_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)1313ea7b4bf5SPeter Avalos ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
1314411677aeSAaron LI 	       const struct isakmp_gen *ext, u_int item_len,
1315411677aeSAaron LI 	       const u_char *ep _U_, uint32_t phase, uint32_t doi _U_,
1316411677aeSAaron LI 	       uint32_t proto _U_, int depth _U_)
131741c99275SPeter Avalos {
131841c99275SPeter Avalos #define USE_IPSECDOI_IN_PHASE1	1
1319ea7b4bf5SPeter Avalos 	const struct ikev1_pl_id *p;
132041c99275SPeter Avalos 	static const char *idtypestr[] = {
132141c99275SPeter Avalos 		"IPv4", "IPv4net", "IPv6", "IPv6net",
132241c99275SPeter Avalos 	};
132341c99275SPeter Avalos 	static const char *ipsecidtypestr[] = {
132441c99275SPeter Avalos 		NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
132541c99275SPeter Avalos 		"IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
132641c99275SPeter Avalos 		"keyid",
132741c99275SPeter Avalos 	};
1328*ed775ee7SAntonio Huete Jimenez 	u_int len;
132941c99275SPeter Avalos 	const u_char *data;
133041c99275SPeter Avalos 
1331*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_ID));
133241c99275SPeter Avalos 
1333411677aeSAaron LI 	p = (const struct ikev1_pl_id *)ext;
1334*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
133541c99275SPeter Avalos 	if (sizeof(*p) < item_len) {
1336411677aeSAaron LI 		data = (const u_char *)(p + 1);
133741c99275SPeter Avalos 		len = item_len - sizeof(*p);
133841c99275SPeter Avalos 	} else {
133941c99275SPeter Avalos 		data = NULL;
134041c99275SPeter Avalos 		len = 0;
134141c99275SPeter Avalos 	}
134241c99275SPeter Avalos 
134341c99275SPeter Avalos #if 0 /*debug*/
1344*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [phase=%u doi=%u proto=%u]", phase, doi, proto);
134541c99275SPeter Avalos #endif
134641c99275SPeter Avalos 	switch (phase) {
134741c99275SPeter Avalos #ifndef USE_IPSECDOI_IN_PHASE1
134841c99275SPeter Avalos 	case 1:
134941c99275SPeter Avalos #endif
135041c99275SPeter Avalos 	default:
1351*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" idtype=%s",
1352*ed775ee7SAntonio Huete Jimenez 			 STR_OR_ID(GET_U_1(p->d.id_type), idtypestr));
1353*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" doi_data=%u",
1354*ed775ee7SAntonio Huete Jimenez 			  GET_BE_U_4(p->d.doi_data) & 0xffffff);
135541c99275SPeter Avalos 		break;
135641c99275SPeter Avalos 
135741c99275SPeter Avalos #ifdef USE_IPSECDOI_IN_PHASE1
135841c99275SPeter Avalos 	case 1:
135941c99275SPeter Avalos #endif
136041c99275SPeter Avalos 	case 2:
136141c99275SPeter Avalos 	    {
1362411677aeSAaron LI 		const struct ipsecdoi_id *doi_p;
1363411677aeSAaron LI 		const char *p_name;
1364*ed775ee7SAntonio Huete Jimenez 		uint8_t type, proto_id;
136541c99275SPeter Avalos 
1366411677aeSAaron LI 		doi_p = (const struct ipsecdoi_id *)ext;
1367*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_SIZE(doi_p);
1368*ed775ee7SAntonio Huete Jimenez 		type = GET_U_1(doi_p->type);
1369*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" idtype=%s", STR_OR_ID(type, ipsecidtypestr));
1370411677aeSAaron LI 		/* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
1371*ed775ee7SAntonio Huete Jimenez 		proto_id = GET_U_1(doi_p->proto_id);
1372*ed775ee7SAntonio Huete Jimenez 		if (!ndo->ndo_nflag && proto_id && (p_name = netdb_protoname(proto_id)) != NULL)
1373*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" protoid=%s", p_name);
1374411677aeSAaron LI 		else
1375*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" protoid=%u", proto_id);
1376*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" port=%u", GET_BE_U_2(doi_p->port));
137741c99275SPeter Avalos 		if (!len)
137841c99275SPeter Avalos 			break;
137941c99275SPeter Avalos 		if (data == NULL)
138041c99275SPeter Avalos 			goto trunc;
1381*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(data, len);
1382*ed775ee7SAntonio Huete Jimenez 		switch (type) {
138341c99275SPeter Avalos 		case IPSECDOI_ID_IPV4_ADDR:
138441c99275SPeter Avalos 			if (len < 4)
1385*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u [bad: < 4]", len);
138641c99275SPeter Avalos 			else
1387*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u %s", len, GET_IPADDR_STRING(data));
138841c99275SPeter Avalos 			len = 0;
138941c99275SPeter Avalos 			break;
139041c99275SPeter Avalos 		case IPSECDOI_ID_FQDN:
139141c99275SPeter Avalos 		case IPSECDOI_ID_USER_FQDN:
139241c99275SPeter Avalos 		    {
1393*ed775ee7SAntonio Huete Jimenez 			u_int i;
1394*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" len=%u ", len);
139541c99275SPeter Avalos 			for (i = 0; i < len; i++)
1396*ed775ee7SAntonio Huete Jimenez 				fn_print_char(ndo, GET_U_1(data + i));
139741c99275SPeter Avalos 			len = 0;
139841c99275SPeter Avalos 			break;
139941c99275SPeter Avalos 		    }
140041c99275SPeter Avalos 		case IPSECDOI_ID_IPV4_ADDR_SUBNET:
140141c99275SPeter Avalos 		    {
140241c99275SPeter Avalos 			const u_char *mask;
140341c99275SPeter Avalos 			if (len < 8)
1404*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u [bad: < 8]", len);
140541c99275SPeter Avalos 			else {
1406*ed775ee7SAntonio Huete Jimenez 				mask = data + sizeof(nd_ipv4);
1407*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u %s/%u.%u.%u.%u", len,
1408*ed775ee7SAntonio Huete Jimenez 					  GET_IPADDR_STRING(data),
1409*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask), GET_U_1(mask + 1),
1410*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 2),
1411*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 3));
141241c99275SPeter Avalos 			}
141341c99275SPeter Avalos 			len = 0;
141441c99275SPeter Avalos 			break;
141541c99275SPeter Avalos 		    }
141641c99275SPeter Avalos 		case IPSECDOI_ID_IPV6_ADDR:
141741c99275SPeter Avalos 			if (len < 16)
1418*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u [bad: < 16]", len);
141941c99275SPeter Avalos 			else
1420*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u %s", len, GET_IP6ADDR_STRING(data));
142141c99275SPeter Avalos 			len = 0;
142241c99275SPeter Avalos 			break;
142341c99275SPeter Avalos 		case IPSECDOI_ID_IPV6_ADDR_SUBNET:
142441c99275SPeter Avalos 		    {
1425411677aeSAaron LI 			const u_char *mask;
1426411677aeSAaron LI 			if (len < 32)
1427*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u [bad: < 32]", len);
142841c99275SPeter Avalos 			else {
1429*ed775ee7SAntonio Huete Jimenez 				mask = (const u_char *)(data + sizeof(nd_ipv6));
143041c99275SPeter Avalos 				/*XXX*/
1431*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len,
1432*ed775ee7SAntonio Huete Jimenez 					  GET_IP6ADDR_STRING(data),
1433*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask), GET_U_1(mask + 1),
1434*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 2),
1435*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 3),
1436*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 4),
1437*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 5),
1438*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 6),
1439*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 7),
1440*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 8),
1441*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 9),
1442*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 10),
1443*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 11),
1444*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 12),
1445*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 13),
1446*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 14),
1447*ed775ee7SAntonio Huete Jimenez 					  GET_U_1(mask + 15));
144841c99275SPeter Avalos 			}
144941c99275SPeter Avalos 			len = 0;
145041c99275SPeter Avalos 			break;
145141c99275SPeter Avalos 		    }
145241c99275SPeter Avalos 		case IPSECDOI_ID_IPV4_ADDR_RANGE:
145341c99275SPeter Avalos 			if (len < 8)
1454*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u [bad: < 8]", len);
145541c99275SPeter Avalos 			else {
1456*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u %s-%s", len,
1457*ed775ee7SAntonio Huete Jimenez 					  GET_IPADDR_STRING(data),
1458*ed775ee7SAntonio Huete Jimenez 					  GET_IPADDR_STRING(data + sizeof(nd_ipv4)));
145941c99275SPeter Avalos 			}
146041c99275SPeter Avalos 			len = 0;
146141c99275SPeter Avalos 			break;
146241c99275SPeter Avalos 		case IPSECDOI_ID_IPV6_ADDR_RANGE:
146341c99275SPeter Avalos 			if (len < 32)
1464*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u [bad: < 32]", len);
146541c99275SPeter Avalos 			else {
1466*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" len=%u %s-%s", len,
1467*ed775ee7SAntonio Huete Jimenez 					  GET_IP6ADDR_STRING(data),
1468*ed775ee7SAntonio Huete Jimenez 					  GET_IP6ADDR_STRING(data + sizeof(nd_ipv6)));
146941c99275SPeter Avalos 			}
147041c99275SPeter Avalos 			len = 0;
147141c99275SPeter Avalos 			break;
147241c99275SPeter Avalos 		case IPSECDOI_ID_DER_ASN1_DN:
147341c99275SPeter Avalos 		case IPSECDOI_ID_DER_ASN1_GN:
147441c99275SPeter Avalos 		case IPSECDOI_ID_KEY_ID:
147541c99275SPeter Avalos 			break;
147641c99275SPeter Avalos 		}
147741c99275SPeter Avalos 		break;
147841c99275SPeter Avalos 	    }
147941c99275SPeter Avalos 	}
148041c99275SPeter Avalos 	if (data && len) {
1481*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" len=%u", len);
1482ea7b4bf5SPeter Avalos 		if (2 < ndo->ndo_vflag) {
1483*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" ");
1484411677aeSAaron LI 			if (!rawprint(ndo, (const uint8_t *)data, len))
148541c99275SPeter Avalos 				goto trunc;
148641c99275SPeter Avalos 		}
148741c99275SPeter Avalos 	}
1488411677aeSAaron LI 	return (const u_char *)ext + item_len;
148941c99275SPeter Avalos trunc:
1490*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID));
149141c99275SPeter Avalos 	return NULL;
149241c99275SPeter Avalos }
149341c99275SPeter Avalos 
149441c99275SPeter Avalos static const u_char *
ikev1_cert_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi0 _U_,uint32_t proto0 _U_,int depth _U_)1495ea7b4bf5SPeter Avalos ikev1_cert_print(netdissect_options *ndo, u_char tpay _U_,
1496411677aeSAaron LI 		 const struct isakmp_gen *ext, u_int item_len,
1497411677aeSAaron LI 		 const u_char *ep _U_, uint32_t phase _U_,
1498411677aeSAaron LI 		 uint32_t doi0 _U_,
1499411677aeSAaron LI 		 uint32_t proto0 _U_, int depth _U_)
150041c99275SPeter Avalos {
1501ea7b4bf5SPeter Avalos 	const struct ikev1_pl_cert *p;
150241c99275SPeter Avalos 	static const char *certstr[] = {
150341c99275SPeter Avalos 		"none",	"pkcs7", "pgp", "dns",
150441c99275SPeter Avalos 		"x509sign", "x509ke", "kerberos", "crl",
150541c99275SPeter Avalos 		"arl", "spki", "x509attr",
150641c99275SPeter Avalos 	};
150741c99275SPeter Avalos 
1508*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CERT));
150941c99275SPeter Avalos 
1510411677aeSAaron LI 	p = (const struct ikev1_pl_cert *)ext;
1511*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1512*ed775ee7SAntonio Huete Jimenez 	/*
1513*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1514*ed775ee7SAntonio Huete Jimenez 	 */
1515*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
1516*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p->encode), certstr));
1517ea7b4bf5SPeter Avalos 	if (2 < ndo->ndo_vflag && 4 < item_len) {
1518411677aeSAaron LI 		/* Print the entire payload in hex */
1519*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1520411677aeSAaron LI 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
152141c99275SPeter Avalos 			goto trunc;
152241c99275SPeter Avalos 	}
1523411677aeSAaron LI 	return (const u_char *)ext + item_len;
152441c99275SPeter Avalos trunc:
1525*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT));
152641c99275SPeter Avalos 	return NULL;
152741c99275SPeter Avalos }
152841c99275SPeter Avalos 
152941c99275SPeter Avalos static const u_char *
ikev1_cr_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi0 _U_,uint32_t proto0 _U_,int depth _U_)1530ea7b4bf5SPeter Avalos ikev1_cr_print(netdissect_options *ndo, u_char tpay _U_,
1531411677aeSAaron LI 	       const struct isakmp_gen *ext, u_int item_len,
1532411677aeSAaron LI 	       const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1533411677aeSAaron LI 	       uint32_t proto0 _U_, int depth _U_)
153441c99275SPeter Avalos {
1535ea7b4bf5SPeter Avalos 	const struct ikev1_pl_cert *p;
153641c99275SPeter Avalos 	static const char *certstr[] = {
153741c99275SPeter Avalos 		"none",	"pkcs7", "pgp", "dns",
153841c99275SPeter Avalos 		"x509sign", "x509ke", "kerberos", "crl",
153941c99275SPeter Avalos 		"arl", "spki", "x509attr",
154041c99275SPeter Avalos 	};
154141c99275SPeter Avalos 
1542*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CR));
154341c99275SPeter Avalos 
1544411677aeSAaron LI 	p = (const struct ikev1_pl_cert *)ext;
1545*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1546*ed775ee7SAntonio Huete Jimenez 	/*
1547*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1548*ed775ee7SAntonio Huete Jimenez 	 */
1549*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
1550*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p->encode), certstr));
1551ea7b4bf5SPeter Avalos 	if (2 < ndo->ndo_vflag && 4 < item_len) {
1552411677aeSAaron LI 		/* Print the entire payload in hex */
1553*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1554411677aeSAaron LI 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
155541c99275SPeter Avalos 			goto trunc;
155641c99275SPeter Avalos 	}
1557411677aeSAaron LI 	return (const u_char *)ext + item_len;
155841c99275SPeter Avalos trunc:
1559*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CR));
156041c99275SPeter Avalos 	return NULL;
156141c99275SPeter Avalos }
156241c99275SPeter Avalos 
156341c99275SPeter Avalos static const u_char *
ikev1_hash_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)1564ea7b4bf5SPeter Avalos ikev1_hash_print(netdissect_options *ndo, u_char tpay _U_,
1565*ed775ee7SAntonio Huete Jimenez 		 const struct isakmp_gen *ext, u_int item_len,
1566411677aeSAaron LI 		 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1567411677aeSAaron LI 		 uint32_t proto _U_, int depth _U_)
156841c99275SPeter Avalos {
1569*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_HASH));
157041c99275SPeter Avalos 
1571*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
1572*ed775ee7SAntonio Huete Jimenez 	/*
1573*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1574*ed775ee7SAntonio Huete Jimenez 	 */
1575*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
1576*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && 4 < item_len) {
1577411677aeSAaron LI 		/* Print the entire payload in hex */
1578*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1579*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
158041c99275SPeter Avalos 			goto trunc;
158141c99275SPeter Avalos 	}
1582*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
158341c99275SPeter Avalos trunc:
1584*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_HASH));
158541c99275SPeter Avalos 	return NULL;
158641c99275SPeter Avalos }
158741c99275SPeter Avalos 
158841c99275SPeter Avalos static const u_char *
ikev1_sig_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)1589ea7b4bf5SPeter Avalos ikev1_sig_print(netdissect_options *ndo, u_char tpay _U_,
1590*ed775ee7SAntonio Huete Jimenez 		const struct isakmp_gen *ext, u_int item_len,
1591411677aeSAaron LI 		const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1592411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
159341c99275SPeter Avalos {
1594*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SIG));
159541c99275SPeter Avalos 
1596*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
1597*ed775ee7SAntonio Huete Jimenez 	/*
1598*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1599*ed775ee7SAntonio Huete Jimenez 	 */
1600*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
1601*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && 4 < item_len) {
1602411677aeSAaron LI 		/* Print the entire payload in hex */
1603*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1604*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
160541c99275SPeter Avalos 			goto trunc;
160641c99275SPeter Avalos 	}
1607*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
160841c99275SPeter Avalos trunc:
1609*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SIG));
161041c99275SPeter Avalos 	return NULL;
161141c99275SPeter Avalos }
161241c99275SPeter Avalos 
161341c99275SPeter Avalos static const u_char *
ikev1_nonce_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)1614ea7b4bf5SPeter Avalos ikev1_nonce_print(netdissect_options *ndo, u_char tpay _U_,
1615ea7b4bf5SPeter Avalos 		  const struct isakmp_gen *ext,
1616*ed775ee7SAntonio Huete Jimenez 		  u_int item_len,
1617411677aeSAaron LI 		  const u_char *ep,
1618411677aeSAaron LI 		  uint32_t phase _U_, uint32_t doi _U_,
1619411677aeSAaron LI 		  uint32_t proto _U_, int depth _U_)
162041c99275SPeter Avalos {
1621*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_NONCE));
162241c99275SPeter Avalos 
1623*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
1624411677aeSAaron LI 	/*
1625411677aeSAaron LI 	 * Our caller has ensured that the length is >= 4.
1626411677aeSAaron LI 	 */
1627*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" n len=%u", item_len - 4);
1628*ed775ee7SAntonio Huete Jimenez 	if (item_len > 4) {
1629411677aeSAaron LI 		if (ndo->ndo_vflag > 2) {
1630*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" ");
1631*ed775ee7SAntonio Huete Jimenez 			if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
1632ea7b4bf5SPeter Avalos 				goto trunc;
1633411677aeSAaron LI 		} else if (ndo->ndo_vflag > 1) {
1634*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" ");
1635411677aeSAaron LI 			if (!ike_show_somedata(ndo, (const u_char *)(ext + 1), ep))
163641c99275SPeter Avalos 				goto trunc;
163741c99275SPeter Avalos 		}
1638411677aeSAaron LI 	}
1639*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
164041c99275SPeter Avalos trunc:
1641*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE));
164241c99275SPeter Avalos 	return NULL;
164341c99275SPeter Avalos }
164441c99275SPeter Avalos 
164541c99275SPeter Avalos static const u_char *
ikev1_n_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep,uint32_t phase _U_,uint32_t doi0 _U_,uint32_t proto0 _U_,int depth _U_)1646ea7b4bf5SPeter Avalos ikev1_n_print(netdissect_options *ndo, u_char tpay _U_,
1647ea7b4bf5SPeter Avalos 	      const struct isakmp_gen *ext, u_int item_len,
1648411677aeSAaron LI 	      const u_char *ep, uint32_t phase _U_, uint32_t doi0 _U_,
1649411677aeSAaron LI 	      uint32_t proto0 _U_, int depth _U_)
165041c99275SPeter Avalos {
1651411677aeSAaron LI 	const struct ikev1_pl_n *p;
165241c99275SPeter Avalos 	const u_char *cp;
1653411677aeSAaron LI 	const u_char *ep2;
1654411677aeSAaron LI 	uint32_t doi;
1655411677aeSAaron LI 	uint32_t proto;
1656*ed775ee7SAntonio Huete Jimenez 	uint16_t type;
1657*ed775ee7SAntonio Huete Jimenez 	uint8_t spi_size;
165841c99275SPeter Avalos 	static const char *notify_error_str[] = {
165941c99275SPeter Avalos 		NULL,				"INVALID-PAYLOAD-TYPE",
166041c99275SPeter Avalos 		"DOI-NOT-SUPPORTED",		"SITUATION-NOT-SUPPORTED",
166141c99275SPeter Avalos 		"INVALID-COOKIE",		"INVALID-MAJOR-VERSION",
166241c99275SPeter Avalos 		"INVALID-MINOR-VERSION",	"INVALID-EXCHANGE-TYPE",
166341c99275SPeter Avalos 		"INVALID-FLAGS",		"INVALID-MESSAGE-ID",
166441c99275SPeter Avalos 		"INVALID-PROTOCOL-ID",		"INVALID-SPI",
166541c99275SPeter Avalos 		"INVALID-TRANSFORM-ID",		"ATTRIBUTES-NOT-SUPPORTED",
166641c99275SPeter Avalos 		"NO-PROPOSAL-CHOSEN",		"BAD-PROPOSAL-SYNTAX",
166741c99275SPeter Avalos 		"PAYLOAD-MALFORMED",		"INVALID-KEY-INFORMATION",
166841c99275SPeter Avalos 		"INVALID-ID-INFORMATION",	"INVALID-CERT-ENCODING",
166941c99275SPeter Avalos 		"INVALID-CERTIFICATE",		"CERT-TYPE-UNSUPPORTED",
167041c99275SPeter Avalos 		"INVALID-CERT-AUTHORITY",	"INVALID-HASH-INFORMATION",
167141c99275SPeter Avalos 		"AUTHENTICATION-FAILED",	"INVALID-SIGNATURE",
167241c99275SPeter Avalos 		"ADDRESS-NOTIFICATION",		"NOTIFY-SA-LIFETIME",
167341c99275SPeter Avalos 		"CERTIFICATE-UNAVAILABLE",	"UNSUPPORTED-EXCHANGE-TYPE",
167441c99275SPeter Avalos 		"UNEQUAL-PAYLOAD-LENGTHS",
167541c99275SPeter Avalos 	};
167641c99275SPeter Avalos 	static const char *ipsec_notify_error_str[] = {
167741c99275SPeter Avalos 		"RESERVED",
167841c99275SPeter Avalos 	};
167941c99275SPeter Avalos 	static const char *notify_status_str[] = {
168041c99275SPeter Avalos 		"CONNECTED",
168141c99275SPeter Avalos 	};
168241c99275SPeter Avalos 	static const char *ipsec_notify_status_str[] = {
168341c99275SPeter Avalos 		"RESPONDER-LIFETIME",		"REPLAY-STATUS",
168441c99275SPeter Avalos 		"INITIAL-CONTACT",
168541c99275SPeter Avalos 	};
168641c99275SPeter Avalos /* NOTE: these macro must be called with x in proper range */
168741c99275SPeter Avalos 
168841c99275SPeter Avalos /* 0 - 8191 */
168941c99275SPeter Avalos #define NOTIFY_ERROR_STR(x) \
169041c99275SPeter Avalos 	STR_OR_ID((x), notify_error_str)
169141c99275SPeter Avalos 
169241c99275SPeter Avalos /* 8192 - 16383 */
169341c99275SPeter Avalos #define IPSEC_NOTIFY_ERROR_STR(x) \
169441c99275SPeter Avalos 	STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
169541c99275SPeter Avalos 
169641c99275SPeter Avalos /* 16384 - 24575 */
169741c99275SPeter Avalos #define NOTIFY_STATUS_STR(x) \
169841c99275SPeter Avalos 	STR_OR_ID((u_int)((x) - 16384), notify_status_str)
169941c99275SPeter Avalos 
170041c99275SPeter Avalos /* 24576 - 32767 */
170141c99275SPeter Avalos #define IPSEC_NOTIFY_STATUS_STR(x) \
170241c99275SPeter Avalos 	STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
170341c99275SPeter Avalos 
1704*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_N));
170541c99275SPeter Avalos 
1706411677aeSAaron LI 	p = (const struct ikev1_pl_n *)ext;
1707*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1708*ed775ee7SAntonio Huete Jimenez 	doi = GET_BE_U_4(p->doi);
1709*ed775ee7SAntonio Huete Jimenez 	proto = GET_U_1(p->prot_id);
171041c99275SPeter Avalos 	if (doi != 1) {
1711*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" doi=%u", doi);
1712*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" proto=%u", proto);
1713*ed775ee7SAntonio Huete Jimenez 		type = GET_BE_U_2(p->type);
1714*ed775ee7SAntonio Huete Jimenez 		if (type < 8192)
1715*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type));
1716*ed775ee7SAntonio Huete Jimenez 		else if (type < 16384)
1717*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" type=%s", numstr(type));
1718*ed775ee7SAntonio Huete Jimenez 		else if (type < 24576)
1719*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type));
172041c99275SPeter Avalos 		else
1721*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" type=%s", numstr(type));
1722*ed775ee7SAntonio Huete Jimenez 		spi_size = GET_U_1(p->spi_size);
1723*ed775ee7SAntonio Huete Jimenez 		if (spi_size) {
1724*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" spi=");
1725*ed775ee7SAntonio Huete Jimenez 			if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
172641c99275SPeter Avalos 				goto trunc;
172741c99275SPeter Avalos 		}
1728*ed775ee7SAntonio Huete Jimenez 		return (const u_char *)(p + 1) + spi_size;
172941c99275SPeter Avalos 	}
173041c99275SPeter Avalos 
1731*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" doi=ipsec");
1732*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" proto=%s", PROTOIDSTR(proto));
1733*ed775ee7SAntonio Huete Jimenez 	type = GET_BE_U_2(p->type);
1734*ed775ee7SAntonio Huete Jimenez 	if (type < 8192)
1735*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type));
1736*ed775ee7SAntonio Huete Jimenez 	else if (type < 16384)
1737*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" type=%s", IPSEC_NOTIFY_ERROR_STR(type));
1738*ed775ee7SAntonio Huete Jimenez 	else if (type < 24576)
1739*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type));
1740*ed775ee7SAntonio Huete Jimenez 	else if (type < 32768)
1741*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" type=%s", IPSEC_NOTIFY_STATUS_STR(type));
174241c99275SPeter Avalos 	else
1743*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" type=%s", numstr(type));
1744*ed775ee7SAntonio Huete Jimenez 	spi_size = GET_U_1(p->spi_size);
1745*ed775ee7SAntonio Huete Jimenez 	if (spi_size) {
1746*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" spi=");
1747*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
174841c99275SPeter Avalos 			goto trunc;
174941c99275SPeter Avalos 	}
175041c99275SPeter Avalos 
1751*ed775ee7SAntonio Huete Jimenez 	cp = (const u_char *)(p + 1) + spi_size;
1752411677aeSAaron LI 	ep2 = (const u_char *)p + item_len;
175341c99275SPeter Avalos 
175441c99275SPeter Avalos 	if (cp < ep) {
1755*ed775ee7SAntonio Huete Jimenez 		switch (type) {
175641c99275SPeter Avalos 		case IPSECDOI_NTYPE_RESPONDER_LIFETIME:
175741c99275SPeter Avalos 		    {
175841c99275SPeter Avalos 			const struct attrmap *map = oakley_t_map;
175941c99275SPeter Avalos 			size_t nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
1760*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" attrs=(");
176141c99275SPeter Avalos 			while (cp < ep && cp < ep2) {
1762411677aeSAaron LI 				cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1763411677aeSAaron LI 				if (cp == NULL) {
1764*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(")");
1765411677aeSAaron LI 					goto trunc;
176641c99275SPeter Avalos 				}
1767411677aeSAaron LI 			}
1768*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(")");
176941c99275SPeter Avalos 			break;
177041c99275SPeter Avalos 		    }
177141c99275SPeter Avalos 		case IPSECDOI_NTYPE_REPLAY_STATUS:
1772*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" status=(");
1773*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("replay detection %sabled",
1774*ed775ee7SAntonio Huete Jimenez 				  GET_BE_U_4(cp) ? "en" : "dis");
1775*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(")");
177641c99275SPeter Avalos 			break;
177741c99275SPeter Avalos 		default:
1778411677aeSAaron LI 			/*
1779411677aeSAaron LI 			 * XXX - fill in more types here; see, for example,
1780411677aeSAaron LI 			 * draft-ietf-ipsec-notifymsg-04.
1781411677aeSAaron LI 			 */
1782411677aeSAaron LI 			if (ndo->ndo_vflag > 3) {
1783*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(" data=(");
1784411677aeSAaron LI 				if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
1785411677aeSAaron LI 					goto trunc;
1786*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(")");
1787411677aeSAaron LI 			} else {
1788411677aeSAaron LI 				if (!ike_show_somedata(ndo, cp, ep))
1789411677aeSAaron LI 					goto trunc;
179041c99275SPeter Avalos 			}
1791411677aeSAaron LI 			break;
1792411677aeSAaron LI 		}
1793411677aeSAaron LI 	}
1794411677aeSAaron LI 	return (const u_char *)ext + item_len;
179541c99275SPeter Avalos trunc:
1796*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N));
179741c99275SPeter Avalos 	return NULL;
179841c99275SPeter Avalos }
179941c99275SPeter Avalos 
180041c99275SPeter Avalos static const u_char *
ikev1_d_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len _U_,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi0 _U_,uint32_t proto0 _U_,int depth _U_)1801ea7b4bf5SPeter Avalos ikev1_d_print(netdissect_options *ndo, u_char tpay _U_,
1802ea7b4bf5SPeter Avalos 	      const struct isakmp_gen *ext, u_int item_len _U_,
1803411677aeSAaron LI 	      const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1804411677aeSAaron LI 	      uint32_t proto0 _U_, int depth _U_)
180541c99275SPeter Avalos {
1806ea7b4bf5SPeter Avalos 	const struct ikev1_pl_d *p;
1807411677aeSAaron LI 	const uint8_t *q;
1808411677aeSAaron LI 	uint32_t doi;
1809411677aeSAaron LI 	uint32_t proto;
1810*ed775ee7SAntonio Huete Jimenez 	uint8_t spi_size;
1811*ed775ee7SAntonio Huete Jimenez 	uint16_t num_spi;
1812*ed775ee7SAntonio Huete Jimenez 	u_int i;
181341c99275SPeter Avalos 
1814*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_D));
181541c99275SPeter Avalos 
1816411677aeSAaron LI 	p = (const struct ikev1_pl_d *)ext;
1817*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1818*ed775ee7SAntonio Huete Jimenez 	doi = GET_BE_U_4(p->doi);
1819*ed775ee7SAntonio Huete Jimenez 	proto = GET_U_1(p->prot_id);
182041c99275SPeter Avalos 	if (doi != 1) {
1821*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" doi=%u", doi);
1822*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" proto=%u", proto);
182341c99275SPeter Avalos 	} else {
1824*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" doi=ipsec");
1825*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" proto=%s", PROTOIDSTR(proto));
182641c99275SPeter Avalos 	}
1827*ed775ee7SAntonio Huete Jimenez 	spi_size = GET_U_1(p->spi_size);
1828*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" spilen=%u", spi_size);
1829*ed775ee7SAntonio Huete Jimenez 	num_spi = GET_BE_U_2(p->num_spi);
1830*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" nspi=%u", num_spi);
1831*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" spi=");
1832411677aeSAaron LI 	q = (const uint8_t *)(p + 1);
1833*ed775ee7SAntonio Huete Jimenez 	for (i = 0; i < num_spi; i++) {
183441c99275SPeter Avalos 		if (i != 0)
1835*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(",");
1836*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)q, spi_size))
183741c99275SPeter Avalos 			goto trunc;
1838*ed775ee7SAntonio Huete Jimenez 		q += spi_size;
183941c99275SPeter Avalos 	}
184041c99275SPeter Avalos 	return q;
184141c99275SPeter Avalos trunc:
1842*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_D));
184341c99275SPeter Avalos 	return NULL;
184441c99275SPeter Avalos }
184541c99275SPeter Avalos 
184641c99275SPeter Avalos static const u_char *
ikev1_vid_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)1847ea7b4bf5SPeter Avalos ikev1_vid_print(netdissect_options *ndo, u_char tpay _U_,
1848ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
1849*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
1850411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
1851411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
185241c99275SPeter Avalos {
1853*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_VID));
185441c99275SPeter Avalos 
1855*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
1856*ed775ee7SAntonio Huete Jimenez 	/*
1857*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1858*ed775ee7SAntonio Huete Jimenez 	 */
1859*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
1860*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && 4 < item_len) {
1861411677aeSAaron LI 		/* Print the entire payload in hex */
1862*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1863*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
186441c99275SPeter Avalos 			goto trunc;
186541c99275SPeter Avalos 	}
1866*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
186741c99275SPeter Avalos trunc:
1868*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID));
1869ea7b4bf5SPeter Avalos 	return NULL;
1870ea7b4bf5SPeter Avalos }
1871ea7b4bf5SPeter Avalos 
1872ea7b4bf5SPeter Avalos /************************************************************/
1873ea7b4bf5SPeter Avalos /*                                                          */
1874ea7b4bf5SPeter Avalos /*              IKE v2 - rfc4306 - dissector                */
1875ea7b4bf5SPeter Avalos /*                                                          */
1876ea7b4bf5SPeter Avalos /************************************************************/
1877ea7b4bf5SPeter Avalos 
1878ea7b4bf5SPeter Avalos static void
ikev2_pay_print(netdissect_options * ndo,const char * payname,uint8_t critical)1879*ed775ee7SAntonio Huete Jimenez ikev2_pay_print(netdissect_options *ndo, const char *payname, uint8_t critical)
1880ea7b4bf5SPeter Avalos {
1881*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s%s:", payname, critical&0x80 ? "[C]" : "");
1882ea7b4bf5SPeter Avalos }
1883ea7b4bf5SPeter Avalos 
1884ea7b4bf5SPeter Avalos static const u_char *
ikev2_gen_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len)1885ea7b4bf5SPeter Avalos ikev2_gen_print(netdissect_options *ndo, u_char tpay,
1886*ed775ee7SAntonio Huete Jimenez 		const struct isakmp_gen *ext, u_int item_len)
1887ea7b4bf5SPeter Avalos {
1888*ed775ee7SAntonio Huete Jimenez 	const struct isakmp_gen *p = (const struct isakmp_gen *)ext;
1889ea7b4bf5SPeter Avalos 
1890*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
1891*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(p->critical));
1892ea7b4bf5SPeter Avalos 
1893*ed775ee7SAntonio Huete Jimenez 	/*
1894*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
1895*ed775ee7SAntonio Huete Jimenez 	 */
1896*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
1897*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && 4 < item_len) {
1898411677aeSAaron LI 		/* Print the entire payload in hex */
1899*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
1900*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
1901ea7b4bf5SPeter Avalos 			goto trunc;
1902ea7b4bf5SPeter Avalos 	}
1903*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
1904ea7b4bf5SPeter Avalos trunc:
1905*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
190641c99275SPeter Avalos 	return NULL;
190741c99275SPeter Avalos }
190841c99275SPeter Avalos 
190941c99275SPeter Avalos static const u_char *
ikev2_t_print(netdissect_options * ndo,int tcount,const struct isakmp_gen * ext,u_int item_len,const u_char * ep)1910411677aeSAaron LI ikev2_t_print(netdissect_options *ndo, int tcount,
1911ea7b4bf5SPeter Avalos 	      const struct isakmp_gen *ext, u_int item_len,
1912411677aeSAaron LI 	      const u_char *ep)
1913ea7b4bf5SPeter Avalos {
1914ea7b4bf5SPeter Avalos 	const struct ikev2_t *p;
1915411677aeSAaron LI 	uint16_t  t_id;
1916*ed775ee7SAntonio Huete Jimenez 	uint8_t t_type;
1917ea7b4bf5SPeter Avalos 	const u_char *cp;
1918ea7b4bf5SPeter Avalos 	const char *idstr;
1919ea7b4bf5SPeter Avalos 	const struct attrmap *map;
1920ea7b4bf5SPeter Avalos 	size_t nmap;
1921ea7b4bf5SPeter Avalos 	const u_char *ep2;
1922ea7b4bf5SPeter Avalos 
1923411677aeSAaron LI 	p = (const struct ikev2_t *)ext;
1924*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
1925*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_T), GET_U_1(p->h.critical));
1926ea7b4bf5SPeter Avalos 
1927*ed775ee7SAntonio Huete Jimenez 	t_id = GET_BE_U_2(p->t_id);
1928ea7b4bf5SPeter Avalos 
1929ea7b4bf5SPeter Avalos 	map = NULL;
1930ea7b4bf5SPeter Avalos 	nmap = 0;
1931ea7b4bf5SPeter Avalos 
1932*ed775ee7SAntonio Huete Jimenez 	t_type = GET_U_1(p->t_type);
1933*ed775ee7SAntonio Huete Jimenez 	switch (t_type) {
1934ea7b4bf5SPeter Avalos 	case IV2_T_ENCR:
1935ea7b4bf5SPeter Avalos 		idstr = STR_OR_ID(t_id, esp_p_map);
1936ea7b4bf5SPeter Avalos 		map = encr_t_map;
1937ea7b4bf5SPeter Avalos 		nmap = sizeof(encr_t_map)/sizeof(encr_t_map[0]);
1938ea7b4bf5SPeter Avalos 		break;
1939ea7b4bf5SPeter Avalos 
1940ea7b4bf5SPeter Avalos 	case IV2_T_PRF:
1941ea7b4bf5SPeter Avalos 		idstr = STR_OR_ID(t_id, prf_p_map);
1942ea7b4bf5SPeter Avalos 		break;
1943ea7b4bf5SPeter Avalos 
1944ea7b4bf5SPeter Avalos 	case IV2_T_INTEG:
1945ea7b4bf5SPeter Avalos 		idstr = STR_OR_ID(t_id, integ_p_map);
1946ea7b4bf5SPeter Avalos 		break;
1947ea7b4bf5SPeter Avalos 
1948ea7b4bf5SPeter Avalos 	case IV2_T_DH:
1949ea7b4bf5SPeter Avalos 		idstr = STR_OR_ID(t_id, dh_p_map);
1950ea7b4bf5SPeter Avalos 		break;
1951ea7b4bf5SPeter Avalos 
1952ea7b4bf5SPeter Avalos 	case IV2_T_ESN:
1953ea7b4bf5SPeter Avalos 		idstr = STR_OR_ID(t_id, esn_p_map);
1954ea7b4bf5SPeter Avalos 		break;
1955ea7b4bf5SPeter Avalos 
1956ea7b4bf5SPeter Avalos 	default:
1957ea7b4bf5SPeter Avalos 		idstr = NULL;
1958ea7b4bf5SPeter Avalos 		break;
1959ea7b4bf5SPeter Avalos 	}
1960ea7b4bf5SPeter Avalos 
1961ea7b4bf5SPeter Avalos 	if (idstr)
1962*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" #%u type=%s id=%s ", tcount,
1963*ed775ee7SAntonio Huete Jimenez 			  STR_OR_ID(t_type, ikev2_t_type_map),
1964*ed775ee7SAntonio Huete Jimenez 			  idstr);
1965ea7b4bf5SPeter Avalos 	else
1966*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" #%u type=%s id=%u ", tcount,
1967*ed775ee7SAntonio Huete Jimenez 			  STR_OR_ID(t_type, ikev2_t_type_map),
1968*ed775ee7SAntonio Huete Jimenez 			  t_id);
1969411677aeSAaron LI 	cp = (const u_char *)(p + 1);
1970411677aeSAaron LI 	ep2 = (const u_char *)p + item_len;
1971ea7b4bf5SPeter Avalos 	while (cp < ep && cp < ep2) {
1972ea7b4bf5SPeter Avalos 		if (map && nmap) {
1973411677aeSAaron LI 			cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1974ea7b4bf5SPeter Avalos 		} else
1975411677aeSAaron LI 			cp = ikev1_attr_print(ndo, cp, ep2);
1976411677aeSAaron LI 		if (cp == NULL)
1977411677aeSAaron LI 			goto trunc;
1978ea7b4bf5SPeter Avalos 	}
1979ea7b4bf5SPeter Avalos 	if (ep < ep2)
1980*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("...");
1981ea7b4bf5SPeter Avalos 	return cp;
1982ea7b4bf5SPeter Avalos trunc:
1983*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T));
1984ea7b4bf5SPeter Avalos 	return NULL;
1985ea7b4bf5SPeter Avalos }
1986ea7b4bf5SPeter Avalos 
1987ea7b4bf5SPeter Avalos static const u_char *
ikev2_p_print(netdissect_options * ndo,u_char tpay _U_,int pcount _U_,const struct isakmp_gen * ext,u_int oprop_length,const u_char * ep,int depth)1988ea7b4bf5SPeter Avalos ikev2_p_print(netdissect_options *ndo, u_char tpay _U_, int pcount _U_,
1989411677aeSAaron LI 	      const struct isakmp_gen *ext, u_int oprop_length,
1990411677aeSAaron LI 	      const u_char *ep, int depth)
1991ea7b4bf5SPeter Avalos {
1992ea7b4bf5SPeter Avalos 	const struct ikev2_p *p;
1993411677aeSAaron LI 	u_int prop_length;
1994*ed775ee7SAntonio Huete Jimenez 	uint8_t spi_size;
1995ea7b4bf5SPeter Avalos 	const u_char *cp;
1996411677aeSAaron LI 	int i;
1997411677aeSAaron LI 	int tcount;
1998411677aeSAaron LI 	u_char np;
1999411677aeSAaron LI 	u_int item_len;
2000ea7b4bf5SPeter Avalos 
2001411677aeSAaron LI 	p = (const struct ikev2_p *)ext;
2002*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
2003411677aeSAaron LI 
2004*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_P), GET_U_1(p->h.critical));
2005ea7b4bf5SPeter Avalos 
2006411677aeSAaron LI 	/*
2007411677aeSAaron LI 	 * ikev2_sa_print() guarantees that this is >= 4.
2008411677aeSAaron LI 	 */
2009411677aeSAaron LI 	prop_length = oprop_length - 4;
2010*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" #%u protoid=%s transform=%u len=%u",
2011*ed775ee7SAntonio Huete Jimenez 		  GET_U_1(p->p_no),  PROTOIDSTR(GET_U_1(p->prot_id)),
2012*ed775ee7SAntonio Huete Jimenez 		  GET_U_1(p->num_t), oprop_length);
2013411677aeSAaron LI 	cp = (const u_char *)(p + 1);
2014411677aeSAaron LI 
2015*ed775ee7SAntonio Huete Jimenez 	spi_size = GET_U_1(p->spi_size);
2016*ed775ee7SAntonio Huete Jimenez 	if (spi_size) {
2017*ed775ee7SAntonio Huete Jimenez 		if (prop_length < spi_size)
2018411677aeSAaron LI 			goto toolong;
2019*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" spi=");
2020*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)cp, spi_size))
2021ea7b4bf5SPeter Avalos 			goto trunc;
2022*ed775ee7SAntonio Huete Jimenez 		cp += spi_size;
2023*ed775ee7SAntonio Huete Jimenez 		prop_length -= spi_size;
2024ea7b4bf5SPeter Avalos 	}
2025ea7b4bf5SPeter Avalos 
2026411677aeSAaron LI 	/*
2027411677aeSAaron LI 	 * Print the transforms.
2028411677aeSAaron LI 	 */
2029411677aeSAaron LI 	tcount = 0;
2030*ed775ee7SAntonio Huete Jimenez 	for (np = ISAKMP_NPTYPE_T; np != 0; np = GET_U_1(ext->np)) {
2031411677aeSAaron LI 		tcount++;
2032411677aeSAaron LI 		ext = (const struct isakmp_gen *)cp;
2033411677aeSAaron LI 		if (prop_length < sizeof(*ext))
2034411677aeSAaron LI 			goto toolong;
2035*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_SIZE(ext);
2036ea7b4bf5SPeter Avalos 
2037411677aeSAaron LI 		/*
2038411677aeSAaron LI 		 * Since we can't have a payload length of less than 4 bytes,
2039411677aeSAaron LI 		 * we need to bail out here if the generic header is nonsensical
2040411677aeSAaron LI 		 * or truncated, otherwise we could loop forever processing
2041411677aeSAaron LI 		 * zero-length items or otherwise misdissect the packet.
2042411677aeSAaron LI 		 */
2043*ed775ee7SAntonio Huete Jimenez 		item_len = GET_BE_U_2(ext->len);
2044411677aeSAaron LI 		if (item_len <= 4)
2045411677aeSAaron LI 			goto trunc;
2046ea7b4bf5SPeter Avalos 
2047411677aeSAaron LI 		if (prop_length < item_len)
2048411677aeSAaron LI 			goto toolong;
2049*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(cp, item_len);
2050411677aeSAaron LI 
2051411677aeSAaron LI 		depth++;
2052*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n");
2053411677aeSAaron LI 		for (i = 0; i < depth; i++)
2054*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("    ");
2055*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("(");
2056411677aeSAaron LI 		if (np == ISAKMP_NPTYPE_T) {
2057411677aeSAaron LI 			cp = ikev2_t_print(ndo, tcount, ext, item_len, ep);
2058411677aeSAaron LI 			if (cp == NULL) {
2059411677aeSAaron LI 				/* error, already reported */
2060411677aeSAaron LI 				return NULL;
2061411677aeSAaron LI 			}
2062411677aeSAaron LI 		} else {
2063*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%s", NPSTR(np));
2064411677aeSAaron LI 			cp += item_len;
2065411677aeSAaron LI 		}
2066*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(")");
2067411677aeSAaron LI 		depth--;
2068411677aeSAaron LI 		prop_length -= item_len;
2069411677aeSAaron LI 	}
2070411677aeSAaron LI 	return cp;
2071411677aeSAaron LI toolong:
2072411677aeSAaron LI 	/*
2073411677aeSAaron LI 	 * Skip the rest of the proposal.
2074411677aeSAaron LI 	 */
2075411677aeSAaron LI 	cp += prop_length;
2076*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
2077ea7b4bf5SPeter Avalos 	return cp;
2078ea7b4bf5SPeter Avalos trunc:
2079*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
2080ea7b4bf5SPeter Avalos 	return NULL;
2081ea7b4bf5SPeter Avalos }
2082ea7b4bf5SPeter Avalos 
2083ea7b4bf5SPeter Avalos static const u_char *
ikev2_sa_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext1,u_int osa_length,const u_char * ep,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth)2084ea7b4bf5SPeter Avalos ikev2_sa_print(netdissect_options *ndo, u_char tpay,
2085ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext1,
2086411677aeSAaron LI 		u_int osa_length, const u_char *ep,
2087411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2088411677aeSAaron LI 		uint32_t proto _U_, int depth)
2089ea7b4bf5SPeter Avalos {
2090411677aeSAaron LI 	const struct isakmp_gen *ext;
2091411677aeSAaron LI 	u_int sa_length;
2092411677aeSAaron LI 	const u_char *cp;
2093411677aeSAaron LI 	int i;
2094411677aeSAaron LI 	int pcount;
2095411677aeSAaron LI 	u_char np;
2096411677aeSAaron LI 	u_int item_len;
2097ea7b4bf5SPeter Avalos 
2098*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext1);
2099*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, "sa", GET_U_1(ext1->critical));
2100ea7b4bf5SPeter Avalos 
2101411677aeSAaron LI 	/*
2102411677aeSAaron LI 	 * ikev2_sub0_print() guarantees that this is >= 4.
2103411677aeSAaron LI 	 */
2104*ed775ee7SAntonio Huete Jimenez 	osa_length= GET_BE_U_2(ext1->len);
210527bfbee1SPeter Avalos 	sa_length = osa_length - 4;
2106*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", sa_length);
2107ea7b4bf5SPeter Avalos 
2108411677aeSAaron LI 	/*
2109411677aeSAaron LI 	 * Print the payloads.
2110411677aeSAaron LI 	 */
2111411677aeSAaron LI 	cp = (const u_char *)(ext1 + 1);
2112411677aeSAaron LI 	pcount = 0;
2113*ed775ee7SAntonio Huete Jimenez 	for (np = ISAKMP_NPTYPE_P; np != 0; np = GET_U_1(ext->np)) {
2114411677aeSAaron LI 		pcount++;
2115411677aeSAaron LI 		ext = (const struct isakmp_gen *)cp;
2116411677aeSAaron LI 		if (sa_length < sizeof(*ext))
2117411677aeSAaron LI 			goto toolong;
2118*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_SIZE(ext);
2119ea7b4bf5SPeter Avalos 
2120411677aeSAaron LI 		/*
2121411677aeSAaron LI 		 * Since we can't have a payload length of less than 4 bytes,
2122411677aeSAaron LI 		 * we need to bail out here if the generic header is nonsensical
2123411677aeSAaron LI 		 * or truncated, otherwise we could loop forever processing
2124411677aeSAaron LI 		 * zero-length items or otherwise misdissect the packet.
2125411677aeSAaron LI 		 */
2126*ed775ee7SAntonio Huete Jimenez 		item_len = GET_BE_U_2(ext->len);
2127411677aeSAaron LI 		if (item_len <= 4)
2128411677aeSAaron LI 			goto trunc;
2129411677aeSAaron LI 
2130411677aeSAaron LI 		if (sa_length < item_len)
2131411677aeSAaron LI 			goto toolong;
2132*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(cp, item_len);
2133411677aeSAaron LI 
2134411677aeSAaron LI 		depth++;
2135*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n");
2136411677aeSAaron LI 		for (i = 0; i < depth; i++)
2137*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("    ");
2138*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("(");
2139411677aeSAaron LI 		if (np == ISAKMP_NPTYPE_P) {
2140411677aeSAaron LI 			cp = ikev2_p_print(ndo, np, pcount, ext, item_len,
2141411677aeSAaron LI 					   ep, depth);
2142411677aeSAaron LI 			if (cp == NULL) {
2143411677aeSAaron LI 				/* error, already reported */
2144411677aeSAaron LI 				return NULL;
2145411677aeSAaron LI 			}
2146411677aeSAaron LI 		} else {
2147*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%s", NPSTR(np));
2148411677aeSAaron LI 			cp += item_len;
2149411677aeSAaron LI 		}
2150*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(")");
2151411677aeSAaron LI 		depth--;
2152411677aeSAaron LI 		sa_length -= item_len;
2153411677aeSAaron LI 	}
2154411677aeSAaron LI 	return cp;
2155411677aeSAaron LI toolong:
2156411677aeSAaron LI 	/*
2157411677aeSAaron LI 	 * Skip the rest of the SA.
2158411677aeSAaron LI 	 */
2159411677aeSAaron LI 	cp += sa_length;
2160*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
2161411677aeSAaron LI 	return cp;
2162ea7b4bf5SPeter Avalos trunc:
2163*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
2164ea7b4bf5SPeter Avalos 	return NULL;
2165ea7b4bf5SPeter Avalos }
2166ea7b4bf5SPeter Avalos 
2167ea7b4bf5SPeter Avalos static const u_char *
ikev2_ke_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2168ea7b4bf5SPeter Avalos ikev2_ke_print(netdissect_options *ndo, u_char tpay,
2169ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2170*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2171411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2172411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2173ea7b4bf5SPeter Avalos {
2174411677aeSAaron LI 	const struct ikev2_ke *k;
2175ea7b4bf5SPeter Avalos 
2176411677aeSAaron LI 	k = (const struct ikev2_ke *)ext;
2177*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(k);
2178*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(k->h.critical));
2179ea7b4bf5SPeter Avalos 
2180*ed775ee7SAntonio Huete Jimenez 	if (item_len < 8) {
2181*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" len=%u < 8", item_len);
2182*ed775ee7SAntonio Huete Jimenez 		return (const u_char *)ext + item_len;
2183*ed775ee7SAntonio Huete Jimenez 	}
2184*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u group=%s", item_len - 8,
2185*ed775ee7SAntonio Huete Jimenez 		  STR_OR_ID(GET_BE_U_2(k->ke_group), dh_p_map));
2186ea7b4bf5SPeter Avalos 
2187*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && 8 < item_len) {
2188*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
2189*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(k + 1), item_len - 8))
2190ea7b4bf5SPeter Avalos 			goto trunc;
2191ea7b4bf5SPeter Avalos 	}
2192*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
2193ea7b4bf5SPeter Avalos trunc:
2194*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
2195ea7b4bf5SPeter Avalos 	return NULL;
2196ea7b4bf5SPeter Avalos }
2197ea7b4bf5SPeter Avalos 
2198ea7b4bf5SPeter Avalos static const u_char *
ikev2_ID_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2199ea7b4bf5SPeter Avalos ikev2_ID_print(netdissect_options *ndo, u_char tpay,
2200ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2201*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2202411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2203411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2204ea7b4bf5SPeter Avalos {
2205411677aeSAaron LI 	const struct ikev2_id *idp;
2206*ed775ee7SAntonio Huete Jimenez 	u_int idtype_len, i;
220727bfbee1SPeter Avalos 	unsigned int dumpascii, dumphex;
2208411677aeSAaron LI 	const unsigned char *typedata;
220927bfbee1SPeter Avalos 
2210411677aeSAaron LI 	idp = (const struct ikev2_id *)ext;
2211*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(idp);
2212*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(idp->h.critical));
221327bfbee1SPeter Avalos 
2214*ed775ee7SAntonio Huete Jimenez 	/*
2215*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
2216*ed775ee7SAntonio Huete Jimenez 	 */
2217*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
2218*ed775ee7SAntonio Huete Jimenez 	if (2 < ndo->ndo_vflag && 4 < item_len) {
2219411677aeSAaron LI 		/* Print the entire payload in hex */
2220*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
2221*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
222227bfbee1SPeter Avalos 			goto trunc;
222327bfbee1SPeter Avalos 	}
222427bfbee1SPeter Avalos 
2225*ed775ee7SAntonio Huete Jimenez 	idtype_len =item_len - sizeof(struct ikev2_id);
222627bfbee1SPeter Avalos 	dumpascii = 0;
222727bfbee1SPeter Avalos 	dumphex   = 0;
2228411677aeSAaron LI 	typedata  = (const unsigned char *)(ext)+sizeof(struct ikev2_id);
222927bfbee1SPeter Avalos 
2230*ed775ee7SAntonio Huete Jimenez 	switch(GET_U_1(idp->type)) {
223127bfbee1SPeter Avalos 	case ID_IPV4_ADDR:
2232*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ipv4:");
223327bfbee1SPeter Avalos 		dumphex=1;
223427bfbee1SPeter Avalos 		break;
223527bfbee1SPeter Avalos 	case ID_FQDN:
2236*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" fqdn:");
223727bfbee1SPeter Avalos 		dumpascii=1;
223827bfbee1SPeter Avalos 		break;
223927bfbee1SPeter Avalos 	case ID_RFC822_ADDR:
2240*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" rfc822:");
224127bfbee1SPeter Avalos 		dumpascii=1;
224227bfbee1SPeter Avalos 		break;
224327bfbee1SPeter Avalos 	case ID_IPV6_ADDR:
2244*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ipv6:");
224527bfbee1SPeter Avalos 		dumphex=1;
224627bfbee1SPeter Avalos 		break;
224727bfbee1SPeter Avalos 	case ID_DER_ASN1_DN:
2248*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" dn:");
224927bfbee1SPeter Avalos 		dumphex=1;
225027bfbee1SPeter Avalos 		break;
225127bfbee1SPeter Avalos 	case ID_DER_ASN1_GN:
2252*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" gn:");
225327bfbee1SPeter Avalos 		dumphex=1;
225427bfbee1SPeter Avalos 		break;
225527bfbee1SPeter Avalos 	case ID_KEY_ID:
2256*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" keyid:");
225727bfbee1SPeter Avalos 		dumphex=1;
225827bfbee1SPeter Avalos 		break;
225927bfbee1SPeter Avalos 	}
226027bfbee1SPeter Avalos 
226127bfbee1SPeter Avalos 	if(dumpascii) {
2262*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(typedata, idtype_len);
226327bfbee1SPeter Avalos 		for(i=0; i<idtype_len; i++) {
2264*ed775ee7SAntonio Huete Jimenez 			if(ND_ASCII_ISPRINT(GET_U_1(typedata + i))) {
2265*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%c", GET_U_1(typedata + i));
226627bfbee1SPeter Avalos 			} else {
2267*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(".");
226827bfbee1SPeter Avalos 			}
226927bfbee1SPeter Avalos 		}
227027bfbee1SPeter Avalos 	}
227127bfbee1SPeter Avalos 	if(dumphex) {
2272411677aeSAaron LI 		if (!rawprint(ndo, (const uint8_t *)typedata, idtype_len))
227327bfbee1SPeter Avalos 			goto trunc;
227427bfbee1SPeter Avalos 	}
227527bfbee1SPeter Avalos 
2276*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
227727bfbee1SPeter Avalos trunc:
2278*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
227927bfbee1SPeter Avalos 	return NULL;
2280ea7b4bf5SPeter Avalos }
2281ea7b4bf5SPeter Avalos 
2282ea7b4bf5SPeter Avalos static const u_char *
ikev2_cert_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2283ea7b4bf5SPeter Avalos ikev2_cert_print(netdissect_options *ndo, u_char tpay,
2284ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2285*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2286411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2287411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2288ea7b4bf5SPeter Avalos {
2289*ed775ee7SAntonio Huete Jimenez 	return ikev2_gen_print(ndo, tpay, ext, item_len);
2290ea7b4bf5SPeter Avalos }
2291ea7b4bf5SPeter Avalos 
2292ea7b4bf5SPeter Avalos static const u_char *
ikev2_cr_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2293ea7b4bf5SPeter Avalos ikev2_cr_print(netdissect_options *ndo, u_char tpay,
2294ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2295*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2296411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2297411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2298ea7b4bf5SPeter Avalos {
2299*ed775ee7SAntonio Huete Jimenez 	return ikev2_gen_print(ndo, tpay, ext, item_len);
2300ea7b4bf5SPeter Avalos }
2301ea7b4bf5SPeter Avalos 
2302ea7b4bf5SPeter Avalos static const u_char *
ikev2_auth_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2303ea7b4bf5SPeter Avalos ikev2_auth_print(netdissect_options *ndo, u_char tpay,
2304ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2305*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep,
2306411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2307411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2308ea7b4bf5SPeter Avalos {
2309*ed775ee7SAntonio Huete Jimenez 	const struct ikev2_auth *p;
2310ea7b4bf5SPeter Avalos 	const char *v2_auth[]={ "invalid", "rsasig",
2311ea7b4bf5SPeter Avalos 				"shared-secret", "dsssig" };
2312*ed775ee7SAntonio Huete Jimenez 	const u_char *authdata = (const u_char*)ext + sizeof(struct ikev2_auth);
2313ea7b4bf5SPeter Avalos 
2314*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_LEN(ext, sizeof(struct ikev2_auth));
2315*ed775ee7SAntonio Huete Jimenez 	p = (const struct ikev2_auth *)ext;
2316*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(p->h.critical));
2317ea7b4bf5SPeter Avalos 
2318411677aeSAaron LI 	/*
2319411677aeSAaron LI 	 * Our caller has ensured that the length is >= 4.
2320411677aeSAaron LI 	 */
2321*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u method=%s", item_len-4,
2322*ed775ee7SAntonio Huete Jimenez 		  STR_OR_ID(GET_U_1(p->auth_method), v2_auth));
2323*ed775ee7SAntonio Huete Jimenez 	if (item_len > 4) {
2324411677aeSAaron LI 		if (ndo->ndo_vflag > 1) {
2325*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" authdata=(");
2326*ed775ee7SAntonio Huete Jimenez 			if (!rawprint(ndo, (const uint8_t *)authdata, item_len - sizeof(struct ikev2_auth)))
2327ea7b4bf5SPeter Avalos 				goto trunc;
2328*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(") ");
2329411677aeSAaron LI 		} else if (ndo->ndo_vflag) {
2330411677aeSAaron LI 			if (!ike_show_somedata(ndo, authdata, ep))
2331411677aeSAaron LI 				goto trunc;
2332411677aeSAaron LI 		}
2333ea7b4bf5SPeter Avalos 	}
2334ea7b4bf5SPeter Avalos 
2335*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
2336ea7b4bf5SPeter Avalos trunc:
2337*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
2338ea7b4bf5SPeter Avalos 	return NULL;
2339ea7b4bf5SPeter Avalos }
2340ea7b4bf5SPeter Avalos 
2341ea7b4bf5SPeter Avalos static const u_char *
ikev2_nonce_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2342ea7b4bf5SPeter Avalos ikev2_nonce_print(netdissect_options *ndo, u_char tpay,
2343ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2344*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep,
2345411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2346411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2347ea7b4bf5SPeter Avalos {
2348*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
2349*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, "nonce", GET_U_1(ext->critical));
2350ea7b4bf5SPeter Avalos 
2351*ed775ee7SAntonio Huete Jimenez 	/*
2352*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
2353*ed775ee7SAntonio Huete Jimenez 	 */
2354*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", item_len - 4);
2355*ed775ee7SAntonio Huete Jimenez 	if (1 < ndo->ndo_vflag && 4 < item_len) {
2356*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" nonce=(");
2357*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
2358ea7b4bf5SPeter Avalos 			goto trunc;
2359*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(") ");
2360*ed775ee7SAntonio Huete Jimenez 	} else if(ndo->ndo_vflag && 4 < item_len) {
2361ea7b4bf5SPeter Avalos 		if(!ike_show_somedata(ndo, (const u_char *)(ext+1), ep)) goto trunc;
2362ea7b4bf5SPeter Avalos 	}
2363ea7b4bf5SPeter Avalos 
2364*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
2365ea7b4bf5SPeter Avalos trunc:
2366*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
2367ea7b4bf5SPeter Avalos 	return NULL;
2368ea7b4bf5SPeter Avalos }
2369ea7b4bf5SPeter Avalos 
2370ea7b4bf5SPeter Avalos /* notify payloads */
2371ea7b4bf5SPeter Avalos static const u_char *
ikev2_n_print(netdissect_options * ndo,u_char tpay _U_,const struct isakmp_gen * ext,u_int item_len,const u_char * ep,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2372ea7b4bf5SPeter Avalos ikev2_n_print(netdissect_options *ndo, u_char tpay _U_,
2373ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2374411677aeSAaron LI 		u_int item_len, const u_char *ep,
2375411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2376411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2377ea7b4bf5SPeter Avalos {
2378411677aeSAaron LI 	const struct ikev2_n *p;
2379*ed775ee7SAntonio Huete Jimenez 	uint16_t type;
2380*ed775ee7SAntonio Huete Jimenez 	uint8_t spi_size;
2381ea7b4bf5SPeter Avalos 	const u_char *cp;
2382411677aeSAaron LI 	u_char showspi, showsomedata;
2383ea7b4bf5SPeter Avalos 	const char *notify_name;
2384ea7b4bf5SPeter Avalos 
2385411677aeSAaron LI 	p = (const struct ikev2_n *)ext;
2386*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(p);
2387*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_N), GET_U_1(p->h.critical));
2388ea7b4bf5SPeter Avalos 
2389ea7b4bf5SPeter Avalos 	showspi = 1;
2390ea7b4bf5SPeter Avalos 	showsomedata=0;
2391ea7b4bf5SPeter Avalos 	notify_name=NULL;
2392ea7b4bf5SPeter Avalos 
2393*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" prot_id=%s", PROTOIDSTR(GET_U_1(p->prot_id)));
2394ea7b4bf5SPeter Avalos 
2395*ed775ee7SAntonio Huete Jimenez 	type = GET_BE_U_2(p->type);
2396ea7b4bf5SPeter Avalos 
2397ea7b4bf5SPeter Avalos 	/* notify space is annoying sparse */
2398ea7b4bf5SPeter Avalos 	switch(type) {
2399ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD:
2400ea7b4bf5SPeter Avalos 		notify_name = "unsupported_critical_payload";
2401ea7b4bf5SPeter Avalos 		showspi = 0;
2402ea7b4bf5SPeter Avalos 		break;
2403ea7b4bf5SPeter Avalos 
2404ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_IKE_SPI:
2405ea7b4bf5SPeter Avalos 		notify_name = "invalid_ike_spi";
2406ea7b4bf5SPeter Avalos 		showspi = 1;
2407ea7b4bf5SPeter Avalos 		break;
2408ea7b4bf5SPeter Avalos 
2409ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_MAJOR_VERSION:
2410ea7b4bf5SPeter Avalos 		notify_name = "invalid_major_version";
2411ea7b4bf5SPeter Avalos 		showspi = 0;
2412ea7b4bf5SPeter Avalos 		break;
2413ea7b4bf5SPeter Avalos 
2414ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_SYNTAX:
2415ea7b4bf5SPeter Avalos 		notify_name = "invalid_syntax";
2416ea7b4bf5SPeter Avalos 		showspi = 1;
2417ea7b4bf5SPeter Avalos 		break;
2418ea7b4bf5SPeter Avalos 
2419ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_MESSAGE_ID:
2420ea7b4bf5SPeter Avalos 		notify_name = "invalid_message_id";
2421ea7b4bf5SPeter Avalos 		showspi = 1;
2422ea7b4bf5SPeter Avalos 		break;
2423ea7b4bf5SPeter Avalos 
2424ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_SPI:
2425ea7b4bf5SPeter Avalos 		notify_name = "invalid_spi";
2426ea7b4bf5SPeter Avalos 		showspi = 1;
2427ea7b4bf5SPeter Avalos 		break;
2428ea7b4bf5SPeter Avalos 
2429ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_NO_PROPOSAL_CHOSEN:
2430ea7b4bf5SPeter Avalos 		notify_name = "no_protocol_chosen";
2431ea7b4bf5SPeter Avalos 		showspi = 1;
2432ea7b4bf5SPeter Avalos 		break;
2433ea7b4bf5SPeter Avalos 
2434ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_KE_PAYLOAD:
2435ea7b4bf5SPeter Avalos 		notify_name = "invalid_ke_payload";
2436ea7b4bf5SPeter Avalos 		showspi = 1;
2437ea7b4bf5SPeter Avalos 		break;
2438ea7b4bf5SPeter Avalos 
2439ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_AUTHENTICATION_FAILED:
2440ea7b4bf5SPeter Avalos 		notify_name = "authentication_failed";
2441ea7b4bf5SPeter Avalos 		showspi = 1;
2442ea7b4bf5SPeter Avalos 		break;
2443ea7b4bf5SPeter Avalos 
2444ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_SINGLE_PAIR_REQUIRED:
2445ea7b4bf5SPeter Avalos 		notify_name = "single_pair_required";
2446ea7b4bf5SPeter Avalos 		showspi = 1;
2447ea7b4bf5SPeter Avalos 		break;
2448ea7b4bf5SPeter Avalos 
2449ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_NO_ADDITIONAL_SAS:
2450ea7b4bf5SPeter Avalos 		notify_name = "no_additional_sas";
2451ea7b4bf5SPeter Avalos 		showspi = 0;
2452ea7b4bf5SPeter Avalos 		break;
2453ea7b4bf5SPeter Avalos 
2454ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE:
2455ea7b4bf5SPeter Avalos 		notify_name = "internal_address_failure";
2456ea7b4bf5SPeter Avalos 		showspi = 0;
2457ea7b4bf5SPeter Avalos 		break;
2458ea7b4bf5SPeter Avalos 
2459ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_FAILED_CP_REQUIRED:
2460ea7b4bf5SPeter Avalos 		notify_name = "failed:cp_required";
2461ea7b4bf5SPeter Avalos 		showspi = 0;
2462ea7b4bf5SPeter Avalos 		break;
2463ea7b4bf5SPeter Avalos 
2464ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INVALID_SELECTORS:
2465ea7b4bf5SPeter Avalos 		notify_name = "invalid_selectors";
2466ea7b4bf5SPeter Avalos 		showspi = 0;
2467ea7b4bf5SPeter Avalos 		break;
2468ea7b4bf5SPeter Avalos 
2469ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_INITIAL_CONTACT:
2470ea7b4bf5SPeter Avalos 		notify_name = "initial_contact";
2471ea7b4bf5SPeter Avalos 		showspi = 0;
2472ea7b4bf5SPeter Avalos 		break;
2473ea7b4bf5SPeter Avalos 
2474ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_SET_WINDOW_SIZE:
2475ea7b4bf5SPeter Avalos 		notify_name = "set_window_size";
2476ea7b4bf5SPeter Avalos 		showspi = 0;
2477ea7b4bf5SPeter Avalos 		break;
2478ea7b4bf5SPeter Avalos 
2479ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE:
2480ea7b4bf5SPeter Avalos 		notify_name = "additional_ts_possible";
2481ea7b4bf5SPeter Avalos 		showspi = 0;
2482ea7b4bf5SPeter Avalos 		break;
2483ea7b4bf5SPeter Avalos 
2484ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_IPCOMP_SUPPORTED:
2485ea7b4bf5SPeter Avalos 		notify_name = "ipcomp_supported";
2486ea7b4bf5SPeter Avalos 		showspi = 0;
2487ea7b4bf5SPeter Avalos 		break;
2488ea7b4bf5SPeter Avalos 
2489ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP:
2490ea7b4bf5SPeter Avalos 		notify_name = "nat_detection_source_ip";
2491ea7b4bf5SPeter Avalos 		showspi = 1;
2492ea7b4bf5SPeter Avalos 		break;
2493ea7b4bf5SPeter Avalos 
2494ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP:
2495ea7b4bf5SPeter Avalos 		notify_name = "nat_detection_destination_ip";
2496ea7b4bf5SPeter Avalos 		showspi = 1;
2497ea7b4bf5SPeter Avalos 		break;
2498ea7b4bf5SPeter Avalos 
2499ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_COOKIE:
2500ea7b4bf5SPeter Avalos 		notify_name = "cookie";
2501ea7b4bf5SPeter Avalos 		showspi = 1;
2502ea7b4bf5SPeter Avalos 		showsomedata= 1;
2503ea7b4bf5SPeter Avalos 		break;
2504ea7b4bf5SPeter Avalos 
2505ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_USE_TRANSPORT_MODE:
2506ea7b4bf5SPeter Avalos 		notify_name = "use_transport_mode";
2507ea7b4bf5SPeter Avalos 		showspi = 0;
2508ea7b4bf5SPeter Avalos 		break;
2509ea7b4bf5SPeter Avalos 
2510ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED:
2511ea7b4bf5SPeter Avalos 		notify_name = "http_cert_lookup_supported";
2512ea7b4bf5SPeter Avalos 		showspi = 0;
2513ea7b4bf5SPeter Avalos 		break;
2514ea7b4bf5SPeter Avalos 
2515ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_REKEY_SA:
2516ea7b4bf5SPeter Avalos 		notify_name = "rekey_sa";
2517ea7b4bf5SPeter Avalos 		showspi = 1;
2518ea7b4bf5SPeter Avalos 		break;
2519ea7b4bf5SPeter Avalos 
2520ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED:
2521ea7b4bf5SPeter Avalos 		notify_name = "tfc_padding_not_supported";
2522ea7b4bf5SPeter Avalos 		showspi = 0;
2523ea7b4bf5SPeter Avalos 		break;
2524ea7b4bf5SPeter Avalos 
2525ea7b4bf5SPeter Avalos 	case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO:
2526ea7b4bf5SPeter Avalos 		notify_name = "non_first_fragment_also";
2527ea7b4bf5SPeter Avalos 		showspi = 0;
2528ea7b4bf5SPeter Avalos 		break;
2529ea7b4bf5SPeter Avalos 
2530ea7b4bf5SPeter Avalos 	default:
2531ea7b4bf5SPeter Avalos 		if (type < 8192) {
2532ea7b4bf5SPeter Avalos 			notify_name="error";
2533ea7b4bf5SPeter Avalos 		} else if(type < 16384) {
2534ea7b4bf5SPeter Avalos 			notify_name="private-error";
2535ea7b4bf5SPeter Avalos 		} else if(type < 40960) {
2536ea7b4bf5SPeter Avalos 			notify_name="status";
2537ea7b4bf5SPeter Avalos 		} else {
2538ea7b4bf5SPeter Avalos 			notify_name="private-status";
2539ea7b4bf5SPeter Avalos 		}
2540ea7b4bf5SPeter Avalos 	}
2541ea7b4bf5SPeter Avalos 
2542ea7b4bf5SPeter Avalos 	if(notify_name) {
2543*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" type=%u(%s)", type, notify_name);
2544ea7b4bf5SPeter Avalos 	}
2545ea7b4bf5SPeter Avalos 
2546ea7b4bf5SPeter Avalos 
2547*ed775ee7SAntonio Huete Jimenez 	spi_size = GET_U_1(p->spi_size);
2548*ed775ee7SAntonio Huete Jimenez 	if (showspi && spi_size) {
2549*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" spi=");
2550*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
2551ea7b4bf5SPeter Avalos 			goto trunc;
2552ea7b4bf5SPeter Avalos 	}
2553ea7b4bf5SPeter Avalos 
2554*ed775ee7SAntonio Huete Jimenez 	cp = (const u_char *)(p + 1) + spi_size;
2555ea7b4bf5SPeter Avalos 
2556411677aeSAaron LI 	if (cp < ep) {
2557411677aeSAaron LI 		if (ndo->ndo_vflag > 3 || (showsomedata && ep-cp < 30)) {
2558*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" data=(");
2559411677aeSAaron LI 			if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
2560ea7b4bf5SPeter Avalos 				goto trunc;
2561ea7b4bf5SPeter Avalos 
2562*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(")");
2563411677aeSAaron LI 		} else if (showsomedata) {
2564411677aeSAaron LI 			if (!ike_show_somedata(ndo, cp, ep))
2565411677aeSAaron LI 				goto trunc;
2566411677aeSAaron LI 		}
2567ea7b4bf5SPeter Avalos 	}
2568ea7b4bf5SPeter Avalos 
2569411677aeSAaron LI 	return (const u_char *)ext + item_len;
2570ea7b4bf5SPeter Avalos trunc:
2571*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N));
2572ea7b4bf5SPeter Avalos 	return NULL;
2573ea7b4bf5SPeter Avalos }
2574ea7b4bf5SPeter Avalos 
2575ea7b4bf5SPeter Avalos static const u_char *
ikev2_d_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2576ea7b4bf5SPeter Avalos ikev2_d_print(netdissect_options *ndo, u_char tpay,
2577ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2578*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2579411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2580411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2581ea7b4bf5SPeter Avalos {
2582*ed775ee7SAntonio Huete Jimenez 	return ikev2_gen_print(ndo, tpay, ext, item_len);
2583ea7b4bf5SPeter Avalos }
2584ea7b4bf5SPeter Avalos 
2585ea7b4bf5SPeter Avalos static const u_char *
ikev2_vid_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2586ea7b4bf5SPeter Avalos ikev2_vid_print(netdissect_options *ndo, u_char tpay,
2587ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2588*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2589411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2590411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2591ea7b4bf5SPeter Avalos {
2592ea7b4bf5SPeter Avalos 	const u_char *vid;
2593*ed775ee7SAntonio Huete Jimenez 	u_int i, len;
2594ea7b4bf5SPeter Avalos 
2595*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
2596*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(ext->critical));
2597*ed775ee7SAntonio Huete Jimenez 
2598*ed775ee7SAntonio Huete Jimenez 	/*
2599*ed775ee7SAntonio Huete Jimenez 	 * Our caller has ensured that the length is >= 4.
2600*ed775ee7SAntonio Huete Jimenez 	 */
2601*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u vid=", item_len - 4);
2602ea7b4bf5SPeter Avalos 
2603ea7b4bf5SPeter Avalos 	vid = (const u_char *)(ext+1);
2604*ed775ee7SAntonio Huete Jimenez 	len = item_len - 4;
2605*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_LEN(vid, len);
2606ea7b4bf5SPeter Avalos 	for(i=0; i<len; i++) {
2607*ed775ee7SAntonio Huete Jimenez 		if(ND_ASCII_ISPRINT(GET_U_1(vid + i)))
2608*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%c", GET_U_1(vid + i));
2609*ed775ee7SAntonio Huete Jimenez 		else ND_PRINT(".");
2610ea7b4bf5SPeter Avalos 	}
2611ea7b4bf5SPeter Avalos 	if (2 < ndo->ndo_vflag && 4 < len) {
2612411677aeSAaron LI 		/* Print the entire payload in hex */
2613*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
2614*ed775ee7SAntonio Huete Jimenez 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
2615ea7b4bf5SPeter Avalos 			goto trunc;
2616ea7b4bf5SPeter Avalos 	}
2617*ed775ee7SAntonio Huete Jimenez 	return (const u_char *)ext + item_len;
2618ea7b4bf5SPeter Avalos trunc:
2619*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
2620ea7b4bf5SPeter Avalos 	return NULL;
2621ea7b4bf5SPeter Avalos }
2622ea7b4bf5SPeter Avalos 
2623ea7b4bf5SPeter Avalos static const u_char *
ikev2_TS_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2624ea7b4bf5SPeter Avalos ikev2_TS_print(netdissect_options *ndo, u_char tpay,
2625ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2626*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2627411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2628411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2629ea7b4bf5SPeter Avalos {
2630*ed775ee7SAntonio Huete Jimenez 	return ikev2_gen_print(ndo, tpay, ext, item_len);
2631ea7b4bf5SPeter Avalos }
2632ea7b4bf5SPeter Avalos 
2633ea7b4bf5SPeter Avalos static const u_char *
ikev2_e_print(netdissect_options * ndo,_U_ const struct isakmp * base,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,_U_ uint32_t phase,_U_ uint32_t doi,_U_ uint32_t proto,_U_ int depth)263427bfbee1SPeter Avalos ikev2_e_print(netdissect_options *ndo,
263527bfbee1SPeter Avalos #ifndef HAVE_LIBCRYPTO
263627bfbee1SPeter Avalos 	      _U_
263727bfbee1SPeter Avalos #endif
2638*ed775ee7SAntonio Huete Jimenez 	      const struct isakmp *base,
263927bfbee1SPeter Avalos 	      u_char tpay,
2640ea7b4bf5SPeter Avalos 	      const struct isakmp_gen *ext,
2641*ed775ee7SAntonio Huete Jimenez 	      u_int item_len, const u_char *ep _U_,
264227bfbee1SPeter Avalos #ifndef HAVE_LIBCRYPTO
264327bfbee1SPeter Avalos 	      _U_
264427bfbee1SPeter Avalos #endif
2645411677aeSAaron LI 	      uint32_t phase,
264627bfbee1SPeter Avalos #ifndef HAVE_LIBCRYPTO
264727bfbee1SPeter Avalos 	      _U_
264827bfbee1SPeter Avalos #endif
2649411677aeSAaron LI 	      uint32_t doi,
265027bfbee1SPeter Avalos #ifndef HAVE_LIBCRYPTO
265127bfbee1SPeter Avalos 	      _U_
265227bfbee1SPeter Avalos #endif
2653411677aeSAaron LI 	      uint32_t proto,
265427bfbee1SPeter Avalos #ifndef HAVE_LIBCRYPTO
265527bfbee1SPeter Avalos 	      _U_
265627bfbee1SPeter Avalos #endif
265727bfbee1SPeter Avalos 	      int depth)
2658ea7b4bf5SPeter Avalos {
2659411677aeSAaron LI 	const u_char *dat;
2660*ed775ee7SAntonio Huete Jimenez 	u_int dlen;
2661*ed775ee7SAntonio Huete Jimenez #ifdef HAVE_LIBCRYPTO
2662*ed775ee7SAntonio Huete Jimenez 	uint8_t np;
2663*ed775ee7SAntonio Huete Jimenez #endif
266427bfbee1SPeter Avalos 
2665*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
2666*ed775ee7SAntonio Huete Jimenez 	ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(ext->critical));
266727bfbee1SPeter Avalos 
2668*ed775ee7SAntonio Huete Jimenez 	dlen = item_len-4;
266927bfbee1SPeter Avalos 
2670*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" len=%u", dlen);
267127bfbee1SPeter Avalos 	if (2 < ndo->ndo_vflag && 4 < dlen) {
2672*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ");
2673411677aeSAaron LI 		if (!rawprint(ndo, (const uint8_t *)(ext + 1), dlen))
267427bfbee1SPeter Avalos 			goto trunc;
267527bfbee1SPeter Avalos 	}
267627bfbee1SPeter Avalos 
2677411677aeSAaron LI 	dat = (const u_char *)(ext+1);
2678*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_LEN(dat, dlen);
267927bfbee1SPeter Avalos 
268027bfbee1SPeter Avalos #ifdef HAVE_LIBCRYPTO
2681*ed775ee7SAntonio Huete Jimenez 	np = GET_U_1(ext->np);
2682*ed775ee7SAntonio Huete Jimenez 
2683*ed775ee7SAntonio Huete Jimenez 	/* try to decrypt it! */
2684*ed775ee7SAntonio Huete Jimenez 	if(esp_decrypt_buffer_by_ikev2_print(ndo,
2685*ed775ee7SAntonio Huete Jimenez 					     GET_U_1(base->flags) & ISAKMP_FLAG_I,
268627bfbee1SPeter Avalos 					     base->i_ck, base->r_ck,
268727bfbee1SPeter Avalos 					     dat, dat+dlen)) {
268827bfbee1SPeter Avalos 
268927bfbee1SPeter Avalos 		ext = (const struct isakmp_gen *)ndo->ndo_packetp;
269027bfbee1SPeter Avalos 
269127bfbee1SPeter Avalos 		/* got it decrypted, print stuff inside. */
2692*ed775ee7SAntonio Huete Jimenez 		ikev2_sub_print(ndo, base, np, ext,
2693*ed775ee7SAntonio Huete Jimenez 				ndo->ndo_snapend, phase, doi, proto, depth+1);
2694*ed775ee7SAntonio Huete Jimenez 
2695*ed775ee7SAntonio Huete Jimenez 		/*
2696*ed775ee7SAntonio Huete Jimenez 		 * esp_decrypt_buffer_by_ikev2_print pushed information
2697*ed775ee7SAntonio Huete Jimenez 		 * on the buffer stack; we're done with the buffer, so
2698*ed775ee7SAntonio Huete Jimenez 		 * pop it (which frees the buffer)
2699*ed775ee7SAntonio Huete Jimenez 		 */
2700*ed775ee7SAntonio Huete Jimenez 		nd_pop_packet_info(ndo);
270127bfbee1SPeter Avalos 	}
270227bfbee1SPeter Avalos #endif
270327bfbee1SPeter Avalos 
270427bfbee1SPeter Avalos 
270527bfbee1SPeter Avalos 	/* always return NULL, because E must be at end, and NP refers
270627bfbee1SPeter Avalos 	 * to what was inside.
270727bfbee1SPeter Avalos 	 */
270827bfbee1SPeter Avalos 	return NULL;
270927bfbee1SPeter Avalos trunc:
2710*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(tpay));
271127bfbee1SPeter Avalos 	return NULL;
2712ea7b4bf5SPeter Avalos }
2713ea7b4bf5SPeter Avalos 
2714ea7b4bf5SPeter Avalos static const u_char *
ikev2_cp_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2715ea7b4bf5SPeter Avalos ikev2_cp_print(netdissect_options *ndo, u_char tpay,
2716ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2717*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2718411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2719411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2720ea7b4bf5SPeter Avalos {
2721*ed775ee7SAntonio Huete Jimenez 	return ikev2_gen_print(ndo, tpay, ext, item_len);
2722ea7b4bf5SPeter Avalos }
2723ea7b4bf5SPeter Avalos 
2724ea7b4bf5SPeter Avalos static const u_char *
ikev2_eap_print(netdissect_options * ndo,u_char tpay,const struct isakmp_gen * ext,u_int item_len,const u_char * ep _U_,uint32_t phase _U_,uint32_t doi _U_,uint32_t proto _U_,int depth _U_)2725ea7b4bf5SPeter Avalos ikev2_eap_print(netdissect_options *ndo, u_char tpay,
2726ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext,
2727*ed775ee7SAntonio Huete Jimenez 		u_int item_len, const u_char *ep _U_,
2728411677aeSAaron LI 		uint32_t phase _U_, uint32_t doi _U_,
2729411677aeSAaron LI 		uint32_t proto _U_, int depth _U_)
2730ea7b4bf5SPeter Avalos {
2731*ed775ee7SAntonio Huete Jimenez 	return ikev2_gen_print(ndo, tpay, ext, item_len);
2732ea7b4bf5SPeter Avalos }
2733ea7b4bf5SPeter Avalos 
2734ea7b4bf5SPeter Avalos static const u_char *
ike_sub0_print(netdissect_options * ndo,u_char np,const struct isakmp_gen * ext,const u_char * ep,uint32_t phase,uint32_t doi,uint32_t proto,int depth)2735ea7b4bf5SPeter Avalos ike_sub0_print(netdissect_options *ndo,
2736ea7b4bf5SPeter Avalos 		 u_char np, const struct isakmp_gen *ext, const u_char *ep,
273727bfbee1SPeter Avalos 
2738411677aeSAaron LI 	       uint32_t phase, uint32_t doi, uint32_t proto, int depth)
273941c99275SPeter Avalos {
274041c99275SPeter Avalos 	const u_char *cp;
274141c99275SPeter Avalos 	u_int item_len;
274241c99275SPeter Avalos 
2743411677aeSAaron LI 	cp = (const u_char *)ext;
2744*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
274541c99275SPeter Avalos 
274641c99275SPeter Avalos 	/*
274741c99275SPeter Avalos 	 * Since we can't have a payload length of less than 4 bytes,
274841c99275SPeter Avalos 	 * we need to bail out here if the generic header is nonsensical
274941c99275SPeter Avalos 	 * or truncated, otherwise we could loop forever processing
275041c99275SPeter Avalos 	 * zero-length items or otherwise misdissect the packet.
275141c99275SPeter Avalos 	 */
2752*ed775ee7SAntonio Huete Jimenez 	item_len = GET_BE_U_2(ext->len);
275341c99275SPeter Avalos 	if (item_len <= 4)
275441c99275SPeter Avalos 		return NULL;
275541c99275SPeter Avalos 
275641c99275SPeter Avalos 	if (NPFUNC(np)) {
275741c99275SPeter Avalos 		/*
275841c99275SPeter Avalos 		 * XXX - what if item_len is too short, or too long,
275941c99275SPeter Avalos 		 * for this payload type?
276041c99275SPeter Avalos 		 */
2761ea7b4bf5SPeter Avalos 		cp = (*npfunc[np])(ndo, np, ext, item_len, ep, phase, doi, proto, depth);
276241c99275SPeter Avalos 	} else {
2763*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("%s", NPSTR(np));
276441c99275SPeter Avalos 		cp += item_len;
276541c99275SPeter Avalos 	}
276641c99275SPeter Avalos 
276741c99275SPeter Avalos 	return cp;
276841c99275SPeter Avalos trunc:
2769*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
277041c99275SPeter Avalos 	return NULL;
277141c99275SPeter Avalos }
277241c99275SPeter Avalos 
277341c99275SPeter Avalos static const u_char *
ikev1_sub_print(netdissect_options * ndo,u_char np,const struct isakmp_gen * ext,const u_char * ep,uint32_t phase,uint32_t doi,uint32_t proto,int depth)2774ea7b4bf5SPeter Avalos ikev1_sub_print(netdissect_options *ndo,
2775ea7b4bf5SPeter Avalos 		u_char np, const struct isakmp_gen *ext, const u_char *ep,
2776411677aeSAaron LI 		uint32_t phase, uint32_t doi, uint32_t proto, int depth)
277741c99275SPeter Avalos {
277841c99275SPeter Avalos 	const u_char *cp;
277941c99275SPeter Avalos 	int i;
2780*ed775ee7SAntonio Huete Jimenez 	u_int item_len;
278141c99275SPeter Avalos 
278241c99275SPeter Avalos 	cp = (const u_char *)ext;
278341c99275SPeter Avalos 
278441c99275SPeter Avalos 	while (np) {
2785*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_SIZE(ext);
278641c99275SPeter Avalos 
2787*ed775ee7SAntonio Huete Jimenez 		item_len = GET_BE_U_2(ext->len);
2788*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(ext, item_len);
278941c99275SPeter Avalos 
279041c99275SPeter Avalos 		depth++;
2791*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n");
279241c99275SPeter Avalos 		for (i = 0; i < depth; i++)
2793*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("    ");
2794*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("(");
2795ea7b4bf5SPeter Avalos 		cp = ike_sub0_print(ndo, np, ext, ep, phase, doi, proto, depth);
2796*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(")");
279741c99275SPeter Avalos 		depth--;
279841c99275SPeter Avalos 
279941c99275SPeter Avalos 		if (cp == NULL) {
280041c99275SPeter Avalos 			/* Zero-length subitem */
280141c99275SPeter Avalos 			return NULL;
280241c99275SPeter Avalos 		}
280341c99275SPeter Avalos 
2804*ed775ee7SAntonio Huete Jimenez 		np = GET_U_1(ext->np);
2805411677aeSAaron LI 		ext = (const struct isakmp_gen *)cp;
280641c99275SPeter Avalos 	}
280741c99275SPeter Avalos 	return cp;
280841c99275SPeter Avalos trunc:
2809*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(np));
281041c99275SPeter Avalos 	return NULL;
281141c99275SPeter Avalos }
281241c99275SPeter Avalos 
281341c99275SPeter Avalos static char *
numstr(u_int x)2814*ed775ee7SAntonio Huete Jimenez numstr(u_int x)
281541c99275SPeter Avalos {
281641c99275SPeter Avalos 	static char buf[20];
2817*ed775ee7SAntonio Huete Jimenez 	snprintf(buf, sizeof(buf), "#%u", x);
281841c99275SPeter Avalos 	return buf;
281941c99275SPeter Avalos }
282041c99275SPeter Avalos 
282127bfbee1SPeter Avalos static void
ikev1_print(netdissect_options * ndo,const u_char * bp,u_int length,const u_char * bp2,const struct isakmp * base)2822ea7b4bf5SPeter Avalos ikev1_print(netdissect_options *ndo,
2823ea7b4bf5SPeter Avalos 	    const u_char *bp,  u_int length,
2824*ed775ee7SAntonio Huete Jimenez 	    const u_char *bp2, const struct isakmp *base)
2825ea7b4bf5SPeter Avalos {
2826ea7b4bf5SPeter Avalos 	const struct isakmp *p;
2827ea7b4bf5SPeter Avalos 	const u_char *ep;
2828*ed775ee7SAntonio Huete Jimenez 	u_int flags;
2829ea7b4bf5SPeter Avalos 	u_char np;
2830ea7b4bf5SPeter Avalos 	int i;
2831*ed775ee7SAntonio Huete Jimenez 	u_int phase;
2832ea7b4bf5SPeter Avalos 
2833ea7b4bf5SPeter Avalos 	p = (const struct isakmp *)bp;
2834ea7b4bf5SPeter Avalos 	ep = ndo->ndo_snapend;
2835ea7b4bf5SPeter Avalos 
2836*ed775ee7SAntonio Huete Jimenez 	phase = (GET_BE_U_4(base->msgid) == 0) ? 1 : 2;
2837ea7b4bf5SPeter Avalos 	if (phase == 1)
2838*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" phase %u", phase);
2839ea7b4bf5SPeter Avalos 	else
2840*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" phase %u/others", phase);
2841ea7b4bf5SPeter Avalos 
2842ea7b4bf5SPeter Avalos 	i = cookie_find(&base->i_ck);
2843ea7b4bf5SPeter Avalos 	if (i < 0) {
2844411677aeSAaron LI 		if (iszero((const u_char *)&base->r_ck, sizeof(base->r_ck))) {
2845ea7b4bf5SPeter Avalos 			/* the first packet */
2846*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" I");
2847ea7b4bf5SPeter Avalos 			if (bp2)
2848*ed775ee7SAntonio Huete Jimenez 				cookie_record(ndo, &base->i_ck, bp2);
2849ea7b4bf5SPeter Avalos 		} else
2850*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" ?");
2851ea7b4bf5SPeter Avalos 	} else {
2852*ed775ee7SAntonio Huete Jimenez 		if (bp2 && cookie_isinitiator(ndo, i, bp2))
2853*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" I");
2854*ed775ee7SAntonio Huete Jimenez 		else if (bp2 && cookie_isresponder(ndo, i, bp2))
2855*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" R");
2856ea7b4bf5SPeter Avalos 		else
2857*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" ?");
2858ea7b4bf5SPeter Avalos 	}
2859ea7b4bf5SPeter Avalos 
2860*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" %s", ETYPESTR(GET_U_1(base->etype)));
2861*ed775ee7SAntonio Huete Jimenez 	flags = GET_U_1(base->flags);
2862*ed775ee7SAntonio Huete Jimenez 	if (flags) {
2863*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[%s%s]", flags & ISAKMP_FLAG_E ? "E" : "",
2864*ed775ee7SAntonio Huete Jimenez 			  flags & ISAKMP_FLAG_C ? "C" : "");
2865ea7b4bf5SPeter Avalos 	}
2866ea7b4bf5SPeter Avalos 
2867ea7b4bf5SPeter Avalos 	if (ndo->ndo_vflag) {
2868ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext;
2869ea7b4bf5SPeter Avalos 
2870*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(":");
2871*ed775ee7SAntonio Huete Jimenez 
2872*ed775ee7SAntonio Huete Jimenez 		np = GET_U_1(base->np);
2873ea7b4bf5SPeter Avalos 
2874ea7b4bf5SPeter Avalos 		/* regardless of phase... */
2875*ed775ee7SAntonio Huete Jimenez 		if (flags & ISAKMP_FLAG_E) {
2876ea7b4bf5SPeter Avalos 			/*
2877ea7b4bf5SPeter Avalos 			 * encrypted, nothing we can do right now.
2878ea7b4bf5SPeter Avalos 			 * we hope to decrypt the packet in the future...
2879ea7b4bf5SPeter Avalos 			 */
2880*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" [encrypted %s]", NPSTR(np));
2881ea7b4bf5SPeter Avalos 			goto done;
2882ea7b4bf5SPeter Avalos 		}
2883ea7b4bf5SPeter Avalos 
2884*ed775ee7SAntonio Huete Jimenez 		CHECKLEN(p + 1, np);
2885411677aeSAaron LI 		ext = (const struct isakmp_gen *)(p + 1);
2886ea7b4bf5SPeter Avalos 		ikev1_sub_print(ndo, np, ext, ep, phase, 0, 0, 0);
2887ea7b4bf5SPeter Avalos 	}
2888ea7b4bf5SPeter Avalos 
2889ea7b4bf5SPeter Avalos done:
2890ea7b4bf5SPeter Avalos 	if (ndo->ndo_vflag) {
2891*ed775ee7SAntonio Huete Jimenez 		if (GET_BE_U_4(base->len) != length) {
2892*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
2893*ed775ee7SAntonio Huete Jimenez 				  GET_BE_U_4(base->len), length);
2894ea7b4bf5SPeter Avalos 		}
2895ea7b4bf5SPeter Avalos 	}
2896ea7b4bf5SPeter Avalos }
2897ea7b4bf5SPeter Avalos 
2898ea7b4bf5SPeter Avalos static const u_char *
ikev2_sub0_print(netdissect_options * ndo,const struct isakmp * base,u_char np,const struct isakmp_gen * ext,const u_char * ep,uint32_t phase,uint32_t doi,uint32_t proto,int depth)2899*ed775ee7SAntonio Huete Jimenez ikev2_sub0_print(netdissect_options *ndo, const struct isakmp *base,
2900411677aeSAaron LI 		 u_char np,
2901ea7b4bf5SPeter Avalos 		 const struct isakmp_gen *ext, const u_char *ep,
2902411677aeSAaron LI 		 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
2903ea7b4bf5SPeter Avalos {
2904ea7b4bf5SPeter Avalos 	const u_char *cp;
2905ea7b4bf5SPeter Avalos 	u_int item_len;
2906ea7b4bf5SPeter Avalos 
2907411677aeSAaron LI 	cp = (const u_char *)ext;
2908*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_SIZE(ext);
2909ea7b4bf5SPeter Avalos 
2910ea7b4bf5SPeter Avalos 	/*
2911ea7b4bf5SPeter Avalos 	 * Since we can't have a payload length of less than 4 bytes,
2912ea7b4bf5SPeter Avalos 	 * we need to bail out here if the generic header is nonsensical
2913ea7b4bf5SPeter Avalos 	 * or truncated, otherwise we could loop forever processing
2914ea7b4bf5SPeter Avalos 	 * zero-length items or otherwise misdissect the packet.
2915ea7b4bf5SPeter Avalos 	 */
2916*ed775ee7SAntonio Huete Jimenez 	item_len = GET_BE_U_2(ext->len);
2917ea7b4bf5SPeter Avalos 	if (item_len <= 4)
2918ea7b4bf5SPeter Avalos 		return NULL;
2919ea7b4bf5SPeter Avalos 
2920411677aeSAaron LI 	if (np == ISAKMP_NPTYPE_v2E) {
292127bfbee1SPeter Avalos 		cp = ikev2_e_print(ndo, base, np, ext, item_len,
292227bfbee1SPeter Avalos 				   ep, phase, doi, proto, depth);
2923ea7b4bf5SPeter Avalos 	} else if (NPFUNC(np)) {
2924ea7b4bf5SPeter Avalos 		/*
2925ea7b4bf5SPeter Avalos 		 * XXX - what if item_len is too short, or too long,
2926ea7b4bf5SPeter Avalos 		 * for this payload type?
2927ea7b4bf5SPeter Avalos 		 */
2928411677aeSAaron LI 		cp = (*npfunc[np])(ndo, np, ext, item_len,
2929ea7b4bf5SPeter Avalos 				   ep, phase, doi, proto, depth);
2930ea7b4bf5SPeter Avalos 	} else {
2931*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("%s", NPSTR(np));
2932ea7b4bf5SPeter Avalos 		cp += item_len;
2933ea7b4bf5SPeter Avalos 	}
2934ea7b4bf5SPeter Avalos 
2935ea7b4bf5SPeter Avalos 	return cp;
2936ea7b4bf5SPeter Avalos trunc:
2937*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
2938ea7b4bf5SPeter Avalos 	return NULL;
2939ea7b4bf5SPeter Avalos }
2940ea7b4bf5SPeter Avalos 
2941ea7b4bf5SPeter Avalos static const u_char *
ikev2_sub_print(netdissect_options * ndo,const struct isakmp * base,u_char np,const struct isakmp_gen * ext,const u_char * ep,uint32_t phase,uint32_t doi,uint32_t proto,int depth)2942ea7b4bf5SPeter Avalos ikev2_sub_print(netdissect_options *ndo,
2943*ed775ee7SAntonio Huete Jimenez 		const struct isakmp *base,
2944ea7b4bf5SPeter Avalos 		u_char np, const struct isakmp_gen *ext, const u_char *ep,
2945411677aeSAaron LI 		uint32_t phase, uint32_t doi, uint32_t proto, int depth)
2946ea7b4bf5SPeter Avalos {
2947ea7b4bf5SPeter Avalos 	const u_char *cp;
2948ea7b4bf5SPeter Avalos 	int i;
2949ea7b4bf5SPeter Avalos 
2950ea7b4bf5SPeter Avalos 	cp = (const u_char *)ext;
2951ea7b4bf5SPeter Avalos 	while (np) {
2952*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_SIZE(ext);
2953ea7b4bf5SPeter Avalos 
2954*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(ext, GET_BE_U_2(ext->len));
2955ea7b4bf5SPeter Avalos 
2956ea7b4bf5SPeter Avalos 		depth++;
2957*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n");
2958ea7b4bf5SPeter Avalos 		for (i = 0; i < depth; i++)
2959*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("    ");
2960*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("(");
2961411677aeSAaron LI 		cp = ikev2_sub0_print(ndo, base, np,
2962ea7b4bf5SPeter Avalos 				      ext, ep, phase, doi, proto, depth);
2963*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(")");
2964ea7b4bf5SPeter Avalos 		depth--;
2965ea7b4bf5SPeter Avalos 
2966ea7b4bf5SPeter Avalos 		if (cp == NULL) {
2967ea7b4bf5SPeter Avalos 			/* Zero-length subitem */
2968ea7b4bf5SPeter Avalos 			return NULL;
2969ea7b4bf5SPeter Avalos 		}
2970ea7b4bf5SPeter Avalos 
2971*ed775ee7SAntonio Huete Jimenez 		np = GET_U_1(ext->np);
2972411677aeSAaron LI 		ext = (const struct isakmp_gen *)cp;
2973ea7b4bf5SPeter Avalos 	}
2974ea7b4bf5SPeter Avalos 	return cp;
2975ea7b4bf5SPeter Avalos trunc:
2976*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" [|%s]", NPSTR(np));
2977ea7b4bf5SPeter Avalos 	return NULL;
2978ea7b4bf5SPeter Avalos }
2979ea7b4bf5SPeter Avalos 
2980ea7b4bf5SPeter Avalos static void
ikev2_print(netdissect_options * ndo,const u_char * bp,u_int length,const u_char * bp2 _U_,const struct isakmp * base)2981ea7b4bf5SPeter Avalos ikev2_print(netdissect_options *ndo,
2982ea7b4bf5SPeter Avalos 	    const u_char *bp,  u_int length,
2983*ed775ee7SAntonio Huete Jimenez 	    const u_char *bp2 _U_, const struct isakmp *base)
2984ea7b4bf5SPeter Avalos {
2985ea7b4bf5SPeter Avalos 	const struct isakmp *p;
2986ea7b4bf5SPeter Avalos 	const u_char *ep;
2987*ed775ee7SAntonio Huete Jimenez 	uint8_t flags;
2988ea7b4bf5SPeter Avalos 	u_char np;
2989*ed775ee7SAntonio Huete Jimenez 	u_int phase;
2990ea7b4bf5SPeter Avalos 
2991ea7b4bf5SPeter Avalos 	p = (const struct isakmp *)bp;
2992ea7b4bf5SPeter Avalos 	ep = ndo->ndo_snapend;
2993ea7b4bf5SPeter Avalos 
2994*ed775ee7SAntonio Huete Jimenez 	phase = (GET_BE_U_4(base->msgid) == 0) ? 1 : 2;
2995ea7b4bf5SPeter Avalos 	if (phase == 1)
2996*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" parent_sa");
2997ea7b4bf5SPeter Avalos 	else
2998*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" child_sa ");
2999ea7b4bf5SPeter Avalos 
3000*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" %s", ETYPESTR(GET_U_1(base->etype)));
3001*ed775ee7SAntonio Huete Jimenez 	flags = GET_U_1(base->flags);
3002*ed775ee7SAntonio Huete Jimenez 	if (flags) {
3003*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[%s%s%s]",
3004*ed775ee7SAntonio Huete Jimenez 			  flags & ISAKMP_FLAG_I ? "I" : "",
3005*ed775ee7SAntonio Huete Jimenez 			  flags & ISAKMP_FLAG_V ? "V" : "",
3006*ed775ee7SAntonio Huete Jimenez 			  flags & ISAKMP_FLAG_R ? "R" : "");
3007ea7b4bf5SPeter Avalos 	}
3008ea7b4bf5SPeter Avalos 
3009ea7b4bf5SPeter Avalos 	if (ndo->ndo_vflag) {
3010ea7b4bf5SPeter Avalos 		const struct isakmp_gen *ext;
3011ea7b4bf5SPeter Avalos 
3012*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(":");
3013*ed775ee7SAntonio Huete Jimenez 
3014*ed775ee7SAntonio Huete Jimenez 		np = GET_U_1(base->np);
3015ea7b4bf5SPeter Avalos 
3016ea7b4bf5SPeter Avalos 		/* regardless of phase... */
3017*ed775ee7SAntonio Huete Jimenez 		if (flags & ISAKMP_FLAG_E) {
3018ea7b4bf5SPeter Avalos 			/*
3019ea7b4bf5SPeter Avalos 			 * encrypted, nothing we can do right now.
3020ea7b4bf5SPeter Avalos 			 * we hope to decrypt the packet in the future...
3021ea7b4bf5SPeter Avalos 			 */
3022*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" [encrypted %s]", NPSTR(np));
3023ea7b4bf5SPeter Avalos 			goto done;
3024ea7b4bf5SPeter Avalos 		}
3025ea7b4bf5SPeter Avalos 
3026*ed775ee7SAntonio Huete Jimenez 		CHECKLEN(p + 1, np)
3027411677aeSAaron LI 		ext = (const struct isakmp_gen *)(p + 1);
302827bfbee1SPeter Avalos 		ikev2_sub_print(ndo, base, np, ext, ep, phase, 0, 0, 0);
3029ea7b4bf5SPeter Avalos 	}
3030ea7b4bf5SPeter Avalos 
3031ea7b4bf5SPeter Avalos done:
3032ea7b4bf5SPeter Avalos 	if (ndo->ndo_vflag) {
3033*ed775ee7SAntonio Huete Jimenez 		if (GET_BE_U_4(base->len) != length) {
3034*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
3035*ed775ee7SAntonio Huete Jimenez 				  GET_BE_U_4(base->len), length);
3036ea7b4bf5SPeter Avalos 		}
3037ea7b4bf5SPeter Avalos 	}
3038ea7b4bf5SPeter Avalos }
3039ea7b4bf5SPeter Avalos 
3040ea7b4bf5SPeter Avalos void
isakmp_print(netdissect_options * ndo,const u_char * bp,u_int length,const u_char * bp2)304141c99275SPeter Avalos isakmp_print(netdissect_options *ndo,
304241c99275SPeter Avalos 	     const u_char *bp, u_int length,
304341c99275SPeter Avalos 	     const u_char *bp2)
304441c99275SPeter Avalos {
304541c99275SPeter Avalos 	const struct isakmp *p;
304641c99275SPeter Avalos 	const u_char *ep;
3047*ed775ee7SAntonio Huete Jimenez 	u_int major, minor;
304841c99275SPeter Avalos 
3049*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "isakmp";
305027bfbee1SPeter Avalos #ifdef HAVE_LIBCRYPTO
305127bfbee1SPeter Avalos 	/* initialize SAs */
305227bfbee1SPeter Avalos 	if (ndo->ndo_sa_list_head == NULL) {
305327bfbee1SPeter Avalos 		if (ndo->ndo_espsecret)
3054*ed775ee7SAntonio Huete Jimenez 			esp_decodesecret_print(ndo);
305527bfbee1SPeter Avalos 	}
305627bfbee1SPeter Avalos #endif
305727bfbee1SPeter Avalos 
305841c99275SPeter Avalos 	p = (const struct isakmp *)bp;
305941c99275SPeter Avalos 	ep = ndo->ndo_snapend;
306041c99275SPeter Avalos 
3061411677aeSAaron LI 	if ((const struct isakmp *)ep < p + 1) {
3062*ed775ee7SAntonio Huete Jimenez 		nd_print_trunc(ndo);
306341c99275SPeter Avalos 		return;
306441c99275SPeter Avalos 	}
306541c99275SPeter Avalos 
3066*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("isakmp");
3067*ed775ee7SAntonio Huete Jimenez 	major = (GET_U_1(p->vers) & ISAKMP_VERS_MAJOR)
306841c99275SPeter Avalos 		>> ISAKMP_VERS_MAJOR_SHIFT;
3069*ed775ee7SAntonio Huete Jimenez 	minor = (GET_U_1(p->vers) & ISAKMP_VERS_MINOR)
307041c99275SPeter Avalos 		>> ISAKMP_VERS_MINOR_SHIFT;
3071ea7b4bf5SPeter Avalos 
3072ea7b4bf5SPeter Avalos 	if (ndo->ndo_vflag) {
3073*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" %u.%u", major, minor);
307441c99275SPeter Avalos 	}
307541c99275SPeter Avalos 
3076ea7b4bf5SPeter Avalos 	if (ndo->ndo_vflag) {
3077*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" msgid ");
3078*ed775ee7SAntonio Huete Jimenez 		hexprint(ndo, p->msgid, sizeof(p->msgid));
307941c99275SPeter Avalos 	}
308041c99275SPeter Avalos 
3081ea7b4bf5SPeter Avalos 	if (1 < ndo->ndo_vflag) {
3082*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" cookie ");
3083*ed775ee7SAntonio Huete Jimenez 		hexprint(ndo, p->i_ck, sizeof(p->i_ck));
3084*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("->");
3085*ed775ee7SAntonio Huete Jimenez 		hexprint(ndo, p->r_ck, sizeof(p->r_ck));
308641c99275SPeter Avalos 	}
3087*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(":");
308841c99275SPeter Avalos 
3089ea7b4bf5SPeter Avalos 	switch(major) {
3090ea7b4bf5SPeter Avalos 	case IKEv1_MAJOR_VERSION:
3091*ed775ee7SAntonio Huete Jimenez 		ikev1_print(ndo, bp, length, bp2, p);
3092ea7b4bf5SPeter Avalos 		break;
309341c99275SPeter Avalos 
3094ea7b4bf5SPeter Avalos 	case IKEv2_MAJOR_VERSION:
3095*ed775ee7SAntonio Huete Jimenez 		ikev2_print(ndo, bp, length, bp2, p);
3096ea7b4bf5SPeter Avalos 		break;
309741c99275SPeter Avalos 	}
309841c99275SPeter Avalos }
309941c99275SPeter Avalos 
310041c99275SPeter Avalos void
isakmp_rfc3948_print(netdissect_options * ndo,const u_char * bp,u_int length,const u_char * bp2,int ver,int fragmented,u_int ttl_hl)310141c99275SPeter Avalos isakmp_rfc3948_print(netdissect_options *ndo,
310241c99275SPeter Avalos 		     const u_char *bp, u_int length,
3103*ed775ee7SAntonio Huete Jimenez 		     const u_char *bp2, int ver, int fragmented, u_int ttl_hl)
310441c99275SPeter Avalos {
3105*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "isakmp_rfc3948";
3106*ed775ee7SAntonio Huete Jimenez 	if(length == 1 && GET_U_1(bp)==0xff) {
3107*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("isakmp-nat-keep-alive");
310841c99275SPeter Avalos 		return;
310941c99275SPeter Avalos 	}
311041c99275SPeter Avalos 
311141c99275SPeter Avalos 	if(length < 4) {
311241c99275SPeter Avalos 		goto trunc;
311341c99275SPeter Avalos 	}
311441c99275SPeter Avalos 
311541c99275SPeter Avalos 	/*
311641c99275SPeter Avalos 	 * see if this is an IKE packet
311741c99275SPeter Avalos 	 */
3118*ed775ee7SAntonio Huete Jimenez 	if (GET_BE_U_4(bp) == 0) {
3119*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("NONESP-encap: ");
312041c99275SPeter Avalos 		isakmp_print(ndo, bp+4, length-4, bp2);
312141c99275SPeter Avalos 		return;
312241c99275SPeter Avalos 	}
312341c99275SPeter Avalos 
312441c99275SPeter Avalos 	/* must be an ESP packet */
312541c99275SPeter Avalos 	{
3126*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("UDP-encap: ");
312741c99275SPeter Avalos 
3128*ed775ee7SAntonio Huete Jimenez 		esp_print(ndo, bp, length, bp2, ver, fragmented, ttl_hl);
312941c99275SPeter Avalos 
3130*ed775ee7SAntonio Huete Jimenez 		/*
3131*ed775ee7SAntonio Huete Jimenez 		 * Either this has decrypted the payload and
3132*ed775ee7SAntonio Huete Jimenez 		 * printed it, in which case there's nothing more
3133*ed775ee7SAntonio Huete Jimenez 		 * to do, or it hasn't, in which case there's
3134*ed775ee7SAntonio Huete Jimenez 		 * nothing more to do.
3135*ed775ee7SAntonio Huete Jimenez 		 */
313641c99275SPeter Avalos 		return;
313741c99275SPeter Avalos 	}
313841c99275SPeter Avalos 
313941c99275SPeter Avalos trunc:
3140*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
314141c99275SPeter Avalos }
3142