tcp_ecn.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef _NET_TCP_ECN_H_
  2. #define _NET_TCP_ECN_H_ 1
  3. #include <net/inet_ecn.h>
  4. #define TCP_HP_BITS (~(TCP_RESERVED_BITS|TCP_FLAG_PSH))
  5. #define TCP_ECN_OK 1
  6. #define TCP_ECN_QUEUE_CWR 2
  7. #define TCP_ECN_DEMAND_CWR 4
  8. static inline void TCP_ECN_queue_cwr(struct tcp_sock *tp)
  9. {
  10. if (tp->ecn_flags&TCP_ECN_OK)
  11. tp->ecn_flags |= TCP_ECN_QUEUE_CWR;
  12. }
  13. /* Output functions */
  14. static inline void TCP_ECN_send_synack(struct tcp_sock *tp,
  15. struct sk_buff *skb)
  16. {
  17. TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_CWR;
  18. if (!(tp->ecn_flags&TCP_ECN_OK))
  19. TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_ECE;
  20. }
  21. static inline void TCP_ECN_send_syn(struct sock *sk, struct tcp_sock *tp,
  22. struct sk_buff *skb)
  23. {
  24. tp->ecn_flags = 0;
  25. if (sysctl_tcp_ecn && !(sk->sk_route_caps & NETIF_F_TSO)) {
  26. TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_ECE|TCPCB_FLAG_CWR;
  27. tp->ecn_flags = TCP_ECN_OK;
  28. sock_set_flag(sk, SOCK_NO_LARGESEND);
  29. }
  30. }
  31. static __inline__ void
  32. TCP_ECN_make_synack(struct open_request *req, struct tcphdr *th)
  33. {
  34. if (req->ecn_ok)
  35. th->ece = 1;
  36. }
  37. static inline void TCP_ECN_send(struct sock *sk, struct tcp_sock *tp,
  38. struct sk_buff *skb, int tcp_header_len)
  39. {
  40. if (tp->ecn_flags & TCP_ECN_OK) {
  41. /* Not-retransmitted data segment: set ECT and inject CWR. */
  42. if (skb->len != tcp_header_len &&
  43. !before(TCP_SKB_CB(skb)->seq, tp->snd_nxt)) {
  44. INET_ECN_xmit(sk);
  45. if (tp->ecn_flags&TCP_ECN_QUEUE_CWR) {
  46. tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR;
  47. skb->h.th->cwr = 1;
  48. }
  49. } else {
  50. /* ACK or retransmitted segment: clear ECT|CE */
  51. INET_ECN_dontxmit(sk);
  52. }
  53. if (tp->ecn_flags & TCP_ECN_DEMAND_CWR)
  54. skb->h.th->ece = 1;
  55. }
  56. }
  57. /* Input functions */
  58. static inline void TCP_ECN_accept_cwr(struct tcp_sock *tp, struct sk_buff *skb)
  59. {
  60. if (skb->h.th->cwr)
  61. tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
  62. }
  63. static inline void TCP_ECN_withdraw_cwr(struct tcp_sock *tp)
  64. {
  65. tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
  66. }
  67. static inline void TCP_ECN_check_ce(struct tcp_sock *tp, struct sk_buff *skb)
  68. {
  69. if (tp->ecn_flags&TCP_ECN_OK) {
  70. if (INET_ECN_is_ce(TCP_SKB_CB(skb)->flags))
  71. tp->ecn_flags |= TCP_ECN_DEMAND_CWR;
  72. /* Funny extension: if ECT is not set on a segment,
  73. * it is surely retransmit. It is not in ECN RFC,
  74. * but Linux follows this rule. */
  75. else if (INET_ECN_is_not_ect((TCP_SKB_CB(skb)->flags)))
  76. tcp_enter_quickack_mode(tp);
  77. }
  78. }
  79. static inline void TCP_ECN_rcv_synack(struct tcp_sock *tp, struct tcphdr *th)
  80. {
  81. if ((tp->ecn_flags&TCP_ECN_OK) && (!th->ece || th->cwr))
  82. tp->ecn_flags &= ~TCP_ECN_OK;
  83. }
  84. static inline void TCP_ECN_rcv_syn(struct tcp_sock *tp, struct tcphdr *th)
  85. {
  86. if ((tp->ecn_flags&TCP_ECN_OK) && (!th->ece || !th->cwr))
  87. tp->ecn_flags &= ~TCP_ECN_OK;
  88. }
  89. static inline int TCP_ECN_rcv_ecn_echo(struct tcp_sock *tp, struct tcphdr *th)
  90. {
  91. if (th->ece && !th->syn && (tp->ecn_flags&TCP_ECN_OK))
  92. return 1;
  93. return 0;
  94. }
  95. static inline void TCP_ECN_openreq_child(struct tcp_sock *tp,
  96. struct open_request *req)
  97. {
  98. tp->ecn_flags = req->ecn_ok ? TCP_ECN_OK : 0;
  99. }
  100. static __inline__ void
  101. TCP_ECN_create_request(struct open_request *req, struct tcphdr *th)
  102. {
  103. if (sysctl_tcp_ecn && th->ece && th->cwr)
  104. req->ecn_ok = 1;
  105. }
  106. #endif