Tunnel: Cleanup old tunnel infrastructure.
[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 tnl_ops {
30         u8 ipproto;             /* The IP protocol for the tunnel. */
31
32         /*
33          * Returns the length of the tunnel header that will be added in
34          * build_header() (i.e. excludes the IP header).
35          */
36         int (*hdr_len)(const struct ovs_key_ipv4_tunnel *);
37         /*
38         * Builds header for given SKB.  Space will have already been
39         * allocated at the start of the packet equal
40         * to sizeof(struct iphdr) + value returned by hdr_len().
41         */
42         void (*build_header)(const struct vport *, struct sk_buff *,
43                              int tunnel_hlen);
44 };
45
46 struct tnl_vport {
47         struct rcu_head rcu;
48
49         __be16 dst_port;
50         char name[IFNAMSIZ];
51         const struct tnl_ops *tnl_ops;
52 };
53
54 struct vport *ovs_tnl_create(const struct vport_parms *, const struct vport_ops *,
55                              const struct tnl_ops *);
56 void ovs_tnl_destroy(struct vport *);
57
58 const char *ovs_tnl_get_name(const struct vport *vport);
59 int ovs_tnl_send(struct vport *vport, struct sk_buff *skb);
60 void ovs_tnl_rcv(struct vport *vport, struct sk_buff *skb);
61 u16 ovs_tnl_get_src_port(struct sk_buff *skb);
62
63 static inline struct tnl_vport *tnl_vport_priv(const struct vport *vport)
64 {
65         return vport_priv(vport);
66 }
67
68 static inline void tnl_tun_key_init(struct ovs_key_ipv4_tunnel *tun_key,
69                                     const struct iphdr *iph, __be64 tun_id, u32 tun_flags)
70 {
71         tun_key->tun_id = tun_id;
72         tun_key->ipv4_src = iph->saddr;
73         tun_key->ipv4_dst = iph->daddr;
74         tun_key->ipv4_tos = iph->tos;
75         tun_key->ipv4_ttl = iph->ttl;
76         tun_key->tun_flags = tun_flags;
77
78         /* clear struct padding. */
79         memset((unsigned char*) tun_key + OVS_TUNNEL_KEY_SIZE, 0,
80                sizeof(*tun_key) - OVS_TUNNEL_KEY_SIZE);
81 }
82
83 #endif /* tunnel.h */