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
52 #include "rx_globals.h"
57 extern struct hostent *hostutil_GetHostByName();
67 while (tc = *aport++) {
68 if (tc < '0' || tc > '9')
69 return -1; /* bad port number */
71 total += tc - (int)'0';
80 register struct servent *ts;
81 ts = getservbyname(aname, NULL);
84 return ts->s_port; /* returns it in network byte order */
88 MainCommand(as, arock)
90 struct cmd_syndesc *as;
95 struct sockaddr_in taddr;
97 struct in_addr hostAddr;
100 register afs_int32 code;
104 int onlyClient, onlyServer;
117 struct rx_debugStats tstats;
118 char *portName, *hostName;
120 struct rx_debugConn tconn;
126 afs_int32 length = 64;
128 afs_uint32 supportedDebugValues = 0;
129 afs_uint32 supportedStatValues = 0;
130 afs_uint32 supportedConnValues = 0;
131 afs_uint32 supportedPeerValues = 0;
132 afs_int32 nextconn = 0;
133 afs_int32 nextpeer = 0;
135 nodally = (as->parms[2].items ? 1 : 0);
136 allconns = (as->parms[3].items ? 1 : 0);
137 rxstats = (as->parms[4].items ? 1 : 0);
138 onlyServer = (as->parms[5].items ? 1 : 0);
139 onlyClient = (as->parms[6].items ? 1 : 0);
140 version_flag = (as->parms[10].items ? 1 : 0);
141 noConns = (as->parms[11].items ? 1 : 0);
142 showPeers = (as->parms[12].items ? 1 : 0);
143 showLong = (as->parms[13].items ? 1 : 0);
145 if (as->parms[0].items)
146 hostName = as->parms[0].items->data;
150 if (as->parms[1].items)
151 portName = as->parms[1].items->data;
155 if (as->parms[7].items) {
156 char *name = as->parms[7].items->data;
157 if ((onlyPort = PortNumber(name)) == -1)
158 onlyPort = PortName(name);
159 if (onlyPort == -1) {
160 printf("rxdebug: can't resolve port name %s\n", name);
166 if (as->parms[8].items) {
167 char *name = as->parms[8].items->data;
169 th = hostutil_GetHostByName(name);
171 printf("rxdebug: host %s not found in host table\n", name);
174 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
178 if (as->parms[9].items) {
179 char *name = as->parms[9].items->data;
180 if (strcmp(name, "clear") == 0)
182 else if (strcmp(name, "auth") == 0)
184 else if (strcmp(name, "crypt") == 0)
186 else if ((strcmp(name, "null") == 0) || (strcmp(name, "none") == 0)
187 || (strncmp(name, "noauth", 6) == 0)
188 || (strncmp(name, "unauth", 6) == 0))
191 fprintf(stderr, "Unknown authentication level: %s\n", name);
199 th = hostutil_GetHostByName(hostName);
201 printf("rxdebug: host %s not found in host table\n", hostName);
204 memcpy(&host, th->h_addr, sizeof(afs_int32));
206 host = htonl(0x7f000001); /* IP localhost */
209 port = htons(7000); /* default is fileserver */
211 if ((port = PortNumber(portName)) == -1)
212 port = PortName(portName);
214 printf("rxdebug: can't resolve port name %s\n", portName);
221 hostAddr.s_addr = host;
222 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
223 printf("Trying %s (port %d):\n", hoststr, ntohs(port));
224 s = socket(AF_INET, SOCK_DGRAM, 0);
225 taddr.sin_family = AF_INET;
227 taddr.sin_addr.s_addr = 0;
228 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
229 taddr.sin_len = sizeof(struct sockaddr_in);
231 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
239 code = rx_GetServerVersion(s, host, port, length, version);
241 printf("get version call failed with code %d, errno %d\n", code,
245 printf("AFS version: %s\n", version);
253 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
255 printf("getstats call failed with code %d\n", code);
259 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
260 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
261 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
262 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
263 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
264 withWaited = (supportedDebugValues & RX_SERVER_DEBUG_WAITED_CNT);
265 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
267 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
268 tstats.nFreePackets, tstats.packetReclaims, tstats.callsExecuted,
270 if (!tstats.waitingForPackets)
272 printf("waiting for packets.\n");
274 printf("%d calls waiting for a thread\n", tstats.nWaiting);
276 printf("%d threads are idle\n", tstats.idleThreads);
278 printf("%d calls have waited for a thread\n", tstats.nWaited);
285 "WARNING: Server doesn't support retrieval of Rx statistics\n");
287 struct rx_stats rxstats;
289 /* should gracefully handle the case where rx_stats grows */
291 rx_GetServerStats(s, host, port, &rxstats,
292 &supportedStatValues);
294 printf("rxstats call failed with code %d\n", code);
297 if (code != sizeof(rxstats)) {
298 if ((((struct rx_debugIn *)(&rxstats))->type ==
302 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
304 /* handle other versions?... */
307 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
308 tstats.nFreePackets, tstats.version);
316 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
320 printf("Showing only server connections\n");
322 printf("Showing only client connections\n");
323 if (onlyAuth != 999) {
324 static char *name[] =
325 { "unauthenticated", "rxkad_clear", "rxkad_auth",
328 printf("Showing only %s connections\n", name[onlyAuth + 1]);
330 if (onlyHost != -1) {
331 hostAddr.s_addr = onlyHost;
332 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
333 printf("Showing only connections from host %s\n",
337 printf("Showing only connections on port %u\n", ntohs(onlyPort));
341 rx_GetServerConnections(s, host, port, &nextconn, allconns,
342 supportedDebugValues, &tconn,
343 &supportedConnValues);
345 printf("getconn call failed with code %d\n", code);
348 if (tconn.cid == (afs_int32) 0xffffffff) {
353 /* see if we're in nodally mode and all calls are dallying */
356 for (j = 0; j < RX_MAXCALLS; j++) {
357 if (tconn.callState[j] != RX_STATE_NOTINIT
358 && tconn.callState[j] != RX_STATE_DALLY) {
364 /* this call looks too ordinary, bump skipped count and go
370 if ((onlyHost != -1) && (onlyHost != tconn.host))
372 if ((onlyPort != -1) && (onlyPort != tconn.port))
374 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
376 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
378 if (onlyAuth != 999) {
379 if (onlyAuth == -1) {
380 if (tconn.securityIndex != 0)
383 if (tconn.securityIndex != 2)
385 if (withSecStats && (tconn.secStats.type == 3)
386 && (tconn.secStats.level != onlyAuth))
391 /* now display the connection */
392 hostAddr.s_addr = tconn.host;
393 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
394 printf("Connection from host %s, port %hu, ", hoststr,
397 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
399 printf("cid %x", tconn.cid);
401 printf(", error %d", tconn.error);
402 printf("\n serial %d, ", tconn.serial);
403 printf(" natMTU %d, ", tconn.natMTU);
407 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
408 printf(" MAKECALL_WAITING");
409 if (tconn.flags & RX_CONN_DESTROY_ME)
410 printf(" DESTROYED");
411 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
415 printf("security index %d, ", tconn.securityIndex);
416 if (tconn.type == RX_CLIENT_CONNECTION)
417 printf("client conn\n");
419 printf("server conn\n");
422 switch ((int)tconn.secStats.type) {
424 if (tconn.securityIndex == 2)
426 (" no GetStats procedure for security object\n");
429 printf(" rxnull level=%d, flags=%d\n",
430 tconn.secStats.level, tconn.secStats.flags);
433 printf(" rxvab level=%d, flags=%d\n",
434 tconn.secStats.level, tconn.secStats.flags);
438 char flags = tconn.secStats.flags;
439 if (tconn.secStats.level == 0)
441 else if (tconn.secStats.level == 1)
443 else if (tconn.secStats.level == 2)
447 printf(" rxkad: level %s", level);
453 printf(" authenticated");
458 if (tconn.secStats.expires)
459 /* Apparently due to a bug in the RT compiler that
460 * prevents (afs_uint32)0xffffffff => (double) from working,
461 * this code produces negative lifetimes when run on the
463 printf(", expires in %.1f hours",
464 ((afs_uint32) tconn.secStats.expires -
467 printf("\n Received %u bytes in %u packets\n",
468 tconn.secStats.bytesReceived,
469 tconn.secStats.packetsReceived);
470 printf(" Sent %u bytes in %u packets\n",
471 tconn.secStats.bytesSent,
472 tconn.secStats.packetsSent);
479 printf(" unknown\n");
483 for (j = 0; j < RX_MAXCALLS; j++) {
484 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
485 if (tconn.callState[j] == RX_STATE_NOTINIT) {
486 printf("not initialized\n");
488 } else if (tconn.callState[j] == RX_STATE_PRECALL)
490 else if (tconn.callState[j] == RX_STATE_ACTIVE)
492 else if (tconn.callState[j] == RX_STATE_DALLY)
494 else if (tconn.callState[j] == RX_STATE_HOLD)
497 if (tconn.callMode[j] == RX_MODE_SENDING)
499 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
501 else if (tconn.callMode[j] == RX_MODE_ERROR)
503 else if (tconn.callMode[j] == RX_MODE_EOF)
507 if (tconn.callFlags[j]) {
509 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
510 printf(" reader_wait");
511 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
512 printf(" window_alloc");
513 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
514 printf(" window_send");
515 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
516 printf(" wait_packets");
517 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
518 printf(" waiting_for_process");
519 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
520 printf(" receive_done");
521 if (tconn.callFlags[j] & RX_CALL_CLEARED)
522 printf(" call_cleared");
524 if (tconn.callOther[j] & RX_OTHER_IN)
525 printf(", has_input_packets");
526 if (tconn.callOther[j] & RX_OTHER_OUT)
527 printf(", has_output_packets");
532 printf("Skipped %d dallying connections.\n", dallyCounter);
534 if (showPeers && withPeers) {
536 struct rx_debugPeer tpeer;
538 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
539 &supportedPeerValues);
541 printf("getpeer call failed with code %d\n", code);
544 if (tpeer.host == 0xffffffff) {
549 if ((onlyHost != -1) && (onlyHost != tpeer.host))
551 if ((onlyPort != -1) && (onlyPort != tpeer.port))
554 /* now display the peer */
555 hostAddr.s_addr = tpeer.host;
556 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
557 printf("Peer at host %s, port %hu\n", hoststr,
559 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
560 tpeer.natMTU, tpeer.maxMTU);
561 printf("\tpackets sent %u\tpacket resends %u\n", tpeer.nSent,
563 printf("\tbytes sent high %u low %u\n", tpeer.bytesSent.high,
564 tpeer.bytesSent.low);
565 printf("\tbytes received high %u low %u\n",
566 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
567 printf("\trtt %u msec, rtt_dev %u msec\n", tpeer.rtt >> 3,
569 printf("\ttimeout %u.%03u sec\n", tpeer.timeout.sec,
570 tpeer.timeout.usec / 1000);
574 printf("\tin/out packet skew: %d/%d\n", tpeer.inPacketSkew,
575 tpeer.outPacketSkew);
576 printf("\tcongestion window %d, MTU %d\n", tpeer.cwind,
578 printf("\tcurrent/if/max jumbogram size: %d/%d/%d\n",
579 tpeer.nDgramPackets, tpeer.ifDgramPackets,
580 tpeer.maxDgramPackets);
586 /* simple main program */
588 #include "AFS_component_version_number.c"
595 struct cmd_syndesc *ts;
601 if (afs_winsockInit() < 0) {
602 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
607 ts = cmd_CreateSyntax(NULL, MainCommand, 0, "probe RX server");
608 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
609 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
610 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
611 "don't show dallying conns");
612 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
613 "don't filter out uninteresting connections on server");
614 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
615 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
616 "only show server conns");
617 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
618 "only show client conns");
619 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
621 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
623 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
624 "show only <auth level>");
626 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
627 "show AFS version id");
628 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
629 "show no connections");
630 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
631 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "detailed output");
633 cmd_Dispatch(argc, argv);