VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / net / inet_ecn.h
1 #ifndef _INET_ECN_H_
2 #define _INET_ECN_H_
3
4 #include <linux/ip.h>
5
6 enum {
7         INET_ECN_NOT_ECT = 0,
8         INET_ECN_ECT_1 = 1,
9         INET_ECN_ECT_0 = 2,
10         INET_ECN_CE = 3,
11         INET_ECN_MASK = 3,
12 };
13
14 static inline int INET_ECN_is_ce(__u8 dsfield)
15 {
16         return (dsfield & INET_ECN_MASK) == INET_ECN_CE;
17 }
18
19 static inline int INET_ECN_is_not_ce(__u8 dsfield)
20 {
21         return (dsfield & INET_ECN_MASK) == INET_ECN_ECT_0;
22 }
23
24 static inline int INET_ECN_is_capable(__u8 dsfield)
25 {
26         return (dsfield & INET_ECN_ECT_0);
27 }
28
29 static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
30 {
31         outer &= ~INET_ECN_MASK;
32         if (INET_ECN_is_capable(inner))
33                 outer |= (inner & INET_ECN_MASK);
34         return outer;
35 }
36
37 #define INET_ECN_xmit(sk) do { inet_sk(sk)->tos |= INET_ECN_ECT_0; } while (0)
38 #define INET_ECN_dontxmit(sk) \
39         do { inet_sk(sk)->tos &= ~INET_ECN_MASK; } while (0)
40
41 #define IP6_ECN_flow_init(label) do {           \
42       (label) &= ~htonl(INET_ECN_MASK << 20);   \
43     } while (0)
44
45 #define IP6_ECN_flow_xmit(sk, label) do {                               \
46         if (INET_ECN_is_capable(inet_sk(sk)->tos))                      \
47                 (label) |= __constant_htons(INET_ECN_ECT_0 << 4);       \
48     } while (0)
49
50 static inline void IP_ECN_set_ce(struct iphdr *iph)
51 {
52         u32 check = iph->check;
53         check += __constant_htons(0xFFFE);
54         iph->check = check + (check>=0xFFFF);
55         iph->tos |= INET_ECN_CE;
56 }
57
58 static inline void IP_ECN_clear(struct iphdr *iph)
59 {
60         iph->tos &= ~INET_ECN_MASK;
61 }
62
63 struct ipv6hdr;
64
65 static inline void IP6_ECN_set_ce(struct ipv6hdr *iph)
66 {
67         *(u32*)iph |= htonl(INET_ECN_CE << 20);
68 }
69
70 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
71 {
72         *(u32*)iph &= ~htonl(INET_ECN_MASK << 20);
73 }
74
75 #define ip6_get_dsfield(iph) ((ntohs(*(u16*)(iph)) >> 4) & 0xFF)
76
77 #endif