Btrfs: switch the btrfs tree locks to reader/writer
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / net / inet_ecn.h
blob2fa8d1341a0afa291e1fd5aa74bf0f7c4c91806f
1 #ifndef _INET_ECN_H_
2 #define _INET_ECN_H_
4 #include <linux/ip.h>
5 #include <linux/skbuff.h>
7 #include <net/inet_sock.h>
8 #include <net/dsfield.h>
10 enum {
11 INET_ECN_NOT_ECT = 0,
12 INET_ECN_ECT_1 = 1,
13 INET_ECN_ECT_0 = 2,
14 INET_ECN_CE = 3,
15 INET_ECN_MASK = 3,
18 static inline int INET_ECN_is_ce(__u8 dsfield)
20 return (dsfield & INET_ECN_MASK) == INET_ECN_CE;
23 static inline int INET_ECN_is_not_ect(__u8 dsfield)
25 return (dsfield & INET_ECN_MASK) == INET_ECN_NOT_ECT;
28 static inline int INET_ECN_is_capable(__u8 dsfield)
30 return dsfield & INET_ECN_ECT_0;
33 static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
35 outer &= ~INET_ECN_MASK;
36 outer |= !INET_ECN_is_ce(inner) ? (inner & INET_ECN_MASK) :
37 INET_ECN_ECT_0;
38 return outer;
41 static inline void INET_ECN_xmit(struct sock *sk)
43 inet_sk(sk)->tos |= INET_ECN_ECT_0;
44 if (inet6_sk(sk) != NULL)
45 inet6_sk(sk)->tclass |= INET_ECN_ECT_0;
48 static inline void INET_ECN_dontxmit(struct sock *sk)
50 inet_sk(sk)->tos &= ~INET_ECN_MASK;
51 if (inet6_sk(sk) != NULL)
52 inet6_sk(sk)->tclass &= ~INET_ECN_MASK;
55 #define IP6_ECN_flow_init(label) do { \
56 (label) &= ~htonl(INET_ECN_MASK << 20); \
57 } while (0)
59 #define IP6_ECN_flow_xmit(sk, label) do { \
60 if (INET_ECN_is_capable(inet6_sk(sk)->tclass)) \
61 (label) |= htonl(INET_ECN_ECT_0 << 20); \
62 } while (0)
64 static inline int IP_ECN_set_ce(struct iphdr *iph)
66 u32 check = (__force u32)iph->check;
67 u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
70 * After the last operation we have (in binary):
71 * INET_ECN_NOT_ECT => 01
72 * INET_ECN_ECT_1 => 10
73 * INET_ECN_ECT_0 => 11
74 * INET_ECN_CE => 00
76 if (!(ecn & 2))
77 return !ecn;
80 * The following gives us:
81 * INET_ECN_ECT_1 => check += htons(0xFFFD)
82 * INET_ECN_ECT_0 => check += htons(0xFFFE)
84 check += (__force u16)htons(0xFFFB) + (__force u16)htons(ecn);
86 iph->check = (__force __sum16)(check + (check>=0xFFFF));
87 iph->tos |= INET_ECN_CE;
88 return 1;
91 static inline void IP_ECN_clear(struct iphdr *iph)
93 iph->tos &= ~INET_ECN_MASK;
96 static inline void ipv4_copy_dscp(unsigned int dscp, struct iphdr *inner)
98 dscp &= ~INET_ECN_MASK;
99 ipv4_change_dsfield(inner, INET_ECN_MASK, dscp);
102 struct ipv6hdr;
104 static inline int IP6_ECN_set_ce(struct ipv6hdr *iph)
106 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
107 return 0;
108 *(__be32*)iph |= htonl(INET_ECN_CE << 20);
109 return 1;
112 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
114 *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
117 static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
119 dscp &= ~INET_ECN_MASK;
120 ipv6_change_dsfield(inner, INET_ECN_MASK, dscp);
123 static inline int INET_ECN_set_ce(struct sk_buff *skb)
125 switch (skb->protocol) {
126 case cpu_to_be16(ETH_P_IP):
127 if (skb->network_header + sizeof(struct iphdr) <= skb->tail)
128 return IP_ECN_set_ce(ip_hdr(skb));
129 break;
131 case cpu_to_be16(ETH_P_IPV6):
132 if (skb->network_header + sizeof(struct ipv6hdr) <= skb->tail)
133 return IP6_ECN_set_ce(ipv6_hdr(skb));
134 break;
137 return 0;
140 #endif