Skip to content

Commit 2eb786d

Browse files
committed
tcp: rate limit the sending of all RST segments
Also rate limit the sending of RST segments in the following cases: * when receiving data on a closed socket. * when a socket can not be created at the end of the handshake and the sysctl-variable net.inet.tcp.syncache.rst_on_sock_fail is 1. * when an ACK segment is received in SYN SENT state and it does not acknowledge the SYN segment. After this change, there is no need anymore to provide a rstreason to tcp_dropwithreset(), since it is always BANDLIM_TCP_RST. This will be a follow-up commit, since it will change the code in a couple of places, but will not change the functionality. Reviewed by: rrs, Nick Banks, Peter Lei MFC after: 1 week Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D51815
1 parent b6521ce commit 2eb786d

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

sys/netinet/tcp_input.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ tcp_input_with_port(struct mbuf **mp, int *offp, int proto, uint16_t port)
11341134
V_tcp_sc_rst_sock_fail ?
11351135
"sending RST" : "try again");
11361136
if (V_tcp_sc_rst_sock_fail) {
1137-
rstreason = BANDLIM_UNLIMITED;
1137+
rstreason = BANDLIM_TCP_RST;
11381138
goto dropwithreset;
11391139
} else
11401140
goto dropunlock;
@@ -1568,7 +1568,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th,
15681568
*/
15691569
if ((tp->t_state == TCPS_SYN_SENT) && (thflags & TH_ACK) &&
15701570
(SEQ_LEQ(th->th_ack, tp->iss) || SEQ_GT(th->th_ack, tp->snd_max))) {
1571-
rstreason = BANDLIM_UNLIMITED;
1571+
rstreason = BANDLIM_TCP_RST;
15721572
tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT);
15731573
goto dropwithreset;
15741574
}
@@ -2346,7 +2346,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th,
23462346
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
23472347
tp = tcp_close(tp);
23482348
TCPSTAT_INC(tcps_rcvafterclose);
2349-
rstreason = BANDLIM_UNLIMITED;
2349+
rstreason = BANDLIM_TCP_RST;
23502350
goto dropwithreset;
23512351
}
23522352

sys/netinet/tcp_stacks/bbr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7863,7 +7863,7 @@ bbr_process_ack(struct mbuf *m, struct tcphdr *th, struct socket *so,
78637863
/* tcp_close will kill the inp pre-log the Reset */
78647864
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
78657865
tp = tcp_close(tp);
7866-
ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, tlen);
7866+
ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, tlen);
78677867
BBR_STAT_INC(bbr_dropped_af_data);
78687868
return (1);
78697869
}
@@ -9405,7 +9405,7 @@ bbr_check_data_after_close(struct mbuf *m, struct tcp_bbr *bbr,
94059405
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
94069406
tp = tcp_close(tp);
94079407
KMOD_TCPSTAT_INC(tcps_rcvafterclose);
9408-
ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, (*tlen));
9408+
ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, (*tlen));
94099409
return (1);
94109410
}
94119411
if (sbavail(&so->so_snd) == 0)

sys/netinet/tcp_stacks/rack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12038,7 +12038,7 @@ rack_process_ack(struct mbuf *m, struct tcphdr *th, struct socket *so,
1203812038
/* tcp_close will kill the inp pre-log the Reset */
1203912039
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
1204012040
tp = tcp_close(tp);
12041-
ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, tlen);
12041+
ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, tlen);
1204212042
return (1);
1204312043
}
1204412044
}
@@ -13518,7 +13518,7 @@ rack_check_data_after_close(struct mbuf *m,
1351813518
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
1351913519
tp = tcp_close(tp);
1352013520
KMOD_TCPSTAT_INC(tcps_rcvafterclose);
13521-
ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, (*tlen));
13521+
ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, (*tlen));
1352213522
return (1);
1352313523
}
1352413524
if (sbavail(&so->so_snd) == 0)

0 commit comments

Comments
 (0)