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