2 * Declarations of outines for {fragment,segment} reassembly
4 * $Id: reassemble.h,v 1.21 2003/12/20 03:21:20 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* make sure that all flags that are set in a fragment entry is also set for
26 * the flags field of fd_head !!!
29 /* only in fd_head: packet is defragmented */
30 #define FD_DEFRAGMENTED 0x0001
32 /* there are overlapping fragments */
33 #define FD_OVERLAP 0x0002
35 /* overlapping fragments contain different data */
36 #define FD_OVERLAPCONFLICT 0x0004
38 /* more than one fragment which indicates end-of data */
39 #define FD_MULTIPLETAILS 0x0008
41 /* fragment contains data past the end of the datagram */
42 #define FD_TOOLONGFRAGMENT 0x0010
44 /* fragment data not alloced, fd->data pointing to fd_head->data+fd->offset */
45 #define FD_NOT_MALLOCED 0x0020
47 /* this flag is used to request fragment_add to continue the reassembly process */
48 #define FD_PARTIAL_REASSEMBLY 0x0040
50 /* fragment offset is indicated by sequence number and not byte offset
51 into the defragmented packet */
52 #define FD_BLOCKSEQUENCE 0x0100
54 typedef struct _fragment_data {
55 struct _fragment_data *next;
59 guint32 datalen; /*Only valid in first item of list */
60 guint32 reassembled_in; /* frame where this PDU was reassembled,
61 only valid in the first item of the list
62 and when FD_DEFRAGMENTED is set*/
68 * Initialize a fragment table.
70 extern void fragment_table_init(GHashTable **fragment_table);
73 * Initialize a reassembled-packet table.
75 extern void reassembled_table_init(GHashTable **reassembled_table);
78 * Free up all space allocated for fragment keys and data.
80 void reassemble_init(void);
83 * This function adds a new fragment to the fragment hash table.
84 * If this is the first fragment seen for this datagram, a new entry
85 * is created in the hash table, otherwise this fragment is just added
86 * to the linked list of fragments for this packet.
87 * The list of fragments for a specific datagram is kept sorted for
90 * Returns a pointer to the head of the fragment data list if we have all the
91 * fragments, NULL otherwise.
93 extern fragment_data *fragment_add(tvbuff_t *tvb, int offset, packet_info *pinfo,
94 guint32 id, GHashTable *fragment_table, guint32 frag_offset,
95 guint32 frag_data_len, gboolean more_frags);
96 extern fragment_data *fragment_add_multiple_ok(tvbuff_t *tvb, int offset,
97 packet_info *pinfo, guint32 id, GHashTable *fragment_table,
98 guint32 frag_offset, guint32 frag_data_len, gboolean more_frags);
100 extern fragment_data *fragment_add_check(tvbuff_t *tvb, int offset,
101 packet_info *pinfo, guint32 id, GHashTable *fragment_table,
102 GHashTable *reassembled_table, guint32 frag_offset,
103 guint32 frag_data_len, gboolean more_frags);
105 /* same as fragment_add() but this one assumes frag_number is a block
106 sequence number. note that frag_number is 0 for the first fragment. */
107 extern fragment_data *fragment_add_seq(tvbuff_t *tvb, int offset, packet_info *pinfo,
108 guint32 id, GHashTable *fragment_table, guint32 frag_number,
109 guint32 frag_data_len, gboolean more_frags);
112 * These functions add a new fragment to the fragment hash table.
113 * If this is the first fragment seen for this datagram, a new
114 * "fragment_data" structure is allocated to refer to the reassembled,
117 * in "fragment_add_seq_802_11()", if "more_frags" is false,
118 * the structure is not added to the hash table, and not given
119 * any fragments to refer to, but is just returned;
121 * otherwise, this fragment is added to the linked list of fragments
122 * for this packet, and the "fragment_data" structure is put into
125 * Otherwise, this fragment is just added to the linked list of fragments
128 * If, after processing this fragment, we have all the fragments, they
129 * remove that from the fragment hash table if necessary and add it
130 * to the table of reassembled fragments, and return a pointer to the
131 * head of the fragment list.
133 * If this is the first fragment we've seen, and "more_frags" is false,
134 * "fragment_add_seq_802_11()" does nothing to the fragment data list,
135 * and returns a pointer to the head of that (empty) list. The other
136 * routines return NULL.
138 * Otherwise, they return NULL.
140 * "fragment_add_seq_check()" and "fragment_add_seq_802_11()" assume
141 * frag_number is a block sequence number.
142 * The bsn for the first block is 0.
144 * "fragment_add_seq_next()" is for protocols with no sequence number,
145 * and assumes fragments always appear in sequence.
147 extern fragment_data *
148 fragment_add_seq_check(tvbuff_t *tvb, int offset, packet_info *pinfo,
149 guint32 id, GHashTable *fragment_table,
150 GHashTable *reassembled_table, guint32 frag_number,
151 guint32 frag_data_len, gboolean more_frags);
153 extern fragment_data *
154 fragment_add_seq_802_11(tvbuff_t *tvb, int offset, packet_info *pinfo,
155 guint32 id, GHashTable *fragment_table,
156 GHashTable *reassembled_table, guint32 frag_number,
157 guint32 frag_data_len, gboolean more_frags);
159 extern fragment_data *
160 fragment_add_seq_next(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 id,
161 GHashTable *fragment_table, GHashTable *reassembled_table,
162 guint32 frag_data_len, gboolean more_frags);
164 /* to specify how much to reassemble, for fragmentation where last fragment can not be
165 * identified by flags or such.
166 * note that for FD_BLOCKSEQUENCE tot_len is the index for the tail fragment.
167 * i.e. since the block numbers start at 0, if we specify tot_len==2, that
168 * actually means we want to defragment 3 blocks, block 0, 1 and 2.
172 fragment_set_tot_len(packet_info *pinfo, guint32 id, GHashTable *fragment_table,
175 /* to resad whatever totlen previously set */
177 fragment_get_tot_len(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
180 * This function will set the partial reassembly flag(FD_PARTIAL_REASSEMBLY) for a fh.
181 * When this function is called, the fh MUST already exist, i.e.
182 * the fh MUST be created by the initial call to fragment_add() before
183 * this function is called. Also note that this function MUST be called to indicate
184 * a fh will be extended (increase the already stored data). After calling this function,
185 * and if FD_DEFRAGMENTED is set, the reassembly process will be continued.
188 fragment_set_partial_reassembly(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
190 /* This function is used to check if there is partial or completed reassembly state
191 * matching this packet. I.e. Are there reassembly going on or not for this packet?
193 extern fragment_data *
194 fragment_get(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
196 /* This will free up all resources and delete reassembly state for this PDU.
197 * Except if the PDU is completely reassembled, then it would NOT deallocate the
198 * buffer holding the reassembled data but instead return the pointer to that
201 * So, if you call fragment_delete and it returns non-NULL, YOU are responsible to
202 * g_free() that buffer.
204 extern unsigned char *
205 fragment_delete(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
207 /* hf_fragment, hf_fragment_error, and hf_reassembled_in should be
208 FT_FRAMENUM, the others should be FT_BOOLEAN
210 typedef struct _fragment_items {
216 int *hf_fragment_overlap;
217 int *hf_fragment_overlap_conflict;
218 int *hf_fragment_multiple_tails;
219 int *hf_fragment_too_long_fragment;
220 int *hf_fragment_error;
221 int *hf_reassembled_in;
227 process_reassembled_data(tvbuff_t *tvb, int offset, packet_info *pinfo,
228 char *name, fragment_data *fd_head, const fragment_items *fit,
229 gboolean *update_col_infop, proto_tree *tree);
232 show_fragment_tree(fragment_data *ipfd_head, const fragment_items *fit,
233 proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb);
236 show_fragment_seq_tree(fragment_data *ipfd_head, const fragment_items *fit,
237 proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb);