2000-10-19 06:45:11 +00:00
|
|
|
/* packet-tpkt.c
|
|
|
|
*
|
2001-03-28 07:49:41 +00:00
|
|
|
* Routine to check for RFC 1006 TPKT header and to dissect TPKT header
|
2000-10-19 06:45:11 +00:00
|
|
|
* Copyright 2000, Philips Electronics N.V.
|
2004-02-14 22:48:53 +00:00
|
|
|
* Andreas Sikkema <h323@ramdyne.nl>
|
2000-10-19 06:45:11 +00:00
|
|
|
*
|
2001-03-28 07:49:41 +00:00
|
|
|
* Routine to dissect RFC 1006 TPKT packet containing OSI TP PDU
|
|
|
|
* Copyright 2001, Martin Thomas <Martin_A_Thomas@yahoo.com>
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-06-12 06:32:39 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-10-19 06:45:11 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-10-19 06:45:11 +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
|
|
|
*
|
2000-10-19 06:45:11 +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
|
|
|
*
|
2000-10-19 06:45:11 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2000-10-19 06:45:11 +00:00
|
|
|
|
|
|
|
#include "packet-tpkt.h"
|
2002-02-22 11:28:03 +00:00
|
|
|
#include "packet-frame.h"
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2007-11-16 08:18:30 +00:00
|
|
|
#include <ctype.h>
|
2000-10-19 06:45:11 +00:00
|
|
|
/* TPKT header fields */
|
|
|
|
static int proto_tpkt = -1;
|
2003-12-02 18:50:52 +00:00
|
|
|
static protocol_t *proto_tpkt_ptr;
|
2000-10-19 06:45:11 +00:00
|
|
|
static int hf_tpkt_version = -1;
|
|
|
|
static int hf_tpkt_reserved = -1;
|
|
|
|
static int hf_tpkt_length = -1;
|
|
|
|
|
2007-11-16 08:18:30 +00:00
|
|
|
|
2000-10-19 06:45:11 +00:00
|
|
|
/* TPKT fields defining a sub tree */
|
|
|
|
static gint ett_tpkt = -1;
|
|
|
|
|
2002-02-22 08:56:48 +00:00
|
|
|
/* desegmentation of OSI over TPKT over TCP */
|
|
|
|
static gboolean tpkt_desegment = TRUE;
|
|
|
|
|
2007-10-29 07:16:49 +00:00
|
|
|
#define TCP_PORT_TPKT 102
|
|
|
|
#define TCP_PORT_TPKT_X224 3389
|
2001-03-28 07:49:41 +00:00
|
|
|
|
|
|
|
/* find the dissector for OSI TP (aka COTP) */
|
2002-08-28 21:04:11 +00:00
|
|
|
static dissector_handle_t osi_tp_handle;
|
2001-03-28 07:49:41 +00:00
|
|
|
|
2007-10-29 07:16:49 +00:00
|
|
|
/* find the dissector for X.224 */
|
|
|
|
static dissector_handle_t x224_handle;
|
|
|
|
|
2001-03-28 07:49:41 +00:00
|
|
|
/*
|
|
|
|
* Check whether this could be a TPKT-encapsulated PDU.
|
2002-02-23 02:30:16 +00:00
|
|
|
* Returns -1 if it's not, and the PDU length from the TPKT header
|
|
|
|
* if it is.
|
2002-05-13 21:18:26 +00:00
|
|
|
*
|
|
|
|
* "min_len" is the minimum length of the PDU; the length field in the
|
|
|
|
* TPKT header must be at least "4+min_len" in order for this to be a
|
|
|
|
* valid TPKT PDU for the protocol in question.
|
2001-03-28 07:49:41 +00:00
|
|
|
*/
|
Clean up the heuristic code in the Q.931 dissector. If it's a heuristic
dissector, it's looking for Q.931 encapsulated inside TPKT, so it
shouldn't check whether the first byte is NLPID_Q_931 or not, as it
*won't* be NLPID_Q_931, it'll be 3, for the TPKT version. It should
first check whether "is_tpkt()" thinks it's a TPKT packet, and then
check that the packet has at least 3 bytes past the TPKT header, then
check the first byte in the payload to see whether it's NLPID_Q_931. If
that all succeeds, treat it as Q.931 inside TPKT.
Make "is_tpkt()" return the length from the TPKT header on success, and
-1 on failure, and return the offset past the TPKT header via a pointer
(so clients don't have to know that the TPKT header is 4 bytes long).
svn path=/trunk/; revision=4669
2002-02-02 02:51:20 +00:00
|
|
|
int
|
2002-05-13 21:18:26 +00:00
|
|
|
is_tpkt(tvbuff_t *tvb, int min_len)
|
2000-10-19 06:45:11 +00:00
|
|
|
{
|
2002-05-13 21:18:26 +00:00
|
|
|
guint16 pkt_len;
|
|
|
|
|
Clean up the heuristic code in the Q.931 dissector. If it's a heuristic
dissector, it's looking for Q.931 encapsulated inside TPKT, so it
shouldn't check whether the first byte is NLPID_Q_931 or not, as it
*won't* be NLPID_Q_931, it'll be 3, for the TPKT version. It should
first check whether "is_tpkt()" thinks it's a TPKT packet, and then
check that the packet has at least 3 bytes past the TPKT header, then
check the first byte in the payload to see whether it's NLPID_Q_931. If
that all succeeds, treat it as Q.931 inside TPKT.
Make "is_tpkt()" return the length from the TPKT header on success, and
-1 on failure, and return the offset past the TPKT header via a pointer
(so clients don't have to know that the TPKT header is 4 bytes long).
svn path=/trunk/; revision=4669
2002-02-02 02:51:20 +00:00
|
|
|
/*
|
|
|
|
* If TPKT is disabled, don't dissect it, just return -1, meaning
|
|
|
|
* "this isn't TPKT".
|
|
|
|
*/
|
2003-12-02 18:50:52 +00:00
|
|
|
if (!proto_is_protocol_enabled(proto_tpkt_ptr))
|
Clean up the heuristic code in the Q.931 dissector. If it's a heuristic
dissector, it's looking for Q.931 encapsulated inside TPKT, so it
shouldn't check whether the first byte is NLPID_Q_931 or not, as it
*won't* be NLPID_Q_931, it'll be 3, for the TPKT version. It should
first check whether "is_tpkt()" thinks it's a TPKT packet, and then
check that the packet has at least 3 bytes past the TPKT header, then
check the first byte in the payload to see whether it's NLPID_Q_931. If
that all succeeds, treat it as Q.931 inside TPKT.
Make "is_tpkt()" return the length from the TPKT header on success, and
-1 on failure, and return the offset past the TPKT header via a pointer
(so clients don't have to know that the TPKT header is 4 bytes long).
svn path=/trunk/; revision=4669
2002-02-02 02:51:20 +00:00
|
|
|
return -1;
|
|
|
|
|
2001-03-28 07:49:41 +00:00
|
|
|
/* There should at least be 4 bytes left in the frame */
|
2007-10-11 21:23:14 +00:00
|
|
|
if (tvb_length(tvb) < 4)
|
Clean up the heuristic code in the Q.931 dissector. If it's a heuristic
dissector, it's looking for Q.931 encapsulated inside TPKT, so it
shouldn't check whether the first byte is NLPID_Q_931 or not, as it
*won't* be NLPID_Q_931, it'll be 3, for the TPKT version. It should
first check whether "is_tpkt()" thinks it's a TPKT packet, and then
check that the packet has at least 3 bytes past the TPKT header, then
check the first byte in the payload to see whether it's NLPID_Q_931. If
that all succeeds, treat it as Q.931 inside TPKT.
Make "is_tpkt()" return the length from the TPKT header on success, and
-1 on failure, and return the offset past the TPKT header via a pointer
(so clients don't have to know that the TPKT header is 4 bytes long).
svn path=/trunk/; revision=4669
2002-02-02 02:51:20 +00:00
|
|
|
return -1; /* there aren't */
|
|
|
|
|
|
|
|
/*
|
2002-08-28 21:04:11 +00:00
|
|
|
* The first octet should be 3 and the second one should be 0
|
|
|
|
* The H.323 implementers guide suggests that this might not
|
2001-03-28 07:49:41 +00:00
|
|
|
* always be the case....
|
|
|
|
*/
|
2002-02-23 02:30:16 +00:00
|
|
|
if (!(tvb_get_guint8(tvb, 0) == 3 && tvb_get_guint8(tvb, 1) == 0))
|
2002-05-13 21:18:26 +00:00
|
|
|
return -1; /* they're not */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the length from the TPKT header. Make sure it's large
|
|
|
|
* enough.
|
|
|
|
*/
|
|
|
|
pkt_len = tvb_get_ntohs(tvb, 2);
|
|
|
|
if (pkt_len < 4 + min_len)
|
|
|
|
return -1; /* it's not */
|
Clean up the heuristic code in the Q.931 dissector. If it's a heuristic
dissector, it's looking for Q.931 encapsulated inside TPKT, so it
shouldn't check whether the first byte is NLPID_Q_931 or not, as it
*won't* be NLPID_Q_931, it'll be 3, for the TPKT version. It should
first check whether "is_tpkt()" thinks it's a TPKT packet, and then
check that the packet has at least 3 bytes past the TPKT header, then
check the first byte in the payload to see whether it's NLPID_Q_931. If
that all succeeds, treat it as Q.931 inside TPKT.
Make "is_tpkt()" return the length from the TPKT header on success, and
-1 on failure, and return the offset past the TPKT header via a pointer
(so clients don't have to know that the TPKT header is 4 bytes long).
svn path=/trunk/; revision=4669
2002-02-02 02:51:20 +00:00
|
|
|
|
2002-02-23 02:30:16 +00:00
|
|
|
/*
|
2002-05-13 21:18:26 +00:00
|
|
|
* Return the length from the header.
|
2002-02-23 02:30:16 +00:00
|
|
|
*/
|
2002-05-13 21:18:26 +00:00
|
|
|
return pkt_len;
|
2000-10-19 06:45:11 +00:00
|
|
|
}
|
2010-10-10 20:07:06 +00:00
|
|
|
guint16
|
|
|
|
is_asciitpkt(tvbuff_t *tvb)
|
2007-11-16 08:18:30 +00:00
|
|
|
{
|
|
|
|
guint16 count;
|
|
|
|
/*
|
|
|
|
* If TPKT is disabled, don't dissect it, just return -1, meaning
|
|
|
|
* "this isn't TPKT".
|
|
|
|
*/
|
|
|
|
if (!proto_is_protocol_enabled(proto_tpkt_ptr))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* There should at least be 8 bytes left in the frame */
|
|
|
|
if (!tvb_bytes_exist(tvb, 0, 8))
|
|
|
|
return -1; /* there aren't */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first four octets should be ASCII
|
|
|
|
*/
|
|
|
|
for (count = 0; count <=7 ; count ++)
|
|
|
|
{
|
|
|
|
if(!isalnum(tvb_get_guint8(tvb,count)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-10-10 20:07:06 +00:00
|
|
|
static int
|
|
|
|
parseLengthText ( guint8* pTpktData )
|
2007-11-16 08:18:30 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
const guint8 * pData = pTpktData;
|
|
|
|
int bitvalue = 0, count1 = 3;
|
|
|
|
int count;
|
|
|
|
for (count = 0; count <= 3; count++)
|
|
|
|
{
|
|
|
|
if (('0' <= *(pData + count)) && (*(pData + count) <= '9'))
|
|
|
|
bitvalue = *(pData + count) - 48;
|
|
|
|
else if (('a' <= *(pData + count)) && (*(pData + count) <= 'f' ))
|
|
|
|
bitvalue = *(pData + count) - 87;
|
|
|
|
else if (('A' <= *(pData + count)) && (*(pData + count) <= 'F' ))
|
|
|
|
bitvalue = *(pData + count) - 55;
|
|
|
|
|
|
|
|
value += bitvalue << (4*count1);
|
|
|
|
count1--;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2010-10-10 20:07:06 +00:00
|
|
|
static int
|
|
|
|
parseVersionText ( guint8* pTpktData )
|
2007-11-16 08:18:30 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
guint8 * pData = pTpktData;
|
|
|
|
int bitvalue = 0, count1 = 1;
|
|
|
|
int count;
|
|
|
|
for (count = 0; count <= 1; count++)
|
|
|
|
{
|
|
|
|
if (('0' <= *(pData + count)) && (*(pData + count) <= '9'))
|
|
|
|
bitvalue = *(pData + count) - 48;
|
|
|
|
else if (('a' <= *(pData + count)) && (*(pData + count) <= 'f' ))
|
|
|
|
bitvalue = *(pData + count) - 87;
|
|
|
|
else if (('A' <= *(pData + count)) && (*(pData + count) <= 'F' ))
|
|
|
|
bitvalue = *(pData + count) - 55;
|
|
|
|
|
|
|
|
value += bitvalue << (4*count1);
|
|
|
|
count1--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
2010-10-10 20:07:06 +00:00
|
|
|
static int
|
|
|
|
parseReservedText ( guint8* pTpktData )
|
2007-11-16 08:18:30 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
guint8 * pData = pTpktData;
|
|
|
|
int bitvalue = 0, count1 = 1;
|
|
|
|
int count;
|
|
|
|
for (count = 0; count <= 1; count++)
|
|
|
|
{
|
|
|
|
if (('0' <= *(pData + count)) && (*(pData + count) <= '9'))
|
|
|
|
bitvalue = *(pData + count) - 48;
|
|
|
|
else if (('a' <= *(pData + count)) && (*(pData + count) <= 'f' ))
|
|
|
|
bitvalue = *(pData + count) - 87;
|
|
|
|
else if (('A' <= *(pData + count)) && (*(pData + count) <= 'F' ))
|
|
|
|
bitvalue = *(pData + count) - 55;
|
|
|
|
|
|
|
|
value += bitvalue << (4*count1);
|
|
|
|
count1--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Dissect ASCII TPKT-encapsulated data in a TCP stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dissect_asciitpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
2010-10-08 17:48:22 +00:00
|
|
|
dissector_handle_t subdissector_handle)
|
2007-11-16 08:18:30 +00:00
|
|
|
{
|
|
|
|
proto_item *ti = NULL;
|
|
|
|
proto_tree *tpkt_tree = NULL;
|
|
|
|
volatile int offset = 0;
|
|
|
|
int length_remaining;
|
|
|
|
int data_len;
|
2010-10-10 20:07:06 +00:00
|
|
|
volatile int mgcp_packet_len = 0;
|
2007-11-16 08:18:30 +00:00
|
|
|
int mgcp_version = 0;
|
|
|
|
int mgcp_reserved = 0;
|
|
|
|
volatile int length;
|
2008-11-22 15:55:01 +00:00
|
|
|
tvbuff_t *volatile next_tvb;
|
2007-11-16 08:18:30 +00:00
|
|
|
const char *saved_proto;
|
|
|
|
guint8 string[4];
|
2010-10-08 17:48:22 +00:00
|
|
|
void *pd_save;
|
|
|
|
|
2007-11-16 08:18:30 +00:00
|
|
|
/*
|
|
|
|
* If we're reassembling segmented TPKT PDUs, empty the COL_INFO
|
|
|
|
* column, so subdissectors can append information
|
|
|
|
* without having to worry about emptying the column.
|
|
|
|
*
|
|
|
|
* We use "col_add_str()" because the subdissector
|
|
|
|
* might be appending information to the column, in
|
|
|
|
* which case we'd have to zero the buffer out explicitly
|
|
|
|
* anyway.
|
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
if (tpkt_desegment)
|
2007-11-16 08:18:30 +00:00
|
|
|
col_add_str(pinfo->cinfo, COL_INFO, "");
|
|
|
|
|
|
|
|
while (tvb_reported_length_remaining(tvb, offset) != 0) {
|
|
|
|
/*
|
|
|
|
* Is the first byte of this putative TPKT header
|
|
|
|
* a valid TPKT version number, i.e. 3?
|
|
|
|
*/
|
|
|
|
if (tvb_get_guint8(tvb, offset) != 48) {
|
|
|
|
/*
|
|
|
|
* No, so don't assume this is a TPKT header;
|
|
|
|
* we might be in the middle of TPKT data,
|
|
|
|
* so don't get the length and don't try to
|
|
|
|
* do reassembly.
|
|
|
|
*/
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
|
2009-08-09 07:01:26 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
|
2007-11-16 08:18:30 +00:00
|
|
|
if (tree) {
|
|
|
|
ti = proto_tree_add_item(tree, proto_tpkt, tvb,
|
|
|
|
offset, -1, FALSE);
|
|
|
|
tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);
|
|
|
|
proto_item_set_text(ti, "TPKT");
|
|
|
|
|
|
|
|
proto_tree_add_text(tpkt_tree, tvb, offset, -1,
|
|
|
|
"Continuation data");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
length_remaining = tvb_length_remaining(tvb, offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the length from the TPKT header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tvb_memcpy(tvb, (guint8 *)string, offset, 2);
|
|
|
|
mgcp_version = parseVersionText(string);
|
|
|
|
tvb_memcpy(tvb, (guint8 *)string, offset +2, 2);
|
|
|
|
mgcp_reserved = parseReservedText(string);
|
|
|
|
tvb_memcpy(tvb, (guint8 *)string, offset + 4, 4);
|
|
|
|
mgcp_packet_len = parseLengthText(string);
|
|
|
|
data_len = mgcp_packet_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dissect the TPKT header.
|
|
|
|
* Save and restore "pinfo->current_proto".
|
|
|
|
*/
|
|
|
|
saved_proto = pinfo->current_proto;
|
|
|
|
pinfo->current_proto = "TPKT";
|
|
|
|
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
|
2007-11-16 08:18:30 +00:00
|
|
|
/*
|
|
|
|
* Don't add the TPKT header information if we're
|
|
|
|
* reassembling segmented TPKT PDUs or if this
|
|
|
|
* PDU isn't reassembled.
|
|
|
|
*
|
|
|
|
* XXX - the first is so that subdissectors can append
|
|
|
|
* information without getting TPKT stuff in the middle;
|
|
|
|
* why the second?
|
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
if (!tpkt_desegment && !pinfo->fragmented) {
|
2007-11-16 08:18:30 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO,
|
|
|
|
"TPKT Data length = %u", data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
ti = proto_tree_add_item(tree, proto_tpkt, tvb,
|
|
|
|
offset, 8, FALSE);
|
|
|
|
tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);
|
|
|
|
proto_item_set_text(ti, "TPKT");
|
|
|
|
|
|
|
|
/* Version */
|
|
|
|
proto_tree_add_uint(tpkt_tree, hf_tpkt_version, tvb,
|
|
|
|
offset, 2, mgcp_version);
|
|
|
|
|
|
|
|
/* Reserved octet*/
|
|
|
|
proto_tree_add_uint(tpkt_tree, hf_tpkt_reserved, tvb,
|
|
|
|
offset + 2, 2, mgcp_reserved);
|
|
|
|
|
|
|
|
/* Length */
|
|
|
|
proto_tree_add_uint(tpkt_tree, hf_tpkt_length, tvb,
|
|
|
|
offset + 4, 4, mgcp_packet_len);
|
|
|
|
}
|
|
|
|
pinfo->current_proto = saved_proto;
|
|
|
|
|
|
|
|
/* Skip the TPKT header. */
|
|
|
|
offset += TEXT_LAYER_LENGTH;
|
|
|
|
length = length_remaining - TEXT_LAYER_LENGTH;
|
|
|
|
if (length > data_len)
|
|
|
|
length = data_len;
|
|
|
|
|
|
|
|
next_tvb = tvb_new_subset(tvb, offset,length, data_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the subdissector.
|
|
|
|
*
|
|
|
|
* Catch the ReportedBoundsError exception; if this
|
|
|
|
* particular message happens to get a ReportedBoundsError
|
|
|
|
* exception, that doesn't mean that we should stop
|
|
|
|
* dissecting TPKT messages within this frame or chunk
|
|
|
|
* of reassembled data.
|
|
|
|
*
|
|
|
|
* If it gets a BoundsError, we can stop, as there's nothing
|
|
|
|
* more to see, so we just re-throw it.
|
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
pd_save = pinfo->private_data;
|
2007-11-16 08:18:30 +00:00
|
|
|
TRY {
|
|
|
|
call_dissector(subdissector_handle, next_tvb, pinfo,
|
|
|
|
tree);
|
|
|
|
}
|
|
|
|
CATCH(BoundsError) {
|
|
|
|
RETHROW;
|
|
|
|
}
|
|
|
|
CATCH(ReportedBoundsError) {
|
2010-10-08 17:48:22 +00:00
|
|
|
/* Restore the private_data structure in case one of the
|
|
|
|
* called dissectors modified it (and, due to the exception,
|
|
|
|
* was unable to restore it).
|
|
|
|
*/
|
|
|
|
pinfo->private_data = pd_save;
|
|
|
|
|
2007-11-16 08:18:30 +00:00
|
|
|
show_reported_bounds_error(tvb, pinfo, tree);
|
|
|
|
}
|
|
|
|
ENDTRY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip the payload.
|
|
|
|
*/
|
|
|
|
offset += data_len;
|
|
|
|
}
|
|
|
|
}
|
2000-10-19 06:45:11 +00:00
|
|
|
|
2001-03-28 07:49:41 +00:00
|
|
|
/*
|
2002-02-22 08:56:48 +00:00
|
|
|
* Dissect TPKT-encapsulated data in a TCP stream.
|
2001-03-28 07:49:41 +00:00
|
|
|
*/
|
2002-02-22 08:56:48 +00:00
|
|
|
void
|
|
|
|
dissect_tpkt_encap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
2010-10-08 17:48:22 +00:00
|
|
|
gboolean desegment, dissector_handle_t subdissector_handle)
|
2000-10-19 06:45:11 +00:00
|
|
|
{
|
2002-02-22 08:56:48 +00:00
|
|
|
proto_item *ti = NULL;
|
|
|
|
proto_tree *tpkt_tree = NULL;
|
2002-02-22 21:52:09 +00:00
|
|
|
volatile int offset = 0;
|
2002-02-22 08:56:48 +00:00
|
|
|
int length_remaining;
|
|
|
|
int data_len;
|
2002-02-22 21:52:09 +00:00
|
|
|
volatile int length;
|
2008-11-22 15:55:01 +00:00
|
|
|
tvbuff_t *volatile next_tvb;
|
2002-02-22 08:56:48 +00:00
|
|
|
const char *saved_proto;
|
2010-10-08 17:48:22 +00:00
|
|
|
void *pd_save;
|
2002-02-22 08:56:48 +00:00
|
|
|
|
2002-03-25 20:17:09 +00:00
|
|
|
/*
|
|
|
|
* If we're reassembling segmented TPKT PDUs, empty the COL_INFO
|
|
|
|
* column, so subdissectors can append information
|
|
|
|
* without having to worry about emptying the column.
|
|
|
|
*
|
|
|
|
* We use "col_add_str()" because the subdissector
|
|
|
|
* might be appending information to the column, in
|
|
|
|
* which case we'd have to zero the buffer out explicitly
|
|
|
|
* anyway.
|
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
if (desegment)
|
2007-10-11 21:23:14 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "");
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2002-02-22 08:56:48 +00:00
|
|
|
while (tvb_reported_length_remaining(tvb, offset) != 0) {
|
2002-07-31 18:45:50 +00:00
|
|
|
/*
|
|
|
|
* Is the first byte of this putative TPKT header
|
|
|
|
* a valid TPKT version number, i.e. 3?
|
|
|
|
*/
|
|
|
|
if (tvb_get_guint8(tvb, offset) != 3) {
|
|
|
|
/*
|
|
|
|
* No, so don't assume this is a TPKT header;
|
|
|
|
* we might be in the middle of TPKT data,
|
|
|
|
* so don't get the length and don't try to
|
|
|
|
* do reassembly.
|
|
|
|
*/
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
|
2009-08-09 07:01:26 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
|
2002-07-31 18:45:50 +00:00
|
|
|
if (tree) {
|
|
|
|
ti = proto_tree_add_item(tree, proto_tpkt, tvb,
|
|
|
|
offset, -1, FALSE);
|
|
|
|
tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);
|
2005-07-12 21:09:34 +00:00
|
|
|
proto_item_set_text(ti, "TPKT");
|
2002-07-31 18:45:50 +00:00
|
|
|
|
|
|
|
proto_tree_add_text(tpkt_tree, tvb, offset, -1,
|
|
|
|
"Continuation data");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-22 08:56:48 +00:00
|
|
|
length_remaining = tvb_length_remaining(tvb, offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can we do reassembly?
|
|
|
|
*/
|
|
|
|
if (desegment && pinfo->can_desegment) {
|
|
|
|
/*
|
|
|
|
* Yes - is the TPKT header split across segment
|
|
|
|
* boundaries?
|
|
|
|
*/
|
|
|
|
if (length_remaining < 4) {
|
|
|
|
/*
|
|
|
|
* Yes. Tell the TCP dissector where
|
|
|
|
* the data for this message starts in
|
|
|
|
* the data it handed us, and how many
|
|
|
|
* more bytes we need, and return.
|
|
|
|
*/
|
|
|
|
pinfo->desegment_offset = offset;
|
|
|
|
pinfo->desegment_len = 4 - length_remaining;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
In the Q.931-over-TPKT-over-TCP dissector, if the TCP segment we're
handed looks as if it contains only a TPKT header (4 bytes long, and
those 4 bytes look like a TPKT header according to "is_tpkt()"), call
the "dissect TPKT over a TCP stream" routine. If we're doing
reassembly, that routine will force a reassembly because the TPKT
payload isn't in that segment, and the various heuristic XXX-over-TPKT
dissectors will be called again, this time with enough data for them to
say whether the TPKT payload is for them or not; if we're not doing
reassembly, we'll dissect the TPKT header and then call the "dissect a
Q.931 PDU" routine, which will throw an exception because there isn't
any payload from which to fetch data (and that's what we want to
happen).
In the "dissect TPKT over a TCP stream" routine, if reassembly is
enabled, do the check to see if we need to do reassembly to get the
payload before dissecting the TPKT header, so that we don't dissect the
TPKT header and then decide "oops, we need some more data to get the
TPKT payload".
svn path=/trunk/; revision=4792
2002-02-23 21:07:48 +00:00
|
|
|
/*
|
|
|
|
* Get the length from the TPKT header.
|
|
|
|
*/
|
|
|
|
data_len = tvb_get_ntohs(tvb, offset + 2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can we do reassembly?
|
|
|
|
*/
|
|
|
|
if (desegment && pinfo->can_desegment) {
|
|
|
|
/*
|
|
|
|
* Yes - is the payload split across segment
|
|
|
|
* boundaries?
|
|
|
|
*/
|
2002-03-05 22:15:21 +00:00
|
|
|
if (length_remaining < data_len) {
|
In the Q.931-over-TPKT-over-TCP dissector, if the TCP segment we're
handed looks as if it contains only a TPKT header (4 bytes long, and
those 4 bytes look like a TPKT header according to "is_tpkt()"), call
the "dissect TPKT over a TCP stream" routine. If we're doing
reassembly, that routine will force a reassembly because the TPKT
payload isn't in that segment, and the various heuristic XXX-over-TPKT
dissectors will be called again, this time with enough data for them to
say whether the TPKT payload is for them or not; if we're not doing
reassembly, we'll dissect the TPKT header and then call the "dissect a
Q.931 PDU" routine, which will throw an exception because there isn't
any payload from which to fetch data (and that's what we want to
happen).
In the "dissect TPKT over a TCP stream" routine, if reassembly is
enabled, do the check to see if we need to do reassembly to get the
payload before dissecting the TPKT header, so that we don't dissect the
TPKT header and then decide "oops, we need some more data to get the
TPKT payload".
svn path=/trunk/; revision=4792
2002-02-23 21:07:48 +00:00
|
|
|
/*
|
|
|
|
* Yes. Tell the TCP dissector where
|
|
|
|
* the data for this message starts in
|
|
|
|
* the data it handed us, and how many
|
|
|
|
* more bytes we need, and return.
|
|
|
|
*/
|
|
|
|
pinfo->desegment_offset = offset;
|
|
|
|
pinfo->desegment_len =
|
2002-03-05 22:15:21 +00:00
|
|
|
data_len - length_remaining;
|
In the Q.931-over-TPKT-over-TCP dissector, if the TCP segment we're
handed looks as if it contains only a TPKT header (4 bytes long, and
those 4 bytes look like a TPKT header according to "is_tpkt()"), call
the "dissect TPKT over a TCP stream" routine. If we're doing
reassembly, that routine will force a reassembly because the TPKT
payload isn't in that segment, and the various heuristic XXX-over-TPKT
dissectors will be called again, this time with enough data for them to
say whether the TPKT payload is for them or not; if we're not doing
reassembly, we'll dissect the TPKT header and then call the "dissect a
Q.931 PDU" routine, which will throw an exception because there isn't
any payload from which to fetch data (and that's what we want to
happen).
In the "dissect TPKT over a TCP stream" routine, if reassembly is
enabled, do the check to see if we need to do reassembly to get the
payload before dissecting the TPKT header, so that we don't dissect the
TPKT header and then decide "oops, we need some more data to get the
TPKT payload".
svn path=/trunk/; revision=4792
2002-02-23 21:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-22 08:56:48 +00:00
|
|
|
/*
|
|
|
|
* Dissect the TPKT header.
|
|
|
|
* Save and restore "pinfo->current_proto".
|
|
|
|
*/
|
|
|
|
saved_proto = pinfo->current_proto;
|
|
|
|
pinfo->current_proto = "TPKT";
|
|
|
|
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
|
2002-03-25 20:17:09 +00:00
|
|
|
/*
|
|
|
|
* Don't add the TPKT header information if we're
|
|
|
|
* reassembling segmented TPKT PDUs or if this
|
|
|
|
* PDU isn't reassembled.
|
|
|
|
*
|
|
|
|
* XXX - the first is so that subdissectors can append
|
|
|
|
* information without getting TPKT stuff in the middle;
|
|
|
|
* why the second?
|
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
if (!desegment && !pinfo->fragmented) {
|
2002-02-22 08:56:48 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO,
|
|
|
|
"TPKT Data length = %u", data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
ti = proto_tree_add_item(tree, proto_tpkt, tvb,
|
|
|
|
offset, 4, FALSE);
|
|
|
|
tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);
|
2005-07-12 21:09:34 +00:00
|
|
|
proto_item_set_text(ti, "TPKT");
|
2002-02-22 08:56:48 +00:00
|
|
|
|
|
|
|
/* Version */
|
|
|
|
proto_tree_add_item(tpkt_tree, hf_tpkt_version, tvb,
|
|
|
|
offset, 1, FALSE);
|
2005-07-12 21:09:34 +00:00
|
|
|
proto_item_append_text(ti, ", Version: 3");
|
2002-02-22 08:56:48 +00:00
|
|
|
|
|
|
|
/* Reserved octet*/
|
|
|
|
proto_tree_add_item(tpkt_tree, hf_tpkt_reserved, tvb,
|
|
|
|
offset + 1, 1, FALSE);
|
|
|
|
|
|
|
|
/* Length */
|
|
|
|
proto_tree_add_uint(tpkt_tree, hf_tpkt_length, tvb,
|
|
|
|
offset + 2, 2, data_len);
|
2005-07-12 21:09:34 +00:00
|
|
|
proto_item_append_text(ti, ", Length: %u", data_len);
|
2002-02-22 08:56:48 +00:00
|
|
|
}
|
|
|
|
pinfo->current_proto = saved_proto;
|
|
|
|
|
|
|
|
/* Skip the TPKT header. */
|
|
|
|
offset += 4;
|
2002-03-05 22:15:21 +00:00
|
|
|
data_len -= 4;
|
2002-02-22 08:56:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a tvbuff containing the amount of the payload
|
|
|
|
* we have available. Make its reported length the
|
|
|
|
* amount of data in this TPKT packet.
|
2002-02-22 11:28:03 +00:00
|
|
|
*
|
|
|
|
* XXX - if reassembly isn't enabled. the subdissector
|
|
|
|
* will throw a BoundsError exception, rather than a
|
|
|
|
* ReportedBoundsError exception. We really want
|
|
|
|
* a tvbuff where the length is "length", the reported
|
|
|
|
* length is "plen + 2", and the "if the snapshot length
|
|
|
|
* were infinite" length were the minimum of the
|
|
|
|
* reported length of the tvbuff handed to us and "plen+2",
|
|
|
|
* with a new type of exception thrown if the offset is
|
|
|
|
* within the reported length but beyond that third length,
|
|
|
|
* with that exception getting the "Unreassembled Packet"
|
|
|
|
* error.
|
2002-02-22 08:56:48 +00:00
|
|
|
*/
|
|
|
|
length = length_remaining - 4;
|
|
|
|
if (length > data_len)
|
|
|
|
length = data_len;
|
|
|
|
next_tvb = tvb_new_subset(tvb, offset, length, data_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the subdissector.
|
2002-02-22 11:28:03 +00:00
|
|
|
*
|
|
|
|
* Catch the ReportedBoundsError exception; if this
|
|
|
|
* particular message happens to get a ReportedBoundsError
|
|
|
|
* exception, that doesn't mean that we should stop
|
|
|
|
* dissecting TPKT messages within this frame or chunk
|
|
|
|
* of reassembled data.
|
|
|
|
*
|
|
|
|
* If it gets a BoundsError, we can stop, as there's nothing
|
|
|
|
* more to see, so we just re-throw it.
|
2002-02-22 08:56:48 +00:00
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
pd_save = pinfo->private_data;
|
2002-02-22 11:28:03 +00:00
|
|
|
TRY {
|
|
|
|
call_dissector(subdissector_handle, next_tvb, pinfo,
|
|
|
|
tree);
|
|
|
|
}
|
|
|
|
CATCH(BoundsError) {
|
|
|
|
RETHROW;
|
|
|
|
}
|
|
|
|
CATCH(ReportedBoundsError) {
|
2010-10-08 17:48:22 +00:00
|
|
|
/* Restore the private_data structure in case one of the
|
|
|
|
* called dissectors modified it (and, due to the exception,
|
|
|
|
* was unable to restore it).
|
|
|
|
*/
|
|
|
|
pinfo->private_data = pd_save;
|
|
|
|
|
2002-02-22 11:28:03 +00:00
|
|
|
show_reported_bounds_error(tvb, pinfo, tree);
|
|
|
|
}
|
|
|
|
ENDTRY;
|
2002-02-22 08:56:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip the payload.
|
|
|
|
*/
|
|
|
|
offset += length;
|
2000-10-19 06:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-28 07:49:41 +00:00
|
|
|
/*
|
|
|
|
* Dissect RFC 1006 TPKT, which wraps a TPKT header around an OSI TP
|
|
|
|
* PDU.
|
|
|
|
*/
|
|
|
|
static void
|
2002-02-22 08:56:48 +00:00
|
|
|
dissect_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
2001-03-28 07:49:41 +00:00
|
|
|
{
|
2002-02-22 08:56:48 +00:00
|
|
|
dissect_tpkt_encap(tvb, pinfo, tree, tpkt_desegment, osi_tp_handle);
|
2001-03-28 07:49:41 +00:00
|
|
|
}
|
|
|
|
|
2007-10-29 07:16:49 +00:00
|
|
|
/*
|
|
|
|
* Dissect RFC 1006 TPKT, which wraps a TPKT header around an X.224
|
|
|
|
* PDU.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dissect_tpkt_x224(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
dissect_tpkt_encap(tvb, pinfo, tree, tpkt_desegment, x224_handle);
|
|
|
|
}
|
2010-10-10 20:07:06 +00:00
|
|
|
|
2007-11-16 08:18:30 +00:00
|
|
|
/*
|
|
|
|
* Dissect ASCII TPKT, which wraps a ASCII TPKT header around an OSI TP
|
|
|
|
* PDU.
|
2010-10-10 20:07:06 +00:00
|
|
|
*/
|
|
|
|
#if 0
|
2007-11-16 08:18:30 +00:00
|
|
|
static void
|
|
|
|
dissect_ascii_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
dissect_asciitpkt(tvb, pinfo, tree, osi_tp_handle);
|
|
|
|
}
|
2010-10-10 20:07:06 +00:00
|
|
|
#endif
|
2007-10-29 07:16:49 +00:00
|
|
|
|
2000-10-19 06:45:11 +00:00
|
|
|
void
|
|
|
|
proto_register_tpkt(void)
|
|
|
|
{
|
2002-08-28 21:04:11 +00:00
|
|
|
static hf_register_info hf[] =
|
2000-10-19 06:45:11 +00:00
|
|
|
{
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
2000-10-19 06:45:11 +00:00
|
|
|
&hf_tpkt_version,
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
|
|
|
"Version",
|
|
|
|
"tpkt.version",
|
|
|
|
FT_UINT8,
|
|
|
|
BASE_DEC,
|
|
|
|
NULL,
|
2000-10-19 06:45:11 +00:00
|
|
|
0x0,
|
2005-07-12 21:09:34 +00:00
|
|
|
"Version, only version 3 is defined", HFILL
|
2000-10-19 06:45:11 +00:00
|
|
|
}
|
|
|
|
},
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
2000-10-19 06:45:11 +00:00
|
|
|
&hf_tpkt_reserved,
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
|
|
|
"Reserved",
|
|
|
|
"tpkt.reserved",
|
|
|
|
FT_UINT8,
|
|
|
|
BASE_DEC,
|
|
|
|
NULL,
|
2000-10-19 06:45:11 +00:00
|
|
|
0x0,
|
2005-07-12 21:09:34 +00:00
|
|
|
"Reserved, should be 0", HFILL
|
2000-10-19 06:45:11 +00:00
|
|
|
}
|
|
|
|
},
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
2000-10-19 06:45:11 +00:00
|
|
|
&hf_tpkt_length,
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
|
|
|
"Length",
|
|
|
|
"tpkt.length",
|
|
|
|
FT_UINT16,
|
|
|
|
BASE_DEC,
|
|
|
|
NULL,
|
2000-10-19 06:45:11 +00:00
|
|
|
0x0,
|
2005-07-12 21:09:34 +00:00
|
|
|
"Length of data unit, including this header", HFILL
|
2000-10-19 06:45:11 +00:00
|
|
|
}
|
|
|
|
},
|
2001-03-28 07:49:41 +00:00
|
|
|
};
|
2002-08-28 21:04:11 +00:00
|
|
|
|
|
|
|
static gint *ett[] =
|
2000-10-19 06:45:11 +00:00
|
|
|
{
|
|
|
|
&ett_tpkt,
|
|
|
|
};
|
2002-02-22 08:56:48 +00:00
|
|
|
module_t *tpkt_module;
|
2000-10-19 06:45:11 +00:00
|
|
|
|
2005-07-12 21:09:34 +00:00
|
|
|
proto_tpkt = proto_register_protocol("TPKT - ISO on TCP - RFC1006", "TPKT", "tpkt");
|
2003-12-02 18:50:52 +00:00
|
|
|
proto_tpkt_ptr = find_protocol_by_id(proto_tpkt);
|
2000-10-19 06:45:11 +00:00
|
|
|
proto_register_field_array(proto_tpkt, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2006-08-27 08:31:29 +00:00
|
|
|
register_dissector("tpkt", dissect_tpkt, proto_tpkt);
|
2010-10-08 17:48:22 +00:00
|
|
|
|
2002-02-22 08:56:48 +00:00
|
|
|
tpkt_module = prefs_register_protocol(proto_tpkt, NULL);
|
|
|
|
prefs_register_bool_preference(tpkt_module, "desegment",
|
2004-08-21 09:02:52 +00:00
|
|
|
"Reassemble TPKT messages spanning multiple TCP segments",
|
|
|
|
"Whether the TPKT dissector should reassemble messages spanning multiple TCP segments. "
|
|
|
|
"To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
|
2002-02-22 08:56:48 +00:00
|
|
|
&tpkt_desegment);
|
2000-10-19 06:45:11 +00:00
|
|
|
}
|
2001-03-28 07:49:41 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_tpkt(void)
|
|
|
|
{
|
2008-09-30 14:49:44 +00:00
|
|
|
dissector_handle_t tpkt_handle, tpkt_x224_handle;
|
2001-12-03 04:00:26 +00:00
|
|
|
|
2001-03-28 07:49:41 +00:00
|
|
|
osi_tp_handle = find_dissector("ositp");
|
2008-09-30 14:49:44 +00:00
|
|
|
tpkt_handle = find_dissector("tpkt");
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", TCP_PORT_TPKT, tpkt_handle);
|
2007-10-29 07:16:49 +00:00
|
|
|
|
|
|
|
x224_handle = find_dissector("x224");
|
2008-09-30 14:49:44 +00:00
|
|
|
tpkt_x224_handle = create_dissector_handle(dissect_tpkt_x224, proto_tpkt);
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", TCP_PORT_TPKT_X224, tpkt_x224_handle);
|
2010-10-08 17:48:22 +00:00
|
|
|
|
2007-11-17 09:17:06 +00:00
|
|
|
/*
|
2008-09-30 14:49:44 +00:00
|
|
|
tpkt_ascii_handle = create_dissector_handle(dissect_ascii_tpkt, proto_tpkt);
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", TCP_PORT_TPKT, tpkt_ascii_handle);
|
2007-11-17 09:17:06 +00:00
|
|
|
*/
|
2010-10-08 17:48:22 +00:00
|
|
|
|
2001-03-28 07:49:41 +00:00
|
|
|
}
|