ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 static inline int INET_ECN_is_ce(__u8 dsfield)
7 {
8         return (dsfield&3) == 3;
9 }
10
11 static inline int INET_ECN_is_not_ce(__u8 dsfield)
12 {
13         return (dsfield&3) == 2;
14 }
15
16 static inline int INET_ECN_is_capable(__u8 dsfield)
17 {
18         return (dsfield&2);
19 }
20
21 static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
22 {
23         outer &= ~3;
24         if (INET_ECN_is_capable(inner))
25                 outer |= (inner & 3);
26         return outer;
27 }
28
29 #define INET_ECN_xmit(sk) do { inet_sk(sk)->tos |= 2; } while (0)
30 #define INET_ECN_dontxmit(sk) do { inet_sk(sk)->tos &= ~3; } while (0)
31
32 #define IP6_ECN_flow_init(label) do {   \
33       (label) &= ~htonl(3<<20);         \
34     } while (0)
35
36 #define IP6_ECN_flow_xmit(sk, label) do {                       \
37         if (INET_ECN_is_capable(inet_sk(sk)->tos))              \
38                 (label) |= __constant_htons(2 << 4);            \
39     } while (0)
40
41 static inline void IP_ECN_set_ce(struct iphdr *iph)
42 {
43         u32 check = iph->check;
44         check += __constant_htons(0xFFFE);
45         iph->check = check + (check>=0xFFFF);
46         iph->tos |= 1;
47 }
48
49 static inline void IP_ECN_clear(struct iphdr *iph)
50 {
51         iph->tos &= ~3;
52 }
53
54 struct ipv6hdr;
55
56 static inline void IP6_ECN_set_ce(struct ipv6hdr *iph)
57 {
58         *(u32*)iph |= htonl(1<<20);
59 }
60
61 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
62 {
63         *(u32*)iph &= ~htonl(3<<20);
64 }
65
66 #define ip6_get_dsfield(iph) ((ntohs(*(u16*)(iph)) >> 4) & 0xFF)
67
68 #endif