2 * Routines for "Linux pktgen" dissection
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
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.
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
;
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
;
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
;
51 /* check for min size */
52 if (tvb_reported_length(tvb
) < 16) { /* Not a PKTGEN packet. */
56 /* check for magic number */
57 magic
= tvb_get_ntohl(tvb
,0);
58 if (magic
!= PKTGEN_MAGIC
) {
59 /* Not a PKTGEN packet. */
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));
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
);
83 proto_tree_add_item(pktgen_tree
, hf_pktgen_seqnum
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
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
);
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
);
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
,
107 /* Register the protocol with Wireshark */
108 void proto_register_pktgen(void)
110 /* Setup list of header fields */
112 static hf_register_info hf
[] = {
116 "Magic number", "pktgen.magic",
117 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
118 "The pktgen magic number", HFILL
124 "Sequence number", "pktgen.seqnum",
125 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
132 "Timestamp tvsec", "pktgen.tvsec",
133 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
134 "Timestamp tvsec part", HFILL
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,
155 /* Setup protocol subtree array */
157 static int *ett
[] = {
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
185 * indent-tabs-mode: nil
188 * vi: set shiftwidth=4 tabstop=8 expandtab:
189 * :indentSize=4:tabSize=8:noTabs=true: