aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/opcua/opcua.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-10-07 16:25:01 -0400
committerMichael Mann <mmann78@netscape.net>2016-10-08 02:44:53 +0000
commit268841f3e00b7cf0f16c81dd2b3b952172130b8b (patch)
tree359e01cf5eba83308760531888713fe0ff0bc10b /plugins/opcua/opcua.c
parent11d3224142c0531879fb8e415daf9639a4eace66 (diff)
Combine Decode As and port preferences for tcp.port dissector table.
This patch introduces new APIs to allow dissectors to have a preference for a (TCP) port, but the underlying data is actually part of Decode As functionality. For now the APIs are intentionally separate from the regular APIs that register a dissector within a dissector table. It may be possible to eventually combine the two so that all dissectors that register with a dissector table have an opportunity to "automatically" have a preference to adjust the "table value" through the preferences dialog. The tcp.port dissector table was used as the guinea pig. This will eventually be expanded to other dissector tables as well (most notably UDP ports). Some dissectors that "shared" a TCP/UDP port preference were also converted. It also removed the need for some preference callback functions (mostly when the callback function was the proto_reg_handoff function) so there is cleanup around that. Dissectors that has a port preference whose default was 0 were switched to using the dissector_add_for_decode_as_with_preference API rather than dissector_add_uint_with_preference Also added comments for TCP ports used that aren't IANA registered. Change-Id: I99604f95d426ad345f4b494598d94178b886eb67 Reviewed-on: https://code.wireshark.org/review/17724 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'plugins/opcua/opcua.c')
-rw-r--r--plugins/opcua/opcua.c61
1 files changed, 4 insertions, 57 deletions
diff --git a/plugins/opcua/opcua.c b/plugins/opcua/opcua.c
index e3f2bf0376..1341b96882 100644
--- a/plugins/opcua/opcua.c
+++ b/plugins/opcua/opcua.c
@@ -20,7 +20,6 @@
#include "config.h"
#include <epan/packet.h>
-#include <epan/prefs.h>
#include <epan/reassemble.h>
#include <epan/dissectors/packet-tcp.h>
#include "opcua_transport_layer.h"
@@ -44,9 +43,8 @@ typedef int (*FctParse)(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gin
static int proto_opcua = -1;
static dissector_handle_t opcua_handle;
-static range_t *global_tcp_ports_opcua;
/** Official IANA registered port for OPC UA Binary Protocol. */
-#define OPCUA_PORT 4840
+#define OPCUA_PORT_RANGE "4840"
/** subtree types used in opcua_transport_layer.c */
gint ett_opcua_extensionobject = -1;
@@ -357,18 +355,6 @@ static int dissect_opcua(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo
return tvb_reported_length(tvb);
}
-static void register_tcp_port(guint32 port)
-{
- if (port != 0)
- dissector_add_uint("tcp.port", port, opcua_handle);
-}
-
-static void unregister_tcp_port(guint32 port)
-{
- if (port != 0)
- dissector_delete_uint("tcp.port", port, opcua_handle);
-}
-
static void
init_opcua(void)
{
@@ -387,8 +373,6 @@ cleanup_opcua(void)
*/
void proto_register_opcua(void)
{
- char *tmp;
-
static hf_register_info hf[] =
{
/* id full name abbreviation type display strings bitmask blurb HFILL */
@@ -414,13 +398,7 @@ void proto_register_opcua(void)
&ett_opcua_fragments
};
- module_t *opcua_module;
-
- proto_opcua = proto_register_protocol(
- "OpcUa Binary Protocol", /* name */
- "OpcUa", /* short name */
- "opcua" /* abbrev */
- );
+ proto_opcua = proto_register_protocol("OpcUa Binary Protocol", "OpcUa", "opcua");
registerTransportLayerTypes(proto_opcua);
registerSecurityLayerTypes(proto_opcua);
@@ -432,48 +410,17 @@ void proto_register_opcua(void)
registerFieldTypes(proto_opcua);
proto_register_subtree_array(ett, array_length(ett));
-
- tmp = g_strdup_printf("%d", OPCUA_PORT);
- range_convert_str(&global_tcp_ports_opcua, tmp, 65535);
- g_free(tmp);
-
proto_register_field_array(proto_opcua, hf, array_length(hf));
register_init_routine(&init_opcua);
register_cleanup_routine(&cleanup_opcua);
-
- /* register user preferences */
- opcua_module = prefs_register_protocol(proto_opcua, proto_reg_handoff_opcua);
- prefs_register_range_preference(opcua_module, "tcp_ports",
- "OPC UA TCP Ports",
- "The TCP ports for the OPC UA TCP Binary Protocol (comma separated list)",
- &global_tcp_ports_opcua, 65535);
-
}
void proto_reg_handoff_opcua(void)
{
- static gboolean opcua_initialized = FALSE;
- static range_t *tcp_ports_opcua = NULL;
-
- if(!opcua_initialized)
- {
- opcua_handle = create_dissector_handle(dissect_opcua, proto_opcua);
- opcua_initialized = TRUE;
- }
- else
- {
- /* clean up ports and their lists */
- if (tcp_ports_opcua != NULL)
- {
- range_foreach(tcp_ports_opcua, unregister_tcp_port);
- g_free(tcp_ports_opcua);
- }
- }
+ opcua_handle = create_dissector_handle(dissect_opcua, proto_opcua);
- /* If we now have a PDU tree, register for the port or ports we have */
- tcp_ports_opcua = range_copy(global_tcp_ports_opcua);
- range_foreach(tcp_ports_opcua, register_tcp_port);
+ dissector_add_uint_range_with_preference("tcp.port", OPCUA_PORT_RANGE, opcua_handle);
}
/*