SUNRPC: rpc_create() default hostname should support AF_INET6 addresses
If the ULP doesn't pass a hostname string to rpc_create(), it manufactures one based on the passed-in address. Be smart enough to handle an AF_INET6 address properly in this case. Move the default servername logic before the xprt_create_transport() call to simplify error handling in rpc_create(). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
parent
40c553193d
commit
510deb0d70
@ -30,6 +30,7 @@
|
|||||||
#include <linux/smp_lock.h>
|
#include <linux/smp_lock.h>
|
||||||
#include <linux/utsname.h>
|
#include <linux/utsname.h>
|
||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
|
#include <linux/in6.h>
|
||||||
|
|
||||||
#include <linux/sunrpc/clnt.h>
|
#include <linux/sunrpc/clnt.h>
|
||||||
#include <linux/sunrpc/rpc_pipe_fs.h>
|
#include <linux/sunrpc/rpc_pipe_fs.h>
|
||||||
@ -247,7 +248,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
|
|||||||
.addrlen = args->addrsize,
|
.addrlen = args->addrsize,
|
||||||
.timeout = args->timeout
|
.timeout = args->timeout
|
||||||
};
|
};
|
||||||
char servername[20];
|
char servername[48];
|
||||||
|
|
||||||
xprt = xprt_create_transport(&xprtargs);
|
xprt = xprt_create_transport(&xprtargs);
|
||||||
if (IS_ERR(xprt))
|
if (IS_ERR(xprt))
|
||||||
@ -258,13 +259,34 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
|
|||||||
* up a string representation of the passed-in address.
|
* up a string representation of the passed-in address.
|
||||||
*/
|
*/
|
||||||
if (args->servername == NULL) {
|
if (args->servername == NULL) {
|
||||||
struct sockaddr_in *addr =
|
servername[0] = '\0';
|
||||||
(struct sockaddr_in *) args->address;
|
switch (args->address->sa_family) {
|
||||||
snprintf(servername, sizeof(servername), NIPQUAD_FMT,
|
case AF_INET: {
|
||||||
NIPQUAD(addr->sin_addr.s_addr));
|
struct sockaddr_in *sin =
|
||||||
|
(struct sockaddr_in *)args->address;
|
||||||
|
snprintf(servername, sizeof(servername), NIPQUAD_FMT,
|
||||||
|
NIPQUAD(sin->sin_addr.s_addr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AF_INET6: {
|
||||||
|
struct sockaddr_in6 *sin =
|
||||||
|
(struct sockaddr_in6 *)args->address;
|
||||||
|
snprintf(servername, sizeof(servername), NIP6_FMT,
|
||||||
|
NIP6(sin->sin6_addr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
/* caller wants default server name, but
|
||||||
|
* address family isn't recognized. */
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
args->servername = servername;
|
args->servername = servername;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xprt = xprt_create_transport(&xprtargs);
|
||||||
|
if (IS_ERR(xprt))
|
||||||
|
return (struct rpc_clnt *)xprt;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* By default, kernel RPC client connects from a reserved port.
|
* By default, kernel RPC client connects from a reserved port.
|
||||||
* CAP_NET_BIND_SERVICE will not be set for unprivileged requesters,
|
* CAP_NET_BIND_SERVICE will not be set for unprivileged requesters,
|
||||||
|
Loading…
Reference in New Issue
Block a user