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"
56 extern struct hostent *hostutil_GetHostByName();
66 while (tc = *aport++) {
67 if (tc < '0' || tc > '9')
68 return -1; /* bad port number */
70 total += tc - (int)'0';
79 register struct servent *ts;
80 ts = getservbyname(aname, NULL);
83 return ts->s_port; /* returns it in network byte order */
87 MainCommand(as, arock)
89 struct cmd_syndesc *as;
94 struct sockaddr_in taddr;
96 struct in_addr hostAddr;
99 register afs_int32 code;
103 int onlyClient, onlyServer;
115 struct rx_debugStats tstats;
116 char *portName, *hostName;
117 struct rx_debugConn tconn;
123 afs_int32 length = 64;
125 afs_uint32 supportedDebugValues = 0;
126 afs_uint32 supportedStatValues = 0;
127 afs_uint32 supportedConnValues = 0;
128 afs_uint32 supportedPeerValues = 0;
129 afs_int32 nextconn = 0;
130 afs_int32 nextpeer = 0;
132 nodally = (as->parms[2].items ? 1 : 0);
133 allconns = (as->parms[3].items ? 1 : 0);
134 rxstats = (as->parms[4].items ? 1 : 0);
135 onlyServer = (as->parms[5].items ? 1 : 0);
136 onlyClient = (as->parms[6].items ? 1 : 0);
137 version_flag = (as->parms[10].items ? 1 : 0);
138 noConns = (as->parms[11].items ? 1 : 0);
139 showPeers = (as->parms[12].items ? 1 : 0);
140 showLong = (as->parms[13].items ? 1 : 0);
142 if (as->parms[0].items)
143 hostName = as->parms[0].items->data;
147 if (as->parms[1].items)
148 portName = as->parms[1].items->data;
152 if (as->parms[7].items) {
153 char *name = as->parms[7].items->data;
154 if ((onlyPort = PortNumber(name)) == -1)
155 onlyPort = PortName(name);
156 if (onlyPort == -1) {
157 printf("rxdebug: can't resolve port name %s\n", name);
163 if (as->parms[8].items) {
164 char *name = as->parms[8].items->data;
166 th = hostutil_GetHostByName(name);
168 printf("rxdebug: host %s not found in host table\n", name);
171 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
175 if (as->parms[9].items) {
176 char *name = as->parms[9].items->data;
177 if (strcmp(name, "clear") == 0)
179 else if (strcmp(name, "auth") == 0)
181 else if (strcmp(name, "crypt") == 0)
183 else if ((strcmp(name, "null") == 0) || (strcmp(name, "none") == 0)
184 || (strncmp(name, "noauth", 6) == 0)
185 || (strncmp(name, "unauth", 6) == 0))
188 fprintf(stderr, "Unknown authentication level: %s\n", name);
196 th = hostutil_GetHostByName(hostName);
198 printf("rxdebug: host %s not found in host table\n", hostName);
201 memcpy(&host, th->h_addr, sizeof(afs_int32));
203 host = htonl(0x7f000001); /* IP localhost */
206 port = htons(7000); /* default is fileserver */
208 if ((port = PortNumber(portName)) == -1)
209 port = PortName(portName);
211 printf("rxdebug: can't resolve port name %s\n", portName);
218 hostAddr.s_addr = host;
219 printf("Trying %s (port %d):\n", inet_ntoa(hostAddr), ntohs(port));
220 s = socket(AF_INET, SOCK_DGRAM, 0);
221 taddr.sin_family = AF_INET;
223 taddr.sin_addr.s_addr = 0;
224 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
225 taddr.sin_len = sizeof(struct sockaddr_in);
227 code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
235 code = rx_GetServerVersion(s, host, port, length, version);
237 printf("get version call failed with code %d, errno %d\n", code,
241 printf("AFS version: %s\n", version);
249 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
251 printf("getstats call failed with code %d\n", code);
255 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
256 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
257 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
258 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
259 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
260 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
262 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
263 tstats.nFreePackets, tstats.packetReclaims, tstats.callsExecuted,
265 if (!tstats.waitingForPackets)
267 printf("waiting for packets.\n");
269 printf("%d calls waiting for a thread\n", tstats.nWaiting);
271 printf("%d threads are idle\n", tstats.idleThreads);
278 "WARNING: Server doesn't support retrieval of Rx statistics\n");
280 struct rx_stats rxstats;
282 /* should gracefully handle the case where rx_stats grows */
284 rx_GetServerStats(s, host, port, &rxstats,
285 &supportedStatValues);
287 printf("rxstats call failed with code %d\n", code);
290 if (code != sizeof(rxstats)) {
291 if ((((struct rx_debugIn *)(&rxstats))->type ==
295 ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
297 /* handle other versions?... */
300 rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats),
301 tstats.nFreePackets, tstats.version);
309 "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
313 printf("Showing only server connections\n");
315 printf("Showing only client connections\n");
316 if (onlyAuth != 999) {
317 static char *name[] =
318 { "unauthenticated", "rxkad_clear", "rxkad_auth",
321 printf("Showing only %s connections\n", name[onlyAuth + 1]);
323 if (onlyHost != -1) {
324 hostAddr.s_addr = onlyHost;
325 printf("Showing only connections from host %s\n",
326 inet_ntoa(hostAddr));
329 printf("Showing only connections on port %u\n", ntohs(onlyPort));
333 rx_GetServerConnections(s, host, port, &nextconn, allconns,
334 supportedDebugValues, &tconn,
335 &supportedConnValues);
337 printf("getconn call failed with code %d\n", code);
340 if (tconn.cid == 0xffffffff) {
345 /* see if we're in nodally mode and all calls are dallying */
348 for (j = 0; j < RX_MAXCALLS; j++) {
349 if (tconn.callState[j] != RX_STATE_NOTINIT
350 && tconn.callState[j] != RX_STATE_DALLY) {
356 /* this call looks too ordinary, bump skipped count and go
362 if ((onlyHost != -1) && (onlyHost != tconn.host))
364 if ((onlyPort != -1) && (onlyPort != tconn.port))
366 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION))
368 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION))
370 if (onlyAuth != 999) {
371 if (onlyAuth == -1) {
372 if (tconn.securityIndex != 0)
375 if (tconn.securityIndex != 2)
377 if (withSecStats && (tconn.secStats.type == 3)
378 && (tconn.secStats.level != onlyAuth))
383 /* now display the connection */
384 hostAddr.s_addr = tconn.host;
385 printf("Connection from host %s, port %hu, ", inet_ntoa(hostAddr),
388 printf("Cuid %x/%x", tconn.epoch, tconn.cid);
390 printf("cid %x", tconn.cid);
392 printf(", error %d", tconn.error);
393 printf("\n serial %d, ", tconn.serial);
394 printf(" natMTU %d, ", tconn.natMTU);
398 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
399 printf(" MAKECALL_WAITING");
400 if (tconn.flags & RX_CONN_DESTROY_ME)
401 printf(" DESTROYED");
402 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM)
406 printf("security index %d, ", tconn.securityIndex);
407 if (tconn.type == RX_CLIENT_CONNECTION)
408 printf("client conn\n");
410 printf("server conn\n");
413 switch ((int)tconn.secStats.type) {
415 if (tconn.securityIndex == 2)
417 (" no GetStats procedure for security object\n");
420 printf(" rxnull level=%d, flags=%d\n",
421 tconn.secStats.level, tconn.secStats.flags);
424 printf(" rxvab level=%d, flags=%d\n",
425 tconn.secStats.level, tconn.secStats.flags);
429 char flags = tconn.secStats.flags;
430 if (tconn.secStats.level == 0)
432 else if (tconn.secStats.level == 1)
434 else if (tconn.secStats.level == 2)
438 printf(" rxkad: level %s", level);
444 printf(" authenticated");
449 if (tconn.secStats.expires)
450 /* Apparently due to a bug in the RT compiler that
451 * prevents (afs_uint32)0xffffffff => (double) from working,
452 * this code produces negative lifetimes when run on the
454 printf(", expires in %.1f hours",
455 ((afs_uint32) tconn.secStats.expires -
458 printf("\n Received %d bytes in %d packets\n",
459 tconn.secStats.bytesReceived,
460 tconn.secStats.packetsReceived);
461 printf(" Sent %d bytes in %d packets\n",
462 tconn.secStats.bytesSent,
463 tconn.secStats.packetsSent);
470 printf(" unknown\n");
474 for (j = 0; j < RX_MAXCALLS; j++) {
475 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
476 if (tconn.callState[j] == RX_STATE_NOTINIT) {
477 printf("not initialized\n");
479 } else if (tconn.callState[j] == RX_STATE_PRECALL)
481 else if (tconn.callState[j] == RX_STATE_ACTIVE)
483 else if (tconn.callState[j] == RX_STATE_DALLY)
485 else if (tconn.callState[j] == RX_STATE_HOLD)
488 if (tconn.callMode[j] == RX_MODE_SENDING)
490 else if (tconn.callMode[j] == RX_MODE_RECEIVING)
492 else if (tconn.callMode[j] == RX_MODE_ERROR)
494 else if (tconn.callMode[j] == RX_MODE_EOF)
498 if (tconn.callFlags[j]) {
500 if (tconn.callFlags[j] & RX_CALL_READER_WAIT)
501 printf(" reader_wait");
502 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_ALLOC)
503 printf(" window_alloc");
504 if (tconn.callFlags[j] & RX_CALL_WAIT_WINDOW_SEND)
505 printf(" window_send");
506 if (tconn.callFlags[j] & RX_CALL_WAIT_PACKETS)
507 printf(" wait_packets");
508 if (tconn.callFlags[j] & RX_CALL_WAIT_PROC)
509 printf(" waiting_for_process");
510 if (tconn.callFlags[j] & RX_CALL_RECEIVE_DONE)
511 printf(" receive_done");
512 if (tconn.callFlags[j] & RX_CALL_CLEARED)
513 printf(" call_cleared");
515 if (tconn.callOther[j] & RX_OTHER_IN)
516 printf(", has_input_packets");
517 if (tconn.callOther[j] & RX_OTHER_OUT)
518 printf(", has_output_packets");
523 printf("Skipped %d dallying connections.\n", dallyCounter);
525 if (showPeers && withPeers) {
527 struct rx_debugPeer tpeer;
529 rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer,
530 &supportedPeerValues);
532 printf("getpeer call failed with code %d\n", code);
535 if (tpeer.host == 0xffffffff) {
540 if ((onlyHost != -1) && (onlyHost != tpeer.host))
542 if ((onlyPort != -1) && (onlyPort != tpeer.port))
545 /* now display the peer */
546 hostAddr.s_addr = tpeer.host;
547 printf("Peer at host %s, port %hu\n", inet_ntoa(hostAddr),
549 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
550 tpeer.natMTU, tpeer.maxMTU);
551 printf("\tpackets sent %d\tpacket resends %d\n", tpeer.nSent,
553 printf("\tbytes sent high %d low %d\n", tpeer.bytesSent.high,
554 tpeer.bytesSent.low);
555 printf("\tbytes received high %d low %d\n",
556 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
557 printf("\trtt %d msec, rtt_dev %d msec\n", tpeer.rtt >> 3,
559 printf("\ttimeout %d.%03d sec\n", tpeer.timeout.sec,
560 tpeer.timeout.usec / 1000);
564 printf("\tin/out packet skew: %d/%d\n", tpeer.inPacketSkew,
565 tpeer.outPacketSkew);
566 printf("\tcongestion window %d, MTU %d\n", tpeer.cwind,
568 printf("\tcurrent/if/max jumbogram size: %d/%d/%d\n",
569 tpeer.nDgramPackets, tpeer.ifDgramPackets,
570 tpeer.maxDgramPackets);
576 /* simple main program */
578 #include "AFS_component_version_number.c"
585 struct cmd_syndesc *ts;
588 if (afs_winsockInit() < 0) {
589 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
594 ts = cmd_CreateSyntax(NULL, MainCommand, 0, "probe RX server");
595 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
596 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
597 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
598 "don't show dallying conns");
599 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
600 "don't filter out uninteresting connections on server");
601 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
602 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
603 "only show server conns");
604 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
605 "only show client conns");
606 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL,
608 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL,
610 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
611 "show only <auth level>");
613 cmd_AddParm(ts, "-version", CMD_FLAG, CMD_OPTIONAL,
614 "show AFS version id");
615 cmd_AddParm(ts, "-noconns", CMD_FLAG, CMD_OPTIONAL,
616 "show no connections");
617 cmd_AddParm(ts, "-peers", CMD_FLAG, CMD_OPTIONAL, "show peers");
618 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "detailed output");
620 cmd_Dispatch(argc, argv);