Wireshark-dev: [Wireshark-dev] [PATCH] dccp: support for variable-length checksums
From: Gerrit Renker <gerrit@xxxxxxxxxxxxxx>
Date: Mon, 30 Oct 2006 15:49:39 +0000
This patch adds support for correct computation of
variable length DCCP checksums as specified in 
RFC 4340, section 9.

Previously wireshark was unable to compute these 
checksums, only full-coverage checksums could be 
validated.

This patch
	* makes checksum computation dependent
          upon the header CsCov field (cf. RFC 4340, 5.1)
	* removes the case where checksums are zero
	  (unlike UDP/packet-udp, from which the code stems,
           zero checksums are illegal in DCCP (as in TCP))
	* fixes a minor typo - missing bitshift of the
	  CCVal field 


The patch has been tested against latest automatic build, 
correctness of checksum computation
has been manually validated; sample traces can be supplied. 

I would like to see this merged, in particular since a
Linux kernel patch for DCCP partial checksums already exists.

Please CC: all feedback to this address, I am not subscribed.

Thanks,
Gerrit Renker
---
 packet-dcp.c |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
--- wireshark-0.99.4-SVN-19738/epan/dissectors/packet-dcp.c.orig	2006-10-30 14:52:53.000000000 +0000
+++ wireshark-0.99.4-SVN-19738/epan/dissectors/packet-dcp.c	2006-10-30 14:53:02.000000000 +0000
@@ -541,6 +541,16 @@
 
 	} /* end while() */
 }
+/* compute DCCP checksum coverage according to RFC 4340, section 9 */
+static inline guint dccp_csum_coverage(const e_dcphdr *dcph, guint len)
+{
+	guint cov;
+	
+	if (dcph->cscov == 0)
+		return len;
+	cov = (dcph->data_offset + dcph->cscov - 1) * sizeof(guint32);
+	return (cov > len)? len : cov;
+}
 
 static void dissect_dcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
@@ -595,7 +605,8 @@
 	/* DBG("dcph->data_offset: %d\n", dcph->data_offset); */
 	dcph->cscov=tvb_get_guint8(tvb, offset+5)&0x0F;
 	/* DBG("dcph->cscov: %d\n", dcph->cscov); */
-	dcph->ccval=tvb_get_guint8(tvb, offset+5)&0xF0;
+	dcph->ccval=tvb_get_guint8(tvb, offset+5) &0xF0;
+	dcph->ccval >>= 4;
 	/* DBG("dcph->ccval: %d\n", dcph->ccval); */
 	dcph->checksum=tvb_get_ntohs(tvb, offset+6);
 	/* DBG("dcph->checksum: %d\n", dcph->checksum); */
@@ -662,15 +673,11 @@
 		proto_tree_add_uint(dcp_tree, hf_dcp_ccval, tvb, offset + 5, 1, dcph->ccval);
 		proto_tree_add_uint(dcp_tree, hf_dcp_cscov, tvb, offset + 5, 1, dcph->cscov);
 				
-		/* checksum analisys taken from packet-udp */
+		/* checksum analysis taken from packet-udp (difference: mandatory checksums in DCCP) */
 				
 		reported_len = tvb_reported_length(tvb);
 		len = tvb_length(tvb);
-		if (dcph->checksum == 0) {
-			/* No checksum supplied in the packet */
-			proto_tree_add_uint_format_value(dcp_tree, hf_dcp_checksum, tvb,
-							 offset + 6, 2, dcph->checksum, "0x%04x (none)", dcph->checksum);
-		} else if (!pinfo->fragmented && len >= reported_len) {
+		if (!pinfo->fragmented && len >= reported_len) {
 
 			/* The packet isn't part of a fragmented datagram and isn't
 			   truncated, so we can checksum it.
@@ -703,7 +710,7 @@
 					break;
 				}
 				cksum_vec[3].ptr = tvb_get_ptr(tvb, offset, len);
-				cksum_vec[3].len = reported_len;
+				cksum_vec[3].len = dccp_csum_coverage(dcph, reported_len);
 				computed_cksum = in_cksum(&cksum_vec[0], 4);
 				if (computed_cksum == 0) {
 					proto_tree_add_uint_format_value(dcp_tree, hf_dcp_checksum, tvb,