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