2 * Routines for Datagram Congestion Control Protocol, "DCCP" dissection:
3 * it should conform to RFC 4340
7 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * Copied from packet-udp.c
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.
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.
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.
32 * Nov 13, 2006: makes checksum computation dependent
33 * upon the header CsCov field (cf. RFC 4340, 5.1)
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))
41 * Jan 29, 2007: updates the offsets of the timestamps to be
42 * compliant to (cf. RFC 4342, sec. 13).
45 * Mar 11, 2012: add support for RFC 5596 (DCCP-Listen Packet)
46 * (Francesco Fondelli)
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>
63 #include "packet-dccp.h"
66 * Some definitions and the dissect_options() logic have been taken
67 * from Arnaldo Carvalho de Melo's DCCP implementation, thanks!
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
76 #define DCCP_OPT_LEN_MAX 1008
77 #define DCCP_HDR_LEN_MAX (DCCP_HDR_LEN + DCCP_HDR_PKT_TYPES_LEN_MAX + \
80 void proto_register_dccp(void);
81 void proto_reg_handoff_dccp(void);
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'
88 static const value_string dccp_packet_type_vals[] = {
108 static const value_string dccp_reset_code_vals[] = {
109 {0x00, "Unspecified" },
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" },
119 {0x0A, "Bad Init Cookie" },
120 {0x0B, "Aggression Penalty"},
125 static const value_string dccp_feature_options_vals[] = {
133 static const value_string dccp_feature_numbers_vals[] = {
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 */
147 static int proto_dccp = -1;
148 static int dccp_tap = -1;
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;
164 static int hf_dccp_ack_res = -1;
165 static int hf_dccp_ack = -1;
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;
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;
182 static gint ett_dccp = -1;
183 static gint ett_dccp_options = -1;
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;
189 static dissector_table_t dccp_subdissector_table;
190 static heur_dissector_list_t heur_subdissector_list;
191 static dissector_handle_t data_handle;
194 static gboolean dccp_summary_in_tree = TRUE;
195 static gboolean try_heuristic_first = FALSE;
196 static gboolean dccp_check_checksum = TRUE;
199 decode_dccp_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
200 proto_tree *tree, int sport, int dport)
203 int low_port, high_port;
204 heur_dtbl_entry_t *hdtbl_entry;
206 next_tvb = tvb_new_subset_remaining(tvb, offset);
209 * determine if this packet is part of a conversation and call dissector
210 * for the conversation if available
212 if (try_conversation_dissector(&pinfo->src, &pinfo->dst, PT_DCCP, sport,
213 dport, next_tvb, pinfo, tree, NULL)) {
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)) {
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:
231 * 1) we pick the same dissector for traffic going in both directions;
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);
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.
250 dissector_try_uint(dccp_subdissector_table, low_port,
251 next_tvb, pinfo, tree)) {
255 if (high_port != 0 &&
256 dissector_try_uint(dccp_subdissector_table, high_port,
257 next_tvb, pinfo, tree)) {
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)) {
269 /* Oh, well, we don't know this; dissect it as data. */
270 call_dissector(data_handle, next_tvb, pinfo, tree);
274 * decode a variable-length number of nbytes starting at offset. Based on
275 * a concept by Arnaldo de Melo
278 tvb_get_ntoh_var(tvbuff_t *tvb, gint offset, guint nbytes)
283 ptr = tvb_get_ptr(tvb, offset, nbytes);
285 value += ((guint64) * ptr++) << 40;
287 value += ((guint64) * ptr++) << 32;
289 value += ((guint64) * ptr++) << 24;
291 value += ((guint64) * ptr++) << 16;
293 value += ((guint64) * ptr++) << 8;
301 dissect_feature_options(proto_tree *dccp_options_tree, tvbuff_t *tvb,
302 int offset, guint8 option_len,
305 guint8 feature_number = tvb_get_guint8(tvb, offset + 2);
306 proto_item *dccp_item, *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);
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,
321 * decode the feature according to whether it is server-priority (list)
322 * or NN (single number)
324 switch (feature_number) {
326 /* Server Priority features (RFC 4340, 6.3.1) */
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,
340 for (i = 0; i < option_len - 3; i++)
341 proto_item_append_text(dccp_item, "%s %d", i ? "," : "",
346 /* Non-negotiable features (RFC 4340, 6.3.2) */
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,
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,
361 /* Reserved, specific, or unknown features */
363 if (feature_number == 0 ||
364 (feature_number >= 10 && feature_number <= 127))
365 proto_item_append_text(dccp_item, "Reserved feature number %d",
367 else if (feature_number >= 193)
368 proto_item_append_text(dccp_item, "CCID-specific feature number %d",
371 proto_item_append_text(dccp_item, "Unknown feature number %d",
375 proto_item_append_text(dccp_item, ")");
379 * This function dissects DCCP options
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_,
389 * if here I'm sure there is at least offset_end - offset_start bytes
390 * in tvb and it should be options
392 int offset = offset_start;
393 guint8 option_type = 0;
394 guint8 option_len = 0;
397 proto_item *dccp_item = NULL;
398 proto_item *option_item;
400 while (offset < offset_end) {
401 /* first byte is the option type */
402 option_type = tvb_get_guint8(tvb, offset);
404 proto_tree_add_uint(dccp_options_tree, hf_dccp_option_type, tvb,
408 PROTO_ITEM_SET_HIDDEN(option_item);
410 if (option_type >= 32) { /* variable length options */
411 option_len = tvb_get_guint8(tvb, offset + 1);
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");
418 } else { /* 1byte options */
422 switch (option_type) {
424 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
428 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
432 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
439 dissect_feature_options(dccp_options_tree, tvb, offset, option_len,
444 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
446 for (i = 0; i < option_len - 2; i++) {
448 proto_item_append_text(dccp_item, "%02x",
449 tvb_get_guint8(tvb, offset + 2 + i));
451 proto_item_append_text(dccp_item, " %02x",
452 tvb_get_guint8(tvb, offset + 2 + i));
454 proto_item_append_text(dccp_item, ")");
458 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
459 "NDP Count too long (max 6 bytes)");
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,
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));
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, ")");
485 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
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));
493 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp, tvb,
495 tvb_get_ntohl(tvb, offset + 2));
497 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
498 "Timestamp too long [%u != 6]", option_len);
502 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
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,
508 tvb_get_ntohl(tvb, offset + 2));
509 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
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,
515 tvb_get_ntohl(tvb, offset + 2));
516 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
518 tvb_get_ntohl(tvb, offset + 6));
520 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
521 "Wrong Timestamp Echo length");
525 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
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,
531 tvb_get_ntohl(tvb, offset + 2));
533 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
534 "Wrong Elapsed Time length");
537 if (option_len == 6) {
538 proto_tree_add_uint(dccp_options_tree, hf_dccp_data_checksum,
540 tvb_get_ntohl(tvb, offset + 2));
542 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
543 "Wrong Data checksum length");
545 case 192: /* RFC 4342, 8.5 */
546 if (option_len == 6) {
547 p = tvb_get_ntohl(tvb, offset + 2);
549 * According to the comment in section 8.5 of RFC 4342,
550 * 0xffffffff can mean zero
553 proto_tree_add_text(dccp_options_tree, tvb, offset,
555 "CCID3 Loss Event Rate: 0 (or max)");
557 proto_tree_add_text(dccp_options_tree, tvb, offset,
558 option_len, "CCID3 Loss Event Rate: %u",
561 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
562 "Wrong CCID3 Loss Event Rate length");
564 case 193: /* RFC 4342, 8.6 */
565 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
566 "CCID3 Loss Intervals");
568 * FIXME: not implemented and apparently not used by any
569 * implementation so far
572 case 194: /* RFC 4342, 8.3 */
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));
578 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
579 "Wrong CCID3 Receive Rate length");
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,
589 if (option_type >= 128) {
590 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
596 /* if here we don't know this option */
597 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
601 offset += option_len; /* move offset past the dissected option */
606 * compute DCCP checksum coverage according to RFC 4340, section 9
609 dccp_csum_coverage(const e_dccphdr *dccph, guint len)
613 if (dccph->cscov == 0)
616 cov = (dccph->data_offset + dccph->cscov - 1) * (guint)sizeof (guint32);
617 return (cov > len) ? len : cov;
621 dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
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;
630 guint16 computed_cksum;
633 guint reported_len = 0;
634 guint advertised_dccp_header_len = 0;
635 guint options_len = 0;
638 dccph = wmem_new0(wmem_packet_scope(), e_dccphdr);
640 SET_ADDRESS(&dccph->ip_src, pinfo->src.type, pinfo->src.len,
642 SET_ADDRESS(&dccph->ip_dst, pinfo->dst.type, pinfo->dst.len,
645 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DCCP");
646 col_clear(pinfo->cinfo, COL_INFO);
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);
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,
656 ep_dccp_port_to_display(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);
662 col_add_fstr(pinfo->cinfo, COL_INFO,
663 "%s ", ep_dccp_port_to_display(dccph->sport));
665 proto_tree_add_uint(dccp_tree, hf_dccp_port, tvb, offset, 2,
667 PROTO_ITEM_SET_HIDDEN(hidden_item);
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,
674 ep_dccp_port_to_display(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);
680 col_append_fstr(pinfo->cinfo, COL_INFO, " > %s",
681 ep_dccp_port_to_display(dccph->dport));
683 proto_tree_add_uint(dccp_tree, hf_dccp_port, tvb, offset, 2,
685 PROTO_ITEM_SET_HIDDEN(hidden_item);
689 * update pinfo structure. I guess I have to do it, because this
690 * is a transport protocol dissector.
692 pinfo->ptype = PT_DCCP;
693 pinfo->srcport = dccph->sport;
694 pinfo->destport = dccph->dport;
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,
702 dccph->cscov = tvb_get_guint8(tvb, offset) & 0x0F;
703 dccph->ccval = tvb_get_guint8(tvb, offset) & 0xF0;
705 proto_tree_add_uint(dccp_tree, hf_dccp_ccval, tvb, offset, 1,
707 proto_tree_add_uint(dccp_tree, hf_dccp_cscov, tvb, offset, 1,
711 dccph->checksum = tvb_get_ntohs(tvb, offset);
714 * checksum analysis taken from packet-udp (difference: mandatory
717 reported_len = tvb_reported_length(tvb);
718 len = tvb_length(tvb);
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
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) {
734 phdr[0] = g_htonl((IP_PROTO_DCCP << 16) + reported_len);
735 cksum_vec[2].len = 4;
738 phdr[0] = g_htonl(reported_len);
739 phdr[1] = g_htonl(IP_PROTO_DCCP);
740 cksum_vec[2].len = 8;
744 /* DCCP runs only atop IPv4 and IPv6... */
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,
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,
765 "0x%04x [incorrect, should be 0x%04x]",
767 in_cksum_shouldbe(dccph->checksum, computed_cksum));
770 proto_tree_add_uint_format_value(dccp_tree, hf_dccp_checksum,
772 offset, 2, dccph->checksum,
773 "0x%04x", dccph->checksum);
776 proto_tree_add_uint_format_value(dccp_tree, hf_dccp_checksum, tvb,
777 offset, 2, dccph->checksum,
778 "0x%04x", dccph->checksum);
782 dccph->reserved1 = tvb_get_guint8(tvb, offset) & 0xE0;
783 dccph->reserved1 >>= 5;
785 proto_tree_add_uint(dccp_tree, hf_dccp_res1, tvb, offset, 1,
787 PROTO_ITEM_SET_HIDDEN(hidden_item);
789 dccph->type = tvb_get_guint8(tvb, offset) & 0x1E;
791 proto_tree_add_uint(dccp_tree, hf_dccp_type, tvb, offset, 1,
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,
798 col_append_fstr(pinfo->cinfo, COL_INFO, " [%s]",
799 val_to_str_const(dccph->type, dccp_packet_type_vals,
802 dccph->x = tvb_get_guint8(tvb, offset) & 0x01;
803 proto_tree_add_boolean(dccp_tree, hf_dccp_x, tvb, offset, 1,
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);
814 dccph->reserved2 = tvb_get_guint8(tvb, offset);
816 proto_tree_add_uint(dccp_tree, hf_dccp_res2, tvb, offset, 1,
818 PROTO_ITEM_SET_HIDDEN(hidden_item);
821 dccph->seq = tvb_get_ntoh48(tvb, offset);
822 proto_tree_add_uint64(dccp_tree, hf_dccp_seq, tvb, offset, 6,
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);
832 dccph->seq = tvb_get_ntoh24(tvb, offset);
833 proto_tree_add_uint64(dccp_tree, hf_dccp_seq, tvb, offset, 3,
837 if (dccp_summary_in_tree) {
838 proto_item_append_text(dccp_item, " Seq=%" G_GINT64_MODIFIER "u",
841 col_append_fstr(pinfo->cinfo, COL_INFO,
842 " Seq=%" G_GINT64_MODIFIER "u",
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);
856 dccph->service_code = tvb_get_ntohl(tvb, offset);
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 */
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);
871 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
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);
878 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
880 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
883 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
885 col_append_fstr(pinfo->cinfo, COL_INFO,
886 " (Ack=%" G_GINT64_MODIFIER "u)",
888 offset += 8; /* move offset past the Acknowledgement Number Subheader */
890 dccph->service_code = tvb_get_ntohl(tvb, offset);
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);
897 offset += 4; /* move offset past the service code */
899 case 0x2: /* DCCP-Data */
900 /* nothing to dissect */
902 case 0x3: /* DCCP-Ack */
903 case 0x4: /* DCCP-DataAck */
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);
912 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
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);
919 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
921 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
923 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2,
925 col_append_fstr(pinfo->cinfo, COL_INFO,
926 " (Ack=%" G_GINT64_MODIFIER "u)",
928 offset += 8; /* move offset past the Ack Number Subheader */
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);
937 dccph->ack_reserved = tvb_get_guint8(tvb, offset);
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);
944 dccph->ack = tvb_get_guint8(tvb, offset + 1);
946 dccph->ack += tvb_get_ntohs(tvb, offset + 2);
948 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 1,
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 */
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);
962 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
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);
971 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
973 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
976 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
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 */
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);
988 proto_tree_add_uint(dccp_tree, hf_dccp_reset_code, tvb, offset, 1,
990 proto_tree_add_uint(dccp_tree, hf_dccp_data1, tvb, offset + 1, 1,
992 proto_tree_add_uint(dccp_tree, hf_dccp_data2, tvb, offset + 2, 1,
994 proto_tree_add_uint(dccp_tree, hf_dccp_data3, tvb, offset + 3, 1,
997 col_append_fstr(pinfo->cinfo, COL_INFO, " (code=%s)",
998 val_to_str_const(dccph->reset_code, dccp_reset_code_vals,
1001 offset += 4; /* move offset past the Reset Code and data123 */
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);
1014 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
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);
1021 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
1023 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
1025 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
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 */
1032 expert_add_info(pinfo, dccp_item, &ei_dccp_packet_type_reserved);
1033 return tvb_length(tvb);
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.
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);
1048 * The checks done above ensure that
1049 * advertised_dccp_header_len >= offset.
1051 * advertised_dccp_header_len - offset is the number of bytes of
1054 if (advertised_dccp_header_len > offset) {
1055 options_len = advertised_dccp_header_len - offset;
1058 proto_tree_add_none_format(dccp_tree, hf_dccp_options, tvb,
1060 options_len, "Options: (%u byte%s)",
1062 plurality(options_len, "", "s"));
1063 dccp_options_tree = proto_item_add_subtree(dccp_item,
1066 dissect_options(tvb, pinfo, dccp_options_tree, tree, dccph, offset,
1067 offset + options_len);
1070 offset += options_len; /* move offset past the Options */
1071 proto_item_set_end(dccp_item, tvb, offset);
1073 /* queuing tap data */
1074 tap_queue_packet(dccp_tap, pinfo, dccph);
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);
1080 return tvb_length(tvb);
1084 proto_register_dccp(void)
1086 module_t *dccp_module;
1088 static hf_register_info hf[] = {
1092 "Source Port", "dccp.srcport",
1093 FT_UINT16, BASE_DEC, NULL, 0x0,
1100 "Destination Port", "dccp.dstport",
1101 FT_UINT16, BASE_DEC, NULL, 0x0,
1108 "Source or Destination Port", "dccp.port",
1109 FT_UINT16, BASE_DEC, NULL, 0x0,
1114 &hf_dccp_data_offset,
1116 "Data Offset", "dccp.data_offset",
1117 FT_UINT8, BASE_DEC, NULL, 0x0,
1124 "CCVal", "dccp.ccval",
1125 FT_UINT8, BASE_DEC, NULL, 0x0,
1132 "Checksum Coverage", "dccp.cscov",
1133 FT_UINT8, BASE_DEC, NULL, 0x0,
1138 &hf_dccp_checksum_bad,
1140 "Bad Checksum", "dccp.checksum_bad",
1141 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1148 "Checksum", "dccp.checksum",
1149 FT_UINT16, BASE_HEX, NULL, 0x0,
1156 "Reserved", "dccp.res1",
1157 FT_UINT8, BASE_HEX, NULL, 0x0,
1164 "Reserved", "dccp.res2",
1165 FT_UINT8, BASE_HEX, NULL, 0x0,
1172 "Type", "dccp.type",
1173 FT_UINT8, BASE_DEC, VALS(dccp_packet_type_vals), 0x0,
1180 "Extended Sequence Numbers", "dccp.x",
1181 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1188 "Sequence Number", "dccp.seq",
1189 FT_UINT64, BASE_DEC, NULL, 0x0,
1196 "Reserved", "dccp.ack_res",
1197 FT_UINT16, BASE_HEX, NULL, 0x0,
1204 "Acknowledgement Number", "dccp.ack",
1205 FT_UINT64, BASE_DEC, NULL, 0x0,
1210 &hf_dccp_service_code,
1212 "Service Code", "dccp.service_code",
1213 FT_UINT32, BASE_DEC, NULL, 0x0,
1218 &hf_dccp_reset_code,
1220 "Reset Code", "dccp.reset_code",
1221 FT_UINT8, BASE_DEC, VALS(dccp_reset_code_vals), 0x0,
1228 "Data 1", "dccp.data1",
1229 FT_UINT8, BASE_DEC, NULL, 0x0,
1236 "Data 2", "dccp.data2",
1237 FT_UINT8, BASE_DEC, NULL, 0x0,
1244 "Data 3", "dccp.data3",
1245 FT_UINT8, BASE_DEC, NULL, 0x0,
1250 &hf_dccp_option_type,
1252 "Option Type", "dccp.option_type",
1253 FT_UINT8, BASE_DEC, NULL, 0x0,
1258 &hf_dccp_feature_number,
1260 "Feature Number", "dccp.feature_number",
1261 FT_UINT8, BASE_DEC, NULL, 0x0,
1269 "NDP Count", "dccp.ndp_count",
1270 FT_UINT64, BASE_DEC, NULL, 0x0,
1278 "Timestamp", "dccp.timestamp",
1279 FT_UINT32, BASE_DEC, NULL, 0x0,
1284 &hf_dccp_timestamp_echo,
1286 "Timestamp Echo", "dccp.timestamp_echo",
1287 FT_UINT32, BASE_DEC, NULL, 0x0,
1292 &hf_dccp_elapsed_time,
1294 "Elapsed Time", "dccp.elapsed_time",
1295 FT_UINT32, BASE_DEC, NULL, 0x0,
1300 &hf_dccp_data_checksum,
1302 "Data Checksum", "dccp.checksum_data",
1303 FT_UINT32, BASE_HEX, NULL, 0x0,
1310 "Options", "dccp.options",
1311 FT_NONE, BASE_NONE, NULL, 0x0,
1312 "DCCP Options fields", HFILL
1317 static gint *ett[] = {
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 }},
1328 expert_module_t* expert_dccp;
1331 proto_register_protocol("Datagram Congestion Control Protocol", "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));
1339 dccp_subdissector_table =
1340 register_dissector_table("dccp.port", "DCCP port", FT_UINT16,
1342 register_heur_dissector_list("dccp", &heur_subdissector_list);
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);
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);
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);
1368 proto_reg_handoff_dccp(void)
1370 dissector_handle_t dccp_handle;
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");
1379 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1384 * indent-tabs-mode: nil
1387 * vi: set shiftwidth=4 tabstop=8 expandtab:
1388 * :indentSize=4:tabSize=8:noTabs=true: