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