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