Coverage Report

Created: 2026-09-28 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-exablaze.c
Line
Count
Source
1
/* packet-exablaze.c
2
 * Routines for dissection of Exablaze trailers
3
 * Copyright 2018 Exablaze
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 <math.h>
15
16
#include <epan/packet.h>
17
18
void proto_register_exablaze(void);
19
void proto_reg_handoff_exablaze(void);
20
21
static int proto_exablaze;
22
23
static int hf_exablaze_original_fcs;
24
static int hf_exablaze_device;
25
static int hf_exablaze_port;
26
static int hf_exablaze_timestamp;
27
static int hf_exablaze_timestamp_integer;
28
static int hf_exablaze_timestamp_fractional;
29
30
static int ett_exablaze;
31
static int ett_exablaze_timestamp;
32
33
static int
34
dissect_exablaze(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
35
        void *data _U_)
36
0
{
37
0
    proto_item *ti;
38
0
    proto_tree *exablaze_tree;
39
0
    proto_tree *timestamp_tree;
40
41
0
    unsigned trailer_length;
42
0
    unsigned fcs_length;
43
0
    unsigned offset;
44
0
    bool trailer_found;
45
46
0
    uint8_t device;
47
0
    uint8_t port;
48
0
    uint32_t timestamp_sec;
49
0
    uint64_t timestamp_frac;
50
51
0
    nstime_t timestamp;
52
0
    double timestamp_frac_double;
53
0
    struct tm *tm;
54
55
0
    trailer_length = tvb_reported_length(tvb);
56
57
0
    if (trailer_length != tvb_captured_length(tvb)) {
58
        /* The heuristics require the whole trailer to be captured */
59
0
        return 0;
60
0
    }
61
62
    /* Try matching with and without FCS */
63
0
    trailer_found = false;
64
0
    for (fcs_length = 0; fcs_length <= 4; fcs_length += 4)
65
0
    {
66
0
        if (trailer_length < fcs_length + 16)
67
0
            continue;
68
69
0
        offset = trailer_length - fcs_length - 16;
70
71
0
        device = tvb_get_uint8(tvb, offset + 4);
72
0
        port = tvb_get_uint8(tvb, offset + 5);
73
0
        timestamp_sec = tvb_get_ntohl(tvb, offset + 6);
74
0
        timestamp_frac = tvb_get_ntoh40(tvb, offset + 10);
75
76
        /* If the capture time and timestamp differ by more than a week,
77
         * then this is probably not a valid Exablaze trailer */
78
0
        if (timestamp_sec > (unsigned)pinfo->abs_ts.secs) {
79
0
            if (timestamp_sec - pinfo->abs_ts.secs > 604800)
80
0
                continue;
81
0
        } else {
82
0
            if (pinfo->abs_ts.secs - timestamp_sec > 604800)
83
0
                continue;
84
0
        }
85
86
0
        trailer_found = true;
87
0
        break;
88
0
    }
89
90
0
    if (!trailer_found)
91
0
        return 0;
92
93
    /* Fractional part is a 40 bit binary fraction of a second */
94
0
    timestamp.secs = timestamp_sec;
95
0
    timestamp_frac_double = ldexp((double)timestamp_frac, -40);
96
0
    timestamp.nsecs = (int)(timestamp_frac_double * 1000000000);
97
98
0
    ti = proto_tree_add_item(tree, proto_exablaze, tvb, offset, 16, ENC_NA);
99
0
    proto_item_append_text(ti, ", Device: %u, Port: %u, Timestamp: ",
100
0
            device, port);
101
102
0
    tm = localtime(&timestamp.secs);
103
0
    if (tm)
104
0
        proto_item_append_text(ti, "%02u:%02u:%02.12f",
105
0
                tm->tm_hour, tm->tm_min, tm->tm_sec + timestamp_frac_double);
106
0
    else
107
0
        proto_item_append_text(ti, "<Not representable>");
108
109
0
    exablaze_tree = proto_item_add_subtree(ti, ett_exablaze);
110
0
    proto_tree_add_item(exablaze_tree, hf_exablaze_original_fcs, tvb,
111
0
            offset, 4, ENC_BIG_ENDIAN);
112
0
    proto_tree_add_item(exablaze_tree, hf_exablaze_device, tvb,
113
0
            offset + 4, 1, ENC_BIG_ENDIAN);
114
0
    proto_tree_add_item(exablaze_tree, hf_exablaze_port, tvb,
115
0
            offset + 5, 1, ENC_BIG_ENDIAN);
116
117
0
    ti = proto_tree_add_time(exablaze_tree, hf_exablaze_timestamp, tvb,
118
0
            offset + 6, 9, &timestamp);
119
0
    timestamp_tree = proto_item_add_subtree(ti, ett_exablaze_timestamp);
120
121
0
    proto_tree_add_item(timestamp_tree, hf_exablaze_timestamp_integer, tvb,
122
0
            offset + 6, 4, ENC_BIG_ENDIAN);
123
0
    proto_tree_add_double_format_value(timestamp_tree,
124
0
            hf_exablaze_timestamp_fractional, tvb, offset + 10, 5,
125
0
            timestamp_frac_double, "%.12f", timestamp_frac_double);
126
127
0
    return offset + 16;
128
0
}
129
130
static bool
131
dissect_exablaze_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
132
0
{
133
0
    return dissect_exablaze(tvb, pinfo, tree, data) > 0;
134
0
}
135
136
void
137
proto_register_exablaze(void)
138
16
{
139
16
    static hf_register_info hf[] = {
140
16
        {
141
16
            &hf_exablaze_original_fcs,
142
16
            {
143
16
                "Original FCS", "exablaze.original_fcs",
144
16
                FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL
145
16
            }
146
16
        },
147
16
        {
148
16
            &hf_exablaze_device,
149
16
            {
150
16
                "Device ID", "exablaze.device",
151
16
                FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
152
16
            }
153
16
        },
154
16
        {
155
16
            &hf_exablaze_port,
156
16
            {
157
16
                "Port", "exablaze.port",
158
16
                FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
159
16
            }
160
16
        },
161
16
        {
162
16
            &hf_exablaze_timestamp,
163
16
            {
164
16
                "Timestamp", "exablaze.timestamp",
165
16
                FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL
166
16
            }
167
16
        },
168
16
        {   &hf_exablaze_timestamp_integer,
169
16
            {
170
16
                "Seconds since epoch", "exablaze.timestamp.seconds",
171
16
                FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL
172
16
            }
173
16
        },
174
16
        {   &hf_exablaze_timestamp_fractional,
175
16
            {
176
16
                "Fractional seconds",
177
16
                "exablaze.timestamp.fractional_seconds",
178
16
                FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL
179
16
            }
180
16
        }
181
16
    };
182
183
16
    static int *ett[] = {
184
16
        &ett_exablaze,
185
16
        &ett_exablaze_timestamp
186
16
    };
187
188
16
    proto_exablaze = proto_register_protocol("Exablaze trailer", "Exablaze",
189
16
            "exablaze");
190
16
    proto_register_field_array(proto_exablaze, hf, array_length(hf));
191
16
    proto_register_subtree_array(ett, array_length(ett));
192
16
}
193
194
void
195
proto_reg_handoff_exablaze(void)
196
16
{
197
16
    heur_dissector_add("eth.trailer", dissect_exablaze_heur, "Exablaze trailer",
198
16
            "exablaze_eth", proto_exablaze, HEURISTIC_DISABLE);
199
16
}
200
201
/*
202
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
203
 *
204
 * Local variables:
205
 * c-basic-offset: 4
206
 * tab-width: 8
207
 * indent-tabs-mode: nil
208
 * End:
209
 *
210
 * vi: set shiftwidth=4 tabstop=8 expandtab:
211
 * :indentSize=4:tabSize=8:noTabs=true:
212
 */