2005-06-04 19:22:39 +00:00
|
|
|
/* packet-user_encap.c
|
2005-07-25 19:06:02 +00:00
|
|
|
* Allow users to specify the dissectors for DLTs
|
2008-08-05 21:03:46 +00:00
|
|
|
* Luis E. Garcia Ontanon <luis@ontanon.org>
|
2005-06-04 19:22:39 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-06-04 19:22:39 +00:00
|
|
|
* Copyright 1998
|
|
|
|
*
|
|
|
|
* 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
|
2011-05-08 20:22:18 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2005-06-04 19:22:39 +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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-06-04 19:22:39 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2005-06-04 19:22:39 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
2007-02-07 20:45:14 +00:00
|
|
|
#include <epan/expert.h>
|
2005-06-04 19:22:39 +00:00
|
|
|
#include <epan/prefs.h>
|
2007-02-07 20:45:14 +00:00
|
|
|
#include <epan/uat.h>
|
|
|
|
#include <epan/emem.h>
|
2005-06-04 19:22:39 +00:00
|
|
|
|
2007-03-27 21:09:34 +00:00
|
|
|
#ifdef _MSC_VER
|
2007-03-27 02:14:56 +00:00
|
|
|
/* disable: warning C4090: 'XY' : different 'const' qualifiers */
|
|
|
|
#pragma warning(disable:4090)
|
|
|
|
#endif
|
|
|
|
|
2005-06-04 19:22:39 +00:00
|
|
|
typedef struct _user_encap_t {
|
2011-06-20 02:27:31 +00:00
|
|
|
guint encap;
|
|
|
|
char* payload_proto_name;
|
|
|
|
dissector_handle_t payload_proto;
|
|
|
|
char* header_proto_name;
|
|
|
|
dissector_handle_t header_proto;
|
|
|
|
char* trailer_proto_name;
|
|
|
|
dissector_handle_t trailer_proto;
|
|
|
|
guint header_size;
|
|
|
|
guint trailer_size;
|
2005-06-04 19:22:39 +00:00
|
|
|
} user_encap_t;
|
|
|
|
|
2007-02-09 03:11:14 +00:00
|
|
|
#define ENCAP0_STR "User 0 (DLT=147)"
|
2007-02-07 20:45:14 +00:00
|
|
|
static const value_string user_dlts[] = {
|
2011-06-20 02:27:31 +00:00
|
|
|
{ WTAP_ENCAP_USER0, ENCAP0_STR},
|
|
|
|
{ WTAP_ENCAP_USER1, "User 1 (DLT=148)"},
|
|
|
|
{ WTAP_ENCAP_USER2, "User 2 (DLT=149)"},
|
|
|
|
{ WTAP_ENCAP_USER3, "User 3 (DLT=150)"},
|
|
|
|
{ WTAP_ENCAP_USER4, "User 4 (DLT=151)"},
|
|
|
|
{ WTAP_ENCAP_USER5, "User 5 (DLT=152)"},
|
|
|
|
{ WTAP_ENCAP_USER6, "User 6 (DLT=153)"},
|
|
|
|
{ WTAP_ENCAP_USER7, "User 7 (DLT=154)"},
|
|
|
|
{ WTAP_ENCAP_USER8, "User 8 (DLT=155)"},
|
|
|
|
{ WTAP_ENCAP_USER9, "User 9 (DLT=156)"},
|
|
|
|
{ WTAP_ENCAP_USER10, "User 10 (DLT=157)"},
|
|
|
|
{ WTAP_ENCAP_USER11, "User 11 (DLT=158)"},
|
|
|
|
{ WTAP_ENCAP_USER12, "User 12 (DLT=159)"},
|
|
|
|
{ WTAP_ENCAP_USER13, "User 13 (DLT=160)"},
|
|
|
|
{ WTAP_ENCAP_USER14, "User 14 (DLT=161)"},
|
|
|
|
{ WTAP_ENCAP_USER15, "User 15 (DLT=162)"},
|
|
|
|
{ 0, NULL }
|
2005-06-04 19:22:39 +00:00
|
|
|
};
|
2007-02-07 20:45:14 +00:00
|
|
|
static int proto_user_encap = -1;
|
2005-06-04 19:22:39 +00:00
|
|
|
|
2013-05-28 03:11:44 +00:00
|
|
|
static expert_field ei_user_encap_not_handled = EI_INIT;
|
|
|
|
|
2007-02-07 20:45:14 +00:00
|
|
|
static user_encap_t* encaps = NULL;
|
|
|
|
static guint num_encaps = 0;
|
|
|
|
static uat_t* encaps_uat;
|
|
|
|
static dissector_handle_t data_handle;
|
2005-06-04 19:22:39 +00:00
|
|
|
|
2007-02-07 20:45:14 +00:00
|
|
|
static void dissect_user(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
|
2011-06-20 02:27:31 +00:00
|
|
|
user_encap_t* encap = NULL;
|
|
|
|
tvbuff_t* payload_tvb;
|
|
|
|
proto_item* item;
|
2013-05-18 17:08:46 +00:00
|
|
|
gint len, reported_len;
|
2011-06-20 02:27:31 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_encaps; i++) {
|
|
|
|
if (encaps[i].encap == pinfo->match_uint) {
|
|
|
|
encap = &(encaps[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:10:19 +00:00
|
|
|
item = proto_tree_add_item(tree,proto_user_encap,tvb,0,-1,ENC_NA);
|
2011-06-20 02:27:31 +00:00
|
|
|
if (!encap) {
|
|
|
|
char* msg = ep_strdup_printf("User encapsulation not handled: DLT=%d, "
|
|
|
|
"check your Preferences->Protocols->DLT_USER",
|
|
|
|
pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
|
|
|
|
proto_item_set_text(item,"%s",msg);
|
2013-05-28 03:11:44 +00:00
|
|
|
expert_add_info_format_text(pinfo, item, &ei_user_encap_not_handled, "%s", msg);
|
2011-06-20 02:27:31 +00:00
|
|
|
|
|
|
|
call_dissector(data_handle, tvb, pinfo, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (encap->payload_proto == NULL) {
|
|
|
|
char* msg = ep_strdup_printf("User encapsulation's protocol %s not found: "
|
|
|
|
"DLT=%d, check your Preferences->Protocols->DLT_USER",
|
|
|
|
encap->payload_proto_name,
|
|
|
|
pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
|
|
|
|
proto_item_set_text(item,"%s",msg);
|
2013-05-28 03:11:44 +00:00
|
|
|
expert_add_info_format_text(pinfo, item, &ei_user_encap_not_handled, "%s", msg);
|
2011-06-20 02:27:31 +00:00
|
|
|
|
|
|
|
call_dissector(data_handle, tvb, pinfo, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_item_set_text(item,"DLT: %d",pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
|
|
|
|
|
|
|
|
if (encap->header_size) {
|
|
|
|
tvbuff_t* hdr_tvb = tvb_new_subset(tvb, 0, encap->header_size, encap->header_size);
|
|
|
|
call_dissector(encap->header_proto, hdr_tvb, pinfo, tree);
|
|
|
|
if (encap->header_proto_name) {
|
|
|
|
const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->header_proto_name));
|
|
|
|
if (proto_name) {
|
|
|
|
proto_item_append_text(item, ", Header: %s (%s)", encap->header_proto_name, proto_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-18 17:08:46 +00:00
|
|
|
len = tvb_length(tvb) - (encap->header_size + encap->trailer_size);
|
|
|
|
reported_len = tvb_reported_length(tvb) - (encap->header_size + encap->trailer_size);
|
|
|
|
|
|
|
|
payload_tvb = tvb_new_subset(tvb, encap->header_size, len, reported_len);
|
2011-06-20 02:27:31 +00:00
|
|
|
call_dissector(encap->payload_proto, payload_tvb, pinfo, tree);
|
|
|
|
if (encap->payload_proto_name) {
|
|
|
|
const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->payload_proto_name));
|
|
|
|
if (proto_name) {
|
|
|
|
proto_item_append_text(item, ", Payload: %s (%s)", encap->payload_proto_name, proto_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encap->trailer_size) {
|
|
|
|
tvbuff_t* trailer_tvb = tvb_new_subset(tvb, encap->header_size + len, encap->trailer_size, encap->trailer_size);
|
|
|
|
call_dissector(encap->trailer_proto, trailer_tvb, pinfo, tree);
|
|
|
|
if (encap->trailer_proto_name) {
|
|
|
|
const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->trailer_proto_name));
|
|
|
|
if (proto_name) {
|
|
|
|
proto_item_append_text(item, ", Trailer: %s (%s)", encap->trailer_proto_name, proto_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-04 19:22:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 19:13:26 +00:00
|
|
|
static void* user_copy_cb(void* dest, const void* orig, size_t len _U_)
|
2009-03-08 22:31:28 +00:00
|
|
|
{
|
2013-03-19 22:03:00 +00:00
|
|
|
const user_encap_t *o = (const user_encap_t *)orig;
|
|
|
|
user_encap_t *d = (user_encap_t *)dest;
|
2009-03-08 22:31:28 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
d->payload_proto_name = g_strdup(o->payload_proto_name);
|
|
|
|
d->header_proto_name = g_strdup(o->header_proto_name);
|
|
|
|
d->trailer_proto_name = g_strdup(o->trailer_proto_name);
|
2009-03-08 22:31:28 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
return d;
|
2009-03-08 22:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void user_free_cb(void* record)
|
|
|
|
{
|
2013-03-19 22:03:00 +00:00
|
|
|
user_encap_t *u = (user_encap_t *)record;
|
2009-03-08 22:31:28 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
g_free(u->payload_proto_name);
|
|
|
|
g_free(u->header_proto_name);
|
|
|
|
g_free(u->trailer_proto_name);
|
2007-02-07 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2013-03-12 06:40:13 +00:00
|
|
|
UAT_VS_DEF(user_encap, encap, user_encap_t, guint, WTAP_ENCAP_USER0, ENCAP0_STR)
|
2007-05-25 16:47:22 +00:00
|
|
|
UAT_PROTO_DEF(user_encap, payload_proto, payload_proto, payload_proto_name, user_encap_t)
|
2007-02-07 20:45:14 +00:00
|
|
|
UAT_DEC_CB_DEF(user_encap, header_size, user_encap_t)
|
|
|
|
UAT_DEC_CB_DEF(user_encap, trailer_size, user_encap_t)
|
2007-05-25 16:47:22 +00:00
|
|
|
UAT_PROTO_DEF(user_encap, header_proto, header_proto, header_proto_name, user_encap_t)
|
|
|
|
UAT_PROTO_DEF(user_encap, trailer_proto, trailer_proto, trailer_proto_name, user_encap_t)
|
2007-02-07 20:45:14 +00:00
|
|
|
|
|
|
|
void proto_reg_handoff_user_encap(void)
|
|
|
|
{
|
2011-06-20 02:27:31 +00:00
|
|
|
dissector_handle_t user_encap_handle;
|
|
|
|
guint i;
|
2011-06-19 19:13:26 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
user_encap_handle = find_dissector("user_dlt");
|
|
|
|
data_handle = find_dissector("data");
|
2011-06-19 19:13:26 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
for (i = WTAP_ENCAP_USER0 ; i <= WTAP_ENCAP_USER15; i++)
|
|
|
|
dissector_add_uint("wtap_encap", i, user_encap_handle);
|
2005-06-04 19:22:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-07 20:45:14 +00:00
|
|
|
|
2005-06-04 19:22:39 +00:00
|
|
|
void proto_register_user_encap(void)
|
|
|
|
{
|
2011-06-20 02:27:31 +00:00
|
|
|
module_t *module;
|
2013-05-28 03:11:44 +00:00
|
|
|
expert_module_t* expert_user_encap;
|
2011-06-20 02:27:31 +00:00
|
|
|
|
|
|
|
static uat_field_t user_flds[] = {
|
|
|
|
UAT_FLD_VS(user_encap,encap,"DLT",user_dlts,"The DLT"),
|
|
|
|
UAT_FLD_PROTO(user_encap,payload_proto,"Payload protocol",
|
|
|
|
"Protocol to be used for the payload of this DLT"),
|
|
|
|
UAT_FLD_DEC(user_encap,header_size,"Header size",
|
|
|
|
"Size of an eventual header that precedes the actual payload, 0 means none"),
|
|
|
|
UAT_FLD_PROTO(user_encap,header_proto,"Header protocol",
|
|
|
|
"Protocol to be used for the header (empty = data)"),
|
|
|
|
UAT_FLD_DEC(user_encap,trailer_size,"Trailer size",
|
|
|
|
"Size of an eventual trailer that follows the actual payload, 0 means none"),
|
|
|
|
UAT_FLD_PROTO(user_encap,trailer_proto,"Trailer protocol",
|
|
|
|
"Protocol to be used for the trailer (empty = data)"),
|
|
|
|
UAT_END_FIELDS
|
|
|
|
};
|
|
|
|
|
2013-05-28 03:11:44 +00:00
|
|
|
static ei_register_info ei[] = {
|
|
|
|
{ &ei_user_encap_not_handled, { "user_dlt.not_handled", PI_UNDECODED, PI_WARN, "Formatted text", EXPFILL }},
|
|
|
|
};
|
2011-06-20 02:27:31 +00:00
|
|
|
|
|
|
|
proto_user_encap = proto_register_protocol("DLT User","DLT_USER","user_dlt");
|
2013-05-28 03:11:44 +00:00
|
|
|
expert_user_encap = expert_register_protocol(proto_user_encap);
|
|
|
|
expert_register_field_array(expert_user_encap, ei, array_length(ei));
|
2011-06-20 02:27:31 +00:00
|
|
|
|
|
|
|
module = prefs_register_protocol(proto_user_encap, NULL);
|
|
|
|
|
|
|
|
encaps_uat = uat_new("User DLTs Table",
|
|
|
|
sizeof(user_encap_t),
|
|
|
|
"user_dlts",
|
|
|
|
TRUE,
|
2013-03-19 22:03:00 +00:00
|
|
|
(void**) &encaps,
|
2011-06-20 02:27:31 +00:00
|
|
|
&num_encaps,
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
UAT_AFFECTS_DISSECTION, /* affects dissection of packets, but not set of named fields */
|
2011-06-20 02:27:31 +00:00
|
|
|
"ChUserDLTsSection",
|
|
|
|
user_copy_cb,
|
|
|
|
NULL,
|
|
|
|
user_free_cb,
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
NULL,
|
2011-06-20 02:27:31 +00:00
|
|
|
user_flds );
|
2011-06-19 19:13:26 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
prefs_register_uat_preference(module,
|
|
|
|
"encaps_table",
|
|
|
|
"Encapsulations Table",
|
|
|
|
"A table that enumerates the various protocols to be used against a certain user DLT",
|
|
|
|
encaps_uat);
|
2011-06-19 19:13:26 +00:00
|
|
|
|
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
register_dissector("user_dlt",dissect_user,proto_user_encap);
|
2007-02-07 20:45:14 +00:00
|
|
|
|
2011-06-20 02:27:31 +00:00
|
|
|
/*
|
|
|
|
prefs_register_protocol_obsolete(proto_register_protocol("DLT User A","DLT_USER_A","user_dlt_a"));
|
|
|
|
prefs_register_protocol_obsolete(proto_register_protocol("DLT User B","DLT_USER_B","user_dlt_b"));
|
|
|
|
prefs_register_protocol_obsolete(proto_register_protocol("DLT User C","DLT_USER_C","user_dlt_c"));
|
|
|
|
prefs_register_protocol_obsolete(proto_register_protocol("DLT User D","DLT_USER_D","user_dlt_d"));
|
|
|
|
*/
|
2005-06-04 19:22:39 +00:00
|
|
|
}
|