print-rx.c revision 80231
1191762Simp/*
2191762Simp * This code unmangles RX packets.  RX is the mutant form of RPC that AFS
3191762Simp * uses to communicate between clients and servers.
4191762Simp *
5191762Simp * In this code, I mainly concern myself with decoding the AFS calls, not
6191762Simp * with the guts of RX, per se.
7191762Simp *
8191762Simp * Bah.  If I never look at rx_packet.h again, it will be too soon.
9191762Simp *
10191762Simp * Ken Hornstein <kenh@cmf.nrl.navy.mil>
11191762Simp *
12191762Simp */
13191762Simp
14191762Simp#ifndef lint
15191762Simpstatic const char rcsid[] =
16191762Simp    "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.20.2.1 2001/07/09 01:40:59 fenner Exp $";
17191762Simp#endif
18191762Simp
19191762Simp#ifdef HAVE_CONFIG_H
20191762Simp#include "config.h"
21191762Simp#endif
22191762Simp
23191762Simp#include <stdio.h>
24191762Simp#include <stdlib.h>
25191762Simp#include <string.h>
26191762Simp#include <time.h>
27191762Simp#include <sys/param.h>
28191762Simp#include <sys/time.h>
29191762Simp#include <sys/types.h>
30191762Simp#include <sys/socket.h>
31191762Simp#include <netinet/in.h>
32191762Simp#include <arpa/inet.h>
33191762Simp
34191762Simp#include "interface.h"
35191762Simp#include "addrtoname.h"
36191762Simp#include "extract.h"
37191762Simp
38191762Simp#undef NOERROR					/* Solaris sucks */
39191762Simp#include <arpa/nameser.h>
40191762Simp
41191762Simp#include "rx.h"
42191762Simp
43191762Simp#include "ip.h"
44191762Simp
45191762Simpstatic struct tok rx_types[] = {
46191762Simp	{ RX_PACKET_TYPE_DATA,		"data" },
47191762Simp	{ RX_PACKET_TYPE_ACK,		"ack" },
48191762Simp	{ RX_PACKET_TYPE_BUSY,		"busy" },
49191762Simp	{ RX_PACKET_TYPE_ABORT,		"abort" },
50191762Simp	{ RX_PACKET_TYPE_ACKALL,	"ackall" },
51191762Simp	{ RX_PACKET_TYPE_CHALLENGE,	"challenge" },
52191762Simp	{ RX_PACKET_TYPE_RESPONSE,	"response" },
53191762Simp	{ RX_PACKET_TYPE_DEBUG,		"debug" },
54191762Simp	{ RX_PACKET_TYPE_PARAMS,	"params" },
55191762Simp	{ RX_PACKET_TYPE_VERSION,	"version" },
56191762Simp	{ 0,				NULL },
57191762Simp};
58191762Simp
59191762Simpstatic struct tok rx_flags[] = {
60191762Simp	{ RX_CLIENT_INITIATED,	"client-init" },
61191762Simp	{ RX_REQUEST_ACK,	"req-ack" },
62191762Simp	{ RX_LAST_PACKET,	"last-pckt" },
63191762Simp	{ RX_MORE_PACKETS,	"more-pckts" },
64191762Simp	{ RX_FREE_PACKET,	"free-pckt" }
65191762Simp};
66191762Simp
67191762Simpstatic struct tok fs_req[] = {
68191762Simp	{ 130,		"fetch-data" },
69191762Simp	{ 131,		"fetch-acl" },
70191762Simp	{ 132,		"fetch-status" },
71191762Simp	{ 133,		"store-data" },
72191762Simp	{ 134,		"store-acl" },
73191762Simp	{ 135,		"store-status" },
74191762Simp	{ 136,		"remove-file" },
75191762Simp	{ 137,		"create-file" },
76191762Simp	{ 138,		"rename" },
77191762Simp	{ 139,		"symlink" },
78191762Simp	{ 140,		"link" },
79191762Simp	{ 141,		"makedir" },
80191762Simp	{ 142,		"rmdir" },
81191762Simp	{ 143,		"oldsetlock" },
82191762Simp	{ 144,		"oldextlock" },
83191762Simp	{ 145,		"oldrellock" },
84191762Simp	{ 146,		"get-stats" },
85191762Simp	{ 147,		"give-cbs" },
86191762Simp	{ 148,		"get-vlinfo" },
87191762Simp	{ 149,		"get-vlstats" },
88191762Simp	{ 150,		"set-vlstats" },
89191762Simp	{ 151,		"get-rootvl" },
90191762Simp	{ 152,		"check-token" },
91191762Simp	{ 153,		"get-time" },
92191762Simp	{ 154,		"nget-vlinfo" },
93191762Simp	{ 155,		"bulk-stat" },
94191762Simp	{ 156,		"setlock" },
95191762Simp	{ 157,		"extlock" },
96191762Simp	{ 158,		"rellock" },
97191762Simp	{ 159,		"xstat-ver" },
98191762Simp	{ 160,		"get-xstat" },
99191762Simp	{ 161,		"dfs-lookup" },
100191762Simp	{ 162,		"dfs-flushcps" },
101191762Simp	{ 163,		"dfs-symlink" },
102191762Simp	{ 0,		NULL },
103191762Simp};
104191762Simp
105191762Simpstatic struct tok cb_req[] = {
106191762Simp	{ 204,		"callback" },
107191762Simp	{ 205,		"initcb" },
108191762Simp	{ 206,		"probe" },
109191762Simp	{ 207,		"getlock" },
110191762Simp	{ 208,		"getce" },
111191762Simp	{ 209,		"xstatver" },
112191762Simp	{ 210,		"getxstat" },
113191762Simp	{ 211,		"initcb2" },
114191762Simp	{ 212,		"whoareyou" },
115191762Simp	{ 213,		"initcb3" },
116191762Simp	{ 214,		"probeuuid" },
117191762Simp	{ 0,		NULL },
118191762Simp};
119191762Simp
120191762Simpstatic struct tok pt_req[] = {
121191762Simp	{ 500,		"new-user" },
122191762Simp	{ 501,		"where-is-it" },
123191762Simp	{ 502,		"dump-entry" },
124191762Simp	{ 503,		"add-to-group" },
125191762Simp	{ 504,		"name-to-id" },
126191762Simp	{ 505,		"id-to-name" },
127191762Simp	{ 506,		"delete" },
128191762Simp	{ 507,		"remove-from-group" },
129191762Simp	{ 508,		"get-cps" },
130191762Simp	{ 509,		"new-entry" },
131191762Simp	{ 510,		"list-max" },
132191762Simp	{ 511,		"set-max" },
133191762Simp	{ 512,		"list-entry" },
134191762Simp	{ 513,		"change-entry" },
135191762Simp	{ 514,		"list-elements" },
136191762Simp	{ 515,		"same-mbr-of" },
137191762Simp	{ 516,		"set-fld-sentry" },
138191762Simp	{ 517,		"list-owned" },
139191762Simp	{ 518,		"get-cps2" },
140191762Simp	{ 519,		"get-host-cps" },
141191762Simp	{ 520,		"update-entry" },
142191762Simp	{ 0,		NULL },
143191762Simp};
144191762Simp
145191762Simpstatic struct tok vldb_req[] = {
146191762Simp	{ 501,		"create-entry" },
147191762Simp	{ 502,		"delete-entry" },
148191762Simp	{ 503,		"get-entry-by-id" },
149191762Simp	{ 504,		"get-entry-by-name" },
150191762Simp	{ 505,		"get-new-volume-id" },
151191762Simp	{ 506,		"replace-entry" },
152191762Simp	{ 507,		"update-entry" },
153191762Simp	{ 508,		"setlock" },
154191762Simp	{ 509,		"releaselock" },
155191762Simp	{ 510,		"list-entry" },
156191762Simp	{ 511,		"list-attrib" },
157191762Simp	{ 512,		"linked-list" },
158191762Simp	{ 513,		"get-stats" },
159191762Simp	{ 514,		"probe" },
160191762Simp	{ 515,		"get-addrs" },
161191762Simp	{ 516,		"change-addr" },
162191762Simp	{ 517,		"create-entry-n" },
163191762Simp	{ 518,		"get-entry-by-id-n" },
164191762Simp	{ 519,		"get-entry-by-name-n" },
165191762Simp	{ 520,		"replace-entry-n" },
166191762Simp	{ 521,		"list-entry-n" },
167191762Simp	{ 522,		"list-attrib-n" },
168191762Simp	{ 523,		"linked-list-n" },
169191762Simp	{ 524,		"update-entry-by-name" },
170191762Simp	{ 525,		"create-entry-u" },
171191762Simp	{ 526,		"get-entry-by-id-u" },
172191762Simp	{ 527,		"get-entry-by-name-u" },
173191762Simp	{ 528,		"replace-entry-u" },
174191762Simp	{ 529,		"list-entry-u" },
175191762Simp	{ 530,		"list-attrib-u" },
176191762Simp	{ 531,		"linked-list-u" },
177191762Simp	{ 532,		"regaddr" },
178191762Simp	{ 533,		"get-addrs-u" },
179191762Simp	{ 0,		NULL },
180191762Simp};
181191762Simp
182191762Simpstatic struct tok kauth_req[] = {
183191762Simp	{ 1,		"auth-old" },
184191762Simp	{ 21,		"authenticate" },
185191762Simp	{ 22,		"authenticate-v2" },
186191762Simp	{ 2,		"change-pw" },
187191762Simp	{ 3,		"get-ticket-old" },
188191762Simp	{ 23,		"get-ticket" },
189191762Simp	{ 4,		"set-pw" },
190191762Simp	{ 5,		"set-fields" },
191191762Simp	{ 6,		"create-user" },
192191762Simp	{ 7,		"delete-user" },
193191762Simp	{ 8,		"get-entry" },
194191762Simp	{ 9,		"list-entry" },
195191762Simp	{ 10,		"get-stats" },
196191762Simp	{ 11,		"debug" },
197191762Simp	{ 12,		"get-pw" },
198191762Simp	{ 13,		"get-random-key" },
199191762Simp	{ 14,		"unlock" },
200191762Simp	{ 15,		"lock-status" },
201191762Simp	{ 0,		NULL },
202191762Simp};
203191762Simp
204191762Simpstatic struct tok vol_req[] = {
205191762Simp	{ 100,		"create-volume" },
206191762Simp	{ 101,		"delete-volume" },
207191762Simp	{ 102,		"restore" },
208191762Simp	{ 103,		"forward" },
209191762Simp	{ 104,		"end-trans" },
210191762Simp	{ 105,		"clone" },
211191762Simp	{ 106,		"set-flags" },
212191762Simp	{ 107,		"get-flags" },
213191762Simp	{ 108,		"trans-create" },
214191762Simp	{ 109,		"dump" },
215191762Simp	{ 110,		"get-nth-volume" },
216191762Simp	{ 111,		"set-forwarding" },
217191762Simp	{ 112,		"get-name" },
218191762Simp	{ 113,		"get-status" },
219191762Simp	{ 114,		"sig-restore" },
220191762Simp	{ 115,		"list-partitions" },
221191762Simp	{ 116,		"list-volumes" },
222191762Simp	{ 117,		"set-id-types" },
223191762Simp	{ 118,		"monitor" },
224191762Simp	{ 119,		"partition-info" },
225191762Simp	{ 120,		"reclone" },
226191762Simp	{ 121,		"list-one-volume" },
227191762Simp	{ 122,		"nuke" },
228191762Simp	{ 123,		"set-date" },
229191762Simp	{ 124,		"x-list-volumes" },
230191762Simp	{ 125,		"x-list-one-volume" },
231191762Simp	{ 126,		"set-info" },
232191762Simp	{ 127,		"x-list-partitions" },
233191762Simp	{ 128,		"forward-multiple" },
234191762Simp	{ 0,		NULL },
235191762Simp};
236191762Simp
237191762Simpstatic struct tok bos_req[] = {
238191762Simp	{ 80,		"create-bnode" },
239191762Simp	{ 81,		"delete-bnode" },
240191762Simp	{ 82,		"set-status" },
241191762Simp	{ 83,		"get-status" },
242191762Simp	{ 84,		"enumerate-instance" },
243191762Simp	{ 85,		"get-instance-info" },
244191762Simp	{ 86,		"get-instance-parm" },
245191762Simp	{ 87,		"add-superuser" },
246191762Simp	{ 88,		"delete-superuser" },
247191762Simp	{ 89,		"list-superusers" },
248191762Simp	{ 90,		"list-keys" },
249191762Simp	{ 91,		"add-key" },
250191762Simp	{ 92,		"delete-key" },
251191762Simp	{ 93,		"set-cell-name" },
252191762Simp	{ 94,		"get-cell-name" },
253191762Simp	{ 95,		"get-cell-host" },
254191762Simp	{ 96,		"add-cell-host" },
255191762Simp	{ 97,		"delete-cell-host" },
256191762Simp	{ 98,		"set-t-status" },
257191762Simp	{ 99,		"shutdown-all" },
258191762Simp	{ 100,		"restart-all" },
259191762Simp	{ 101,		"startup-all" },
260191762Simp	{ 102,		"set-noauth-flag" },
261191762Simp	{ 103,		"re-bozo" },
262191762Simp	{ 104,		"restart" },
263191762Simp	{ 105,		"start-bozo-install" },
264191762Simp	{ 106,		"uninstall" },
265191762Simp	{ 107,		"get-dates" },
266191762Simp	{ 108,		"exec" },
267191762Simp	{ 109,		"prune" },
268191762Simp	{ 110,		"set-restart-time" },
269191762Simp	{ 111,		"get-restart-time" },
270191762Simp	{ 112,		"start-bozo-log" },
271191762Simp	{ 113,		"wait-all" },
272191762Simp	{ 114,		"get-instance-strings" },
273191762Simp	{ 0,		NULL },
274191762Simp};
275191762Simp
276191762Simpstatic struct tok ubik_req[] = {
277191762Simp	{ 10000,	"vote-beacon" },
278191762Simp	{ 10001,	"vote-debug-old" },
279191762Simp	{ 10002,	"vote-sdebug-old" },
280191762Simp	{ 10003,	"vote-getsyncsite" },
281191762Simp	{ 10004,	"vote-debug" },
282191762Simp	{ 10005,	"vote-sdebug" },
283191762Simp	{ 20000,	"disk-begin" },
284191762Simp	{ 20001,	"disk-commit" },
285191762Simp	{ 20002,	"disk-lock" },
286191762Simp	{ 20003,	"disk-write" },
287191762Simp	{ 20004,	"disk-getversion" },
288191762Simp	{ 20005,	"disk-getfile" },
289191762Simp	{ 20006,	"disk-sendfile" },
290191762Simp	{ 20007,	"disk-abort" },
291191762Simp	{ 20008,	"disk-releaselocks" },
292191762Simp	{ 20009,	"disk-truncate" },
293191762Simp	{ 20010,	"disk-probe" },
294191762Simp	{ 20011,	"disk-writev" },
295191762Simp	{ 20012,	"disk-interfaceaddr" },
296191762Simp	{ 20013,	"disk-setversion" },
297191762Simp	{ 0,		NULL },
298191762Simp};
299191762Simp
300191762Simp#define VOTE_LOW	10000
301191762Simp#define VOTE_HIGH	10005
302191762Simp#define DISK_LOW	20000
303191762Simp#define DISK_HIGH	20013
304191762Simp
305191762Simpstatic struct tok cb_types[] = {
306191762Simp	{ 1,		"exclusive" },
307191762Simp	{ 2,		"shared" },
308191762Simp	{ 3,		"dropped" },
309191762Simp	{ 0,		NULL },
310191762Simp};
311191762Simp
312191762Simpstatic struct tok ubik_lock_types[] = {
313191762Simp	{ 1,		"read" },
314191762Simp	{ 2,		"write" },
315191762Simp	{ 3,		"wait" },
316191762Simp	{ 0,		NULL },
317191762Simp};
318191762Simp
319191762Simpstatic char *voltype[] = { "read-write", "read-only", "backup" };
320191762Simp
321191762Simpstatic struct tok afs_fs_errors[] = {
322191762Simp	{ 101,		"salvage volume" },
323191762Simp	{ 102, 		"no such vnode" },
324191762Simp	{ 103, 		"no such volume" },
325191762Simp	{ 104, 		"volume exist" },
326191762Simp	{ 105, 		"no service" },
327191762Simp	{ 106, 		"volume offline" },
328191762Simp	{ 107, 		"voline online" },
329191762Simp	{ 108, 		"diskfull" },
330191762Simp	{ 109, 		"diskquota exceeded" },
331191762Simp	{ 110, 		"volume busy" },
332191762Simp	{ 111, 		"volume moved" },
333191762Simp	{ 112, 		"AFS IO error" },
334191762Simp	{ -100,		"restarting fileserver" },
335191762Simp	{ 0,		NULL }
336191762Simp};
337191762Simp
338191762Simp/*
339191762Simp * Reasons for acknowledging a packet
340191762Simp */
341191762Simp
342191762Simpstatic struct tok rx_ack_reasons[] = {
343191762Simp	{ 1,		"ack requested" },
344191762Simp	{ 2,		"duplicate packet" },
345191762Simp	{ 3,		"out of sequence" },
346191762Simp	{ 4,		"exceeds window" },
347191762Simp	{ 5,		"no buffer space" },
348191762Simp	{ 6,		"ping" },
349191762Simp	{ 7,		"ping response" },
350191762Simp	{ 8,		"delay" },
351191762Simp	{ 0,		NULL },
352191762Simp};
353191762Simp
354191762Simp/*
355191762Simp * Cache entries we keep around so we can figure out the RX opcode
356191762Simp * numbers for replies.  This allows us to make sense of RX reply packets.
357191762Simp */
358191762Simp
359191762Simpstruct rx_cache_entry {
360191762Simp	u_int32_t	callnum;	/* Call number (net order) */
361191762Simp	struct in_addr	client;		/* client IP address (net order) */
362191762Simp	struct in_addr	server;		/* server IP address (net order) */
363191762Simp	int		dport;		/* server port (host order) */
364191762Simp	u_short		serviceId;	/* Service identifier (net order) */
365191762Simp	u_int32_t	opcode;		/* RX opcode (host order) */
366191762Simp};
367191762Simp
368191762Simp#define RX_CACHE_SIZE	64
369191762Simp
370191762Simpstatic struct rx_cache_entry	rx_cache[RX_CACHE_SIZE];
371191762Simp
372191762Simpstatic int	rx_cache_next = 0;
373191762Simpstatic int	rx_cache_hint = 0;
374191762Simpstatic void	rx_cache_insert(const u_char *, const struct ip *, int, int);
375191762Simpstatic int	rx_cache_find(const struct rx_header *, const struct ip *,
376191762Simp			      int, int32_t *);
377191762Simp
378192306Simpstatic void ack_print(const u_char *, int);
379191762Simpstatic void fs_print(const u_char *, int);
380191762Simpstatic void fs_reply_print(const u_char *, int, int32_t);
381191762Simpstatic void acl_print(u_char *, int, u_char *);
382191762Simpstatic void cb_print(const u_char *, int);
383191762Simpstatic void cb_reply_print(const u_char *, int, int32_t);
384191762Simpstatic void prot_print(const u_char *, int);
385191762Simpstatic void prot_reply_print(const u_char *, int, int32_t);
386191762Simpstatic void vldb_print(const u_char *, int);
387191762Simpstatic void vldb_reply_print(const u_char *, int, int32_t);
388191762Simpstatic void kauth_print(const u_char *, int);
389191762Simpstatic void kauth_reply_print(const u_char *, int, int32_t);
390191762Simpstatic void vol_print(const u_char *, int);
391191762Simpstatic void vol_reply_print(const u_char *, int, int32_t);
392191762Simpstatic void bos_print(const u_char *, int);
393191762Simpstatic void bos_reply_print(const u_char *, int, int32_t);
394191762Simpstatic void ubik_print(const u_char *, int);
395191762Simpstatic void ubik_reply_print(const u_char *, int, int32_t);
396191762Simp
397191762Simpstatic void rx_ack_print(const u_char *, int);
398191762Simp
399191762Simpstatic int is_ubik(u_int32_t);
400191762Simp
401191762Simp/*
402191762Simp * Handle the rx-level packet.  See if we know what port it's going to so
403191762Simp * we can peek at the afs call inside
404191762Simp */
405191762Simp
406191762Simpvoid
407191762Simprx_print(register const u_char *bp, int length, int sport, int dport,
408191762Simp	 u_char *bp2)
409191762Simp{
410191762Simp	register struct rx_header *rxh;
411191762Simp	int i;
412191762Simp	int32_t opcode;
413191762Simp
414191762Simp	if (snapend - bp < sizeof (struct rx_header)) {
415191762Simp		printf(" [|rx] (%d)", length);
416191762Simp		return;
417191762Simp	}
418191762Simp
419191762Simp	rxh = (struct rx_header *) bp;
420191762Simp
421191762Simp	printf(" rx %s", tok2str(rx_types, "type %d", rxh->type));
422191762Simp
423191762Simp	if (vflag) {
424191762Simp		int firstflag = 0;
425191762Simp
426191762Simp		if (vflag > 1)
427191762Simp			printf(" cid %08x call# %d",
428191762Simp			       (int) EXTRACT_32BITS(&rxh->cid),
429191762Simp			       (int) EXTRACT_32BITS(&rxh->callNumber));
430191762Simp
431191762Simp		printf(" seq %d ser %d",
432191762Simp		       (int) EXTRACT_32BITS(&rxh->seq),
433191762Simp		       (int) EXTRACT_32BITS(&rxh->serial));
434191762Simp
435191762Simp		if (vflag > 2)
436191762Simp			printf(" secindex %d serviceid %hu",
437191762Simp				(int) rxh->securityIndex,
438191762Simp				EXTRACT_16BITS(&rxh->serviceId));
439191762Simp
440191762Simp		if (vflag > 1)
441191762Simp			for (i = 0; i < NUM_RX_FLAGS; i++) {
442191762Simp				if (rxh->flags & rx_flags[i].v) {
443191762Simp					if (!firstflag) {
444191762Simp						firstflag = 1;
445191762Simp						printf(" ");
446191762Simp					} else {
447191762Simp						printf(",");
448191762Simp					}
449191762Simp					printf("<%s>", rx_flags[i].s);
450191762Simp				}
451191762Simp			}
452191762Simp	}
453191762Simp
454191762Simp	/*
455191762Simp	 * Try to handle AFS calls that we know about.  Check the destination
456191762Simp	 * port and make sure it's a data packet.  Also, make sure the
457191762Simp	 * seq number is 1 (because otherwise it's a continuation packet,
458191762Simp	 * and we can't interpret that).  Also, seems that reply packets
459191762Simp	 * do not have the client-init flag set, so we check for that
460191762Simp	 * as well.
461191762Simp	 */
462191762Simp
463191762Simp 	if (rxh->type == RX_PACKET_TYPE_ACK)
464191762Simp 	    ack_print(bp, length);
465191762Simp	else if (rxh->type == RX_PACKET_TYPE_DATA &&
466191762Simp	    EXTRACT_32BITS(&rxh->seq) == 1 &&
467191762Simp	    rxh->flags & RX_CLIENT_INITIATED) {
468191762Simp
469191762Simp		/*
470191762Simp		 * Insert this call into the call cache table, so we
471191762Simp		 * have a chance to print out replies
472191762Simp		 */
473191762Simp
474191762Simp		rx_cache_insert(bp, (const struct ip *) bp2, dport, length);
475191762Simp
476191762Simp		switch (dport) {
477191762Simp			case FS_RX_PORT:	/* AFS file service */
478191762Simp				fs_print(bp, length);
479191762Simp				break;
480191762Simp			case CB_RX_PORT:	/* AFS callback service */
481191762Simp				cb_print(bp, length);
482191762Simp				break;
483191762Simp			case PROT_RX_PORT:	/* AFS protection service */
484191762Simp				prot_print(bp, length);
485191762Simp				break;
486191762Simp			case VLDB_RX_PORT:	/* AFS VLDB service */
487191762Simp				vldb_print(bp, length);
488191762Simp				break;
489191762Simp			case KAUTH_RX_PORT:	/* AFS Kerberos auth service */
490191762Simp				kauth_print(bp, length);
491191762Simp				break;
492191762Simp			case VOL_RX_PORT:	/* AFS Volume service */
493191762Simp				vol_print(bp, length);
494191762Simp				break;
495191762Simp			case BOS_RX_PORT:	/* AFS BOS service */
496191762Simp				bos_print(bp, length);
497191762Simp				break;
498191762Simp			default:
499191762Simp				;
500191762Simp		}
501191762Simp
502191762Simp	/*
503191762Simp	 * If it's a reply (client-init is _not_ set, but seq is one)
504191762Simp	 * then look it up in the cache.  If we find it, call the reply
505191762Simp	 * printing functions  Note that we handle abort packets here,
506191762Simp	 * because printing out the return code can be useful at times.
507191762Simp	 */
508191762Simp
509191762Simp	} else if (((rxh->type == RX_PACKET_TYPE_DATA &&
510191762Simp					EXTRACT_32BITS(&rxh->seq) == 1) ||
511191762Simp		    rxh->type == RX_PACKET_TYPE_ABORT) &&
512191762Simp		   (rxh->flags & RX_CLIENT_INITIATED) == 0 &&
513191762Simp		   rx_cache_find(rxh, (const struct ip *) bp2,
514191762Simp				 sport, &opcode)) {
515191762Simp
516191762Simp		switch (sport) {
517191762Simp			case FS_RX_PORT:	/* AFS file service */
518191762Simp				fs_reply_print(bp, length, opcode);
519191762Simp				break;
520191762Simp			case CB_RX_PORT:	/* AFS callback service */
521191762Simp				cb_reply_print(bp, length, opcode);
522191762Simp				break;
523191762Simp			case PROT_RX_PORT:	/* AFS PT service */
524191762Simp				prot_reply_print(bp, length, opcode);
525191762Simp				break;
526191762Simp			case VLDB_RX_PORT:	/* AFS VLDB service */
527191762Simp				vldb_reply_print(bp, length, opcode);
528191762Simp				break;
529191762Simp			case KAUTH_RX_PORT:	/* AFS Kerberos auth service */
530191762Simp				kauth_reply_print(bp, length, opcode);
531191762Simp				break;
532191762Simp			case VOL_RX_PORT:	/* AFS Volume service */
533191762Simp				vol_reply_print(bp, length, opcode);
534191762Simp				break;
535191762Simp			case BOS_RX_PORT:	/* AFS BOS service */
536191762Simp				bos_reply_print(bp, length, opcode);
537191762Simp				break;
538191762Simp			default:
539191762Simp				;
540191762Simp		}
541191762Simp
542191762Simp	/*
543191762Simp	 * If it's an RX ack packet, then use the appropriate ack decoding
544191762Simp	 * function (there isn't any service-specific information in the
545191762Simp	 * ack packet, so we can use one for all AFS services)
546191762Simp	 */
547191762Simp
548191762Simp	} else if (rxh->type == RX_PACKET_TYPE_ACK)
549191762Simp		rx_ack_print(bp, length);
550191762Simp
551191762Simp
552191762Simp	printf(" (%d)", length);
553191762Simp}
554191762Simp
555191762Simp/*
556191762Simp * Insert an entry into the cache.  Taken from print-nfs.c
557191762Simp */
558191762Simp
559191762Simpstatic void
560191762Simprx_cache_insert(const u_char *bp, const struct ip *ip, int dport,
561191762Simp		int length)
562191762Simp{
563191762Simp	struct rx_cache_entry *rxent;
564191762Simp	const struct rx_header *rxh = (const struct rx_header *) bp;
565191762Simp
566191762Simp	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t))
567191762Simp		return;
568191762Simp
569191762Simp	rxent = &rx_cache[rx_cache_next];
570191762Simp
571191762Simp	if (++rx_cache_next >= RX_CACHE_SIZE)
572191762Simp		rx_cache_next = 0;
573191762Simp
574191762Simp	rxent->callnum = rxh->callNumber;
575191762Simp	rxent->client = ip->ip_src;
576191762Simp	rxent->server = ip->ip_dst;
577191762Simp	rxent->dport = dport;
578191762Simp	rxent->serviceId = rxh->serviceId;
579191762Simp	rxent->opcode = EXTRACT_32BITS(bp + sizeof(struct rx_header));
580191762Simp}
581191762Simp
582191762Simp/*
583191762Simp * Lookup an entry in the cache.  Also taken from print-nfs.c
584191762Simp *
585191762Simp * Note that because this is a reply, we're looking at the _source_
586191762Simp * port.
587191762Simp */
588191762Simp
589191762Simpstatic int
590191762Simprx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport,
591191762Simp	      int32_t *opcode)
592191762Simp{
593191762Simp	int i;
594191762Simp	struct rx_cache_entry *rxent;
595191762Simp	u_int32_t clip = ip->ip_dst.s_addr;
596191762Simp	u_int32_t sip = ip->ip_src.s_addr;
597191762Simp
598191762Simp	/* Start the search where we last left off */
599191762Simp
600191762Simp	i = rx_cache_hint;
601191762Simp	do {
602191762Simp		rxent = &rx_cache[i];
603191762Simp		if (rxent->callnum == rxh->callNumber &&
604191762Simp		    rxent->client.s_addr == clip &&
605191762Simp		    rxent->server.s_addr == sip &&
606191762Simp		    rxent->serviceId == rxh->serviceId &&
607191762Simp		    rxent->dport == sport) {
608191762Simp
609191762Simp			/* We got a match! */
610191762Simp
611191762Simp			rx_cache_hint = i;
612191762Simp			*opcode = rxent->opcode;
613191762Simp			return(1);
614191762Simp		}
615191762Simp		if (++i > RX_CACHE_SIZE)
616191762Simp			i = 0;
617191762Simp	} while (i != rx_cache_hint);
618191762Simp
619191762Simp	/* Our search failed */
620191762Simp	return(0);
621191762Simp}
622191762Simp
623191762Simp/*
624191762Simp * These extrememly grody macros handle the printing of various AFS stuff.
625191762Simp */
626191762Simp
627191762Simp#define FIDOUT() { unsigned long n1, n2, n3; \
628191762Simp			TCHECK2(bp[0], sizeof(int32_t) * 3); \
629191762Simp			n1 = EXTRACT_32BITS(bp); \
630191762Simp			bp += sizeof(int32_t); \
631191762Simp			n2 = EXTRACT_32BITS(bp); \
632191762Simp			bp += sizeof(int32_t); \
633191762Simp			n3 = EXTRACT_32BITS(bp); \
634191762Simp			bp += sizeof(int32_t); \
635191762Simp			printf(" fid %d/%d/%d", (int) n1, (int) n2, (int) n3); \
636191762Simp		}
637191762Simp
638191762Simp#define STROUT(MAX) { unsigned int i; \
639191762Simp			TCHECK2(bp[0], sizeof(int32_t)); \
640191762Simp			i = EXTRACT_32BITS(bp); \
641191762Simp			if (i > MAX) \
642191762Simp				goto trunc; \
643191762Simp			bp += sizeof(int32_t); \
644191762Simp			printf(" \""); \
645191762Simp			if (fn_printn(bp, i, snapend)) \
646191762Simp				goto trunc; \
647191762Simp			printf("\""); \
648191762Simp			bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \
649191762Simp		}
650191762Simp
651191762Simp#define INTOUT() { int i; \
652191762Simp			TCHECK2(bp[0], sizeof(int32_t)); \
653191762Simp			i = (int) EXTRACT_32BITS(bp); \
654191762Simp			bp += sizeof(int32_t); \
655191762Simp			printf(" %d", i); \
656191762Simp		}
657191762Simp
658191762Simp#define UINTOUT() { unsigned long i; \
659191762Simp			TCHECK2(bp[0], sizeof(int32_t)); \
660191762Simp			i = EXTRACT_32BITS(bp); \
661191762Simp			bp += sizeof(int32_t); \
662191762Simp			printf(" %lu", i); \
663191762Simp		}
664191762Simp
665191762Simp#define DATEOUT() { time_t t; struct tm *tm; char str[256]; \
666191762Simp			TCHECK2(bp[0], sizeof(int32_t)); \
667192046Snwhitehorn			t = (time_t) EXTRACT_32BITS(bp); \
668192046Snwhitehorn			bp += sizeof(int32_t); \
669192042Snwhitehorn			tm = localtime(&t); \
670191762Simp			strftime(str, 256, "%Y/%m/%d %T", tm); \
671191762Simp			printf(" %s", str); \
672191762Simp		}
673191762Simp
674191762Simp#define STOREATTROUT() { unsigned long mask, i; \
675191762Simp			TCHECK2(bp[0], (sizeof(int32_t)*6)); \
676191762Simp			mask = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
677191762Simp			if (mask) printf (" StoreStatus"); \
678191762Simp  		        if (mask & 1) { printf(" date"); DATEOUT(); } \
679191762Simp			else bp += sizeof(int32_t); \
680191762Simp			i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
681191762Simp  		        if (mask & 2) printf(" owner %lu", i);  \
682191762Simp			i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
683191762Simp  		        if (mask & 4) printf(" group %lu", i); \
684191762Simp			i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
685191762Simp  		        if (mask & 8) printf(" mode %lo", i & 07777); \
686191762Simp			i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
687191762Simp  		        if (mask & 16) printf(" segsize %lu", i); \
688191762Simp			/* undocumented in 3.3 docu */ \
689191762Simp  		        if (mask & 1024) printf(" fsync");  \
690191762Simp		}
691191762Simp
692191762Simp#define UBIK_VERSIONOUT() {int32_t epoch; int32_t counter; \
693191762Simp			TCHECK2(bp[0], sizeof(int32_t) * 2); \
694191762Simp			epoch = EXTRACT_32BITS(bp); \
695191762Simp			bp += sizeof(int32_t); \
696191762Simp			counter = EXTRACT_32BITS(bp); \
697191762Simp			bp += sizeof(int32_t); \
698191762Simp			printf(" %d.%d", epoch, counter); \
699191762Simp		}
700191762Simp
701191762Simp#define AFSUUIDOUT() {u_int32_t temp; int i; \
702191762Simp			TCHECK2(bp[0], 11*sizeof(u_int32_t)); \
703191762Simp			temp = EXTRACT_32BITS(bp); \
704191762Simp			bp += sizeof(u_int32_t); \
705191762Simp			printf(" %08x", temp); \
706191762Simp			temp = EXTRACT_32BITS(bp); \
707191762Simp			bp += sizeof(u_int32_t); \
708191762Simp			printf("%04x", temp); \
709191762Simp			temp = EXTRACT_32BITS(bp); \
710191762Simp			bp += sizeof(u_int32_t); \
711191762Simp			printf("%04x", temp); \
712191762Simp			for (i = 0; i < 8; i++) { \
713191762Simp				temp = EXTRACT_32BITS(bp); \
714191762Simp				bp += sizeof(u_int32_t); \
715191762Simp				printf("%02x", (unsigned char) temp); \
716191762Simp			} \
717191762Simp		}
718191762Simp
719191762Simp/*
720191762Simp * This is the sickest one of all
721191762Simp */
722191762Simp
723191762Simp#define VECOUT(MAX) { char *sp; \
724191762Simp			int k; \
725191762Simp			TCHECK2(bp[0], MAX * sizeof(int32_t)); \
726191762Simp			sp = s; \
727191762Simp			for (k = 0; k < MAX; k++) { \
728191762Simp				*sp++ = (char) EXTRACT_32BITS(bp); \
729191762Simp				bp += sizeof(int32_t); \
730191762Simp			} \
731191762Simp			s[MAX] = '\0'; \
732191762Simp			printf(" \""); \
733191762Simp			fn_print(s, NULL); \
734191762Simp			printf("\""); \
735191762Simp		}
736191762Simp
737191762Simpstatic void
738191762Simpack_print(register const u_char *bp, int length)
739191762Simp{
740191762Simp        u_char nAcks;
741191762Simp	int i;
742191762Simp
743191762Simp	if (vflag <= 1)
744191762Simp	        return;
745191762Simp
746191762Simp 	if (length <= sizeof(struct rx_header))
747191762Simp		return;
748191762Simp
749191762Simp	bp += sizeof(struct rx_header);
750191762Simp
751191762Simp	/*
752191762Simp	 * Packets < firstPacket are implicitly acknowledged and may
753191762Simp	 * be discarded by the sender.
754191762Simp	 *
755191762Simp	 * Packets >= firstPacket+nAcks are implicitly NOT acknowledged.
756191762Simp	 *
757191762Simp	 * No packets with sequence numbers >= firstPacket should be
758191762Simp	 * discarded by the sender (they may thrown out at any time by
759191762Simp	 * the receiver)
760191762Simp	 */
761191762Simp#define RX_ACK_REASONS "RDOXSprn"
762191762Simp	/* Requested, Duplicate, Out_of_sequence, eXceeds_window, no_Space,
763191762Simp	 * Ping, ping_Response, No_{progress, particular_reason}.
764191762Simp	 */
765191762Simp#if 0
766191762Simp	struct rx_ackPacket {
767191762Simp	  u_short bufferSpace;	/* Skip! */
768191762Simp	  u_short maxSkew;	/* Skip! */
769191762Simp	  u_long  firstPacket;
770191762Simp	  u_long  previousPacket; /* Obsolete! */
771191762Simp	  u_long  serial;	/* Serial that prompted the ack, */
772191762Simp	  u_char  reason;	/* and the reason why. */
773191762Simp	  u_char  nAcks;
774191762Simp	  u_char  acks[RX_MAXACKS]; /* Selective acks (not a bitmap). */
775191762Simp	};
776191762Simp#endif
777191762Simp#define RX_ACK_TYPE_NACK 0
778191762Simp
779191762Simp	TCHECK2(bp[0], 8);	/* bufferSpace and maxSkew */
780191762Simp	bp += 4;
781191762Simp	printf(" fir %u", (unsigned)EXTRACT_32BITS(bp));
782191762Simp	bp += 4;
783191762Simp	TCHECK2(bp[0], 8);	/* previousPacket and serial */
784191762Simp	bp += 4;
785191762Simp	printf(" %u", (unsigned)EXTRACT_32BITS(bp));
786191762Simp	bp += 4;
787191762Simp	TCHECK2(bp[0], 1);
788191762Simp	printf("%c", RX_ACK_REASONS[(*bp - 1) & 07u]);
789191762Simp	bp += 1;		/* reason */
790191762Simp	TCHECK2(bp[0], 1);
791191762Simp	nAcks = *bp;
792191762Simp	bp += 1;		/* nAcks */
793191762Simp
794191762Simp	for (i = 0; i < nAcks; i++) {
795191762Simp	    TCHECK2(bp[0], 1);
796191762Simp	    putchar(*bp == RX_ACK_TYPE_NACK? '-' : '*');
797191762Simp	    bp += 1;
798191762Simp	}
799191762Simp
800191762Simp	return;
801191762Simp
802191762Simptrunc:
803191762Simp	printf(" [|ack]");
804191762Simp}
805191762Simp
806191762Simp/*
807191762Simp * Handle calls to the AFS file service (fs)
808191762Simp */
809191762Simp
810191762Simpstatic void
811191762Simpfs_print(register const u_char *bp, int length)
812191762Simp{
813191762Simp	int fs_op;
814191762Simp	unsigned long i;
815191762Simp	char s[AFSNAMEMAX];
816191762Simp
817191762Simp	if (length <= sizeof(struct rx_header))
818191762Simp		return;
819191762Simp
820191762Simp	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
821191762Simp		goto trunc;
822191762Simp	}
823191762Simp
824191762Simp	/*
825191762Simp	 * Print out the afs call we're invoking.  The table used here was
826191762Simp	 * gleaned from fsint/afsint.xg
827191762Simp	 */
828191762Simp
829191762Simp	fs_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
830191762Simp
831191762Simp	printf(" fs call %s", tok2str(fs_req, "op#%d", fs_op));
832191762Simp
833191762Simp	/*
834191762Simp	 * Print out arguments to some of the AFS calls.  This stuff is
835191762Simp	 * all from afsint.xg
836191762Simp	 */
837191762Simp
838191762Simp	bp += sizeof(struct rx_header) + 4;
839191762Simp
840191762Simp	/*
841191762Simp	 * Sigh.  This is gross.  Ritchie forgive me.
842191762Simp	 */
843191762Simp
844191762Simp	switch (fs_op) {
845191762Simp		case 130:	/* Fetch data */
846191762Simp			FIDOUT();
847191762Simp			printf(" offset");
848191762Simp			UINTOUT();
849191762Simp			printf(" length");
850191762Simp			UINTOUT();
851191762Simp			break;
852191762Simp		case 131:	/* Fetch ACL */
853191762Simp		case 132:	/* Fetch Status */
854191762Simp		case 143:	/* Old set lock */
855191762Simp		case 144:	/* Old extend lock */
856191762Simp		case 145:	/* Old release lock */
857191762Simp		case 156:	/* Set lock */
858191762Simp		case 157:	/* Extend lock */
859191762Simp		case 158:	/* Release lock */
860191762Simp			FIDOUT();
861191762Simp			break;
862191762Simp		case 135:	/* Store status */
863191762Simp			FIDOUT();
864191762Simp			STOREATTROUT();
865191762Simp			break;
866191762Simp		case 133:	/* Store data */
867191762Simp			FIDOUT();
868191762Simp			STOREATTROUT();
869191762Simp			printf(" offset");
870191762Simp			UINTOUT();
871191762Simp			printf(" length");
872191762Simp			UINTOUT();
873191762Simp			printf(" flen");
874191762Simp			UINTOUT();
875191762Simp			break;
876191762Simp		case 134:	/* Store ACL */
877191762Simp		{
878191762Simp			char a[AFSOPAQUEMAX+1];
879191762Simp			FIDOUT();
880191762Simp			TCHECK2(bp[0], 4);
881191762Simp			i = EXTRACT_32BITS(bp);
882191762Simp			bp += sizeof(int32_t);
883191762Simp			TCHECK2(bp[0], i);
884191762Simp			i = min(AFSOPAQUEMAX, i);
885191762Simp			strncpy(a, (char *) bp, i);
886191762Simp			a[i] = '\0';
887191762Simp			acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
888191762Simp			break;
889191762Simp		}
890191762Simp		case 137:	/* Create file */
891191762Simp		case 141:	/* MakeDir */
892191762Simp			FIDOUT();
893191762Simp			STROUT(AFSNAMEMAX);
894191762Simp			STOREATTROUT();
895191762Simp			break;
896191762Simp		case 136:	/* Remove file */
897191762Simp		case 142:	/* Remove directory */
898191762Simp			FIDOUT();
899191762Simp			STROUT(AFSNAMEMAX);
900191762Simp			break;
901191762Simp		case 138:	/* Rename file */
902191762Simp			printf(" old");
903191762Simp			FIDOUT();
904191762Simp			STROUT(AFSNAMEMAX);
905191762Simp			printf(" new");
906191762Simp			FIDOUT();
907191762Simp			STROUT(AFSNAMEMAX);
908191762Simp			break;
909191762Simp		case 139:	/* Symlink */
910191762Simp			FIDOUT();
911191762Simp			STROUT(AFSNAMEMAX);
912191762Simp			printf(" link to");
913191762Simp			STROUT(AFSNAMEMAX);
914191762Simp			break;
915191762Simp		case 140:	/* Link */
916191762Simp			FIDOUT();
917191762Simp			STROUT(AFSNAMEMAX);
918191762Simp			printf(" link to");
919191762Simp			FIDOUT();
920191762Simp			break;
921191762Simp		case 148:	/* Get volume info */
922191762Simp			STROUT(AFSNAMEMAX);
923191762Simp			break;
924191762Simp		case 149:	/* Get volume stats */
925191762Simp		case 150:	/* Set volume stats */
926191762Simp			printf(" volid");
927191762Simp			UINTOUT();
928191762Simp			break;
929191762Simp		case 154:	/* New get volume info */
930191762Simp			printf(" volname");
931191762Simp			STROUT(AFSNAMEMAX);
932191762Simp			break;
933191762Simp		case 155:	/* Bulk stat */
934191762Simp		{
935191762Simp			unsigned long j;
936191762Simp			TCHECK2(bp[0], 4);
937191762Simp			j = EXTRACT_32BITS(bp);
938191762Simp			bp += sizeof(int32_t);
939191762Simp
940191762Simp			for (i = 0; i < j; i++) {
941191762Simp				FIDOUT();
942191762Simp				if (i != j - 1)
943191762Simp					printf(",");
944191762Simp			}
945191762Simp			if (j == 0)
946191762Simp				printf(" <none!>");
947191762Simp		}
948191762Simp		default:
949191762Simp			;
950191762Simp	}
951191762Simp
952191762Simp	return;
953191762Simp
954191762Simptrunc:
955191762Simp	printf(" [|fs]");
956191762Simp}
957191762Simp
958191762Simp/*
959191762Simp * Handle replies to the AFS file service
960191762Simp */
961191762Simp
962191762Simpstatic void
963191762Simpfs_reply_print(register const u_char *bp, int length, int32_t opcode)
964191762Simp{
965191762Simp	unsigned long i;
966191762Simp	char s[AFSNAMEMAX];
967191762Simp	struct rx_header *rxh;
968191762Simp
969191762Simp	if (length <= sizeof(struct rx_header))
970191762Simp		return;
971191762Simp
972191762Simp	rxh = (struct rx_header *) bp;
973191762Simp
974191762Simp	/*
975191762Simp	 * Print out the afs call we're invoking.  The table used here was
976191762Simp	 * gleaned from fsint/afsint.xg
977191762Simp	 */
978191762Simp
979191762Simp	printf(" fs reply %s", tok2str(fs_req, "op#%d", opcode));
980191762Simp
981191762Simp	bp += sizeof(struct rx_header);
982191762Simp
983191762Simp	/*
984191762Simp	 * If it was a data packet, interpret the response
985191762Simp	 */
986191762Simp
987191762Simp	if (rxh->type == RX_PACKET_TYPE_DATA) {
988191762Simp		switch (opcode) {
989191762Simp		case 131:	/* Fetch ACL */
990191762Simp		{
991191762Simp			char a[AFSOPAQUEMAX+1];
992191762Simp			TCHECK2(bp[0], 4);
993191762Simp			i = EXTRACT_32BITS(bp);
994191762Simp			bp += sizeof(int32_t);
995191762Simp			TCHECK2(bp[0], i);
996191762Simp			i = min(AFSOPAQUEMAX, i);
997191762Simp			strncpy(a, (char *) bp, i);
998191762Simp			a[i] = '\0';
999191762Simp			acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
1000191762Simp			break;
1001191762Simp		}
1002191762Simp		case 137:	/* Create file */
1003191762Simp		case 141:	/* MakeDir */
1004191762Simp			printf(" new");
1005191762Simp			FIDOUT();
1006191762Simp			break;
1007191762Simp		case 151:	/* Get root volume */
1008191762Simp			printf(" root volume");
1009191762Simp			STROUT(AFSNAMEMAX);
1010191762Simp			break;
1011191762Simp		case 153:	/* Get time */
1012191762Simp			DATEOUT();
1013191762Simp			break;
1014191762Simp		default:
1015191762Simp			;
1016191762Simp		}
1017191762Simp	} else if (rxh->type == RX_PACKET_TYPE_ABORT) {
1018191762Simp		int i;
1019191762Simp
1020191762Simp 		/*
1021191762Simp 		 * Otherwise, just print out the return code
1022191762Simp 		 */
1023191762Simp		TCHECK2(bp[0], sizeof(int32_t));
1024		i = (int) EXTRACT_32BITS(bp);
1025		bp += sizeof(int32_t);
1026
1027		printf(" error %s", tok2str(afs_fs_errors, "#%d", i));
1028	} else {
1029		printf(" strange fs reply of type %d", rxh->type);
1030	}
1031
1032	return;
1033
1034trunc:
1035	printf(" [|fs]");
1036}
1037
1038/*
1039 * Print out an AFS ACL string.  An AFS ACL is a string that has the
1040 * following format:
1041 *
1042 * <positive> <negative>
1043 * <uid1> <aclbits1>
1044 * ....
1045 *
1046 * "positive" and "negative" are integers which contain the number of
1047 * positive and negative ACL's in the string.  The uid/aclbits pair are
1048 * ASCII strings containing the UID/PTS record and and a ascii number
1049 * representing a logical OR of all the ACL permission bits
1050 */
1051
1052static void
1053acl_print(u_char *s, int maxsize, u_char *end)
1054{
1055	int pos, neg, acl;
1056	int n, i;
1057	char *user;
1058
1059	if ((user = (char *)malloc(maxsize)) == NULL)
1060		return;
1061
1062	if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
1063		goto finish;
1064
1065	s += n;
1066
1067	if (s > end)
1068		goto finish;
1069
1070	/*
1071	 * This wacky order preserves the order used by the "fs" command
1072	 */
1073
1074#define ACLOUT(acl) \
1075	if (acl & PRSFS_READ) \
1076		printf("r"); \
1077	if (acl & PRSFS_LOOKUP) \
1078		printf("l"); \
1079	if (acl & PRSFS_INSERT) \
1080		printf("i"); \
1081	if (acl & PRSFS_DELETE) \
1082		printf("d"); \
1083	if (acl & PRSFS_WRITE) \
1084		printf("w"); \
1085	if (acl & PRSFS_LOCK) \
1086		printf("k"); \
1087	if (acl & PRSFS_ADMINISTER) \
1088		printf("a");
1089
1090	for (i = 0; i < pos; i++) {
1091		if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
1092			goto finish;
1093		s += n;
1094		printf(" +{");
1095		fn_print(user, NULL);
1096		printf(" ");
1097		ACLOUT(acl);
1098		printf("}");
1099		if (s > end)
1100			goto finish;
1101	}
1102
1103	for (i = 0; i < neg; i++) {
1104		if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
1105			goto finish;
1106		s += n;
1107		printf(" -{");
1108		fn_print(user, NULL);
1109		printf(" ");
1110		ACLOUT(acl);
1111		printf("}");
1112		if (s > end)
1113			goto finish;
1114	}
1115
1116finish:
1117	free(user);
1118	return;
1119}
1120
1121#undef ACLOUT
1122
1123/*
1124 * Handle calls to the AFS callback service
1125 */
1126
1127static void
1128cb_print(register const u_char *bp, int length)
1129{
1130	int cb_op;
1131	unsigned long i;
1132
1133	if (length <= sizeof(struct rx_header))
1134		return;
1135
1136	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1137		goto trunc;
1138	}
1139
1140	/*
1141	 * Print out the afs call we're invoking.  The table used here was
1142	 * gleaned from fsint/afscbint.xg
1143	 */
1144
1145	cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1146
1147	printf(" cb call %s", tok2str(cb_req, "op#%d", cb_op));
1148
1149	bp += sizeof(struct rx_header) + 4;
1150
1151	/*
1152	 * Print out the afs call we're invoking.  The table used here was
1153	 * gleaned from fsint/afscbint.xg
1154	 */
1155
1156	switch (cb_op) {
1157		case 204:		/* Callback */
1158		{
1159			unsigned long j, t;
1160			TCHECK2(bp[0], 4);
1161			j = EXTRACT_32BITS(bp);
1162			bp += sizeof(int32_t);
1163
1164			for (i = 0; i < j; i++) {
1165				FIDOUT();
1166				if (i != j - 1)
1167					printf(",");
1168			}
1169
1170			if (j == 0)
1171				printf(" <none!>");
1172
1173			j = EXTRACT_32BITS(bp);
1174			bp += sizeof(int32_t);
1175
1176			if (j != 0)
1177				printf(";");
1178
1179			for (i = 0; i < j; i++) {
1180				printf(" ver");
1181				INTOUT();
1182				printf(" expires");
1183				DATEOUT();
1184				TCHECK2(bp[0], 4);
1185				t = EXTRACT_32BITS(bp);
1186				bp += sizeof(int32_t);
1187				tok2str(cb_types, "type %d", t);
1188			}
1189		}
1190		case 214: {
1191			printf(" afsuuid");
1192			AFSUUIDOUT();
1193			break;
1194		}
1195		default:
1196			;
1197	}
1198
1199	return;
1200
1201trunc:
1202	printf(" [|cb]");
1203}
1204
1205/*
1206 * Handle replies to the AFS Callback Service
1207 */
1208
1209static void
1210cb_reply_print(register const u_char *bp, int length, int32_t opcode)
1211{
1212	struct rx_header *rxh;
1213
1214	if (length <= sizeof(struct rx_header))
1215		return;
1216
1217	rxh = (struct rx_header *) bp;
1218
1219	/*
1220	 * Print out the afs call we're invoking.  The table used here was
1221	 * gleaned from fsint/afscbint.xg
1222	 */
1223
1224	printf(" cb reply %s", tok2str(cb_req, "op#%d", opcode));
1225
1226	bp += sizeof(struct rx_header);
1227
1228	/*
1229	 * If it was a data packet, interpret the response.
1230	 */
1231
1232	if (rxh->type == RX_PACKET_TYPE_DATA)
1233		switch (opcode) {
1234		case 213:	/* InitCallBackState3 */
1235			AFSUUIDOUT();
1236			break;
1237		default:
1238		;
1239		}
1240	else {
1241		/*
1242		 * Otherwise, just print out the return code
1243		 */
1244		printf(" errcode");
1245		INTOUT();
1246	}
1247
1248	return;
1249
1250trunc:
1251	printf(" [|cb]");
1252}
1253
1254/*
1255 * Handle calls to the AFS protection database server
1256 */
1257
1258static void
1259prot_print(register const u_char *bp, int length)
1260{
1261	unsigned long i;
1262	char s[AFSNAMEMAX];
1263	int pt_op;
1264
1265	if (length <= sizeof(struct rx_header))
1266		return;
1267
1268	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1269		goto trunc;
1270	}
1271
1272	/*
1273	 * Print out the afs call we're invoking.  The table used here was
1274	 * gleaned from ptserver/ptint.xg
1275	 */
1276
1277	pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1278
1279	printf(" pt");
1280
1281	if (is_ubik(pt_op)) {
1282		ubik_print(bp, length);
1283		return;
1284	}
1285
1286	printf(" call %s", tok2str(pt_req, "op#%d", pt_op));
1287
1288	/*
1289	 * Decode some of the arguments to the PT calls
1290	 */
1291
1292	bp += sizeof(struct rx_header) + 4;
1293
1294	switch (pt_op) {
1295		case 500:	/* I New User */
1296			STROUT(PRNAMEMAX);
1297			printf(" id");
1298			INTOUT();
1299			printf(" oldid");
1300			INTOUT();
1301			break;
1302		case 501:	/* Where is it */
1303		case 506:	/* Delete */
1304		case 508:	/* Get CPS */
1305		case 512:	/* List entry */
1306		case 514:	/* List elements */
1307		case 517:	/* List owned */
1308		case 518:	/* Get CPS2 */
1309		case 519:	/* Get host CPS */
1310			printf(" id");
1311			INTOUT();
1312			break;
1313		case 502:	/* Dump entry */
1314			printf(" pos");
1315			INTOUT();
1316			break;
1317		case 503:	/* Add to group */
1318		case 507:	/* Remove from group */
1319		case 515:	/* Is a member of? */
1320			printf(" uid");
1321			INTOUT();
1322			printf(" gid");
1323			INTOUT();
1324			break;
1325		case 504:	/* Name to ID */
1326		{
1327			unsigned long j;
1328			TCHECK2(bp[0], 4);
1329			j = EXTRACT_32BITS(bp);
1330			bp += sizeof(int32_t);
1331
1332			/*
1333			 * Who designed this chicken-shit protocol?
1334			 *
1335			 * Each character is stored as a 32-bit
1336			 * integer!
1337			 */
1338
1339			for (i = 0; i < j; i++) {
1340				VECOUT(PRNAMEMAX);
1341			}
1342			if (j == 0)
1343				printf(" <none!>");
1344		}
1345			break;
1346		case 505:	/* Id to name */
1347		{
1348			unsigned long j;
1349			printf(" ids:");
1350			TCHECK2(bp[0], 4);
1351			i = EXTRACT_32BITS(bp);
1352			bp += sizeof(int32_t);
1353			for (j = 0; j < i; j++)
1354				INTOUT();
1355			if (j == 0)
1356				printf(" <none!>");
1357		}
1358			break;
1359		case 509:	/* New entry */
1360			STROUT(PRNAMEMAX);
1361			printf(" flag");
1362			INTOUT();
1363			printf(" oid");
1364			INTOUT();
1365			break;
1366		case 511:	/* Set max */
1367			printf(" id");
1368			INTOUT();
1369			printf(" gflag");
1370			INTOUT();
1371			break;
1372		case 513:	/* Change entry */
1373			printf(" id");
1374			INTOUT();
1375			STROUT(PRNAMEMAX);
1376			printf(" oldid");
1377			INTOUT();
1378			printf(" newid");
1379			INTOUT();
1380			break;
1381		case 520:	/* Update entry */
1382			printf(" id");
1383			INTOUT();
1384			STROUT(PRNAMEMAX);
1385			break;
1386		default:
1387			;
1388	}
1389
1390
1391	return;
1392
1393trunc:
1394	printf(" [|pt]");
1395}
1396
1397/*
1398 * Handle replies to the AFS protection service
1399 */
1400
1401static void
1402prot_reply_print(register const u_char *bp, int length, int32_t opcode)
1403{
1404	struct rx_header *rxh;
1405	unsigned long i;
1406	char s[AFSNAMEMAX];
1407
1408	if (length < sizeof(struct rx_header))
1409		return;
1410
1411	rxh = (struct rx_header *) bp;
1412
1413	/*
1414	 * Print out the afs call we're invoking.  The table used here was
1415	 * gleaned from ptserver/ptint.xg.  Check to see if it's a
1416	 * Ubik call, however.
1417	 */
1418
1419	printf(" pt");
1420
1421	if (is_ubik(opcode)) {
1422		ubik_reply_print(bp, length, opcode);
1423		return;
1424	}
1425
1426	printf(" reply %s", tok2str(pt_req, "op#%d", opcode));
1427
1428	bp += sizeof(struct rx_header);
1429
1430	/*
1431	 * If it was a data packet, interpret the response
1432	 */
1433
1434	if (rxh->type == RX_PACKET_TYPE_DATA)
1435		switch (opcode) {
1436		case 504:		/* Name to ID */
1437		{
1438			unsigned long j;
1439			printf(" ids:");
1440			TCHECK2(bp[0], 4);
1441			i = EXTRACT_32BITS(bp);
1442			bp += sizeof(int32_t);
1443			for (j = 0; j < i; j++)
1444				INTOUT();
1445			if (j == 0)
1446				printf(" <none!>");
1447		}
1448			break;
1449		case 505:		/* ID to name */
1450		{
1451			unsigned long j;
1452			TCHECK2(bp[0], 4);
1453			j = EXTRACT_32BITS(bp);
1454			bp += sizeof(int32_t);
1455
1456			/*
1457			 * Who designed this chicken-shit protocol?
1458			 *
1459			 * Each character is stored as a 32-bit
1460			 * integer!
1461			 */
1462
1463			for (i = 0; i < j; i++) {
1464				VECOUT(PRNAMEMAX);
1465			}
1466			if (j == 0)
1467				printf(" <none!>");
1468		}
1469			break;
1470		case 508:		/* Get CPS */
1471		case 514:		/* List elements */
1472		case 517:		/* List owned */
1473		case 518:		/* Get CPS2 */
1474		case 519:		/* Get host CPS */
1475		{
1476			unsigned long j;
1477			TCHECK2(bp[0], 4);
1478			j = EXTRACT_32BITS(bp);
1479			bp += sizeof(int32_t);
1480			for (i = 0; i < j; i++) {
1481				INTOUT();
1482			}
1483			if (j == 0)
1484				printf(" <none!>");
1485		}
1486			break;
1487		case 510:		/* List max */
1488			printf(" maxuid");
1489			INTOUT();
1490			printf(" maxgid");
1491			INTOUT();
1492			break;
1493		default:
1494			;
1495		}
1496	else {
1497		/*
1498		 * Otherwise, just print out the return code
1499		 */
1500		printf(" errcode");
1501		INTOUT();
1502	}
1503
1504	return;
1505
1506trunc:
1507	printf(" [|pt]");
1508}
1509
1510/*
1511 * Handle calls to the AFS volume location database service
1512 */
1513
1514static void
1515vldb_print(register const u_char *bp, int length)
1516{
1517	int vldb_op;
1518	unsigned long i;
1519	char s[AFSNAMEMAX];
1520
1521	if (length <= sizeof(struct rx_header))
1522		return;
1523
1524	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1525		goto trunc;
1526	}
1527
1528	/*
1529	 * Print out the afs call we're invoking.  The table used here was
1530	 * gleaned from vlserver/vldbint.xg
1531	 */
1532
1533	vldb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1534
1535	printf(" vldb");
1536
1537	if (is_ubik(vldb_op)) {
1538		ubik_print(bp, length);
1539		return;
1540	}
1541	printf(" call %s", tok2str(vldb_req, "op#%d", vldb_op));
1542
1543	/*
1544	 * Decode some of the arguments to the VLDB calls
1545	 */
1546
1547	bp += sizeof(struct rx_header) + 4;
1548
1549	switch (vldb_op) {
1550		case 501:	/* Create new volume */
1551		case 517:	/* Create entry N */
1552			VECOUT(VLNAMEMAX);
1553			break;
1554		case 502:	/* Delete entry */
1555		case 503:	/* Get entry by ID */
1556		case 507:	/* Update entry */
1557		case 508:	/* Set lock */
1558		case 509:	/* Release lock */
1559		case 518:	/* Get entry by ID N */
1560			printf(" volid");
1561			INTOUT();
1562			TCHECK2(bp[0], sizeof(int32_t));
1563			i = EXTRACT_32BITS(bp);
1564			bp += sizeof(int32_t);
1565			if (i <= 2)
1566				printf(" type %s", voltype[i]);
1567			break;
1568		case 504:	/* Get entry by name */
1569		case 519:	/* Get entry by name N */
1570		case 524:	/* Update entry by name */
1571		case 527:	/* Get entry by name U */
1572			STROUT(VLNAMEMAX);
1573			break;
1574		case 505:	/* Get new vol id */
1575			printf(" bump");
1576			INTOUT();
1577			break;
1578		case 506:	/* Replace entry */
1579		case 520:	/* Replace entry N */
1580			printf(" volid");
1581			INTOUT();
1582			TCHECK2(bp[0], sizeof(int32_t));
1583			i = EXTRACT_32BITS(bp);
1584			bp += sizeof(int32_t);
1585			if (i <= 2)
1586				printf(" type %s", voltype[i]);
1587			VECOUT(VLNAMEMAX);
1588			break;
1589		case 510:	/* List entry */
1590		case 521:	/* List entry N */
1591			printf(" index");
1592			INTOUT();
1593			break;
1594		default:
1595			;
1596	}
1597
1598	return;
1599
1600trunc:
1601	printf(" [|vldb]");
1602}
1603
1604/*
1605 * Handle replies to the AFS volume location database service
1606 */
1607
1608static void
1609vldb_reply_print(register const u_char *bp, int length, int32_t opcode)
1610{
1611	struct rx_header *rxh;
1612	unsigned long i;
1613	char s[AFSNAMEMAX];
1614
1615	if (length < sizeof(struct rx_header))
1616		return;
1617
1618	rxh = (struct rx_header *) bp;
1619
1620	/*
1621	 * Print out the afs call we're invoking.  The table used here was
1622	 * gleaned from vlserver/vldbint.xg.  Check to see if it's a
1623	 * Ubik call, however.
1624	 */
1625
1626	printf(" vldb");
1627
1628	if (is_ubik(opcode)) {
1629		ubik_reply_print(bp, length, opcode);
1630		return;
1631	}
1632
1633	printf(" reply %s", tok2str(vldb_req, "op#%d", opcode));
1634
1635	bp += sizeof(struct rx_header);
1636
1637	/*
1638	 * If it was a data packet, interpret the response
1639	 */
1640
1641	if (rxh->type == RX_PACKET_TYPE_DATA)
1642		switch (opcode) {
1643		case 510:	/* List entry */
1644			printf(" count");
1645			INTOUT();
1646			printf(" nextindex");
1647			INTOUT();
1648		case 503:	/* Get entry by id */
1649		case 504:	/* Get entry by name */
1650		{	unsigned long nservers, j;
1651			VECOUT(VLNAMEMAX);
1652			TCHECK2(bp[0], sizeof(int32_t));
1653			bp += sizeof(int32_t);
1654			printf(" numservers");
1655			TCHECK2(bp[0], sizeof(int32_t));
1656			nservers = EXTRACT_32BITS(bp);
1657			bp += sizeof(int32_t);
1658			printf(" %lu", nservers);
1659			printf(" servers");
1660			for (i = 0; i < 8; i++) {
1661				TCHECK2(bp[0], sizeof(int32_t));
1662				if (i < nservers)
1663					printf(" %s",
1664					   inet_ntoa(*((struct in_addr *) bp)));
1665				bp += sizeof(int32_t);
1666			}
1667			printf(" partitions");
1668			for (i = 0; i < 8; i++) {
1669				TCHECK2(bp[0], sizeof(int32_t));
1670				j = EXTRACT_32BITS(bp);
1671				if (i < nservers && j <= 26)
1672					printf(" %c", 'a' + (int)j);
1673				else if (i < nservers)
1674					printf(" %lu", j);
1675				bp += sizeof(int32_t);
1676			}
1677			TCHECK2(bp[0], 8 * sizeof(int32_t));
1678			bp += 8 * sizeof(int32_t);
1679			printf(" rwvol");
1680			UINTOUT();
1681			printf(" rovol");
1682			UINTOUT();
1683			printf(" backup");
1684			UINTOUT();
1685		}
1686			break;
1687		case 505:	/* Get new volume ID */
1688			printf(" newvol");
1689			UINTOUT();
1690			break;
1691		case 521:	/* List entry */
1692		case 529:	/* List entry U */
1693			printf(" count");
1694			INTOUT();
1695			printf(" nextindex");
1696			INTOUT();
1697		case 518:	/* Get entry by ID N */
1698		case 519:	/* Get entry by name N */
1699		{	unsigned long nservers, j;
1700			VECOUT(VLNAMEMAX);
1701			printf(" numservers");
1702			TCHECK2(bp[0], sizeof(int32_t));
1703			nservers = EXTRACT_32BITS(bp);
1704			bp += sizeof(int32_t);
1705			printf(" %lu", nservers);
1706			printf(" servers");
1707			for (i = 0; i < 13; i++) {
1708				TCHECK2(bp[0], sizeof(int32_t));
1709				if (i < nservers)
1710					printf(" %s",
1711					   inet_ntoa(*((struct in_addr *) bp)));
1712				bp += sizeof(int32_t);
1713			}
1714			printf(" partitions");
1715			for (i = 0; i < 13; i++) {
1716				TCHECK2(bp[0], sizeof(int32_t));
1717				j = EXTRACT_32BITS(bp);
1718				if (i < nservers && j <= 26)
1719					printf(" %c", 'a' + (int)j);
1720				else if (i < nservers)
1721					printf(" %lu", j);
1722				bp += sizeof(int32_t);
1723			}
1724			TCHECK2(bp[0], 13 * sizeof(int32_t));
1725			bp += 13 * sizeof(int32_t);
1726			printf(" rwvol");
1727			UINTOUT();
1728			printf(" rovol");
1729			UINTOUT();
1730			printf(" backup");
1731			UINTOUT();
1732		}
1733			break;
1734		case 526:	/* Get entry by ID U */
1735		case 527:	/* Get entry by name U */
1736		{	unsigned long nservers, j;
1737			VECOUT(VLNAMEMAX);
1738			printf(" numservers");
1739			TCHECK2(bp[0], sizeof(int32_t));
1740			nservers = EXTRACT_32BITS(bp);
1741			bp += sizeof(int32_t);
1742			printf(" %lu", nservers);
1743			printf(" servers");
1744			for (i = 0; i < 13; i++) {
1745				if (i < nservers) {
1746					printf(" afsuuid");
1747					AFSUUIDOUT();
1748				} else {
1749					TCHECK2(bp[0], 44);
1750					bp += 44;
1751				}
1752			}
1753			TCHECK2(bp[0], 4 * 13);
1754			bp += 4 * 13;
1755			printf(" partitions");
1756			for (i = 0; i < 13; i++) {
1757				TCHECK2(bp[0], sizeof(int32_t));
1758				j = EXTRACT_32BITS(bp);
1759				if (i < nservers && j <= 26)
1760					printf(" %c", 'a' + (int)j);
1761				else if (i < nservers)
1762					printf(" %lu", j);
1763				bp += sizeof(int32_t);
1764			}
1765			TCHECK2(bp[0], 13 * sizeof(int32_t));
1766			bp += 13 * sizeof(int32_t);
1767			printf(" rwvol");
1768			UINTOUT();
1769			printf(" rovol");
1770			UINTOUT();
1771			printf(" backup");
1772			UINTOUT();
1773		}
1774		default:
1775			;
1776		}
1777
1778	else {
1779		/*
1780		 * Otherwise, just print out the return code
1781		 */
1782		printf(" errcode");
1783		INTOUT();
1784	}
1785
1786	return;
1787
1788trunc:
1789	printf(" [|vldb]");
1790}
1791
1792/*
1793 * Handle calls to the AFS Kerberos Authentication service
1794 */
1795
1796static void
1797kauth_print(register const u_char *bp, int length)
1798{
1799	int kauth_op;
1800	char s[AFSNAMEMAX];
1801
1802	if (length <= sizeof(struct rx_header))
1803		return;
1804
1805	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1806		goto trunc;
1807	}
1808
1809	/*
1810	 * Print out the afs call we're invoking.  The table used here was
1811	 * gleaned from kauth/kauth.rg
1812	 */
1813
1814	kauth_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1815
1816	printf(" kauth");
1817
1818	if (is_ubik(kauth_op)) {
1819		ubik_print(bp, length);
1820		return;
1821	}
1822
1823
1824	printf(" call %s", tok2str(kauth_req, "op#%d", kauth_op));
1825
1826	/*
1827	 * Decode some of the arguments to the KA calls
1828	 */
1829
1830	bp += sizeof(struct rx_header) + 4;
1831
1832	switch (kauth_op) {
1833		case 1:		/* Authenticate old */;
1834		case 21:	/* Authenticate */
1835		case 22:	/* Authenticate-V2 */
1836		case 2:		/* Change PW */
1837		case 5:		/* Set fields */
1838		case 6:		/* Create user */
1839		case 7:		/* Delete user */
1840		case 8:		/* Get entry */
1841		case 14:	/* Unlock */
1842		case 15:	/* Lock status */
1843			printf(" principal");
1844			STROUT(KANAMEMAX);
1845			STROUT(KANAMEMAX);
1846			break;
1847		case 3:		/* GetTicket-old */
1848		case 23:	/* GetTicket */
1849		{
1850			int i;
1851			printf(" kvno");
1852			INTOUT();
1853			printf(" domain");
1854			STROUT(KANAMEMAX);
1855			TCHECK2(bp[0], sizeof(int32_t));
1856			i = (int) EXTRACT_32BITS(bp);
1857			bp += sizeof(int32_t);
1858			TCHECK2(bp[0], i);
1859			bp += i;
1860			printf(" principal");
1861			STROUT(KANAMEMAX);
1862			STROUT(KANAMEMAX);
1863			break;
1864		}
1865		case 4:		/* Set Password */
1866			printf(" principal");
1867			STROUT(KANAMEMAX);
1868			STROUT(KANAMEMAX);
1869			printf(" kvno");
1870			INTOUT();
1871			break;
1872		case 12:	/* Get password */
1873			printf(" name");
1874			STROUT(KANAMEMAX);
1875			break;
1876		default:
1877			;
1878	}
1879
1880	return;
1881
1882trunc:
1883	printf(" [|kauth]");
1884}
1885
1886/*
1887 * Handle replies to the AFS Kerberos Authentication Service
1888 */
1889
1890static void
1891kauth_reply_print(register const u_char *bp, int length, int32_t opcode)
1892{
1893	struct rx_header *rxh;
1894
1895	if (length <= sizeof(struct rx_header))
1896		return;
1897
1898	rxh = (struct rx_header *) bp;
1899
1900	/*
1901	 * Print out the afs call we're invoking.  The table used here was
1902	 * gleaned from kauth/kauth.rg
1903	 */
1904
1905	printf(" kauth");
1906
1907	if (is_ubik(opcode)) {
1908		ubik_reply_print(bp, length, opcode);
1909		return;
1910	}
1911
1912	printf(" reply %s", tok2str(kauth_req, "op#%d", opcode));
1913
1914	bp += sizeof(struct rx_header);
1915
1916	/*
1917	 * If it was a data packet, interpret the response.
1918	 */
1919
1920	if (rxh->type == RX_PACKET_TYPE_DATA)
1921		/* Well, no, not really.  Leave this for later */
1922		;
1923	else {
1924		/*
1925		 * Otherwise, just print out the return code
1926		 */
1927		printf(" errcode");
1928		INTOUT();
1929	}
1930
1931	return;
1932
1933trunc:
1934	printf(" [|kauth]");
1935}
1936
1937/*
1938 * Handle calls to the AFS Volume location service
1939 */
1940
1941static void
1942vol_print(register const u_char *bp, int length)
1943{
1944	int vol_op;
1945
1946	if (length <= sizeof(struct rx_header))
1947		return;
1948
1949	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1950		goto trunc;
1951	}
1952
1953	/*
1954	 * Print out the afs call we're invoking.  The table used here was
1955	 * gleaned from volser/volint.xg
1956	 */
1957
1958	vol_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1959
1960	printf(" vol call %s", tok2str(vol_req, "op#%d", vol_op));
1961
1962	/*
1963	 * Normally there would be a switch statement here to decode the
1964	 * arguments to the AFS call, but since I don't have access to
1965	 * an AFS server (yet) and I'm not an AFS admin, I can't
1966	 * test any of these calls.  Leave this blank for now.
1967	 */
1968
1969	return;
1970
1971trunc:
1972	printf(" [|vol]");
1973}
1974
1975/*
1976 * Handle replies to the AFS Volume Service
1977 */
1978
1979static void
1980vol_reply_print(register const u_char *bp, int length, int32_t opcode)
1981{
1982	struct rx_header *rxh;
1983
1984	if (length <= sizeof(struct rx_header))
1985		return;
1986
1987	rxh = (struct rx_header *) bp;
1988
1989	/*
1990	 * Print out the afs call we're invoking.  The table used here was
1991	 * gleaned from volser/volint.xg
1992	 */
1993
1994	printf(" vol reply %s", tok2str(vol_req, "op#%d", opcode));
1995
1996	bp += sizeof(struct rx_header);
1997
1998	/*
1999	 * If it was a data packet, interpret the response.
2000	 */
2001
2002	if (rxh->type == RX_PACKET_TYPE_DATA)
2003		/* Well, no, not really.  Leave this for later */
2004		;
2005	else {
2006		/*
2007		 * Otherwise, just print out the return code
2008		 */
2009		printf(" errcode");
2010		INTOUT();
2011	}
2012
2013	return;
2014
2015trunc:
2016	printf(" [|vol]");
2017}
2018
2019/*
2020 * Handle calls to the AFS BOS service
2021 */
2022
2023static void
2024bos_print(register const u_char *bp, int length)
2025{
2026	int bos_op;
2027	char s[BOSNAMEMAX];
2028
2029	if (length <= sizeof(struct rx_header))
2030		return;
2031
2032	if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
2033		goto trunc;
2034	}
2035
2036	/*
2037	 * Print out the afs call we're invoking.  The table used here was
2038	 * gleaned from bozo/bosint.xg
2039	 */
2040
2041	bos_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2042
2043	printf(" bos call %s", tok2str(bos_req, "op#%d", bos_op));
2044
2045	/*
2046	 * Decode some of the arguments to the BOS calls
2047	 */
2048
2049	bp += sizeof(struct rx_header) + 4;
2050
2051	switch (bos_op) {
2052		case 80:	/* Create B node */
2053			printf(" type");
2054			STROUT(BOSNAMEMAX);
2055			printf(" instance");
2056			STROUT(BOSNAMEMAX);
2057			break;
2058		case 81:	/* Delete B node */
2059		case 83:	/* Get status */
2060		case 85:	/* Get instance info */
2061		case 87:	/* Add super user */
2062		case 88:	/* Delete super user */
2063		case 93:	/* Set cell name */
2064		case 96:	/* Add cell host */
2065		case 97:	/* Delete cell host */
2066		case 104:	/* Restart */
2067		case 106:	/* Uninstall */
2068		case 108:	/* Exec */
2069		case 112:	/* Getlog */
2070		case 114:	/* Get instance strings */
2071			STROUT(BOSNAMEMAX);
2072			break;
2073		case 82:	/* Set status */
2074		case 98:	/* Set T status */
2075			STROUT(BOSNAMEMAX);
2076			printf(" status");
2077			INTOUT();
2078			break;
2079		case 86:	/* Get instance parm */
2080			STROUT(BOSNAMEMAX);
2081			printf(" num");
2082			INTOUT();
2083			break;
2084		case 84:	/* Enumerate instance */
2085		case 89:	/* List super users */
2086		case 90:	/* List keys */
2087		case 91:	/* Add key */
2088		case 92:	/* Delete key */
2089		case 95:	/* Get cell host */
2090			INTOUT();
2091			break;
2092		case 105:	/* Install */
2093			STROUT(BOSNAMEMAX);
2094			printf(" size");
2095			INTOUT();
2096			printf(" flags");
2097			INTOUT();
2098			printf(" date");
2099			INTOUT();
2100			break;
2101		default:
2102			;
2103	}
2104
2105	return;
2106
2107trunc:
2108	printf(" [|bos]");
2109}
2110
2111/*
2112 * Handle replies to the AFS BOS Service
2113 */
2114
2115static void
2116bos_reply_print(register const u_char *bp, int length, int32_t opcode)
2117{
2118	struct rx_header *rxh;
2119
2120	if (length <= sizeof(struct rx_header))
2121		return;
2122
2123	rxh = (struct rx_header *) bp;
2124
2125	/*
2126	 * Print out the afs call we're invoking.  The table used here was
2127	 * gleaned from volser/volint.xg
2128	 */
2129
2130	printf(" bos reply %s", tok2str(bos_req, "op#%d", opcode));
2131
2132	bp += sizeof(struct rx_header);
2133
2134	/*
2135	 * If it was a data packet, interpret the response.
2136	 */
2137
2138	if (rxh->type == RX_PACKET_TYPE_DATA)
2139		/* Well, no, not really.  Leave this for later */
2140		;
2141	else {
2142		/*
2143		 * Otherwise, just print out the return code
2144		 */
2145		printf(" errcode");
2146		INTOUT();
2147	}
2148
2149	return;
2150
2151trunc:
2152	printf(" [|bos]");
2153}
2154
2155/*
2156 * Check to see if this is a Ubik opcode.
2157 */
2158
2159static int
2160is_ubik(u_int32_t opcode)
2161{
2162	if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
2163	    (opcode >= DISK_LOW && opcode <= DISK_HIGH))
2164		return(1);
2165	else
2166		return(0);
2167}
2168
2169/*
2170 * Handle Ubik opcodes to any one of the replicated database services
2171 */
2172
2173static void
2174ubik_print(register const u_char *bp, int length)
2175{
2176	int ubik_op;
2177	int32_t temp;
2178
2179	/*
2180	 * Print out the afs call we're invoking.  The table used here was
2181	 * gleaned from ubik/ubik_int.xg
2182	 */
2183
2184	ubik_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2185
2186	printf(" ubik call %s", tok2str(ubik_req, "op#%d", ubik_op));
2187
2188	/*
2189	 * Decode some of the arguments to the Ubik calls
2190	 */
2191
2192	bp += sizeof(struct rx_header) + 4;
2193
2194	switch (ubik_op) {
2195		case 10000:		/* Beacon */
2196			TCHECK2(bp[0], 4);
2197			temp = EXTRACT_32BITS(bp);
2198			bp += sizeof(int32_t);
2199			printf(" syncsite %s", temp ? "yes" : "no");
2200			printf(" votestart");
2201			DATEOUT();
2202			printf(" dbversion");
2203			UBIK_VERSIONOUT();
2204			printf(" tid");
2205			UBIK_VERSIONOUT();
2206			break;
2207		case 10003:		/* Get sync site */
2208			printf(" site");
2209			UINTOUT();
2210			break;
2211		case 20000:		/* Begin */
2212		case 20001:		/* Commit */
2213		case 20007:		/* Abort */
2214		case 20008:		/* Release locks */
2215		case 20010:		/* Writev */
2216			printf(" tid");
2217			UBIK_VERSIONOUT();
2218			break;
2219		case 20002:		/* Lock */
2220			printf(" tid");
2221			UBIK_VERSIONOUT();
2222			printf(" file");
2223			INTOUT();
2224			printf(" pos");
2225			INTOUT();
2226			printf(" length");
2227			INTOUT();
2228			temp = EXTRACT_32BITS(bp);
2229			bp += sizeof(int32_t);
2230			tok2str(ubik_lock_types, "type %d", temp);
2231			break;
2232		case 20003:		/* Write */
2233			printf(" tid");
2234			UBIK_VERSIONOUT();
2235			printf(" file");
2236			INTOUT();
2237			printf(" pos");
2238			INTOUT();
2239			break;
2240		case 20005:		/* Get file */
2241			printf(" file");
2242			INTOUT();
2243			break;
2244		case 20006:		/* Send file */
2245			printf(" file");
2246			INTOUT();
2247			printf(" length");
2248			INTOUT();
2249			printf(" dbversion");
2250			UBIK_VERSIONOUT();
2251			break;
2252		case 20009:		/* Truncate */
2253			printf(" tid");
2254			UBIK_VERSIONOUT();
2255			printf(" file");
2256			INTOUT();
2257			printf(" length");
2258			INTOUT();
2259			break;
2260		case 20012:		/* Set version */
2261			printf(" tid");
2262			UBIK_VERSIONOUT();
2263			printf(" oldversion");
2264			UBIK_VERSIONOUT();
2265			printf(" newversion");
2266			UBIK_VERSIONOUT();
2267			break;
2268		default:
2269			;
2270	}
2271
2272	return;
2273
2274trunc:
2275	printf(" [|ubik]");
2276}
2277
2278/*
2279 * Handle Ubik replies to any one of the replicated database services
2280 */
2281
2282static void
2283ubik_reply_print(register const u_char *bp, int length, int32_t opcode)
2284{
2285	struct rx_header *rxh;
2286
2287	if (length < sizeof(struct rx_header))
2288		return;
2289
2290	rxh = (struct rx_header *) bp;
2291
2292	/*
2293	 * Print out the ubik call we're invoking.  This table was gleaned
2294	 * from ubik/ubik_int.xg
2295	 */
2296
2297	printf(" ubik reply %s", tok2str(ubik_req, "op#%d", opcode));
2298
2299	bp += sizeof(struct rx_header);
2300
2301	/*
2302	 * If it was a data packet, print out the arguments to the Ubik calls
2303	 */
2304
2305	if (rxh->type == RX_PACKET_TYPE_DATA)
2306		switch (opcode) {
2307		case 10000:		/* Beacon */
2308			printf(" vote no");
2309			break;
2310		case 20004:		/* Get version */
2311			printf(" dbversion");
2312			UBIK_VERSIONOUT();
2313			break;
2314		default:
2315			;
2316		}
2317
2318	/*
2319	 * Otherwise, print out "yes" it it was a beacon packet (because
2320	 * that's how yes votes are returned, go figure), otherwise
2321	 * just print out the error code.
2322	 */
2323
2324	else
2325		switch (opcode) {
2326		case 10000:		/* Beacon */
2327			printf(" vote yes until");
2328			DATEOUT();
2329			break;
2330		default:
2331			printf(" errcode");
2332			INTOUT();
2333		}
2334
2335	return;
2336
2337trunc:
2338	printf(" [|ubik]");
2339}
2340
2341/*
2342 * Handle RX ACK packets.
2343 */
2344
2345static void
2346rx_ack_print(register const u_char *bp, int length)
2347{
2348	struct rx_ackPacket *rxa;
2349	int i, start, last;
2350
2351	if (length < sizeof(struct rx_header))
2352		return;
2353
2354	bp += sizeof(struct rx_header);
2355
2356	/*
2357	 * This may seem a little odd .... the rx_ackPacket structure
2358	 * contains an array of individual packet acknowledgements
2359	 * (used for selective ack/nack), but since it's variable in size,
2360	 * we don't want to truncate based on the size of the whole
2361	 * rx_ackPacket structure.
2362	 */
2363
2364	TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS);
2365
2366	rxa = (struct rx_ackPacket *) bp;
2367	bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS);
2368
2369	/*
2370	 * Print out a few useful things from the ack packet structure
2371	 */
2372
2373	if (vflag > 2)
2374		printf(" bufspace %d maxskew %d",
2375		       (int) EXTRACT_16BITS(&rxa->bufferSpace),
2376		       (int) EXTRACT_16BITS(&rxa->maxSkew));
2377
2378	printf(" first %d serial %d reason %s",
2379	       EXTRACT_32BITS(&rxa->firstPacket), EXTRACT_32BITS(&rxa->serial),
2380	       tok2str(rx_ack_reasons, "#%d", (int) rxa->reason));
2381
2382	/*
2383	 * Okay, now we print out the ack array.  The way _this_ works
2384	 * is that we start at "first", and step through the ack array.
2385	 * If we have a contiguous range of acks/nacks, try to
2386	 * collapse them into a range.
2387	 *
2388	 * If you're really clever, you might have noticed that this
2389	 * doesn't seem quite correct.  Specifically, due to structure
2390	 * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually
2391	 * yield the start of the ack array (because RX_MAXACKS is 255
2392	 * and the structure will likely get padded to a 2 or 4 byte
2393	 * boundary).  However, this is the way it's implemented inside
2394	 * of AFS - the start of the extra fields are at
2395	 * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_
2396	 * the exact start of the ack array.  Sigh.  That's why we aren't
2397	 * using bp, but instead use rxa->acks[].  But nAcks gets added
2398	 * to bp after this, so bp ends up at the right spot.  Go figure.
2399	 */
2400
2401	if (rxa->nAcks != 0) {
2402
2403		TCHECK2(bp[0], rxa->nAcks);
2404
2405		/*
2406		 * Sigh, this is gross, but it seems to work to collapse
2407		 * ranges correctly.
2408		 */
2409
2410		for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2411			if (rxa->acks[i] == RX_ACK_TYPE_ACK) {
2412
2413				/*
2414				 * I figured this deserved _some_ explanation.
2415				 * First, print "acked" and the packet seq
2416				 * number if this is the first time we've
2417				 * seen an acked packet.
2418				 */
2419
2420				if (last == -2) {
2421					printf(" acked %d",
2422					       rxa->firstPacket + i);
2423					start = i;
2424				}
2425
2426				/*
2427				 * Otherwise, if the there is a skip in
2428				 * the range (such as an nacked packet in
2429				 * the middle of some acked packets),
2430				 * then print the current packet number
2431				 * seperated from the last number by
2432				 * a comma.
2433				 */
2434
2435				else if (last != i - 1) {
2436					printf(",%d", rxa->firstPacket + i);
2437					start = i;
2438				}
2439
2440				/*
2441				 * We always set last to the value of
2442				 * the last ack we saw.  Conversely, start
2443				 * is set to the value of the first ack
2444				 * we saw in a range.
2445				 */
2446
2447				last = i;
2448
2449				/*
2450				 * Okay, this bit a code gets executed when
2451				 * we hit a nack ... in _this_ case we
2452				 * want to print out the range of packets
2453				 * that were acked, so we need to print
2454				 * the _previous_ packet number seperated
2455				 * from the first by a dash (-).  Since we
2456				 * already printed the first packet above,
2457				 * just print the final packet.  Don't
2458				 * do this if there will be a single-length
2459				 * range.
2460				 */
2461			} else if (last == i - 1 && start != last)
2462				printf("-%d", rxa->firstPacket + i - 1);
2463
2464		/*
2465		 * So, what's going on here?  We ran off the end of the
2466		 * ack list, and if we got a range we need to finish it up.
2467		 * So we need to determine if the last packet in the list
2468		 * was an ack (if so, then last will be set to it) and
2469		 * we need to see if the last range didn't start with the
2470		 * last packet (because if it _did_, then that would mean
2471		 * that the packet number has already been printed and
2472		 * we don't need to print it again).
2473		 */
2474
2475		if (last == i - 1 && start != last)
2476			printf("-%d", rxa->firstPacket + i - 1);
2477
2478		/*
2479		 * Same as above, just without comments
2480		 */
2481
2482		for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2483			if (rxa->acks[i] == RX_ACK_TYPE_NACK) {
2484				if (last == -2) {
2485					printf(" nacked %d",
2486					       rxa->firstPacket + i);
2487					start = i;
2488				} else if (last != i - 1) {
2489					printf(",%d", rxa->firstPacket + i);
2490					start = i;
2491				}
2492				last = i;
2493			} else if (last == i - 1 && start != last)
2494				printf("-%d", rxa->firstPacket + i - 1);
2495
2496		if (last == i - 1 && start != last)
2497			printf("-%d", rxa->firstPacket + i - 1);
2498
2499		bp += rxa->nAcks;
2500	}
2501
2502
2503	/*
2504	 * These are optional fields; depending on your version of AFS,
2505	 * you may or may not see them
2506	 */
2507
2508#define TRUNCRET(n)	if (snapend - bp + 1 <= n) return;
2509
2510	if (vflag > 1) {
2511		TRUNCRET(4);
2512		printf(" ifmtu");
2513		INTOUT();
2514
2515		TRUNCRET(4);
2516		printf(" maxmtu");
2517		INTOUT();
2518
2519		TRUNCRET(4);
2520		printf(" rwind");
2521		INTOUT();
2522
2523		TRUNCRET(4);
2524		printf(" maxpackets");
2525		INTOUT();
2526	}
2527
2528	return;
2529
2530trunc:
2531	printf(" [|ack]");
2532}
2533#undef TRUNCRET
2534