2 * Routines for "Linux pktgen" dissection
4 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * The linux packet generator is a tool to generate packets at very high speed in the kernel.
29 * See linux/net/core/pktgen.c and linux/Documentation/networking/pktgen.txt for more info.
36 #include <epan/packet.h>
38 /* magic num used for heuristic */
39 static const guint8 pktgen_magic[] = { 0xbe, 0x9b, 0xe9, 0x55 };
41 /* Initialize the protocol and registered fields */
42 static int proto_pktgen = -1;
45 static int hf_pktgen_magic = -1;
46 static int hf_pktgen_seqnum = -1;
47 static int hf_pktgen_tvsec = -1;
48 static int hf_pktgen_tvusec = -1;
49 static int hf_pktgen_timestamp = -1;
51 /* Initialize the subtree pointer */
52 static gint ett_pktgen = -1;
54 /* data dissector handle */
55 static dissector_handle_t data_handle;
58 static gboolean dissect_pktgen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
60 proto_item *ti = NULL;
61 proto_item *tmp = NULL;
62 proto_tree *pktgen_tree = NULL;
66 /* check for min size */
67 if(tvb_length(tvb) < 16) { /* Not a PKTGEN packet. */
71 /* check for magic number */
72 if(tvb_memeql(tvb, 0, pktgen_magic, 4) == -1) { /* Not a PKTGEN packet. */
76 /* Make entries in Protocol column and Info column on summary display */
78 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PKTGEN");
80 if(check_col(pinfo->cinfo, COL_INFO)) {
81 col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 4));
86 /* create display subtree for the protocol */
88 ti = proto_tree_add_item(tree, proto_pktgen, tvb, 0, -1, ENC_NA);
90 pktgen_tree = proto_item_add_subtree(ti, ett_pktgen);
92 /* add items to the subtree */
94 proto_tree_add_item(pktgen_tree, hf_pktgen_magic, tvb, offset, 4, ENC_BIG_ENDIAN);
97 proto_tree_add_item(pktgen_tree, hf_pktgen_seqnum, tvb, offset, 4, ENC_BIG_ENDIAN);
100 tstamp.secs = tvb_get_ntohl(tvb, offset);
101 tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvsec, tvb, offset, 4, ENC_BIG_ENDIAN);
102 PROTO_ITEM_SET_GENERATED(tmp);
105 tstamp.nsecs = tvb_get_ntohl(tvb, offset) /* microsecond on the wire so... */ * 1000;
106 tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvusec, tvb, offset, 4, ENC_BIG_ENDIAN);
107 PROTO_ITEM_SET_GENERATED(tmp);
110 proto_tree_add_time(pktgen_tree, hf_pktgen_timestamp, tvb, offset - 8, 8, &tstamp);
113 if(tvb_length_remaining(tvb, offset)) /* random data */
114 proto_tree_add_text(pktgen_tree, tvb, offset, -1, "Data (%u bytes)",
115 tvb_length_remaining(tvb, offset));
117 if(tvb_length_remaining(tvb, offset)) /* random data */
118 call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo,
127 /* Register the protocol with Wireshark */
128 void proto_register_pktgen(void)
130 /* Setup list of header fields */
132 static hf_register_info hf[] = {
136 "Magic number", "pktgen.magic",
137 FT_UINT32, BASE_HEX, NULL, 0x0,
138 "The pktgen magic number", HFILL
144 "Sequence number", "pktgen.seqnum",
145 FT_UINT32, BASE_DEC, NULL, 0x0,
152 "Timestamp tvsec", "pktgen.tvsec",
153 FT_UINT32, BASE_DEC, NULL, 0x0,
154 "Timestamp tvsec part", HFILL
160 "Timestamp tvusec", "pktgen.tvusec",
161 FT_UINT32, BASE_DEC, NULL, 0x0,
162 "Timestamp tvusec part", HFILL
166 { &hf_pktgen_timestamp,
168 "Timestamp", "pktgen.timestamp",
169 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
175 /* Setup protocol subtree array */
177 static gint *ett[] = {
181 /* Register the protocol name and description */
183 proto_pktgen = proto_register_protocol("Linux Kernel Packet Generator", "PKTGEN", "pktgen");
185 /* Required function calls to register the header fields and subtrees used */
187 proto_register_field_array(proto_pktgen, hf, array_length(hf));
188 proto_register_subtree_array(ett, array_length(ett));
192 void proto_reg_handoff_pktgen(void)
194 /* Register as a heuristic UDP dissector */
195 heur_dissector_add("udp", dissect_pktgen, proto_pktgen);
197 /* Find data dissector handle */
198 data_handle = find_dissector("data");