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 <afs/afsutil.h>
19 #include <rx/rx_user.h>
20 #include <rx/rx_clock.h>
21 #include <rx/rx_queue.h>
23 #include <rx/rx_globals.h>
33 PortNumber(char *aport)
39 while ((tc = *aport++)) {
40 if (tc < '0' || tc > '9')
41 return -1; /* bad port number */
43 total += tc - (int)'0';
52 ts = getservbyname(aname, NULL);
55 return ts->s_port; /* returns it in network byte order */
59 MainCommand(struct cmd_syndesc *as, void *arock)
64 struct sockaddr_in taddr;
66 struct in_addr hostAddr;
73 int onlyClient, onlyServer;
87 struct rx_debugStats tstats;
88 char *portName, *hostName;
90 struct rx_debugConn tconn;
96 afs_int32 length = 64;
98 afs_uint32 supportedDebugValues = 0;
99 afs_uint32 supportedStatValues = 0;
100 afs_uint32 supportedConnValues = 0;
101 afs_uint32 supportedPeerValues = 0;
102 afs_int32 nextconn = 0;
103 afs_int32 nextpeer = 0;
105 nodally = (as->parms[2].items ? 1 : 0);
106 allconns = (as->parms[3].items ? 1 : 0);
107 rxstats = (as->parms[4].items ? 1 : 0);
108 onlyServer = (as->parms[5].items ? 1 : 0);
109 onlyClient = (as->parms[6].items ? 1 : 0);
110 version_flag = (as->parms[10].items ? 1 : 0);
111 noConns = (as->parms[11].items ? 1 : 0);
112 showPeers = (as->parms[12].items ? 1 : 0);
113 showLong = (as->parms[13].items ? 1 : 0);
115 if (as->parms[0].items)
116 hostName = as->parms[0].items->data;
120 if (as->parms[1].items)
121 portName = as->parms[1].items->data;
125 if (as->parms[7].items) {
126 char *name = as->parms[7].items->data;
127 if ((onlyPort = PortNumber(name)) == -1)
128 onlyPort = PortName(name);
129 if (onlyPort == -1) {
130 printf("rxdebug: can't resolve port name %s\n", name);
136 if (as->parms[8].items) {
137 char *name = as->parms[8].items->data;
139 th = hostutil_GetHostByName(name);
141 printf("rxdebug: host %s not found in host table\n", name);
144 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
148 if (as->parms[9].items) {
149 char *name = as->parms[9].items->data;
150 /* Note that this assumes that the security levels for rxkad and rxgk
151 * use the same constants (0, 1, and 2). Perhaps a little ugly, but the
152 * constants being identical makes it really convenient to do it this
154 if (strcmp(name, "clear") == 0)
156 else if (strcmp(name, "auth") == 0)
158 else if (strcmp(name, "crypt") == 0)
160 else if ((strcmp(name, "null") == 0) || (strcmp(name, "none") == 0)
161 || (strncmp(name, "noauth", 6) == 0)
162 || (strncmp(name, "unauth", 6) == 0))
165 fprintf(stderr, "Unknown authentication level: %s\n", name);
173 th = hostutil_GetHostByName(hostName);
175 printf("rxdebug: host %s not found in host table\n", hostName);
178 memcpy(&host, th->h_addr, sizeof(afs_int32));
180 host = htonl(0x7f000001); /* IP localhost */
183 port = htons(7000); /* default is fileserver */
185 if ((port = PortNumber(portName)) == -1)
186 port = PortName(portName);
188 printf("rxdebug: can't resolve port name %s\n", portName);
195 hostAddr.s_addr = host;
196 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
197 printf("Trying %s (port %d):\n", hoststr, ntohs(port));
198 s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
199 if (s == OSI_NULLSOCKET) {
201 fprintf(stderr, "socket() failed with error %u\n", WSAGetLastError());
207 taddr.sin_family = AF_INET;
209 taddr.sin_addr.s_addr = 0;
210 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
211 taddr.sin_len = sizeof(struct sockaddr_in);
213 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
216 fprintf(stderr, "bind() failed with error %u\n", WSAGetLastError());
224 memset(version, 0, sizeof(version));
226 code = rx_GetServerVersion(s, host, port, length, version);
228 printf("get version call failed with code %d, errno %d\n", code,
232 version[sizeof(version) - 1] = '\0';
233 printf("AFS version: %s\n", version);
241 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
243 printf("getstats call failed with code %d\n", code);
247 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
248 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
249 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
250 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
251 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
252 withWaited = (supportedDebugValues & RX_SERVER_DEBUG_WAITED_CNT);
253 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
254 withPackets = (supportedDebugValues & RX_SERVER_DEBUG_PACKETS_CNT);
257 printf("Free packets: %d/%d, packet reclaims: %d, calls: %d, used FDs: %d\n",
258 tstats.nFreePackets, tstats.nPackets, tstats.packetReclaims,
259 tstats.callsExecuted, tstats.usedFDs);
261 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
262 tstats.nFreePackets, tstats.packetReclaims, tstats.callsExecuted,
264 if (!tstats.waitingForPackets)
266 printf("waiting for packets.\n");
268 printf("%d calls waiting for a thread\n", tstats.nWaiting);
270 printf("%d threads are idle\n", tstats.idleThreads);
272 printf("%d calls have waited for a thread\n", tstats.nWaited);
279 "WARNING: Server doesn't support retrieval of Rx statistics\n");
281 struct rx_statistics rxstats;
283 /* should gracefully handle the case where rx_stats grows */
285 rx_GetServerStats(s, host, port, &rxstats,
286 &supportedStatValues);
288 printf("rxstats call failed with code %d\n", code);
291 if (code != sizeof(rxstats)) {
292 struct rx_debugIn debug;
293 memcpy(&debug, &rxstats, sizeof(debug));
294 if (debug.type == RX_DEBUGI_BADTYPE)
297 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
299 /* handle other versions?... */
302 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
303 tstats.nFreePackets, tstats.version);
311 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
315 printf("Showing only server connections\n");
317 printf("Showing only client connections\n");
318 if (onlyAuth != 999) {
319 static char *name[] =
320 { "unauthenticated", "clear", "auth",
323 printf("Showing only %s connections\n", name[onlyAuth + 1]);
325 if (onlyHost != -1) {
326 hostAddr.s_addr = onlyHost;
327 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
328 printf("Showing only connections from host %s\n",
332 printf("Showing only connections on port %u\n", ntohs(onlyPort));
336 rx_GetServerConnections(s, host, port, &nextconn, allconns,
337 supportedDebugValues, &tconn,
338 &supportedConnValues);
340 printf("getconn call failed with code %d\n", code);
343 if (tconn.cid == (afs_int32) 0xffffffff) {
348 /* see if we're in nodally mode and all calls are dallying */
351 for (j = 0; j < RX_MAXCALLS; j++) {
352 if (tconn.callState[j] != RX_STATE_NOTINIT
353 && tconn.callState[j] != RX_STATE_DALLY) {
359 /* this call looks too ordinary, bump skipped count and go
365 if ((onlyHost != -1) && (onlyHost != tconn.host))
367 if ((onlyPort != -1) && (onlyPort != tconn.port))
369 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
371 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
373 if (onlyAuth != 999) {
374 if (onlyAuth == -1) {
375 if (tconn.securityIndex != RX_SECIDX_NULL)
378 if (tconn.securityIndex != RX_SECIDX_KAD) {
380 if (tconn.securityIndex != RX_SECIDX_GK)
384 if (withSecStats && (tconn.secStats.type == RX_SECTYPE_KAD)
385 && (tconn.secStats.level != onlyAuth))
388 if (withSecStats && (tconn.secStats.type == RX_SECTYPE_GK)
389 && (tconn.secStats.level != onlyAuth))
395 /* now display the connection */
396 hostAddr.s_addr = tconn.host;
397 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
398 printf("Connection from host %s, port %hu, ", hoststr,
401 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
403 printf("cid %x", tconn.cid);
405 printf(", error %d", tconn.error);
406 printf("\n serial %d, ", tconn.serial);
407 printf(" natMTU %d, ", tconn.natMTU);
411 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
412 printf(" MAKECALL_WAITING");
413 if (tconn.flags & RX_CONN_DESTROY_ME)
414 printf(" DESTROYED");
415 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
417 if (tconn.flags & RX_CONN_KNOW_WINDOW)
418 printf(" knowWindow");
419 if (tconn.flags & RX_CONN_RESET)
421 if (tconn.flags & RX_CONN_BUSY)
423 if (tconn.flags & RX_CONN_ATTACHWAIT)
424 printf(" attachWait");
427 printf("security index %d, ", tconn.securityIndex);
428 if (tconn.type == RX_CLIENT_CONNECTION)
429 printf("client conn\n");
431 printf("server conn\n");
434 switch ((int)tconn.secStats.type) {
436 if (tconn.securityIndex == RX_SECIDX_KAD)
438 (" no GetStats procedure for security object\n");
440 case RX_SECTYPE_NULL:
441 printf(" rxnull level=%d, flags=%d\n",
442 tconn.secStats.level, tconn.secStats.flags);
445 printf(" rxvab level=%d, flags=%d\n",
446 tconn.secStats.level, tconn.secStats.flags);
448 case RX_SECTYPE_KAD:{
450 char flags = tconn.secStats.flags;
451 if (tconn.secStats.level == 0)
453 else if (tconn.secStats.level == 1)
455 else if (tconn.secStats.level == 2)
459 printf(" rxkad: level %s", level);
465 printf(" authenticated");
470 if (tconn.secStats.expires)
471 /* Apparently due to a bug in the RT compiler that
472 * prevents (afs_uint32)0xffffffff => (double) from working,
473 * this code produces negative lifetimes when run on the
475 printf(", expires in %.1f hours",
476 ((afs_uint32) tconn.secStats.expires -
479 printf("\n Received %u bytes in %u packets\n",
480 tconn.secStats.bytesReceived,
481 tconn.secStats.packetsReceived);
482 printf(" Sent %u bytes in %u packets\n",
483 tconn.secStats.bytesSent,
484 tconn.secStats.packetsSent);
490 case RX_SECTYPE_GK: {
492 char flags = tconn.secStats.flags;
493 if (tconn.secStats.level == RXGK_LEVEL_CLEAR)
495 else if (tconn.secStats.level == RXGK_LEVEL_AUTH)
497 else if (tconn.secStats.level == RXGK_LEVEL_CRYPT)
501 printf(" rxgk: level %s", level);
504 if ((flags & RXGK_STATS_UNALLOC))
506 if ((flags & RXGK_STATS_AUTH))
507 printf(" authenticated");
508 if (tconn.secStats.expires)
509 printf(", expires in %.1f hours",
510 ((afs_uint32) tconn.secStats.expires -
512 if (!(flags & RXGK_STATS_UNALLOC)) {
513 printf("\n Received %u bytes in %u packets\n",
514 tconn.secStats.bytesReceived,
515 tconn.secStats.packetsReceived);
516 printf(" Sent %u bytes in %u packets\n",
517 tconn.secStats.bytesSent,
518 tconn.secStats.packetsSent);
523 #endif /* ENABLE_RXGK */
526 printf(" unknown\n");
530 for (j = 0; j < RX_MAXCALLS; j++) {
531 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
532 if (tconn.callState[j] == RX_STATE_NOTINIT) {
533 printf("not initialized\n");
535 } else if (tconn.callState[j] == RX_STATE_PRECALL)
537 else if (tconn.callState[j] == RX_STATE_ACTIVE)
539 else if (tconn.callState[j] == RX_STATE_DALLY)
541 else if (tconn.callState[j] == RX_STATE_HOLD)
543 else if (tconn.callState[j] == RX_STATE_RESET)
546 if (tconn.callMode[j] == RX_MODE_SENDING)
548 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
550 else if (tconn.callMode[j] == RX_MODE_ERROR)
552 else if (tconn.callMode[j] == RX_MODE_EOF)
556 if (tconn.callFlags[j]) {
558 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
559 printf(" reader_wait");
560 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
561 printf(" window_alloc");
562 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
563 printf(" window_send");
564 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
565 printf(" wait_packets");
566 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
567 printf(" waiting_for_process");
568 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
569 printf(" receive_done");
570 if (tconn.callFlags[j] & RX_CALL_CLEARED)
571 printf(" call_cleared");
573 if (tconn.callOther[j] & RX_OTHER_IN)
574 printf(", has_input_packets");
575 if (tconn.callOther[j] & RX_OTHER_OUT)
576 printf(", has_output_packets");
581 printf("Skipped %d dallying connections.\n", dallyCounter);
583 if (showPeers && withPeers) {
585 struct rx_debugPeer tpeer;
587 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
588 &supportedPeerValues);
590 printf("getpeer call failed with code %d\n", code);
593 if (tpeer.host == 0xffffffff) {
598 if ((onlyHost != -1) && (onlyHost != tpeer.host))
600 if ((onlyPort != -1) && (onlyPort != tpeer.port))
603 /* now display the peer */
604 hostAddr.s_addr = tpeer.host;
605 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
606 printf("Peer at host %s, port %hu\n", hoststr,
608 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
609 tpeer.natMTU, tpeer.maxMTU);
610 printf("\tpackets sent %u\tpacket resends %u\n", tpeer.nSent,
612 printf("\tbytes sent high %u low %u\n", tpeer.bytesSent.high,
613 tpeer.bytesSent.low);
614 printf("\tbytes received high %u low %u\n",
615 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
616 printf("\trtt %u msec, rtt_dev %u msec\n", tpeer.rtt >> 3,
618 printf("\ttimeout %u.%03u sec\n", tpeer.timeout.sec,
619 tpeer.timeout.usec / 1000);
623 printf("\tin/out packet skew: %d/%d\n", tpeer.inPacketSkew,
624 tpeer.outPacketSkew);
625 printf("\tcongestion window %d, MTU %d\n", tpeer.cwind,
627 printf("\tcurrent/if/max jumbogram size: %d/%d/%d\n",
628 tpeer.nDgramPackets, tpeer.ifDgramPackets,
629 tpeer.maxDgramPackets);
635 /* simple main program */
637 #include "AFS_component_version_number.c"
640 main(int argc, char **argv)
642 struct cmd_syndesc *ts;
648 if (afs_winsockInit() < 0) {
649 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
654 ts = cmd_CreateSyntax(NULL, MainCommand, NULL, 0, "probe RX server");
655 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
656 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
657 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
658 "don't show dallying conns");
659 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
660 "don't filter out uninteresting connections on server");
661 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
662 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
663 "only show server conns");
664 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
665 "only show client conns");
666 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
668 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
670 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
671 "show only <auth level>");
673 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
674 "show AFS version id");
675 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
676 "show no connections");
677 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
678 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "detailed output");
680 cmd_Dispatch(argc, argv);