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(as, arock)
84 struct cmd_syndesc *as;
89 struct sockaddr_in taddr;
91 struct in_addr hostAddr;
94 register afs_int32 code;
98 int onlyClient, onlyServer;
111 struct rx_debugStats tstats;
112 char *portName, *hostName;
114 struct rx_debugConn tconn;
120 afs_int32 length = 64;
122 afs_uint32 supportedDebugValues = 0;
123 afs_uint32 supportedStatValues = 0;
124 afs_uint32 supportedConnValues = 0;
125 afs_uint32 supportedPeerValues = 0;
126 afs_int32 nextconn = 0;
127 afs_int32 nextpeer = 0;
129 nodally = (as->parms[2].items ? 1 : 0);
130 allconns = (as->parms[3].items ? 1 : 0);
131 rxstats = (as->parms[4].items ? 1 : 0);
132 onlyServer = (as->parms[5].items ? 1 : 0);
133 onlyClient = (as->parms[6].items ? 1 : 0);
134 version_flag = (as->parms[10].items ? 1 : 0);
135 noConns = (as->parms[11].items ? 1 : 0);
136 showPeers = (as->parms[12].items ? 1 : 0);
137 showLong = (as->parms[13].items ? 1 : 0);
139 if (as->parms[0].items)
140 hostName = as->parms[0].items->data;
144 if (as->parms[1].items)
145 portName = as->parms[1].items->data;
149 if (as->parms[7].items) {
150 char *name = as->parms[7].items->data;
151 if ((onlyPort = PortNumber(name)) == -1)
152 onlyPort = PortName(name);
153 if (onlyPort == -1) {
154 printf("rxdebug: can't resolve port name %s\n", name);
160 if (as->parms[8].items) {
161 char *name = as->parms[8].items->data;
163 th = hostutil_GetHostByName(name);
165 printf("rxdebug: host %s not found in host table\n", name);
168 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
172 if (as->parms[9].items) {
173 char *name = as->parms[9].items->data;
174 if (strcmp(name, "clear") == 0)
176 else if (strcmp(name, "auth") == 0)
178 else if (strcmp(name, "crypt") == 0)
180 else if ((strcmp(name, "null") == 0) || (strcmp(name, "none") == 0)
181 || (strncmp(name, "noauth", 6) == 0)
182 || (strncmp(name, "unauth", 6) == 0))
185 fprintf(stderr, "Unknown authentication level: %s\n", name);
193 th = hostutil_GetHostByName(hostName);
195 printf("rxdebug: host %s not found in host table\n", hostName);
198 memcpy(&host, th->h_addr, sizeof(afs_int32));
200 host = htonl(0x7f000001); /* IP localhost */
203 port = htons(7000); /* default is fileserver */
205 if ((port = PortNumber(portName)) == -1)
206 port = PortName(portName);
208 printf("rxdebug: can't resolve port name %s\n", portName);
215 hostAddr.s_addr = host;
216 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
217 printf("Trying %s (port %d):\n", hoststr, ntohs(port));
218 s = socket(AF_INET, SOCK_DGRAM, 0);
219 taddr.sin_family = AF_INET;
221 taddr.sin_addr.s_addr = 0;
222 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
223 taddr.sin_len = sizeof(struct sockaddr_in);
225 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
233 code = rx_GetServerVersion(s, host, port, length, version);
235 printf("get version call failed with code %d, errno %d\n", code,
239 printf("AFS version: %s\n", version);
247 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
249 printf("getstats call failed with code %d\n", code);
253 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
254 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
255 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
256 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
257 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
258 withWaited = (supportedDebugValues & RX_SERVER_DEBUG_WAITED_CNT);
259 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
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_stats 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 if ((((struct rx_debugIn *)(&rxstats))->type ==
296 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
298 /* handle other versions?... */
301 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
302 tstats.nFreePackets, tstats.version);
310 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
314 printf("Showing only server connections\n");
316 printf("Showing only client connections\n");
317 if (onlyAuth != 999) {
318 static char *name[] =
319 { "unauthenticated", "rxkad_clear", "rxkad_auth",
322 printf("Showing only %s connections\n", name[onlyAuth + 1]);
324 if (onlyHost != -1) {
325 hostAddr.s_addr = onlyHost;
326 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
327 printf("Showing only connections from host %s\n",
331 printf("Showing only connections on port %u\n", ntohs(onlyPort));
335 rx_GetServerConnections(s, host, port, &nextconn, allconns,
336 supportedDebugValues, &tconn,
337 &supportedConnValues);
339 printf("getconn call failed with code %d\n", code);
342 if (tconn.cid == (afs_int32) 0xffffffff) {
347 /* see if we're in nodally mode and all calls are dallying */
350 for (j = 0; j < RX_MAXCALLS; j++) {
351 if (tconn.callState[j] != RX_STATE_NOTINIT
352 && tconn.callState[j] != RX_STATE_DALLY) {
358 /* this call looks too ordinary, bump skipped count and go
364 if ((onlyHost != -1) && (onlyHost != tconn.host))
366 if ((onlyPort != -1) && (onlyPort != tconn.port))
368 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
370 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
372 if (onlyAuth != 999) {
373 if (onlyAuth == -1) {
374 if (tconn.securityIndex != 0)
377 if (tconn.securityIndex != 2)
379 if (withSecStats && (tconn.secStats.type == 3)
380 && (tconn.secStats.level != onlyAuth))
385 /* now display the connection */
386 hostAddr.s_addr = tconn.host;
387 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
388 printf("Connection from host %s, port %hu, ", hoststr,
391 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
393 printf("cid %x", tconn.cid);
395 printf(", error %d", tconn.error);
396 printf("\n serial %d, ", tconn.serial);
397 printf(" natMTU %d, ", tconn.natMTU);
401 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
402 printf(" MAKECALL_WAITING");
403 if (tconn.flags & RX_CONN_DESTROY_ME)
404 printf(" DESTROYED");
405 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
409 printf("security index %d, ", tconn.securityIndex);
410 if (tconn.type == RX_CLIENT_CONNECTION)
411 printf("client conn\n");
413 printf("server conn\n");
416 switch ((int)tconn.secStats.type) {
418 if (tconn.securityIndex == 2)
420 (" no GetStats procedure for security object\n");
423 printf(" rxnull level=%d, flags=%d\n",
424 tconn.secStats.level, tconn.secStats.flags);
427 printf(" rxvab level=%d, flags=%d\n",
428 tconn.secStats.level, tconn.secStats.flags);
432 char flags = tconn.secStats.flags;
433 if (tconn.secStats.level == 0)
435 else if (tconn.secStats.level == 1)
437 else if (tconn.secStats.level == 2)
441 printf(" rxkad: level %s", level);
447 printf(" authenticated");
452 if (tconn.secStats.expires)
453 /* Apparently due to a bug in the RT compiler that
454 * prevents (afs_uint32)0xffffffff => (double) from working,
455 * this code produces negative lifetimes when run on the
457 printf(", expires in %.1f hours",
458 ((afs_uint32) tconn.secStats.expires -
461 printf("\n Received %u bytes in %u packets\n",
462 tconn.secStats.bytesReceived,
463 tconn.secStats.packetsReceived);
464 printf(" Sent %u bytes in %u packets\n",
465 tconn.secStats.bytesSent,
466 tconn.secStats.packetsSent);
473 printf(" unknown\n");
477 for (j = 0; j < RX_MAXCALLS; j++) {
478 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
479 if (tconn.callState[j] == RX_STATE_NOTINIT) {
480 printf("not initialized\n");
482 } else if (tconn.callState[j] == RX_STATE_PRECALL)
484 else if (tconn.callState[j] == RX_STATE_ACTIVE)
486 else if (tconn.callState[j] == RX_STATE_DALLY)
488 else if (tconn.callState[j] == RX_STATE_HOLD)
491 if (tconn.callMode[j] == RX_MODE_SENDING)
493 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
495 else if (tconn.callMode[j] == RX_MODE_ERROR)
497 else if (tconn.callMode[j] == RX_MODE_EOF)
501 if (tconn.callFlags[j]) {
503 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
504 printf(" reader_wait");
505 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
506 printf(" window_alloc");
507 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
508 printf(" window_send");
509 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
510 printf(" wait_packets");
511 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
512 printf(" waiting_for_process");
513 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
514 printf(" receive_done");
515 if (tconn.callFlags[j] & RX_CALL_CLEARED)
516 printf(" call_cleared");
518 if (tconn.callOther[j] & RX_OTHER_IN)
519 printf(", has_input_packets");
520 if (tconn.callOther[j] & RX_OTHER_OUT)
521 printf(", has_output_packets");
526 printf("Skipped %d dallying connections.\n", dallyCounter);
528 if (showPeers && withPeers) {
530 struct rx_debugPeer tpeer;
532 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
533 &supportedPeerValues);
535 printf("getpeer call failed with code %d\n", code);
538 if (tpeer.host == 0xffffffff) {
543 if ((onlyHost != -1) && (onlyHost != tpeer.host))
545 if ((onlyPort != -1) && (onlyPort != tpeer.port))
548 /* now display the peer */
549 hostAddr.s_addr = tpeer.host;
550 afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
551 printf("Peer at host %s, port %hu\n", hoststr,
553 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
554 tpeer.natMTU, tpeer.maxMTU);
555 printf("\tpackets sent %u\tpacket resends %u\n", tpeer.nSent,
557 printf("\tbytes sent high %u low %u\n", tpeer.bytesSent.high,
558 tpeer.bytesSent.low);
559 printf("\tbytes received high %u low %u\n",
560 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
561 printf("\trtt %u msec, rtt_dev %u msec\n", tpeer.rtt >> 3,
563 printf("\ttimeout %u.%03u sec\n", tpeer.timeout.sec,
564 tpeer.timeout.usec / 1000);
568 printf("\tin/out packet skew: %d/%d\n", tpeer.inPacketSkew,
569 tpeer.outPacketSkew);
570 printf("\tcongestion window %d, MTU %d\n", tpeer.cwind,
572 printf("\tcurrent/if/max jumbogram size: %d/%d/%d\n",
573 tpeer.nDgramPackets, tpeer.ifDgramPackets,
574 tpeer.maxDgramPackets);
580 /* simple main program */
582 #include "AFS_component_version_number.c"
589 struct cmd_syndesc *ts;
595 if (afs_winsockInit() < 0) {
596 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
601 ts = cmd_CreateSyntax(NULL, MainCommand, 0, "probe RX server");
602 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
603 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
604 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
605 "don't show dallying conns");
606 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
607 "don't filter out uninteresting connections on server");
608 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
609 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
610 "only show server conns");
611 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
612 "only show client conns");
613 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
615 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
617 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
618 "show only <auth level>");
620 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
621 "show AFS version id");
622 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
623 "show no connections");
624 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
625 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "detailed output");
627 cmd_Dispatch(argc, argv);