1 #ifndef __NET_IP_TUNNELS_WRAPPER_H
2 #define __NET_IP_TUNNELS_WRAPPER_H 1
4 #include <linux/version.h>
6 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
7 #include_next <net/ip_tunnels.h>
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
12 #include <linux/if_tunnel.h>
13 #include <linux/netdevice.h>
14 #include <linux/skbuff.h>
15 #include <linux/types.h>
16 #include <net/dsfield.h>
18 #include <net/inet_ecn.h>
20 #include <net/rtnetlink.h>
22 struct sk_buff *ovs_iptunnel_handle_offloads(struct sk_buff *skb,
23 bool csum_help, int gso_type_mask,
24 void (*fix_segment)(struct sk_buff *));
26 #define iptunnel_xmit rpl_iptunnel_xmit
27 int rpl_iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
28 __be32 src, __be32 dst, __u8 proto, __u8 tos, __u8 ttl,
29 __be16 df, bool xnet);
31 #define iptunnel_pull_header rpl_iptunnel_pull_header
32 int rpl_iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto);
36 #define ovs_iptunnel_handle_offloads(skb, csum_help, gso_type_mask, fix_segment) \
37 iptunnel_handle_offloads(skb, csum_help, gso_type_mask)
42 #define TUNNEL_CSUM __cpu_to_be16(0x01)
43 #define TUNNEL_ROUTING __cpu_to_be16(0x02)
44 #define TUNNEL_KEY __cpu_to_be16(0x04)
45 #define TUNNEL_SEQ __cpu_to_be16(0x08)
46 #define TUNNEL_STRICT __cpu_to_be16(0x10)
47 #define TUNNEL_REC __cpu_to_be16(0x20)
48 #define TUNNEL_VERSION __cpu_to_be16(0x40)
49 #define TUNNEL_NO_KEY __cpu_to_be16(0x80)
59 #define PACKET_REJECT 1
62 #ifndef TUNNEL_DONT_FRAGMENT
63 #define TUNNEL_DONT_FRAGMENT __cpu_to_be16(0x0100)
67 #define TUNNEL_OAM __cpu_to_be16(0x0200)
68 #define TUNNEL_CRIT_OPT __cpu_to_be16(0x0400)
71 #ifndef TUNNEL_GENEVE_OPT
72 #define TUNNEL_GENEVE_OPT __cpu_to_be16(0x0800)
75 #ifndef TUNNEL_VXLAN_OPT
76 #define TUNNEL_VXLAN_OPT __cpu_to_be16(0x1000)
79 /* Older kernels defined TUNNEL_OPTIONS_PRESENT to GENEVE only */
80 #undef TUNNEL_OPTIONS_PRESENT
81 #define TUNNEL_OPTIONS_PRESENT (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT)
83 #define skb_is_encapsulated ovs_skb_is_encapsulated
84 bool ovs_skb_is_encapsulated(struct sk_buff *skb);
86 #ifndef HAVE_METADATA_DST
87 /* Used to memset ip_tunnel padding. */
88 #define IP_TUNNEL_KEY_SIZE offsetofend(struct ip_tunnel_key, tp_dst)
90 /* Used to memset ipv4 address padding. */
91 #define IP_TUNNEL_KEY_IPV4_PAD offsetofend(struct ip_tunnel_key, u.ipv4.dst)
92 #define IP_TUNNEL_KEY_IPV4_PAD_LEN \
93 (FIELD_SIZEOF(struct ip_tunnel_key, u) - \
94 FIELD_SIZEOF(struct ip_tunnel_key, u.ipv4))
96 struct ip_tunnel_key {
109 u8 tos; /* TOS for IPv4, TC for IPv6 */
110 u8 ttl; /* TTL for IPv4, HL for IPv6 */
115 /* Flags for ip_tunnel_info mode. */
116 #define IP_TUNNEL_INFO_TX 0x01 /* represents tx tunnel parameters */
117 #define IP_TUNNEL_INFO_IPV6 0x02 /* key contains IPv6 addresses */
119 struct ip_tunnel_info {
120 struct ip_tunnel_key key;
125 static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info *tun_info)
127 return tun_info->mode & IP_TUNNEL_INFO_IPV6 ? AF_INET6 : AF_INET;
130 static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info)
135 static inline void ip_tunnel_info_opts_get(void *to,
136 const struct ip_tunnel_info *info)
138 memcpy(to, info + 1, info->options_len);
141 static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
142 const void *from, int len)
144 memcpy(ip_tunnel_info_opts(info), from, len);
145 info->options_len = len;
148 static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
149 __be32 saddr, __be32 daddr,
151 __be16 tp_src, __be16 tp_dst,
152 __be64 tun_id, __be16 tun_flags)
154 key->tun_id = tun_id;
155 key->u.ipv4.src = saddr;
156 key->u.ipv4.dst = daddr;
157 memset((unsigned char *)key + IP_TUNNEL_KEY_IPV4_PAD,
158 0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
161 key->tun_flags = tun_flags;
163 /* For the tunnel types on the top of IPsec, the tp_src and tp_dst of
164 * the upper tunnel are used.
165 * E.g: GRE over IPSEC, the tp_src and tp_port are zero.
167 key->tp_src = tp_src;
168 key->tp_dst = tp_dst;
170 /* Clear struct padding. */
171 if (sizeof(*key) != IP_TUNNEL_KEY_SIZE)
172 memset((unsigned char *)key + IP_TUNNEL_KEY_SIZE,
173 0, sizeof(*key) - IP_TUNNEL_KEY_SIZE);
176 #define ip_tunnel_collect_metadata() true
179 #define ip_tunnel rpl_ip_tunnel
182 struct net_device *dev;
183 struct net *net; /* netns for packet i/o */
185 int err_count; /* Number of arrived ICMP errors */
186 unsigned long err_time; /* Time when the last ICMP error
190 /* These four fields used only by GRE */
191 u32 i_seqno; /* The last seen seqno */
192 u32 o_seqno; /* The last output seqno */
193 int tun_hlen; /* Precalculated header length */
196 struct ip_tunnel_parm parms;
198 int encap_hlen; /* Encap header length (FOU,GUE) */
199 int hlen; /* tun_hlen + encap_hlen */
205 #define ip_tunnel_net rpl_ip_tunnel_net
206 struct ip_tunnel_net {
207 struct ip_tunnel __rcu *collect_md_tun;
208 struct rtnl_link_ops *rtnl_ops;
212 #ifndef HAVE_PCPU_SW_NETSTATS
213 #define ip_tunnel_get_stats64 rpl_ip_tunnel_get_stats64
214 struct rtnl_link_stats64 *rpl_ip_tunnel_get_stats64(struct net_device *dev,
215 struct rtnl_link_stats64 *tot);
218 #define ip_tunnel_get_dsfield rpl_ip_tunnel_get_dsfield
219 static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
220 const struct sk_buff *skb)
222 if (skb->protocol == htons(ETH_P_IP))
224 else if (skb->protocol == htons(ETH_P_IPV6))
225 return ipv6_get_dsfield((const struct ipv6hdr *)iph);
230 #define ip_tunnel_ecn_encap rpl_ip_tunnel_ecn_encap
231 static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,
232 const struct sk_buff *skb)
234 u8 inner = ip_tunnel_get_dsfield(iph, skb);
236 return INET_ECN_encapsulate(tos, inner);
239 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
240 #define iptunnel_xmit_stats(err, stats, dummy) \
243 (stats)->tx_bytes += err; \
244 (stats)->tx_packets++; \
245 } else if (err < 0) { \
246 (stats)->tx_errors++; \
247 (stats)->tx_aborted_errors++; \
249 (stats)->tx_dropped++; \
254 #define iptunnel_xmit_stats rpl_iptunnel_xmit_stats
255 static inline void iptunnel_xmit_stats(int err,
256 struct net_device_stats *err_stats,
257 struct pcpu_sw_netstats __percpu *stats)
260 struct pcpu_sw_netstats *tstats = this_cpu_ptr(stats);
262 u64_stats_update_begin(&tstats->syncp);
263 tstats->tx_bytes += err;
264 tstats->tx_packets++;
265 u64_stats_update_end(&tstats->syncp);
266 } else if (err < 0) {
267 err_stats->tx_errors++;
268 err_stats->tx_aborted_errors++;
270 err_stats->tx_dropped++;
275 #define ip_tunnel_init rpl_ip_tunnel_init
276 int rpl_ip_tunnel_init(struct net_device *dev);
278 #define ip_tunnel_uninit rpl_ip_tunnel_uninit
279 void rpl_ip_tunnel_uninit(struct net_device *dev);
281 #define ip_tunnel_change_mtu rpl_ip_tunnel_change_mtu
282 int rpl_ip_tunnel_change_mtu(struct net_device *dev, int new_mtu);
284 #define ip_tunnel_newlink rpl_ip_tunnel_newlink
285 int rpl_ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
286 struct ip_tunnel_parm *p);
288 #define ip_tunnel_dellink rpl_ip_tunnel_dellink
289 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
290 void rpl_ip_tunnel_dellink(struct net_device *dev, struct list_head *head);
292 void rpl_ip_tunnel_dellink(struct net_device *dev);
295 #define ip_tunnel_init_net rpl_ip_tunnel_init_net
296 int rpl_ip_tunnel_init_net(struct net *net, int ip_tnl_net_id,
297 struct rtnl_link_ops *ops, char *devname);
299 #define ip_tunnel_delete_net rpl_ip_tunnel_delete_net
300 void rpl_ip_tunnel_delete_net(struct ip_tunnel_net *itn, struct rtnl_link_ops *ops);
302 #define ip_tunnel_setup rpl_ip_tunnel_setup
303 void rpl_ip_tunnel_setup(struct net_device *dev, int net_id);
305 #define ip_tunnel_get_iflink rpl_ip_tunnel_get_iflink
306 int rpl_ip_tunnel_get_iflink(const struct net_device *dev);
307 #endif /* HAVE_METADATA_DST */
308 #endif /* __NET_IP_TUNNELS_H */