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