summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-prp.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:53 +0000
commita86c5f7cae7ec9a3398300555a0b644689d946a1 (patch)
tree39fe4b107c71174fd1e8a8ceb9a4d2aa14116248 /epan/dissectors/packet-prp.c
parentReleasing progress-linux version 4.2.6-1~progress7.99u1. (diff)
downloadwireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.tar.xz
wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.zip
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/dissectors/packet-prp.c')
-rw-r--r--epan/dissectors/packet-prp.c103
1 files changed, 35 insertions, 68 deletions
diff --git a/epan/dissectors/packet-prp.c b/epan/dissectors/packet-prp.c
index 11c45be5..27f2d182 100644
--- a/epan/dissectors/packet-prp.c
+++ b/epan/dissectors/packet-prp.c
@@ -32,69 +32,39 @@ static const value_string prp_lan_vals[] = {
void proto_register_prp(void);
-static int proto_prp = -1;
+static int proto_prp;
/* Initialize trailer fields */
-static int hf_prp_redundancy_control_trailer_sequence_nr = -1;
-static int hf_prp_redundancy_control_trailer_lan = -1;
-static int hf_prp_redundancy_control_trailer_size = -1;
-static int hf_prp_redundancy_control_trailer_suffix = -1;
-static int hf_prp_redundancy_control_trailer_version = -1;
+static int hf_prp_redundancy_control_trailer_sequence_nr;
+static int hf_prp_redundancy_control_trailer_lan;
+static int hf_prp_redundancy_control_trailer_size;
+static int hf_prp_redundancy_control_trailer_suffix;
+static int hf_prp_redundancy_control_trailer_version;
/* Initialize the subtree pointers */
-static gint ett_prp_redundancy_control_trailer = -1;
+static int ett_prp_redundancy_control_trailer;
/* Code to actually dissect the packets */
static int
-dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
+dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data)
{
proto_item *ti;
proto_tree *prp_tree;
- guint i;
- guint length;
- guint offset;
- guint16 lan_id;
- guint16 lsdu_size;
- guint16 prp1_suffix;
- guint trailer_start;
- guint trailer_length;
+ int i;
+ int length;
+ uint16_t lan_id;
+ uint16_t lsdu_size;
+ uint16_t prp1_suffix;
+ unsigned trailer_start;
+ unsigned trailer_length;
trailer_start = 0;
trailer_length = 0;
length = tvb_reported_length(tvb);
- if(length < 14)
- return 0;
-
- /*
- * This is horribly broken. It assumes the frame is an Ethernet
- * frame, with a type field at an offset of 12 bytes from the header.
- * That is not guaranteed to be true.
- *
- * Ideally, this should be a heuristic dissector registered in
- * the "eth.trailer" heuristic dissector table (and it can
- * be registered as "disabled by default" there); unfortunately,
- * it needs to know the length of the entire frame for the
- * PRP-0 heuristic, so it'd have to be passed that length
- * out of band.
- */
- if (!tvb_bytes_exist(tvb, 12, 2))
- return 0;
- if(ETHERTYPE_VLAN == tvb_get_ntohs(tvb, 12)) /* tagged frame */
- {
- offset = 18;
- }
- else /* untagged */
- {
- offset = 14;
- }
-
- if (!tree)
- return tvb_captured_length(tvb);
-
/*
* Is there enough data in the packet to every try to search for a
* trailer?
@@ -102,23 +72,25 @@ dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, pr
if (!tvb_bytes_exist(tvb, (length-4)+2, 2))
return 0; /* no */
+ if (data == NULL) {
+ return 0;
+ }
+
+ int lsdu_size_correct = *(int*)data;
+
/* search for PRP-0 trailer */
/* If the frame is > 64 bytes, the PRP-0 trailer is always at the end. */
/* If the frame is <= 64 bytes, the PRP-0 trailer may be anywhere (before the padding) */
- for(i=length-4; i>=offset; i--)
+ for(i = 0; i <= length - 4; i++)
{
- lan_id = tvb_get_ntohs(tvb, (i+2)) >> 12;
- lsdu_size = tvb_get_ntohs(tvb, (i+2)) & 0x0fff;
- if(lsdu_size == i+4-offset && (lan_id == 0xa || lan_id == 0xb))
+ lan_id = tvb_get_ntohs(tvb, length - 2 - i) >> 12;
+ lsdu_size = tvb_get_ntohs(tvb, length - 2 - i) & 0x0fff;
+ if(lsdu_size == (lsdu_size_correct - i) && (lan_id == 0xa || lan_id == 0xb))
{
- trailer_start = i;
+ trailer_start = length - 4 - i;
trailer_length = 4;
break;
}
-
- if (length > 64) {
- break; /* don't search, just check the last position */
- }
}
/* check for PRP-1 trailer */
@@ -167,7 +139,6 @@ dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, pr
tvb, trailer_start+2, 2, ENC_BIG_ENDIAN);
} else {
/* PRP-1 */
- int lsdu_size_correct = length-offset;
if (lsdu_size == lsdu_size_correct) {
proto_tree_add_uint_format(prp_tree, hf_prp_redundancy_control_trailer_size,
tvb, trailer_start+2, 2, lsdu_size,
@@ -182,7 +153,12 @@ dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, pr
tvb, trailer_start+4, 2, ENC_BIG_ENDIAN);
}
}
- return tvb_captured_length(tvb);
+ return trailer_length;
+}
+
+static bool dissect_prp_redundancy_control_trailer_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data)
+{
+ return dissect_prp_redundancy_control_trailer(tvb, pinfo, parent_tree, data) > 0;
}
/* Register the protocol with Wireshark */
@@ -221,23 +197,15 @@ void proto_register_prp(void)
}
};
- static gint *ett[] = {
+ static int *ett[] = {
&ett_prp_redundancy_control_trailer,
};
module_t *prp_module;
- dissector_handle_t prp_handle;
/* Register the protocol name and description */
proto_prp = proto_register_protocol("Parallel Redundancy Protocol (IEC62439 Part 3)", "PRP", "prp");
- /* Post dissectors (such as the trailer dissector for this protocol)
- * get called for every single frame anyone loads into Wireshark.
- * Since this protocol is not of general interest we disable this
- * protocol by default.
- */
- proto_disable_by_default(proto_prp);
-
prp_module = prefs_register_protocol_obsolete(proto_prp);
prefs_register_obsolete_preference(prp_module, "enable");
@@ -246,9 +214,8 @@ void proto_register_prp(void)
proto_register_field_array(proto_prp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
- prp_handle = register_dissector("prp", dissect_prp_redundancy_control_trailer, proto_prp);
-
- register_postdissector(prp_handle);
+ heur_dissector_add("eth.trailer", dissect_prp_redundancy_control_trailer_heur,
+ "PRP Trailer", "prp_eth", proto_prp, HEURISTIC_ENABLE);
}
/*