The TFO server-side code contains some changes that are not conditioned on

the TCP_RFC7413 kernel option. This change removes those few instructions
from the packet processing path.

While not strictly necessary, for the sake of consistency, I applied the
new IS_FASTOPEN macro to all places in the packet processing path that
used the (t_flags & TF_FASTOPEN) check.

Reviewed by:	hiren
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D8219
This commit is contained in:
Jonathan T. Looney 2016-10-12 19:06:50 +00:00
parent de1cac0d4b
commit 68bd7ed102
5 changed files with 28 additions and 13 deletions

View File

@ -1028,7 +1028,7 @@ tcp_input(struct mbuf **mp, int *offp, int proto)
#endif
if (!((tp->t_state == TCPS_ESTABLISHED && (thflags & TH_SYN) == 0) ||
(tp->t_state == TCPS_LISTEN && (thflags & TH_SYN) &&
!(tp->t_flags & TF_FASTOPEN)))) {
!IS_FASTOPEN(tp->t_flags)))) {
if (ti_locked == TI_UNLOCKED) {
if (INP_INFO_TRY_RLOCK(&V_tcbinfo) == 0) {
in_pcbref(inp);
@ -1506,7 +1506,9 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
struct in_conninfo *inc;
struct mbuf *mfree;
struct tcpopt to;
#ifdef TCP_RFC7413
int tfo_syn;
#endif
#ifdef TCPDEBUG
/*
@ -1964,7 +1966,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
goto dropwithreset;
}
#ifdef TCP_RFC7413
if (tp->t_flags & TF_FASTOPEN) {
if (IS_FASTOPEN(tp->t_flags)) {
/*
* When a TFO connection is in SYN_RECEIVED, the
* only valid packets are the initial SYN, a
@ -2398,7 +2400,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
(tp->t_flags & TF_NEEDSYN)) {
#ifdef TCP_RFC7413
if (tp->t_state == TCPS_SYN_RECEIVED &&
tp->t_flags & TF_FASTOPEN) {
IS_FASTOPEN(tp->t_flags)) {
tp->snd_wnd = tiwin;
cc_conn_init(tp);
}
@ -2461,7 +2463,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
* snd_cwnd reduction that occurs when a TFO SYN|ACK
* is retransmitted.
*/
if (!(tp->t_flags & TF_FASTOPEN))
if (!IS_FASTOPEN(tp->t_flags))
#endif
cc_conn_init(tp);
tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp));
@ -3028,8 +3030,12 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
* case PRU_RCVD). If a FIN has already been received on this
* connection then we just ignore the text.
*/
#ifdef TCP_RFC7413
tfo_syn = ((tp->t_state == TCPS_SYN_RECEIVED) &&
(tp->t_flags & TF_FASTOPEN));
IS_FASTOPEN(tp->t_flags));
#else
#define tfo_syn (false)
#endif
if ((tlen || (thflags & TH_FIN) || tfo_syn) &&
TCPS_HAVERCVDFIN(tp->t_state) == 0) {
tcp_seq save_start = th->th_seq;
@ -3253,6 +3259,9 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so,
if (tp != NULL)
INP_WUNLOCK(tp->t_inpcb);
m_freem(m);
#ifndef TCP_RFC7413
#undef tfo_syn
#endif
}
/*

View File

@ -230,7 +230,7 @@ tcp_output(struct tcpcb *tp)
* For TFO connections in SYN_RECEIVED, only allow the initial
* SYN|ACK and those sent by the retransmit timer.
*/
if ((tp->t_flags & TF_FASTOPEN) &&
if (IS_FASTOPEN(tp->t_flags) &&
(tp->t_state == TCPS_SYN_RECEIVED) &&
SEQ_GT(tp->snd_max, tp->snd_una) && /* initial SYN|ACK sent */
(tp->snd_nxt != tp->snd_una)) /* not a retransmit */
@ -426,7 +426,7 @@ tcp_output(struct tcpcb *tp)
* When sending additional segments following a TFO SYN|ACK,
* do not include the SYN bit.
*/
if ((tp->t_flags & TF_FASTOPEN) &&
if (IS_FASTOPEN(tp->t_flags) &&
(tp->t_state == TCPS_SYN_RECEIVED))
flags &= ~TH_SYN;
#endif
@ -449,7 +449,7 @@ tcp_output(struct tcpcb *tp)
* don't include data, as the presence of data may have caused the
* original SYN|ACK to have been dropped by a middlebox.
*/
if ((tp->t_flags & TF_FASTOPEN) &&
if (IS_FASTOPEN(tp->t_flags) &&
(((tp->t_state == TCPS_SYN_RECEIVED) && (tp->t_rxtshift > 0)) ||
(flags & TH_RST)))
len = 0;
@ -786,7 +786,7 @@ tcp_output(struct tcpcb *tp)
* the TFO option may have caused the original
* SYN|ACK to have been dropped by a middlebox.
*/
if ((tp->t_flags & TF_FASTOPEN) &&
if (IS_FASTOPEN(tp->t_flags) &&
(tp->t_state == TCPS_SYN_RECEIVED) &&
(tp->t_rxtshift == 0)) {
to.to_tfo_len = TCP_FASTOPEN_COOKIE_LEN;

View File

@ -1209,7 +1209,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
ltflags = (tp->t_flags & (TF_NOOPT | TF_SIGNATURE));
#ifdef TCP_RFC7413
if (V_tcp_fastopen_enabled && (tp->t_flags & TF_FASTOPEN) &&
if (V_tcp_fastopen_enabled && IS_FASTOPEN(tp->t_flags) &&
(tp->t_tfo_pending != NULL) && (to->to_flags & TOF_FASTOPEN)) {
/*
* Limit the number of pending TFO connections to

View File

@ -410,7 +410,7 @@ tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
SOCK_UNLOCK(so);
#ifdef TCP_RFC7413
if (tp->t_flags & TF_FASTOPEN)
if (IS_FASTOPEN(tp->t_flags))
tp->t_tfo_pending = tcp_fastopen_alloc_counter();
#endif
out:
@ -460,7 +460,7 @@ tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
SOCK_UNLOCK(so);
#ifdef TCP_RFC7413
if (tp->t_flags & TF_FASTOPEN)
if (IS_FASTOPEN(tp->t_flags))
tp->t_tfo_pending = tcp_fastopen_alloc_counter();
#endif
out:
@ -826,7 +826,7 @@ tcp_usr_rcvd(struct socket *so, int flags)
* application response data, or failing that, when the DELACK timer
* expires.
*/
if ((tp->t_flags & TF_FASTOPEN) &&
if (IS_FASTOPEN(tp->t_flags) &&
(tp->t_state == TCPS_SYN_RECEIVED))
goto out;
#endif

View File

@ -349,6 +349,12 @@ struct tcpcb {
#define ENTER_RECOVERY(t_flags) t_flags |= (TF_CONGRECOVERY | TF_FASTRECOVERY)
#define EXIT_RECOVERY(t_flags) t_flags &= ~(TF_CONGRECOVERY | TF_FASTRECOVERY)
#if defined(_KERNEL) && !defined(TCP_RFC7413)
#define IS_FASTOPEN(t_flags) (false)
#else
#define IS_FASTOPEN(t_flags) (t_flags & TF_FASTOPEN)
#endif
#define BYTES_THIS_ACK(tp, th) (th->th_ack - tp->snd_una)
/*