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