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