Add a mechanism by which a dissector can be registered by name, another

dissector can get a "handle" for that dissector by name and then call
that dissector through the handle.

This allows dissectors that can't be called through a port table or a
heuristic table to be called from other dissectors without directly
referring to the dissector function - dynamically-loaded modules, under
Windows, cannot directly call functions in the main program, and
non-plugin dissectors are in the main program and thus cannot be called
from plugin dissectors unless either

	1) a pointer to the dissector is put in the Big Transfer Vector

or

	2) some other mechanism for getting a pointer to the dissector
	   is provided.

This mechanism could also support registering old-style dissectors and
calling them from new-style dissectors without the new-style dissector
having to do the argument translation itself (I didn't add support for
registering old-style dissectors because I'd prefer to have people
tvbuffify their code if they have to register a dissector...).

It could also, in the future, perhaps support

	disabling of protocols;

	setting "pinfo->current_proto";

inside "call_dissector()" - and inside "{old_}dissector_try_port()" and
"{old_"dissector_try_heuristic()" - allowing a pile of stuff that
currently has to be done in every dissector be done by common code.
(I have some ideas about how to do this, by

	having "proto_register_protocol()" take an abbreviation - of the
	sort that would be put in, for example, "pinfo->current_proto" -
	as an argument;

	having the calls to register dissectors take an index returned
	by "proto_register_protocol()" as an argument.

The abbreviation could be used elsewhere as well, e.g. in the "Decoding"
tab of the "Edit->Protocols" dialog box, and in a GUI for constructing
protocol filters.  Watch this space.)

Make "dissect_sdp()" the first client of this mechanism; it's now static
to "packet-sdp.c", and all dissectors that call it - including the MGCP
plugin - now call it through a dissector handle fetched by
"find_dissector()".  (Next step - see if Ethereal can now compile on
Windows as a result of this.)

svn path=/trunk/; revision=2647
This commit is contained in:
Guy Harris 2000-11-15 07:07:52 +00:00
parent 7c3fcbac34
commit 77ad89b12d
13 changed files with 173 additions and 55 deletions

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for Ethereal
#
# $Id: Makefile.am,v 1.245 2000/11/15 05:41:41 guy Exp $
# $Id: Makefile.am,v 1.246 2000/11/15 07:07:43 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@ -242,7 +242,6 @@ noinst_HEADERS = \
packet-rtcp.h \
packet-rtp.h \
packet-rx.h \
packet-sdp.h \
packet-smb.h \
packet-smb-common.h \
packet-sna.h \

View File

@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
* $Id: packet.c,v 1.4 2000/11/13 07:19:24 guy Exp $
* $Id: packet.c,v 1.5 2000/11/15 07:07:46 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -1405,7 +1405,7 @@ dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
void
register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
{
/* Create our hash-of-hashes if it doesn't already exist */
/* Create our hash-of-lists if it doesn't already exist */
if (heur_dissector_lists == NULL) {
heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
g_assert(heur_dissector_lists != NULL);
@ -1418,3 +1418,81 @@ register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissec
g_hash_table_insert(heur_dissector_lists, (gpointer)name,
(gpointer) sub_dissectors);
}
/*
* Register dissectors by name; used if one dissector always calls a
* particular dissector, or if it bases the decision of which dissector
* to call on something other than a numerical value or on "try a bunch
* of dissectors until one likes the packet".
*/
/*
* List of registered dissectors.
*/
static GHashTable *registered_dissectors = NULL;
/*
* An entry in the list of registered dissectors.
*/
struct dissector_handle {
const char *name; /* dissector name */
dissector_t dissector;
};
/* Find a registered dissector by name. */
dissector_handle_t
find_dissector(const char *name)
{
g_assert(registered_dissectors != NULL);
return g_hash_table_lookup(registered_dissectors, name);
}
/* Register a dissector by name. */
void
register_dissector(const char *name, dissector_t dissector)
{
struct dissector_handle *handle;
/* Create our hash table if it doesn't already exist */
if (registered_dissectors == NULL) {
registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
g_assert(registered_dissectors != NULL);
}
/* Make sure the registration is unique */
g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
handle = g_malloc(sizeof (struct dissector_handle));
handle->name = name;
handle->dissector = dissector;
g_hash_table_insert(registered_dissectors, (gpointer)name,
(gpointer) handle);
}
/* Call a dissector through a handle. */
void
old_call_dissector(dissector_handle_t handle, const u_char *pd,
int offset, frame_data *fd, proto_tree *tree)
{
tvbuff_t *tvb;
/*
* Old dissector calling new dissector; use
* "tvb_create_from_top()" to remap.
*
* XXX - what about the "pd" argument? Do
* any dissectors not just pass that along and
* let the "offset" argument handle stepping
* through the packet?
*/
tvb = tvb_create_from_top(offset);
(*handle->dissector)(tvb, &pi, tree);
}
void
call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
packet_info *pinfo, proto_tree *tree)
{
(*handle->dissector)(tvb, pinfo, tree);
}

View File

@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
* $Id: packet.h,v 1.4 2000/11/13 07:19:27 guy Exp $
* $Id: packet.h,v 1.5 2000/11/15 07:07:47 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -249,6 +249,21 @@ gboolean old_dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
gboolean dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
/* Handle for dissectors you call directly. */
typedef struct dissector_handle *dissector_handle_t;
/* Register a dissector. */
void register_dissector(const char *name, dissector_t dissector);
/* Find a dissector by name. */
dissector_handle_t find_dissector(const char *name);
/* Call a dissector through a handle. */
void old_call_dissector(dissector_handle_t handle, const u_char *pd,
int offset, frame_data *fd, proto_tree *tree);
void call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
packet_info *pinfo, proto_tree *tree);
/* Utility routines used by packet*.c */
gchar* ether_to_str(const guint8 *);
gchar* ether_to_str_punct(const guint8 *, char);

View File

@ -1,7 +1,7 @@
/* plugins.c
* plugin routines
*
* $Id: plugins.c,v 1.8 2000/11/13 10:13:18 guy Exp $
* $Id: plugins.c,v 1.9 2000/11/15 07:07:47 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -620,6 +620,11 @@ init_plugins(const char *plugin_dir)
patable.p_heur_dissector_add = heur_dissector_add;
patable.p_register_dissector = p_register_dissector;
patable.p_find_dissector = p_find_dissector;
patable.p_old_call_dissector = p_old_call_dissector;
patable.p_call_dissector = p_call_dissector;
patable.p_dissect_data = dissect_data;
patable.p_old_dissect_data = old_dissect_data;

View File

@ -4,7 +4,7 @@
* Jason Lango <jal@netapp.com>
* Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
*
* $Id: packet-rtsp.c,v 1.25 2000/11/13 08:58:10 guy Exp $
* $Id: packet-rtsp.c,v 1.26 2000/11/15 07:07:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -39,7 +39,6 @@
#include <glib.h>
#include "packet.h"
#include "packet-sdp.h"
#include "packet-rtp.h"
#include "packet-rtcp.h"
#include "conversation.h"
@ -74,6 +73,8 @@ static const char *rtsp_methods[] = {
#define RTSP_NMETHODS (sizeof rtsp_methods / sizeof rtsp_methods[0])
static dissector_handle_t sdp_handle;
static rtsp_type_t
is_rtsp_request_or_reply(const u_char *line, int linelen)
{
@ -359,7 +360,7 @@ dissect_rtsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
* dissect it.
*/
new_tvb = tvb_new_subset(tvb, offset, -1, -1);
dissect_sdp(new_tvb, pinfo, tree);
call_dissector(sdp_handle, new_tvb, pinfo, tree);
}
} else {
if (datalen > 0) {
@ -463,4 +464,9 @@ void
proto_reg_handoff_rtsp(void)
{
dissector_add("tcp.port", TCP_PORT_RTSP, dissect_rtsp);
/*
* Get a handle for the SDP dissector.
*/
sdp_handle = find_dissector("sdp");
}

View File

@ -4,7 +4,7 @@
*
* Heikki Vatiainen <hessu@cs.tut.fi>
*
* $Id: packet-sap.c,v 1.13 2000/11/10 06:50:36 guy Exp $
* $Id: packet-sap.c,v 1.14 2000/11/15 07:07:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -43,7 +43,6 @@
#include <glib.h>
#include "packet.h"
#include "packet-ipv6.h"
#include "packet-sdp.h"
#define UDP_PORT_SAP 9875
@ -126,6 +125,8 @@ static gint ett_sap_flags = -1;
static gint ett_sap_auth = -1;
static gint ett_sap_authf = -1;
static dissector_handle_t sdp_handle;
static void
dissect_sap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@ -277,7 +278,7 @@ dissect_sap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
/* Done with SAP */
dissect_sdp(tvb, pinfo, tree);
call_dissector(sdp_handle, tvb, pinfo, tree);
}
return;
@ -363,4 +364,9 @@ void
proto_reg_handoff_sap(void)
{
dissector_add("udp.port", UDP_PORT_SAP, dissect_sap);
/*
* Get a handle for the SDP dissector.
*/
sdp_handle = find_dissector("sdp");
}

View File

@ -4,7 +4,7 @@
* Jason Lango <jal@netapp.com>
* Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
*
* $Id: packet-sdp.c,v 1.15 2000/11/13 08:58:12 guy Exp $
* $Id: packet-sdp.c,v 1.16 2000/11/15 07:07:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -45,7 +45,7 @@ static int proto_sdp = -1;
static int ett_sdp = -1;
void
static void
dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
proto_tree *sdp_tree;
@ -218,4 +218,12 @@ proto_register_sdp(void)
proto_sdp = proto_register_protocol("Session Description Protocol", "sdp");
/* proto_register_field_array(proto_sdp, hf, array_length(hf));*/
proto_register_subtree_array(ett, array_length(ett));
/*
* Register the dissector by name, so other dissectors can
* grab it by name rather than just referring to it directly
* (you can't refer to it directly from a plugin dissector
* on Windows without stuffing it into the Big Transfer Vector).
*/
register_dissector("sdp", dissect_sdp);
}

View File

@ -1,30 +0,0 @@
/* packet-sdp.h
*
* $Id: packet-sdp.h,v 1.3 2000/11/10 06:50:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* Copyright 1998 Gerald Combs
*
*
* 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.
*/
#ifndef __PACKET_SDP_H__
#define __PACKET_SDP_H__
void dissect_sdp(tvbuff_t *, packet_info *, proto_tree *);
#endif

View File

@ -7,7 +7,7 @@
*
* Copyright 2000, Heikki Vatiainen <hessu@cs.tut.fi>
*
* $Id: packet-sip.c,v 1.4 2000/11/13 09:04:27 guy Exp $
* $Id: packet-sip.c,v 1.5 2000/11/15 07:07:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -40,7 +40,6 @@
#include <glib.h>
#include "packet.h"
#include "packet-sdp.h"
#define TCP_PORT_SIP 5060
#define UDP_PORT_SIP 5060
@ -66,6 +65,8 @@ static const char *sip_methods[] = {
static int sip_is_request(tvbuff_t *tvb, guint32 offset);
static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset);
static dissector_handle_t sdp_handle;
/* Code to actually dissect the packets */
static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@ -120,7 +121,7 @@ static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (tvb_length_remaining(tvb, offset) > 0) {
next_tvb = tvb_new_subset(tvb, offset, -1, -1);
dissect_sdp(next_tvb, pinfo, tree);
call_dissector(sdp_handle, next_tvb, pinfo, tree);
}
return;
@ -195,4 +196,9 @@ proto_reg_handoff_sip(void)
{
dissector_add("tcp.port", TCP_PORT_SIP, dissect_sip);
dissector_add("udp.port", UDP_PORT_SIP, dissect_sip);
/*
* Get a handle for the SDP dissector.
*/
sdp_handle = find_dissector("sdp");
}

View File

@ -2,7 +2,7 @@
* Routines for mgcp packet disassembly
* RFC 2705
*
* $Id: packet-mgcp.c,v 1.4 2000/11/12 11:08:46 guy Exp $
* $Id: packet-mgcp.c,v 1.5 2000/11/15 07:07:52 guy Exp $
*
* Copyright (c) 2000 by Ed Warnicke <hagbard@physics.rutgers.edu>
*
@ -47,7 +47,6 @@
#include <time.h>
#include <string.h>
#include "packet.h"
#include "packet-sdp.h"
#include "resolv.h"
#include "prefs.h"
#include "strutil.h"
@ -182,6 +181,8 @@ static gint tvb_section_length(tvbuff_t* tvb, gint tvb_sectionbegin,
gint tvb_sectionend);
static gboolean is_rfc2234_alpha(guint8 c);
static dissector_handle_t sdp_handle;
/*
* dissect_mgcp - The dissector for the Media Gateway Control Protocol
*/
@ -273,7 +274,7 @@ dissect_mgcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
tvb_sectionbegin++;
next_tvb = tvb_new_subset(tvb, tvb_sectionbegin, -1, -1);
dissect_sdp(next_tvb, pinfo, tree);
call_dissector(sdp_handle, next_tvb, pinfo, tree);
}
}
/*
@ -1087,6 +1088,11 @@ static gint tvb_section_length(tvbuff_t* tvb, gint tvb_sectionbegin,
/* Start the functions we need for the plugin stuff */
void plugin_reg_handoff(void){
proto_reg_handoff_mgcp();
/*
* Get a handle for the SDP dissector.
*/
sdp_handle = find_dissector("sdp");
}
DLLEXPORT void plugin_init(plugin_address_table_t *pat){
@ -1103,5 +1109,3 @@ DLLEXPORT void plugin_init(plugin_address_table_t *pat){
dfilter_init();
}
/* End the functions we need for plugin stuff */

View File

@ -1,7 +1,7 @@
/* plugin_api.c
* Routines for Ethereal plugins.
*
* $Id: plugin_api.c,v 1.12 2000/11/14 10:38:13 guy Exp $
* $Id: plugin_api.c,v 1.13 2000/11/15 07:07:49 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@xiexie.org>
@ -53,6 +53,10 @@ plugin_address_table_init(plugin_address_table_t *pat)
p_old_dissector_add = pat->p_old_dissector_add;
p_dissector_delete = pat->p_dissector_delete;
p_heur_dissector_add = pat->p_heur_dissector_add;
p_register_dissector = pat->p_register_dissector;
p_find_dissector = pat->p_find_dissector;
p_old_call_dissector = pat->p_old_call_dissector;
p_call_dissector = pat->p_call_dissector;
p_dissect_data = pat->p_dissect_data;
p_old_dissect_data = pat->p_old_dissect_data;
p_proto_is_protocol_enabled = pat->p_proto_is_protocol_enabled;

View File

@ -1,7 +1,7 @@
/* plugin_api.h
* Routines for Ethereal plugins.
*
* $Id: plugin_api.h,v 1.11 2000/11/14 10:38:13 guy Exp $
* $Id: plugin_api.h,v 1.12 2000/11/15 07:07:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@xiexie.org>
@ -57,6 +57,11 @@
#define heur_dissector_add (*p_heur_dissector_add)
#define register_dissector (*p_register_dissector)
#define find_dissector (*p_find_dissector)
#define old_call_dissector (*p_old_call_dissector)
#define call_dissector (*p_call_dissector)
#define dissect_data (*p_dissect_data)
#define old_dissect_data (*p_old_dissect_data)

View File

@ -1,7 +1,7 @@
/* plugin_table.h
* Table of exported addresses for Ethereal plugins.
*
* $Id: plugin_table.h,v 1.8 2000/11/14 10:38:13 guy Exp $
* $Id: plugin_table.h,v 1.9 2000/11/15 07:07:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@xiexie.org>
@ -49,6 +49,13 @@ typedef void (*addr_dissector_delete)(const char *, guint32, dissector_t);
typedef void (*addr_heur_dissector_add)(const char *, heur_dissector_t);
typedef void (*addr_register_dissector)(const char *, dissector_t);
typedef dissector_handle_t (*addr_find_dissector)(const char *);
typedef void (*addr_old_call_dissector)(dissector_handle_t, const u_char *,
int, frame_data *, proto_tree *);
typedef void (*addr_call_dissector)(dissector_handle_t, tvbuff_t *,
packet_info *, proto_tree *);
typedef void (*addr_dissect_data)(tvbuff_t *, packet_info *, proto_tree *);
typedef void (*addr_old_dissect_data)(const u_char *, int, frame_data *, proto_tree *);
@ -187,6 +194,11 @@ typedef struct {
addr_heur_dissector_add p_heur_dissector_add;
addr_register_dissector p_register_dissector;
addr_find_dissector p_find_dissector;
addr_old_call_dissector p_old_call_dissector;
addr_call_dissector p_call_dissector;
addr_dissect_data p_dissect_data;
addr_old_dissect_data p_old_dissect_data;