rxdebug: Add rxgk support
[openafs.git] / src / rxdebug / rxdebug.c
index 8ebd6c2..5cd30b2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -9,54 +9,34 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
+#include <roken.h>
 
-#include <sys/types.h>
-#include <errno.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <sys/file.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <sys/stat.h>
-#include <afs/stds.h>
+#include <afs/afsutil.h>
 #include <afs/cmd.h>
 
-#include <stdio.h>
+#include <rx/rx_user.h>
+#include <rx/rx_clock.h>
+#include <rx/rx_queue.h>
+#include <rx/rx.h>
+#include <rx/rx_globals.h>
 
-#include "rx_user.h"
-#include "rx_clock.h"
-#include "rx_queue.h"
-#include "rx.h"
-#include "rx_globals.h"
+#ifdef ENABLE_RXGK
+# include <rx/rxgk.h>
+#endif
 
 
 #define        TIMEOUT     20
 
-extern struct hostent *hostutil_GetHostByName();
-
 static short
-PortNumber(aport)
-     register char *aport;
+PortNumber(char *aport)
 {
-    register int tc;
-    register short total;
+    int tc;
+    short total;
 
     total = 0;
-    while (tc = *aport++) {
+    while ((tc = *aport++)) {
        if (tc < '0' || tc > '9')
            return -1;          /* bad port number */
        total *= 10;
@@ -66,10 +46,9 @@ PortNumber(aport)
 }
 
 static short
-PortName(aname)
-     register char *aname;
+PortName(char *aname)
 {
-    register struct servent *ts;
+    struct servent *ts;
     ts = getservbyname(aname, NULL);
     if (!ts)
        return -1;
@@ -79,7 +58,7 @@ PortName(aname)
 int
 MainCommand(struct cmd_syndesc *as, void *arock)
 {
-    register int i;
+    int i;
     osi_socket s;
     int j;
     struct sockaddr_in taddr;
@@ -87,7 +66,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
     struct in_addr hostAddr;
     short port;
     struct hostent *th;
-    register afs_int32 code;
+    afs_int32 code;
     int nodally;
     int allconns;
     int rxstats;
@@ -168,6 +147,10 @@ MainCommand(struct cmd_syndesc *as, void *arock)
 
     if (as->parms[9].items) {
        char *name = as->parms[9].items->data;
+        /* Note that this assumes that the security levels for rxkad and rxgk
+         * use the same constants (0, 1, and 2). Perhaps a little ugly, but the
+         * constants being identical makes it really convenient to do it this
+         * way. */
        if (strcmp(name, "clear") == 0)
            onlyAuth = 0;
        else if (strcmp(name, "auth") == 0)
@@ -212,7 +195,15 @@ MainCommand(struct cmd_syndesc *as, void *arock)
     hostAddr.s_addr = host;
     afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
     printf("Trying %s (port %d):\n", hoststr, ntohs(port));
-    s = socket(AF_INET, SOCK_DGRAM, 0);
+    s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+    if (s == OSI_NULLSOCKET) {
+#ifdef AFS_NT40_ENV
+        fprintf(stderr, "socket() failed with error %u\n", WSAGetLastError());
+#else
+       perror("socket");
+#endif
+       exit(1);
+    }
     taddr.sin_family = AF_INET;
     taddr.sin_port = 0;
     taddr.sin_addr.s_addr = 0;
@@ -221,11 +212,16 @@ MainCommand(struct cmd_syndesc *as, void *arock)
 #endif
     code = bind(s, (struct sockaddr *)&taddr, sizeof(struct sockaddr_in));
     if (code) {
+#ifdef AFS_NT40_ENV
+        fprintf(stderr, "bind() failed with error %u\n", WSAGetLastError());
+#else
        perror("bind");
+#endif
        exit(1);
     }
 
     if (version_flag) {
+        memset(version, 0, sizeof(version));
 
        code = rx_GetServerVersion(s, host, port, length, version);
        if (code < 0) {
@@ -233,6 +229,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
                   errno);
            exit(1);
        }
+        version[sizeof(version) - 1] = '\0';
        printf("AFS version: %s\n", version);
        fflush(stdout);
 
@@ -258,7 +255,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
 
     if (withPackets)
         printf("Free packets: %d/%d, packet reclaims: %d, calls: %d, used FDs: %d\n",
-               tstats.nFreePackets, tstats.nPackets, tstats.packetReclaims, 
+               tstats.nFreePackets, tstats.nPackets, tstats.packetReclaims,
                tstats.callsExecuted, tstats.usedFDs);
     else
         printf("Free packets: %d, packet reclaims: %d, calls: %d, used FDs: %d\n",
@@ -292,8 +289,9 @@ MainCommand(struct cmd_syndesc *as, void *arock)
                exit(1);
            }
            if (code != sizeof(rxstats)) {
-               if ((((struct rx_debugIn *)(&rxstats))->type ==
-                    RX_DEBUGI_BADTYPE))
+               struct rx_debugIn debug;
+               memcpy(&debug, &rxstats, sizeof(debug));
+               if (debug.type == RX_DEBUGI_BADTYPE)
                    goto noRxStats;
                printf
                    ("WARNING: returned Rx statistics of unexpected size (got %d)\n",
@@ -319,8 +317,8 @@ MainCommand(struct cmd_syndesc *as, void *arock)
            printf("Showing only client connections\n");
        if (onlyAuth != 999) {
            static char *name[] =
-               { "unauthenticated", "rxkad_clear", "rxkad_auth",
-               "rxkad_crypt"
+               { "unauthenticated", "clear", "auth",
+               "crypt"
            };
            printf("Showing only %s connections\n", name[onlyAuth + 1]);
        }
@@ -374,14 +372,23 @@ MainCommand(struct cmd_syndesc *as, void *arock)
                continue;
            if (onlyAuth != 999) {
                if (onlyAuth == -1) {
-                   if (tconn.securityIndex != 0)
+                   if (tconn.securityIndex != RX_SECIDX_NULL)
                        continue;
                } else {
-                   if (tconn.securityIndex != 2)
+                   if (tconn.securityIndex != RX_SECIDX_KAD) {
+#ifdef ENABLE_RXGK
+                        if (tconn.securityIndex != RX_SECIDX_GK)
+#endif
+                            continue;
+                    }
+                   if (withSecStats && (tconn.secStats.type == RX_SECTYPE_KAD)
+                       && (tconn.secStats.level != onlyAuth))
                        continue;
-                   if (withSecStats && (tconn.secStats.type == 3)
+#ifdef ENABLE_RXGK
+                   if (withSecStats && (tconn.secStats.type == RX_SECTYPE_GK)
                        && (tconn.secStats.level != onlyAuth))
                        continue;
+#endif
                }
            }
 
@@ -425,20 +432,20 @@ MainCommand(struct cmd_syndesc *as, void *arock)
 
            if (withSecStats) {
                switch ((int)tconn.secStats.type) {
-               case 0:
-                   if (tconn.securityIndex == 2)
+               case RX_SECTYPE_UNK:
+                   if (tconn.securityIndex == RX_SECIDX_KAD)
                        printf
                            ("  no GetStats procedure for security object\n");
                    break;
-               case 1:
+               case RX_SECTYPE_NULL:
                    printf("  rxnull level=%d, flags=%d\n",
                           tconn.secStats.level, tconn.secStats.flags);
                    break;
-               case 2:
+               case RX_SECTYPE_VAB:
                    printf("  rxvab level=%d, flags=%d\n",
                           tconn.secStats.level, tconn.secStats.flags);
                    break;
-               case 3:{
+               case RX_SECTYPE_KAD:{
                        char *level;
                        char flags = tconn.secStats.flags;
                        if (tconn.secStats.level == 0)
@@ -479,6 +486,41 @@ MainCommand(struct cmd_syndesc *as, void *arock)
                            printf("\n");
                        break;
                    }
+#ifdef ENABLE_RXGK
+                case RX_SECTYPE_GK: {
+                       char *level;
+                       char flags = tconn.secStats.flags;
+                       if (tconn.secStats.level == RXGK_LEVEL_CLEAR)
+                           level = "clear";
+                       else if (tconn.secStats.level == RXGK_LEVEL_AUTH)
+                           level = "auth";
+                       else if (tconn.secStats.level == RXGK_LEVEL_CRYPT)
+                           level = "crypt";
+                       else
+                           level = "unknown";
+                       printf("  rxgk: level %s", level);
+                       if (flags)
+                           printf(", flags");
+                       if ((flags & RXGK_STATS_UNALLOC))
+                           printf(" unalloc");
+                       if ((flags & RXGK_STATS_AUTH))
+                           printf(" authenticated");
+                       if (tconn.secStats.expires)
+                           printf(", expires in %.1f hours",
+                                  ((afs_uint32) tconn.secStats.expires -
+                                   time(0)) / 3600.0);
+                       if (!(flags & RXGK_STATS_UNALLOC)) {
+                           printf("\n  Received %u bytes in %u packets\n",
+                                  tconn.secStats.bytesReceived,
+                                  tconn.secStats.packetsReceived);
+                           printf("  Sent %u bytes in %u packets\n",
+                                  tconn.secStats.bytesSent,
+                                  tconn.secStats.packetsSent);
+                       } else
+                           printf("\n");
+                       break;
+                    }
+#endif /* ENABLE_RXGK */
 
                default:
                    printf("  unknown\n");
@@ -498,6 +540,8 @@ MainCommand(struct cmd_syndesc *as, void *arock)
                    printf("dally, ");
                else if (tconn.callState[j] == RX_STATE_HOLD)
                    printf("hold, ");
+               else if (tconn.callState[j] == RX_STATE_RESET)
+                   printf("reset, ");
                printf("mode: ");
                if (tconn.callMode[j] == RX_MODE_SENDING)
                    printf("sending");
@@ -559,7 +603,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
            /* now display the peer */
            hostAddr.s_addr = tpeer.host;
            afs_inet_ntoa_r(hostAddr.s_addr, hoststr);
-           printf("Peer at host %s, port %hu\n", hoststr, 
+           printf("Peer at host %s, port %hu\n", hoststr,
                   ntohs(tpeer.port));
            printf("\tifMTU %hu\tnatMTU %hu\tmaxMTU %hu\n", tpeer.ifMTU,
                   tpeer.natMTU, tpeer.maxMTU);
@@ -593,9 +637,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
 #include "AFS_component_version_number.c"
 #endif
 int
-main(argc, argv)
-     int argc;
-     char **argv;
+main(int argc, char **argv)
 {
     struct cmd_syndesc *ts;
 
@@ -609,7 +651,7 @@ main(argc, argv)
     }
 #endif
 
-    ts = cmd_CreateSyntax(NULL, MainCommand, NULL, "probe RX server");
+    ts = cmd_CreateSyntax(NULL, MainCommand, NULL, 0, "probe RX server");
     cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
     cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
     cmd_AddParm(ts, "-nodally", CMD_FLAG, CMD_OPTIONAL,