cleanup
[linux-2.4.21-pre4.git] / include / net1 / inet_ecn.h
1 #ifndef _INET_ECN_H_
2 #define _INET_ECN_H_
3
4 static inline int INET_ECN_is_ce(__u8 dsfield)
5 {
6         return (dsfield&3) == 3;
7 }
8
9 static inline int INET_ECN_is_not_ce(__u8 dsfield)
10 {
11         return (dsfield&3) == 2;
12 }
13
14 static inline int INET_ECN_is_capable(__u8 dsfield)
15 {
16         return (dsfield&2);
17 }
18
19 static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
20 {
21         outer &= ~3;
22         if (INET_ECN_is_capable(inner))
23                 outer |= (inner & 3);
24         return outer;
25 }
26
27 #ifdef CONFIG_NET
28 #define INET_ECN_xmit(sk) do { (sk)->protinfo.af_inet.tos |= 2; } while (0)
29 #define INET_ECN_dontxmit(sk) do { (sk)->protinfo.af_inet.tos &= ~3; } while (0)
30 #else
31 #define INET_ECN_xmit(sk) do { } while (0)
32 #define INET_ECN_dontxmit(sk) do { } while (0)
33 #endif
34
35 #define IP6_ECN_flow_init(label) do {   \
36       (label) &= ~htonl(3<<20);         \
37     } while (0)
38
39 #define IP6_ECN_flow_xmit(sk, label) do {                       \
40         if (INET_ECN_is_capable((sk)->protinfo.af_inet.tos))    \
41                 (label) |= __constant_htons(2 << 4);            \
42     } while (0)
43
44 static inline void IP_ECN_set_ce(struct iphdr *iph)
45 {
46         u32 check = iph->check;
47         check += __constant_htons(0xFFFE);
48         iph->check = check + (check>=0xFFFF);
49         iph->tos |= 1;
50 }
51
52 struct ipv6hdr;
53
54 static inline void IP6_ECN_set_ce(struct ipv6hdr *iph)
55 {
56         *(u32*)iph |= htonl(1<<20);
57 }
58
59 #define ip6_get_dsfield(iph) ((ntohs(*(u16*)(iph)) >> 4) & 0xFF)
60
61 #endif