From 6b86ed04298a3ed38b0ee97efea7eb80e3738621 Mon Sep 17 00:00:00 2001 From: Erez Zadok Date: Thu, 22 Jan 2004 05:01:06 +0000 Subject: [PATCH] * 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. --- ChangeLog | 30 +++++++++++++++++++++++++++++ NEWS | 6 +++++- amd/amd.c | 9 +++++---- amd/amd.h | 3 ++- amd/conf.c | 12 +++++++++++- conf/transp/transp_sockets.c | 37 ++++++++++++++++++++++++++++++++---- conf/transp/transp_tli.c | 10 ++++++---- doc/am-utils.texi | 20 ++++++++++++++++--- hlfsd/hlfsd.c | 4 ++-- include/am_utils.h | 4 ++-- scripts/amd.conf-sample | 2 ++ scripts/amd.conf.5 | 10 +++++++++- wire-test/wire-test.c | 4 ++-- 13 files changed, 126 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 701ab182..82e95272 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2004-01-21 Erez Zadok + + * 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 * amd/conf.c (gopt_nfs_allow_insecure_port): support function for diff --git a/NEWS b/NEWS index e3696559..0f4d34ec 100644 --- 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) @@ -10,6 +10,10 @@ 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. diff --git a/amd/amd.c b/amd/amd.c index 35bb205b..dfd7a3cd 100644 --- 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 */ diff --git a/amd/amd.h b/amd/amd.h index 4d30f2f7..491ba5fe 100644 --- 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 */ diff --git a/amd/conf.c b/amd/conf.c index b4763def..3e9f9ebd 100644 --- a/amd/conf.c +++ b/amd/conf.c @@ -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) { diff --git a/conf/transp/transp_sockets.c b/conf/transp/transp_sockets.c index af5d7f0c..1b292089 100644 --- a/conf/transp/transp_sockets.c +++ b/conf/transp/transp_sockets.c @@ -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 @@ -60,10 +60,13 @@ * 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); } diff --git a/conf/transp/transp_tli.c b/conf/transp/transp_tli.c index 33d11202..f9bbb184 100644 --- a/conf/transp/transp_tli.c +++ b/conf/transp/transp_tli.c @@ -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 @@ -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 */ diff --git a/doc/am-utils.texi b/doc/am-utils.texi index 118bfcee..18116ceb 100644 --- a/doc/am-utils.texi +++ b/doc/am-utils.texi @@ -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 diff --git a/hlfsd/hlfsd.c b/hlfsd/hlfsd.c index ecacdeff..1a2b2245 100644 --- a/hlfsd/hlfsd.c +++ b/hlfsd/hlfsd.c @@ -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 and Alexander Dupuy @@ -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 */ diff --git a/include/am_utils.h b/include/am_utils.h index 2e3c6fa3..23f8cee7 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -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); diff --git a/scripts/amd.conf-sample b/scripts/amd.conf-sample index 96772d57..760f3854 100644 --- a/scripts/amd.conf-sample +++ b/scripts/amd.conf-sample @@ -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 diff --git a/scripts/amd.conf.5 b/scripts/amd.conf.5 index c83f1023..68a41d06 100644 --- a/scripts/amd.conf.5 +++ b/scripts/amd.conf.5 @@ -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 diff --git a/wire-test/wire-test.c b/wire-test/wire-test.c index a70a752e..7381625c 100644 --- a/wire-test/wire-test.c +++ b/wire-test/wire-test.c @@ -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)); /* -- 2.43.0