]> The Tcpdump Group git mirrors - tcpdump/blob - print-rx.c
Revert partially the commit 21b1273
[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 _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 _i = GET_BE_U_4(bp); \
789 bp += sizeof(uint32_t); \
790 ND_PRINT(" %u", _i); \
791 }
792
793 #define UINT64OUT() { uint64_t _i; \
794 ND_TCHECK_LEN(bp, sizeof(uint64_t)); \
795 _i = GET_BE_U_8(bp); \
796 bp += sizeof(uint64_t); \
797 ND_PRINT(" %" PRIu64, _i); \
798 }
799
800 #define DATEOUT() { time_t _t; struct tm *tm; char str[256]; \
801 _t = (time_t) GET_BE_S_4(bp); \
802 bp += sizeof(int32_t); \
803 tm = localtime(&_t); \
804 strftime(str, 256, "%Y/%m/%d %H:%M:%S", tm); \
805 ND_PRINT(" %s", str); \
806 }
807
808 #define STOREATTROUT() { uint32_t mask, _i; \
809 ND_TCHECK_LEN(bp, (sizeof(uint32_t) * 6)); \
810 mask = GET_BE_U_4(bp); bp += sizeof(uint32_t); \
811 if (mask) ND_PRINT(" StoreStatus"); \
812 if (mask & 1) { ND_PRINT(" date"); DATEOUT(); } \
813 else bp += sizeof(uint32_t); \
814 _i = GET_BE_U_4(bp); bp += sizeof(uint32_t); \
815 if (mask & 2) ND_PRINT(" owner %u", _i); \
816 _i = GET_BE_U_4(bp); bp += sizeof(uint32_t); \
817 if (mask & 4) ND_PRINT(" group %u", _i); \
818 _i = GET_BE_U_4(bp); bp += sizeof(uint32_t); \
819 if (mask & 8) ND_PRINT(" mode %o", _i & 07777); \
820 _i = GET_BE_U_4(bp); bp += sizeof(uint32_t); \
821 if (mask & 16) ND_PRINT(" segsize %u", _i); \
822 /* undocumented in 3.3 docu */ \
823 if (mask & 1024) ND_PRINT(" fsync"); \
824 }
825
826 #define UBIK_VERSIONOUT() {uint32_t epoch; uint32_t counter; \
827 ND_TCHECK_LEN(bp, sizeof(uint32_t) * 2); \
828 epoch = GET_BE_U_4(bp); \
829 bp += sizeof(uint32_t); \
830 counter = GET_BE_U_4(bp); \
831 bp += sizeof(uint32_t); \
832 ND_PRINT(" %u.%u", epoch, counter); \
833 }
834
835 #define AFSUUIDOUT() {uint32_t temp; int _i; \
836 ND_TCHECK_LEN(bp, 11 * sizeof(uint32_t)); \
837 temp = GET_BE_U_4(bp); \
838 bp += sizeof(uint32_t); \
839 ND_PRINT(" %08x", temp); \
840 temp = GET_BE_U_4(bp); \
841 bp += sizeof(uint32_t); \
842 ND_PRINT("%04x", temp); \
843 temp = GET_BE_U_4(bp); \
844 bp += sizeof(uint32_t); \
845 ND_PRINT("%04x", temp); \
846 for (_i = 0; _i < 8; _i++) { \
847 temp = GET_BE_U_4(bp); \
848 bp += sizeof(uint32_t); \
849 ND_PRINT("%02x", (unsigned char) temp); \
850 } \
851 }
852
853 /*
854 * This is the sickest one of all
855 * MAX is expected to be a constant here
856 */
857
858 #define VECOUT(MAX) { u_char *sp; \
859 u_char s[(MAX) + 1]; \
860 uint32_t k; \
861 ND_TCHECK_LEN(bp, (MAX) * sizeof(uint32_t)); \
862 sp = s; \
863 for (k = 0; k < (MAX); k++) { \
864 *sp++ = (u_char) GET_BE_U_4(bp); \
865 bp += sizeof(uint32_t); \
866 } \
867 s[(MAX)] = '\0'; \
868 ND_PRINT(" \""); \
869 fn_print_str(ndo, s); \
870 ND_PRINT("\""); \
871 }
872
873 #define DESTSERVEROUT() { uint32_t n1, n2, n3; \
874 ND_TCHECK_LEN(bp, sizeof(uint32_t) * 3); \
875 n1 = GET_BE_U_4(bp); \
876 bp += sizeof(uint32_t); \
877 n2 = GET_BE_U_4(bp); \
878 bp += sizeof(uint32_t); \
879 n3 = GET_BE_U_4(bp); \
880 bp += sizeof(uint32_t); \
881 ND_PRINT(" server %u:%u:%u", n1, n2, n3); \
882 }
883
884 /*
885 * Handle calls to the AFS file service (fs)
886 */
887
888 static void
889 fs_print(netdissect_options *ndo,
890 const u_char *bp, u_int length)
891 {
892 uint32_t fs_op;
893 uint32_t i;
894
895 if (length <= sizeof(struct rx_header))
896 return;
897
898 /*
899 * Print out the afs call we're invoking. The table used here was
900 * gleaned from fsint/afsint.xg
901 */
902
903 fs_op = GET_BE_U_4(bp + sizeof(struct rx_header));
904
905 ND_PRINT(" fs call %s", tok2str(fs_req, "op#%u", fs_op));
906
907 /*
908 * Print out arguments to some of the AFS calls. This stuff is
909 * all from afsint.xg
910 */
911
912 bp += sizeof(struct rx_header) + 4;
913
914 /*
915 * Sigh. This is gross. Ritchie forgive me.
916 */
917
918 switch (fs_op) {
919 case 130: /* Fetch data */
920 FIDOUT();
921 ND_PRINT(" offset");
922 UINTOUT();
923 ND_PRINT(" length");
924 UINTOUT();
925 break;
926 case 131: /* Fetch ACL */
927 case 132: /* Fetch Status */
928 case 143: /* Old set lock */
929 case 144: /* Old extend lock */
930 case 145: /* Old release lock */
931 case 156: /* Set lock */
932 case 157: /* Extend lock */
933 case 158: /* Release lock */
934 FIDOUT();
935 break;
936 case 135: /* Store status */
937 FIDOUT();
938 STOREATTROUT();
939 break;
940 case 133: /* Store data */
941 FIDOUT();
942 STOREATTROUT();
943 ND_PRINT(" offset");
944 UINTOUT();
945 ND_PRINT(" length");
946 UINTOUT();
947 ND_PRINT(" flen");
948 UINTOUT();
949 break;
950 case 134: /* Store ACL */
951 {
952 char a[AFSOPAQUEMAX+1];
953 FIDOUT();
954 i = GET_BE_U_4(bp);
955 bp += sizeof(uint32_t);
956 ND_TCHECK_LEN(bp, i);
957 i = ND_MIN(AFSOPAQUEMAX, i);
958 strncpy(a, (const char *) bp, i);
959 a[i] = '\0';
960 acl_print(ndo, (u_char *) a, (u_char *) a + i);
961 break;
962 }
963 case 137: /* Create file */
964 case 141: /* MakeDir */
965 FIDOUT();
966 STROUT(AFSNAMEMAX);
967 STOREATTROUT();
968 break;
969 case 136: /* Remove file */
970 case 142: /* Remove directory */
971 FIDOUT();
972 STROUT(AFSNAMEMAX);
973 break;
974 case 138: /* Rename file */
975 ND_PRINT(" old");
976 FIDOUT();
977 STROUT(AFSNAMEMAX);
978 ND_PRINT(" new");
979 FIDOUT();
980 STROUT(AFSNAMEMAX);
981 break;
982 case 139: /* Symlink */
983 FIDOUT();
984 STROUT(AFSNAMEMAX);
985 ND_PRINT(" link to");
986 STROUT(AFSNAMEMAX);
987 break;
988 case 140: /* Link */
989 FIDOUT();
990 STROUT(AFSNAMEMAX);
991 ND_PRINT(" link to");
992 FIDOUT();
993 break;
994 case 148: /* Get volume info */
995 STROUT(AFSNAMEMAX);
996 break;
997 case 149: /* Get volume stats */
998 case 150: /* Set volume stats */
999 ND_PRINT(" volid");
1000 UINTOUT();
1001 break;
1002 case 154: /* New get volume info */
1003 ND_PRINT(" volname");
1004 STROUT(AFSNAMEMAX);
1005 break;
1006 case 155: /* Bulk stat */
1007 case 65536: /* Inline bulk stat */
1008 {
1009 uint32_t j;
1010 j = GET_BE_U_4(bp);
1011 bp += sizeof(uint32_t);
1012
1013 for (i = 0; i < j; i++) {
1014 FIDOUT();
1015 if (i != j - 1)
1016 ND_PRINT(",");
1017 }
1018 if (j == 0)
1019 ND_PRINT(" <none!>");
1020 break;
1021 }
1022 case 65537: /* Fetch data 64 */
1023 FIDOUT();
1024 ND_PRINT(" offset");
1025 UINT64OUT();
1026 ND_PRINT(" length");
1027 UINT64OUT();
1028 break;
1029 case 65538: /* Store data 64 */
1030 FIDOUT();
1031 STOREATTROUT();
1032 ND_PRINT(" offset");
1033 UINT64OUT();
1034 ND_PRINT(" length");
1035 UINT64OUT();
1036 ND_PRINT(" flen");
1037 UINT64OUT();
1038 break;
1039 case 65541: /* CallBack rx conn address */
1040 ND_PRINT(" addr");
1041 UINTOUT();
1042 default:
1043 ;
1044 }
1045
1046 return;
1047
1048 trunc:
1049 ND_PRINT(" [|fs]");
1050 }
1051
1052 /*
1053 * Handle replies to the AFS file service
1054 */
1055
1056 static void
1057 fs_reply_print(netdissect_options *ndo,
1058 const u_char *bp, u_int length, uint32_t opcode)
1059 {
1060 uint32_t i;
1061 const struct rx_header *rxh;
1062 uint8_t type;
1063
1064 if (length <= sizeof(struct rx_header))
1065 return;
1066
1067 rxh = (const struct rx_header *) bp;
1068
1069 /*
1070 * Print out the afs call we're invoking. The table used here was
1071 * gleaned from fsint/afsint.xg
1072 */
1073
1074 ND_PRINT(" fs reply %s", tok2str(fs_req, "op#%u", opcode));
1075
1076 type = GET_U_1(rxh->type);
1077 bp += sizeof(struct rx_header);
1078
1079 /*
1080 * If it was a data packet, interpret the response
1081 */
1082
1083 if (type == RX_PACKET_TYPE_DATA) {
1084 switch (opcode) {
1085 case 131: /* Fetch ACL */
1086 {
1087 char a[AFSOPAQUEMAX+1];
1088 i = GET_BE_U_4(bp);
1089 bp += sizeof(uint32_t);
1090 ND_TCHECK_LEN(bp, i);
1091 i = ND_MIN(AFSOPAQUEMAX, i);
1092 strncpy(a, (const char *) bp, i);
1093 a[i] = '\0';
1094 acl_print(ndo, (u_char *) a, (u_char *) a + i);
1095 break;
1096 }
1097 case 137: /* Create file */
1098 case 141: /* MakeDir */
1099 ND_PRINT(" new");
1100 FIDOUT();
1101 break;
1102 case 151: /* Get root volume */
1103 ND_PRINT(" root volume");
1104 STROUT(AFSNAMEMAX);
1105 break;
1106 case 153: /* Get time */
1107 DATEOUT();
1108 break;
1109 default:
1110 ;
1111 }
1112 } else if (type == RX_PACKET_TYPE_ABORT) {
1113 /*
1114 * Otherwise, just print out the return code
1115 */
1116 int32_t errcode;
1117
1118 errcode = GET_BE_S_4(bp);
1119 bp += sizeof(int32_t);
1120
1121 ND_PRINT(" error %s", tok2str(afs_fs_errors, "#%d", errcode));
1122 } else {
1123 ND_PRINT(" strange fs reply of type %u", type);
1124 }
1125
1126 return;
1127
1128 trunc:
1129 ND_PRINT(" [|fs]");
1130 }
1131
1132 /*
1133 * Print out an AFS ACL string. An AFS ACL is a string that has the
1134 * following format:
1135 *
1136 * <positive> <negative>
1137 * <uid1> <aclbits1>
1138 * ....
1139 *
1140 * "positive" and "negative" are integers which contain the number of
1141 * positive and negative ACL's in the string. The uid/aclbits pair are
1142 * ASCII strings containing the UID/PTS record and an ASCII number
1143 * representing a logical OR of all the ACL permission bits
1144 */
1145
1146 #define NUMSTRINGIFY(x) XSTRINGIFY(x)
1147
1148 static void
1149 acl_print(netdissect_options *ndo,
1150 u_char *s, u_char *end)
1151 {
1152 int pos, neg, acl;
1153 int n, i;
1154 char user[USERNAMEMAX+1];
1155
1156 if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
1157 return;
1158
1159 s += n;
1160
1161 if (s > end)
1162 return;
1163
1164 /*
1165 * This wacky order preserves the order used by the "fs" command
1166 */
1167
1168 #define ACLOUT(acl) \
1169 ND_PRINT("%s%s%s%s%s%s%s", \
1170 acl & PRSFS_READ ? "r" : "", \
1171 acl & PRSFS_LOOKUP ? "l" : "", \
1172 acl & PRSFS_INSERT ? "i" : "", \
1173 acl & PRSFS_DELETE ? "d" : "", \
1174 acl & PRSFS_WRITE ? "w" : "", \
1175 acl & PRSFS_LOCK ? "k" : "", \
1176 acl & PRSFS_ADMINISTER ? "a" : "");
1177
1178 for (i = 0; i < pos; i++) {
1179 if (sscanf((char *) s, "%" NUMSTRINGIFY(USERNAMEMAX) "s %d\n%n", user, &acl, &n) != 2)
1180 return;
1181 s += n;
1182 ND_PRINT(" +{");
1183 fn_print_str(ndo, (u_char *)user);
1184 ND_PRINT(" ");
1185 ACLOUT(acl);
1186 ND_PRINT("}");
1187 if (s > end)
1188 return;
1189 }
1190
1191 for (i = 0; i < neg; i++) {
1192 if (sscanf((char *) s, "%" NUMSTRINGIFY(USERNAMEMAX) "s %d\n%n", user, &acl, &n) != 2)
1193 return;
1194 s += n;
1195 ND_PRINT(" -{");
1196 fn_print_str(ndo, (u_char *)user);
1197 ND_PRINT(" ");
1198 ACLOUT(acl);
1199 ND_PRINT("}");
1200 if (s > end)
1201 return;
1202 }
1203 }
1204
1205 #undef ACLOUT
1206
1207 /*
1208 * Handle calls to the AFS callback service
1209 */
1210
1211 static void
1212 cb_print(netdissect_options *ndo,
1213 const u_char *bp, u_int length)
1214 {
1215 uint32_t cb_op;
1216 uint32_t i;
1217
1218 if (length <= sizeof(struct rx_header))
1219 return;
1220
1221 /*
1222 * Print out the afs call we're invoking. The table used here was
1223 * gleaned from fsint/afscbint.xg
1224 */
1225
1226 cb_op = GET_BE_U_4(bp + sizeof(struct rx_header));
1227
1228 ND_PRINT(" cb call %s", tok2str(cb_req, "op#%u", cb_op));
1229
1230 bp += sizeof(struct rx_header) + 4;
1231
1232 /*
1233 * Print out the afs call we're invoking. The table used here was
1234 * gleaned from fsint/afscbint.xg
1235 */
1236
1237 switch (cb_op) {
1238 case 204: /* Callback */
1239 {
1240 uint32_t j, t;
1241 j = GET_BE_U_4(bp);
1242 bp += sizeof(uint32_t);
1243
1244 for (i = 0; i < j; i++) {
1245 FIDOUT();
1246 if (i != j - 1)
1247 ND_PRINT(",");
1248 }
1249
1250 if (j == 0)
1251 ND_PRINT(" <none!>");
1252
1253 j = GET_BE_U_4(bp);
1254 bp += sizeof(uint32_t);
1255
1256 if (j != 0)
1257 ND_PRINT(";");
1258
1259 for (i = 0; i < j; i++) {
1260 ND_PRINT(" ver");
1261 INTOUT();
1262 ND_PRINT(" expires");
1263 DATEOUT();
1264 t = GET_BE_U_4(bp);
1265 bp += sizeof(uint32_t);
1266 tok2str(cb_types, "type %u", t);
1267 }
1268 break;
1269 }
1270 case 214: {
1271 ND_PRINT(" afsuuid");
1272 AFSUUIDOUT();
1273 break;
1274 }
1275 default:
1276 ;
1277 }
1278
1279 return;
1280
1281 trunc:
1282 ND_PRINT(" [|cb]");
1283 }
1284
1285 /*
1286 * Handle replies to the AFS Callback Service
1287 */
1288
1289 static void
1290 cb_reply_print(netdissect_options *ndo,
1291 const u_char *bp, u_int length, uint32_t opcode)
1292 {
1293 const struct rx_header *rxh;
1294 uint8_t type;
1295
1296 if (length <= sizeof(struct rx_header))
1297 return;
1298
1299 rxh = (const struct rx_header *) bp;
1300
1301 /*
1302 * Print out the afs call we're invoking. The table used here was
1303 * gleaned from fsint/afscbint.xg
1304 */
1305
1306 ND_PRINT(" cb reply %s", tok2str(cb_req, "op#%u", opcode));
1307
1308 type = GET_U_1(rxh->type);
1309 bp += sizeof(struct rx_header);
1310
1311 /*
1312 * If it was a data packet, interpret the response.
1313 */
1314
1315 if (type == RX_PACKET_TYPE_DATA)
1316 switch (opcode) {
1317 case 213: /* InitCallBackState3 */
1318 AFSUUIDOUT();
1319 break;
1320 default:
1321 ;
1322 }
1323 else {
1324 /*
1325 * Otherwise, just print out the return code
1326 */
1327 ND_PRINT(" errcode");
1328 INTOUT();
1329 }
1330
1331 return;
1332
1333 trunc:
1334 ND_PRINT(" [|cb]");
1335 }
1336
1337 /*
1338 * Handle calls to the AFS protection database server
1339 */
1340
1341 static void
1342 prot_print(netdissect_options *ndo,
1343 const u_char *bp, u_int length)
1344 {
1345 uint32_t i;
1346 uint32_t pt_op;
1347
1348 if (length <= sizeof(struct rx_header))
1349 return;
1350
1351 /*
1352 * Print out the afs call we're invoking. The table used here was
1353 * gleaned from ptserver/ptint.xg
1354 */
1355
1356 pt_op = GET_BE_U_4(bp + sizeof(struct rx_header));
1357
1358 ND_PRINT(" pt");
1359
1360 if (is_ubik(pt_op)) {
1361 ubik_print(ndo, bp);
1362 return;
1363 }
1364
1365 ND_PRINT(" call %s", tok2str(pt_req, "op#%u", pt_op));
1366
1367 /*
1368 * Decode some of the arguments to the PT calls
1369 */
1370
1371 bp += sizeof(struct rx_header) + 4;
1372
1373 switch (pt_op) {
1374 case 500: /* I New User */
1375 STROUT(PRNAMEMAX);
1376 ND_PRINT(" id");
1377 INTOUT();
1378 ND_PRINT(" oldid");
1379 INTOUT();
1380 break;
1381 case 501: /* Where is it */
1382 case 506: /* Delete */
1383 case 508: /* Get CPS */
1384 case 512: /* List entry */
1385 case 514: /* List elements */
1386 case 517: /* List owned */
1387 case 518: /* Get CPS2 */
1388 case 519: /* Get host CPS */
1389 case 530: /* List super groups */
1390 ND_PRINT(" id");
1391 INTOUT();
1392 break;
1393 case 502: /* Dump entry */
1394 ND_PRINT(" pos");
1395 INTOUT();
1396 break;
1397 case 503: /* Add to group */
1398 case 507: /* Remove from group */
1399 case 515: /* Is a member of? */
1400 ND_PRINT(" uid");
1401 INTOUT();
1402 ND_PRINT(" gid");
1403 INTOUT();
1404 break;
1405 case 504: /* Name to ID */
1406 {
1407 uint32_t j;
1408 j = GET_BE_U_4(bp);
1409 bp += sizeof(uint32_t);
1410
1411 /*
1412 * Who designed this chicken-shit protocol?
1413 *
1414 * Each character is stored as a 32-bit
1415 * integer!
1416 */
1417
1418 for (i = 0; i < j; i++) {
1419 VECOUT(PRNAMEMAX);
1420 }
1421 if (j == 0)
1422 ND_PRINT(" <none!>");
1423 }
1424 break;
1425 case 505: /* Id to name */
1426 {
1427 uint32_t j;
1428 ND_PRINT(" ids:");
1429 i = GET_BE_U_4(bp);
1430 bp += sizeof(uint32_t);
1431 for (j = 0; j < i; j++)
1432 INTOUT();
1433 if (j == 0)
1434 ND_PRINT(" <none!>");
1435 }
1436 break;
1437 case 509: /* New entry */
1438 STROUT(PRNAMEMAX);
1439 ND_PRINT(" flag");
1440 INTOUT();
1441 ND_PRINT(" oid");
1442 INTOUT();
1443 break;
1444 case 511: /* Set max */
1445 ND_PRINT(" id");
1446 INTOUT();
1447 ND_PRINT(" gflag");
1448 INTOUT();
1449 break;
1450 case 513: /* Change entry */
1451 ND_PRINT(" id");
1452 INTOUT();
1453 STROUT(PRNAMEMAX);
1454 ND_PRINT(" oldid");
1455 INTOUT();
1456 ND_PRINT(" newid");
1457 INTOUT();
1458 break;
1459 case 520: /* Update entry */
1460 ND_PRINT(" id");
1461 INTOUT();
1462 STROUT(PRNAMEMAX);
1463 break;
1464 default:
1465 ;
1466 }
1467
1468
1469 return;
1470
1471 trunc:
1472 ND_PRINT(" [|pt]");
1473 }
1474
1475 /*
1476 * Handle replies to the AFS protection service
1477 */
1478
1479 static void
1480 prot_reply_print(netdissect_options *ndo,
1481 const u_char *bp, u_int length, uint32_t opcode)
1482 {
1483 const struct rx_header *rxh;
1484 uint8_t type;
1485 uint32_t i;
1486
1487 if (length < sizeof(struct rx_header))
1488 return;
1489
1490 rxh = (const struct rx_header *) bp;
1491
1492 /*
1493 * Print out the afs call we're invoking. The table used here was
1494 * gleaned from ptserver/ptint.xg. Check to see if it's a
1495 * Ubik call, however.
1496 */
1497
1498 ND_PRINT(" pt");
1499
1500 if (is_ubik(opcode)) {
1501 ubik_reply_print(ndo, bp, length, opcode);
1502 return;
1503 }
1504
1505 ND_PRINT(" reply %s", tok2str(pt_req, "op#%u", opcode));
1506
1507 type = GET_U_1(rxh->type);
1508 bp += sizeof(struct rx_header);
1509
1510 /*
1511 * If it was a data packet, interpret the response
1512 */
1513
1514 if (type == RX_PACKET_TYPE_DATA)
1515 switch (opcode) {
1516 case 504: /* Name to ID */
1517 {
1518 uint32_t j;
1519 ND_PRINT(" ids:");
1520 i = GET_BE_U_4(bp);
1521 bp += sizeof(uint32_t);
1522 for (j = 0; j < i; j++)
1523 INTOUT();
1524 if (j == 0)
1525 ND_PRINT(" <none!>");
1526 }
1527 break;
1528 case 505: /* ID to name */
1529 {
1530 uint32_t j;
1531 j = GET_BE_U_4(bp);
1532 bp += sizeof(uint32_t);
1533
1534 /*
1535 * Who designed this chicken-shit protocol?
1536 *
1537 * Each character is stored as a 32-bit
1538 * integer!
1539 */
1540
1541 for (i = 0; i < j; i++) {
1542 VECOUT(PRNAMEMAX);
1543 }
1544 if (j == 0)
1545 ND_PRINT(" <none!>");
1546 }
1547 break;
1548 case 508: /* Get CPS */
1549 case 514: /* List elements */
1550 case 517: /* List owned */
1551 case 518: /* Get CPS2 */
1552 case 519: /* Get host CPS */
1553 {
1554 uint32_t j;
1555 j = GET_BE_U_4(bp);
1556 bp += sizeof(uint32_t);
1557 for (i = 0; i < j; i++) {
1558 INTOUT();
1559 }
1560 if (j == 0)
1561 ND_PRINT(" <none!>");
1562 }
1563 break;
1564 case 510: /* List max */
1565 ND_PRINT(" maxuid");
1566 INTOUT();
1567 ND_PRINT(" maxgid");
1568 INTOUT();
1569 break;
1570 default:
1571 ;
1572 }
1573 else {
1574 /*
1575 * Otherwise, just print out the return code
1576 */
1577 ND_PRINT(" errcode");
1578 INTOUT();
1579 }
1580
1581 return;
1582
1583 trunc:
1584 ND_PRINT(" [|pt]");
1585 }
1586
1587 /*
1588 * Handle calls to the AFS volume location database service
1589 */
1590
1591 static void
1592 vldb_print(netdissect_options *ndo,
1593 const u_char *bp, u_int length)
1594 {
1595 uint32_t vldb_op;
1596 uint32_t i;
1597
1598 if (length <= sizeof(struct rx_header))
1599 return;
1600
1601 /*
1602 * Print out the afs call we're invoking. The table used here was
1603 * gleaned from vlserver/vldbint.xg
1604 */
1605
1606 vldb_op = GET_BE_U_4(bp + sizeof(struct rx_header));
1607
1608 ND_PRINT(" vldb");
1609
1610 if (is_ubik(vldb_op)) {
1611 ubik_print(ndo, bp);
1612 return;
1613 }
1614 ND_PRINT(" call %s", tok2str(vldb_req, "op#%u", vldb_op));
1615
1616 /*
1617 * Decode some of the arguments to the VLDB calls
1618 */
1619
1620 bp += sizeof(struct rx_header) + 4;
1621
1622 switch (vldb_op) {
1623 case 501: /* Create new volume */
1624 case 517: /* Create entry N */
1625 VECOUT(VLNAMEMAX);
1626 break;
1627 case 502: /* Delete entry */
1628 case 503: /* Get entry by ID */
1629 case 507: /* Update entry */
1630 case 508: /* Set lock */
1631 case 509: /* Release lock */
1632 case 518: /* Get entry by ID N */
1633 ND_PRINT(" volid");
1634 INTOUT();
1635 i = GET_BE_U_4(bp);
1636 bp += sizeof(uint32_t);
1637 if (i <= 2)
1638 ND_PRINT(" type %s", voltype[i]);
1639 break;
1640 case 504: /* Get entry by name */
1641 case 519: /* Get entry by name N */
1642 case 524: /* Update entry by name */
1643 case 527: /* Get entry by name U */
1644 STROUT(VLNAMEMAX);
1645 break;
1646 case 505: /* Get new vol id */
1647 ND_PRINT(" bump");
1648 INTOUT();
1649 break;
1650 case 506: /* Replace entry */
1651 case 520: /* Replace entry N */
1652 ND_PRINT(" volid");
1653 INTOUT();
1654 i = GET_BE_U_4(bp);
1655 bp += sizeof(uint32_t);
1656 if (i <= 2)
1657 ND_PRINT(" type %s", voltype[i]);
1658 VECOUT(VLNAMEMAX);
1659 break;
1660 case 510: /* List entry */
1661 case 521: /* List entry N */
1662 ND_PRINT(" index");
1663 INTOUT();
1664 break;
1665 default:
1666 ;
1667 }
1668
1669 return;
1670
1671 trunc:
1672 ND_PRINT(" [|vldb]");
1673 }
1674
1675 /*
1676 * Handle replies to the AFS volume location database service
1677 */
1678
1679 static void
1680 vldb_reply_print(netdissect_options *ndo,
1681 const u_char *bp, u_int length, uint32_t opcode)
1682 {
1683 const struct rx_header *rxh;
1684 uint8_t type;
1685 uint32_t i;
1686
1687 if (length < sizeof(struct rx_header))
1688 return;
1689
1690 rxh = (const struct rx_header *) bp;
1691
1692 /*
1693 * Print out the afs call we're invoking. The table used here was
1694 * gleaned from vlserver/vldbint.xg. Check to see if it's a
1695 * Ubik call, however.
1696 */
1697
1698 ND_PRINT(" vldb");
1699
1700 if (is_ubik(opcode)) {
1701 ubik_reply_print(ndo, bp, length, opcode);
1702 return;
1703 }
1704
1705 ND_PRINT(" reply %s", tok2str(vldb_req, "op#%u", opcode));
1706
1707 type = GET_U_1(rxh->type);
1708 bp += sizeof(struct rx_header);
1709
1710 /*
1711 * If it was a data packet, interpret the response
1712 */
1713
1714 if (type == RX_PACKET_TYPE_DATA)
1715 switch (opcode) {
1716 case 510: /* List entry */
1717 ND_PRINT(" count");
1718 INTOUT();
1719 ND_PRINT(" nextindex");
1720 INTOUT();
1721 ND_FALL_THROUGH;
1722 case 503: /* Get entry by id */
1723 case 504: /* Get entry by name */
1724 { uint32_t nservers, j;
1725 VECOUT(VLNAMEMAX);
1726 ND_TCHECK_4(bp);
1727 bp += sizeof(uint32_t);
1728 ND_PRINT(" numservers");
1729 nservers = GET_BE_U_4(bp);
1730 bp += sizeof(uint32_t);
1731 ND_PRINT(" %u", nservers);
1732 ND_PRINT(" servers");
1733 for (i = 0; i < 8; i++) {
1734 ND_TCHECK_4(bp);
1735 if (i < nservers)
1736 ND_PRINT(" %s",
1737 intoa(GET_IPV4_TO_NETWORK_ORDER(bp)));
1738 bp += sizeof(nd_ipv4);
1739 }
1740 ND_PRINT(" partitions");
1741 for (i = 0; i < 8; i++) {
1742 j = GET_BE_U_4(bp);
1743 if (i < nservers && j <= 26)
1744 ND_PRINT(" %c", 'a' + j);
1745 else if (i < nservers)
1746 ND_PRINT(" %u", j);
1747 bp += sizeof(uint32_t);
1748 }
1749 ND_TCHECK_LEN(bp, 8 * sizeof(uint32_t));
1750 bp += 8 * sizeof(uint32_t);
1751 ND_PRINT(" rwvol");
1752 UINTOUT();
1753 ND_PRINT(" rovol");
1754 UINTOUT();
1755 ND_PRINT(" backup");
1756 UINTOUT();
1757 }
1758 break;
1759 case 505: /* Get new volume ID */
1760 ND_PRINT(" newvol");
1761 UINTOUT();
1762 break;
1763 case 521: /* List entry */
1764 case 529: /* List entry U */
1765 ND_PRINT(" count");
1766 INTOUT();
1767 ND_PRINT(" nextindex");
1768 INTOUT();
1769 ND_FALL_THROUGH;
1770 case 518: /* Get entry by ID N */
1771 case 519: /* Get entry by name N */
1772 { uint32_t nservers, j;
1773 VECOUT(VLNAMEMAX);
1774 ND_PRINT(" numservers");
1775 nservers = GET_BE_U_4(bp);
1776 bp += sizeof(uint32_t);
1777 ND_PRINT(" %u", nservers);
1778 ND_PRINT(" servers");
1779 for (i = 0; i < 13; i++) {
1780 ND_TCHECK_4(bp);
1781 if (i < nservers)
1782 ND_PRINT(" %s",
1783 intoa(GET_IPV4_TO_NETWORK_ORDER(bp)));
1784 bp += sizeof(nd_ipv4);
1785 }
1786 ND_PRINT(" partitions");
1787 for (i = 0; i < 13; i++) {
1788 j = GET_BE_U_4(bp);
1789 if (i < nservers && j <= 26)
1790 ND_PRINT(" %c", 'a' + j);
1791 else if (i < nservers)
1792 ND_PRINT(" %u", j);
1793 bp += sizeof(uint32_t);
1794 }
1795 ND_TCHECK_LEN(bp, 13 * sizeof(uint32_t));
1796 bp += 13 * sizeof(uint32_t);
1797 ND_PRINT(" rwvol");
1798 UINTOUT();
1799 ND_PRINT(" rovol");
1800 UINTOUT();
1801 ND_PRINT(" backup");
1802 UINTOUT();
1803 }
1804 break;
1805 case 526: /* Get entry by ID U */
1806 case 527: /* Get entry by name U */
1807 { uint32_t nservers, j;
1808 VECOUT(VLNAMEMAX);
1809 ND_PRINT(" numservers");
1810 nservers = GET_BE_U_4(bp);
1811 bp += sizeof(uint32_t);
1812 ND_PRINT(" %u", nservers);
1813 ND_PRINT(" servers");
1814 for (i = 0; i < 13; i++) {
1815 if (i < nservers) {
1816 ND_PRINT(" afsuuid");
1817 AFSUUIDOUT();
1818 } else {
1819 ND_TCHECK_LEN(bp, 44);
1820 bp += 44;
1821 }
1822 }
1823 ND_TCHECK_LEN(bp, 4 * 13);
1824 bp += 4 * 13;
1825 ND_PRINT(" partitions");
1826 for (i = 0; i < 13; i++) {
1827 j = GET_BE_U_4(bp);
1828 if (i < nservers && j <= 26)
1829 ND_PRINT(" %c", 'a' + j);
1830 else if (i < nservers)
1831 ND_PRINT(" %u", j);
1832 bp += sizeof(uint32_t);
1833 }
1834 ND_TCHECK_LEN(bp, 13 * sizeof(uint32_t));
1835 bp += 13 * sizeof(uint32_t);
1836 ND_PRINT(" rwvol");
1837 UINTOUT();
1838 ND_PRINT(" rovol");
1839 UINTOUT();
1840 ND_PRINT(" backup");
1841 UINTOUT();
1842 }
1843 default:
1844 ;
1845 }
1846
1847 else {
1848 /*
1849 * Otherwise, just print out the return code
1850 */
1851 ND_PRINT(" errcode");
1852 INTOUT();
1853 }
1854
1855 return;
1856
1857 trunc:
1858 ND_PRINT(" [|vldb]");
1859 }
1860
1861 /*
1862 * Handle calls to the AFS Kerberos Authentication service
1863 */
1864
1865 static void
1866 kauth_print(netdissect_options *ndo,
1867 const u_char *bp, u_int length)
1868 {
1869 uint32_t kauth_op;
1870
1871 if (length <= sizeof(struct rx_header))
1872 return;
1873
1874 /*
1875 * Print out the afs call we're invoking. The table used here was
1876 * gleaned from kauth/kauth.rg
1877 */
1878
1879 kauth_op = GET_BE_U_4(bp + sizeof(struct rx_header));
1880
1881 ND_PRINT(" kauth");
1882
1883 if (is_ubik(kauth_op)) {
1884 ubik_print(ndo, bp);
1885 return;
1886 }
1887
1888
1889 ND_PRINT(" call %s", tok2str(kauth_req, "op#%u", kauth_op));
1890
1891 /*
1892 * Decode some of the arguments to the KA calls
1893 */
1894
1895 bp += sizeof(struct rx_header) + 4;
1896
1897 switch (kauth_op) {
1898 case 1: /* Authenticate old */
1899 case 21: /* Authenticate */
1900 case 22: /* Authenticate-V2 */
1901 case 2: /* Change PW */
1902 case 5: /* Set fields */
1903 case 6: /* Create user */
1904 case 7: /* Delete user */
1905 case 8: /* Get entry */
1906 case 14: /* Unlock */
1907 case 15: /* Lock status */
1908 ND_PRINT(" principal");
1909 STROUT(KANAMEMAX);
1910 STROUT(KANAMEMAX);
1911 break;
1912 case 3: /* GetTicket-old */
1913 case 23: /* GetTicket */
1914 {
1915 uint32_t i;
1916 ND_PRINT(" kvno");
1917 INTOUT();
1918 ND_PRINT(" domain");
1919 STROUT(KANAMEMAX);
1920 i = GET_BE_U_4(bp);
1921 bp += sizeof(uint32_t);
1922 ND_TCHECK_LEN(bp, i);
1923 bp += i;
1924 ND_PRINT(" principal");
1925 STROUT(KANAMEMAX);
1926 STROUT(KANAMEMAX);
1927 break;
1928 }
1929 case 4: /* Set Password */
1930 ND_PRINT(" principal");
1931 STROUT(KANAMEMAX);
1932 STROUT(KANAMEMAX);
1933 ND_PRINT(" kvno");
1934 INTOUT();
1935 break;
1936 case 12: /* Get password */
1937 ND_PRINT(" name");
1938 STROUT(KANAMEMAX);
1939 break;
1940 default:
1941 ;
1942 }
1943
1944 return;
1945
1946 trunc:
1947 ND_PRINT(" [|kauth]");
1948 }
1949
1950 /*
1951 * Handle replies to the AFS Kerberos Authentication Service
1952 */
1953
1954 static void
1955 kauth_reply_print(netdissect_options *ndo,
1956 const u_char *bp, u_int length, uint32_t opcode)
1957 {
1958 const struct rx_header *rxh;
1959 uint8_t type;
1960
1961 if (length <= sizeof(struct rx_header))
1962 return;
1963
1964 rxh = (const struct rx_header *) bp;
1965
1966 /*
1967 * Print out the afs call we're invoking. The table used here was
1968 * gleaned from kauth/kauth.rg
1969 */
1970
1971 ND_PRINT(" kauth");
1972
1973 if (is_ubik(opcode)) {
1974 ubik_reply_print(ndo, bp, length, opcode);
1975 return;
1976 }
1977
1978 ND_PRINT(" reply %s", tok2str(kauth_req, "op#%u", opcode));
1979
1980 type = GET_U_1(rxh->type);
1981 bp += sizeof(struct rx_header);
1982
1983 /*
1984 * If it was a data packet, interpret the response.
1985 */
1986
1987 if (type == RX_PACKET_TYPE_DATA)
1988 /* Well, no, not really. Leave this for later */
1989 ;
1990 else {
1991 /*
1992 * Otherwise, just print out the return code
1993 */
1994 ND_PRINT(" errcode");
1995 INTOUT();
1996 }
1997 }
1998
1999 /*
2000 * Handle calls to the AFS Volume location service
2001 */
2002
2003 static void
2004 vol_print(netdissect_options *ndo,
2005 const u_char *bp, u_int length)
2006 {
2007 uint32_t vol_op;
2008
2009 if (length <= sizeof(struct rx_header))
2010 return;
2011
2012 /*
2013 * Print out the afs call we're invoking. The table used here was
2014 * gleaned from volser/volint.xg
2015 */
2016
2017 vol_op = GET_BE_U_4(bp + sizeof(struct rx_header));
2018
2019 ND_PRINT(" vol call %s", tok2str(vol_req, "op#%u", vol_op));
2020
2021 bp += sizeof(struct rx_header) + 4;
2022
2023 switch (vol_op) {
2024 case 100: /* Create volume */
2025 ND_PRINT(" partition");
2026 UINTOUT();
2027 ND_PRINT(" name");
2028 STROUT(AFSNAMEMAX);
2029 ND_PRINT(" type");
2030 UINTOUT();
2031 ND_PRINT(" parent");
2032 UINTOUT();
2033 break;
2034 case 101: /* Delete volume */
2035 case 107: /* Get flags */
2036 ND_PRINT(" trans");
2037 UINTOUT();
2038 break;
2039 case 102: /* Restore */
2040 ND_PRINT(" totrans");
2041 UINTOUT();
2042 ND_PRINT(" flags");
2043 UINTOUT();
2044 break;
2045 case 103: /* Forward */
2046 ND_PRINT(" fromtrans");
2047 UINTOUT();
2048 ND_PRINT(" fromdate");
2049 DATEOUT();
2050 DESTSERVEROUT();
2051 ND_PRINT(" desttrans");
2052 INTOUT();
2053 break;
2054 case 104: /* End trans */
2055 ND_PRINT(" trans");
2056 UINTOUT();
2057 break;
2058 case 105: /* Clone */
2059 ND_PRINT(" trans");
2060 UINTOUT();
2061 ND_PRINT(" purgevol");
2062 UINTOUT();
2063 ND_PRINT(" newtype");
2064 UINTOUT();
2065 ND_PRINT(" newname");
2066 STROUT(AFSNAMEMAX);
2067 break;
2068 case 106: /* Set flags */
2069 ND_PRINT(" trans");
2070 UINTOUT();
2071 ND_PRINT(" flags");
2072 UINTOUT();
2073 break;
2074 case 108: /* Trans create */
2075 ND_PRINT(" vol");
2076 UINTOUT();
2077 ND_PRINT(" partition");
2078 UINTOUT();
2079 ND_PRINT(" flags");
2080 UINTOUT();
2081 break;
2082 case 109: /* Dump */
2083 case 655537: /* Get size */
2084 ND_PRINT(" fromtrans");
2085 UINTOUT();
2086 ND_PRINT(" fromdate");
2087 DATEOUT();
2088 break;
2089 case 110: /* Get n-th volume */
2090 ND_PRINT(" index");
2091 UINTOUT();
2092 break;
2093 case 111: /* Set forwarding */
2094 ND_PRINT(" tid");
2095 UINTOUT();
2096 ND_PRINT(" newsite");
2097 UINTOUT();
2098 break;
2099 case 112: /* Get name */
2100 case 113: /* Get status */
2101 ND_PRINT(" tid");
2102 break;
2103 case 114: /* Signal restore */
2104 ND_PRINT(" name");
2105 STROUT(AFSNAMEMAX);
2106 ND_PRINT(" type");
2107 UINTOUT();
2108 ND_PRINT(" pid");
2109 UINTOUT();
2110 ND_PRINT(" cloneid");
2111 UINTOUT();
2112 break;
2113 case 116: /* List volumes */
2114 ND_PRINT(" partition");
2115 UINTOUT();
2116 ND_PRINT(" flags");
2117 UINTOUT();
2118 break;
2119 case 117: /* Set id types */
2120 ND_PRINT(" tid");
2121 UINTOUT();
2122 ND_PRINT(" name");
2123 STROUT(AFSNAMEMAX);
2124 ND_PRINT(" type");
2125 UINTOUT();
2126 ND_PRINT(" pid");
2127 UINTOUT();
2128 ND_PRINT(" clone");
2129 UINTOUT();
2130 ND_PRINT(" backup");
2131 UINTOUT();
2132 break;
2133 case 119: /* Partition info */
2134 ND_PRINT(" name");
2135 STROUT(AFSNAMEMAX);
2136 break;
2137 case 120: /* Reclone */
2138 ND_PRINT(" tid");
2139 UINTOUT();
2140 break;
2141 case 121: /* List one volume */
2142 case 122: /* Nuke volume */
2143 case 124: /* Extended List volumes */
2144 case 125: /* Extended List one volume */
2145 case 65536: /* Convert RO to RW volume */
2146 ND_PRINT(" partid");
2147 UINTOUT();
2148 ND_PRINT(" volid");
2149 UINTOUT();
2150 break;
2151 case 123: /* Set date */
2152 ND_PRINT(" tid");
2153 UINTOUT();
2154 ND_PRINT(" date");
2155 DATEOUT();
2156 break;
2157 case 126: /* Set info */
2158 ND_PRINT(" tid");
2159 UINTOUT();
2160 break;
2161 case 128: /* Forward multiple */
2162 ND_PRINT(" fromtrans");
2163 UINTOUT();
2164 ND_PRINT(" fromdate");
2165 DATEOUT();
2166 {
2167 uint32_t i, j;
2168 j = GET_BE_U_4(bp);
2169 bp += sizeof(uint32_t);
2170 for (i = 0; i < j; i++) {
2171 DESTSERVEROUT();
2172 if (i != j - 1)
2173 ND_PRINT(",");
2174 }
2175 if (j == 0)
2176 ND_PRINT(" <none!>");
2177 }
2178 break;
2179 case 65538: /* Dump version 2 */
2180 ND_PRINT(" fromtrans");
2181 UINTOUT();
2182 ND_PRINT(" fromdate");
2183 DATEOUT();
2184 ND_PRINT(" flags");
2185 UINTOUT();
2186 break;
2187 default:
2188 ;
2189 }
2190 return;
2191
2192 trunc:
2193 ND_PRINT(" [|vol]");
2194 }
2195
2196 /*
2197 * Handle replies to the AFS Volume Service
2198 */
2199
2200 static void
2201 vol_reply_print(netdissect_options *ndo,
2202 const u_char *bp, u_int length, uint32_t opcode)
2203 {
2204 const struct rx_header *rxh;
2205 uint8_t type;
2206
2207 if (length <= sizeof(struct rx_header))
2208 return;
2209
2210 rxh = (const struct rx_header *) bp;
2211
2212 /*
2213 * Print out the afs call we're invoking. The table used here was
2214 * gleaned from volser/volint.xg
2215 */
2216
2217 ND_PRINT(" vol reply %s", tok2str(vol_req, "op#%u", opcode));
2218
2219 type = GET_U_1(rxh->type);
2220 bp += sizeof(struct rx_header);
2221
2222 /*
2223 * If it was a data packet, interpret the response.
2224 */
2225
2226 if (type == RX_PACKET_TYPE_DATA) {
2227 switch (opcode) {
2228 case 100: /* Create volume */
2229 ND_PRINT(" volid");
2230 UINTOUT();
2231 ND_PRINT(" trans");
2232 UINTOUT();
2233 break;
2234 case 104: /* End transaction */
2235 UINTOUT();
2236 break;
2237 case 105: /* Clone */
2238 ND_PRINT(" newvol");
2239 UINTOUT();
2240 break;
2241 case 107: /* Get flags */
2242 UINTOUT();
2243 break;
2244 case 108: /* Transaction create */
2245 ND_PRINT(" trans");
2246 UINTOUT();
2247 break;
2248 case 110: /* Get n-th volume */
2249 ND_PRINT(" volume");
2250 UINTOUT();
2251 ND_PRINT(" partition");
2252 UINTOUT();
2253 break;
2254 case 112: /* Get name */
2255 STROUT(AFSNAMEMAX);
2256 break;
2257 case 113: /* Get status */
2258 ND_PRINT(" volid");
2259 UINTOUT();
2260 ND_PRINT(" nextuniq");
2261 UINTOUT();
2262 ND_PRINT(" type");
2263 UINTOUT();
2264 ND_PRINT(" parentid");
2265 UINTOUT();
2266 ND_PRINT(" clone");
2267 UINTOUT();
2268 ND_PRINT(" backup");
2269 UINTOUT();
2270 ND_PRINT(" restore");
2271 UINTOUT();
2272 ND_PRINT(" maxquota");
2273 UINTOUT();
2274 ND_PRINT(" minquota");
2275 UINTOUT();
2276 ND_PRINT(" owner");
2277 UINTOUT();
2278 ND_PRINT(" create");
2279 DATEOUT();
2280 ND_PRINT(" access");
2281 DATEOUT();
2282 ND_PRINT(" update");
2283 DATEOUT();
2284 ND_PRINT(" expire");
2285 DATEOUT();
2286 ND_PRINT(" backup");
2287 DATEOUT();
2288 ND_PRINT(" copy");
2289 DATEOUT();
2290 break;
2291 case 115: /* Old list partitions */
2292 break;
2293 case 116: /* List volumes */
2294 case 121: /* List one volume */
2295 {
2296 uint32_t i, j;
2297 j = GET_BE_U_4(bp);
2298 bp += sizeof(uint32_t);
2299 for (i = 0; i < j; i++) {
2300 ND_PRINT(" name");
2301 VECOUT(32);
2302 ND_PRINT(" volid");
2303 UINTOUT();
2304 ND_PRINT(" type");
2305 bp += sizeof(uint32_t) * 21;
2306 if (i != j - 1)
2307 ND_PRINT(",");
2308 }
2309 if (j == 0)
2310 ND_PRINT(" <none!>");
2311 }
2312 break;
2313
2314
2315 default:
2316 ;
2317 }
2318 } else {
2319 /*
2320 * Otherwise, just print out the return code
2321 */
2322 ND_PRINT(" errcode");
2323 INTOUT();
2324 }
2325
2326 return;
2327
2328 trunc:
2329 ND_PRINT(" [|vol]");
2330 }
2331
2332 /*
2333 * Handle calls to the AFS BOS service
2334 */
2335
2336 static void
2337 bos_print(netdissect_options *ndo,
2338 const u_char *bp, u_int length)
2339 {
2340 uint32_t bos_op;
2341
2342 if (length <= sizeof(struct rx_header))
2343 return;
2344
2345 /*
2346 * Print out the afs call we're invoking. The table used here was
2347 * gleaned from bozo/bosint.xg
2348 */
2349
2350 bos_op = GET_BE_U_4(bp + sizeof(struct rx_header));
2351
2352 ND_PRINT(" bos call %s", tok2str(bos_req, "op#%u", bos_op));
2353
2354 /*
2355 * Decode some of the arguments to the BOS calls
2356 */
2357
2358 bp += sizeof(struct rx_header) + 4;
2359
2360 switch (bos_op) {
2361 case 80: /* Create B node */
2362 ND_PRINT(" type");
2363 STROUT(BOSNAMEMAX);
2364 ND_PRINT(" instance");
2365 STROUT(BOSNAMEMAX);
2366 break;
2367 case 81: /* Delete B node */
2368 case 83: /* Get status */
2369 case 85: /* Get instance info */
2370 case 87: /* Add super user */
2371 case 88: /* Delete super user */
2372 case 93: /* Set cell name */
2373 case 96: /* Add cell host */
2374 case 97: /* Delete cell host */
2375 case 104: /* Restart */
2376 case 106: /* Uninstall */
2377 case 108: /* Exec */
2378 case 112: /* Getlog */
2379 case 114: /* Get instance strings */
2380 STROUT(BOSNAMEMAX);
2381 break;
2382 case 82: /* Set status */
2383 case 98: /* Set T status */
2384 STROUT(BOSNAMEMAX);
2385 ND_PRINT(" status");
2386 INTOUT();
2387 break;
2388 case 86: /* Get instance parm */
2389 STROUT(BOSNAMEMAX);
2390 ND_PRINT(" num");
2391 INTOUT();
2392 break;
2393 case 84: /* Enumerate instance */
2394 case 89: /* List super users */
2395 case 90: /* List keys */
2396 case 91: /* Add key */
2397 case 92: /* Delete key */
2398 case 95: /* Get cell host */
2399 INTOUT();
2400 break;
2401 case 105: /* Install */
2402 STROUT(BOSNAMEMAX);
2403 ND_PRINT(" size");
2404 INTOUT();
2405 ND_PRINT(" flags");
2406 INTOUT();
2407 ND_PRINT(" date");
2408 INTOUT();
2409 break;
2410 default:
2411 ;
2412 }
2413
2414 return;
2415
2416 trunc:
2417 ND_PRINT(" [|bos]");
2418 }
2419
2420 /*
2421 * Handle replies to the AFS BOS Service
2422 */
2423
2424 static void
2425 bos_reply_print(netdissect_options *ndo,
2426 const u_char *bp, u_int length, uint32_t opcode)
2427 {
2428 const struct rx_header *rxh;
2429 uint8_t type;
2430
2431 if (length <= sizeof(struct rx_header))
2432 return;
2433
2434 rxh = (const struct rx_header *) bp;
2435
2436 /*
2437 * Print out the afs call we're invoking. The table used here was
2438 * gleaned from volser/volint.xg
2439 */
2440
2441 ND_PRINT(" bos reply %s", tok2str(bos_req, "op#%u", opcode));
2442
2443 type = GET_U_1(rxh->type);
2444 bp += sizeof(struct rx_header);
2445
2446 /*
2447 * If it was a data packet, interpret the response.
2448 */
2449
2450 if (type == RX_PACKET_TYPE_DATA)
2451 /* Well, no, not really. Leave this for later */
2452 ;
2453 else {
2454 /*
2455 * Otherwise, just print out the return code
2456 */
2457 ND_PRINT(" errcode");
2458 INTOUT();
2459 }
2460 }
2461
2462 /*
2463 * Check to see if this is a Ubik opcode.
2464 */
2465
2466 static int
2467 is_ubik(uint32_t opcode)
2468 {
2469 if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) ||
2470 (opcode >= DISK_LOW && opcode <= DISK_HIGH))
2471 return(1);
2472 else
2473 return(0);
2474 }
2475
2476 /*
2477 * Handle Ubik opcodes to any one of the replicated database services
2478 */
2479
2480 static void
2481 ubik_print(netdissect_options *ndo,
2482 const u_char *bp)
2483 {
2484 uint32_t ubik_op;
2485 uint32_t temp;
2486
2487 /*
2488 * Print out the afs call we're invoking. The table used here was
2489 * gleaned from ubik/ubik_int.xg
2490 */
2491
2492 /* Every function that calls this function first makes a bounds check
2493 * for (sizeof(rx_header) + 4) bytes, so long as it remains this way
2494 * the line below will not over-read.
2495 */
2496 ubik_op = GET_BE_U_4(bp + sizeof(struct rx_header));
2497
2498 ND_PRINT(" ubik call %s", tok2str(ubik_req, "op#%u", ubik_op));
2499
2500 /*
2501 * Decode some of the arguments to the Ubik calls
2502 */
2503
2504 bp += sizeof(struct rx_header) + 4;
2505
2506 switch (ubik_op) {
2507 case 10000: /* Beacon */
2508 temp = GET_BE_U_4(bp);
2509 bp += sizeof(uint32_t);
2510 ND_PRINT(" syncsite %s", temp ? "yes" : "no");
2511 ND_PRINT(" votestart");
2512 DATEOUT();
2513 ND_PRINT(" dbversion");
2514 UBIK_VERSIONOUT();
2515 ND_PRINT(" tid");
2516 UBIK_VERSIONOUT();
2517 break;
2518 case 10003: /* Get sync site */
2519 ND_PRINT(" site");
2520 UINTOUT();
2521 break;
2522 case 20000: /* Begin */
2523 case 20001: /* Commit */
2524 case 20007: /* Abort */
2525 case 20008: /* Release locks */
2526 case 20010: /* Writev */
2527 ND_PRINT(" tid");
2528 UBIK_VERSIONOUT();
2529 break;
2530 case 20002: /* Lock */
2531 ND_PRINT(" tid");
2532 UBIK_VERSIONOUT();
2533 ND_PRINT(" file");
2534 INTOUT();
2535 ND_PRINT(" pos");
2536 INTOUT();
2537 ND_PRINT(" length");
2538 INTOUT();
2539 temp = GET_BE_U_4(bp);
2540 bp += sizeof(uint32_t);
2541 tok2str(ubik_lock_types, "type %u", temp);
2542 break;
2543 case 20003: /* Write */
2544 ND_PRINT(" tid");
2545 UBIK_VERSIONOUT();
2546 ND_PRINT(" file");
2547 INTOUT();
2548 ND_PRINT(" pos");
2549 INTOUT();
2550 break;
2551 case 20005: /* Get file */
2552 ND_PRINT(" file");
2553 INTOUT();
2554 break;
2555 case 20006: /* Send file */
2556 ND_PRINT(" file");
2557 INTOUT();
2558 ND_PRINT(" length");
2559 INTOUT();
2560 ND_PRINT(" dbversion");
2561 UBIK_VERSIONOUT();
2562 break;
2563 case 20009: /* Truncate */
2564 ND_PRINT(" tid");
2565 UBIK_VERSIONOUT();
2566 ND_PRINT(" file");
2567 INTOUT();
2568 ND_PRINT(" length");
2569 INTOUT();
2570 break;
2571 case 20012: /* Set version */
2572 ND_PRINT(" tid");
2573 UBIK_VERSIONOUT();
2574 ND_PRINT(" oldversion");
2575 UBIK_VERSIONOUT();
2576 ND_PRINT(" newversion");
2577 UBIK_VERSIONOUT();
2578 break;
2579 default:
2580 ;
2581 }
2582
2583 return;
2584
2585 trunc:
2586 ND_PRINT(" [|ubik]");
2587 }
2588
2589 /*
2590 * Handle Ubik replies to any one of the replicated database services
2591 */
2592
2593 static void
2594 ubik_reply_print(netdissect_options *ndo,
2595 const u_char *bp, u_int length, uint32_t opcode)
2596 {
2597 const struct rx_header *rxh;
2598 uint8_t type;
2599
2600 if (length < sizeof(struct rx_header))
2601 return;
2602
2603 rxh = (const struct rx_header *) bp;
2604
2605 /*
2606 * Print out the ubik call we're invoking. This table was gleaned
2607 * from ubik/ubik_int.xg
2608 */
2609
2610 ND_PRINT(" ubik reply %s", tok2str(ubik_req, "op#%u", opcode));
2611
2612 type = GET_U_1(rxh->type);
2613 bp += sizeof(struct rx_header);
2614
2615 /*
2616 * If it was a data packet, print out the arguments to the Ubik calls
2617 */
2618
2619 if (type == RX_PACKET_TYPE_DATA)
2620 switch (opcode) {
2621 case 10000: /* Beacon */
2622 ND_PRINT(" vote no");
2623 break;
2624 case 20004: /* Get version */
2625 ND_PRINT(" dbversion");
2626 UBIK_VERSIONOUT();
2627 break;
2628 default:
2629 ;
2630 }
2631
2632 /*
2633 * Otherwise, print out "yes" if it was a beacon packet (because
2634 * that's how yes votes are returned, go figure), otherwise
2635 * just print out the error code.
2636 */
2637
2638 else
2639 switch (opcode) {
2640 case 10000: /* Beacon */
2641 ND_PRINT(" vote yes until");
2642 DATEOUT();
2643 break;
2644 default:
2645 ND_PRINT(" errcode");
2646 INTOUT();
2647 }
2648
2649 return;
2650
2651 trunc:
2652 ND_PRINT(" [|ubik]");
2653 }
2654
2655 /*
2656 * Handle RX ACK packets.
2657 */
2658
2659 static void
2660 rx_ack_print(netdissect_options *ndo,
2661 const u_char *bp, u_int length)
2662 {
2663 const struct rx_ackPacket *rxa;
2664 uint8_t nAcks;
2665 int i, start, last;
2666 uint32_t firstPacket;
2667
2668 if (length < sizeof(struct rx_header))
2669 return;
2670
2671 bp += sizeof(struct rx_header);
2672
2673 ND_TCHECK_LEN(bp, sizeof(struct rx_ackPacket));
2674
2675 rxa = (const struct rx_ackPacket *) bp;
2676 bp += sizeof(struct rx_ackPacket);
2677
2678 /*
2679 * Print out a few useful things from the ack packet structure
2680 */
2681
2682 if (ndo->ndo_vflag > 2)
2683 ND_PRINT(" bufspace %u maxskew %u",
2684 GET_BE_U_2(rxa->bufferSpace),
2685 GET_BE_U_2(rxa->maxSkew));
2686
2687 firstPacket = GET_BE_U_4(rxa->firstPacket);
2688 ND_PRINT(" first %u serial %u reason %s",
2689 firstPacket, GET_BE_U_4(rxa->serial),
2690 tok2str(rx_ack_reasons, "#%u", GET_U_1(rxa->reason)));
2691
2692 /*
2693 * Okay, now we print out the ack array. The way _this_ works
2694 * is that we start at "first", and step through the ack array.
2695 * If we have a contiguous range of acks/nacks, try to
2696 * collapse them into a range.
2697 *
2698 * If you're really clever, you might have noticed that this
2699 * doesn't seem quite correct. Specifically, due to structure
2700 * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually
2701 * yield the start of the ack array (because RX_MAXACKS is 255
2702 * and the structure will likely get padded to a 2 or 4 byte
2703 * boundary). However, this is the way it's implemented inside
2704 * of AFS - the start of the extra fields are at
2705 * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_
2706 * the exact start of the ack array. Sigh. That's why we aren't
2707 * using bp, but instead use rxa->acks[]. But nAcks gets added
2708 * to bp after this, so bp ends up at the right spot. Go figure.
2709 */
2710
2711 nAcks = GET_U_1(rxa->nAcks);
2712 if (nAcks != 0) {
2713
2714 ND_TCHECK_LEN(bp, nAcks);
2715
2716 /*
2717 * Sigh, this is gross, but it seems to work to collapse
2718 * ranges correctly.
2719 */
2720
2721 for (i = 0, start = last = -2; i < nAcks; i++)
2722 if (GET_U_1(bp + i) == RX_ACK_TYPE_ACK) {
2723
2724 /*
2725 * I figured this deserved _some_ explanation.
2726 * First, print "acked" and the packet seq
2727 * number if this is the first time we've
2728 * seen an acked packet.
2729 */
2730
2731 if (last == -2) {
2732 ND_PRINT(" acked %u", firstPacket + i);
2733 start = i;
2734 }
2735
2736 /*
2737 * Otherwise, if there is a skip in
2738 * the range (such as an nacked packet in
2739 * the middle of some acked packets),
2740 * then print the current packet number
2741 * separated from the last number by
2742 * a comma.
2743 */
2744
2745 else if (last != i - 1) {
2746 ND_PRINT(",%u", firstPacket + i);
2747 start = i;
2748 }
2749
2750 /*
2751 * We always set last to the value of
2752 * the last ack we saw. Conversely, start
2753 * is set to the value of the first ack
2754 * we saw in a range.
2755 */
2756
2757 last = i;
2758
2759 /*
2760 * Okay, this bit a code gets executed when
2761 * we hit a nack ... in _this_ case we
2762 * want to print out the range of packets
2763 * that were acked, so we need to print
2764 * the _previous_ packet number separated
2765 * from the first by a dash (-). Since we
2766 * already printed the first packet above,
2767 * just print the final packet. Don't
2768 * do this if there will be a single-length
2769 * range.
2770 */
2771 } else if (last == i - 1 && start != last)
2772 ND_PRINT("-%u", firstPacket + i - 1);
2773
2774 /*
2775 * So, what's going on here? We ran off the end of the
2776 * ack list, and if we got a range we need to finish it up.
2777 * So we need to determine if the last packet in the list
2778 * was an ack (if so, then last will be set to it) and
2779 * we need to see if the last range didn't start with the
2780 * last packet (because if it _did_, then that would mean
2781 * that the packet number has already been printed and
2782 * we don't need to print it again).
2783 */
2784
2785 if (last == i - 1 && start != last)
2786 ND_PRINT("-%u", firstPacket + i - 1);
2787
2788 /*
2789 * Same as above, just without comments
2790 */
2791
2792 for (i = 0, start = last = -2; i < nAcks; i++)
2793 if (GET_U_1(bp + i) == RX_ACK_TYPE_NACK) {
2794 if (last == -2) {
2795 ND_PRINT(" nacked %u", firstPacket + i);
2796 start = i;
2797 } else if (last != i - 1) {
2798 ND_PRINT(",%u", firstPacket + i);
2799 start = i;
2800 }
2801 last = i;
2802 } else if (last == i - 1 && start != last)
2803 ND_PRINT("-%u", firstPacket + i - 1);
2804
2805 if (last == i - 1 && start != last)
2806 ND_PRINT("-%u", firstPacket + i - 1);
2807
2808 bp += nAcks;
2809 }
2810
2811 /* Padding. */
2812 bp += 3;
2813
2814 /*
2815 * These are optional fields; depending on your version of AFS,
2816 * you may or may not see them
2817 */
2818
2819 #define TRUNCRET(n) if (ndo->ndo_snapend - bp + 1 <= n) return;
2820
2821 if (ndo->ndo_vflag > 1) {
2822 TRUNCRET(4);
2823 ND_PRINT(" ifmtu");
2824 UINTOUT();
2825
2826 TRUNCRET(4);
2827 ND_PRINT(" maxmtu");
2828 UINTOUT();
2829
2830 TRUNCRET(4);
2831 ND_PRINT(" rwind");
2832 UINTOUT();
2833
2834 TRUNCRET(4);
2835 ND_PRINT(" maxpackets");
2836 UINTOUT();
2837 }
2838
2839 return;
2840
2841 trunc:
2842 ND_PRINT(" [|ack]");
2843 }
2844 #undef TRUNCRET