Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-dccp.c
1 /* packet-dccp.c
2  * Routines for Datagram Congestion Control Protocol, "DCCP" dissection:
3  * it should conform to RFC 4340
4  *
5  * Copyright 2005 _FF_
6  *
7  * Francesco Fondelli <francesco dot fondelli, gmail dot com>
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * Copied from packet-udp.c
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28  */
29
30 /* NOTES:
31  *
32  * Nov 13, 2006: makes checksum computation dependent
33  * upon the header CsCov field (cf. RFC 4340, 5.1)
34  * (Gerrit Renker)
35  *
36  * Nov 13, 2006: removes the case where checksums are zero
37  * (unlike UDP/packet-udp, from which the code stems,
38  * zero checksums are illegal in DCCP (as in TCP))
39  * (Gerrit Renker)
40  *
41  * Jan 29, 2007: updates the offsets of the timestamps to be
42  * compliant to (cf. RFC 4342, sec. 13).
43  * (Gerrit Renker)
44  *
45  * Mar 11, 2012: add support for RFC 5596 (DCCP-Listen Packet)
46  * (Francesco Fondelli)
47  */
48
49 #include "config.h"
50
51 #include <glib.h>
52
53 #include <epan/packet.h>
54 #include <epan/addr_resolv.h>
55 #include <epan/ipproto.h>
56 #include <epan/in_cksum.h>
57 #include <epan/prefs.h>
58 #include <epan/expert.h>
59 #include <epan/wmem/wmem.h>
60 #include "packet-ip.h"
61 #include <epan/conversation.h>
62 #include <epan/tap.h>
63 #include "packet-dccp.h"
64
65 /*
66  * Some definitions and the dissect_options() logic have been taken
67  * from Arnaldo Carvalho de Melo's DCCP implementation, thanks!
68  */
69 #define DCCP_GEN_HDR_LEN_NO_X 12      /* generic header length, without extended sequence numbers */
70 #define DCCP_GEN_HDR_LEN_X    16      /* generic header length, with extended sequence numbers */
71 #define DCCP_HDR_LEN 16               /* base DCCP header length, with 48 bits seqnums */
72 #define DCCP_HDR_LEN_MIN 12           /* with 24 bits seqnum */
73 #define DCCP_HDR_PKT_TYPES_LEN_MAX 12 /* max per packet type extra
74                                        * header length
75                                        */
76 #define DCCP_OPT_LEN_MAX 1008
77 #define DCCP_HDR_LEN_MAX (DCCP_HDR_LEN + DCCP_HDR_PKT_TYPES_LEN_MAX + \
78                           DCCP_OPT_LEN_MAX)
79
80 void proto_register_dccp(void);
81 void proto_reg_handoff_dccp(void);
82
83 /*
84  * FF: please keep this list in sync with
85  * http://www.iana.org/assignments/dccp-parameters/dccp-parameters.xml
86  * Registry Name: 'Packet Types'
87  */
88 static const value_string dccp_packet_type_vals[] = {
89     {0x0, "Request" },
90     {0x1, "Response"},
91     {0x2, "Data"    },
92     {0x3, "Ack"     },
93     {0x4, "DataAck" },
94     {0x5, "CloseReq"},
95     {0x6, "Close"   },
96     {0x7, "Reset"   },
97     {0x8, "Sync"    },
98     {0x9, "SyncAck" },
99     {0xA, "Listen"  },
100     {0xB, "Reserved"},
101     {0xC, "Reserved"},
102     {0xD, "Reserved"},
103     {0xE, "Reserved"},
104     {0xF, "Reserved"},
105     {0,   NULL      }
106 };
107
108 static const value_string dccp_reset_code_vals[] = {
109     {0x00, "Unspecified"       },
110     {0x01, "Closed"            },
111     {0x02, "Aborted"           },
112     {0x03, "No Connection"     },
113     {0x04, "Packet Error"      },
114     {0x05, "Option Error"      },
115     {0x06, "Mandatory Error"   },
116     {0x07, "Connection Refused"},
117     {0x08, "Bad Service Code"  },
118     {0x09, "Too Busy"          },
119     {0x0A, "Bad Init Cookie"   },
120     {0x0B, "Aggression Penalty"},
121     {0x0C, "Reserved"          },
122     {0,    NULL                }
123 };
124
125 static const value_string dccp_feature_options_vals[] = {
126     {0x20, "Change L" },
127     {0x21, "Confirm L"},
128     {0x22, "Change R" },
129     {0x23, "Confirm R"},
130     {0,    NULL       }
131 };
132
133 static const value_string dccp_feature_numbers_vals[] = {
134     {0x01, "CCID"                     },
135     {0x02, "Allow Short Seqnums"      },
136     {0x03, "Sequence Window"          },
137     {0x04, "ECN Incapable"            },
138     {0x05, "Ack Ratio"                },
139     {0x06, "Send Ack Vector"          },
140     {0x07, "Send NDP Count"           },
141     {0x08, "Minimum Checksum Coverage"},
142     {0x09, "Check Data Checksum"      },
143     {0xC0, "Send Loss Event Rate"     }, /* CCID3, RFC 4342, 8.5 */
144     {0,    NULL                       }
145 };
146
147 static int proto_dccp = -1;
148 static int dccp_tap = -1;
149
150 static int hf_dccp_srcport = -1;
151 static int hf_dccp_dstport = -1;
152 static int hf_dccp_port = -1;
153 static int hf_dccp_data_offset = -1;
154 static int hf_dccp_ccval = -1;
155 static int hf_dccp_cscov = -1;
156 static int hf_dccp_checksum = -1;
157 static int hf_dccp_checksum_bad = -1;
158 static int hf_dccp_res1 = -1;
159 static int hf_dccp_type = -1;
160 static int hf_dccp_x = -1;
161 static int hf_dccp_res2 = -1;
162 static int hf_dccp_seq = -1;
163
164 static int hf_dccp_ack_res = -1;
165 static int hf_dccp_ack = -1;
166
167 static int hf_dccp_service_code = -1;
168 static int hf_dccp_reset_code = -1;
169 static int hf_dccp_data1 = -1;
170 static int hf_dccp_data2 = -1;
171 static int hf_dccp_data3 = -1;
172
173 static int hf_dccp_options = -1;
174 static int hf_dccp_option_type = -1;
175 static int hf_dccp_feature_number = -1;
176 /* static int hf_dccp_ndp_count = -1; */
177 static int hf_dccp_timestamp = -1;
178 static int hf_dccp_timestamp_echo = -1;
179 static int hf_dccp_elapsed_time = -1;
180 static int hf_dccp_data_checksum = -1;
181
182 static gint ett_dccp = -1;
183 static gint ett_dccp_options = -1;
184
185 static expert_field ei_dccp_option_len_bad = EI_INIT;
186 static expert_field ei_dccp_advertised_header_length_bad = EI_INIT;
187 static expert_field ei_dccp_packet_type_reserved = EI_INIT;
188
189 static dissector_table_t dccp_subdissector_table;
190 static heur_dissector_list_t heur_subdissector_list;
191 static dissector_handle_t data_handle;
192
193 /* preferences */
194 static gboolean dccp_summary_in_tree = TRUE;
195 static gboolean try_heuristic_first  = FALSE;
196 static gboolean dccp_check_checksum  = TRUE;
197
198 static void
199 decode_dccp_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
200                   proto_tree *tree, int sport, int dport)
201 {
202     tvbuff_t *next_tvb;
203     int       low_port, high_port;
204     heur_dtbl_entry_t *hdtbl_entry;
205
206     next_tvb = tvb_new_subset_remaining(tvb, offset);
207
208     /*
209      * determine if this packet is part of a conversation and call dissector
210      * for the conversation if available
211      */
212     if (try_conversation_dissector(&pinfo->src, &pinfo->dst, PT_DCCP, sport,
213                                    dport, next_tvb, pinfo, tree, NULL)) {
214         return;
215     }
216
217     if (try_heuristic_first) {
218         /* do lookup with the heuristic subdissector table */
219         if (dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo,
220                                     tree, &hdtbl_entry, NULL)) {
221             return;
222         }
223     }
224
225     /*
226      * Do lookups with the subdissector table.
227      * We try the port number with the lower value first, followed by the
228      * port number with the higher value.  This means that, for packets
229      * where a dissector is registered for *both* port numbers:
230      *
231      * 1) we pick the same dissector for traffic going in both directions;
232      *
233      * 2) we prefer the port number that's more likely to be the right
234      * one (as that prefers well-known ports to reserved ports);
235      *
236      * although there is, of course, no guarantee that any such strategy
237      * will always pick the right port number.
238      * XXX - we ignore port numbers of 0, as some dissectors use a port
239      * number of 0 to disable the port.
240      */
241     if (sport > dport) {
242         low_port  = dport;
243         high_port = sport;
244     } else {
245         low_port  = sport;
246         high_port = dport;
247     }
248
249     if (low_port != 0 &&
250         dissector_try_uint(dccp_subdissector_table, low_port,
251                            next_tvb, pinfo, tree)) {
252         return;
253     }
254
255     if (high_port != 0 &&
256         dissector_try_uint(dccp_subdissector_table, high_port,
257                            next_tvb, pinfo, tree)) {
258         return;
259     }
260
261     if (!try_heuristic_first) {
262         /* do lookup with the heuristic subdissector table */
263         if (dissector_try_heuristic(heur_subdissector_list, next_tvb,
264                                     pinfo, tree, &hdtbl_entry, NULL)) {
265             return;
266         }
267     }
268
269     /* Oh, well, we don't know this; dissect it as data. */
270     call_dissector(data_handle, next_tvb, pinfo, tree);
271 }
272
273 /*
274  * decode a variable-length number of nbytes starting at offset.  Based on
275  * a concept by Arnaldo de Melo
276  */
277 static guint64
278 tvb_get_ntoh_var(tvbuff_t *tvb, gint offset, guint nbytes)
279 {
280     const guint8 *ptr;
281     guint64       value = 0;
282
283     ptr = tvb_get_ptr(tvb, offset, nbytes);
284     if (nbytes > 5)
285         value += ((guint64) * ptr++) << 40;
286     if (nbytes > 4)
287         value += ((guint64) * ptr++) << 32;
288     if (nbytes > 3)
289         value += ((guint64) * ptr++) << 24;
290     if (nbytes > 2)
291         value += ((guint64) * ptr++) << 16;
292     if (nbytes > 1)
293         value += ((guint64) * ptr++) << 8;
294     if (nbytes > 0)
295         value += *ptr;
296
297     return value;
298 }
299
300 static void
301 dissect_feature_options(proto_tree *dccp_options_tree, tvbuff_t *tvb,
302                         int offset, guint8 option_len,
303                         guint8 option_type)
304 {
305     guint8      feature_number = tvb_get_guint8(tvb, offset + 2);
306     proto_item *dccp_item, *hidden_item;
307     int         i;
308
309     hidden_item =
310         proto_tree_add_uint(dccp_options_tree, hf_dccp_feature_number, tvb,
311                             offset + 2, 1, feature_number);
312     PROTO_ITEM_SET_HIDDEN(hidden_item);
313
314     dccp_item =
315         proto_tree_add_text(dccp_options_tree, tvb, offset, option_len, "%s(",
316                             val_to_str_const(option_type,
317                                              dccp_feature_options_vals,
318                                              "Unknown Type"));
319
320     /*
321      * decode the feature according to whether it is server-priority (list)
322      * or NN (single number)
323      */
324     switch (feature_number) {
325
326     /* Server Priority features (RFC 4340, 6.3.1) */
327
328     case 1:       /* Congestion Control ID (CCID); fall through    */
329     case 2:       /* Allow Short Seqnums; fall through             */
330     case 4:       /* ECN Incapable; fall through                   */
331     case 6:       /* Send Ack Vector; fall through                 */
332     case 7:       /* Send NDP Count; fall through                  */
333     case 8:       /* Minimum Checksum Coverage; fall through       */
334     case 9:       /* Check Data Checksum; fall through             */
335     case 192:     /* Send Loss Event Rate, RFC 4342, section 8.4   */
336         proto_item_append_text(dccp_item, "%s",
337                                val_to_str_const(feature_number,
338                                                 dccp_feature_numbers_vals,
339                                                 "Unknown Type"));
340         for (i = 0; i < option_len - 3; i++)
341             proto_item_append_text(dccp_item, "%s %d", i ? "," : "",
342                                    tvb_get_guint8(tvb,
343                                                   offset + 3 + i));
344         break;
345
346     /* Non-negotiable features (RFC 4340, 6.3.2) */
347
348     case 3:       /* Sequence Window; fall through                 */
349     case 5:       /* Ack Ratio                                     */
350         proto_item_append_text(dccp_item, "%s",
351                                val_to_str_const(feature_number,
352                                                 dccp_feature_numbers_vals,
353                                                 "Unknown Type"));
354
355         if (option_len > 3) /* could be empty Confirm */
356             proto_item_append_text(dccp_item, " %" G_GINT64_MODIFIER "u",
357                                    tvb_get_ntoh_var(tvb, offset + 3,
358                                                     option_len - 3));
359         break;
360
361     /* Reserved, specific, or unknown features */
362     default:
363         if (feature_number == 0 ||
364             (feature_number >= 10 && feature_number <= 127))
365             proto_item_append_text(dccp_item, "Reserved feature number %d",
366                                    feature_number);
367         else if (feature_number >= 193)
368             proto_item_append_text(dccp_item, "CCID-specific feature number %d",
369                                    feature_number);
370         else
371             proto_item_append_text(dccp_item, "Unknown feature number %d",
372                                    feature_number);
373         break;
374     }
375     proto_item_append_text(dccp_item, ")");
376 }
377
378 /*
379  * This function dissects DCCP options
380  */
381 static void
382 dissect_options(tvbuff_t *tvb, packet_info *pinfo _U_,
383                 proto_tree *dccp_options_tree, proto_tree *tree _U_,
384                 e_dccphdr *dccph _U_,
385                 int offset_start,
386                 int offset_end)
387 {
388     /*
389      * if here I'm sure there is at least offset_end - offset_start bytes
390      * in tvb and it should be options
391      */
392     int         offset      = offset_start;
393     guint8      option_type = 0;
394     guint8      option_len  = 0;
395     int         i;
396     guint32     p;
397     proto_item *dccp_item   = NULL;
398     proto_item *option_item;
399
400     while (offset < offset_end) {
401         /* first byte is the option type */
402         option_type = tvb_get_guint8(tvb, offset);
403         option_item =
404             proto_tree_add_uint(dccp_options_tree, hf_dccp_option_type, tvb,
405                                 offset,
406                                 1,
407                                 option_type);
408         PROTO_ITEM_SET_HIDDEN(option_item);
409
410         if (option_type >= 32) { /* variable length options */
411             option_len = tvb_get_guint8(tvb, offset + 1);
412
413             if (option_len < 2) {
414                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
415                     "Option length incorrect, must be >= 2");
416                 return;
417             }
418         } else { /* 1byte options */
419             option_len = 1;
420         }
421
422         switch (option_type) {
423         case 0:
424             proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
425                                 "Padding");
426             break;
427         case 1:
428             proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
429                                 "Mandatory");
430             break;
431         case 2:
432             proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
433                                 "Slow Receiver");
434             break;
435         case 32:
436         case 33:
437         case 34:
438         case 35:
439             dissect_feature_options(dccp_options_tree, tvb, offset, option_len,
440                                     option_type);
441             break;
442         case 36:
443             dccp_item =
444                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
445                                     "Init Cookie(");
446             for (i = 0; i < option_len - 2; i++) {
447                 if (i == 0)
448                     proto_item_append_text(dccp_item, "%02x",
449                                            tvb_get_guint8(tvb, offset + 2 + i));
450                 else
451                     proto_item_append_text(dccp_item, " %02x",
452                                            tvb_get_guint8(tvb, offset + 2 + i));
453             }
454             proto_item_append_text(dccp_item, ")");
455             break;
456         case 37:
457             if (option_len > 8)
458                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
459                                         "NDP Count too long (max 6 bytes)");
460             else
461                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
462                                     "NDP Count: %" G_GINT64_MODIFIER "u",
463                                     tvb_get_ntoh_var(tvb, offset + 2,
464                                                      option_len - 2));
465             break;
466         case 38:
467             dccp_item =
468                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
469                                     "Ack Vector [Nonce 0]:");
470             for (i = 0; i < option_len - 2; i++)
471                 proto_item_append_text(dccp_item, " %02x",
472                                        tvb_get_guint8(tvb, offset + 2 + i));
473             break;
474         case 39:
475             dccp_item =
476                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
477                                     "Ack Vector [Nonce 1]:");
478             for (i = 0; i < option_len - 2; i++)
479                 proto_item_append_text(dccp_item, " %02x",
480                                        tvb_get_guint8(tvb, offset + 2 + i));
481             proto_item_append_text(dccp_item, ")");
482             break;
483         case 40:
484             dccp_item =
485                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
486                                     "Data Dropped:");
487             for (i = 0; i < option_len - 2; i++)
488                 proto_item_append_text(dccp_item, " %02x",
489                                        tvb_get_guint8(tvb, offset + 2 + i));
490             break;
491         case 41:
492             if (option_len == 6)
493                 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp, tvb,
494                                     offset + 2, 4,
495                                     tvb_get_ntohl(tvb, offset + 2));
496             else
497                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
498                                         "Timestamp too long [%u != 6]", option_len);
499             break;
500         case 42:
501             if (option_len == 6)
502                 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
503                                     tvb, offset + 2, 4,
504                                     tvb_get_ntohl(tvb, offset + 2));
505             else if (option_len == 8) {
506                 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
507                                     tvb, offset + 2, 4,
508                                     tvb_get_ntohl(tvb, offset + 2));
509                 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
510                                     tvb, offset + 6, 2,
511                                     tvb_get_ntohs(tvb, offset + 6));
512             } else if (option_len == 10) {
513                 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
514                                     tvb, offset + 2, 4,
515                                     tvb_get_ntohl(tvb, offset + 2));
516                 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
517                                     tvb, offset + 6, 4,
518                                     tvb_get_ntohl(tvb, offset + 6));
519             } else
520                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
521                                         "Wrong Timestamp Echo length");
522             break;
523         case 43:
524             if (option_len == 4)
525                 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
526                                     tvb, offset + 2, 2,
527                                     tvb_get_ntohs(tvb, offset + 2));
528             else if (option_len == 6)
529                 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
530                                     tvb, offset + 2, 4,
531                                     tvb_get_ntohl(tvb, offset + 2));
532             else
533                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
534                                         "Wrong Elapsed Time length");
535             break;
536         case 44:
537             if (option_len == 6) {
538                 proto_tree_add_uint(dccp_options_tree, hf_dccp_data_checksum,
539                                     tvb, offset + 2, 4,
540                                     tvb_get_ntohl(tvb, offset + 2));
541             } else
542                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
543                                         "Wrong Data checksum length");
544             break;
545         case 192: /* RFC 4342, 8.5 */
546             if (option_len == 6) {
547                 p = tvb_get_ntohl(tvb, offset + 2);
548                 /*
549                  * According to the comment in section 8.5 of RFC 4342,
550                  * 0xffffffff can mean zero
551                  */
552                 if (p == 0xFFFFFFFF)
553                     proto_tree_add_text(dccp_options_tree, tvb, offset,
554                                         option_len,
555                                         "CCID3 Loss Event Rate: 0 (or max)");
556                 else
557                     proto_tree_add_text(dccp_options_tree, tvb, offset,
558                                         option_len, "CCID3 Loss Event Rate: %u",
559                                         p);
560             } else
561                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
562                                         "Wrong CCID3 Loss Event Rate length");
563             break;
564         case 193: /* RFC 4342, 8.6 */
565             proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
566                                 "CCID3 Loss Intervals");
567             /*
568              * FIXME: not implemented and apparently not used by any
569              * implementation so far
570              */
571             break;
572         case 194: /* RFC 4342, 8.3 */
573             if (option_len == 6)
574                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
575                                     "CCID3 Receive Rate: %u bytes/sec",
576                                     tvb_get_ntohl(tvb, offset + 2));
577             else
578                 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
579                                         "Wrong CCID3 Receive Rate length");
580             break;
581         default:
582             if (((option_type >= 45) && (option_type <= 127)) ||
583                 ((option_type >= 3) && (option_type <= 31))) {
584                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
585                                     "Reserved");
586                 break;
587             }
588
589             if (option_type >= 128) {
590                 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
591                                     "CCID option %d",
592                                     option_type);
593                 break;
594             }
595
596             /* if here we don't know this option */
597             proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
598                                 "Unknown");
599             break;
600         } /* end switch() */
601         offset += option_len; /* move offset past the dissected option */
602     } /* end while() */
603 }
604
605 /*
606  * compute DCCP checksum coverage according to RFC 4340, section 9
607 */
608 static inline guint
609 dccp_csum_coverage(const e_dccphdr *dccph, guint len)
610 {
611     guint cov;
612
613     if (dccph->cscov == 0)
614         return len;
615
616     cov = (dccph->data_offset + dccph->cscov - 1) * (guint)sizeof (guint32);
617     return (cov > len) ? len : cov;
618 }
619
620 static int
621 dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
622 {
623     proto_tree *dccp_tree;
624     proto_tree *dccp_options_tree = NULL;
625     proto_item *dccp_item         = NULL;
626     proto_item *hidden_item, *offset_item;
627
628     vec_t      cksum_vec[4];
629     guint32    phdr[2];
630     guint16    computed_cksum;
631     guint      offset                     = 0;
632     guint      len                        = 0;
633     guint      reported_len               = 0;
634     guint      advertised_dccp_header_len = 0;
635     guint      options_len                = 0;
636     e_dccphdr *dccph;
637
638     dccph = wmem_new0(wmem_packet_scope(), e_dccphdr);
639
640     SET_ADDRESS(&dccph->ip_src, pinfo->src.type, pinfo->src.len,
641                 pinfo->src.data);
642     SET_ADDRESS(&dccph->ip_dst, pinfo->dst.type, pinfo->dst.len,
643                 pinfo->dst.data);
644
645     col_set_str(pinfo->cinfo, COL_PROTOCOL, "DCCP");
646     col_clear(pinfo->cinfo, COL_INFO);
647
648     dccp_item = proto_tree_add_item(tree, proto_dccp, tvb, offset, -1, ENC_NA);
649     dccp_tree = proto_item_add_subtree(dccp_item, ett_dccp);
650
651     /* Extract generic header */
652     dccph->sport = tvb_get_ntohs(tvb, offset);
653     proto_tree_add_uint_format_value(dccp_tree, hf_dccp_srcport, tvb,
654                                      offset, 2, dccph->sport,
655                                      "%s (%u)",
656                                      ep_dccp_port_to_display(dccph->sport),
657                                      dccph->sport);
658     if (dccp_summary_in_tree) {
659         proto_item_append_text(dccp_item, ", Src Port: %s (%u)",
660                                ep_dccp_port_to_display(dccph->sport), dccph->sport);
661     }
662     col_add_fstr(pinfo->cinfo, COL_INFO,
663                  "%s ", ep_dccp_port_to_display(dccph->sport));
664     hidden_item =
665         proto_tree_add_uint(dccp_tree, hf_dccp_port, tvb, offset, 2,
666                             dccph->sport);
667     PROTO_ITEM_SET_HIDDEN(hidden_item);
668     offset += 2;
669
670     dccph->dport = tvb_get_ntohs(tvb, offset);
671     proto_tree_add_uint_format_value(dccp_tree, hf_dccp_dstport, tvb,
672                                      offset, 2, dccph->dport,
673                                      "%s (%u)",
674                                      ep_dccp_port_to_display(dccph->dport),
675                                      dccph->dport);
676     if (dccp_summary_in_tree) {
677         proto_item_append_text(dccp_item, ", Dst Port: %s (%u)",
678                                ep_dccp_port_to_display(dccph->dport), dccph->dport);
679     }
680     col_append_fstr(pinfo->cinfo, COL_INFO, " > %s",
681                     ep_dccp_port_to_display(dccph->dport));
682     hidden_item =
683         proto_tree_add_uint(dccp_tree, hf_dccp_port, tvb, offset, 2,
684                             dccph->dport);
685     PROTO_ITEM_SET_HIDDEN(hidden_item);
686     offset += 2;
687
688     /*
689      * update pinfo structure. I guess I have to do it, because this
690      * is a transport protocol dissector.
691      */
692     pinfo->ptype = PT_DCCP;
693     pinfo->srcport = dccph->sport;
694     pinfo->destport = dccph->dport;
695
696     dccph->data_offset = tvb_get_guint8(tvb, offset);
697     advertised_dccp_header_len = dccph->data_offset * 4;
698     offset_item = proto_tree_add_uint(dccp_tree, hf_dccp_data_offset, tvb, offset, 1,
699                                       dccph->data_offset);
700     offset += 1;
701
702     dccph->cscov = tvb_get_guint8(tvb, offset) & 0x0F;
703     dccph->ccval = tvb_get_guint8(tvb, offset) & 0xF0;
704     dccph->ccval >>= 4;
705     proto_tree_add_uint(dccp_tree, hf_dccp_ccval, tvb, offset, 1,
706                         dccph->ccval);
707     proto_tree_add_uint(dccp_tree, hf_dccp_cscov, tvb, offset, 1,
708                         dccph->cscov);
709     offset += 1;
710
711     dccph->checksum = tvb_get_ntohs(tvb, offset);
712
713     /*
714      * checksum analysis taken from packet-udp (difference: mandatory
715      * checksums in DCCP)
716      */
717     reported_len = tvb_reported_length(tvb);
718     len = tvb_length(tvb);
719
720     if (!pinfo->fragmented && len >= reported_len) {
721         /* The packet isn't part of a fragmented datagram and isn't
722             * truncated, so we can checksum it.
723             * XXX - make a bigger scatter-gather list once we do fragment
724             * reassembly? */
725         if (dccp_check_checksum) {
726             /* Set up the fields of the pseudo-header. */
727             cksum_vec[0].ptr = (const guint8 *)pinfo->src.data;
728             cksum_vec[0].len = pinfo->src.len;
729             cksum_vec[1].ptr = (const guint8 *)pinfo->dst.data;
730             cksum_vec[1].len = pinfo->dst.len;
731             cksum_vec[2].ptr = (const guint8 *) &phdr;
732             switch (pinfo->src.type) {
733             case AT_IPv4:
734                 phdr[0] = g_htonl((IP_PROTO_DCCP << 16) + reported_len);
735                 cksum_vec[2].len = 4;
736                 break;
737             case AT_IPv6:
738                 phdr[0] = g_htonl(reported_len);
739                 phdr[1] = g_htonl(IP_PROTO_DCCP);
740                 cksum_vec[2].len = 8;
741                 break;
742
743             default:
744                 /* DCCP runs only atop IPv4 and IPv6... */
745                 break;
746             }
747             cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, len);
748             cksum_vec[3].len = dccp_csum_coverage(dccph, reported_len);
749             computed_cksum = in_cksum(&cksum_vec[0], 4);
750             if (computed_cksum == 0) {
751                 proto_tree_add_uint_format_value(dccp_tree,
752                                                  hf_dccp_checksum, tvb,
753                                                  offset, 2,
754                                                  dccph->checksum,
755                                                  "0x%04x [correct]",
756                                                  dccph->checksum);
757             } else {
758                 hidden_item =
759                     proto_tree_add_boolean(dccp_tree, hf_dccp_checksum_bad,
760                                            tvb, offset, 2, TRUE);
761                 PROTO_ITEM_SET_HIDDEN(hidden_item);
762                 proto_tree_add_uint_format_value(
763                     dccp_tree, hf_dccp_checksum, tvb, offset, 2,
764                     dccph->checksum,
765                     "0x%04x [incorrect, should be 0x%04x]",
766                     dccph->checksum,
767                     in_cksum_shouldbe(dccph->checksum, computed_cksum));
768             }
769         } else {
770             proto_tree_add_uint_format_value(dccp_tree, hf_dccp_checksum,
771                                              tvb,
772                                              offset, 2, dccph->checksum,
773                                              "0x%04x", dccph->checksum);
774         }
775     } else {
776         proto_tree_add_uint_format_value(dccp_tree, hf_dccp_checksum, tvb,
777                                          offset, 2, dccph->checksum,
778                                          "0x%04x", dccph->checksum);
779     }
780     offset += 2;
781
782     dccph->reserved1 = tvb_get_guint8(tvb, offset) & 0xE0;
783     dccph->reserved1 >>= 5;
784     hidden_item =
785         proto_tree_add_uint(dccp_tree, hf_dccp_res1, tvb, offset, 1,
786                             dccph->reserved1);
787     PROTO_ITEM_SET_HIDDEN(hidden_item);
788
789     dccph->type = tvb_get_guint8(tvb, offset) & 0x1E;
790     dccph->type >>= 1;
791     proto_tree_add_uint(dccp_tree, hf_dccp_type, tvb, offset, 1,
792                         dccph->type);
793     if (dccp_summary_in_tree) {
794         proto_item_append_text(dccp_item, " [%s]",
795                                val_to_str_const(dccph->type, dccp_packet_type_vals,
796                                                 "Unknown Type"));
797     }
798     col_append_fstr(pinfo->cinfo, COL_INFO, " [%s]",
799                     val_to_str_const(dccph->type, dccp_packet_type_vals,
800                                      "Unknown Type"));
801
802     dccph->x = tvb_get_guint8(tvb, offset) & 0x01;
803     proto_tree_add_boolean(dccp_tree, hf_dccp_x, tvb, offset, 1,
804                            dccph->x);
805     offset += 1;
806
807     if (dccph->x) {
808         if (advertised_dccp_header_len < DCCP_GEN_HDR_LEN_X) {
809             expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
810                 "Advertised header length (%u) is smaller than the minimum (%u)",
811                 advertised_dccp_header_len, DCCP_GEN_HDR_LEN_X);
812             return tvb_length(tvb);
813         }
814         dccph->reserved2 = tvb_get_guint8(tvb, offset);
815         hidden_item =
816             proto_tree_add_uint(dccp_tree, hf_dccp_res2, tvb, offset, 1,
817                                 dccph->reserved2);
818         PROTO_ITEM_SET_HIDDEN(hidden_item);
819         offset += 1;
820
821         dccph->seq = tvb_get_ntoh48(tvb, offset);
822         proto_tree_add_uint64(dccp_tree, hf_dccp_seq, tvb, offset, 6,
823                               dccph->seq);
824         offset += 6;
825     } else {
826         if (advertised_dccp_header_len < DCCP_GEN_HDR_LEN_NO_X) {
827             expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
828                 "Advertised header length (%u) is smaller than the minimum (%u)",
829                 advertised_dccp_header_len, DCCP_GEN_HDR_LEN_NO_X);
830             return tvb_length(tvb);
831         }
832         dccph->seq = tvb_get_ntoh24(tvb, offset);
833         proto_tree_add_uint64(dccp_tree, hf_dccp_seq, tvb, offset, 3,
834                               dccph->seq);
835         offset += 3;
836     }
837     if (dccp_summary_in_tree) {
838         proto_item_append_text(dccp_item, " Seq=%" G_GINT64_MODIFIER "u",
839                                dccph->seq);
840     }
841     col_append_fstr(pinfo->cinfo, COL_INFO,
842                     " Seq=%" G_GINT64_MODIFIER "u",
843                     dccph->seq);
844
845     /* dissecting type dependant additional fields */
846     switch (dccph->type) {
847     case 0x0: /* DCCP-Request */
848     case 0xA: /* DCCP-Listen */
849         if (advertised_dccp_header_len < offset + 4) {
850             expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
851                 "Advertised header length (%u) is smaller than the minimum (%u) for %s",
852                 advertised_dccp_header_len, offset + 4,
853                 val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
854             return tvb_length(tvb);
855         }
856         dccph->service_code = tvb_get_ntohl(tvb, offset);
857         if (tree)
858             proto_tree_add_uint(dccp_tree, hf_dccp_service_code, tvb, offset, 4,
859                                 dccph->service_code);
860         col_append_fstr(pinfo->cinfo, COL_INFO, " (service=%u)",
861                         dccph->service_code);
862         offset += 4; /* move offset past the service code */
863         break;
864     case 0x1: /* DCCP-Response */
865         if (advertised_dccp_header_len < offset + 12) {
866             expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
867                 "Advertised header length (%u) is smaller than the minimum (%u) for Response",
868                 advertised_dccp_header_len, offset + 12);
869             return tvb_length(tvb);
870         }
871         dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
872         if (tree) {
873             hidden_item =
874                 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset, 2,
875                                     dccph->ack_reserved);
876             PROTO_ITEM_SET_HIDDEN(hidden_item);
877         }
878         dccph->ack = tvb_get_ntohs(tvb, offset + 2);
879         dccph->ack <<= 32;
880         dccph->ack += tvb_get_ntohl(tvb, offset + 4);
881
882         if (tree)
883             proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
884                                   dccph->ack);
885         col_append_fstr(pinfo->cinfo, COL_INFO,
886                         " (Ack=%" G_GINT64_MODIFIER "u)",
887                         dccph->ack);
888         offset += 8; /* move offset past the Acknowledgement Number Subheader */
889
890         dccph->service_code = tvb_get_ntohl(tvb, offset);
891         if (tree)
892             proto_tree_add_uint(dccp_tree, hf_dccp_service_code, tvb, offset, 4,
893                                 dccph->service_code);
894         col_append_fstr(pinfo->cinfo, COL_INFO, " (service=%u)",
895                         dccph->service_code);
896
897         offset += 4; /* move offset past the service code */
898         break;
899     case 0x2: /* DCCP-Data */
900         /* nothing to dissect */
901         break;
902     case 0x3: /* DCCP-Ack */
903     case 0x4: /* DCCP-DataAck */
904         if (dccph->x) {
905             if (advertised_dccp_header_len < offset + 8) {
906                 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
907                     "Advertised header length (%u) is smaller than the minimum (%u) for %s",
908                     advertised_dccp_header_len, offset + 8,
909                     val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
910                 return tvb_length(tvb);
911             }
912             dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
913             if (tree) {
914                 hidden_item =
915                     proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset,
916                                         2, dccph->ack_reserved);
917                 PROTO_ITEM_SET_HIDDEN(hidden_item);
918             }
919             dccph->ack = tvb_get_ntohs(tvb, offset + 2);
920             dccph->ack <<= 32;
921             dccph->ack += tvb_get_ntohl(tvb, offset + 4);
922             if (tree)
923                 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2,
924                                       6, dccph->ack);
925             col_append_fstr(pinfo->cinfo, COL_INFO,
926                             " (Ack=%" G_GINT64_MODIFIER "u)",
927                             dccph->ack);
928             offset += 8; /* move offset past the Ack Number Subheader */
929         } else {
930             if (advertised_dccp_header_len < offset + 4) {
931                 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
932                     "Advertised header length (%u) is smaller than the minimum (%u) for %s",
933                     advertised_dccp_header_len, offset + 4,
934                     val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
935                 return tvb_length(tvb);
936             }
937             dccph->ack_reserved = tvb_get_guint8(tvb, offset);
938             if (tree) {
939                 hidden_item =
940                     proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset,
941                                         1, dccph->ack_reserved);
942                 PROTO_ITEM_SET_HIDDEN(hidden_item);
943             }
944             dccph->ack = tvb_get_guint8(tvb, offset + 1);
945             dccph->ack <<= 16;
946             dccph->ack += tvb_get_ntohs(tvb, offset + 2);
947             if (tree)
948                 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 1,
949                                       3, dccph->ack);
950             col_append_fstr(pinfo->cinfo, COL_INFO,
951                             " (Ack=%" G_GINT64_MODIFIER "u)", dccph->ack);
952             offset += 4; /* move offset past the Ack. Number Subheader */
953         }
954         break;
955     case 0x7: /* DCCP-Reset */
956         if (advertised_dccp_header_len < offset + 4) {
957             expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
958                 "Advertised header length (%u) is smaller than the minimum (%u) for Reset",
959                 advertised_dccp_header_len, offset + 4);
960             return tvb_length(tvb);
961         }
962         dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
963
964         if (tree) {
965             hidden_item =
966                 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset, 2,
967                                     dccph->ack_reserved);
968             PROTO_ITEM_SET_HIDDEN(hidden_item);
969         }
970
971         dccph->ack = tvb_get_ntohs(tvb, offset + 2);
972         dccph->ack <<= 32;
973         dccph->ack += tvb_get_ntohl(tvb, offset + 4);
974
975         if (tree)
976             proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
977                                   dccph->ack);
978         col_append_fstr(pinfo->cinfo, COL_INFO,
979                         " (Ack=%" G_GINT64_MODIFIER "u)", dccph->ack);
980         offset += 8; /* move offset past the Ack. Number Subheader */
981
982         dccph->reset_code = tvb_get_guint8(tvb, offset);
983         dccph->data1 = tvb_get_guint8(tvb, offset + 1);
984         dccph->data2 = tvb_get_guint8(tvb, offset + 2);
985         dccph->data3 = tvb_get_guint8(tvb, offset + 3);
986
987         if (tree) {
988             proto_tree_add_uint(dccp_tree, hf_dccp_reset_code, tvb, offset, 1,
989                                 dccph->reset_code);
990             proto_tree_add_uint(dccp_tree, hf_dccp_data1, tvb, offset + 1, 1,
991                                 dccph->data1);
992             proto_tree_add_uint(dccp_tree, hf_dccp_data2, tvb, offset + 2, 1,
993                                 dccph->data2);
994             proto_tree_add_uint(dccp_tree, hf_dccp_data3, tvb, offset + 3, 1,
995                                 dccph->data3);
996         }
997         col_append_fstr(pinfo->cinfo, COL_INFO, " (code=%s)",
998                         val_to_str_const(dccph->reset_code, dccp_reset_code_vals,
999                                          "Unknown"));
1000
1001         offset += 4; /* move offset past the Reset Code and data123 */
1002         break;
1003     case 0x5: /* DCCP-CloseReq */
1004     case 0x6: /* DCCP-Close */
1005     case 0x8: /* DCCP-Sync */
1006     case 0x9: /* DCCP-SyncAck */
1007         if (advertised_dccp_header_len < offset + 8) {
1008             expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
1009                 "Advertised header length (%u) is smaller than the minimum (%u) for %s",
1010                 advertised_dccp_header_len, offset + 8,
1011                 val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
1012             return tvb_length(tvb);
1013         }
1014         dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
1015         if (tree) {
1016             hidden_item =
1017                 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset, 2,
1018                                     dccph->ack_reserved);
1019             PROTO_ITEM_SET_HIDDEN(hidden_item);
1020         }
1021         dccph->ack = tvb_get_ntohs(tvb, offset + 2);
1022         dccph->ack <<= 32;
1023         dccph->ack += tvb_get_ntohl(tvb, offset + 4);
1024         if (tree)
1025             proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
1026                                   dccph->ack);
1027         col_append_fstr(pinfo->cinfo, COL_INFO,
1028                         " (Ack=%" G_GINT64_MODIFIER "u)", dccph->ack);
1029         offset += 8; /* move offset past the Ack. Number Subheader */
1030         break;
1031     default:
1032         expert_add_info(pinfo, dccp_item, &ei_dccp_packet_type_reserved);
1033         return tvb_length(tvb);
1034     }
1035
1036     /*
1037      * note: data_offset is the offset from the start of the packet's
1038      * DCCP header to the start of its application data area, in 32-bit words.
1039      */
1040     if (advertised_dccp_header_len > DCCP_HDR_LEN_MAX) {
1041         expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
1042             "Advertised header length (%u) is larger than the maximum (%u)",
1043             advertised_dccp_header_len, DCCP_HDR_LEN_MAX);
1044         return tvb_length(tvb);
1045     }
1046
1047     /*
1048      * The checks done above ensure that
1049      * advertised_dccp_header_len >= offset.
1050      *
1051      * advertised_dccp_header_len - offset is the number of bytes of
1052      * options.
1053      */
1054     if (advertised_dccp_header_len > offset) {
1055         options_len = advertised_dccp_header_len - offset;
1056         if (dccp_tree) {
1057             dccp_item =
1058                 proto_tree_add_none_format(dccp_tree, hf_dccp_options, tvb,
1059                                            offset,
1060                                            options_len, "Options: (%u byte%s)",
1061                                            options_len,
1062                                            plurality(options_len, "", "s"));
1063             dccp_options_tree = proto_item_add_subtree(dccp_item,
1064                                                        ett_dccp_options);
1065         }
1066         dissect_options(tvb, pinfo, dccp_options_tree, tree, dccph, offset,
1067                         offset + options_len);
1068     }
1069
1070     offset += options_len; /* move offset past the Options */
1071     proto_item_set_end(dccp_item, tvb, offset);
1072
1073     /* queuing tap data */
1074     tap_queue_packet(dccp_tap, pinfo, dccph);
1075
1076     /* call sub-dissectors */
1077     if (!pinfo->flags.in_error_pkt || tvb_reported_length_remaining(tvb, offset) > 0)
1078         decode_dccp_ports(tvb, offset, pinfo, tree, dccph->sport, dccph->dport);
1079
1080     return tvb_length(tvb);
1081 }
1082
1083 void
1084 proto_register_dccp(void)
1085 {
1086     module_t *dccp_module;
1087
1088     static hf_register_info hf[] = {
1089         {
1090             &hf_dccp_srcport,
1091             {
1092                 "Source Port", "dccp.srcport",
1093                 FT_UINT16, BASE_DEC, NULL, 0x0,
1094                 NULL, HFILL
1095             }
1096         },
1097         {
1098             &hf_dccp_dstport,
1099             {
1100                 "Destination Port", "dccp.dstport",
1101                 FT_UINT16, BASE_DEC, NULL, 0x0,
1102                 NULL, HFILL
1103             }
1104         },
1105         {
1106             &hf_dccp_port,
1107             {
1108                 "Source or Destination Port", "dccp.port",
1109                 FT_UINT16, BASE_DEC, NULL, 0x0,
1110                 NULL, HFILL
1111             }
1112         },
1113         {
1114             &hf_dccp_data_offset,
1115             {
1116                 "Data Offset", "dccp.data_offset",
1117                 FT_UINT8, BASE_DEC, NULL, 0x0,
1118                 NULL, HFILL
1119             }
1120         },
1121         {
1122             &hf_dccp_ccval,
1123             {
1124                 "CCVal", "dccp.ccval",
1125                 FT_UINT8, BASE_DEC, NULL, 0x0,
1126                 NULL, HFILL
1127             }
1128         },
1129         {
1130             &hf_dccp_cscov,
1131             {
1132                 "Checksum Coverage", "dccp.cscov",
1133                 FT_UINT8, BASE_DEC, NULL, 0x0,
1134                 NULL, HFILL
1135             }
1136         },
1137         {
1138             &hf_dccp_checksum_bad,
1139             {
1140                 "Bad Checksum", "dccp.checksum_bad",
1141                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1142                 NULL, HFILL
1143             }
1144         },
1145         {
1146             &hf_dccp_checksum,
1147             {
1148                 "Checksum", "dccp.checksum",
1149                 FT_UINT16, BASE_HEX, NULL, 0x0,
1150                 NULL, HFILL
1151             }
1152         },
1153         {
1154             &hf_dccp_res1,
1155             {
1156                 "Reserved", "dccp.res1",
1157                 FT_UINT8, BASE_HEX, NULL, 0x0,
1158                 NULL, HFILL
1159             }
1160         },
1161         {
1162             &hf_dccp_res2,
1163             {
1164                 "Reserved", "dccp.res2",
1165                 FT_UINT8, BASE_HEX, NULL, 0x0,
1166                 NULL, HFILL
1167             }
1168         },
1169         {
1170             &hf_dccp_type,
1171             {
1172                 "Type", "dccp.type",
1173                 FT_UINT8, BASE_DEC, VALS(dccp_packet_type_vals), 0x0,
1174                 NULL, HFILL
1175             }
1176         },
1177         {
1178             &hf_dccp_x,
1179             {
1180                 "Extended Sequence Numbers", "dccp.x",
1181                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1182                 NULL, HFILL
1183             }
1184         },
1185         {
1186             &hf_dccp_seq,
1187             {
1188                 "Sequence Number", "dccp.seq",
1189                 FT_UINT64, BASE_DEC, NULL, 0x0,
1190                 NULL, HFILL
1191             }
1192         },
1193         {
1194             &hf_dccp_ack_res,
1195             {
1196                 "Reserved", "dccp.ack_res",
1197                 FT_UINT16, BASE_HEX, NULL, 0x0,
1198                 NULL, HFILL
1199             }
1200         },
1201         {
1202             &hf_dccp_ack,
1203             {
1204                 "Acknowledgement Number", "dccp.ack",
1205                 FT_UINT64, BASE_DEC, NULL, 0x0,
1206                 NULL, HFILL
1207             }
1208         },
1209         {
1210             &hf_dccp_service_code,
1211             {
1212                 "Service Code", "dccp.service_code",
1213                 FT_UINT32, BASE_DEC, NULL, 0x0,
1214                 NULL, HFILL
1215             }
1216         },
1217         {
1218             &hf_dccp_reset_code,
1219             {
1220                 "Reset Code", "dccp.reset_code",
1221                 FT_UINT8, BASE_DEC, VALS(dccp_reset_code_vals), 0x0,
1222                 NULL, HFILL
1223             }
1224         },
1225         {
1226             &hf_dccp_data1,
1227             {
1228                 "Data 1", "dccp.data1",
1229                 FT_UINT8, BASE_DEC, NULL, 0x0,
1230                 NULL, HFILL
1231             }
1232         },
1233         {
1234             &hf_dccp_data2,
1235             {
1236                 "Data 2", "dccp.data2",
1237                 FT_UINT8, BASE_DEC, NULL, 0x0,
1238                 NULL, HFILL
1239             }
1240         },
1241         {
1242             &hf_dccp_data3,
1243             {
1244                 "Data 3", "dccp.data3",
1245                 FT_UINT8, BASE_DEC, NULL, 0x0,
1246                 NULL, HFILL
1247             }
1248         },
1249         {
1250             &hf_dccp_option_type,
1251             {
1252                 "Option Type", "dccp.option_type",
1253                 FT_UINT8, BASE_DEC, NULL, 0x0,
1254                 NULL, HFILL
1255             }
1256         },
1257         {
1258             &hf_dccp_feature_number,
1259             {
1260                 "Feature Number", "dccp.feature_number",
1261                 FT_UINT8, BASE_DEC, NULL, 0x0,
1262                 NULL, HFILL
1263             }
1264         },
1265 #if 0
1266         {
1267             &hf_dccp_ndp_count,
1268             {
1269                 "NDP Count", "dccp.ndp_count",
1270                 FT_UINT64, BASE_DEC, NULL, 0x0,
1271                 NULL, HFILL
1272             }
1273         },
1274 #endif
1275         {
1276             &hf_dccp_timestamp,
1277             {
1278                 "Timestamp", "dccp.timestamp",
1279                 FT_UINT32, BASE_DEC, NULL, 0x0,
1280                 NULL, HFILL
1281             }
1282         },
1283         {
1284             &hf_dccp_timestamp_echo,
1285             {
1286                 "Timestamp Echo", "dccp.timestamp_echo",
1287                 FT_UINT32, BASE_DEC, NULL, 0x0,
1288                 NULL, HFILL
1289             }
1290         },
1291         {
1292             &hf_dccp_elapsed_time,
1293             {
1294                 "Elapsed Time", "dccp.elapsed_time",
1295                 FT_UINT32, BASE_DEC, NULL, 0x0,
1296                 NULL, HFILL
1297             }
1298         },
1299         {
1300             &hf_dccp_data_checksum,
1301             {
1302                 "Data Checksum", "dccp.checksum_data",
1303                 FT_UINT32, BASE_HEX, NULL, 0x0,
1304                 NULL, HFILL
1305             }
1306         },
1307         {
1308             &hf_dccp_options,
1309             {
1310                 "Options", "dccp.options",
1311                 FT_NONE, BASE_NONE, NULL, 0x0,
1312                 "DCCP Options fields", HFILL
1313             }
1314         }
1315     };
1316
1317     static gint *ett[] = {
1318         &ett_dccp,
1319         &ett_dccp_options
1320     };
1321
1322     static ei_register_info ei[] = {
1323         { &ei_dccp_option_len_bad, { "dccp.option.len.bad", PI_PROTOCOL, PI_WARN, "Bad option length", EXPFILL }},
1324         { &ei_dccp_advertised_header_length_bad, { "dccp.advertised_header_length.bad", PI_MALFORMED, PI_ERROR, "Advertised header length bad", EXPFILL }},
1325         { &ei_dccp_packet_type_reserved, { "dccp.packet_type.reserved", PI_PROTOCOL, PI_WARN, "Reserved packet type: unable to dissect further", EXPFILL }},
1326     };
1327
1328     expert_module_t* expert_dccp;
1329
1330     proto_dccp =
1331         proto_register_protocol("Datagram Congestion Control Protocol", "DCCP",
1332                                 "dccp");
1333     proto_register_field_array(proto_dccp, hf, array_length(hf));
1334     proto_register_subtree_array(ett, array_length(ett));
1335     expert_dccp = expert_register_protocol(proto_dccp);
1336     expert_register_field_array(expert_dccp, ei, array_length(ei));
1337
1338     /* subdissectors */
1339     dccp_subdissector_table =
1340         register_dissector_table("dccp.port", "DCCP port", FT_UINT16,
1341                                  BASE_DEC);
1342     register_heur_dissector_list("dccp", &heur_subdissector_list);
1343
1344     /* reg preferences */
1345     dccp_module = prefs_register_protocol(proto_dccp, NULL);
1346     prefs_register_bool_preference(
1347         dccp_module, "summary_in_tree",
1348         "Show DCCP summary in protocol tree",
1349         "Whether the DCCP summary line should be shown in the protocol tree",
1350         &dccp_summary_in_tree);
1351
1352     prefs_register_bool_preference(
1353         dccp_module, "try_heuristic_first",
1354         "Try heuristic sub-dissectors first",
1355         "Try to decode a packet using an heuristic sub-dissector before "
1356         "using a sub-dissector "
1357         "registered to a specific port",
1358         &try_heuristic_first);
1359
1360     prefs_register_bool_preference(
1361         dccp_module, "check_checksum",
1362         "Check the validity of the DCCP checksum when possible",
1363         "Whether to check the validity of the DCCP checksum",
1364         &dccp_check_checksum);
1365 }
1366
1367 void
1368 proto_reg_handoff_dccp(void)
1369 {
1370     dissector_handle_t dccp_handle;
1371
1372     dccp_handle = new_create_dissector_handle(dissect_dccp, proto_dccp);
1373     dissector_add_uint("ip.proto", IP_PROTO_DCCP, dccp_handle);
1374     data_handle = find_dissector("data");
1375     dccp_tap    = register_tap("dccp");
1376 }
1377
1378 /*
1379  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
1380  *
1381  * Local variables:
1382  * c-basic-offset: 4
1383  * tab-width: 8
1384  * indent-tabs-mode: nil
1385  * End:
1386  *
1387  * vi: set shiftwidth=4 tabstop=8 expandtab:
1388  * :indentSize=4:tabSize=8:noTabs=true:
1389  */