* wire-test/wire-test.c, hlfsd/hlfsd.c (main): pass NULL as second
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 22 Jan 2004 05:01:06 +0000 (05:01 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Thu, 22 Jan 2004 05:01:06 +0000 (05:01 +0000)
parameter to amu_get_myaddress().

* conf/transp/transp_tli.c (amu_get_myaddress): resolve value of
localhost_address amd.conf parameter, if defined (else default to
HOST_SELF_CONNECT).
Removed htonl() around socket address copying (I think it was
wrong) since plog("My IP address is...") in amd.c was printing
addresses wrong on Solaris x86..

* conf/transp/transp_sockets.c (amu_get_myaddress): comment out
old DEBUG code that warns if 127.0.0.1 isn't the same as what
get_myaddress() reports.  Add code to resolve value of
localhost_address amd.conf parameter, if defined (else default to
127.0.0.1).

* amd/conf.c (gopt_localhost_address): new function to parse
amd.conf parameter localhost_address.

* amd/amd.h: global field to store amd.conf localhost_address
parameter.

* amd/amd.c (main): call amu_get_myaddress with global option,
which could have been set in amd.conf.

* NEWS, doc/am-utils.texi, scripts/amd.conf-sample,
scripts/amd.conf.5: document new option localhost_address.

13 files changed:
ChangeLog
NEWS
amd/amd.c
amd/amd.h
amd/conf.c
conf/transp/transp_sockets.c
conf/transp/transp_tli.c
doc/am-utils.texi
hlfsd/hlfsd.c
include/am_utils.h
scripts/amd.conf-sample
scripts/amd.conf.5
wire-test/wire-test.c

index 701ab1826b04609365814f0d708a1c027ba71334..82e9527237ef6c0fe84d30f803bf3be81df6199c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2004-01-21  Erez Zadok  <ezk@cs.sunysb.edu>
+
+       * wire-test/wire-test.c, hlfsd/hlfsd.c (main): pass NULL as second
+       parameter to amu_get_myaddress().
+
+       * conf/transp/transp_tli.c (amu_get_myaddress): resolve value of
+       localhost_address amd.conf parameter, if defined (else default to
+       HOST_SELF_CONNECT).
+       Removed htonl() around socket address copying (I think it was
+       wrong) since plog("My IP address is...") in amd.c was printing
+       addresses wrong on Solaris x86..
+
+       * conf/transp/transp_sockets.c (amu_get_myaddress): comment out
+       old DEBUG code that warns if 127.0.0.1 isn't the same as what
+       get_myaddress() reports.  Add code to resolve value of
+       localhost_address amd.conf parameter, if defined (else default to
+       127.0.0.1).
+
+       * amd/conf.c (gopt_localhost_address): new function to parse
+       amd.conf parameter localhost_address.
+
+       * amd/amd.h: global field to store amd.conf localhost_address
+       parameter.
+
+       * amd/amd.c (main): call amu_get_myaddress with global option,
+       which could have been set in amd.conf.
+
+       * NEWS, doc/am-utils.texi, scripts/amd.conf-sample,
+       scripts/amd.conf.5: document new option localhost_address.
+
 2004-01-20  Ion Badulescu  <ionut@moisil.badula.org>
 
        * amd/conf.c (gopt_nfs_allow_insecure_port): support function for
diff --git a/NEWS b/NEWS
index e369655996b133cab0a523b79d3e3d24b258c53b..0f4d34ecbcd47159e21278721ff8266b1eb3d1c1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,7 @@
 
 - minor new ports:
        i386-pc-solaris2.10
-        i386-unknown-freebsd4.8
+       i386-unknown-freebsd4.8
        i386-unknown-freebsd4.9
        i386-unknown-freebsd5.1 (5.1-RELEASE)
        i386-unknown-freebsd5.2 (5.2-RELEASE)
        sparc-sun-solaris2.10
        x86_64-unknown-linux-rh2.9.5AS
 
+- new amd.conf parameter: localhost_address.  Used to override the localhost
+  (often 127.0.0.1) address Amd uses to connect to for the local NFS server
+  and RPC server.
+
 - fully support WebNFS as per RFC 2054.  It now tries v3/TCP first, falling
   back to v2/UDP if this doesn't work.  The "webnfs" pseudo-mount options
   has been renamed (again) to "public" to match Solaris 2.
index 35bb205b3da4e552f297b93acbbdae58fe0ceb46..dfd7a3cd9b9814c971612a044de1284a245288e0 100644 (file)
--- a/amd/amd.c
+++ b/amd/amd.c
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: amd.c,v 1.25 2004/01/06 03:56:19 ezk Exp $
+ * $Id: amd.c,v 1.26 2004/01/22 05:01:06 ezk Exp $
  *
  */
 
@@ -482,10 +482,11 @@ main(int argc, char *argv[])
   }
 
   /*
-   * Get our own IP address so that we
-   * can mount the automounter.
+   * Get our own IP address so that we can mount the automounter.  We pass
+   * localhost_address which could be used as the default localhost
+   * name/address in amu_get_myaddress().
    */
-  amu_get_myaddress(&myipaddr);
+  amu_get_myaddress(&myipaddr, gopt.localhost_address);
   plog(XLOG_INFO, "My ip addr is %s", inet_ntoa(myipaddr));
 
   /* avoid hanging on other NFS servers if started elsewhere */
index 4d30f2f7838a071a1d6069f8f222cb179bb03f14..491ba5fe4777c3a1b3a527ea3af42cbd521aa42a 100644 (file)
--- a/amd/amd.h
+++ b/amd/amd.h
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: amd.h,v 1.51 2004/01/21 03:42:12 ib42 Exp $
+ * $Id: amd.h,v 1.52 2004/01/22 05:01:06 ezk Exp $
  *
  */
 
@@ -250,6 +250,7 @@ struct amu_global_options {
   char *op_sys_vendor;         /* name of OS vendor ${vendor} */
   char *pid_file;              /* PID file */
   char *sub_domain;            /* local domain */
+  char *localhost_address;     /* localhost address (NULL means use 127.0.0.1) */
   char *map_defaults;          /* global map /default options */
   char *map_options;           /* global map options */
   int map_reload_interval;     /* map reload interval */
index b4763def155e6bb7dffc62f92270de9cf401e1e0..3e9f9ebd048aa74c64e7d1cbd5115f60fa59cd92 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: conf.c,v 1.22 2004/01/21 03:42:12 ib42 Exp $
+ * $Id: conf.c,v 1.23 2004/01/22 05:01:06 ezk Exp $
  *
  */
 
@@ -92,6 +92,7 @@ static int gopt_ldap_cache_seconds(const char *val);
 static int gopt_ldap_hostports(const char *val);
 static int gopt_ldap_proto_version(const char *val);
 static int gopt_local_domain(const char *val);
+static int gopt_localhost_address(const char *val);
 static int gopt_log_file(const char *val);
 static int gopt_log_options(const char *val);
 static int gopt_map_defaults(const char *val);
@@ -158,6 +159,7 @@ static struct _func_map glob_functable[] = {
   {"ldap_hostports",           gopt_ldap_hostports},
   {"ldap_proto_version",       gopt_ldap_proto_version},
   {"local_domain",             gopt_local_domain},
+  {"localhost_address",                gopt_localhost_address},
   {"log_file",                 gopt_log_file},
   {"log_options",              gopt_log_options},
   {"map_defaults",             gopt_map_defaults},
@@ -485,6 +487,14 @@ gopt_local_domain(const char *val)
 }
 
 
+static int
+gopt_localhost_address(const char *val)
+{
+  gopt.localhost_address = strdup((char *)val);
+  return 0;
+}
+
+
 static int
 gopt_ldap_base(const char *val)
 {
index af5d7f0c2cc7e9e3c48b1ba56439c376e02dd4aa..1b2920897a3bdef748bffb5261508b0ff2e4eb37 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: transp_sockets.c,v 1.27 2004/01/06 03:56:20 ezk Exp $
+ * $Id: transp_sockets.c,v 1.28 2004/01/22 05:01:06 ezk Exp $
  *
  * Socket specific utilities.
  *      -Erez Zadok <ezk@cs.columbia.edu>
  * find the IP address that can be used to connect to the local host
  */
 void
-amu_get_myaddress(struct in_addr *iap)
+amu_get_myaddress(struct in_addr *iap, const char *preferred_localhost)
 {
+  struct hostent *hp;
 
-#ifdef DEBUG
+#ifdef DEBUG_off
+#error this code is old and probably not useful any longer.
+#error Erez, Jan 21, 2004.
   struct sockaddr_in sin;
 
   /*
@@ -81,8 +84,34 @@ amu_get_myaddress(struct in_addr *iap)
   if (sin.sin_addr.s_addr != htonl(INADDR_LOOPBACK))
     dlog("amu_get_myaddress: myaddress conflict (0x%x vs. 0x%lx)",
         sin.sin_addr.s_addr, (u_long) htonl(INADDR_LOOPBACK));
-#endif /* DEBUG */
+#endif /* DEBUG_off */
+
+  if (preferred_localhost == NULL)
+    goto out;
+
+  /* if specified preferred locahost, then try to use it */
+  hp = gethostbyname(preferred_localhost);
+  if (hp == NULL) {
+    /* XXX: if hstrerror()/h_errno aren't portable, then need to port the next statement */
+    plog(XLOG_ERROR, "Unable to resolve localhost_address \"%s\" (%s): using default",
+        preferred_localhost, hstrerror(h_errno));
+    goto out;
+  }
+  if (hp->h_addr_list == NULL) {
+    plog(XLOG_ERROR, "localhost_address \"%s\" has no IP addresses: using default",
+        preferred_localhost);
+    goto out;
+  }
+  if (hp->h_addr_list[1] != NULL) {
+    plog(XLOG_ERROR, "localhost_address \"%s\" has more than one IP addresses: using first",
+        preferred_localhost);
+    goto out;
+  }
+  memmove((voidp) &iap->s_addr, (voidp) hp->h_addr_list[0], sizeof(iap->s_addr));
+  plog(XLOG_INFO, "localhost_address \"%s\" requested", preferred_localhost);
+  return;
 
+ out:
   iap->s_addr = htonl(INADDR_LOOPBACK);
 }
 
index 33d112027e653766aacb8fa8e7056cdbc8a18b97..f9bbb184921d89ca00ff83ec2fe37bf00de15ed2 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: transp_tli.c,v 1.20 2004/01/06 03:56:20 ezk Exp $
+ * $Id: transp_tli.c,v 1.21 2004/01/22 05:01:06 ezk Exp $
  *
  * TLI specific utilities.
  *      -Erez Zadok <ezk@cs.columbia.edu>
@@ -56,7 +56,7 @@ struct netconfig *nfsncp;
  * find the IP address that can be used to connect to the local host
  */
 void
-amu_get_myaddress(struct in_addr *iap)
+amu_get_myaddress(struct in_addr *iap, const char *preferred_localhost)
 {
   int ret;
   voidp handlep;
@@ -66,7 +66,7 @@ amu_get_myaddress(struct in_addr *iap)
 
   handlep = setnetconfig();
   ncp = getnetconfig(handlep);
-  service.h_host = HOST_SELF_CONNECT;
+  service.h_host = (preferred_localhost ? (char *) preferred_localhost : HOST_SELF_CONNECT);
   service.h_serv = (char *) NULL;
 
   ret = netdir_getbyname(ncp, &service, &addrs);
@@ -80,7 +80,9 @@ amu_get_myaddress(struct in_addr *iap)
      * host.  Maybe something can be done with those.
      */
     struct sockaddr_in *sinp = (struct sockaddr_in *) addrs->n_addrs[0].buf;
-    iap->s_addr = htonl(sinp->sin_addr.s_addr);
+    if (preferred_localhost)
+      plog(XLOG_INFO, "localhost_address \"%s\" requested", preferred_localhost);
+    iap->s_addr = sinp->sin_addr.s_addr; /* XXX: used to be htonl() */
   }
 
   endnetconfig(handlep);       /* free's up internal resources too */
index 118bfceece53e1552e9c1544828c3f17722c771f..18116ceb976683a8a0702d8aae3bc8162c3072e3 100644 (file)
@@ -38,7 +38,7 @@
 @c
 @c      %W% (Berkeley) %G%
 @c
-@c $Id: am-utils.texi,v 1.82 2004/01/21 03:42:12 ib42 Exp $
+@c $Id: am-utils.texi,v 1.83 2004/01/22 05:01:06 ezk Exp $
 @c
 @setfilename am-utils.info
 
@@ -4184,6 +4184,7 @@ The following parameters are applicable to the @samp{[global]} section only.
 * ldap_hostports Parameter::
 * ldap_proto_version Parameter::
 * local_domain Parameter::
+* localhost_address Parameter::
 * log_file Parameter::
 * log_options Parameter::
 * map_reload_interval Parameter::
@@ -4369,7 +4370,7 @@ Specify the LDAP host and port values.
 With a value of 3 will use LDAPv3 protocol.
 
 @c ----------------------------------------------------------------
-@node local_domain Parameter, log_file Parameter, ldap_proto_version Parameter, Global Parameters
+@node local_domain Parameter, localhost_address Parameter, ldap_proto_version Parameter, Global Parameters
 @comment  node-name,  next,  previous,  up
 @subsection @t{local_domain} Parameter
 @cindex local_domain Parameter
@@ -4380,7 +4381,20 @@ the domain name is determined from the hostname, by removing the first
 component of the fully-qualified host name.
 
 @c ----------------------------------------------------------------
-@node log_file Parameter, log_options Parameter, local_domain Parameter, Global Parameters
+@node localhost_address Parameter, log_file Parameter, local_domain Parameter, Global Parameters
+@comment  node-name,  next,  previous,  up
+@subsection @t{localhost_address} Parameter
+@cindex localhost_address Parameter
+
+(type=string, default to localhost or 127.0.0.1).  Specify the name or
+IP address for @i{Amd} to use when connecting the sockets for the
+local NFS server and the RPC server.  This defaults to 127.0.0.1 or
+whatever the host reports as its local address.  This parameter is
+useful on hosts with multiple addresses where you want to force
+@i{Amd} to connect to a specific address.
+
+@c ----------------------------------------------------------------
+@node log_file Parameter, log_options Parameter, localhost_address Parameter, Global Parameters
 @comment  node-name,  next,  previous,  up
 @subsection @t{log_file} Parameter
 @cindex log_file Parameter
index ecacdeff5682d7f04dc283b6c179acc5e9fbfd83..1a2b2245a31461019770181c1838f8e9aa92b753 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: hlfsd.c,v 1.26 2004/01/06 03:56:20 ezk Exp $
+ * $Id: hlfsd.c,v 1.27 2004/01/22 05:01:06 ezk Exp $
  *
  * HLFSD was written at Columbia University Computer Science Department, by
  * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu>
@@ -501,7 +501,7 @@ main(int argc, char *argv[])
   /* some systems don't have a mount type, but a mount flag */
 
 #ifndef HAVE_TRANSPORT_TYPE_TLI
-  amu_get_myaddress(&localsocket.sin_addr);
+  amu_get_myaddress(&localsocket.sin_addr, NULL);
   localsocket.sin_family = AF_INET;
   localsocket.sin_port = htons(nfsxprt->xp_port);
 #endif /* not HAVE_TRANSPORT_TYPE_TLI */
index 2e3c6fa3d7b496998bddf891671437a5ac038b53..23f8cee73146608cdb6d7696ef9d71db81dd9b18 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: am_utils.h,v 1.56 2004/01/06 03:56:20 ezk Exp $
+ * $Id: am_utils.h,v 1.57 2004/01/22 05:01:06 ezk Exp $
  *
  */
 
@@ -302,7 +302,7 @@ extern int switch_to_logfile(char *logfile, int orig_umask);
 extern mntlist *read_mtab(char *, const char *);
 extern struct sockaddr_in *amu_svc_getcaller(SVCXPRT *xprt);
 extern time_t time(time_t *);
-extern void amu_get_myaddress(struct in_addr *iap);
+extern void amu_get_myaddress(struct in_addr *iap, const char *preferred_localhost);
 extern void amu_release_controlling_tty(void);
 extern void compute_automounter_nfs_args(nfs_args_t *nap, mntent_t *mntp);
 extern void discard_mntlist(mntlist *mp);
index 96772d5775f7772047c2e9a102ddf6ede332680e..760f3854d8826ebbc3796f8a0a09c74f44b48486 100644 (file)
@@ -85,6 +85,8 @@ nfs_proto =                   udp | tcp
 use_tcpwrappers =              yes | no
 # allow NFS requests from insecure (>=1024) ports
 nfs_allow_insecure_port =      yes | no
+# address used for local NFS mount and RPC server (default to localhost)
+localhost_address =            foo.example.com | 192.168.1.2
 
 ##############################################################################
 # DEFINE AN AMD MOUNT POINT
index c83f10237458c0d3fb4b5473271ee51257f37f94..68a41d068dc3ef6de2728e0a070a9c147f4a824a 100644 (file)
@@ -38,7 +38,7 @@
 .\"
 .\"    %W% (Berkeley) %G%
 .\"
-.\" $Id: amd.conf.5,v 1.26 2004/01/21 03:42:12 ib42 Exp $
+.\" $Id: amd.conf.5,v 1.27 2004/01/22 05:01:06 ezk Exp $
 .\"
 .TH AMD.CONF 5 "7 August 1997"
 .SH NAME
@@ -306,6 +306,14 @@ option to amd.  Specify the local domain name.  If this option is not given
 the domain name is determined from the hostname, by removing the first
 component of the fully-qualified host name.
 
+.TP
+.BR localhost_address " (string, default to localhost or 127.0.0.1)"
+Specify the name or IP address for amd to use when connecting the sockets
+for the local NFS server and the RPC server.  This defaults to 127.0.0.1 or
+whatever the host reports as its local address.  This parameter is useful on
+hosts with multiple addresses where you want to force amd to connect to a
+specific address.
+
 .TP
 .BR log_file " (string, default=/dev/stderr)"
 Same as the
index a70a752e294ea32ff954f9503889f10c4825ba12..7381625cbcf14ae743dcdd36bc73ad719e45ec17 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: wire-test.c,v 1.10 2004/01/06 03:56:21 ezk Exp $
+ * $Id: wire-test.c,v 1.11 2004/01/22 05:01:06 ezk Exp $
  *
  */
 
@@ -78,7 +78,7 @@ main(int argc, char **argv)
   }
 
   /* also print my IP address */
-  amu_get_myaddress(&myipaddr);
+  amu_get_myaddress(&myipaddr, NULL);
   fprintf(stderr, "My IP address is 0x%x.\n", (unsigned int) htonl(myipaddr.s_addr));
 
   /*