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