Fix some duplicate display filter names.
[obnox/wireshark/wip.git] / epan / dissectors / packet-iwarp-mpa.c
index 16eddc3dbc454b640b0a5ac4d48ca03c8459ede0..aae4c593193d027eecd893480e3c8c2cbd08db3c 100644 (file)
 #include "config.h"
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-
 #include <epan/packet.h>
 #include <epan/emem.h>
 #include <epan/conversation.h>
 #include <epan/dissectors/packet-tcp.h>
 #include <epan/expert.h>
-#include <epan/crc32.h>
+#include <wsutil/crc32.h>
 
 /* DEFINES */
 
@@ -303,8 +298,8 @@ remove_markers(tvbuff_t *tvb, packet_info *pinfo, guint32 marker_offset,
                guint32 num_markers, guint32 orig_length)
 {
        guint8 *mfree_buff = NULL;
-       const guint8 *raw_data_ptr = NULL;
        guint32 mfree_buff_length, tot_copy, cur_copy;
+       guint32 source_offset;
        tvbuff_t *mfree_tvb = NULL;
 
        DISSECTOR_ASSERT(num_markers > 0);
@@ -315,16 +310,13 @@ remove_markers(tvbuff_t *tvb, packet_info *pinfo, guint32 marker_offset,
        mfree_buff_length = orig_length - (MPA_MARKER_LEN * num_markers);
        mfree_buff = g_malloc(mfree_buff_length);
 
-       if (!mfree_buff)
-               THROW(OutOfMemoryError);
-
-       raw_data_ptr = tvb_get_ptr(tvb, 0, -1);
        tot_copy = 0;
+       source_offset = 0;
        cur_copy = marker_offset;
        while (tot_copy < mfree_buff_length) {
-               memcpy(mfree_buff+tot_copy, raw_data_ptr, cur_copy);
+               tvb_memcpy(tvb, mfree_buff+tot_copy, source_offset, cur_copy);
                tot_copy += cur_copy;
-               raw_data_ptr += cur_copy + MPA_MARKER_LEN;
+               source_offset += cur_copy + MPA_MARKER_LEN;
                cur_copy = MIN(MPA_MARKER_INTERVAL, (mfree_buff_length - tot_copy));
        }
        mfree_tvb = tvb_new_child_real_data(tvb, mfree_buff, mfree_buff_length,
@@ -347,15 +339,7 @@ is_mpa_req(tvbuff_t *tvb, packet_info *pinfo)
                        || tvb_get_ntoh64(tvb, 8) != MPA_ID_REQ_FRAME)
                return FALSE;
 
-       conversation = find_conversation(pinfo->fd->num, &pinfo->src,
-                       &pinfo->dst, pinfo->ptype, pinfo->srcport,
-                       pinfo->destport, 0);
-
-       if (!conversation) {
-               conversation = conversation_new(pinfo->fd->num, &pinfo->src,
-                               &pinfo->dst, pinfo->ptype, pinfo->srcport,
-                               pinfo->destport, 0);
-       }
+       conversation = find_or_create_conversation(pinfo);
 
        if (!get_mpa_state(conversation)) {
 
@@ -497,40 +481,40 @@ dissect_mpa_req_rep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 
        if (tree) {
                mpa_item = proto_tree_add_item(tree, proto_iwarp_mpa, tvb, 0,
-                               -1, FALSE);
+                               -1, ENC_NA);
                mpa_tree = proto_item_add_subtree(mpa_item, ett_mpa);
 
                if (message_type == MPA_REQUEST_FRAME) {
                        mpa_header_item = proto_tree_add_item(mpa_tree,
-                                       hf_mpa_req, tvb, offset, -1, FALSE);
+                                       hf_mpa_req, tvb, offset, -1, ENC_NA);
                        mpa_header_tree = proto_item_add_subtree(
                                        mpa_header_item, ett_mpa);
                        proto_tree_add_item(mpa_header_tree, hf_mpa_key_req,
-                                       tvb, offset, MPA_REQ_REP_KEY_LEN, FALSE);
+                                       tvb, offset, MPA_REQ_REP_KEY_LEN, ENC_NA);
                }
 
                if (message_type == MPA_REPLY_FRAME) {
                        mpa_header_item = proto_tree_add_item(mpa_tree,
-                                       hf_mpa_rep, tvb, offset, -1, FALSE);
+                                       hf_mpa_rep, tvb, offset, -1, ENC_NA);
                        mpa_header_tree = proto_item_add_subtree(
                                        mpa_header_item, ett_mpa);
                        proto_tree_add_item(mpa_header_tree, hf_mpa_key_rep,
-                                       tvb, offset, MPA_REQ_REP_KEY_LEN, FALSE);
+                                       tvb, offset, MPA_REQ_REP_KEY_LEN, ENC_NA);
                }
                offset += MPA_REQ_REP_KEY_LEN;
 
                proto_tree_add_item(mpa_header_tree, hf_mpa_flag_m, tvb,
-                               offset, MPA_REQ_REP_FLAG_LEN, FALSE);
+                               offset, MPA_REQ_REP_FLAG_LEN, ENC_BIG_ENDIAN);
                proto_tree_add_item(mpa_header_tree, hf_mpa_flag_c, tvb,
-                               offset, MPA_REQ_REP_FLAG_LEN, FALSE);
+                               offset, MPA_REQ_REP_FLAG_LEN, ENC_BIG_ENDIAN);
                proto_tree_add_item(mpa_header_tree, hf_mpa_flag_r, tvb,
-                               offset, MPA_REQ_REP_FLAG_LEN, FALSE);
+                               offset, MPA_REQ_REP_FLAG_LEN, ENC_BIG_ENDIAN);
                proto_tree_add_item(mpa_header_tree, hf_mpa_flag_res, tvb,
-                               offset, MPA_REQ_REP_FLAG_LEN, FALSE);
+                               offset, MPA_REQ_REP_FLAG_LEN, ENC_BIG_ENDIAN);
                offset += MPA_REQ_REP_FLAG_LEN;
 
                proto_tree_add_item(mpa_header_tree, hf_mpa_rev, tvb,
-                               offset, MPA_REQ_REP_REV_LEN, FALSE);
+                               offset, MPA_REQ_REP_REV_LEN, ENC_BIG_ENDIAN);
                offset += MPA_REQ_REP_REV_LEN;
 
                /* check whether the Private Data Length conforms to RFC 5044 */
@@ -552,7 +536,7 @@ dissect_mpa_req_rep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                if (pd_length) {
                        proto_tree_add_item(mpa_header_tree,
                                        hf_mpa_private_data, tvb, offset,
-                                       pd_length, FALSE);
+                                       pd_length, ENC_NA);
                }
        }
        return TRUE;
@@ -622,7 +606,7 @@ dissect_fpdu_crc(tvbuff_t *tvb, proto_tree *tree, mpa_state_t *state,
                }
        } else {
                proto_tree_add_item(tree, hf_mpa_crc, tvb, offset, MPA_CRC_LEN,
-                               FALSE);
+                               ENC_BIG_ENDIAN);
        }
 }
 
@@ -637,14 +621,14 @@ dissect_fpdu_markers(tvbuff_t *tvb, proto_tree *tree, mpa_state_t *state,
        guint32 offset, i;
 
        mpa_marker_item = proto_tree_add_item(tree, hf_mpa_marker, tvb,
-                       0, -1, FALSE);
+                       0, -1, ENC_NA);
        mpa_marker_tree = proto_item_add_subtree(mpa_marker_item, ett_mpa);
 
        offset = get_first_marker_offset(state, tcpinfo, endpoint);
 
        for (i=0; i<number_of_markers(state, tcpinfo, endpoint); i++) {
                proto_tree_add_item(mpa_marker_tree, hf_mpa_marker_res, tvb,
-                               offset, MPA_MARKER_RSVD_LEN, FALSE);
+                               offset, MPA_MARKER_RSVD_LEN, ENC_BIG_ENDIAN);
                fpduptr = (guint16) tvb_get_ntohs(tvb, offset+MPA_MARKER_RSVD_LEN);
                proto_tree_add_uint_format_value(mpa_marker_tree,
                                hf_mpa_marker_fpduptr, tvb,
@@ -751,11 +735,11 @@ dissect_mpa_fpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                }
 
                mpa_item = proto_tree_add_item(tree, proto_iwarp_mpa, tvb, 0,
-                               -1, FALSE);
+                               -1, ENC_NA);
                mpa_tree = proto_item_add_subtree(mpa_item, ett_mpa);
 
                mpa_header_item = proto_tree_add_item(mpa_tree, hf_mpa_fpdu,
-                               tvb, offset, -1, FALSE);
+                               tvb, offset, -1, ENC_NA);
                mpa_header_tree = proto_item_add_subtree(mpa_header_item,
                                ett_mpa);
 
@@ -777,7 +761,7 @@ dissect_mpa_fpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                                                tvb, pad_offset(tcpinfo,
                                                                total_length,
                                                                pad_length),
-                                                               pad_length, FALSE);
+                                                               pad_length, ENC_NA);
                        }
 
                        dissect_fpdu_crc(tvb, mpa_header_tree, state,
@@ -792,7 +776,7 @@ dissect_mpa_fpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 
                        if (pad_length > 0) {
                                proto_tree_add_item(mpa_header_tree, hf_mpa_pad, tvb, offset,
-                                               pad_length, FALSE);
+                                               pad_length, ENC_NA);
                                offset += pad_length;
                        }
 
@@ -835,7 +819,7 @@ dissect_iwarp_mpa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                }
 
                /* Markers are used by either the Initiator or the Responder or both. */
-               if (state->ini_exp_m_res || state->res_exp_m_ini) {
+               if ((state->ini_exp_m_res || state->res_exp_m_ini) && endpoint <= MPA_RESPONDER) {
 
                        /* find the TCP sequence number of the first FPDU */
                        if (!state->minfo[endpoint].valid) {
@@ -853,7 +837,7 @@ dissect_iwarp_mpa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        return FALSE;
 
                /* removes Markers if any and prepares new tvbuff for next dissector */
-               if (state->minfo[endpoint].valid
+               if (endpoint <= MPA_RESPONDER && state->minfo[endpoint].valid
                                && number_of_markers(state, tcpinfo, endpoint) > 0) {
                        next_tvb = tvb_new_subset(remove_markers(tvb, pinfo,
                                        get_first_marker_offset(state, tcpinfo, endpoint),