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