checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-opa-fe.c
1 /* packet-opa-fe.c
2  * Routines for Omni-Path FE header dissection
3  * Copyright (c) 2016, Intel Corporation.
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "config.h"
13
14 #include <epan/packet.h>
15 #include <epan/prefs.h>
16
17 #include "packet-ssl.h"
18 #include "packet-tcp.h"
19
20 void proto_reg_handoff_opa_fe(void);
21 void proto_register_opa_fe(void);
22
23 #define OPA_FE_TCP_RANGE "3245-3248" /* Not IANA registered */
24 #define OPA_FE_SSL_RANGE "3249-3252"
25
26 #define OPA_FE_HEADER_LEN 24
27
28 /* Wireshark ID */
29 static gint proto_opa_fe = -1;
30
31 /* Variables to hold expansion values between packets */
32 static gint ett_fe = -1;
33
34 /* SnC Fields */
35 static gint hf_opa_fe_magicnumber = -1;
36 static gint hf_opa_fe_length_oob = -1;
37 static gint hf_opa_fe_headerversion = -1;
38 static gint hf_opa_fe_length = -1;
39 static gint hf_opa_fe_Reserved64 = -1;
40
41 /* Dissector Declarations */
42 static dissector_handle_t opa_fe_handle;
43 static dissector_handle_t opa_mad_handle;
44
45 static range_t *global_fe_ssl_range = NULL;
46
47 static range_t *fe_ssl_range = NULL;
48
49 static guint get_opa_fe_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
50 {
51     return tvb_get_ntohl(tvb, offset + 4);
52 }
53 static int dissect_opa_fe_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
54 {
55     gint offset = 0;    /* Current Offset */
56     proto_item *FE_item;
57     proto_tree *FE_tree;
58
59     col_set_str(pinfo->cinfo, COL_PROTOCOL, "Omni-Path");
60     col_clear(pinfo->cinfo, COL_INFO);
61
62     tree = proto_tree_get_root(tree);
63
64     FE_item = proto_tree_add_item(tree, proto_opa_fe, tvb, offset, OPA_FE_HEADER_LEN, ENC_NA);
65     FE_tree = proto_item_add_subtree(FE_item, ett_fe);
66
67     proto_tree_add_item(FE_tree, hf_opa_fe_magicnumber, tvb, offset, 4, ENC_BIG_ENDIAN);
68     offset += 4;
69     proto_tree_add_item(FE_tree, hf_opa_fe_length_oob, tvb, offset, 4, ENC_BIG_ENDIAN);
70     offset += 4;
71     proto_tree_add_item(FE_tree, hf_opa_fe_headerversion, tvb, offset, 4, ENC_BIG_ENDIAN);
72     offset += 4;
73     proto_tree_add_item(FE_tree, hf_opa_fe_length, tvb, offset, 4, ENC_BIG_ENDIAN);
74     offset += 4;
75     proto_tree_add_item(FE_tree, hf_opa_fe_Reserved64, tvb, offset, 8, ENC_BIG_ENDIAN);
76     offset += 8;
77
78     /* Pass to OPA MAD dissector */
79     call_dissector(opa_mad_handle, tvb_new_subset_remaining(tvb, offset), pinfo, FE_tree);
80     return tvb_captured_length(tvb);
81 }
82
83 static int dissect_opa_fe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
84 {
85     tcp_dissect_pdus(tvb, pinfo, tree, TRUE, OPA_FE_HEADER_LEN,
86         get_opa_fe_message_len, dissect_opa_fe_message, data);
87
88     return tvb_reported_length(tvb);
89 }
90
91 static void range_delete_fe_ssl_callback(guint32 port, gpointer ptr _U_)
92 {
93     ssl_dissector_delete(port, opa_fe_handle);
94 }
95
96 static void range_add_fe_ssl_callback(guint32 port, gpointer ptr _U_)
97 {
98     ssl_dissector_add(port, opa_fe_handle);
99 }
100
101 void proto_register_opa_fe(void)
102 {
103     module_t *opa_fe_module;
104
105     static hf_register_info hf[] = {
106         { &hf_opa_fe_magicnumber, {
107                 "Magic Number", "opa.fe.magicnumber",
108                 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
109         },
110         { &hf_opa_fe_length_oob, {
111                 "Length OOB", "opa.fe.lengthoob",
112                 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
113         },
114         { &hf_opa_fe_headerversion, {
115                 "Header Version", "opa.fe.headerversion",
116                 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
117         },
118         { &hf_opa_fe_length, {
119                 "Length", "opa.fe.length",
120                 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
121         },
122         { &hf_opa_fe_Reserved64, {
123                 "Reserved (64 bits)", "opa.fe.reserved64",
124                 FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }
125         }
126     };
127
128     static gint *ett[] = {
129         &ett_fe
130     };
131
132     proto_opa_fe = proto_register_protocol(
133         "Intel Omni-Path FE Header - Omni-Path Fabric Excutive Header",
134         "OPA FE", "opa.fe");
135     opa_fe_handle = register_dissector("opa.fe", dissect_opa_fe, proto_opa_fe);
136
137     proto_register_field_array(proto_opa_fe, hf, array_length(hf));
138     proto_register_subtree_array(ett, array_length(ett));
139
140     opa_fe_module = prefs_register_protocol(proto_opa_fe, proto_reg_handoff_opa_fe);
141     range_convert_str(wmem_epan_scope(), &global_fe_ssl_range, OPA_FE_SSL_RANGE, 65535);
142     prefs_register_range_preference(opa_fe_module, "tls.port", "SSL/TLS Ports",
143         "SSL/TLS Ports range",
144         &global_fe_ssl_range, 65535);
145 }
146
147 void proto_reg_handoff_opa_fe(void)
148 {
149     static gboolean initialized = FALSE;
150
151     if (!initialized)
152     {
153         opa_mad_handle = find_dissector("opa.mad");
154         dissector_add_uint_range_with_preference("tcp.port", OPA_FE_TCP_RANGE, opa_fe_handle);
155         initialized = TRUE;
156     }
157
158     range_foreach(fe_ssl_range, range_delete_fe_ssl_callback, NULL);
159     wmem_free(wmem_epan_scope(), fe_ssl_range);
160     fe_ssl_range = range_copy(wmem_epan_scope(), global_fe_ssl_range);
161     range_foreach(fe_ssl_range, range_add_fe_ssl_callback, NULL);
162
163 }
164
165 /*
166  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
167  *
168  * Local variables:
169  * c-basic-offset: 4
170  * tab-width: 8
171  * indent-tabs-mode: nil
172  * End:
173  *
174  * vi: set shiftwidth=4 tabstop=8 expandtab:
175  * :indentSize=4:tabSize=8:noTabs=true:
176  */