File 0191-mount-don-t-bind-a-socket-needlessly.patch of Package nfs-utils.33226
From ccff2763d001517aa09dda37a3d0ed7a08be0b5a Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Tue, 3 Aug 2021 11:57:11 +1000
Subject: [PATCH] mount: don't bind a socket needlessly.
When clnt_ping() calls get_socket(), get_socket() will create a socket,
call bind() to choose an unused local port, and then connect to the
given address.
The "bind()" call is unnecessary and problematic.
It is unnecessary as the "connect()" call will bind the socket as
required.
It is problematic as it requires a completely unused port number, rather
than just a port number which isn't currently in use for connecting to
the given remote address.
If all local ports (net.ipv4.ip_local_port_range) are in use, the bind()
will fail. However the connect() call will only fail if all those port
are in use for connecting to the same address.
So remove the unnecessary bind() call.
Signed-off-by: NeilBrown <neilb@suse.de>
---
utils/mount/network.c | 4 ----
1 file changed, 4 deletions(-)
--- a/utils/mount/network.c
+++ b/utils/mount/network.c
@@ -423,10 +423,6 @@ static int get_socket(struct sockaddr_in
if (resvp) {
if (bindresvport(so, &laddr) < 0)
goto err_bindresvport;
- } else {
- cc = bind(so, SAFE_SOCKADDR(&laddr), namelen);
- if (cc < 0)
- goto err_bind;
}
if (type == SOCK_STREAM || (conn && type == SOCK_DGRAM)) {
cc = connect_to(so, SAFE_SOCKADDR(saddr), namelen,