Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-lanforge.c
Line
Count
Source
1
/* packet-lanforge.c
2
 * Routines for "LANforge traffic generator IP protocol" dissection
3
 * Copyright 2008
4
 * Ben Greear <greearb@candelatech.com>
5
 *
6
 * Based on pktgen dissectory by:
7
 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
8
 *
9
 * Wireshark - Network traffic analyzer
10
 * By Gerald Combs <gerald@wireshark.org>
11
 * Copyright 1998 Gerald Combs
12
 *
13
 * SPDX-License-Identifier: GPL-2.0-or-later
14
 */
15
16
/* LANforge generates network traffic for load & performance testing.
17
 * See http://www.candelatech.com for more info.
18
 */
19
20
#include "config.h"
21
22
#include <epan/packet.h>
23
24
void proto_register_lanforge(void);
25
void proto_reg_handoff_lanforge(void);
26
27
/* magic num used for heuristic */
28
1.26k
#define LANFORGE_MAGIC 0x1a2b3c4d
29
30
/* Initialize the protocol and registered fields */
31
static int proto_lanforge;
32
33
/* lanforge header */
34
static int hf_lanforge_crc;
35
static int hf_lanforge_magic;
36
static int hf_lanforge_src_session;
37
static int hf_lanforge_dst_session;
38
static int hf_lanforge_pld_len_l;
39
static int hf_lanforge_pld_len_h;
40
static int hf_lanforge_pld_len;
41
static int hf_lanforge_pld_pattern;
42
static int hf_lanforge_seq;
43
static int hf_lanforge_tx_time_s;
44
static int hf_lanforge_tx_time_ns;
45
static int hf_lanforge_timestamp;
46
47
/* Initialize the subtree pointer */
48
static int ett_lanforge;
49
50
/* entry point */
51
static bool dissect_lanforge(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
52
2.52k
{
53
2.52k
    proto_item *ti;
54
2.52k
    proto_tree *lanforge_tree;
55
2.52k
    uint32_t offset = 0;
56
2.52k
    uint32_t magic, pld_len, pld_len_h;
57
58
    /* check for min size */
59
2.52k
    if(tvb_captured_length(tvb) < 28) {  /* Not a LANforge packet. */
60
1.26k
        return false;
61
1.26k
    }
62
63
    /* check for magic number */
64
1.26k
    magic = tvb_get_ntohl(tvb, 4);
65
1.26k
    if(magic != LANFORGE_MAGIC){
66
        /* Not a LANforge packet. */
67
1.26k
        return false;
68
1.26k
    }
69
70
    /* Make entries in Protocol column and Info column on summary display */
71
72
1
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "LANforge");
73
74
1
    col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 16));
75
76
    /* create display subtree for the protocol */
77
78
1
    ti = proto_tree_add_item(tree, proto_lanforge, tvb, 0, -1, ENC_NA);
79
80
1
    lanforge_tree = proto_item_add_subtree(ti, ett_lanforge);
81
82
    /* add items to the subtree */
83
84
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_crc, tvb, offset, 4, ENC_BIG_ENDIAN);
85
1
    offset+=4;
86
87
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_magic, tvb, offset, 4, ENC_BIG_ENDIAN);
88
1
    offset+=4;
89
90
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_src_session, tvb, offset, 2, ENC_BIG_ENDIAN);
91
1
    offset+=2;
92
93
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_dst_session, tvb, offset, 2, ENC_BIG_ENDIAN);
94
1
    offset+=2;
95
96
1
    proto_tree_add_item_ret_uint(lanforge_tree, hf_lanforge_pld_len_l,
97
1
            tvb, offset, 2, ENC_BIG_ENDIAN, &pld_len);
98
1
    offset+=2;
99
1
    proto_tree_add_item_ret_uint(lanforge_tree, hf_lanforge_pld_len_h,
100
1
            tvb, offset, 1, ENC_BIG_ENDIAN, &pld_len_h);
101
1
    offset+=1;
102
1
    pld_len |= (pld_len_h << 16);
103
1
    proto_tree_add_uint(lanforge_tree, hf_lanforge_pld_len, tvb, offset-3, 3, pld_len);
104
105
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_pld_pattern, tvb, offset, 1, ENC_BIG_ENDIAN);
106
1
    offset+=1;
107
108
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_seq, tvb, offset, 4, ENC_BIG_ENDIAN);
109
1
    offset+=4;
110
111
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_tx_time_s, tvb, offset, 4, ENC_BIG_ENDIAN);
112
1
    offset+=4;
113
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_tx_time_ns, tvb, offset, 4, ENC_BIG_ENDIAN);
114
1
    offset+=4;
115
1
    proto_tree_add_item(lanforge_tree, hf_lanforge_timestamp,
116
1
            tvb, offset - 8, 8, ENC_TIME_SECS_NSECS|ENC_BIG_ENDIAN);
117
118
1
    if(tvb_reported_length_remaining(tvb, offset) > 0) /* random data */
119
1
        call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo,
120
1
                lanforge_tree);
121
122
1
    return true;
123
1.26k
}
124
125
126
/* Register the protocol with Wireshark */
127
void proto_register_lanforge(void)
128
15
{
129
    /* Setup list of header fields */
130
131
15
    static hf_register_info hf[] = {
132
133
15
        { &hf_lanforge_crc,
134
15
          {
135
15
              "CRC", "lanforge.CRC",
136
15
              FT_UINT32, BASE_HEX, NULL, 0x0,
137
15
              "The LANforge CRC number", HFILL
138
15
          }
139
15
        },
140
141
15
        { &hf_lanforge_magic,
142
15
          {
143
15
              "Magic number", "lanforge.magic",
144
15
              FT_UINT32, BASE_HEX, NULL, 0x0,
145
15
              "The LANforge magic number", HFILL
146
15
          }
147
15
        },
148
149
15
        { &hf_lanforge_src_session,
150
15
          {
151
15
              "Source session ID", "lanforge.source-session-id",
152
15
              FT_UINT16, BASE_DEC, NULL, 0x0,
153
15
              "The LANforge source session ID", HFILL
154
15
          }
155
15
        },
156
157
15
        { &hf_lanforge_dst_session,
158
15
          {
159
15
              "Dest session ID", "lanforge.dest-session-id",
160
15
              FT_UINT16, BASE_DEC, NULL, 0x0,
161
15
              "The LANforge dest session ID", HFILL
162
15
          }
163
15
        },
164
165
15
        { &hf_lanforge_pld_len_l,
166
15
          {
167
15
              "Payload Length(L)", "lanforge.pld-len-L",
168
15
              FT_UINT16, BASE_DEC, NULL, 0x0,
169
15
              "The LANforge payload length (low bytes)", HFILL
170
15
          }
171
15
        },
172
173
15
        { &hf_lanforge_pld_len_h,
174
15
          {
175
15
              "Payload Length(H)", "lanforge.pld-len-H",
176
15
              FT_UINT8, BASE_DEC, NULL, 0x0,
177
15
              "The LANforge payload length (high byte)", HFILL
178
15
          }
179
15
        },
180
181
15
        { &hf_lanforge_pld_len,
182
15
          {
183
15
              "Payload Length", "lanforge.pld-length",
184
15
              FT_UINT32, BASE_DEC, NULL, 0x0,
185
15
              "The LANforge payload length", HFILL
186
15
          }
187
15
        },
188
189
15
        { &hf_lanforge_pld_pattern,
190
15
          {
191
15
              "Payload Pattern", "lanforge.pld-pattern",
192
15
              FT_UINT16, BASE_DEC, NULL, 0x0,
193
15
              "The LANforge payload pattern", HFILL
194
15
          }
195
15
        },
196
197
15
        { &hf_lanforge_seq,
198
15
          {
199
15
              "Sequence Number", "lanforge.seqno",
200
15
              FT_UINT32, BASE_DEC, NULL, 0x0,
201
15
              "The LANforge Sequence Number", HFILL
202
15
          }
203
15
        },
204
205
15
        { &hf_lanforge_tx_time_s,
206
15
          {
207
15
              "Timestamp Secs", "lanforge.ts-secs",
208
15
              FT_UINT32, BASE_DEC, NULL, 0x0,
209
15
              NULL, HFILL
210
15
          }
211
15
        },
212
213
15
        { &hf_lanforge_tx_time_ns,
214
15
          {
215
15
              "Timestamp nsecs", "lanforge.ts-nsecs",
216
15
              FT_UINT32, BASE_DEC, NULL, 0x0,
217
15
              NULL, HFILL
218
15
          }
219
15
        },
220
221
15
        { &hf_lanforge_timestamp,
222
15
          {
223
15
              "Timestamp", "lanforge.timestamp",
224
15
              FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
225
15
              NULL, HFILL
226
15
          }
227
15
        }
228
15
    };
229
230
    /* Setup protocol subtree array */
231
232
15
    static int *ett[] = {
233
15
        &ett_lanforge
234
15
    };
235
236
    /* Register the protocol name and description */
237
238
15
    proto_lanforge = proto_register_protocol("LANforge Traffic Generator", "LANforge", "lanforge");
239
240
    /* Required function calls to register the header fields and subtrees used */
241
242
15
    proto_register_field_array(proto_lanforge, hf, array_length(hf));
243
15
    proto_register_subtree_array(ett, array_length(ett));
244
15
}
245
246
247
void proto_reg_handoff_lanforge(void)
248
15
{
249
    /* Register as a heuristic UDP dissector */
250
15
    heur_dissector_add("udp", dissect_lanforge, "LANforge over UDP", "lanforge_udp", proto_lanforge, HEURISTIC_ENABLE);
251
15
    heur_dissector_add("tcp", dissect_lanforge, "LANforge over TCP", "lanforge_tcp", proto_lanforge, HEURISTIC_ENABLE);
252
15
}
253
254
/*
255
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
256
 *
257
 * Local variables:
258
 * c-basic-offset: 4
259
 * tab-width: 8
260
 * indent-tabs-mode: nil
261
 * End:
262
 *
263
 * vi: set shiftwidth=4 tabstop=8 expandtab:
264
 * :indentSize=4:tabSize=8:noTabs=true:
265
 */