Add a separate hash table to the reassembly code for reassembled
[obnox/wireshark/wip.git] / packet-afs-macros.h
1 /* packet-afs-macros.h
2  * Helper macros for AFS packet dissection
3  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
4  * Based on routines from tcpdump patches by
5  *   Ken Hornstein <kenh@cmf.nrl.navy.mil>
6  * Portions based on information retrieved from the RX definitions
7  *   in Arla, the free AFS client at http://www.stacken.kth.se/project/arla/
8  * Portions based on information/specs retrieved from the OpenAFS sources at
9  *   www.openafs.org, Copyright IBM. 
10  *
11  * $Id: packet-afs-macros.h,v 1.18 2002/02/10 02:22:02 guy Exp $
12  *
13  * Ethereal - Network traffic analyzer
14  * By Gerald Combs <gerald@ethereal.com>
15  * Copyright 1998 Gerald Combs
16  *
17  * Copied from packet-tftp.c
18  *
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  */
33
34
35
36 /*
37  * Macros for helper dissection routines
38  *
39  * The macros are here to save on coding. They assume that
40  * the current offset is in 'offset', and that the offset
41  * should be incremented after performing the macro's operation.
42  */
43
44
45 /* Output a unsigned integer, stored into field 'field'
46    Assumes it is in network byte order, converts to host before using */
47 #define OUT_UINT(field) \
48         proto_tree_add_uint(tree, field, tvb, offset, sizeof(guint32), tvb_get_ntohl(tvb, offset)); \
49         offset += 4;
50
51 /* Output a unsigned integer, stored into field 'field'
52    Assumes it is in network byte order, converts to host before using */
53 #define OUT_INT(field) \
54         proto_tree_add_int(tree, field, tvb, offset, sizeof(gint32), tvb_get_ntohl(tvb, offset)); \
55         offset += 4;
56         
57 /* Output a unsigned integer, stored into field 'field'
58    Assumes it is in network byte order, converts to host before using, 
59    Note - does not increment offset, so can be used repeatedly for bitfields */
60 #define DISP_UINT(field) \
61         proto_tree_add_uint(tree,field,tvb,offset,sizeof(guint32),tvb_get_ntohl(tvb, offset)); 
62
63 /* Output an IPv4 address, stored into field 'field' */
64 #define OUT_IP(field) \
65         proto_tree_add_ipv4(tree,field,tvb,offset,sizeof(gint32),\
66                 tvb_get_letohl(tvb, offset));\
67         offset += 4;
68
69 /* Output a simple rx array */
70 #define OUT_RXArray8(func) \
71         { \
72                 unsigned int j,i; \
73                 j = tvb_get_guint8(tvb, offset); \
74                 offset += 1; \
75                 for (i=0; i<j; i++) { \
76                         func; \
77                 } \
78         }
79
80 /* Output a simple rx array */
81 #define OUT_RXArray32(func) \
82         { \
83                 unsigned int j,i; \
84                 j = tvb_get_ntohl(tvb, offset); \
85                 offset += sizeof(guint32); \
86                 for (i=0; i<j; i++) { \
87                         func; \
88                 } \
89         }
90
91 /* Output a UNIX seconds/microseconds timestamp, after converting to an
92    nstime_t */
93 #define OUT_TIMESTAMP(field) \
94         { nstime_t ts; \
95         ts.secs = tvb_get_ntohl(tvb, offset); \
96         ts.nsecs = tvb_get_ntohl(tvb, offset)*1000; \
97         proto_tree_add_time(tree,field, tvb,offset,2*sizeof(guint32),&ts); \
98         offset += 8; \
99         }
100
101 /* Output a UNIX seconds-only timestamp, after converting to an nstime_t */
102 #define OUT_DATE(field) \
103         { nstime_t ts; \
104         ts.secs = tvb_get_ntohl(tvb, offset); \
105         ts.nsecs = 0; \
106         proto_tree_add_time(tree,field, tvb,offset,sizeof(guint32),&ts); \
107         offset += 4; \
108         }
109
110 /* Output a rx style string, up to a maximum length first 
111    4 bytes - length, then char data */
112 #define OUT_RXString(field) \
113         {       int i,len; \
114                 char *tmp; \
115                 i = tvb_get_ntohl(tvb, offset); \
116                 offset += 4; \
117                 len = ((i+4-1)/4)*4; \
118                 tmp = g_malloc(i+1); \
119                 memcpy(tmp, tvb_get_ptr(tvb,offset,i), i); \
120                 tmp[i] = '\0'; \
121                 proto_tree_add_string(tree, field, tvb, offset-4, len+4, \
122                 (void *)tmp); \
123                 g_free(tmp); \
124                 offset += len; \
125         }
126
127 /* Output a fixed length vectorized string (each char is a 32 bit int) */
128 #define OUT_RXStringV(field, length) \
129         {       char tmp[length+1]; \
130                 int i,soff; \
131                 soff = offset;\
132                 for (i=0; i<length; i++)\
133                 {\
134                         tmp[i] = (char) tvb_get_ntohl(tvb, offset);\
135                         offset += sizeof(guint32);\
136                 }\
137                 tmp[length] = '\0';\
138                 proto_tree_add_string(tree, field, tvb, soff, length*sizeof(guint32), tmp);\
139         }
140
141
142 /* Output a callback */
143 #define OUT_FS_AFSCallBack() \
144         {       proto_tree *save, *ti; \
145                 ti = proto_tree_add_text(tree, tvb, offset, 3*4, "Callback"); \
146                 save = tree; \
147                 tree = proto_item_add_subtree(ti, ett_afs_callback); \
148                 OUT_UINT(hf_afs_fs_callback_version); \
149                 OUT_DATE(hf_afs_fs_callback_expires); \
150                 OUT_UINT(hf_afs_fs_callback_type); \
151                 tree = save; \
152         }
153
154 /* Output a callback */
155 #define OUT_CB_AFSCallBack() \
156         {       proto_tree *save, *ti; \
157                 ti = proto_tree_add_text(tree, tvb, offset, 3*4, "Callback"); \
158                 save = tree; \
159                 tree = proto_item_add_subtree(ti, ett_afs_callback); \
160                 OUT_UINT(hf_afs_cb_callback_version); \
161                 OUT_DATE(hf_afs_cb_callback_expires); \
162                 OUT_UINT(hf_afs_cb_callback_type); \
163                 tree = save; \
164         }
165
166 /* Output a File ID */
167 #define OUT_FS_AFSFid(label) \
168         {       proto_tree *save, *ti; \
169                 ti = proto_tree_add_text(tree, tvb, offset, 3*4, \
170                         "FileID (%s)", label); \
171                 save = tree; \
172                 tree = proto_item_add_subtree(ti, ett_afs_fid); \
173                 OUT_UINT(hf_afs_fs_fid_volume); \
174                 OUT_UINT(hf_afs_fs_fid_vnode); \
175                 OUT_UINT(hf_afs_fs_fid_uniqifier); \
176                 tree = save; \
177         }
178
179 /* Output a Status mask */
180 #define OUT_FS_STATUSMASK() \
181         {       proto_tree *save, *ti; \
182                 guint32 mask; \
183                 mask = tvb_get_ntohl(tvb, offset); \
184                 ti = proto_tree_add_uint(tree, hf_afs_fs_status_mask, tvb, offset, \
185                         sizeof(guint32), mask); \
186                 save = tree; \
187                 tree = proto_item_add_subtree(ti, ett_afs_status_mask); \
188                 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setmodtime, \
189                         tvb,offset,sizeof(guint32), mask); \
190                 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setowner, \
191                         tvb,offset,sizeof(guint32), mask); \
192                 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setgroup, \
193                         tvb,offset,sizeof(guint32), mask); \
194                 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setmode, \
195                         tvb,offset,sizeof(guint32), mask); \
196                 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setsegsize, \
197                         tvb,offset,sizeof(guint32), mask); \
198                 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_fsync, \
199                         tvb,offset,sizeof(guint32), mask); \
200                 offset += 4; \
201                 tree = save; \
202         }
203
204 /* Output vldb flags */
205 #define OUT_VLDB_Flags() \
206         {       proto_tree *save, *ti; \
207                 guint32 flags; \
208                 flags = tvb_get_ntohl(tvb, offset); \
209                 ti = proto_tree_add_uint(tree, hf_afs_vldb_flags, tvb, offset, \
210                         sizeof(guint32), flags); \
211                 save = tree; \
212                 tree = proto_item_add_subtree(ti, ett_afs_vldb_flags); \
213                 proto_tree_add_boolean(tree, hf_afs_vldb_flags_rwexists, \
214                         tvb,offset,sizeof(guint32), flags); \
215                 proto_tree_add_boolean(tree, hf_afs_vldb_flags_roexists, \
216                         tvb,offset,sizeof(guint32), flags); \
217                 proto_tree_add_boolean(tree, hf_afs_vldb_flags_bkexists, \
218                         tvb,offset,sizeof(guint32), flags); \
219                 proto_tree_add_boolean(tree, hf_afs_vldb_flags_dfsfileset, \
220                         tvb,offset,sizeof(guint32), flags); \
221                 offset += 4; \
222                 tree = save; \
223         }
224
225
226
227 /* Output a File ID */
228 #define OUT_CB_AFSFid(label) \
229         {       proto_tree *save, *ti; \
230                 ti = proto_tree_add_text(tree, tvb, offset, 3*4, \
231                         "FileID (%s)", label); \
232                 save = tree; \
233                 tree = proto_item_add_subtree(ti, ett_afs_fid); \
234                 OUT_UINT(hf_afs_cb_fid_volume); \
235                 OUT_UINT(hf_afs_cb_fid_vnode); \
236                 OUT_UINT(hf_afs_cb_fid_uniqifier); \
237                 tree = save; \
238         }
239         
240 /* Output a StoreStatus */
241 #define OUT_FS_AFSStoreStatus(label) \
242         {       proto_tree *save, *ti; \
243                 ti = proto_tree_add_text(tree, tvb, offset, 6*4, \
244                         label); \
245                 save = tree; \
246                 tree = proto_item_add_subtree(ti, ett_afs_status); \
247                 OUT_FS_STATUSMASK(); \
248                 OUT_DATE(hf_afs_fs_status_clientmodtime); \
249                 OUT_UINT(hf_afs_fs_status_owner); \
250                 OUT_UINT(hf_afs_fs_status_group); \
251                 OUT_UINT(hf_afs_fs_status_mode); \
252                 OUT_UINT(hf_afs_fs_status_segsize); \
253                 tree = save; \
254         }
255
256 /* Output a FetchStatus */
257 #define OUT_FS_AFSFetchStatus(label) \
258         {       proto_tree *save, *ti; \
259                 ti = proto_tree_add_text(tree, tvb, offset, 21*4, \
260                         label); \
261                 save = tree; \
262                 tree = proto_item_add_subtree(ti, ett_afs_status); \
263                 OUT_UINT(hf_afs_fs_status_interfaceversion); \
264                 OUT_UINT(hf_afs_fs_status_filetype); \
265                 OUT_UINT(hf_afs_fs_status_linkcount); \
266                 OUT_UINT(hf_afs_fs_status_length); \
267                 OUT_UINT(hf_afs_fs_status_dataversion); \
268                 OUT_UINT(hf_afs_fs_status_author); \
269                 OUT_UINT(hf_afs_fs_status_owner); \
270                 OUT_UINT(hf_afs_fs_status_calleraccess); \
271                 OUT_UINT(hf_afs_fs_status_anonymousaccess); \
272                 OUT_UINT(hf_afs_fs_status_mode); \
273                 OUT_UINT(hf_afs_fs_status_parentvnode); \
274                 OUT_UINT(hf_afs_fs_status_parentunique); \
275                 OUT_UINT(hf_afs_fs_status_segsize); \
276                 OUT_DATE(hf_afs_fs_status_clientmodtime); \
277                 OUT_DATE(hf_afs_fs_status_servermodtime); \
278                 OUT_UINT(hf_afs_fs_status_group); \
279                 OUT_UINT(hf_afs_fs_status_synccounter); \
280                 OUT_UINT(hf_afs_fs_status_dataversionhigh); \
281                 OUT_UINT(hf_afs_fs_status_spare2); \
282                 OUT_UINT(hf_afs_fs_status_spare3); \
283                 OUT_UINT(hf_afs_fs_status_spare4); \
284                 tree = save; \
285         }
286
287 /* Output a VolSync */
288 #define OUT_FS_AFSVolSync() \
289         {       proto_tree *save, *ti; \
290                 ti = proto_tree_add_text(tree, tvb, offset, 6*4, \
291                         "VolSync"); \
292                 save = tree; \
293                 tree = proto_item_add_subtree(ti, ett_afs_volsync); \
294                 OUT_DATE(hf_afs_fs_volsync_spare1); \
295                 OUT_UINT(hf_afs_fs_volsync_spare2); \
296                 OUT_UINT(hf_afs_fs_volsync_spare3); \
297                 OUT_UINT(hf_afs_fs_volsync_spare4); \
298                 OUT_UINT(hf_afs_fs_volsync_spare5); \
299                 OUT_UINT(hf_afs_fs_volsync_spare6); \
300                 tree = save; \
301         }
302
303 /* Output a AFSCBFids */
304 #define OUT_FS_AFSCBFids() \
305         OUT_RXArray32(OUT_FS_AFSFid("Target"));
306
307 /* Output a ViceIds */
308 #define OUT_FS_ViceIds() \
309         OUT_RXArray8(OUT_UINT(hf_afs_fs_viceid));
310
311 /* Output a IPAddrs */
312 #define OUT_FS_IPAddrs() \
313         OUT_RXArray8(OUT_IP(hf_afs_fs_ipaddr));
314
315 /* Output a AFSCBs */
316 #define OUT_FS_AFSCBs() \
317         OUT_RXArray32(OUT_FS_AFSCallBack());
318
319 /* Output a AFSBulkStats */
320 #define OUT_FS_AFSBulkStats() \
321         OUT_RXArray32(OUT_FS_AFSFetchStatus("Status"));
322
323 /* Output a AFSFetchVolumeStatus */
324 #define OUT_FS_AFSFetchVolumeStatus()
325
326 /* Output a AFSStoreVolumeStatus */
327 #define OUT_FS_AFSStoreVolumeStatus()
328
329 /* Output a ViceStatistics structure */
330 #define OUT_FS_ViceStatistics()
331
332 /* Output a AFS_CollData structure */
333 #define OUT_FS_AFS_CollData()
334
335 /* Output a VolumeInfo structure */
336 #define OUT_FS_VolumeInfo()
337
338 /* Output an AFS Token - might just be bytes though */
339 #define OUT_FS_AFSTOKEN() OUT_RXStringV(hf_afs_fs_token, 1024)
340
341 /* Output a AFS acl */
342 #define ACLOUT(who, positive, acl, bytes) \
343         {       proto_tree *save, *ti; \
344                 int tmpoffset; \
345                 int acllen; \
346                 char tmp[10]; \
347                 tmp[0] = 0; \
348                 if ( acl & PRSFS_READ ) strcat(tmp, "r"); \
349                 if ( acl & PRSFS_LOOKUP ) strcat(tmp, "l"); \
350                 if ( acl & PRSFS_INSERT ) strcat(tmp, "i"); \
351                 if ( acl & PRSFS_DELETE ) strcat(tmp, "d"); \
352                 if ( acl & PRSFS_WRITE ) strcat(tmp, "w"); \
353                 if ( acl & PRSFS_LOCK ) strcat(tmp, "k"); \
354                 if ( acl & PRSFS_ADMINISTER ) strcat(tmp, "a"); \
355                 ti = proto_tree_add_text(tree, tvb, offset, bytes, \
356                         "ACL:  %s %s%s", \
357                         who, tmp, positive ? "" : " (negative)"); \
358                 save = tree; \
359                 tree = proto_item_add_subtree(ti, ett_afs_acl); \
360                 proto_tree_add_string(tree,hf_afs_fs_acl_entity, tvb,offset,strlen(who), who);\
361                 tmpoffset = offset + strlen(who) + 1; \
362                 acllen = bytes - strlen(who) - 1; \
363                 proto_tree_add_boolean(tree,hf_afs_fs_acl_r, tvb,tmpoffset,acllen,acl);\
364                 proto_tree_add_boolean(tree,hf_afs_fs_acl_l, tvb,tmpoffset,acllen,acl);\
365                 proto_tree_add_boolean(tree,hf_afs_fs_acl_i, tvb,tmpoffset,acllen,acl);\
366                 proto_tree_add_boolean(tree,hf_afs_fs_acl_d, tvb,tmpoffset,acllen,acl);\
367                 proto_tree_add_boolean(tree,hf_afs_fs_acl_w, tvb,tmpoffset,acllen,acl);\
368                 proto_tree_add_boolean(tree,hf_afs_fs_acl_k, tvb,tmpoffset,acllen,acl);\
369                 proto_tree_add_boolean(tree,hf_afs_fs_acl_a, tvb,tmpoffset,acllen,acl);\
370                 tree = save; \
371         }
372
373 /* Output a UUID */
374 #define OUT_UUID(x) \
375         OUT_BYTES(x, 11*sizeof(guint32));
376 #define SKIP_UUID() \
377         SKIP(11*sizeof(guint32));
378
379
380 /* Output a bulkaddr */
381 #define OUT_VLDB_BulkAddr() \
382         OUT_RXArray32(OUT_IP(hf_afs_vldb_serverip));
383
384 /* output a bozo_key */
385 #define OUT_BOS_KEY() \
386         OUT_BYTES(hf_afs_bos_key, 8);
387
388 /* output a bozo_key */
389 #define OUT_BOS_KEYINFO() \
390         OUT_TIMESTAMP(hf_afs_bos_keymodtime); \
391         OUT_UINT(hf_afs_bos_keychecksum); \
392         OUT_UINT(hf_afs_bos_keyspare2);
393
394 /* output a bozo_netKTime */
395 #define OUT_BOS_TIME() \
396         SKIP(4); SKIP(2); SKIP(2); SKIP(2); SKIP(2);
397
398 /* output a bozo_status */
399 #define OUT_BOS_STATUS() \
400         SKIP(10 * 4);
401
402 /* output a ubik interface addr array */
403 #define OUT_UBIK_InterfaceAddrs() \
404     { \
405         unsigned int i,j,seen_null=0; \
406         for (i=0; i<255; i++) { \
407                 j = tvb_get_ntohl(tvb, offset); \
408                 if ( j != 0 ) { \
409                         OUT_IP(hf_afs_ubik_interface); \
410                         seen_null = 0; \
411                 } else { \
412                         if ( ! seen_null ) { \
413                         proto_tree_add_text(tree, tvb, offset, \
414                                 tvb_length_remaining(tvb, offset), \
415                                 "Null Interface Addresses"); \
416                                 seen_null = 1; \
417                         } \
418                         offset += 4; \
419                 }\
420         } \
421     }
422
423 #define OUT_UBIK_DebugOld() \
424         { \
425                 OUT_DATE(hf_afs_ubik_now); \
426                 OUT_DATE(hf_afs_ubik_lastyestime); \
427                 OUT_IP(hf_afs_ubik_lastyeshost); \
428                 OUT_UINT(hf_afs_ubik_lastyesstate); \
429                 OUT_DATE(hf_afs_ubik_lastyesclaim); \
430                 OUT_IP(hf_afs_ubik_lowesthost); \
431                 OUT_DATE(hf_afs_ubik_lowesttime); \
432                 OUT_IP(hf_afs_ubik_synchost); \
433                 OUT_DATE(hf_afs_ubik_synctime); \
434                 OUT_UBIKVERSION("Sync Version"); \
435                 OUT_UBIKVERSION("Sync TID"); \
436                 OUT_UINT(hf_afs_ubik_amsyncsite); \
437                 OUT_DATE(hf_afs_ubik_syncsiteuntil); \
438                 OUT_UINT(hf_afs_ubik_nservers); \
439                 OUT_UINT(hf_afs_ubik_lockedpages); \
440                 OUT_UINT(hf_afs_ubik_writelockedpages); \
441                 OUT_UBIKVERSION("Local Version"); \
442                 OUT_UINT(hf_afs_ubik_activewrite); \
443                 OUT_UINT(hf_afs_ubik_tidcounter); \
444                 OUT_UINT(hf_afs_ubik_anyreadlocks); \
445                 OUT_UINT(hf_afs_ubik_anywritelocks); \
446                 OUT_UINT(hf_afs_ubik_recoverystate); \
447                 OUT_UINT(hf_afs_ubik_currenttrans); \
448                 OUT_UINT(hf_afs_ubik_writetrans); \
449                 OUT_DATE(hf_afs_ubik_epochtime); \
450         }
451
452 #define OUT_UBIK_SDebugOld() \
453         { \
454                 OUT_IP(hf_afs_ubik_addr); \
455                 OUT_DATE(hf_afs_ubik_lastvotetime); \
456                 OUT_DATE(hf_afs_ubik_lastbeaconsent); \
457                 OUT_UINT(hf_afs_ubik_lastvote); \
458                 OUT_UBIKVERSION("Remote Version"); \
459                 OUT_UINT(hf_afs_ubik_currentdb); \
460                 OUT_UINT(hf_afs_ubik_beaconsincedown); \
461                 OUT_UINT(hf_afs_ubik_up); \
462         }
463
464 /* Skip a certain number of bytes */
465 #define SKIP(bytes) \
466         offset += bytes;
467         
468 /* Raw data - to end of frame */
469 #define OUT_BYTES_ALL(field) OUT_BYTES(field, tvb_length_remaining(tvb,offset))
470
471 /* Raw data */
472 #define OUT_BYTES(field, bytes) \
473         proto_tree_add_item(tree, field, tvb, offset, bytes, FALSE);\
474         offset += bytes;
475
476
477
478 /* Skip the opcode */
479 #define SKIP_OPCODE() \
480         { \
481                 SKIP(sizeof(guint32)); \
482         }
483
484 /* Output a UBIK version code */
485 #define OUT_UBIKVERSION(label) \
486         {       proto_tree *save, *ti; \
487                 unsigned int epoch,counter; \
488                 nstime_t ts; \
489                 epoch = tvb_get_ntohl(tvb, offset); \
490                 offset += 4; \
491                 counter = tvb_get_ntohl(tvb, offset); \
492                 offset += 4; \
493                 ts.secs = epoch; \
494                 ts.nsecs = 0; \
495                 ti = proto_tree_add_text(tree, tvb, offset-8, 8, \
496                         "UBIK Version (%s): %u.%u", label, epoch, counter ); \
497                 save = tree; \
498                 tree = proto_item_add_subtree(ti, ett_afs_ubikver); \
499                 if ( epoch != 0 ) \
500                 proto_tree_add_time(tree,hf_afs_ubik_version_epoch, tvb,offset-8, \
501                         sizeof(guint32),&ts); \
502                 else \
503                         proto_tree_add_text(tree, tvb, offset-8, \
504                         sizeof(guint32),"Epoch: 0"); \
505                 proto_tree_add_uint(tree,hf_afs_ubik_version_counter, tvb,offset-4, \
506                         sizeof(guint32),counter); \
507                 tree = save; \
508         }