3 * Routines for FCoIB dissection - Fibre Channel over Infiniband
4 * Copyright (c) 2010 Mellanox Technologies Ltd. (slavak@mellanox.co.il)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Based on packet-fcoe.c, Copyright (c) 2006 Nuova Systems, Inc. (jre@nuovasystems.com)
12 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include <epan/packet.h>
20 #include <epan/prefs.h>
21 #include <epan/crc32-tvb.h>
22 #include <epan/expert.h>
23 #include <epan/addr_resolv.h>
24 #include "packet-fc.h"
26 void proto_register_fcoib(void);
27 void proto_reg_handoff_fcoib(void);
29 #define FCOIB_HEADER_LEN 16 /* header: encap. header, SOF, and padding */
30 #define FCOIB_TRAILER_LEN 8 /* trailer: FC-CRC, EOF and padding */
31 #define FCOIB_VER_OFFSET 2 /* offset of ver field (in bytes) inside FCoIB Encap. header */
55 static const value_string fcoib_eof_vals
[] = {
56 {FCOIB_EOFn
, "EOFn" },
57 {FCOIB_EOFt
, "EOFt" },
58 {FCOIB_EOFrt
, "EOFrt" },
59 {FCOIB_EOFdt
, "EOFdt" },
60 {FCOIB_EOFni
, "EOFni" },
61 {FCOIB_EOFdti
, "EOFdti" },
62 {FCOIB_EOFrti
, "EOFrti" },
63 {FCOIB_EOFa
, "EOFa" },
67 static const value_string fcoib_sof_vals
[] = {
68 {FCOIB_SOFf
, "SOFf" },
69 {FCOIB_SOFi4
, "SOFi4" },
70 {FCOIB_SOFi2
, "SOFi2" },
71 {FCOIB_SOFi3
, "SOFi3" },
72 {FCOIB_SOFn4
, "SOFn4" },
73 {FCOIB_SOFn2
, "SOFn2" },
74 {FCOIB_SOFn3
, "SOFn3" },
75 {FCOIB_SOFc4
, "SOFc4" },
79 static int proto_fcoib
;
80 static int hf_fcoib_ver
;
81 static int hf_fcoib_sig
;
82 static int hf_fcoib_sof
;
83 static int hf_fcoib_eof
;
84 static int hf_fcoib_crc
;
85 static int hf_fcoib_crc_status
;
89 static expert_field ei_fcoib_crc
;
91 static dissector_handle_t fc_handle
;
94 dissect_fcoib(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
110 proto_tree
*fcoib_tree
;
113 uint32_t crc_computed
= 0;
117 frame_len
= tvb_reported_length_remaining(tvb
, 0) -
118 FCOIB_HEADER_LEN
- FCOIB_TRAILER_LEN
;
119 crc_offset
= FCOIB_HEADER_LEN
+ frame_len
;
120 eof_offset
= crc_offset
+ 4;
121 sof_offset
= FCOIB_HEADER_LEN
- 1;
124 return 0; /* this packet isn't even long enough to contain the header+trailer w/o FC payload! */
126 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FCoIB");
127 next_tvb
= tvb_new_subset_length(tvb
, FCOIB_HEADER_LEN
, frame_len
);
130 * Only version 0 is defined at this point.
131 * Don't print the version in the short summary if it is zero.
134 version
= tvb_get_uint8(tvb
, 0 + FCOIB_VER_OFFSET
) >> 4;
136 ver
= wmem_strdup_printf(pinfo
->pool
, ver
, "ver %d ", version
);
138 if (tvb_bytes_exist(tvb
, 0, 1))
139 sig
= tvb_get_uint8(tvb
, 0) >> 6;
142 if (tvb_bytes_exist(tvb
, eof_offset
, 1)) {
143 eof
= tvb_get_uint8(tvb
, eof_offset
);
144 eof_str
= val_to_str(eof
, fcoib_eof_vals
, "0x%x");
148 if (tvb_bytes_exist(tvb
, sof_offset
, 1)) {
149 sof
= tvb_get_uint8(tvb
, sof_offset
);
150 sof_str
= val_to_str(sof
, fcoib_sof_vals
, "0x%x");
157 crc_exists
= tvb_bytes_exist(tvb
, crc_offset
, 4);
159 crc
= tvb_get_ntohl(tvb
, crc_offset
);
160 crc_computed
= crc32_802_tvb(next_tvb
, frame_len
);
161 if (crc
!= crc_computed
) {
162 crc_msg
= " [bad FC CRC]";
166 if ((frame_len
% 4) != 0 || frame_len
< 24) {
167 len_msg
= " [invalid length]";
170 ti
= proto_tree_add_protocol_format(tree
, proto_fcoib
, tvb
, 0,
172 "FCoIB %s(%s/%s) %d bytes%s%s", ver
,
177 /* Dissect the FCoIB Encapsulation header */
179 fcoib_tree
= proto_item_add_subtree(ti
, ett_fcoib
);
180 proto_tree_add_uint(fcoib_tree
, hf_fcoib_sig
, tvb
, 0, 1, sig
);
181 proto_tree_add_uint(fcoib_tree
, hf_fcoib_ver
, tvb
, FCOIB_VER_OFFSET
, 1, version
);
182 proto_tree_add_uint(fcoib_tree
, hf_fcoib_sof
, tvb
, sof_offset
, 1, sof
);
185 * Create the CRC information.
188 proto_tree_add_checksum(fcoib_tree
, tvb
, crc_offset
, hf_fcoib_crc
, hf_fcoib_crc_status
, &ei_fcoib_crc
, pinfo
, crc_computed
, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_VERIFY
);
189 proto_tree_set_appendix(fcoib_tree
, tvb
, crc_offset
,
190 tvb_captured_length_remaining (tvb
, crc_offset
));
192 proto_tree_add_checksum(fcoib_tree
, tvb
, crc_offset
, hf_fcoib_crc
, hf_fcoib_crc_status
, &ei_fcoib_crc
, pinfo
, 0, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NOT_PRESENT
);
198 if (tvb_bytes_exist(tvb
, eof_offset
, 1)) {
199 proto_tree_add_item(fcoib_tree
, hf_fcoib_eof
, tvb
, eof_offset
, 1, ENC_BIG_ENDIAN
);
202 /* Set the SOF/EOF flags in the packet_info header */
204 if (sof
== FCOIB_SOFi3
|| sof
== FCOIB_SOFi2
|| sof
== FCOIB_SOFi4
) {
205 fc_data
.sof_eof
= FC_DATA_SOF_FIRST_FRAME
;
206 } else if (sof
== FCOIB_SOFf
) {
207 fc_data
.sof_eof
= FC_DATA_SOF_SOFF
;
210 if (eof
!= FCOIB_EOFn
) {
211 fc_data
.sof_eof
|= FC_DATA_EOF_LAST_FRAME
;
212 if (eof
!= FCOIB_EOFt
) {
213 fc_data
.sof_eof
|= FC_DATA_EOF_INVALID
;
217 /* Call the FC Dissector if this is carrying an FC frame */
218 fc_data
.ethertype
= ETHERTYPE_UNK
;
221 call_dissector_with_data(fc_handle
, next_tvb
, pinfo
, tree
, &fc_data
);
223 call_data_dissector(next_tvb
, pinfo
, tree
);
226 return tvb_captured_length(tvb
);
230 dissect_fcoib_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
240 frame_len
= tvb_reported_length_remaining(tvb
, 0) -
241 FCOIB_HEADER_LEN
- FCOIB_TRAILER_LEN
;
242 crc_offset
= FCOIB_HEADER_LEN
+ frame_len
;
243 eof_offset
= crc_offset
+ 4;
244 sof_offset
= FCOIB_HEADER_LEN
- 1;
247 return false; /* this packet isn't even long enough to contain the header+trailer w/o FC payload! */
249 /* we start off with some basic heuristics checks to make sure this could be a FCoIB packet */
251 if (tvb_bytes_exist(tvb
, 0, 1))
252 sig
= tvb_get_uint8(tvb
, 0) >> 6;
253 if (tvb_bytes_exist(tvb
, eof_offset
, 1))
254 eof
= tvb_get_uint8(tvb
, eof_offset
);
255 if (tvb_bytes_exist(tvb
, sof_offset
, 1))
256 sof
= tvb_get_uint8(tvb
, sof_offset
);
259 return false; /* the sig field in the FCoIB Encap. header MUST be 2'b01*/
260 if (!tvb_bytes_exist(tvb
, eof_offset
+ 1, 3) || tvb_get_ntoh24(tvb
, eof_offset
+ 1) != 0)
261 return false; /* 3 bytes of RESERVED field immediately after eEOF MUST be 0 */
262 if (!try_val_to_str(sof
, fcoib_sof_vals
))
263 return false; /* invalid value for SOF */
264 if (!try_val_to_str(eof
, fcoib_eof_vals
))
265 return false; /* invalid value for EOF */
267 dissect_fcoib(tvb
, pinfo
, tree
, data
);
272 proto_register_fcoib(void)
274 module_t
*fcoib_module
;
276 /* Setup list of header fields See Section 1.6.1 for details*/
277 static hf_register_info hf
[] = {
279 {"SOF", "fcoib.sof", FT_UINT8
, BASE_HEX
, VALS(fcoib_sof_vals
), 0,
282 {"EOF", "fcoib.eof", FT_UINT8
, BASE_HEX
, VALS(fcoib_eof_vals
), 0,
285 {"Signature", "fcoib.sig", FT_UINT8
, BASE_HEX
, NULL
, 0, NULL
, HFILL
}},
287 {"Version", "fcoib.ver", FT_UINT32
, BASE_DEC
, NULL
, 0, NULL
, HFILL
}},
289 {"CRC", "fcoib.crc", FT_UINT32
, BASE_HEX
, NULL
, 0, NULL
, HFILL
}},
290 { &hf_fcoib_crc_status
,
291 {"CRC Status", "fcoib.crc.status", FT_UINT8
, BASE_NONE
, VALS(proto_checksum_vals
), 0x0,
294 static int *ett
[] = {
298 static ei_register_info ei
[] = {
299 { &ei_fcoib_crc
, { "fcoib.crc.bad", PI_CHECKSUM
, PI_ERROR
, "Bad checksum", EXPFILL
}},
302 expert_module_t
* expert_fcoib
;
304 /* Register the protocol name and description */
305 proto_fcoib
= proto_register_protocol("Fibre Channel over Infiniband",
308 /* Required function calls to register the header fields and
310 proto_register_field_array(proto_fcoib
, hf
, array_length(hf
));
311 proto_register_subtree_array(ett
, array_length(ett
));
312 expert_fcoib
= expert_register_protocol(proto_fcoib
);
313 expert_register_field_array(expert_fcoib
, ei
, array_length(ei
));
315 fcoib_module
= prefs_register_protocol(proto_fcoib
, NULL
);
317 prefs_register_static_text_preference(fcoib_module
, "use_decode_as",
318 "Heuristic matching preferences removed. Use Infiniband protocol preferences or Decode As.",
319 "Simple heuristics can still be enable (may generate false positives) through Infiniband protocol preferences."
320 "To force FCoIB dissection use Decode As");
322 prefs_register_obsolete_preference(fcoib_module
, "heur_en");
323 prefs_register_obsolete_preference(fcoib_module
, "manual_en");
325 prefs_register_obsolete_preference(fcoib_module
, "addr_a");
326 prefs_register_obsolete_preference(fcoib_module
, "addr_a_type");
327 prefs_register_obsolete_preference(fcoib_module
, "addr_a_id");
328 prefs_register_obsolete_preference(fcoib_module
, "addr_a_qp");
330 prefs_register_obsolete_preference(fcoib_module
, "addr_b");
331 prefs_register_obsolete_preference(fcoib_module
, "addr_b_type");
332 prefs_register_obsolete_preference(fcoib_module
, "addr_b_id");
333 prefs_register_obsolete_preference(fcoib_module
, "addr_b_qp");
337 proto_reg_handoff_fcoib(void)
339 heur_dissector_add("infiniband.payload", dissect_fcoib_heur
, "Fibre Channel over Infiniband", "fc_infiniband", proto_fcoib
, HEURISTIC_ENABLE
);
341 dissector_add_for_decode_as("infiniband", create_dissector_handle( dissect_fcoib
, proto_fcoib
) );
343 fc_handle
= find_dissector_add_dependency("fc", proto_fcoib
);
347 * Editor modelines - https://www.wireshark.org/tools/modelines.html
352 * indent-tabs-mode: nil
355 * vi: set shiftwidth=4 tabstop=8 expandtab:
356 * :indentSize=4:tabSize=8:noTabs=true: