datapath: Add support for lwtunnel
[cascardo/ovs.git] / datapath / linux / compat / include / net / inet_ecn.h
1 #ifndef _INET_ECN_WRAPPER_H_
2 #define _INET_ECN_WRAPPER_H_
3
4 #include_next <net/inet_ecn.h>
5
6 #define INET_ECN_decapsulate rpl_INET_ECN_decapsulate
7 static inline int INET_ECN_decapsulate(struct sk_buff *skb,
8                                        __u8 outer, __u8 inner)
9 {
10         if (INET_ECN_is_not_ect(inner)) {
11                 switch (outer & INET_ECN_MASK) {
12                         case INET_ECN_NOT_ECT:
13                                 return 0;
14                         case INET_ECN_ECT_0:
15                         case INET_ECN_ECT_1:
16                                 return 1;
17                         case INET_ECN_CE:
18                                 return 2;
19                 }
20         }
21
22         if (INET_ECN_is_ce(outer))
23                 INET_ECN_set_ce(skb);
24
25         return 0;
26 }
27
28 #define IP_ECN_decapsulate rpl_IP_ECN_decapsulate
29 static inline int IP_ECN_decapsulate(const struct iphdr *oiph,
30                 struct sk_buff *skb)
31 {
32         __u8 inner;
33
34         if (skb->protocol == htons(ETH_P_IP))
35                 inner = ip_hdr(skb)->tos;
36         else if (skb->protocol == htons(ETH_P_IPV6))
37                 inner = ipv6_get_dsfield(ipv6_hdr(skb));
38         else
39                 return 0;
40
41         return INET_ECN_decapsulate(skb, oiph->tos, inner);
42 }
43
44 #define IP6_ECN_decapsulate rpl_IP6_ECN_decapsulate
45 static inline int IP6_ECN_decapsulate(const struct ipv6hdr *oipv6h,
46                                       struct sk_buff *skb)
47 {
48         __u8 inner;
49
50         if (skb->protocol == htons(ETH_P_IP))
51                 inner = ip_hdr(skb)->tos;
52         else if (skb->protocol == htons(ETH_P_IPV6))
53                 inner = ipv6_get_dsfield(ipv6_hdr(skb));
54         else
55                 return 0;
56
57         return INET_ECN_decapsulate(skb, ipv6_get_dsfield(oipv6h), inner);
58 }
59 #endif