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