From patchwork Thu Jun 23 19:29:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 913472 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5NJTvZZ000782 for ; Thu, 23 Jun 2011 19:30:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933003Ab1FWTaH (ORCPT ); Thu, 23 Jun 2011 15:30:07 -0400 Received: from mail.candelatech.com ([208.74.158.172]:43990 "EHLO ns3.lanforge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932729Ab1FWTaH (ORCPT ); Thu, 23 Jun 2011 15:30:07 -0400 Received: from localhost.localdomain (firewall.candelatech.com [70.89.124.249]) by ns3.lanforge.com (8.14.2/8.14.2) with ESMTP id p5NJTq57001237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 23 Jun 2011 12:29:54 -0700 From: greearb@candelatech.com To: linux-nfs@vger.kernel.org Cc: Ben Greear Subject: [PATCH v2 10/12] nfs: Bind to srcaddr in rpcb_create. Date: Thu, 23 Jun 2011 12:29:44 -0700 Message-Id: <1308857388-12243-11-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1308857388-12243-1-git-send-email-greearb@candelatech.com> References: <1308857388-12243-1-git-send-email-greearb@candelatech.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 23 Jun 2011 19:30:09 +0000 (UTC) From: Ben Greear This more properly clones the existing client connection settings, allowing rpc calls to take advantage of routing rules based on source IP addresses. Signed-off-by: Ben Greear --- :100644 100644 9a80a92... 4985e18... M net/sunrpc/rpcb_clnt.c :100644 100644 90c292e... 22841e1... M net/sunrpc/sunrpc.h :100644 100644 37299c0... 72408c2... M net/sunrpc/xprtsock.c net/sunrpc/rpcb_clnt.c | 28 ++++++++++++++++++++++++++-- net/sunrpc/sunrpc.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ net/sunrpc/xprtsock.c | 43 ------------------------------------------- 3 files changed, 71 insertions(+), 45 deletions(-) diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index 9a80a92..4985e18 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c @@ -28,6 +28,7 @@ #include #include #include +#include "sunrpc.h" #ifdef RPC_DEBUG # define RPCDBG_FACILITY RPCDBG_BIND @@ -292,11 +293,13 @@ out: } static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, - size_t salen, int proto, u32 version) + size_t salen, int proto, u32 version, + struct sockaddr *srcaddr) { struct rpc_create_args args = { .net = &init_net, .protocol = proto, + .saddress = srcaddr, .address = srvaddr, .addrsize = salen, .servername = hostname, @@ -601,11 +604,32 @@ void rpcb_getport_async(struct rpc_task *task) struct rpc_task *child; struct sockaddr_storage addr; struct sockaddr *sap = (struct sockaddr *)&addr; + struct sockaddr_storage srcaddr; + struct sockaddr *srcaddra = NULL; size_t salen; int status; + struct sock_xprt *sxprt; clnt = rpcb_find_transport_owner(task->tk_client); xprt = clnt->cl_xprt; + sxprt = container_of(xprt, struct sock_xprt, xprt); + + /* We just want to bind to the IP, not the port */ + memset(&srcaddr, 0, sizeof(srcaddr)); + srcaddr.ss_family = sxprt->srcaddr.ss_family; + if (sxprt->srcaddr.ss_family == AF_INET) { + struct sockaddr_in *si = (struct sockaddr_in *)(&srcaddr); + struct sockaddr_in *si2; + si2 = (struct sockaddr_in *)(&sxprt->srcaddr); + si->sin_addr.s_addr = si2->sin_addr.s_addr; + srcaddra = (struct sockaddr *)(&srcaddr); + } else if (sxprt->srcaddr.ss_family == AF_INET6) { + struct sockaddr_in6 *si = (struct sockaddr_in6 *)(&srcaddr); + struct sockaddr_in6 *si2; + si2 = (struct sockaddr_in6 *)(&sxprt->srcaddr); + memcpy(&si->sin6_addr, &si2->sin6_addr, sizeof(si2->sin6_addr)); + srcaddra = (struct sockaddr *)(&srcaddr); + } dprintk("RPC: %5u %s(%s, %u, %u, %d)\n", task->tk_pid, __func__, @@ -660,7 +684,7 @@ void rpcb_getport_async(struct rpc_task *task) task->tk_pid, __func__, bind_version); rpcb_clnt = rpcb_create(clnt->cl_server, sap, salen, xprt->prot, - bind_version); + bind_version, srcaddra); if (IS_ERR(rpcb_clnt)) { status = PTR_ERR(rpcb_clnt); dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n", diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h index 90c292e..22841e1 100644 --- a/net/sunrpc/sunrpc.h +++ b/net/sunrpc/sunrpc.h @@ -37,6 +37,51 @@ struct rpc_buffer { char data[]; }; +struct sock_xprt { + struct rpc_xprt xprt; + + /* + * Network layer + */ + struct socket *sock; + struct sock *inet; + + /* + * State of TCP reply receive + */ + __be32 tcp_fraghdr, + tcp_xid, + tcp_calldir; + + u32 tcp_offset, + tcp_reclen; + + unsigned long tcp_copied, + tcp_flags; + + /* + * Connection of transports + */ + struct delayed_work connect_worker; + struct sockaddr_storage srcaddr; + unsigned short srcport; + + /* + * UDP socket buffer size parameters + */ + size_t rcvsize, + sndsize; + + /* + * Saved socket callback addresses + */ + void (*old_data_ready)(struct sock *, int); + void (*old_state_change)(struct sock *); + void (*old_write_space)(struct sock *); + void (*old_error_report)(struct sock *); +}; + + static inline int rpc_reply_expected(struct rpc_task *task) { return (task->tk_msg.rpc_proc != NULL) && diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 37299c0..72408c2 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -202,49 +202,6 @@ static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count) } #endif -struct sock_xprt { - struct rpc_xprt xprt; - - /* - * Network layer - */ - struct socket * sock; - struct sock * inet; - - /* - * State of TCP reply receive - */ - __be32 tcp_fraghdr, - tcp_xid, - tcp_calldir; - - u32 tcp_offset, - tcp_reclen; - - unsigned long tcp_copied, - tcp_flags; - - /* - * Connection of transports - */ - struct delayed_work connect_worker; - struct sockaddr_storage srcaddr; - unsigned short srcport; - - /* - * UDP socket buffer size parameters - */ - size_t rcvsize, - sndsize; - - /* - * Saved socket callback addresses - */ - void (*old_data_ready)(struct sock *, int); - void (*old_state_change)(struct sock *); - void (*old_write_space)(struct sock *); - void (*old_error_report)(struct sock *); -}; /* * TCP receive state flags