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