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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
/* packet-userlog.c
* Routines for userlog protocol packet disassembly
* Copyright 2016, Jun Wang <sdn_app@163.com>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/*
* Userlog is user flow logs of H3C device.
* Flow logging records users' access to the extranet. The device classifies and
* calculates flows through the 5-tuple information, which includes source IP address,
* destination IP address, source port, destination port, and protocol number,
* and generates user flow logs. Flow logging records the 5-tuple information of
* the packets and number of the bytes received and sent. With flow logs, administrators
* can track and record accesses to the network, facilitating the availability and
* security of the network.
*
*/
#include "config.h"
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/ipproto.h>
void proto_register_userlog(void);
void proto_reg_handoff_userlog(void);
static dissector_handle_t userlog_handle;
static int proto_userlog = -1;
static int hf_userlog_version = -1;
static int hf_userlog_logtype = -1;
static int hf_userlog_count = -1;
static int hf_userlog_timestamp = -1;
static int hf_userlog_header_reserved = -1;
static int hf_userlog_proto = -1;
static int hf_userlog_Operator = -1;
static int hf_userlog_IPVerion = -1;
static int hf_userlog_IPToS = -1;
static int hf_userlog_SourceIP = -1;
static int hf_userlog_SrcNatIP = -1;
static int hf_userlog_DestIP = -1;
static int hf_userlog_DestNatIP = -1;
static int hf_userlog_SrcPort = -1;
static int hf_userlog_SrcNatPort = -1;
static int hf_userlog_DestPort = -1;
static int hf_userlog_DestNatPort = -1;
static int hf_userlog_StartTime = -1;
static int hf_userlog_EndTime = -1;
static int hf_userlog_InTotalPkg = -1;
static int hf_userlog_InTotalByte = -1;
static int hf_userlog_OutTotalPkg = -1;
static int hf_userlog_OutTotalByte = -1;
static int hf_userlog_Reserved1 = -1;
static int hf_userlog_Reserved2 = -1;
static int hf_userlog_Reserved3 = -1;
static gint ett_userlog = -1;
static gint ett_userlog_header = -1;
static gint ett_userlog_log = -1;
static const value_string version[] = {
{ 1, "V1" },
{ 3, "V3" },
{ 0, NULL }
};
static const value_string logtype[] = {
{ 1, "NAT" },
{ 2, "BAS" },
{ 4, "Flow" },
{ 0, NULL }
};
static const value_string Operator[] = {
{ 1, "normal close flow" },
{ 2, "timeout" },
{ 3, "clear flow" },
{ 4, "overflow" },
{ 5, "nat static" },
{ 6, "time data threshold" },
{ 7, "flow delete" },
{ 8, "flow create" },
{ 0, NULL }
};
/* Minimum length (in bytes) of the protocol data. */
#define USERLOG_MIN_LENGTH 8
/* Code to actually dissect the packets */
static int
dissect_userlog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
/* Set up structures needed to add the protocol subtree and manage it */
proto_item *ti;
proto_tree *userlog_header, *userlog_tree;
proto_tree *userlog_log;
/* Other misc. local variables. */
gint offset = 0;
guint log_count = 1;
guint log_type, log_max;
/* Check that the packet is long enough for it to belong to us. */
if (tvb_reported_length(tvb) < USERLOG_MIN_LENGTH)
return 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "UserLog");
/* Clear out stuff in the info column */
col_clear(pinfo->cinfo,COL_INFO);
ti = proto_tree_add_item(tree, proto_userlog, tvb, 0, -1, ENC_NA);
userlog_tree = proto_item_add_subtree(ti, ett_userlog);
userlog_header = proto_tree_add_subtree(userlog_tree, tvb, 0, 16, ett_userlog_header, NULL, "UserLog Header");
proto_tree_add_item(userlog_header, hf_userlog_version, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item_ret_uint(userlog_header, hf_userlog_logtype, tvb, offset, 1, ENC_BIG_ENDIAN, &log_type);
col_add_fstr(pinfo->cinfo, COL_INFO, "LogType = %s", val_to_str(log_type, logtype, "Unknown (0x%02x)"));
offset += 1;
proto_tree_add_item_ret_uint(userlog_header, hf_userlog_count, tvb, offset, 2, ENC_BIG_ENDIAN, &log_max);
proto_item_append_text(ti, ", Log Count = %d", log_max);
offset += 2;
proto_tree_add_item(userlog_header, hf_userlog_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
/* XXX - 8 bytes unaccounted for */
proto_tree_add_item(userlog_header, hf_userlog_header_reserved, tvb, offset, 8, ENC_NA);
offset += 8;
if (userlog_tree) { /* we are being asked for details */
while ( log_count <= log_max)
{
userlog_log = proto_tree_add_subtree_format(userlog_tree, tvb, offset, 64, ett_userlog_log, NULL, "UserLog No.%d", log_count);
proto_tree_add_item(userlog_log, hf_userlog_proto, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(userlog_log, hf_userlog_Operator, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(userlog_log, hf_userlog_IPVerion, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(userlog_log, hf_userlog_IPToS, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(userlog_log, hf_userlog_SourceIP, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_SrcNatIP, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_DestIP, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_DestNatIP, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_SrcPort, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(userlog_log, hf_userlog_SrcNatPort, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(userlog_log, hf_userlog_DestPort, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(userlog_log, hf_userlog_DestNatPort, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(userlog_log, hf_userlog_StartTime, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_EndTime, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_InTotalPkg, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_InTotalByte, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_OutTotalPkg, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_OutTotalByte, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_Reserved1, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_Reserved2, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(userlog_log, hf_userlog_Reserved3, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
log_count++;
}
}
return tvb_captured_length(tvb);
}
void
proto_register_userlog(void)
{
static hf_register_info hf[] = {
{ &hf_userlog_version,
{ "Version", "userlog.version",
FT_UINT8, BASE_DEC,
VALS(version), 0x0,
NULL, HFILL }
},
{ &hf_userlog_logtype,
{ "LogType", "userlog.logtype",
FT_UINT8, BASE_DEC,
VALS(logtype), 0x0,
NULL, HFILL }
},
{ &hf_userlog_count,
{ "LogCount", "userlog.count",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_timestamp,
{ "TimeStamp", "userlog.timestamp",
FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_header_reserved,
{ "Reserved", "userlog.header_reserved",
FT_BYTES, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_proto,
{ "Protocol", "userlog.proto",
FT_UINT8, BASE_DEC|BASE_EXT_STRING,
&ipproto_val_ext, 0x0,
NULL, HFILL }
},
{ &hf_userlog_Operator,
{ "Operator", "userlog.Operator",
FT_UINT8, BASE_DEC,
VALS(Operator), 0x0,
NULL, HFILL }
},
{ &hf_userlog_IPVerion,
{ "IP Version", "userlog.IPVersion",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_IPToS,
{ "IP ToS", "userlog.IPToS",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_SourceIP,
{ "Source-IP", "userlog.SourceIP",
FT_IPv4, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_SrcNatIP,
{ "Source-NAT-IP", "userlog.Source-NAT-IP",
FT_IPv4, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_DestIP,
{ "Destination-IP", "userlog.Destination-IP",
FT_IPv4, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_DestNatIP,
{ "Destination-NAT-IP", "userlog.Destination-NAT-IP",
FT_IPv4, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_SrcPort,
{ "Source-Port", "userlog.Source-Port",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_SrcNatPort,
{ "Source-NAT-Port", "userlog.Source-NAT-Port",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_DestPort,
{ "Destination-Port", "userlog.Destination-Port",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_DestNatPort,
{ "Destination-NAT-Port", "userlog.Destination-NAT-Port",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_StartTime,
{ "StartTime", "userlog.StartTime",
FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_EndTime,
{ "EndTime", "userlog.EndTime",
FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_InTotalPkg,
{ "InTotalPkg", "userlog.InTotalPkg",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_InTotalByte,
{ "InTotalByte", "userlog.InTotalByte",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_OutTotalPkg,
{ "OutTotalPkg", "userlog.OutTotalPkg",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_OutTotalByte,
{ "OutTotalByte", "userlog.OutTotalByte",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_Reserved1,
{ "Reserved1", "userlog.Reserved1",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_Reserved2,
{ "Reserved2", "userlog.Reserved2",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_userlog_Reserved3,
{ "Reserved3", "userlog.Reserved3",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
}
};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_userlog,
&ett_userlog_header,
&ett_userlog_log
};
proto_userlog = proto_register_protocol("UserLog Protocol", "UserLog", "userlog");
proto_register_field_array(proto_userlog, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
userlog_handle = register_dissector("userlog", dissect_userlog, proto_userlog);
}
void
proto_reg_handoff_userlog(void)
{
dissector_add_for_decode_as_with_preference("udp.port", userlog_handle);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/
|