aboutsummaryrefslogtreecommitdiffstats
path: root/packet-afs-macros.h
blob: 31fde803104eac264b5d80bf11e55a900c5a5bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/* packet-afs-macros.h
 * Helper macros for AFS packet dissection
 * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
 * Based on routines from tcpdump patches by
 *   Ken Hornstein <kenh@cmf.nrl.navy.mil>
 * Portions based on information retrieved from the RX definitions
 *   in Arla, the free AFS client at http://www.stacken.kth.se/project/arla/
 * Portions based on information/specs retrieved from the OpenAFS sources at
 *   www.openafs.org, Copyright IBM. 
 *
 * $Id: packet-afs-macros.h,v 1.5 2000/11/03 22:38:07 nneul Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-tftp.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */



/*
 * Macros for helper dissection routines
 *
 * The macros are here to save on coding. They assume that
 * the current offset is in 'curoffset', and that the offset
 * should be incremented after performing the macro's operation.
 */

/* Get the next available integer, be sure and call TRUNC beforehand */
#define GETINT() (pntohl(&pd[curoffset]))

/* Check if enough bytes are present, if not, return to caller
   after adding a 'Truncated' message to tree */
#define TRUNC(bytes) \
	if(!BYTES_ARE_IN_FRAME(curoffset,(bytes))) \
	{	\
		proto_tree_add_text(tree, NullTVB,curoffset, \
			END_OF_FRAME,"Truncated"); \
		/* not sure why, but this didn't work */ \
		/* if (check_col(fd, COL_INFO)) */ \
			/* col_append_fstr(fd, COL_INFO, " (TRUNCATED)"); */ \
		return; \
	} 

/* Output a unsigned integer, stored into field 'field'
   Assumes it is in network byte order, converts to host before using */
#define OUT_UINT(field) \
	TRUNC(sizeof(guint32)) \
	proto_tree_add_uint(tree,field, NullTVB,curoffset,sizeof(guint32), GETINT()); \
	curoffset += 4;

/* Output a unsigned integer, stored into field 'field'
   Assumes it is in network byte order, converts to host before using */
#define OUT_INT(field) \
	TRUNC(sizeof(guint32)) \
	proto_tree_add_int(tree,field, NullTVB,curoffset,sizeof(gint32), GETINT()); \
	curoffset += 4;
	
/* Output a unsigned integer, stored into field 'field'
   Assumes it is in network byte order, converts to host before using, 
   Note - does not increment offset, so can be used repeatedly for bitfields */
#define DISP_UINT(field) \
	TRUNC(sizeof(guint32)) \
	proto_tree_add_uint(tree,field, NullTVB,curoffset,sizeof(guint32), GETINT()); 

/* Output an IPv4 address, stored into field 'field' */
#define OUT_IP(field) \
	TRUNC(sizeof(gint32)) \
	proto_tree_add_ipv4(tree,field, NullTVB,curoffset,sizeof(gint32),\
		*((int*)&pd[curoffset]));\
	curoffset += 4;

/* Output a UNIX seconds/microseconds timestamp, after converting to a timeval */
#define OUT_TIMESTAMP(field) \
	{ struct timeval tv; \
	TRUNC(2*sizeof(guint32)); \
	tv.tv_sec = GETINT(); \
	tv.tv_usec = GETINT(); \
	proto_tree_add_time(tree,field, NullTVB,curoffset,2*sizeof(guint32),&tv); \
	curoffset += 8; \
	}

/* Output a UNIX seconds-only timestamp, after converting to a timeval */
#define OUT_DATE(field) \
	{ struct timeval tv; \
	TRUNC(sizeof(guint32)); \
	tv.tv_sec = GETINT(); \
	tv.tv_usec = 0; \
	proto_tree_add_time(tree,field, NullTVB,curoffset,sizeof(guint32),&tv); \
	curoffset += 4; \
	}

/* Output a callback */
#define OUT_FS_AFSCallBack() \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 3*4, "Callback"); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_callback); \
		TRUNC(3*sizeof(guint32)); \
		OUT_UINT(hf_afs_fs_callback_version); \
		OUT_DATE(hf_afs_fs_callback_expires); \
		OUT_UINT(hf_afs_fs_callback_type); \
		tree = save; \
	}

/* Output a callback */
#define OUT_CB_AFSCallBack() \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 3*4, "Callback"); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_callback); \
		TRUNC(3*sizeof(guint32)); \
		OUT_UINT(hf_afs_cb_callback_version); \
		OUT_DATE(hf_afs_cb_callback_expires); \
		OUT_UINT(hf_afs_cb_callback_type); \
		tree = save; \
	}


/* Output a File ID */
#define OUT_FS_AFSFid(label) \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 3*4, \
			"FileID (%s)", label); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_fid); \
		OUT_UINT(hf_afs_fs_fid_volume); \
		OUT_UINT(hf_afs_fs_fid_vnode); \
		OUT_UINT(hf_afs_fs_fid_uniqifier); \
		tree = save; \
	}

/* Output a Status mask */
#define OUT_FS_STATUSMASK() \
	{ 	proto_tree *save, *ti; \
		guint32 mask; \
		TRUNC(sizeof(guint32)); \
		mask = GETINT(); \
		ti = proto_tree_add_uint(tree, hf_afs_fs_status_mask, NullTVB, curoffset, \
			sizeof(guint32), mask); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_status_mask); \
		proto_tree_add_uint(tree, hf_afs_fs_status_mask_setmodtime, \
			NullTVB,curoffset,sizeof(guint32), mask); \
		proto_tree_add_uint(tree, hf_afs_fs_status_mask_setowner, \
			NullTVB,curoffset,sizeof(guint32), mask); \
		proto_tree_add_uint(tree, hf_afs_fs_status_mask_setgroup, \
			NullTVB,curoffset,sizeof(guint32), mask); \
		proto_tree_add_uint(tree, hf_afs_fs_status_mask_setmode, \
			NullTVB,curoffset,sizeof(guint32), mask); \
		proto_tree_add_uint(tree, hf_afs_fs_status_mask_setsegsize, \
			NullTVB,curoffset,sizeof(guint32), mask); \
		proto_tree_add_uint(tree, hf_afs_fs_status_mask_fsync, \
			NullTVB,curoffset,sizeof(guint32), mask); \
		curoffset += 4; \
		tree = save; \
	}

/* Output a File ID */
#define OUT_CB_AFSFid(label) \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 3*4, \
			"FileID (%s)", label); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_fid); \
		OUT_UINT(hf_afs_cb_fid_volume); \
		OUT_UINT(hf_afs_cb_fid_vnode); \
		OUT_UINT(hf_afs_cb_fid_uniqifier); \
		tree = save; \
	}
	
/* Output a StoreStatus */
#define OUT_FS_AFSStoreStatus(label) \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 6*4, \
			label); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_status); \
		OUT_FS_STATUSMASK(); \
		OUT_DATE(hf_afs_fs_status_clientmodtime); \
		OUT_UINT(hf_afs_fs_status_owner); \
		OUT_UINT(hf_afs_fs_status_group); \
		OUT_UINT(hf_afs_fs_status_mode); \
		OUT_UINT(hf_afs_fs_status_segsize); \
		tree = save; \
	}

/* Output a FetchStatus */
#define OUT_FS_AFSFetchStatus(label) \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 21*4, \
			label); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_status); \
		OUT_UINT(hf_afs_fs_status_interfaceversion); \
		OUT_UINT(hf_afs_fs_status_filetype); \
		OUT_UINT(hf_afs_fs_status_linkcount); \
		OUT_UINT(hf_afs_fs_status_length); \
		OUT_UINT(hf_afs_fs_status_dataversion); \
		OUT_UINT(hf_afs_fs_status_author); \
		OUT_UINT(hf_afs_fs_status_owner); \
		OUT_UINT(hf_afs_fs_status_calleraccess); \
		OUT_UINT(hf_afs_fs_status_anonymousaccess); \
		OUT_UINT(hf_afs_fs_status_mode); \
		OUT_UINT(hf_afs_fs_status_parentvnode); \
		OUT_UINT(hf_afs_fs_status_parentunique); \
		OUT_UINT(hf_afs_fs_status_segsize); \
		OUT_DATE(hf_afs_fs_status_clientmodtime); \
		OUT_DATE(hf_afs_fs_status_servermodtime); \
		OUT_UINT(hf_afs_fs_status_group); \
		OUT_UINT(hf_afs_fs_status_synccounter); \
		OUT_UINT(hf_afs_fs_status_dataversionhigh); \
		OUT_UINT(hf_afs_fs_status_spare2); \
		OUT_UINT(hf_afs_fs_status_spare3); \
		OUT_UINT(hf_afs_fs_status_spare4); \
		tree = save; \
	}

/* Output a VolSync */
#define OUT_FS_AFSVolSync() \
	{ 	proto_tree *save, *ti; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 6*4, \
			"VolSync"); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_volsync); \
		OUT_UINT(hf_afs_fs_volsync_spare1); \
		OUT_UINT(hf_afs_fs_volsync_spare2); \
		OUT_UINT(hf_afs_fs_volsync_spare3); \
		OUT_UINT(hf_afs_fs_volsync_spare4); \
		OUT_UINT(hf_afs_fs_volsync_spare5); \
		OUT_UINT(hf_afs_fs_volsync_spare6); \
		tree = save; \
	}

/* Output a AFSCBFids */
#define OUT_FS_AFSCBFids() \
	{ \
		unsigned int j,i; \
		TRUNC(1); \
		j = pntohl(&pd[curoffset]); \
		curoffset += 1; \
		for (i=0; i<j; i++) { \
			OUT_FS_AFSFid("Target"); \
		} \
	}	

/* Output a ViceIds */
#define OUT_FS_ViceIds() \
	{ \
		unsigned int j,i; \
		TRUNC(1); \
		j = pntohl(&pd[curoffset]); \
		curoffset += 1; \
		for (i=0; i<j; i++) { \
			OUT_UINT(hf_afs_fs_viceid); \
		} \
	}

/* Output a IPAddrs */
#define OUT_FS_IPAddrs() \
	{ \
		unsigned int j,i; \
		TRUNC(1); \
		j = pntohl(&pd[curoffset]); \
		curoffset += 1; \
		for (i=0; i<j; i++) { \
			OUT_IP(hf_afs_fs_ipaddr); \
		} \
	}

/* Output a AFSCBs */
#define OUT_FS_AFSCBs()	\
	{ \
		unsigned int j,i; \
		TRUNC(1); \
		j = pntohl(&pd[curoffset]); \
		curoffset += 1; \
		for (i=0; i<j; i++) { \
			OUT_FS_AFSCallBack(); \
		} \
	}


/* Output a AFSBulkStats */
#define OUT_FS_AFSBulkStats() \
	{ \
		unsigned int j,i; \
		TRUNC(1); \
		j = pntohl(&pd[curoffset]); \
		curoffset += 1; \
		for (i=0; i<j; i++) { \
			OUT_FS_AFSFetchStatus("Status"); \
		} \
	}

/* Output a AFSFetchVolumeStatus */
#define OUT_FS_AFSFetchVolumeStatus()

/* Output a AFSStoreVolumeStatus */
#define OUT_FS_AFSStoreVolumeStatus()

/* Output a ViceStatistics structure */
#define OUT_FS_ViceStatistics()

/* Output a AFS_CollData structure */
#define OUT_FS_AFS_CollData()

/* Output a VolumeInfo structure */
#define OUT_FS_VolumeInfo()

/* Output an AFS Token - might just be bytes though */
#define OUT_FS_AFSTOKEN() VECOUT(hf_afs_fs_token, 1024)

/* Output a AFS acl */
#define ACLOUT(who, positive, acl, bytes) \
	{ 	proto_tree *save, *ti; \
		int tmpoffset; \
		int acllen; \
		char tmp[10]; \
		tmp[0] = 0; \
		if ( acl & PRSFS_READ ) strcat(tmp, "r"); \
		if ( acl & PRSFS_LOOKUP ) strcat(tmp, "l"); \
		if ( acl & PRSFS_INSERT ) strcat(tmp, "i"); \
		if ( acl & PRSFS_DELETE ) strcat(tmp, "d"); \
		if ( acl & PRSFS_WRITE ) strcat(tmp, "w"); \
		if ( acl & PRSFS_LOCK ) strcat(tmp, "k"); \
		if ( acl & PRSFS_ADMINISTER ) strcat(tmp, "a"); \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, bytes, \
			"ACL:  %s %s%s", \
			who, tmp, positive ? "" : " (negative)"); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_acl); \
		proto_tree_add_string(tree,hf_afs_fs_acl_entity, NullTVB,curoffset,strlen(who), who);\
		tmpoffset = curoffset + strlen(who) + 1; \
		acllen = bytes - strlen(who) - 1; \
		proto_tree_add_uint(tree,hf_afs_fs_acl_r, NullTVB,tmpoffset,acllen,acl);\
		proto_tree_add_uint(tree,hf_afs_fs_acl_l, NullTVB,tmpoffset,acllen,acl);\
		proto_tree_add_uint(tree,hf_afs_fs_acl_i, NullTVB,tmpoffset,acllen,acl);\
		proto_tree_add_uint(tree,hf_afs_fs_acl_d, NullTVB,tmpoffset,acllen,acl);\
		proto_tree_add_uint(tree,hf_afs_fs_acl_w, NullTVB,tmpoffset,acllen,acl);\
		proto_tree_add_uint(tree,hf_afs_fs_acl_k, NullTVB,tmpoffset,acllen,acl);\
		proto_tree_add_uint(tree,hf_afs_fs_acl_a, NullTVB,tmpoffset,acllen,acl);\
		tree = save; \
	}

/* output a bozo_key */
#define OUT_BOS_KEY() \
	OUT_BYTES(hf_afs_bos_key, 8);

/* output a bozo_key */
#define OUT_BOS_KEYINFO() \
	OUT_TIMESTAMP(hf_afs_bos_keymodtime); \
	OUT_UINT(hf_afs_bos_keychecksum); \
	OUT_UINT(hf_afs_bos_keyspare2);

/* output a bozo_netKTime */
#define OUT_BOS_TIME() \
	SKIP(4); SKIP(2); SKIP(2); SKIP(2); SKIP(2);

/* output a bozo_status */
#define OUT_BOS_STATUS() \
	SKIP(10 * 4);

/* Skip a certain number of bytes */
#define SKIP(bytes) \
	TRUNC(bytes) \
	curoffset += bytes;
	
/* Raw data - to end of frame */
#define OUT_BYTES_ALL(field) OUT_BYTES(field, offset+END_OF_FRAME-curoffset)

/* Raw data */
#define OUT_BYTES(field, bytes) \
	TRUNC(bytes); \
	proto_tree_add_bytes(tree,field, NullTVB,curoffset,bytes,\
		(void *)&pd[curoffset]); \
	curoffset += bytes;

/* Output a rx style string, up to a maximum length first 
   4 bytes - length, then char data */
#define OUT_STRING(field) \
	{	int i; \
		TRUNC(4); \
		i = GETINT(); \
		curoffset += 4; \
		if ( i > 0 ) { \
			char *tmp; \
			TRUNC(i); \
			tmp = g_malloc(i+1); \
			memcpy(tmp, &pd[curoffset], i); \
			tmp[i] = '\0'; \
			proto_tree_add_string(tree, field, NullTVB, curoffset-4, i+4, \
			(void *)tmp); \
			g_free(tmp); \
		} else { \
			proto_tree_add_string(tree, field, NullTVB, curoffset-4, 4, \
			""); \
		} \
		curoffset += i; \
	}

/* Output a fixed length vectorized string (each char is a 32 bit int) */
#define VECOUT(field, length) \
	{ 	char tmp[length+1]; \
		int i,soff; \
		soff = curoffset;\
		TRUNC(length * sizeof(guint32));\
		for (i=0; i<length; i++)\
		{\
			tmp[i] = (char) GETINT();\
			curoffset += sizeof(guint32);\
		}\
		tmp[length] = '\0';\
		proto_tree_add_string(tree, field, NullTVB, soff, length, tmp);\
	}

/* Skip the opcode */
#define SKIP_OPCODE() \
	{ \
		SKIP(sizeof(guint32)); \
	}

/* Output a UBIK version code */
#define OUT_UBIKVERSION(label) \
	{ 	proto_tree *save, *ti; \
		unsigned int epoch,counter; \
		struct timeval tv; \
		TRUNC(8); \
		epoch = GETINT(); \
		curoffset += 4; \
		counter = GETINT(); \
		curoffset += 4; \
		tv.tv_sec = epoch; \
		tv.tv_usec = 0; \
		ti = proto_tree_add_text(tree, NullTVB, curoffset, 3*4, \
			"UBIK Version (%s): %u.%u", label, epoch, counter ); \
		save = tree; \
		tree = proto_item_add_subtree(ti, ett_afs_ubikver); \
		proto_tree_add_time(tree,hf_afs_ubik_version_epoch, NullTVB,curoffset-8, \
			sizeof(guint32),&tv); \
		proto_tree_add_uint(tree,hf_afs_ubik_version_counter, NullTVB,curoffset-4, \
			sizeof(guint32),counter); \
		tree = save; \
	}