1999-09-14 08:06:47 +00:00
|
|
|
/* packet-icp.c
|
1999-11-16 11:44:20 +00:00
|
|
|
* Routines for ICP (internet cache protocol) packet disassembly
|
|
|
|
* RFC 2186 && RFC 2187
|
2001-12-03 04:00:26 +00:00
|
|
|
* By Peter Torvals
|
|
|
|
* Copyright 1999 Peter Torvals
|
1999-09-14 08:06:47 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1999-09-14 08:06:47 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-12-03 04:00:26 +00:00
|
|
|
* Copyright 1998
|
|
|
|
*
|
1999-09-14 08:06: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_TEXTBUF_LENGTH 600
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
#include <stdlib.h>
|
1999-09-14 08:06:47 +00:00
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2004-08-06 19:57:49 +00:00
|
|
|
#include <epan/addr_resolv.h>
|
1999-09-14 08:06:47 +00:00
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static int proto_icp=-1;
|
|
|
|
static int hf_icp_length=-1;
|
|
|
|
static int hf_icp_opcode=-1;
|
|
|
|
static int hf_icp_version=-1;
|
|
|
|
static int hf_icp_request_nr=-1;
|
|
|
|
|
|
|
|
static gint ett_icp = -1;
|
|
|
|
static gint ett_icp_payload = -1;
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
#define UDP_PORT_ICP 3130
|
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
#define CODE_ICP_OP_QUERY 1
|
|
|
|
#define CODE_ICP_OP_INVALID 0
|
|
|
|
#define CODE_ICP_OP_HIT 2
|
|
|
|
#define CODE_ICP_OP_MISS 3
|
|
|
|
#define CODE_ICP_OP_ERR 4
|
|
|
|
#define CODE_ICP_OP_SEND 5
|
|
|
|
#define CODE_ICP_OP_SENDA 6
|
|
|
|
#define CODE_ICP_OP_DATABEG 7
|
|
|
|
#define CODE_ICP_OP_DATA 8
|
|
|
|
#define CODE_ICP_OP_DATAEND 9
|
|
|
|
#define CODE_ICP_OP_SECHO 10
|
|
|
|
#define CODE_ICP_OP_DECHO 11
|
|
|
|
#define CODE_ICP_OP_MISS_NOFETCH 21
|
|
|
|
#define CODE_ICP_OP_DENIED 22
|
|
|
|
#define CODE_ICP_OP_HIT_OBJ 23
|
|
|
|
|
2008-08-14 23:51:52 +00:00
|
|
|
static const value_string opcode_vals[] = {
|
1999-09-14 08:06:47 +00:00
|
|
|
{ CODE_ICP_OP_INVALID , "ICP_INVALID" },
|
|
|
|
{ CODE_ICP_OP_QUERY , "ICP_QUERY" },
|
|
|
|
{ CODE_ICP_OP_HIT , "ICP_HIT" },
|
|
|
|
{ CODE_ICP_OP_MISS , "ICP_MISS" },
|
|
|
|
{ CODE_ICP_OP_ERR , "ICP_ERR" },
|
|
|
|
{ CODE_ICP_OP_SEND, "ICP_SEND" },
|
|
|
|
{ CODE_ICP_OP_SENDA, "ICP_SENDA"},
|
|
|
|
{ CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
|
|
|
|
{ CODE_ICP_OP_DATA, "ICP_DATA"},
|
2002-08-28 21:04:11 +00:00
|
|
|
{ CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
|
1999-09-14 08:06:47 +00:00
|
|
|
{ CODE_ICP_OP_SECHO , "ICP_SECHO"},
|
|
|
|
{ CODE_ICP_OP_DECHO , "ICP_DECHO"},
|
|
|
|
{ CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
|
|
|
|
{ CODE_ICP_OP_DENIED , "ICP_DENIED"},
|
|
|
|
{ CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2001-02-28 21:26:58 +00:00
|
|
|
static void dissect_icp_payload(tvbuff_t *tvb, int offset,
|
|
|
|
proto_tree *pload_tree, guint8 opcode)
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
2001-02-28 21:26:58 +00:00
|
|
|
gint stringlength;
|
|
|
|
guint16 objectlength;
|
2000-04-08 07:07:42 +00:00
|
|
|
|
2001-02-28 21:26:58 +00:00
|
|
|
switch(opcode)
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
|
|
|
case CODE_ICP_OP_QUERY:
|
|
|
|
/* 4 byte requester host address */
|
2001-02-28 21:26:58 +00:00
|
|
|
proto_tree_add_text(pload_tree, tvb,offset,4,
|
|
|
|
"Requester Host Address %s",
|
|
|
|
ip_to_str(tvb_get_ptr(tvb, offset, 4)));
|
|
|
|
offset += 4;
|
1999-09-14 08:06:47 +00:00
|
|
|
|
|
|
|
/* null terminated URL */
|
2001-02-28 21:26:58 +00:00
|
|
|
stringlength = tvb_strsize(tvb, offset);
|
|
|
|
proto_tree_add_text(pload_tree, tvb, offset, stringlength,
|
|
|
|
"URL: %s", tvb_get_ptr(tvb, offset, stringlength));
|
1999-09-14 08:06:47 +00:00
|
|
|
break;
|
2001-02-28 21:26:58 +00:00
|
|
|
|
|
|
|
case CODE_ICP_OP_SECHO:
|
|
|
|
case CODE_ICP_OP_DECHO:
|
|
|
|
case CODE_ICP_OP_HIT:
|
|
|
|
case CODE_ICP_OP_MISS:
|
|
|
|
case CODE_ICP_OP_ERR:
|
|
|
|
case CODE_ICP_OP_MISS_NOFETCH:
|
|
|
|
case CODE_ICP_OP_DENIED:
|
|
|
|
stringlength = tvb_strsize(tvb, offset);
|
|
|
|
proto_tree_add_text(pload_tree, tvb, offset, stringlength,
|
|
|
|
"URL: %s", tvb_get_ptr(tvb, offset, stringlength));
|
|
|
|
break;
|
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
case CODE_ICP_OP_HIT_OBJ:
|
2001-02-28 21:26:58 +00:00
|
|
|
/* null terminated URL */
|
|
|
|
stringlength = tvb_strsize(tvb, offset);
|
|
|
|
proto_tree_add_text(pload_tree, tvb, offset, stringlength,
|
|
|
|
"URL: %s", tvb_get_ptr(tvb, offset, stringlength));
|
|
|
|
offset += stringlength;
|
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
/* 2 byte object size */
|
|
|
|
/* object data not recommended by standard*/
|
2001-02-28 21:26:58 +00:00
|
|
|
objectlength=tvb_get_ntohs(tvb, offset);
|
|
|
|
proto_tree_add_text(pload_tree, tvb,offset,2,"Object length: %u", objectlength);
|
|
|
|
offset += 2;
|
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
/* object data not recommended by standard*/
|
2001-02-28 21:26:58 +00:00
|
|
|
proto_tree_add_text(pload_tree, tvb,offset,objectlength,"Object data");
|
|
|
|
if (objectlength > tvb_reported_length_remaining(tvb, offset))
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
2001-02-28 21:26:58 +00:00
|
|
|
proto_tree_add_text(pload_tree, tvb,offset,0,
|
1999-09-14 08:06:47 +00:00
|
|
|
"Packet is fragmented, rest of object is in next udp packet");
|
|
|
|
}
|
2001-02-28 21:26:58 +00:00
|
|
|
break;
|
2002-08-28 21:04:11 +00:00
|
|
|
default:
|
1999-09-14 08:06:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-28 21:26:58 +00:00
|
|
|
static void dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
|
|
|
proto_tree *icp_tree , *payload_tree;
|
|
|
|
proto_item *ti , *payloadtf;
|
2001-02-28 21:26:58 +00:00
|
|
|
guint8 opcode;
|
|
|
|
guint16 message_length;
|
|
|
|
guint32 request_number;
|
|
|
|
guint32 options;
|
|
|
|
guint32 option_data;
|
1999-09-14 08:06:47 +00:00
|
|
|
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICP");
|
2009-08-09 07:36:13 +00:00
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
1999-09-14 08:06:47 +00:00
|
|
|
|
2001-02-28 21:26:58 +00:00
|
|
|
opcode=tvb_get_guint8(tvb, 0);
|
|
|
|
message_length=tvb_get_ntohs(tvb, 2);
|
|
|
|
request_number=tvb_get_ntohl(tvb, 4);
|
1999-09-14 08:06:47 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
2001-12-10 00:26:21 +00:00
|
|
|
col_add_fstr(pinfo->cinfo,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
|
2001-02-28 21:26:58 +00:00
|
|
|
val_to_str(opcode, opcode_vals, "Unknown"), opcode,
|
|
|
|
request_number);
|
1999-09-14 08:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tree)
|
|
|
|
{
|
|
|
|
|
2001-02-28 21:26:58 +00:00
|
|
|
ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, FALSE);
|
1999-11-16 11:44:20 +00:00
|
|
|
icp_tree = proto_item_add_subtree(ti, ett_icp);
|
2001-02-28 21:26:58 +00:00
|
|
|
|
|
|
|
proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
|
|
|
|
|
|
|
|
proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, FALSE);
|
|
|
|
|
|
|
|
proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
|
|
|
|
|
|
|
|
proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
|
|
|
|
request_number);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-02-28 21:26:58 +00:00
|
|
|
options=tvb_get_ntohl(tvb, 8);
|
|
|
|
if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
2001-02-28 21:26:58 +00:00
|
|
|
proto_tree_add_text(icp_tree, tvb,8,4,
|
1999-09-14 08:06:47 +00:00
|
|
|
"option: ICP_FLAG_HIT_OBJ");
|
|
|
|
}
|
2001-02-28 21:26:58 +00:00
|
|
|
if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
2001-02-28 21:26:58 +00:00
|
|
|
proto_tree_add_text(icp_tree, tvb,8,4,
|
1999-09-14 08:06:47 +00:00
|
|
|
"option:ICP_FLAG_SRC_RTT");
|
|
|
|
}
|
2001-02-28 21:26:58 +00:00
|
|
|
if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
|
1999-09-14 08:06:47 +00:00
|
|
|
{
|
2001-02-28 21:26:58 +00:00
|
|
|
option_data=tvb_get_ntohl(tvb, 12);
|
|
|
|
proto_tree_add_text(icp_tree, tvb,8,8,
|
|
|
|
"option: ICP_FLAG_SCR_RTT RTT=%u",
|
|
|
|
option_data & 0x0000ffff);
|
1999-09-14 08:06:47 +00:00
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
|
|
|
proto_tree_add_text(icp_tree, tvb, 16, 4,
|
2001-02-28 21:26:58 +00:00
|
|
|
"Sender Host IP address %s",
|
|
|
|
ip_to_str(tvb_get_ptr(tvb, 16, 4)));
|
|
|
|
|
|
|
|
payloadtf = proto_tree_add_text(icp_tree, tvb,
|
|
|
|
20, message_length - 20,
|
1999-09-14 08:06:47 +00:00
|
|
|
"Payload");
|
1999-11-16 11:44:20 +00:00
|
|
|
payload_tree = proto_item_add_subtree(payloadtf, ett_icp_payload);
|
2001-02-28 21:26:58 +00:00
|
|
|
dissect_icp_payload(tvb, 20, payload_tree, opcode);
|
1999-09-14 08:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
|
|
|
proto_register_icp(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_icp_opcode,
|
2001-02-28 21:26:58 +00:00
|
|
|
{ "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
|
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
|
|
|
0x0, NULL, HFILL }},
|
1999-10-12 06:21:15 +00:00
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
{ &hf_icp_version,
|
2001-02-28 21:26:58 +00:00
|
|
|
{ "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
|
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
|
|
|
0x0, NULL, HFILL }},
|
1999-10-12 06:21:15 +00:00
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
{ &hf_icp_length,
|
2001-02-28 21:26:58 +00:00
|
|
|
{ "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
|
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
|
|
|
0x0, NULL, HFILL }},
|
1999-10-12 06:21:15 +00:00
|
|
|
|
1999-09-14 08:06:47 +00:00
|
|
|
{ &hf_icp_request_nr,
|
2001-02-28 21:26:58 +00:00
|
|
|
{ "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
|
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
|
|
|
0x0, NULL, HFILL }},
|
1999-10-12 06:21:15 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_icp,
|
|
|
|
&ett_icp_payload,
|
|
|
|
};
|
1999-09-14 08:06:47 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_icp = proto_register_protocol("Internet Cache Protocol",
|
|
|
|
"ICP", "icp");
|
1999-09-14 08:06:47 +00:00
|
|
|
proto_register_field_array(proto_icp, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-09-14 08:06:47 +00:00
|
|
|
}
|
2000-04-08 07:07:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_icp(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t icp_handle;
|
|
|
|
|
|
|
|
icp_handle = create_dissector_handle(dissect_icp, proto_icp);
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("udp.port", UDP_PORT_ICP, icp_handle);
|
2000-04-08 07:07:42 +00:00
|
|
|
}
|