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>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * Copied from packet-udp.c
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 * Nov 13, 2006: makes checksum computation dependent
35 * upon the header CsCov field (cf. RFC 4340, 5.1)
38 * Nov 13, 2006: removes the case where checksums are zero
39 * (unlike UDP/packet-udp, from which the code stems,
40 * zero checksums are illegal in DCCP (as in TCP))
43 * Jan 29, 2007: updates the offsets of the timestamps to be
44 * compliant to (cf. RFC 4342, sec. 13).
47 * Mar 11, 2012: add support for RFC 5596 (DCCP-Listen Packet)
48 * (Francesco Fondelli)
55 #include <epan/packet.h>
56 #include <epan/addr_resolv.h>
57 #include <epan/ipproto.h>
58 #include <epan/in_cksum.h>
59 #include <epan/prefs.h>
60 #include <epan/expert.h>
61 #include <epan/wmem/wmem.h>
62 #include "packet-ip.h"
63 #include <epan/conversation.h>
65 #include "packet-dccp.h"
68 * Some definitions and the dissect_options() logic have been taken
69 * from Arnaldo Carvalho de Melo's DCCP implementation, thanks!
71 #define DCCP_GEN_HDR_LEN_NO_X 12 /* generic header length, without extended sequence numbers */
72 #define DCCP_GEN_HDR_LEN_X 16 /* generic header length, with extended sequence numbers */
73 #define DCCP_HDR_LEN 16 /* base DCCP header length, with 48 bits seqnums */
74 #define DCCP_HDR_LEN_MIN 12 /* with 24 bits seqnum */
75 #define DCCP_HDR_PKT_TYPES_LEN_MAX 12 /* max per packet type extra
78 #define DCCP_OPT_LEN_MAX 1008
79 #define DCCP_HDR_LEN_MAX (DCCP_HDR_LEN + DCCP_HDR_PKT_TYPES_LEN_MAX + \
82 void proto_register_dccp(void);
83 void proto_reg_handoff_dccp(void);
86 * FF: please keep this list in sync with
87 * http://www.iana.org/assignments/dccp-parameters/dccp-parameters.xml
88 * Registry Name: 'Packet Types'
90 static const value_string dccp_packet_type_vals[] = {
110 static const value_string dccp_reset_code_vals[] = {
111 {0x00, "Unspecified" },
114 {0x03, "No Connection" },
115 {0x04, "Packet Error" },
116 {0x05, "Option Error" },
117 {0x06, "Mandatory Error" },
118 {0x07, "Connection Refused"},
119 {0x08, "Bad Service Code" },
121 {0x0A, "Bad Init Cookie" },
122 {0x0B, "Aggression Penalty"},
127 static const value_string dccp_feature_options_vals[] = {
135 static const value_string dccp_feature_numbers_vals[] = {
137 {0x02, "Allow Short Seqnums" },
138 {0x03, "Sequence Window" },
139 {0x04, "ECN Incapable" },
140 {0x05, "Ack Ratio" },
141 {0x06, "Send Ack Vector" },
142 {0x07, "Send NDP Count" },
143 {0x08, "Minimum Checksum Coverage"},
144 {0x09, "Check Data Checksum" },
145 {0xC0, "Send Loss Event Rate" }, /* CCID3, RFC 4342, 8.5 */
149 static int proto_dccp = -1;
150 static int dccp_tap = -1;
152 static int hf_dccp_srcport = -1;
153 static int hf_dccp_dstport = -1;
154 static int hf_dccp_port = -1;
155 static int hf_dccp_data_offset = -1;
156 static int hf_dccp_ccval = -1;
157 static int hf_dccp_cscov = -1;
158 static int hf_dccp_checksum = -1;
159 static int hf_dccp_checksum_bad = -1;
160 static int hf_dccp_res1 = -1;
161 static int hf_dccp_type = -1;
162 static int hf_dccp_x = -1;
163 static int hf_dccp_res2 = -1;
164 static int hf_dccp_seq = -1;
166 static int hf_dccp_ack_res = -1;
167 static int hf_dccp_ack = -1;
169 static int hf_dccp_service_code = -1;
170 static int hf_dccp_reset_code = -1;
171 static int hf_dccp_data1 = -1;
172 static int hf_dccp_data2 = -1;
173 static int hf_dccp_data3 = -1;
175 static int hf_dccp_options = -1;
176 static int hf_dccp_option_type = -1;
177 static int hf_dccp_feature_number = -1;
178 /* static int hf_dccp_ndp_count = -1; */
179 static int hf_dccp_timestamp = -1;
180 static int hf_dccp_timestamp_echo = -1;
181 static int hf_dccp_elapsed_time = -1;
182 static int hf_dccp_data_checksum = -1;
184 static gint ett_dccp = -1;
185 static gint ett_dccp_options = -1;
187 static expert_field ei_dccp_option_len_bad = EI_INIT;
188 static expert_field ei_dccp_advertised_header_length_bad = EI_INIT;
189 static expert_field ei_dccp_packet_type_reserved = EI_INIT;
191 static dissector_table_t dccp_subdissector_table;
192 static heur_dissector_list_t heur_subdissector_list;
193 static dissector_handle_t data_handle;
196 static gboolean dccp_summary_in_tree = TRUE;
197 static gboolean try_heuristic_first = FALSE;
198 static gboolean dccp_check_checksum = TRUE;
201 decode_dccp_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
202 proto_tree *tree, int sport, int dport)
205 int low_port, high_port;
207 next_tvb = tvb_new_subset_remaining(tvb, offset);
210 * determine if this packet is part of a conversation and call dissector
211 * for the conversation if available
213 if (try_conversation_dissector(&pinfo->src, &pinfo->dst, PT_DCCP, sport,
214 dport, next_tvb, pinfo, tree, NULL)) {
218 if (try_heuristic_first) {
219 /* do lookup with the heuristic subdissector table */
220 if (dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo,
227 * Do lookups with the subdissector table.
228 * We try the port number with the lower value first, followed by the
229 * port number with the higher value. This means that, for packets
230 * where a dissector is registered for *both* port numbers:
232 * 1) we pick the same dissector for traffic going in both directions;
234 * 2) we prefer the port number that's more likely to be the right
235 * one (as that prefers well-known ports to reserved ports);
237 * although there is, of course, no guarantee that any such strategy
238 * will always pick the right port number.
239 * XXX - we ignore port numbers of 0, as some dissectors use a port
240 * number of 0 to disable the port.
251 dissector_try_uint(dccp_subdissector_table, low_port,
252 next_tvb, pinfo, tree)) {
256 if (high_port != 0 &&
257 dissector_try_uint(dccp_subdissector_table, high_port,
258 next_tvb, pinfo, tree)) {
262 if (!try_heuristic_first) {
263 /* do lookup with the heuristic subdissector table */
264 if (dissector_try_heuristic(heur_subdissector_list, next_tvb,
265 pinfo, tree, NULL)) {
270 /* Oh, well, we don't know this; dissect it as data. */
271 call_dissector(data_handle, next_tvb, pinfo, tree);
275 * decode a variable-length number of nbytes starting at offset. Based on
276 * a concept by Arnaldo de Melo
279 tvb_get_ntoh_var(tvbuff_t *tvb, gint offset, guint nbytes)
284 ptr = tvb_get_ptr(tvb, offset, nbytes);
286 value += ((guint64) * ptr++) << 40;
288 value += ((guint64) * ptr++) << 32;
290 value += ((guint64) * ptr++) << 24;
292 value += ((guint64) * ptr++) << 16;
294 value += ((guint64) * ptr++) << 8;
302 dissect_feature_options(proto_tree *dccp_options_tree, tvbuff_t *tvb,
303 int offset, guint8 option_len,
306 guint8 feature_number = tvb_get_guint8(tvb, offset + 2);
307 proto_item *dccp_item, *hidden_item;
311 proto_tree_add_uint(dccp_options_tree, hf_dccp_feature_number, tvb,
312 offset + 2, 1, feature_number);
313 PROTO_ITEM_SET_HIDDEN(hidden_item);
316 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len, "%s(",
317 val_to_str_const(option_type,
318 dccp_feature_options_vals,
322 * decode the feature according to whether it is server-priority (list)
323 * or NN (single number)
325 switch (feature_number) {
327 /* Server Priority features (RFC 4340, 6.3.1) */
329 case 1: /* Congestion Control ID (CCID); fall through */
330 case 2: /* Allow Short Seqnums; fall through */
331 case 4: /* ECN Incapable; fall through */
332 case 6: /* Send Ack Vector; fall through */
333 case 7: /* Send NDP Count; fall through */
334 case 8: /* Minimum Checksum Coverage; fall through */
335 case 9: /* Check Data Checksum; fall through */
336 case 192: /* Send Loss Event Rate, RFC 4342, section 8.4 */
337 proto_item_append_text(dccp_item, "%s",
338 val_to_str_const(feature_number,
339 dccp_feature_numbers_vals,
341 for (i = 0; i < option_len - 3; i++)
342 proto_item_append_text(dccp_item, "%s %d", i ? "," : "",
347 /* Non-negotiable features (RFC 4340, 6.3.2) */
349 case 3: /* Sequence Window; fall through */
350 case 5: /* Ack Ratio */
351 proto_item_append_text(dccp_item, "%s",
352 val_to_str_const(feature_number,
353 dccp_feature_numbers_vals,
356 if (option_len > 3) /* could be empty Confirm */
357 proto_item_append_text(dccp_item, " %" G_GINT64_MODIFIER "u",
358 tvb_get_ntoh_var(tvb, offset + 3,
362 /* Reserved, specific, or unknown features */
364 if (feature_number == 0 ||
365 (feature_number >= 10 && feature_number <= 127))
366 proto_item_append_text(dccp_item, "Reserved feature number %d",
368 else if (feature_number >= 193)
369 proto_item_append_text(dccp_item, "CCID-specific feature number %d",
372 proto_item_append_text(dccp_item, "Unknown feature number %d",
376 proto_item_append_text(dccp_item, ")");
380 * This function dissects DCCP options
383 dissect_options(tvbuff_t *tvb, packet_info *pinfo _U_,
384 proto_tree *dccp_options_tree, proto_tree *tree _U_,
385 e_dccphdr *dccph _U_,
390 * if here I'm sure there is at least offset_end - offset_start bytes
391 * in tvb and it should be options
393 int offset = offset_start;
394 guint8 option_type = 0;
395 guint8 option_len = 0;
398 proto_item *dccp_item = NULL;
399 proto_item *option_item;
401 while (offset < offset_end) {
402 /* first byte is the option type */
403 option_type = tvb_get_guint8(tvb, offset);
405 proto_tree_add_uint(dccp_options_tree, hf_dccp_option_type, tvb,
409 PROTO_ITEM_SET_HIDDEN(option_item);
411 if (option_type >= 32) { /* variable length options */
412 option_len = tvb_get_guint8(tvb, offset + 1);
414 if (option_len < 2) {
415 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
416 "Option length incorrect, must be >= 2");
419 } else { /* 1byte options */
423 switch (option_type) {
425 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
429 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
433 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
440 dissect_feature_options(dccp_options_tree, tvb, offset, option_len,
445 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
447 for (i = 0; i < option_len - 2; i++) {
449 proto_item_append_text(dccp_item, "%02x",
450 tvb_get_guint8(tvb, offset + 2 + i));
452 proto_item_append_text(dccp_item, " %02x",
453 tvb_get_guint8(tvb, offset + 2 + i));
455 proto_item_append_text(dccp_item, ")");
459 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
460 "NDP Count too long (max 6 bytes)");
462 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
463 "NDP Count: %" G_GINT64_MODIFIER "u",
464 tvb_get_ntoh_var(tvb, offset + 2,
469 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
470 "Ack Vector [Nonce 0]:");
471 for (i = 0; i < option_len - 2; i++)
472 proto_item_append_text(dccp_item, " %02x",
473 tvb_get_guint8(tvb, offset + 2 + i));
477 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
478 "Ack Vector [Nonce 1]:");
479 for (i = 0; i < option_len - 2; i++)
480 proto_item_append_text(dccp_item, " %02x",
481 tvb_get_guint8(tvb, offset + 2 + i));
482 proto_item_append_text(dccp_item, ")");
486 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
488 for (i = 0; i < option_len - 2; i++)
489 proto_item_append_text(dccp_item, " %02x",
490 tvb_get_guint8(tvb, offset + 2 + i));
494 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp, tvb,
496 tvb_get_ntohl(tvb, offset + 2));
498 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
499 "Timestamp too long [%u != 6]", option_len);
503 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
505 tvb_get_ntohl(tvb, offset + 2));
506 else if (option_len == 8) {
507 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
509 tvb_get_ntohl(tvb, offset + 2));
510 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
512 tvb_get_ntohs(tvb, offset + 6));
513 } else if (option_len == 10) {
514 proto_tree_add_uint(dccp_options_tree, hf_dccp_timestamp_echo,
516 tvb_get_ntohl(tvb, offset + 2));
517 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
519 tvb_get_ntohl(tvb, offset + 6));
521 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
522 "Wrong Timestamp Echo length");
526 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
528 tvb_get_ntohs(tvb, offset + 2));
529 else if (option_len == 6)
530 proto_tree_add_uint(dccp_options_tree, hf_dccp_elapsed_time,
532 tvb_get_ntohl(tvb, offset + 2));
534 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
535 "Wrong Elapsed Time length");
538 if (option_len == 6) {
539 proto_tree_add_uint(dccp_options_tree, hf_dccp_data_checksum,
541 tvb_get_ntohl(tvb, offset + 2));
543 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
544 "Wrong Data checksum length");
546 case 192: /* RFC 4342, 8.5 */
547 if (option_len == 6) {
548 p = tvb_get_ntohl(tvb, offset + 2);
550 * According to the comment in section 8.5 of RFC 4342,
551 * 0xffffffff can mean zero
554 proto_tree_add_text(dccp_options_tree, tvb, offset,
556 "CCID3 Loss Event Rate: 0 (or max)");
558 proto_tree_add_text(dccp_options_tree, tvb, offset,
559 option_len, "CCID3 Loss Event Rate: %u",
562 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
563 "Wrong CCID3 Loss Event Rate length");
565 case 193: /* RFC 4342, 8.6 */
566 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
567 "CCID3 Loss Intervals");
569 * FIXME: not implemented and apparently not used by any
570 * implementation so far
573 case 194: /* RFC 4342, 8.3 */
575 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
576 "CCID3 Receive Rate: %u bytes/sec",
577 tvb_get_ntohl(tvb, offset + 2));
579 expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
580 "Wrong CCID3 Receive Rate length");
583 if (((option_type >= 45) && (option_type <= 127)) ||
584 ((option_type >= 3) && (option_type <= 31))) {
585 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
590 if (option_type >= 128) {
591 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
597 /* if here we don't know this option */
598 proto_tree_add_text(dccp_options_tree, tvb, offset, option_len,
602 offset += option_len; /* move offset past the dissected option */
607 * compute DCCP checksum coverage according to RFC 4340, section 9
610 dccp_csum_coverage(const e_dccphdr *dccph, guint len)
614 if (dccph->cscov == 0)
617 cov = (dccph->data_offset + dccph->cscov - 1) * (guint)sizeof (guint32);
618 return (cov > len) ? len : cov;
622 dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
624 proto_tree *dccp_tree;
625 proto_tree *dccp_options_tree = NULL;
626 proto_item *dccp_item = NULL;
627 proto_item *hidden_item, *offset_item;
631 guint16 computed_cksum;
634 guint reported_len = 0;
635 guint advertised_dccp_header_len = 0;
636 guint options_len = 0;
639 dccph = wmem_new0(wmem_packet_scope(), e_dccphdr);
641 SET_ADDRESS(&dccph->ip_src, pinfo->src.type, pinfo->src.len,
643 SET_ADDRESS(&dccph->ip_dst, pinfo->dst.type, pinfo->dst.len,
646 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DCCP");
647 col_clear(pinfo->cinfo, COL_INFO);
649 dccp_item = proto_tree_add_item(tree, proto_dccp, tvb, offset, -1, ENC_NA);
650 dccp_tree = proto_item_add_subtree(dccp_item, ett_dccp);
652 /* Extract generic header */
653 dccph->sport = tvb_get_ntohs(tvb, offset);
654 proto_tree_add_uint_format_value(dccp_tree, hf_dccp_srcport, tvb,
655 offset, 2, dccph->sport,
657 get_dccp_port(dccph->sport),
659 if (dccp_summary_in_tree) {
660 proto_item_append_text(dccp_item, ", Src Port: %s (%u)",
661 get_dccp_port(dccph->sport), dccph->sport);
663 col_add_fstr(pinfo->cinfo, COL_INFO,
664 "%s ", get_dccp_port(dccph->sport));
666 proto_tree_add_uint(dccp_tree, hf_dccp_port, tvb, offset, 2,
668 PROTO_ITEM_SET_HIDDEN(hidden_item);
671 dccph->dport = tvb_get_ntohs(tvb, offset);
672 proto_tree_add_uint_format_value(dccp_tree, hf_dccp_dstport, tvb,
673 offset, 2, dccph->dport,
675 get_dccp_port(dccph->dport),
677 if (dccp_summary_in_tree) {
678 proto_item_append_text(dccp_item, ", Dst Port: %s (%u)",
679 get_dccp_port(dccph->dport), dccph->dport);
681 col_append_fstr(pinfo->cinfo, COL_INFO, " > %s",
682 get_dccp_port(dccph->dport));
684 proto_tree_add_uint(dccp_tree, hf_dccp_port, tvb, offset, 2,
686 PROTO_ITEM_SET_HIDDEN(hidden_item);
690 * update pinfo structure. I guess I have to do it, because this
691 * is a transport protocol dissector.
693 pinfo->ptype = PT_DCCP;
694 pinfo->srcport = dccph->sport;
695 pinfo->destport = dccph->dport;
697 dccph->data_offset = tvb_get_guint8(tvb, offset);
698 advertised_dccp_header_len = dccph->data_offset * 4;
699 offset_item = proto_tree_add_uint(dccp_tree, hf_dccp_data_offset, tvb, offset, 1,
703 dccph->cscov = tvb_get_guint8(tvb, offset) & 0x0F;
704 dccph->ccval = tvb_get_guint8(tvb, offset) & 0xF0;
706 proto_tree_add_uint(dccp_tree, hf_dccp_ccval, tvb, offset, 1,
708 proto_tree_add_uint(dccp_tree, hf_dccp_cscov, tvb, offset, 1,
712 dccph->checksum = tvb_get_ntohs(tvb, offset);
715 * checksum analysis taken from packet-udp (difference: mandatory
718 reported_len = tvb_reported_length(tvb);
719 len = tvb_length(tvb);
721 if (!pinfo->fragmented && len >= reported_len) {
722 /* The packet isn't part of a fragmented datagram and isn't
723 * truncated, so we can checksum it.
724 * XXX - make a bigger scatter-gather list once we do fragment
726 if (dccp_check_checksum) {
727 /* Set up the fields of the pseudo-header. */
728 cksum_vec[0].ptr = (const guint8 *)pinfo->src.data;
729 cksum_vec[0].len = pinfo->src.len;
730 cksum_vec[1].ptr = (const guint8 *)pinfo->dst.data;
731 cksum_vec[1].len = pinfo->dst.len;
732 cksum_vec[2].ptr = (const guint8 *) &phdr;
733 switch (pinfo->src.type) {
735 phdr[0] = g_htonl((IP_PROTO_DCCP << 16) + reported_len);
736 cksum_vec[2].len = 4;
739 phdr[0] = g_htonl(reported_len);
740 phdr[1] = g_htonl(IP_PROTO_DCCP);
741 cksum_vec[2].len = 8;
745 /* DCCP runs only atop IPv4 and IPv6... */
748 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, len);
749 cksum_vec[3].len = dccp_csum_coverage(dccph, reported_len);
750 computed_cksum = in_cksum(&cksum_vec[0], 4);
751 if (computed_cksum == 0) {
752 proto_tree_add_uint_format_value(dccp_tree,
753 hf_dccp_checksum, tvb,
760 proto_tree_add_boolean(dccp_tree, hf_dccp_checksum_bad,
761 tvb, offset, 2, TRUE);
762 PROTO_ITEM_SET_HIDDEN(hidden_item);
763 proto_tree_add_uint_format_value(
764 dccp_tree, hf_dccp_checksum, tvb, offset, 2,
766 "0x%04x [incorrect, should be 0x%04x]",
768 in_cksum_shouldbe(dccph->checksum, computed_cksum));
771 proto_tree_add_uint_format_value(dccp_tree, hf_dccp_checksum,
773 offset, 2, dccph->checksum,
774 "0x%04x", dccph->checksum);
777 proto_tree_add_uint_format_value(dccp_tree, hf_dccp_checksum, tvb,
778 offset, 2, dccph->checksum,
779 "0x%04x", dccph->checksum);
783 dccph->reserved1 = tvb_get_guint8(tvb, offset) & 0xE0;
784 dccph->reserved1 >>= 5;
786 proto_tree_add_uint(dccp_tree, hf_dccp_res1, tvb, offset, 1,
788 PROTO_ITEM_SET_HIDDEN(hidden_item);
790 dccph->type = tvb_get_guint8(tvb, offset) & 0x1E;
792 proto_tree_add_uint(dccp_tree, hf_dccp_type, tvb, offset, 1,
794 if (dccp_summary_in_tree) {
795 proto_item_append_text(dccp_item, " [%s]",
796 val_to_str_const(dccph->type, dccp_packet_type_vals,
799 col_append_fstr(pinfo->cinfo, COL_INFO, " [%s]",
800 val_to_str_const(dccph->type, dccp_packet_type_vals,
803 dccph->x = tvb_get_guint8(tvb, offset) & 0x01;
804 proto_tree_add_boolean(dccp_tree, hf_dccp_x, tvb, offset, 1,
809 if (advertised_dccp_header_len < DCCP_GEN_HDR_LEN_X) {
810 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
811 "Advertised header length (%u) is smaller than the minimum (%u)",
812 advertised_dccp_header_len, DCCP_GEN_HDR_LEN_X);
813 return tvb_length(tvb);
815 dccph->reserved2 = tvb_get_guint8(tvb, offset);
817 proto_tree_add_uint(dccp_tree, hf_dccp_res2, tvb, offset, 1,
819 PROTO_ITEM_SET_HIDDEN(hidden_item);
822 dccph->seq = tvb_get_ntoh48(tvb, offset);
823 proto_tree_add_uint64(dccp_tree, hf_dccp_seq, tvb, offset, 6,
827 if (advertised_dccp_header_len < DCCP_GEN_HDR_LEN_NO_X) {
828 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
829 "Advertised header length (%u) is smaller than the minimum (%u)",
830 advertised_dccp_header_len, DCCP_GEN_HDR_LEN_NO_X);
831 return tvb_length(tvb);
833 dccph->seq = tvb_get_ntoh24(tvb, offset);
834 proto_tree_add_uint64(dccp_tree, hf_dccp_seq, tvb, offset, 3,
838 if (dccp_summary_in_tree) {
839 proto_item_append_text(dccp_item, " Seq=%" G_GINT64_MODIFIER "u",
842 col_append_fstr(pinfo->cinfo, COL_INFO,
843 " Seq=%" G_GINT64_MODIFIER "u",
846 /* dissecting type dependant additional fields */
847 switch (dccph->type) {
848 case 0x0: /* DCCP-Request */
849 case 0xA: /* DCCP-Listen */
850 if (advertised_dccp_header_len < offset + 4) {
851 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
852 "Advertised header length (%u) is smaller than the minimum (%u) for %s",
853 advertised_dccp_header_len, offset + 4,
854 val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
855 return tvb_length(tvb);
857 dccph->service_code = tvb_get_ntohl(tvb, offset);
859 proto_tree_add_uint(dccp_tree, hf_dccp_service_code, tvb, offset, 4,
860 dccph->service_code);
861 col_append_fstr(pinfo->cinfo, COL_INFO, " (service=%u)",
862 dccph->service_code);
863 offset += 4; /* move offset past the service code */
865 case 0x1: /* DCCP-Response */
866 if (advertised_dccp_header_len < offset + 12) {
867 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
868 "Advertised header length (%u) is smaller than the minimum (%u) for Response",
869 advertised_dccp_header_len, offset + 12);
870 return tvb_length(tvb);
872 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
875 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset, 2,
876 dccph->ack_reserved);
877 PROTO_ITEM_SET_HIDDEN(hidden_item);
879 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
881 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
884 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
886 col_append_fstr(pinfo->cinfo, COL_INFO,
887 " (Ack=%" G_GINT64_MODIFIER "u)",
889 offset += 8; /* move offset past the Acknowledgement Number Subheader */
891 dccph->service_code = tvb_get_ntohl(tvb, offset);
893 proto_tree_add_uint(dccp_tree, hf_dccp_service_code, tvb, offset, 4,
894 dccph->service_code);
895 col_append_fstr(pinfo->cinfo, COL_INFO, " (service=%u)",
896 dccph->service_code);
898 offset += 4; /* move offset past the service code */
900 case 0x2: /* DCCP-Data */
901 /* nothing to dissect */
903 case 0x3: /* DCCP-Ack */
904 case 0x4: /* DCCP-DataAck */
906 if (advertised_dccp_header_len < offset + 8) {
907 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
908 "Advertised header length (%u) is smaller than the minimum (%u) for %s",
909 advertised_dccp_header_len, offset + 8,
910 val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
911 return tvb_length(tvb);
913 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
916 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset,
917 2, dccph->ack_reserved);
918 PROTO_ITEM_SET_HIDDEN(hidden_item);
920 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
922 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
924 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2,
926 col_append_fstr(pinfo->cinfo, COL_INFO,
927 " (Ack=%" G_GINT64_MODIFIER "u)",
929 offset += 8; /* move offset past the Ack Number Subheader */
931 if (advertised_dccp_header_len < offset + 4) {
932 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
933 "Advertised header length (%u) is smaller than the minimum (%u) for %s",
934 advertised_dccp_header_len, offset + 4,
935 val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
936 return tvb_length(tvb);
938 dccph->ack_reserved = tvb_get_guint8(tvb, offset);
941 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset,
942 1, dccph->ack_reserved);
943 PROTO_ITEM_SET_HIDDEN(hidden_item);
945 dccph->ack = tvb_get_guint8(tvb, offset + 1);
947 dccph->ack += tvb_get_ntohs(tvb, offset + 2);
949 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 1,
951 col_append_fstr(pinfo->cinfo, COL_INFO,
952 " (Ack=%" G_GINT64_MODIFIER "u)", dccph->ack);
953 offset += 4; /* move offset past the Ack. Number Subheader */
956 case 0x7: /* DCCP-Reset */
957 if (advertised_dccp_header_len < offset + 4) {
958 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
959 "Advertised header length (%u) is smaller than the minimum (%u) for Reset",
960 advertised_dccp_header_len, offset + 4);
961 return tvb_length(tvb);
963 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
967 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset, 2,
968 dccph->ack_reserved);
969 PROTO_ITEM_SET_HIDDEN(hidden_item);
972 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
974 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
977 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
979 col_append_fstr(pinfo->cinfo, COL_INFO,
980 " (Ack=%" G_GINT64_MODIFIER "u)", dccph->ack);
981 offset += 8; /* move offset past the Ack. Number Subheader */
983 dccph->reset_code = tvb_get_guint8(tvb, offset);
984 dccph->data1 = tvb_get_guint8(tvb, offset + 1);
985 dccph->data2 = tvb_get_guint8(tvb, offset + 2);
986 dccph->data3 = tvb_get_guint8(tvb, offset + 3);
989 proto_tree_add_uint(dccp_tree, hf_dccp_reset_code, tvb, offset, 1,
991 proto_tree_add_uint(dccp_tree, hf_dccp_data1, tvb, offset + 1, 1,
993 proto_tree_add_uint(dccp_tree, hf_dccp_data2, tvb, offset + 2, 1,
995 proto_tree_add_uint(dccp_tree, hf_dccp_data3, tvb, offset + 3, 1,
998 col_append_fstr(pinfo->cinfo, COL_INFO, " (code=%s)",
999 val_to_str_const(dccph->reset_code, dccp_reset_code_vals,
1002 offset += 4; /* move offset past the Reset Code and data123 */
1004 case 0x5: /* DCCP-CloseReq */
1005 case 0x6: /* DCCP-Close */
1006 case 0x8: /* DCCP-Sync */
1007 case 0x9: /* DCCP-SyncAck */
1008 if (advertised_dccp_header_len < offset + 8) {
1009 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
1010 "Advertised header length (%u) is smaller than the minimum (%u) for %s",
1011 advertised_dccp_header_len, offset + 8,
1012 val_to_str(dccph->type, dccp_packet_type_vals, "Unknown (%u)"));
1013 return tvb_length(tvb);
1015 dccph->ack_reserved = tvb_get_ntohs(tvb, offset);
1018 proto_tree_add_uint(dccp_tree, hf_dccp_ack_res, tvb, offset, 2,
1019 dccph->ack_reserved);
1020 PROTO_ITEM_SET_HIDDEN(hidden_item);
1022 dccph->ack = tvb_get_ntohs(tvb, offset + 2);
1024 dccph->ack += tvb_get_ntohl(tvb, offset + 4);
1026 proto_tree_add_uint64(dccp_tree, hf_dccp_ack, tvb, offset + 2, 6,
1028 col_append_fstr(pinfo->cinfo, COL_INFO,
1029 " (Ack=%" G_GINT64_MODIFIER "u)", dccph->ack);
1030 offset += 8; /* move offset past the Ack. Number Subheader */
1033 expert_add_info(pinfo, dccp_item, &ei_dccp_packet_type_reserved);
1034 return tvb_length(tvb);
1038 * note: data_offset is the offset from the start of the packet's
1039 * DCCP header to the start of its application data area, in 32-bit words.
1041 if (advertised_dccp_header_len > DCCP_HDR_LEN_MAX) {
1042 expert_add_info_format(pinfo, offset_item, &ei_dccp_advertised_header_length_bad,
1043 "Advertised header length (%u) is larger than the maximum (%u)",
1044 advertised_dccp_header_len, DCCP_HDR_LEN_MAX);
1045 return tvb_length(tvb);
1049 * The checks done above ensure that
1050 * advertised_dccp_header_len >= offset.
1052 * advertised_dccp_header_len - offset is the number of bytes of
1055 if (advertised_dccp_header_len > offset) {
1056 options_len = advertised_dccp_header_len - offset;
1059 proto_tree_add_none_format(dccp_tree, hf_dccp_options, tvb,
1061 options_len, "Options: (%u byte%s)",
1063 plurality(options_len, "", "s"));
1064 dccp_options_tree = proto_item_add_subtree(dccp_item,
1067 dissect_options(tvb, pinfo, dccp_options_tree, tree, dccph, offset,
1068 offset + options_len);
1071 offset += options_len; /* move offset past the Options */
1072 proto_item_set_end(dccp_item, tvb, offset);
1074 /* queuing tap data */
1075 tap_queue_packet(dccp_tap, pinfo, dccph);
1077 /* call sub-dissectors */
1078 if (!pinfo->flags.in_error_pkt || tvb_reported_length_remaining(tvb, offset) > 0)
1079 decode_dccp_ports(tvb, offset, pinfo, tree, dccph->sport, dccph->dport);
1081 return tvb_length(tvb);
1085 proto_register_dccp(void)
1087 module_t *dccp_module;
1089 static hf_register_info hf[] = {
1093 "Source Port", "dccp.srcport",
1094 FT_UINT16, BASE_DEC, NULL, 0x0,
1101 "Destination Port", "dccp.dstport",
1102 FT_UINT16, BASE_DEC, NULL, 0x0,
1109 "Source or Destination Port", "dccp.port",
1110 FT_UINT16, BASE_DEC, NULL, 0x0,
1115 &hf_dccp_data_offset,
1117 "Data Offset", "dccp.data_offset",
1118 FT_UINT8, BASE_DEC, NULL, 0x0,
1125 "CCVal", "dccp.ccval",
1126 FT_UINT8, BASE_DEC, NULL, 0x0,
1133 "Checksum Coverage", "dccp.cscov",
1134 FT_UINT8, BASE_DEC, NULL, 0x0,
1139 &hf_dccp_checksum_bad,
1141 "Bad Checksum", "dccp.checksum_bad",
1142 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1149 "Checksum", "dccp.checksum",
1150 FT_UINT16, BASE_HEX, NULL, 0x0,
1157 "Reserved", "dccp.res1",
1158 FT_UINT8, BASE_HEX, NULL, 0x0,
1165 "Reserved", "dccp.res2",
1166 FT_UINT8, BASE_HEX, NULL, 0x0,
1173 "Type", "dccp.type",
1174 FT_UINT8, BASE_DEC, VALS(dccp_packet_type_vals), 0x0,
1181 "Extended Sequence Numbers", "dccp.x",
1182 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1189 "Sequence Number", "dccp.seq",
1190 FT_UINT64, BASE_DEC, NULL, 0x0,
1197 "Reserved", "dccp.ack_res",
1198 FT_UINT16, BASE_HEX, NULL, 0x0,
1205 "Acknowledgement Number", "dccp.ack",
1206 FT_UINT64, BASE_DEC, NULL, 0x0,
1211 &hf_dccp_service_code,
1213 "Service Code", "dccp.service_code",
1214 FT_UINT32, BASE_DEC, NULL, 0x0,
1219 &hf_dccp_reset_code,
1221 "Reset Code", "dccp.reset_code",
1222 FT_UINT8, BASE_DEC, VALS(dccp_reset_code_vals), 0x0,
1229 "Data 1", "dccp.data1",
1230 FT_UINT8, BASE_DEC, NULL, 0x0,
1237 "Data 2", "dccp.data2",
1238 FT_UINT8, BASE_DEC, NULL, 0x0,
1245 "Data 3", "dccp.data3",
1246 FT_UINT8, BASE_DEC, NULL, 0x0,
1251 &hf_dccp_option_type,
1253 "Option Type", "dccp.option_type",
1254 FT_UINT8, BASE_DEC, NULL, 0x0,
1259 &hf_dccp_feature_number,
1261 "Feature Number", "dccp.feature_number",
1262 FT_UINT8, BASE_DEC, NULL, 0x0,
1270 "NDP Count", "dccp.ndp_count",
1271 FT_UINT64, BASE_DEC, NULL, 0x0,
1279 "Timestamp", "dccp.timestamp",
1280 FT_UINT32, BASE_DEC, NULL, 0x0,
1285 &hf_dccp_timestamp_echo,
1287 "Timestamp Echo", "dccp.timestamp_echo",
1288 FT_UINT32, BASE_DEC, NULL, 0x0,
1293 &hf_dccp_elapsed_time,
1295 "Elapsed Time", "dccp.elapsed_time",
1296 FT_UINT32, BASE_DEC, NULL, 0x0,
1301 &hf_dccp_data_checksum,
1303 "Data Checksum", "dccp.checksum_data",
1304 FT_UINT32, BASE_HEX, NULL, 0x0,
1311 "Options", "dccp.options",
1312 FT_NONE, BASE_NONE, NULL, 0x0,
1313 "DCCP Options fields", HFILL
1318 static gint *ett[] = {
1323 static ei_register_info ei[] = {
1324 { &ei_dccp_option_len_bad, { "dccp.option.len.bad", PI_PROTOCOL, PI_WARN, "Bad option length", EXPFILL }},
1325 { &ei_dccp_advertised_header_length_bad, { "dccp.advertised_header_length.bad", PI_MALFORMED, PI_ERROR, "Advertised header length bad", EXPFILL }},
1326 { &ei_dccp_packet_type_reserved, { "dccp.packet_type.reserved", PI_PROTOCOL, PI_WARN, "Reserved packet type: unable to dissect further", EXPFILL }},
1329 expert_module_t* expert_dccp;
1332 proto_register_protocol("Datagram Congestion Control Protocol", "DCCP",
1334 proto_register_field_array(proto_dccp, hf, array_length(hf));
1335 proto_register_subtree_array(ett, array_length(ett));
1336 expert_dccp = expert_register_protocol(proto_dccp);
1337 expert_register_field_array(expert_dccp, ei, array_length(ei));
1340 dccp_subdissector_table =
1341 register_dissector_table("dccp.port", "DCCP port", FT_UINT16,
1343 register_heur_dissector_list("dccp", &heur_subdissector_list);
1345 /* reg preferences */
1346 dccp_module = prefs_register_protocol(proto_dccp, NULL);
1347 prefs_register_bool_preference(
1348 dccp_module, "summary_in_tree",
1349 "Show DCCP summary in protocol tree",
1350 "Whether the DCCP summary line should be shown in the protocol tree",
1351 &dccp_summary_in_tree);
1353 prefs_register_bool_preference(
1354 dccp_module, "try_heuristic_first",
1355 "Try heuristic sub-dissectors first",
1356 "Try to decode a packet using an heuristic sub-dissector before "
1357 "using a sub-dissector "
1358 "registered to a specific port",
1359 &try_heuristic_first);
1361 prefs_register_bool_preference(
1362 dccp_module, "check_checksum",
1363 "Check the validity of the DCCP checksum when possible",
1364 "Whether to check the validity of the DCCP checksum",
1365 &dccp_check_checksum);
1369 proto_reg_handoff_dccp(void)
1371 dissector_handle_t dccp_handle;
1373 dccp_handle = new_create_dissector_handle(dissect_dccp, proto_dccp);
1374 dissector_add_uint("ip.proto", IP_PROTO_DCCP, dccp_handle);
1375 data_handle = find_dissector("data");
1376 dccp_tap = register_tap("dccp");
1380 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1385 * indent-tabs-mode: nil
1388 * vi: set shiftwidth=4 tabstop=8 expandtab:
1389 * :indentSize=4:tabSize=8:noTabs=true: