You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gu...@apache.org on 2021/05/14 01:33:24 UTC
[incubator-nuttx] 03/05: fs: nfs: Do not bind to a local port in
TCP mode
This is an automated email from the ASF dual-hosted git repository.
gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit e1b14271c85f4aa0a23dfa2036afae7d53e9817c
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Wed May 12 13:58:20 2021 +0900
fs: nfs: Do not bind to a local port in TCP mode
Summary:
- Since binding to a local port is not necessary in TCP mode,
it should be done only in UDP mode
Impact:
- None
Testing:
- Tested with NFS server on Ubuntu 18.04 (x86_64)
- Tested with spresense:rndis (defconfig will be updated later)
Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
fs/nfs/rpc_clnt.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/fs/nfs/rpc_clnt.c b/fs/nfs/rpc_clnt.c
index 46ee90b..cdc029d 100644
--- a/fs/nfs/rpc_clnt.c
+++ b/fs/nfs/rpc_clnt.c
@@ -241,27 +241,30 @@ static int rpcclnt_socket(FAR struct rpcclnt *rpc, in_port_t rport)
goto bad;
}
- /* Some servers require that the client port be a reserved port
- * number. We always allocate a reserved port, as this prevents
- * filehandle disclosure through UDP port capture.
- */
-
- do
+ if (rpc->rc_sotype == SOCK_DGRAM)
{
- *lport = htons(--port);
- error = psock_bind(&rpc->rc_so, (FAR struct sockaddr *)&laddr,
- addrlen);
- if (error < 0)
+ /* Some servers require that the client port be a reserved port
+ * number. We always allocate a reserved port, as this prevents
+ * filehandle disclosure through UDP port capture.
+ */
+
+ do
{
- ferr("ERROR: psock_bind failed: %d\n", error);
+ *lport = htons(--port);
+ error = psock_bind(&rpc->rc_so, (FAR struct sockaddr *)&laddr,
+ addrlen);
+ if (error < 0)
+ {
+ ferr("ERROR: psock_bind failed: %d\n", error);
+ }
}
- }
- while (error == -EADDRINUSE && port >= 512);
+ while (error == -EADDRINUSE && port >= 512);
- if (error)
- {
- ferr("ERROR: psock_bind failed: %d\n", error);
- goto bad;
+ if (error)
+ {
+ ferr("ERROR: psock_bind failed: %d\n", error);
+ goto bad;
+ }
}
/* Protocols that do not require connections could be optionally left