Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-rx.c
blob103bef891c55acc1358cbad06d50a2165e85dbf4
1 /* $NetBSD$ */
3 /*
4 * Copyright: (c) 2000 United States Government as represented by the
5 * Secretary of the Navy. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. The names of the authors may not be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 * This code unmangles RX packets. RX is the mutant form of RPC that AFS
27 * uses to communicate between clients and servers.
29 * In this code, I mainly concern myself with decoding the AFS calls, not
30 * with the guts of RX, per se.
32 * Bah. If I never look at rx_packet.h again, it will be too soon.
34 * Ken Hornstein <kenh@cmf.nrl.navy.mil>
37 #include <sys/cdefs.h>
38 #ifndef lint
39 #if 0
40 static const char rcsid[] _U_ =
41 "@(#) Header: /tcpdump/master/tcpdump/print-rx.c,v 1.37.2.2 2007/06/15 19:43:15 guy Exp";
42 #else
43 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
44 #endif
45 #endif
47 #ifdef HAVE_CONFIG_H
48 #include "config.h"
49 #endif
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <tcpdump-stdinc.h>
56 #include "interface.h"
57 #include "addrtoname.h"
58 #include "extract.h"
60 #include "rx.h"
62 #include "ip.h"
64 static struct tok rx_types[] = {
65 { RX_PACKET_TYPE_DATA, "data" },
66 { RX_PACKET_TYPE_ACK, "ack" },
67 { RX_PACKET_TYPE_BUSY, "busy" },
68 { RX_PACKET_TYPE_ABORT, "abort" },
69 { RX_PACKET_TYPE_ACKALL, "ackall" },
70 { RX_PACKET_TYPE_CHALLENGE, "challenge" },
71 { RX_PACKET_TYPE_RESPONSE, "response" },
72 { RX_PACKET_TYPE_DEBUG, "debug" },
73 { RX_PACKET_TYPE_PARAMS, "params" },
74 { RX_PACKET_TYPE_VERSION, "version" },
75 { 0, NULL },
78 static struct double_tok {
79 int flag; /* Rx flag */
80 int packetType; /* Packet type */
81 const char *s; /* Flag string */
82 } rx_flags[] = {
83 { RX_CLIENT_INITIATED, 0, "client-init" },
84 { RX_REQUEST_ACK, 0, "req-ack" },
85 { RX_LAST_PACKET, 0, "last-pckt" },
86 { RX_MORE_PACKETS, 0, "more-pckts" },
87 { RX_FREE_PACKET, 0, "free-pckt" },
88 { RX_SLOW_START_OK, RX_PACKET_TYPE_ACK, "slow-start" },
89 { RX_JUMBO_PACKET, RX_PACKET_TYPE_DATA, "jumbogram" }
92 static struct tok fs_req[] = {
93 { 130, "fetch-data" },
94 { 131, "fetch-acl" },
95 { 132, "fetch-status" },
96 { 133, "store-data" },
97 { 134, "store-acl" },
98 { 135, "store-status" },
99 { 136, "remove-file" },
100 { 137, "create-file" },
101 { 138, "rename" },
102 { 139, "symlink" },
103 { 140, "link" },
104 { 141, "makedir" },
105 { 142, "rmdir" },
106 { 143, "oldsetlock" },
107 { 144, "oldextlock" },
108 { 145, "oldrellock" },
109 { 146, "get-stats" },
110 { 147, "give-cbs" },
111 { 148, "get-vlinfo" },
112 { 149, "get-vlstats" },
113 { 150, "set-vlstats" },
114 { 151, "get-rootvl" },
115 { 152, "check-token" },
116 { 153, "get-time" },
117 { 154, "nget-vlinfo" },
118 { 155, "bulk-stat" },
119 { 156, "setlock" },
120 { 157, "extlock" },
121 { 158, "rellock" },
122 { 159, "xstat-ver" },
123 { 160, "get-xstat" },
124 { 161, "dfs-lookup" },
125 { 162, "dfs-flushcps" },
126 { 163, "dfs-symlink" },
127 { 220, "residency" },
128 { 0, NULL },
131 static struct tok cb_req[] = {
132 { 204, "callback" },
133 { 205, "initcb" },
134 { 206, "probe" },
135 { 207, "getlock" },
136 { 208, "getce" },
137 { 209, "xstatver" },
138 { 210, "getxstat" },
139 { 211, "initcb2" },
140 { 212, "whoareyou" },
141 { 213, "initcb3" },
142 { 214, "probeuuid" },
143 { 215, "getsrvprefs" },
144 { 216, "getcellservdb" },
145 { 217, "getlocalcell" },
146 { 218, "getcacheconf" },
147 { 0, NULL },
150 static struct tok pt_req[] = {
151 { 500, "new-user" },
152 { 501, "where-is-it" },
153 { 502, "dump-entry" },
154 { 503, "add-to-group" },
155 { 504, "name-to-id" },
156 { 505, "id-to-name" },
157 { 506, "delete" },
158 { 507, "remove-from-group" },
159 { 508, "get-cps" },
160 { 509, "new-entry" },
161 { 510, "list-max" },
162 { 511, "set-max" },
163 { 512, "list-entry" },
164 { 513, "change-entry" },
165 { 514, "list-elements" },
166 { 515, "same-mbr-of" },
167 { 516, "set-fld-sentry" },
168 { 517, "list-owned" },
169 { 518, "get-cps2" },
170 { 519, "get-host-cps" },
171 { 520, "update-entry" },
172 { 521, "list-entries" },
173 { 0, NULL },
176 static struct tok vldb_req[] = {
177 { 501, "create-entry" },
178 { 502, "delete-entry" },
179 { 503, "get-entry-by-id" },
180 { 504, "get-entry-by-name" },
181 { 505, "get-new-volume-id" },
182 { 506, "replace-entry" },
183 { 507, "update-entry" },
184 { 508, "setlock" },
185 { 509, "releaselock" },
186 { 510, "list-entry" },
187 { 511, "list-attrib" },
188 { 512, "linked-list" },
189 { 513, "get-stats" },
190 { 514, "probe" },
191 { 515, "get-addrs" },
192 { 516, "change-addr" },
193 { 517, "create-entry-n" },
194 { 518, "get-entry-by-id-n" },
195 { 519, "get-entry-by-name-n" },
196 { 520, "replace-entry-n" },
197 { 521, "list-entry-n" },
198 { 522, "list-attrib-n" },
199 { 523, "linked-list-n" },
200 { 524, "update-entry-by-name" },
201 { 525, "create-entry-u" },
202 { 526, "get-entry-by-id-u" },
203 { 527, "get-entry-by-name-u" },
204 { 528, "replace-entry-u" },
205 { 529, "list-entry-u" },
206 { 530, "list-attrib-u" },
207 { 531, "linked-list-u" },
208 { 532, "regaddr" },
209 { 533, "get-addrs-u" },
210 { 534, "list-attrib-n2" },
211 { 0, NULL },
214 static struct tok kauth_req[] = {
215 { 1, "auth-old" },
216 { 21, "authenticate" },
217 { 22, "authenticate-v2" },
218 { 2, "change-pw" },
219 { 3, "get-ticket-old" },
220 { 23, "get-ticket" },
221 { 4, "set-pw" },
222 { 5, "set-fields" },
223 { 6, "create-user" },
224 { 7, "delete-user" },
225 { 8, "get-entry" },
226 { 9, "list-entry" },
227 { 10, "get-stats" },
228 { 11, "debug" },
229 { 12, "get-pw" },
230 { 13, "get-random-key" },
231 { 14, "unlock" },
232 { 15, "lock-status" },
233 { 0, NULL },
236 static struct tok vol_req[] = {
237 { 100, "create-volume" },
238 { 101, "delete-volume" },
239 { 102, "restore" },
240 { 103, "forward" },
241 { 104, "end-trans" },
242 { 105, "clone" },
243 { 106, "set-flags" },
244 { 107, "get-flags" },
245 { 108, "trans-create" },
246 { 109, "dump" },
247 { 110, "get-nth-volume" },
248 { 111, "set-forwarding" },
249 { 112, "get-name" },
250 { 113, "get-status" },
251 { 114, "sig-restore" },
252 { 115, "list-partitions" },
253 { 116, "list-volumes" },
254 { 117, "set-id-types" },
255 { 118, "monitor" },
256 { 119, "partition-info" },
257 { 120, "reclone" },
258 { 121, "list-one-volume" },
259 { 122, "nuke" },
260 { 123, "set-date" },
261 { 124, "x-list-volumes" },
262 { 125, "x-list-one-volume" },
263 { 126, "set-info" },
264 { 127, "x-list-partitions" },
265 { 128, "forward-multiple" },
266 { 0, NULL },
269 static struct tok bos_req[] = {
270 { 80, "create-bnode" },
271 { 81, "delete-bnode" },
272 { 82, "set-status" },
273 { 83, "get-status" },
274 { 84, "enumerate-instance" },
275 { 85, "get-instance-info" },
276 { 86, "get-instance-parm" },
277 { 87, "add-superuser" },
278 { 88, "delete-superuser" },
279 { 89, "list-superusers" },
280 { 90, "list-keys" },
281 { 91, "add-key" },
282 { 92, "delete-key" },
283 { 93, "set-cell-name" },
284 { 94, "get-cell-name" },
285 { 95, "get-cell-host" },
286 { 96, "add-cell-host" },
287 { 97, "delete-cell-host" },
288 { 98, "set-t-status" },
289 { 99, "shutdown-all" },
290 { 100, "restart-all" },
291 { 101, "startup-all" },
292 { 102, "set-noauth-flag" },
293 { 103, "re-bozo" },
294 { 104, "restart" },
295 { 105, "start-bozo-install" },
296 { 106, "uninstall" },
297 { 107, "get-dates" },
298 { 108, "exec" },
299 { 109, "prune" },
300 { 110, "set-restart-time" },
301 { 111, "get-restart-time" },
302 { 112, "start-bozo-log" },
303 { 113, "wait-all" },
304 { 114, "get-instance-strings" },
305 { 115, "get-restricted" },
306 { 116, "set-restricted" },
307 { 0, NULL },
310 static struct tok ubik_req[] = {
311 { 10000, "vote-beacon" },
312 { 10001, "vote-debug-old" },
313 { 10002, "vote-sdebug-old" },
314 { 10003, "vote-getsyncsite" },
315 { 10004, "vote-debug" },
316 { 10005, "vote-sdebug" },
317 { 20000, "disk-begin" },
318 { 20001, "disk-commit" },
319 { 20002, "disk-lock" },
320 { 20003, "disk-write" },
321 { 20004, "disk-getversion" },
322 { 20005, "disk-getfile" },
323 { 20006, "disk-sendfile" },
324 { 20007, "disk-abort" },
325 { 20008, "disk-releaselocks" },
326 { 20009, "disk-truncate" },
327 { 20010, "disk-probe" },
328 { 20011, "disk-writev" },
329 { 20012, "disk-interfaceaddr" },
330 { 20013, "disk-setversion" },
331 { 0, NULL },
334 #define VOTE_LOW 10000
335 #define VOTE_HIGH 10005
336 #define DISK_LOW 20000
337 #define DISK_HIGH 20013
339 static struct tok cb_types[] = {
340 { 1, "exclusive" },
341 { 2, "shared" },
342 { 3, "dropped" },
343 { 0, NULL },
346 static struct tok ubik_lock_types[] = {
347 { 1, "read" },
348 { 2, "write" },
349 { 3, "wait" },
350 { 0, NULL },
353 static const char *voltype[] = { "read-write", "read-only", "backup" };
355 static struct tok afs_fs_errors[] = {
356 { 101, "salvage volume" },
357 { 102, "no such vnode" },
358 { 103, "no such volume" },
359 { 104, "volume exist" },
360 { 105, "no service" },
361 { 106, "volume offline" },
362 { 107, "voline online" },
363 { 108, "diskfull" },
364 { 109, "diskquota exceeded" },
365 { 110, "volume busy" },
366 { 111, "volume moved" },
367 { 112, "AFS IO error" },
368 { -100, "restarting fileserver" },
369 { 0, NULL }
373 * Reasons for acknowledging a packet
376 static struct tok rx_ack_reasons[] = {
377 { 1, "ack requested" },
378 { 2, "duplicate packet" },
379 { 3, "out of sequence" },
380 { 4, "exceeds window" },
381 { 5, "no buffer space" },
382 { 6, "ping" },
383 { 7, "ping response" },
384 { 8, "delay" },
385 { 9, "idle" },
386 { 0, NULL },
390 * Cache entries we keep around so we can figure out the RX opcode
391 * numbers for replies. This allows us to make sense of RX reply packets.
394 struct rx_cache_entry {
395 u_int32_t callnum; /* Call number (net order) */
396 struct in_addr client; /* client IP address (net order) */
397 struct in_addr server; /* server IP address (net order) */
398 int dport; /* server port (host order) */
399 u_short serviceId; /* Service identifier (net order) */
400 u_int32_t opcode; /* RX opcode (host order) */
403 #define RX_CACHE_SIZE 64
405 static struct rx_cache_entry rx_cache[RX_CACHE_SIZE];
407 static int rx_cache_next = 0;
408 static int rx_cache_hint = 0;
409 static void rx_cache_insert(const u_char *, const struct ip *, int);
410 static int rx_cache_find(const struct rx_header *, const struct ip *,
411 int, int32_t *);
413 static void fs_print(const u_char *, int);
414 static void fs_reply_print(const u_char *, int, int32_t);
415 static void acl_print(u_char *, int, u_char *);
416 static void cb_print(const u_char *, int);
417 static void cb_reply_print(const u_char *, int, int32_t);
418 static void prot_print(const u_char *, int);
419 static void prot_reply_print(const u_char *, int, int32_t);
420 static void vldb_print(const u_char *, int);
421 static void vldb_reply_print(const u_char *, int, int32_t);
422 static void kauth_print(const u_char *, int);
423 static void kauth_reply_print(const u_char *, int, int32_t);
424 static void vol_print(const u_char *, int);
425 static void vol_reply_print(const u_char *, int, int32_t);
426 static void bos_print(const u_char *, int);
427 static void bos_reply_print(const u_char *, int, int32_t);
428 static void ubik_print(const u_char *);
429 static void ubik_reply_print(const u_char *, int, int32_t);
431 static void rx_ack_print(const u_char *, int);
433 static int is_ubik(u_int32_t);
436 * Handle the rx-level packet. See if we know what port it's going to so
437 * we can peek at the afs call inside
440 void
441 rx_print(register const u_char *bp, int length, int sport, int dport,
442 u_char *bp2)
444 register struct rx_header *rxh;
445 int i;
446 int32_t opcode;
448 if (snapend - bp < (int)sizeof (struct rx_header)) {
449 printf(" [|rx] (%d)", length);
450 return;
453 rxh = (struct rx_header *) bp;
455 printf(" rx %s", tok2str(rx_types, "type %d", rxh->type));
457 if (vflag) {
458 int firstflag = 0;
460 if (vflag > 1)
461 printf(" cid %08x call# %d",
462 (int) EXTRACT_32BITS(&rxh->cid),
463 (int) EXTRACT_32BITS(&rxh->callNumber));
465 printf(" seq %d ser %d",
466 (int) EXTRACT_32BITS(&rxh->seq),
467 (int) EXTRACT_32BITS(&rxh->serial));
469 if (vflag > 2)
470 printf(" secindex %d serviceid %hu",
471 (int) rxh->securityIndex,
472 EXTRACT_16BITS(&rxh->serviceId));
474 if (vflag > 1)
475 for (i = 0; i < NUM_RX_FLAGS; i++) {
476 if (rxh->flags & rx_flags[i].flag &&
477 (!rx_flags[i].packetType ||
478 rxh->type == rx_flags[i].packetType)) {
479 if (!firstflag) {
480 firstflag = 1;
481 printf(" ");
482 } else {
483 printf(",");
485 printf("<%s>", rx_flags[i].s);
491 * Try to handle AFS calls that we know about. Check the destination
492 * port and make sure it's a data packet. Also, make sure the
493 * seq number is 1 (because otherwise it's a continuation packet,
494 * and we can't interpret that). Also, seems that reply packets
495 * do not have the client-init flag set, so we check for that
496 * as well.
499 if (rxh->type == RX_PACKET_TYPE_DATA &&
500 EXTRACT_32BITS(&rxh->seq) == 1 &&
501 rxh->flags & RX_CLIENT_INITIATED) {
504 * Insert this call into the call cache table, so we
505 * have a chance to print out replies
508 rx_cache_insert(bp, (const struct ip *) bp2, dport);
510 switch (dport) {
511 case FS_RX_PORT: /* AFS file service */
512 fs_print(bp, length);
513 break;
514 case CB_RX_PORT: /* AFS callback service */
515 cb_print(bp, length);
516 break;
517 case PROT_RX_PORT: /* AFS protection service */
518 prot_print(bp, length);
519 break;
520 case VLDB_RX_PORT: /* AFS VLDB service */
521 vldb_print(bp, length);
522 break;
523 case KAUTH_RX_PORT: /* AFS Kerberos auth service */
524 kauth_print(bp, length);
525 break;
526 case VOL_RX_PORT: /* AFS Volume service */
527 vol_print(bp, length);
528 break;
529 case BOS_RX_PORT: /* AFS BOS service */
530 bos_print(bp, length);
531 break;
532 default:
537 * If it's a reply (client-init is _not_ set, but seq is one)
538 * then look it up in the cache. If we find it, call the reply
539 * printing functions Note that we handle abort packets here,
540 * because printing out the return code can be useful at times.
543 } else if (((rxh->type == RX_PACKET_TYPE_DATA &&
544 EXTRACT_32BITS(&rxh->seq) == 1) ||
545 rxh->type == RX_PACKET_TYPE_ABORT) &&
546 (rxh->flags & RX_CLIENT_INITIATED) == 0 &&
547 rx_cache_find(rxh, (const struct ip *) bp2,
548 sport, &opcode)) {
550 switch (sport) {
551 case FS_RX_PORT: /* AFS file service */
552 fs_reply_print(bp, length, opcode);
553 break;
554 case CB_RX_PORT: /* AFS callback service */
555 cb_reply_print(bp, length, opcode);
556 break;
557 case PROT_RX_PORT: /* AFS PT service */
558 prot_reply_print(bp, length, opcode);
559 break;
560 case VLDB_RX_PORT: /* AFS VLDB service */
561 vldb_reply_print(bp, length, opcode);
562 break;
563 case KAUTH_RX_PORT: /* AFS Kerberos auth service */
564 kauth_reply_print(bp, length, opcode);
565 break;
566 case VOL_RX_PORT: /* AFS Volume service */
567 vol_reply_print(bp, length, opcode);
568 break;
569 case BOS_RX_PORT: /* AFS BOS service */
570 bos_reply_print(bp, length, opcode);
571 break;
572 default:
577 * If it's an RX ack packet, then use the appropriate ack decoding
578 * function (there isn't any service-specific information in the
579 * ack packet, so we can use one for all AFS services)
582 } else if (rxh->type == RX_PACKET_TYPE_ACK)
583 rx_ack_print(bp, length);
586 printf(" (%d)", length);
590 * Insert an entry into the cache. Taken from print-nfs.c
593 static void
594 rx_cache_insert(const u_char *bp, const struct ip *ip, int dport)
596 struct rx_cache_entry *rxent;
597 const struct rx_header *rxh = (const struct rx_header *) bp;
599 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t)))
600 return;
602 rxent = &rx_cache[rx_cache_next];
604 if (++rx_cache_next >= RX_CACHE_SIZE)
605 rx_cache_next = 0;
607 rxent->callnum = rxh->callNumber;
608 rxent->client = ip->ip_src;
609 rxent->server = ip->ip_dst;
610 rxent->dport = dport;
611 rxent->serviceId = rxh->serviceId;
612 rxent->opcode = EXTRACT_32BITS(bp + sizeof(struct rx_header));
616 * Lookup an entry in the cache. Also taken from print-nfs.c
618 * Note that because this is a reply, we're looking at the _source_
619 * port.
622 static int
623 rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport,
624 int32_t *opcode)
626 int i;
627 struct rx_cache_entry *rxent;
628 u_int32_t clip = ip->ip_dst.s_addr;
629 u_int32_t sip = ip->ip_src.s_addr;
631 /* Start the search where we last left off */
633 i = rx_cache_hint;
634 do {
635 rxent = &rx_cache[i];
636 if (rxent->callnum == rxh->callNumber &&
637 rxent->client.s_addr == clip &&
638 rxent->server.s_addr == sip &&
639 rxent->serviceId == rxh->serviceId &&
640 rxent->dport == sport) {
642 /* We got a match! */
644 rx_cache_hint = i;
645 *opcode = rxent->opcode;
646 return(1);
648 if (++i > RX_CACHE_SIZE)
649 i = 0;
650 } while (i != rx_cache_hint);
652 /* Our search failed */
653 return(0);
657 * These extrememly grody macros handle the printing of various AFS stuff.
660 #define FIDOUT() { unsigned long n1, n2, n3; \
661 TCHECK2(bp[0], sizeof(int32_t) * 3); \
662 n1 = EXTRACT_32BITS(bp); \
663 bp += sizeof(int32_t); \
664 n2 = EXTRACT_32BITS(bp); \
665 bp += sizeof(int32_t); \
666 n3 = EXTRACT_32BITS(bp); \
667 bp += sizeof(int32_t); \
668 printf(" fid %d/%d/%d", (int) n1, (int) n2, (int) n3); \
671 #define STROUT(MAX) { unsigned int i; \
672 TCHECK2(bp[0], sizeof(int32_t)); \
673 i = EXTRACT_32BITS(bp); \
674 if (i > (MAX)) \
675 goto trunc; \
676 bp += sizeof(int32_t); \
677 printf(" \""); \
678 if (fn_printn(bp, i, snapend)) \
679 goto trunc; \
680 printf("\""); \
681 bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \
684 #define INTOUT() { int i; \
685 TCHECK2(bp[0], sizeof(int32_t)); \
686 i = (int) EXTRACT_32BITS(bp); \
687 bp += sizeof(int32_t); \
688 printf(" %d", i); \
691 #define UINTOUT() { unsigned long i; \
692 TCHECK2(bp[0], sizeof(int32_t)); \
693 i = EXTRACT_32BITS(bp); \
694 bp += sizeof(int32_t); \
695 printf(" %lu", i); \
698 #define DATEOUT() { time_t t; struct tm *tm; char str[256]; \
699 TCHECK2(bp[0], sizeof(int32_t)); \
700 t = (time_t) EXTRACT_32BITS(bp); \
701 bp += sizeof(int32_t); \
702 tm = localtime(&t); \
703 strftime(str, 256, "%Y/%m/%d %T", tm); \
704 printf(" %s", str); \
707 #define STOREATTROUT() { unsigned long mask, i; \
708 TCHECK2(bp[0], (sizeof(int32_t)*6)); \
709 mask = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
710 if (mask) printf (" StoreStatus"); \
711 if (mask & 1) { printf(" date"); DATEOUT(); } \
712 else bp += sizeof(int32_t); \
713 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
714 if (mask & 2) printf(" owner %lu", i); \
715 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
716 if (mask & 4) printf(" group %lu", i); \
717 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
718 if (mask & 8) printf(" mode %lo", i & 07777); \
719 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
720 if (mask & 16) printf(" segsize %lu", i); \
721 /* undocumented in 3.3 docu */ \
722 if (mask & 1024) printf(" fsync"); \
725 #define UBIK_VERSIONOUT() {int32_t epoch; int32_t counter; \
726 TCHECK2(bp[0], sizeof(int32_t) * 2); \
727 epoch = EXTRACT_32BITS(bp); \
728 bp += sizeof(int32_t); \
729 counter = EXTRACT_32BITS(bp); \
730 bp += sizeof(int32_t); \
731 printf(" %d.%d", epoch, counter); \
734 #define AFSUUIDOUT() {u_int32_t temp; int i; \
735 TCHECK2(bp[0], 11*sizeof(u_int32_t)); \
736 temp = EXTRACT_32BITS(bp); \
737 bp += sizeof(u_int32_t); \
738 printf(" %08x", temp); \
739 temp = EXTRACT_32BITS(bp); \
740 bp += sizeof(u_int32_t); \
741 printf("%04x", temp); \
742 temp = EXTRACT_32BITS(bp); \
743 bp += sizeof(u_int32_t); \
744 printf("%04x", temp); \
745 for (i = 0; i < 8; i++) { \
746 temp = EXTRACT_32BITS(bp); \
747 bp += sizeof(u_int32_t); \
748 printf("%02x", (unsigned char) temp); \
753 * This is the sickest one of all
756 #define VECOUT(MAX) { u_char *sp; \
757 u_char s[AFSNAMEMAX]; \
758 int k; \
759 if ((MAX) + 1 > sizeof(s)) \
760 goto trunc; \
761 TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \
762 sp = s; \
763 for (k = 0; k < (MAX); k++) { \
764 *sp++ = (u_char) EXTRACT_32BITS(bp); \
765 bp += sizeof(int32_t); \
767 s[(MAX)] = '\0'; \
768 printf(" \""); \
769 fn_print(s, NULL); \
770 printf("\""); \
774 * Handle calls to the AFS file service (fs)
777 static void
778 fs_print(register const u_char *bp, int length)
780 int fs_op;
781 unsigned long i;
783 if (length <= (int)sizeof(struct rx_header))
784 return;
786 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
787 goto trunc;
791 * Print out the afs call we're invoking. The table used here was
792 * gleaned from fsint/afsint.xg
795 fs_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
797 printf(" fs call %s", tok2str(fs_req, "op#%d", fs_op));
800 * Print out arguments to some of the AFS calls. This stuff is
801 * all from afsint.xg
804 bp += sizeof(struct rx_header) + 4;
807 * Sigh. This is gross. Ritchie forgive me.
810 switch (fs_op) {
811 case 130: /* Fetch data */
812 FIDOUT();
813 printf(" offset");
814 UINTOUT();
815 printf(" length");
816 UINTOUT();
817 break;
818 case 131: /* Fetch ACL */
819 case 132: /* Fetch Status */
820 case 143: /* Old set lock */
821 case 144: /* Old extend lock */
822 case 145: /* Old release lock */
823 case 156: /* Set lock */
824 case 157: /* Extend lock */
825 case 158: /* Release lock */
826 FIDOUT();
827 break;
828 case 135: /* Store status */
829 FIDOUT();
830 STOREATTROUT();
831 break;
832 case 133: /* Store data */
833 FIDOUT();
834 STOREATTROUT();
835 printf(" offset");
836 UINTOUT();
837 printf(" length");
838 UINTOUT();
839 printf(" flen");
840 UINTOUT();
841 break;
842 case 134: /* Store ACL */
844 char a[AFSOPAQUEMAX+1];
845 FIDOUT();
846 TCHECK2(bp[0], 4);
847 i = EXTRACT_32BITS(bp);
848 bp += sizeof(int32_t);
849 TCHECK2(bp[0], i);
850 i = min(AFSOPAQUEMAX, i);
851 strncpy(a, (char *) bp, i);
852 a[i] = '\0';
853 acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
854 break;
856 case 137: /* Create file */
857 case 141: /* MakeDir */
858 FIDOUT();
859 STROUT(AFSNAMEMAX);
860 STOREATTROUT();
861 break;
862 case 136: /* Remove file */
863 case 142: /* Remove directory */
864 FIDOUT();
865 STROUT(AFSNAMEMAX);
866 break;
867 case 138: /* Rename file */
868 printf(" old");
869 FIDOUT();
870 STROUT(AFSNAMEMAX);
871 printf(" new");
872 FIDOUT();
873 STROUT(AFSNAMEMAX);
874 break;
875 case 139: /* Symlink */
876 FIDOUT();
877 STROUT(AFSNAMEMAX);
878 printf(" link to");
879 STROUT(AFSNAMEMAX);
880 break;
881 case 140: /* Link */
882 FIDOUT();
883 STROUT(AFSNAMEMAX);
884 printf(" link to");
885 FIDOUT();
886 break;
887 case 148: /* Get volume info */
888 STROUT(AFSNAMEMAX);
889 break;
890 case 149: /* Get volume stats */
891 case 150: /* Set volume stats */
892 printf(" volid");
893 UINTOUT();
894 break;
895 case 154: /* New get volume info */
896 printf(" volname");
897 STROUT(AFSNAMEMAX);
898 break;
899 case 155: /* Bulk stat */
901 unsigned long j;
902 TCHECK2(bp[0], 4);
903 j = EXTRACT_32BITS(bp);
904 bp += sizeof(int32_t);
906 for (i = 0; i < j; i++) {
907 FIDOUT();
908 if (i != j - 1)
909 printf(",");
911 if (j == 0)
912 printf(" <none!>");
914 default:
918 return;
920 trunc:
921 printf(" [|fs]");
925 * Handle replies to the AFS file service
928 static void
929 fs_reply_print(register const u_char *bp, int length, int32_t opcode)
931 unsigned long i;
932 struct rx_header *rxh;
934 if (length <= (int)sizeof(struct rx_header))
935 return;
937 rxh = (struct rx_header *) bp;
940 * Print out the afs call we're invoking. The table used here was
941 * gleaned from fsint/afsint.xg
944 printf(" fs reply %s", tok2str(fs_req, "op#%d", opcode));
946 bp += sizeof(struct rx_header);
949 * If it was a data packet, interpret the response
952 if (rxh->type == RX_PACKET_TYPE_DATA) {
953 switch (opcode) {
954 case 131: /* Fetch ACL */
956 char a[AFSOPAQUEMAX+1];
957 TCHECK2(bp[0], 4);
958 i = EXTRACT_32BITS(bp);
959 bp += sizeof(int32_t);
960 TCHECK2(bp[0], i);
961 i = min(AFSOPAQUEMAX, i);
962 strncpy(a, (char *) bp, i);
963 a[i] = '\0';
964 acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
965 break;
967 case 137: /* Create file */
968 case 141: /* MakeDir */
969 printf(" new");
970 FIDOUT();
971 break;
972 case 151: /* Get root volume */
973 printf(" root volume");
974 STROUT(AFSNAMEMAX);
975 break;
976 case 153: /* Get time */
977 DATEOUT();
978 break;
979 default:
982 } else if (rxh->type == RX_PACKET_TYPE_ABORT) {
983 int i;
986 * Otherwise, just print out the return code
988 TCHECK2(bp[0], sizeof(int32_t));
989 i = (int) EXTRACT_32BITS(bp);
990 bp += sizeof(int32_t);
992 printf(" error %s", tok2str(afs_fs_errors, "#%d", i));
993 } else {
994 printf(" strange fs reply of type %d", rxh->type);
997 return;
999 trunc:
1000 printf(" [|fs]");
1004 * Print out an AFS ACL string. An AFS ACL is a string that has the
1005 * following format:
1007 * <positive> <negative>
1008 * <uid1> <aclbits1>
1009 * ....
1011 * "positive" and "negative" are integers which contain the number of
1012 * positive and negative ACL's in the string. The uid/aclbits pair are
1013 * ASCII strings containing the UID/PTS record and and a ascii number
1014 * representing a logical OR of all the ACL permission bits
1017 static void
1018 acl_print(u_char *s, int maxsize, u_char *end)
1020 int pos, neg, acl;
1021 int n, i;
1022 char *user;
1023 char fmt[1024];
1025 if ((user = (char *)malloc(maxsize)) == NULL)
1026 return;
1028 if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
1029 goto finish;
1031 s += n;
1033 if (s > end)
1034 goto finish;
1037 * This wacky order preserves the order used by the "fs" command
1040 #define ACLOUT(acl) \
1041 if (acl & PRSFS_READ) \
1042 printf("r"); \
1043 if (acl & PRSFS_LOOKUP) \
1044 printf("l"); \
1045 if (acl & PRSFS_INSERT) \
1046 printf("i"); \
1047 if (acl & PRSFS_DELETE) \
1048 printf("d"); \
1049 if (acl & PRSFS_WRITE) \
1050 printf("w"); \
1051 if (acl & PRSFS_LOCK) \
1052 printf("k"); \
1053 if (acl & PRSFS_ADMINISTER) \
1054 printf("a");
1056 for (i = 0; i < pos; i++) {
1057 snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1);
1058 if (sscanf((char *) s, fmt, user, &acl, &n) != 2)
1059 goto finish;
1060 s += n;
1061 printf(" +{");
1062 fn_print((u_char *)user, NULL);
1063 printf(" ");
1064 ACLOUT(acl);
1065 printf("}");
1066 if (s > end)
1067 goto finish;
1070 for (i = 0; i < neg; i++) {
1071 snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1);
1072 if (sscanf((char *) s, fmt, user, &acl, &n) != 2)
1073 goto finish;
1074 s += n;
1075 printf(" -{");
1076 fn_print((u_char *)user, NULL);
1077 printf(" ");
1078 ACLOUT(acl);
1079 printf("}");
1080 if (s > end)
1081 goto finish;
1084 finish:
1085 free(user);
1086 return;
1089 #undef ACLOUT
1092 * Handle calls to the AFS callback service
1095 static void
1096 cb_print(register const u_char *bp, int length)
1098 int cb_op;
1099 unsigned long i;
1101 if (length <= (int)sizeof(struct rx_header))
1102 return;
1104 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1105 goto trunc;
1109 * Print out the afs call we're invoking. The table used here was
1110 * gleaned from fsint/afscbint.xg
1113 cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1115 printf(" cb call %s", tok2str(cb_req, "op#%d", cb_op));
1117 bp += sizeof(struct rx_header) + 4;
1120 * Print out the afs call we're invoking. The table used here was
1121 * gleaned from fsint/afscbint.xg
1124 switch (cb_op) {
1125 case 204: /* Callback */
1127 unsigned long j, t;
1128 TCHECK2(bp[0], 4);
1129 j = EXTRACT_32BITS(bp);
1130 bp += sizeof(int32_t);
1132 for (i = 0; i < j; i++) {
1133 FIDOUT();
1134 if (i != j - 1)
1135 printf(",");
1138 if (j == 0)
1139 printf(" <none!>");
1141 j = EXTRACT_32BITS(bp);
1142 bp += sizeof(int32_t);
1144 if (j != 0)
1145 printf(";");
1147 for (i = 0; i < j; i++) {
1148 printf(" ver");
1149 INTOUT();
1150 printf(" expires");
1151 DATEOUT();
1152 TCHECK2(bp[0], 4);
1153 t = EXTRACT_32BITS(bp);
1154 bp += sizeof(int32_t);
1155 tok2str(cb_types, "type %d", t);
1158 case 214: {
1159 printf(" afsuuid");
1160 AFSUUIDOUT();
1161 break;
1163 default:
1167 return;
1169 trunc:
1170 printf(" [|cb]");
1174 * Handle replies to the AFS Callback Service
1177 static void
1178 cb_reply_print(register const u_char *bp, int length, int32_t opcode)
1180 struct rx_header *rxh;
1182 if (length <= (int)sizeof(struct rx_header))
1183 return;
1185 rxh = (struct rx_header *) bp;
1188 * Print out the afs call we're invoking. The table used here was
1189 * gleaned from fsint/afscbint.xg
1192 printf(" cb reply %s", tok2str(cb_req, "op#%d", opcode));
1194 bp += sizeof(struct rx_header);
1197 * If it was a data packet, interpret the response.
1200 if (rxh->type == RX_PACKET_TYPE_DATA)
1201 switch (opcode) {
1202 case 213: /* InitCallBackState3 */
1203 AFSUUIDOUT();
1204 break;
1205 default:
1208 else {
1210 * Otherwise, just print out the return code
1212 printf(" errcode");
1213 INTOUT();
1216 return;
1218 trunc:
1219 printf(" [|cb]");
1223 * Handle calls to the AFS protection database server
1226 static void
1227 prot_print(register const u_char *bp, int length)
1229 unsigned long i;
1230 int pt_op;
1232 if (length <= (int)sizeof(struct rx_header))
1233 return;
1235 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1236 goto trunc;
1240 * Print out the afs call we're invoking. The table used here was
1241 * gleaned from ptserver/ptint.xg
1244 pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1246 printf(" pt");
1248 if (is_ubik(pt_op)) {
1249 ubik_print(bp);
1250 return;
1253 printf(" call %s", tok2str(pt_req, "op#%d", pt_op));
1256 * Decode some of the arguments to the PT calls
1259 bp += sizeof(struct rx_header) + 4;
1261 switch (pt_op) {
1262 case 500: /* I New User */
1263 STROUT(PRNAMEMAX);
1264 printf(" id");
1265 INTOUT();
1266 printf(" oldid");
1267 INTOUT();
1268 break;
1269 case 501: /* Where is it */
1270 case 506: /* Delete */
1271 case 508: /* Get CPS */
1272 case 512: /* List entry */
1273 case 514: /* List elements */
1274 case 517: /* List owned */
1275 case 518: /* Get CPS2 */
1276 case 519: /* Get host CPS */
1277 printf(" id");
1278 INTOUT();
1279 break;
1280 case 502: /* Dump entry */
1281 printf(" pos");
1282 INTOUT();
1283 break;
1284 case 503: /* Add to group */
1285 case 507: /* Remove from group */
1286 case 515: /* Is a member of? */
1287 printf(" uid");
1288 INTOUT();
1289 printf(" gid");
1290 INTOUT();
1291 break;
1292 case 504: /* Name to ID */
1294 unsigned long j;
1295 TCHECK2(bp[0], 4);
1296 j = EXTRACT_32BITS(bp);
1297 bp += sizeof(int32_t);
1300 * Who designed this chicken-shit protocol?
1302 * Each character is stored as a 32-bit
1303 * integer!
1306 for (i = 0; i < j; i++) {
1307 VECOUT(PRNAMEMAX);
1309 if (j == 0)
1310 printf(" <none!>");
1312 break;
1313 case 505: /* Id to name */
1315 unsigned long j;
1316 printf(" ids:");
1317 TCHECK2(bp[0], 4);
1318 i = EXTRACT_32BITS(bp);
1319 bp += sizeof(int32_t);
1320 for (j = 0; j < i; j++)
1321 INTOUT();
1322 if (j == 0)
1323 printf(" <none!>");
1325 break;
1326 case 509: /* New entry */
1327 STROUT(PRNAMEMAX);
1328 printf(" flag");
1329 INTOUT();
1330 printf(" oid");
1331 INTOUT();
1332 break;
1333 case 511: /* Set max */
1334 printf(" id");
1335 INTOUT();
1336 printf(" gflag");
1337 INTOUT();
1338 break;
1339 case 513: /* Change entry */
1340 printf(" id");
1341 INTOUT();
1342 STROUT(PRNAMEMAX);
1343 printf(" oldid");
1344 INTOUT();
1345 printf(" newid");
1346 INTOUT();
1347 break;
1348 case 520: /* Update entry */
1349 printf(" id");
1350 INTOUT();
1351 STROUT(PRNAMEMAX);
1352 break;
1353 default:
1358 return;
1360 trunc:
1361 printf(" [|pt]");
1365 * Handle replies to the AFS protection service
1368 static void
1369 prot_reply_print(register const u_char *bp, int length, int32_t opcode)
1371 struct rx_header *rxh;
1372 unsigned long i;
1374 if (length < (int)sizeof(struct rx_header))
1375 return;
1377 rxh = (struct rx_header *) bp;
1380 * Print out the afs call we're invoking. The table used here was
1381 * gleaned from ptserver/ptint.xg. Check to see if it's a
1382 * Ubik call, however.
1385 printf(" pt");
1387 if (is_ubik(opcode)) {
1388 ubik_reply_print(bp, length, opcode);
1389 return;
1392 printf(" reply %s", tok2str(pt_req, "op#%d", opcode));
1394 bp += sizeof(struct rx_header);
1397 * If it was a data packet, interpret the response
1400 if (rxh->type == RX_PACKET_TYPE_DATA)
1401 switch (opcode) {
1402 case 504: /* Name to ID */
1404 unsigned long j;
1405 printf(" ids:");
1406 TCHECK2(bp[0], 4);
1407 i = EXTRACT_32BITS(bp);
1408 bp += sizeof(int32_t);
1409 for (j = 0; j < i; j++)
1410 INTOUT();
1411 if (j == 0)
1412 printf(" <none!>");
1414 break;
1415 case 505: /* ID to name */
1417 unsigned long j;
1418 TCHECK2(bp[0], 4);
1419 j = EXTRACT_32BITS(bp);
1420 bp += sizeof(int32_t);
1423 * Who designed this chicken-shit protocol?
1425 * Each character is stored as a 32-bit
1426 * integer!
1429 for (i = 0; i < j; i++) {
1430 VECOUT(PRNAMEMAX);
1432 if (j == 0)
1433 printf(" <none!>");
1435 break;
1436 case 508: /* Get CPS */
1437 case 514: /* List elements */
1438 case 517: /* List owned */
1439 case 518: /* Get CPS2 */
1440 case 519: /* Get host CPS */
1442 unsigned long j;
1443 TCHECK2(bp[0], 4);
1444 j = EXTRACT_32BITS(bp);
1445 bp += sizeof(int32_t);
1446 for (i = 0; i < j; i++) {
1447 INTOUT();
1449 if (j == 0)
1450 printf(" <none!>");
1452 break;
1453 case 510: /* List max */
1454 printf(" maxuid");
1455 INTOUT();
1456 printf(" maxgid");
1457 INTOUT();
1458 break;
1459 default:
1462 else {
1464 * Otherwise, just print out the return code
1466 printf(" errcode");
1467 INTOUT();
1470 return;
1472 trunc:
1473 printf(" [|pt]");
1477 * Handle calls to the AFS volume location database service
1480 static void
1481 vldb_print(register const u_char *bp, int length)
1483 int vldb_op;
1484 unsigned long i;
1486 if (length <= (int)sizeof(struct rx_header))
1487 return;
1489 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1490 goto trunc;
1494 * Print out the afs call we're invoking. The table used here was
1495 * gleaned from vlserver/vldbint.xg
1498 vldb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1500 printf(" vldb");
1502 if (is_ubik(vldb_op)) {
1503 ubik_print(bp);
1504 return;
1506 printf(" call %s", tok2str(vldb_req, "op#%d", vldb_op));
1509 * Decode some of the arguments to the VLDB calls
1512 bp += sizeof(struct rx_header) + 4;
1514 switch (vldb_op) {
1515 case 501: /* Create new volume */
1516 case 517: /* Create entry N */
1517 VECOUT(VLNAMEMAX);
1518 break;
1519 case 502: /* Delete entry */
1520 case 503: /* Get entry by ID */
1521 case 507: /* Update entry */
1522 case 508: /* Set lock */
1523 case 509: /* Release lock */
1524 case 518: /* Get entry by ID N */
1525 printf(" volid");
1526 INTOUT();
1527 TCHECK2(bp[0], sizeof(int32_t));
1528 i = EXTRACT_32BITS(bp);
1529 bp += sizeof(int32_t);
1530 if (i <= 2)
1531 printf(" type %s", voltype[i]);
1532 break;
1533 case 504: /* Get entry by name */
1534 case 519: /* Get entry by name N */
1535 case 524: /* Update entry by name */
1536 case 527: /* Get entry by name U */
1537 STROUT(VLNAMEMAX);
1538 break;
1539 case 505: /* Get new vol id */
1540 printf(" bump");
1541 INTOUT();
1542 break;
1543 case 506: /* Replace entry */
1544 case 520: /* Replace entry N */
1545 printf(" volid");
1546 INTOUT();
1547 TCHECK2(bp[0], sizeof(int32_t));
1548 i = EXTRACT_32BITS(bp);
1549 bp += sizeof(int32_t);
1550 if (i <= 2)
1551 printf(" type %s", voltype[i]);
1552 VECOUT(VLNAMEMAX);
1553 break;
1554 case 510: /* List entry */
1555 case 521: /* List entry N */
1556 printf(" index");
1557 INTOUT();
1558 break;
1559 default:
1563 return;
1565 trunc:
1566 printf(" [|vldb]");
1570 * Handle replies to the AFS volume location database service
1573 static void
1574 vldb_reply_print(register const u_char *bp, int length, int32_t opcode)
1576 struct rx_header *rxh;
1577 unsigned long i;
1579 if (length < (int)sizeof(struct rx_header))
1580 return;
1582 rxh = (struct rx_header *) bp;
1585 * Print out the afs call we're invoking. The table used here was
1586 * gleaned from vlserver/vldbint.xg. Check to see if it's a
1587 * Ubik call, however.
1590 printf(" vldb");
1592 if (is_ubik(opcode)) {
1593 ubik_reply_print(bp, length, opcode);
1594 return;
1597 printf(" reply %s", tok2str(vldb_req, "op#%d", opcode));
1599 bp += sizeof(struct rx_header);
1602 * If it was a data packet, interpret the response
1605 if (rxh->type == RX_PACKET_TYPE_DATA)
1606 switch (opcode) {
1607 case 510: /* List entry */
1608 printf(" count");
1609 INTOUT();
1610 printf(" nextindex");
1611 INTOUT();
1612 case 503: /* Get entry by id */
1613 case 504: /* Get entry by name */
1614 { unsigned long nservers, j;
1615 VECOUT(VLNAMEMAX);
1616 TCHECK2(bp[0], sizeof(int32_t));
1617 bp += sizeof(int32_t);
1618 printf(" numservers");
1619 TCHECK2(bp[0], sizeof(int32_t));
1620 nservers = EXTRACT_32BITS(bp);
1621 bp += sizeof(int32_t);
1622 printf(" %lu", nservers);
1623 printf(" servers");
1624 for (i = 0; i < 8; i++) {
1625 TCHECK2(bp[0], sizeof(int32_t));
1626 if (i < nservers)
1627 printf(" %s",
1628 intoa(((struct in_addr *) bp)->s_addr));
1629 bp += sizeof(int32_t);
1631 printf(" partitions");
1632 for (i = 0; i < 8; i++) {
1633 TCHECK2(bp[0], sizeof(int32_t));
1634 j = EXTRACT_32BITS(bp);
1635 if (i < nservers && j <= 26)
1636 printf(" %c", 'a' + (int)j);
1637 else if (i < nservers)
1638 printf(" %lu", j);
1639 bp += sizeof(int32_t);
1641 TCHECK2(bp[0], 8 * sizeof(int32_t));
1642 bp += 8 * sizeof(int32_t);
1643 printf(" rwvol");
1644 UINTOUT();
1645 printf(" rovol");
1646 UINTOUT();
1647 printf(" backup");
1648 UINTOUT();
1650 break;
1651 case 505: /* Get new volume ID */
1652 printf(" newvol");
1653 UINTOUT();
1654 break;
1655 case 521: /* List entry */
1656 case 529: /* List entry U */
1657 printf(" count");
1658 INTOUT();
1659 printf(" nextindex");
1660 INTOUT();
1661 case 518: /* Get entry by ID N */
1662 case 519: /* Get entry by name N */
1663 { unsigned long nservers, j;
1664 VECOUT(VLNAMEMAX);
1665 printf(" numservers");
1666 TCHECK2(bp[0], sizeof(int32_t));
1667 nservers = EXTRACT_32BITS(bp);
1668 bp += sizeof(int32_t);
1669 printf(" %lu", nservers);
1670 printf(" servers");
1671 for (i = 0; i < 13; i++) {
1672 TCHECK2(bp[0], sizeof(int32_t));
1673 if (i < nservers)
1674 printf(" %s",
1675 intoa(((struct in_addr *) bp)->s_addr));
1676 bp += sizeof(int32_t);
1678 printf(" partitions");
1679 for (i = 0; i < 13; i++) {
1680 TCHECK2(bp[0], sizeof(int32_t));
1681 j = EXTRACT_32BITS(bp);
1682 if (i < nservers && j <= 26)
1683 printf(" %c", 'a' + (int)j);
1684 else if (i < nservers)
1685 printf(" %lu", j);
1686 bp += sizeof(int32_t);
1688 TCHECK2(bp[0], 13 * sizeof(int32_t));
1689 bp += 13 * sizeof(int32_t);
1690 printf(" rwvol");
1691 UINTOUT();
1692 printf(" rovol");
1693 UINTOUT();
1694 printf(" backup");
1695 UINTOUT();
1697 break;
1698 case 526: /* Get entry by ID U */
1699 case 527: /* Get entry by name U */
1700 { unsigned long nservers, j;
1701 VECOUT(VLNAMEMAX);
1702 printf(" numservers");
1703 TCHECK2(bp[0], sizeof(int32_t));
1704 nservers = EXTRACT_32BITS(bp);
1705 bp += sizeof(int32_t);
1706 printf(" %lu", nservers);
1707 printf(" servers");
1708 for (i = 0; i < 13; i++) {
1709 if (i < nservers) {
1710 printf(" afsuuid");
1711 AFSUUIDOUT();
1712 } else {
1713 TCHECK2(bp[0], 44);
1714 bp += 44;
1717 TCHECK2(bp[0], 4 * 13);
1718 bp += 4 * 13;
1719 printf(" partitions");
1720 for (i = 0; i < 13; i++) {
1721 TCHECK2(bp[0], sizeof(int32_t));
1722 j = EXTRACT_32BITS(bp);
1723 if (i < nservers && j <= 26)
1724 printf(" %c", 'a' + (int)j);
1725 else if (i < nservers)
1726 printf(" %lu", j);
1727 bp += sizeof(int32_t);
1729 TCHECK2(bp[0], 13 * sizeof(int32_t));
1730 bp += 13 * sizeof(int32_t);
1731 printf(" rwvol");
1732 UINTOUT();
1733 printf(" rovol");
1734 UINTOUT();
1735 printf(" backup");
1736 UINTOUT();
1738 default:
1742 else {
1744 * Otherwise, just print out the return code
1746 printf(" errcode");
1747 INTOUT();
1750 return;
1752 trunc:
1753 printf(" [|vldb]");
1757 * Handle calls to the AFS Kerberos Authentication service
1760 static void
1761 kauth_print(register const u_char *bp, int length)
1763 int kauth_op;
1765 if (length <= (int)sizeof(struct rx_header))
1766 return;
1768 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1769 goto trunc;
1773 * Print out the afs call we're invoking. The table used here was
1774 * gleaned from kauth/kauth.rg
1777 kauth_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1779 printf(" kauth");
1781 if (is_ubik(kauth_op)) {
1782 ubik_print(bp);
1783 return;
1787 printf(" call %s", tok2str(kauth_req, "op#%d", kauth_op));
1790 * Decode some of the arguments to the KA calls
1793 bp += sizeof(struct rx_header) + 4;
1795 switch (kauth_op) {
1796 case 1: /* Authenticate old */;
1797 case 21: /* Authenticate */
1798 case 22: /* Authenticate-V2 */
1799 case 2: /* Change PW */
1800 case 5: /* Set fields */
1801 case 6: /* Create user */
1802 case 7: /* Delete user */
1803 case 8: /* Get entry */
1804 case 14: /* Unlock */
1805 case 15: /* Lock status */
1806 printf(" principal");
1807 STROUT(KANAMEMAX);
1808 STROUT(KANAMEMAX);
1809 break;
1810 case 3: /* GetTicket-old */
1811 case 23: /* GetTicket */
1813 int i;
1814 printf(" kvno");
1815 INTOUT();
1816 printf(" domain");
1817 STROUT(KANAMEMAX);
1818 TCHECK2(bp[0], sizeof(int32_t));
1819 i = (int) EXTRACT_32BITS(bp);
1820 bp += sizeof(int32_t);
1821 TCHECK2(bp[0], i);
1822 bp += i;
1823 printf(" principal");
1824 STROUT(KANAMEMAX);
1825 STROUT(KANAMEMAX);
1826 break;
1828 case 4: /* Set Password */
1829 printf(" principal");
1830 STROUT(KANAMEMAX);
1831 STROUT(KANAMEMAX);
1832 printf(" kvno");
1833 INTOUT();
1834 break;
1835 case 12: /* Get password */
1836 printf(" name");
1837 STROUT(KANAMEMAX);
1838 break;
1839 default:
1843 return;
1845 trunc:
1846 printf(" [|kauth]");
1850 * Handle replies to the AFS Kerberos Authentication Service
1853 static void
1854 kauth_reply_print(register const u_char *bp, int length, int32_t opcode)
1856 struct rx_header *rxh;
1858 if (length <= (int)sizeof(struct rx_header))
1859 return;
1861 rxh = (struct rx_header *) bp;
1864 * Print out the afs call we're invoking. The table used here was
1865 * gleaned from kauth/kauth.rg
1868 printf(" kauth");
1870 if (is_ubik(opcode)) {
1871 ubik_reply_print(bp, length, opcode);
1872 return;
1875 printf(" reply %s", tok2str(kauth_req, "op#%d", opcode));
1877 bp += sizeof(struct rx_header);
1880 * If it was a data packet, interpret the response.
1883 if (rxh->type == RX_PACKET_TYPE_DATA)
1884 /* Well, no, not really. Leave this for later */
1886 else {
1888 * Otherwise, just print out the return code
1890 printf(" errcode");
1891 INTOUT();
1894 return;
1896 trunc:
1897 printf(" [|kauth]");
1901 * Handle calls to the AFS Volume location service
1904 static void
1905 vol_print(register const u_char *bp, int length)
1907 int vol_op;
1909 if (length <= (int)sizeof(struct rx_header))
1910 return;
1912 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1913 goto trunc;
1917 * Print out the afs call we're invoking. The table used here was
1918 * gleaned from volser/volint.xg
1921 vol_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1923 printf(" vol call %s", tok2str(vol_req, "op#%d", vol_op));
1926 * Normally there would be a switch statement here to decode the
1927 * arguments to the AFS call, but since I don't have access to
1928 * an AFS server (yet) and I'm not an AFS admin, I can't
1929 * test any of these calls. Leave this blank for now.
1932 return;
1934 trunc:
1935 printf(" [|vol]");
1939 * Handle replies to the AFS Volume Service
1942 static void
1943 vol_reply_print(register const u_char *bp, int length, int32_t opcode)
1945 struct rx_header *rxh;
1947 if (length <= (int)sizeof(struct rx_header))
1948 return;
1950 rxh = (struct rx_header *) bp;
1953 * Print out the afs call we're invoking. The table used here was
1954 * gleaned from volser/volint.xg
1957 printf(" vol reply %s", tok2str(vol_req, "op#%d", opcode));
1959 bp += sizeof(struct rx_header);
1962 * If it was a data packet, interpret the response.
1965 if (rxh->type == RX_PACKET_TYPE_DATA)
1966 /* Well, no, not really. Leave this for later */
1968 else {
1970 * Otherwise, just print out the return code
1972 printf(" errcode");
1973 INTOUT();
1976 return;
1978 trunc:
1979 printf(" [|vol]");
1983 * Handle calls to the AFS BOS service
1986 static void
1987 bos_print(register const u_char *bp, int length)
1989 int bos_op;
1991 if (length <= (int)sizeof(struct rx_header))
1992 return;
1994 if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) {
1995 goto trunc;
1999 * Print out the afs call we're invoking. The table used here was
2000 * gleaned from bozo/bosint.xg
2003 bos_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2005 printf(" bos call %s", tok2str(bos_req, "op#%d", bos_op));
2008 * Decode some of the arguments to the BOS calls
2011 bp += sizeof(struct rx_header) + 4;
2013 switch (bos_op) {
2014 case 80: /* Create B node */
2015 printf(" type");
2016 STROUT(BOSNAMEMAX);
2017 printf(" instance");
2018 STROUT(BOSNAMEMAX);
2019 break;
2020 case 81: /* Delete B node */
2021 case 83: /* Get status */
2022 case 85: /* Get instance info */
2023 case 87: /* Add super user */
2024 case 88: /* Delete super user */
2025 case 93: /* Set cell name */
2026 case 96: /* Add cell host */
2027 case 97: /* Delete cell host */
2028 case 104: /* Restart */
2029 case 106: /* Uninstall */
2030 case 108: /* Exec */
2031 case 112: /* Getlog */
2032 case 114: /* Get instance strings */
2033 STROUT(BOSNAMEMAX);
2034 break;
2035 case 82: /* Set status */
2036 case 98: /* Set T status */
2037 STROUT(BOSNAMEMAX);
2038 printf(" status");
2039 INTOUT();
2040 break;
2041 case 86: /* Get instance parm */
2042 STROUT(BOSNAMEMAX);
2043 printf(" num");
2044 INTOUT();
2045 break;
2046 case 84: /* Enumerate instance */
2047 case 89: /* List super users */
2048 case 90: /* List keys */
2049 case 91: /* Add key */
2050 case 92: /* Delete key */
2051 case 95: /* Get cell host */
2052 INTOUT();
2053 break;
2054 case 105: /* Install */
2055 STROUT(BOSNAMEMAX);
2056 printf(" size");
2057 INTOUT();
2058 printf(" flags");
2059 INTOUT();
2060 printf(" date");
2061 INTOUT();
2062 break;
2063 default:
2067 return;
2069 trunc:
2070 printf(" [|bos]");
2074 * Handle replies to the AFS BOS Service
2077 static void
2078 bos_reply_print(register const u_char *bp, int length, int32_t opcode)
2080 struct rx_header *rxh;
2082 if (length <= (int)sizeof(struct rx_header))
2083 return;
2085 rxh = (struct rx_header *) bp;
2088 * Print out the afs call we're invoking. The table used here was
2089 * gleaned from volser/volint.xg
2092 printf(" bos reply %s", tok2str(bos_req, "op#%d", opcode));
2094 bp += sizeof(struct rx_header);
2097 * If it was a data packet, interpret the response.
2100 if (rxh->type == RX_PACKET_TYPE_DATA)
2101 /* Well, no, not really. Leave this for later */
2103 else {
2105 * Otherwise, just print out the return code
2107 printf(" errcode");
2108 INTOUT();
2111 return;
2113 trunc:
2114 printf(" [|bos]");
2118 * Check to see if this is a Ubik opcode.
2121 static int
2122 is_ubik(u_int32_t opcode)
2124 if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
2125 (opcode >= DISK_LOW && opcode <= DISK_HIGH))
2126 return(1);
2127 else
2128 return(0);
2132 * Handle Ubik opcodes to any one of the replicated database services
2135 static void
2136 ubik_print(register const u_char *bp)
2138 int ubik_op;
2139 int32_t temp;
2142 * Print out the afs call we're invoking. The table used here was
2143 * gleaned from ubik/ubik_int.xg
2146 ubik_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2148 printf(" ubik call %s", tok2str(ubik_req, "op#%d", ubik_op));
2151 * Decode some of the arguments to the Ubik calls
2154 bp += sizeof(struct rx_header) + 4;
2156 switch (ubik_op) {
2157 case 10000: /* Beacon */
2158 TCHECK2(bp[0], 4);
2159 temp = EXTRACT_32BITS(bp);
2160 bp += sizeof(int32_t);
2161 printf(" syncsite %s", temp ? "yes" : "no");
2162 printf(" votestart");
2163 DATEOUT();
2164 printf(" dbversion");
2165 UBIK_VERSIONOUT();
2166 printf(" tid");
2167 UBIK_VERSIONOUT();
2168 break;
2169 case 10003: /* Get sync site */
2170 printf(" site");
2171 UINTOUT();
2172 break;
2173 case 20000: /* Begin */
2174 case 20001: /* Commit */
2175 case 20007: /* Abort */
2176 case 20008: /* Release locks */
2177 case 20010: /* Writev */
2178 printf(" tid");
2179 UBIK_VERSIONOUT();
2180 break;
2181 case 20002: /* Lock */
2182 printf(" tid");
2183 UBIK_VERSIONOUT();
2184 printf(" file");
2185 INTOUT();
2186 printf(" pos");
2187 INTOUT();
2188 printf(" length");
2189 INTOUT();
2190 temp = EXTRACT_32BITS(bp);
2191 bp += sizeof(int32_t);
2192 tok2str(ubik_lock_types, "type %d", temp);
2193 break;
2194 case 20003: /* Write */
2195 printf(" tid");
2196 UBIK_VERSIONOUT();
2197 printf(" file");
2198 INTOUT();
2199 printf(" pos");
2200 INTOUT();
2201 break;
2202 case 20005: /* Get file */
2203 printf(" file");
2204 INTOUT();
2205 break;
2206 case 20006: /* Send file */
2207 printf(" file");
2208 INTOUT();
2209 printf(" length");
2210 INTOUT();
2211 printf(" dbversion");
2212 UBIK_VERSIONOUT();
2213 break;
2214 case 20009: /* Truncate */
2215 printf(" tid");
2216 UBIK_VERSIONOUT();
2217 printf(" file");
2218 INTOUT();
2219 printf(" length");
2220 INTOUT();
2221 break;
2222 case 20012: /* Set version */
2223 printf(" tid");
2224 UBIK_VERSIONOUT();
2225 printf(" oldversion");
2226 UBIK_VERSIONOUT();
2227 printf(" newversion");
2228 UBIK_VERSIONOUT();
2229 break;
2230 default:
2234 return;
2236 trunc:
2237 printf(" [|ubik]");
2241 * Handle Ubik replies to any one of the replicated database services
2244 static void
2245 ubik_reply_print(register const u_char *bp, int length, int32_t opcode)
2247 struct rx_header *rxh;
2249 if (length < (int)sizeof(struct rx_header))
2250 return;
2252 rxh = (struct rx_header *) bp;
2255 * Print out the ubik call we're invoking. This table was gleaned
2256 * from ubik/ubik_int.xg
2259 printf(" ubik reply %s", tok2str(ubik_req, "op#%d", opcode));
2261 bp += sizeof(struct rx_header);
2264 * If it was a data packet, print out the arguments to the Ubik calls
2267 if (rxh->type == RX_PACKET_TYPE_DATA)
2268 switch (opcode) {
2269 case 10000: /* Beacon */
2270 printf(" vote no");
2271 break;
2272 case 20004: /* Get version */
2273 printf(" dbversion");
2274 UBIK_VERSIONOUT();
2275 break;
2276 default:
2281 * Otherwise, print out "yes" it it was a beacon packet (because
2282 * that's how yes votes are returned, go figure), otherwise
2283 * just print out the error code.
2286 else
2287 switch (opcode) {
2288 case 10000: /* Beacon */
2289 printf(" vote yes until");
2290 DATEOUT();
2291 break;
2292 default:
2293 printf(" errcode");
2294 INTOUT();
2297 return;
2299 trunc:
2300 printf(" [|ubik]");
2304 * Handle RX ACK packets.
2307 static void
2308 rx_ack_print(register const u_char *bp, int length)
2310 struct rx_ackPacket *rxa;
2311 int i, start, last;
2312 u_int32_t firstPacket;
2314 if (length < (int)sizeof(struct rx_header))
2315 return;
2317 bp += sizeof(struct rx_header);
2320 * This may seem a little odd .... the rx_ackPacket structure
2321 * contains an array of individual packet acknowledgements
2322 * (used for selective ack/nack), but since it's variable in size,
2323 * we don't want to truncate based on the size of the whole
2324 * rx_ackPacket structure.
2327 TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS);
2329 rxa = (struct rx_ackPacket *) bp;
2330 bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS);
2333 * Print out a few useful things from the ack packet structure
2336 if (vflag > 2)
2337 printf(" bufspace %d maxskew %d",
2338 (int) EXTRACT_16BITS(&rxa->bufferSpace),
2339 (int) EXTRACT_16BITS(&rxa->maxSkew));
2341 firstPacket = EXTRACT_32BITS(&rxa->firstPacket);
2342 printf(" first %d serial %d reason %s",
2343 firstPacket, EXTRACT_32BITS(&rxa->serial),
2344 tok2str(rx_ack_reasons, "#%d", (int) rxa->reason));
2347 * Okay, now we print out the ack array. The way _this_ works
2348 * is that we start at "first", and step through the ack array.
2349 * If we have a contiguous range of acks/nacks, try to
2350 * collapse them into a range.
2352 * If you're really clever, you might have noticed that this
2353 * doesn't seem quite correct. Specifically, due to structure
2354 * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually
2355 * yield the start of the ack array (because RX_MAXACKS is 255
2356 * and the structure will likely get padded to a 2 or 4 byte
2357 * boundary). However, this is the way it's implemented inside
2358 * of AFS - the start of the extra fields are at
2359 * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_
2360 * the exact start of the ack array. Sigh. That's why we aren't
2361 * using bp, but instead use rxa->acks[]. But nAcks gets added
2362 * to bp after this, so bp ends up at the right spot. Go figure.
2365 if (rxa->nAcks != 0) {
2367 TCHECK2(bp[0], rxa->nAcks);
2370 * Sigh, this is gross, but it seems to work to collapse
2371 * ranges correctly.
2374 for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2375 if (rxa->acks[i] == RX_ACK_TYPE_ACK) {
2378 * I figured this deserved _some_ explanation.
2379 * First, print "acked" and the packet seq
2380 * number if this is the first time we've
2381 * seen an acked packet.
2384 if (last == -2) {
2385 printf(" acked %d",
2386 firstPacket + i);
2387 start = i;
2391 * Otherwise, if the there is a skip in
2392 * the range (such as an nacked packet in
2393 * the middle of some acked packets),
2394 * then print the current packet number
2395 * seperated from the last number by
2396 * a comma.
2399 else if (last != i - 1) {
2400 printf(",%d", firstPacket + i);
2401 start = i;
2405 * We always set last to the value of
2406 * the last ack we saw. Conversely, start
2407 * is set to the value of the first ack
2408 * we saw in a range.
2411 last = i;
2414 * Okay, this bit a code gets executed when
2415 * we hit a nack ... in _this_ case we
2416 * want to print out the range of packets
2417 * that were acked, so we need to print
2418 * the _previous_ packet number seperated
2419 * from the first by a dash (-). Since we
2420 * already printed the first packet above,
2421 * just print the final packet. Don't
2422 * do this if there will be a single-length
2423 * range.
2425 } else if (last == i - 1 && start != last)
2426 printf("-%d", firstPacket + i - 1);
2429 * So, what's going on here? We ran off the end of the
2430 * ack list, and if we got a range we need to finish it up.
2431 * So we need to determine if the last packet in the list
2432 * was an ack (if so, then last will be set to it) and
2433 * we need to see if the last range didn't start with the
2434 * last packet (because if it _did_, then that would mean
2435 * that the packet number has already been printed and
2436 * we don't need to print it again).
2439 if (last == i - 1 && start != last)
2440 printf("-%d", firstPacket + i - 1);
2443 * Same as above, just without comments
2446 for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2447 if (rxa->acks[i] == RX_ACK_TYPE_NACK) {
2448 if (last == -2) {
2449 printf(" nacked %d",
2450 firstPacket + i);
2451 start = i;
2452 } else if (last != i - 1) {
2453 printf(",%d", firstPacket + i);
2454 start = i;
2456 last = i;
2457 } else if (last == i - 1 && start != last)
2458 printf("-%d", firstPacket + i - 1);
2460 if (last == i - 1 && start != last)
2461 printf("-%d", firstPacket + i - 1);
2463 bp += rxa->nAcks;
2468 * These are optional fields; depending on your version of AFS,
2469 * you may or may not see them
2472 #define TRUNCRET(n) if (snapend - bp + 1 <= n) return;
2474 if (vflag > 1) {
2475 TRUNCRET(4);
2476 printf(" ifmtu");
2477 INTOUT();
2479 TRUNCRET(4);
2480 printf(" maxmtu");
2481 INTOUT();
2483 TRUNCRET(4);
2484 printf(" rwind");
2485 INTOUT();
2487 TRUNCRET(4);
2488 printf(" maxpackets");
2489 INTOUT();
2492 return;
2494 trunc:
2495 printf(" [|ack]");
2497 #undef TRUNCRET