forked from osmocom/wireshark
Use correct parent tree when creating a subtree: Fixes Coverity 902 [UNUSED];
Remove unneeded #includes; Do some whitespace cleanup. svn path=/trunk/; revision=37329
This commit is contained in:
parent
57b17b8794
commit
befd2a6f74
|
@ -28,9 +28,6 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <epan/packet.h>
|
||||
#include <epan/strutil.h>
|
||||
|
||||
|
@ -40,8 +37,8 @@
|
|||
|
||||
|
||||
/* Offsets in TLV structure. */
|
||||
#define TLV_TYPE 0
|
||||
#define TLV_LENGTH 2
|
||||
#define TLV_TYPE 0
|
||||
#define TLV_LENGTH 2
|
||||
|
||||
static int proto_fefd = -1;
|
||||
static int hf_fefd_version = -1;
|
||||
|
@ -69,14 +66,14 @@ static dissector_handle_t data_handle;
|
|||
|
||||
|
||||
static const value_string type_vals[] = {
|
||||
{ TYPE_DEVICE_ID, "Device ID" },
|
||||
{ TYPE_PORT_ID, "Port ID" },
|
||||
{ TYPE_ECHO, "Echo" },
|
||||
{ TYPE_MESSAGE_INTERVAL, "Message interval" },
|
||||
{ TYPE_TIMEOUT_INTERVAL, "Timeout interval" },
|
||||
{ TYPE_DEVICE_NAME, "Device name" },
|
||||
{ TYPE_SEQUENCE_NUMBER, "Sequence number" },
|
||||
{ 0, NULL }
|
||||
{ TYPE_DEVICE_ID, "Device ID" },
|
||||
{ TYPE_PORT_ID, "Port ID" },
|
||||
{ TYPE_ECHO, "Echo" },
|
||||
{ TYPE_MESSAGE_INTERVAL, "Message interval" },
|
||||
{ TYPE_TIMEOUT_INTERVAL, "Timeout interval" },
|
||||
{ TYPE_DEVICE_NAME, "Device name" },
|
||||
{ TYPE_SEQUENCE_NUMBER, "Sequence number" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
#define OPCODE_RESERVED 0x00
|
||||
|
@ -85,11 +82,11 @@ static const value_string type_vals[] = {
|
|||
#define OPCODE_FLUSH 0x03
|
||||
|
||||
static const value_string opcode_vals[] = {
|
||||
{ OPCODE_RESERVED, "Reserved" },
|
||||
{ OPCODE_PROBE, "Probe" },
|
||||
{ OPCODE_ECHO, "Echo" },
|
||||
{ OPCODE_FLUSH, "Flush" },
|
||||
{ 0, NULL }
|
||||
{ OPCODE_RESERVED, "Reserved" },
|
||||
{ OPCODE_PROBE, "Probe" },
|
||||
{ OPCODE_ECHO, "Echo" },
|
||||
{ OPCODE_FLUSH, "Flush" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -108,130 +105,130 @@ dissect_fefd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
col_clear(pinfo->cinfo, COL_INFO);
|
||||
|
||||
if (tree) {
|
||||
proto_item *flags_ti;
|
||||
proto_tree *flags_tree;
|
||||
proto_item *flags_ti;
|
||||
proto_tree *flags_tree;
|
||||
|
||||
ti = proto_tree_add_item(tree, proto_fefd, tvb, offset, -1, FALSE);
|
||||
fefd_tree = proto_item_add_subtree(ti, ett_fefd);
|
||||
ti = proto_tree_add_item(tree, proto_fefd, tvb, offset, -1, FALSE);
|
||||
fefd_tree = proto_item_add_subtree(ti, ett_fefd);
|
||||
|
||||
/* FEFD header */
|
||||
proto_tree_add_item(fefd_tree, hf_fefd_version, tvb, offset, 1, FALSE);
|
||||
proto_tree_add_item(fefd_tree, hf_fefd_opcode, tvb, offset, 1, FALSE);
|
||||
offset += 1;
|
||||
flags_ti = proto_tree_add_item(fefd_tree, hf_fefd_flags, tvb, offset, 1, FALSE);
|
||||
flags_tree = proto_item_add_subtree(ti, ett_fefd_flags);
|
||||
proto_tree_add_item(flags_tree, hf_fefd_flags_rt, tvb, offset, 1, FALSE);
|
||||
proto_tree_add_item(flags_tree, hf_fefd_flags_rsy, tvb, offset, 1, FALSE);
|
||||
offset += 1;
|
||||
proto_tree_add_item(fefd_tree, hf_fefd_checksum, tvb, offset, 2, FALSE);
|
||||
offset += 2;
|
||||
/* FEFD header */
|
||||
proto_tree_add_item(fefd_tree, hf_fefd_version, tvb, offset, 1, FALSE);
|
||||
proto_tree_add_item(fefd_tree, hf_fefd_opcode, tvb, offset, 1, FALSE);
|
||||
offset += 1;
|
||||
flags_ti = proto_tree_add_item(fefd_tree, hf_fefd_flags, tvb, offset, 1, FALSE);
|
||||
flags_tree = proto_item_add_subtree(flags_ti, ett_fefd_flags);
|
||||
proto_tree_add_item(flags_tree, hf_fefd_flags_rt, tvb, offset, 1, FALSE);
|
||||
proto_tree_add_item(flags_tree, hf_fefd_flags_rsy, tvb, offset, 1, FALSE);
|
||||
offset += 1;
|
||||
proto_tree_add_item(fefd_tree, hf_fefd_checksum, tvb, offset, 2, FALSE);
|
||||
offset += 2;
|
||||
} else {
|
||||
offset += 4; /* The version/opcode/flags/checksum fields from above */
|
||||
offset += 4; /* The version/opcode/flags/checksum fields from above */
|
||||
}
|
||||
|
||||
while (tvb_reported_length_remaining(tvb, offset) != 0) {
|
||||
type = tvb_get_ntohs(tvb, offset + TLV_TYPE);
|
||||
length = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
|
||||
if (length < 4) {
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset, 4,
|
||||
"TLV with invalid length %u (< 4)",
|
||||
length);
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
}
|
||||
offset += 4;
|
||||
break;
|
||||
}
|
||||
while (tvb_reported_length_remaining(tvb, offset) != 0) {
|
||||
type = tvb_get_ntohs(tvb, offset + TLV_TYPE);
|
||||
length = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
|
||||
if (length < 4) {
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset, 4,
|
||||
"TLV with invalid length %u (< 4)",
|
||||
length);
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
}
|
||||
offset += 4;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
switch (type) {
|
||||
|
||||
case TYPE_DEVICE_ID:
|
||||
/* Device ID */
|
||||
case TYPE_DEVICE_ID:
|
||||
/* Device ID */
|
||||
|
||||
if (check_col(pinfo->cinfo, COL_INFO))
|
||||
col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
|
||||
"Device ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4,
|
||||
length - 4));
|
||||
if (check_col(pinfo->cinfo, COL_INFO))
|
||||
col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
|
||||
"Device ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4,
|
||||
length - 4));
|
||||
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
|
||||
length, "Device ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4, length - 4));
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Device ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4, length - 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
|
||||
length, "Device ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4, length - 4));
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Device ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4, length - 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_PORT_ID:
|
||||
real_length = length;
|
||||
if (tvb_get_guint8(tvb, offset + real_length) != 0x00) {
|
||||
/* The length in the TLV doesn't appear to be the
|
||||
length of the TLV, as the byte just past it
|
||||
isn't the first byte of a 2-byte big-endian
|
||||
small integer; make the length of the TLV the length
|
||||
in the TLV, plus 4 bytes for the TLV type and length,
|
||||
minus 1 because that's what makes one capture work. */
|
||||
real_length = length + 3;
|
||||
}
|
||||
case TYPE_PORT_ID:
|
||||
real_length = length;
|
||||
if (tvb_get_guint8(tvb, offset + real_length) != 0x00) {
|
||||
/* The length in the TLV doesn't appear to be the
|
||||
length of the TLV, as the byte just past it
|
||||
isn't the first byte of a 2-byte big-endian
|
||||
small integer; make the length of the TLV the length
|
||||
in the TLV, plus 4 bytes for the TLV type and length,
|
||||
minus 1 because that's what makes one capture work. */
|
||||
real_length = length + 3;
|
||||
}
|
||||
|
||||
if (check_col(pinfo->cinfo, COL_INFO))
|
||||
col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
|
||||
"Port ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4, real_length - 4));
|
||||
if (check_col(pinfo->cinfo, COL_INFO))
|
||||
col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
|
||||
"Port ID: %s",
|
||||
tvb_format_stringzpad(tvb, offset + 4, real_length - 4));
|
||||
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
|
||||
real_length, "Port ID: %s",
|
||||
tvb_format_text(tvb, offset + 4, real_length - 4));
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
real_length - 4,
|
||||
"Sent through Interface: %s",
|
||||
tvb_format_text(tvb, offset + 4, real_length - 4));
|
||||
}
|
||||
offset += real_length;
|
||||
break;
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
|
||||
real_length, "Port ID: %s",
|
||||
tvb_format_text(tvb, offset + 4, real_length - 4));
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
real_length - 4,
|
||||
"Sent through Interface: %s",
|
||||
tvb_format_text(tvb, offset + 4, real_length - 4));
|
||||
}
|
||||
offset += real_length;
|
||||
break;
|
||||
|
||||
case TYPE_ECHO:
|
||||
case TYPE_MESSAGE_INTERVAL:
|
||||
case TYPE_TIMEOUT_INTERVAL:
|
||||
case TYPE_DEVICE_NAME:
|
||||
case TYPE_SEQUENCE_NUMBER:
|
||||
default:
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
|
||||
length, "Type: %s, length: %u",
|
||||
val_to_str(type, type_vals, "Unknown (0x%04x)"),
|
||||
length);
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
if (length > 4) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Data");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
case TYPE_ECHO:
|
||||
case TYPE_MESSAGE_INTERVAL:
|
||||
case TYPE_TIMEOUT_INTERVAL:
|
||||
case TYPE_DEVICE_NAME:
|
||||
case TYPE_SEQUENCE_NUMBER:
|
||||
default:
|
||||
tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
|
||||
length, "Type: %s, length: %u",
|
||||
val_to_str(type, type_vals, "Unknown (0x%04x)"),
|
||||
length);
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
|
||||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
if (length > 4) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Data");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
|
||||
call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo, fefd_tree);
|
||||
}
|
||||
|
@ -240,42 +237,42 @@ void
|
|||
proto_register_fefd(void)
|
||||
{
|
||||
static hf_register_info hf[] = {
|
||||
{ &hf_fefd_version,
|
||||
{ "Version", "fefd.version", FT_UINT8, BASE_DEC, NULL, 0xE0,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_version,
|
||||
{ "Version", "fefd.version", FT_UINT8, BASE_DEC, NULL, 0xE0,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_opcode,
|
||||
{ "Opcode", "fefd.opcode", FT_UINT8, BASE_DEC, VALS(opcode_vals), 0x1F,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_opcode,
|
||||
{ "Opcode", "fefd.opcode", FT_UINT8, BASE_DEC, VALS(opcode_vals), 0x1F,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_flags,
|
||||
{ "Flags", "fefd.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_flags,
|
||||
{ "Flags", "fefd.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_flags_rt,
|
||||
{ "Recommended timeout", "fefd.flags.rt", FT_BOOLEAN, 8, NULL, 0x80,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_flags_rt,
|
||||
{ "Recommended timeout", "fefd.flags.rt", FT_BOOLEAN, 8, NULL, 0x80,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_flags_rsy,
|
||||
{ "ReSynch", "fefd.flags.rsy", FT_BOOLEAN, 8, NULL, 0x40,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_flags_rsy,
|
||||
{ "ReSynch", "fefd.flags.rsy", FT_BOOLEAN, 8, NULL, 0x40,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_checksum,
|
||||
{ "Checksum", "fefd.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_checksum,
|
||||
{ "Checksum", "fefd.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_tlvtype,
|
||||
{ "Type", "fefd.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0,
|
||||
NULL, HFILL }},
|
||||
{ &hf_fefd_tlvtype,
|
||||
{ "Type", "fefd.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_fefd_tlvlength,
|
||||
{ "Length", "fefd.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0,
|
||||
NULL, HFILL }}
|
||||
{ &hf_fefd_tlvlength,
|
||||
{ "Length", "fefd.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0,
|
||||
NULL, HFILL }}
|
||||
};
|
||||
static gint *ett[] = {
|
||||
&ett_fefd,
|
||||
&ett_fefd_flags,
|
||||
&ett_fefd_tlv
|
||||
&ett_fefd,
|
||||
&ett_fefd_flags,
|
||||
&ett_fefd_tlv
|
||||
};
|
||||
|
||||
proto_fefd = proto_register_protocol("Far End Failure Detection", "FEFD", "fefd");
|
||||
|
|
Loading…
Reference in New Issue