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>
29 PortNumber(char *aport)
35 while ((tc = *aport++)) {
36 if (tc < '0' || tc > '9')
37 return -1; /* bad port number */
39 total += tc - (int)'0';
48 ts = getservbyname(aname, NULL);
51 return ts->s_port; /* returns it in network byte order */
55 MainCommand(struct cmd_syndesc *as, void *arock)
60 struct sockaddr_in taddr;
62 struct in_addr hostAddr;
69 int onlyClient, onlyServer;
83 struct rx_debugStats tstats;
84 char *portName, *hostName;
86 struct rx_debugConn tconn;
92 afs_int32 length = 64;
94 afs_uint32 supportedDebugValues = 0;
95 afs_uint32 supportedStatValues = 0;
96 afs_uint32 supportedConnValues = 0;
97 afs_uint32 supportedPeerValues = 0;
98 afs_int32 nextconn = 0;
99 afs_int32 nextpeer = 0;
101 nodally = (as->parms[2].items ? 1 : 0);
102 allconns = (as->parms[3].items ? 1 : 0);
103 rxstats = (as->parms[4].items ? 1 : 0);
104 onlyServer = (as->parms[5].items ? 1 : 0);
105 onlyClient = (as->parms[6].items ? 1 : 0);
106 version_flag = (as->parms[10].items ? 1 : 0);
107 noConns = (as->parms[11].items ? 1 : 0);
108 showPeers = (as->parms[12].items ? 1 : 0);
109 showLong = (as->parms[13].items ? 1 : 0);
111 if (as->parms[0].items)
112 hostName = as->parms[0].items->data;
116 if (as->parms[1].items)
117 portName = as->parms[1].items->data;
121 if (as->parms[7].items) {
122 char *name = as->parms[7].items->data;
123 if ((onlyPort = PortNumber(name)) == -1)
124 onlyPort = PortName(name);
125 if (onlyPort == -1) {
126 printf("rxdebug: can't resolve port name %s\n", name);
132 if (as->parms[8].items) {
133 char *name = as->parms[8].items->data;
135 th = hostutil_GetHostByName(name);
137 printf("rxdebug: host %s not found in host table\n", name);
140 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
144 if (as->parms[9].items) {
145 char *name = as->parms[9].items->data;
146 if (strcmp(name, "clear") == 0)
148 else if (strcmp(name, "auth") == 0)
150 else if (strcmp(name, "crypt") == 0)
152 else if ((strcmp(name, "null") == 0) || (strcmp(name, "none") == 0)
153 || (strncmp(name, "noauth", 6) == 0)
154 || (strncmp(name, "unauth", 6) == 0))
157 fprintf(stderr, "Unknown authentication level: %s\n", name);
165 th = hostutil_GetHostByName(hostName);
167 printf("rxdebug: host %s not found in host table\n", hostName);
170 memcpy(&host, th->h_addr, sizeof(afs_int32));
172 host = htonl(0x7f000001); /* IP localhost */
175 port = htons(7000); /* default is fileserver */
177 if ((port = PortNumber(portName)) == -1)
178 port = PortName(portName);
180 printf("rxdebug: can't resolve port name %s\n", portName);
187 hostAddr.s_addr = host;
188 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
189 printf("Trying %s (port %d):\n", hoststr, ntohs(port));
190 s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
191 if (s == OSI_NULLSOCKET) {
193 fprintf(stderr, "socket() failed with error %u\n", WSAGetLastError());
199 taddr.sin_family = AF_INET;
201 taddr.sin_addr.s_addr = 0;
202 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
203 taddr.sin_len = sizeof(struct sockaddr_in);
205 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
208 fprintf(stderr, "bind() failed with error %u\n", WSAGetLastError());
217 code = rx_GetServerVersion(s, host, port, length, version);
219 printf("get version call failed with code %d, errno %d\n", code,
223 printf("AFS version: %s\n", version);
231 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
233 printf("getstats call failed with code %d\n", code);
237 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
238 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
239 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
240 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
241 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
242 withWaited = (supportedDebugValues & RX_SERVER_DEBUG_WAITED_CNT);
243 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
244 withPackets = (supportedDebugValues & RX_SERVER_DEBUG_PACKETS_CNT);
247 printf("Free packets: %d/%d, packet reclaims: %d, calls: %d, used FDs: %d\n",
248 tstats.nFreePackets, tstats.nPackets, tstats.packetReclaims,
249 tstats.callsExecuted, tstats.usedFDs);
251 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
252 tstats.nFreePackets, tstats.packetReclaims, tstats.callsExecuted,
254 if (!tstats.waitingForPackets)
256 printf("waiting for packets.\n");
258 printf("%d calls waiting for a thread\n", tstats.nWaiting);
260 printf("%d threads are idle\n", tstats.idleThreads);
262 printf("%d calls have waited for a thread\n", tstats.nWaited);
269 "WARNING: Server doesn't support retrieval of Rx statistics\n");
271 struct rx_statistics rxstats;
273 /* should gracefully handle the case where rx_stats grows */
275 rx_GetServerStats(s, host, port, &rxstats,
276 &supportedStatValues);
278 printf("rxstats call failed with code %d\n", code);
281 if (code != sizeof(rxstats)) {
282 struct rx_debugIn debug;
283 memcpy(&debug, &rxstats, sizeof(debug));
284 if (debug.type == RX_DEBUGI_BADTYPE)
287 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
289 /* handle other versions?... */
292 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
293 tstats.nFreePackets, tstats.version);
301 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
305 printf("Showing only server connections\n");
307 printf("Showing only client connections\n");
308 if (onlyAuth != 999) {
309 static char *name[] =
310 { "unauthenticated", "rxkad_clear", "rxkad_auth",
313 printf("Showing only %s connections\n", name[onlyAuth + 1]);
315 if (onlyHost != -1) {
316 hostAddr.s_addr = onlyHost;
317 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
318 printf("Showing only connections from host %s\n",
322 printf("Showing only connections on port %u\n", ntohs(onlyPort));
326 rx_GetServerConnections(s, host, port, &nextconn, allconns,
327 supportedDebugValues, &tconn,
328 &supportedConnValues);
330 printf("getconn call failed with code %d\n", code);
333 if (tconn.cid == (afs_int32) 0xffffffff) {
338 /* see if we're in nodally mode and all calls are dallying */
341 for (j = 0; j < RX_MAXCALLS; j++) {
342 if (tconn.callState[j] != RX_STATE_NOTINIT
343 && tconn.callState[j] != RX_STATE_DALLY) {
349 /* this call looks too ordinary, bump skipped count and go
355 if ((onlyHost != -1) && (onlyHost != tconn.host))
357 if ((onlyPort != -1) && (onlyPort != tconn.port))
359 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
361 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
363 if (onlyAuth != 999) {
364 if (onlyAuth == -1) {
365 if (tconn.securityIndex != RX_SECIDX_NULL)
368 if (tconn.securityIndex != RX_SECIDX_KAD)
370 if (withSecStats && (tconn.secStats.type == RX_SECTYPE_KAD)
371 && (tconn.secStats.level != onlyAuth))
376 /* now display the connection */
377 hostAddr.s_addr = tconn.host;
378 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
379 printf("Connection from host %s, port %hu, ", hoststr,
382 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
384 printf("cid %x", tconn.cid);
386 printf(", error %d", tconn.error);
387 printf("\n serial %d, ", tconn.serial);
388 printf(" natMTU %d, ", tconn.natMTU);
392 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
393 printf(" MAKECALL_WAITING");
394 if (tconn.flags & RX_CONN_DESTROY_ME)
395 printf(" DESTROYED");
396 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
398 if (tconn.flags & RX_CONN_KNOW_WINDOW)
399 printf(" knowWindow");
400 if (tconn.flags & RX_CONN_RESET)
402 if (tconn.flags & RX_CONN_BUSY)
404 if (tconn.flags & RX_CONN_ATTACHWAIT)
405 printf(" attachWait");
408 printf("security index %d, ", tconn.securityIndex);
409 if (tconn.type == RX_CLIENT_CONNECTION)
410 printf("client conn\n");
412 printf("server conn\n");
415 switch ((int)tconn.secStats.type) {
417 if (tconn.securityIndex == RX_SECIDX_KAD)
419 (" no GetStats procedure for security object\n");
421 case RX_SECTYPE_NULL:
422 printf(" rxnull level=%d, flags=%d\n",
423 tconn.secStats.level, tconn.secStats.flags);
426 printf(" rxvab level=%d, flags=%d\n",
427 tconn.secStats.level, tconn.secStats.flags);
429 case RX_SECTYPE_KAD:{
431 char flags = tconn.secStats.flags;
432 if (tconn.secStats.level == 0)
434 else if (tconn.secStats.level == 1)
436 else if (tconn.secStats.level == 2)
440 printf(" rxkad: level %s", level);
446 printf(" authenticated");
451 if (tconn.secStats.expires)
452 /* Apparently due to a bug in the RT compiler that
453 * prevents (afs_uint32)0xffffffff => (double) from working,
454 * this code produces negative lifetimes when run on the
456 printf(", expires in %.1f hours",
457 ((afs_uint32) tconn.secStats.expires -
460 printf("\n Received %u bytes in %u packets\n",
461 tconn.secStats.bytesReceived,
462 tconn.secStats.packetsReceived);
463 printf(" Sent %u bytes in %u packets\n",
464 tconn.secStats.bytesSent,
465 tconn.secStats.packetsSent);
472 printf(" unknown\n");
476 for (j = 0; j < RX_MAXCALLS; j++) {
477 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
478 if (tconn.callState[j] == RX_STATE_NOTINIT) {
479 printf("not initialized\n");
481 } else if (tconn.callState[j] == RX_STATE_PRECALL)
483 else if (tconn.callState[j] == RX_STATE_ACTIVE)
485 else if (tconn.callState[j] == RX_STATE_DALLY)
487 else if (tconn.callState[j] == RX_STATE_HOLD)
489 else if (tconn.callState[j] == RX_STATE_RESET)
492 if (tconn.callMode[j] == RX_MODE_SENDING)
494 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
496 else if (tconn.callMode[j] == RX_MODE_ERROR)
498 else if (tconn.callMode[j] == RX_MODE_EOF)
502 if (tconn.callFlags[j]) {
504 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
505 printf(" reader_wait");
506 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
507 printf(" window_alloc");
508 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
509 printf(" window_send");
510 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
511 printf(" wait_packets");
512 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
513 printf(" waiting_for_process");
514 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
515 printf(" receive_done");
516 if (tconn.callFlags[j] & RX_CALL_CLEARED)
517 printf(" call_cleared");
519 if (tconn.callOther[j] & RX_OTHER_IN)
520 printf(", has_input_packets");
521 if (tconn.callOther[j] & RX_OTHER_OUT)
522 printf(", has_output_packets");
527 printf("Skipped %d dallying connections.\n", dallyCounter);
529 if (showPeers && withPeers) {
531 struct rx_debugPeer tpeer;
533 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
534 &supportedPeerValues);
536 printf("getpeer call failed with code %d\n", code);
539 if (tpeer.host == 0xffffffff) {
544 if ((onlyHost != -1) && (onlyHost != tpeer.host))
546 if ((onlyPort != -1) && (onlyPort != tpeer.port))
549 /* now display the peer */
550 hostAddr.s_addr = tpeer.host;
551 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
552 printf("Peer at host %s, port %hu\n", hoststr,
554 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
555 tpeer.natMTU, tpeer.maxMTU);
556 printf("\tpackets sent %u\tpacket resends %u\n", tpeer.nSent,
558 printf("\tbytes sent high %u low %u\n", tpeer.bytesSent.high,
559 tpeer.bytesSent.low);
560 printf("\tbytes received high %u low %u\n",
561 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
562 printf("\trtt %u msec, rtt_dev %u msec\n", tpeer.rtt >> 3,
564 printf("\ttimeout %u.%03u sec\n", tpeer.timeout.sec,
565 tpeer.timeout.usec / 1000);
569 printf("\tin/out packet skew: %d/%d\n", tpeer.inPacketSkew,
570 tpeer.outPacketSkew);
571 printf("\tcongestion window %d, MTU %d\n", tpeer.cwind,
573 printf("\tcurrent/if/max jumbogram size: %d/%d/%d\n",
574 tpeer.nDgramPackets, tpeer.ifDgramPackets,
575 tpeer.maxDgramPackets);
581 /* simple main program */
583 #include "AFS_component_version_number.c"
586 main(int argc, char **argv)
588 struct cmd_syndesc *ts;
594 if (afs_winsockInit() < 0) {
595 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
600 ts = cmd_CreateSyntax(NULL, MainCommand, NULL, 0, "probe RX server");
601 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
602 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
603 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
604 "don't show dallying conns");
605 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
606 "don't filter out uninteresting connections on server");
607 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
608 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
609 "only show server conns");
610 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
611 "only show client conns");
612 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
614 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
616 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
617 "show only <auth level>");
619 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
620 "show AFS version id");
621 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
622 "show no connections");
623 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
624 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "detailed output");
626 cmd_Dispatch(argc, argv);