17de7c47a8e7ace8b314e77f18cf6af3a938a7f1
[sliver-openvswitch.git] / datapath / tunnel.h
1 /*
2  * Copyright (c) 2007-2012 Nicira, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 2 of the GNU General Public
6  * License as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA
17  */
18
19 #ifndef TUNNEL_H
20 #define TUNNEL_H 1
21
22 #include <linux/version.h>
23 #include <net/net_namespace.h>
24 #include <net/netns/generic.h>
25
26 #include "flow.h"
27 #include "vport.h"
28
29 struct rtable *find_route(struct net *net,
30                           __be32 *saddr, __be32 daddr, u8 ipproto,
31                           u8 tos, u32 skb_mark);
32
33 u16 ovs_tnl_get_src_port(struct sk_buff *skb);
34
35 int ovs_tnl_send(struct vport *vport, struct sk_buff *skb,
36                  u8 ipproto, int tunnel_hlen,
37                  void (*build_header)(const struct vport *,
38                                       struct sk_buff *,
39                                       int tunnel_hlen));
40
41 void ovs_tnl_rcv(struct vport *vport, struct sk_buff *skb,
42                  struct ovs_key_ipv4_tunnel *tun_key);
43
44 static inline void tnl_tun_key_init(struct ovs_key_ipv4_tunnel *tun_key,
45                                          const struct iphdr *iph, __be64 tun_id,
46                                          __be16 tun_flags)
47 {
48         tun_key->tun_id = tun_id;
49         tun_key->ipv4_src = iph->saddr;
50         tun_key->ipv4_dst = iph->daddr;
51         tun_key->ipv4_tos = iph->tos;
52         tun_key->ipv4_ttl = iph->ttl;
53         tun_key->tun_flags = tun_flags;
54
55         /* clear struct padding. */
56         memset((unsigned char*) tun_key + OVS_TUNNEL_KEY_SIZE, 0,
57                sizeof(*tun_key) - OVS_TUNNEL_KEY_SIZE);
58 }
59
60 #endif /* TUNNEL_H */