Coverage Report

Created: 2026-07-12 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-fcct.c
Line
Count
Source
1
/* packet-fcct.c
2
 * Routines for FC Common Transport Protocol (used by GS3 services)
3
 * Copyright 2001, Dinesh G Dutt <ddutt@andiamo.com>
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/to_str.h>
16
#include "packet-fc.h"
17
#include "packet-fcct.h"
18
19
void proto_register_fcct(void);
20
void proto_reg_handoff_fcct(void);
21
22
static dissector_handle_t fcct_handle;
23
24
/* Initialize the protocol and registered fields */
25
static int proto_fcct;
26
static int hf_fcct_revision;
27
static int hf_fcct_inid;
28
static int hf_fcct_gstype;
29
static int hf_fcct_gssubtype;
30
static int hf_fcct_options;
31
static int hf_fcct_server; /* derived field */
32
33
/* Extended preamble fields */
34
#if 0
35
static int hf_fcct_ext_said;
36
static int hf_fcct_ext_tid;
37
static int hf_fcct_ext_reqname;
38
static int hf_fcct_ext_tstamp;
39
static int hf_fcct_ext_authblk;
40
#endif
41
42
/* Initialize the subtree pointers */
43
static int ett_fcct;
44
static int ett_fcct_ext;  /* for the extended header */
45
46
const value_string fc_ct_rjt_code_vals [] = {
47
    {FCCT_RJT_INVCMDCODE, "Invalid Cmd Code"},
48
    {FCCT_RJT_INVVERSION, "Invalid Version Level"},
49
    {FCCT_RJT_LOGICALERR, "Logical Error"},
50
    {FCCT_RJT_INVSIZE,    "Invalid CT_IU Size"},
51
    {FCCT_RJT_LOGICALBSY, "Logical Busy"},
52
    {FCCT_RJT_PROTOERR,   "Protocol Error"},
53
    {FCCT_RJT_GENFAIL,    "Unable to Perform Cmd"},
54
    {FCCT_RJT_CMDNOTSUPP, "Cmd Not Supported"},
55
    {0, NULL},
56
};
57
58
const value_string fc_ct_gstype_vals[] = {
59
    {FCCT_GSTYPE_KEYSVC, "Key Service"},
60
    {FCCT_GSTYPE_ALIASSVC, "Alias Service"},
61
    {FCCT_GSTYPE_MGMTSVC, "Management Service"},
62
    {FCCT_GSTYPE_TIMESVC, "Time Service"},
63
    {FCCT_GSTYPE_DIRSVC, "Directory Service"},
64
    {FCCT_GSTYPE_FCTLR, "Fabric Controller"},
65
    {FCCT_GSTYPE_VENDOR, "Vendor-Specific"},
66
    {0, NULL},
67
};
68
69
const value_string fc_ct_gsserver_vals[] = {
70
    {FCCT_GSRVR_DNS, "dNS"},
71
    {FCCT_GSRVR_IP,  "IP"},
72
    {FCCT_GSRVR_FCS, "Fabric Config Server"},
73
    {FCCT_GSRVR_UNS, "Unzoned Name Server"},
74
    {FCCT_GSRVR_FZS, "Fabric Zone Server"},
75
    {FCCT_GSRVR_TS,  "Time Server"},
76
    {FCCT_GSRVR_KS,  "Key Server"},
77
    {FCCT_GSRVR_AS,  "Alias Server"},
78
    {FCCT_GSRVR_FCTLR, "Fabric Controller"},
79
    {0, NULL},
80
};
81
82
static dissector_table_t fcct_gserver_table;
83
84
uint8_t
85
get_gs_server (uint8_t gstype, uint8_t gssubtype)
86
225
{
87
225
    switch (gstype) {
88
2
    case FCCT_GSTYPE_KEYSVC:
89
2
        return FCCT_GSRVR_KS;
90
0
    case FCCT_GSTYPE_ALIASSVC:
91
0
        if (gssubtype == FCCT_GSSUBTYPE_AS)
92
0
            return FCCT_GSRVR_AS;
93
0
        return FCCT_GSRVR_UNKNOWN;
94
70
    case FCCT_GSTYPE_MGMTSVC:
95
70
        if (gssubtype == FCCT_GSSUBTYPE_FCS)
96
2
            return FCCT_GSRVR_FCS;
97
68
        else if (gssubtype == FCCT_GSSUBTYPE_UNS)
98
3
            return FCCT_GSRVR_UNS;
99
65
        else if (gssubtype == FCCT_GSSUBTYPE_FZS)
100
59
            return FCCT_GSRVR_FZS;
101
6
        else return FCCT_GSRVR_UNKNOWN;
102
1
    case FCCT_GSTYPE_TIMESVC:
103
1
        if (gssubtype == FCCT_GSSUBTYPE_TS)
104
0
            return FCCT_GSRVR_TS;
105
1
        return FCCT_GSRVR_UNKNOWN;
106
4
    case FCCT_GSTYPE_DIRSVC:
107
4
        if (gssubtype == FCCT_GSSUBTYPE_DNS)
108
0
            return FCCT_GSRVR_DNS;
109
4
        else if (gssubtype == FCCT_GSSUBTYPE_IP)
110
2
            return FCCT_GSRVR_IP;
111
2
        return FCCT_GSRVR_UNKNOWN;
112
3
    case FCCT_GSRVR_FCTLR:
113
3
         if (gssubtype == FCCT_GSSUBTYPE_FCTLR)
114
1
              return (FCCT_GSRVR_FCTLR);
115
2
         else return (FCCT_GSRVR_UNKNOWN);
116
145
    default:
117
145
        return FCCT_GSRVR_UNKNOWN;
118
225
    }
119
225
}
120
121
/* Code to actually dissect the packets */
122
static int
123
dissect_fcct (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
124
88
{
125
126
/* Set up structures needed to add the protocol subtree and manage it */
127
88
    proto_item *ti;
128
88
    proto_tree *fcct_tree;
129
88
    tvbuff_t *next_tvb;
130
88
    int in_id,
131
88
        offset = 0;
132
88
    uint8_t server;
133
88
    fc_ct_preamble cthdr;
134
88
    address addr;
135
136
    /* Make entries in Protocol column and Info column on summary display */
137
88
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "FC_CT");
138
139
    /*
140
      cthdr.revision = tvb_get_uint8 (tvb, offset++);
141
      cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
142
      offset += 3;
143
144
      cthdr.gstype = tvb_get_uint8 (tvb, offset++);
145
      cthdr.options = tvb_get_uint8 (tvb, offset++);
146
    */
147
88
    tvb_memcpy (tvb, (uint8_t *)&cthdr, offset, FCCT_PRMBL_SIZE);
148
88
    cthdr.revision = tvb_get_uint8 (tvb, offset++);
149
88
    cthdr.in_id = tvb_get_ntoh24 (tvb, offset);
150
88
    cthdr.opcode = g_ntohs (cthdr.opcode);
151
88
    cthdr.maxres_size = g_ntohs (cthdr.maxres_size);
152
153
88
    if (cthdr.opcode < FCCT_MSG_REQ_MAX) {
154
74
        col_append_str (pinfo->cinfo, COL_INFO, " Request");
155
74
    }
156
14
    else if (cthdr.opcode == FCCT_MSG_ACC) {
157
0
        col_append_str (pinfo->cinfo, COL_INFO, " Accept");
158
0
    }
159
14
    else if (cthdr.opcode == FCCT_MSG_RJT) {
160
0
        col_append_fstr (pinfo->cinfo, COL_INFO, " Reject (%s)",
161
0
                            val_to_str(pinfo->pool, cthdr.rjt_code, fc_ct_rjt_code_vals, "0x%x"));
162
0
    }
163
14
    else {
164
14
        col_append_str (pinfo->cinfo, COL_INFO, " Reserved");
165
14
    }
166
167
88
    in_id = cthdr.in_id;
168
88
    in_id = g_htonl (in_id) >> 8;
169
170
    /* Determine server */
171
88
    server = get_gs_server (cthdr.gstype, cthdr.gssubtype);
172
173
88
    if (tree) {
174
86
        offset = 0;
175
86
        ti = proto_tree_add_protocol_format (tree, proto_fcct, tvb, 0, FCCT_PRMBL_SIZE,
176
86
                                             "FC_CT");
177
86
        fcct_tree = proto_item_add_subtree (ti, ett_fcct);
178
179
86
        proto_tree_add_item (fcct_tree, hf_fcct_revision, tvb, offset++,
180
86
                             sizeof (uint8_t), ENC_BIG_ENDIAN);
181
86
        set_address(&addr, AT_FC, 3, &in_id);
182
86
        proto_tree_add_string (fcct_tree, hf_fcct_inid, tvb, offset, 3,
183
86
                               address_to_str(pinfo->pool, &addr));
184
86
        offset += 3; /* sizeof FC address */
185
186
86
        proto_tree_add_item (fcct_tree, hf_fcct_gstype, tvb, offset++,
187
86
                             sizeof (uint8_t), ENC_BIG_ENDIAN);
188
86
        proto_tree_add_item (fcct_tree, hf_fcct_gssubtype, tvb, offset,
189
86
                             sizeof (uint8_t), ENC_BIG_ENDIAN);
190
86
        proto_tree_add_uint (fcct_tree, hf_fcct_server, tvb, offset++, 1,
191
86
                             server);
192
86
        proto_tree_add_item (fcct_tree, hf_fcct_options, tvb, offset++,
193
86
                             sizeof (uint8_t), ENC_BIG_ENDIAN);
194
195
86
    }
196
    /* We do not change the starting offset for the next protocol in the
197
     * chain since the fc_ct header is common to the sub-protocols.
198
     * Pass the fchdr* received from parent dissector through to sub-protocols
199
     */
200
88
    next_tvb = tvb_new_subset_remaining (tvb, 0);
201
88
    if (!dissector_try_uint_with_data(fcct_gserver_table, server, next_tvb, pinfo,
202
88
                             tree, true, data)) {
203
23
        call_data_dissector(next_tvb, pinfo, tree);
204
23
    }
205
206
88
    return tvb_captured_length(tvb);
207
88
}
208
209
/* Register the protocol with Wireshark */
210
211
void
212
proto_register_fcct(void)
213
15
{
214
215
/* Setup list of header fields  See Section 1.6.1 for details*/
216
15
    static hf_register_info hf[] = {
217
15
        { &hf_fcct_revision,
218
15
          {"Revision", "fcct.revision", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
219
15
        { &hf_fcct_inid,
220
15
          {"IN_ID", "fcct.in_id", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
221
15
        { &hf_fcct_gstype,
222
15
          {"GS Type", "fcct.gstype", FT_UINT8, BASE_HEX, VALS(fc_ct_gstype_vals),
223
15
           0x0, NULL, HFILL}},
224
15
        { &hf_fcct_gssubtype,
225
15
          {"GS Subtype", "fcct.gssubtype", FT_UINT8, BASE_HEX, NULL, 0x0,
226
15
           NULL, HFILL}},
227
15
        { &hf_fcct_server,
228
15
          {"Server", "fcct.server", FT_UINT8, BASE_HEX,
229
15
           VALS (fc_ct_gsserver_vals), 0x0,
230
15
           "Derived from GS Type & Subtype fields", HFILL}},
231
15
        { &hf_fcct_options,
232
15
          {"Options", "fcct.options", FT_UINT8, BASE_HEX, NULL, 0x0, NULL,
233
15
           HFILL}},
234
#if 0
235
        { &hf_fcct_ext_said,
236
          {"Auth SAID", "fcct.ext_said", FT_UINT32, BASE_HEX, NULL, 0x0, NULL,
237
           HFILL}},
238
        { &hf_fcct_ext_tid,
239
          {"Transaction ID", "fcct.ext_tid", FT_UINT32, BASE_HEX, NULL, 0x0, NULL,
240
           HFILL}},
241
        { &hf_fcct_ext_reqname,
242
          {"Requestor Port Name", "fcct.ext_reqnm", FT_BYTES, BASE_NONE, NULL,
243
           0x0, NULL, HFILL}},
244
        { &hf_fcct_ext_tstamp,
245
          {"Timestamp", "fcct.ext_tstamp", FT_BYTES, BASE_NONE, NULL, 0x0, NULL,
246
           HFILL}},
247
        { &hf_fcct_ext_authblk,
248
          {"Auth Hash Blk", "fcct.ext_authblk", FT_BYTES, BASE_NONE, NULL, 0x0,
249
           NULL, HFILL}},
250
#endif
251
15
    };
252
253
    /* Setup protocol subtree array */
254
15
    static int *ett[] = {
255
15
        &ett_fcct,
256
15
        &ett_fcct_ext,
257
15
    };
258
259
    /* Register the protocol name and description */
260
15
    proto_fcct = proto_register_protocol("Fibre Channel Common Transport", "FC_CT", "fcct");
261
262
    /* Required function calls to register the header fields and subtrees used */
263
15
    proto_register_field_array(proto_fcct, hf, array_length(hf));
264
15
    proto_register_subtree_array(ett, array_length(ett));
265
266
15
    fcct_gserver_table = register_dissector_table ("fcct.server",
267
15
                                                   "FCCT Server",
268
15
                                                   proto_fcct, FT_UINT8, BASE_HEX);
269
270
15
    fcct_handle = register_dissector("fcct", dissect_fcct, proto_fcct);
271
15
}
272
273
void
274
proto_reg_handoff_fcct (void)
275
15
{
276
15
    dissector_add_uint("fc.ftype", FC_FTYPE_FCCT, fcct_handle);
277
15
}
278
279
/*
280
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
281
 *
282
 * Local variables:
283
 * c-basic-offset: 4
284
 * tab-width: 8
285
 * indent-tabs-mode: nil
286
 * End:
287
 *
288
 * vi: set shiftwidth=4 tabstop=8 expandtab:
289
 * :indentSize=4:tabSize=8:noTabs=true:
290
 */