#! /bin/sh /usr/share/dpatch/dpatch-run ## 30nfs4-setclientid.dpatch by Steinar H. Gunderson , ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Get a more sensible client ID; based on a patch by Neil ## DP: Brown . @DPATCH@ --- a/mount/nfsmount.c +++ b/mount/nfsmount.c @@ -111,7 +111,7 @@ static int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp); -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 *caddr); /* Convert RPC errors into strings */ void rpc_strerror(void) @@ -118,7 +118,7 @@ int get_socket(struct sockaddr_in *saddr */ 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,4 +160,13 @@ clnt_ping(struct sockaddr_in *saddr, con clnt_destroy(clnt); close(sock); + 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_PROGVERSMISMATCH) return 1; --- a/mount/nfs4mount.c +++ b/mount/nfs4mount.c @@ -76,7 +76,7 @@ #define NFS_PORT 2049 #endif -extern int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int); +extern int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int, struct sockaddr_in *caddr); extern void rpc_strerror(void); struct { @@ -189,9 +189,10 @@ int nfs4mount(const char *spec, const ch static struct nfs4_mount_data data; static char hostdir[1024]; static char ip_addr[16] = "127.0.0.1"; - static struct sockaddr_in server_addr; + static struct sockaddr_in server_addr, client_addr; static int pseudoflavour[MAX_USER_FLAVOUR]; int num_flavour = 0; + int ip_addr_in_opts = 0; char *hostname, *dirname, *old_opts; char new_opts[1024]; @@ -302,6 +303,7 @@ int nfs4mount(const char *spec, const ch opteq+1); strncpy(ip_addr,opteq+1, sizeof(ip_addr)); ip_addr[sizeof(ip_addr)-1] = '\0'; + ip_addr_in_opts = 1; } else if (!strcmp(opt, "sec")) { num_flavour = parse_sec(opteq+1, pseudoflavour); if (!num_flavour) @@ -412,7 +414,18 @@ #endif data.version = NFS4_MOUNT_VERSION; - clnt_ping(&server_addr, NFS_PROGRAM, 4, data.proto); + client_addr.sin_family = 0; + client_addr.sin_addr.s_addr = 0; + clnt_ping(&server_addr, NFS_PROGRAM, 4, data.proto, &client_addr); + if (rpc_createerr.cf_stat == RPC_SUCCESS) { + if (!ip_addr_in_opts && + client_addr.sin_family != 0 && + client_addr.sin_addr.s_addr != 0) { + snprintf(ip_addr, sizeof(ip_addr), "%s", + inet_ntoa(client_addr.sin_addr)); + data.client_addr.len = strlen(ip_addr); + } + } if (rpc_createerr.cf_stat) { fprintf(stderr, "mount to NFS server '%s' failed.\n", data.hostname.data); goto fail; --- a/mount/nfsmount.c +++ b/mount/nfsmount.c @@ -376,7 +376,7 @@ probe_port(clnt_addr_t *server, break; } saddr->sin_port = htons(p_port); - if (clnt_ping(saddr, prog, *p_vers, *p_prot)) + if (clnt_ping(saddr, prog, *p_vers, *p_prot, NULL)) goto out_ok; if (!prot) { if (*++p_prot)