Ethereal-dev: [Ethereal-dev] Here is the correct patch for iSNS & conversation

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

From: Dinesh G Dutt <ddutt@xxxxxxxxx>
Date: Tue, 29 Jun 2004 15:08:39 -0700
I sent in the wrong patch file. Please use this one instead. Sorry,

Dinesh
--
Index: epan/conversation.c
===================================================================
RCS file: /cvsroot/ethereal/epan/conversation.c,v
retrieving revision 1.24
diff -u -r1.24 conversation.c
--- epan/conversation.c	9 Jan 2004 00:57:48 -0000	1.24
+++ epan/conversation.c	29 Jun 2004 09:35:49 -0000
@@ -464,7 +464,7 @@
 	new_index++;
 
 	if (options & NO_ADDR2) {
-		if (options & NO_PORT2) {
+		if (options & (NO_PORT2|NO_PORT2_FORCE)) {
 			g_hash_table_insert(conversation_hashtable_no_addr2_or_port2,
 			    new_key, conversation);
 		} else {
@@ -472,7 +472,7 @@
 			    new_key, conversation);
 		}
 	} else {
-		if (options & NO_PORT2) {
+		if (options & (NO_PORT2|NO_PORT2_FORCE)) {
 			g_hash_table_insert(conversation_hashtable_no_port2,
 			    new_key, conversation);
 		} else {
@@ -493,7 +493,7 @@
 	/*
 	 * If the port 2 value is not wildcarded, don't set it.
 	 */
-	if (!(conv->options & NO_PORT2))
+        if ((!(conv->options & NO_PORT2)) || (conv->options & NO_PORT2_FORCE))
 		return;
 
 	if (conv->options & NO_ADDR2) {
Index: epan/conversation.h
===================================================================
RCS file: /cvsroot/ethereal/epan/conversation.h,v
retrieving revision 1.10
diff -u -r1.10 conversation.h
--- epan/conversation.h	28 Aug 2002 20:40:44 -0000	1.10
+++ epan/conversation.h	29 Jun 2004 09:35:49 -0000
@@ -31,6 +31,7 @@
  */
 #define NO_ADDR2 0x01
 #define NO_PORT2 0x02
+#define NO_PORT2_FORCE 0x04
 
 /*
  * Flags to pass to "find_conversation()" to indicate that the address B
@@ -38,6 +39,7 @@
  */
 #define NO_ADDR_B 0x01
 #define NO_PORT_B 0x02
+#define NO_PORT_B_FORCE 0x04
 
 #include "packet.h"		/* for conversation dissector type */
 
Index: packet-isns.c
===================================================================
RCS file: /cvsroot/ethereal/packet-isns.c,v
retrieving revision 1.8
diff -u -r1.8 packet-isns.c
--- packet-isns.c	27 May 2004 08:33:22 -0000	1.8
+++ packet-isns.c	29 Jun 2004 09:36:00 -0000
@@ -51,6 +51,7 @@
 #endif
 
 #include <epan/packet.h>
+#include <epan/conversation.h>
 #include "packet-tcp.h"
 #include "prefs.h"
 
@@ -61,13 +62,22 @@
 #define ISNS_TCP_PORT 3205
 #define ISNS_UDP_PORT 3205
 
+#define ISNS_OTHER_PORT 0
+#define ISNS_ESI_PORT 1
+#define ISNS_SCN_PORT 2
+
+
+dissector_handle_t isns_tcp_handle;
+dissector_handle_t isns_udp_handle;
+
 static gint ett_isns_flags = -1;
 static gint ett_isns_payload = -1;
 static gint ett_isns_attribute = -1;
 static gint ett_isns_port = -1;
 static gint ett_isns_isnt = -1;
 
-static guint AddAttribute(tvbuff_t *tvb, proto_tree *tree, guint offset, guint16 function_id);
+static guint AddAttribute(packet_info *pinfo, tvbuff_t *tvb, proto_tree *tree,
+                          guint offset, guint16 function_id);
 
 /* Initialize the protocol and registered fields */
 static int proto_isns = -1;
@@ -740,7 +750,7 @@
 
 	    while( offset < packet_len )
 	    {
-		offset = AddAttribute(tvb, tt, offset, function_id);
+		offset = AddAttribute(pinfo, tvb, tt, offset, function_id);
 	    }
 	}
     }
@@ -748,7 +758,6 @@
     return;
 }
 
-
 static guint
 get_isns_pdu_len(tvbuff_t *tvb, int offset)
 {
@@ -861,23 +870,46 @@
 }
 
 static guint
-dissect_isns_attr_port(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len)
+dissect_isns_attr_port(tvbuff_t *tvb, guint offset, proto_tree *parent_tree, int hf_index, guint32 tag, guint32 len,
+                       guint16 port_type, packet_info *pinfo)
 {
 	proto_item *tree=NULL;
 	proto_item *item=NULL;
 	guint16 port = tvb_get_ntohs(tvb, offset + 10);
-	guint16 port_type = tvb_get_ntohs(tvb, offset + 8)&0x01;
+	guint16 isudp = tvb_get_ntohs(tvb, offset + 8)&0x01;
+        conversation_t *conversation;
 
 	if(parent_tree){
-		item = proto_tree_add_uint(parent_tree, hf_index, tvb, offset+8, 4, port);
-		tree = proto_item_add_subtree(item, ett_isns_port);
+            item = proto_tree_add_uint(parent_tree, hf_index, tvb, offset+8, 4, port);
+            tree = proto_item_add_subtree(item, ett_isns_port);
 	}
 
-	proto_tree_add_boolean(tree, hf_isns_port_type, tvb, offset+8, 2, port_type);
+	proto_tree_add_boolean(tree, hf_isns_port_type, tvb, offset+8, 2, isudp);
 
 	proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
 	proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
 
+        if ((port_type == ISNS_ESI_PORT) || (port_type == ISNS_SCN_PORT)) {
+            if (isudp) {
+                conversation = find_conversation (&pinfo->src, &pinfo->dst, PT_UDP,
+                                                  port, 0, NO_PORT_B);
+                if (conversation == NULL) {
+                    conversation = conversation_new (&pinfo->src, &pinfo->dst,
+                                                     PT_UDP, port, 0, NO_PORT2_FORCE);
+                    conversation_set_dissector (conversation, isns_udp_handle);
+                }
+            }
+            else {
+                conversation = find_conversation (&pinfo->src, &pinfo->dst, PT_TCP,
+                                                  port, 0, NO_PORT_B);
+                if (conversation == NULL) {
+                    conversation = conversation_new (&pinfo->src, &pinfo->dst,
+                                                     PT_TCP, port, 0, NO_PORT2_FORCE);
+                    conversation_set_dissector (conversation, isns_tcp_handle);
+                }
+            }
+        }
+
 	return offset+8+len;
 }
 
@@ -1018,7 +1050,8 @@
 
 
 static guint
-AddAttribute(tvbuff_t *tvb, proto_tree *tree, guint offset, guint16 function_id)
+AddAttribute(packet_info *pinfo, tvbuff_t *tvb, proto_tree *tree, guint offset,
+             guint16 function_id)
 {
     guint32 tag,len;
 
@@ -1028,6 +1061,14 @@
 
     /* Now the Length */
     len = tvb_get_ntohl(tvb, offset + 4);
+
+    if (!len) {
+        if (tree) {
+            proto_tree_add_uint(tree, hf_isns_attr_tag, tvb, offset, 4, tag);
+            proto_tree_add_uint(tree, hf_isns_attr_len, tvb, offset+4, 4, len);
+        }
+        return (offset+8);
+    }
     
     switch( tag )
     {
@@ -1068,7 +1109,7 @@
 	offset = dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_portal_ip_addr, tag, len);
 	break;
     case ISNS_ATTR_TAG_PORTAL_PORT:
-	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_portal_port, tag, len);
+	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_portal_port, tag, len, ISNS_OTHER_PORT, pinfo);
 	break;
     case ISNS_ATTR_TAG_PORTAL_SYMBOLIC_NAME:
 	offset = dissect_isns_attr_string(tvb, offset, tree, hf_isns_portal_symbolic_name, tag, len);
@@ -1077,7 +1118,7 @@
 	offset = dissect_isns_attr_integer(tvb, offset, tree, hf_isns_esi_interval, tag, len, function_id);
 	break;
     case ISNS_ATTR_TAG_ESI_PORT:
-	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_esi_port, tag, len);
+	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_esi_port, tag, len, ISNS_ESI_PORT, pinfo);
 	break;
     case ISNS_ATTR_TAG_PORTAL_GROUP:
 	offset = dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
@@ -1086,7 +1127,7 @@
 	offset = dissect_isns_attr_integer(tvb, offset, tree, hf_isns_portal_index, tag, len, function_id);
 	break;
     case ISNS_ATTR_TAG_SCN_PORT:
-	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_scn_port, tag, len);
+	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_scn_port, tag, len, ISNS_SCN_PORT, pinfo);
 	break;
     case ISNS_ATTR_TAG_PORTAL_NEXT_INDEX:
 	offset = dissect_isns_attr_integer(tvb, offset, tree, hf_isns_portal_next_index, tag, len, function_id);
@@ -1107,7 +1148,7 @@
 	offset = dissect_isns_attr_string(tvb, offset, tree, hf_isns_iscsi_name, tag, len);
 	break;
     case ISNS_ATTR_TAG_ISCSI_NODE_TYPE:
-	offset = dissect_isns_attr_iscsi_node_type(tvb, offset, tree, hf_isns_iscsi_node_type, tag, len);
+        offset = dissect_isns_attr_iscsi_node_type(tvb, offset, tree, hf_isns_iscsi_node_type, tag, len);
 	break;
     case ISNS_ATTR_TAG_ISCSI_ALIAS:
 	offset = dissect_isns_attr_string(tvb, offset, tree, hf_isns_iscsi_alias, tag, len);
@@ -1134,7 +1175,7 @@
 	offset = dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_pg_portal_ip_addr, tag, len);
 	break;
     case ISNS_ATTR_TAG_PG_PORTAL_PORT:
-	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_pg_portal_port, tag, len);
+	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_pg_portal_port, tag, len, ISNS_OTHER_PORT, pinfo);
 	break;
     case ISNS_ATTR_TAG_PORTAL_GROUP_TAG:
 	offset = dissect_isns_attr_integer(tvb, offset, tree, hf_isns_portal_group_tag, tag, len, function_id);
@@ -1284,7 +1325,8 @@
 	offset = dissect_isns_attr_ip_address(tvb, offset, tree, hf_isns_dd_member_portal_ip_addr, tag, len);
 	break;
     case ISNS_ATTR_TAG_DD_MEMBER_PORTAL_PORT:
-	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_dd_member_portal_port, tag, len);
+	offset = dissect_isns_attr_port(tvb, offset, tree, hf_isns_dd_member_portal_port,
+                                        tag, len, ISNS_OTHER_PORT, pinfo);
 	break;
     case ISNS_ATTR_TAG_DD_FEATURES:
 	offset = dissect_isns_attr_not_decoded_yet(tvb, offset, tree, hf_isns_not_decoded_yet, tag, len);
@@ -1872,10 +1914,9 @@
 void
 proto_reg_handoff_isns(void)
 {
-    dissector_handle_t isns_tcp_handle;
-    dissector_handle_t isns_udp_handle;
     isns_tcp_handle = create_dissector_handle(dissect_isns_tcp,proto_isns);
     isns_udp_handle = create_dissector_handle(dissect_isns_udp,proto_isns);
+
     dissector_add("tcp.port",ISNS_TCP_PORT,isns_tcp_handle);
     dissector_add("udp.port",ISNS_UDP_PORT,isns_udp_handle);
 }
-- 
Become the change you want to see in the world - Gandhi