Add dissection of one more bit in Quota FS Flags bitmask
[obnox/wireshark/wip.git] / reassemble.h
1 /* reassemble.h
2  * Declarations of outines for {fragment,segment} reassembly
3  *
4  * $Id: reassemble.h,v 1.4 2002/02/03 23:28:38 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  * 
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.
14  * 
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.
19  * 
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.
23  */
24
25 /* make sure that all flags that are set in a fragment entry is also set for
26  * the flags field of fd_head !!!
27  */
28
29 /* only in fd_head: packet is defragmented */
30 #define FD_DEFRAGMENTED         0x0001
31
32 /* there are overlapping fragments */
33 #define FD_OVERLAP              0x0002
34
35 /* overlapping fragments contain different data */ 
36 #define FD_OVERLAPCONFLICT      0x0004  
37
38 /* more than one fragment which indicates end-of data */
39 #define FD_MULTIPLETAILS        0x0008
40
41 /* fragment contains data past the end of the datagram */
42 #define FD_TOOLONGFRAGMENT      0x0010
43
44 /* fragment data not alloced, fd->data pointing to fd_head->data+fd->offset */
45 #define FD_NOT_MALLOCED         0x0020
46
47 /* this flag is used to request fragment_add to continue the reassembly process */
48 #define FD_PARTIAL_REASSEMBLY   0x0040
49
50 /* fragment offset is indicated by sequence number and not byte offset
51    into the defragmented packet */
52 #define FD_BLOCKSEQUENCE        0x0100
53
54 typedef struct _fragment_data {
55         struct _fragment_data *next;
56         guint32 frame;
57         guint32 offset;
58         guint32 len;
59         guint32 datalen; /*Only valid in first item of list */
60         guint32 flags;
61         unsigned char *data;
62 } fragment_data;
63
64 /*
65  * Initialize a fragment table.
66  */
67 void fragment_table_init(GHashTable **fragment_table);
68
69 /*
70  * Free up all space allocated for fragment keys and data.
71  */
72 void reassemble_init(void);
73
74 /*
75  * This function adds a new fragment to the fragment hash table.
76  * If this is the first fragment seen for this datagram, a new entry
77  * is created in the hash table, otherwise this fragment is just added
78  * to the linked list of fragments for this packet.
79  * The list of fragments for a specific datagram is kept sorted for
80  * easier handling.
81  *
82  * Returns a pointer to the head of the fragment data list if we have all the
83  * fragments, NULL otherwise.
84  */
85 fragment_data *fragment_add(tvbuff_t *tvb, int offset, packet_info *pinfo,
86     guint32 id, GHashTable *fragment_table, guint32 frag_offset,
87     guint32 frag_data_len, gboolean more_frags);
88
89 /* same as fragment_add() but this one assumes frag_offset is a block
90    sequence number. note that frag_offset is 0 for the first fragment. */
91 fragment_data *fragment_add_seq(tvbuff_t *tvb, int offset, packet_info *pinfo,
92     guint32 id, GHashTable *fragment_table, guint32 frag_offset,
93     guint32 frag_data_len, gboolean more_frags);
94
95 /* to specify how much to reassemble, for fragmentation where last fragment can not be 
96  * identified by flags or such.
97  * note that for FD_BLOCKSEQUENCE tot_len is the index for the tail fragment.
98  * i.e. since the block numbers start at 0, if we specify tot_len==2, that 
99  * actually means we want to defragment 3 blocks, block 0, 1 and 2.
100  *
101  */
102 void
103 fragment_set_tot_len(packet_info *pinfo, guint32 id, GHashTable *fragment_table, 
104                      guint32 tot_len);
105 /*
106  * This function will set the partial reassembly flag(FD_PARTIAL_REASSEMBLY) for a fh.
107  * When this function is called, the fh MUST already exist, i.e.
108  * the fh MUST be created by the initial call to fragment_add() before
109  * this function is called. Also note that this function MUST be called to indicate 
110  * a fh will be extended (increase the already stored data). After calling this function,
111  * and if FD_DEFRAGMENTED is set, the reassembly process will be continued.
112  */
113 void
114 fragment_set_partial_reassembly(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
115
116 /* This function is used to check if there is partial or completed reassembly state
117  * matching this packet. I.e. Are there reassembly going on or not for this packet?
118  */
119 fragment_data *
120 fragment_get(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
121
122 /* This will free up all resources and delete reassembly state for this PDU.
123  * Except if the PDU is completely reassembled, then it would NOT deallocate the
124  * buffer holding the reassembled data but instead return the pointer to that
125  * buffer.
126  * 
127  * So, if you call fragment_delete and it returns non-NULL, YOU are responsible to 
128  * g_free() that buffer.
129  */
130 unsigned char *
131 fragment_delete(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
132
133