Add Vxlan-Gpe over IPv6
[vpp.git] / vnet / vnet / vxlan-gpe / vxlan_gpe.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef included_vnet_vxlan_gpe_h
16 #define included_vnet_vxlan_gpe_h
17
18 #include <vppinfra/error.h>
19 #include <vppinfra/hash.h>
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/l2/l2_input.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/vxlan-gpe/vxlan_gpe_packet.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/ip/ip6_packet.h>
27 #include <vnet/ip/udp.h>
28
29
30 typedef CLIB_PACKED (struct {
31   ip4_header_t ip4;             /* 20 bytes */
32   udp_header_t udp;             /* 8 bytes */
33   vxlan_gpe_header_t vxlan;     /* 8 bytes */
34 }) ip4_vxlan_gpe_header_t;
35
36 typedef CLIB_PACKED (struct {
37   ip6_header_t ip6;             /* 40 bytes */
38   udp_header_t udp;             /* 8 bytes */
39   vxlan_gpe_header_t vxlan;     /* 8 bytes */
40 }) ip6_vxlan_gpe_header_t;
41
42 typedef CLIB_PACKED(struct {
43   /* 
44    * Key fields: local remote, vni 
45    * all fields in NET byte order
46    */
47   union {
48     struct {
49       u32 local;
50       u32 remote;
51       u32 vni;                      /* shifted 8 bits */
52       u32 pad;
53     };
54     u64 as_u64[2];
55   };
56 }) vxlan4_gpe_tunnel_key_t;
57
58 typedef CLIB_PACKED(struct {
59   /*
60    * Key fields: local remote, vni
61    * all fields in NET byte order
62    */
63   ip6_address_t local;
64   ip6_address_t remote;
65   u32 vni;                      /* shifted 8 bits */
66 }) vxlan6_gpe_tunnel_key_t;
67
68 typedef struct {
69   /* Rewrite string. $$$$ embed vnet_rewrite header */
70   u8 * rewrite;
71
72   /* encapsulated protocol */
73   u8 protocol;
74
75   /* tunnel src and dst addresses */
76   ip46_address_t local;
77   ip46_address_t remote;
78
79   /* FIB indices */
80   u32 encap_fib_index;          /* tunnel partner lookup here */
81   u32 decap_fib_index;          /* inner IP lookup here */
82
83   /* vxlan VNI in HOST byte order, shifted left 8 bits */
84   u32 vni;
85
86   /*decap next index*/
87   u32 decap_next_index;
88
89   /* vnet intfc hw/sw_if_index */
90   u32 hw_if_index;
91   u32 sw_if_index;
92
93   union { /* storage for the hash key */
94         vxlan4_gpe_tunnel_key_t key4;
95         vxlan6_gpe_tunnel_key_t key6;
96   };
97
98   /* flags */
99   u32 flags;
100 } vxlan_gpe_tunnel_t;
101
102 /* Flags for vxlan_gpe_tunnel_t.flags */
103 #define VXLAN_GPE_TUNNEL_IS_IPV4        1
104
105 #define foreach_vxlan_gpe_input_next        \
106 _(DROP, "error-drop")                           \
107 _(IP4_INPUT, "ip4-input")                       \
108 _(IP6_INPUT, "ip6-input")                       \
109 _(ETHERNET_INPUT, "ethernet-input")             
110
111 typedef enum {
112 #define _(s,n) VXLAN_GPE_INPUT_NEXT_##s,
113   foreach_vxlan_gpe_input_next
114 #undef _
115   VXLAN_GPE_INPUT_N_NEXT,
116 } vxlan_gpe_input_next_t;
117
118 typedef enum {
119 #define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n,
120 #include <vnet/vxlan-gpe/vxlan_gpe_error.def>
121 #undef vxlan_gpe_error
122   VXLAN_GPE_N_ERROR,
123 } vxlan_gpe_input_error_t;
124
125 typedef struct {
126   /* vector of encap tunnel instances */
127   vxlan_gpe_tunnel_t *tunnels;
128
129   /* lookup tunnel by key */
130   uword * vxlan4_gpe_tunnel_by_key;
131   uword * vxlan6_gpe_tunnel_by_key;
132
133   /* Free vlib hw_if_indices */
134   u32 * free_vxlan_gpe_tunnel_hw_if_indices;
135
136   /* show device instance by real device instance */
137   u32 * dev_inst_by_real;
138
139   /* convenience */
140   vlib_main_t * vlib_main;
141   vnet_main_t * vnet_main;
142 } vxlan_gpe_main_t;
143
144 vxlan_gpe_main_t vxlan_gpe_main;
145
146 extern vlib_node_registration_t vxlan_gpe_encap_node;
147 extern vlib_node_registration_t vxlan4_gpe_input_node;
148 extern vlib_node_registration_t vxlan6_gpe_input_node;
149
150 u8 * format_vxlan_gpe_encap_trace (u8 * s, va_list * args);
151
152 typedef struct {
153   u8 is_add;
154   u8 is_ip6;
155   ip46_address_t local, remote;
156   u8 protocol;
157   u32 encap_fib_index;
158   u32 decap_fib_index;
159   u32 decap_next_index;
160   u32 vni;
161 } vnet_vxlan_gpe_add_del_tunnel_args_t;
162
163
164 int vnet_vxlan_gpe_add_del_tunnel 
165 (vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
166
167
168
169
170
171 #endif /* included_vnet_vxlan_gpe_h */