xref: /netbsd-src/external/bsd/tcpdump/dist/print-rx.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*
2  * Copyright: (c) 2000 United States Government as represented by the
3  *	Secretary of the Navy. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright
10  *      notice, this list of conditions and the following disclaimer.
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in
13  *      the documentation and/or other materials provided with the
14  *      distribution.
15  *   3. The names of the authors may not be used to endorse or promote
16  *      products derived from this software without specific prior
17  *      written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22  */
23 
24 /* \summary: AFS RX printer */
25 
26 /*
27  * This code unmangles RX packets.  RX is the mutant form of RPC that AFS
28  * uses to communicate between clients and servers.
29  *
30  * In this code, I mainly concern myself with decoding the AFS calls, not
31  * with the guts of RX, per se.
32  *
33  * Bah.  If I never look at rx_packet.h again, it will be too soon.
34  *
35  * Ken Hornstein <kenh@cmf.nrl.navy.mil>
36  */
37 
38 #include <sys/cdefs.h>
39 #ifndef lint
40 __RCSID("$NetBSD: print-rx.c,v 1.8 2017/09/08 14:01:13 christos Exp $");
41 #endif
42 
43 #ifdef HAVE_CONFIG_H
44 #include "config.h"
45 #endif
46 
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <netdissect-stdinc.h>
51 
52 #include "netdissect.h"
53 #include "addrtoname.h"
54 #include "extract.h"
55 
56 #include "ip.h"
57 
58 #define FS_RX_PORT	7000
59 #define CB_RX_PORT	7001
60 #define PROT_RX_PORT	7002
61 #define VLDB_RX_PORT	7003
62 #define KAUTH_RX_PORT	7004
63 #define VOL_RX_PORT	7005
64 #define ERROR_RX_PORT	7006		/* Doesn't seem to be used */
65 #define BOS_RX_PORT	7007
66 
67 #define AFSNAMEMAX 256
68 #define AFSOPAQUEMAX 1024
69 #define PRNAMEMAX 64
70 #define VLNAMEMAX 65
71 #define KANAMEMAX 64
72 #define BOSNAMEMAX 256
73 
74 #define	PRSFS_READ		1 /* Read files */
75 #define	PRSFS_WRITE		2 /* Write files */
76 #define	PRSFS_INSERT		4 /* Insert files into a directory */
77 #define	PRSFS_LOOKUP		8 /* Lookup files into a directory */
78 #define	PRSFS_DELETE		16 /* Delete files */
79 #define	PRSFS_LOCK		32 /* Lock files */
80 #define	PRSFS_ADMINISTER	64 /* Change ACL's */
81 
82 struct rx_header {
83 	nd_uint32_t epoch;
84 	nd_uint32_t cid;
85 	nd_uint32_t callNumber;
86 	nd_uint32_t seq;
87 	nd_uint32_t serial;
88 	nd_uint8_t type;
89 #define RX_PACKET_TYPE_DATA		1
90 #define RX_PACKET_TYPE_ACK		2
91 #define RX_PACKET_TYPE_BUSY		3
92 #define RX_PACKET_TYPE_ABORT		4
93 #define RX_PACKET_TYPE_ACKALL		5
94 #define RX_PACKET_TYPE_CHALLENGE	6
95 #define RX_PACKET_TYPE_RESPONSE		7
96 #define RX_PACKET_TYPE_DEBUG		8
97 #define RX_PACKET_TYPE_PARAMS		9
98 #define RX_PACKET_TYPE_VERSION		13
99 	nd_uint8_t flags;
100 #define RX_CLIENT_INITIATED	1
101 #define RX_REQUEST_ACK		2
102 #define RX_LAST_PACKET		4
103 #define RX_MORE_PACKETS		8
104 #define RX_FREE_PACKET		16
105 #define RX_SLOW_START_OK	32
106 #define RX_JUMBO_PACKET		32
107 	nd_uint8_t userStatus;
108 	nd_uint8_t securityIndex;
109 	nd_uint16_t spare;		/* How clever: even though the AFS */
110 	nd_uint16_t serviceId;		/* header files indicate that the */
111 };					/* serviceId is first, it's really */
112 					/* encoded _after_ the spare field */
113 					/* I wasted a day figuring that out! */
114 
115 #define NUM_RX_FLAGS 7
116 
117 #define RX_MAXACKS 255
118 
119 struct rx_ackPacket {
120 	uint16_t bufferSpace;		/* Number of packet buffers available */
121 	uint16_t maxSkew;		/* Max diff between ack'd packet and */
122 					/* highest packet received */
123 	uint32_t firstPacket;		/* The first packet in ack list */
124 	uint32_t previousPacket;	/* Previous packet recv'd (obsolete) */
125 	uint32_t serial;		/* # of packet that prompted the ack */
126 	uint8_t reason;		/* Reason for acknowledgement */
127 	uint8_t nAcks;			/* Number of acknowledgements */
128 	uint8_t acks[RX_MAXACKS];	/* Up to RX_MAXACKS acknowledgements */
129 };
130 
131 /*
132  * Values for the acks array
133  */
134 
135 #define RX_ACK_TYPE_NACK	0	/* Don't have this packet */
136 #define RX_ACK_TYPE_ACK		1	/* I have this packet */
137 
138 static const struct tok rx_types[] = {
139 	{ RX_PACKET_TYPE_DATA,		"data" },
140 	{ RX_PACKET_TYPE_ACK,		"ack" },
141 	{ RX_PACKET_TYPE_BUSY,		"busy" },
142 	{ RX_PACKET_TYPE_ABORT,		"abort" },
143 	{ RX_PACKET_TYPE_ACKALL,	"ackall" },
144 	{ RX_PACKET_TYPE_CHALLENGE,	"challenge" },
145 	{ RX_PACKET_TYPE_RESPONSE,	"response" },
146 	{ RX_PACKET_TYPE_DEBUG,		"debug" },
147 	{ RX_PACKET_TYPE_PARAMS,	"params" },
148 	{ RX_PACKET_TYPE_VERSION,	"version" },
149 	{ 0,				NULL },
150 };
151 
152 static const struct double_tok {
153 	int flag;		/* Rx flag */
154 	int packetType;		/* Packet type */
155 	const char *s;		/* Flag string */
156 } rx_flags[] = {
157 	{ RX_CLIENT_INITIATED,	0,			"client-init" },
158 	{ RX_REQUEST_ACK,	0,			"req-ack" },
159 	{ RX_LAST_PACKET,	0,			"last-pckt" },
160 	{ RX_MORE_PACKETS,	0,			"more-pckts" },
161 	{ RX_FREE_PACKET,	0,			"free-pckt" },
162 	{ RX_SLOW_START_OK,	RX_PACKET_TYPE_ACK,	"slow-start" },
163 	{ RX_JUMBO_PACKET,	RX_PACKET_TYPE_DATA,	"jumbogram" }
164 };
165 
166 static const struct tok fs_req[] = {
167 	{ 130,		"fetch-data" },
168 	{ 131,		"fetch-acl" },
169 	{ 132,		"fetch-status" },
170 	{ 133,		"store-data" },
171 	{ 134,		"store-acl" },
172 	{ 135,		"store-status" },
173 	{ 136,		"remove-file" },
174 	{ 137,		"create-file" },
175 	{ 138,		"rename" },
176 	{ 139,		"symlink" },
177 	{ 140,		"link" },
178 	{ 141,		"makedir" },
179 	{ 142,		"rmdir" },
180 	{ 143,		"oldsetlock" },
181 	{ 144,		"oldextlock" },
182 	{ 145,		"oldrellock" },
183 	{ 146,		"get-stats" },
184 	{ 147,		"give-cbs" },
185 	{ 148,		"get-vlinfo" },
186 	{ 149,		"get-vlstats" },
187 	{ 150,		"set-vlstats" },
188 	{ 151,		"get-rootvl" },
189 	{ 152,		"check-token" },
190 	{ 153,		"get-time" },
191 	{ 154,		"nget-vlinfo" },
192 	{ 155,		"bulk-stat" },
193 	{ 156,		"setlock" },
194 	{ 157,		"extlock" },
195 	{ 158,		"rellock" },
196 	{ 159,		"xstat-ver" },
197 	{ 160,		"get-xstat" },
198 	{ 161,		"dfs-lookup" },
199 	{ 162,		"dfs-flushcps" },
200 	{ 163,		"dfs-symlink" },
201 	{ 220,		"residency" },
202 	{ 65536,        "inline-bulk-status" },
203 	{ 65537,        "fetch-data-64" },
204 	{ 65538,        "store-data-64" },
205 	{ 65539,        "give-up-all-cbs" },
206 	{ 65540,        "get-caps" },
207 	{ 65541,        "cb-rx-conn-addr" },
208 	{ 0,		NULL },
209 };
210 
211 static const struct tok cb_req[] = {
212 	{ 204,		"callback" },
213 	{ 205,		"initcb" },
214 	{ 206,		"probe" },
215 	{ 207,		"getlock" },
216 	{ 208,		"getce" },
217 	{ 209,		"xstatver" },
218 	{ 210,		"getxstat" },
219 	{ 211,		"initcb2" },
220 	{ 212,		"whoareyou" },
221 	{ 213,		"initcb3" },
222 	{ 214,		"probeuuid" },
223 	{ 215,		"getsrvprefs" },
224 	{ 216,		"getcellservdb" },
225 	{ 217,		"getlocalcell" },
226 	{ 218,		"getcacheconf" },
227 	{ 65536,        "getce64" },
228 	{ 65537,        "getcellbynum" },
229 	{ 65538,        "tellmeaboutyourself" },
230 	{ 0,		NULL },
231 };
232 
233 static const struct tok pt_req[] = {
234 	{ 500,		"new-user" },
235 	{ 501,		"where-is-it" },
236 	{ 502,		"dump-entry" },
237 	{ 503,		"add-to-group" },
238 	{ 504,		"name-to-id" },
239 	{ 505,		"id-to-name" },
240 	{ 506,		"delete" },
241 	{ 507,		"remove-from-group" },
242 	{ 508,		"get-cps" },
243 	{ 509,		"new-entry" },
244 	{ 510,		"list-max" },
245 	{ 511,		"set-max" },
246 	{ 512,		"list-entry" },
247 	{ 513,		"change-entry" },
248 	{ 514,		"list-elements" },
249 	{ 515,		"same-mbr-of" },
250 	{ 516,		"set-fld-sentry" },
251 	{ 517,		"list-owned" },
252 	{ 518,		"get-cps2" },
253 	{ 519,		"get-host-cps" },
254 	{ 520,		"update-entry" },
255 	{ 521,		"list-entries" },
256 	{ 530,		"list-super-groups" },
257 	{ 0,		NULL },
258 };
259 
260 static const struct tok vldb_req[] = {
261 	{ 501,		"create-entry" },
262 	{ 502,		"delete-entry" },
263 	{ 503,		"get-entry-by-id" },
264 	{ 504,		"get-entry-by-name" },
265 	{ 505,		"get-new-volume-id" },
266 	{ 506,		"replace-entry" },
267 	{ 507,		"update-entry" },
268 	{ 508,		"setlock" },
269 	{ 509,		"releaselock" },
270 	{ 510,		"list-entry" },
271 	{ 511,		"list-attrib" },
272 	{ 512,		"linked-list" },
273 	{ 513,		"get-stats" },
274 	{ 514,		"probe" },
275 	{ 515,		"get-addrs" },
276 	{ 516,		"change-addr" },
277 	{ 517,		"create-entry-n" },
278 	{ 518,		"get-entry-by-id-n" },
279 	{ 519,		"get-entry-by-name-n" },
280 	{ 520,		"replace-entry-n" },
281 	{ 521,		"list-entry-n" },
282 	{ 522,		"list-attrib-n" },
283 	{ 523,		"linked-list-n" },
284 	{ 524,		"update-entry-by-name" },
285 	{ 525,		"create-entry-u" },
286 	{ 526,		"get-entry-by-id-u" },
287 	{ 527,		"get-entry-by-name-u" },
288 	{ 528,		"replace-entry-u" },
289 	{ 529,		"list-entry-u" },
290 	{ 530,		"list-attrib-u" },
291 	{ 531,		"linked-list-u" },
292 	{ 532,		"regaddr" },
293 	{ 533,		"get-addrs-u" },
294 	{ 534,		"list-attrib-n2" },
295 	{ 0,		NULL },
296 };
297 
298 static const struct tok kauth_req[] = {
299 	{ 1,		"auth-old" },
300 	{ 21,		"authenticate" },
301 	{ 22,		"authenticate-v2" },
302 	{ 2,		"change-pw" },
303 	{ 3,		"get-ticket-old" },
304 	{ 23,		"get-ticket" },
305 	{ 4,		"set-pw" },
306 	{ 5,		"set-fields" },
307 	{ 6,		"create-user" },
308 	{ 7,		"delete-user" },
309 	{ 8,		"get-entry" },
310 	{ 9,		"list-entry" },
311 	{ 10,		"get-stats" },
312 	{ 11,		"debug" },
313 	{ 12,		"get-pw" },
314 	{ 13,		"get-random-key" },
315 	{ 14,		"unlock" },
316 	{ 15,		"lock-status" },
317 	{ 0,		NULL },
318 };
319 
320 static const struct tok vol_req[] = {
321 	{ 100,		"create-volume" },
322 	{ 101,		"delete-volume" },
323 	{ 102,		"restore" },
324 	{ 103,		"forward" },
325 	{ 104,		"end-trans" },
326 	{ 105,		"clone" },
327 	{ 106,		"set-flags" },
328 	{ 107,		"get-flags" },
329 	{ 108,		"trans-create" },
330 	{ 109,		"dump" },
331 	{ 110,		"get-nth-volume" },
332 	{ 111,		"set-forwarding" },
333 	{ 112,		"get-name" },
334 	{ 113,		"get-status" },
335 	{ 114,		"sig-restore" },
336 	{ 115,		"list-partitions" },
337 	{ 116,		"list-volumes" },
338 	{ 117,		"set-id-types" },
339 	{ 118,		"monitor" },
340 	{ 119,		"partition-info" },
341 	{ 120,		"reclone" },
342 	{ 121,		"list-one-volume" },
343 	{ 122,		"nuke" },
344 	{ 123,		"set-date" },
345 	{ 124,		"x-list-volumes" },
346 	{ 125,		"x-list-one-volume" },
347 	{ 126,		"set-info" },
348 	{ 127,		"x-list-partitions" },
349 	{ 128,		"forward-multiple" },
350 	{ 65536,	"convert-ro" },
351 	{ 65537,	"get-size" },
352 	{ 65538,	"dump-v2" },
353 	{ 0,		NULL },
354 };
355 
356 static const struct tok bos_req[] = {
357 	{ 80,		"create-bnode" },
358 	{ 81,		"delete-bnode" },
359 	{ 82,		"set-status" },
360 	{ 83,		"get-status" },
361 	{ 84,		"enumerate-instance" },
362 	{ 85,		"get-instance-info" },
363 	{ 86,		"get-instance-parm" },
364 	{ 87,		"add-superuser" },
365 	{ 88,		"delete-superuser" },
366 	{ 89,		"list-superusers" },
367 	{ 90,		"list-keys" },
368 	{ 91,		"add-key" },
369 	{ 92,		"delete-key" },
370 	{ 93,		"set-cell-name" },
371 	{ 94,		"get-cell-name" },
372 	{ 95,		"get-cell-host" },
373 	{ 96,		"add-cell-host" },
374 	{ 97,		"delete-cell-host" },
375 	{ 98,		"set-t-status" },
376 	{ 99,		"shutdown-all" },
377 	{ 100,		"restart-all" },
378 	{ 101,		"startup-all" },
379 	{ 102,		"set-noauth-flag" },
380 	{ 103,		"re-bozo" },
381 	{ 104,		"restart" },
382 	{ 105,		"start-bozo-install" },
383 	{ 106,		"uninstall" },
384 	{ 107,		"get-dates" },
385 	{ 108,		"exec" },
386 	{ 109,		"prune" },
387 	{ 110,		"set-restart-time" },
388 	{ 111,		"get-restart-time" },
389 	{ 112,		"start-bozo-log" },
390 	{ 113,		"wait-all" },
391 	{ 114,		"get-instance-strings" },
392 	{ 115,		"get-restricted" },
393 	{ 116,		"set-restricted" },
394 	{ 0,		NULL },
395 };
396 
397 static const struct tok ubik_req[] = {
398 	{ 10000,	"vote-beacon" },
399 	{ 10001,	"vote-debug-old" },
400 	{ 10002,	"vote-sdebug-old" },
401 	{ 10003,	"vote-getsyncsite" },
402 	{ 10004,	"vote-debug" },
403 	{ 10005,	"vote-sdebug" },
404 	{ 10006,	"vote-xdebug" },
405 	{ 10007,	"vote-xsdebug" },
406 	{ 20000,	"disk-begin" },
407 	{ 20001,	"disk-commit" },
408 	{ 20002,	"disk-lock" },
409 	{ 20003,	"disk-write" },
410 	{ 20004,	"disk-getversion" },
411 	{ 20005,	"disk-getfile" },
412 	{ 20006,	"disk-sendfile" },
413 	{ 20007,	"disk-abort" },
414 	{ 20008,	"disk-releaselocks" },
415 	{ 20009,	"disk-truncate" },
416 	{ 20010,	"disk-probe" },
417 	{ 20011,	"disk-writev" },
418 	{ 20012,	"disk-interfaceaddr" },
419 	{ 20013,	"disk-setversion" },
420 	{ 0,		NULL },
421 };
422 
423 #define VOTE_LOW	10000
424 #define VOTE_HIGH	10007
425 #define DISK_LOW	20000
426 #define DISK_HIGH	20013
427 
428 static const struct tok cb_types[] = {
429 	{ 1,		"exclusive" },
430 	{ 2,		"shared" },
431 	{ 3,		"dropped" },
432 	{ 0,		NULL },
433 };
434 
435 static const struct tok ubik_lock_types[] = {
436 	{ 1,		"read" },
437 	{ 2,		"write" },
438 	{ 3,		"wait" },
439 	{ 0,		NULL },
440 };
441 
442 static const char *voltype[] = { "read-write", "read-only", "backup" };
443 
444 static const struct tok afs_fs_errors[] = {
445 	{ 101,		"salvage volume" },
446 	{ 102, 		"no such vnode" },
447 	{ 103, 		"no such volume" },
448 	{ 104, 		"volume exist" },
449 	{ 105, 		"no service" },
450 	{ 106, 		"volume offline" },
451 	{ 107, 		"voline online" },
452 	{ 108, 		"diskfull" },
453 	{ 109, 		"diskquota exceeded" },
454 	{ 110, 		"volume busy" },
455 	{ 111, 		"volume moved" },
456 	{ 112, 		"AFS IO error" },
457 	{ 0xffffff9c,	"restarting fileserver" }, /* -100, sic! */
458 	{ 0,		NULL }
459 };
460 
461 /*
462  * Reasons for acknowledging a packet
463  */
464 
465 static const struct tok rx_ack_reasons[] = {
466 	{ 1,		"ack requested" },
467 	{ 2,		"duplicate packet" },
468 	{ 3,		"out of sequence" },
469 	{ 4,		"exceeds window" },
470 	{ 5,		"no buffer space" },
471 	{ 6,		"ping" },
472 	{ 7,		"ping response" },
473 	{ 8,		"delay" },
474 	{ 9,		"idle" },
475 	{ 0,		NULL },
476 };
477 
478 /*
479  * Cache entries we keep around so we can figure out the RX opcode
480  * numbers for replies.  This allows us to make sense of RX reply packets.
481  */
482 
483 struct rx_cache_entry {
484 	uint32_t	callnum;	/* Call number (net order) */
485 	struct in_addr	client;		/* client IP address (net order) */
486 	struct in_addr	server;		/* server IP address (net order) */
487 	int		dport;		/* server port (host order) */
488 	u_short		serviceId;	/* Service identifier (net order) */
489 	uint32_t	opcode;		/* RX opcode (host order) */
490 };
491 
492 #define RX_CACHE_SIZE	64
493 
494 static struct rx_cache_entry	rx_cache[RX_CACHE_SIZE];
495 
496 static int	rx_cache_next = 0;
497 static int	rx_cache_hint = 0;
498 static void	rx_cache_insert(netdissect_options *, const u_char *, const struct ip *, int);
499 static int	rx_cache_find(const struct rx_header *, const struct ip *,
500 			      int, int32_t *);
501 
502 static void fs_print(netdissect_options *, const u_char *, int);
503 static void fs_reply_print(netdissect_options *, const u_char *, int, int32_t);
504 static void acl_print(netdissect_options *, u_char *, int, u_char *);
505 static void cb_print(netdissect_options *, const u_char *, int);
506 static void cb_reply_print(netdissect_options *, const u_char *, int, int32_t);
507 static void prot_print(netdissect_options *, const u_char *, int);
508 static void prot_reply_print(netdissect_options *, const u_char *, int, int32_t);
509 static void vldb_print(netdissect_options *, const u_char *, int);
510 static void vldb_reply_print(netdissect_options *, const u_char *, int, int32_t);
511 static void kauth_print(netdissect_options *, const u_char *, int);
512 static void kauth_reply_print(netdissect_options *, const u_char *, int, int32_t);
513 static void vol_print(netdissect_options *, const u_char *, int);
514 static void vol_reply_print(netdissect_options *, const u_char *, int, int32_t);
515 static void bos_print(netdissect_options *, const u_char *, int);
516 static void bos_reply_print(netdissect_options *, const u_char *, int, int32_t);
517 static void ubik_print(netdissect_options *, const u_char *);
518 static void ubik_reply_print(netdissect_options *, const u_char *, int, int32_t);
519 
520 static void rx_ack_print(netdissect_options *, const u_char *, int);
521 
522 static int is_ubik(uint32_t);
523 
524 /*
525  * Handle the rx-level packet.  See if we know what port it's going to so
526  * we can peek at the afs call inside
527  */
528 
529 void
530 rx_print(netdissect_options *ndo,
531          register const u_char *bp, int length, int sport, int dport,
532          const u_char *bp2)
533 {
534 	register const struct rx_header *rxh;
535 	int i;
536 	int32_t opcode;
537 
538 	if (ndo->ndo_snapend - bp < (int)sizeof (struct rx_header)) {
539 		ND_PRINT((ndo, " [|rx] (%d)", length));
540 		return;
541 	}
542 
543 	rxh = (const struct rx_header *) bp;
544 
545 	ND_PRINT((ndo, " rx %s", tok2str(rx_types, "type %d", rxh->type)));
546 
547 	if (ndo->ndo_vflag) {
548 		int firstflag = 0;
549 
550 		if (ndo->ndo_vflag > 1)
551 			ND_PRINT((ndo, " cid %08x call# %d",
552 			       (int) EXTRACT_32BITS(&rxh->cid),
553 			       (int) EXTRACT_32BITS(&rxh->callNumber)));
554 
555 		ND_PRINT((ndo, " seq %d ser %d",
556 		       (int) EXTRACT_32BITS(&rxh->seq),
557 		       (int) EXTRACT_32BITS(&rxh->serial)));
558 
559 		if (ndo->ndo_vflag > 2)
560 			ND_PRINT((ndo, " secindex %d serviceid %hu",
561 				(int) rxh->securityIndex,
562 				EXTRACT_16BITS(&rxh->serviceId)));
563 
564 		if (ndo->ndo_vflag > 1)
565 			for (i = 0; i < NUM_RX_FLAGS; i++) {
566 				if (rxh->flags & rx_flags[i].flag &&
567 				    (!rx_flags[i].packetType ||
568 				     rxh->type == rx_flags[i].packetType)) {
569 					if (!firstflag) {
570 						firstflag = 1;
571 						ND_PRINT((ndo, " "));
572 					} else {
573 						ND_PRINT((ndo, ","));
574 					}
575 					ND_PRINT((ndo, "<%s>", rx_flags[i].s));
576 				}
577 			}
578 	}
579 
580 	/*
581 	 * Try to handle AFS calls that we know about.  Check the destination
582 	 * port and make sure it's a data packet.  Also, make sure the
583 	 * seq number is 1 (because otherwise it's a continuation packet,
584 	 * and we can't interpret that).  Also, seems that reply packets
585 	 * do not have the client-init flag set, so we check for that
586 	 * as well.
587 	 */
588 
589 	if (rxh->type == RX_PACKET_TYPE_DATA &&
590 	    EXTRACT_32BITS(&rxh->seq) == 1 &&
591 	    rxh->flags & RX_CLIENT_INITIATED) {
592 
593 		/*
594 		 * Insert this call into the call cache table, so we
595 		 * have a chance to print out replies
596 		 */
597 
598 		rx_cache_insert(ndo, bp, (const struct ip *) bp2, dport);
599 
600 		switch (dport) {
601 			case FS_RX_PORT:	/* AFS file service */
602 				fs_print(ndo, bp, length);
603 				break;
604 			case CB_RX_PORT:	/* AFS callback service */
605 				cb_print(ndo, bp, length);
606 				break;
607 			case PROT_RX_PORT:	/* AFS protection service */
608 				prot_print(ndo, bp, length);
609 				break;
610 			case VLDB_RX_PORT:	/* AFS VLDB service */
611 				vldb_print(ndo, bp, length);
612 				break;
613 			case KAUTH_RX_PORT:	/* AFS Kerberos auth service */
614 				kauth_print(ndo, bp, length);
615 				break;
616 			case VOL_RX_PORT:	/* AFS Volume service */
617 				vol_print(ndo, bp, length);
618 				break;
619 			case BOS_RX_PORT:	/* AFS BOS service */
620 				bos_print(ndo, bp, length);
621 				break;
622 			default:
623 				;
624 		}
625 
626 	/*
627 	 * If it's a reply (client-init is _not_ set, but seq is one)
628 	 * then look it up in the cache.  If we find it, call the reply
629 	 * printing functions  Note that we handle abort packets here,
630 	 * because printing out the return code can be useful at times.
631 	 */
632 
633 	} else if (((rxh->type == RX_PACKET_TYPE_DATA &&
634 					EXTRACT_32BITS(&rxh->seq) == 1) ||
635 		    rxh->type == RX_PACKET_TYPE_ABORT) &&
636 		   (rxh->flags & RX_CLIENT_INITIATED) == 0 &&
637 		   rx_cache_find(rxh, (const struct ip *) bp2,
638 				 sport, &opcode)) {
639 
640 		switch (sport) {
641 			case FS_RX_PORT:	/* AFS file service */
642 				fs_reply_print(ndo, bp, length, opcode);
643 				break;
644 			case CB_RX_PORT:	/* AFS callback service */
645 				cb_reply_print(ndo, bp, length, opcode);
646 				break;
647 			case PROT_RX_PORT:	/* AFS PT service */
648 				prot_reply_print(ndo, bp, length, opcode);
649 				break;
650 			case VLDB_RX_PORT:	/* AFS VLDB service */
651 				vldb_reply_print(ndo, bp, length, opcode);
652 				break;
653 			case KAUTH_RX_PORT:	/* AFS Kerberos auth service */
654 				kauth_reply_print(ndo, bp, length, opcode);
655 				break;
656 			case VOL_RX_PORT:	/* AFS Volume service */
657 				vol_reply_print(ndo, bp, length, opcode);
658 				break;
659 			case BOS_RX_PORT:	/* AFS BOS service */
660 				bos_reply_print(ndo, bp, length, opcode);
661 				break;
662 			default:
663 				;
664 		}
665 
666 	/*
667 	 * If it's an RX ack packet, then use the appropriate ack decoding
668 	 * function (there isn't any service-specific information in the
669 	 * ack packet, so we can use one for all AFS services)
670 	 */
671 
672 	} else if (rxh->type == RX_PACKET_TYPE_ACK)
673 		rx_ack_print(ndo, bp, length);
674 
675 
676 	ND_PRINT((ndo, " (%d)", length));
677 }
678 
679 /*
680  * Insert an entry into the cache.  Taken from print-nfs.c
681  */
682 
683 static void
684 rx_cache_insert(netdissect_options *ndo,
685                 const u_char *bp, const struct ip *ip, int dport)
686 {
687 	struct rx_cache_entry *rxent;
688 	const struct rx_header *rxh = (const struct rx_header *) bp;
689 
690 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t)))
691 		return;
692 
693 	rxent = &rx_cache[rx_cache_next];
694 
695 	if (++rx_cache_next >= RX_CACHE_SIZE)
696 		rx_cache_next = 0;
697 
698 	rxent->callnum = EXTRACT_32BITS(&rxh->callNumber);
699 	UNALIGNED_MEMCPY(&rxent->client, &ip->ip_src, sizeof(uint32_t));
700 	UNALIGNED_MEMCPY(&rxent->server, &ip->ip_dst, sizeof(uint32_t));
701 	rxent->dport = dport;
702 	rxent->serviceId = EXTRACT_32BITS(&rxh->serviceId);
703 	rxent->opcode = EXTRACT_32BITS(bp + sizeof(struct rx_header));
704 }
705 
706 /*
707  * Lookup an entry in the cache.  Also taken from print-nfs.c
708  *
709  * Note that because this is a reply, we're looking at the _source_
710  * port.
711  */
712 
713 static int
714 rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport,
715 	      int32_t *opcode)
716 {
717 	int i;
718 	struct rx_cache_entry *rxent;
719 	uint32_t clip;
720 	uint32_t sip;
721 
722 	UNALIGNED_MEMCPY(&clip, &ip->ip_dst, sizeof(uint32_t));
723 	UNALIGNED_MEMCPY(&sip, &ip->ip_src, sizeof(uint32_t));
724 
725 	/* Start the search where we last left off */
726 
727 	i = rx_cache_hint;
728 	do {
729 		rxent = &rx_cache[i];
730 		if (rxent->callnum == EXTRACT_32BITS(&rxh->callNumber) &&
731 		    rxent->client.s_addr == clip &&
732 		    rxent->server.s_addr == sip &&
733 		    rxent->serviceId == EXTRACT_32BITS(&rxh->serviceId) &&
734 		    rxent->dport == sport) {
735 
736 			/* We got a match! */
737 
738 			rx_cache_hint = i;
739 			*opcode = rxent->opcode;
740 			return(1);
741 		}
742 		if (++i >= RX_CACHE_SIZE)
743 			i = 0;
744 	} while (i != rx_cache_hint);
745 
746 	/* Our search failed */
747 	return(0);
748 }
749 
750 /*
751  * These extrememly grody macros handle the printing of various AFS stuff.
752  */
753 
754 #define FIDOUT() { unsigned long n1, n2, n3; \
755 			ND_TCHECK2(bp[0], sizeof(int32_t) * 3); \
756 			n1 = EXTRACT_32BITS(bp); \
757 			bp += sizeof(int32_t); \
758 			n2 = EXTRACT_32BITS(bp); \
759 			bp += sizeof(int32_t); \
760 			n3 = EXTRACT_32BITS(bp); \
761 			bp += sizeof(int32_t); \
762 			ND_PRINT((ndo, " fid %d/%d/%d", (int) n1, (int) n2, (int) n3)); \
763 		}
764 
765 #define STROUT(MAX) { unsigned int _i; \
766 			ND_TCHECK2(bp[0], sizeof(int32_t)); \
767 			_i = EXTRACT_32BITS(bp); \
768 			if (_i > (MAX)) \
769 				goto trunc; \
770 			bp += sizeof(int32_t); \
771 			ND_PRINT((ndo, " \"")); \
772 			if (fn_printn(ndo, bp, _i, ndo->ndo_snapend)) \
773 				goto trunc; \
774 			ND_PRINT((ndo, "\"")); \
775 			bp += ((_i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \
776 		}
777 
778 #define INTOUT() { int _i; \
779 			ND_TCHECK2(bp[0], sizeof(int32_t)); \
780 			_i = (int) EXTRACT_32BITS(bp); \
781 			bp += sizeof(int32_t); \
782 			ND_PRINT((ndo, " %d", _i)); \
783 		}
784 
785 #define UINTOUT() { unsigned long _i; \
786 			ND_TCHECK2(bp[0], sizeof(int32_t)); \
787 			_i = EXTRACT_32BITS(bp); \
788 			bp += sizeof(int32_t); \
789 			ND_PRINT((ndo, " %lu", _i)); \
790 		}
791 
792 #define UINT64OUT() { uint64_t _i; \
793 			ND_TCHECK2(bp[0], sizeof(uint64_t)); \
794 			_i = EXTRACT_64BITS(bp); \
795 			bp += sizeof(uint64_t); \
796 			ND_PRINT((ndo, " %" PRIu64, _i)); \
797 		}
798 
799 #define DATEOUT() { time_t _t; struct tm *tm; char str[256]; \
800 			ND_TCHECK2(bp[0], sizeof(int32_t)); \
801 			_t = (time_t) EXTRACT_32BITS(bp); \
802 			bp += sizeof(int32_t); \
803 			tm = localtime(&_t); \
804 			strftime(str, 256, "%Y/%m/%d %H:%M:%S", tm); \
805 			ND_PRINT((ndo, " %s", str)); \
806 		}
807 
808 #define STOREATTROUT() { unsigned long mask, _i; \
809 			ND_TCHECK2(bp[0], (sizeof(int32_t)*6)); \
810 			mask = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
811 			if (mask) ND_PRINT((ndo, " StoreStatus")); \
812 		        if (mask & 1) { ND_PRINT((ndo, " date")); DATEOUT(); } \
813 			else bp += sizeof(int32_t); \
814 			_i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
815 		        if (mask & 2) ND_PRINT((ndo, " owner %lu", _i));  \
816 			_i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
817 		        if (mask & 4) ND_PRINT((ndo, " group %lu", _i)); \
818 			_i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
819 		        if (mask & 8) ND_PRINT((ndo, " mode %lo", _i & 07777)); \
820 			_i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
821 		        if (mask & 16) ND_PRINT((ndo, " segsize %lu", _i)); \
822 			/* undocumented in 3.3 docu */ \
823 		        if (mask & 1024) ND_PRINT((ndo, " fsync"));  \
824 		}
825 
826 #define UBIK_VERSIONOUT() {int32_t epoch; int32_t counter; \
827 			ND_TCHECK2(bp[0], sizeof(int32_t) * 2); \
828 			epoch = EXTRACT_32BITS(bp); \
829 			bp += sizeof(int32_t); \
830 			counter = EXTRACT_32BITS(bp); \
831 			bp += sizeof(int32_t); \
832 			ND_PRINT((ndo, " %d.%d", epoch, counter)); \
833 		}
834 
835 #define AFSUUIDOUT() {uint32_t temp; int _i; \
836 			ND_TCHECK2(bp[0], 11*sizeof(uint32_t)); \
837 			temp = EXTRACT_32BITS(bp); \
838 			bp += sizeof(uint32_t); \
839 			ND_PRINT((ndo, " %08x", temp)); \
840 			temp = EXTRACT_32BITS(bp); \
841 			bp += sizeof(uint32_t); \
842 			ND_PRINT((ndo, "%04x", temp)); \
843 			temp = EXTRACT_32BITS(bp); \
844 			bp += sizeof(uint32_t); \
845 			ND_PRINT((ndo, "%04x", temp)); \
846 			for (_i = 0; _i < 8; _i++) { \
847 				temp = EXTRACT_32BITS(bp); \
848 				bp += sizeof(uint32_t); \
849 				ND_PRINT((ndo, "%02x", (unsigned char) temp)); \
850 			} \
851 		}
852 
853 /*
854  * This is the sickest one of all
855  */
856 
857 #define VECOUT(MAX) { u_char *sp; \
858 			u_char s[AFSNAMEMAX]; \
859 			int k; \
860 			if ((MAX) + 1 > sizeof(s)) \
861 				goto trunc; \
862 			ND_TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \
863 			sp = s; \
864 			for (k = 0; k < (MAX); k++) { \
865 				*sp++ = (u_char) EXTRACT_32BITS(bp); \
866 				bp += sizeof(int32_t); \
867 			} \
868 			s[(MAX)] = '\0'; \
869 			ND_PRINT((ndo, " \"")); \
870 			fn_print(ndo, s, NULL); \
871 			ND_PRINT((ndo, "\"")); \
872 		}
873 
874 #define DESTSERVEROUT() { unsigned long n1, n2, n3; \
875 			ND_TCHECK2(bp[0], sizeof(int32_t) * 3); \
876 			n1 = EXTRACT_32BITS(bp); \
877 			bp += sizeof(int32_t); \
878 			n2 = EXTRACT_32BITS(bp); \
879 			bp += sizeof(int32_t); \
880 			n3 = EXTRACT_32BITS(bp); \
881 			bp += sizeof(int32_t); \
882 			ND_PRINT((ndo, " server %d:%d:%d", (int) n1, (int) n2, (int) n3)); \
883 		}
884 
885 /*
886  * Handle calls to the AFS file service (fs)
887  */
888 
889 static void
890 fs_print(netdissect_options *ndo,
891          register const u_char *bp, int length)
892 {
893 	int fs_op;
894 	unsigned long i;
895 
896 	if (length <= (int)sizeof(struct rx_header))
897 		return;
898 
899 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
900 		goto trunc;
901 	}
902 
903 	/*
904 	 * Print out the afs call we're invoking.  The table used here was
905 	 * gleaned from fsint/afsint.xg
906 	 */
907 
908 	fs_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
909 
910 	ND_PRINT((ndo, " fs call %s", tok2str(fs_req, "op#%d", fs_op)));
911 
912 	/*
913 	 * Print out arguments to some of the AFS calls.  This stuff is
914 	 * all from afsint.xg
915 	 */
916 
917 	bp += sizeof(struct rx_header) + 4;
918 
919 	/*
920 	 * Sigh.  This is gross.  Ritchie forgive me.
921 	 */
922 
923 	switch (fs_op) {
924 		case 130:	/* Fetch data */
925 			FIDOUT();
926 			ND_PRINT((ndo, " offset"));
927 			UINTOUT();
928 			ND_PRINT((ndo, " length"));
929 			UINTOUT();
930 			break;
931 		case 131:	/* Fetch ACL */
932 		case 132:	/* Fetch Status */
933 		case 143:	/* Old set lock */
934 		case 144:	/* Old extend lock */
935 		case 145:	/* Old release lock */
936 		case 156:	/* Set lock */
937 		case 157:	/* Extend lock */
938 		case 158:	/* Release lock */
939 			FIDOUT();
940 			break;
941 		case 135:	/* Store status */
942 			FIDOUT();
943 			STOREATTROUT();
944 			break;
945 		case 133:	/* Store data */
946 			FIDOUT();
947 			STOREATTROUT();
948 			ND_PRINT((ndo, " offset"));
949 			UINTOUT();
950 			ND_PRINT((ndo, " length"));
951 			UINTOUT();
952 			ND_PRINT((ndo, " flen"));
953 			UINTOUT();
954 			break;
955 		case 134:	/* Store ACL */
956 		{
957 			char a[AFSOPAQUEMAX+1];
958 			FIDOUT();
959 			ND_TCHECK2(bp[0], 4);
960 			i = EXTRACT_32BITS(bp);
961 			bp += sizeof(int32_t);
962 			ND_TCHECK2(bp[0], i);
963 			i = min(AFSOPAQUEMAX, i);
964 			strncpy(a, (const char *) bp, i);
965 			a[i] = '\0';
966 			acl_print(ndo, (u_char *) a, sizeof(a), (u_char *) a + i);
967 			break;
968 		}
969 		case 137:	/* Create file */
970 		case 141:	/* MakeDir */
971 			FIDOUT();
972 			STROUT(AFSNAMEMAX);
973 			STOREATTROUT();
974 			break;
975 		case 136:	/* Remove file */
976 		case 142:	/* Remove directory */
977 			FIDOUT();
978 			STROUT(AFSNAMEMAX);
979 			break;
980 		case 138:	/* Rename file */
981 			ND_PRINT((ndo, " old"));
982 			FIDOUT();
983 			STROUT(AFSNAMEMAX);
984 			ND_PRINT((ndo, " new"));
985 			FIDOUT();
986 			STROUT(AFSNAMEMAX);
987 			break;
988 		case 139:	/* Symlink */
989 			FIDOUT();
990 			STROUT(AFSNAMEMAX);
991 			ND_PRINT((ndo, " link to"));
992 			STROUT(AFSNAMEMAX);
993 			break;
994 		case 140:	/* Link */
995 			FIDOUT();
996 			STROUT(AFSNAMEMAX);
997 			ND_PRINT((ndo, " link to"));
998 			FIDOUT();
999 			break;
1000 		case 148:	/* Get volume info */
1001 			STROUT(AFSNAMEMAX);
1002 			break;
1003 		case 149:	/* Get volume stats */
1004 		case 150:	/* Set volume stats */
1005 			ND_PRINT((ndo, " volid"));
1006 			UINTOUT();
1007 			break;
1008 		case 154:	/* New get volume info */
1009 			ND_PRINT((ndo, " volname"));
1010 			STROUT(AFSNAMEMAX);
1011 			break;
1012 		case 155:	/* Bulk stat */
1013 		case 65536:     /* Inline bulk stat */
1014 		{
1015 			unsigned long j;
1016 			ND_TCHECK2(bp[0], 4);
1017 			j = EXTRACT_32BITS(bp);
1018 			bp += sizeof(int32_t);
1019 
1020 			for (i = 0; i < j; i++) {
1021 				FIDOUT();
1022 				if (i != j - 1)
1023 					ND_PRINT((ndo, ","));
1024 			}
1025 			if (j == 0)
1026 				ND_PRINT((ndo, " <none!>"));
1027 		}
1028 		case 65537:	/* Fetch data 64 */
1029 			FIDOUT();
1030 			ND_PRINT((ndo, " offset"));
1031 			UINT64OUT();
1032 			ND_PRINT((ndo, " length"));
1033 			UINT64OUT();
1034 			break;
1035 		case 65538:	/* Store data 64 */
1036 			FIDOUT();
1037 			STOREATTROUT();
1038 			ND_PRINT((ndo, " offset"));
1039 			UINT64OUT();
1040 			ND_PRINT((ndo, " length"));
1041 			UINT64OUT();
1042 			ND_PRINT((ndo, " flen"));
1043 			UINT64OUT();
1044 			break;
1045 		case 65541:    /* CallBack rx conn address */
1046 			ND_PRINT((ndo, " addr"));
1047 			UINTOUT();
1048 		default:
1049 			;
1050 	}
1051 
1052 	return;
1053 
1054 trunc:
1055 	ND_PRINT((ndo, " [|fs]"));
1056 }
1057 
1058 /*
1059  * Handle replies to the AFS file service
1060  */
1061 
1062 static void
1063 fs_reply_print(netdissect_options *ndo,
1064                register const u_char *bp, int length, int32_t opcode)
1065 {
1066 	unsigned long i;
1067 	const struct rx_header *rxh;
1068 
1069 	if (length <= (int)sizeof(struct rx_header))
1070 		return;
1071 
1072 	rxh = (const struct rx_header *) bp;
1073 
1074 	/*
1075 	 * Print out the afs call we're invoking.  The table used here was
1076 	 * gleaned from fsint/afsint.xg
1077 	 */
1078 
1079 	ND_PRINT((ndo, " fs reply %s", tok2str(fs_req, "op#%d", opcode)));
1080 
1081 	bp += sizeof(struct rx_header);
1082 
1083 	/*
1084 	 * If it was a data packet, interpret the response
1085 	 */
1086 
1087 	if (rxh->type == RX_PACKET_TYPE_DATA) {
1088 		switch (opcode) {
1089 		case 131:	/* Fetch ACL */
1090 		{
1091 			char a[AFSOPAQUEMAX+1];
1092 			ND_TCHECK2(bp[0], 4);
1093 			i = EXTRACT_32BITS(bp);
1094 			bp += sizeof(int32_t);
1095 			ND_TCHECK2(bp[0], i);
1096 			i = min(AFSOPAQUEMAX, i);
1097 			strncpy(a, (const char *) bp, i);
1098 			a[i] = '\0';
1099 			acl_print(ndo, (u_char *) a, sizeof(a), (u_char *) a + i);
1100 			break;
1101 		}
1102 		case 137:	/* Create file */
1103 		case 141:	/* MakeDir */
1104 			ND_PRINT((ndo, " new"));
1105 			FIDOUT();
1106 			break;
1107 		case 151:	/* Get root volume */
1108 			ND_PRINT((ndo, " root volume"));
1109 			STROUT(AFSNAMEMAX);
1110 			break;
1111 		case 153:	/* Get time */
1112 			DATEOUT();
1113 			break;
1114 		default:
1115 			;
1116 		}
1117 	} else if (rxh->type == RX_PACKET_TYPE_ABORT) {
1118 		/*
1119 		 * Otherwise, just print out the return code
1120 		 */
1121 		ND_TCHECK2(bp[0], sizeof(int32_t));
1122 		i = (int) EXTRACT_32BITS(bp);
1123 		bp += sizeof(int32_t);
1124 
1125 		ND_PRINT((ndo, " error %s", tok2str(afs_fs_errors, "#%d", i)));
1126 	} else {
1127 		ND_PRINT((ndo, " strange fs reply of type %d", rxh->type));
1128 	}
1129 
1130 	return;
1131 
1132 trunc:
1133 	ND_PRINT((ndo, " [|fs]"));
1134 }
1135 
1136 /*
1137  * Print out an AFS ACL string.  An AFS ACL is a string that has the
1138  * following format:
1139  *
1140  * <positive> <negative>
1141  * <uid1> <aclbits1>
1142  * ....
1143  *
1144  * "positive" and "negative" are integers which contain the number of
1145  * positive and negative ACL's in the string.  The uid/aclbits pair are
1146  * ASCII strings containing the UID/PTS record and and a ascii number
1147  * representing a logical OR of all the ACL permission bits
1148  */
1149 
1150 static void
1151 acl_print(netdissect_options *ndo,
1152           u_char *s, int maxsize, u_char *end)
1153 {
1154 	int pos, neg, acl;
1155 	int n, i;
1156 	char *user;
1157 	char fmt[1024];
1158 
1159 	if ((user = (char *)malloc(maxsize)) == NULL)
1160 		return;
1161 
1162 	if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
1163 		goto finish;
1164 
1165 	s += n;
1166 
1167 	if (s > end)
1168 		goto finish;
1169 
1170 	/*
1171 	 * This wacky order preserves the order used by the "fs" command
1172 	 */
1173 
1174 #define ACLOUT(acl) \
1175 	ND_PRINT((ndo, "%s%s%s%s%s%s%s", \
1176 	          acl & PRSFS_READ       ? "r" : "", \
1177 	          acl & PRSFS_LOOKUP     ? "l" : "", \
1178 	          acl & PRSFS_INSERT     ? "i" : "", \
1179 	          acl & PRSFS_DELETE     ? "d" : "", \
1180 	          acl & PRSFS_WRITE      ? "w" : "", \
1181 	          acl & PRSFS_LOCK       ? "k" : "", \
1182 	          acl & PRSFS_ADMINISTER ? "a" : ""));
1183 
1184 	for (i = 0; i < pos; i++) {
1185 		snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1);
1186 		if (sscanf((char *) s, fmt, user, &acl, &n) != 2)
1187 			goto finish;
1188 		s += n;
1189 		ND_PRINT((ndo, " +{"));
1190 		fn_print(ndo, (u_char *)user, NULL);
1191 		ND_PRINT((ndo, " "));
1192 		ACLOUT(acl);
1193 		ND_PRINT((ndo, "}"));
1194 		if (s > end)
1195 			goto finish;
1196 	}
1197 
1198 	for (i = 0; i < neg; i++) {
1199 		snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1);
1200 		if (sscanf((char *) s, fmt, user, &acl, &n) != 2)
1201 			goto finish;
1202 		s += n;
1203 		ND_PRINT((ndo, " -{"));
1204 		fn_print(ndo, (u_char *)user, NULL);
1205 		ND_PRINT((ndo, " "));
1206 		ACLOUT(acl);
1207 		ND_PRINT((ndo, "}"));
1208 		if (s > end)
1209 			goto finish;
1210 	}
1211 
1212 finish:
1213 	free(user);
1214 	return;
1215 }
1216 
1217 #undef ACLOUT
1218 
1219 /*
1220  * Handle calls to the AFS callback service
1221  */
1222 
1223 static void
1224 cb_print(netdissect_options *ndo,
1225          register const u_char *bp, int length)
1226 {
1227 	int cb_op;
1228 	unsigned long i;
1229 
1230 	if (length <= (int)sizeof(struct rx_header))
1231 		return;
1232 
1233 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1234 		goto trunc;
1235 	}
1236 
1237 	/*
1238 	 * Print out the afs call we're invoking.  The table used here was
1239 	 * gleaned from fsint/afscbint.xg
1240 	 */
1241 
1242 	cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1243 
1244 	ND_PRINT((ndo, " cb call %s", tok2str(cb_req, "op#%d", cb_op)));
1245 
1246 	bp += sizeof(struct rx_header) + 4;
1247 
1248 	/*
1249 	 * Print out the afs call we're invoking.  The table used here was
1250 	 * gleaned from fsint/afscbint.xg
1251 	 */
1252 
1253 	switch (cb_op) {
1254 		case 204:		/* Callback */
1255 		{
1256 			unsigned long j, t;
1257 			ND_TCHECK2(bp[0], 4);
1258 			j = EXTRACT_32BITS(bp);
1259 			bp += sizeof(int32_t);
1260 
1261 			for (i = 0; i < j; i++) {
1262 				FIDOUT();
1263 				if (i != j - 1)
1264 					ND_PRINT((ndo, ","));
1265 			}
1266 
1267 			if (j == 0)
1268 				ND_PRINT((ndo, " <none!>"));
1269 
1270 			ND_TCHECK_32BITS(bp);
1271 			j = EXTRACT_32BITS(bp);
1272 			bp += sizeof(int32_t);
1273 
1274 			if (j != 0)
1275 				ND_PRINT((ndo, ";"));
1276 
1277 			for (i = 0; i < j; i++) {
1278 				ND_PRINT((ndo, " ver"));
1279 				INTOUT();
1280 				ND_PRINT((ndo, " expires"));
1281 				DATEOUT();
1282 				ND_TCHECK2(bp[0], 4);
1283 				t = EXTRACT_32BITS(bp);
1284 				bp += sizeof(int32_t);
1285 				tok2str(cb_types, "type %d", t);
1286 			}
1287 		}
1288 		case 214: {
1289 			ND_PRINT((ndo, " afsuuid"));
1290 			AFSUUIDOUT();
1291 			break;
1292 		}
1293 		default:
1294 			;
1295 	}
1296 
1297 	return;
1298 
1299 trunc:
1300 	ND_PRINT((ndo, " [|cb]"));
1301 }
1302 
1303 /*
1304  * Handle replies to the AFS Callback Service
1305  */
1306 
1307 static void
1308 cb_reply_print(netdissect_options *ndo,
1309                register const u_char *bp, int length, int32_t opcode)
1310 {
1311 	const struct rx_header *rxh;
1312 
1313 	if (length <= (int)sizeof(struct rx_header))
1314 		return;
1315 
1316 	rxh = (const struct rx_header *) bp;
1317 
1318 	/*
1319 	 * Print out the afs call we're invoking.  The table used here was
1320 	 * gleaned from fsint/afscbint.xg
1321 	 */
1322 
1323 	ND_PRINT((ndo, " cb reply %s", tok2str(cb_req, "op#%d", opcode)));
1324 
1325 	bp += sizeof(struct rx_header);
1326 
1327 	/*
1328 	 * If it was a data packet, interpret the response.
1329 	 */
1330 
1331 	if (rxh->type == RX_PACKET_TYPE_DATA)
1332 		switch (opcode) {
1333 		case 213:	/* InitCallBackState3 */
1334 			AFSUUIDOUT();
1335 			break;
1336 		default:
1337 		;
1338 		}
1339 	else {
1340 		/*
1341 		 * Otherwise, just print out the return code
1342 		 */
1343 		ND_PRINT((ndo, " errcode"));
1344 		INTOUT();
1345 	}
1346 
1347 	return;
1348 
1349 trunc:
1350 	ND_PRINT((ndo, " [|cb]"));
1351 }
1352 
1353 /*
1354  * Handle calls to the AFS protection database server
1355  */
1356 
1357 static void
1358 prot_print(netdissect_options *ndo,
1359            register const u_char *bp, int length)
1360 {
1361 	unsigned long i;
1362 	int pt_op;
1363 
1364 	if (length <= (int)sizeof(struct rx_header))
1365 		return;
1366 
1367 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1368 		goto trunc;
1369 	}
1370 
1371 	/*
1372 	 * Print out the afs call we're invoking.  The table used here was
1373 	 * gleaned from ptserver/ptint.xg
1374 	 */
1375 
1376 	pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1377 
1378 	ND_PRINT((ndo, " pt"));
1379 
1380 	if (is_ubik(pt_op)) {
1381 		ubik_print(ndo, bp);
1382 		return;
1383 	}
1384 
1385 	ND_PRINT((ndo, " call %s", tok2str(pt_req, "op#%d", pt_op)));
1386 
1387 	/*
1388 	 * Decode some of the arguments to the PT calls
1389 	 */
1390 
1391 	bp += sizeof(struct rx_header) + 4;
1392 
1393 	switch (pt_op) {
1394 		case 500:	/* I New User */
1395 			STROUT(PRNAMEMAX);
1396 			ND_PRINT((ndo, " id"));
1397 			INTOUT();
1398 			ND_PRINT((ndo, " oldid"));
1399 			INTOUT();
1400 			break;
1401 		case 501:	/* Where is it */
1402 		case 506:	/* Delete */
1403 		case 508:	/* Get CPS */
1404 		case 512:	/* List entry */
1405 		case 514:	/* List elements */
1406 		case 517:	/* List owned */
1407 		case 518:	/* Get CPS2 */
1408 		case 519:	/* Get host CPS */
1409 		case 530:	/* List super groups */
1410 			ND_PRINT((ndo, " id"));
1411 			INTOUT();
1412 			break;
1413 		case 502:	/* Dump entry */
1414 			ND_PRINT((ndo, " pos"));
1415 			INTOUT();
1416 			break;
1417 		case 503:	/* Add to group */
1418 		case 507:	/* Remove from group */
1419 		case 515:	/* Is a member of? */
1420 			ND_PRINT((ndo, " uid"));
1421 			INTOUT();
1422 			ND_PRINT((ndo, " gid"));
1423 			INTOUT();
1424 			break;
1425 		case 504:	/* Name to ID */
1426 		{
1427 			unsigned long j;
1428 			ND_TCHECK2(bp[0], 4);
1429 			j = EXTRACT_32BITS(bp);
1430 			bp += sizeof(int32_t);
1431 
1432 			/*
1433 			 * Who designed this chicken-shit protocol?
1434 			 *
1435 			 * Each character is stored as a 32-bit
1436 			 * integer!
1437 			 */
1438 
1439 			for (i = 0; i < j; i++) {
1440 				VECOUT(PRNAMEMAX);
1441 			}
1442 			if (j == 0)
1443 				ND_PRINT((ndo, " <none!>"));
1444 		}
1445 			break;
1446 		case 505:	/* Id to name */
1447 		{
1448 			unsigned long j;
1449 			ND_PRINT((ndo, " ids:"));
1450 			ND_TCHECK2(bp[0], 4);
1451 			i = EXTRACT_32BITS(bp);
1452 			bp += sizeof(int32_t);
1453 			for (j = 0; j < i; j++)
1454 				INTOUT();
1455 			if (j == 0)
1456 				ND_PRINT((ndo, " <none!>"));
1457 		}
1458 			break;
1459 		case 509:	/* New entry */
1460 			STROUT(PRNAMEMAX);
1461 			ND_PRINT((ndo, " flag"));
1462 			INTOUT();
1463 			ND_PRINT((ndo, " oid"));
1464 			INTOUT();
1465 			break;
1466 		case 511:	/* Set max */
1467 			ND_PRINT((ndo, " id"));
1468 			INTOUT();
1469 			ND_PRINT((ndo, " gflag"));
1470 			INTOUT();
1471 			break;
1472 		case 513:	/* Change entry */
1473 			ND_PRINT((ndo, " id"));
1474 			INTOUT();
1475 			STROUT(PRNAMEMAX);
1476 			ND_PRINT((ndo, " oldid"));
1477 			INTOUT();
1478 			ND_PRINT((ndo, " newid"));
1479 			INTOUT();
1480 			break;
1481 		case 520:	/* Update entry */
1482 			ND_PRINT((ndo, " id"));
1483 			INTOUT();
1484 			STROUT(PRNAMEMAX);
1485 			break;
1486 		default:
1487 			;
1488 	}
1489 
1490 
1491 	return;
1492 
1493 trunc:
1494 	ND_PRINT((ndo, " [|pt]"));
1495 }
1496 
1497 /*
1498  * Handle replies to the AFS protection service
1499  */
1500 
1501 static void
1502 prot_reply_print(netdissect_options *ndo,
1503                  register const u_char *bp, int length, int32_t opcode)
1504 {
1505 	const struct rx_header *rxh;
1506 	unsigned long i;
1507 
1508 	if (length < (int)sizeof(struct rx_header))
1509 		return;
1510 
1511 	rxh = (const struct rx_header *) bp;
1512 
1513 	/*
1514 	 * Print out the afs call we're invoking.  The table used here was
1515 	 * gleaned from ptserver/ptint.xg.  Check to see if it's a
1516 	 * Ubik call, however.
1517 	 */
1518 
1519 	ND_PRINT((ndo, " pt"));
1520 
1521 	if (is_ubik(opcode)) {
1522 		ubik_reply_print(ndo, bp, length, opcode);
1523 		return;
1524 	}
1525 
1526 	ND_PRINT((ndo, " reply %s", tok2str(pt_req, "op#%d", opcode)));
1527 
1528 	bp += sizeof(struct rx_header);
1529 
1530 	/*
1531 	 * If it was a data packet, interpret the response
1532 	 */
1533 
1534 	if (rxh->type == RX_PACKET_TYPE_DATA)
1535 		switch (opcode) {
1536 		case 504:		/* Name to ID */
1537 		{
1538 			unsigned long j;
1539 			ND_PRINT((ndo, " ids:"));
1540 			ND_TCHECK2(bp[0], 4);
1541 			i = EXTRACT_32BITS(bp);
1542 			bp += sizeof(int32_t);
1543 			for (j = 0; j < i; j++)
1544 				INTOUT();
1545 			if (j == 0)
1546 				ND_PRINT((ndo, " <none!>"));
1547 		}
1548 			break;
1549 		case 505:		/* ID to name */
1550 		{
1551 			unsigned long j;
1552 			ND_TCHECK2(bp[0], 4);
1553 			j = EXTRACT_32BITS(bp);
1554 			bp += sizeof(int32_t);
1555 
1556 			/*
1557 			 * Who designed this chicken-shit protocol?
1558 			 *
1559 			 * Each character is stored as a 32-bit
1560 			 * integer!
1561 			 */
1562 
1563 			for (i = 0; i < j; i++) {
1564 				VECOUT(PRNAMEMAX);
1565 			}
1566 			if (j == 0)
1567 				ND_PRINT((ndo, " <none!>"));
1568 		}
1569 			break;
1570 		case 508:		/* Get CPS */
1571 		case 514:		/* List elements */
1572 		case 517:		/* List owned */
1573 		case 518:		/* Get CPS2 */
1574 		case 519:		/* Get host CPS */
1575 		{
1576 			unsigned long j;
1577 			ND_TCHECK2(bp[0], 4);
1578 			j = EXTRACT_32BITS(bp);
1579 			bp += sizeof(int32_t);
1580 			for (i = 0; i < j; i++) {
1581 				INTOUT();
1582 			}
1583 			if (j == 0)
1584 				ND_PRINT((ndo, " <none!>"));
1585 		}
1586 			break;
1587 		case 510:		/* List max */
1588 			ND_PRINT((ndo, " maxuid"));
1589 			INTOUT();
1590 			ND_PRINT((ndo, " maxgid"));
1591 			INTOUT();
1592 			break;
1593 		default:
1594 			;
1595 		}
1596 	else {
1597 		/*
1598 		 * Otherwise, just print out the return code
1599 		 */
1600 		ND_PRINT((ndo, " errcode"));
1601 		INTOUT();
1602 	}
1603 
1604 	return;
1605 
1606 trunc:
1607 	ND_PRINT((ndo, " [|pt]"));
1608 }
1609 
1610 /*
1611  * Handle calls to the AFS volume location database service
1612  */
1613 
1614 static void
1615 vldb_print(netdissect_options *ndo,
1616            register const u_char *bp, int length)
1617 {
1618 	int vldb_op;
1619 	unsigned long i;
1620 
1621 	if (length <= (int)sizeof(struct rx_header))
1622 		return;
1623 
1624 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1625 		goto trunc;
1626 	}
1627 
1628 	/*
1629 	 * Print out the afs call we're invoking.  The table used here was
1630 	 * gleaned from vlserver/vldbint.xg
1631 	 */
1632 
1633 	vldb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1634 
1635 	ND_PRINT((ndo, " vldb"));
1636 
1637 	if (is_ubik(vldb_op)) {
1638 		ubik_print(ndo, bp);
1639 		return;
1640 	}
1641 	ND_PRINT((ndo, " call %s", tok2str(vldb_req, "op#%d", vldb_op)));
1642 
1643 	/*
1644 	 * Decode some of the arguments to the VLDB calls
1645 	 */
1646 
1647 	bp += sizeof(struct rx_header) + 4;
1648 
1649 	switch (vldb_op) {
1650 		case 501:	/* Create new volume */
1651 		case 517:	/* Create entry N */
1652 			VECOUT(VLNAMEMAX);
1653 			break;
1654 		case 502:	/* Delete entry */
1655 		case 503:	/* Get entry by ID */
1656 		case 507:	/* Update entry */
1657 		case 508:	/* Set lock */
1658 		case 509:	/* Release lock */
1659 		case 518:	/* Get entry by ID N */
1660 			ND_PRINT((ndo, " volid"));
1661 			INTOUT();
1662 			ND_TCHECK2(bp[0], sizeof(int32_t));
1663 			i = EXTRACT_32BITS(bp);
1664 			bp += sizeof(int32_t);
1665 			if (i <= 2)
1666 				ND_PRINT((ndo, " type %s", voltype[i]));
1667 			break;
1668 		case 504:	/* Get entry by name */
1669 		case 519:	/* Get entry by name N */
1670 		case 524:	/* Update entry by name */
1671 		case 527:	/* Get entry by name U */
1672 			STROUT(VLNAMEMAX);
1673 			break;
1674 		case 505:	/* Get new vol id */
1675 			ND_PRINT((ndo, " bump"));
1676 			INTOUT();
1677 			break;
1678 		case 506:	/* Replace entry */
1679 		case 520:	/* Replace entry N */
1680 			ND_PRINT((ndo, " volid"));
1681 			INTOUT();
1682 			ND_TCHECK2(bp[0], sizeof(int32_t));
1683 			i = EXTRACT_32BITS(bp);
1684 			bp += sizeof(int32_t);
1685 			if (i <= 2)
1686 				ND_PRINT((ndo, " type %s", voltype[i]));
1687 			VECOUT(VLNAMEMAX);
1688 			break;
1689 		case 510:	/* List entry */
1690 		case 521:	/* List entry N */
1691 			ND_PRINT((ndo, " index"));
1692 			INTOUT();
1693 			break;
1694 		default:
1695 			;
1696 	}
1697 
1698 	return;
1699 
1700 trunc:
1701 	ND_PRINT((ndo, " [|vldb]"));
1702 }
1703 
1704 /*
1705  * Handle replies to the AFS volume location database service
1706  */
1707 
1708 static void
1709 vldb_reply_print(netdissect_options *ndo,
1710                  register const u_char *bp, int length, int32_t opcode)
1711 {
1712 	const struct rx_header *rxh;
1713 	unsigned long i;
1714 
1715 	if (length < (int)sizeof(struct rx_header))
1716 		return;
1717 
1718 	rxh = (const struct rx_header *) bp;
1719 
1720 	/*
1721 	 * Print out the afs call we're invoking.  The table used here was
1722 	 * gleaned from vlserver/vldbint.xg.  Check to see if it's a
1723 	 * Ubik call, however.
1724 	 */
1725 
1726 	ND_PRINT((ndo, " vldb"));
1727 
1728 	if (is_ubik(opcode)) {
1729 		ubik_reply_print(ndo, bp, length, opcode);
1730 		return;
1731 	}
1732 
1733 	ND_PRINT((ndo, " reply %s", tok2str(vldb_req, "op#%d", opcode)));
1734 
1735 	bp += sizeof(struct rx_header);
1736 
1737 	/*
1738 	 * If it was a data packet, interpret the response
1739 	 */
1740 
1741 	if (rxh->type == RX_PACKET_TYPE_DATA)
1742 		switch (opcode) {
1743 		case 510:	/* List entry */
1744 			ND_PRINT((ndo, " count"));
1745 			INTOUT();
1746 			ND_PRINT((ndo, " nextindex"));
1747 			INTOUT();
1748 		case 503:	/* Get entry by id */
1749 		case 504:	/* Get entry by name */
1750 		{	unsigned long nservers, j;
1751 			VECOUT(VLNAMEMAX);
1752 			ND_TCHECK2(bp[0], sizeof(int32_t));
1753 			bp += sizeof(int32_t);
1754 			ND_PRINT((ndo, " numservers"));
1755 			ND_TCHECK2(bp[0], sizeof(int32_t));
1756 			nservers = EXTRACT_32BITS(bp);
1757 			bp += sizeof(int32_t);
1758 			ND_PRINT((ndo, " %lu", nservers));
1759 			ND_PRINT((ndo, " servers"));
1760 			for (i = 0; i < 8; i++) {
1761 				ND_TCHECK2(bp[0], sizeof(int32_t));
1762 				if (i < nservers)
1763 					ND_PRINT((ndo, " %s",
1764 					   intoa(((const struct in_addr *) bp)->s_addr)));
1765 				bp += sizeof(int32_t);
1766 			}
1767 			ND_PRINT((ndo, " partitions"));
1768 			for (i = 0; i < 8; i++) {
1769 				ND_TCHECK2(bp[0], sizeof(int32_t));
1770 				j = EXTRACT_32BITS(bp);
1771 				if (i < nservers && j <= 26)
1772 					ND_PRINT((ndo, " %c", 'a' + (int)j));
1773 				else if (i < nservers)
1774 					ND_PRINT((ndo, " %lu", j));
1775 				bp += sizeof(int32_t);
1776 			}
1777 			ND_TCHECK2(bp[0], 8 * sizeof(int32_t));
1778 			bp += 8 * sizeof(int32_t);
1779 			ND_PRINT((ndo, " rwvol"));
1780 			UINTOUT();
1781 			ND_PRINT((ndo, " rovol"));
1782 			UINTOUT();
1783 			ND_PRINT((ndo, " backup"));
1784 			UINTOUT();
1785 		}
1786 			break;
1787 		case 505:	/* Get new volume ID */
1788 			ND_PRINT((ndo, " newvol"));
1789 			UINTOUT();
1790 			break;
1791 		case 521:	/* List entry */
1792 		case 529:	/* List entry U */
1793 			ND_PRINT((ndo, " count"));
1794 			INTOUT();
1795 			ND_PRINT((ndo, " nextindex"));
1796 			INTOUT();
1797 		case 518:	/* Get entry by ID N */
1798 		case 519:	/* Get entry by name N */
1799 		{	unsigned long nservers, j;
1800 			VECOUT(VLNAMEMAX);
1801 			ND_PRINT((ndo, " numservers"));
1802 			ND_TCHECK2(bp[0], sizeof(int32_t));
1803 			nservers = EXTRACT_32BITS(bp);
1804 			bp += sizeof(int32_t);
1805 			ND_PRINT((ndo, " %lu", nservers));
1806 			ND_PRINT((ndo, " servers"));
1807 			for (i = 0; i < 13; i++) {
1808 				ND_TCHECK2(bp[0], sizeof(int32_t));
1809 				if (i < nservers)
1810 					ND_PRINT((ndo, " %s",
1811 					   intoa(((const struct in_addr *) bp)->s_addr)));
1812 				bp += sizeof(int32_t);
1813 			}
1814 			ND_PRINT((ndo, " partitions"));
1815 			for (i = 0; i < 13; i++) {
1816 				ND_TCHECK2(bp[0], sizeof(int32_t));
1817 				j = EXTRACT_32BITS(bp);
1818 				if (i < nservers && j <= 26)
1819 					ND_PRINT((ndo, " %c", 'a' + (int)j));
1820 				else if (i < nservers)
1821 					ND_PRINT((ndo, " %lu", j));
1822 				bp += sizeof(int32_t);
1823 			}
1824 			ND_TCHECK2(bp[0], 13 * sizeof(int32_t));
1825 			bp += 13 * sizeof(int32_t);
1826 			ND_PRINT((ndo, " rwvol"));
1827 			UINTOUT();
1828 			ND_PRINT((ndo, " rovol"));
1829 			UINTOUT();
1830 			ND_PRINT((ndo, " backup"));
1831 			UINTOUT();
1832 		}
1833 			break;
1834 		case 526:	/* Get entry by ID U */
1835 		case 527:	/* Get entry by name U */
1836 		{	unsigned long nservers, j;
1837 			VECOUT(VLNAMEMAX);
1838 			ND_PRINT((ndo, " numservers"));
1839 			ND_TCHECK2(bp[0], sizeof(int32_t));
1840 			nservers = EXTRACT_32BITS(bp);
1841 			bp += sizeof(int32_t);
1842 			ND_PRINT((ndo, " %lu", nservers));
1843 			ND_PRINT((ndo, " servers"));
1844 			for (i = 0; i < 13; i++) {
1845 				if (i < nservers) {
1846 					ND_PRINT((ndo, " afsuuid"));
1847 					AFSUUIDOUT();
1848 				} else {
1849 					ND_TCHECK2(bp[0], 44);
1850 					bp += 44;
1851 				}
1852 			}
1853 			ND_TCHECK2(bp[0], 4 * 13);
1854 			bp += 4 * 13;
1855 			ND_PRINT((ndo, " partitions"));
1856 			for (i = 0; i < 13; i++) {
1857 				ND_TCHECK2(bp[0], sizeof(int32_t));
1858 				j = EXTRACT_32BITS(bp);
1859 				if (i < nservers && j <= 26)
1860 					ND_PRINT((ndo, " %c", 'a' + (int)j));
1861 				else if (i < nservers)
1862 					ND_PRINT((ndo, " %lu", j));
1863 				bp += sizeof(int32_t);
1864 			}
1865 			ND_TCHECK2(bp[0], 13 * sizeof(int32_t));
1866 			bp += 13 * sizeof(int32_t);
1867 			ND_PRINT((ndo, " rwvol"));
1868 			UINTOUT();
1869 			ND_PRINT((ndo, " rovol"));
1870 			UINTOUT();
1871 			ND_PRINT((ndo, " backup"));
1872 			UINTOUT();
1873 		}
1874 		default:
1875 			;
1876 		}
1877 
1878 	else {
1879 		/*
1880 		 * Otherwise, just print out the return code
1881 		 */
1882 		ND_PRINT((ndo, " errcode"));
1883 		INTOUT();
1884 	}
1885 
1886 	return;
1887 
1888 trunc:
1889 	ND_PRINT((ndo, " [|vldb]"));
1890 }
1891 
1892 /*
1893  * Handle calls to the AFS Kerberos Authentication service
1894  */
1895 
1896 static void
1897 kauth_print(netdissect_options *ndo,
1898             register const u_char *bp, int length)
1899 {
1900 	int kauth_op;
1901 
1902 	if (length <= (int)sizeof(struct rx_header))
1903 		return;
1904 
1905 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1906 		goto trunc;
1907 	}
1908 
1909 	/*
1910 	 * Print out the afs call we're invoking.  The table used here was
1911 	 * gleaned from kauth/kauth.rg
1912 	 */
1913 
1914 	kauth_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1915 
1916 	ND_PRINT((ndo, " kauth"));
1917 
1918 	if (is_ubik(kauth_op)) {
1919 		ubik_print(ndo, bp);
1920 		return;
1921 	}
1922 
1923 
1924 	ND_PRINT((ndo, " call %s", tok2str(kauth_req, "op#%d", kauth_op)));
1925 
1926 	/*
1927 	 * Decode some of the arguments to the KA calls
1928 	 */
1929 
1930 	bp += sizeof(struct rx_header) + 4;
1931 
1932 	switch (kauth_op) {
1933 		case 1:		/* Authenticate old */
1934 		case 21:	/* Authenticate */
1935 		case 22:	/* Authenticate-V2 */
1936 		case 2:		/* Change PW */
1937 		case 5:		/* Set fields */
1938 		case 6:		/* Create user */
1939 		case 7:		/* Delete user */
1940 		case 8:		/* Get entry */
1941 		case 14:	/* Unlock */
1942 		case 15:	/* Lock status */
1943 			ND_PRINT((ndo, " principal"));
1944 			STROUT(KANAMEMAX);
1945 			STROUT(KANAMEMAX);
1946 			break;
1947 		case 3:		/* GetTicket-old */
1948 		case 23:	/* GetTicket */
1949 		{
1950 			int i;
1951 			ND_PRINT((ndo, " kvno"));
1952 			INTOUT();
1953 			ND_PRINT((ndo, " domain"));
1954 			STROUT(KANAMEMAX);
1955 			ND_TCHECK2(bp[0], sizeof(int32_t));
1956 			i = (int) EXTRACT_32BITS(bp);
1957 			bp += sizeof(int32_t);
1958 			ND_TCHECK2(bp[0], i);
1959 			bp += i;
1960 			ND_PRINT((ndo, " principal"));
1961 			STROUT(KANAMEMAX);
1962 			STROUT(KANAMEMAX);
1963 			break;
1964 		}
1965 		case 4:		/* Set Password */
1966 			ND_PRINT((ndo, " principal"));
1967 			STROUT(KANAMEMAX);
1968 			STROUT(KANAMEMAX);
1969 			ND_PRINT((ndo, " kvno"));
1970 			INTOUT();
1971 			break;
1972 		case 12:	/* Get password */
1973 			ND_PRINT((ndo, " name"));
1974 			STROUT(KANAMEMAX);
1975 			break;
1976 		default:
1977 			;
1978 	}
1979 
1980 	return;
1981 
1982 trunc:
1983 	ND_PRINT((ndo, " [|kauth]"));
1984 }
1985 
1986 /*
1987  * Handle replies to the AFS Kerberos Authentication Service
1988  */
1989 
1990 static void
1991 kauth_reply_print(netdissect_options *ndo,
1992                   register const u_char *bp, int length, int32_t opcode)
1993 {
1994 	const struct rx_header *rxh;
1995 
1996 	if (length <= (int)sizeof(struct rx_header))
1997 		return;
1998 
1999 	rxh = (const struct rx_header *) bp;
2000 
2001 	/*
2002 	 * Print out the afs call we're invoking.  The table used here was
2003 	 * gleaned from kauth/kauth.rg
2004 	 */
2005 
2006 	ND_PRINT((ndo, " kauth"));
2007 
2008 	if (is_ubik(opcode)) {
2009 		ubik_reply_print(ndo, bp, length, opcode);
2010 		return;
2011 	}
2012 
2013 	ND_PRINT((ndo, " reply %s", tok2str(kauth_req, "op#%d", opcode)));
2014 
2015 	bp += sizeof(struct rx_header);
2016 
2017 	/*
2018 	 * If it was a data packet, interpret the response.
2019 	 */
2020 
2021 	if (rxh->type == RX_PACKET_TYPE_DATA)
2022 		/* Well, no, not really.  Leave this for later */
2023 		;
2024 	else {
2025 		/*
2026 		 * Otherwise, just print out the return code
2027 		 */
2028 		ND_PRINT((ndo, " errcode"));
2029 		INTOUT();
2030 	}
2031 
2032 	return;
2033 
2034 trunc:
2035 	ND_PRINT((ndo, " [|kauth]"));
2036 }
2037 
2038 /*
2039  * Handle calls to the AFS Volume location service
2040  */
2041 
2042 static void
2043 vol_print(netdissect_options *ndo,
2044           register const u_char *bp, int length)
2045 {
2046 	int vol_op;
2047 
2048 	if (length <= (int)sizeof(struct rx_header))
2049 		return;
2050 
2051 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
2052 		goto trunc;
2053 	}
2054 
2055 	/*
2056 	 * Print out the afs call we're invoking.  The table used here was
2057 	 * gleaned from volser/volint.xg
2058 	 */
2059 
2060 	vol_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2061 
2062 	ND_PRINT((ndo, " vol call %s", tok2str(vol_req, "op#%d", vol_op)));
2063 
2064 	bp += sizeof(struct rx_header) + 4;
2065 
2066 	switch (vol_op) {
2067 		case 100:	/* Create volume */
2068 			ND_PRINT((ndo, " partition"));
2069 			UINTOUT();
2070 			ND_PRINT((ndo, " name"));
2071 			STROUT(AFSNAMEMAX);
2072 			ND_PRINT((ndo, " type"));
2073 			UINTOUT();
2074 			ND_PRINT((ndo, " parent"));
2075 			UINTOUT();
2076 			break;
2077 		case 101:	/* Delete volume */
2078 		case 107:	/* Get flags */
2079 			ND_PRINT((ndo, " trans"));
2080 			UINTOUT();
2081 			break;
2082 		case 102:	/* Restore */
2083 			ND_PRINT((ndo, " totrans"));
2084 			UINTOUT();
2085 			ND_PRINT((ndo, " flags"));
2086 			UINTOUT();
2087 			break;
2088 		case 103:	/* Forward */
2089 			ND_PRINT((ndo, " fromtrans"));
2090 			UINTOUT();
2091 			ND_PRINT((ndo, " fromdate"));
2092 			DATEOUT();
2093 			DESTSERVEROUT();
2094 			ND_PRINT((ndo, " desttrans"));
2095 			INTOUT();
2096 			break;
2097 		case 104:	/* End trans */
2098 			ND_PRINT((ndo, " trans"));
2099 			UINTOUT();
2100 			break;
2101 		case 105:	/* Clone */
2102 			ND_PRINT((ndo, " trans"));
2103 			UINTOUT();
2104 			ND_PRINT((ndo, " purgevol"));
2105 			UINTOUT();
2106 			ND_PRINT((ndo, " newtype"));
2107 			UINTOUT();
2108 			ND_PRINT((ndo, " newname"));
2109 			STROUT(AFSNAMEMAX);
2110 			break;
2111 		case 106:	/* Set flags */
2112 			ND_PRINT((ndo, " trans"));
2113 			UINTOUT();
2114 			ND_PRINT((ndo, " flags"));
2115 			UINTOUT();
2116 			break;
2117 		case 108:	/* Trans create */
2118 			ND_PRINT((ndo, " vol"));
2119 			UINTOUT();
2120 			ND_PRINT((ndo, " partition"));
2121 			UINTOUT();
2122 			ND_PRINT((ndo, " flags"));
2123 			UINTOUT();
2124 			break;
2125 		case 109:	/* Dump */
2126 		case 655537:	/* Get size */
2127 			ND_PRINT((ndo, " fromtrans"));
2128 			UINTOUT();
2129 			ND_PRINT((ndo, " fromdate"));
2130 			DATEOUT();
2131 			break;
2132 		case 110:	/* Get n-th volume */
2133 			ND_PRINT((ndo, " index"));
2134 			UINTOUT();
2135 			break;
2136 		case 111:	/* Set forwarding */
2137 			ND_PRINT((ndo, " tid"));
2138 			UINTOUT();
2139 			ND_PRINT((ndo, " newsite"));
2140 			UINTOUT();
2141 			break;
2142 		case 112:	/* Get name */
2143 		case 113:	/* Get status */
2144 			ND_PRINT((ndo, " tid"));
2145 			break;
2146 		case 114:	/* Signal restore */
2147 			ND_PRINT((ndo, " name"));
2148 			STROUT(AFSNAMEMAX);
2149 			ND_PRINT((ndo, " type"));
2150 			UINTOUT();
2151 			ND_PRINT((ndo, " pid"));
2152 			UINTOUT();
2153 			ND_PRINT((ndo, " cloneid"));
2154 			UINTOUT();
2155 			break;
2156 		case 116:	/* List volumes */
2157 			ND_PRINT((ndo, " partition"));
2158 			UINTOUT();
2159 			ND_PRINT((ndo, " flags"));
2160 			UINTOUT();
2161 			break;
2162 		case 117:	/* Set id types */
2163 			ND_PRINT((ndo, " tid"));
2164 			UINTOUT();
2165 			ND_PRINT((ndo, " name"));
2166 			STROUT(AFSNAMEMAX);
2167 			ND_PRINT((ndo, " type"));
2168 			UINTOUT();
2169 			ND_PRINT((ndo, " pid"));
2170 			UINTOUT();
2171 			ND_PRINT((ndo, " clone"));
2172 			UINTOUT();
2173 			ND_PRINT((ndo, " backup"));
2174 			UINTOUT();
2175 			break;
2176 		case 119:	/* Partition info */
2177 			ND_PRINT((ndo, " name"));
2178 			STROUT(AFSNAMEMAX);
2179 			break;
2180 		case 120:	/* Reclone */
2181 			ND_PRINT((ndo, " tid"));
2182 			UINTOUT();
2183 			break;
2184 		case 121:	/* List one volume */
2185 		case 122:	/* Nuke volume */
2186 		case 124:	/* Extended List volumes */
2187 		case 125:	/* Extended List one volume */
2188 		case 65536:	/* Convert RO to RW volume */
2189 			ND_PRINT((ndo, " partid"));
2190 			UINTOUT();
2191 			ND_PRINT((ndo, " volid"));
2192 			UINTOUT();
2193 			break;
2194 		case 123:	/* Set date */
2195 			ND_PRINT((ndo, " tid"));
2196 			UINTOUT();
2197 			ND_PRINT((ndo, " date"));
2198 			DATEOUT();
2199 			break;
2200 		case 126:	/* Set info */
2201 			ND_PRINT((ndo, " tid"));
2202 			UINTOUT();
2203 			break;
2204 		case 128:	/* Forward multiple */
2205 			ND_PRINT((ndo, " fromtrans"));
2206 			UINTOUT();
2207 			ND_PRINT((ndo, " fromdate"));
2208 			DATEOUT();
2209 			{
2210 				unsigned long i, j;
2211 				ND_TCHECK2(bp[0], 4);
2212 				j = EXTRACT_32BITS(bp);
2213 				bp += sizeof(int32_t);
2214 				for (i = 0; i < j; i++) {
2215 					DESTSERVEROUT();
2216 					if (i != j - 1)
2217 						ND_PRINT((ndo, ","));
2218 				}
2219 				if (j == 0)
2220 					ND_PRINT((ndo, " <none!>"));
2221 			}
2222 			break;
2223 		case 65538:	/* Dump version 2 */
2224 			ND_PRINT((ndo, " fromtrans"));
2225 			UINTOUT();
2226 			ND_PRINT((ndo, " fromdate"));
2227 			DATEOUT();
2228 			ND_PRINT((ndo, " flags"));
2229 			UINTOUT();
2230 			break;
2231 		default:
2232 			;
2233 	}
2234 	return;
2235 
2236 trunc:
2237 	ND_PRINT((ndo, " [|vol]"));
2238 }
2239 
2240 /*
2241  * Handle replies to the AFS Volume Service
2242  */
2243 
2244 static void
2245 vol_reply_print(netdissect_options *ndo,
2246                 register const u_char *bp, int length, int32_t opcode)
2247 {
2248 	const struct rx_header *rxh;
2249 
2250 	if (length <= (int)sizeof(struct rx_header))
2251 		return;
2252 
2253 	rxh = (const struct rx_header *) bp;
2254 
2255 	/*
2256 	 * Print out the afs call we're invoking.  The table used here was
2257 	 * gleaned from volser/volint.xg
2258 	 */
2259 
2260 	ND_PRINT((ndo, " vol reply %s", tok2str(vol_req, "op#%d", opcode)));
2261 
2262 	bp += sizeof(struct rx_header);
2263 
2264 	/*
2265 	 * If it was a data packet, interpret the response.
2266 	 */
2267 
2268 	if (rxh->type == RX_PACKET_TYPE_DATA) {
2269 		switch (opcode) {
2270 			case 100:	/* Create volume */
2271 				ND_PRINT((ndo, " volid"));
2272 				UINTOUT();
2273 				ND_PRINT((ndo, " trans"));
2274 				UINTOUT();
2275 				break;
2276 			case 104:	/* End transaction */
2277 				UINTOUT();
2278 				break;
2279 			case 105:	/* Clone */
2280 				ND_PRINT((ndo, " newvol"));
2281 				UINTOUT();
2282 				break;
2283 			case 107:	/* Get flags */
2284 				UINTOUT();
2285 				break;
2286 			case 108:	/* Transaction create */
2287 				ND_PRINT((ndo, " trans"));
2288 				UINTOUT();
2289 				break;
2290 			case 110:	/* Get n-th volume */
2291 				ND_PRINT((ndo, " volume"));
2292 				UINTOUT();
2293 				ND_PRINT((ndo, " partition"));
2294 				UINTOUT();
2295 				break;
2296 			case 112:	/* Get name */
2297 				STROUT(AFSNAMEMAX);
2298 				break;
2299 			case 113:	/* Get status */
2300 				ND_PRINT((ndo, " volid"));
2301 				UINTOUT();
2302 				ND_PRINT((ndo, " nextuniq"));
2303 				UINTOUT();
2304 				ND_PRINT((ndo, " type"));
2305 				UINTOUT();
2306 				ND_PRINT((ndo, " parentid"));
2307 				UINTOUT();
2308 				ND_PRINT((ndo, " clone"));
2309 				UINTOUT();
2310 				ND_PRINT((ndo, " backup"));
2311 				UINTOUT();
2312 				ND_PRINT((ndo, " restore"));
2313 				UINTOUT();
2314 				ND_PRINT((ndo, " maxquota"));
2315 				UINTOUT();
2316 				ND_PRINT((ndo, " minquota"));
2317 				UINTOUT();
2318 				ND_PRINT((ndo, " owner"));
2319 				UINTOUT();
2320 				ND_PRINT((ndo, " create"));
2321 				DATEOUT();
2322 				ND_PRINT((ndo, " access"));
2323 				DATEOUT();
2324 				ND_PRINT((ndo, " update"));
2325 				DATEOUT();
2326 				ND_PRINT((ndo, " expire"));
2327 				DATEOUT();
2328 				ND_PRINT((ndo, " backup"));
2329 				DATEOUT();
2330 				ND_PRINT((ndo, " copy"));
2331 				DATEOUT();
2332 				break;
2333 			case 115:	/* Old list partitions */
2334 				break;
2335 			case 116:	/* List volumes */
2336 			case 121:	/* List one volume */
2337 				{
2338 					unsigned long i, j;
2339 					ND_TCHECK2(bp[0], 4);
2340 					j = EXTRACT_32BITS(bp);
2341 					bp += sizeof(int32_t);
2342 					for (i = 0; i < j; i++) {
2343 						ND_PRINT((ndo, " name"));
2344 						VECOUT(32);
2345 						ND_PRINT((ndo, " volid"));
2346 						UINTOUT();
2347 						ND_PRINT((ndo, " type"));
2348 						bp += sizeof(int32_t) * 21;
2349 						if (i != j - 1)
2350 							ND_PRINT((ndo, ","));
2351 					}
2352 					if (j == 0)
2353 						ND_PRINT((ndo, " <none!>"));
2354 				}
2355 				break;
2356 
2357 
2358 			default:
2359 				;
2360 		}
2361 	} else {
2362 		/*
2363 		 * Otherwise, just print out the return code
2364 		 */
2365 		ND_PRINT((ndo, " errcode"));
2366 		INTOUT();
2367 	}
2368 
2369 	return;
2370 
2371 trunc:
2372 	ND_PRINT((ndo, " [|vol]"));
2373 }
2374 
2375 /*
2376  * Handle calls to the AFS BOS service
2377  */
2378 
2379 static void
2380 bos_print(netdissect_options *ndo,
2381           register const u_char *bp, int length)
2382 {
2383 	int bos_op;
2384 
2385 	if (length <= (int)sizeof(struct rx_header))
2386 		return;
2387 
2388 	if (ndo->ndo_snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
2389 		goto trunc;
2390 	}
2391 
2392 	/*
2393 	 * Print out the afs call we're invoking.  The table used here was
2394 	 * gleaned from bozo/bosint.xg
2395 	 */
2396 
2397 	bos_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2398 
2399 	ND_PRINT((ndo, " bos call %s", tok2str(bos_req, "op#%d", bos_op)));
2400 
2401 	/*
2402 	 * Decode some of the arguments to the BOS calls
2403 	 */
2404 
2405 	bp += sizeof(struct rx_header) + 4;
2406 
2407 	switch (bos_op) {
2408 		case 80:	/* Create B node */
2409 			ND_PRINT((ndo, " type"));
2410 			STROUT(BOSNAMEMAX);
2411 			ND_PRINT((ndo, " instance"));
2412 			STROUT(BOSNAMEMAX);
2413 			break;
2414 		case 81:	/* Delete B node */
2415 		case 83:	/* Get status */
2416 		case 85:	/* Get instance info */
2417 		case 87:	/* Add super user */
2418 		case 88:	/* Delete super user */
2419 		case 93:	/* Set cell name */
2420 		case 96:	/* Add cell host */
2421 		case 97:	/* Delete cell host */
2422 		case 104:	/* Restart */
2423 		case 106:	/* Uninstall */
2424 		case 108:	/* Exec */
2425 		case 112:	/* Getlog */
2426 		case 114:	/* Get instance strings */
2427 			STROUT(BOSNAMEMAX);
2428 			break;
2429 		case 82:	/* Set status */
2430 		case 98:	/* Set T status */
2431 			STROUT(BOSNAMEMAX);
2432 			ND_PRINT((ndo, " status"));
2433 			INTOUT();
2434 			break;
2435 		case 86:	/* Get instance parm */
2436 			STROUT(BOSNAMEMAX);
2437 			ND_PRINT((ndo, " num"));
2438 			INTOUT();
2439 			break;
2440 		case 84:	/* Enumerate instance */
2441 		case 89:	/* List super users */
2442 		case 90:	/* List keys */
2443 		case 91:	/* Add key */
2444 		case 92:	/* Delete key */
2445 		case 95:	/* Get cell host */
2446 			INTOUT();
2447 			break;
2448 		case 105:	/* Install */
2449 			STROUT(BOSNAMEMAX);
2450 			ND_PRINT((ndo, " size"));
2451 			INTOUT();
2452 			ND_PRINT((ndo, " flags"));
2453 			INTOUT();
2454 			ND_PRINT((ndo, " date"));
2455 			INTOUT();
2456 			break;
2457 		default:
2458 			;
2459 	}
2460 
2461 	return;
2462 
2463 trunc:
2464 	ND_PRINT((ndo, " [|bos]"));
2465 }
2466 
2467 /*
2468  * Handle replies to the AFS BOS Service
2469  */
2470 
2471 static void
2472 bos_reply_print(netdissect_options *ndo,
2473                 register const u_char *bp, int length, int32_t opcode)
2474 {
2475 	const struct rx_header *rxh;
2476 
2477 	if (length <= (int)sizeof(struct rx_header))
2478 		return;
2479 
2480 	rxh = (const struct rx_header *) bp;
2481 
2482 	/*
2483 	 * Print out the afs call we're invoking.  The table used here was
2484 	 * gleaned from volser/volint.xg
2485 	 */
2486 
2487 	ND_PRINT((ndo, " bos reply %s", tok2str(bos_req, "op#%d", opcode)));
2488 
2489 	bp += sizeof(struct rx_header);
2490 
2491 	/*
2492 	 * If it was a data packet, interpret the response.
2493 	 */
2494 
2495 	if (rxh->type == RX_PACKET_TYPE_DATA)
2496 		/* Well, no, not really.  Leave this for later */
2497 		;
2498 	else {
2499 		/*
2500 		 * Otherwise, just print out the return code
2501 		 */
2502 		ND_PRINT((ndo, " errcode"));
2503 		INTOUT();
2504 	}
2505 
2506 	return;
2507 
2508 trunc:
2509 	ND_PRINT((ndo, " [|bos]"));
2510 }
2511 
2512 /*
2513  * Check to see if this is a Ubik opcode.
2514  */
2515 
2516 static int
2517 is_ubik(uint32_t opcode)
2518 {
2519 	if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
2520 	    (opcode >= DISK_LOW && opcode <= DISK_HIGH))
2521 		return(1);
2522 	else
2523 		return(0);
2524 }
2525 
2526 /*
2527  * Handle Ubik opcodes to any one of the replicated database services
2528  */
2529 
2530 static void
2531 ubik_print(netdissect_options *ndo,
2532            register const u_char *bp)
2533 {
2534 	int ubik_op;
2535 	int32_t temp;
2536 
2537 	/*
2538 	 * Print out the afs call we're invoking.  The table used here was
2539 	 * gleaned from ubik/ubik_int.xg
2540 	 */
2541 
2542 	/* Every function that calls this function first makes a bounds check
2543 	 * for (sizeof(rx_header) + 4) bytes, so long as it remains this way
2544 	 * the line below will not over-read.
2545 	 */
2546 	ubik_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2547 
2548 	ND_PRINT((ndo, " ubik call %s", tok2str(ubik_req, "op#%d", ubik_op)));
2549 
2550 	/*
2551 	 * Decode some of the arguments to the Ubik calls
2552 	 */
2553 
2554 	bp += sizeof(struct rx_header) + 4;
2555 
2556 	switch (ubik_op) {
2557 		case 10000:		/* Beacon */
2558 			ND_TCHECK2(bp[0], 4);
2559 			temp = EXTRACT_32BITS(bp);
2560 			bp += sizeof(int32_t);
2561 			ND_PRINT((ndo, " syncsite %s", temp ? "yes" : "no"));
2562 			ND_PRINT((ndo, " votestart"));
2563 			DATEOUT();
2564 			ND_PRINT((ndo, " dbversion"));
2565 			UBIK_VERSIONOUT();
2566 			ND_PRINT((ndo, " tid"));
2567 			UBIK_VERSIONOUT();
2568 			break;
2569 		case 10003:		/* Get sync site */
2570 			ND_PRINT((ndo, " site"));
2571 			UINTOUT();
2572 			break;
2573 		case 20000:		/* Begin */
2574 		case 20001:		/* Commit */
2575 		case 20007:		/* Abort */
2576 		case 20008:		/* Release locks */
2577 		case 20010:		/* Writev */
2578 			ND_PRINT((ndo, " tid"));
2579 			UBIK_VERSIONOUT();
2580 			break;
2581 		case 20002:		/* Lock */
2582 			ND_PRINT((ndo, " tid"));
2583 			UBIK_VERSIONOUT();
2584 			ND_PRINT((ndo, " file"));
2585 			INTOUT();
2586 			ND_PRINT((ndo, " pos"));
2587 			INTOUT();
2588 			ND_PRINT((ndo, " length"));
2589 			INTOUT();
2590 			ND_TCHECK_32BITS(bp);
2591 			temp = EXTRACT_32BITS(bp);
2592 			bp += sizeof(int32_t);
2593 			tok2str(ubik_lock_types, "type %d", temp);
2594 			break;
2595 		case 20003:		/* Write */
2596 			ND_PRINT((ndo, " tid"));
2597 			UBIK_VERSIONOUT();
2598 			ND_PRINT((ndo, " file"));
2599 			INTOUT();
2600 			ND_PRINT((ndo, " pos"));
2601 			INTOUT();
2602 			break;
2603 		case 20005:		/* Get file */
2604 			ND_PRINT((ndo, " file"));
2605 			INTOUT();
2606 			break;
2607 		case 20006:		/* Send file */
2608 			ND_PRINT((ndo, " file"));
2609 			INTOUT();
2610 			ND_PRINT((ndo, " length"));
2611 			INTOUT();
2612 			ND_PRINT((ndo, " dbversion"));
2613 			UBIK_VERSIONOUT();
2614 			break;
2615 		case 20009:		/* Truncate */
2616 			ND_PRINT((ndo, " tid"));
2617 			UBIK_VERSIONOUT();
2618 			ND_PRINT((ndo, " file"));
2619 			INTOUT();
2620 			ND_PRINT((ndo, " length"));
2621 			INTOUT();
2622 			break;
2623 		case 20012:		/* Set version */
2624 			ND_PRINT((ndo, " tid"));
2625 			UBIK_VERSIONOUT();
2626 			ND_PRINT((ndo, " oldversion"));
2627 			UBIK_VERSIONOUT();
2628 			ND_PRINT((ndo, " newversion"));
2629 			UBIK_VERSIONOUT();
2630 			break;
2631 		default:
2632 			;
2633 	}
2634 
2635 	return;
2636 
2637 trunc:
2638 	ND_PRINT((ndo, " [|ubik]"));
2639 }
2640 
2641 /*
2642  * Handle Ubik replies to any one of the replicated database services
2643  */
2644 
2645 static void
2646 ubik_reply_print(netdissect_options *ndo,
2647                  register const u_char *bp, int length, int32_t opcode)
2648 {
2649 	const struct rx_header *rxh;
2650 
2651 	if (length < (int)sizeof(struct rx_header))
2652 		return;
2653 
2654 	rxh = (const struct rx_header *) bp;
2655 
2656 	/*
2657 	 * Print out the ubik call we're invoking.  This table was gleaned
2658 	 * from ubik/ubik_int.xg
2659 	 */
2660 
2661 	ND_PRINT((ndo, " ubik reply %s", tok2str(ubik_req, "op#%d", opcode)));
2662 
2663 	bp += sizeof(struct rx_header);
2664 
2665 	/*
2666 	 * If it was a data packet, print out the arguments to the Ubik calls
2667 	 */
2668 
2669 	if (rxh->type == RX_PACKET_TYPE_DATA)
2670 		switch (opcode) {
2671 		case 10000:		/* Beacon */
2672 			ND_PRINT((ndo, " vote no"));
2673 			break;
2674 		case 20004:		/* Get version */
2675 			ND_PRINT((ndo, " dbversion"));
2676 			UBIK_VERSIONOUT();
2677 			break;
2678 		default:
2679 			;
2680 		}
2681 
2682 	/*
2683 	 * Otherwise, print out "yes" it it was a beacon packet (because
2684 	 * that's how yes votes are returned, go figure), otherwise
2685 	 * just print out the error code.
2686 	 */
2687 
2688 	else
2689 		switch (opcode) {
2690 		case 10000:		/* Beacon */
2691 			ND_PRINT((ndo, " vote yes until"));
2692 			DATEOUT();
2693 			break;
2694 		default:
2695 			ND_PRINT((ndo, " errcode"));
2696 			INTOUT();
2697 		}
2698 
2699 	return;
2700 
2701 trunc:
2702 	ND_PRINT((ndo, " [|ubik]"));
2703 }
2704 
2705 /*
2706  * Handle RX ACK packets.
2707  */
2708 
2709 static void
2710 rx_ack_print(netdissect_options *ndo,
2711              register const u_char *bp, int length)
2712 {
2713 	const struct rx_ackPacket *rxa;
2714 	int i, start, last;
2715 	uint32_t firstPacket;
2716 
2717 	if (length < (int)sizeof(struct rx_header))
2718 		return;
2719 
2720 	bp += sizeof(struct rx_header);
2721 
2722 	/*
2723 	 * This may seem a little odd .... the rx_ackPacket structure
2724 	 * contains an array of individual packet acknowledgements
2725 	 * (used for selective ack/nack), but since it's variable in size,
2726 	 * we don't want to truncate based on the size of the whole
2727 	 * rx_ackPacket structure.
2728 	 */
2729 
2730 	ND_TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS);
2731 
2732 	rxa = (const struct rx_ackPacket *) bp;
2733 	bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS);
2734 
2735 	/*
2736 	 * Print out a few useful things from the ack packet structure
2737 	 */
2738 
2739 	if (ndo->ndo_vflag > 2)
2740 		ND_PRINT((ndo, " bufspace %d maxskew %d",
2741 		       (int) EXTRACT_16BITS(&rxa->bufferSpace),
2742 		       (int) EXTRACT_16BITS(&rxa->maxSkew)));
2743 
2744 	firstPacket = EXTRACT_32BITS(&rxa->firstPacket);
2745 	ND_PRINT((ndo, " first %d serial %d reason %s",
2746 	       firstPacket, EXTRACT_32BITS(&rxa->serial),
2747 	       tok2str(rx_ack_reasons, "#%d", (int) rxa->reason)));
2748 
2749 	/*
2750 	 * Okay, now we print out the ack array.  The way _this_ works
2751 	 * is that we start at "first", and step through the ack array.
2752 	 * If we have a contiguous range of acks/nacks, try to
2753 	 * collapse them into a range.
2754 	 *
2755 	 * If you're really clever, you might have noticed that this
2756 	 * doesn't seem quite correct.  Specifically, due to structure
2757 	 * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually
2758 	 * yield the start of the ack array (because RX_MAXACKS is 255
2759 	 * and the structure will likely get padded to a 2 or 4 byte
2760 	 * boundary).  However, this is the way it's implemented inside
2761 	 * of AFS - the start of the extra fields are at
2762 	 * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_
2763 	 * the exact start of the ack array.  Sigh.  That's why we aren't
2764 	 * using bp, but instead use rxa->acks[].  But nAcks gets added
2765 	 * to bp after this, so bp ends up at the right spot.  Go figure.
2766 	 */
2767 
2768 	if (rxa->nAcks != 0) {
2769 
2770 		ND_TCHECK2(bp[0], rxa->nAcks);
2771 
2772 		/*
2773 		 * Sigh, this is gross, but it seems to work to collapse
2774 		 * ranges correctly.
2775 		 */
2776 
2777 		for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2778 			if (rxa->acks[i] == RX_ACK_TYPE_ACK) {
2779 
2780 				/*
2781 				 * I figured this deserved _some_ explanation.
2782 				 * First, print "acked" and the packet seq
2783 				 * number if this is the first time we've
2784 				 * seen an acked packet.
2785 				 */
2786 
2787 				if (last == -2) {
2788 					ND_PRINT((ndo, " acked %d", firstPacket + i));
2789 					start = i;
2790 				}
2791 
2792 				/*
2793 				 * Otherwise, if there is a skip in
2794 				 * the range (such as an nacked packet in
2795 				 * the middle of some acked packets),
2796 				 * then print the current packet number
2797 				 * seperated from the last number by
2798 				 * a comma.
2799 				 */
2800 
2801 				else if (last != i - 1) {
2802 					ND_PRINT((ndo, ",%d", firstPacket + i));
2803 					start = i;
2804 				}
2805 
2806 				/*
2807 				 * We always set last to the value of
2808 				 * the last ack we saw.  Conversely, start
2809 				 * is set to the value of the first ack
2810 				 * we saw in a range.
2811 				 */
2812 
2813 				last = i;
2814 
2815 				/*
2816 				 * Okay, this bit a code gets executed when
2817 				 * we hit a nack ... in _this_ case we
2818 				 * want to print out the range of packets
2819 				 * that were acked, so we need to print
2820 				 * the _previous_ packet number seperated
2821 				 * from the first by a dash (-).  Since we
2822 				 * already printed the first packet above,
2823 				 * just print the final packet.  Don't
2824 				 * do this if there will be a single-length
2825 				 * range.
2826 				 */
2827 			} else if (last == i - 1 && start != last)
2828 				ND_PRINT((ndo, "-%d", firstPacket + i - 1));
2829 
2830 		/*
2831 		 * So, what's going on here?  We ran off the end of the
2832 		 * ack list, and if we got a range we need to finish it up.
2833 		 * So we need to determine if the last packet in the list
2834 		 * was an ack (if so, then last will be set to it) and
2835 		 * we need to see if the last range didn't start with the
2836 		 * last packet (because if it _did_, then that would mean
2837 		 * that the packet number has already been printed and
2838 		 * we don't need to print it again).
2839 		 */
2840 
2841 		if (last == i - 1 && start != last)
2842 			ND_PRINT((ndo, "-%d", firstPacket + i - 1));
2843 
2844 		/*
2845 		 * Same as above, just without comments
2846 		 */
2847 
2848 		for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2849 			if (rxa->acks[i] == RX_ACK_TYPE_NACK) {
2850 				if (last == -2) {
2851 					ND_PRINT((ndo, " nacked %d", firstPacket + i));
2852 					start = i;
2853 				} else if (last != i - 1) {
2854 					ND_PRINT((ndo, ",%d", firstPacket + i));
2855 					start = i;
2856 				}
2857 				last = i;
2858 			} else if (last == i - 1 && start != last)
2859 				ND_PRINT((ndo, "-%d", firstPacket + i - 1));
2860 
2861 		if (last == i - 1 && start != last)
2862 			ND_PRINT((ndo, "-%d", firstPacket + i - 1));
2863 
2864 		bp += rxa->nAcks;
2865 	}
2866 
2867 
2868 	/*
2869 	 * These are optional fields; depending on your version of AFS,
2870 	 * you may or may not see them
2871 	 */
2872 
2873 #define TRUNCRET(n)	if (ndo->ndo_snapend - bp + 1 <= n) return;
2874 
2875 	if (ndo->ndo_vflag > 1) {
2876 		TRUNCRET(4);
2877 		ND_PRINT((ndo, " ifmtu"));
2878 		INTOUT();
2879 
2880 		TRUNCRET(4);
2881 		ND_PRINT((ndo, " maxmtu"));
2882 		INTOUT();
2883 
2884 		TRUNCRET(4);
2885 		ND_PRINT((ndo, " rwind"));
2886 		INTOUT();
2887 
2888 		TRUNCRET(4);
2889 		ND_PRINT((ndo, " maxpackets"));
2890 		INTOUT();
2891 	}
2892 
2893 	return;
2894 
2895 trunc:
2896 	ND_PRINT((ndo, " [|ack]"));
2897 }
2898 #undef TRUNCRET
2899