aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2023-02-07 17:21:52 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2023-02-07 17:21:52 +0000
commitdfc4d218ce5d9e1d1d2be09c6cfc3d1c89ad27ff (patch)
tree9b6c422f3e2a825573c282493da58cced14ad2e9
parent8932f7ce1783a10e9ba79c61d54077aa7693552e (diff)
tcp: use straight in_pcbconnect() in tcp_connect()
This brings tcp_connect() par with tcp6_connect(). The code removed now is a remnant of "truncating old TIME-WAIT" removed back in 2004 in c94c54e4df9a. Reviewed by: markj, tuexen Differential Revision: https://reviews.freebsd.org/D38405
-rw-r--r--sys/netinet/tcp_usrreq.c35
1 files changed, 6 insertions, 29 deletions
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 2ae1c4b89c8e..c204fc356ed7 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1387,48 +1387,25 @@ struct protosw tcp6_protosw = {
#ifdef INET
/*
* Common subroutine to open a TCP connection to remote host specified
- * by struct sockaddr_in. Call in_pcbconnect_setup() to choose local
- * host address and assign a local port number if needed. Initialize
- * connection parameters and enter SYN-SENT state.
+ * by struct sockaddr_in. Call in_pcbconnect() to choose local host address
+ * and assign a local port number and install the inpcb into the hash.
+ * Initialize connection parameters and enter SYN-SENT state.
*/
static int
tcp_connect(struct tcpcb *tp, struct sockaddr_in *sin, struct thread *td)
{
struct inpcb *inp = tptoinpcb(tp);
struct socket *so = tptosocket(tp);
- struct in_addr laddr;
- u_short lport;
int error;
NET_EPOCH_ASSERT();
INP_WLOCK_ASSERT(inp);
INP_HASH_WLOCK(&V_tcbinfo);
- /*
- * Cannot simply call in_pcbconnect, because there might be an
- * earlier incarnation of this same connection still in
- * TIME_WAIT state, creating an ADDRINUSE error.
- */
- laddr = inp->inp_laddr;
- lport = inp->inp_lport;
- error = in_pcbconnect_setup(inp, sin, &laddr.s_addr, &lport,
- &inp->inp_faddr.s_addr, &inp->inp_fport, td->td_ucred);
- if (error) {
- INP_HASH_WUNLOCK(&V_tcbinfo);
- return (error);
- }
- /* Handle initial bind if it hadn't been done in advance. */
- if (inp->inp_lport == 0) {
- inp->inp_lport = lport;
- if (in_pcbinshash(inp) != 0) {
- inp->inp_lport = 0;
- INP_HASH_WUNLOCK(&V_tcbinfo);
- return (EAGAIN);
- }
- }
- inp->inp_laddr = laddr;
- in_pcbrehash(inp);
+ error = in_pcbconnect(inp, sin, td->td_ucred, true);
INP_HASH_WUNLOCK(&V_tcbinfo);
+ if (error != 0)
+ return (error);
/*
* Compute window scaling to request: