xref: /linux/net/ipv4/tcp_dctcp.h (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1*ffd177deSYuchung Cheng #ifndef _TCP_DCTCP_H
2*ffd177deSYuchung Cheng #define _TCP_DCTCP_H
3*ffd177deSYuchung Cheng 
dctcp_ece_ack_cwr(struct sock * sk,u32 ce_state)4*ffd177deSYuchung Cheng static inline void dctcp_ece_ack_cwr(struct sock *sk, u32 ce_state)
5*ffd177deSYuchung Cheng {
6*ffd177deSYuchung Cheng 	struct tcp_sock *tp = tcp_sk(sk);
7*ffd177deSYuchung Cheng 
8*ffd177deSYuchung Cheng 	if (ce_state == 1)
9*ffd177deSYuchung Cheng 		tp->ecn_flags |= TCP_ECN_DEMAND_CWR;
10*ffd177deSYuchung Cheng 	else
11*ffd177deSYuchung Cheng 		tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
12*ffd177deSYuchung Cheng }
13*ffd177deSYuchung Cheng 
14*ffd177deSYuchung Cheng /* Minimal DCTP CE state machine:
15*ffd177deSYuchung Cheng  *
16*ffd177deSYuchung Cheng  * S:	0 <- last pkt was non-CE
17*ffd177deSYuchung Cheng  *	1 <- last pkt was CE
18*ffd177deSYuchung Cheng  */
dctcp_ece_ack_update(struct sock * sk,enum tcp_ca_event evt,u32 * prior_rcv_nxt,u32 * ce_state)19*ffd177deSYuchung Cheng static inline void dctcp_ece_ack_update(struct sock *sk, enum tcp_ca_event evt,
20*ffd177deSYuchung Cheng 					u32 *prior_rcv_nxt, u32 *ce_state)
21*ffd177deSYuchung Cheng {
22*ffd177deSYuchung Cheng 	u32 new_ce_state = (evt == CA_EVENT_ECN_IS_CE) ? 1 : 0;
23*ffd177deSYuchung Cheng 
24*ffd177deSYuchung Cheng 	if (*ce_state != new_ce_state) {
25*ffd177deSYuchung Cheng 		/* CE state has changed, force an immediate ACK to
26*ffd177deSYuchung Cheng 		 * reflect the new CE state. If an ACK was delayed,
27*ffd177deSYuchung Cheng 		 * send that first to reflect the prior CE state.
28*ffd177deSYuchung Cheng 		 */
29*ffd177deSYuchung Cheng 		if (inet_csk(sk)->icsk_ack.pending & ICSK_ACK_TIMER) {
30*ffd177deSYuchung Cheng 			dctcp_ece_ack_cwr(sk, *ce_state);
31*ffd177deSYuchung Cheng 			__tcp_send_ack(sk, *prior_rcv_nxt);
32*ffd177deSYuchung Cheng 		}
33*ffd177deSYuchung Cheng 		inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW;
34*ffd177deSYuchung Cheng 	}
35*ffd177deSYuchung Cheng 	*prior_rcv_nxt = tcp_sk(sk)->rcv_nxt;
36*ffd177deSYuchung Cheng 	*ce_state = new_ce_state;
37*ffd177deSYuchung Cheng 	dctcp_ece_ack_cwr(sk, new_ce_state);
38*ffd177deSYuchung Cheng }
39*ffd177deSYuchung Cheng 
40*ffd177deSYuchung Cheng #endif
41