Ethereal-dev: [Ethereal-dev] Patch : OLSR decoding with unknown message types

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

From: "Yann ." <yann_eads@xxxxxxxxxxx>
Date: Wed, 05 Jan 2005 12:35:16 +0100
Hello Gerald,
Hello list,

As I'm developping an extension to olsrd, I noticed that the current Ethereal OLSR decoding does not handle properly messages with a custom message type. The first OLSR message in the packet with an unknown message type is considered to have no payload and the remaining data is decoded like if it were a new message header. The decoding of the rest of the packet is then totally wrong.

Here is a patch that modifies 'epan/dissectors/packet-olsr.c' to fix this issue. Now, the payload of unknown message types is marked as "Data (%u bytes)" and the next message in the same packet (if any) is well decoded.

I hope everything is fine since that's my first day in Ethereal development,
Yann




------------------------------------------------------------------
I don't read e-mails on yann_eads()hotmail.com

_________________________________________________________________
Nouveau MSN Hotmail : créez une adresse @hotmail.fr qui vous ressemble ! http://www.msn.fr/newmsnhotmail --- ethereal-0.10.8-orig/epan/dissectors/packet-olsr.c 2004-12-14 20:53:51.000000000 +0100 +++ ethereal-0.10.8/epan/dissectors/packet-olsr.c 2005-01-05 11:53:06.000000000 +0100
@@ -85,6 +85,8 @@
static int hf_olsr_netmask6 = -1;
static int hf_olsr_network6_addr = -1;

+static int hf_olsr_data = -1;
+
/* Initialize the subtree pointers*/
static gint ett_olsr = -1;

@@ -103,7 +105,7 @@
	proto_item *ti;
	proto_tree *olsr_tree;

- int offset, link_message_size, message_size, message_type, packet_size, position; + int offset, link_message_size, message_size, message_len, message_type, packet_size, position;
	int high_bits, low_bits, vtime, htime;
	double Vtime, Htime;

@@ -146,12 +148,9 @@
		 */
		if (!tvb_bytes_exist(tvb, 4, 4))
			return 0;	/* not enough bytes for them */
-		message_type = tvb_get_guint8(tvb, 4);
-		if (match_strval(message_type, message_type_vals) == NULL)
-			return 0;	/* not valid */
		/* OK, what about the message length? */
-		message_size = tvb_get_ntohs(tvb, 4+2);
-		if (message_size < 4)
+		message_len = tvb_get_ntohs(tvb, 4+2);
+		if (message_len < 4)
			return 0;	/* length not enough for a message header */
	}

@@ -189,15 +188,15 @@
proto_tree_add_double_format(olsr_tree, hf_olsr_vtime, tvb, position+1, 1, Vtime, "Validity Time: %.3f (in seconds)", Vtime);

			/*-------------Dissect Message Size---------------------------*/
-			message_size = tvb_get_ntohs(tvb, position+2);
-			if (message_size < 4) {
- proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_size,"Message Size: %u bytes (too short, must be >= 4)", message_size);
+			message_len = tvb_get_ntohs(tvb, position+2);
+			if (message_len < 4) {
+ proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_len,"Message Size: %u bytes (too short, must be >= 4)", message_len);
				break;
			}
- proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_size,"Message Size: %u bytes", message_size); + proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_len,"Message Size: %u bytes", message_len);

			packet_size--;
-			message_size = (message_size - 4) /4;
+			message_size = (message_len - 4) /4;
			offset = position + 4;
			position = offset;

@@ -346,6 +345,18 @@
				} /* end while for HNA */
				position = offset;
			} /* end if for HNA */
+ /*-----------------------------Undefined message types-----------------------------*/
+			else if(message_size>0) {
+				if((message_len-12)%4) {
+ proto_tree_add_bytes_format(olsr_tree, hf_olsr_data, tvb, position, 1, tvb_get_ptr(tvb, position, 1), "Data (%u bytes) (must be aligned on 32 bits)", message_len-12);
+					break;
+				}
+ proto_tree_add_bytes_format(olsr_tree, hf_olsr_data, tvb, position, message_len-12, tvb_get_ptr(tvb, position, message_len-12), "Data (%u bytes)", message_len-12);
+				packet_size -= (message_len-12)/4;
+				message_size = 0;
+				offset += message_len-12;
+				position = offset;
+			} /* end if for undefined message types */

		} /* end while for message alive */
	} /* end if for IPV4 */
@@ -375,15 +386,15 @@
proto_tree_add_double_format(olsr_tree, hf_olsr_vtime, tvb, position+1, 1, Vtime, "Validity Time: %.3f (in seconds)", Vtime);

			/*-------------Dissect Message Size---------------------------*/
-			message_size = tvb_get_ntohs(tvb, position+2);
-			if (message_size < 4) {
- proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_size,"Message Size: %u bytes (too short, must be >= 4)", message_size);
+			message_len = tvb_get_ntohs(tvb, position+2);
+			if (message_len < 4) {
+ proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_len,"Message Size: %u bytes (too short, must be >= 4)", message_len);
				break;
			}
- proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_size,"Message Size: %u bytes", message_size); + proto_tree_add_uint_format(olsr_tree, hf_olsr_message_size, tvb, position+2, 2, message_len,"Message Size: %u bytes", message_len);

			packet_size--;
-			message_size = (message_size - 4) /4;
+			message_size = (message_len - 4) /4;

			offset = position + 4;
			position = offset;
@@ -533,6 +544,18 @@
				} /* end while for HNA */
				position = offset;
			} /* end if for HNA */
+ /*-----------------------------Undefined message types-----------------------------*/
+			else if(message_size>0) {
+				if((message_len-24)%4) {
+ proto_tree_add_bytes_format(olsr_tree, hf_olsr_data, tvb, position, 1, tvb_get_ptr(tvb, position, 1), "Data (%u bytes) (must be aligned on 32 bits)", message_len-24);
+					break;
+				}
+ proto_tree_add_bytes_format(olsr_tree, hf_olsr_data, tvb, position, message_len-24, tvb_get_ptr(tvb, position, message_len-24), "Data (%u bytes)", message_len-24);
+				packet_size -= (message_len-24)/4;
+				message_size = 0;
+				offset += message_len-24;
+				position = offset;
+			} /* end if for undefined message types */
		} /* end while for message alive */
	} /* end if for IPV6 */
	return tvb_length(tvb);
@@ -658,6 +681,11 @@
			{ "Netmask", "olsr.netmask6",
			   FT_IPv6, BASE_NONE, NULL, 0,
			  "Netmask", HFILL }},
+
+		{ &hf_olsr_data,
+			{ "Data", "olsr.data",
+			   FT_BYTES, BASE_HEX, NULL, 0,
+			  "Data", HFILL }},
	};