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.
11 * $Id: packet-afs-macros.h,v 1.18 2002/02/10 02:22:02 guy Exp $
13 * Ethereal - Network traffic analyzer
14 * By Gerald Combs <gerald@ethereal.com>
15 * Copyright 1998 Gerald Combs
17 * Copied from packet-tftp.c
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.
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.
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.
37 * Macros for helper dissection routines
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.
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)); \
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)); \
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));
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));\
69 /* Output a simple rx array */
70 #define OUT_RXArray8(func) \
73 j = tvb_get_guint8(tvb, offset); \
75 for (i=0; i<j; i++) { \
80 /* Output a simple rx array */
81 #define OUT_RXArray32(func) \
84 j = tvb_get_ntohl(tvb, offset); \
85 offset += sizeof(guint32); \
86 for (i=0; i<j; i++) { \
91 /* Output a UNIX seconds/microseconds timestamp, after converting to an
93 #define OUT_TIMESTAMP(field) \
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); \
101 /* Output a UNIX seconds-only timestamp, after converting to an nstime_t */
102 #define OUT_DATE(field) \
104 ts.secs = tvb_get_ntohl(tvb, offset); \
106 proto_tree_add_time(tree,field, tvb,offset,sizeof(guint32),&ts); \
110 /* Output a rx style string, up to a maximum length first
111 4 bytes - length, then char data */
112 #define OUT_RXString(field) \
115 i = tvb_get_ntohl(tvb, offset); \
117 len = ((i+4-1)/4)*4; \
118 tmp = g_malloc(i+1); \
119 memcpy(tmp, tvb_get_ptr(tvb,offset,i), i); \
121 proto_tree_add_string(tree, field, tvb, offset-4, len+4, \
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]; \
132 for (i=0; i<length; i++)\
134 tmp[i] = (char) tvb_get_ntohl(tvb, offset);\
135 offset += sizeof(guint32);\
138 proto_tree_add_string(tree, field, tvb, soff, length*sizeof(guint32), tmp);\
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"); \
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); \
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"); \
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); \
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); \
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); \
179 /* Output a Status mask */
180 #define OUT_FS_STATUSMASK() \
181 { proto_tree *save, *ti; \
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); \
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); \
204 /* Output vldb flags */
205 #define OUT_VLDB_Flags() \
206 { proto_tree *save, *ti; \
208 flags = tvb_get_ntohl(tvb, offset); \
209 ti = proto_tree_add_uint(tree, hf_afs_vldb_flags, tvb, offset, \
210 sizeof(guint32), flags); \
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); \
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); \
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); \
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, \
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); \
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, \
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); \
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, \
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); \
303 /* Output a AFSCBFids */
304 #define OUT_FS_AFSCBFids() \
305 OUT_RXArray32(OUT_FS_AFSFid("Target"));
307 /* Output a ViceIds */
308 #define OUT_FS_ViceIds() \
309 OUT_RXArray8(OUT_UINT(hf_afs_fs_viceid));
311 /* Output a IPAddrs */
312 #define OUT_FS_IPAddrs() \
313 OUT_RXArray8(OUT_IP(hf_afs_fs_ipaddr));
315 /* Output a AFSCBs */
316 #define OUT_FS_AFSCBs() \
317 OUT_RXArray32(OUT_FS_AFSCallBack());
319 /* Output a AFSBulkStats */
320 #define OUT_FS_AFSBulkStats() \
321 OUT_RXArray32(OUT_FS_AFSFetchStatus("Status"));
323 /* Output a AFSFetchVolumeStatus */
324 #define OUT_FS_AFSFetchVolumeStatus()
326 /* Output a AFSStoreVolumeStatus */
327 #define OUT_FS_AFSStoreVolumeStatus()
329 /* Output a ViceStatistics structure */
330 #define OUT_FS_ViceStatistics()
332 /* Output a AFS_CollData structure */
333 #define OUT_FS_AFS_CollData()
335 /* Output a VolumeInfo structure */
336 #define OUT_FS_VolumeInfo()
338 /* Output an AFS Token - might just be bytes though */
339 #define OUT_FS_AFSTOKEN() OUT_RXStringV(hf_afs_fs_token, 1024)
341 /* Output a AFS acl */
342 #define ACLOUT(who, positive, acl, bytes) \
343 { proto_tree *save, *ti; \
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, \
357 who, tmp, positive ? "" : " (negative)"); \
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);\
374 #define OUT_UUID(x) \
375 OUT_BYTES(x, 11*sizeof(guint32));
376 #define SKIP_UUID() \
377 SKIP(11*sizeof(guint32));
380 /* Output a bulkaddr */
381 #define OUT_VLDB_BulkAddr() \
382 OUT_RXArray32(OUT_IP(hf_afs_vldb_serverip));
384 /* output a bozo_key */
385 #define OUT_BOS_KEY() \
386 OUT_BYTES(hf_afs_bos_key, 8);
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);
394 /* output a bozo_netKTime */
395 #define OUT_BOS_TIME() \
396 SKIP(4); SKIP(2); SKIP(2); SKIP(2); SKIP(2);
398 /* output a bozo_status */
399 #define OUT_BOS_STATUS() \
402 /* output a ubik interface addr array */
403 #define OUT_UBIK_InterfaceAddrs() \
405 unsigned int i,j,seen_null=0; \
406 for (i=0; i<255; i++) { \
407 j = tvb_get_ntohl(tvb, offset); \
409 OUT_IP(hf_afs_ubik_interface); \
412 if ( ! seen_null ) { \
413 proto_tree_add_text(tree, tvb, offset, \
414 tvb_length_remaining(tvb, offset), \
415 "Null Interface Addresses"); \
423 #define OUT_UBIK_DebugOld() \
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); \
452 #define OUT_UBIK_SDebugOld() \
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); \
464 /* Skip a certain number of bytes */
465 #define SKIP(bytes) \
468 /* Raw data - to end of frame */
469 #define OUT_BYTES_ALL(field) OUT_BYTES(field, tvb_length_remaining(tvb,offset))
472 #define OUT_BYTES(field, bytes) \
473 proto_tree_add_item(tree, field, tvb, offset, bytes, FALSE);\
478 /* Skip the opcode */
479 #define SKIP_OPCODE() \
481 SKIP(sizeof(guint32)); \
484 /* Output a UBIK version code */
485 #define OUT_UBIKVERSION(label) \
486 { proto_tree *save, *ti; \
487 unsigned int epoch,counter; \
489 epoch = tvb_get_ntohl(tvb, offset); \
491 counter = tvb_get_ntohl(tvb, offset); \
495 ti = proto_tree_add_text(tree, tvb, offset-8, 8, \
496 "UBIK Version (%s): %u.%u", label, epoch, counter ); \
498 tree = proto_item_add_subtree(ti, ett_afs_ubikver); \
500 proto_tree_add_time(tree,hf_afs_ubik_version_epoch, tvb,offset-8, \
501 sizeof(guint32),&ts); \
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); \