Don't trust data in packet.
[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.27 2000/10/02 18:38:50 gram 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     if (!IS_DATA_IN_FRAME(offset)) {
622             proto_tree_add_text(ntree, NullTVB, 0, 0,
623                             "Bad Offset: %u", offset);
624             return;
625     }
626   }
627
628   if (hdr->next_payload < NUM_LOAD_TYPES) {
629     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
630       dissect_transform(pd, offset, fd, tree, protocol_id);
631     else
632       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
633   }
634   else
635     old_dissect_data(pd, offset, fd, tree);
636 }
637
638 static void
639 dissect_key_exch(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
640
641   struct ke_hdr *       hdr     = (struct ke_hdr *)(pd + offset);
642   guint16               length  = pntohs(&hdr->length);
643   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Key Exchange payload");
644   proto_tree *          ntree;
645
646   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
647   
648   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
649                       "Next payload: %s (%u)",
650                       payloadtype2str(hdr->next_payload), hdr->next_payload);
651   offset += sizeof(hdr->next_payload) * 2;
652   
653   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
654                       "Length: %u", length);
655   offset += sizeof(length);
656   
657   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Key Exchange Data");
658   offset += (length - sizeof(*hdr));
659   
660   if (hdr->next_payload < NUM_LOAD_TYPES) {
661     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
662       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
663     else
664       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
665   }
666   else
667     old_dissect_data(pd, offset, fd, tree);
668 }
669
670 static void
671 dissect_id(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
672
673   struct id_hdr *       hdr     = (struct id_hdr *)(pd + offset);
674   guint16               length  = pntohs(&hdr->length);
675   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Identification payload");
676   proto_tree *          ntree;
677
678   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
679   
680   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
681                       "Next payload: %s (%u)",
682                       payloadtype2str(hdr->next_payload), hdr->next_payload);
683   offset += sizeof(hdr->next_payload) * 2;
684   
685   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
686                       "Length: %u", length);
687   offset += sizeof(length);
688   
689   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->id_type),
690                       "ID type: %s (%u)", id2str(hdr->id_type), hdr->id_type);
691   offset += sizeof(hdr->id_type);
692
693   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
694                       "Protocol ID: %u", hdr->protocol_id);
695   offset += sizeof(hdr->protocol_id);
696   
697   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->port),
698                       "Port: %u", pntohs(&hdr->port));
699   offset += sizeof(hdr->port);
700   
701   switch (hdr->id_type) {
702     case 1:
703     case 4:
704       proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
705                           "Identification data: %s", ip_to_str(pd+offset));
706       break;
707     case 2:
708     case 3:
709       proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
710                           "Identification data: %s", (char *)(pd+offset));
711       break;
712     default:
713       proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Identification Data");
714   }
715   offset += (length - sizeof(*hdr));
716   
717   if (hdr->next_payload < NUM_LOAD_TYPES) {
718     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
719       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
720     else
721       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
722   }
723   else
724     old_dissect_data(pd, offset, fd, tree);
725 }
726
727 static void
728 dissect_cert(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
729
730   struct cert_hdr *     hdr     = (struct cert_hdr *)(pd + offset);
731   guint16               length  = pntohs(&hdr->length);
732   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate payload");
733   proto_tree *          ntree;
734
735   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
736   
737   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
738                       "Next payload: %s (%u)",
739                       payloadtype2str(hdr->next_payload), hdr->next_payload);
740   offset += sizeof(hdr->next_payload) * 2;
741   
742   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
743                       "Length: %u", length);
744   offset += sizeof(length);
745   
746   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_enc),
747                       "Certificate encoding: %u", hdr->cert_enc);
748   offset += sizeof(hdr->cert_enc);
749
750   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Data");
751   offset += (length - sizeof(*hdr));
752   
753   if (hdr->next_payload < NUM_LOAD_TYPES) {
754     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
755       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
756     else
757       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
758   }
759   else
760     old_dissect_data(pd, offset, fd, tree);
761 }
762
763 static void
764 dissect_certreq(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
765
766   struct certreq_hdr *  hdr     = (struct certreq_hdr *)(pd + offset);
767   guint16               length  = pntohs(&hdr->length);
768   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate Request payload");
769   proto_tree *          ntree;
770
771   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
772   
773   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
774                       "Next payload: %s (%u)",
775                       payloadtype2str(hdr->next_payload), hdr->next_payload);
776   offset += sizeof(hdr->next_payload) * 2;
777   
778   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
779                       "Length: %u", length);
780   offset += sizeof(length);
781   
782   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_type),
783                       "Certificate type: %u", hdr->cert_type);
784   offset += sizeof(hdr->cert_type);
785
786   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Authority");
787   offset += (length - sizeof(*hdr));
788   
789   if (hdr->next_payload < NUM_LOAD_TYPES) {
790     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
791       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
792     else
793       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
794   }
795   else
796     old_dissect_data(pd, offset, fd, tree);
797 }
798
799 static void
800 dissect_hash(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
801
802   struct hash_hdr *     hdr     = (struct hash_hdr *)(pd + offset);
803   guint16               length  = pntohs(&hdr->length);
804   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Hash payload");
805   proto_tree *          ntree;
806
807   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
808   
809   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
810                       "Next payload: %s (%u)",
811                       payloadtype2str(hdr->next_payload), hdr->next_payload);
812   offset += sizeof(hdr->next_payload) * 2;
813   
814   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
815                       "Length: %u", length);
816   offset += sizeof(length);
817   
818   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Hash Data");
819   offset += (length - sizeof(*hdr));
820   
821   if (hdr->next_payload < NUM_LOAD_TYPES) {
822     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
823       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
824     else
825       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
826   }
827   else
828     old_dissect_data(pd, offset, fd, tree);
829 }
830
831 static void
832 dissect_sig(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
833
834   struct sig_hdr *      hdr     = (struct sig_hdr *)(pd + offset);
835   guint16               length  = pntohs(&hdr->length);
836   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Signature payload");
837   proto_tree *          ntree;
838
839   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
840   
841   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
842                       "Next payload: %s (%u)",
843                       payloadtype2str(hdr->next_payload), hdr->next_payload);
844   offset += sizeof(hdr->next_payload) * 2;
845   
846   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
847                       "Length: %u", length);
848   offset += sizeof(length);
849   
850   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Signature Data");
851   offset += (length - sizeof(*hdr));
852   
853   if (hdr->next_payload < NUM_LOAD_TYPES) {
854     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
855       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
856     else
857       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
858   }
859   else
860     old_dissect_data(pd, offset, fd, tree);
861 }
862
863 static void
864 dissect_nonce(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
865
866   struct nonce_hdr *    hdr     = (struct nonce_hdr *)(pd + offset);
867   guint16               length  = pntohs(&hdr->length);
868   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Nonce payload");
869   proto_tree *          ntree;
870
871   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
872   
873   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
874                       "Next payload: %s (%u)",
875                       payloadtype2str(hdr->next_payload), hdr->next_payload);
876   offset += sizeof(hdr->next_payload) * 2;
877   
878   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
879                       "Length: %u", length);
880   offset += sizeof(length);
881   
882   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Nonce Data");
883   offset += (length - sizeof(*hdr));
884   
885   if (hdr->next_payload < NUM_LOAD_TYPES) {
886     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
887       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
888     else
889       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
890   }
891   else
892     old_dissect_data(pd, offset, fd, tree);
893 }
894
895 static void
896 dissect_notif(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
897
898   struct notif_hdr *    hdr     = (struct notif_hdr *)(pd + offset);
899   guint16               length  = pntohs(&hdr->length);
900   guint32               doi     = pntohl(&hdr->doi);
901   guint16               msgtype = pntohs(&hdr->msgtype);
902   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Notification payload");
903   proto_tree *          ntree;
904
905   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
906   
907   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
908                       "Next payload: %s (%u)",
909                       payloadtype2str(hdr->next_payload), hdr->next_payload);
910   offset += sizeof(hdr->next_payload) * 2;
911   
912   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
913                       "Length: %u", length);
914   offset += sizeof(length);
915   
916   proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
917                       "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
918   offset += sizeof(doi);
919
920   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
921                       "Protocol ID: %s (%u)",
922                       proto2str(hdr->protocol_id), hdr->protocol_id);
923   offset += sizeof(hdr->protocol_id);
924   
925   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
926                       "SPI size: %u", hdr->spi_size);
927   offset += sizeof(hdr->spi_size);
928   
929   proto_tree_add_text(ntree, NullTVB, offset, sizeof(msgtype),
930                       "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
931   offset += sizeof(msgtype);
932
933   if (hdr->spi_size) {
934     proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size, "Security Parameter Index");
935     offset += hdr->spi_size;
936   }
937
938   if (length - sizeof(*hdr)) {
939     proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr) - hdr->spi_size,
940                         "Notification Data");
941     offset += (length - sizeof(*hdr) - hdr->spi_size);
942   }
943   
944   if (hdr->next_payload < NUM_LOAD_TYPES) {
945     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
946       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
947     else
948       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
949   }
950   else
951     old_dissect_data(pd, offset, fd, tree);
952 }
953
954 static void
955 dissect_delete(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
956
957   struct delete_hdr *   hdr      = (struct delete_hdr *)(pd + offset);
958   guint16               length   = pntohs(&hdr->length);
959   guint32               doi      = pntohl(&hdr->doi);
960   guint16               num_spis = pntohs(&hdr->num_spis);
961   proto_item *          ti       = proto_tree_add_text(tree, NullTVB, offset, length, "Delete payload");
962   proto_tree *          ntree;
963   guint16               i;
964   
965   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
966   
967   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
968                       "Next payload: %s (%u)",
969                       payloadtype2str(hdr->next_payload), hdr->next_payload);
970   offset += sizeof(hdr->next_payload) * 2;
971   
972   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
973                       "Length: %u", length);
974   offset += sizeof(length);
975   
976   proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
977                       "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
978   offset += sizeof(doi);
979
980   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
981                       "Protocol ID: %s (%u)",
982                       proto2str(hdr->protocol_id), hdr->protocol_id);
983   offset += sizeof(hdr->protocol_id);
984   
985   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
986                       "SPI size: %u", hdr->spi_size);
987   offset += sizeof(hdr->spi_size);
988   
989   proto_tree_add_text(ntree, NullTVB, offset, num_spis,
990                       "Number of SPIs: %u", num_spis);
991   offset += sizeof(hdr->num_spis);
992   
993   for (i = 0; i < num_spis; ++i) {
994     proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size,
995                         "SPI (%d)", i);
996     offset += hdr->spi_size;
997   }
998
999   if (hdr->next_payload < NUM_LOAD_TYPES) {
1000     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1001       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
1002     else
1003       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1004   }
1005   else
1006     old_dissect_data(pd, offset, fd, tree);
1007 }
1008
1009 static void
1010 dissect_vid(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1011
1012   struct vid_hdr *      hdr     = (struct vid_hdr *)(pd + offset);
1013   guint16               length  = pntohs(&hdr->length);
1014   proto_item *          ti      = proto_tree_add_text(tree, NullTVB, offset, length, "Vendor ID payload");
1015   proto_tree *          ntree;
1016
1017   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1018   
1019   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1020                       "Next payload: %s (%u)",
1021                       payloadtype2str(hdr->next_payload), hdr->next_payload);
1022   offset += sizeof(hdr->next_payload) * 2;
1023   
1024   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1025                       "Length: %u", length);
1026   offset += sizeof(length);
1027   
1028   proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Vendor ID");
1029   offset += (length - sizeof(*hdr));
1030   
1031   if (hdr->next_payload < NUM_LOAD_TYPES) {
1032     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1033       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
1034     else
1035       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1036   }
1037   else
1038     old_dissect_data(pd, offset, fd, tree);
1039 }
1040
1041 static void
1042 dissect_config(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1043
1044   struct cfg_hdr *      hdr      = (struct cfg_hdr *)(pd + offset);
1045   guint16               length   = pntohs(&hdr->length);
1046   proto_item *          ti       = proto_tree_add_text(tree, NullTVB, offset, length, "Attribute payload");
1047   proto_tree *          ntree;
1048
1049   ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1050
1051   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1052                       "Next payload: %s (%u)",
1053                       payloadtype2str(hdr->next_payload), hdr->next_payload);
1054   offset += sizeof(hdr->next_payload) *2;
1055   
1056   proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1057                      "Length: %u", length);
1058   offset += sizeof(length);
1059   
1060   proto_tree_add_text(ntree,NullTVB, offset, sizeof(hdr->type),
1061                       "Type %s (%u)",attrtype2str(hdr->type),hdr->type);
1062   
1063   offset += (sizeof(hdr->type) + sizeof(hdr->reserved2));
1064   
1065   proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->identifier),
1066                       "Identifier: %u", pntohs(&hdr->identifier));
1067   offset += sizeof(hdr->identifier);
1068   length -= sizeof(*hdr);
1069   
1070   while(length) {
1071     guint16 type = pntohs(pd + offset) & 0x7fff;
1072     guint16 val_len = pntohs(pd + offset + 2);
1073     
1074     if(pd[offset] & 0x80) {
1075       proto_tree_add_text(ntree, NullTVB, offset, 4,
1076                           "%s (%u)",cfgattrident2str(type),val_len);
1077       offset += 4;
1078       length -= 4;
1079     }
1080     else {
1081       guint pack_len = 4 + val_len;
1082
1083       proto_tree_add_text(ntree, NullTVB, offset, 4,
1084                           "%s (%se)", cfgattrident2str(type), num2str(pd + offset + 4, val_len));
1085       offset += pack_len;
1086       length -= pack_len;
1087     }
1088   }
1089
1090   if (hdr->next_payload < NUM_LOAD_TYPES) {
1091     if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1092       dissect_transform(pd, offset, fd, tree, 0);       /* XXX - protocol ID? */
1093     else
1094       (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1095   }
1096   else
1097     old_dissect_data(pd, offset, fd, tree);
1098  
1099 }
1100
1101 static const char *
1102 payloadtype2str(guint8 type) {
1103
1104   if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
1105   if (type < 128)            return "RESERVED";
1106   if (type < 256)            return "Private USE";
1107
1108   return "Huh? You should never see this! Shame on you!";
1109 }
1110
1111 static const char *
1112 exchtype2str(guint8 type) {
1113
1114 #define NUM_EXCHSTRS    7
1115   static const char * exchstrs[NUM_EXCHSTRS] = {
1116     "NONE",
1117     "Base",
1118     "Identity Protection (Main Mode)",
1119     "Authentication Only",
1120     "Aggressive",
1121     "Informational",
1122     "Transaction (Config Mode)"
1123   };
1124   
1125   if (type < NUM_EXCHSTRS) return exchstrs[type];
1126   if (type < 32)           return "ISAKMP Future Use";
1127   switch (type) {
1128   case 32:
1129     return "Quick Mode";
1130   case 33:
1131     return "New Group Mode";
1132   }
1133   if (type < 240)          return "DOI Specific Use";
1134   if (type < 256)          return "Private Use";
1135   
1136   return "Huh? You should never see this! Shame on you!";
1137 }
1138
1139 static const char *
1140 doitype2str(guint32 type) {
1141   if (type == 1) return "IPSEC";
1142   return "Unknown DOI Type";
1143 }
1144
1145 static const char *
1146 msgtype2str(guint16 type) {
1147
1148 #define NUM_PREDEFINED  31
1149   static const char *msgs[NUM_PREDEFINED] = {
1150     "<UNKNOWN>",
1151     "INVALID-PAYLOAD-TYPE",
1152     "DOI-NOT-SUPPORTED",
1153     "SITUATION-NOT-SUPPORTED",
1154     "INVALID-COOKIE",
1155     "INVALID-MAJOR-VERSION",
1156     "INVALID-MINOR-VERSION",
1157     "INVALID-EXCHANGE-TYPE",
1158     "INVALID-FLAGS",
1159     "INVALID-MESSAGE-ID",
1160     "INVALID-PROTOCOL-ID",
1161     "INVALID-SPI",
1162     "INVALID-TRANSFORM-ID",
1163     "ATTRIBUTES-NOT-SUPPORTED",
1164     "NO-PROPOSAL-CHOSEN",
1165     "BAD-PROPOSAL-SYNTAX",
1166     "PAYLOAD-MALFORMED",
1167     "INVALID-KEY-INFORMATION",
1168     "INVALID-ID-INFORMATION",
1169     "INVALID-CERT-ENCODING",
1170     "INVALID-CERTIFICATE",
1171     "CERT-TYPE-UNSUPPORTED",
1172     "INVALID-CERT-AUTHORITY",
1173     "INVALID-HASH-INFORMATION",
1174     "AUTHENTICATION-FAILED",
1175     "INVALID-SIGNATURE",
1176     "ADDRESS-NOTIFICATION",
1177     "NOTIFY-SA-LIFETIME",
1178     "CERTIFICATE-UNAVAILABLE",
1179     "UNSUPPORTED-EXCHANGE-TYPE",
1180     "UNEQUAL-PAYLOAD-LENGTHS"
1181   };
1182
1183   if (type < NUM_PREDEFINED) return msgs[type];
1184   if (type < 8192)           return "RESERVED (Future Use)";
1185   if (type < 16384)          return "Private Use";
1186   if (type < 16385)          return "CONNECTED";
1187   if (type < 24576)          return "RESERVED (Future Use) - status";
1188   if (type < 24577)          return "RESPONDER-LIFETIME";
1189   if (type < 24578)          return "REPLAY-STATUS";
1190   if (type < 24579)          return "INITIAL-CONTACT";
1191   if (type < 32768)          return "DOI-specific codes";
1192   if (type < 40960)          return "Private Use - status";
1193   if (type < 65535)          return "RESERVED (Future Use) - status (2)";
1194
1195   return "Huh? You should never see this! Shame on you!";
1196 }
1197
1198 static const char *
1199 situation2str(guint32 type) {
1200
1201 #define SIT_MSG_NUM     1024
1202 #define SIT_IDENTITY    0x01
1203 #define SIT_SECRECY     0x02
1204 #define SIT_INTEGRITY   0x04
1205
1206   static char   msg[SIT_MSG_NUM];
1207   int           n = 0;
1208   char *        sep = "";
1209   
1210   if (type & SIT_IDENTITY) {
1211     n += snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
1212     sep = " & ";
1213   }
1214   if (type & SIT_SECRECY) {
1215     n += snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
1216     sep = " & ";
1217   }
1218   if (type & SIT_INTEGRITY) {
1219     n += snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
1220     sep = " & ";
1221   }
1222
1223   return msg;
1224 }
1225
1226 static const char *
1227 value2str(int ike_p1, guint16 att_type, guint16 value) {
1228   
1229   if (value == 0) return "RESERVED";
1230   
1231   if (!ike_p1) {
1232   switch (att_type) {
1233     case 1:
1234       switch (value) {
1235         case 1:  return "Seconds";
1236         case 2:  return "Kilobytes";
1237         default: return "UNKNOWN-SA-VALUE";
1238       }
1239     case 2:
1240       return "Duration-Value";
1241     case 3:
1242       return "Group-Value";
1243     case 4:
1244       switch (value) {
1245         case 1:  return "Tunnel";
1246         case 2:  return "Transport";
1247         default: return "UNKNOWN-ENCAPSULATION-VALUE";
1248       }
1249     case 5:
1250       switch (value) {
1251         case 1:  return "HMAC-MD5";
1252         case 2:  return "HMAC-SHA";
1253         case 3:  return "DES-MAC";
1254         case 4:  return "KPDK";
1255         default: return "UNKNOWN-AUTHENTICATION-VALUE";
1256       }
1257     case 6:
1258       return "Key-Length";
1259     case 7:
1260       return "Key-Rounds";
1261     case 8:
1262       return "log2-size";
1263     default: return "UNKNOWN-ATTRIBUTE-TYPE";
1264   }
1265   }
1266   else {
1267     switch (att_type) {
1268       case 1:
1269         switch (value) {
1270           case 1:  return "DES-CBC";
1271           case 2:  return "IDEA-CBC";
1272           case 3:  return "BLOWFISH-CBC";
1273           case 4:  return "RC5-R16-B64-CBC";
1274           case 5:  return "3DES-CBC";
1275           case 6:  return "CAST-CBC";
1276           default: return "UNKNOWN-ENCRYPTION-ALG";
1277         }
1278       case 2:
1279         switch (value) {
1280           case 1:  return "MD5";
1281           case 2:  return "SHA";
1282           case 3:  return "TIGER";
1283           default: return "UNKNOWN-HASH-ALG";
1284         }
1285       case 3:
1286         switch (value) {
1287           case 1:  return "PSK";
1288           case 2:  return "DSS-SIG";
1289           case 3:  return "RSA-SIG";
1290           case 4:  return "RSA-ENC";
1291           case 5:  return "RSA-Revised-ENC";
1292           case 64221: return "HybridInitRSA";
1293           case 64222: return "HybridRespRSA";
1294           case 64223: return "HybridInitDSS";
1295           case 64224: return "HybridRespDSS";
1296           case 65001: return "XAUTHInitPreShared";
1297           case 65002: return "XAUTHRespPreShared";
1298           case 65003: return "XAUTHInitDSS";
1299           case 65004: return "XAUTHRespDSS";
1300           case 65005: return "XAUTHInitRSA";
1301           case 65006: return "XAUTHRespRSA";
1302           case 65007: return "XAUTHInitRSAEncryption";
1303           case 65008: return "XAUTHRespRSAEncryption";
1304           case 65009: return "XAUTHInitRSARevisedEncryption";
1305           case 65010: return "XAUTHRespRSARevisedEncryption";
1306           default: return "UNKNOWN-AUTH-METHOD";
1307         }
1308       case 4:
1309       case 6:
1310       case 7:
1311       case 8:
1312       case 9:
1313       case 10:
1314       case 16:
1315         return "Group-Value";
1316       case 5:
1317         switch (value) {
1318           case 1:  return "MODP";
1319           case 2:  return "ECP";
1320           case 3:  return "EC2N";
1321           default: return "UNKNOWN-GROUPT-TYPE";
1322         }
1323       case 11:
1324         switch (value) {
1325           case 1:  return "Seconds";
1326           case 2:  return "Kilobytes";
1327           default: return "UNKNOWN-SA-VALUE";
1328         }
1329       case 12:
1330         return "Duration-Value";
1331       case 13:
1332         return "PRF-Value";
1333       case 14:
1334         return "Key-Length";
1335       case 15:
1336         return "Field-Size";
1337       default: return "UNKNOWN-ATTRIBUTE-TYPE";
1338     }
1339   }
1340 }
1341
1342 static const char * 
1343 attrtype2str(guint8 type) {
1344   switch (type) {
1345   case 0: return "Reserved";
1346   case 1: return "ISAKMP_CFG_REQUEST";
1347   case 2: return "ISAKMP_CFG_REPLY";
1348   case 3: return "ISAKMP_CFG_SET";
1349   case 4: return "ISAKMP_CFG_ACK";
1350   }
1351   if(type < 127)
1352     return "Future use";
1353   return "Private use";
1354 }
1355
1356 static const char * 
1357 cfgattrident2str(guint16 ident) {
1358 #define NUM_ATTR_DEFINED        12
1359   static const char *msgs[NUM_PREDEFINED] = {
1360     "RESERVED",
1361     "INTERNAL_IP4_ADDRESS",
1362     "INTERNAL_IP4_NETMASK",
1363     "INTERNAL_IP4_DNS",
1364     "INTERNAL_IP4_NBNS",
1365     "INTERNAL_ADDRESS_EXPIREY",
1366     "INTERNAL_IP4_DHCP",
1367     "APPLICATION_VERSION"
1368     "INTERNAL_IP6_ADDRESS",
1369     "INTERNAL_IP6_NETMASK",
1370     "INTERNAL_IP6_DNS",
1371     "INTERNAL_IP6_NBNS",
1372     "INTERNAL_IP6_DHCP",
1373   }; 
1374   if(ident < NUM_ATTR_DEFINED)
1375     return msgs[ident];
1376   if(ident < 16383)
1377     return "Future use";
1378   switch(ident) {
1379   case 16520: return "XAUTH_TYPE";
1380   case 16521: return "XAUTH_USER_NAME";
1381   case 16522: return "XAUTH_USER_PASSWORD";
1382   case 16523: return "XAUTH_PASSCODE";
1383   case 16524: return "XAUTH_MESSAGE";
1384   case 16525: return "XAUTH_CHALLANGE";
1385   case 16526: return "XAUTH_DOMAIN";
1386   case 16527: return "XAUTH_STATUS";
1387   default: return "Private use";
1388   }
1389 }
1390
1391 static const char *
1392 num2str(const guint8 *pd, guint16 len) {
1393
1394 #define NUMSTR_LEN      1024
1395   static char           numstr[NUMSTR_LEN];
1396   
1397   switch (len) {
1398   case 1:
1399     snprintf(numstr, NUMSTR_LEN, "%u", *pd);
1400     break;
1401   case 2:
1402     snprintf(numstr, NUMSTR_LEN, "%u", pntohs(pd));
1403     break;
1404   case 3:
1405     snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd) & 0x0fff);
1406     break;
1407   case 4:
1408     snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd));
1409     break;
1410   default:
1411     snprintf(numstr, NUMSTR_LEN, "<too big>");
1412   }
1413
1414   return numstr;
1415 }
1416
1417 void
1418 proto_register_isakmp(void)
1419 {
1420 /*        static hf_register_info hf[] = {
1421                 { &variable,
1422                 { "Name",           "isakmp.abbreviation", TYPE, VALS_POINTER }},
1423         };*/
1424         static gint *ett[] = {
1425                 &ett_isakmp,
1426                 &ett_isakmp_flags,
1427                 &ett_isakmp_payload,
1428         };
1429
1430         proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol", "isakmp");
1431  /*       proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1432         proto_register_subtree_array(ett, array_length(ett));
1433 }
1434
1435 void
1436 proto_reg_handoff_isakmp(void)
1437 {
1438         old_dissector_add("udp.port", UDP_PORT_ISAKMP, dissect_isakmp);
1439 }