aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-fcoe.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2012-07-12 17:22:47 +0000
committerBill Meier <wmeier@newsguy.com>2012-07-12 17:22:47 +0000
commit859affc2bd93d3461a9828707a7a559b0f496095 (patch)
tree9478a775f2baaf79def16065593e2f714f922305 /epan/dissectors/packet-fcoe.c
parent02d23f97b09fdf5a511f7ac0cc136ed4e295bcae (diff)
Don't call subdissectors / expert...() / col...() under 'if (tree)'
Also: Remove some uneeded initializers; Do some whitespace cleanup and re-formatting. svn path=/trunk/; revision=43681
Diffstat (limited to 'epan/dissectors/packet-fcoe.c')
-rw-r--r--epan/dissectors/packet-fcoe.c197
1 files changed, 95 insertions, 102 deletions
diff --git a/epan/dissectors/packet-fcoe.c b/epan/dissectors/packet-fcoe.c
index f17162a8bf..928b853182 100644
--- a/epan/dissectors/packet-fcoe.c
+++ b/epan/dissectors/packet-fcoe.c
@@ -43,7 +43,7 @@
#include <epan/expert.h>
#define FCOE_HEADER_LEN 14 /* header: version, SOF, and padding */
-#define FCOE_TRAILER_LEN 8 /* trailer: CRC, EOF, and padding */
+#define FCOE_TRAILER_LEN 8 /* trailer: CRC, EOF, and padding */
typedef enum {
FCOE_EOFn = 0x41,
@@ -68,14 +68,14 @@ typedef enum {
} fcoe_sof_t;
static const value_string fcoe_eof_vals[] = {
- {FCOE_EOFn, "EOFn" },
- {FCOE_EOFt, "EOFt" },
- {FCOE_EOFrt, "EOFrt" },
- {FCOE_EOFdt, "EOFdt" },
- {FCOE_EOFni, "EOFni" },
+ {FCOE_EOFn, "EOFn" },
+ {FCOE_EOFt, "EOFt" },
+ {FCOE_EOFrt, "EOFrt" },
+ {FCOE_EOFdt, "EOFdt" },
+ {FCOE_EOFni, "EOFni" },
{FCOE_EOFdti, "EOFdti" },
{FCOE_EOFrti, "EOFrti" },
- {FCOE_EOFa, "EOFa" },
+ {FCOE_EOFa, "EOFa" },
{0, NULL}
};
@@ -109,27 +109,27 @@ static dissector_handle_t fc_handle;
static void
dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
- gint crc_offset;
- gint eof_offset;
- gint frame_len = 0;
- gint header_len = FCOE_HEADER_LEN;
- guint version;
+ gint crc_offset;
+ gint eof_offset;
+ gint frame_len = 0;
+ gint header_len = FCOE_HEADER_LEN;
+ guint version;
const char *ver;
- guint16 len_sof;
- gint bytes_remaining;
- guint8 sof = 0;
- guint8 eof = 0;
+ guint16 len_sof;
+ gint bytes_remaining;
+ guint8 sof = 0;
+ guint8 eof = 0;
const char *eof_str;
const char *crc_msg;
const char *len_msg;
proto_item *ti;
proto_item *item;
- proto_tree *fcoe_tree = NULL;
+ proto_tree *fcoe_tree;
proto_tree *crc_tree;
- tvbuff_t *next_tvb;
- gboolean crc_exists;
- guint32 crc_computed = 0;
- guint32 crc = 0;
+ tvbuff_t *next_tvb;
+ gboolean crc_exists;
+ guint32 crc_computed = 0;
+ guint32 crc = 0;
/*
* For now, handle both the version defined before and after August 2007.
@@ -167,90 +167,87 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (bytes_remaining > frame_len)
bytes_remaining = frame_len; /* backing length */
next_tvb = tvb_new_subset(tvb, header_len, bytes_remaining, frame_len);
-
- if (tree) {
- eof_str = "none";
- if (tvb_bytes_exist(tvb, eof_offset, 1)) {
- eof = tvb_get_guint8(tvb, eof_offset);
- eof_str = val_to_str(eof, fcoe_eof_vals, "0x%x");
- }
+ eof_str = "none";
+ if (tvb_bytes_exist(tvb, eof_offset, 1)) {
+ eof = tvb_get_guint8(tvb, eof_offset);
+ eof_str = val_to_str(eof, fcoe_eof_vals, "0x%x");
+ }
- /*
- * Check the CRC.
- */
- crc_msg = "";
- crc_exists = tvb_bytes_exist(tvb, crc_offset, 4);
- if (crc_exists) {
- crc = tvb_get_ntohl(tvb, crc_offset);
- crc_computed = crc32_802_tvb(next_tvb, frame_len);
- if (crc != crc_computed) {
- crc_msg = " [bad FC CRC]";
- }
- }
- len_msg = "";
- if ((frame_len % 4) != 0 || frame_len < 24) {
- len_msg = " [invalid length]";
+ /*
+ * Check the CRC.
+ */
+ crc_msg = "";
+ crc_exists = tvb_bytes_exist(tvb, crc_offset, 4);
+ if (crc_exists) {
+ crc = tvb_get_ntohl(tvb, crc_offset);
+ crc_computed = crc32_802_tvb(next_tvb, frame_len);
+ if (crc != crc_computed) {
+ crc_msg = " [bad FC CRC]";
}
+ }
+ len_msg = "";
+ if ((frame_len % 4) != 0 || frame_len < 24) {
+ len_msg = " [invalid length]";
+ }
- ti = proto_tree_add_protocol_format(tree, proto_fcoe, tvb, 0,
- header_len,
- "FCoE %s(%s/%s) %d bytes%s%s", ver,
- val_to_str(sof, fcoe_sof_vals,
- "0x%x"),
- eof_str, frame_len, crc_msg,
- len_msg);
+ ti = proto_tree_add_protocol_format(tree, proto_fcoe, tvb, 0,
+ header_len,
+ "FCoE %s(%s/%s) %d bytes%s%s", ver,
+ val_to_str(sof, fcoe_sof_vals,
+ "0x%x"),
+ eof_str, frame_len, crc_msg,
+ len_msg);
- /* Dissect the FCoE header */
+ /* Dissect the FCoE header */
- fcoe_tree = proto_item_add_subtree(ti, ett_fcoe);
- proto_tree_add_uint(fcoe_tree, hf_fcoe_ver, tvb, 0, 1, version);
- if (tvb_get_guint8(tvb, 1)) {
- proto_tree_add_uint(fcoe_tree, hf_fcoe_len, tvb, 0, 2, frame_len);
- }
- proto_tree_add_uint(fcoe_tree, hf_fcoe_sof, tvb,
- header_len - 1, 1, sof);
+ fcoe_tree = proto_item_add_subtree(ti, ett_fcoe);
+ proto_tree_add_uint(fcoe_tree, hf_fcoe_ver, tvb, 0, 1, version);
+ if (tvb_get_guint8(tvb, 1)) {
+ proto_tree_add_uint(fcoe_tree, hf_fcoe_len, tvb, 0, 2, frame_len);
+ }
+ proto_tree_add_uint(fcoe_tree, hf_fcoe_sof, tvb,
+ header_len - 1, 1, sof);
- /*
- * Create the CRC information.
- */
- if (crc_exists) {
- if (crc == crc_computed) {
- item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
- crc_offset, 4, crc,
- "CRC: %8.8x [valid]", crc);
- } else {
- item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
- crc_offset, 4, crc,
- "CRC: %8.8x "
- "[error: should be %8.8x]",
- crc, crc_computed);
- expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR,
- "Bad FC CRC %8.8x %8.x",
- crc, crc_computed);
- }
- proto_tree_set_appendix(fcoe_tree, tvb, crc_offset,
- tvb_length_remaining (tvb, crc_offset));
+ /*
+ * Create the CRC information.
+ */
+ if (crc_exists) {
+ if (crc == crc_computed) {
+ item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
+ crc_offset, 4, crc,
+ "CRC: %8.8x [valid]", crc);
} else {
- item = proto_tree_add_text(fcoe_tree, tvb, crc_offset, 0,
- "CRC: [missing]");
+ item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
+ crc_offset, 4, crc,
+ "CRC: %8.8x "
+ "[error: should be %8.8x]",
+ crc, crc_computed);
+ expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR,
+ "Bad FC CRC %8.8x %8.x",
+ crc, crc_computed);
}
- crc_tree = proto_item_add_subtree(item, ett_fcoe_crc);
- ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_bad, tvb,
- crc_offset, 4,
- crc_exists && crc != crc_computed);
- PROTO_ITEM_SET_GENERATED(ti);
- ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_good, tvb,
- crc_offset, 4,
- crc_exists && crc == crc_computed);
- PROTO_ITEM_SET_GENERATED(ti);
+ proto_tree_set_appendix(fcoe_tree, tvb, crc_offset,
+ tvb_length_remaining (tvb, crc_offset));
+ } else {
+ item = proto_tree_add_text(fcoe_tree, tvb, crc_offset, 0,
+ "CRC: [missing]");
+ }
+ crc_tree = proto_item_add_subtree(item, ett_fcoe_crc);
+ ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_bad, tvb,
+ crc_offset, 4,
+ crc_exists && crc != crc_computed);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_good, tvb,
+ crc_offset, 4,
+ crc_exists && crc == crc_computed);
+ PROTO_ITEM_SET_GENERATED(ti);
- /*
- * Interpret the EOF.
- */
- if (tvb_bytes_exist(tvb, eof_offset, 1)) {
- proto_tree_add_item(fcoe_tree, hf_fcoe_eof, tvb, eof_offset, 1, ENC_BIG_ENDIAN);
- }
+ /*
+ * Interpret the EOF.
+ */
+ if (tvb_bytes_exist(tvb, eof_offset, 1)) {
+ proto_tree_add_item(fcoe_tree, hf_fcoe_eof, tvb, eof_offset, 1, ENC_BIG_ENDIAN);
}
/* Set the SOF/EOF flags in the packet_info header */
@@ -268,7 +265,7 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
/* Call the FC Dissector if this is carrying an FC frame */
-
+
if (fc_handle) {
call_dissector(fc_handle, next_tvb, pinfo, tree);
} else if (data_handle) {
@@ -322,17 +319,13 @@ proto_register_fcoe(void)
prefs_register_obsolete_preference(fcoe_module, "ethertype");
}
-/*
- * This function name is required because a script is used to find these
- * routines and create the code that calls these routines.
- */
void
proto_reg_handoff_fcoe(void)
{
dissector_handle_t fcoe_handle;
-
+
fcoe_handle = create_dissector_handle(dissect_fcoe, proto_fcoe);
dissector_add_uint("ethertype", ETHERTYPE_FCOE, fcoe_handle);
data_handle = find_dissector("data");
- fc_handle = find_dissector("fc");
+ fc_handle = find_dissector("fc");
}