1999-02-15 06:36:57 +00:00
|
|
|
/* packet-tftp.c
|
|
|
|
* Routines for tftp packet dissection
|
|
|
|
*
|
|
|
|
* Richard Sharpe <rsharpe@ns.aus.com>
|
2000-01-27 07:09:45 +00:00
|
|
|
* Craig Newell <CraigN@cheque.uq.edu.au>
|
2011-01-31 21:23:49 +00:00
|
|
|
* RFC2347 TFTP Option Extension
|
2006-09-06 08:24:36 +00:00
|
|
|
* Joerg Mayer (see AUTHORS file)
|
|
|
|
* RFC2348 TFTP Blocksize Option
|
1999-02-15 06:36:57 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1999-02-15 06:36:57 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
1999-02-15 06:36:57 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-bootp.c
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-02-15 06:36:57 +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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-02-15 06:36:57 +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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-02-15 06:36:57 +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.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 08:24:36 +00:00
|
|
|
/* Documentation:
|
|
|
|
* RFC 1350: THE TFTP PROTOCOL (REVISION 2)
|
|
|
|
* RFC 2090: TFTP Multicast Option
|
|
|
|
* (not yet implemented)
|
|
|
|
* RFC 2347: TFTP Option Extension
|
|
|
|
* RFC 2348: TFTP Blocksize Option
|
|
|
|
* RFC 2349: TFTP Timeout Interval and Transfer Size Options
|
|
|
|
* (not yet implemented)
|
|
|
|
*/
|
|
|
|
|
1999-02-15 06:36:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <glib.h>
|
2009-08-26 19:27:49 +00:00
|
|
|
#include <stdlib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/conversation.h>
|
2006-09-05 15:58:11 +00:00
|
|
|
#include <epan/emem.h>
|
|
|
|
#include <epan/expert.h>
|
2009-06-03 09:57:22 +00:00
|
|
|
#include <epan/range.h>
|
|
|
|
#include <epan/prefs.h>
|
2006-09-05 15:58:11 +00:00
|
|
|
|
|
|
|
/* Things we may want to remember for a whole conversation */
|
|
|
|
typedef struct _tftp_conv_info_t {
|
|
|
|
guint16 blocksize;
|
2009-03-27 19:45:46 +00:00
|
|
|
gchar *source_file, *destination_file;
|
2006-09-05 15:58:11 +00:00
|
|
|
} tftp_conv_info_t;
|
|
|
|
|
1999-02-15 06:36:57 +00:00
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
static int proto_tftp = -1;
|
2000-11-10 09:17:10 +00:00
|
|
|
static int hf_tftp_opcode = -1;
|
|
|
|
static int hf_tftp_source_file = -1;
|
|
|
|
static int hf_tftp_destination_file = -1;
|
|
|
|
static int hf_tftp_transfer_type = -1;
|
|
|
|
static int hf_tftp_blocknum = -1;
|
1999-11-14 10:32:26 +00:00
|
|
|
static int hf_tftp_error_code = -1;
|
2000-11-10 09:17:10 +00:00
|
|
|
static int hf_tftp_error_string = -1;
|
2006-09-06 08:24:36 +00:00
|
|
|
static int hf_tftp_option_name = -1;
|
|
|
|
static int hf_tftp_option_value = -1;
|
1999-07-29 05:47:07 +00:00
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_tftp = -1;
|
2006-09-06 08:24:36 +00:00
|
|
|
static gint ett_tftp_option = -1;
|
1999-11-16 11:44:20 +00:00
|
|
|
|
2001-11-27 07:13:32 +00:00
|
|
|
static dissector_handle_t tftp_handle;
|
2011-01-31 21:23:49 +00:00
|
|
|
static dissector_handle_t data_handle;
|
2001-11-26 05:13:14 +00:00
|
|
|
|
2009-06-03 09:57:22 +00:00
|
|
|
#define UDP_PORT_TFTP_RANGE "69"
|
|
|
|
|
|
|
|
void proto_reg_handoff_tftp (void);
|
|
|
|
|
|
|
|
/* User definable values */
|
|
|
|
static range_t *global_tftp_port_range;
|
2000-10-21 09:54:12 +00:00
|
|
|
|
2001-02-09 06:08:11 +00:00
|
|
|
#define TFTP_RRQ 1
|
|
|
|
#define TFTP_WRQ 2
|
|
|
|
#define TFTP_DATA 3
|
|
|
|
#define TFTP_ACK 4
|
|
|
|
#define TFTP_ERROR 5
|
|
|
|
#define TFTP_OACK 6
|
2008-06-21 10:04:27 +00:00
|
|
|
#define TFTP_INFO 255
|
1999-05-13 05:46:04 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
static const value_string tftp_opcode_vals[] = {
|
2001-02-09 06:08:11 +00:00
|
|
|
{ TFTP_RRQ, "Read Request" },
|
|
|
|
{ TFTP_WRQ, "Write Request" },
|
|
|
|
{ TFTP_DATA, "Data Packet" },
|
|
|
|
{ TFTP_ACK, "Acknowledgement" },
|
|
|
|
{ TFTP_ERROR, "Error Code" },
|
|
|
|
{ TFTP_OACK, "Option Acknowledgement" },
|
2008-06-21 10:04:27 +00:00
|
|
|
{ TFTP_INFO, "Information (MSDP)" },
|
2001-02-09 06:08:11 +00:00
|
|
|
{ 0, NULL }
|
1999-02-15 06:36:57 +00:00
|
|
|
};
|
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
static const value_string tftp_error_code_vals[] = {
|
|
|
|
{ 0, "Not defined" },
|
|
|
|
{ 1, "File not found" },
|
|
|
|
{ 2, "Access violation" },
|
|
|
|
{ 3, "Disk full or allocation exceeded" },
|
|
|
|
{ 4, "Illegal TFTP Operation" },
|
2006-09-06 08:24:36 +00:00
|
|
|
{ 5, "Unknown transfer ID" }, /* Does not cause termination */
|
2000-11-10 09:17:10 +00:00
|
|
|
{ 6, "File already exists" },
|
|
|
|
{ 7, "No such user" },
|
2002-06-13 08:48:44 +00:00
|
|
|
{ 8, "Option negotiation failed" },
|
2000-11-10 09:17:10 +00:00
|
|
|
{ 0, NULL }
|
1999-02-15 06:36:57 +00:00
|
|
|
};
|
|
|
|
|
2006-09-06 08:24:36 +00:00
|
|
|
static void
|
|
|
|
tftp_dissect_options(tvbuff_t *tvb, packet_info *pinfo, int offset,
|
|
|
|
proto_tree *tree, guint16 opcode, tftp_conv_info_t *tftp_info)
|
|
|
|
{
|
|
|
|
int option_len, value_len;
|
|
|
|
int value_offset;
|
2008-07-11 20:15:52 +00:00
|
|
|
const char *optionname;
|
|
|
|
const char *optionvalue;
|
2006-09-06 08:24:36 +00:00
|
|
|
proto_item *opt_item;
|
|
|
|
proto_tree *opt_tree;
|
|
|
|
|
|
|
|
while (tvb_offset_exists(tvb, offset)) {
|
|
|
|
option_len = tvb_strsize(tvb, offset); /* length of option */
|
|
|
|
value_offset = offset + option_len;
|
|
|
|
value_len = tvb_strsize(tvb, value_offset); /* length of value */
|
2008-02-16 01:33:48 +00:00
|
|
|
optionname = tvb_format_text(tvb, offset, option_len);
|
|
|
|
optionvalue = tvb_format_text(tvb, value_offset, value_len);
|
2006-09-06 08:24:36 +00:00
|
|
|
opt_item = proto_tree_add_text(tree, tvb, offset, option_len+value_len,
|
|
|
|
"Option: %s = %s", optionname, optionvalue);
|
|
|
|
|
|
|
|
opt_tree = proto_item_add_subtree(opt_item, ett_tftp_option);
|
|
|
|
proto_tree_add_item(opt_tree, hf_tftp_option_name, tvb, offset,
|
2011-10-15 18:46:26 +00:00
|
|
|
option_len, ENC_ASCII|ENC_NA);
|
2006-09-06 08:24:36 +00:00
|
|
|
proto_tree_add_item(opt_tree, hf_tftp_option_value, tvb, value_offset,
|
2011-10-15 18:46:26 +00:00
|
|
|
value_len, ENC_ASCII|ENC_NA);
|
2006-09-06 08:24:36 +00:00
|
|
|
|
|
|
|
offset += option_len + value_len;
|
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", %s=%s",
|
|
|
|
optionname, optionvalue);
|
2006-09-06 08:24:36 +00:00
|
|
|
|
|
|
|
/* Special code to handle individual options */
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
if (!g_ascii_strcasecmp((const char *)optionname, "blksize") &&
|
2006-09-06 08:24:36 +00:00
|
|
|
opcode == TFTP_OACK) {
|
|
|
|
gint blocksize = strtol((const char *)optionvalue, NULL, 10);
|
|
|
|
if (blocksize < 8 || blocksize > 65464) {
|
|
|
|
expert_add_info_format(pinfo, NULL, PI_RESPONSE_CODE,
|
|
|
|
PI_WARN, "TFTP blocksize out of range");
|
|
|
|
} else {
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_info->blocksize = blocksize;
|
2006-09-06 08:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2008-08-01 15:11:06 +00:00
|
|
|
static void dissect_tftp_message(tftp_conv_info_t *tftp_info,
|
2010-05-13 18:28:34 +00:00
|
|
|
tvbuff_t *tvb, packet_info *pinfo,
|
2008-08-01 15:11:06 +00:00
|
|
|
proto_tree *tree)
|
1999-02-15 06:36:57 +00:00
|
|
|
{
|
2006-09-05 15:58:11 +00:00
|
|
|
proto_tree *tftp_tree = NULL;
|
|
|
|
proto_item *ti;
|
|
|
|
gint offset = 0;
|
|
|
|
guint16 opcode;
|
|
|
|
guint16 bytes;
|
|
|
|
guint16 blocknum;
|
2011-01-31 21:23:49 +00:00
|
|
|
guint i1;
|
2006-09-05 15:58:11 +00:00
|
|
|
guint16 error;
|
2000-10-21 09:54:12 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TFTP");
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
opcode = tvb_get_ntohs(tvb, offset);
|
1999-02-15 06:36:57 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
col_add_str(pinfo->cinfo, COL_INFO,
|
|
|
|
val_to_str(opcode, tftp_opcode_vals, "Unknown (0x%04x)"));
|
1999-02-15 06:36:57 +00:00
|
|
|
|
|
|
|
if (tree) {
|
2011-10-21 02:10:19 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_tftp, tvb, offset, -1, ENC_NA);
|
1999-11-16 11:44:20 +00:00
|
|
|
tftp_tree = proto_item_add_subtree(ti, ett_tftp);
|
1999-02-15 06:36:57 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
if (tftp_info->source_file) {
|
2009-03-27 19:45:46 +00:00
|
|
|
ti = proto_tree_add_string(tftp_tree, hf_tftp_source_file, tvb,
|
|
|
|
0, 0, tftp_info->source_file);
|
|
|
|
PROTO_ITEM_SET_GENERATED(ti);
|
|
|
|
}
|
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
if (tftp_info->destination_file) {
|
2009-03-27 19:45:46 +00:00
|
|
|
ti = proto_tree_add_string(tftp_tree, hf_tftp_destination_file, tvb,
|
|
|
|
0, 0, tftp_info->destination_file);
|
|
|
|
PROTO_ITEM_SET_GENERATED(ti);
|
|
|
|
}
|
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
proto_tree_add_uint(tftp_tree, hf_tftp_opcode, tvb,
|
2011-01-31 21:23:49 +00:00
|
|
|
offset, 2, opcode);
|
2001-11-03 02:19:10 +00:00
|
|
|
}
|
|
|
|
offset += 2;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
switch (opcode) {
|
|
|
|
|
|
|
|
case TFTP_RRQ:
|
|
|
|
i1 = tvb_strsize(tvb, offset);
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_source_file,
|
2011-10-15 18:46:26 +00:00
|
|
|
tvb, offset, i1, ENC_ASCII|ENC_NA);
|
2009-03-27 19:45:46 +00:00
|
|
|
|
|
|
|
tftp_info->source_file = tvb_get_seasonal_string(tvb, offset, i1);
|
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", File: %s",
|
|
|
|
tvb_format_stringzpad(tvb, offset, i1));
|
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
offset += i1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
i1 = tvb_strsize(tvb, offset);
|
2011-08-08 19:27:14 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_transfer_type,
|
2011-10-15 18:46:26 +00:00
|
|
|
tvb, offset, i1, ENC_ASCII|ENC_NA);
|
2011-01-31 21:23:49 +00:00
|
|
|
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Transfer type: %s",
|
|
|
|
tvb_format_stringzpad(tvb, offset, i1));
|
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
offset += i1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_dissect_options(tvb, pinfo, offset, tftp_tree,
|
|
|
|
opcode, tftp_info);
|
2001-11-03 02:19:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TFTP_WRQ:
|
|
|
|
i1 = tvb_strsize(tvb, offset);
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_destination_file,
|
2011-10-15 18:46:26 +00:00
|
|
|
tvb, offset, i1, ENC_ASCII|ENC_NA);
|
2009-03-27 19:45:46 +00:00
|
|
|
|
|
|
|
tftp_info->destination_file =
|
2011-01-31 21:23:49 +00:00
|
|
|
tvb_get_seasonal_string(tvb, offset, i1);
|
|
|
|
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", File: %s",
|
|
|
|
tvb_format_stringzpad(tvb, offset, i1));
|
2009-03-27 19:45:46 +00:00
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
offset += i1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
i1 = tvb_strsize(tvb, offset);
|
2011-04-06 00:07:52 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_transfer_type,
|
2011-10-15 18:46:26 +00:00
|
|
|
tvb, offset, i1, ENC_ASCII|ENC_NA);
|
2011-01-31 21:23:49 +00:00
|
|
|
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Transfer type: %s",
|
|
|
|
tvb_format_stringzpad(tvb, offset, i1));
|
2009-03-27 19:45:46 +00:00
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
offset += i1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_dissect_options(tvb, pinfo, offset, tftp_tree,
|
|
|
|
opcode, tftp_info);
|
2001-11-03 02:19:10 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-21 10:04:27 +00:00
|
|
|
case TFTP_INFO:
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_dissect_options(tvb, pinfo, offset, tftp_tree,
|
|
|
|
opcode, tftp_info);
|
2008-06-21 10:04:27 +00:00
|
|
|
break;
|
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
case TFTP_DATA:
|
2002-05-24 22:50:55 +00:00
|
|
|
blocknum = tvb_get_ntohs(tvb, offset);
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_uint(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
|
|
|
|
blocknum);
|
|
|
|
|
2002-05-24 22:50:55 +00:00
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
bytes = tvb_reported_length_remaining(tvb, offset);
|
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Block: %i%s",
|
|
|
|
blocknum,
|
|
|
|
(bytes < tftp_info->blocksize)?" (last)":"" );
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2003-12-24 10:48:13 +00:00
|
|
|
if (bytes != 0) {
|
2011-01-31 21:23:49 +00:00
|
|
|
tvbuff_t *data_tvb = tvb_new_subset(tvb, offset, -1, bytes);
|
|
|
|
call_dissector(data_handle, data_tvb, pinfo, tree);
|
2001-11-03 02:19:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TFTP_ACK:
|
2002-05-24 22:50:55 +00:00
|
|
|
blocknum = tvb_get_ntohs(tvb, offset);
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_uint(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
|
|
|
|
blocknum);
|
|
|
|
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Block: %i",
|
|
|
|
blocknum);
|
2001-11-03 02:19:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TFTP_ERROR:
|
2001-11-03 02:25:26 +00:00
|
|
|
error = tvb_get_ntohs(tvb, offset);
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_uint(tftp_tree, hf_tftp_error_code, tvb, offset, 2,
|
|
|
|
error);
|
|
|
|
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Code: %s",
|
|
|
|
val_to_str(error, tftp_error_code_vals, "Unknown (%u)"));
|
|
|
|
|
2001-11-03 02:19:10 +00:00
|
|
|
offset += 2;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
2001-11-03 02:25:26 +00:00
|
|
|
i1 = tvb_strsize(tvb, offset);
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_error_string, tvb, offset,
|
2011-10-15 18:46:26 +00:00
|
|
|
i1, ENC_ASCII|ENC_NA);
|
2011-01-31 21:23:49 +00:00
|
|
|
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Message: %s",
|
|
|
|
tvb_format_stringzpad(tvb, offset, i1));
|
|
|
|
|
2006-09-06 08:24:36 +00:00
|
|
|
expert_add_info_format(pinfo, NULL, PI_RESPONSE_CODE,
|
2011-01-31 21:23:49 +00:00
|
|
|
PI_NOTE, "TFTP blocksize out of range");
|
2001-11-03 02:19:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TFTP_OACK:
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_dissect_options(tvb, pinfo, offset, tftp_tree,
|
|
|
|
opcode, tftp_info);
|
2001-11-03 02:19:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-01-31 21:23:49 +00:00
|
|
|
proto_tree_add_text(tftp_tree, tvb, offset, -1,
|
|
|
|
"Data (%d bytes)", tvb_reported_length_remaining(tvb, offset));
|
2001-11-03 02:19:10 +00:00
|
|
|
break;
|
1999-02-15 06:36:57 +00:00
|
|
|
|
|
|
|
}
|
2011-01-31 21:23:49 +00:00
|
|
|
|
2008-08-01 15:11:06 +00:00
|
|
|
return;
|
1999-02-15 06:36:57 +00:00
|
|
|
}
|
1999-07-29 05:47:07 +00:00
|
|
|
|
2008-08-01 15:11:06 +00:00
|
|
|
static gboolean
|
|
|
|
dissect_embeddedtftp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
/* Used to dissect TFTP packets where one can not assume
|
|
|
|
that the TFTP is the only protocol used by that port, and
|
|
|
|
that TFTP may not be carried by UDP */
|
|
|
|
conversation_t *conversation = NULL;
|
2011-01-31 21:23:49 +00:00
|
|
|
guint16 opcode;
|
2008-08-01 15:11:06 +00:00
|
|
|
tftp_conv_info_t *tftp_info;
|
|
|
|
|
2010-05-13 18:28:34 +00:00
|
|
|
conversation = find_or_create_conversation(pinfo);
|
2008-08-01 15:11:06 +00:00
|
|
|
|
|
|
|
tftp_info = conversation_get_proto_data(conversation, proto_tftp);
|
|
|
|
if (!tftp_info) {
|
|
|
|
tftp_info = se_alloc(sizeof(tftp_conv_info_t));
|
|
|
|
tftp_info->blocksize = 512; /* TFTP default block size */
|
2009-03-27 19:45:46 +00:00
|
|
|
tftp_info->source_file = NULL;
|
|
|
|
tftp_info->destination_file = NULL;
|
2008-08-01 15:11:06 +00:00
|
|
|
conversation_add_proto_data(conversation, proto_tftp, tftp_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
opcode = tvb_get_ntohs(tvb, 0);
|
|
|
|
|
|
|
|
if ((opcode == TFTP_RRQ) ||
|
|
|
|
(opcode == TFTP_WRQ) ||
|
|
|
|
(opcode == TFTP_DATA) ||
|
|
|
|
(opcode == TFTP_ACK) ||
|
|
|
|
(opcode == TFTP_ERROR) ||
|
|
|
|
(opcode == TFTP_INFO) ||
|
|
|
|
(opcode == TFTP_OACK)) {
|
|
|
|
dissect_tftp_message(tftp_info, tvb, pinfo, tree);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
conversation_t *conversation = NULL;
|
|
|
|
tftp_conv_info_t *tftp_info;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first TFTP packet goes to the TFTP port; the second one
|
|
|
|
* comes from some *other* port, but goes back to the same
|
|
|
|
* IP address and port as the ones from which the first packet
|
|
|
|
* came; all subsequent packets go between those two IP addresses
|
|
|
|
* and ports.
|
|
|
|
*
|
|
|
|
* If this packet went to the TFTP port, we check to see if
|
|
|
|
* there's already a conversation with one address/port pair
|
|
|
|
* matching the source IP address and port of this packet,
|
|
|
|
* the other address matching the destination IP address of this
|
|
|
|
* packet, and any destination port.
|
|
|
|
*
|
|
|
|
* If not, we create one, with its address 1/port 1 pair being
|
|
|
|
* the source address/port of this packet, its address 2 being
|
|
|
|
* the destination address of this packet, and its port 2 being
|
|
|
|
* wildcarded, and give it the TFTP dissector as a dissector.
|
|
|
|
*/
|
2009-06-03 09:57:22 +00:00
|
|
|
if (value_is_in_range(global_tftp_port_range, pinfo->destport)) {
|
2008-08-01 15:11:06 +00:00
|
|
|
conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
|
|
|
|
pinfo->srcport, 0, NO_PORT_B);
|
2011-12-19 17:59:34 +00:00
|
|
|
if( (conversation == NULL) || (conversation->dissector_handle != tftp_handle) ){
|
2008-08-01 15:11:06 +00:00
|
|
|
conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
|
|
|
|
pinfo->srcport, 0, NO_PORT2);
|
2011-12-19 17:59:34 +00:00
|
|
|
conversation_set_dissector(conversation, tftp_handle);
|
2008-08-01 15:11:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
|
2011-01-31 21:23:49 +00:00
|
|
|
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
|
2011-12-19 17:59:34 +00:00
|
|
|
if( (conversation == NULL) || (conversation->dissector_handle != tftp_handle) ){
|
2008-08-01 15:11:06 +00:00
|
|
|
conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
|
|
|
|
pinfo->destport, pinfo->srcport, 0);
|
2011-12-19 17:59:34 +00:00
|
|
|
conversation_set_dissector(conversation, tftp_handle);
|
|
|
|
} else if (conversation->options & NO_PORT_B) {
|
|
|
|
if (pinfo->destport == conversation->key_ptr->port1)
|
|
|
|
conversation_set_port2(conversation, pinfo->srcport);
|
|
|
|
else
|
|
|
|
return;
|
2008-08-01 15:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tftp_info = conversation_get_proto_data(conversation, proto_tftp);
|
|
|
|
if (!tftp_info) {
|
2009-03-27 19:45:46 +00:00
|
|
|
tftp_info = se_alloc(sizeof(tftp_conv_info_t));
|
|
|
|
tftp_info->blocksize = 512; /* TFTP default block size */
|
|
|
|
tftp_info->source_file = NULL;
|
|
|
|
tftp_info->destination_file = NULL;
|
|
|
|
conversation_add_proto_data(conversation, proto_tftp, tftp_info);
|
2008-08-01 15:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dissect_tftp_message(tftp_info, tvb, pinfo, tree);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
void
|
|
|
|
proto_register_tftp(void)
|
|
|
|
{
|
1999-11-14 10:32:26 +00:00
|
|
|
static hf_register_info hf[] = {
|
2000-11-10 09:17:10 +00:00
|
|
|
{ &hf_tftp_opcode,
|
|
|
|
{ "Opcode", "tftp.opcode",
|
|
|
|
FT_UINT16, BASE_DEC, VALS(tftp_opcode_vals), 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"TFTP message type", HFILL }},
|
1999-11-14 10:32:26 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
{ &hf_tftp_source_file,
|
|
|
|
{ "Source File", "tftp.source_file",
|
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
|
|
|
FT_STRINGZ, BASE_NONE, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"TFTP source file name", HFILL }},
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
{ &hf_tftp_destination_file,
|
|
|
|
{ "DESTINATION File", "tftp.destination_file",
|
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
|
|
|
FT_STRINGZ, BASE_NONE, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"TFTP source file name", HFILL }},
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
{ &hf_tftp_transfer_type,
|
|
|
|
{ "Type", "tftp.type",
|
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
|
|
|
FT_STRINGZ, BASE_NONE, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"TFTP transfer type", HFILL }},
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
{ &hf_tftp_blocknum,
|
|
|
|
{ "Block", "tftp.block",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Block number", HFILL }},
|
2000-11-10 09:17:10 +00:00
|
|
|
|
1999-11-14 10:32:26 +00:00
|
|
|
{ &hf_tftp_error_code,
|
|
|
|
{ "Error code", "tftp.error.code",
|
2000-11-10 09:17:10 +00:00
|
|
|
FT_UINT16, BASE_DEC, VALS(tftp_error_code_vals), 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Error code in case of TFTP error message", HFILL }},
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
{ &hf_tftp_error_string,
|
|
|
|
{ "Error message", "tftp.error.message",
|
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
|
|
|
FT_STRINGZ, BASE_NONE, NULL, 0x0,
|
2006-09-06 08:24:36 +00:00
|
|
|
"Error string in case of TFTP error message", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_tftp_option_name,
|
2011-01-31 21:23:49 +00:00
|
|
|
{ "Option name", "tftp.option.name",
|
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
|
|
|
FT_STRINGZ, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
2006-09-06 08:24:36 +00:00
|
|
|
|
|
|
|
{ &hf_tftp_option_value,
|
2011-01-31 21:23:49 +00:00
|
|
|
{ "Option value", "tftp.option.value",
|
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
|
|
|
FT_STRINGZ, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
2006-09-06 08:24:36 +00:00
|
|
|
|
1999-11-14 10:32:26 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_tftp,
|
2006-09-06 08:24:36 +00:00
|
|
|
&ett_tftp_option,
|
1999-11-16 11:44:20 +00:00
|
|
|
};
|
1999-11-14 10:32:26 +00:00
|
|
|
|
2009-06-03 09:57:22 +00:00
|
|
|
module_t *tftp_module;
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_tftp = proto_register_protocol("Trivial File Transfer Protocol",
|
|
|
|
"TFTP", "tftp");
|
1999-11-14 10:32:26 +00:00
|
|
|
proto_register_field_array(proto_tftp, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2001-11-27 07:13:32 +00:00
|
|
|
|
2005-04-27 06:50:04 +00:00
|
|
|
register_dissector("tftp", dissect_tftp, proto_tftp);
|
2009-06-03 09:57:22 +00:00
|
|
|
|
|
|
|
/* Set default UDP ports */
|
2011-01-31 21:23:49 +00:00
|
|
|
range_convert_str(&global_tftp_port_range, UDP_PORT_TFTP_RANGE, MAX_UDP_PORT);
|
2009-06-03 09:57:22 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_module = prefs_register_protocol(proto_tftp, proto_reg_handoff_tftp);
|
|
|
|
prefs_register_range_preference(tftp_module, "udp_ports",
|
2009-06-03 09:57:22 +00:00
|
|
|
"TFTP port numbers",
|
|
|
|
"Port numbers used for TFTP traffic "
|
2011-01-31 21:23:49 +00:00
|
|
|
"(default " UDP_PORT_TFTP_RANGE ")",
|
|
|
|
&global_tftp_port_range, MAX_UDP_PORT);
|
2009-06-03 09:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void range_delete_callback (guint32 port)
|
|
|
|
{
|
2011-01-31 21:23:49 +00:00
|
|
|
dissector_delete_uint("udp.port", port, tftp_handle);
|
2009-06-03 09:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void range_add_callback (guint32 port)
|
|
|
|
{
|
2011-01-31 21:23:49 +00:00
|
|
|
dissector_add_uint("udp.port", port, tftp_handle);
|
1999-07-29 05:47:07 +00:00
|
|
|
}
|
2000-10-21 09:54:12 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_tftp(void)
|
|
|
|
{
|
2009-06-03 09:57:22 +00:00
|
|
|
static range_t *tftp_port_range;
|
|
|
|
static gboolean tftp_initialized = FALSE;
|
|
|
|
|
|
|
|
if (!tftp_initialized) {
|
|
|
|
tftp_handle = find_dissector("tftp");
|
2011-01-31 21:23:49 +00:00
|
|
|
data_handle = find_dissector("data");
|
2009-09-13 23:03:38 +00:00
|
|
|
heur_dissector_add("stun", dissect_embeddedtftp_heur, proto_tftp);
|
2009-06-03 09:57:22 +00:00
|
|
|
tftp_initialized = TRUE;
|
|
|
|
} else {
|
2011-01-31 21:23:49 +00:00
|
|
|
range_foreach(tftp_port_range, range_delete_callback);
|
|
|
|
g_free(tftp_port_range);
|
2009-06-03 09:57:22 +00:00
|
|
|
}
|
2008-08-01 15:11:06 +00:00
|
|
|
|
2011-01-31 21:23:49 +00:00
|
|
|
tftp_port_range = range_copy(global_tftp_port_range);
|
|
|
|
range_foreach(tftp_port_range, range_add_callback);
|
2000-10-21 09:54:12 +00:00
|
|
|
}
|
2011-01-31 21:23:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2011-09-21 16:28:53 +00:00
|
|
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
2011-01-31 21:23:49 +00:00
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|