2006-09-18 09:27:47 +00:00
|
|
|
/* packet-pktgen.c
|
|
|
|
* Routines for "Linux pktgen" dissection
|
2011-09-21 23:42:55 +00:00
|
|
|
* Copyright 2006 _FF_
|
2006-09-18 09:27:47 +00:00
|
|
|
* Francesco Fondelli <francesco dot fondelli, gmail dot com>
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
2011-09-21 23:42:55 +00:00
|
|
|
*
|
2006-09-18 09:27:47 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2011-09-21 23:42:55 +00:00
|
|
|
*
|
2006-09-18 09:27:47 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-09-21 23:42:55 +00:00
|
|
|
*
|
2006-09-18 09:27:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* FF:
|
|
|
|
* The linux packet generator is a tool to generate packets at very high speed in the kernel.
|
|
|
|
* See linux/net/core/pktgen.c and linux/Documentation/networking/pktgen.txt for more info.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
|
|
|
|
/* magic num used for heuristic */
|
|
|
|
static const guint8 pktgen_magic[] = { 0xbe, 0x9b, 0xe9, 0x55 };
|
|
|
|
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_pktgen = -1;
|
|
|
|
|
|
|
|
/* pktgen header */
|
|
|
|
static int hf_pktgen_magic = -1;
|
|
|
|
static int hf_pktgen_seqnum = -1;
|
|
|
|
static int hf_pktgen_tvsec = -1;
|
|
|
|
static int hf_pktgen_tvusec = -1;
|
|
|
|
static int hf_pktgen_timestamp = -1;
|
|
|
|
|
|
|
|
/* Initialize the subtree pointer */
|
|
|
|
static gint ett_pktgen = -1;
|
|
|
|
|
|
|
|
/* data dissector handle */
|
2008-09-26 17:04:01 +00:00
|
|
|
static dissector_handle_t data_handle;
|
2006-09-18 09:27:47 +00:00
|
|
|
|
|
|
|
/* entry point */
|
|
|
|
static gboolean dissect_pktgen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_item *ti = NULL;
|
|
|
|
proto_item *tmp = NULL;
|
|
|
|
proto_tree *pktgen_tree = NULL;
|
|
|
|
guint32 offset = 0;
|
|
|
|
nstime_t tstamp;
|
|
|
|
|
|
|
|
/* check for min size */
|
2007-11-09 06:01:18 +00:00
|
|
|
if(tvb_length(tvb) < 16) { /* Not a PKTGEN packet. */
|
2006-09-18 09:27:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* check for magic number */
|
|
|
|
if(tvb_memeql(tvb, 0, pktgen_magic, 4) == -1) { /* Not a PKTGEN packet. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* Make entries in Protocol column and Info column on summary display */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PKTGEN");
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
if(check_col(pinfo->cinfo, COL_INFO)) {
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 4));
|
|
|
|
}
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
if(tree) {
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* create display subtree for the protocol */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2011-10-21 02:10:19 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_pktgen, tvb, 0, -1, ENC_NA);
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
pktgen_tree = proto_item_add_subtree(ti, ett_pktgen);
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* add items to the subtree */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(pktgen_tree, hf_pktgen_magic, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2006-09-18 09:27:47 +00:00
|
|
|
offset+=4;
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(pktgen_tree, hf_pktgen_seqnum, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2006-09-18 09:27:47 +00:00
|
|
|
offset+=4;
|
|
|
|
|
|
|
|
tstamp.secs = tvb_get_ntohl(tvb, offset);
|
2011-10-06 03:35:44 +00:00
|
|
|
tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvsec, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2006-09-18 09:27:47 +00:00
|
|
|
PROTO_ITEM_SET_GENERATED(tmp);
|
|
|
|
offset+=4;
|
|
|
|
|
|
|
|
tstamp.nsecs = tvb_get_ntohl(tvb, offset) /* microsecond on the wire so... */ * 1000;
|
2011-10-06 03:35:44 +00:00
|
|
|
tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvusec, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2006-09-18 09:27:47 +00:00
|
|
|
PROTO_ITEM_SET_GENERATED(tmp);
|
|
|
|
offset+=4;
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
proto_tree_add_time(pktgen_tree, hf_pktgen_timestamp, tvb, offset - 8, 8, &tstamp);
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
#if 0
|
|
|
|
if(tvb_length_remaining(tvb, offset)) /* random data */
|
|
|
|
proto_tree_add_text(pktgen_tree, tvb, offset, -1, "Data (%u bytes)",
|
|
|
|
tvb_length_remaining(tvb, offset));
|
|
|
|
#else
|
|
|
|
if(tvb_length_remaining(tvb, offset)) /* random data */
|
2009-08-16 12:36:22 +00:00
|
|
|
call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo,
|
2006-09-18 09:27:47 +00:00
|
|
|
pktgen_tree);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Register the protocol with Wireshark */
|
|
|
|
void proto_register_pktgen(void)
|
2011-09-21 23:42:55 +00:00
|
|
|
{
|
2006-09-18 09:27:47 +00:00
|
|
|
/* Setup list of header fields */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
static hf_register_info hf[] = {
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
{ &hf_pktgen_magic,
|
2011-09-21 23:42:55 +00:00
|
|
|
{
|
|
|
|
"Magic number", "pktgen.magic",
|
|
|
|
FT_UINT32, BASE_HEX, NULL, 0x0,
|
2006-09-18 09:27:47 +00:00
|
|
|
"The pktgen magic number", HFILL
|
|
|
|
}
|
|
|
|
},
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
{ &hf_pktgen_seqnum,
|
2011-09-21 23:42:55 +00:00
|
|
|
{
|
|
|
|
"Sequence number", "pktgen.seqnum",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL
|
2006-09-18 09:27:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_pktgen_tvsec,
|
2011-09-21 23:42:55 +00:00
|
|
|
{
|
|
|
|
"Timestamp tvsec", "pktgen.tvsec",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2006-09-18 09:27:47 +00:00
|
|
|
"Timestamp tvsec part", HFILL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_pktgen_tvusec,
|
2011-09-21 23:42:55 +00:00
|
|
|
{
|
|
|
|
"Timestamp tvusec", "pktgen.tvusec",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2006-09-18 09:27:47 +00:00
|
|
|
"Timestamp tvusec part", HFILL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_pktgen_timestamp,
|
2011-09-21 23:42:55 +00:00
|
|
|
{
|
|
|
|
"Timestamp", "pktgen.timestamp",
|
2009-12-19 03:17:44 +00:00
|
|
|
FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL
|
2006-09-18 09:27:47 +00:00
|
|
|
}
|
2011-09-21 23:42:55 +00:00
|
|
|
}
|
2006-09-18 09:27:47 +00:00
|
|
|
};
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* Setup protocol subtree array */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_pktgen
|
|
|
|
};
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* Register the protocol name and description */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
proto_pktgen = proto_register_protocol("Linux Kernel Packet Generator", "PKTGEN", "pktgen");
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
/* Required function calls to register the header fields and subtrees used */
|
2011-09-21 23:42:55 +00:00
|
|
|
|
2006-09-18 09:27:47 +00:00
|
|
|
proto_register_field_array(proto_pktgen, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void proto_reg_handoff_pktgen(void)
|
|
|
|
{
|
|
|
|
/* Register as a heuristic UDP dissector */
|
|
|
|
heur_dissector_add("udp", dissect_pktgen, proto_pktgen);
|
|
|
|
|
|
|
|
/* Find data dissector handle */
|
|
|
|
data_handle = find_dissector("data");
|
|
|
|
}
|