datapath: Add support for tunnel fragmentation.
[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 /*
17  * The absolute minimum fragment size.  Note that there are many other
18  * definitions of the minimum MTU.
19  */
20 #define IP_MIN_MTU 68
21
22 /*
23  * One of these goes in your struct tnl_ops and in tnl_find_port().
24  * These values are in the same namespace as other TNL_T_* values, so
25  * you have only the first 10 bits to define protocol identifiers.
26  */
27 #define TNL_T_PROTO_GRE         0
28
29 /* You only need these flags when you are calling tnl_find_port(). */
30 #define TNL_T_KEY_EXACT         (1 << 10)
31 #define TNL_T_KEY_MATCH         (1 << 11)
32 #define TNL_T_KEY_EITHER        (TNL_T_KEY_EXACT | TNL_T_KEY_MATCH)
33
34 struct tnl_mutable_config {
35         struct rcu_head rcu;
36
37         unsigned char eth_addr[ETH_ALEN];
38         unsigned int mtu;
39         struct tnl_port_config port_config;
40
41         /* Set of TNL_T_* flags that define the category for lookup. */
42         u32 tunnel_type;
43
44         int tunnel_hlen; /* Tunnel header length. */
45 };
46
47 struct tnl_ops {
48         /* Put your TNL_T_PROTO_* type in here. */
49         u32 tunnel_type;
50         u8 ipproto;
51
52         /*
53          * Returns the length of the tunnel header you will add in
54          * build_header() (i.e. excludes the IP header).  Returns a negative
55          * error code if the configuration is invalid.
56          */
57         int (*hdr_len)(const struct tnl_port_config *);
58
59         /*
60          * Returns a linked list of SKBs with tunnel headers (multiple
61          * packets may be generated in the event of fragmentation).  Space
62          * will have already been allocated at the start of the packet equal
63          * to sizeof(struct iphdr) + value returned by hdr_len().  The IP
64          * header will have already been constructed.
65          */
66         struct sk_buff *(*build_header)(struct sk_buff *,
67                                         const struct vport *,
68                                         const struct tnl_mutable_config *,
69                                         struct dst_entry *);
70 };
71
72 struct tnl_vport {
73         struct rcu_head rcu;
74         struct tbl_node tbl_node;
75
76         char name[IFNAMSIZ];
77         const struct tnl_ops *tnl_ops;
78
79         /* Protected by RCU. */
80         struct tnl_mutable_config *mutable;
81
82         atomic_t frag_id;
83 };
84
85 int tnl_init(void);
86 void tnl_exit(void);
87 struct vport *tnl_create(const char *name, const void __user *config,
88                          const struct vport_ops *,
89                          const struct tnl_ops *);
90 int tnl_modify(struct vport *, const void __user *config);
91 int tnl_destroy(struct vport *);
92 int tnl_set_mtu(struct vport *vport, int mtu);
93 int tnl_set_addr(struct vport *vport, const unsigned char *addr);
94 const char *tnl_get_name(const struct vport *vport);
95 const unsigned char *tnl_get_addr(const struct vport *vport);
96 int tnl_get_mtu(const struct vport *vport);
97 int tnl_send(struct vport *vport, struct sk_buff *skb);
98 void tnl_rcv(struct vport *vport, struct sk_buff *skb);
99
100 struct vport *tnl_find_port(__be32 saddr, __be32 daddr, __be32 key,
101                             int tunnel_type,
102                             const struct tnl_mutable_config **mutable);
103 bool tnl_frag_needed(struct vport *vport,
104                      const struct tnl_mutable_config *mutable,
105                      struct sk_buff *skb, unsigned int mtu, __be32 flow_key);
106
107 static inline struct tnl_vport *tnl_vport_priv(const struct vport *vport)
108 {
109         return vport_priv(vport);
110 }
111
112 #endif /* tunnel.h */