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