afs: add afsd -inumcalc option
[openafs.git] / src / afs / afs_util.c
index 90696f1..8bd595c 100644 (file)
 
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs/afs_stats.h"     /* afs statistics */
-
-#ifdef AFS_LINUX20_ENV
 #include "hcrypto/md5.h"
-#endif
-
-#if    defined(AFS_SUN5_ENV)
-#include <inet/led.h>
-#include <inet/common.h>
-#include <netinet/ip6.h>
-#include <inet/ip.h>
-#endif
 
 #if    defined(AFS_AIX_ENV)
 #include <sys/fp_io.h>
 #endif
 
-afs_int32 afs_new_inum = 0;
+afs_int32 afs_md5inum = 0;
 
 #ifndef afs_cv2string
 char *
@@ -107,7 +97,7 @@ afs_strtoi_r(const char *str, char **endptr, afs_uint32 *ret)
 
 #ifndef afs_strcasecmp
 int
-afs_strcasecmp(char *s1, char *s2)
+afs_strcasecmp(const char *s1, const char *s2)
 {
     while (*s1 && *s2) {
        char c1, c2;
@@ -194,7 +184,7 @@ afs_strdup(char *s)
 
 void
 print_internet_address(char *preamble, struct srvAddr *sa, char *postamble,
-                      int flag, int code)
+                      int flag, int code, struct rx_connection *rxconn)
 {
     struct server *aserver = sa->server;
     char *ptr = "\n";
@@ -214,13 +204,30 @@ print_internet_address(char *preamble, struct srvAddr *sa, char *postamble,
                " (multi-homed address; other same-host interfaces may still be down)\n";
        }
     }
-    afs_warn("%s%d.%d.%d.%d in cell %s%s (code %d)%s", preamble, (address >> 24),
+    afs_warnall("%s%d.%d.%d.%d in cell %s%s (code %d)%s", preamble, (address >> 24),
             (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
             aserver->cell->cellName, postamble, code, ptr);
-    afs_warnuser("%s%d.%d.%d.%d in cell %s%s (code %d)%s", preamble, (address >> 24),
-                (address >> 16) & 0xff, (address >> 8) & 0xff,
-                (address) & 0xff, aserver->cell->cellName, postamble, code, ptr);
 
+    if (flag == 1 && rxconn) {
+       /* server was marked down, check Rx to see if this was possibly due to
+        * an ICMP error received from the network */
+       int errorigin, errtype, errcode;
+       const char *errmsg;
+       if (rx_GetNetworkError(rxconn, &errorigin, &errtype, &errcode, &errmsg) == 0) {
+           const char *str1 = " (";
+           const char *str2 = ")";
+           if (!errmsg) {
+               errmsg = str1 = str2 = "";
+           }
+           afs_warnall("afs: network error for %d.%d.%d.%d:%d: origin %d type %d code %d%s%s%s\n",
+                    (address >> 24),
+                    (address >> 16) & 0xff,
+                    (address >> 8) & 0xff,
+                    (address) & 0xff,
+                    (int)ntohs(sa->sa_portal),
+                    errorigin, errtype, errcode, str1, errmsg, str2);
+       }
+    }
 }                              /*print_internet_address */
 
 
@@ -367,7 +374,6 @@ afs_data_pointer_to_int32(const void *p)
     return ip.i32[i32_sub];
 }
 
-#ifdef AFS_LINUX20_ENV
 static_inline afs_int32
 afs_calc_inum_md5(afs_int32 cell, afs_int32 volume, afs_int32 vnode)
 {
@@ -375,7 +381,7 @@ afs_calc_inum_md5(afs_int32 cell, afs_int32 volume, afs_int32 vnode)
     char digest[16];
     struct md5 ct;
 
-    if (afs_new_inum) {
+    if (afs_md5inum) {
        int offset;
        MD5_Init(&ct);
        MD5_Update(&ct, &cell, 4);
@@ -399,9 +405,6 @@ afs_calc_inum_md5(afs_int32 cell, afs_int32 volume, afs_int32 vnode)
     }
     return ino;
 }
-#else
-# define afs_calc_inum_md5(cell, volume, vnode) 0
-#endif
 
 afs_int32
 afs_calc_inum(afs_int32 cell, afs_int32 volume, afs_int32 vnode)