autofs-5.0.5 - include ip address in debug logging

From: Ian Kent <raven@themaw.net>

When probing availability of a host also log the network address along
with the host name.
---

 CHANGELOG            |    1 +
 include/rpc_subs.h   |    1 +
 lib/rpc_subs.c       |   20 ++++++++++++++++++++
 modules/replicated.c |   24 +++++++++++++++++++-----
 4 files changed, 41 insertions(+), 5 deletions(-)


diff --git a/CHANGELOG b/CHANGELOG
index 5ac1648..4b4389b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -68,6 +68,7 @@
 - fix null cache clean.
 - automount(8) man page correction.
 - fix out of order locking in readmap.
+- include ip address in debug logging.
 
 03/09/2009 autofs-5.0.5
 -----------------------
diff --git a/include/rpc_subs.h b/include/rpc_subs.h
index 87fd568..5ffc1b1 100644
--- a/include/rpc_subs.h
+++ b/include/rpc_subs.h
@@ -69,6 +69,7 @@ int rpc_ping_proto(struct conn_info *);
 int rpc_ping(const char *, long, long, unsigned int);
 double elapsed(struct timeval, struct timeval);
 int rpc_time(const char *, unsigned int, unsigned int, long, long, unsigned int, double *);
+const char *get_addr_string(struct sockaddr *, char *, socklen_t);
 
 #endif
 
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
index 9da3d38..af8c101 100644
--- a/lib/rpc_subs.c
+++ b/lib/rpc_subs.c
@@ -999,6 +999,26 @@ try_tcp:
 	return exportlist;
 }
 
+const char *get_addr_string(struct sockaddr *sa, char *name, socklen_t len)
+{
+	void *addr;
+
+	if (len < INET6_ADDRSTRLEN)
+		return NULL;
+
+	if (sa->sa_family == AF_INET) {
+		struct sockaddr_in *ipv4 = (struct sockaddr_in *) sa;
+		addr = &(ipv4->sin_addr);
+	} else if (sa->sa_family == AF_INET6) {
+		struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) sa;
+		addr = &(ipv6->sin6_addr);
+	} else {
+		return NULL;
+	}
+
+	return inet_ntop(sa->sa_family, addr, name, len);
+}
+
 #if 0
 #include <stdio.h>
 
diff --git a/modules/replicated.c b/modules/replicated.c
index 975c254..76b75c7 100644
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -526,6 +526,8 @@ static unsigned int get_nfs_info(unsigned logopt, struct host *host,
 	char *have_port_opt = options ? strstr(options, "port=") : NULL;
 	unsigned int random_selection = host->options & MOUNT_FLAG_RANDOM_SELECT;
 	unsigned int use_weight_only = host->options & MOUNT_FLAG_USE_WEIGHT_ONLY;
+	socklen_t len = INET6_ADDRSTRLEN;
+	char buf[len + 1];
 	struct pmap parms;
 	struct timeval start, end;
 	struct timezone tz;
@@ -533,9 +535,14 @@ static unsigned int get_nfs_info(unsigned logopt, struct host *host,
 	double taken = 0;
 	int status, count = 0;
 
-	debug(logopt,
-	      "called for host %s proto %s version 0x%x",
-	      host->name, proto, version);
+	if (host->addr)
+		debug(logopt, "called with host %s(%s) proto %s version 0x%x",
+		      host->name, get_addr_string(host->addr, buf, len),
+		      proto, version);
+	else
+		debug(logopt,
+		      "called for host %s proto %s version 0x%x",
+		      host->name, proto, version);
 
 	memset(&parms, 0, sizeof(struct pmap));
 
@@ -748,6 +755,8 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
 	char *have_port_opt = options ? strstr(options, "port=") : NULL;
 	unsigned int random_selection = host->options & MOUNT_FLAG_RANDOM_SELECT;
 	unsigned int use_weight_only = host->options & MOUNT_FLAG_USE_WEIGHT_ONLY;
+	socklen_t len = INET6_ADDRSTRLEN;
+	char buf[len + 1];
 	struct conn_info pm_info, rpc_info;
 	struct pmap parms;
 	const char *proto;
@@ -758,8 +767,13 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
 	time_t timeout = RPC_TIMEOUT;
 	int status;
 
-	debug(logopt,
-	      "called with host %s version 0x%x", host->name, version);
+	if (host->addr)
+		debug(logopt, "called with host %s(%s) version 0x%x",
+			host->name, get_addr_string(host->addr, buf, len),
+			version);
+	else
+		debug(logopt, "called with host %s version 0x%x",
+			host->name, version);
 
 	memset(&pm_info, 0, sizeof(struct conn_info));
 	memset(&rpc_info, 0, sizeof(struct conn_info));