use of setsockopt(SO_LINGER)
Kevin Steves
kevin at atomicgears.com
Fri Sep 6 13:51:17 EST 2002
I would like to remove setsockopt(SO_LINGER), as there does not seem
to be a reason for its use. If you know of specific reasons we should
keep any of these let me know, or run this patch in local test trees
where possible.
This is against OpenBSD, but should apply to portable with some
fuzz.
Index: channels.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/channels.c,v
retrieving revision 1.180
diff -u -r1.180 channels.c
--- channels.c 4 Jul 2002 08:12:15 -0000 1.180
+++ channels.c 4 Sep 2002 17:12:51 -0000
@@ -2016,7 +2016,6 @@
struct addrinfo hints, *ai, *aitop;
const char *host;
char ntop[NI_MAXHOST], strport[NI_MAXSERV];
- struct linger linger;
success = 0;
host = (type == SSH_CHANNEL_RPORT_LISTENER) ?
@@ -2059,13 +2058,13 @@
continue;
}
/*
- * Set socket options. We would like the socket to disappear
- * as soon as it has been closed for whatever reason.
+ * Set socket options.
+ * Allow local port reuse in TIME_WAIT.
*/
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- linger.l_onoff = 1;
- linger.l_linger = 5;
- setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on,
+ sizeof(on)) == -1)
+ error("setsockopt SO_REUSEADDR: %s", strerror(errno));
+
debug("Local forwarding listening on %s port %s.", ntop, strport);
/* Bind the socket to the address. */
Index: sshconnect.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sshconnect.c,v
retrieving revision 1.133
diff -u -r1.133 sshconnect.c
--- sshconnect.c 29 Jul 2002 18:57:30 -0000 1.133
+++ sshconnect.c 4 Sep 2002 17:12:53 -0000
@@ -225,7 +225,6 @@
int sock = -1, attempt;
char ntop[NI_MAXHOST], strport[NI_MAXSERV];
struct addrinfo hints, *ai, *aitop;
- struct linger linger;
struct servent *sp;
/*
* Did we get only other errors than "Connection refused" (which
@@ -325,15 +324,6 @@
}
debug("Connection established.");
-
- /*
- * Set socket options. We would like the socket to disappear as soon
- * as it has been closed for whatever reason.
- */
- /* setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); */
- linger.l_onoff = 1;
- linger.l_linger = 5;
- setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger));
/* Set keepalives if requested. */
if (options.keepalives &&
Index: sshd.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sshd.c,v
retrieving revision 1.257
diff -u -r1.257 sshd.c
--- sshd.c 23 Jul 2002 16:03:10 -0000 1.257
+++ sshd.c 4 Sep 2002 17:12:55 -0000
@@ -789,7 +789,6 @@
const char *remote_ip;
int remote_port;
FILE *f;
- struct linger linger;
struct addrinfo *ai;
char ntop[NI_MAXHOST], strport[NI_MAXSERV];
int listen_sock, maxfd;
@@ -1102,17 +1101,12 @@
continue;
}
/*
- * Set socket options. We try to make the port
- * reusable and have it close as fast as possible
- * without waiting in unnecessary wait states on
- * close.
+ * Set socket options.
+ * Allow local port reuse in TIME_WAIT.
*/
- setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR,
- &on, sizeof(on));
- linger.l_onoff = 1;
- linger.l_linger = 5;
- setsockopt(listen_sock, SOL_SOCKET, SO_LINGER,
- &linger, sizeof(linger));
+ if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR,
+ &on, sizeof(on)) == -1)
+ error("setsockopt SO_REUSEADDR: %s", strerror(errno));
debug("Bind to port %s on %s.", strport, ntop);
@@ -1355,16 +1349,6 @@
signal(SIGTERM, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
-
- /*
- * Set socket options for the connection. We want the socket to
- * close as fast as possible without waiting for anything. If the
- * connection is not a socket, these will do nothing.
- */
- /* setsockopt(sock_in, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); */
- linger.l_onoff = 1;
- linger.l_linger = 5;
- setsockopt(sock_in, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
/* Set keepalives if requested. */
if (options.keepalives &&
More information about the openssh-unix-dev
mailing list