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.23 2004/01/19 18:36:32 jmayer 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 seconds-only time value, after converting to an nstime_t;
102 this can be an absolute time as a UNIX time-since-epoch, or a
103 relative time in seconds */
104 #define OUT_TIMESECS(field) \
106 ts.secs = tvb_get_ntohl(tvb, offset); \
108 proto_tree_add_time(tree,field, tvb,offset,sizeof(guint32),&ts); \
112 /* Output a rx style string, up to a maximum length first
113 4 bytes - length, then char data */
114 #define OUT_RXString(field) \
118 i = tvb_get_ntohl(tvb, offset); \
120 p = tvb_get_ptr(tvb,offset,i); \
121 len = ((i+4-1)/4)*4; \
122 tmp = g_malloc(i+1); \
125 proto_tree_add_string(tree, field, tvb, offset-4, len+4, \
131 /* Output a fixed length vectorized string (each char is a 32 bit int) */
132 #define OUT_RXStringV(field, length) \
133 { char tmp[length+1]; \
136 for (i=0; i<length; i++)\
138 tmp[i] = (char) tvb_get_ntohl(tvb, offset);\
139 offset += sizeof(guint32);\
142 proto_tree_add_string(tree, field, tvb, soff, length*sizeof(guint32), tmp);\
146 /* Output a callback */
147 #define OUT_FS_AFSCallBack() \
148 { proto_tree *save, *ti; \
149 ti = proto_tree_add_text(tree, tvb, offset, 3*4, "Callback"); \
151 tree = proto_item_add_subtree(ti, ett_afs_callback); \
152 OUT_UINT(hf_afs_fs_callback_version); \
153 OUT_TIMESECS(hf_afs_fs_callback_expires); \
154 OUT_UINT(hf_afs_fs_callback_type); \
158 /* Output a callback */
159 #define OUT_CB_AFSCallBack() \
160 { proto_tree *save, *ti; \
161 ti = proto_tree_add_text(tree, tvb, offset, 3*4, "Callback"); \
163 tree = proto_item_add_subtree(ti, ett_afs_callback); \
164 OUT_UINT(hf_afs_cb_callback_version); \
165 OUT_TIMESECS(hf_afs_cb_callback_expires); \
166 OUT_UINT(hf_afs_cb_callback_type); \
170 /* Output a File ID */
171 #define OUT_FS_AFSFid(label) \
172 { proto_tree *save, *ti; \
173 ti = proto_tree_add_text(tree, tvb, offset, 3*4, \
174 "FileID (%s)", label); \
176 tree = proto_item_add_subtree(ti, ett_afs_fid); \
177 OUT_UINT(hf_afs_fs_fid_volume); \
178 OUT_UINT(hf_afs_fs_fid_vnode); \
179 OUT_UINT(hf_afs_fs_fid_uniqifier); \
183 /* Output a Status mask */
184 #define OUT_FS_STATUSMASK() \
185 { proto_tree *save, *ti; \
187 mask = tvb_get_ntohl(tvb, offset); \
188 ti = proto_tree_add_uint(tree, hf_afs_fs_status_mask, tvb, offset, \
189 sizeof(guint32), mask); \
191 tree = proto_item_add_subtree(ti, ett_afs_status_mask); \
192 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setmodtime, \
193 tvb,offset,sizeof(guint32), mask); \
194 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setowner, \
195 tvb,offset,sizeof(guint32), mask); \
196 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setgroup, \
197 tvb,offset,sizeof(guint32), mask); \
198 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setmode, \
199 tvb,offset,sizeof(guint32), mask); \
200 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_setsegsize, \
201 tvb,offset,sizeof(guint32), mask); \
202 proto_tree_add_boolean(tree, hf_afs_fs_status_mask_fsync, \
203 tvb,offset,sizeof(guint32), mask); \
208 /* Output vldb flags */
209 #define OUT_VLDB_Flags() \
210 { proto_tree *save, *ti; \
212 flags = tvb_get_ntohl(tvb, offset); \
213 ti = proto_tree_add_uint(tree, hf_afs_vldb_flags, tvb, offset, \
214 sizeof(guint32), flags); \
216 tree = proto_item_add_subtree(ti, ett_afs_vldb_flags); \
217 proto_tree_add_boolean(tree, hf_afs_vldb_flags_rwexists, \
218 tvb,offset,sizeof(guint32), flags); \
219 proto_tree_add_boolean(tree, hf_afs_vldb_flags_roexists, \
220 tvb,offset,sizeof(guint32), flags); \
221 proto_tree_add_boolean(tree, hf_afs_vldb_flags_bkexists, \
222 tvb,offset,sizeof(guint32), flags); \
223 proto_tree_add_boolean(tree, hf_afs_vldb_flags_dfsfileset, \
224 tvb,offset,sizeof(guint32), flags); \
231 /* Output a File ID */
232 #define OUT_CB_AFSFid(label) \
233 { proto_tree *save, *ti; \
234 ti = proto_tree_add_text(tree, tvb, offset, 3*4, \
235 "FileID (%s)", label); \
237 tree = proto_item_add_subtree(ti, ett_afs_fid); \
238 OUT_UINT(hf_afs_cb_fid_volume); \
239 OUT_UINT(hf_afs_cb_fid_vnode); \
240 OUT_UINT(hf_afs_cb_fid_uniqifier); \
244 /* Output a StoreStatus */
245 #define OUT_FS_AFSStoreStatus(label) \
246 { proto_tree *save, *ti; \
247 ti = proto_tree_add_text(tree, tvb, offset, 6*4, \
250 tree = proto_item_add_subtree(ti, ett_afs_status); \
251 OUT_FS_STATUSMASK(); \
252 OUT_TIMESECS(hf_afs_fs_status_clientmodtime); \
253 OUT_UINT(hf_afs_fs_status_owner); \
254 OUT_UINT(hf_afs_fs_status_group); \
255 OUT_UINT(hf_afs_fs_status_mode); \
256 OUT_UINT(hf_afs_fs_status_segsize); \
260 /* Output a FetchStatus */
261 #define OUT_FS_AFSFetchStatus(label) \
262 { proto_tree *save, *ti; \
263 ti = proto_tree_add_text(tree, tvb, offset, 21*4, \
266 tree = proto_item_add_subtree(ti, ett_afs_status); \
267 OUT_UINT(hf_afs_fs_status_interfaceversion); \
268 OUT_UINT(hf_afs_fs_status_filetype); \
269 OUT_UINT(hf_afs_fs_status_linkcount); \
270 OUT_UINT(hf_afs_fs_status_length); \
271 OUT_UINT(hf_afs_fs_status_dataversion); \
272 OUT_UINT(hf_afs_fs_status_author); \
273 OUT_UINT(hf_afs_fs_status_owner); \
274 OUT_UINT(hf_afs_fs_status_calleraccess); \
275 OUT_UINT(hf_afs_fs_status_anonymousaccess); \
276 OUT_UINT(hf_afs_fs_status_mode); \
277 OUT_UINT(hf_afs_fs_status_parentvnode); \
278 OUT_UINT(hf_afs_fs_status_parentunique); \
279 OUT_UINT(hf_afs_fs_status_segsize); \
280 OUT_TIMESECS(hf_afs_fs_status_clientmodtime); \
281 OUT_TIMESECS(hf_afs_fs_status_servermodtime); \
282 OUT_UINT(hf_afs_fs_status_group); \
283 OUT_UINT(hf_afs_fs_status_synccounter); \
284 OUT_UINT(hf_afs_fs_status_dataversionhigh); \
285 OUT_UINT(hf_afs_fs_status_spare2); \
286 OUT_UINT(hf_afs_fs_status_spare3); \
287 OUT_UINT(hf_afs_fs_status_spare4); \
291 /* Output a VolSync */
292 #define OUT_FS_AFSVolSync() \
293 { proto_tree *save, *ti; \
294 ti = proto_tree_add_text(tree, tvb, offset, 6*4, \
297 tree = proto_item_add_subtree(ti, ett_afs_volsync); \
298 OUT_TIMESECS(hf_afs_fs_volsync_spare1); \
299 OUT_UINT(hf_afs_fs_volsync_spare2); \
300 OUT_UINT(hf_afs_fs_volsync_spare3); \
301 OUT_UINT(hf_afs_fs_volsync_spare4); \
302 OUT_UINT(hf_afs_fs_volsync_spare5); \
303 OUT_UINT(hf_afs_fs_volsync_spare6); \
307 /* Output a AFSCBFids */
308 #define OUT_FS_AFSCBFids() \
309 OUT_RXArray32(OUT_FS_AFSFid("Target"));
311 /* Output a ViceIds */
312 #define OUT_FS_ViceIds() \
313 OUT_RXArray8(OUT_UINT(hf_afs_fs_viceid));
315 /* Output a IPAddrs */
316 #define OUT_FS_IPAddrs() \
317 OUT_RXArray8(OUT_IP(hf_afs_fs_ipaddr));
319 /* Output a AFSCBs */
320 #define OUT_FS_AFSCBs() \
321 OUT_RXArray32(OUT_FS_AFSCallBack());
323 /* Output a AFSBulkStats */
324 #define OUT_FS_AFSBulkStats() \
325 OUT_RXArray32(OUT_FS_AFSFetchStatus("Status"));
327 /* Output a AFSFetchVolumeStatus */
328 #define OUT_FS_AFSFetchVolumeStatus()
330 /* Output a AFSStoreVolumeStatus */
331 #define OUT_FS_AFSStoreVolumeStatus()
333 /* Output a ViceStatistics structure */
334 #define OUT_FS_ViceStatistics()
336 /* Output a AFS_CollData structure */
337 #define OUT_FS_AFS_CollData()
339 /* Output a VolumeInfo structure */
340 #define OUT_FS_VolumeInfo()
342 /* Output an AFS Token - might just be bytes though */
343 #define OUT_FS_AFSTOKEN() OUT_RXStringV(hf_afs_fs_token, 1024)
345 /* Output a AFS acl */
346 #define ACLOUT(who, positive, acl, bytes) \
347 { proto_tree *save, *ti; \
352 if ( acl & PRSFS_READ ) strcat(tmp, "r"); \
353 if ( acl & PRSFS_LOOKUP ) strcat(tmp, "l"); \
354 if ( acl & PRSFS_INSERT ) strcat(tmp, "i"); \
355 if ( acl & PRSFS_DELETE ) strcat(tmp, "d"); \
356 if ( acl & PRSFS_WRITE ) strcat(tmp, "w"); \
357 if ( acl & PRSFS_LOCK ) strcat(tmp, "k"); \
358 if ( acl & PRSFS_ADMINISTER ) strcat(tmp, "a"); \
359 ti = proto_tree_add_text(tree, tvb, offset, bytes, \
361 who, tmp, positive ? "" : " (negative)"); \
363 tree = proto_item_add_subtree(ti, ett_afs_acl); \
364 proto_tree_add_string(tree,hf_afs_fs_acl_entity, tvb,offset,strlen(who), who);\
365 tmpoffset = offset + strlen(who) + 1; \
366 acllen = bytes - strlen(who) - 1; \
367 proto_tree_add_boolean(tree,hf_afs_fs_acl_r, tvb,tmpoffset,acllen,acl);\
368 proto_tree_add_boolean(tree,hf_afs_fs_acl_l, tvb,tmpoffset,acllen,acl);\
369 proto_tree_add_boolean(tree,hf_afs_fs_acl_i, tvb,tmpoffset,acllen,acl);\
370 proto_tree_add_boolean(tree,hf_afs_fs_acl_d, tvb,tmpoffset,acllen,acl);\
371 proto_tree_add_boolean(tree,hf_afs_fs_acl_w, tvb,tmpoffset,acllen,acl);\
372 proto_tree_add_boolean(tree,hf_afs_fs_acl_k, tvb,tmpoffset,acllen,acl);\
373 proto_tree_add_boolean(tree,hf_afs_fs_acl_a, tvb,tmpoffset,acllen,acl);\
378 #define OUT_UUID(x) \
379 OUT_BYTES(x, 11*sizeof(guint32));
380 #define SKIP_UUID() \
381 SKIP(11*sizeof(guint32));
384 /* Output a bulkaddr */
385 #define OUT_VLDB_BulkAddr() \
386 OUT_RXArray32(OUT_IP(hf_afs_vldb_serverip));
388 /* output a bozo_key */
389 #define OUT_BOS_KEY() \
390 OUT_BYTES(hf_afs_bos_key, 8);
392 /* output a bozo_key */
393 #define OUT_BOS_KEYINFO() \
394 OUT_TIMESTAMP(hf_afs_bos_keymodtime); \
395 OUT_UINT(hf_afs_bos_keychecksum); \
396 OUT_UINT(hf_afs_bos_keyspare2);
398 /* output a bozo_netKTime */
399 #define OUT_BOS_TIME() \
400 SKIP(4); SKIP(2); SKIP(2); SKIP(2); SKIP(2);
402 /* output a bozo_status */
403 #define OUT_BOS_STATUS() \
406 /* output a ubik interface addr array */
407 #define OUT_UBIK_InterfaceAddrs() \
409 unsigned int i,j,seen_null=0; \
410 for (i=0; i<255; i++) { \
411 j = tvb_get_ntohl(tvb, offset); \
413 OUT_IP(hf_afs_ubik_interface); \
416 if ( ! seen_null ) { \
417 proto_tree_add_text(tree, tvb, offset, \
418 tvb_length_remaining(tvb, offset), \
419 "Null Interface Addresses"); \
427 #define OUT_UBIK_DebugOld() \
429 OUT_TIMESECS(hf_afs_ubik_now); \
430 OUT_TIMESECS(hf_afs_ubik_lastyestime); \
431 OUT_IP(hf_afs_ubik_lastyeshost); \
432 OUT_UINT(hf_afs_ubik_lastyesstate); \
433 OUT_TIMESECS(hf_afs_ubik_lastyesclaim); \
434 OUT_IP(hf_afs_ubik_lowesthost); \
435 OUT_TIMESECS(hf_afs_ubik_lowesttime); \
436 OUT_IP(hf_afs_ubik_synchost); \
437 OUT_TIMESECS(hf_afs_ubik_synctime); \
438 OUT_UBIKVERSION("Sync Version"); \
439 OUT_UBIKVERSION("Sync TID"); \
440 OUT_UINT(hf_afs_ubik_amsyncsite); \
441 OUT_TIMESECS(hf_afs_ubik_syncsiteuntil); \
442 OUT_UINT(hf_afs_ubik_nservers); \
443 OUT_UINT(hf_afs_ubik_lockedpages); \
444 OUT_UINT(hf_afs_ubik_writelockedpages); \
445 OUT_UBIKVERSION("Local Version"); \
446 OUT_UINT(hf_afs_ubik_activewrite); \
447 OUT_UINT(hf_afs_ubik_tidcounter); \
448 OUT_UINT(hf_afs_ubik_anyreadlocks); \
449 OUT_UINT(hf_afs_ubik_anywritelocks); \
450 OUT_UINT(hf_afs_ubik_recoverystate); \
451 OUT_UINT(hf_afs_ubik_currenttrans); \
452 OUT_UINT(hf_afs_ubik_writetrans); \
453 OUT_TIMESECS(hf_afs_ubik_epochtime); \
456 #define OUT_UBIK_SDebugOld() \
458 OUT_IP(hf_afs_ubik_addr); \
459 OUT_TIMESECS(hf_afs_ubik_lastvotetime); \
460 OUT_TIMESECS(hf_afs_ubik_lastbeaconsent); \
461 OUT_UINT(hf_afs_ubik_lastvote); \
462 OUT_UBIKVERSION("Remote Version"); \
463 OUT_UINT(hf_afs_ubik_currentdb); \
464 OUT_UINT(hf_afs_ubik_beaconsincedown); \
465 OUT_UINT(hf_afs_ubik_up); \
468 /* Skip a certain number of bytes */
469 #define SKIP(bytes) \
472 /* Raw data - to end of frame */
473 #define OUT_BYTES_ALL(field) OUT_BYTES(field, tvb_length_remaining(tvb,offset))
476 #define OUT_BYTES(field, bytes) \
477 proto_tree_add_item(tree, field, tvb, offset, bytes, FALSE);\
482 /* Skip the opcode */
483 #define SKIP_OPCODE() \
485 SKIP(sizeof(guint32)); \
488 /* Output a UBIK version code */
489 #define OUT_UBIKVERSION(label) \
490 { proto_tree *save, *ti; \
491 unsigned int epoch,counter; \
493 epoch = tvb_get_ntohl(tvb, offset); \
495 counter = tvb_get_ntohl(tvb, offset); \
499 ti = proto_tree_add_text(tree, tvb, offset-8, 8, \
500 "UBIK Version (%s): %u.%u", label, epoch, counter ); \
502 tree = proto_item_add_subtree(ti, ett_afs_ubikver); \
504 proto_tree_add_time(tree,hf_afs_ubik_version_epoch, tvb,offset-8, \
505 sizeof(guint32),&ts); \
507 proto_tree_add_text(tree, tvb, offset-8, \
508 sizeof(guint32),"Epoch: 0"); \
509 proto_tree_add_uint(tree,hf_afs_ubik_version_counter, tvb,offset-4, \
510 sizeof(guint32),counter); \
514 /* Output a kauth getticket request */
515 #define OUT_KAUTH_GetTicket() \
518 OUT_UINT(hf_afs_kauth_kvno); \
519 OUT_RXString(hf_afs_kauth_domain); \
520 len = tvb_get_ntohl(tvb, offset); \
522 OUT_BYTES(hf_afs_kauth_data, len); \
523 OUT_RXString(hf_afs_kauth_princ); \
524 OUT_RXString(hf_afs_kauth_realm); \