89e73bac67677ea46df8289cedb3b8e258767df5
[sliver-openvswitch.git] / datapath / tunnel.h
1 /*
2  * Copyright (c) 2010 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 #ifndef TUNNEL_H
10 #define TUNNEL_H 1
11
12 #include "openvswitch/tunnel.h"
13 #include "table.h"
14 #include "vport.h"
15
16 /* The absolute minimum fragment size.  Note that there are many other
17  * definitions of the minimum MTU. */
18 #define IP_MIN_MTU 68
19
20 /*
21  * One of these goes in your struct tnl_ops and in tnl_find_port().
22  * These values are in the same namespace as other TNL_T_* values, so
23  * you have only the first 10 bits to define protocol identifiers.
24  */
25 #define TNL_T_PROTO_GRE         0
26
27 /* You only need these flags when you are calling tnl_find_port(). */
28 #define TNL_T_KEY_EXACT         (1 << 10)
29 #define TNL_T_KEY_MATCH         (1 << 11)
30 #define TNL_T_KEY_EITHER        (TNL_T_KEY_EXACT | TNL_T_KEY_MATCH)
31
32 struct tnl_mutable_config {
33         struct rcu_head rcu;
34
35         unsigned char eth_addr[ETH_ALEN];
36         unsigned int mtu;
37         struct tnl_port_config port_config;
38
39         /* Set of TNL_T_* flags that define the category for lookup. */
40         u32 tunnel_type;
41
42         int tunnel_hlen; /* Tunnel header length. */
43 };
44
45 struct tnl_ops {
46         /* Put your TNL_T_PROTO_* type in here. */
47         u32 tunnel_type;
48         u8 ipproto;
49
50         int (*hdr_len)(const struct tnl_port_config *);
51         void (*build_header)(struct sk_buff *, const struct vport *,
52                              const struct tnl_mutable_config *);
53 };
54
55 struct tnl_vport {
56         struct rcu_head rcu;
57         struct tbl_node tbl_node;
58
59         char name[IFNAMSIZ];
60         const struct tnl_ops *tnl_ops;
61
62         /* Protected by RCU. */
63         struct tnl_mutable_config *mutable;
64 };
65
66 int tnl_init(void);
67 void tnl_exit(void);
68 struct vport *tnl_create(const char *name, const void __user *config,
69                          const struct vport_ops *,
70                          const struct tnl_ops *);
71 int tnl_modify(struct vport *, const void __user *config);
72 int tnl_destroy(struct vport *);
73 int tnl_set_mtu(struct vport *vport, int mtu);
74 int tnl_set_addr(struct vport *vport, const unsigned char *addr);
75 const char *tnl_get_name(const struct vport *vport);
76 const unsigned char *tnl_get_addr(const struct vport *vport);
77 int tnl_get_mtu(const struct vport *vport);
78 int tnl_send(struct vport *vport, struct sk_buff *skb);
79 void tnl_rcv(struct vport *vport, struct sk_buff *skb);
80
81 struct vport *tnl_find_port(__be32 saddr, __be32 daddr, __be32 key,
82                             int tunnel_type,
83                             const struct tnl_mutable_config **mutable);
84 bool tnl_frag_needed(struct vport *vport,
85                      const struct tnl_mutable_config *mutable,
86                      struct sk_buff *skb, unsigned int mtu, __be32 flow_key);
87
88 static inline struct tnl_vport *tnl_vport_priv(const struct vport *vport)
89 {
90         return vport_priv(vport);
91 }
92
93 #endif /* tunnel.h */