/* reassemble.h
* Declarations of outines for {fragment,segment} reassembly
*
- * $Id$
- *
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* make sure that all flags that are set in a fragment entry is also set for
* the flags field of fd_head !!!
*/
+#ifndef REASSEMBLE_H
+#define REASSEMBLE_H
+
+#include "ws_symbol_export.h"
+
/* only in fd_head: packet is defragmented */
#define FD_DEFRAGMENTED 0x0001
/* more than one fragment which indicates end-of data */
#define FD_MULTIPLETAILS 0x0008
-/* fragment contains data past the end of the datagram */
+/* fragment starts before the end of the datagram but extends
+ past the end of the datagram */
#define FD_TOOLONGFRAGMENT 0x0010
-/* fragment data not alloc'ed, fd->data pointing to fd_head->data+fd->offset */
-#define FD_NOT_MALLOCED 0x0020
+/* fragment tvb is subset, don't tvb_free() it */
+#define FD_SUBSET_TVB 0x0020
/* this flag is used to request fragment_add to continue the reassembly process */
#define FD_PARTIAL_REASSEMBLY 0x0040
*/
#define FD_DATALEN_SET 0x0400
-typedef struct _fragment_data {
- struct _fragment_data *next;
- guint32 frame;
- guint32 offset;
- guint32 len;
+typedef struct _fragment_item {
+ struct _fragment_item *next;
+ guint32 frame; /* XXX - does this apply to reassembly heads? */
+ guint32 offset; /* XXX - does this apply to reassembly heads? */
+ guint32 len; /* XXX - does this apply to reassembly heads? */
+ guint32 fragment_nr_offset; /* offset for frame numbering, for sequences, where the
+ * provided fragment number of the first fragment does
+ * not start with 0
+ * XXX - does this apply only to reassembly heads? */
guint32 datalen; /* Only valid in first item of list and when
* flags&FD_DATALEN_SET is set;
* number of bytes or (if flags&FD_BLOCKSEQUENCE set)
guint32 reassembled_in; /* frame where this PDU was reassembled,
only valid in the first item of the list
and when FD_DEFRAGMENTED is set*/
- guint32 flags;
- unsigned char *data;
-} fragment_data;
+ guint32 flags; /* XXX - do some of these apply only to reassembly
+ heads and others only to fragments within
+ a reassembly? */
+ tvbuff_t *tvb_data;
+
+ /*
+ * Null if the reassembly had no error; non-null if it had
+ * an error, in which case it's the string for the error.
+ *
+ * XXX - this is wasted in all but the reassembly head; we
+ * should probably have separate data structures for a
+ * reassembly and for the fragments in a reassembly.
+ */
+ const char *error;
+} fragment_item, fragment_head;
/*
* in the tvb, and if not, do something a bit odd. */
#define REASSEMBLE_FLAGS_CHECK_DATA_PRESENT 0x0004
-/* a function for copying hash keys */
-typedef void *(*fragment_key_copier)(const void *key);
+/* a function for creating temporary hash keys */
+typedef gpointer (*fragment_temporary_key)(const packet_info *pinfo,
+ const guint32 id, const void *data);
+/* a function for creating persistent hash keys */
+typedef gpointer (*fragment_persistent_key)(const packet_info *pinfo,
+ const guint32 id, const void *data);
/*
- * Initialize a fragment table.
+ * Data structure to keep track of fragments and reassemblies.
*/
-extern void fragment_table_init(GHashTable **fragment_table);
-extern void dcerpc_fragment_table_init(GHashTable **fragment_table);
+typedef struct {
+ GHashTable *fragment_table;
+ GHashTable *reassembled_table;
+ fragment_temporary_key temporary_key_func;
+ fragment_persistent_key persistent_key_func;
+ GDestroyNotify free_temporary_key_func; /* temporary key destruction function */
+} reassembly_table;
/*
- * Initialize a reassembled-packet table.
+ * Table of functions for a reassembly table.
*/
-extern void reassembled_table_init(GHashTable **reassembled_table);
+typedef struct {
+ /* Functions for fragment table */
+ GHashFunc hash_func; /* hash function */
+ GEqualFunc equal_func; /* comparison function */
+ fragment_temporary_key temporary_key_func; /* temporary key creation function */
+ fragment_persistent_key persistent_key_func; /* persistent key creation function */
+ GDestroyNotify free_temporary_key_func; /* temporary key destruction function */
+ GDestroyNotify free_persistent_key_func; /* persistent key destruction function */
+} reassembly_table_functions;
/*
- * Free up all space allocated for fragment keys and data.
+ * Tables of functions exported for the benefit of dissectors that
+ * don't need special items in their keys.
*/
-void reassemble_cleanup(void);
+WS_DLL_PUBLIC const reassembly_table_functions
+ addresses_reassembly_table_functions; /* keys have endpoint addresses and an ID */
+WS_DLL_PUBLIC const reassembly_table_functions
+ addresses_ports_reassembly_table_functions; /* keys have endpoint addresses and ports and an ID */
/*
- * Initialise fragment keys and data.
+ * Initialize/destroy a reassembly table.
+ *
+ * init: If table doesn't exist: create table;
+ * else: just remove any entries;
+ * destroy: remove entries and destroy table;
*/
-void reassemble_init(void);
+WS_DLL_PUBLIC void
+reassembly_table_init(reassembly_table *table,
+ const reassembly_table_functions *funcs);
+WS_DLL_PUBLIC void
+reassembly_table_destroy(reassembly_table *table);
/*
- * This function adds a new fragment to the fragment hash table.
+ * This function adds a new fragment to the reassembly table
* If this is the first fragment seen for this datagram, a new entry
- * is created in the hash table, otherwise this fragment is just added
+ * is created in the table, otherwise this fragment is just added
* to the linked list of fragments for this packet.
* The list of fragments for a specific datagram is kept sorted for
* easier handling.
* Returns a pointer to the head of the fragment data list if we have all the
* fragments, NULL otherwise.
*/
-extern fragment_data *fragment_add(tvbuff_t *tvb, const int offset, const packet_info *pinfo,
- const guint32 id, GHashTable *fragment_table, const guint32 frag_offset,
- guint32 const frag_data_len, const gboolean more_frags);
-extern fragment_data *fragment_add_multiple_ok(tvbuff_t *tvb, const int offset,
- const packet_info *pinfo, const guint32 id, GHashTable *fragment_table,
- const guint32 frag_offset, const guint32 frag_data_len, const gboolean more_frags);
+WS_DLL_PUBLIC fragment_head *
+fragment_add(reassembly_table *table, tvbuff_t *tvb, const int offset,
+ const packet_info *pinfo, const guint32 id, const void *data,
+ const guint32 frag_offset, const guint32 frag_data_len,
+ const gboolean more_frags);
+WS_DLL_PUBLIC fragment_head *
+fragment_add_multiple_ok(reassembly_table *table, tvbuff_t *tvb,
+ const int offset, const packet_info *pinfo,
+ const guint32 id, const void *data,
+ const guint32 frag_offset,
+ const guint32 frag_data_len,
+ const gboolean more_frags);
/*
- * This routine extends fragment_add to use a "reassembled_table".
+ * This routine extends fragment_add to use a "reassembled_table"
+ * included in the reassembly table.
*
* If, after processing this fragment, we have all the fragments, they
* remove that from the fragment hash table if necessary and add it
* to the table of reassembled fragments, and return a pointer to the
* head of the fragment list.
*/
-extern fragment_data *fragment_add_check(tvbuff_t *tvb, const int offset,
- const packet_info *pinfo, const guint32 id, GHashTable *fragment_table,
- GHashTable *reassembled_table, const guint32 frag_offset,
- const guint32 frag_data_len, const gboolean more_frags);
+WS_DLL_PUBLIC fragment_head *
+fragment_add_check(reassembly_table *table, tvbuff_t *tvb, const int offset,
+ const packet_info *pinfo, const guint32 id,
+ const void *data, const guint32 frag_offset,
+ const guint32 frag_data_len, const gboolean more_frags);
/* same as fragment_add() but this one assumes frag_number is a block
sequence number. note that frag_number is 0 for the first fragment. */
* the first fragment of each datagram).
*
* If this is the first fragment seen for this datagram, a new
- * "fragment_data" structure is allocated to refer to the reassembled
+ * "fragment_head" structure is allocated to refer to the reassembled
* packet, and:
*
* if "more_frags" is false, and either we have no sequence numbers, or
* returned list to see if this case was hit or not.
*
* Otherwise, this fragment is just added to the linked list of fragments
- * for this packet; the fragment_data is also added to the fragment hash if
+ * for this packet; the fragment_item is also added to the fragment hash if
* necessary.
*
* If this packet completes assembly, these functions return the head of the
* fragment data; otherwise, they return null.
*/
-
-/* "key" should be an arbitrary key used for indexing the fragment hash;
- * "key_copier" is called to copy the key to a more appropriate store before
- * inserting a new entry to the hash.
- */
-extern fragment_data *
-fragment_add_seq_key(tvbuff_t *tvb, const int offset, const packet_info *pinfo,
- void *key, fragment_key_copier key_copier,
- GHashTable *fragment_table, guint32 frag_number,
- const guint32 frag_data_len, const gboolean more_frags,
- const guint32 flags);
-
-/* a wrapper for fragment_add_seq_key - uses a key of source, dest and id */
-extern fragment_data *fragment_add_seq(tvbuff_t *tvb, const int offset, const packet_info *pinfo,
- const guint32 id, GHashTable *fragment_table, const guint32 frag_number,
- const guint32 frag_data_len, const gboolean more_frags);
-
-/* another wrapper for fragment_add_seq_key - uses a key of source, dest, id
- * and act_id */
-extern fragment_data *
-fragment_add_dcerpc_dg(tvbuff_t *tvb, const int offset, const packet_info *pinfo, const guint32 id,
- void *act_id,
- GHashTable *fragment_table, const guint32 frag_number,
- const guint32 frag_data_len, const gboolean more_frags);
+WS_DLL_PUBLIC fragment_head *
+fragment_add_seq(reassembly_table *table, tvbuff_t *tvb, const int offset,
+ const packet_info *pinfo, const guint32 id, const void *data,
+ const guint32 frag_number, const guint32 frag_data_len,
+ const gboolean more_frags, const guint32 flags);
/*
- * These routines extend fragment_add_seq_key to use a "reassembled_table".
+ * These routines extend fragment_add_seq to use the "reassembled_table".
*
* If, after processing this fragment, we have all the fragments, they
* remove that from the fragment hash table if necessary and add it
* to the table of reassembled fragments, and return a pointer to the
* head of the fragment list.
*/
-extern fragment_data *
-fragment_add_seq_check(tvbuff_t *tvb, const int offset, const packet_info *pinfo,
- const guint32 id, GHashTable *fragment_table,
- GHashTable *reassembled_table, const guint32 frag_number,
- const guint32 frag_data_len, const gboolean more_frags);
-
-extern fragment_data *
-fragment_add_seq_802_11(tvbuff_t *tvb, int offset, packet_info *pinfo,
- guint32 id, GHashTable *fragment_table,
- GHashTable *reassembled_table, guint32 frag_number,
- guint32 frag_data_len, gboolean more_frags);
-
-extern fragment_data *
-fragment_add_seq_next(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 id,
- GHashTable *fragment_table, GHashTable *reassembled_table,
- guint32 frag_data_len, gboolean more_frags);
-
-extern void
-fragment_start_seq_check(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table,
+WS_DLL_PUBLIC fragment_head *
+fragment_add_seq_check(reassembly_table *table, tvbuff_t *tvb, const int offset,
+ const packet_info *pinfo, const guint32 id,
+ const void *data,
+ const guint32 frag_number, const guint32 frag_data_len,
+ const gboolean more_frags);
+
+WS_DLL_PUBLIC fragment_head *
+fragment_add_seq_802_11(reassembly_table *table, tvbuff_t *tvb,
+ const int offset, const packet_info *pinfo,
+ const guint32 id, const void *data,
+ const guint32 frag_number, const guint32 frag_data_len,
+ const gboolean more_frags);
+
+WS_DLL_PUBLIC fragment_head *
+fragment_add_seq_next(reassembly_table *table, tvbuff_t *tvb, const int offset,
+ const packet_info *pinfo, const guint32 id,
+ const void *data, const guint32 frag_data_len,
+ const gboolean more_frags);
+
+WS_DLL_PUBLIC void
+fragment_start_seq_check(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id, const void *data,
const guint32 tot_len);
-extern fragment_data *
-fragment_end_seq_next(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table,
- GHashTable *reassembled_table);
+WS_DLL_PUBLIC fragment_head *
+fragment_end_seq_next(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id, const void *data);
+
+/* To specify the offset for the fragment numbering, the first fragment is added with 0, and
+ * afterwards this offset is set. All additional calls to off_seq_check will calculate
+ * the number in sequence in regards to the offset */
+WS_DLL_PUBLIC void
+fragment_add_seq_offset(reassembly_table *table, const packet_info *pinfo, const guint32 id,
+ const void *data, const guint32 fragment_offset);
+
/* to specify how much to reassemble, for fragmentation where last fragment can not be
* identified by flags or such.
* note that for FD_BLOCKSEQUENCE tot_len is the index for the tail fragment.
* actually means we want to defragment 3 blocks, block 0, 1 and 2.
*
*/
-extern void
-fragment_set_tot_len(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table,
- const guint32 tot_len);
+WS_DLL_PUBLIC void
+fragment_set_tot_len(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id, const void *data, const guint32 tot_len);
/* to resad whatever totlen previously set */
-extern guint32
-fragment_get_tot_len(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table);
+WS_DLL_PUBLIC guint32
+fragment_get_tot_len(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id, const void *data);
/*
* This function will set the partial reassembly flag(FD_PARTIAL_REASSEMBLY) for a fh.
* a fh will be extended (increase the already stored data). After calling this function,
* and if FD_DEFRAGMENTED is set, the reassembly process will be continued.
*/
-extern void
-fragment_set_partial_reassembly(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table);
+WS_DLL_PUBLIC void
+fragment_set_partial_reassembly(reassembly_table *table,
+ const packet_info *pinfo, const guint32 id,
+ const void *data);
/* This function is used to check if there is partial or completed reassembly state
* matching this packet. I.e. Are there reassembly going on or not for this packet?
*/
-extern fragment_data *
-fragment_get(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table);
+WS_DLL_PUBLIC fragment_head *
+fragment_get(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id, const void *data);
/* The same for the reassemble table */
/* id *must* be the frame number for this to work! */
-extern fragment_data *
-fragment_get_reassembled(const guint32 id, GHashTable *reassembled_table);
+WS_DLL_PUBLIC fragment_head *
+fragment_get_reassembled(reassembly_table *table, const guint32 id);
-extern fragment_data *
-fragment_get_reassembled_id(const packet_info *pinfo, const guint32 id, GHashTable *reassembled_table);
+WS_DLL_PUBLIC fragment_head *
+fragment_get_reassembled_id(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id);
/* This will free up all resources and delete reassembly state for this PDU.
* Except if the PDU is completely reassembled, then it would NOT deallocate the
- * buffer holding the reassembled data but instead return the pointer to that
- * buffer.
+ * buffer holding the reassembled data but instead return the TVB
*
* So, if you call fragment_delete and it returns non-NULL, YOU are responsible to
- * g_free() that buffer.
+ * tvb_free() .
+ */
+WS_DLL_PUBLIC tvbuff_t *
+fragment_delete(reassembly_table *table, const packet_info *pinfo,
+ const guint32 id, const void *data);
+
+/* This struct holds references to all the tree and field handles used when
+ * displaying the reassembled fragment tree in the packet details view. A
+ * dissector will populate this structure with its own tree and field handles
+ * and then invoke show_fragement_tree to have those items added to the packet
+ * details tree.
*/
-extern unsigned char *
-fragment_delete(const packet_info *pinfo, const guint32 id, GHashTable *fragment_table);
-
-/* hf_fragment, hf_fragment_error, and hf_reassembled_in should be
- FT_FRAMENUM, the others should be FT_BOOLEAN
-*/
typedef struct _fragment_items {
- gint *ett_fragment;
- gint *ett_fragments;
-
- int *hf_fragments;
- int *hf_fragment;
- int *hf_fragment_overlap;
- int *hf_fragment_overlap_conflict;
- int *hf_fragment_multiple_tails;
- int *hf_fragment_too_long_fragment;
- int *hf_fragment_error;
- int *hf_reassembled_in;
- int *hf_reassembled_length;
-
- const char *tag;
+ gint *ett_fragment;
+ gint *ett_fragments;
+
+ int *hf_fragments; /* FT_NONE */
+ int *hf_fragment; /* FT_FRAMENUM */
+ int *hf_fragment_overlap; /* FT_BOOLEAN */
+ int *hf_fragment_overlap_conflict; /* FT_BOOLEAN */
+ int *hf_fragment_multiple_tails; /* FT_BOOLEAN */
+ int *hf_fragment_too_long_fragment; /* FT_BOOLEAN */
+ int *hf_fragment_error; /* FT_FRAMENUM */
+ int *hf_fragment_count; /* FT_UINT32 */
+ int *hf_reassembled_in; /* FT_FRAMENUM */
+ int *hf_reassembled_length; /* FT_UINT32 */
+ int *hf_reassembled_data; /* FT_BYTES */
+
+ const char *tag;
} fragment_items;
-extern tvbuff_t *
+WS_DLL_PUBLIC tvbuff_t *
process_reassembled_data(tvbuff_t *tvb, const int offset, packet_info *pinfo,
- const char *name, fragment_data *fd_head, const fragment_items *fit,
+ const char *name, fragment_head *fd_head, const fragment_items *fit,
gboolean *update_col_infop, proto_tree *tree);
-extern gboolean
-show_fragment_tree(fragment_data *ipfd_head, const fragment_items *fit,
+WS_DLL_PUBLIC gboolean
+show_fragment_tree(fragment_head *ipfd_head, const fragment_items *fit,
proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_item **fi);
-extern gboolean
-show_fragment_seq_tree(fragment_data *ipfd_head, const fragment_items *fit,
+WS_DLL_PUBLIC gboolean
+show_fragment_seq_tree(fragment_head *ipfd_head, const fragment_items *fit,
proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_item **fi);
+
+#endif