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>
25 #ifdef HAVE_NETINET_IN_H
26 #include <netinet/in.h>
28 #ifdef HAVE_SYS_TIME_H
51 #include "rx_globals.h"
64 while (tc = *aport++) {
65 if (tc < '0' || tc > '9')
66 return -1; /* bad port number */
68 total += tc - (int)'0';
77 register struct servent *ts;
78 ts = getservbyname(aname, NULL);
81 return ts->s_port; /* returns it in network byte order */
85 MainCommand(as, arock)
87 struct cmd_syndesc *as;
92 struct sockaddr_in taddr;
94 struct in_addr hostAddr;
97 register afs_int32 code;
101 int onlyClient, onlyServer;
113 struct rx_debugStats tstats;
114 char *portName, *hostName;
115 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);
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 printf("Trying %s (port %d):\n", inet_ntoa(hostAddr), ntohs(port));
216 s = socket(AF_INET, SOCK_DGRAM, 0);
217 taddr.sin_family = AF_INET;
219 taddr.sin_addr.s_addr = 0;
220 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
221 taddr.sin_len = sizeof(struct sockaddr_in);
223 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
231 code = rx_GetServerVersion(s, host, port, length, version);
233 printf("get version call failed with code %d, errno %d\n", code,
237 printf("AFS version: %s\n", version);
245 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
247 printf("getstats call failed with code %d\n", code);
251 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
252 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
253 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
254 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
255 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
256 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
258 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
259 tstats.nFreePackets, tstats.packetReclaims, tstats.callsExecuted,
261 if (!tstats.waitingForPackets)
263 printf("waiting for packets.\n");
265 printf("%d calls waiting for a thread\n", tstats.nWaiting);
267 printf("%d threads are idle\n", tstats.idleThreads);
274 "WARNING: Server doesn't support retrieval of Rx statistics\n");
276 struct rx_stats rxstats;
278 /* should gracefully handle the case where rx_stats grows */
280 rx_GetServerStats(s, host, port, &rxstats,
281 &supportedStatValues);
283 printf("rxstats call failed with code %d\n", code);
286 if (code != sizeof(rxstats)) {
287 if ((((struct rx_debugIn *)(&rxstats))->type ==
291 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
293 /* handle other versions?... */
296 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
297 tstats.nFreePackets, tstats.version);
305 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
309 printf("Showing only server connections\n");
311 printf("Showing only client connections\n");
312 if (onlyAuth != 999) {
313 static char *name[] =
314 { "unauthenticated", "rxkad_clear", "rxkad_auth",
317 printf("Showing only %s connections\n", name[onlyAuth + 1]);
319 if (onlyHost != -1) {
320 hostAddr.s_addr = onlyHost;
321 printf("Showing only connections from host %s\n",
322 inet_ntoa(hostAddr));
325 printf("Showing only connections on port %u\n", ntohs(onlyPort));
329 rx_GetServerConnections(s, host, port, &nextconn, allconns,
330 supportedDebugValues, &tconn,
331 &supportedConnValues);
333 printf("getconn call failed with code %d\n", code);
336 if (tconn.cid == (afs_int32) 0xffffffff) {
341 /* see if we're in nodally mode and all calls are dallying */
344 for (j = 0; j < RX_MAXCALLS; j++) {
345 if (tconn.callState[j] != RX_STATE_NOTINIT
346 && tconn.callState[j] != RX_STATE_DALLY) {
352 /* this call looks too ordinary, bump skipped count and go
358 if ((onlyHost != -1) && (onlyHost != tconn.host))
360 if ((onlyPort != -1) && (onlyPort != tconn.port))
362 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
364 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
366 if (onlyAuth != 999) {
367 if (onlyAuth == -1) {
368 if (tconn.securityIndex != 0)
371 if (tconn.securityIndex != 2)
373 if (withSecStats && (tconn.secStats.type == 3)
374 && (tconn.secStats.level != onlyAuth))
379 /* now display the connection */
380 hostAddr.s_addr = tconn.host;
381 printf("Connection from host %s, port %hu, ", inet_ntoa(hostAddr),
384 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
386 printf("cid %x", tconn.cid);
388 printf(", error %d", tconn.error);
389 printf("\n serial %d, ", tconn.serial);
390 printf(" natMTU %d, ", tconn.natMTU);
394 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
395 printf(" MAKECALL_WAITING");
396 if (tconn.flags & RX_CONN_DESTROY_ME)
397 printf(" DESTROYED");
398 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
402 printf("security index %d, ", tconn.securityIndex);
403 if (tconn.type == RX_CLIENT_CONNECTION)
404 printf("client conn\n");
406 printf("server conn\n");
409 switch ((int)tconn.secStats.type) {
411 if (tconn.securityIndex == 2)
413 (" no GetStats procedure for security object\n");
416 printf(" rxnull level=%d, flags=%d\n",
417 tconn.secStats.level, tconn.secStats.flags);
420 printf(" rxvab level=%d, flags=%d\n",
421 tconn.secStats.level, tconn.secStats.flags);
425 char flags = tconn.secStats.flags;
426 if (tconn.secStats.level == 0)
428 else if (tconn.secStats.level == 1)
430 else if (tconn.secStats.level == 2)
434 printf(" rxkad: level %s", level);
440 printf(" authenticated");
445 if (tconn.secStats.expires)
446 /* Apparently due to a bug in the RT compiler that
447 * prevents (afs_uint32)0xffffffff => (double) from working,
448 * this code produces negative lifetimes when run on the
450 printf(", expires in %.1f hours",
451 ((afs_uint32) tconn.secStats.expires -
454 printf("\n Received %d bytes in %d packets\n",
455 tconn.secStats.bytesReceived,
456 tconn.secStats.packetsReceived);
457 printf(" Sent %d bytes in %d packets\n",
458 tconn.secStats.bytesSent,
459 tconn.secStats.packetsSent);
466 printf(" unknown\n");
470 for (j = 0; j < RX_MAXCALLS; j++) {
471 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
472 if (tconn.callState[j] == RX_STATE_NOTINIT) {
473 printf("not initialized\n");
475 } else if (tconn.callState[j] == RX_STATE_PRECALL)
477 else if (tconn.callState[j] == RX_STATE_ACTIVE)
479 else if (tconn.callState[j] == RX_STATE_DALLY)
481 else if (tconn.callState[j] == RX_STATE_HOLD)
484 if (tconn.callMode[j] == RX_MODE_SENDING)
486 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
488 else if (tconn.callMode[j] == RX_MODE_ERROR)
490 else if (tconn.callMode[j] == RX_MODE_EOF)
494 if (tconn.callFlags[j]) {
496 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
497 printf(" reader_wait");
498 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
499 printf(" window_alloc");
500 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
501 printf(" window_send");
502 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
503 printf(" wait_packets");
504 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
505 printf(" waiting_for_process");
506 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
507 printf(" receive_done");
508 if (tconn.callFlags[j] & RX_CALL_CLEARED)
509 printf(" call_cleared");
511 if (tconn.callOther[j] & RX_OTHER_IN)
512 printf(", has_input_packets");
513 if (tconn.callOther[j] & RX_OTHER_OUT)
514 printf(", has_output_packets");
519 printf("Skipped %d dallying connections.\n", dallyCounter);
521 if (showPeers && withPeers) {
523 struct rx_debugPeer tpeer;
525 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
526 &supportedPeerValues);
528 printf("getpeer call failed with code %d\n", code);
531 if (tpeer.host == 0xffffffff) {
536 if ((onlyHost != -1) && (onlyHost != tpeer.host))
538 if ((onlyPort != -1) && (onlyPort != tpeer.port))
541 /* now display the peer */
542 hostAddr.s_addr = tpeer.host;
543 printf("Peer at host %s, port %hu\n", inet_ntoa(hostAddr),
545 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
546 tpeer.natMTU, tpeer.maxMTU);
547 printf("\tpackets sent %d\tpacket resends %d\n", tpeer.nSent,
549 printf("\tbytes sent high %d low %d\n", tpeer.bytesSent.high,
550 tpeer.bytesSent.low);
551 printf("\tbytes received high %d low %d\n",
552 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
553 printf("\trtt %d msec, rtt_dev %d msec\n", tpeer.rtt >> 3,
555 printf("\ttimeout %d.%03d sec\n", tpeer.timeout.sec,
556 tpeer.timeout.usec / 1000);
562 /* simple main program */
564 #include "AFS_component_version_number.c"
571 struct cmd_syndesc *ts;
574 if (afs_winsockInit() < 0) {
575 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
580 ts = cmd_CreateSyntax(NULL, MainCommand, 0, "probe RX server");
581 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
582 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
583 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
584 "don't show dallying conns");
585 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
586 "don't filter out uninteresting connections on server");
587 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
588 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
589 "only show server conns");
590 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
591 "only show client conns");
592 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
594 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
596 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
597 "show only <auth level>");
599 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
600 "show AFS version id");
601 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
602 "show no connections");
603 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
605 cmd_Dispatch(argc, argv);