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>
15 #include <sys/types.h>
20 #include <sys/socket.h>
24 #ifdef HAVE_NETINET_IN_H
25 #include <netinet/in.h>
27 #ifdef HAVE_SYS_TIME_H
50 #include "rx_globals.h"
55 extern struct hostent *hostutil_GetHostByName();
57 static short PortNumber(aport)
64 while (tc = *aport++) {
65 if (tc < '0' || tc > '9') return -1; /* bad port number */
67 total += tc - (int) '0';
72 static short PortName(aname)
75 register struct servent *ts;
76 ts = getservbyname(aname, (char *) 0);
78 return ts->s_port; /* returns it in network byte order */
81 int MainCommand(as, arock)
83 struct cmd_syndesc *as;
88 struct sockaddr_in taddr;
90 struct in_addr hostAddr;
93 register afs_int32 code;
97 int onlyClient, onlyServer;
109 struct rx_debugStats tstats;
110 char *portName, *hostName;
111 struct rx_debugConn tconn;
118 afs_uint32 supportedDebugValues = 0;
119 afs_uint32 supportedStatValues = 0;
120 afs_uint32 supportedConnValues = 0;
121 afs_uint32 supportedPeerValues = 0;
122 afs_int32 nextconn = 0;
123 afs_int32 nextpeer = 0;
125 nodally = (as->parms[2].items ? 1 : 0);
126 allconns = (as->parms[3].items ? 1 : 0);
127 rxstats = (as->parms[4].items ? 1 : 0);
128 onlyServer = (as->parms[5].items ? 1 : 0);
129 onlyClient = (as->parms[6].items ? 1 : 0);
130 version_flag=(as->parms[10].items ? 1 : 0);
131 noConns = (as->parms[11].items ? 1 : 0);
132 showPeers = (as->parms[12].items ? 1 : 0);
134 if (as->parms[0].items)
135 hostName = as->parms[0].items->data;
137 hostName = (char *) 0;
139 if (as->parms[1].items)
140 portName = as->parms[1].items->data;
142 portName = (char *) 0;
144 if (as->parms[7].items) {
145 char *name = as->parms[7].items->data;
146 if ((onlyPort = PortNumber(name)) == -1)
147 onlyPort = PortName(name);
148 if (onlyPort == -1) {
149 printf("rxdebug: can't resolve port name %s\n", name);
152 } else onlyPort = -1;
154 if (as->parms[8].items) {
155 char *name = as->parms[8].items->data;
157 th = hostutil_GetHostByName(name);
159 printf("rxdebug: host %s not found in host table\n", name);
162 memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));
163 } else onlyHost = -1;
165 if (as->parms[9].items) {
166 char *name = as->parms[9].items->data;
167 if (strcmp (name, "clear") == 0) onlyAuth = 0;
168 else if (strcmp (name, "auth") == 0) onlyAuth = 1;
169 else if (strcmp (name, "crypt") == 0) onlyAuth = 2;
170 else if ((strcmp (name, "null") == 0) ||
171 (strcmp (name, "none") == 0) ||
172 (strncmp (name, "noauth", 6) == 0) ||
173 (strncmp (name, "unauth", 6) == 0)) onlyAuth = -1;
175 fprintf (stderr, "Unknown authentication level: %s\n", name);
178 } else onlyAuth = 999;
182 th = hostutil_GetHostByName(hostName);
184 printf("rxdebug: host %s not found in host table\n", hostName);
187 memcpy(&host, th->h_addr, sizeof(afs_int32));
189 else host = htonl(0x7f000001); /* IP localhost */
192 port = htons(7000); /* default is fileserver */
194 if ((port = PortNumber(portName)) == -1)
195 port = PortName(portName);
197 printf("rxdebug: can't resolve port name %s\n", portName);
204 hostAddr.s_addr = host;
205 printf("Trying %s (port %d):\n", inet_ntoa(hostAddr), ntohs(port));
206 s = socket(AF_INET, SOCK_DGRAM, 0);
207 taddr.sin_family = AF_INET;
209 taddr.sin_addr.s_addr = 0;
210 code = bind(s, (struct sockaddr *) &taddr, sizeof(struct sockaddr_in));
219 code = rx_GetServerVersion(s, host, port, length, version);
222 printf("get version call failed with code %d, errno %d\n",
226 printf("AFS version: %s\n",version);fflush(stdout);
233 code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);
235 printf("getstats call failed with code %d\n", code);
239 withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
240 withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
241 withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
242 withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
243 withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
244 withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);
246 printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
247 tstats.nFreePackets, tstats.packetReclaims,
248 tstats.callsExecuted, tstats.usedFDs);
249 if (!tstats.waitingForPackets) printf("not ");
250 printf("waiting for packets.\n");
252 printf("%d calls waiting for a thread\n",tstats.nWaiting);
253 if ( withIdleThreads )
254 printf("%d threads are idle\n", tstats.idleThreads);
260 fprintf (stderr, "WARNING: Server doesn't support retrieval of Rx statistics\n");
263 struct rx_stats rxstats;
265 /* should gracefully handle the case where rx_stats grows */
266 code = rx_GetServerStats(s, host, port, &rxstats, &supportedStatValues);
268 printf("rxstats call failed with code %d\n", code);
271 if (code != sizeof(rxstats)) {
272 if ((((struct rx_debugIn *)(&rxstats))->type ==
273 RX_DEBUGI_BADTYPE)) goto noRxStats;
274 printf ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
276 /* handle other versions?... */
279 rx_PrintTheseStats (stdout, &rxstats, sizeof(rxstats),
280 tstats.nFreePackets, tstats.version);
286 if (!withAllConn) fprintf (stderr, "WARNING: Server doesn't support retrieval of all connections,\n getting only interesting instead.\n");
289 if (onlyServer) printf ("Showing only server connections\n");
290 if (onlyClient) printf ("Showing only client connections\n");
291 if (onlyAuth != 999) {
292 static char *name[] =
293 {"unauthenticated", "rxkad_clear", "rxkad_auth", "rxkad_crypt"};
294 printf ("Showing only %s connections\n", name[onlyAuth+1]);
296 if (onlyHost != -1) {
297 hostAddr.s_addr = onlyHost;
298 printf ("Showing only connections from host %s\n",
299 inet_ntoa(hostAddr));
302 printf ("Showing only connections on port %u\n", ntohs(onlyPort));
305 code = rx_GetServerConnections(s, host, port, &nextconn, allconns,
306 supportedDebugValues, &tconn,
307 &supportedConnValues);
309 printf("getconn call failed with code %d\n", code);
312 if (tconn.cid == 0xffffffff) {
317 /* see if we're in nodally mode and all calls are dallying */
320 for(j=0;j<RX_MAXCALLS;j++) {
321 if (tconn.callState[j] != RX_STATE_NOTINIT &&
322 tconn.callState[j] != RX_STATE_DALLY) {
328 /* this call looks too ordinary, bump skipped count and go
334 if ((onlyHost != -1) && (onlyHost != tconn.host)) continue;
335 if ((onlyPort != -1) && (onlyPort != tconn.port)) continue;
336 if (onlyServer && (tconn.type != RX_SERVER_CONNECTION)) continue;
337 if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION)) continue;
338 if (onlyAuth != 999) {
339 if (onlyAuth == -1) {
340 if (tconn.securityIndex != 0) continue;
342 if (tconn.securityIndex != 2) continue;
343 if (withSecStats && (tconn.secStats.type == 3) &&
344 (tconn.secStats.level != onlyAuth)) continue;
348 /* now display the connection */
349 hostAddr.s_addr = tconn.host;
350 printf("Connection from host %s, port %hu, ",
351 inet_ntoa(hostAddr), ntohs(tconn.port));
353 printf ("Cuid %x/%x", tconn.epoch, tconn.cid);
354 else printf ("cid %x", tconn.cid);
355 if (tconn.error) printf (", error %d", tconn.error);
356 printf("\n serial %d, ", tconn.serial);
357 printf(" natMTU %d, ", tconn.natMTU);
361 if (tconn.flags & RX_CONN_MAKECALL_WAITING)
362 printf(" MAKECALL_WAITING");
363 if (tconn.flags & RX_CONN_DESTROY_ME) printf(" DESTROYED");
364 if (tconn.flags & RX_CONN_USING_PACKET_CKSUM) printf(" pktCksum");
367 printf("security index %d, ", tconn.securityIndex);
368 if (tconn.type == RX_CLIENT_CONNECTION) printf("client conn\n");
369 else printf("server conn\n");
372 switch ((int)tconn.secStats.type) {
374 if (tconn.securityIndex == 2)
375 printf (" no GetStats procedure for security object\n");
378 printf (" rxnull level=%d, flags=%d\n",
379 tconn.secStats.level, tconn.secStats.flags);
382 printf (" rxvab level=%d, flags=%d\n",
383 tconn.secStats.level, tconn.secStats.flags);
387 char flags = tconn.secStats.flags;
388 if (tconn.secStats.level == 0) level = "clear";
389 else if (tconn.secStats.level == 1) level = "auth";
390 else if (tconn.secStats.level == 2) level = "crypt";
391 else level = "unknown";
392 printf (" rxkad: level %s", level);
393 if (flags) printf (", flags");
394 if (flags & 1) printf (" unalloc");
395 if (flags & 2) printf (" authenticated");
396 if (flags & 4) printf (" expired");
397 if (flags & 8) printf (" pktCksum");
398 if (tconn.secStats.expires)
399 /* Apparently due to a bug in the RT compiler that
400 * prevents (afs_uint32)0xffffffff => (double) from working,
401 * this code produces negative lifetimes when run on the
403 printf (", expires in %.1f hours",
404 ((afs_uint32)tconn.secStats.expires -
407 printf ("\n Received %d bytes in %d packets\n",
408 tconn.secStats.bytesReceived,
409 tconn.secStats.packetsReceived);
410 printf (" Sent %d bytes in %d packets\n",
411 tconn.secStats.bytesSent,
412 tconn.secStats.packetsSent);
413 } else printf ("\n");
417 default: printf(" unknown\n");
421 for(j=0;j<RX_MAXCALLS;j++) {
422 printf(" call %d: # %d, state ", j, tconn.callNumber[j]);
423 if (tconn.callState[j]==RX_STATE_NOTINIT) {
424 printf("not initialized\n");
427 else if (tconn.callState[j]==RX_STATE_PRECALL)
429 else if (tconn.callState[j] == RX_STATE_ACTIVE)
431 else if (tconn.callState[j] == RX_STATE_DALLY)
433 else if (tconn.callState[j] == RX_STATE_HOLD)
436 if (tconn.callMode[j]==RX_MODE_SENDING)
438 else if (tconn.callMode[j]==RX_MODE_RECEIVING)
440 else if (tconn.callMode[j]==RX_MODE_ERROR)
442 else if (tconn.callMode[j] == RX_MODE_EOF)
444 else printf("unknown");
445 if (tconn.callFlags[j]) {
447 if (tconn.callFlags[j]&RX_CALL_READER_WAIT)
448 printf(" reader_wait");
449 if (tconn.callFlags[j]&RX_CALL_WAIT_WINDOW_ALLOC)
450 printf(" window_alloc");
451 if (tconn.callFlags[j]&RX_CALL_WAIT_WINDOW_SEND)
452 printf(" window_send");
453 if (tconn.callFlags[j]&RX_CALL_WAIT_PACKETS)
454 printf(" wait_packets");
455 if (tconn.callFlags[j]&RX_CALL_WAIT_PROC)
456 printf(" waiting_for_process");
457 if (tconn.callFlags[j]&RX_CALL_RECEIVE_DONE)
458 printf(" receive_done");
459 if (tconn.callFlags[j]&RX_CALL_CLEARED)
460 printf(" call_cleared");
462 if (tconn.callOther[j] & RX_OTHER_IN)
463 printf(", has_input_packets");
464 if (tconn.callOther[j] & RX_OTHER_OUT)
465 printf(", has_output_packets");
469 if (nodally) printf("Skipped %d dallying connections.\n", dallyCounter);
471 if (showPeers && withPeers) {
473 struct rx_debugPeer tpeer;
474 code = rx_GetServerPeers(s, host, port, &nextpeer, allconns, &tpeer, &supportedPeerValues);
476 printf("getpeer call failed with code %d\n", code);
479 if (tpeer.host == 0xffffffff) {
484 if ((onlyHost != -1) && (onlyHost != tpeer.host)) continue;
485 if ((onlyPort != -1) && (onlyPort != tpeer.port)) continue;
487 /* now display the peer */
488 hostAddr.s_addr = tpeer.host;
489 printf("Peer at host %s, port %hu\n",
490 inet_ntoa(hostAddr), ntohs(tpeer.port));
491 printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n",
492 tpeer.ifMTU, tpeer.natMTU, tpeer.maxMTU);
493 printf("\tpackets sent %d\tpacket resends %d\n",
494 tpeer.nSent, tpeer.reSends);
495 printf("\tbytes sent high %d low %d\n",
496 tpeer.bytesSent.high, tpeer.bytesSent.low);
497 printf("\tbytes received high %d low %d\n",
498 tpeer.bytesReceived.high, tpeer.bytesReceived.low);
499 printf("\trtt %d msec, rtt_dev %d msec\n",
500 tpeer.rtt >> 3, tpeer.rtt_dev >> 2);
501 printf("\ttimeout %d.%03d sec\n",
502 tpeer.timeout.sec, tpeer.timeout.usec / 1000);
508 /* simple main program */
510 #include "AFS_component_version_number.c"
516 struct cmd_syndesc *ts;
519 if (afs_winsockInit()<0) {
520 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
525 ts = cmd_CreateSyntax((char *) 0, MainCommand, 0, "probe RX server");
526 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
527 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
528 cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,
529 "don't show dallying conns");
530 cmd_AddParm(ts, "-allconnections", CMD_FLAG, CMD_OPTIONAL,
531 "don't filter out uninteresting connections on server");
532 cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "show Rx statistics");
533 cmd_AddParm(ts, "-onlyserver", CMD_FLAG, CMD_OPTIONAL,
534 "only show server conns");
535 cmd_AddParm(ts, "-onlyclient", CMD_FLAG, CMD_OPTIONAL,
536 "only show client conns");
537 cmd_AddParm(ts, "-onlyport", CMD_SINGLE, CMD_OPTIONAL, "show only <port>");
538 cmd_AddParm(ts, "-onlyhost", CMD_SINGLE, CMD_OPTIONAL, "show only <host>");
539 cmd_AddParm(ts, "-onlyauth", CMD_SINGLE, CMD_OPTIONAL,
540 "show only <auth level>");
542 cmd_AddParm(ts,"-version",CMD_FLAG,CMD_OPTIONAL,"show AFS version id");
543 cmd_AddParm(ts,"-noconns",CMD_FLAG,CMD_OPTIONAL,"show no connections");
544 cmd_AddParm(ts,"-peers",CMD_FLAG,CMD_OPTIONAL,"show peers");
546 cmd_Dispatch(argc, argv);