linux-old/include/net/tcp_ecn.h
<<
>>
Prefs
   1#ifndef _NET_TCP_ECN_H_
   2#define _NET_TCP_ECN_H_ 1
   3
   4#include <net/inet_ecn.h>
   5
   6#define TCP_HP_BITS (~(TCP_RESERVED_BITS|TCP_FLAG_PSH))
   7
   8#define TCP_ECN_OK              1
   9#define TCP_ECN_QUEUE_CWR       2
  10#define TCP_ECN_DEMAND_CWR      4
  11
  12static __inline__ void
  13TCP_ECN_queue_cwr(struct tcp_opt *tp)
  14{
  15        if (tp->ecn_flags&TCP_ECN_OK)
  16                tp->ecn_flags |= TCP_ECN_QUEUE_CWR;
  17}
  18
  19
  20/* Output functions */
  21
  22static __inline__ void
  23TCP_ECN_send_synack(struct tcp_opt *tp, struct sk_buff *skb)
  24{
  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;
  28}
  29
  30static __inline__ void
  31TCP_ECN_send_syn(struct tcp_opt *tp, struct sk_buff *skb)
  32{
  33        tp->ecn_flags = 0;
  34        if (sysctl_tcp_ecn) {
  35                TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_ECE|TCPCB_FLAG_CWR;
  36                tp->ecn_flags = TCP_ECN_OK;
  37        }
  38}
  39
  40static __inline__ void
  41TCP_ECN_make_synack(struct open_request *req, struct tcphdr *th)
  42{
  43        if (req->ecn_ok)
  44                th->ece = 1;
  45}
  46
  47static __inline__ void
  48TCP_ECN_send(struct sock *sk, struct tcp_opt *tp, struct sk_buff *skb, int tcp_header_len)
  49{
  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)) {
  54                        INET_ECN_xmit(sk);
  55                        if (tp->ecn_flags&TCP_ECN_QUEUE_CWR) {
  56                                tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR;
  57                                skb->h.th->cwr = 1;
  58                        }
  59                } else {
  60                        /* ACK or retransmitted segment: clear ECT|CE */
  61                        INET_ECN_dontxmit(sk);
  62                }
  63                if (tp->ecn_flags & TCP_ECN_DEMAND_CWR)
  64                        skb->h.th->ece = 1;
  65        }
  66}
  67
  68/* Input functions */
  69
  70static __inline__ void
  71TCP_ECN_accept_cwr(struct tcp_opt *tp, struct sk_buff *skb)
  72{
  73        if (skb->h.th->cwr)
  74                tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
  75}
  76
  77static __inline__ void
  78TCP_ECN_withdraw_cwr(struct tcp_opt *tp)
  79{
  80        tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR;
  81}
  82
  83static __inline__ void
  84TCP_ECN_check_ce(struct tcp_opt *tp, struct sk_buff *skb)
  85{
  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_capable((TCP_SKB_CB(skb)->flags)))
  93                        tcp_enter_quickack_mode(tp);
  94        }
  95}
  96
  97static __inline__ void
  98TCP_ECN_rcv_synack(struct tcp_opt *tp, struct tcphdr *th)
  99{
 100        if ((tp->ecn_flags&TCP_ECN_OK) && (!th->ece || th->cwr))
 101                tp->ecn_flags &= ~TCP_ECN_OK;
 102}
 103
 104static __inline__ void
 105TCP_ECN_rcv_syn(struct tcp_opt *tp, struct tcphdr *th)
 106{
 107        if ((tp->ecn_flags&TCP_ECN_OK) && (!th->ece || !th->cwr))
 108                tp->ecn_flags &= ~TCP_ECN_OK;
 109}
 110
 111static __inline__ int
 112TCP_ECN_rcv_ecn_echo(struct tcp_opt *tp, struct tcphdr *th)
 113{
 114        if (th->ece && !th->syn && (tp->ecn_flags&TCP_ECN_OK))
 115                return 1;
 116        return 0;
 117}
 118
 119static __inline__ void
 120TCP_ECN_openreq_child(struct tcp_opt *tp, struct open_request *req)
 121{
 122        tp->ecn_flags = req->ecn_ok ? TCP_ECN_OK : 0;
 123}
 124
 125static __inline__ void
 126TCP_ECN_create_request(struct open_request *req, struct tcphdr *th)
 127{
 128        if (sysctl_tcp_ecn && th->ece && th->cwr)
 129                req->ecn_ok = 1;
 130}
 131
 132#endif
 133
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.