Ethereal-dev: [Ethereal-dev] Patches for FCIP & FC dissectors

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: Wed, 18 Feb 2004 16:14:44 -0800
Hi,

I'm including patches to FCIP & FC decoders that:
    - Add FCIP to the list of protocols that can be selected from "Decode As"
    - Add an indicator for EISL header in FC frames.

Dinesh
--
Index: packet-fcip.c
===================================================================
RCS file: /cvsroot/ethereal/packet-fcip.c,v
retrieving revision 1.11
diff -u -r1.11 packet-fcip.c
--- packet-fcip.c	21 Dec 2003 04:31:56 -0000	1.11
+++ packet-fcip.c	19 Feb 2004 00:14:10 -0000
@@ -377,7 +377,8 @@
 }
 
 static gboolean
-dissect_fcip (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+dissect_fcip (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+              gboolean check_port)
 {
     gint offset = 0,
          start  = 0,
@@ -393,7 +394,8 @@
         return FALSE;
     }
 
-    if ((pinfo->srcport != fcip_port) && (pinfo->destport != fcip_port)) {
+    if (check_port &&
+        ((pinfo->srcport != fcip_port) && (pinfo->destport != fcip_port))) {
         return FALSE;
     }
 
@@ -525,6 +527,23 @@
     return (TRUE);
 }
 
+/* This is called for those sessions where we have explicitely said
+   this to be FCIP using "Decode As..."
+   In this case we will not check the port number for sanity and just
+   do as the user said.
+*/
+static void
+dissect_fcip_handle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+    dissect_fcip (tvb, pinfo, tree, FALSE);
+}
+
+static gboolean
+dissect_fcip_heur (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+    return (dissect_fcip (tvb, pinfo, tree, TRUE));
+}
+
 void
 proto_register_fcip (void)
 {
@@ -649,7 +668,13 @@
 void
 proto_reg_handoff_fcip (void)
 {
-    heur_dissector_add("tcp", dissect_fcip, proto_fcip);
+    dissector_handle_t fcip_handle;
+
+    heur_dissector_add("tcp", dissect_fcip_heur, proto_fcip);
+
+    fcip_handle = create_dissector_handle(dissect_fcip_handle, proto_fcip);
+    dissector_add_handle("tcp.port", fcip_handle);
+
     data_handle = find_dissector("data");
     fc_handle = find_dissector("fc");
 }

Index: packet-fc.c
===================================================================
RCS file: /cvsroot/ethereal/packet-fc.c,v
retrieving revision 1.17
diff -u -r1.17 packet-fc.c
--- packet-fc.c	17 Dec 2003 23:35:28 -0000	1.17
+++ packet-fc.c	19 Feb 2004 00:14:30 -0000
@@ -109,6 +109,7 @@
 static int hf_fc_param = -1;
 static int hf_fc_ftype = -1;    /* Derived field, non-existent in FC hdr */
 static int hf_fc_reassembled = -1;
+static int hf_fc_eisl = -1;
 
 /* Network_Header fields */
 static int hf_fc_nh_da = -1;
@@ -761,7 +762,7 @@
     proto_item *ti=NULL;
     proto_tree *fc_tree = NULL;
     tvbuff_t *next_tvb;
-    int offset = 0, next_offset;
+    int offset = 0, next_offset, eisl_offset = -1;
     gboolean is_lastframe_inseq, is_1frame_inseq, is_valid_frame;
     gboolean is_exchg_resp = 0;
     fragment_data *fcfrag_head;
@@ -793,6 +794,7 @@
      * real FC header. EISL is Cisco-proprietary and is not decoded.
      */
     if (fchdr.r_ctl == FC_RCTL_EISL) {
+        eisl_offset = offset;
         offset += 8;
         fchdr.r_ctl = tvb_get_guint8 (tvb, offset);
     }
@@ -852,6 +854,11 @@
         fc_tree = proto_item_add_subtree (ti, ett_fc);
     }
 
+    /* Highlight EISL header, if present */
+    if (eisl_offset != -1) {
+        proto_tree_add_item (fc_tree, hf_fc_eisl, tvb, eisl_offset, 8, 0);
+    }
+
     /* match first exchange with last exchange */
     if(fchdr.fctl&FC_FCTL_EXCHANGE_FIRST){
         if(!pinfo->fd->flags.visited){
@@ -1391,6 +1398,8 @@
         { &hf_fc_time,
           { "Time from Exchange First", "fc.time", FT_RELATIVE_TIME, BASE_NONE, NULL,
            0, "Time since the first frame of the Exchange", HFILL }},
+        { &hf_fc_eisl,
+          {"EISL Header", "fc.eisl", FT_BYTES, BASE_HEX, NULL, 0, "EISL Header", HFILL}},
     };
 
     /* Setup protocol subtree array */
-- 
Become the change you want to see in the world - Gandhi