Ethereal-dev: [Ethereal-dev] YADP (Yet Another Diameter Patch)

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: David Frascone <dave@xxxxxxxxxxxx>
Date: Fri, 2 Nov 2001 23:40:03 -0600
Heh . . that didn't take long, did it!

The Diameter dissector now does desegmentation.  Too BEAUTIFUL!  If I had
known that it was this easy . . . .

BTW - I was looking back through old e-mails and found where I asked the
list about tcp reassembly about a year ago, and someone (Gilbert, I think)
was *thinking* about doing it . . . . there was an old thread about coloring
errors too and Guy was *very* against it, since tethereal doesn't display
color . . . History is funny :)


-Dave

On Friday, 02 Nov 2001, David Frascone wrote:
> Sweet!  I'll start hacking away then :)
> 
? diameter.diff
Index: packet-diameter.c
===================================================================
RCS file: /cvsroot/ethereal/packet-diameter.c,v
retrieving revision 1.30
diff -r1.30 packet-diameter.c
219a220,223
> 
> /* desegmentation of Diameter over TCP */
> static gboolean gbl_diameter_desegment = TRUE;
> 
934c938,939
< static void dissect_diameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
---
> static guint32 dissect_diameter_common(tvbuff_t *tvb, size_t start, packet_info *pinfo,
> 									   proto_tree *tree)
957a963,965
>   /* set our offset */
>   offset=start;
> 
1056c1064,1065
< 	ti = proto_tree_add_item(tree, proto_diameter, tvb, offset, tvb_length(tvb), FALSE);
---
> 	ti = proto_tree_add_item(tree, proto_diameter, tvb, offset,
> 							 MAX(pktLength,MIN_DIAMETER_SIZE), FALSE);
1111c1120
< 	  return;
---
> 	  return (offset + MAX(pktLength,MIN_DIAMETER_SIZE));
1120c1129
< 	avp_tvb = tvb_new_subset(tvb, offset, -1, avplength);
---
> 	avp_tvb = tvb_new_subset(tvb, offset, avplength, avplength);
1122c1131
< 								tvb, offset, tvb_length(tvb),
---
> 								tvb, offset, avplength,
1129a1139
> 	return MAX((offset + avplength), MIN_DIAMETER_SIZE);
1131c1141,1192
< } /* dissect_diameter */
---
>   return (offset + MAX(pktLength, MIN_DIAMETER_SIZE));
> 
> } /* dissect_diameter_common */
> 
> static void
> dissect_diameter_sctp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
> {
> 	dissect_diameter_common(tvb, 0, pinfo, tree);
> }
> 
> static void
> dissect_diameter_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
> {
> 	size_t offset = 0;
> 	guint32 plen;
> 	guint32 available_bytes;
> /* 	guint32 noffset; */
> 	
> 	/* Loop through the packet, dissecting multiple diameter messages */
> 	do {
> 		available_bytes = tvb_length_remaining(tvb, offset);
> 		if (available_bytes < 4) {
> 			g_warning("Diameter:  Bailing because only %d bytes of packet are available",
> 					  available_bytes);
> 			return; /* Bail.  We can't even get our length */
> 		}
> 
> 		/* get our packet length */
> 		plen = tvb_get_ntohl(tvb, offset);
> 		plen &= 0x00ffffff; /* get rid of the flags */
> 
> 		/*Desegmentation */
> 		if (gbl_diameter_desegment) {
> 			if (pinfo->can_desegment
> 				&& plen > available_bytes) {
> 				pinfo->desegment_offset = offset;
> 				pinfo->desegment_len = plen - available_bytes;
> /* 				g_warning("Diameter: Bailing for deseg because plen(%d) > available(%d)", */
> /* 						  plen, available_bytes); */
> 				return;
> 			}
> 		}
> 	
> 		/* Otherwise, dissect our packet */
> 		offset = dissect_diameter_common(tvb, offset, pinfo, tree);
> 
> /* 		g_warning("dissected from %d to %d bytes out of %d (available was %d plen was %d)", */
> /* 				  offset, noffset, tvb_length(tvb), available_bytes, plen); */
> /* 		offset=noffset; */
> 	} while (offset < tvb_length(tvb));
> 
> } /* dissect_diameter_tcp */
1552,1553c1613,1614
< 	dissector_delete("tcp.port", TcpPort, dissect_diameter);
< 	dissector_delete("sctp.port", SctpPort, dissect_diameter);
---
> 	dissector_delete("tcp.port", TcpPort, dissect_diameter_tcp);
> 	dissector_delete("sctp.port", SctpPort, dissect_diameter_sctp);
1566c1627
<   dissector_add("tcp.port", gbl_diameterTcpPort, dissect_diameter,
---
>   dissector_add("tcp.port", gbl_diameterTcpPort, dissect_diameter_tcp,
1569c1630
< 				dissect_diameter, proto_diameter);
---
> 				dissect_diameter_sctp, proto_diameter);
1734a1796,1800
> 	/* Desegmentation */
> 	prefs_register_bool_preference(diameter_module, "diameter.desegment",
> 								   "Desegment all Diameter messages spanning multiple TCP segments",
> 								   "Whether the Diameter dissector should desegment all messages spanning multiple TCP segments",
> 								   &gbl_diameter_desegment);