File: /usr/src/linux/include/net/inet_ecn.h

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