70f4dff6e49303d7bc14bb315a99dc15135f0f38
[obnox/wireshark/wip.git] / packet-afs.c
1 /* packet-afs.c
2  * Routines 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.c,v 1.38 2002/01/18 21:46:51 nneul 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 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <stdio.h>
39
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
42 #endif
43
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
46 #endif
47
48 #include <string.h>
49 #include <glib.h>
50 #include "packet.h"
51 #include "conversation.h"
52 #include "resolv.h"
53
54 #include "packet-rx.h"
55 #include "packet-afs.h"
56 #include "packet-afs-defs.h"
57 #include "packet-afs-macros.h"
58
59 #define GETSTR tvb_get_ptr(tvb,offset,tvb_length_remaining(tvb,offset))
60
61 #define VALID_OPCODE(opcode) ((opcode >= OPCODE_LOW && opcode <= OPCODE_HIGH) || \
62                 (opcode >= VOTE_LOW && opcode <= VOTE_HIGH) || \
63                 (opcode >= DISK_LOW && opcode <= DISK_HIGH))
64
65 int afs_packet_init_count = 100;
66
67 struct afs_request_key {
68   guint32 conversation, callnumber;
69   guint16 service;
70 };
71
72 struct afs_request_val {
73   guint32 opcode;
74 };
75
76 GHashTable *afs_request_hash = NULL;
77 GMemChunk *afs_request_keys = NULL;
78 GMemChunk *afs_request_vals = NULL;
79
80
81
82 /*
83  * Dissector prototypes
84  */
85 static int dissect_acl(tvbuff_t *tvb, struct rxinfo *rxinfo, 
86         proto_tree *tree, int offset);
87 static void dissect_fs_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
88         proto_tree *tree, int offset, int opcode);
89 static void dissect_fs_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
90         proto_tree *tree, int offset, int opcode);
91 static void dissect_bos_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
92         proto_tree *tree, int offset, int opcode);
93 static void dissect_bos_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
94         proto_tree *tree, int offset, int opcode);
95 static void dissect_vol_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
96         proto_tree *tree, int offset, int opcode);
97 static void dissect_vol_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
98         proto_tree *tree, int offset, int opcode);
99 static void dissect_kauth_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
100         proto_tree *tree, int offset, int opcode);
101 static void dissect_kauth_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
102         proto_tree *tree, int offset, int opcode);
103 static void dissect_cb_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
104         proto_tree *tree, int offset, int opcode);
105 static void dissect_cb_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
106         proto_tree *tree, int offset, int opcode);
107 static void dissect_prot_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
108         proto_tree *tree, int offset, int opcode);
109 static void dissect_prot_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
110         proto_tree *tree, int offset, int opcode);
111 static void dissect_vldb_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
112         proto_tree *tree, int offset, int opcode);
113 static void dissect_vldb_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
114         proto_tree *tree, int offset, int opcode);
115 static void dissect_ubik_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
116         proto_tree *tree, int offset, int opcode);
117 static void dissect_ubik_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
118         proto_tree *tree, int offset, int opcode);
119 static void dissect_backup_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, 
120         proto_tree *tree, int offset, int opcode);
121 static void dissect_backup_request(tvbuff_t *tvb, struct rxinfo *rxinfo, 
122         proto_tree *tree, int offset, int opcode);
123
124 /*
125  * Hash Functions
126  */
127 static gint
128 afs_equal(gconstpointer v, gconstpointer w)
129 {
130   struct afs_request_key *v1 = (struct afs_request_key *)v;
131   struct afs_request_key *v2 = (struct afs_request_key *)w;
132
133   if (v1 -> conversation == v2 -> conversation &&
134       v1 -> service == v2 -> service &&
135       v1 -> callnumber == v2 -> callnumber ) {
136
137     return 1;
138   }
139
140   return 0;
141 }
142
143 static guint
144 afs_hash (gconstpointer v)
145 {
146         struct afs_request_key *key = (struct afs_request_key *)v;
147         guint val;
148
149         val = key -> conversation + key -> service + key -> callnumber;
150
151         return val;
152 }
153
154 /*
155  * Protocol initialization
156  */
157 static void
158 afs_init_protocol(void)
159 {
160         if (afs_request_hash)
161                 g_hash_table_destroy(afs_request_hash);
162         if (afs_request_keys)
163                 g_mem_chunk_destroy(afs_request_keys);
164         if (afs_request_vals)
165                 g_mem_chunk_destroy(afs_request_vals);
166
167         afs_request_hash = g_hash_table_new(afs_hash, afs_equal);
168         afs_request_keys = g_mem_chunk_new("afs_request_keys",
169                 sizeof(struct afs_request_key),
170                 afs_packet_init_count * sizeof(struct afs_request_key),
171                 G_ALLOC_AND_FREE);
172         afs_request_vals = g_mem_chunk_new("afs_request_vals",
173                 sizeof(struct afs_request_val),
174                 afs_packet_init_count * sizeof(struct afs_request_val),
175                 G_ALLOC_AND_FREE);
176 }
177
178
179
180 /*
181  * Dissection routines
182  */
183
184 static void
185 dissect_afs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
186 {
187         struct rxinfo *rxinfo = pinfo->private_data;
188         int reply = 0;
189         conversation_t *conversation;
190         struct afs_request_key request_key, *new_request_key;
191         struct afs_request_val *request_val;
192         proto_tree      *afs_tree, *afs_op_tree, *ti;
193         int port, node, typenode, opcode;
194         value_string const *vals;
195         int offset = 0;
196         void (*dissector)(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode);
197
198
199         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
200                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AFS (RX)");
201         }
202         if (check_col(pinfo->cinfo, COL_INFO)) {
203                 col_clear(pinfo->cinfo, COL_INFO);
204         }
205
206         reply = (rxinfo->flags & RX_CLIENT_INITIATED) == 0;
207         port = ((reply == 0) ? pinfo->destport : pinfo->srcport );
208
209         /*
210          * Find out what conversation this packet is part of.
211          * XXX - this should really be done by the transport-layer protocol,
212          * although for connectionless transports, we may not want to do that
213          * unless we know some higher-level protocol will want it - or we
214          * may want to do it, so you can say e.g. "show only the packets in
215          * this UDP 'connection'".
216          *
217          * Note that we don't have to worry about the direction this packet
218          * was going - the conversation code handles that for us, treating
219          * packets from A:X to B:Y as being part of the same conversation as
220          * packets from B:Y to A:X.
221          */
222         conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype,
223             pinfo->srcport, pinfo->destport, 0);
224         if (conversation == NULL) {
225                 /* It's not part of any conversation - create a new one. */
226                 conversation = conversation_new(&pinfo->src, &pinfo->dst, 
227                         pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
228         }
229
230         request_key.conversation = conversation->index; 
231         request_key.service = rxinfo->serviceid;
232         request_key.callnumber = rxinfo->callnumber;
233
234         request_val = (struct afs_request_val *) g_hash_table_lookup(
235                 afs_request_hash, &request_key);
236
237         /* only allocate a new hash element when it's a request */
238         opcode = 0;
239         if ( !request_val && !reply) {
240                 new_request_key = g_mem_chunk_alloc(afs_request_keys);
241                 *new_request_key = request_key;
242
243                 request_val = g_mem_chunk_alloc(afs_request_vals);
244                 request_val -> opcode = tvb_get_ntohl(tvb, offset);
245
246                 g_hash_table_insert(afs_request_hash, new_request_key,
247                         request_val);
248         }
249
250         if ( request_val ) {
251                 opcode = request_val->opcode;
252         }
253
254         node = 0;
255         typenode = 0;
256         vals = NULL;
257         dissector = NULL;
258         switch (port) {
259                 case AFS_PORT_FS:
260                         typenode = hf_afs_fs;
261                         node = hf_afs_fs_opcode;
262                         vals = fs_req;
263                         dissector = reply ? dissect_fs_reply : dissect_fs_request;
264                         break;
265                 case AFS_PORT_CB:
266                         typenode = hf_afs_cb;
267                         node = hf_afs_cb_opcode;
268                         vals = cb_req;
269                         dissector = reply ? dissect_cb_reply : dissect_cb_request;
270                         break;
271                 case AFS_PORT_PROT:
272                         typenode = hf_afs_prot;
273                         node = hf_afs_prot_opcode;
274                         vals = prot_req;
275                         dissector = reply ? dissect_prot_reply : dissect_prot_request;
276                         break;
277                 case AFS_PORT_VLDB:
278                         typenode = hf_afs_vldb;
279                         node = hf_afs_vldb_opcode;
280                         vals = vldb_req;
281                         dissector = reply ? dissect_vldb_reply : dissect_vldb_request;
282                         break;
283                 case AFS_PORT_KAUTH:
284                         typenode = hf_afs_kauth;
285                         node = hf_afs_kauth_opcode;
286                         vals = kauth_req;
287                         dissector = reply ? dissect_kauth_reply : dissect_kauth_request;
288                         break;
289                 case AFS_PORT_VOL:
290                         typenode = hf_afs_vol;
291                         node = hf_afs_vol_opcode;
292                         vals = vol_req;
293                         dissector = reply ? dissect_vol_reply : dissect_vol_request;
294                         break;
295                 case AFS_PORT_ERROR:
296                         typenode = hf_afs_error;
297                         node = hf_afs_error_opcode;
298                         /* dissector = reply ? dissect_error_reply : dissect_error_request; */
299                         break;
300                 case AFS_PORT_BOS:
301                         typenode = hf_afs_bos;
302                         node = hf_afs_bos_opcode;
303                         vals = bos_req;
304                         dissector = reply ? dissect_bos_reply : dissect_bos_request;
305                         break;
306                 case AFS_PORT_UPDATE:
307                         typenode = hf_afs_update;
308                         node = hf_afs_update_opcode;
309                         vals = update_req;
310                         /* dissector = reply ? dissect_update_reply : dissect_update_request; */
311                         break;
312                 case AFS_PORT_RMTSYS:
313                         typenode = hf_afs_rmtsys;
314                         node = hf_afs_rmtsys_opcode;
315                         vals = rmtsys_req;
316                         /* dissector = reply ? dissect_rmtsys_reply : dissect_rmtsys_request; */
317                         break;
318                 case AFS_PORT_BACKUP:
319                         typenode = hf_afs_backup;
320                         node = hf_afs_backup_opcode;
321                         vals = backup_req;
322                         dissector = reply ? dissect_backup_reply : dissect_backup_request;
323                         break;
324         }
325
326         if ( (opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
327                 (opcode >= DISK_LOW && opcode <= DISK_HIGH) ) {
328                 typenode = hf_afs_ubik;
329                 node = hf_afs_ubik_opcode;
330                 vals = ubik_req;
331                 dissector = reply ? dissect_ubik_reply : dissect_ubik_request;
332         }
333
334
335         if ( VALID_OPCODE(opcode) ) {
336                 if ( vals ) {
337                         if (check_col(pinfo->cinfo, COL_INFO))
338                                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s%s %s: %s (%d)",
339                                 typenode == hf_afs_ubik ? "UBIK-" : "",
340                                 val_to_str(port, port_types_short, "Unknown(%d)"),
341                                 reply ? "Reply" : "Request",
342                                 val_to_str(opcode, vals, "Unknown(%d)"), opcode);
343                 } else {
344                         if (check_col(pinfo->cinfo, COL_INFO))
345                                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s%s %s: Unknown(%d)",
346                                 typenode == hf_afs_ubik ? "UBIK-" : "",
347                                 val_to_str(port, port_types_short, "Unknown(%d)"),
348                                 reply ? "Reply" : "Request",
349                                 opcode);
350                 }
351         } else {
352                 if (check_col(pinfo->cinfo, COL_INFO))
353                         col_add_fstr(pinfo->cinfo, COL_INFO, "Encrypted %s %s",
354                         val_to_str(port, port_types_short, "Unknown(%d)"),
355                         reply ? "Reply" : "Request"
356                         );
357         }
358
359         if (tree) {
360                 ti = proto_tree_add_item(tree, proto_afs, tvb, offset, 
361                                 tvb_length_remaining(tvb, offset), FALSE);
362                 afs_tree = proto_item_add_subtree(ti, ett_afs);
363
364                 proto_tree_add_text(afs_tree, tvb,
365                         offset, tvb_length_remaining(tvb, offset),
366                         "Service: %s%s%s %s",
367                         VALID_OPCODE(opcode) ? "" : "Encrypted ",
368                         typenode == hf_afs_ubik ? "UBIK - " : "",
369                         val_to_str(port, port_types, "Unknown(%d)"),
370                         reply ? "Reply" : "Request");
371
372                 if ( VALID_OPCODE(opcode) ) {
373                         /* until we do cache, can't handle replies */
374                         ti = NULL;
375                         if ( !reply && node != 0 ) {
376                                 if ( rxinfo->seq == 1 )
377                                 {
378                                         ti = proto_tree_add_uint(afs_tree,
379                                                 node, tvb, offset, 4, opcode);
380                                 } else {
381                                         ti = proto_tree_add_uint(afs_tree,
382                                                 node, tvb, offset, 0, opcode);
383                                 }
384                         } else if ( reply && node != 0 ) {
385                                 /* the opcode isn't in this packet */
386                                 ti = proto_tree_add_uint(afs_tree,
387                                         node, tvb, offset, 0, opcode);
388                         } else {
389                                 ti = proto_tree_add_text(afs_tree, tvb,
390                                         offset, 0, "Operation: Unknown");
391                         }
392         
393                         /* Add the subtree for this particular service */
394                         afs_op_tree = proto_item_add_subtree(ti, ett_afs_op);
395         
396                         if ( typenode != 0 ) {
397                                 /* indicate the type of request */
398                                 proto_tree_add_boolean_hidden(afs_tree, typenode, tvb, offset, 0, 1);
399                         }
400         
401                         /* Process the packet according to what service it is */
402                         if ( dissector ) {
403                                 (*dissector)(tvb, rxinfo, afs_op_tree, offset, opcode);
404                         }
405                 }
406         }
407
408         /* if it's the last packet, and it's a reply, remove opcode
409                 from hash */
410         /* ignoring for now, I'm not sure how the chunk deallocation works */
411         if ( rxinfo->flags & RX_LAST_PACKET && reply ){
412
413         }
414 }
415
416
417 /*
418  * Here is a helper routine for adding an AFS acl to the proto tree
419  * This is to be used with FS packets only
420  *
421  * An AFS ACL is a string that has the following format:
422  *
423  * <positive> <negative>
424  * <uid1> <aclbits1>
425  * ....
426  *
427  * "positive" and "negative" are integers which contain the number of
428  * positive and negative ACL's in the string.  The uid/aclbits pair are
429  * ASCII strings containing the UID/PTS record and and a ascii number
430  * representing a logical OR of all the ACL permission bits
431  */
432 /* FIXME: sscanf is probably quite dangerous if we run outside the packet. */
433 static int 
434 dissect_acl(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset)
435 {
436         int old_offset;
437         gint32 bytes;
438         int i, n, pos, neg, acl;
439         char user[128]; /* Be sure to adjust sscanf()s below if length is changed... */
440
441         old_offset = offset;
442         bytes = tvb_get_ntohl(tvb, offset);
443         OUT_UINT(hf_afs_fs_acl_datasize);
444
445
446         if (sscanf((char *) GETSTR, "%d %n", &pos, &n) != 1) {
447                 /* does not matter what we return, if this fails, 
448                  * we cant dissect anything else in the packet either.
449                  */
450                 return offset;
451         }
452         proto_tree_add_uint(tree, hf_afs_fs_acl_count_positive, tvb, 
453                 offset, n, pos);
454         offset += n;
455
456
457         if (sscanf((char *) GETSTR, "%d %n", &neg, &n) != 1) {
458                 return offset;
459         }
460         proto_tree_add_uint(tree, hf_afs_fs_acl_count_negative, tvb, 
461                 offset, n, neg);
462         offset += n;
463
464         /*
465          * This wacky order preserves the order used by the "fs" command
466          */
467         for (i = 0; i < pos; i++) {
468                 if (sscanf((char *) GETSTR, 
469                                 "%127s %d %n", user, &acl, &n) != 2) {
470                         return offset;
471                 }
472                 ACLOUT(user,1,acl,n);
473                 offset += n;
474         }
475         for (i = 0; i < neg; i++) {
476                 if (sscanf((char *) GETSTR, 
477                         "%127s %d %n", user, &acl, &n) != 2) {
478                         return offset;
479                 }
480                 ACLOUT(user,0,acl,n);
481                 offset += n;
482                 if (offset >= old_offset+bytes ) {
483                         return offset;
484                 }
485         }
486
487         return offset;
488 }
489
490 /*
491  * Here are the helper dissection routines
492  */
493
494 static void
495 dissect_fs_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
496 {
497         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
498         {
499                 switch ( opcode )
500                 {
501                         case 130: /* fetch data */
502                                 /* only on first packet */
503                                 if ( rxinfo->seq == 1 )
504                                 {
505                                         OUT_FS_AFSFetchStatus("Status");
506                                         OUT_FS_AFSCallBack();
507                                         OUT_FS_AFSVolSync();
508                                 }
509                                 OUT_BYTES_ALL(hf_afs_fs_data);
510                                 break;
511                         case 131: /* fetch acl */
512                                 offset = dissect_acl(tvb, rxinfo, tree, offset);
513                                 OUT_FS_AFSFetchStatus("Status");
514                                 OUT_FS_AFSVolSync();
515                                 break;
516                         case 132: /* Fetch status */
517                                 OUT_FS_AFSFetchStatus("Status");
518                                 OUT_FS_AFSCallBack();
519                                 OUT_FS_AFSVolSync();
520                                 break;  
521                         case 133: /* Store data */
522                         case 134: /* Store ACL */
523                         case 135: /* Store status */
524                         case 136: /* Remove file */
525                                 OUT_FS_AFSFetchStatus("Status");
526                                 OUT_FS_AFSVolSync();
527                                 break;
528                         case 137: /* create file */
529                         case 141: /* make dir */
530                         case 161: /* lookup */
531                         case 163: /* dfs symlink */
532                                 OUT_FS_AFSFid((opcode == 137)? "New File" : ((opcode == 141)? "New Directory" : "File"));
533                                 OUT_FS_AFSFetchStatus("File Status");
534                                 OUT_FS_AFSFetchStatus("Directory Status");
535                                 OUT_FS_AFSCallBack();
536                                 OUT_FS_AFSVolSync();
537                                 break;
538                         case 138: /* rename */
539                                 OUT_FS_AFSFetchStatus("Old Directory Status");
540                                 OUT_FS_AFSFetchStatus("New Directory Status");
541                                 OUT_FS_AFSVolSync();
542                                 break;
543                         case 139: /* symlink */
544                                 OUT_FS_AFSFid("Symlink");
545                         case 140: /* link */
546                                 OUT_FS_AFSFetchStatus("Symlink Status");
547                         case 142: /* rmdir */
548                                 OUT_FS_AFSFetchStatus("Directory Status");
549                                 OUT_FS_AFSVolSync();
550                                 break;
551                         case 143: /* old set lock */
552                         case 144: /* old extend lock */
553                         case 145: /* old release lock */
554                         case 147: /* give up callbacks */
555                         case 150: /* set volume status */
556                         case 152: /* check token */ 
557                                 /* nothing returned */
558                                 break;
559                         case 146: /* get statistics */
560                                 OUT_FS_ViceStatistics();
561                                 break;
562                         case 148: /* get volume info */
563                         case 154: /* n-get-volume-info */
564                                 OUT_FS_VolumeInfo();
565                                 break;
566                         case 149: /* get volume status */
567                                 OUT_FS_AFSFetchVolumeStatus();
568                                 OUT_STRING(hf_afs_fs_volname);
569                                 OUT_STRING(hf_afs_fs_offlinemsg);
570                                 OUT_STRING(hf_afs_fs_motd);
571                                 break;
572                         case 151: /* root volume */
573                                 OUT_STRING(hf_afs_fs_volname);
574                                 break;
575                         case 153: /* get time */
576                                 OUT_TIMESTAMP(hf_afs_fs_timestamp);
577                                 break;
578                         case 155: /* bulk status */
579                                 OUT_FS_AFSBulkStats();
580                                 SKIP(4); 
581                                 OUT_FS_AFSCBs();
582                                 OUT_FS_AFSVolSync();
583                                 break;
584                         case 156: /* set lock */
585                         case 157: /* extend lock */
586                         case 158: /* release lock */
587                                 OUT_FS_AFSVolSync();
588                                 break;
589                         case 159: /* x-stats-version */
590                                 OUT_UINT(hf_afs_fs_xstats_version);
591                                 break;
592                         case 160: /* get xstats */
593                                 OUT_UINT(hf_afs_fs_xstats_version);
594                                 OUT_DATE(hf_afs_fs_xstats_timestamp);
595                                 OUT_FS_AFS_CollData();
596                                 break;
597                         case 162: /* flush cps */
598                                 OUT_UINT(hf_afs_fs_cps_spare2);
599                                 OUT_UINT(hf_afs_fs_cps_spare3);
600                                 break;
601                 }
602         }
603         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
604         {
605                 OUT_UINT(hf_afs_fs_errcode);
606         }
607 }
608
609 static void
610 dissect_fs_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
611 {
612         /* skip the opcode if this is the first packet in the stream */
613         if ( rxinfo->seq == 1 )
614         {
615                 offset += 4;  /* skip the opcode */
616         }
617
618         switch ( opcode )
619         {
620                 case 130: /* Fetch data */
621                         OUT_FS_AFSFid("Source");
622                         OUT_UINT(hf_afs_fs_offset);
623                         OUT_UINT(hf_afs_fs_length);
624                         break;
625                 case 131: /* Fetch ACL */
626                         OUT_FS_AFSFid("Target");
627                         break;          
628                 case 132: /* Fetch Status */
629                         OUT_FS_AFSFid("Target");
630                         break;
631                 case 133: /* Store Data */
632                         if ( rxinfo->seq == 1 )
633                         {
634                                 OUT_FS_AFSFid("Destination");
635                                 OUT_FS_AFSStoreStatus("Status");
636                                 OUT_UINT(hf_afs_fs_offset);
637                                 OUT_UINT(hf_afs_fs_length);
638                                 OUT_UINT(hf_afs_fs_flength);
639                         }
640                         OUT_BYTES_ALL(hf_afs_fs_data);
641                         break;
642                 case 134: /* Store ACL */
643                         OUT_FS_AFSFid("Target");
644                         offset = dissect_acl(tvb, rxinfo, tree, offset);
645                         break;
646                 case 135: /* Store Status */
647                         OUT_FS_AFSFid("Target");
648                         OUT_FS_AFSStoreStatus("Status");
649                         break;
650                 case 136: /* Remove File */
651                         OUT_FS_AFSFid("Remove File");
652                         OUT_STRING(hf_afs_fs_name);
653                         break;
654                 case 137: /* Create File */
655                         OUT_FS_AFSFid("Target");
656                         OUT_STRING(hf_afs_fs_name);
657                         OUT_FS_AFSStoreStatus("Status");
658                         break;
659                 case 138: /* Rename file */
660                         OUT_FS_AFSFid("Old");
661                         OUT_STRING(hf_afs_fs_oldname);
662                         OUT_FS_AFSFid("New");
663                         OUT_STRING(hf_afs_fs_newname);
664                         break;
665                 case 139: /* Symlink */
666                         OUT_FS_AFSFid("File");
667                         OUT_STRING(hf_afs_fs_symlink_name);
668                         OUT_STRING(hf_afs_fs_symlink_content);
669                         OUT_FS_AFSStoreStatus("Status");
670                         break;
671                 case 140: /* Link */
672                         OUT_FS_AFSFid("Link To (New File)");
673                         OUT_STRING(hf_afs_fs_name);
674                         OUT_FS_AFSFid("Link From (Old File)");
675                         break;
676                 case 141: /* Make dir */
677                         OUT_FS_AFSFid("Target");
678                         OUT_STRING(hf_afs_fs_name);
679                         OUT_FS_AFSStoreStatus("Status");
680                         break;
681                 case 142: /* Remove dir */
682                         OUT_FS_AFSFid("Target");
683                         OUT_STRING(hf_afs_fs_name);
684                         break;
685                 case 143: /* Old Set Lock */
686                         OUT_FS_AFSFid("Target");
687                         OUT_UINT(hf_afs_fs_vicelocktype);
688                         OUT_FS_AFSVolSync();
689                         break;
690                 case 144: /* Old Extend Lock */
691                         OUT_FS_AFSFid("Target");
692                         OUT_FS_AFSVolSync();
693                         break;
694                 case 145: /* Old Release Lock */
695                         OUT_FS_AFSFid("Target");
696                         OUT_FS_AFSVolSync();
697                         break;
698                 case 146: /* Get statistics */
699                         /* no params */
700                         break;
701                 case 147: /* Give up callbacks */
702                         OUT_FS_AFSCBFids();
703                         OUT_FS_AFSCBs();
704                         break;
705                 case 148: /* Get vol info */
706                         OUT_STRING(hf_afs_fs_volname);
707                         break;
708                 case 149: /* Get vol stats */
709                         OUT_UINT(hf_afs_fs_volid);
710                         break;
711                 case 150: /* Set vol stats */
712                         OUT_UINT(hf_afs_fs_volid);
713                         OUT_FS_AFSStoreVolumeStatus();
714                         OUT_STRING(hf_afs_fs_volname);
715                         OUT_STRING(hf_afs_fs_offlinemsg);
716                         OUT_STRING(hf_afs_fs_motd);
717                         break;
718                 case 151: /* get root volume */
719                         /* no params */
720                         break;
721                 case 152: /* check token */
722                         OUT_UINT(hf_afs_fs_viceid);
723                         OUT_FS_AFSTOKEN();
724                         break;
725                 case 153: /* get time */
726                         /* no params */
727                         break;
728                 case 154: /* new get vol info */
729                         OUT_STRING(hf_afs_fs_volname);
730                         break;
731                 case 155: /* bulk stat */
732                         OUT_FS_AFSCBFids();
733                         break;
734                 case 156: /* Set Lock */
735                         OUT_FS_AFSFid("Target");
736                         OUT_UINT(hf_afs_fs_vicelocktype);
737                         break;
738                 case 157: /* Extend Lock */
739                         OUT_FS_AFSFid("Target");
740                         break;
741                 case 158: /* Release Lock */
742                         OUT_FS_AFSFid("Target");
743                         break;
744                 case 159: /* xstats version */
745                         /* no params */
746                         break;
747                 case 160: /* get xstats */
748                         OUT_UINT(hf_afs_fs_xstats_clientversion);
749                         OUT_UINT(hf_afs_fs_xstats_collnumber);
750                         break;
751                 case 161: /* lookup */
752                         OUT_FS_AFSFid("Target");
753                         OUT_STRING(hf_afs_fs_name);
754                         break;
755                 case 162: /* flush cps */
756                         OUT_FS_ViceIds();
757                         OUT_FS_IPAddrs();
758                         OUT_UINT(hf_afs_fs_cps_spare1);
759                         break;
760                 case 163: /* dfs symlink */
761                         OUT_FS_AFSFid("Target");
762                         OUT_STRING(hf_afs_fs_symlink_name);
763                         OUT_STRING(hf_afs_fs_symlink_content);
764                         OUT_FS_AFSStoreStatus("Symlink Status");
765                         break;
766         }
767 }
768
769 /*
770  * BOS Helpers
771  */
772 static void
773 dissect_bos_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
774 {
775         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
776         {
777                 switch ( opcode )
778                 {
779                         case 80: /* create bnode */
780                                 /* no output */
781                                 break;
782                         case 81: /* delete bnode */
783                                 /* no output */
784                                 break;
785                         case 82: /* set status */
786                                 /* no output */
787                                 break;
788                         case 83: /* get status */
789                                 OUT_INT(hf_afs_bos_status);
790                                 OUT_STRING(hf_afs_bos_statusdesc);
791                                 break;
792                         case 84: /* enumerate instance */
793                                 OUT_STRING(hf_afs_bos_instance);
794                                 break;
795                         case 85: /* get instance info */
796                                 OUT_STRING(hf_afs_bos_type);
797                                 OUT_BOS_STATUS();
798                                 break;
799                         case 86: /* get instance parm */
800                                 OUT_STRING(hf_afs_bos_parm);
801                                 break;
802                         case 87: /* add siperuser */
803                                 /* no output */
804                                 break;
805                         case 88: /* delete superuser */
806                                 /* no output */
807                                 break;
808                         case 89: /* list superusers */
809                                 OUT_STRING(hf_afs_bos_user);
810                                 break;
811                         case 90: /* list keys */
812                                 OUT_UINT(hf_afs_bos_kvno);
813                                 OUT_BOS_KEY();
814                                 OUT_BOS_KEYINFO();
815                                 break;
816                         case 91: /* add key */
817                                 /* no output */
818                                 break;
819                         case 92: /* delete key */
820                                 /* no output */
821                                 break;
822                         case 93: /* set cell name */
823                                 /* no output */
824                                 break;
825                         case 94: /* get cell name */
826                                 OUT_STRING(hf_afs_bos_cell);
827                                 break;
828                         case 95: /* get cell host */
829                                 OUT_STRING(hf_afs_bos_host);
830                                 break;
831                         case 96: /* add cell host */
832                                 /* no output */
833                                 break;
834                         case 97: /* delete cell host */
835                                 /* no output */
836                                 break;
837                         case 98: /* set tstatus */
838                                 /* no output */
839                                 break;
840                         case 99: /* shutdown all */
841                                 /* no output */
842                                 break;
843                         case 100: /* restart all */
844                                 /* no output */
845                                 break;
846                         case 101: /* startup all */
847                                 /* no output */
848                                 break;
849                         case 102: /* set noauth flag */
850                                 /* no output */
851                                 break;
852                         case 103: /* rebozo */
853                                 /* no output */
854                                 break;
855                         case 104: /* restart */
856                                 /* no output */
857                                 break;
858                         case 105: /* install */
859                                 /* no output */
860                                 break;
861                         case 106: /* uninstall */
862                                 /* no output */
863                                 break;
864                         case 107: /* get dates */
865                                 OUT_DATE(hf_afs_bos_newtime);
866                                 OUT_DATE(hf_afs_bos_baktime);
867                                 OUT_DATE(hf_afs_bos_oldtime);
868                                 break;
869                         case 108: /* exec */
870                                 /* no output */
871                                 break;
872                         case 109: /* prune */
873                                 /* no output */
874                                 break;
875                         case 110: /* set restart time */
876                                 /* no output */
877                                 break;
878                         case 111: /* get restart time */
879                                 OUT_BOS_TIME();
880                                 break;
881                         case 112: /* get log */
882                                 /* need to make this dump a big string somehow */
883                                 OUT_BYTES_ALL(hf_afs_bos_data);
884                                 break;
885                         case 113: /* wait all */
886                                 /* no output */
887                                 break;
888                         case 114: /* get instance strings */
889                                 OUT_STRING(hf_afs_bos_error);
890                                 OUT_STRING(hf_afs_bos_spare1);
891                                 OUT_STRING(hf_afs_bos_spare2);
892                                 OUT_STRING(hf_afs_bos_spare3);
893                                 break;
894                 }
895         }
896         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
897         {
898                 OUT_UINT(hf_afs_bos_errcode);
899         }
900 }
901
902 static void
903 dissect_bos_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
904 {
905         offset += 4;  /* skip the opcode */
906
907         switch ( opcode )
908         {
909                 case 80: /* create b node */
910                         OUT_STRING(hf_afs_bos_type);
911                         OUT_STRING(hf_afs_bos_instance);
912                         OUT_STRING(hf_afs_bos_parm);
913                         OUT_STRING(hf_afs_bos_parm);
914                         OUT_STRING(hf_afs_bos_parm);
915                         OUT_STRING(hf_afs_bos_parm);
916                         OUT_STRING(hf_afs_bos_parm);
917                         OUT_STRING(hf_afs_bos_parm);
918                         break;
919                 case 81: /* delete b node */
920                         OUT_STRING(hf_afs_bos_instance);
921                         break;
922                 case 82: /* set status */
923                         OUT_STRING(hf_afs_bos_instance);
924                         OUT_UINT(hf_afs_bos_status);
925                         break;
926                 case 83: /* get status */
927                         OUT_STRING(hf_afs_bos_instance);
928                         break;
929                 case 84: /* enumerate instance */
930                         OUT_UINT(hf_afs_bos_num);
931                         break;
932                 case 85: /* get instance info */
933                         OUT_STRING(hf_afs_bos_instance);
934                         break;
935                 case 86: /* get instance parm */
936                         OUT_STRING(hf_afs_bos_instance);
937                         OUT_UINT(hf_afs_bos_num);
938                         break;
939                 case 87: /* add super user */
940                         OUT_STRING(hf_afs_bos_user);
941                         break;
942                 case 88: /* delete super user */
943                         OUT_STRING(hf_afs_bos_user);
944                         break;
945                 case 89: /* list super users */
946                         OUT_UINT(hf_afs_bos_num);
947                         break;
948                 case 90: /* list keys */
949                         OUT_UINT(hf_afs_bos_num);
950                         break;
951                 case 91: /* add key */
952                         OUT_UINT(hf_afs_bos_num);
953                         OUT_BOS_KEY();
954                         break;
955                 case 92: /* delete key */
956                         OUT_UINT(hf_afs_bos_num);
957                         break;
958                 case 93: /* set cell name */
959                         OUT_STRING(hf_afs_bos_content);
960                         break;
961                 case 95: /* set cell host */
962                         OUT_UINT(hf_afs_bos_num);
963                         break;
964                 case 96: /* add cell host */
965                         OUT_STRING(hf_afs_bos_content);
966                         break;
967                 case 97: /* delete cell host */
968                         OUT_STRING(hf_afs_bos_content);
969                         break;
970                 case 98: /* set t status */
971                         OUT_STRING(hf_afs_bos_content);
972                         OUT_UINT(hf_afs_bos_status);
973                         break;
974                 case 99: /* shutdown all */
975                         /* no params */
976                         break;
977                 case 100: /* restart all */
978                         /* no params */
979                         break;
980                 case 101: /* startup all */
981                         /* no params */
982                         break;
983                 case 102: /* set no-auth flag */
984                         OUT_UINT(hf_afs_bos_flags);
985                         break;
986                 case 103: /* re-bozo? */
987                         /* no params */
988                         break;
989                 case 104: /* restart */
990                         OUT_STRING(hf_afs_bos_instance);
991                         break;
992                 case 105: /* install */
993                         OUT_STRING(hf_afs_bos_path);
994                         OUT_UINT(hf_afs_bos_size);
995                         OUT_UINT(hf_afs_bos_flags);
996                         OUT_UINT(hf_afs_bos_date);
997                         break;
998                 case 106: /* uninstall */
999                         OUT_STRING(hf_afs_bos_path);
1000                         break;
1001                 case 107: /* get dates */
1002                         OUT_STRING(hf_afs_bos_path);
1003                         break;
1004                 case 108: /* exec */
1005                         OUT_STRING(hf_afs_bos_cmd);
1006                         break;
1007                 case 109: /* prune */
1008                         OUT_UINT(hf_afs_bos_flags);
1009                         break;
1010                 case 110: /* set restart time */
1011                         OUT_UINT(hf_afs_bos_num);
1012                         OUT_BOS_TIME();
1013                         break;
1014                 case 111: /* get restart time */
1015                         OUT_UINT(hf_afs_bos_num);
1016                         break;
1017                 case 112: /* get log */
1018                         OUT_STRING(hf_afs_bos_file);
1019                         break;
1020                 case 113: /* wait all */
1021                         /* no params */
1022                         break;
1023                 case 114: /* get instance strings */
1024                         OUT_STRING(hf_afs_bos_content);
1025                         break;
1026         }
1027 }
1028
1029 /*
1030  * VOL Helpers
1031  */
1032 static void
1033 dissect_vol_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1034 {
1035         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
1036         {
1037                 switch ( opcode )
1038                 {
1039                         case 121:
1040                                 /* should loop here maybe */
1041                                 OUT_UINT(hf_afs_vol_count);
1042                                 VECOUT(hf_afs_vol_name, 32); /* not sure on  */
1043                                 break;
1044                 }
1045         }
1046         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
1047         {
1048                 OUT_UINT(hf_afs_vol_errcode);
1049         }
1050 }
1051
1052 static void
1053 dissect_vol_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1054 {
1055         offset += 4;  /* skip the opcode */
1056
1057         switch ( opcode )
1058         {
1059                 case 121: /* list one vol */
1060                         OUT_UINT(hf_afs_vol_count);
1061                         OUT_UINT(hf_afs_vol_id);
1062                         break;
1063         }
1064 }
1065
1066 /*
1067  * KAUTH Helpers
1068  */
1069 static void
1070 dissect_kauth_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1071 {
1072         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
1073         {
1074                 switch ( opcode )
1075                 {
1076                 }
1077         }
1078         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
1079         {
1080                 OUT_UINT(hf_afs_kauth_errcode);
1081         }
1082 }
1083
1084 static void
1085 dissect_kauth_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1086 {
1087         offset += 4;  /* skip the opcode */
1088
1089         switch ( opcode )
1090         {
1091                 case 1: /* authenticate old */
1092                 case 21: /* authenticate */
1093                 case 22: /* authenticate v2 */
1094                 case 2: /* change pw */
1095                 case 5: /* set fields */
1096                 case 6: /* create user */
1097                 case 7: /* delete user */
1098                 case 8: /* get entry */
1099                 case 14: /* unlock */
1100                 case 15: /* lock status */
1101                         OUT_STRING(hf_afs_kauth_princ);
1102                         OUT_STRING(hf_afs_kauth_realm);
1103                         OUT_BYTES_ALL(hf_afs_kauth_data);
1104                         break;
1105                 case 3: /* getticket-old */
1106                 case 23: /* getticket */
1107                         OUT_UINT(hf_afs_kauth_kvno);
1108                         OUT_STRING(hf_afs_kauth_domain);
1109                         OUT_STRING(hf_afs_kauth_data);
1110                         OUT_STRING(hf_afs_kauth_princ);
1111                         OUT_STRING(hf_afs_kauth_realm);
1112                         break;
1113                 case 4: /* set pass */
1114                         OUT_STRING(hf_afs_kauth_princ);
1115                         OUT_STRING(hf_afs_kauth_realm);
1116                         OUT_UINT(hf_afs_kauth_kvno);
1117                         break;
1118                 case 12: /* get pass */
1119                         OUT_STRING(hf_afs_kauth_name);
1120                         break;
1121         }
1122 }
1123
1124 /*
1125  * CB Helpers
1126  */
1127 static void
1128 dissect_cb_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1129 {
1130         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
1131         {
1132                 switch ( opcode )
1133                 {
1134                 }
1135         }
1136         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
1137         {
1138                 OUT_UINT(hf_afs_cb_errcode);
1139         }
1140 }
1141
1142 static void
1143 dissect_cb_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1144 {
1145         offset += 4;  /* skip the opcode */
1146
1147         switch ( opcode )
1148         {
1149                 case 204: /* callback */
1150                 {
1151                         unsigned int i,j;
1152
1153                         j = tvb_get_ntohl(tvb, offset);
1154                         offset += 4;
1155
1156                         for (i=0; i<j; i++)
1157                         {
1158                                 OUT_CB_AFSFid("Target");
1159                         }
1160
1161                         j = tvb_get_ntohl(tvb, offset);
1162                         offset += 4;
1163                         for (i=0; i<j; i++)
1164                         {
1165                                 OUT_CB_AFSCallBack();
1166                         }
1167                 }
1168         }
1169 }
1170
1171 /*
1172  * PROT Helpers
1173  */
1174 static void
1175 dissect_prot_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1176 {
1177         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
1178         {
1179                 switch ( opcode )
1180                 {
1181                         case 504: /* name to id */
1182                                 {
1183                                         unsigned int i, j;
1184
1185                                         j = tvb_get_ntohl(tvb, offset);
1186                                         OUT_UINT(hf_afs_prot_count);
1187
1188                                         for (i=0; i<j; i++)
1189                                         {
1190                                                 OUT_UINT(hf_afs_prot_id);
1191                                         }
1192                                 }
1193                                 break;
1194                         case 505: /* id to name */
1195                                 {
1196                                         unsigned int i, j;
1197
1198                                         j = tvb_get_ntohl(tvb, offset);
1199                                         OUT_UINT(hf_afs_prot_count);
1200
1201                                         for (i=0; i<j; i++)
1202                                         {
1203                                                 VECOUT(hf_afs_prot_name, PRNAMEMAX);
1204                                         }
1205                                 }
1206                                 break;
1207                         case 508: /* get cps */
1208                         case 514: /* list elements */
1209                         case 517: /* list owned */
1210                         case 518: /* get cps2 */
1211                         case 519: /* get host cps */
1212                                 {
1213                                         unsigned int i, j;
1214
1215                                         j = tvb_get_ntohl(tvb, offset);
1216                                         OUT_UINT(hf_afs_prot_count);
1217
1218                                         for (i=0; i<j; i++)
1219                                         {
1220                                                 OUT_UINT(hf_afs_prot_id);
1221                                         }
1222                                 }
1223                                 break;
1224                         case 510: /* list max */
1225                                 OUT_UINT(hf_afs_prot_maxuid);
1226                                 OUT_UINT(hf_afs_prot_maxgid);
1227                                 break;
1228                 }
1229         }
1230         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
1231         {
1232                 OUT_UINT(hf_afs_prot_errcode);
1233         }
1234 }
1235
1236 static void
1237 dissect_prot_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1238 {
1239         offset += 4;  /* skip the opcode */
1240
1241         switch ( opcode )
1242         {
1243                 case 500: /* new user */
1244                         OUT_STRING(hf_afs_prot_name);
1245                         OUT_UINT(hf_afs_prot_id);
1246                         OUT_UINT(hf_afs_prot_oldid);
1247                         break;
1248                 case 501: /* where is it */
1249                 case 506: /* delete */
1250                 case 508: /* get cps */
1251                 case 512: /* list entry */
1252                 case 514: /* list elements */
1253                 case 517: /* list owned */
1254                 case 519: /* get host cps */
1255                         OUT_UINT(hf_afs_prot_id);
1256                         break;
1257                 case 502: /* dump entry */
1258                         OUT_UINT(hf_afs_prot_pos);
1259                         break;
1260                 case 503: /* add to group */
1261                 case 507: /* remove from group */
1262                 case 515: /* is a member of? */
1263                         OUT_UINT(hf_afs_prot_uid);
1264                         OUT_UINT(hf_afs_prot_gid);
1265                         break;
1266                 case 504: /* name to id */
1267                         {
1268                                 unsigned int i, j;
1269
1270                                 j = tvb_get_ntohl(tvb, offset);
1271                                 OUT_UINT(hf_afs_prot_count);
1272
1273                                 for (i=0; i<j; i++)
1274                                 {
1275                                         VECOUT(hf_afs_prot_name,PRNAMEMAX);
1276                                 }
1277                         }
1278                         break;
1279                 case 505: /* id to name */
1280                         {
1281                                 unsigned int i, j;
1282
1283                                 j = tvb_get_ntohl(tvb, offset);
1284                                 OUT_UINT(hf_afs_prot_count);
1285
1286                                 for (i=0; i<j; i++)
1287                                 {
1288                                         OUT_UINT(hf_afs_prot_id);
1289                                 }
1290                         }
1291                         break;
1292                 case 509: /* new entry */
1293                         OUT_STRING(hf_afs_prot_name);
1294                         OUT_UINT(hf_afs_prot_flag);
1295                         OUT_UINT(hf_afs_prot_oldid);
1296                         break;
1297                 case 511: /* set max */
1298                         OUT_UINT(hf_afs_prot_id);
1299                         OUT_UINT(hf_afs_prot_flag);
1300                         break;
1301                 case 513: /* change entry */
1302                         OUT_UINT(hf_afs_prot_id);
1303                         OUT_STRING(hf_afs_prot_name);
1304                         OUT_UINT(hf_afs_prot_oldid);
1305                         OUT_UINT(hf_afs_prot_newid);
1306                         break;
1307                 case 520: /* update entry */
1308                         OUT_UINT(hf_afs_prot_id);
1309                         OUT_STRING(hf_afs_prot_name);
1310                         break;
1311         }
1312 }
1313
1314 /*
1315  * VLDB Helpers
1316  */
1317 static void
1318 dissect_vldb_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1319 {
1320         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
1321         {
1322                 switch ( opcode )
1323                 {
1324                         case 510: /* list entry */
1325                                 OUT_UINT(hf_afs_vldb_count);
1326                                 OUT_UINT(hf_afs_vldb_nextindex);
1327                                 break;
1328                         case 503: /* get entry by id */
1329                         case 504: /* get entry by name */
1330                                 {
1331                                         int nservers,i,j;
1332                                         VECOUT(hf_afs_vldb_name, VLNAMEMAX);
1333                                         nservers = tvb_get_ntohl(tvb, offset);
1334                                         OUT_UINT(hf_afs_vldb_numservers);
1335                                         for (i=0; i<8; i++)
1336                                         {
1337                                                 if ( i<nservers )
1338                                                 {
1339                                                         OUT_IP(hf_afs_vldb_server);
1340                                                 }
1341                                                 else
1342                                                 {
1343                                                         SKIP(4);
1344                                                 }
1345                                         }
1346                                         for (i=0; i<8; i++)
1347                                         {
1348                                                 char part[8];
1349                                                 j = tvb_get_ntohl(tvb, offset);
1350                                                 strcpy(part, "/vicepa");
1351                                                 if ( i<nservers && j<=25 )
1352                                                 {
1353                                                         part[6] = 'a' + (char) j;
1354                                                         proto_tree_add_string(tree, hf_afs_vldb_partition, tvb,
1355                                                                 offset, 4, part);
1356                                                 }
1357                                                 SKIP(4);
1358                                         }
1359                                         SKIP(8 * sizeof(guint32));
1360                                         OUT_UINT(hf_afs_vldb_rwvol);
1361                                         OUT_UINT(hf_afs_vldb_rovol);
1362                                         OUT_UINT(hf_afs_vldb_bkvol);
1363                                 }
1364                                 break;
1365                         case 505: /* get new volume id */
1366                                 OUT_UINT(hf_afs_vldb_id);
1367                                 break;
1368                         case 521: /* list entry */
1369                         case 529: /* list entry U */
1370                                 OUT_UINT(hf_afs_vldb_count);
1371                                 OUT_UINT(hf_afs_vldb_nextindex);
1372                                 break;
1373                         case 518: /* get entry by id n */
1374                         case 519: /* get entry by name N */
1375                                 {
1376                                         int nservers,i,j;
1377                                         VECOUT(hf_afs_vldb_name, VLNAMEMAX);
1378                                         nservers = tvb_get_ntohl(tvb, offset);
1379                                         OUT_UINT(hf_afs_vldb_numservers);
1380                                         for (i=0; i<13; i++)
1381                                         {
1382                                                 if ( i<nservers )
1383                                                 {
1384                                                         OUT_IP(hf_afs_vldb_server);
1385                                                 }
1386                                                 else
1387                                                 {
1388                                                         SKIP(4);
1389                                                 }
1390                                         }
1391                                         for (i=0; i<13; i++)
1392                                         {
1393                                                 char part[8];
1394                                                 j = tvb_get_ntohl(tvb, offset);
1395                                                 strcpy(part, "/vicepa");
1396                                                 if ( i<nservers && j<=25 )
1397                                                 {
1398                                                         part[6] = 'a' + (char) j;
1399                                                         proto_tree_add_string(tree, hf_afs_vldb_partition, tvb,
1400                                                                 offset, 4, part);
1401                                                 }
1402                                                 SKIP(4);
1403                                         }
1404                                         SKIP(13 * sizeof(guint32));
1405                                         OUT_UINT(hf_afs_vldb_rwvol);
1406                                         OUT_UINT(hf_afs_vldb_rovol);
1407                                         OUT_UINT(hf_afs_vldb_bkvol);
1408                                 }
1409                                 break;
1410                         case 526: /* get entry by id u */
1411                         case 527: /* get entry by name u */
1412                                 {
1413                                         int nservers,i,j;
1414                                         VECOUT(hf_afs_vldb_name, VLNAMEMAX);
1415                                         nservers = tvb_get_ntohl(tvb, offset);
1416                                         OUT_UINT(hf_afs_vldb_numservers);
1417                                         for (i=0; i<13; i++)
1418                                         {
1419                                                 if ( i<nservers )
1420                                                 {
1421                                                         OUT_BYTES(hf_afs_vldb_serveruuid, 11*sizeof(guint32));
1422                                                 }
1423                                                 else
1424                                                 {
1425                                                         SKIP(11*sizeof(guint32));
1426                                                 }
1427                                         }
1428                                         for (i=0; i<13; i++)
1429                                         {
1430                                                 if ( i<nservers )
1431                                                 {
1432                                                         OUT_UINT(hf_afs_vldb_serveruniq);
1433                                                 }
1434                                                 else
1435                                                 {
1436                                                         SKIP(sizeof(guint32));
1437                                                 }
1438                                         }
1439                                         for (i=0; i<13; i++)
1440                                         {
1441                                                 char part[8];
1442                                                 j = tvb_get_ntohl(tvb, offset);
1443                                                 strcpy(part, "/vicepa");
1444                                                 if ( i<nservers && j<=25 )
1445                                                 {
1446                                                         part[6] = 'a' + (char) j;
1447                                                         proto_tree_add_string(tree, hf_afs_vldb_partition, tvb,
1448                                                                 offset, 4, part);
1449                                                 }
1450                                                 SKIP(4);
1451                                         }
1452                                         for (i=0; i<13; i++)
1453                                         {
1454                                                 if ( i<nservers )
1455                                                 {
1456                                                         OUT_UINT(hf_afs_vldb_serverflags);
1457                                                 }
1458                                                 else
1459                                                 {
1460                                                         SKIP(sizeof(guint32));
1461                                                 }
1462                                         }
1463                                         OUT_UINT(hf_afs_vldb_rwvol);
1464                                         OUT_UINT(hf_afs_vldb_rovol);
1465                                         OUT_UINT(hf_afs_vldb_bkvol);
1466                                         OUT_UINT(hf_afs_vldb_clonevol);
1467                                         OUT_UINT(hf_afs_vldb_flags);
1468                                         OUT_UINT(hf_afs_vldb_spare1);
1469                                         OUT_UINT(hf_afs_vldb_spare2);
1470                                         OUT_UINT(hf_afs_vldb_spare3);
1471                                         OUT_UINT(hf_afs_vldb_spare4);
1472                                         OUT_UINT(hf_afs_vldb_spare5);
1473                                         OUT_UINT(hf_afs_vldb_spare6);
1474                                         OUT_UINT(hf_afs_vldb_spare7);
1475                                         OUT_UINT(hf_afs_vldb_spare8);
1476                                         OUT_UINT(hf_afs_vldb_spare9);
1477                                 }
1478                                 break;
1479                 }
1480         }
1481         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
1482         {
1483                 OUT_UINT(hf_afs_vldb_errcode);
1484         }
1485 }
1486
1487 static void
1488 dissect_vldb_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1489 {
1490         offset += 4;  /* skip the opcode */
1491
1492         switch ( opcode )
1493         {
1494                 case 501: /* create new volume */
1495                 case 517: /* create entry N */
1496                         VECOUT(hf_afs_vldb_name, VLNAMEMAX);
1497                         break;
1498                 case 502: /* delete entry */
1499                 case 503: /* get entry by id */
1500                 case 507: /* update entry */
1501                 case 508: /* set lock */
1502                 case 509: /* release lock */
1503                 case 518: /* get entry by id */
1504                         OUT_UINT(hf_afs_vldb_id);
1505                         OUT_UINT(hf_afs_vldb_type);
1506                         break;
1507                 case 504: /* get entry by name */
1508                 case 519: /* get entry by name N */
1509                 case 524: /* update entry by name */
1510                 case 527: /* get entry by name U */
1511                         OUT_STRING(hf_afs_vldb_name);
1512                         break;
1513                 case 505: /* get new vol id */
1514                         OUT_UINT(hf_afs_vldb_bump);
1515                         break;
1516                 case 506: /* replace entry */
1517                 case 520: /* replace entry N */
1518                         OUT_UINT(hf_afs_vldb_id);
1519                         OUT_UINT(hf_afs_vldb_type);
1520                         VECOUT(hf_afs_vldb_name, VLNAMEMAX);
1521                         break;
1522                 case 510: /* list entry */
1523                 case 521: /* list entry N */
1524                         OUT_UINT(hf_afs_vldb_index);
1525                         break;
1526         }
1527 }
1528
1529 /*
1530  * UBIK Helpers
1531  */
1532 static void
1533 dissect_ubik_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1534 {
1535         switch ( opcode )
1536         {
1537                 case 10000: /* vote-beacon */
1538                         break;
1539                 case 10001: /* vote-debug-old */
1540                         OUT_UBIK_DebugOld();
1541                         break;
1542                 case 10002: /* vote-sdebug-old */
1543                         OUT_UBIK_SDebugOld();
1544                         break;
1545                 case 10003: /* vote-get syncsite */
1546                         break;
1547                 case 10004: /* vote-debug */
1548                         OUT_UBIK_DebugOld();
1549                         OUT_UBIK_InterfaceAddrs();
1550                         break;
1551                 case 10005: /* vote-sdebug */
1552                         OUT_UBIK_SDebugOld();
1553                         OUT_UBIK_InterfaceAddrs();
1554                         break;
1555                 case 10006: /* vote-xdebug */
1556                         OUT_UBIK_DebugOld();
1557                         OUT_UBIK_InterfaceAddrs();
1558                         OUT_UINT(hf_afs_ubik_isclone);
1559                         break;
1560                 case 10007: /* vote-xsdebug */
1561                         OUT_UBIK_SDebugOld();
1562                         OUT_UBIK_InterfaceAddrs();
1563                         OUT_UINT(hf_afs_ubik_isclone);
1564                         break;
1565                 case 20000: /* disk-begin */
1566                         break;
1567                 case 20004: /* get version */
1568                         OUT_UBIKVERSION("DB Version");
1569                         break;
1570                 case 20010: /* disk-probe */
1571                         break;
1572                 case 20012: /* disk-interfaceaddr */
1573                         OUT_UBIK_InterfaceAddrs();
1574                         break;
1575         }
1576 }
1577
1578 static void
1579 dissect_ubik_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1580 {
1581         offset += 4;  /* skip the opcode */
1582
1583         switch ( opcode )
1584         {
1585                 case 10000: /* vote-beacon */
1586                         OUT_UINT(hf_afs_ubik_state);
1587                         OUT_DATE(hf_afs_ubik_votestart);
1588                         OUT_UBIKVERSION("DB Version");
1589                         OUT_UBIKVERSION("TID");
1590                         break;
1591                 case 10001: /* vote-debug-old */
1592                         break;
1593                 case 10002: /* vote-sdebug-old */
1594                         OUT_UINT(hf_afs_ubik_site);
1595                         break;
1596                 case 10003: /* vote-get sync site */
1597                         OUT_IP(hf_afs_ubik_site);
1598                         break;
1599                 case 10004: /* vote-debug */
1600                 case 10005: /* vote-sdebug */
1601                         OUT_IP(hf_afs_ubik_site);
1602                         break;
1603                 case 20000: /* disk-begin */
1604                         OUT_UBIKVERSION("TID");
1605                         break;
1606                 case 20001: /* disk-commit */
1607                         OUT_UBIKVERSION("TID");
1608                         break;
1609                 case 20002: /* disk-lock */
1610                         OUT_UBIKVERSION("TID");
1611                         OUT_UINT(hf_afs_ubik_file);
1612                         OUT_UINT(hf_afs_ubik_pos);
1613                         OUT_UINT(hf_afs_ubik_length);
1614                         OUT_UINT(hf_afs_ubik_locktype);
1615                         break;
1616                 case 20003: /* disk-write */
1617                         OUT_UBIKVERSION("TID");
1618                         OUT_UINT(hf_afs_ubik_file);
1619                         OUT_UINT(hf_afs_ubik_pos);
1620                         break;
1621                 case 20004: /* disk-get version */
1622                         break;
1623                 case 20005: /* disk-get file */
1624                         OUT_UINT(hf_afs_ubik_file);
1625                         break;
1626                 case 20006: /* disk-send file */
1627                         OUT_UINT(hf_afs_ubik_file);
1628                         OUT_UINT(hf_afs_ubik_length);
1629                         OUT_UBIKVERSION("DB Version");
1630                         break;
1631                 case 20007: /* disk-abort */
1632                 case 20008: /* disk-release locks */
1633                 case 20010: /* disk-probe */
1634                         break;
1635                 case 20009: /* disk-truncate */
1636                         OUT_UBIKVERSION("TID");
1637                         OUT_UINT(hf_afs_ubik_file);
1638                         OUT_UINT(hf_afs_ubik_length);
1639                         break;
1640                 case 20011: /* disk-writev */
1641                         OUT_UBIKVERSION("TID");
1642                         break;
1643                 case 20012: /* disk-interfaceaddr */
1644                         OUT_UBIK_InterfaceAddrs();
1645                         break;
1646                 case 20013: /* disk-set version */
1647                         OUT_UBIKVERSION("TID");
1648                         OUT_UBIKVERSION("Old DB Version");
1649                         OUT_UBIKVERSION("New DB Version");
1650                         break;
1651         }
1652 }
1653
1654 /*
1655  * BACKUP Helpers
1656  */
1657 static void
1658 dissect_backup_reply(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1659 {
1660         if ( rxinfo->type == RX_PACKET_TYPE_DATA )
1661         {
1662                 switch ( opcode )
1663                 {
1664                 }
1665         }
1666         else if ( rxinfo->type == RX_PACKET_TYPE_ABORT )
1667         {
1668                 OUT_UINT(hf_afs_backup_errcode);
1669         }
1670 }
1671
1672 static void
1673 dissect_backup_request(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *tree, int offset, int opcode)
1674 {
1675         offset += 4;  /* skip the opcode */
1676
1677         switch ( opcode )
1678         {
1679         }
1680 }
1681
1682 /*
1683  * Registration code for registering the protocol and fields
1684  */
1685
1686 void
1687 proto_register_afs(void)
1688 {
1689         static hf_register_info hf[] = {
1690 #include "packet-afs-register-info.h"
1691         };
1692         static gint *ett[] = {
1693                 &ett_afs,
1694                 &ett_afs_op,
1695                 &ett_afs_acl,
1696                 &ett_afs_fid,
1697                 &ett_afs_callback,
1698                 &ett_afs_ubikver,
1699                 &ett_afs_status,
1700                 &ett_afs_status_mask,
1701                 &ett_afs_volsync,
1702                 &ett_afs_volumeinfo,
1703                 &ett_afs_vicestat,
1704         };
1705
1706         proto_afs = proto_register_protocol("Andrew File System (AFS)",
1707             "AFS (RX)", "afs");
1708         proto_register_field_array(proto_afs, hf, array_length(hf));
1709         proto_register_subtree_array(ett, array_length(ett));
1710         register_init_routine(&afs_init_protocol);
1711
1712         register_dissector("afs", dissect_afs, proto_afs);
1713 }