git: dfc4d218ce5d - main - tcp: use straight in_pcbconnect() in tcp_connect()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 07 Feb 2023 17:22:42 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=dfc4d218ce5d9e1d1d2be09c6cfc3d1c89ad27ff commit dfc4d218ce5d9e1d1d2be09c6cfc3d1c89ad27ff Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2023-02-07 17:21:52 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2023-02-07 17:21:52 +0000 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 --- sys/netinet/tcp_usrreq.c | 35 ++++++----------------------------- 1 file 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: