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