datapath: Add support for lwtunnel
[cascardo/ovs.git] / datapath / linux / compat / include / net / route.h
1 #ifndef __NET_ROUTE_H_WRAPPER
2 #define __NET_ROUTE_H_WRAPPER
3
4 #include_next <net/route.h>
5
6 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
7 struct flowi_common {
8         int     flowic_oif;
9         __u32   flowic_mark;
10         __u8    flowic_tos;
11         __u8    flowic_proto;
12 };
13
14 union flowi_uli {
15         struct {
16                 __be16  dport;
17                 __be16  sport;
18         } ports;
19
20         struct {
21                 __u8    type;
22                 __u8    code;
23         } icmpt;
24
25         struct {
26                 __le16  dport;
27                 __le16  sport;
28         } dnports;
29
30         __be32          spi;
31         __be32          gre_key;
32
33         struct {
34                 __u8    type;
35         } mht;
36 };
37
38 struct flowi4 {
39         struct flowi_common     __fl_common;
40 #define flowi4_oif              __fl_common.flowic_oif
41 #define flowi4_iif              __fl_common.flowic_iif
42 #define flowi4_mark             __fl_common.flowic_mark
43 #define flowi4_tos              __fl_common.flowic_tos
44 #define flowi4_scope            __fl_common.flowic_scope
45 #define flowi4_proto            __fl_common.flowic_proto
46 #define flowi4_flags            __fl_common.flowic_flags
47 #define flowi4_secid            __fl_common.flowic_secid
48 #define flowi4_tun_key          __fl_common.flowic_tun_key
49
50         union flowi_uli         uli;
51 #define fl4_gre_key             uli.gre_key
52
53         /* (saddr,daddr) must be grouped, same order as in IP header */
54         __be32                  saddr;
55         __be32                  daddr;
56
57 } __attribute__((__aligned__(BITS_PER_LONG/8)));
58
59 struct flowi6 {
60         struct flowi_common     __fl_common;
61 #define flowi6_oif              __fl_common.flowic_oif
62 #define flowi6_iif              __fl_common.flowic_iif
63 #define flowi6_mark             __fl_common.flowic_mark
64 #define flowi6_tos              __fl_common.flowic_tos
65 #define flowi6_scope            __fl_common.flowic_scope
66 #define flowi6_proto            __fl_common.flowic_proto
67 #define flowi6_flags            __fl_common.flowic_flags
68 #define flowi6_secid            __fl_common.flowic_secid
69 #define flowi6_tun_key          __fl_common.flowic_tun_key
70         struct in6_addr         daddr;
71         struct in6_addr         saddr;
72         __be32                  flowlabel;
73         union flowi_uli         uli;
74 #define fl6_sport               uli.ports.sport
75 #define fl6_dport               uli.ports.dport
76 #define fl6_icmp_type           uli.icmpt.type
77 #define fl6_icmp_code           uli.icmpt.code
78 #define fl6_ipsec_spi           uli.spi
79 #define fl6_mh_type             uli.mht.type
80 #define fl6_gre_key             uli.gre_key
81 } __attribute__((__aligned__(BITS_PER_LONG/8)));
82
83 static inline struct rtable *rpl_ip_route_output_key(struct net *net, struct flowi4 *flp)
84 {
85         struct rtable *rt;
86         /* Tunnel configuration keeps DSCP part of TOS bits, But Linux
87          * router expect RT_TOS bits only.
88          */
89
90         struct flowi fl = { .nl_u = { .ip4_u = {
91                                         .daddr = flp->daddr,
92                                         .saddr = flp->saddr,
93                                         .tos   = RT_TOS(flp->flowi4_tos) } },
94                                         .mark = flp->flowi4_mark,
95                                         .proto = flp->flowi4_proto };
96
97         if (unlikely(ip_route_output_key(net, &rt, &fl)))
98                 return ERR_PTR(-EADDRNOTAVAIL);
99         flp->saddr = fl.nl_u.ip4_u.saddr;
100         return rt;
101 }
102 #define ip_route_output_key rpl_ip_route_output_key
103
104 static inline int ip4_dst_hoplimit(const struct dst_entry *dst)
105 {
106         return dst_metric(dst, RTAX_HOPLIMIT);
107 }
108 #endif
109 #endif