1 #ifndef _NET_TCP_ECN_H_
2 #define _NET_TCP_ECN_H_ 1
4 #include <net/inet_ecn.h>
5 #include <net/request_sock.h>
7 #define TCP_HP_BITS (~(TCP_RESERVED_BITS|TCP_FLAG_PSH))
10 #define TCP_ECN_QUEUE_CWR 2
11 #define TCP_ECN_DEMAND_CWR 4
13 static inline void TCP_ECN_queue_cwr(struct tcp_sock *tp)
15 if (tp->ecn_flags&TCP_ECN_OK)
16 tp->ecn_flags |= TCP_ECN_QUEUE_CWR;
20 /* Output functions */
22 static inline void TCP_ECN_send_synack(struct tcp_sock *tp,
25 TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_CWR;
26 if (!(tp->ecn_flags&TCP_ECN_OK))
27 TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_ECE;
30 static inline void TCP_ECN_send_syn(struct sock *sk, struct tcp_sock *tp,
35 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_ECE|TCPCB_FLAG_CWR;
36 tp->ecn_flags = TCP_ECN_OK;
40 static __inline__ void
41 TCP_ECN_make_synack(struct request_sock *req, struct tcphdr *th)
43 if (inet_rsk(req)->ecn_ok)
47 static inline void TCP_ECN_send(struct sock *sk, struct tcp_sock *tp,
48 struct sk_buff *skb, int tcp_header_len)
50 if (tp->ecn_flags & TCP_ECN_OK) {
51 /* Not-retransmitted data segment: set ECT and inject CWR. */
52 if (skb->len != tcp_header_len &&
53 !before(TCP_SKB_CB(skb)->seq, tp->snd_nxt)) {
55 if (tp->ecn_flags&TCP_ECN_QUEUE_CWR) {
56 tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR;
58 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
59 skb_shinfo(skb)->gso_type |=
63 /* ACK or retransmitted segment: clear ECT|CE */
64 INET_ECN_dontxmit(sk);
66 if (tp->ecn_flags & TCP_ECN_DEMAND_CWR)
73 static inline void TCP_ECN_accept_cwr(struct tcp_sock *tp, struct sk_buff *skb)
76 tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
79 static inline void TCP_ECN_withdraw_cwr(struct tcp_sock *tp)
81 tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
84 static inline void TCP_ECN_check_ce(struct tcp_sock *tp, struct sk_buff *skb)
86 if (tp->ecn_flags&TCP_ECN_OK) {
87 if (INET_ECN_is_ce(TCP_SKB_CB(skb)->flags))
88 tp->ecn_flags |= TCP_ECN_DEMAND_CWR;
89 /* Funny extension: if ECT is not set on a segment,
90 * it is surely retransmit. It is not in ECN RFC,
91 * but Linux follows this rule. */
92 else if (INET_ECN_is_not_ect((TCP_SKB_CB(skb)->flags)))
93 tcp_enter_quickack_mode((struct sock *)tp);
97 static inline void TCP_ECN_rcv_synack(struct tcp_sock *tp, struct tcphdr *th)
99 if ((tp->ecn_flags&TCP_ECN_OK) && (!th->ece || th->cwr))
100 tp->ecn_flags &= ~TCP_ECN_OK;
103 static inline void TCP_ECN_rcv_syn(struct tcp_sock *tp, struct tcphdr *th)
105 if ((tp->ecn_flags&TCP_ECN_OK) && (!th->ece || !th->cwr))
106 tp->ecn_flags &= ~TCP_ECN_OK;
109 static inline int TCP_ECN_rcv_ecn_echo(struct tcp_sock *tp, struct tcphdr *th)
111 if (th->ece && !th->syn && (tp->ecn_flags&TCP_ECN_OK))
116 static inline void TCP_ECN_openreq_child(struct tcp_sock *tp,
117 struct request_sock *req)
119 tp->ecn_flags = inet_rsk(req)->ecn_ok ? TCP_ECN_OK : 0;
122 static __inline__ void
123 TCP_ECN_create_request(struct request_sock *req, struct tcphdr *th)
125 if (sysctl_tcp_ecn && th->ece && th->cwr)
126 inet_rsk(req)->ecn_ok = 1;