Skip to content

Commit b8eace7

Browse files
neilbrowngregkh
authored andcommitted
SUNRPC: prevent port reuse on transports which don't request it.
[ Upstream commit bc1c56e ] If an RPC client is created without RPC_CLNT_CREATE_REUSEPORT, it should not reuse the source port when a TCP connection is re-established. This is currently implemented by preventing the source port being recorded after a successful connection (the call to xs_set_srcport()). However the source port is also recorded after a successful bind in xs_bind(). This may not be needed at all and certainly is not wanted when RPC_CLNT_CREATE_REUSEPORT wasn't requested. So avoid that assignment when xprt.reuseport is not set. With this change, NFSv4.1 and later mounts use a different port number on each connection. This is helpful with some firewalls which don't cope well with port reuse. Signed-off-by: NeilBrown <neilb@suse.de> Fixes: e6237b6 ("NFSv4.1: Don't rebind to the same source port when reconnecting to the server") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5577eec commit b8eace7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎net/sunrpc/xprtsock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,8 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
16801680
err = kernel_bind(sock, (struct sockaddr *)&myaddr,
16811681
transport->xprt.addrlen);
16821682
if (err == 0) {
1683-
transport->srcport = port;
1683+
if (transport->xprt.reuseport)
1684+
transport->srcport = port;
16841685
break;
16851686
}
16861687
last = port;

0 commit comments

Comments
 (0)