@@ -60,7 +60,8 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
if (status < 0)
return ERR_PTR(status);
- host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen,
+ host = nlmclnt_lookup_host(nlm_init->address, nlm_init->srcaddr,
+ nlm_init->addrlen,
nlm_init->protocol, nlm_version,
nlm_init->hostname, nlm_init->noresvport);
if (host == NULL) {
@@ -48,6 +48,7 @@ static void nlm_gc_hosts(void);
struct nlm_lookup_host_info {
const int server; /* search for server|client */
const struct sockaddr *sap; /* address to search for */
+ const struct sockaddr *src_addr; /* source address */
const size_t salen; /* it's length */
const unsigned short protocol; /* transport to search for*/
const u32 version; /* NLM version to search for */
@@ -130,7 +131,12 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
memcpy(nlm_addr(host), ni->sap, ni->salen);
host->h_addrlen = ni->salen;
rpc_set_port(nlm_addr(host), 0);
- host->h_srcaddrlen = 0;
+ if (ni->src_addr && ni->src_addr->sa_family != AF_UNSPEC) {
+ memcpy(nlm_srcaddr(host), ni->src_addr, ni->salen);
+ host->h_srcaddrlen = ni->salen;
+ } else {
+ host->h_srcaddrlen = 0;
+ }
host->h_rpcclnt = NULL;
host->h_name = nsm->sm_name;
@@ -202,6 +208,7 @@ static void nlm_destroy_host_locked(struct nlm_host *host)
* created and returned.
*/
struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
+ const struct sockaddr *srcaddr,
const size_t salen,
const unsigned short protocol,
const u32 version,
@@ -216,6 +223,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
.version = version,
.hostname = hostname,
.hostname_len = strlen(hostname),
+ .src_addr = srcaddr,
.noresvport = noresvport,
};
struct hlist_head *chain;
@@ -234,6 +242,13 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
if (!rpc_cmp_addr(nlm_addr(host), sap))
continue;
+ /* Check for local binding match only if user
+ * has specified the source-address.
+ */
+ if (srcaddr && srcaddr->sa_family != AF_UNSPEC &&
+ !rpc_cmp_addr(nlm_srcaddr(host), srcaddr))
+ continue;
+
/* Same address. Share an NSM handle if we already have one */
if (nsm == NULL)
nsm = host->h_nsmhandle;
@@ -705,6 +705,7 @@ static int nfs_start_lockd(struct nfs_server *server)
struct nlmclnt_initdata nlm_init = {
.hostname = clp->cl_hostname,
.address = (struct sockaddr *)&clp->cl_addr,
+ .srcaddr = (struct sockaddr *)&clp->srcaddr,
.addrlen = clp->cl_addrlen,
.nfs_version = clp->rpc_ops->version,
.noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
@@ -38,6 +38,7 @@ extern struct nlmsvc_binding * nlmsvc_ops;
struct nlmclnt_initdata {
const char *hostname;
const struct sockaddr *address;
+ const struct sockaddr *srcaddr;
size_t addrlen;
unsigned short protocol;
u32 nfs_version;
@@ -218,6 +218,7 @@ void nlmclnt_next_cookie(struct nlm_cookie *);
* Host cache
*/
struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
+ const struct sockaddr *bindaddr,
const size_t salen,
const unsigned short protocol,
const u32 version,
@@ -262,6 +262,8 @@ static inline bool rpc_cmp_addr(const struct sockaddr *sap1,
return __rpc_cmp_addr4(sap1, sap2);
case AF_INET6:
return __rpc_cmp_addr6(sap1, sap2);
+ case AF_UNSPEC:
+ return true;
}
}
return false;