]> The Tcpdump Group git mirrors - tcpdump/blob - print-rx.c
Don't allow STROUT() to use a negative string length.
[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.23 2001-07-09 01:39:43 fenner 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) { unsigned int i; \
636 TCHECK2(bp[0], sizeof(int32_t)); \
637 i = EXTRACT_32BITS(bp); \
638 if (i > MAX) \
639 goto trunc; \
640 bp += sizeof(int32_t); \
641 printf(" \""); \
642 if (fn_printn(bp, i, snapend)) \
643 goto trunc; \
644 printf("\""); \
645 bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \
646 }
647
648 #define INTOUT() { int i; \
649 TCHECK2(bp[0], sizeof(int32_t)); \
650 i = (int) EXTRACT_32BITS(bp); \
651 bp += sizeof(int32_t); \
652 printf(" %d", i); \
653 }
654
655 #define UINTOUT() { unsigned long i; \
656 TCHECK2(bp[0], sizeof(int32_t)); \
657 i = EXTRACT_32BITS(bp); \
658 bp += sizeof(int32_t); \
659 printf(" %lu", i); \
660 }
661
662 #define DATEOUT() { time_t t; struct tm *tm; char str[256]; \
663 TCHECK2(bp[0], sizeof(int32_t)); \
664 t = (time_t) EXTRACT_32BITS(bp); \
665 bp += sizeof(int32_t); \
666 tm = localtime(&t); \
667 strftime(str, 256, "%Y/%m/%d %T", tm); \
668 printf(" %s", str); \
669 }
670
671 #define STOREATTROUT() { unsigned long mask, i; \
672 TCHECK2(bp[0], (sizeof(int32_t)*6)); \
673 mask = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
674 if (mask) printf (" StoreStatus"); \
675 if (mask & 1) { printf(" date"); DATEOUT(); } \
676 else bp += sizeof(int32_t); \
677 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
678 if (mask & 2) printf(" owner %lu", i); \
679 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
680 if (mask & 4) printf(" group %lu", i); \
681 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
682 if (mask & 8) printf(" mode %lo", i & 07777); \
683 i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \
684 if (mask & 16) printf(" segsize %lu", i); \
685 /* undocumented in 3.3 docu */ \
686 if (mask & 1024) printf(" fsync"); \
687 }
688
689 #define UBIK_VERSIONOUT() {int32_t epoch; int32_t counter; \
690 TCHECK2(bp[0], sizeof(int32_t) * 2); \
691 epoch = EXTRACT_32BITS(bp); \
692 bp += sizeof(int32_t); \
693 counter = EXTRACT_32BITS(bp); \
694 bp += sizeof(int32_t); \
695 printf(" %d.%d", epoch, counter); \
696 }
697
698 #define AFSUUIDOUT() {u_int32_t temp; int i; \
699 TCHECK2(bp[0], 11*sizeof(u_int32_t)); \
700 temp = EXTRACT_32BITS(bp); \
701 bp += sizeof(u_int32_t); \
702 printf(" %08x", temp); \
703 temp = EXTRACT_32BITS(bp); \
704 bp += sizeof(u_int32_t); \
705 printf("%04x", temp); \
706 temp = EXTRACT_32BITS(bp); \
707 bp += sizeof(u_int32_t); \
708 printf("%04x", temp); \
709 for (i = 0; i < 8; i++) { \
710 temp = EXTRACT_32BITS(bp); \
711 bp += sizeof(u_int32_t); \
712 printf("%02x", (unsigned char) temp); \
713 } \
714 }
715
716 /*
717 * This is the sickest one of all
718 */
719
720 #define VECOUT(MAX) { char *sp; \
721 int k; \
722 TCHECK2(bp[0], MAX * sizeof(int32_t)); \
723 sp = s; \
724 for (k = 0; k < MAX; k++) { \
725 *sp++ = (char) EXTRACT_32BITS(bp); \
726 bp += sizeof(int32_t); \
727 } \
728 s[MAX] = '\0'; \
729 printf(" \""); \
730 fn_print(s, NULL); \
731 printf("\""); \
732 }
733
734 static void
735 ack_print(register const u_char *bp, int length)
736 {
737 u_char nAcks;
738 int i;
739
740 if (vflag <= 1)
741 return;
742
743 if (length <= sizeof(struct rx_header))
744 return;
745
746 bp += sizeof(struct rx_header);
747
748 /*
749 * Packets < firstPacket are implicitly acknowledged and may
750 * be discarded by the sender.
751 *
752 * Packets >= firstPacket+nAcks are implicitly NOT acknowledged.
753 *
754 * No packets with sequence numbers >= firstPacket should be
755 * discarded by the sender (they may thrown out at any time by
756 * the receiver)
757 */
758 #define RX_ACK_REASONS "RDOXSprn"
759 /* Requested, Duplicate, Out_of_sequence, eXceeds_window, no_Space,
760 * Ping, ping_Response, No_{progress, particular_reason}.
761 */
762 #if 0
763 struct rx_ackPacket {
764 u_short bufferSpace; /* Skip! */
765 u_short maxSkew; /* Skip! */
766 u_long firstPacket;
767 u_long previousPacket; /* Obsolete! */
768 u_long serial; /* Serial that prompted the ack, */
769 u_char reason; /* and the reason why. */
770 u_char nAcks;
771 u_char acks[RX_MAXACKS]; /* Selective acks (not a bitmap). */
772 };
773 #endif
774 #define RX_ACK_TYPE_NACK 0
775
776 TCHECK2(bp[0], 8); /* bufferSpace and maxSkew */
777 bp += 4;
778 printf(" fir %u", (unsigned)EXTRACT_32BITS(bp));
779 bp += 4;
780 TCHECK2(bp[0], 8); /* previousPacket and serial */
781 bp += 4;
782 printf(" %u", (unsigned)EXTRACT_32BITS(bp));
783 bp += 4;
784 TCHECK2(bp[0], 1);
785 printf("%c", RX_ACK_REASONS[(*bp - 1) & 07u]);
786 bp += 1; /* reason */
787 TCHECK2(bp[0], 1);
788 nAcks = *bp;
789 bp += 1; /* nAcks */
790
791 for (i = 0; i < nAcks; i++) {
792 TCHECK2(bp[0], 1);
793 putchar(*bp == RX_ACK_TYPE_NACK? '-' : '*');
794 bp += 1;
795 }
796
797 return;
798
799 trunc:
800 printf(" [|ack]");
801 }
802
803 /*
804 * Handle calls to the AFS file service (fs)
805 */
806
807 static void
808 fs_print(register const u_char *bp, int length)
809 {
810 int fs_op;
811 unsigned long i;
812 char s[AFSNAMEMAX];
813
814 if (length <= sizeof(struct rx_header))
815 return;
816
817 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
818 goto trunc;
819 }
820
821 /*
822 * Print out the afs call we're invoking. The table used here was
823 * gleaned from fsint/afsint.xg
824 */
825
826 fs_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
827
828 printf(" fs call %s", tok2str(fs_req, "op#%d", fs_op));
829
830 /*
831 * Print out arguments to some of the AFS calls. This stuff is
832 * all from afsint.xg
833 */
834
835 bp += sizeof(struct rx_header) + 4;
836
837 /*
838 * Sigh. This is gross. Ritchie forgive me.
839 */
840
841 switch (fs_op) {
842 case 130: /* Fetch data */
843 FIDOUT();
844 printf(" offset");
845 UINTOUT();
846 printf(" length");
847 UINTOUT();
848 break;
849 case 131: /* Fetch ACL */
850 case 132: /* Fetch Status */
851 case 143: /* Old set lock */
852 case 144: /* Old extend lock */
853 case 145: /* Old release lock */
854 case 156: /* Set lock */
855 case 157: /* Extend lock */
856 case 158: /* Release lock */
857 FIDOUT();
858 break;
859 case 135: /* Store status */
860 FIDOUT();
861 STOREATTROUT();
862 break;
863 case 133: /* Store data */
864 FIDOUT();
865 STOREATTROUT();
866 printf(" offset");
867 UINTOUT();
868 printf(" length");
869 UINTOUT();
870 printf(" flen");
871 UINTOUT();
872 break;
873 case 134: /* Store ACL */
874 {
875 char a[AFSOPAQUEMAX+1];
876 FIDOUT();
877 TCHECK2(bp[0], 4);
878 i = EXTRACT_32BITS(bp);
879 bp += sizeof(int32_t);
880 TCHECK2(bp[0], i);
881 i = min(AFSOPAQUEMAX, i);
882 strncpy(a, (char *) bp, i);
883 a[i] = '\0';
884 acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
885 break;
886 }
887 case 137: /* Create file */
888 case 141: /* MakeDir */
889 FIDOUT();
890 STROUT(AFSNAMEMAX);
891 STOREATTROUT();
892 break;
893 case 136: /* Remove file */
894 case 142: /* Remove directory */
895 FIDOUT();
896 STROUT(AFSNAMEMAX);
897 break;
898 case 138: /* Rename file */
899 printf(" old");
900 FIDOUT();
901 STROUT(AFSNAMEMAX);
902 printf(" new");
903 FIDOUT();
904 STROUT(AFSNAMEMAX);
905 break;
906 case 139: /* Symlink */
907 FIDOUT();
908 STROUT(AFSNAMEMAX);
909 printf(" link to");
910 STROUT(AFSNAMEMAX);
911 break;
912 case 140: /* Link */
913 FIDOUT();
914 STROUT(AFSNAMEMAX);
915 printf(" link to");
916 FIDOUT();
917 break;
918 case 148: /* Get volume info */
919 STROUT(AFSNAMEMAX);
920 break;
921 case 149: /* Get volume stats */
922 case 150: /* Set volume stats */
923 printf(" volid");
924 UINTOUT();
925 break;
926 case 154: /* New get volume info */
927 printf(" volname");
928 STROUT(AFSNAMEMAX);
929 break;
930 case 155: /* Bulk stat */
931 {
932 unsigned long j;
933 TCHECK2(bp[0], 4);
934 j = EXTRACT_32BITS(bp);
935 bp += sizeof(int32_t);
936
937 for (i = 0; i < j; i++) {
938 FIDOUT();
939 if (i != j - 1)
940 printf(",");
941 }
942 if (j == 0)
943 printf(" <none!>");
944 }
945 default:
946 ;
947 }
948
949 return;
950
951 trunc:
952 printf(" [|fs]");
953 }
954
955 /*
956 * Handle replies to the AFS file service
957 */
958
959 static void
960 fs_reply_print(register const u_char *bp, int length, int32_t opcode)
961 {
962 unsigned long i;
963 char s[AFSNAMEMAX];
964 struct rx_header *rxh;
965
966 if (length <= sizeof(struct rx_header))
967 return;
968
969 rxh = (struct rx_header *) bp;
970
971 /*
972 * Print out the afs call we're invoking. The table used here was
973 * gleaned from fsint/afsint.xg
974 */
975
976 printf(" fs reply %s", tok2str(fs_req, "op#%d", opcode));
977
978 bp += sizeof(struct rx_header);
979
980 /*
981 * If it was a data packet, interpret the response
982 */
983
984 if (rxh->type == RX_PACKET_TYPE_DATA) {
985 switch (opcode) {
986 case 131: /* Fetch ACL */
987 {
988 char a[AFSOPAQUEMAX+1];
989 TCHECK2(bp[0], 4);
990 i = EXTRACT_32BITS(bp);
991 bp += sizeof(int32_t);
992 TCHECK2(bp[0], i);
993 i = min(AFSOPAQUEMAX, i);
994 strncpy(a, (char *) bp, i);
995 a[i] = '\0';
996 acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
997 break;
998 }
999 case 137: /* Create file */
1000 case 141: /* MakeDir */
1001 printf(" new");
1002 FIDOUT();
1003 break;
1004 case 151: /* Get root volume */
1005 printf(" root volume");
1006 STROUT(AFSNAMEMAX);
1007 break;
1008 case 153: /* Get time */
1009 DATEOUT();
1010 break;
1011 default:
1012 ;
1013 }
1014 } else if (rxh->type == RX_PACKET_TYPE_ABORT) {
1015 int i;
1016
1017 /*
1018 * Otherwise, just print out the return code
1019 */
1020 TCHECK2(bp[0], sizeof(int32_t));
1021 i = (int) EXTRACT_32BITS(bp);
1022 bp += sizeof(int32_t);
1023
1024 printf(" error %s", tok2str(afs_fs_errors, "#%d", i));
1025 } else {
1026 printf(" strange fs reply of type %d", rxh->type);
1027 }
1028
1029 return;
1030
1031 trunc:
1032 printf(" [|fs]");
1033 }
1034
1035 /*
1036 * Print out an AFS ACL string. An AFS ACL is a string that has the
1037 * following format:
1038 *
1039 * <positive> <negative>
1040 * <uid1> <aclbits1>
1041 * ....
1042 *
1043 * "positive" and "negative" are integers which contain the number of
1044 * positive and negative ACL's in the string. The uid/aclbits pair are
1045 * ASCII strings containing the UID/PTS record and and a ascii number
1046 * representing a logical OR of all the ACL permission bits
1047 */
1048
1049 static void
1050 acl_print(u_char *s, int maxsize, u_char *end)
1051 {
1052 int pos, neg, acl;
1053 int n, i;
1054 char *user;
1055
1056 if ((user = (char *)malloc(maxsize)) == NULL)
1057 return;
1058
1059 if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
1060 goto finish;
1061
1062 s += n;
1063
1064 if (s > end)
1065 goto finish;
1066
1067 /*
1068 * This wacky order preserves the order used by the "fs" command
1069 */
1070
1071 #define ACLOUT(acl) \
1072 if (acl & PRSFS_READ) \
1073 printf("r"); \
1074 if (acl & PRSFS_LOOKUP) \
1075 printf("l"); \
1076 if (acl & PRSFS_INSERT) \
1077 printf("i"); \
1078 if (acl & PRSFS_DELETE) \
1079 printf("d"); \
1080 if (acl & PRSFS_WRITE) \
1081 printf("w"); \
1082 if (acl & PRSFS_LOCK) \
1083 printf("k"); \
1084 if (acl & PRSFS_ADMINISTER) \
1085 printf("a");
1086
1087 for (i = 0; i < pos; i++) {
1088 if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
1089 goto finish;
1090 s += n;
1091 printf(" +{");
1092 fn_print(user, NULL);
1093 printf(" ");
1094 ACLOUT(acl);
1095 printf("}");
1096 if (s > end)
1097 goto finish;
1098 }
1099
1100 for (i = 0; i < neg; i++) {
1101 if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
1102 goto finish;
1103 s += n;
1104 printf(" -{");
1105 fn_print(user, NULL);
1106 printf(" ");
1107 ACLOUT(acl);
1108 printf("}");
1109 if (s > end)
1110 goto finish;
1111 }
1112
1113 finish:
1114 free(user);
1115 return;
1116 }
1117
1118 #undef ACLOUT
1119
1120 /*
1121 * Handle calls to the AFS callback service
1122 */
1123
1124 static void
1125 cb_print(register const u_char *bp, int length)
1126 {
1127 int cb_op;
1128 unsigned long i;
1129
1130 if (length <= sizeof(struct rx_header))
1131 return;
1132
1133 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1134 goto trunc;
1135 }
1136
1137 /*
1138 * Print out the afs call we're invoking. The table used here was
1139 * gleaned from fsint/afscbint.xg
1140 */
1141
1142 cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1143
1144 printf(" cb call %s", tok2str(cb_req, "op#%d", cb_op));
1145
1146 bp += sizeof(struct rx_header) + 4;
1147
1148 /*
1149 * Print out the afs call we're invoking. The table used here was
1150 * gleaned from fsint/afscbint.xg
1151 */
1152
1153 switch (cb_op) {
1154 case 204: /* Callback */
1155 {
1156 unsigned long j, t;
1157 TCHECK2(bp[0], 4);
1158 j = EXTRACT_32BITS(bp);
1159 bp += sizeof(int32_t);
1160
1161 for (i = 0; i < j; i++) {
1162 FIDOUT();
1163 if (i != j - 1)
1164 printf(",");
1165 }
1166
1167 if (j == 0)
1168 printf(" <none!>");
1169
1170 j = EXTRACT_32BITS(bp);
1171 bp += sizeof(int32_t);
1172
1173 if (j != 0)
1174 printf(";");
1175
1176 for (i = 0; i < j; i++) {
1177 printf(" ver");
1178 INTOUT();
1179 printf(" expires");
1180 DATEOUT();
1181 TCHECK2(bp[0], 4);
1182 t = EXTRACT_32BITS(bp);
1183 bp += sizeof(int32_t);
1184 tok2str(cb_types, "type %d", t);
1185 }
1186 }
1187 case 214: {
1188 printf(" afsuuid");
1189 AFSUUIDOUT();
1190 break;
1191 }
1192 default:
1193 ;
1194 }
1195
1196 return;
1197
1198 trunc:
1199 printf(" [|cb]");
1200 }
1201
1202 /*
1203 * Handle replies to the AFS Callback Service
1204 */
1205
1206 static void
1207 cb_reply_print(register const u_char *bp, int length, int32_t opcode)
1208 {
1209 struct rx_header *rxh;
1210
1211 if (length <= sizeof(struct rx_header))
1212 return;
1213
1214 rxh = (struct rx_header *) bp;
1215
1216 /*
1217 * Print out the afs call we're invoking. The table used here was
1218 * gleaned from fsint/afscbint.xg
1219 */
1220
1221 printf(" cb reply %s", tok2str(cb_req, "op#%d", opcode));
1222
1223 bp += sizeof(struct rx_header);
1224
1225 /*
1226 * If it was a data packet, interpret the response.
1227 */
1228
1229 if (rxh->type == RX_PACKET_TYPE_DATA)
1230 switch (opcode) {
1231 case 213: /* InitCallBackState3 */
1232 AFSUUIDOUT();
1233 break;
1234 default:
1235 ;
1236 }
1237 else {
1238 /*
1239 * Otherwise, just print out the return code
1240 */
1241 printf(" errcode");
1242 INTOUT();
1243 }
1244
1245 return;
1246
1247 trunc:
1248 printf(" [|cb]");
1249 }
1250
1251 /*
1252 * Handle calls to the AFS protection database server
1253 */
1254
1255 static void
1256 prot_print(register const u_char *bp, int length)
1257 {
1258 unsigned long i;
1259 char s[AFSNAMEMAX];
1260 int pt_op;
1261
1262 if (length <= sizeof(struct rx_header))
1263 return;
1264
1265 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1266 goto trunc;
1267 }
1268
1269 /*
1270 * Print out the afs call we're invoking. The table used here was
1271 * gleaned from ptserver/ptint.xg
1272 */
1273
1274 pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1275
1276 printf(" pt");
1277
1278 if (is_ubik(pt_op)) {
1279 ubik_print(bp, length);
1280 return;
1281 }
1282
1283 printf(" call %s", tok2str(pt_req, "op#%d", pt_op));
1284
1285 /*
1286 * Decode some of the arguments to the PT calls
1287 */
1288
1289 bp += sizeof(struct rx_header) + 4;
1290
1291 switch (pt_op) {
1292 case 500: /* I New User */
1293 STROUT(PRNAMEMAX);
1294 printf(" id");
1295 INTOUT();
1296 printf(" oldid");
1297 INTOUT();
1298 break;
1299 case 501: /* Where is it */
1300 case 506: /* Delete */
1301 case 508: /* Get CPS */
1302 case 512: /* List entry */
1303 case 514: /* List elements */
1304 case 517: /* List owned */
1305 case 518: /* Get CPS2 */
1306 case 519: /* Get host CPS */
1307 printf(" id");
1308 INTOUT();
1309 break;
1310 case 502: /* Dump entry */
1311 printf(" pos");
1312 INTOUT();
1313 break;
1314 case 503: /* Add to group */
1315 case 507: /* Remove from group */
1316 case 515: /* Is a member of? */
1317 printf(" uid");
1318 INTOUT();
1319 printf(" gid");
1320 INTOUT();
1321 break;
1322 case 504: /* Name to ID */
1323 {
1324 unsigned long j;
1325 TCHECK2(bp[0], 4);
1326 j = EXTRACT_32BITS(bp);
1327 bp += sizeof(int32_t);
1328
1329 /*
1330 * Who designed this chicken-shit protocol?
1331 *
1332 * Each character is stored as a 32-bit
1333 * integer!
1334 */
1335
1336 for (i = 0; i < j; i++) {
1337 VECOUT(PRNAMEMAX);
1338 }
1339 if (j == 0)
1340 printf(" <none!>");
1341 }
1342 break;
1343 case 505: /* Id to name */
1344 {
1345 unsigned long j;
1346 printf(" ids:");
1347 TCHECK2(bp[0], 4);
1348 i = EXTRACT_32BITS(bp);
1349 bp += sizeof(int32_t);
1350 for (j = 0; j < i; j++)
1351 INTOUT();
1352 if (j == 0)
1353 printf(" <none!>");
1354 }
1355 break;
1356 case 509: /* New entry */
1357 STROUT(PRNAMEMAX);
1358 printf(" flag");
1359 INTOUT();
1360 printf(" oid");
1361 INTOUT();
1362 break;
1363 case 511: /* Set max */
1364 printf(" id");
1365 INTOUT();
1366 printf(" gflag");
1367 INTOUT();
1368 break;
1369 case 513: /* Change entry */
1370 printf(" id");
1371 INTOUT();
1372 STROUT(PRNAMEMAX);
1373 printf(" oldid");
1374 INTOUT();
1375 printf(" newid");
1376 INTOUT();
1377 break;
1378 case 520: /* Update entry */
1379 printf(" id");
1380 INTOUT();
1381 STROUT(PRNAMEMAX);
1382 break;
1383 default:
1384 ;
1385 }
1386
1387
1388 return;
1389
1390 trunc:
1391 printf(" [|pt]");
1392 }
1393
1394 /*
1395 * Handle replies to the AFS protection service
1396 */
1397
1398 static void
1399 prot_reply_print(register const u_char *bp, int length, int32_t opcode)
1400 {
1401 struct rx_header *rxh;
1402 unsigned long i;
1403 char s[AFSNAMEMAX];
1404
1405 if (length < sizeof(struct rx_header))
1406 return;
1407
1408 rxh = (struct rx_header *) bp;
1409
1410 /*
1411 * Print out the afs call we're invoking. The table used here was
1412 * gleaned from ptserver/ptint.xg. Check to see if it's a
1413 * Ubik call, however.
1414 */
1415
1416 printf(" pt");
1417
1418 if (is_ubik(opcode)) {
1419 ubik_reply_print(bp, length, opcode);
1420 return;
1421 }
1422
1423 printf(" reply %s", tok2str(pt_req, "op#%d", opcode));
1424
1425 bp += sizeof(struct rx_header);
1426
1427 /*
1428 * If it was a data packet, interpret the response
1429 */
1430
1431 if (rxh->type == RX_PACKET_TYPE_DATA)
1432 switch (opcode) {
1433 case 504: /* Name to ID */
1434 {
1435 unsigned long j;
1436 printf(" ids:");
1437 TCHECK2(bp[0], 4);
1438 i = EXTRACT_32BITS(bp);
1439 bp += sizeof(int32_t);
1440 for (j = 0; j < i; j++)
1441 INTOUT();
1442 if (j == 0)
1443 printf(" <none!>");
1444 }
1445 break;
1446 case 505: /* ID to name */
1447 {
1448 unsigned long j;
1449 TCHECK2(bp[0], 4);
1450 j = EXTRACT_32BITS(bp);
1451 bp += sizeof(int32_t);
1452
1453 /*
1454 * Who designed this chicken-shit protocol?
1455 *
1456 * Each character is stored as a 32-bit
1457 * integer!
1458 */
1459
1460 for (i = 0; i < j; i++) {
1461 VECOUT(PRNAMEMAX);
1462 }
1463 if (j == 0)
1464 printf(" <none!>");
1465 }
1466 break;
1467 case 508: /* Get CPS */
1468 case 514: /* List elements */
1469 case 517: /* List owned */
1470 case 518: /* Get CPS2 */
1471 case 519: /* Get host CPS */
1472 {
1473 unsigned long j;
1474 TCHECK2(bp[0], 4);
1475 j = EXTRACT_32BITS(bp);
1476 bp += sizeof(int32_t);
1477 for (i = 0; i < j; i++) {
1478 INTOUT();
1479 }
1480 if (j == 0)
1481 printf(" <none!>");
1482 }
1483 break;
1484 case 510: /* List max */
1485 printf(" maxuid");
1486 INTOUT();
1487 printf(" maxgid");
1488 INTOUT();
1489 break;
1490 default:
1491 ;
1492 }
1493 else {
1494 /*
1495 * Otherwise, just print out the return code
1496 */
1497 printf(" errcode");
1498 INTOUT();
1499 }
1500
1501 return;
1502
1503 trunc:
1504 printf(" [|pt]");
1505 }
1506
1507 /*
1508 * Handle calls to the AFS volume location database service
1509 */
1510
1511 static void
1512 vldb_print(register const u_char *bp, int length)
1513 {
1514 int vldb_op;
1515 unsigned long i;
1516 char s[AFSNAMEMAX];
1517
1518 if (length <= sizeof(struct rx_header))
1519 return;
1520
1521 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1522 goto trunc;
1523 }
1524
1525 /*
1526 * Print out the afs call we're invoking. The table used here was
1527 * gleaned from vlserver/vldbint.xg
1528 */
1529
1530 vldb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1531
1532 printf(" vldb");
1533
1534 if (is_ubik(vldb_op)) {
1535 ubik_print(bp, length);
1536 return;
1537 }
1538 printf(" call %s", tok2str(vldb_req, "op#%d", vldb_op));
1539
1540 /*
1541 * Decode some of the arguments to the VLDB calls
1542 */
1543
1544 bp += sizeof(struct rx_header) + 4;
1545
1546 switch (vldb_op) {
1547 case 501: /* Create new volume */
1548 case 517: /* Create entry N */
1549 VECOUT(VLNAMEMAX);
1550 break;
1551 case 502: /* Delete entry */
1552 case 503: /* Get entry by ID */
1553 case 507: /* Update entry */
1554 case 508: /* Set lock */
1555 case 509: /* Release lock */
1556 case 518: /* Get entry by ID N */
1557 printf(" volid");
1558 INTOUT();
1559 TCHECK2(bp[0], sizeof(int32_t));
1560 i = EXTRACT_32BITS(bp);
1561 bp += sizeof(int32_t);
1562 if (i <= 2)
1563 printf(" type %s", voltype[i]);
1564 break;
1565 case 504: /* Get entry by name */
1566 case 519: /* Get entry by name N */
1567 case 524: /* Update entry by name */
1568 case 527: /* Get entry by name U */
1569 STROUT(VLNAMEMAX);
1570 break;
1571 case 505: /* Get new vol id */
1572 printf(" bump");
1573 INTOUT();
1574 break;
1575 case 506: /* Replace entry */
1576 case 520: /* Replace entry N */
1577 printf(" volid");
1578 INTOUT();
1579 TCHECK2(bp[0], sizeof(int32_t));
1580 i = EXTRACT_32BITS(bp);
1581 bp += sizeof(int32_t);
1582 if (i <= 2)
1583 printf(" type %s", voltype[i]);
1584 VECOUT(VLNAMEMAX);
1585 break;
1586 case 510: /* List entry */
1587 case 521: /* List entry N */
1588 printf(" index");
1589 INTOUT();
1590 break;
1591 default:
1592 ;
1593 }
1594
1595 return;
1596
1597 trunc:
1598 printf(" [|vldb]");
1599 }
1600
1601 /*
1602 * Handle replies to the AFS volume location database service
1603 */
1604
1605 static void
1606 vldb_reply_print(register const u_char *bp, int length, int32_t opcode)
1607 {
1608 struct rx_header *rxh;
1609 unsigned long i;
1610 char s[AFSNAMEMAX];
1611
1612 if (length < sizeof(struct rx_header))
1613 return;
1614
1615 rxh = (struct rx_header *) bp;
1616
1617 /*
1618 * Print out the afs call we're invoking. The table used here was
1619 * gleaned from vlserver/vldbint.xg. Check to see if it's a
1620 * Ubik call, however.
1621 */
1622
1623 printf(" vldb");
1624
1625 if (is_ubik(opcode)) {
1626 ubik_reply_print(bp, length, opcode);
1627 return;
1628 }
1629
1630 printf(" reply %s", tok2str(vldb_req, "op#%d", opcode));
1631
1632 bp += sizeof(struct rx_header);
1633
1634 /*
1635 * If it was a data packet, interpret the response
1636 */
1637
1638 if (rxh->type == RX_PACKET_TYPE_DATA)
1639 switch (opcode) {
1640 case 510: /* List entry */
1641 printf(" count");
1642 INTOUT();
1643 printf(" nextindex");
1644 INTOUT();
1645 case 503: /* Get entry by id */
1646 case 504: /* Get entry by name */
1647 { unsigned long nservers, j;
1648 VECOUT(VLNAMEMAX);
1649 TCHECK2(bp[0], sizeof(int32_t));
1650 bp += sizeof(int32_t);
1651 printf(" numservers");
1652 TCHECK2(bp[0], sizeof(int32_t));
1653 nservers = EXTRACT_32BITS(bp);
1654 bp += sizeof(int32_t);
1655 printf(" %lu", nservers);
1656 printf(" servers");
1657 for (i = 0; i < 8; i++) {
1658 TCHECK2(bp[0], sizeof(int32_t));
1659 if (i < nservers)
1660 printf(" %s",
1661 inet_ntoa(*((struct in_addr *) bp)));
1662 bp += sizeof(int32_t);
1663 }
1664 printf(" partitions");
1665 for (i = 0; i < 8; i++) {
1666 TCHECK2(bp[0], sizeof(int32_t));
1667 j = EXTRACT_32BITS(bp);
1668 if (i < nservers && j <= 26)
1669 printf(" %c", 'a' + (int)j);
1670 else if (i < nservers)
1671 printf(" %lu", j);
1672 bp += sizeof(int32_t);
1673 }
1674 TCHECK2(bp[0], 8 * sizeof(int32_t));
1675 bp += 8 * sizeof(int32_t);
1676 printf(" rwvol");
1677 UINTOUT();
1678 printf(" rovol");
1679 UINTOUT();
1680 printf(" backup");
1681 UINTOUT();
1682 }
1683 break;
1684 case 505: /* Get new volume ID */
1685 printf(" newvol");
1686 UINTOUT();
1687 break;
1688 case 521: /* List entry */
1689 case 529: /* List entry U */
1690 printf(" count");
1691 INTOUT();
1692 printf(" nextindex");
1693 INTOUT();
1694 case 518: /* Get entry by ID N */
1695 case 519: /* Get entry by name N */
1696 { unsigned long nservers, j;
1697 VECOUT(VLNAMEMAX);
1698 printf(" numservers");
1699 TCHECK2(bp[0], sizeof(int32_t));
1700 nservers = EXTRACT_32BITS(bp);
1701 bp += sizeof(int32_t);
1702 printf(" %lu", nservers);
1703 printf(" servers");
1704 for (i = 0; i < 13; i++) {
1705 TCHECK2(bp[0], sizeof(int32_t));
1706 if (i < nservers)
1707 printf(" %s",
1708 inet_ntoa(*((struct in_addr *) bp)));
1709 bp += sizeof(int32_t);
1710 }
1711 printf(" partitions");
1712 for (i = 0; i < 13; i++) {
1713 TCHECK2(bp[0], sizeof(int32_t));
1714 j = EXTRACT_32BITS(bp);
1715 if (i < nservers && j <= 26)
1716 printf(" %c", 'a' + (int)j);
1717 else if (i < nservers)
1718 printf(" %lu", j);
1719 bp += sizeof(int32_t);
1720 }
1721 TCHECK2(bp[0], 13 * sizeof(int32_t));
1722 bp += 13 * sizeof(int32_t);
1723 printf(" rwvol");
1724 UINTOUT();
1725 printf(" rovol");
1726 UINTOUT();
1727 printf(" backup");
1728 UINTOUT();
1729 }
1730 break;
1731 case 526: /* Get entry by ID U */
1732 case 527: /* Get entry by name U */
1733 { unsigned long nservers, j;
1734 VECOUT(VLNAMEMAX);
1735 printf(" numservers");
1736 TCHECK2(bp[0], sizeof(int32_t));
1737 nservers = EXTRACT_32BITS(bp);
1738 bp += sizeof(int32_t);
1739 printf(" %lu", nservers);
1740 printf(" servers");
1741 for (i = 0; i < 13; i++) {
1742 if (i < nservers) {
1743 printf(" afsuuid");
1744 AFSUUIDOUT();
1745 } else {
1746 TCHECK2(bp[0], 44);
1747 bp += 44;
1748 }
1749 }
1750 TCHECK2(bp[0], 4 * 13);
1751 bp += 4 * 13;
1752 printf(" partitions");
1753 for (i = 0; i < 13; i++) {
1754 TCHECK2(bp[0], sizeof(int32_t));
1755 j = EXTRACT_32BITS(bp);
1756 if (i < nservers && j <= 26)
1757 printf(" %c", 'a' + (int)j);
1758 else if (i < nservers)
1759 printf(" %lu", j);
1760 bp += sizeof(int32_t);
1761 }
1762 TCHECK2(bp[0], 13 * sizeof(int32_t));
1763 bp += 13 * sizeof(int32_t);
1764 printf(" rwvol");
1765 UINTOUT();
1766 printf(" rovol");
1767 UINTOUT();
1768 printf(" backup");
1769 UINTOUT();
1770 }
1771 default:
1772 ;
1773 }
1774
1775 else {
1776 /*
1777 * Otherwise, just print out the return code
1778 */
1779 printf(" errcode");
1780 INTOUT();
1781 }
1782
1783 return;
1784
1785 trunc:
1786 printf(" [|vldb]");
1787 }
1788
1789 /*
1790 * Handle calls to the AFS Kerberos Authentication service
1791 */
1792
1793 static void
1794 kauth_print(register const u_char *bp, int length)
1795 {
1796 int kauth_op;
1797 char s[AFSNAMEMAX];
1798
1799 if (length <= sizeof(struct rx_header))
1800 return;
1801
1802 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1803 goto trunc;
1804 }
1805
1806 /*
1807 * Print out the afs call we're invoking. The table used here was
1808 * gleaned from kauth/kauth.rg
1809 */
1810
1811 kauth_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1812
1813 printf(" kauth");
1814
1815 if (is_ubik(kauth_op)) {
1816 ubik_print(bp, length);
1817 return;
1818 }
1819
1820
1821 printf(" call %s", tok2str(kauth_req, "op#%d", kauth_op));
1822
1823 /*
1824 * Decode some of the arguments to the KA calls
1825 */
1826
1827 bp += sizeof(struct rx_header) + 4;
1828
1829 switch (kauth_op) {
1830 case 1: /* Authenticate old */;
1831 case 21: /* Authenticate */
1832 case 22: /* Authenticate-V2 */
1833 case 2: /* Change PW */
1834 case 5: /* Set fields */
1835 case 6: /* Create user */
1836 case 7: /* Delete user */
1837 case 8: /* Get entry */
1838 case 14: /* Unlock */
1839 case 15: /* Lock status */
1840 printf(" principal");
1841 STROUT(KANAMEMAX);
1842 STROUT(KANAMEMAX);
1843 break;
1844 case 3: /* GetTicket-old */
1845 case 23: /* GetTicket */
1846 {
1847 int i;
1848 printf(" kvno");
1849 INTOUT();
1850 printf(" domain");
1851 STROUT(KANAMEMAX);
1852 TCHECK2(bp[0], sizeof(int32_t));
1853 i = (int) EXTRACT_32BITS(bp);
1854 bp += sizeof(int32_t);
1855 TCHECK2(bp[0], i);
1856 bp += i;
1857 printf(" principal");
1858 STROUT(KANAMEMAX);
1859 STROUT(KANAMEMAX);
1860 break;
1861 }
1862 case 4: /* Set Password */
1863 printf(" principal");
1864 STROUT(KANAMEMAX);
1865 STROUT(KANAMEMAX);
1866 printf(" kvno");
1867 INTOUT();
1868 break;
1869 case 12: /* Get password */
1870 printf(" name");
1871 STROUT(KANAMEMAX);
1872 break;
1873 default:
1874 ;
1875 }
1876
1877 return;
1878
1879 trunc:
1880 printf(" [|kauth]");
1881 }
1882
1883 /*
1884 * Handle replies to the AFS Kerberos Authentication Service
1885 */
1886
1887 static void
1888 kauth_reply_print(register const u_char *bp, int length, int32_t opcode)
1889 {
1890 struct rx_header *rxh;
1891
1892 if (length <= sizeof(struct rx_header))
1893 return;
1894
1895 rxh = (struct rx_header *) bp;
1896
1897 /*
1898 * Print out the afs call we're invoking. The table used here was
1899 * gleaned from kauth/kauth.rg
1900 */
1901
1902 printf(" kauth");
1903
1904 if (is_ubik(opcode)) {
1905 ubik_reply_print(bp, length, opcode);
1906 return;
1907 }
1908
1909 printf(" reply %s", tok2str(kauth_req, "op#%d", opcode));
1910
1911 bp += sizeof(struct rx_header);
1912
1913 /*
1914 * If it was a data packet, interpret the response.
1915 */
1916
1917 if (rxh->type == RX_PACKET_TYPE_DATA)
1918 /* Well, no, not really. Leave this for later */
1919 ;
1920 else {
1921 /*
1922 * Otherwise, just print out the return code
1923 */
1924 printf(" errcode");
1925 INTOUT();
1926 }
1927
1928 return;
1929
1930 trunc:
1931 printf(" [|kauth]");
1932 }
1933
1934 /*
1935 * Handle calls to the AFS Volume location service
1936 */
1937
1938 static void
1939 vol_print(register const u_char *bp, int length)
1940 {
1941 int vol_op;
1942
1943 if (length <= sizeof(struct rx_header))
1944 return;
1945
1946 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1947 goto trunc;
1948 }
1949
1950 /*
1951 * Print out the afs call we're invoking. The table used here was
1952 * gleaned from volser/volint.xg
1953 */
1954
1955 vol_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1956
1957 printf(" vol call %s", tok2str(vol_req, "op#%d", vol_op));
1958
1959 /*
1960 * Normally there would be a switch statement here to decode the
1961 * arguments to the AFS call, but since I don't have access to
1962 * an AFS server (yet) and I'm not an AFS admin, I can't
1963 * test any of these calls. Leave this blank for now.
1964 */
1965
1966 return;
1967
1968 trunc:
1969 printf(" [|vol]");
1970 }
1971
1972 /*
1973 * Handle replies to the AFS Volume Service
1974 */
1975
1976 static void
1977 vol_reply_print(register const u_char *bp, int length, int32_t opcode)
1978 {
1979 struct rx_header *rxh;
1980
1981 if (length <= sizeof(struct rx_header))
1982 return;
1983
1984 rxh = (struct rx_header *) bp;
1985
1986 /*
1987 * Print out the afs call we're invoking. The table used here was
1988 * gleaned from volser/volint.xg
1989 */
1990
1991 printf(" vol reply %s", tok2str(vol_req, "op#%d", opcode));
1992
1993 bp += sizeof(struct rx_header);
1994
1995 /*
1996 * If it was a data packet, interpret the response.
1997 */
1998
1999 if (rxh->type == RX_PACKET_TYPE_DATA)
2000 /* Well, no, not really. Leave this for later */
2001 ;
2002 else {
2003 /*
2004 * Otherwise, just print out the return code
2005 */
2006 printf(" errcode");
2007 INTOUT();
2008 }
2009
2010 return;
2011
2012 trunc:
2013 printf(" [|vol]");
2014 }
2015
2016 /*
2017 * Handle calls to the AFS BOS service
2018 */
2019
2020 static void
2021 bos_print(register const u_char *bp, int length)
2022 {
2023 int bos_op;
2024 char s[BOSNAMEMAX];
2025
2026 if (length <= sizeof(struct rx_header))
2027 return;
2028
2029 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
2030 goto trunc;
2031 }
2032
2033 /*
2034 * Print out the afs call we're invoking. The table used here was
2035 * gleaned from bozo/bosint.xg
2036 */
2037
2038 bos_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2039
2040 printf(" bos call %s", tok2str(bos_req, "op#%d", bos_op));
2041
2042 /*
2043 * Decode some of the arguments to the BOS calls
2044 */
2045
2046 bp += sizeof(struct rx_header) + 4;
2047
2048 switch (bos_op) {
2049 case 80: /* Create B node */
2050 printf(" type");
2051 STROUT(BOSNAMEMAX);
2052 printf(" instance");
2053 STROUT(BOSNAMEMAX);
2054 break;
2055 case 81: /* Delete B node */
2056 case 83: /* Get status */
2057 case 85: /* Get instance info */
2058 case 87: /* Add super user */
2059 case 88: /* Delete super user */
2060 case 93: /* Set cell name */
2061 case 96: /* Add cell host */
2062 case 97: /* Delete cell host */
2063 case 104: /* Restart */
2064 case 106: /* Uninstall */
2065 case 108: /* Exec */
2066 case 112: /* Getlog */
2067 case 114: /* Get instance strings */
2068 STROUT(BOSNAMEMAX);
2069 break;
2070 case 82: /* Set status */
2071 case 98: /* Set T status */
2072 STROUT(BOSNAMEMAX);
2073 printf(" status");
2074 INTOUT();
2075 break;
2076 case 86: /* Get instance parm */
2077 STROUT(BOSNAMEMAX);
2078 printf(" num");
2079 INTOUT();
2080 break;
2081 case 84: /* Enumerate instance */
2082 case 89: /* List super users */
2083 case 90: /* List keys */
2084 case 91: /* Add key */
2085 case 92: /* Delete key */
2086 case 95: /* Get cell host */
2087 INTOUT();
2088 break;
2089 case 105: /* Install */
2090 STROUT(BOSNAMEMAX);
2091 printf(" size");
2092 INTOUT();
2093 printf(" flags");
2094 INTOUT();
2095 printf(" date");
2096 INTOUT();
2097 break;
2098 default:
2099 ;
2100 }
2101
2102 return;
2103
2104 trunc:
2105 printf(" [|bos]");
2106 }
2107
2108 /*
2109 * Handle replies to the AFS BOS Service
2110 */
2111
2112 static void
2113 bos_reply_print(register const u_char *bp, int length, int32_t opcode)
2114 {
2115 struct rx_header *rxh;
2116
2117 if (length <= sizeof(struct rx_header))
2118 return;
2119
2120 rxh = (struct rx_header *) bp;
2121
2122 /*
2123 * Print out the afs call we're invoking. The table used here was
2124 * gleaned from volser/volint.xg
2125 */
2126
2127 printf(" bos reply %s", tok2str(bos_req, "op#%d", opcode));
2128
2129 bp += sizeof(struct rx_header);
2130
2131 /*
2132 * If it was a data packet, interpret the response.
2133 */
2134
2135 if (rxh->type == RX_PACKET_TYPE_DATA)
2136 /* Well, no, not really. Leave this for later */
2137 ;
2138 else {
2139 /*
2140 * Otherwise, just print out the return code
2141 */
2142 printf(" errcode");
2143 INTOUT();
2144 }
2145
2146 return;
2147
2148 trunc:
2149 printf(" [|bos]");
2150 }
2151
2152 /*
2153 * Check to see if this is a Ubik opcode.
2154 */
2155
2156 static int
2157 is_ubik(u_int32_t opcode)
2158 {
2159 if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
2160 (opcode >= DISK_LOW && opcode <= DISK_HIGH))
2161 return(1);
2162 else
2163 return(0);
2164 }
2165
2166 /*
2167 * Handle Ubik opcodes to any one of the replicated database services
2168 */
2169
2170 static void
2171 ubik_print(register const u_char *bp, int length)
2172 {
2173 int ubik_op;
2174 int32_t temp;
2175
2176 /*
2177 * Print out the afs call we're invoking. The table used here was
2178 * gleaned from ubik/ubik_int.xg
2179 */
2180
2181 ubik_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2182
2183 printf(" ubik call %s", tok2str(ubik_req, "op#%d", ubik_op));
2184
2185 /*
2186 * Decode some of the arguments to the Ubik calls
2187 */
2188
2189 bp += sizeof(struct rx_header) + 4;
2190
2191 switch (ubik_op) {
2192 case 10000: /* Beacon */
2193 TCHECK2(bp[0], 4);
2194 temp = EXTRACT_32BITS(bp);
2195 bp += sizeof(int32_t);
2196 printf(" syncsite %s", temp ? "yes" : "no");
2197 printf(" votestart");
2198 DATEOUT();
2199 printf(" dbversion");
2200 UBIK_VERSIONOUT();
2201 printf(" tid");
2202 UBIK_VERSIONOUT();
2203 break;
2204 case 10003: /* Get sync site */
2205 printf(" site");
2206 UINTOUT();
2207 break;
2208 case 20000: /* Begin */
2209 case 20001: /* Commit */
2210 case 20007: /* Abort */
2211 case 20008: /* Release locks */
2212 case 20010: /* Writev */
2213 printf(" tid");
2214 UBIK_VERSIONOUT();
2215 break;
2216 case 20002: /* Lock */
2217 printf(" tid");
2218 UBIK_VERSIONOUT();
2219 printf(" file");
2220 INTOUT();
2221 printf(" pos");
2222 INTOUT();
2223 printf(" length");
2224 INTOUT();
2225 temp = EXTRACT_32BITS(bp);
2226 bp += sizeof(int32_t);
2227 tok2str(ubik_lock_types, "type %d", temp);
2228 break;
2229 case 20003: /* Write */
2230 printf(" tid");
2231 UBIK_VERSIONOUT();
2232 printf(" file");
2233 INTOUT();
2234 printf(" pos");
2235 INTOUT();
2236 break;
2237 case 20005: /* Get file */
2238 printf(" file");
2239 INTOUT();
2240 break;
2241 case 20006: /* Send file */
2242 printf(" file");
2243 INTOUT();
2244 printf(" length");
2245 INTOUT();
2246 printf(" dbversion");
2247 UBIK_VERSIONOUT();
2248 break;
2249 case 20009: /* Truncate */
2250 printf(" tid");
2251 UBIK_VERSIONOUT();
2252 printf(" file");
2253 INTOUT();
2254 printf(" length");
2255 INTOUT();
2256 break;
2257 case 20012: /* Set version */
2258 printf(" tid");
2259 UBIK_VERSIONOUT();
2260 printf(" oldversion");
2261 UBIK_VERSIONOUT();
2262 printf(" newversion");
2263 UBIK_VERSIONOUT();
2264 break;
2265 default:
2266 ;
2267 }
2268
2269 return;
2270
2271 trunc:
2272 printf(" [|ubik]");
2273 }
2274
2275 /*
2276 * Handle Ubik replies to any one of the replicated database services
2277 */
2278
2279 static void
2280 ubik_reply_print(register const u_char *bp, int length, int32_t opcode)
2281 {
2282 struct rx_header *rxh;
2283
2284 if (length < sizeof(struct rx_header))
2285 return;
2286
2287 rxh = (struct rx_header *) bp;
2288
2289 /*
2290 * Print out the ubik call we're invoking. This table was gleaned
2291 * from ubik/ubik_int.xg
2292 */
2293
2294 printf(" ubik reply %s", tok2str(ubik_req, "op#%d", opcode));
2295
2296 bp += sizeof(struct rx_header);
2297
2298 /*
2299 * If it was a data packet, print out the arguments to the Ubik calls
2300 */
2301
2302 if (rxh->type == RX_PACKET_TYPE_DATA)
2303 switch (opcode) {
2304 case 10000: /* Beacon */
2305 printf(" vote no");
2306 break;
2307 case 20004: /* Get version */
2308 printf(" dbversion");
2309 UBIK_VERSIONOUT();
2310 break;
2311 default:
2312 ;
2313 }
2314
2315 /*
2316 * Otherwise, print out "yes" it it was a beacon packet (because
2317 * that's how yes votes are returned, go figure), otherwise
2318 * just print out the error code.
2319 */
2320
2321 else
2322 switch (opcode) {
2323 case 10000: /* Beacon */
2324 printf(" vote yes until");
2325 DATEOUT();
2326 break;
2327 default:
2328 printf(" errcode");
2329 INTOUT();
2330 }
2331
2332 return;
2333
2334 trunc:
2335 printf(" [|ubik]");
2336 }
2337
2338 /*
2339 * Handle RX ACK packets.
2340 */
2341
2342 static void
2343 rx_ack_print(register const u_char *bp, int length)
2344 {
2345 struct rx_ackPacket *rxa;
2346 int i, start, last;
2347
2348 if (length < sizeof(struct rx_header))
2349 return;
2350
2351 bp += sizeof(struct rx_header);
2352
2353 /*
2354 * This may seem a little odd .... the rx_ackPacket structure
2355 * contains an array of individual packet acknowledgements
2356 * (used for selective ack/nack), but since it's variable in size,
2357 * we don't want to truncate based on the size of the whole
2358 * rx_ackPacket structure.
2359 */
2360
2361 TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS);
2362
2363 rxa = (struct rx_ackPacket *) bp;
2364 bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS);
2365
2366 /*
2367 * Print out a few useful things from the ack packet structure
2368 */
2369
2370 if (vflag > 2)
2371 printf(" bufspace %d maxskew %d",
2372 (int) EXTRACT_16BITS(&rxa->bufferSpace),
2373 (int) EXTRACT_16BITS(&rxa->maxSkew));
2374
2375 printf(" first %d serial %d reason %s",
2376 EXTRACT_32BITS(&rxa->firstPacket), EXTRACT_32BITS(&rxa->serial),
2377 tok2str(rx_ack_reasons, "#%d", (int) rxa->reason));
2378
2379 /*
2380 * Okay, now we print out the ack array. The way _this_ works
2381 * is that we start at "first", and step through the ack array.
2382 * If we have a contiguous range of acks/nacks, try to
2383 * collapse them into a range.
2384 *
2385 * If you're really clever, you might have noticed that this
2386 * doesn't seem quite correct. Specifically, due to structure
2387 * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually
2388 * yield the start of the ack array (because RX_MAXACKS is 255
2389 * and the structure will likely get padded to a 2 or 4 byte
2390 * boundary). However, this is the way it's implemented inside
2391 * of AFS - the start of the extra fields are at
2392 * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_
2393 * the exact start of the ack array. Sigh. That's why we aren't
2394 * using bp, but instead use rxa->acks[]. But nAcks gets added
2395 * to bp after this, so bp ends up at the right spot. Go figure.
2396 */
2397
2398 if (rxa->nAcks != 0) {
2399
2400 TCHECK2(bp[0], rxa->nAcks);
2401
2402 /*
2403 * Sigh, this is gross, but it seems to work to collapse
2404 * ranges correctly.
2405 */
2406
2407 for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2408 if (rxa->acks[i] == RX_ACK_TYPE_ACK) {
2409
2410 /*
2411 * I figured this deserved _some_ explanation.
2412 * First, print "acked" and the packet seq
2413 * number if this is the first time we've
2414 * seen an acked packet.
2415 */
2416
2417 if (last == -2) {
2418 printf(" acked %d",
2419 rxa->firstPacket + i);
2420 start = i;
2421 }
2422
2423 /*
2424 * Otherwise, if the there is a skip in
2425 * the range (such as an nacked packet in
2426 * the middle of some acked packets),
2427 * then print the current packet number
2428 * seperated from the last number by
2429 * a comma.
2430 */
2431
2432 else if (last != i - 1) {
2433 printf(",%d", rxa->firstPacket + i);
2434 start = i;
2435 }
2436
2437 /*
2438 * We always set last to the value of
2439 * the last ack we saw. Conversely, start
2440 * is set to the value of the first ack
2441 * we saw in a range.
2442 */
2443
2444 last = i;
2445
2446 /*
2447 * Okay, this bit a code gets executed when
2448 * we hit a nack ... in _this_ case we
2449 * want to print out the range of packets
2450 * that were acked, so we need to print
2451 * the _previous_ packet number seperated
2452 * from the first by a dash (-). Since we
2453 * already printed the first packet above,
2454 * just print the final packet. Don't
2455 * do this if there will be a single-length
2456 * range.
2457 */
2458 } else if (last == i - 1 && start != last)
2459 printf("-%d", rxa->firstPacket + i - 1);
2460
2461 /*
2462 * So, what's going on here? We ran off the end of the
2463 * ack list, and if we got a range we need to finish it up.
2464 * So we need to determine if the last packet in the list
2465 * was an ack (if so, then last will be set to it) and
2466 * we need to see if the last range didn't start with the
2467 * last packet (because if it _did_, then that would mean
2468 * that the packet number has already been printed and
2469 * we don't need to print it again).
2470 */
2471
2472 if (last == i - 1 && start != last)
2473 printf("-%d", rxa->firstPacket + i - 1);
2474
2475 /*
2476 * Same as above, just without comments
2477 */
2478
2479 for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2480 if (rxa->acks[i] == RX_ACK_TYPE_NACK) {
2481 if (last == -2) {
2482 printf(" nacked %d",
2483 rxa->firstPacket + i);
2484 start = i;
2485 } else if (last != i - 1) {
2486 printf(",%d", rxa->firstPacket + i);
2487 start = i;
2488 }
2489 last = i;
2490 } else if (last == i - 1 && start != last)
2491 printf("-%d", rxa->firstPacket + i - 1);
2492
2493 if (last == i - 1 && start != last)
2494 printf("-%d", rxa->firstPacket + i - 1);
2495
2496 bp += rxa->nAcks;
2497 }
2498
2499
2500 /*
2501 * These are optional fields; depending on your version of AFS,
2502 * you may or may not see them
2503 */
2504
2505 #define TRUNCRET(n) if (snapend - bp + 1 <= n) return;
2506
2507 if (vflag > 1) {
2508 TRUNCRET(4);
2509 printf(" ifmtu");
2510 INTOUT();
2511
2512 TRUNCRET(4);
2513 printf(" maxmtu");
2514 INTOUT();
2515
2516 TRUNCRET(4);
2517 printf(" rwind");
2518 INTOUT();
2519
2520 TRUNCRET(4);
2521 printf(" maxpackets");
2522 INTOUT();
2523 }
2524
2525 return;
2526
2527 trunc:
2528 printf(" [|ack]");
2529 }
2530 #undef TRUNCRET