Make "first_pdu" an argument rather than a global in the ONC RPC
authorGuy Harris <guy@alum.mit.edu>
Mon, 21 Apr 2003 08:13:18 +0000 (08:13 -0000)
committerGuy Harris <guy@alum.mit.edu>
Mon, 21 Apr 2003 08:13:18 +0000 (08:13 -0000)
dissector - including the ONC RPC-over-TCP record marking code, which is
also used by NDMP.

That means that the NDMP dissector can, like the ONC RPC dissector, put
into the Info column items for all the NDMP messages dissected for a
frame; make it do so.

svn path=/trunk/; revision=7516

packet-ndmp.c
packet-rpc.c
rpc_defrag.h

index f2f3de494ccbae2034b9a1a5ae53822ecc43425c..9bf8bd38ce5a591c12bdde1a4b7f96fc944db9a3 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for NDMP dissection
  * 2001 Ronnie Sahlberg (see AUTHORS for email)
  *
- * $Id: packet-ndmp.c,v 1.23 2002/08/28 21:00:23 jmayer Exp $
+ * $Id: packet-ndmp.c,v 1.24 2003/04/21 08:13:18 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -1961,7 +1961,7 @@ dissect_file_name(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *par
                offset = dissect_rpc_string(tvb, tree,
                                hf_ndmp_file_name, offset, &name);
                if (check_col(pinfo->cinfo, COL_INFO)){
-                       col_append_fstr(pinfo->cinfo, COL_INFO, " %s ", name);
+                       col_append_fstr(pinfo->cinfo, COL_INFO, " %s", name);
                }
                break;
        case NDMP_FS_NT:
@@ -1969,7 +1969,7 @@ dissect_file_name(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *par
                offset = dissect_rpc_string(tvb, tree,
                                hf_ndmp_nt_file_name, offset, &name);
                if (check_col(pinfo->cinfo, COL_INFO)){
-                       col_append_fstr(pinfo->cinfo, COL_INFO, " %s ", name);
+                       col_append_fstr(pinfo->cinfo, COL_INFO, " %s", name);
                }
 
                /* dos file */
@@ -1981,12 +1981,12 @@ dissect_file_name(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *par
                offset = dissect_rpc_string(tvb, tree,
                                hf_ndmp_file_name, offset, &name);
                if (check_col(pinfo->cinfo, COL_INFO)){
-                       col_append_fstr(pinfo->cinfo, COL_INFO, " %s ", name);
+                       col_append_fstr(pinfo->cinfo, COL_INFO, " %s", name);
                }
        }
 
        if (check_col(pinfo->cinfo, COL_INFO)){
-               col_append_fstr(pinfo->cinfo, COL_INFO, "(%s)",
+               col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)",
                        val_to_str(type, file_fs_type_vals, "Unknown type") );
        }
 
@@ -2595,7 +2595,7 @@ dissect_ndmp_header(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *p
        offset += 4;
 
        if (check_col(pinfo->cinfo, COL_INFO)){
-               col_append_fstr(pinfo->cinfo, COL_INFO, "%s %s  ",
+               col_append_fstr(pinfo->cinfo, COL_INFO, "%s %s",
                        val_to_str(nh->msg, msg_vals, "Unknown Message (0x%02x)"),
                        val_to_str(nh->type, msg_type_vals, "Unknown Type (0x%02x)")
                        );
@@ -2652,7 +2652,7 @@ dissect_ndmp_cmd(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
 static gboolean
 dissect_ndmp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
     tvbuff_t *frag_tvb, fragment_data *ipfd_head, gboolean is_tcp,
-    guint32 rpc_rm)
+    guint32 rpc_rm, gboolean first_pdu)
 {
        int offset = (is_tcp && tvb == frag_tvb) ? 4 : 0;
        guint32 size;
@@ -2701,8 +2701,12 @@ dissect_ndmp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 
        if (check_col(pinfo->cinfo, COL_PROTOCOL))
                col_set_str(pinfo->cinfo, COL_PROTOCOL, "NDMP");
-       if (check_col(pinfo->cinfo, COL_INFO))
-               col_clear(pinfo->cinfo, COL_INFO);
+       if (check_col(pinfo->cinfo, COL_INFO)) {
+               if (first_pdu)
+                       col_clear(pinfo->cinfo, COL_INFO);
+               else
+                       col_append_fstr(pinfo->cinfo, COL_INFO, "; ");
+       }
 
        if (tree) {
                ndmp_item = proto_tree_add_item(tree, proto_ndmp,
@@ -2729,6 +2733,7 @@ dissect_ndmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
        int offset = 0;
        int len;
+       gboolean first_pdu = TRUE;
 
        while (tvb_reported_length_remaining(tvb, offset) != 0) {
                /*
@@ -2736,7 +2741,8 @@ dissect_ndmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                 */
                len = dissect_rpc_fragment(tvb, offset, pinfo, tree,
                    dissect_ndmp_message, FALSE, proto_ndmp, ett_ndmp,
-                   ndmp_defragment);
+                   ndmp_defragment, first_pdu);
+               first_pdu = FALSE;
                if (len < 0) {
                        /*
                         * We need more data from the TCP stream for
index 818d48db8fc790d071cab432f73b3ba09807528b..9c4beacc67ccc8f42d350378f8cb93d2da459d6a 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for rpc dissection
  * Copyright 1999, Uwe Girlich <Uwe.Girlich@philosys.de>
  *
- * $Id: packet-rpc.c,v 1.119 2003/04/20 11:36:14 guy Exp $
+ * $Id: packet-rpc.c,v 1.120 2003/04/21 08:13:18 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -61,9 +61,6 @@
  *     although we don't currently dissect AUTH_DES or AUTH_KERB.
  */
 
-/* to keep track of which is the first RPC PDU in a packet */
-static gboolean first_pdu;
-
 /* desegmentation of RPC over TCP */
 static gboolean rpc_desegment = TRUE;
 
@@ -1477,7 +1474,7 @@ dissect_rpc_continuation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 static gboolean
 dissect_rpc_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
     tvbuff_t *frag_tvb, fragment_data *ipfd_head, gboolean is_tcp,
-    guint32 rpc_rm)
+    guint32 rpc_rm, gboolean first_pdu)
 {
        guint32 msg_type;
        rpc_call_info_key rpc_call_key;
@@ -1732,13 +1729,10 @@ dissect_rpc_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                }
 
                if (check_col(pinfo->cinfo, COL_INFO)) {
-                       if(!first_pdu){
+                       if (first_pdu)
+                               col_clear(pinfo->cinfo, COL_INFO);
+                       else
                                col_append_fstr(pinfo->cinfo, COL_INFO, "  ; ");
-                       } else {
-                               if (check_col(pinfo->cinfo, COL_INFO))
-                                       col_clear(pinfo->cinfo, COL_INFO);
-                       }
-                       first_pdu=FALSE;
                        col_append_fstr(pinfo->cinfo, COL_INFO,"V%u %s %s XID 0x%x",
                                vers,
                                procname,
@@ -1950,13 +1944,10 @@ dissect_rpc_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                }
 
                if (check_col(pinfo->cinfo, COL_INFO)) {
-                       if(!first_pdu){
+                       if (first_pdu)
+                               col_clear(pinfo->cinfo, COL_INFO);
+                       else
                                col_append_fstr(pinfo->cinfo, COL_INFO, "  ; ");
-                       } else {
-                               if (check_col(pinfo->cinfo, COL_INFO))
-                                       col_clear(pinfo->cinfo, COL_INFO);
-                       }
-                       first_pdu=FALSE;
                        col_append_fstr(pinfo->cinfo, COL_INFO,"V%u %s %s XID 0x%x",
                                vers,
                                procname,
@@ -2300,18 +2291,18 @@ dissect_rpc_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 static gboolean
 dissect_rpc_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-       first_pdu=TRUE;
-
-       return dissect_rpc_message(tvb, pinfo, tree, NULL, NULL, FALSE, 0);
+       return dissect_rpc_message(tvb, pinfo, tree, NULL, NULL, FALSE, 0,
+           TRUE);
 }
 
 static void
 dissect_rpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-       first_pdu=TRUE;
-
-       if (!dissect_rpc_message(tvb, pinfo, tree, NULL, NULL, FALSE, 0))
-               dissect_rpc_continuation(tvb, pinfo, tree);
+       if (!dissect_rpc_message(tvb, pinfo, tree, NULL, NULL, FALSE, 0,
+           TRUE)) {
+               if (tvb_length(tvb) != 0)
+                       dissect_rpc_continuation(tvb, pinfo, tree);
+       }
 }
 
 
@@ -2432,7 +2423,7 @@ show_rpc_fraginfo(tvbuff_t *tvb, tvbuff_t *frag_tvb, proto_tree *tree,
 static gboolean
 call_message_dissector(tvbuff_t *tvb, tvbuff_t *rec_tvb, packet_info *pinfo,
     proto_tree *tree, tvbuff_t *frag_tvb, rec_dissector_t dissector,
-    fragment_data *ipfd_head, guint32 rpc_rm)
+    fragment_data *ipfd_head, guint32 rpc_rm, gboolean first_pdu)
 {
        const char *saved_proto;
        volatile gboolean rpc_succeeded;
@@ -2452,7 +2443,7 @@ call_message_dissector(tvbuff_t *tvb, tvbuff_t *rec_tvb, packet_info *pinfo,
        rpc_succeeded = FALSE;
        TRY {
                rpc_succeeded = (*dissector)(rec_tvb, pinfo, tree,
-                   frag_tvb, ipfd_head, TRUE, rpc_rm);
+                   frag_tvb, ipfd_head, TRUE, rpc_rm, first_pdu);
        }
        CATCH(BoundsError) {
                RETHROW;
@@ -2476,7 +2467,7 @@ call_message_dissector(tvbuff_t *tvb, tvbuff_t *rec_tvb, packet_info *pinfo,
 int
 dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
     proto_tree *tree, rec_dissector_t dissector, gboolean is_heur,
-    int proto, int ett, gboolean defragment)
+    int proto, int ett, gboolean defragment, gboolean first_pdu)
 {
        struct tcpinfo *tcpinfo = pinfo->private_data;
        guint32 seq = tcpinfo->seq + offset;
@@ -2577,7 +2568,7 @@ dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
                save_fragmented = pinfo->fragmented;
                pinfo->fragmented = TRUE;
                rpc_succeeded = call_message_dissector(tvb, rec_tvb, pinfo,
-                   tree, frag_tvb, dissector, ipfd_head, rpc_rm);
+                   tree, frag_tvb, dissector, ipfd_head, rpc_rm, first_pdu);
                pinfo->fragmented = save_fragmented;
                if (!rpc_succeeded)
                        return 0;       /* not RPC */
@@ -2631,7 +2622,7 @@ dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
                         * an exception.
                         */
                        if (!(*dissector)(frag_tvb, pinfo, tree, frag_tvb,
-                           NULL, TRUE, rpc_rm))
+                           NULL, TRUE, rpc_rm, first_pdu))
                                return 0;       /* not valid */
 
                        /*
@@ -2806,7 +2797,7 @@ dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
         * dissector.
         */
        if (!call_message_dissector(tvb, rec_tvb, pinfo, tree,
-           frag_tvb, dissector, ipfd_head, rpc_rm))
+           frag_tvb, dissector, ipfd_head, rpc_rm, first_pdu))
                return 0;       /* not RPC */
        return len;
 }
@@ -2833,6 +2824,7 @@ dissect_rpc_tcp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 {
        int offset = 0;
        gboolean saw_rpc = FALSE;
+       gboolean first_pdu = TRUE;
        int len;
 
        while (tvb_reported_length_remaining(tvb, offset) != 0) {
@@ -2841,7 +2833,8 @@ dissect_rpc_tcp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                 */
                len = dissect_rpc_fragment(tvb, offset, pinfo, tree,
                    dissect_rpc_message, is_heur, proto_rpc, ett_rpc,
-                   rpc_defragment);
+                   rpc_defragment, first_pdu);
+               first_pdu = FALSE;
                if (len < 0) {
                        /*
                         * We need more data from the TCP stream for
@@ -2865,8 +2858,6 @@ dissect_rpc_tcp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 static gboolean
 dissect_rpc_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-       first_pdu=TRUE;
-
        switch (dissect_rpc_tcp_common(tvb, pinfo, tree, TRUE)) {
 
        case IS_RPC:
@@ -2885,8 +2876,6 @@ dissect_rpc_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 static void
 dissect_rpc_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-       first_pdu=TRUE;
-
        if (dissect_rpc_tcp_common(tvb, pinfo, tree, FALSE) == IS_NOT_RPC)
                dissect_rpc_continuation(tvb, pinfo, tree);
 }
@@ -3185,7 +3174,11 @@ proto_reg_handoff_rpc(void)
 
        /* tcp/udp port 111 is used by portmapper which is an onc-rpc service.
           we register onc-rpc on this port so that we can choose RPC in
-          the list offered by DecodeAs.
+          the list offered by DecodeAs, and so that traffic to or from
+          port 111 from or to a higher-numbered port is dissected as RPC
+          even if there's a dissector registered on the other port (it's
+          probably RPC traffic from some randomly-chosen port that happens
+          to match some port for which we have a dissector)
        */
        rpc_tcp_handle = create_dissector_handle(dissect_rpc_tcp, proto_rpc);
        dissector_add("tcp.port", 111, rpc_tcp_handle);
index f674876456eb541562976554067141bd2b35584e..02e60f9bfe63c8d4c11587547493e5e53da63f43 100644 (file)
@@ -1,7 +1,7 @@
-/* rpc-defrag.h
+/* rpc_defrag.h
  * Declarations for RPC defragmentation
  *
- * $Id: rpc_defrag.h,v 1.4 2002/08/28 21:00:41 jmayer Exp $
+ * $Id: rpc_defrag.h,v 1.5 2003/04/21 08:13:18 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #define RPC_RM_FRAGLEN 0x7fffffffL
 
 typedef gboolean (*rec_dissector_t)(tvbuff_t *, packet_info *, proto_tree *,
-       tvbuff_t *, fragment_data *, gboolean, guint32);
+       tvbuff_t *, fragment_data *, gboolean, guint32, gboolean);
 
 extern void show_rpc_fraginfo(tvbuff_t *tvb, tvbuff_t *frag_tvb,
        proto_tree *tree, guint32 rpc_rm, fragment_data *ipfd_head, packet_info *pinfo);
 extern int dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
        proto_tree *tree, rec_dissector_t dissector, gboolean is_heur,
-       int proto, int ett, gboolean defragment);
+       int proto, int ett, gboolean defragment, gboolean first_pdu);
 
 #endif /* __RPC_DEFRAG_H__ */