SUNRPC: create API for getting remote peer address
authorChuck Lever <chuck.lever@oracle.com>
Wed, 23 Aug 2006 00:06:17 +0000 (20:06 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Sat, 23 Sep 2006 03:24:45 +0000 (23:24 -0400)
Provide an API for retrieving the remote peer address without allowing
direct access to the rpc_xprt struct.

Test-plan:
Compile kernel with CONFIG_NFS enabled.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
include/linux/sunrpc/clnt.h
net/sunrpc/clnt.c

index 2e68ac0aa0225a31ed78228e0a2df5177d664d3a..65196b03f0abe73d681ddc9472a81642375e469e 100644 (file)
@@ -123,6 +123,7 @@ void                rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
 size_t         rpc_max_payload(struct rpc_clnt *);
 void           rpc_force_rebind(struct rpc_clnt *);
 int            rpc_ping(struct rpc_clnt *clnt, int flags);
+size_t         rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
 
 /*
  * Helper function for NFSroot support
index d003c2f5688f8447a49c18ce29ce0a3d2994bea9..94768cf5fd5bb8ad071ace4f371d07a36ca0e05d 100644 (file)
@@ -533,6 +533,27 @@ rpc_call_setup(struct rpc_task *task, struct rpc_message *msg, int flags)
                task->tk_action = rpc_exit_task;
 }
 
+/**
+ * rpc_peeraddr - extract remote peer address from clnt's xprt
+ * @clnt: RPC client structure
+ * @buf: target buffer
+ * @size: length of target buffer
+ *
+ * Returns the number of bytes that are actually in the stored address.
+ */
+size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize)
+{
+       size_t bytes;
+       struct rpc_xprt *xprt = clnt->cl_xprt;
+
+       bytes = sizeof(xprt->addr);
+       if (bytes > bufsize)
+               bytes = bufsize;
+       memcpy(buf, &clnt->cl_xprt->addr, bytes);
+       return sizeof(xprt->addr);
+}
+EXPORT_SYMBOL(rpc_peeraddr);
+
 void
 rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
 {