]> The Tcpdump Group git mirrors - tcpdump/blob - print-rx.c
Add an "ip.h" header, to declare the IP stuff needed by dissectors, and
[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.16 2000-09-23 08:54:39 guy Exp $";
17 #endif
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <time.h>
26 #include <sys/param.h>
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <netinet/in_systm.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 *, 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 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 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, (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, (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, u_char *end)
1048 {
1049 int pos, neg, acl;
1050 int n, i;
1051 char user[128];
1052
1053 if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
1054 return;
1055
1056 s += n;
1057
1058 if (s > end)
1059 return;
1060
1061 /*
1062 * This wacky order preserves the order used by the "fs" command
1063 */
1064
1065 #define ACLOUT(acl) \
1066 if (acl & PRSFS_READ) \
1067 printf("r"); \
1068 if (acl & PRSFS_LOOKUP) \
1069 printf("l"); \
1070 if (acl & PRSFS_INSERT) \
1071 printf("i"); \
1072 if (acl & PRSFS_DELETE) \
1073 printf("d"); \
1074 if (acl & PRSFS_WRITE) \
1075 printf("w"); \
1076 if (acl & PRSFS_LOCK) \
1077 printf("k"); \
1078 if (acl & PRSFS_ADMINISTER) \
1079 printf("a");
1080
1081 for (i = 0; i < pos; i++) {
1082 if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
1083 return;
1084 s += n;
1085 printf(" +{%s ", user);
1086 ACLOUT(acl);
1087 printf("}");
1088 if (s > end)
1089 return;
1090 }
1091
1092 for (i = 0; i < neg; i++) {
1093 if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
1094 return;
1095 s += n;
1096 printf(" -{%s ", user);
1097 ACLOUT(acl);
1098 printf("}");
1099 if (s > end)
1100 return;
1101 }
1102 }
1103
1104 #undef ACLOUT
1105
1106 /*
1107 * Handle calls to the AFS callback service
1108 */
1109
1110 static void
1111 cb_print(register const u_char *bp, int length)
1112 {
1113 int cb_op;
1114 unsigned long i;
1115
1116 if (length <= sizeof(struct rx_header))
1117 return;
1118
1119 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1120 goto trunc;
1121 }
1122
1123 /*
1124 * Print out the afs call we're invoking. The table used here was
1125 * gleaned from fsint/afscbint.xg
1126 */
1127
1128 cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1129
1130 printf(" cb call %s", tok2str(cb_req, "op#%d", cb_op));
1131
1132 bp += sizeof(struct rx_header) + 4;
1133
1134 /*
1135 * Print out the afs call we're invoking. The table used here was
1136 * gleaned from fsint/afscbint.xg
1137 */
1138
1139 switch (cb_op) {
1140 case 204: /* Callback */
1141 {
1142 unsigned long j, t;
1143 TCHECK2(bp[0], 4);
1144 j = EXTRACT_32BITS(bp);
1145 bp += sizeof(int32_t);
1146
1147 for (i = 0; i < j; i++) {
1148 FIDOUT();
1149 if (i != j - 1)
1150 printf(",");
1151 }
1152
1153 if (j == 0)
1154 printf(" <none!>");
1155
1156 j = EXTRACT_32BITS(bp);
1157 bp += sizeof(int32_t);
1158
1159 if (j != 0)
1160 printf(";");
1161
1162 for (i = 0; i < j; i++) {
1163 printf(" ver");
1164 INTOUT();
1165 printf(" expires");
1166 DATEOUT();
1167 TCHECK2(bp[0], 4);
1168 t = EXTRACT_32BITS(bp);
1169 bp += sizeof(int32_t);
1170 tok2str(cb_types, "type %d", t);
1171 }
1172 }
1173 case 214: {
1174 printf(" afsuuid");
1175 AFSUUIDOUT();
1176 break;
1177 }
1178 default:
1179 ;
1180 }
1181
1182 return;
1183
1184 trunc:
1185 printf(" [|cb]");
1186 }
1187
1188 /*
1189 * Handle replies to the AFS Callback Service
1190 */
1191
1192 static void
1193 cb_reply_print(register const u_char *bp, int length, int32_t opcode)
1194 {
1195 struct rx_header *rxh;
1196
1197 if (length <= sizeof(struct rx_header))
1198 return;
1199
1200 rxh = (struct rx_header *) bp;
1201
1202 /*
1203 * Print out the afs call we're invoking. The table used here was
1204 * gleaned from fsint/afscbint.xg
1205 */
1206
1207 printf(" cb reply %s", tok2str(cb_req, "op#%d", opcode));
1208
1209 bp += sizeof(struct rx_header);
1210
1211 /*
1212 * If it was a data packet, interpret the response.
1213 */
1214
1215 if (rxh->type == RX_PACKET_TYPE_DATA)
1216 switch (opcode) {
1217 case 213: /* InitCallBackState3 */
1218 AFSUUIDOUT();
1219 break;
1220 default:
1221 ;
1222 }
1223 else {
1224 /*
1225 * Otherwise, just print out the return code
1226 */
1227 printf(" errcode");
1228 INTOUT();
1229 }
1230
1231 return;
1232
1233 trunc:
1234 printf(" [|cb]");
1235 }
1236
1237 /*
1238 * Handle calls to the AFS protection database server
1239 */
1240
1241 static void
1242 prot_print(register const u_char *bp, int length)
1243 {
1244 unsigned long i;
1245 char s[AFSNAMEMAX];
1246 int pt_op;
1247
1248 if (length <= sizeof(struct rx_header))
1249 return;
1250
1251 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1252 goto trunc;
1253 }
1254
1255 /*
1256 * Print out the afs call we're invoking. The table used here was
1257 * gleaned from ptserver/ptint.xg
1258 */
1259
1260 pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1261
1262 printf(" pt");
1263
1264 if (is_ubik(pt_op)) {
1265 ubik_print(bp, length);
1266 return;
1267 }
1268
1269 printf(" call %s", tok2str(pt_req, "op#%d", pt_op));
1270
1271 /*
1272 * Decode some of the arguments to the PT calls
1273 */
1274
1275 bp += sizeof(struct rx_header) + 4;
1276
1277 switch (pt_op) {
1278 case 500: /* I New User */
1279 STROUT(PRNAMEMAX);
1280 printf(" id");
1281 INTOUT();
1282 printf(" oldid");
1283 INTOUT();
1284 break;
1285 case 501: /* Where is it */
1286 case 506: /* Delete */
1287 case 508: /* Get CPS */
1288 case 512: /* List entry */
1289 case 514: /* List elements */
1290 case 517: /* List owned */
1291 case 518: /* Get CPS2 */
1292 case 519: /* Get host CPS */
1293 printf(" id");
1294 INTOUT();
1295 break;
1296 case 502: /* Dump entry */
1297 printf(" pos");
1298 INTOUT();
1299 break;
1300 case 503: /* Add to group */
1301 case 507: /* Remove from group */
1302 case 515: /* Is a member of? */
1303 printf(" uid");
1304 INTOUT();
1305 printf(" gid");
1306 INTOUT();
1307 break;
1308 case 504: /* Name to ID */
1309 {
1310 unsigned long j;
1311 TCHECK2(bp[0], 4);
1312 j = EXTRACT_32BITS(bp);
1313 bp += sizeof(int32_t);
1314
1315 /*
1316 * Who designed this chicken-shit protocol?
1317 *
1318 * Each character is stored as a 32-bit
1319 * integer!
1320 */
1321
1322 for (i = 0; i < j; i++) {
1323 VECOUT(PRNAMEMAX);
1324 }
1325 if (j == 0)
1326 printf(" <none!>");
1327 }
1328 break;
1329 case 505: /* Id to name */
1330 {
1331 unsigned long j;
1332 printf(" ids:");
1333 TCHECK2(bp[0], 4);
1334 i = EXTRACT_32BITS(bp);
1335 bp += sizeof(int32_t);
1336 for (j = 0; j < i; j++)
1337 INTOUT();
1338 if (j == 0)
1339 printf(" <none!>");
1340 }
1341 break;
1342 case 509: /* New entry */
1343 STROUT(PRNAMEMAX);
1344 printf(" flag");
1345 INTOUT();
1346 printf(" oid");
1347 INTOUT();
1348 break;
1349 case 511: /* Set max */
1350 printf(" id");
1351 INTOUT();
1352 printf(" gflag");
1353 INTOUT();
1354 break;
1355 case 513: /* Change entry */
1356 printf(" id");
1357 INTOUT();
1358 STROUT(PRNAMEMAX);
1359 printf(" oldid");
1360 INTOUT();
1361 printf(" newid");
1362 INTOUT();
1363 break;
1364 case 520: /* Update entry */
1365 printf(" id");
1366 INTOUT();
1367 STROUT(PRNAMEMAX);
1368 break;
1369 default:
1370 ;
1371 }
1372
1373
1374 return;
1375
1376 trunc:
1377 printf(" [|pt]");
1378 }
1379
1380 /*
1381 * Handle replies to the AFS protection service
1382 */
1383
1384 static void
1385 prot_reply_print(register const u_char *bp, int length, int32_t opcode)
1386 {
1387 struct rx_header *rxh;
1388 unsigned long i;
1389 char s[AFSNAMEMAX];
1390
1391 if (length < sizeof(struct rx_header))
1392 return;
1393
1394 rxh = (struct rx_header *) bp;
1395
1396 /*
1397 * Print out the afs call we're invoking. The table used here was
1398 * gleaned from ptserver/ptint.xg. Check to see if it's a
1399 * Ubik call, however.
1400 */
1401
1402 printf(" pt");
1403
1404 if (is_ubik(opcode)) {
1405 ubik_reply_print(bp, length, opcode);
1406 return;
1407 }
1408
1409 printf(" reply %s", tok2str(pt_req, "op#%d", opcode));
1410
1411 bp += sizeof(struct rx_header);
1412
1413 /*
1414 * If it was a data packet, interpret the response
1415 */
1416
1417 if (rxh->type == RX_PACKET_TYPE_DATA)
1418 switch (opcode) {
1419 case 504: /* Name to ID */
1420 {
1421 unsigned long j;
1422 printf(" ids:");
1423 TCHECK2(bp[0], 4);
1424 i = EXTRACT_32BITS(bp);
1425 bp += sizeof(int32_t);
1426 for (j = 0; j < i; j++)
1427 INTOUT();
1428 if (j == 0)
1429 printf(" <none!>");
1430 }
1431 break;
1432 case 505: /* ID to name */
1433 {
1434 unsigned long j;
1435 TCHECK2(bp[0], 4);
1436 j = EXTRACT_32BITS(bp);
1437 bp += sizeof(int32_t);
1438
1439 /*
1440 * Who designed this chicken-shit protocol?
1441 *
1442 * Each character is stored as a 32-bit
1443 * integer!
1444 */
1445
1446 for (i = 0; i < j; i++) {
1447 VECOUT(PRNAMEMAX);
1448 }
1449 if (j == 0)
1450 printf(" <none!>");
1451 }
1452 break;
1453 case 508: /* Get CPS */
1454 case 514: /* List elements */
1455 case 517: /* List owned */
1456 case 518: /* Get CPS2 */
1457 case 519: /* Get host CPS */
1458 {
1459 unsigned long j;
1460 TCHECK2(bp[0], 4);
1461 j = EXTRACT_32BITS(bp);
1462 bp += sizeof(int32_t);
1463 for (i = 0; i < j; i++) {
1464 INTOUT();
1465 }
1466 if (j == 0)
1467 printf(" <none!>");
1468 }
1469 break;
1470 case 510: /* List max */
1471 printf(" maxuid");
1472 INTOUT();
1473 printf(" maxgid");
1474 INTOUT();
1475 break;
1476 default:
1477 ;
1478 }
1479 else {
1480 /*
1481 * Otherwise, just print out the return code
1482 */
1483 printf(" errcode");
1484 INTOUT();
1485 }
1486
1487 return;
1488
1489 trunc:
1490 printf(" [|pt]");
1491 }
1492
1493 /*
1494 * Handle calls to the AFS volume location database service
1495 */
1496
1497 static void
1498 vldb_print(register const u_char *bp, int length)
1499 {
1500 int vldb_op;
1501 unsigned long i;
1502 char s[AFSNAMEMAX];
1503
1504 if (length <= sizeof(struct rx_header))
1505 return;
1506
1507 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1508 goto trunc;
1509 }
1510
1511 /*
1512 * Print out the afs call we're invoking. The table used here was
1513 * gleaned from vlserver/vldbint.xg
1514 */
1515
1516 vldb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1517
1518 printf(" vldb");
1519
1520 if (is_ubik(vldb_op)) {
1521 ubik_print(bp, length);
1522 return;
1523 }
1524 printf(" call %s", tok2str(vldb_req, "op#%d", vldb_op));
1525
1526 /*
1527 * Decode some of the arguments to the VLDB calls
1528 */
1529
1530 bp += sizeof(struct rx_header) + 4;
1531
1532 switch (vldb_op) {
1533 case 501: /* Create new volume */
1534 case 517: /* Create entry N */
1535 VECOUT(VLNAMEMAX);
1536 break;
1537 case 502: /* Delete entry */
1538 case 503: /* Get entry by ID */
1539 case 507: /* Update entry */
1540 case 508: /* Set lock */
1541 case 509: /* Release lock */
1542 case 518: /* Get entry by ID N */
1543 printf(" volid");
1544 INTOUT();
1545 TCHECK2(bp[0], sizeof(int32_t));
1546 i = EXTRACT_32BITS(bp);
1547 bp += sizeof(int32_t);
1548 if (i <= 2)
1549 printf(" type %s", voltype[i]);
1550 break;
1551 case 504: /* Get entry by name */
1552 case 519: /* Get entry by name N */
1553 case 524: /* Update entry by name */
1554 case 527: /* Get entry by name U */
1555 STROUT(VLNAMEMAX);
1556 break;
1557 case 505: /* Get new vol id */
1558 printf(" bump");
1559 INTOUT();
1560 break;
1561 case 506: /* Replace entry */
1562 case 520: /* Replace entry N */
1563 printf(" volid");
1564 INTOUT();
1565 TCHECK2(bp[0], sizeof(int32_t));
1566 i = EXTRACT_32BITS(bp);
1567 bp += sizeof(int32_t);
1568 if (i <= 2)
1569 printf(" type %s", voltype[i]);
1570 VECOUT(VLNAMEMAX);
1571 break;
1572 case 510: /* List entry */
1573 case 521: /* List entry N */
1574 printf(" index");
1575 INTOUT();
1576 break;
1577 default:
1578 ;
1579 }
1580
1581 return;
1582
1583 trunc:
1584 printf(" [|vldb]");
1585 }
1586
1587 /*
1588 * Handle replies to the AFS volume location database service
1589 */
1590
1591 static void
1592 vldb_reply_print(register const u_char *bp, int length, int32_t opcode)
1593 {
1594 struct rx_header *rxh;
1595 unsigned long i;
1596 char s[AFSNAMEMAX];
1597
1598 if (length < sizeof(struct rx_header))
1599 return;
1600
1601 rxh = (struct rx_header *) bp;
1602
1603 /*
1604 * Print out the afs call we're invoking. The table used here was
1605 * gleaned from vlserver/vldbint.xg. Check to see if it's a
1606 * Ubik call, however.
1607 */
1608
1609 printf(" vldb");
1610
1611 if (is_ubik(opcode)) {
1612 ubik_reply_print(bp, length, opcode);
1613 return;
1614 }
1615
1616 printf(" reply %s", tok2str(vldb_req, "op#%d", opcode));
1617
1618 bp += sizeof(struct rx_header);
1619
1620 /*
1621 * If it was a data packet, interpret the response
1622 */
1623
1624 if (rxh->type == RX_PACKET_TYPE_DATA)
1625 switch (opcode) {
1626 case 510: /* List entry */
1627 printf(" count");
1628 INTOUT();
1629 printf(" nextindex");
1630 INTOUT();
1631 case 503: /* Get entry by id */
1632 case 504: /* Get entry by name */
1633 { unsigned long nservers, j;
1634 VECOUT(VLNAMEMAX);
1635 TCHECK2(bp[0], sizeof(int32_t));
1636 bp += sizeof(int32_t);
1637 printf(" numservers");
1638 TCHECK2(bp[0], sizeof(int32_t));
1639 nservers = EXTRACT_32BITS(bp);
1640 bp += sizeof(int32_t);
1641 printf(" %lu", nservers);
1642 printf(" servers");
1643 for (i = 0; i < 8; i++) {
1644 TCHECK2(bp[0], sizeof(int32_t));
1645 if (i < nservers)
1646 printf(" %s",
1647 inet_ntoa(*((struct in_addr *) bp)));
1648 bp += sizeof(int32_t);
1649 }
1650 printf(" partitions");
1651 for (i = 0; i < 8; i++) {
1652 TCHECK2(bp[0], sizeof(int32_t));
1653 j = EXTRACT_32BITS(bp);
1654 if (i < nservers && j <= 26)
1655 printf(" %c", 'a' + (int)j);
1656 else if (i < nservers)
1657 printf(" %lu", j);
1658 bp += sizeof(int32_t);
1659 }
1660 TCHECK2(bp[0], 8 * sizeof(int32_t));
1661 bp += 8 * sizeof(int32_t);
1662 printf(" rwvol");
1663 UINTOUT();
1664 printf(" rovol");
1665 UINTOUT();
1666 printf(" backup");
1667 UINTOUT();
1668 }
1669 break;
1670 case 505: /* Get new volume ID */
1671 printf(" newvol");
1672 UINTOUT();
1673 break;
1674 case 521: /* List entry */
1675 case 529: /* List entry U */
1676 printf(" count");
1677 INTOUT();
1678 printf(" nextindex");
1679 INTOUT();
1680 case 518: /* Get entry by ID N */
1681 case 519: /* Get entry by name N */
1682 { unsigned long nservers, j;
1683 VECOUT(VLNAMEMAX);
1684 printf(" numservers");
1685 TCHECK2(bp[0], sizeof(int32_t));
1686 nservers = EXTRACT_32BITS(bp);
1687 bp += sizeof(int32_t);
1688 printf(" %lu", nservers);
1689 printf(" servers");
1690 for (i = 0; i < 13; i++) {
1691 TCHECK2(bp[0], sizeof(int32_t));
1692 if (i < nservers)
1693 printf(" %s",
1694 inet_ntoa(*((struct in_addr *) bp)));
1695 bp += sizeof(int32_t);
1696 }
1697 printf(" partitions");
1698 for (i = 0; i < 13; i++) {
1699 TCHECK2(bp[0], sizeof(int32_t));
1700 j = EXTRACT_32BITS(bp);
1701 if (i < nservers && j <= 26)
1702 printf(" %c", 'a' + (int)j);
1703 else if (i < nservers)
1704 printf(" %lu", j);
1705 bp += sizeof(int32_t);
1706 }
1707 TCHECK2(bp[0], 13 * sizeof(int32_t));
1708 bp += 13 * sizeof(int32_t);
1709 printf(" rwvol");
1710 UINTOUT();
1711 printf(" rovol");
1712 UINTOUT();
1713 printf(" backup");
1714 UINTOUT();
1715 }
1716 break;
1717 case 526: /* Get entry by ID U */
1718 case 527: /* Get entry by name U */
1719 { unsigned long nservers, j;
1720 VECOUT(VLNAMEMAX);
1721 printf(" numservers");
1722 TCHECK2(bp[0], sizeof(int32_t));
1723 nservers = EXTRACT_32BITS(bp);
1724 bp += sizeof(int32_t);
1725 printf(" %lu", nservers);
1726 printf(" servers");
1727 for (i = 0; i < 13; i++) {
1728 if (i < nservers) {
1729 printf(" afsuuid");
1730 AFSUUIDOUT();
1731 } else {
1732 TCHECK2(bp[0], 44);
1733 bp += 44;
1734 }
1735 }
1736 TCHECK2(bp[0], 4 * 13);
1737 bp += 4 * 13;
1738 printf(" partitions");
1739 for (i = 0; i < 13; i++) {
1740 TCHECK2(bp[0], sizeof(int32_t));
1741 j = EXTRACT_32BITS(bp);
1742 if (i < nservers && j <= 26)
1743 printf(" %c", 'a' + (int)j);
1744 else if (i < nservers)
1745 printf(" %lu", j);
1746 bp += sizeof(int32_t);
1747 }
1748 TCHECK2(bp[0], 13 * sizeof(int32_t));
1749 bp += 13 * sizeof(int32_t);
1750 printf(" rwvol");
1751 UINTOUT();
1752 printf(" rovol");
1753 UINTOUT();
1754 printf(" backup");
1755 UINTOUT();
1756 }
1757 default:
1758 ;
1759 }
1760
1761 else {
1762 /*
1763 * Otherwise, just print out the return code
1764 */
1765 printf(" errcode");
1766 INTOUT();
1767 }
1768
1769 return;
1770
1771 trunc:
1772 printf(" [|vldb]");
1773 }
1774
1775 /*
1776 * Handle calls to the AFS Kerberos Authentication service
1777 */
1778
1779 static void
1780 kauth_print(register const u_char *bp, int length)
1781 {
1782 int kauth_op;
1783 char s[AFSNAMEMAX];
1784
1785 if (length <= sizeof(struct rx_header))
1786 return;
1787
1788 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1789 goto trunc;
1790 }
1791
1792 /*
1793 * Print out the afs call we're invoking. The table used here was
1794 * gleaned from kauth/kauth.rg
1795 */
1796
1797 kauth_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1798
1799 printf(" kauth");
1800
1801 if (is_ubik(kauth_op)) {
1802 ubik_print(bp, length);
1803 return;
1804 }
1805
1806
1807 printf(" call %s", tok2str(kauth_req, "op#%d", kauth_op));
1808
1809 /*
1810 * Decode some of the arguments to the KA calls
1811 */
1812
1813 bp += sizeof(struct rx_header) + 4;
1814
1815 switch (kauth_op) {
1816 case 1: /* Authenticate old */;
1817 case 21: /* Authenticate */
1818 case 22: /* Authenticate-V2 */
1819 case 2: /* Change PW */
1820 case 5: /* Set fields */
1821 case 6: /* Create user */
1822 case 7: /* Delete user */
1823 case 8: /* Get entry */
1824 case 14: /* Unlock */
1825 case 15: /* Lock status */
1826 printf(" principal");
1827 STROUT(KANAMEMAX);
1828 STROUT(KANAMEMAX);
1829 break;
1830 case 3: /* GetTicket-old */
1831 case 23: /* GetTicket */
1832 {
1833 int i;
1834 printf(" kvno");
1835 INTOUT();
1836 printf(" domain");
1837 STROUT(KANAMEMAX);
1838 TCHECK2(bp[0], sizeof(int32_t));
1839 i = (int) EXTRACT_32BITS(bp);
1840 bp += sizeof(int32_t);
1841 TCHECK2(bp[0], i);
1842 bp += i;
1843 printf(" principal");
1844 STROUT(KANAMEMAX);
1845 STROUT(KANAMEMAX);
1846 break;
1847 }
1848 case 4: /* Set Password */
1849 printf(" principal");
1850 STROUT(KANAMEMAX);
1851 STROUT(KANAMEMAX);
1852 printf(" kvno");
1853 INTOUT();
1854 break;
1855 case 12: /* Get password */
1856 printf(" name");
1857 STROUT(KANAMEMAX);
1858 break;
1859 default:
1860 ;
1861 }
1862
1863 return;
1864
1865 trunc:
1866 printf(" [|kauth]");
1867 }
1868
1869 /*
1870 * Handle replies to the AFS Kerberos Authentication Service
1871 */
1872
1873 static void
1874 kauth_reply_print(register const u_char *bp, int length, int32_t opcode)
1875 {
1876 struct rx_header *rxh;
1877
1878 if (length <= sizeof(struct rx_header))
1879 return;
1880
1881 rxh = (struct rx_header *) bp;
1882
1883 /*
1884 * Print out the afs call we're invoking. The table used here was
1885 * gleaned from kauth/kauth.rg
1886 */
1887
1888 printf(" kauth");
1889
1890 if (is_ubik(opcode)) {
1891 ubik_reply_print(bp, length, opcode);
1892 return;
1893 }
1894
1895 printf(" reply %s", tok2str(kauth_req, "op#%d", opcode));
1896
1897 bp += sizeof(struct rx_header);
1898
1899 /*
1900 * If it was a data packet, interpret the response.
1901 */
1902
1903 if (rxh->type == RX_PACKET_TYPE_DATA)
1904 /* Well, no, not really. Leave this for later */
1905 ;
1906 else {
1907 /*
1908 * Otherwise, just print out the return code
1909 */
1910 printf(" errcode");
1911 INTOUT();
1912 }
1913
1914 return;
1915
1916 trunc:
1917 printf(" [|kauth]");
1918 }
1919
1920 /*
1921 * Handle calls to the AFS Volume location service
1922 */
1923
1924 static void
1925 vol_print(register const u_char *bp, int length)
1926 {
1927 int vol_op;
1928
1929 if (length <= sizeof(struct rx_header))
1930 return;
1931
1932 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
1933 goto trunc;
1934 }
1935
1936 /*
1937 * Print out the afs call we're invoking. The table used here was
1938 * gleaned from volser/volint.xg
1939 */
1940
1941 vol_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
1942
1943 printf(" vol call %s", tok2str(vol_req, "op#%d", vol_op));
1944
1945 /*
1946 * Normally there would be a switch statement here to decode the
1947 * arguments to the AFS call, but since I don't have access to
1948 * an AFS server (yet) and I'm not an AFS admin, I can't
1949 * test any of these calls. Leave this blank for now.
1950 */
1951
1952 return;
1953
1954 trunc:
1955 printf(" [|vol]");
1956 }
1957
1958 /*
1959 * Handle replies to the AFS Volume Service
1960 */
1961
1962 static void
1963 vol_reply_print(register const u_char *bp, int length, int32_t opcode)
1964 {
1965 struct rx_header *rxh;
1966
1967 if (length <= sizeof(struct rx_header))
1968 return;
1969
1970 rxh = (struct rx_header *) bp;
1971
1972 /*
1973 * Print out the afs call we're invoking. The table used here was
1974 * gleaned from volser/volint.xg
1975 */
1976
1977 printf(" vol reply %s", tok2str(vol_req, "op#%d", opcode));
1978
1979 bp += sizeof(struct rx_header);
1980
1981 /*
1982 * If it was a data packet, interpret the response.
1983 */
1984
1985 if (rxh->type == RX_PACKET_TYPE_DATA)
1986 /* Well, no, not really. Leave this for later */
1987 ;
1988 else {
1989 /*
1990 * Otherwise, just print out the return code
1991 */
1992 printf(" errcode");
1993 INTOUT();
1994 }
1995
1996 return;
1997
1998 trunc:
1999 printf(" [|vol]");
2000 }
2001
2002 /*
2003 * Handle calls to the AFS BOS service
2004 */
2005
2006 static void
2007 bos_print(register const u_char *bp, int length)
2008 {
2009 int bos_op;
2010 char s[BOSNAMEMAX];
2011
2012 if (length <= sizeof(struct rx_header))
2013 return;
2014
2015 if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t)) {
2016 goto trunc;
2017 }
2018
2019 /*
2020 * Print out the afs call we're invoking. The table used here was
2021 * gleaned from bozo/bosint.xg
2022 */
2023
2024 bos_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2025
2026 printf(" bos call %s", tok2str(bos_req, "op#%d", bos_op));
2027
2028 /*
2029 * Decode some of the arguments to the BOS calls
2030 */
2031
2032 bp += sizeof(struct rx_header) + 4;
2033
2034 switch (bos_op) {
2035 case 80: /* Create B node */
2036 printf(" type");
2037 STROUT(BOSNAMEMAX);
2038 printf(" instance");
2039 STROUT(BOSNAMEMAX);
2040 break;
2041 case 81: /* Delete B node */
2042 case 83: /* Get status */
2043 case 85: /* Get instance info */
2044 case 87: /* Add super user */
2045 case 88: /* Delete super user */
2046 case 93: /* Set cell name */
2047 case 96: /* Add cell host */
2048 case 97: /* Delete cell host */
2049 case 104: /* Restart */
2050 case 106: /* Uninstall */
2051 case 108: /* Exec */
2052 case 112: /* Getlog */
2053 case 114: /* Get instance strings */
2054 STROUT(BOSNAMEMAX);
2055 break;
2056 case 82: /* Set status */
2057 case 98: /* Set T status */
2058 STROUT(BOSNAMEMAX);
2059 printf(" status");
2060 INTOUT();
2061 break;
2062 case 86: /* Get instance parm */
2063 STROUT(BOSNAMEMAX);
2064 printf(" num");
2065 INTOUT();
2066 break;
2067 case 84: /* Enumerate instance */
2068 case 89: /* List super users */
2069 case 90: /* List keys */
2070 case 91: /* Add key */
2071 case 92: /* Delete key */
2072 case 95: /* Get cell host */
2073 INTOUT();
2074 break;
2075 case 105: /* Install */
2076 STROUT(BOSNAMEMAX);
2077 printf(" size");
2078 INTOUT();
2079 printf(" flags");
2080 INTOUT();
2081 printf(" date");
2082 INTOUT();
2083 break;
2084 default:
2085 ;
2086 }
2087
2088 return;
2089
2090 trunc:
2091 printf(" [|bos]");
2092 }
2093
2094 /*
2095 * Handle replies to the AFS BOS Service
2096 */
2097
2098 static void
2099 bos_reply_print(register const u_char *bp, int length, int32_t opcode)
2100 {
2101 struct rx_header *rxh;
2102
2103 if (length <= sizeof(struct rx_header))
2104 return;
2105
2106 rxh = (struct rx_header *) bp;
2107
2108 /*
2109 * Print out the afs call we're invoking. The table used here was
2110 * gleaned from volser/volint.xg
2111 */
2112
2113 printf(" bos reply %s", tok2str(bos_req, "op#%d", opcode));
2114
2115 bp += sizeof(struct rx_header);
2116
2117 /*
2118 * If it was a data packet, interpret the response.
2119 */
2120
2121 if (rxh->type == RX_PACKET_TYPE_DATA)
2122 /* Well, no, not really. Leave this for later */
2123 ;
2124 else {
2125 /*
2126 * Otherwise, just print out the return code
2127 */
2128 printf(" errcode");
2129 INTOUT();
2130 }
2131
2132 return;
2133
2134 trunc:
2135 printf(" [|bos]");
2136 }
2137
2138 /*
2139 * Check to see if this is a Ubik opcode.
2140 */
2141
2142 static int
2143 is_ubik(u_int32_t opcode)
2144 {
2145 if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
2146 (opcode >= DISK_LOW && opcode <= DISK_HIGH))
2147 return(1);
2148 else
2149 return(0);
2150 }
2151
2152 /*
2153 * Handle Ubik opcodes to any one of the replicated database services
2154 */
2155
2156 static void
2157 ubik_print(register const u_char *bp, int length)
2158 {
2159 int ubik_op;
2160 int32_t temp;
2161
2162 /*
2163 * Print out the afs call we're invoking. The table used here was
2164 * gleaned from ubik/ubik_int.xg
2165 */
2166
2167 ubik_op = EXTRACT_32BITS(bp + sizeof(struct rx_header));
2168
2169 printf(" ubik call %s", tok2str(ubik_req, "op#%d", ubik_op));
2170
2171 /*
2172 * Decode some of the arguments to the Ubik calls
2173 */
2174
2175 bp += sizeof(struct rx_header) + 4;
2176
2177 switch (ubik_op) {
2178 case 10000: /* Beacon */
2179 TCHECK2(bp[0], 4);
2180 temp = EXTRACT_32BITS(bp);
2181 bp += sizeof(int32_t);
2182 printf(" syncsite %s", temp ? "yes" : "no");
2183 printf(" votestart");
2184 DATEOUT();
2185 printf(" dbversion");
2186 UBIK_VERSIONOUT();
2187 printf(" tid");
2188 UBIK_VERSIONOUT();
2189 break;
2190 case 10003: /* Get sync site */
2191 printf(" site");
2192 UINTOUT();
2193 break;
2194 case 20000: /* Begin */
2195 case 20001: /* Commit */
2196 case 20007: /* Abort */
2197 case 20008: /* Release locks */
2198 case 20010: /* Writev */
2199 printf(" tid");
2200 UBIK_VERSIONOUT();
2201 break;
2202 case 20002: /* Lock */
2203 printf(" tid");
2204 UBIK_VERSIONOUT();
2205 printf(" file");
2206 INTOUT();
2207 printf(" pos");
2208 INTOUT();
2209 printf(" length");
2210 INTOUT();
2211 temp = EXTRACT_32BITS(bp);
2212 bp += sizeof(int32_t);
2213 tok2str(ubik_lock_types, "type %d", temp);
2214 break;
2215 case 20003: /* Write */
2216 printf(" tid");
2217 UBIK_VERSIONOUT();
2218 printf(" file");
2219 INTOUT();
2220 printf(" pos");
2221 INTOUT();
2222 break;
2223 case 20005: /* Get file */
2224 printf(" file");
2225 INTOUT();
2226 break;
2227 case 20006: /* Send file */
2228 printf(" file");
2229 INTOUT();
2230 printf(" length");
2231 INTOUT();
2232 printf(" dbversion");
2233 UBIK_VERSIONOUT();
2234 break;
2235 case 20009: /* Truncate */
2236 printf(" tid");
2237 UBIK_VERSIONOUT();
2238 printf(" file");
2239 INTOUT();
2240 printf(" length");
2241 INTOUT();
2242 break;
2243 case 20012: /* Set version */
2244 printf(" tid");
2245 UBIK_VERSIONOUT();
2246 printf(" oldversion");
2247 UBIK_VERSIONOUT();
2248 printf(" newversion");
2249 UBIK_VERSIONOUT();
2250 break;
2251 default:
2252 ;
2253 }
2254
2255 return;
2256
2257 trunc:
2258 printf(" [|ubik]");
2259 }
2260
2261 /*
2262 * Handle Ubik replies to any one of the replicated database services
2263 */
2264
2265 static void
2266 ubik_reply_print(register const u_char *bp, int length, int32_t opcode)
2267 {
2268 struct rx_header *rxh;
2269
2270 if (length < sizeof(struct rx_header))
2271 return;
2272
2273 rxh = (struct rx_header *) bp;
2274
2275 /*
2276 * Print out the ubik call we're invoking. This table was gleaned
2277 * from ubik/ubik_int.xg
2278 */
2279
2280 printf(" ubik reply %s", tok2str(ubik_req, "op#%d", opcode));
2281
2282 bp += sizeof(struct rx_header);
2283
2284 /*
2285 * If it was a data packet, print out the arguments to the Ubik calls
2286 */
2287
2288 if (rxh->type == RX_PACKET_TYPE_DATA)
2289 switch (opcode) {
2290 case 10000: /* Beacon */
2291 printf(" vote no");
2292 break;
2293 case 20004: /* Get version */
2294 printf(" dbversion");
2295 UBIK_VERSIONOUT();
2296 break;
2297 default:
2298 ;
2299 }
2300
2301 /*
2302 * Otherwise, print out "yes" it it was a beacon packet (because
2303 * that's how yes votes are returned, go figure), otherwise
2304 * just print out the error code.
2305 */
2306
2307 else
2308 switch (opcode) {
2309 case 10000: /* Beacon */
2310 printf(" vote yes until");
2311 DATEOUT();
2312 break;
2313 default:
2314 printf(" errcode");
2315 INTOUT();
2316 }
2317
2318 return;
2319
2320 trunc:
2321 printf(" [|ubik]");
2322 }
2323
2324 /*
2325 * Handle RX ACK packets.
2326 */
2327
2328 void
2329 rx_ack_print(register const u_char *bp, int length)
2330 {
2331 struct rx_ackPacket *rxa;
2332 int i, start, last;
2333
2334 if (length < sizeof(struct rx_header))
2335 return;
2336
2337 bp += sizeof(struct rx_header);
2338
2339 /*
2340 * This may seem a little odd .... the rx_ackPacket structure
2341 * contains an array of individual packet acknowledgements
2342 * (used for selective ack/nack), but since it's variable in size,
2343 * we don't want to truncate based on the size of the whole
2344 * rx_ackPacket structure.
2345 */
2346
2347 TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS);
2348
2349 rxa = (struct rx_ackPacket *) bp;
2350 bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS);
2351
2352 /*
2353 * Print out a few useful things from the ack packet structure
2354 */
2355
2356 if (vflag > 2)
2357 printf(" bufspace %d maxskew %d",
2358 (int) EXTRACT_16BITS(&rxa->bufferSpace),
2359 (int) EXTRACT_16BITS(&rxa->maxSkew));
2360
2361 printf(" first %d serial %d reason %s",
2362 EXTRACT_32BITS(&rxa->firstPacket), EXTRACT_32BITS(&rxa->serial),
2363 tok2str(rx_ack_reasons, "#%d", (int) rxa->reason));
2364
2365 /*
2366 * Okay, now we print out the ack array. The way _this_ works
2367 * is that we start at "first", and step through the ack array.
2368 * If we have a contiguous range of acks/nacks, try to
2369 * collapse them into a range.
2370 *
2371 * If you're really clever, you might have noticed that this
2372 * doesn't seem quite correct. Specifically, due to structure
2373 * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually
2374 * yield the start of the ack array (because RX_MAXACKS is 255
2375 * and the structure will likely get padded to a 2 or 4 byte
2376 * boundary). However, this is the way it's implemented inside
2377 * of AFS - the start of the extra fields are at
2378 * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_
2379 * the exact start of the ack array. Sigh. That's why we aren't
2380 * using bp, but instead use rxa->acks[]. But nAcks gets added
2381 * to bp after this, so bp ends up at the right spot. Go figure.
2382 */
2383
2384 if (rxa->nAcks != 0) {
2385
2386 TCHECK2(bp[0], rxa->nAcks);
2387
2388 /*
2389 * Sigh, this is gross, but it seems to work to collapse
2390 * ranges correctly.
2391 */
2392
2393 for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2394 if (rxa->acks[i] == RX_ACK_TYPE_ACK) {
2395
2396 /*
2397 * I figured this deserved _some_ explanation.
2398 * First, print "acked" and the packet seq
2399 * number if this is the first time we've
2400 * seen an acked packet.
2401 */
2402
2403 if (last == -2) {
2404 printf(" acked %d",
2405 rxa->firstPacket + i);
2406 start = i;
2407 }
2408
2409 /*
2410 * Otherwise, if the there is a skip in
2411 * the range (such as an nacked packet in
2412 * the middle of some acked packets),
2413 * then print the current packet number
2414 * seperated from the last number by
2415 * a comma.
2416 */
2417
2418 else if (last != i - 1) {
2419 printf(",%d", rxa->firstPacket + i);
2420 start = i;
2421 }
2422
2423 /*
2424 * We always set last to the value of
2425 * the last ack we saw. Conversely, start
2426 * is set to the value of the first ack
2427 * we saw in a range.
2428 */
2429
2430 last = i;
2431
2432 /*
2433 * Okay, this bit a code gets executed when
2434 * we hit a nack ... in _this_ case we
2435 * want to print out the range of packets
2436 * that were acked, so we need to print
2437 * the _previous_ packet number seperated
2438 * from the first by a dash (-). Since we
2439 * already printed the first packet above,
2440 * just print the final packet. Don't
2441 * do this if there will be a single-length
2442 * range.
2443 */
2444 } else if (last == i - 1 && start != last)
2445 printf("-%d", rxa->firstPacket + i - 1);
2446
2447 /*
2448 * So, what's going on here? We ran off the end of the
2449 * ack list, and if we got a range we need to finish it up.
2450 * So we need to determine if the last packet in the list
2451 * was an ack (if so, then last will be set to it) and
2452 * we need to see if the last range didn't start with the
2453 * last packet (because if it _did_, then that would mean
2454 * that the packet number has already been printed and
2455 * we don't need to print it again).
2456 */
2457
2458 if (last == i - 1 && start != last)
2459 printf("-%d", rxa->firstPacket + i - 1);
2460
2461 /*
2462 * Same as above, just without comments
2463 */
2464
2465 for (i = 0, start = last = -2; i < rxa->nAcks; i++)
2466 if (rxa->acks[i] == RX_ACK_TYPE_NACK) {
2467 if (last == -2) {
2468 printf(" nacked %d",
2469 rxa->firstPacket + i);
2470 start = i;
2471 } else if (last != i - 1) {
2472 printf(",%d", rxa->firstPacket + i);
2473 start = i;
2474 }
2475 last = i;
2476 } else if (last == i - 1 && start != last)
2477 printf("-%d", rxa->firstPacket + i - 1);
2478
2479 if (last == i - 1 && start != last)
2480 printf("-%d", rxa->firstPacket + i - 1);
2481
2482 bp += rxa->nAcks;
2483 }
2484
2485
2486 /*
2487 * These are optional fields; depending on your version of AFS,
2488 * you may or may not see them
2489 */
2490
2491 #define TRUNCRET(n) if (snapend - bp + 1 <= n) return;
2492
2493 if (vflag > 1) {
2494 TRUNCRET(4);
2495 printf(" ifmtu");
2496 INTOUT();
2497
2498 TRUNCRET(4);
2499 printf(" maxmtu");
2500 INTOUT();
2501
2502 TRUNCRET(4);
2503 printf(" rwind");
2504 INTOUT();
2505
2506 TRUNCRET(4);
2507 printf(" maxpackets");
2508 INTOUT();
2509 }
2510
2511 return;
2512
2513 trunc:
2514 printf(" [|ack]");
2515 }
2516 #undef TRUNCRET