Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-pktgen.c
bloba56914908eb4c46f1e4619f6d195fe1099c64d1b
1 /* packet-pktgen.c
2 * Routines for "Linux pktgen" dissection
3 * Copyright 2006 _FF_
4 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 /* FF:
14 * The linux packet generator is a tool to generate packets at very high speed in the kernel.
15 * See linux/net/core/pktgen.c and linux/Documentation/networking/pktgen.txt for more info.
18 #include "config.h"
20 #include <epan/packet.h>
22 void proto_register_pktgen(void);
23 void proto_reg_handoff_pktgen(void);
25 /* magic num used for heuristic */
26 #define PKTGEN_MAGIC 0xbe9be955
28 /* Initialize the protocol and registered fields */
29 static int proto_pktgen;
31 /* pktgen header */
32 static int hf_pktgen_magic;
33 static int hf_pktgen_seqnum;
34 static int hf_pktgen_tvsec;
35 static int hf_pktgen_tvusec;
36 static int hf_pktgen_timestamp;
38 /* Initialize the subtree pointer */
39 static int ett_pktgen;
41 /* entry point */
42 static bool dissect_pktgen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
44 proto_item *ti = NULL;
45 proto_item *tmp = NULL;
46 proto_tree *pktgen_tree = NULL;
47 uint32_t offset = 0;
48 nstime_t tstamp;
49 uint32_t magic;
51 /* check for min size */
52 if (tvb_reported_length(tvb) < 16) { /* Not a PKTGEN packet. */
53 return false;
56 /* check for magic number */
57 magic = tvb_get_ntohl(tvb,0);
58 if (magic != PKTGEN_MAGIC) {
59 /* Not a PKTGEN packet. */
60 return false;
64 /* Make entries in Protocol column and Info column on summary display */
66 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PKTGEN");
68 col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 4));
70 if (tree) {
72 /* create display subtree for the protocol */
74 ti = proto_tree_add_item(tree, proto_pktgen, tvb, 0, -1, ENC_NA);
76 pktgen_tree = proto_item_add_subtree(ti, ett_pktgen);
78 /* add items to the subtree */
80 proto_tree_add_item(pktgen_tree, hf_pktgen_magic, tvb, offset, 4, ENC_BIG_ENDIAN);
81 offset += 4;
83 proto_tree_add_item(pktgen_tree, hf_pktgen_seqnum, tvb, offset, 4, ENC_BIG_ENDIAN);
84 offset += 4;
86 tstamp.secs = tvb_get_ntohl(tvb, offset);
87 tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvsec, tvb, offset, 4, ENC_BIG_ENDIAN);
88 proto_item_set_generated(tmp);
89 offset += 4;
91 tstamp.nsecs = tvb_get_ntohl(tvb, offset) /* microsecond on the wire so... */ * 1000;
92 tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvusec, tvb, offset, 4, ENC_BIG_ENDIAN);
93 proto_item_set_generated(tmp);
94 offset += 4;
96 proto_tree_add_time(pktgen_tree, hf_pktgen_timestamp, tvb, offset - 8, 8, &tstamp);
98 if (tvb_reported_length_remaining(tvb, offset)) /* random data */
99 call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo,
100 pktgen_tree);
103 return true;
107 /* Register the protocol with Wireshark */
108 void proto_register_pktgen(void)
110 /* Setup list of header fields */
112 static hf_register_info hf[] = {
114 { &hf_pktgen_magic,
116 "Magic number", "pktgen.magic",
117 FT_UINT32, BASE_HEX, NULL, 0x0,
118 "The pktgen magic number", HFILL
122 { &hf_pktgen_seqnum,
124 "Sequence number", "pktgen.seqnum",
125 FT_UINT32, BASE_DEC, NULL, 0x0,
126 NULL, HFILL
130 { &hf_pktgen_tvsec,
132 "Timestamp tvsec", "pktgen.tvsec",
133 FT_UINT32, BASE_DEC, NULL, 0x0,
134 "Timestamp tvsec part", HFILL
138 { &hf_pktgen_tvusec,
140 "Timestamp tvusec", "pktgen.tvusec",
141 FT_UINT32, BASE_DEC, NULL, 0x0,
142 "Timestamp tvusec part", HFILL
146 { &hf_pktgen_timestamp,
148 "Timestamp", "pktgen.timestamp",
149 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
150 NULL, HFILL
155 /* Setup protocol subtree array */
157 static int *ett[] = {
158 &ett_pktgen
161 /* Register the protocol name and description */
163 proto_pktgen = proto_register_protocol("Linux Kernel Packet Generator", "PKTGEN", "pktgen");
165 /* Required function calls to register the header fields and subtrees used */
167 proto_register_field_array(proto_pktgen, hf, array_length(hf));
168 proto_register_subtree_array(ett, array_length(ett));
172 void proto_reg_handoff_pktgen(void)
174 /* Register as a heuristic UDP dissector */
175 heur_dissector_add("udp", dissect_pktgen, "Linux Kernel Packet Generator over UDP", "pktgen_udp", proto_pktgen, HEURISTIC_ENABLE);
180 * Editor modelines - https://www.wireshark.org/tools/modelines.html
182 * Local variables:
183 * c-basic-offset: 4
184 * tab-width: 8
185 * indent-tabs-mode: nil
186 * End:
188 * vi: set shiftwidth=4 tabstop=8 expandtab:
189 * :indentSize=4:tabSize=8:noTabs=true: