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>
|
|
|
|
* RFC2347 TFTP Option Extension
|
1999-02-15 06:36:57 +00:00
|
|
|
*
|
2000-11-19 08:54:37 +00:00
|
|
|
* $Id: packet-tftp.c,v 1.18 2000/11/19 08:54:09 guy Exp $
|
1999-02-15 06:36:57 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2000-01-07 22:05:43 +00:00
|
|
|
* By Gerald Combs <gerald@zing.org>
|
1999-02-15 06:36:57 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-bootp.c
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <glib.h>
|
1999-02-15 06:36:57 +00:00
|
|
|
#include "packet.h"
|
2000-10-21 09:54:12 +00:00
|
|
|
#include "conversation.h"
|
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;
|
1999-07-29 05:47:07 +00:00
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_tftp = -1;
|
|
|
|
|
2000-10-21 09:54:12 +00:00
|
|
|
#define UDP_PORT_TFTP 69
|
|
|
|
|
1999-05-13 05:46:04 +00:00
|
|
|
#define RRQ 1
|
|
|
|
#define WRQ 2
|
|
|
|
#define DATA 3
|
|
|
|
#define ACK 4
|
|
|
|
#define ERROR 5
|
2000-01-27 07:09:45 +00:00
|
|
|
#define OACK 6
|
1999-05-13 05:46:04 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
static const value_string tftp_opcode_vals[] = {
|
|
|
|
{ RRQ, "Read Request" },
|
|
|
|
{ WRQ, "Write Request" },
|
|
|
|
{ DATA, "Data Packet" },
|
|
|
|
{ ACK, "Acknowledgement" },
|
|
|
|
{ ERROR, "Error Code" },
|
|
|
|
{ OACK, "Option Acknowledgement" },
|
|
|
|
{ 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" },
|
|
|
|
{ 5, "Unknown transfer ID" },
|
|
|
|
{ 6, "File already exists" },
|
|
|
|
{ 7, "No such user" },
|
|
|
|
{ 0, NULL }
|
1999-02-15 06:36:57 +00:00
|
|
|
};
|
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
static void tftp_dissect_options(tvbuff_t *tvb, int offset, proto_tree *tree);
|
|
|
|
|
2000-10-21 09:54:12 +00:00
|
|
|
static void
|
2000-11-10 09:17:10 +00:00
|
|
|
dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
1999-02-15 06:36:57 +00:00
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *tftp_tree;
|
|
|
|
proto_item *ti;
|
2000-10-21 09:54:12 +00:00
|
|
|
conversation_t *conversation;
|
2000-11-10 09:17:10 +00:00
|
|
|
gint offset = 0;
|
|
|
|
guint16 opcode;
|
|
|
|
u_int i1;
|
1999-02-15 06:36:57 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
CHECK_DISPLAY_AS_DATA(proto_tftp, tvb, pinfo, tree);
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2000-10-21 09:54:12 +00:00
|
|
|
/*
|
|
|
|
* 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 the source IP address
|
|
|
|
* and port of this packet, the destination IP address of this
|
|
|
|
* packet, and any destination UDP port. If not, we create
|
|
|
|
* one, with a wildcard UDP port, and give it the TFTP dissector
|
|
|
|
* as a dissector.
|
|
|
|
*/
|
2000-11-10 09:17:10 +00:00
|
|
|
if (pinfo->destport == UDP_PORT_TFTP) {
|
2000-11-10 09:22:46 +00:00
|
|
|
conversation = find_conversation(&pinfo->src, &pinfo->dst, PT_UDP,
|
|
|
|
pinfo->srcport, 0, NO_DST_PORT);
|
2000-10-21 09:54:12 +00:00
|
|
|
if (conversation == NULL) {
|
2000-11-10 09:22:46 +00:00
|
|
|
conversation = conversation_new(&pinfo->src, &pinfo->dst, PT_UDP,
|
|
|
|
pinfo->srcport, 0, NULL,
|
2000-10-21 09:54:12 +00:00
|
|
|
NO_DST_PORT);
|
2000-11-10 09:17:10 +00:00
|
|
|
conversation_set_dissector(conversation, dissect_tftp);
|
2000-10-21 09:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
if (check_col(pinfo->fd, COL_PROTOCOL))
|
2000-11-19 08:54:37 +00:00
|
|
|
col_set_str(pinfo->fd, 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
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
if (check_col(pinfo->fd, COL_INFO)) {
|
1999-02-15 06:36:57 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
col_add_fstr(pinfo->fd, COL_INFO, "TFTP %s",
|
|
|
|
val_to_str(opcode, tftp_opcode_vals, "Unknown (0x%04x)"));
|
1999-02-15 06:36:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_tftp, tvb, offset,
|
|
|
|
tvb_length_remaining(tvb, offset), FALSE);
|
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
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
proto_tree_add_uint(tftp_tree, hf_tftp_opcode, tvb,
|
|
|
|
offset, 2, opcode);
|
|
|
|
offset += 2;
|
1999-11-14 10:32:26 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
switch (opcode) {
|
1999-02-15 06:36:57 +00:00
|
|
|
case RRQ:
|
2000-11-10 09:17:10 +00:00
|
|
|
i1 = tvb_strnlen(tvb, offset, -1);
|
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_source_file,
|
|
|
|
tvb, offset, i1 + 1, FALSE);
|
1999-02-15 06:36:57 +00:00
|
|
|
offset += i1 + 1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
i1 = tvb_strnlen(tvb, offset, -1);
|
|
|
|
ti = proto_tree_add_item(tftp_tree, hf_tftp_transfer_type,
|
|
|
|
tvb, offset, i1 + 1, FALSE);
|
2000-01-27 07:09:45 +00:00
|
|
|
offset += i1 + 1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
tftp_dissect_options(tvb, offset, tftp_tree);
|
1999-02-15 06:36:57 +00:00
|
|
|
break;
|
|
|
|
case WRQ:
|
2000-11-10 09:17:10 +00:00
|
|
|
i1 = tvb_strnlen(tvb, offset, -1);
|
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_destination_file,
|
|
|
|
tvb, offset, i1 + 1, FALSE);
|
1999-02-15 06:36:57 +00:00
|
|
|
offset += i1 + 1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
i1 = tvb_strnlen(tvb, offset, -1);
|
|
|
|
ti = proto_tree_add_item(tftp_tree, hf_tftp_transfer_type,
|
|
|
|
tvb, offset, i1 + 1, FALSE);
|
2000-01-27 07:09:45 +00:00
|
|
|
offset += i1 + 1;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
tftp_dissect_options(tvb, offset, tftp_tree);
|
1999-02-15 06:36:57 +00:00
|
|
|
break;
|
|
|
|
case DATA:
|
2000-11-10 09:17:10 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
|
|
|
|
FALSE);
|
1999-02-15 06:36:57 +00:00
|
|
|
offset += 2;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
proto_tree_add_text(tftp_tree, tvb, offset, tvb_length_remaining(tvb, offset),
|
|
|
|
"Data (%d bytes)", tvb_length_remaining(tvb, offset));
|
1999-02-15 06:36:57 +00:00
|
|
|
break;
|
|
|
|
case ACK:
|
2000-11-10 09:17:10 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
|
|
|
|
FALSE);
|
1999-02-15 06:36:57 +00:00
|
|
|
break;
|
|
|
|
case ERROR:
|
2000-11-10 09:17:10 +00:00
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_error_code, tvb, offset, 2,
|
|
|
|
FALSE);
|
1999-02-15 06:36:57 +00:00
|
|
|
offset += 2;
|
2000-11-10 09:17:10 +00:00
|
|
|
|
|
|
|
i1 = tvb_strnlen(tvb, offset, -1);
|
|
|
|
proto_tree_add_item(tftp_tree, hf_tftp_error_string, tvb, offset,
|
|
|
|
i1 + 1, FALSE);
|
1999-02-15 06:36:57 +00:00
|
|
|
break;
|
2000-01-27 07:09:45 +00:00
|
|
|
case OACK:
|
2000-11-10 09:17:10 +00:00
|
|
|
tftp_dissect_options(tvb, offset, tftp_tree);
|
2000-01-27 07:09:45 +00:00
|
|
|
break;
|
1999-02-15 06:36:57 +00:00
|
|
|
default:
|
2000-11-10 09:17:10 +00:00
|
|
|
proto_tree_add_text(tftp_tree, tvb, offset, tvb_length_remaining(tvb, offset),
|
|
|
|
"Data (%d bytes)", tvb_length_remaining(tvb, offset));
|
1999-02-15 06:36:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
1999-07-29 05:47:07 +00:00
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
static void
|
|
|
|
tftp_dissect_options(tvbuff_t *tvb, int offset, proto_tree *tree)
|
|
|
|
{
|
|
|
|
int i1, i2;
|
|
|
|
|
2000-11-13 08:58:17 +00:00
|
|
|
while (tvb_offset_exists(tvb, offset)) {
|
2000-11-10 09:17:10 +00:00
|
|
|
i1 = tvb_strnlen(tvb, offset, -1); /* length of option */
|
|
|
|
i2 = tvb_strnlen(tvb, offset+i1+1, -1); /* length of value */
|
|
|
|
proto_tree_add_text(tree, tvb, offset, i1+i2+2,
|
|
|
|
"Option: %.*s = %.*s",
|
|
|
|
i1, tvb_get_ptr(tvb, offset, i1),
|
|
|
|
i2, tvb_get_ptr(tvb, offset+i1+1, i2));
|
|
|
|
offset += i1 + i2 + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
1999-11-14 10:32:26 +00:00
|
|
|
"TFTP message type" }},
|
|
|
|
|
2000-11-10 09:17:10 +00:00
|
|
|
{ &hf_tftp_source_file,
|
|
|
|
{ "Source File", "tftp.source_file",
|
|
|
|
FT_STRINGZ, BASE_DEC, NULL, 0x0,
|
|
|
|
"TFTP source file name" }},
|
|
|
|
|
|
|
|
{ &hf_tftp_destination_file,
|
|
|
|
{ "DESTINATION File", "tftp.destination_file",
|
|
|
|
FT_STRINGZ, BASE_DEC, NULL, 0x0,
|
|
|
|
"TFTP source file name" }},
|
|
|
|
|
|
|
|
{ &hf_tftp_transfer_type,
|
|
|
|
{ "Type", "tftp.type",
|
|
|
|
FT_STRINGZ, BASE_DEC, NULL, 0x0,
|
|
|
|
"TFTP transfer type" }},
|
|
|
|
|
|
|
|
{ &hf_tftp_blocknum,
|
|
|
|
{ "Block", "tftp.block",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
"Block number" }},
|
|
|
|
|
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,
|
|
|
|
"Error code in case of TFTP error message" }},
|
|
|
|
|
|
|
|
{ &hf_tftp_error_string,
|
|
|
|
{ "Error message", "tftp.error.message",
|
|
|
|
FT_STRINGZ, BASE_DEC, NULL, 0x0,
|
|
|
|
"Error string in case of TFTP error message" }}
|
1999-11-14 10:32:26 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_tftp,
|
|
|
|
};
|
1999-11-14 10:32:26 +00:00
|
|
|
|
|
|
|
proto_tftp = proto_register_protocol("Trivial File Transfer Protocol", "tftp");
|
|
|
|
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));
|
1999-07-29 05:47:07 +00:00
|
|
|
}
|
2000-10-21 09:54:12 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_tftp(void)
|
|
|
|
{
|
2000-11-10 09:17:10 +00:00
|
|
|
dissector_add("udp.port", UDP_PORT_TFTP, dissect_tftp);
|
2000-10-21 09:54:12 +00:00
|
|
|
}
|