Add the "Edit:Protocols..." feature which currently only implements
[obnox/wireshark/wip.git] / packet-isakmp.c
1 /* packet-isakmp.c
2  * Routines for the Internet Security Association and Key Management Protocol
3  * (ISAKMP) (RFC 2408)
4  * Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
5  *
6  * $Id: packet-isakmp.c,v 1.26 2000/08/13 14:08:18 deniel Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <stdio.h>
37
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
40 #endif
41
42 #include <glib.h>
43
44 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
46 #endif
47
48 #include "packet.h"
49
50 static int proto_isakmp = -1;
51
52 static gint ett_isakmp = -1;
53 static gint ett_isakmp_flags = -1;
54 static gint ett_isakmp_payload = -1;
55
56 #define UDP_PORT_ISAKMP 500
57
58 #define NUM_PROTO_TYPES 5
59 #define proto2str(t)    \
60   ((t < NUM_PROTO_TYPES) ? prototypestr[t] : "UNKNOWN-PROTO-TYPE")
61
62 static const char *prototypestr[NUM_PROTO_TYPES] = {
63   "RESERVED",
64   "ISAKMP",
65   "IPSEC_AH",
66   "IPSEC_ESP",
67   "IPCOMP"
68 };
69
70 #define NUM_P1_ATT_TYPES        17
71 #define p1_atttype2str(t)       \
72   ((t < NUM_P1_ATT_TYPES) ? p1_atttypestr[t] : "UNKNOWN-ATTRIBUTE-TYPE")
73
74 static const char *p1_atttypestr[NUM_P1_ATT_TYPES] = {
75   "UNKNOWN-ATTRIBUTE-TYPE",
76   "Encryption-Algorithm",
77   "Hash-Algorithm",
78   "Authentication-Method",
79   "Group-Description",
80   "Group-Type",
81   "Group-Prime",
82   "Group-Generator-One",
83   "Group-Generator-Two",
84   "Group-Curve-A",
85   "Group-Curve-B",
86   "Life-Type",
87   "Life-Duration",
88   "PRF",
89   "Key-Length",
90   "Field-Size",
91   "Group-Order"
92 };
93
94 #define NUM_ATT_TYPES   10
95 #define atttype2str(t)  \
96   ((t < NUM_ATT_TYPES) ? atttypestr[t] : "UNKNOWN-ATTRIBUTE-TYPE")
97
98 static const char *atttypestr[NUM_ATT_TYPES] = {
99   "UNKNOWN-ATTRIBUTE-TYPE",
100   "SA-Life-Type",
101   "SA-Life-Duration",
102   "Group-Description",
103   "Encapsulation-Mode",
104   "Authentication-Algorithm",
105   "Key-Length",
106   "Key-Rounds",
107   "Compress-Dictinary-Size",
108   "Compress-Private-Algorithm"
109 };
110
111 #define NUM_TRANS_TYPES 2
112 #define trans2str(t)    \
113   ((t < NUM_TRANS_TYPES) ? transtypestr[t] : "UNKNOWN-TRANS-TYPE")
114
115 static const char *transtypestr[NUM_TRANS_TYPES] = {
116   "RESERVED",
117   "KEY_IKE"
118 };
119
120 #define NUM_AH_TRANS_TYPES      5
121 #define ah_trans2str(t)         \
122   ((t < NUM_AH_TRANS_TYPES) ? ah_transtypestr[t] : "UNKNOWN-AH-TRANS-TYPE")
123
124 static const char *ah_transtypestr[NUM_AH_TRANS_TYPES] = {
125   "RESERVED",
126   "RESERVED",
127   "MD5",
128   "SHA",
129   "DES"
130 };
131
132 #define NUM_ESP_TRANS_TYPES     12
133 #define esp_trans2str(t)        \
134   ((t < NUM_ESP_TRANS_TYPES) ? esp_transtypestr[t] : "UNKNOWN-ESP-TRANS-TYPE")
135
136 static const char *esp_transtypestr[NUM_ESP_TRANS_TYPES] = {
137   "RESERVED",
138   "DES-IV64",
139   "DES",
140   "3DES",
141   "RC5",
142   "IDEA",
143   "CAST",
144   "BLOWFISH",
145   "3IDEA",
146   "DES-IV32",
147   "RC4",
148   "NULL"
149 };
150
151 #define NUM_ID_TYPES    12
152 #define id2str(t)       \
153   ((t < NUM_ID_TYPES) ? idtypestr[t] : "UNKNOWN-ID-TYPE")
154
155 static const char *idtypestr[NUM_ID_TYPES] = {
156   "RESERVED",
157   "IPV4_ADDR",
158   "FQDN",
159   "USER_FQDN",
160   "IPV4_ADDR_SUBNET",
161   "IPV6_ADDR",
162   "IPV6_ADDR_SUBNET",
163   "IPV4_ADDR_RANGE",
164   "IPV6_ADDR_RANGE",
165   "DER_ASN1_DN",
166   "DER_ASN1_GN",
167   "KEY_ID"
168 };
169
170 struct isakmp_hdr {
171   guint8        icookie[8];
172   guint8        rcookie[8];
173   guint8        next_payload;
174   guint8        version;
175   guint8        exch_type;
176   guint8        flags;
177 #define E_FLAG          0x01
178 #define C_FLAG          0x02
179 #define A_FLAG          0x04
180   guint8        message_id[4];
181   guint8        length[4];
182 };
183
184 struct sa_hdr {
185   guint8        next_payload;
186   guint8        reserved;
187   guint8        length[2];
188   guint8        doi[4];
189   guint8        situation[4];
190 };
191
192 struct proposal_hdr {
193   guint8        next_payload;
194   guint8        reserved;
195   guint8        length[2];
196   guint8        proposal_num;
197   guint8        protocol_id;
198   guint8        spi_size;
199   guint8        num_transforms;
200 };
201
202 struct trans_hdr {
203   guint8        next_payload;
204   guint8        reserved;
205   guint8        length[2];
206   guint8        transform_num;
207   guint8        transform_id;
208   guint8        reserved2[2];
209 };
210
211 #define TRANS_LEN(p)    (pntohs(&((struct trans_hdr *)(p))->length))
212
213 struct ke_hdr {
214   guint8        next_payload;
215   guint8        reserved;
216   guint8        length[2];
217 };
218
219 struct id_hdr {
220   guint8        next_payload;
221   guint8        reserved;
222   guint8        length[2];
223   guint8        id_type;
224   guint8        protocol_id;
225   guint8        port[2];
226 };
227
228 struct cert_hdr {
229   guint8        next_payload;
230   guint8        reserved;
231   guint8        length[2];
232   guint8        cert_enc;
233 };
234
235 struct certreq_hdr {
236   guint8        next_payload;
237   guint8        reserved;
238   guint8        length[2];
239   guint8        cert_type;
240 };
241
242 struct hash_hdr {
243   guint8        next_payload;
244   guint8        reserved;
245   guint8        length[2];
246 };
247
248 struct sig_hdr {
249   guint8        next_payload;
250   guint8        reserved;
251   guint8        length[2];
252 };
253
254 struct nonce_hdr {
255   guint8        next_payload;
256   guint8        reserved;
257   guint8        length[2];
258 };
259
260 struct notif_hdr {
261   guint8        next_payload;
262   guint8        reserved;
263   guint8        length[2];
264   guint8        doi[4];
265   guint8        protocol_id;
266   guint8        spi_size;
267   guint8        msgtype[2];
268 };
269
270 struct delete_hdr {
271   guint8        next_payload;
272   guint8        reserved;
273   guint8        length[2];
274   guint8        doi[4];
275   guint8        protocol_id;
276   guint8        spi_size;
277   guint8        num_spis[2];
278 };
279
280 struct vid_hdr {
281   guint8        next_payload;
282   guint8        reserved;
283   guint8        length[2];
284 };
285
286 struct cfg_hdr {
287   guint8        next_payload;
288   guint8        reserved;
289   guint8        length[2];
290   guint8        type;
291   guint8        reserved2;
292   guint8        identifier[2];
293 };
294
295 static void dissect_none(const u_char *, int, frame_data *, proto_tree *);
296 static void dissect_sa(const u_char *, int, frame_data *, proto_tree *);
297 static void dissect_proposal(const u_char *, int, frame_data *, proto_tree *);
298 static void dissect_transform(const u_char *, int, frame_data *, proto_tree *,
299                 guint8);
300 static void dissect_key_exch(const u_char *, int, frame_data *, proto_tree *);
301 static void dissect_id(const u_char *, int, frame_data *, proto_tree *);
302 static void dissect_cert(const u_char *, int, frame_data *, proto_tree *);
303 static void dissect_certreq(const u_char *, int, frame_data *, proto_tree *);
304 static void dissect_hash(const u_char *, int, frame_data *, proto_tree *);
305 static void dissect_sig(const u_char *, int, frame_data *, proto_tree *);
306 static void dissect_nonce(const u_char *, int, frame_data *, proto_tree *);
307 static void dissect_notif(const u_char *, int, frame_data *, proto_tree *);
308 static void dissect_delete(const u_char *, int, frame_data *, proto_tree *);
309 static void dissect_vid(const u_char *, int, frame_data *, proto_tree *);
310 static void dissect_config(const u_char *, int, frame_data *, proto_tree *);
311
312 static const char *payloadtype2str(guint8);
313 static const char *exchtype2str(guint8);
314 static const char *doitype2str(guint32);
315 static const char *msgtype2str(guint16);
316 static const char *situation2str(guint32);
317 static const char *value2str(int, guint16, guint16);
318 static const char *num2str(const guint8 *, guint16);
319 static const char *attrtype2str(guint8);
320 static const char *cfgattrident2str(guint16);
321
322 #define NUM_LOAD_TYPES          15
323 #define loadtype2str(t) \
324   ((t < NUM_LOAD_TYPES) ? strfuncs[t].str : "Unknown payload type")
325 #define LOAD_TYPE_TRANSFORM     3
326
327 static struct strfunc {
328   const char *  str;
329   void          (*func)(const u_char *, int, frame_data *, proto_tree *);
330 } strfuncs[NUM_LOAD_TYPES] = {
331   {"NONE",                      dissect_none      },
332   {"Security Association",      dissect_sa        },
333   {"Proposal",                  dissect_proposal  },
334   {"Transform",                 NULL },
335   {"Key Exchange",              dissect_key_exch  },
336   {"Identification",            dissect_id        },
337   {"Certificate",               dissect_cert      },
338   {"Certificate Request",       dissect_certreq   },
339   {"Hash",                      dissect_hash      },
340   {"Signature",                 dissect_sig       },
341   {"Nonce",                     dissect_nonce     },
342   {"Notification",              dissect_notif     },
343   {"Delete",                    dissect_delete    },
344   {"Vendor ID",                 dissect_vid       },
345   {"Attrib",                    dissect_config    }
346 };
347
348 static void
349 dissect_isakmp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
350   
351   struct isakmp_hdr *   hdr = (struct isakmp_hdr *)(pd + offset);
352   guint32               len;
353
354   OLD_CHECK_DISPLAY_AS_DATA(proto_isakmp, pd, offset, fd, tree);
355   
356   if (check_col(fd, COL_PROTOCOL))
357     col_add_str(fd, COL_PROTOCOL, "ISAKMP");
358   
359   len = pntohl(&hdr->length);
360   
361   if (check_col(fd, COL_INFO))
362     col_add_fstr(fd, COL_INFO, "%s", exchtype2str(hdr->exch_type));
363   
364   if (IS_DATA_IN_FRAME(offset) && tree) {
365     proto_item *        ti;
366     proto_tree *        isakmp_tree;
367     
368     ti = proto_tree_add_item(tree, proto_isakmp, NullTVB, offset, len, FALSE);
369     isakmp_tree = proto_item_add_subtree(ti, ett_isakmp);
370     
371     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->icookie),
372                         "Initiator cookie");
373     offset += sizeof(hdr->icookie);
374     
375     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->rcookie),
376                         "Responder cookie");
377     offset += sizeof(hdr->rcookie);
378
379     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->next_payload),
380                         "Next payload: %s (%u)",
381                         payloadtype2str(hdr->next_payload), hdr->next_payload);
382     offset += sizeof(hdr->next_payload);
383
384     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->version),
385                         "Version: %u.%u",
386                         hi_nibble(hdr->version), lo_nibble(hdr->version));
387     offset += sizeof(hdr->version);
388     
389     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->exch_type),
390                         "Exchange type: %s (%u)",
391                         exchtype2str(hdr->exch_type), hdr->exch_type);
392     offset += sizeof(hdr->exch_type);
393     
394     {
395       proto_item *      fti;
396       proto_tree *      ftree;
397       
398       fti   = proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->flags), "Flags");
399       ftree = proto_item_add_subtree(fti, ett_isakmp_flags);
400       
401       proto_tree_add_text(ftree, NullTVB, offset, 1, "%s",
402                           decode_boolean_bitfield(hdr->flags, E_FLAG, sizeof(hdr->flags)*8,
403                                                   "Encryption", "No encryption"));
404       proto_tree_add_text(ftree, NullTVB, offset, 1, "%s",
405                           decode_boolean_bitfield(hdr->flags, C_FLAG, sizeof(hdr->flags)*8,
406                                                   "Commit", "No commit"));
407       proto_tree_add_text(ftree, NullTVB, offset, 1, "%s",
408                           decode_boolean_bitfield(hdr->flags, A_FLAG, sizeof(hdr->flags)*8,
409                                                   "Authentication", "No authentication"));
410       offset += sizeof(hdr->flags);
411     }
412
413     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->message_id), "Message ID");
414     offset += sizeof(hdr->message_id);
415     
416     proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->length),
417                         "Length: %u", len);
418     offset += sizeof(hdr->length);
419
420     if (hdr->flags & E_FLAG) {
421       if (IS_DATA_IN_FRAME(offset) && isakmp_tree) {
422         proto_tree_add_text(isakmp_tree, NullTVB, offset, END_OF_FRAME,
423                         "Encrypted payload (%d byte%s)",
424                         END_OF_FRAME, plurality(END_OF_FRAME, "", "s"));
425       }
426     } else {
427       if (hdr->next_payload < NUM_LOAD_TYPES) {
428         if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
429           dissect_transform(pd, offset, fd, isakmp_tree, 0);    /* XXX - protocol ID? */
430         else
431           (*strfuncs[hdr->next_payload].func)(pd, offset, fd, isakmp_tree);
432       }
433       else
434         old_dissect_data(pd, offset, fd, isakmp_tree);
435     }
436   }
437 }
438
439 static void
440 dissect_none(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
441 }
442
443 static void
444 dissect_sa(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
445
446   struct sa_hdr *       hdr       = (struct sa_hdr *)(pd + offset);
447   guint16               length    = pntohs(&hdr->length);
448   guint32               doi       = pntohl(&hdr->doi);
449   guint32               situation = pntohl(&hdr->situation);
450   proto_item *          ti        = proto_tree_add_text(tree, NullTVB, offset, length, "Security Association payload");
451   proto_tree *          ntree;
452
453   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
454   
455   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
456                       "Next payload: %s (%u)",
457                       payloadtype2str(hdr->next_payload), hdr->next_payload);
458   offset += sizeof(hdr->next_payload) * 2;
459   
460   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
461                       "Length: %u", length);
462   offset += sizeof(length);
463   
464   proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
465                       "Domain of interpretation: %s (%u)",
466                       doitype2str(doi), doi);
467   offset += sizeof(doi);
468   
469   proto_tree_add_text(ntree, NullTVB, offset, sizeof(situation),
470                       "Situation: %s (%u)",
471                       situation2str(situation), situation);
472   offset += sizeof(situation);
473   
474   dissect_proposal(pd, offset, fd, ntree);
475   offset += (length - sizeof(*hdr));
476   
477   if (hdr->next_payload < NUM_LOAD_TYPES) {
478     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
479       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
480     else
481       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
482   }
483   else
484     old_dissect_data(pd, offset, fd, tree);
485 }
486
487 static void
488 dissect_proposal(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
489
490   struct proposal_hdr * hdr     = (struct proposal_hdr *)(pd + offset);
491   guint16               length  = pntohs(&hdr->length);
492   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Proposal payload");
493   proto_tree *          ntree;
494
495   int                   next_hdr_offset = offset + length;
496
497   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
498   
499   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
500                       "Next payload: %s (%u)",
501                       payloadtype2str(hdr->next_payload), hdr->next_payload);
502   offset += sizeof(hdr->next_payload) * 2;
503   
504   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
505                       "Length: %u", length);
506   offset += sizeof(length);
507   
508   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->proposal_num),
509                       "Proposal number: %u", hdr->proposal_num);
510   offset += sizeof(hdr->proposal_num);
511   
512   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
513                       "Protocol ID: %s (%u)",
514                       proto2str(hdr->protocol_id), hdr->protocol_id);
515   offset += sizeof(hdr->protocol_id);
516   
517   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
518                       "SPI size: %u", hdr->spi_size);
519   offset += sizeof(hdr->spi_size);
520
521   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->num_transforms),
522                       "Number of transforms: %u", hdr->num_transforms);
523   offset += sizeof(hdr->num_transforms);
524
525   if (hdr->spi_size) {
526     proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size, "SPI");
527     offset += hdr->spi_size;
528   }
529
530   if (hdr->num_transforms > 0)
531     dissect_transform(pd, offset, fd, ntree, hdr->protocol_id);
532
533   if (hdr->next_payload < NUM_LOAD_TYPES) {
534     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
535       dissect_transform(pd, next_hdr_offset, fd, tree, 0);      /* XXX - protocol ID? */
536     else
537       (*strfuncs[hdr->next_payload].func)(pd, next_hdr_offset, fd, tree);
538   }
539   else
540     old_dissect_data(pd, next_hdr_offset, fd, tree);
541 }
542
543 static void
544 dissect_transform(const u_char *pd, int offset, frame_data *fd,
545                 proto_tree *tree, guint8 protocol_id)
546 {
547
548   struct trans_hdr *    hdr     = (struct trans_hdr *)(pd + offset);
549   guint16               length  = pntohs(&hdr->length);
550   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Transform payload");
551   proto_tree *          ntree;
552
553   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
554   
555   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
556                       "Next payload: %s (%u)",
557                       payloadtype2str(hdr->next_payload), hdr->next_payload);
558   offset += sizeof(hdr->next_payload) * 2;
559   
560   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
561                       "Length: %u", length);
562   offset += sizeof(length);
563   
564   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_num),
565                       "Transform number: %u", hdr->transform_num);
566   offset += sizeof(hdr->transform_num);
567
568   switch (protocol_id) {
569   default:
570   case 1:       /* ISAKMP */
571     proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_id),
572                         "Transform ID: %s (%u)",
573                         trans2str(hdr->transform_id), hdr->transform_id);
574     break;
575   case 2:       /* AH */
576     proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_id),
577                         "Transform ID: %s (%u)",
578                         ah_trans2str(hdr->transform_id), hdr->transform_id);
579     break;
580   case 3:       /* ESP */
581     proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_id),
582                         "Transform ID: %s (%u)",
583                         esp_trans2str(hdr->transform_id), hdr->transform_id);
584     break;
585   }
586   offset += sizeof(hdr->transform_id) + sizeof(hdr->reserved2);
587   
588   length -= sizeof(*hdr);
589   while (length) {
590     const char *str = NULL;
591     int ike_phase1 = 0;
592     guint16 type    = pntohs(pd + offset) & 0x7fff;
593     guint16 val_len = pntohs(pd + offset + 2);
594
595     if (protocol_id == 1 && hdr->transform_id == 1) {
596       ike_phase1 = 1;
597       str = p1_atttype2str(type);
598     }
599     else {
600       str = atttype2str(type);
601     }
602
603     if (pd[offset] & 0x80) {
604       proto_tree_add_text(ntree, NullTVB, offset, 4,
605                           "%s (%u): %s (%u)",
606                           str, type,
607                           value2str(ike_phase1, type, val_len), val_len);
608       offset += 4;
609       length -= 4;
610     }
611     else {
612       guint16   pack_len = 4 + val_len;
613       
614       proto_tree_add_text(ntree, NullTVB, offset, pack_len,
615                           "%s (%u): %s",
616                           str, type,
617                           num2str(pd + offset + 4, val_len));
618       offset += pack_len;
619       length -= pack_len;
620     }
621   }
622
623   if (hdr->next_payload < NUM_LOAD_TYPES) {
624     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
625       dissect_transform(pd, offset, fd, tree, protocol_id);
626     else
627       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
628   }
629   else
630     old_dissect_data(pd, offset, fd, tree);
631 }
632
633 static void
634 dissect_key_exch(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
635
636   struct ke_hdr *       hdr     = (struct ke_hdr *)(pd + offset);
637   guint16               length  = pntohs(&hdr->length);
638   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Key Exchange payload");
639   proto_tree *          ntree;
640
641   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
642   
643   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
644                       "Next payload: %s (%u)",
645                       payloadtype2str(hdr->next_payload), hdr->next_payload);
646   offset += sizeof(hdr->next_payload) * 2;
647   
648   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
649                       "Length: %u", length);
650   offset += sizeof(length);
651   
652   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Key Exchange Data");
653   offset += (length - sizeof(*hdr));
654   
655   if (hdr->next_payload < NUM_LOAD_TYPES) {
656     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
657       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
658     else
659       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
660   }
661   else
662     old_dissect_data(pd, offset, fd, tree);
663 }
664
665 static void
666 dissect_id(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
667
668   struct id_hdr *       hdr     = (struct id_hdr *)(pd + offset);
669   guint16               length  = pntohs(&hdr->length);
670   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Identification payload");
671   proto_tree *          ntree;
672
673   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
674   
675   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
676                       "Next payload: %s (%u)",
677                       payloadtype2str(hdr->next_payload), hdr->next_payload);
678   offset += sizeof(hdr->next_payload) * 2;
679   
680   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
681                       "Length: %u", length);
682   offset += sizeof(length);
683   
684   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->id_type),
685                       "ID type: %s (%u)", id2str(hdr->id_type), hdr->id_type);
686   offset += sizeof(hdr->id_type);
687
688   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
689                       "Protocol ID: %u", hdr->protocol_id);
690   offset += sizeof(hdr->protocol_id);
691   
692   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->port),
693                       "Port: %u", pntohs(&hdr->port));
694   offset += sizeof(hdr->port);
695   
696   switch (hdr->id_type) {
697     case 1:
698     case 4:
699       proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
700                           "Identification data: %s", ip_to_str(pd+offset));
701       break;
702     case 2:
703     case 3:
704       proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
705                           "Identification data: %s", (char *)(pd+offset));
706       break;
707     default:
708       proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Identification Data");
709   }
710   offset += (length - sizeof(*hdr));
711   
712   if (hdr->next_payload < NUM_LOAD_TYPES) {
713     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
714       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
715     else
716       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
717   }
718   else
719     old_dissect_data(pd, offset, fd, tree);
720 }
721
722 static void
723 dissect_cert(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
724
725   struct cert_hdr *     hdr     = (struct cert_hdr *)(pd + offset);
726   guint16               length  = pntohs(&hdr->length);
727   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate payload");
728   proto_tree *          ntree;
729
730   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
731   
732   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
733                       "Next payload: %s (%u)",
734                       payloadtype2str(hdr->next_payload), hdr->next_payload);
735   offset += sizeof(hdr->next_payload) * 2;
736   
737   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
738                       "Length: %u", length);
739   offset += sizeof(length);
740   
741   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_enc),
742                       "Certificate encoding: %u", hdr->cert_enc);
743   offset += sizeof(hdr->cert_enc);
744
745   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Data");
746   offset += (length - sizeof(*hdr));
747   
748   if (hdr->next_payload < NUM_LOAD_TYPES) {
749     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
750       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
751     else
752       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
753   }
754   else
755     old_dissect_data(pd, offset, fd, tree);
756 }
757
758 static void
759 dissect_certreq(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
760
761   struct certreq_hdr *  hdr     = (struct certreq_hdr *)(pd + offset);
762   guint16               length  = pntohs(&hdr->length);
763   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate Request payload");
764   proto_tree *          ntree;
765
766   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
767   
768   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
769                       "Next payload: %s (%u)",
770                       payloadtype2str(hdr->next_payload), hdr->next_payload);
771   offset += sizeof(hdr->next_payload) * 2;
772   
773   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
774                       "Length: %u", length);
775   offset += sizeof(length);
776   
777   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_type),
778                       "Certificate type: %u", hdr->cert_type);
779   offset += sizeof(hdr->cert_type);
780
781   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Authority");
782   offset += (length - sizeof(*hdr));
783   
784   if (hdr->next_payload < NUM_LOAD_TYPES) {
785     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
786       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
787     else
788       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
789   }
790   else
791     old_dissect_data(pd, offset, fd, tree);
792 }
793
794 static void
795 dissect_hash(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
796
797   struct hash_hdr *     hdr     = (struct hash_hdr *)(pd + offset);
798   guint16               length  = pntohs(&hdr->length);
799   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Hash payload");
800   proto_tree *          ntree;
801
802   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
803   
804   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
805                       "Next payload: %s (%u)",
806                       payloadtype2str(hdr->next_payload), hdr->next_payload);
807   offset += sizeof(hdr->next_payload) * 2;
808   
809   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
810                       "Length: %u", length);
811   offset += sizeof(length);
812   
813   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Hash Data");
814   offset += (length - sizeof(*hdr));
815   
816   if (hdr->next_payload < NUM_LOAD_TYPES) {
817     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
818       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
819     else
820       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
821   }
822   else
823     old_dissect_data(pd, offset, fd, tree);
824 }
825
826 static void
827 dissect_sig(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
828
829   struct sig_hdr *      hdr     = (struct sig_hdr *)(pd + offset);
830   guint16               length  = pntohs(&hdr->length);
831   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Signature payload");
832   proto_tree *          ntree;
833
834   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
835   
836   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
837                       "Next payload: %s (%u)",
838                       payloadtype2str(hdr->next_payload), hdr->next_payload);
839   offset += sizeof(hdr->next_payload) * 2;
840   
841   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
842                       "Length: %u", length);
843   offset += sizeof(length);
844   
845   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Signature Data");
846   offset += (length - sizeof(*hdr));
847   
848   if (hdr->next_payload < NUM_LOAD_TYPES) {
849     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
850       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
851     else
852       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
853   }
854   else
855     old_dissect_data(pd, offset, fd, tree);
856 }
857
858 static void
859 dissect_nonce(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
860
861   struct nonce_hdr *    hdr     = (struct nonce_hdr *)(pd + offset);
862   guint16               length  = pntohs(&hdr->length);
863   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Nonce payload");
864   proto_tree *          ntree;
865
866   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
867   
868   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
869                       "Next payload: %s (%u)",
870                       payloadtype2str(hdr->next_payload), hdr->next_payload);
871   offset += sizeof(hdr->next_payload) * 2;
872   
873   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
874                       "Length: %u", length);
875   offset += sizeof(length);
876   
877   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Nonce Data");
878   offset += (length - sizeof(*hdr));
879   
880   if (hdr->next_payload < NUM_LOAD_TYPES) {
881     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
882       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
883     else
884       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
885   }
886   else
887     old_dissect_data(pd, offset, fd, tree);
888 }
889
890 static void
891 dissect_notif(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
892
893   struct notif_hdr *    hdr     = (struct notif_hdr *)(pd + offset);
894   guint16               length  = pntohs(&hdr->length);
895   guint32               doi     = pntohl(&hdr->doi);
896   guint16               msgtype = pntohs(&hdr->msgtype);
897   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Notification payload");
898   proto_tree *          ntree;
899
900   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
901   
902   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
903                       "Next payload: %s (%u)",
904                       payloadtype2str(hdr->next_payload), hdr->next_payload);
905   offset += sizeof(hdr->next_payload) * 2;
906   
907   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
908                       "Length: %u", length);
909   offset += sizeof(length);
910   
911   proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
912                       "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
913   offset += sizeof(doi);
914
915   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
916                       "Protocol ID: %s (%u)",
917                       proto2str(hdr->protocol_id), hdr->protocol_id);
918   offset += sizeof(hdr->protocol_id);
919   
920   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
921                       "SPI size: %u", hdr->spi_size);
922   offset += sizeof(hdr->spi_size);
923   
924   proto_tree_add_text(ntree, NullTVB, offset, sizeof(msgtype),
925                       "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
926   offset += sizeof(msgtype);
927
928   if (hdr->spi_size) {
929     proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size, "Security Parameter Index");
930     offset += hdr->spi_size;
931   }
932
933   if (length - sizeof(*hdr)) {
934     proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr) - hdr->spi_size,
935                         "Notification Data");
936     offset += (length - sizeof(*hdr) - hdr->spi_size);
937   }
938   
939   if (hdr->next_payload < NUM_LOAD_TYPES) {
940     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
941       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
942     else
943       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
944   }
945   else
946     old_dissect_data(pd, offset, fd, tree);
947 }
948
949 static void
950 dissect_delete(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
951
952   struct delete_hdr *   hdr      = (struct delete_hdr *)(pd + offset);
953   guint16               length   = pntohs(&hdr->length);
954   guint32               doi      = pntohl(&hdr->doi);
955   guint16               num_spis = pntohs(&hdr->num_spis);
956   proto_item *          ti       = proto_tree_add_text(tree, NullTVB, offset, length, "Delete payload");
957   proto_tree *          ntree;
958   guint16               i;
959   
960   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
961   
962   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
963                       "Next payload: %s (%u)",
964                       payloadtype2str(hdr->next_payload), hdr->next_payload);
965   offset += sizeof(hdr->next_payload) * 2;
966   
967   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
968                       "Length: %u", length);
969   offset += sizeof(length);
970   
971   proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
972                       "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
973   offset += sizeof(doi);
974
975   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
976                       "Protocol ID: %s (%u)",
977                       proto2str(hdr->protocol_id), hdr->protocol_id);
978   offset += sizeof(hdr->protocol_id);
979   
980   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
981                       "SPI size: %u", hdr->spi_size);
982   offset += sizeof(hdr->spi_size);
983   
984   proto_tree_add_text(ntree, NullTVB, offset, num_spis,
985                       "Number of SPIs: %u", num_spis);
986   offset += sizeof(hdr->num_spis);
987   
988   for (i = 0; i < num_spis; ++i) {
989     proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size,
990                         "SPI (%d)", i);
991     offset += hdr->spi_size;
992   }
993
994   if (hdr->next_payload < NUM_LOAD_TYPES) {
995     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
996       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
997     else
998       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
999   }
1000   else
1001     old_dissect_data(pd, offset, fd, tree);
1002 }
1003
1004 static void
1005 dissect_vid(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1006
1007   struct vid_hdr *      hdr     = (struct vid_hdr *)(pd + offset);
1008   guint16               length  = pntohs(&hdr->length);
1009   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Vendor ID payload");
1010   proto_tree *          ntree;
1011
1012   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1013   
1014   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1015                       "Next payload: %s (%u)",
1016                       payloadtype2str(hdr->next_payload), hdr->next_payload);
1017   offset += sizeof(hdr->next_payload) * 2;
1018   
1019   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1020                       "Length: %u", length);
1021   offset += sizeof(length);
1022   
1023   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Vendor ID");
1024   offset += (length - sizeof(*hdr));
1025   
1026   if (hdr->next_payload < NUM_LOAD_TYPES) {
1027     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1028       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
1029     else
1030       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1031   }
1032   else
1033     old_dissect_data(pd, offset, fd, tree);
1034 }
1035
1036 static void
1037 dissect_config(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1038
1039   struct cfg_hdr *      hdr      = (struct cfg_hdr *)(pd + offset);
1040   guint16               length   = pntohs(&hdr->length);
1041   proto_item *          ti       = proto_tree_add_text(tree, NullTVB, offset, length, "Attribute payload");
1042   proto_tree *          ntree;
1043
1044   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1045
1046   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1047                       "Next payload: %s (%u)",
1048                       payloadtype2str(hdr->next_payload), hdr->next_payload);
1049   offset += sizeof(hdr->next_payload) *2;
1050   
1051   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1052                      "Length: %u", length);
1053   offset += sizeof(length);
1054   
1055   proto_tree_add_text(ntree,NullTVB, offset, sizeof(hdr->type),
1056                       "Type %s (%u)",attrtype2str(hdr->type),hdr->type);
1057   
1058   offset += (sizeof(hdr->type) + sizeof(hdr->reserved2));
1059   
1060   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->identifier),
1061                       "Identifier: %u", pntohs(&hdr->identifier));
1062   offset += sizeof(hdr->identifier);
1063   length -= sizeof(*hdr);
1064   
1065   while(length) {
1066     guint16 type = pntohs(pd + offset) & 0x7fff;
1067     guint16 val_len = pntohs(pd + offset + 2);
1068     
1069     if(pd[offset] & 0x80) {
1070       proto_tree_add_text(ntree, NullTVB, offset, 4,
1071                           "%s (%u)",cfgattrident2str(type),val_len);
1072       offset += 4;
1073       length -= 4;
1074     }
1075     else {
1076       guint pack_len = 4 + val_len;
1077
1078       proto_tree_add_text(ntree, NullTVB, offset, 4,
1079                           "%s (%se)", cfgattrident2str(type), num2str(pd + offset + 4, val_len));
1080       offset += pack_len;
1081       length -= pack_len;
1082     }
1083   }
1084
1085   if (hdr->next_payload < NUM_LOAD_TYPES) {
1086     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1087       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
1088     else
1089       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1090   }
1091   else
1092     old_dissect_data(pd, offset, fd, tree);
1093  
1094 }
1095
1096 static const char *
1097 payloadtype2str(guint8 type) {
1098
1099   if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
1100   if (type < 128)            return "RESERVED";
1101   if (type < 256)            return "Private USE";
1102
1103   return "Huh? You should never see this! Shame on you!";
1104 }
1105
1106 static const char *
1107 exchtype2str(guint8 type) {
1108
1109 #define NUM_EXCHSTRS    7
1110   static const char * exchstrs[NUM_EXCHSTRS] = {
1111     "NONE",
1112     "Base",
1113     "Identity Protection (Main Mode)",
1114     "Authentication Only",
1115     "Aggressive",
1116     "Informational",
1117     "Transaction (Config Mode)"
1118   };
1119   
1120   if (type < NUM_EXCHSTRS) return exchstrs[type];
1121   if (type < 32)           return "ISAKMP Future Use";
1122   switch (type) {
1123   case 32:
1124     return "Quick Mode";
1125   case 33:
1126     return "New Group Mode";
1127   }
1128   if (type < 240)          return "DOI Specific Use";
1129   if (type < 256)          return "Private Use";
1130   
1131   return "Huh? You should never see this! Shame on you!";
1132 }
1133
1134 static const char *
1135 doitype2str(guint32 type) {
1136   if (type == 1) return "IPSEC";
1137   return "Unknown DOI Type";
1138 }
1139
1140 static const char *
1141 msgtype2str(guint16 type) {
1142
1143 #define NUM_PREDEFINED  31
1144   static const char *msgs[NUM_PREDEFINED] = {
1145     "<UNKNOWN>",
1146     "INVALID-PAYLOAD-TYPE",
1147     "DOI-NOT-SUPPORTED",
1148     "SITUATION-NOT-SUPPORTED",
1149     "INVALID-COOKIE",
1150     "INVALID-MAJOR-VERSION",
1151     "INVALID-MINOR-VERSION",
1152     "INVALID-EXCHANGE-TYPE",
1153     "INVALID-FLAGS",
1154     "INVALID-MESSAGE-ID",
1155     "INVALID-PROTOCOL-ID",
1156     "INVALID-SPI",
1157     "INVALID-TRANSFORM-ID",
1158     "ATTRIBUTES-NOT-SUPPORTED",
1159     "NO-PROPOSAL-CHOSEN",
1160     "BAD-PROPOSAL-SYNTAX",
1161     "PAYLOAD-MALFORMED",
1162     "INVALID-KEY-INFORMATION",
1163     "INVALID-ID-INFORMATION",
1164     "INVALID-CERT-ENCODING",
1165     "INVALID-CERTIFICATE",
1166     "CERT-TYPE-UNSUPPORTED",
1167     "INVALID-CERT-AUTHORITY",
1168     "INVALID-HASH-INFORMATION",
1169     "AUTHENTICATION-FAILED",
1170     "INVALID-SIGNATURE",
1171     "ADDRESS-NOTIFICATION",
1172     "NOTIFY-SA-LIFETIME",
1173     "CERTIFICATE-UNAVAILABLE",
1174     "UNSUPPORTED-EXCHANGE-TYPE",
1175     "UNEQUAL-PAYLOAD-LENGTHS"
1176   };
1177
1178   if (type < NUM_PREDEFINED) return msgs[type];
1179   if (type < 8192)           return "RESERVED (Future Use)";
1180   if (type < 16384)          return "Private Use";
1181   if (type < 16385)          return "CONNECTED";
1182   if (type < 24576)          return "RESERVED (Future Use) - status";
1183   if (type < 24577)          return "RESPONDER-LIFETIME";
1184   if (type < 24578)          return "REPLAY-STATUS";
1185   if (type < 24579)          return "INITIAL-CONTACT";
1186   if (type < 32768)          return "DOI-specific codes";
1187   if (type < 40960)          return "Private Use - status";
1188   if (type < 65535)          return "RESERVED (Future Use) - status (2)";
1189
1190   return "Huh? You should never see this! Shame on you!";
1191 }
1192
1193 static const char *
1194 situation2str(guint32 type) {
1195
1196 #define SIT_MSG_NUM     1024
1197 #define SIT_IDENTITY    0x01
1198 #define SIT_SECRECY     0x02
1199 #define SIT_INTEGRITY   0x04
1200
1201   static char   msg[SIT_MSG_NUM];
1202   int           n = 0;
1203   char *        sep = "";
1204   
1205   if (type & SIT_IDENTITY) {
1206     n += snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
1207     sep = " & ";
1208   }
1209   if (type & SIT_SECRECY) {
1210     n += snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
1211     sep = " & ";
1212   }
1213   if (type & SIT_INTEGRITY) {
1214     n += snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
1215     sep = " & ";
1216   }
1217
1218   return msg;
1219 }
1220
1221 static const char *
1222 value2str(int ike_p1, guint16 att_type, guint16 value) {
1223   
1224   if (value == 0) return "RESERVED";
1225   
1226   if (!ike_p1) {
1227   switch (att_type) {
1228     case 1:
1229       switch (value) {
1230         case 1:  return "Seconds";
1231         case 2:  return "Kilobytes";
1232         default: return "UNKNOWN-SA-VALUE";
1233       }
1234     case 2:
1235       return "Duration-Value";
1236     case 3:
1237       return "Group-Value";
1238     case 4:
1239       switch (value) {
1240         case 1:  return "Tunnel";
1241         case 2:  return "Transport";
1242         default: return "UNKNOWN-ENCAPSULATION-VALUE";
1243       }
1244     case 5:
1245       switch (value) {
1246         case 1:  return "HMAC-MD5";
1247         case 2:  return "HMAC-SHA";
1248         case 3:  return "DES-MAC";
1249         case 4:  return "KPDK";
1250         default: return "UNKNOWN-AUTHENTICATION-VALUE";
1251       }
1252     case 6:
1253       return "Key-Length";
1254     case 7:
1255       return "Key-Rounds";
1256     case 8:
1257       return "log2-size";
1258     default: return "UNKNOWN-ATTRIBUTE-TYPE";
1259   }
1260   }
1261   else {
1262     switch (att_type) {
1263       case 1:
1264         switch (value) {
1265           case 1:  return "DES-CBC";
1266           case 2:  return "IDEA-CBC";
1267           case 3:  return "BLOWFISH-CBC";
1268           case 4:  return "RC5-R16-B64-CBC";
1269           case 5:  return "3DES-CBC";
1270           case 6:  return "CAST-CBC";
1271           default: return "UNKNOWN-ENCRYPTION-ALG";
1272         }
1273       case 2:
1274         switch (value) {
1275           case 1:  return "MD5";
1276           case 2:  return "SHA";
1277           case 3:  return "TIGER";
1278           default: return "UNKNOWN-HASH-ALG";
1279         }
1280       case 3:
1281         switch (value) {
1282           case 1:  return "PSK";
1283           case 2:  return "DSS-SIG";
1284           case 3:  return "RSA-SIG";
1285           case 4:  return "RSA-ENC";
1286           case 5:  return "RSA-Revised-ENC";
1287           case 64221: return "HybridInitRSA";
1288           case 64222: return "HybridRespRSA";
1289           case 64223: return "HybridInitDSS";
1290           case 64224: return "HybridRespDSS";
1291           case 65001: return "XAUTHInitPreShared";
1292           case 65002: return "XAUTHRespPreShared";
1293           case 65003: return "XAUTHInitDSS";
1294           case 65004: return "XAUTHRespDSS";
1295           case 65005: return "XAUTHInitRSA";
1296           case 65006: return "XAUTHRespRSA";
1297           case 65007: return "XAUTHInitRSAEncryption";
1298           case 65008: return "XAUTHRespRSAEncryption";
1299           case 65009: return "XAUTHInitRSARevisedEncryption";
1300           case 65010: return "XAUTHRespRSARevisedEncryption";
1301           default: return "UNKNOWN-AUTH-METHOD";
1302         }
1303       case 4:
1304       case 6:
1305       case 7:
1306       case 8:
1307       case 9:
1308       case 10:
1309       case 16:
1310         return "Group-Value";
1311       case 5:
1312         switch (value) {
1313           case 1:  return "MODP";
1314           case 2:  return "ECP";
1315           case 3:  return "EC2N";
1316           default: return "UNKNOWN-GROUPT-TYPE";
1317         }
1318       case 11:
1319         switch (value) {
1320           case 1:  return "Seconds";
1321           case 2:  return "Kilobytes";
1322           default: return "UNKNOWN-SA-VALUE";
1323         }
1324       case 12:
1325         return "Duration-Value";
1326       case 13:
1327         return "PRF-Value";
1328       case 14:
1329         return "Key-Length";
1330       case 15:
1331         return "Field-Size";
1332       default: return "UNKNOWN-ATTRIBUTE-TYPE";
1333     }
1334   }
1335 }
1336
1337 static const char * 
1338 attrtype2str(guint8 type) {
1339   switch (type) {
1340   case 0: return "Reserved";
1341   case 1: return "ISAKMP_CFG_REQUEST";
1342   case 2: return "ISAKMP_CFG_REPLY";
1343   case 3: return "ISAKMP_CFG_SET";
1344   case 4: return "ISAKMP_CFG_ACK";
1345   }
1346   if(type < 127)
1347     return "Future use";
1348   return "Private use";
1349 }
1350
1351 static const char * 
1352 cfgattrident2str(guint16 ident) {
1353 #define NUM_ATTR_DEFINED        12
1354   static const char *msgs[NUM_PREDEFINED] = {
1355     "RESERVED",
1356     "INTERNAL_IP4_ADDRESS",
1357     "INTERNAL_IP4_NETMASK",
1358     "INTERNAL_IP4_DNS",
1359     "INTERNAL_IP4_NBNS",
1360     "INTERNAL_ADDRESS_EXPIREY",
1361     "INTERNAL_IP4_DHCP",
1362     "APPLICATION_VERSION"
1363     "INTERNAL_IP6_ADDRESS",
1364     "INTERNAL_IP6_NETMASK",
1365     "INTERNAL_IP6_DNS",
1366     "INTERNAL_IP6_NBNS",
1367     "INTERNAL_IP6_DHCP",
1368   }; 
1369   if(ident < NUM_ATTR_DEFINED)
1370     return msgs[ident];
1371   if(ident < 16383)
1372     return "Future use";
1373   switch(ident) {
1374   case 16520: return "XAUTH_TYPE";
1375   case 16521: return "XAUTH_USER_NAME";
1376   case 16522: return "XAUTH_USER_PASSWORD";
1377   case 16523: return "XAUTH_PASSCODE";
1378   case 16524: return "XAUTH_MESSAGE";
1379   case 16525: return "XAUTH_CHALLANGE";
1380   case 16526: return "XAUTH_DOMAIN";
1381   case 16527: return "XAUTH_STATUS";
1382   default: return "Private use";
1383   }
1384 }
1385
1386 static const char *
1387 num2str(const guint8 *pd, guint16 len) {
1388
1389 #define NUMSTR_LEN      1024
1390   static char           numstr[NUMSTR_LEN];
1391   
1392   switch (len) {
1393   case 1:
1394     snprintf(numstr, NUMSTR_LEN, "%u", *pd);
1395     break;
1396   case 2:
1397     snprintf(numstr, NUMSTR_LEN, "%u", pntohs(pd));
1398     break;
1399   case 3:
1400     snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd) & 0x0fff);
1401     break;
1402   case 4:
1403     snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd));
1404     break;
1405   default:
1406     snprintf(numstr, NUMSTR_LEN, "<too big>");
1407   }
1408
1409   return numstr;
1410 }
1411
1412 void
1413 proto_register_isakmp(void)
1414 {
1415 /*        static hf_register_info hf[] = {
1416                 { &variable,
1417                 { "Name",           "isakmp.abbreviation", TYPE, VALS_POINTER }},
1418         };*/
1419         static gint *ett[] = {
1420                 &ett_isakmp,
1421                 &ett_isakmp_flags,
1422                 &ett_isakmp_payload,
1423         };
1424
1425         proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol", "isakmp");
1426  /*       proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1427         proto_register_subtree_array(ett, array_length(ett));
1428 }
1429
1430 void
1431 proto_reg_handoff_isakmp(void)
1432 {
1433         old_dissector_add("udp.port", UDP_PORT_ISAKMP, dissect_isakmp);
1434 }