Commit 74703901 authored by Gleb Smirnoff's avatar Gleb Smirnoff
Browse files

tcp: use a TCP flag to check if connection has been close(2)d

The flag SS_NOFDREF is a private flag of the socket layer.  It also
is supposed to be read with SOCK_LOCK(), which we don't own here.

Reviewed by:		rrs, tuexen
Differential revision:	https://reviews.freebsd.org/D35663
parent 97dbd377
......@@ -2315,8 +2315,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
* If new data are received on a connection after the
* user processes are gone, then RST the other end.
*/
if ((so->so_state & SS_NOFDREF) &&
tp->t_state > TCPS_CLOSE_WAIT && tlen) {
if ((tp->t_flags & TF_CLOSED) && tlen) {
if ((s = tcp_log_addrs(inc, th, NULL, NULL))) {
log(LOG_DEBUG, "%s; %s: %s: Received %d bytes of data "
"after socket was closed, "
......
......@@ -9493,15 +9493,12 @@ bbr_do_fin_wait_1(struct mbuf *m, struct tcphdr *th, struct socket *so,
/*
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if ((so->so_state & SS_NOFDREF) && tlen) {
/*
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......@@ -9620,15 +9617,12 @@ bbr_do_closing(struct mbuf *m, struct tcphdr *th, struct socket *so,
/*
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if ((so->so_state & SS_NOFDREF) && tlen) {
/*
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......@@ -9733,15 +9727,12 @@ bbr_do_lastack(struct mbuf *m, struct tcphdr *th, struct socket *so,
/*
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if ((so->so_state & SS_NOFDREF) && tlen) {
/*
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......@@ -9850,17 +9841,12 @@ bbr_do_fin_wait_2(struct mbuf *m, struct tcphdr *th, struct socket *so,
* If new data are received on a connection after the user processes
* are gone, then we may RST the other end depending on the outcome
* of bbr_check_data_after_close.
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if ((so->so_state & SS_NOFDREF) &&
tlen) {
/*
* We call a new function now so we might continue and setup
* to reset at all data being ack'd.
*/
if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
}
INP_WLOCK_ASSERT(tp->t_inpcb);
if (tp->t_state > TCPS_CLOSE_WAIT && tlen &&
bbr_check_data_after_close(m, bbr, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......
......@@ -11855,10 +11855,9 @@ rack_do_fin_wait_1(struct mbuf *m, struct tcphdr *th, struct socket *so,
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
*/
if ((so->so_state & SS_NOFDREF) && tlen) {
if (rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......@@ -11983,10 +11982,9 @@ rack_do_closing(struct mbuf *m, struct tcphdr *th, struct socket *so,
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
*/
if ((so->so_state & SS_NOFDREF) && tlen) {
if (rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......@@ -12097,10 +12095,9 @@ rack_do_lastack(struct mbuf *m, struct tcphdr *th, struct socket *so,
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
*/
if ((so->so_state & SS_NOFDREF) && tlen) {
if (rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......@@ -12212,11 +12209,9 @@ rack_do_fin_wait_2(struct mbuf *m, struct tcphdr *th, struct socket *so,
* If new data are received on a connection after the user processes
* are gone, then RST the other end.
*/
if ((so->so_state & SS_NOFDREF) &&
tlen) {
if (rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
}
if ((tp->t_flags & TF_CLOSED) && tlen &&
rack_check_data_after_close(m, tp, &tlen, th, so))
return (1);
/*
* If last ACK falls within this segment's sequence numbers, record
* its timestamp. NOTE: 1) That the test incorporates suggestions
......
......@@ -1406,6 +1406,7 @@ tcp_usr_close(struct socket *so)
if (!(inp->inp_flags & INP_TIMEWAIT) &&
!(inp->inp_flags & INP_DROPPED)) {
tp = intotcpcb(inp);
tp->t_flags |= TF_CLOSED;
TCPDEBUG1();
tcp_disconnect(tp);
TCPDEBUG2(PRU_CLOSE);
......
......@@ -524,7 +524,7 @@ tcp_unlock_or_drop(struct tcpcb *tp, int tcp_output_retval)
#define TF_FORCEDATA 0x00800000 /* force out a byte */
#define TF_TSO 0x01000000 /* TSO enabled on this connection */
#define TF_TOE 0x02000000 /* this connection is offloaded */
#define TF_UNUSED0 0x04000000 /* unused */
#define TF_CLOSED 0x04000000 /* close(2) called on socket */
#define TF_UNUSED1 0x08000000 /* unused */
#define TF_LRD 0x10000000 /* Lost Retransmission Detection */
#define TF_CONGRECOVERY 0x20000000 /* congestion recovery mode */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment