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