2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
21 #include <sys/socket.h>
24 #include <arpa/inet.h>
26 #ifdef HAVE_NETINET_IN_H
27 #include <netinet/in.h>
29 #ifdef HAVE_SYS_TIME_H
46 #include "rx_globals.h"
51 extern struct hostent *hostutil_GetHostByName();
61 while (tc = *aport++) {
62 if (tc < '0' || tc > '9')
63 return -1; /* bad port number */
65 total += tc - (int)'0';
74 register struct servent *ts;
75 ts = getservbyname(aname, NULL);
78 return ts->s_port; /* returns it in network byte order */
82 MainCommand(struct cmd_syndesc *as, void *arock)
87 struct sockaddr_in taddr;
89 struct in_addr hostAddr;
92 register afs_int32 code;
96 int onlyClient, onlyServer;
110 struct rx_debugStats tstats;
111 char *portName, *hostName;
113 struct rx_debugConn tconn;
119 afs_int32 length = 64;
121 afs_uint32 supportedDebugValues = 0;
122 afs_uint32 supportedStatValues = 0;
123 afs_uint32 supportedConnValues = 0;
124 afs_uint32 supportedPeerValues = 0;
125 afs_int32 nextconn = 0;
126 afs_int32 nextpeer = 0;
128 nodally = (as->parms[2].items ? 1 : 0);
129 allconns = (as->parms[3].items ? 1 : 0);
130 rxstats = (as->parms[4].items ? 1 : 0);
131 onlyServer = (as->parms[5].items ? 1 : 0);
132 onlyClient = (as->parms[6].items ? 1 : 0);
133 version_flag = (as->parms[10].items ? 1 : 0);
134 noConns = (as->parms[11].items ? 1 : 0);
135 showPeers = (as->parms[12].items ? 1 : 0);
136 showLong = (as->parms[13].items ? 1 : 0);
138 if (as->parms[0].items)
139 hostName = as->parms[0].items->data;
143 if (as->parms[1].items)
144 portName = as->parms[1].items->data;
148 if (as->parms[7].items) {
149 char *name = as->parms[7].items->data;
150 if ((onlyPort = PortNumber(name)) == -1)
151 onlyPort = PortName(name);
152 if (onlyPort == -1) {
153 printf("rxdebug: can't resolve port name %s\n", name);
159 if (as->parms[8].items) {
160 char *name = as->parms[8].items->data;
162 th = hostutil_GetHostByName(name);
164 printf("rxdebug: host %s not found in host table\n", name);
167 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
171 if (as->parms[9].items) {
172 char *name = as->parms[9].items->data;
173 if (strcmp(name, "clear") == 0)
175 else if (strcmp(name, "auth") == 0)
177 else if (strcmp(name, "crypt") == 0)
179 else if ((strcmp(name, "null") == 0) || (strcmp(name, "none") == 0)
180 || (strncmp(name, "noauth", 6) == 0)
181 || (strncmp(name, "unauth", 6) == 0))
184 fprintf(stderr, "Unknown authentication level: %s\n", name);
192 th = hostutil_GetHostByName(hostName);
194 printf("rxdebug: host %s not found in host table\n", hostName);
197 memcpy(&host, th->h_addr, sizeof(afs_int32));
199 host = htonl(0x7f000001); /* IP localhost */
202 port = htons(7000); /* default is fileserver */
204 if ((port = PortNumber(portName)) == -1)
205 port = PortName(portName);
207 printf("rxdebug: can't resolve port name %s\n", portName);
214 hostAddr.s_addr = host;
215 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
216 printf("Trying %s (port %d):\n", hoststr, ntohs(port));
217 s = socket(AF_INET, SOCK_DGRAM, 0);
218 taddr.sin_family = AF_INET;
220 taddr.sin_addr.s_addr = 0;
221 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
222 taddr.sin_len = sizeof(struct sockaddr_in);
224 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
232 code = rx_GetServerVersion(s, host, port, length, version);
234 printf("get version call failed with code %d, errno %d\n", code,
238 printf("AFS version: %s\n", version);
246 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
248 printf("getstats call failed with code %d\n", code);
252 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
253 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
254 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
255 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
256 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
257 withWaited = (supportedDebugValues & RX_SERVER_DEBUG_WAITED_CNT);
258 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
259 withPackets = (supportedDebugValues & RX_SERVER_DEBUG_PACKETS_CNT);
262 printf("Free packets: %d/%d, packet reclaims: %d, calls: %d, used FDs: %d\n",
263 tstats.nFreePackets, tstats.nPackets, tstats.packetReclaims,
264 tstats.callsExecuted, tstats.usedFDs);
266 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
267 tstats.nFreePackets, tstats.packetReclaims, tstats.callsExecuted,
269 if (!tstats.waitingForPackets)
271 printf("waiting for packets.\n");
273 printf("%d calls waiting for a thread\n", tstats.nWaiting);
275 printf("%d threads are idle\n", tstats.idleThreads);
277 printf("%d calls have waited for a thread\n", tstats.nWaited);
284 "WARNING: Server doesn't support retrieval of Rx statistics\n");
286 struct rx_statistics rxstats;
288 /* should gracefully handle the case where rx_stats grows */
290 rx_GetServerStats(s, host, port, &rxstats,
291 &supportedStatValues);
293 printf("rxstats call failed with code %d\n", code);
296 if (code != sizeof(rxstats)) {
297 if ((((struct rx_debugIn *)(&rxstats))->type ==
301 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
303 /* handle other versions?... */
306 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
307 tstats.nFreePackets, tstats.version);
315 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
319 printf("Showing only server connections\n");
321 printf("Showing only client connections\n");
322 if (onlyAuth != 999) {
323 static char *name[] =
324 { "unauthenticated", "rxkad_clear", "rxkad_auth",
327 printf("Showing only %s connections\n", name[onlyAuth + 1]);
329 if (onlyHost != -1) {
330 hostAddr.s_addr = onlyHost;
331 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
332 printf("Showing only connections from host %s\n",
336 printf("Showing only connections on port %u\n", ntohs(onlyPort));
340 rx_GetServerConnections(s, host, port, &nextconn, allconns,
341 supportedDebugValues, &tconn,
342 &supportedConnValues);
344 printf("getconn call failed with code %d\n", code);
347 if (tconn.cid == (afs_int32) 0xffffffff) {
352 /* see if we're in nodally mode and all calls are dallying */
355 for (j = 0; j < RX_MAXCALLS; j++) {
356 if (tconn.callState[j] != RX_STATE_NOTINIT
357 && tconn.callState[j] != RX_STATE_DALLY) {
363 /* this call looks too ordinary, bump skipped count and go
369 if ((onlyHost != -1) && (onlyHost != tconn.host))
371 if ((onlyPort != -1) && (onlyPort != tconn.port))
373 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
375 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
377 if (onlyAuth != 999) {
378 if (onlyAuth == -1) {
379 if (tconn.securityIndex != 0)
382 if (tconn.securityIndex != 2)
384 if (withSecStats && (tconn.secStats.type == 3)
385 && (tconn.secStats.level != onlyAuth))
390 /* now display the connection */
391 hostAddr.s_addr = tconn.host;
392 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
393 printf("Connection from host %s, port %hu, ", hoststr,
396 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
398 printf("cid %x", tconn.cid);
400 printf(", error %d", tconn.error);
401 printf("\n serial %d, ", tconn.serial);
402 printf(" natMTU %d, ", tconn.natMTU);
406 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
407 printf(" MAKECALL_WAITING");
408 if (tconn.flags & RX_CONN_DESTROY_ME)
409 printf(" DESTROYED");
410 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
412 if (tconn.flags & RX_CONN_KNOW_WINDOW)
413 printf(" knowWindow");
414 if (tconn.flags & RX_CONN_RESET)
416 if (tconn.flags & RX_CONN_BUSY)
418 if (tconn.flags & RX_CONN_ATTACHWAIT)
419 printf(" attachWait");
422 printf("security index %d, ", tconn.securityIndex);
423 if (tconn.type == RX_CLIENT_CONNECTION)
424 printf("client conn\n");
426 printf("server conn\n");
429 switch ((int)tconn.secStats.type) {
431 if (tconn.securityIndex == 2)
433 (" no GetStats procedure for security object\n");
436 printf(" rxnull level=%d, flags=%d\n",
437 tconn.secStats.level, tconn.secStats.flags);
440 printf(" rxvab level=%d, flags=%d\n",
441 tconn.secStats.level, tconn.secStats.flags);
445 char flags = tconn.secStats.flags;
446 if (tconn.secStats.level == 0)
448 else if (tconn.secStats.level == 1)
450 else if (tconn.secStats.level == 2)
454 printf(" rxkad: level %s", level);
460 printf(" authenticated");
465 if (tconn.secStats.expires)
466 /* Apparently due to a bug in the RT compiler that
467 * prevents (afs_uint32)0xffffffff => (double) from working,
468 * this code produces negative lifetimes when run on the
470 printf(", expires in %.1f hours",
471 ((afs_uint32) tconn.secStats.expires -
474 printf("\n Received %u bytes in %u packets\n",
475 tconn.secStats.bytesReceived,
476 tconn.secStats.packetsReceived);
477 printf(" Sent %u bytes in %u packets\n",
478 tconn.secStats.bytesSent,
479 tconn.secStats.packetsSent);
486 printf(" unknown\n");
490 for (j = 0; j < RX_MAXCALLS; j++) {
491 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
492 if (tconn.callState[j] == RX_STATE_NOTINIT) {
493 printf("not initialized\n");
495 } else if (tconn.callState[j] == RX_STATE_PRECALL)
497 else if (tconn.callState[j] == RX_STATE_ACTIVE)
499 else if (tconn.callState[j] == RX_STATE_DALLY)
501 else if (tconn.callState[j] == RX_STATE_HOLD)
504 if (tconn.callMode[j] == RX_MODE_SENDING)
506 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
508 else if (tconn.callMode[j] == RX_MODE_ERROR)
510 else if (tconn.callMode[j] == RX_MODE_EOF)
514 if (tconn.callFlags[j]) {
516 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
517 printf(" reader_wait");
518 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
519 printf(" window_alloc");
520 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
521 printf(" window_send");
522 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
523 printf(" wait_packets");
524 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
525 printf(" waiting_for_process");
526 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
527 printf(" receive_done");
528 if (tconn.callFlags[j] & RX_CALL_CLEARED)
529 printf(" call_cleared");
531 if (tconn.callOther[j] & RX_OTHER_IN)
532 printf(", has_input_packets");
533 if (tconn.callOther[j] & RX_OTHER_OUT)
534 printf(", has_output_packets");
539 printf("Skipped %d dallying connections.\n", dallyCounter);
541 if (showPeers && withPeers) {
543 struct rx_debugPeer tpeer;
545 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
546 &supportedPeerValues);
548 printf("getpeer call failed with code %d\n", code);
551 if (tpeer.host == 0xffffffff) {
556 if ((onlyHost != -1) && (onlyHost != tpeer.host))
558 if ((onlyPort != -1) && (onlyPort != tpeer.port))
561 /* now display the peer */
562 hostAddr.s_addr = tpeer.host;
563 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
564 printf("Peer at host %s, port %hu\n", hoststr,
566 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
567 tpeer.natMTU, tpeer.maxMTU);
568 printf("\tpackets sent %u\tpacket resends %u\n", tpeer.nSent,
570 printf("\tbytes sent high %u low %u\n", tpeer.bytesSent.high,
571 tpeer.bytesSent.low);
572 printf("\tbytes received high %u low %u\n",
573 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
574 printf("\trtt %u msec, rtt_dev %u msec\n", tpeer.rtt >> 3,
576 printf("\ttimeout %u.%03u sec\n", tpeer.timeout.sec,
577 tpeer.timeout.usec / 1000);
581 printf("\tin/out packet skew: %d/%d\n", tpeer.inPacketSkew,
582 tpeer.outPacketSkew);
583 printf("\tcongestion window %d, MTU %d\n", tpeer.cwind,
585 printf("\tcurrent/if/max jumbogram size: %d/%d/%d\n",
586 tpeer.nDgramPackets, tpeer.ifDgramPackets,
587 tpeer.maxDgramPackets);
593 /* simple main program */
595 #include "AFS_component_version_number.c"
602 struct cmd_syndesc *ts;
608 if (afs_winsockInit() < 0) {
609 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
614 ts = cmd_CreateSyntax(NULL, MainCommand, NULL, "probe RX server");
615 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
616 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
617 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
618 "don't show dallying conns");
619 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
620 "don't filter out uninteresting connections on server");
621 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
622 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
623 "only show server conns");
624 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
625 "only show client conns");
626 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
628 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
630 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
631 "show only <auth level>");
633 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
634 "show AFS version id");
635 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
636 "show no connections");
637 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
638 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "detailed output");
640 cmd_Dispatch(argc, argv);