misc: Move l2tp to plugin
[vpp.git] / src / plugins / geneve / geneve.h
1 /*
2  * Copyright (c) 2017 SUSE LLC.
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_geneve_h
16 #define included_vnet_geneve_h
17
18 #include <vppinfra/error.h>
19 #include <vppinfra/hash.h>
20 #include <vnet/vnet.h>
21
22 #include <geneve/geneve_packet.h>
23
24 #include <vnet/ip/ip.h>
25 #include <vnet/ip/vtep.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2/l2_output.h>
28 #include <vnet/l2/l2_bd.h>
29 #include <vnet/ethernet/ethernet.h>
30 #include <vnet/ip/ip4_packet.h>
31 #include <vnet/ip/ip6_packet.h>
32 #include <vnet/udp/udp.h>
33 #include <vnet/dpo/dpo.h>
34 #include <vnet/adj/adj_types.h>
35
36 #define SUPPORT_OPTIONS_HEADER 0
37
38 typedef CLIB_PACKED (struct
39                      {
40                      ip4_header_t ip4;  /* 20 bytes */
41                      udp_header_t udp;  /* 8 bytes */
42                      geneve_header_t geneve;    /* Min 8 bytes, Max 260 bytes */
43                      }) ip4_geneve_header_t;
44
45 typedef CLIB_PACKED (struct
46                      {
47                      ip6_header_t ip6;  /* 40 bytes */
48                      udp_header_t udp;  /* 8 bytes */
49                      geneve_header_t geneve;    /* Min 8 bytes, Max 260 bytes */
50                      }) ip6_geneve_header_t;
51
52 typedef CLIB_PACKED (struct
53                      {
54                      /*
55                       * Key fields: ip source and geneve vni on incoming GENEVE packet
56                       * all fields in NET byte order
57                       */
58                      union
59                      {
60                      struct
61                      {
62                      u32 remote;
63                      u32 vni;   /* shifted left 8 bits */
64                      };
65                      u64 as_u64;
66                      };
67                      }) geneve4_tunnel_key_t;
68
69 typedef CLIB_PACKED (struct
70                      {
71                      /*
72                       * Key fields: ip source and geneve vni on incoming GENEVE packet
73                       * all fields in NET byte order
74                       */
75                      ip6_address_t remote;
76                      u32 vni;   /* shifted left 8 bits */
77                      }) geneve6_tunnel_key_t;
78
79 typedef struct
80 {
81   u32 tunnel_index;
82   u32 vni;
83 } geneve_encap_trace_t;
84
85 typedef struct
86 {
87   /* Required for pool_get_aligned */
88   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
89
90   /* Rewrite string. $$$$ embed vnet_rewrite header */
91   u8 *rewrite;
92
93   /* FIB DPO for IP forwarding of GENEVE encap packet */
94   dpo_id_t next_dpo;
95
96   /* geneve VNI in HOST byte order */
97   u32 vni;
98
99   /* geneve OPTIONS LEN in HOST byte order */
100 #if SUPPORT_OPTIONS_HEADER==1
101   u8 options_len;
102 #endif
103
104   /* tunnel local and remote addresses */
105   ip46_address_t local;
106   ip46_address_t remote;
107
108   /* mcast packet output intfc index (used only if remote is mcast) */
109   u32 mcast_sw_if_index;
110
111   /* decap next index */
112   u32 decap_next_index;
113
114   /* The FIB index for local/remote addresses */
115   u32 encap_fib_index;
116
117   /* vnet intfc index */
118   u32 sw_if_index;
119   u32 hw_if_index;
120
121   /**
122    * Linkage into the FIB object graph
123    */
124   fib_node_t node;
125
126   /*
127    * The FIB entry for (depending on GENEVE tunnel is unicast or mcast)
128    * sending unicast GENEVE encap packets or receiving mcast GENEVE packets
129    */
130   fib_node_index_t fib_entry_index;
131   adj_index_t mcast_adj_index;
132
133   /**
134    * The tunnel is a child of the FIB entry for its desintion. This is
135    * so it receives updates when the forwarding information for that entry
136    * changes.
137    * The tunnels sibling index on the FIB entry's dependency list.
138    */
139   u32 sibling_index;
140
141   u8 l3_mode;
142 } geneve_tunnel_t;
143
144 #define foreach_geneve_input_next        \
145 _(DROP, "error-drop")                   \
146 _(L2_INPUT, "l2-input")
147
148 typedef enum
149 {
150 #define _(s,n) GENEVE_INPUT_NEXT_##s,
151   foreach_geneve_input_next
152 #undef _
153     GENEVE_INPUT_N_NEXT,
154 } geneve_input_next_t;
155
156 typedef enum
157 {
158 #define geneve_error(n,s) GENEVE_ERROR_##n,
159 #include <geneve/geneve_error.def>
160 #undef geneve_error
161   GENEVE_N_ERROR,
162 } geneve_input_error_t;
163
164 typedef struct
165 {
166   /* vector of encap tunnel instances */
167   geneve_tunnel_t *tunnels;
168
169   /* lookup tunnel by key */
170   uword *geneve4_tunnel_by_key; /* keyed on ipv4.remote + vni */
171   uword *geneve6_tunnel_by_key; /* keyed on ipv6.remote + vni */
172
173   /* local VTEP IPs ref count used by geneve-bypass node to check if
174      received GENEVE packet DIP matches any local VTEP address */
175   vtep_table_t vtep_table;
176
177   /* mcast shared info */
178   uword *mcast_shared;          /* keyed on mcast ip46 addr */
179
180   /* Mapping from sw_if_index to tunnel index */
181   u32 *tunnel_index_by_sw_if_index;
182
183   /* convenience */
184   vlib_main_t *vlib_main;
185   vnet_main_t *vnet_main;
186
187   u16 msg_id_base;
188 } geneve_main_t;
189
190 extern geneve_main_t geneve_main;
191
192 extern vlib_node_registration_t geneve4_input_node;
193 extern vlib_node_registration_t geneve6_input_node;
194 extern vlib_node_registration_t geneve4_encap_node;
195 extern vlib_node_registration_t geneve6_encap_node;
196
197 u8 *format_geneve_encap_trace (u8 * s, va_list * args);
198
199 typedef struct
200 {
201   u8 is_add;
202
203   /* we normally use is_ip4, but since this adds to the
204    * structure, this seems less of abreaking change */
205   u8 is_ip6;
206   ip46_address_t local, remote;
207   u32 mcast_sw_if_index;
208   u32 encap_fib_index;
209   u32 decap_next_index;
210   u32 vni;
211   u8 l3_mode;
212 } vnet_geneve_add_del_tunnel_args_t;
213
214 int vnet_geneve_add_del_tunnel
215   (vnet_geneve_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
216
217 void vnet_int_geneve_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable);
218 #endif /* included_vnet_geneve_h */
219
220 /*
221  * fd.io coding-style-patch-verification: ON
222  *
223  * Local Variables:
224  * eval: (c-set-style "gnu")
225  * End:
226  */