From nobody  Mon Oct  6 00:16:12 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.7/8.8.7) id AAA09861;
          Mon, 6 Oct 1997 00:16:12 -0700 (PDT)
          (envelope-from nobody)
Message-Id: <199710060716.AAA09861@hub.freebsd.org>
Date: Mon, 6 Oct 1997 00:16:12 -0700 (PDT)
From: mika@cs.caltech.edu
To: freebsd-gnats-submit@freebsd.org
Subject: /usr/sbin/amd handles remote filesystems on Internet gateways improperly causing system failure
X-Send-Pr-Version: www-1.0

>Number:         4705
>Category:       bin
>Synopsis:       /usr/sbin/amd handles remote filesystems on Internet gateways improperly causing system failure
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct  6 00:20:01 PDT 1997
>Closed-Date:    Sun Oct 19 21:02:55 MEST 1997
>Last-Modified:  Sun Oct 19 21:03:20 MEST 1997
>Originator:     Mika Nystrom
>Release:        FreeBSD-CURRENT 3.0, at most a few days old
>Organization:
California Institute of Technology, Department of Computer Science
>Environment:
FreeBSD obelix.cs.caltech.edu 3.0-CURRENT FreeBSD 3.0-CURRENT #0: Wed Oct  1 20:09:28 PDT 1997     mika@obelix.cs.caltech.edu:/usr/src/sys/compile/P6SERVER_2CPU_256MB  i386

>Description:
For "robustness reasons," AMD duplicates quite a bit of functionality
available in the kernel (so it doesn't block, and so forth).  AMD
does not look up DNS hostnames properly to check that the returned
IP address is locally connected (if there is a set of IP addresses,
it should pick the one available locally).  This causes it to get
very confused when attempting to automount directories stored on 
servers that are also IP gateways.
>How-To-Repeat:
Try to automount a directory on a locally connected IP gateway; if it
works, make sure that the BIND system is returning the addresses in the
wrong order (for some reason, our nameservers cycle the two IP 
addresses of the gateway (131.215.131.77 and 131.215.78.1)
for hosts on 131.215.131.x but for the hosts on 131.215.78.x they 
always return the 131.215.78.1 address of the gateway first...)
>Fix:

This fix will only work with 32-bit IP addresses:

*** amd.c.orig  Tue Sep  2 03:53:17 1997
--- amd.c       Sun Oct  5 18:41:47 1997
***************              
*** 72,77 ****                    
--- 72,78 ----          
  char *arch = ARCH_REP;                        /* Name of current architecture
*/
  char *endian = ARCH_ENDIAN;           /* Big or Little endian */
  char *wire;
+ unsigned long mysubnet;                       /* my subnet */
  int foreground = 1;                   /* This is the top-level server */
  int mypid;                            /* Current process id */
  int immediate_abort;                  /* Should close-down unmounts be retried
 */             
*** wire.c.orig Sat Feb 22 16:07:46 1997
--- wire.c      Sun Oct  5 20:32:59 1997
*************** 
*** 237,242 ****
--- 237,246 ---- 
                                else
                                        s = inet_dquad(buf, subnet);
                        }
+                       mysubnet = htonl(subnet);
+ #if 0
+                       plog(XLOG_ERROR,"wire.c: mysubnet = %#x\n",mysubnet);
+ #endif
                        netname = strdup(s);    
                }
        }
*** ../include/am.h.orig        Sun Oct  5 18:40:57 1997
--- ../include/am.h     Sun Oct  5 18:41:00 1997
***************
*** 165,170 ****                
--- 165,171 ----
  extern int first_free_map;    /* First free node */
  extern am_node *root_node;    /* Node for "root" */
  extern char *wire;            /* Name of primary connected network */
+ extern unsigned long mysubnet;  /* My subnet */
  #define       NEXP_AP (254)
  #define NEXP_AP_MARGIN (128)
                                
*** srvr_nfs.c.orig     Sat Feb 22 16:07:42 1997
--- srvr_nfs.c  Sun Oct  5 20:32:50 1997
***************         
*** 628,633 ****
--- 628,636 ----
        /*
         * lookup host address and canonical name
         */     
+ #if 0  
+       plog (XLOG_ERROR,"Looking up IP address for host %s",host);
+ #endif
        hp = gethostbyname(host);

        /*
***************
*** 653,664 **** 
         * Get here if we can't find an entry
         */
        if (hp) {
                switch (hp->h_addrtype) {
                case AF_INET:
                        ip = ALLOC(sockaddr_in);
                        bzero((voidp) ip, sizeof(*ip));
                        ip->sin_family = AF_INET;
!                       bcopy((voidp) hp->h_addr, (voidp) &ip->sin_addr, sizeof(
ip->sin_addr)); 
        
                        ip->sin_port = htons(NFS_PORT);
                        break;
--- 656,695 ----
         * Get here if we can't find an entry
         */
        if (hp) {
+               int i,match;
                switch (hp->h_addrtype) {
                case AF_INET:
                        ip = ALLOC(sockaddr_in);
                        bzero((voidp) ip, sizeof(*ip));
                        ip->sin_family = AF_INET;
!       
! #define SHIFT_ADDR(addr,soctets) ( (unsigned long)(addr)>>((soctets)*8) & 0xff
 )         
!                       for(i=0;hp->h_addr_list[i];i++) {
!                               /* check *hp->h_addr_list[i] against mysubnet */
!                               int j; 
!                               match = 1;
!                               for (j=0; j<4; j++) {
!                                       if(SHIFT_ADDR(mysubnet,j) && (SHIFT_ADDR
(mysubnet,j) != SHIFT_ADDR(*(unsigned long *)(hp->h_addr_list[i]),j))) {
!                                               match=0;
!                                               break;
!                                       }
!                               }
!                               /* match==1 -> same subnet */
!                               if(match) {
!                                       break;
!                                 }
!                       }
!                       
!                       if(match)
!                               bcopy((voidp) hp->h_addr_list[i],(voidp) &ip->si
n_addr,sizeof(ip->sin_addr));
!                       else
!                               bcopy((voidp) hp->h_addr, (voidp) &ip->sin_addr,
 sizeof(ip->sin_addr));         
! #if 0            ! #if 0
!                       if(match)
!                               plog(XLOG_ERROR,"Using matched IP address %#x",*
(unsigned long *)hp->h_addr_list[i]);
!                       else
!                               plog(XLOG_ERROR,"Using unmatched IP address %#x"
,*(unsigned long *)hp->h_addr);
! #endif
 
                        ip->sin_port = htons(NFS_PORT);
                        break;
             


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: joerg 
State-Changed-When: Sun Oct 19 21:02:55 MEST 1997 
State-Changed-Why:  
Dup for PR # 4678 

>Unformatted:
