2 * Declarations of outines for {fragment,segment} reassembly
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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 /* if REASSEMBLE_FLAGS_CHECK_DATA_PRESENT is set, and the first fragment is
55 * incomplete, this flag is set in the flags word on the fd_head returned.
57 * It's all a fudge to preserve historical behaviour.
59 #define FD_DATA_NOT_PRESENT 0x0200
61 /* This flag is set in the to denote that datalen has ben set to a valid value.
62 * It's implied by FD_DEFRAGMENTED (we must know the total length of the
63 * datagram if we have defragmented it...)
65 #define FD_DATALEN_SET 0x0400
67 typedef struct _fragment_data {
68 struct _fragment_data *next;
72 guint32 datalen; /* Only valid in first item of list and when
73 * flags&FD_DATALEN_SET is set;
74 * number of bytes or (if flags&FD_BLOCKSEQUENCE set)
75 * segments in the datagram */
76 guint32 reassembled_in; /* frame where this PDU was reassembled,
77 only valid in the first item of the list
78 and when FD_DEFRAGMENTED is set*/
85 * Flags for fragment_add_seq_*
88 /* we don't have any sequence numbers - fragments are assumed to appear in
90 #define REASSEMBLE_FLAGS_NO_FRAG_NUMBER 0x0001
92 /* a special fudge for the 802.11 dissector */
93 #define REASSEMBLE_FLAGS_802_11_HACK 0x0002
95 /* causes fragment_add_seq_key to check that all the fragment data is present
96 * in the tvb, and if not, do something a bit odd. */
97 #define REASSEMBLE_FLAGS_CHECK_DATA_PRESENT 0x0004
99 /* a function for copying hash keys */
100 typedef void *(*fragment_key_copier)(const void *key);
104 * Initialize a fragment table.
106 extern void fragment_table_init(GHashTable **fragment_table);
107 extern void dcerpc_fragment_table_init(GHashTable **fragment_table);
110 * Initialize a reassembled-packet table.
112 extern void reassembled_table_init(GHashTable **reassembled_table);
115 * Free up all space allocated for fragment keys and data.
117 void reassemble_init(void);
120 * This function adds a new fragment to the fragment hash table.
121 * If this is the first fragment seen for this datagram, a new entry
122 * is created in the hash table, otherwise this fragment is just added
123 * to the linked list of fragments for this packet.
124 * The list of fragments for a specific datagram is kept sorted for
127 * Returns a pointer to the head of the fragment data list if we have all the
128 * fragments, NULL otherwise.
130 extern fragment_data *fragment_add(tvbuff_t *tvb, int offset, packet_info *pinfo,
131 guint32 id, GHashTable *fragment_table, guint32 frag_offset,
132 guint32 frag_data_len, gboolean more_frags);
133 extern fragment_data *fragment_add_multiple_ok(tvbuff_t *tvb, int offset,
134 packet_info *pinfo, guint32 id, GHashTable *fragment_table,
135 guint32 frag_offset, guint32 frag_data_len, gboolean more_frags);
138 * This routine extends fragment_add to use a "reassembled_table".
140 * If, after processing this fragment, we have all the fragments, they
141 * remove that from the fragment hash table if necessary and add it
142 * to the table of reassembled fragments, and return a pointer to the
143 * head of the fragment list.
145 extern fragment_data *fragment_add_check(tvbuff_t *tvb, int offset,
146 packet_info *pinfo, guint32 id, GHashTable *fragment_table,
147 GHashTable *reassembled_table, guint32 frag_offset,
148 guint32 frag_data_len, gboolean more_frags);
150 /* same as fragment_add() but this one assumes frag_number is a block
151 sequence number. note that frag_number is 0 for the first fragment. */
154 * These functions add a new fragment to the fragment hash table,
155 * assuming that frag_number is a block sequence number (starting from zero for
156 * the first fragment of each datagram).
158 * If this is the first fragment seen for this datagram, a new
159 * "fragment_data" structure is allocated to refer to the reassembled
162 * if "more_frags" is false, and either we have no sequence numbers, or
163 * are using the 802.11 hack, it is assumed that this is the only fragment
164 * in the datagram. The structure is not added to the hash
165 * table, and not given any fragments to refer to, but is just returned.
167 * In this latter case reassembly wasn't done (since there was only one
168 * fragment in the packet); dissectors can check the 'next' pointer on the
169 * returned list to see if this case was hit or not.
171 * Otherwise, this fragment is just added to the linked list of fragments
172 * for this packet; the fragment_data is also added to the fragment hash if
175 * If this packet completes assembly, these functions return the head of the
176 * fragment data; otherwise, they return null.
179 /* "key" should be an arbitrary key used for indexing the fragment hash;
180 * "key_copier" is called to copy the key to a more appropriate store before
181 * inserting a new entry to the hash.
183 extern fragment_data *
184 fragment_add_seq_key(tvbuff_t *tvb, int offset, packet_info *pinfo,
185 void *key, fragment_key_copier key_copier,
186 GHashTable *fragment_table, guint32 frag_number,
187 guint32 frag_data_len, gboolean more_frags,
190 /* a wrapper for fragment_add_seq_key - uses a key of source, dest and id */
191 extern fragment_data *fragment_add_seq(tvbuff_t *tvb, int offset, packet_info *pinfo,
192 guint32 id, GHashTable *fragment_table, guint32 frag_number,
193 guint32 frag_data_len, gboolean more_frags);
195 /* another wrapper for fragment_add_seq_key - uses a key of source, dest, id
197 extern fragment_data *
198 fragment_add_dcerpc_dg(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 id,
200 GHashTable *fragment_table, guint32 frag_number,
201 guint32 frag_data_len, gboolean more_frags);
204 * These routines extend fragment_add_seq_key to use a "reassembled_table".
206 * If, after processing this fragment, we have all the fragments, they
207 * remove that from the fragment hash table if necessary and add it
208 * to the table of reassembled fragments, and return a pointer to the
209 * head of the fragment list.
211 extern fragment_data *
212 fragment_add_seq_check(tvbuff_t *tvb, int offset, packet_info *pinfo,
213 guint32 id, GHashTable *fragment_table,
214 GHashTable *reassembled_table, guint32 frag_number,
215 guint32 frag_data_len, gboolean more_frags);
217 extern fragment_data *
218 fragment_add_seq_802_11(tvbuff_t *tvb, int offset, packet_info *pinfo,
219 guint32 id, GHashTable *fragment_table,
220 GHashTable *reassembled_table, guint32 frag_number,
221 guint32 frag_data_len, gboolean more_frags);
223 extern fragment_data *
224 fragment_add_seq_next(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 id,
225 GHashTable *fragment_table, GHashTable *reassembled_table,
226 guint32 frag_data_len, gboolean more_frags);
229 fragment_start_seq_check(packet_info *pinfo, guint32 id, GHashTable *fragment_table,
232 extern fragment_data *
233 fragment_end_seq_next(packet_info *pinfo, guint32 id, GHashTable *fragment_table,
234 GHashTable *reassembled_table);
235 /* to specify how much to reassemble, for fragmentation where last fragment can not be
236 * identified by flags or such.
237 * note that for FD_BLOCKSEQUENCE tot_len is the index for the tail fragment.
238 * i.e. since the block numbers start at 0, if we specify tot_len==2, that
239 * actually means we want to defragment 3 blocks, block 0, 1 and 2.
243 fragment_set_tot_len(packet_info *pinfo, guint32 id, GHashTable *fragment_table,
246 /* to resad whatever totlen previously set */
248 fragment_get_tot_len(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
251 * This function will set the partial reassembly flag(FD_PARTIAL_REASSEMBLY) for a fh.
252 * When this function is called, the fh MUST already exist, i.e.
253 * the fh MUST be created by the initial call to fragment_add() before
254 * this function is called. Also note that this function MUST be called to indicate
255 * a fh will be extended (increase the already stored data). After calling this function,
256 * and if FD_DEFRAGMENTED is set, the reassembly process will be continued.
259 fragment_set_partial_reassembly(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
261 /* This function is used to check if there is partial or completed reassembly state
262 * matching this packet. I.e. Are there reassembly going on or not for this packet?
264 extern fragment_data *
265 fragment_get(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
267 /* The same for the reassemble table */
268 /* id *must* be the frame number for this to work! */
269 extern fragment_data *
270 fragment_get_reassembled(packet_info *pinfo, guint32 id, GHashTable *reassembled_table);
272 extern fragment_data *
273 fragment_get_reassembled_id(packet_info *pinfo, guint32 id, GHashTable *reassembled_table);
275 /* This will free up all resources and delete reassembly state for this PDU.
276 * Except if the PDU is completely reassembled, then it would NOT deallocate the
277 * buffer holding the reassembled data but instead return the pointer to that
280 * So, if you call fragment_delete and it returns non-NULL, YOU are responsible to
281 * g_free() that buffer.
283 extern unsigned char *
284 fragment_delete(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
286 /* hf_fragment, hf_fragment_error, and hf_reassembled_in should be
287 FT_FRAMENUM, the others should be FT_BOOLEAN
289 typedef struct _fragment_items {
295 int *hf_fragment_overlap;
296 int *hf_fragment_overlap_conflict;
297 int *hf_fragment_multiple_tails;
298 int *hf_fragment_too_long_fragment;
299 int *hf_fragment_error;
300 int *hf_reassembled_in;
306 process_reassembled_data(tvbuff_t *tvb, int offset, packet_info *pinfo,
307 const char *name, fragment_data *fd_head, const fragment_items *fit,
308 gboolean *update_col_infop, proto_tree *tree);
311 show_fragment_tree(fragment_data *ipfd_head, const fragment_items *fit,
312 proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_item **fi);
315 show_fragment_seq_tree(fragment_data *ipfd_head, const fragment_items *fit,
316 proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_item **fi);