datapath-windows: Add GRE TEB support for windows datapath
[cascardo/ovs.git] / datapath-windows / ovsext / Gre.h
1 /*
2  * Copyright (c) 2015 Cloudbase Solutions Srl
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __GRE_H_
18 #define __GRE_H_ 1
19
20 #include "NetProto.h"
21 #include "Flow.h"
22
23 typedef struct _OVS_GRE_VPORT {
24     UINT64 ipId;
25     /*
26      * To be filled
27      */
28 } OVS_GRE_VPORT, *POVS_GRE_VPORT;
29
30
31 /* GRE RFC 2890 header based on http://tools.ietf.org/html/rfc2890
32  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
33  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34  * |C| |K|S| Reserved0       | Ver |         Protocol Type         |
35  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36  * |      Checksum (optional)      |       Reserved1 (Optional)    |
37  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38  * |                         Key (optional)                        |
39  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40  * |                 Sequence Number (Optional)                    |
41  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42  */
43
44 typedef struct GREHdr {
45     UINT16 flags;
46     UINT16 protocolType;
47 } GREHdr, *PGREHdr;
48
49 /* Transparent Ethernet Bridging */
50 #define GRE_NET_TEB     0x5865
51 /* GRE Flags*/
52 #define GRE_CSUM    0x0080
53 #define GRE_KEY     0x0020
54
55 NTSTATUS OvsInitGreTunnel(POVS_VPORT_ENTRY vport);
56
57 VOID OvsCleanupGreTunnel(POVS_VPORT_ENTRY vport);
58
59
60 void OvsCleanupGreTunnel(POVS_VPORT_ENTRY vport);
61
62 NDIS_STATUS OvsEncapGre(POVS_VPORT_ENTRY vport,
63                         PNET_BUFFER_LIST curNbl,
64                         OvsIPv4TunnelKey *tunKey,
65                         POVS_SWITCH_CONTEXT switchContext,
66                         POVS_PACKET_HDR_INFO layers,
67                         PNET_BUFFER_LIST *newNbl);
68
69 NDIS_STATUS OvsDecapGre(POVS_SWITCH_CONTEXT switchContext,
70                         PNET_BUFFER_LIST curNbl,
71                         OvsIPv4TunnelKey *tunKey,
72                         PNET_BUFFER_LIST *newNbl);
73
74 static __inline UINT16
75 OvsTunnelFlagsToGreFlags(UINT16 tunnelflags)
76 {
77     UINT16 flags = 0;
78
79     if (tunnelflags & OVS_TNL_F_CSUM)
80         flags |= GRE_CSUM;
81
82     if (tunnelflags & OVS_TNL_F_KEY)
83         flags |= GRE_KEY;
84
85     return flags;
86 }
87
88 static __inline UINT32
89 GreTunHdrSize(UINT16 flags)
90 {
91     UINT32 sum = sizeof(EthHdr) + sizeof(IPHdr) + sizeof(GREHdr);
92     sum += (flags & OVS_TNL_F_CSUM) ?
93            4 : 0;
94     sum += (flags & OVS_TNL_F_KEY) ?
95            4 : 0;
96
97     return sum;
98 }
99
100 #endif /*__GRE_H_ */