diff options
author | Neil Brown <neilb@suse.de> | 2006-06-23 13:37:08 +1000 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2006-06-23 13:37:08 +1000 |
commit | c2db41e8abb6ddc9d03a0c91c6db043fa0f85a8f (patch) | |
tree | 5ba4131cda3ac7353a4acbbcdcdd02eb8c618c3c /support | |
parent | 11d34d11153df198103a57291937ea9ff8b7356e (diff) | |
download | nfs-utils-c2db41e8abb6ddc9d03a0c91c6db043fa0f85a8f.tar.gz nfs-utils-c2db41e8abb6ddc9d03a0c91c6db043fa0f85a8f.tar.xz nfs-utils-c2db41e8abb6ddc9d03a0c91c6db043fa0f85a8f.zip |
Try to make sure that clientid used for NFSv4 is reliable.
We need to give an IP address to identify this client to the
server.
The current code does a gethostbyname of the hostname. One
some systems this returns 127.0.0.1 or similar, which is not useful.
Instead, use getsockname of the sock used to connect to the server
to confirm that the server is working. This gives the address on the
interface that was chosen to talk to that server, which is the
best address we can find (if there is a NAT in the way, it might
still not work, but in that case there is nothing we can do).
Diffstat (limited to 'support')
-rw-r--r-- | support/include/conn.h | 3 | ||||
-rw-r--r-- | support/nfs/conn.c | 13 |
2 files changed, 12 insertions, 4 deletions
diff --git a/support/include/conn.h b/support/include/conn.h index ae19a3e..1761dc4 100644 --- a/support/include/conn.h +++ b/support/include/conn.h @@ -31,7 +31,8 @@ typedef struct { static const struct timeval TIMEOUT = { 20, 0 }; static const struct timeval RETRY_TIMEOUT = { 3, 0 }; -int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int); +int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int, + struct sockaddr_in *); u_long nfsvers_to_mnt(const u_long); u_long mntvers_to_nfs(const u_long); int get_socket(struct sockaddr_in *, u_int, int); diff --git a/support/nfs/conn.c b/support/nfs/conn.c index a020394..5160c8b 100644 --- a/support/nfs/conn.c +++ b/support/nfs/conn.c @@ -92,7 +92,7 @@ int get_socket(struct sockaddr_in *saddr, u_int p_prot, int resvp) return RPC_ANYSOCK; } } - if (type == SOCK_STREAM) { + if (type == SOCK_STREAM || type == SOCK_DGRAM) { cc = connect(so, (struct sockaddr *)saddr, namelen); if (cc < 0) { rpc_createerr.cf_stat = RPC_SYSTEMERROR; @@ -118,7 +118,7 @@ int get_socket(struct sockaddr_in *saddr, u_int p_prot, int resvp) */ int clnt_ping(struct sockaddr_in *saddr, const u_long prog, const u_long vers, - const u_int prot) + const u_int prot, struct sockaddr_in *caddr) { CLIENT *clnt=NULL; int sock, stat; @@ -160,8 +160,15 @@ clnt_ping(struct sockaddr_in *saddr, const u_long prog, const u_long vers, rpc_createerr.cf_stat = stat; } clnt_destroy(clnt); - if (sock != -1) + if (sock != -1) { + if (caddr) { + /* Get the address of our end of this connection */ + int len = sizeof(*caddr); + if (getsockname(sock, caddr, &len) != 0) + caddr->sin_family = 0; + } close(sock); + } if (stat == RPC_SUCCESS) return 1; |