2 * Routines for userlog protocol packet disassembly
3 * Copyright 2016, Jun Wang <sdn_app@163.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 * Userlog is user flow logs of H3C device.
13 * Flow logging records users' access to the extranet. The device classifies and
14 * calculates flows through the 5-tuple information, which includes source IP address,
15 * destination IP address, source port, destination port, and protocol number,
16 * and generates user flow logs. Flow logging records the 5-tuple information of
17 * the packets and number of the bytes received and sent. With flow logs, administrators
18 * can track and record accesses to the network, facilitating the availability and
19 * security of the network.
25 #include <epan/packet.h>
26 #include <epan/prefs.h>
27 #include <epan/ipproto.h>
29 void proto_register_userlog(void);
30 void proto_reg_handoff_userlog(void);
32 static dissector_handle_t userlog_handle
;
34 static int proto_userlog
;
36 static int hf_userlog_version
;
37 static int hf_userlog_logtype
;
38 static int hf_userlog_count
;
39 static int hf_userlog_timestamp
;
40 static int hf_userlog_header_reserved
;
42 static int hf_userlog_proto
;
43 static int hf_userlog_Operator
;
44 static int hf_userlog_IPVerion
;
45 static int hf_userlog_IPToS
;
47 static int hf_userlog_SourceIP
;
48 static int hf_userlog_SrcNatIP
;
49 static int hf_userlog_DestIP
;
50 static int hf_userlog_DestNatIP
;
51 static int hf_userlog_SrcPort
;
52 static int hf_userlog_SrcNatPort
;
53 static int hf_userlog_DestPort
;
54 static int hf_userlog_DestNatPort
;
56 static int hf_userlog_StartTime
;
57 static int hf_userlog_EndTime
;
59 static int hf_userlog_InTotalPkg
;
60 static int hf_userlog_InTotalByte
;
61 static int hf_userlog_OutTotalPkg
;
62 static int hf_userlog_OutTotalByte
;
64 static int hf_userlog_Reserved1
;
65 static int hf_userlog_Reserved2
;
66 static int hf_userlog_Reserved3
;
68 static int ett_userlog
;
69 static int ett_userlog_header
;
70 static int ett_userlog_log
;
72 static const value_string version
[] = {
78 static const value_string logtype
[] = {
85 static const value_string Operator
[] = {
86 { 1, "normal close flow" },
91 { 6, "time data threshold" },
98 /* Minimum length (in bytes) of the protocol data. */
99 #define USERLOG_MIN_LENGTH 8
102 /* Code to actually dissect the packets */
104 dissect_userlog(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
106 /* Set up structures needed to add the protocol subtree and manage it */
108 proto_tree
*userlog_header
, *userlog_tree
;
109 proto_tree
*userlog_log
;
110 /* Other misc. local variables. */
112 unsigned log_count
= 1;
113 unsigned log_type
, log_max
;
115 /* Check that the packet is long enough for it to belong to us. */
116 if (tvb_reported_length(tvb
) < USERLOG_MIN_LENGTH
)
119 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "UserLog");
120 /* Clear out stuff in the info column */
121 col_clear(pinfo
->cinfo
,COL_INFO
);
123 ti
= proto_tree_add_item(tree
, proto_userlog
, tvb
, 0, -1, ENC_NA
);
124 userlog_tree
= proto_item_add_subtree(ti
, ett_userlog
);
126 userlog_header
= proto_tree_add_subtree(userlog_tree
, tvb
, 0, 16, ett_userlog_header
, NULL
, "UserLog Header");
127 proto_tree_add_item(userlog_header
, hf_userlog_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
130 proto_tree_add_item_ret_uint(userlog_header
, hf_userlog_logtype
, tvb
, offset
, 1, ENC_BIG_ENDIAN
, &log_type
);
131 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "LogType = %s", val_to_str(log_type
, logtype
, "Unknown (0x%02x)"));
134 proto_tree_add_item_ret_uint(userlog_header
, hf_userlog_count
, tvb
, offset
, 2, ENC_BIG_ENDIAN
, &log_max
);
135 proto_item_append_text(ti
, ", Log Count = %d", log_max
);
138 proto_tree_add_item(userlog_header
, hf_userlog_timestamp
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
141 /* XXX - 8 bytes unaccounted for */
142 proto_tree_add_item(userlog_header
, hf_userlog_header_reserved
, tvb
, offset
, 8, ENC_NA
);
145 if (userlog_tree
) { /* we are being asked for details */
146 while ( log_count
<= log_max
)
148 userlog_log
= proto_tree_add_subtree_format(userlog_tree
, tvb
, offset
, 64, ett_userlog_log
, NULL
, "UserLog No.%d", log_count
);
150 proto_tree_add_item(userlog_log
, hf_userlog_proto
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
152 proto_tree_add_item(userlog_log
, hf_userlog_Operator
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
154 proto_tree_add_item(userlog_log
, hf_userlog_IPVerion
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
156 proto_tree_add_item(userlog_log
, hf_userlog_IPToS
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
158 proto_tree_add_item(userlog_log
, hf_userlog_SourceIP
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
160 proto_tree_add_item(userlog_log
, hf_userlog_SrcNatIP
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
162 proto_tree_add_item(userlog_log
, hf_userlog_DestIP
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
164 proto_tree_add_item(userlog_log
, hf_userlog_DestNatIP
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
166 proto_tree_add_item(userlog_log
, hf_userlog_SrcPort
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
168 proto_tree_add_item(userlog_log
, hf_userlog_SrcNatPort
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
170 proto_tree_add_item(userlog_log
, hf_userlog_DestPort
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
172 proto_tree_add_item(userlog_log
, hf_userlog_DestNatPort
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
174 proto_tree_add_item(userlog_log
, hf_userlog_StartTime
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
176 proto_tree_add_item(userlog_log
, hf_userlog_EndTime
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
178 proto_tree_add_item(userlog_log
, hf_userlog_InTotalPkg
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
180 proto_tree_add_item(userlog_log
, hf_userlog_InTotalByte
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
182 proto_tree_add_item(userlog_log
, hf_userlog_OutTotalPkg
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
184 proto_tree_add_item(userlog_log
, hf_userlog_OutTotalByte
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
186 proto_tree_add_item(userlog_log
, hf_userlog_Reserved1
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
188 proto_tree_add_item(userlog_log
, hf_userlog_Reserved2
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
190 proto_tree_add_item(userlog_log
, hf_userlog_Reserved3
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
198 return tvb_captured_length(tvb
);
202 proto_register_userlog(void)
204 static hf_register_info hf
[] = {
205 { &hf_userlog_version
,
206 { "Version", "userlog.version",
212 { &hf_userlog_logtype
,
213 { "LogType", "userlog.logtype",
220 { "LogCount", "userlog.count",
226 { &hf_userlog_timestamp
,
227 { "TimeStamp", "userlog.timestamp",
228 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
,
233 { &hf_userlog_header_reserved
,
234 { "Reserved", "userlog.reserved",
241 { "Protocol", "userlog.proto",
242 FT_UINT8
, BASE_DEC
|BASE_EXT_STRING
,
243 &ipproto_val_ext
, 0x0,
247 { &hf_userlog_Operator
,
248 { "Operator", "userlog.Operator",
254 { &hf_userlog_IPVerion
,
255 { "IP Version", "userlog.IPVersion",
262 { "IP ToS", "userlog.IPToS",
268 { &hf_userlog_SourceIP
,
269 { "Source-IP", "userlog.SourceIP",
275 { &hf_userlog_SrcNatIP
,
276 { "Source-NAT-IP", "userlog.Source-NAT-IP",
282 { &hf_userlog_DestIP
,
283 { "Destination-IP", "userlog.Destination-IP",
289 { &hf_userlog_DestNatIP
,
290 { "Destination-NAT-IP", "userlog.Destination-NAT-IP",
296 { &hf_userlog_SrcPort
,
297 { "Source-Port", "userlog.Source-Port",
303 { &hf_userlog_SrcNatPort
,
304 { "Source-NAT-Port", "userlog.Source-NAT-Port",
310 { &hf_userlog_DestPort
,
311 { "Destination-Port", "userlog.Destination-Port",
317 { &hf_userlog_DestNatPort
,
318 { "Destination-NAT-Port", "userlog.Destination-NAT-Port",
324 { &hf_userlog_StartTime
,
325 { "StartTime", "userlog.StartTime",
326 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
,
331 { &hf_userlog_EndTime
,
332 { "EndTime", "userlog.EndTime",
333 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
,
338 { &hf_userlog_InTotalPkg
,
339 { "InTotalPkg", "userlog.InTotalPkg",
345 { &hf_userlog_InTotalByte
,
346 { "InTotalByte", "userlog.InTotalByte",
352 { &hf_userlog_OutTotalPkg
,
353 { "OutTotalPkg", "userlog.OutTotalPkg",
359 { &hf_userlog_OutTotalByte
,
360 { "OutTotalByte", "userlog.OutTotalByte",
366 { &hf_userlog_Reserved1
,
367 { "Reserved1", "userlog.Reserved1",
373 { &hf_userlog_Reserved2
,
374 { "Reserved2", "userlog.Reserved2",
380 { &hf_userlog_Reserved3
,
381 { "Reserved3", "userlog.Reserved3",
389 /* Setup protocol subtree array */
390 static int *ett
[] = {
396 proto_userlog
= proto_register_protocol("UserLog Protocol", "UserLog", "userlog");
397 proto_register_field_array(proto_userlog
, hf
, array_length(hf
));
398 proto_register_subtree_array(ett
, array_length(ett
));
399 userlog_handle
= register_dissector("userlog", dissect_userlog
, proto_userlog
);
403 proto_reg_handoff_userlog(void)
405 dissector_add_for_decode_as_with_preference("udp.port", userlog_handle
);
410 * Editor modelines - https://www.wireshark.org/tools/modelines.html
415 * indent-tabs-mode: t
418 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
419 * :indentSize=8:tabSize=8:noTabs=false: