dpdk: Add support for Mellanox ConnectX-4 devices
[vpp.git] / vnet / vnet / sr / sr.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 /**
16  * @file
17  * @brief Segment Routing header
18  *
19  * @note sr_replicate only works using DPDK today
20  */
21 #ifndef included_vnet_sr_h
22 #define included_vnet_sr_h
23
24 #include <vnet/vnet.h>
25 #include <vnet/sr/sr_packet.h>
26 #include <vnet/ip/ip6_packet.h>
27
28 #include <openssl/opensslconf.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include <openssl/crypto.h>
33 #include <openssl/sha.h>
34 #include <openssl/opensslv.h>
35 #include <openssl/hmac.h>
36
37 /**
38  *    @brief Segment Route tunnel key
39  */
40 typedef struct
41 {
42   ip6_address_t src;
43   ip6_address_t dst;
44 } ip6_sr_tunnel_key_t;
45
46 /**
47  * @brief Segment Route tunnel
48  */
49 typedef struct
50 {
51   /** src, dst address */
52   ip6_sr_tunnel_key_t key;
53
54   /** Pptional tunnel name */
55   u8 *name;
56
57   /** Mask width for FIB entry */
58   u32 dst_mask_width;
59
60   /** First hop, to save 1 elt in the segment list */
61   ip6_address_t first_hop;
62
63   /** RX Fib index */
64   u32 rx_fib_index;
65   /** TX Fib index */
66   u32 tx_fib_index;
67
68   /** The actual ip6 SR header */
69   u8 *rewrite;
70
71   /** Indicates that this tunnel is part of a policy comprising
72      of multiple tunnels. If == ~0 tunnel is not part of a policy */
73   u32 policy_index;
74 } ip6_sr_tunnel_t;
75
76 /**
77  * @brief Shared secret for keyed-hash message authentication code (HMAC).
78  */
79 typedef struct
80 {
81   u8 *shared_secret;
82 } ip6_sr_hmac_key_t;
83
84 /**
85  * @brief Args required for add/del tunnel.
86  *
87  * Else we end up passing a LOT of parameters around.
88  */
89 typedef struct
90 {
91   /** Key (header imposition case) */
92   ip6_address_t *src_address;
93   ip6_address_t *dst_address;
94   u32 dst_mask_width;
95   u32 rx_table_id;
96   u32 tx_table_id;
97
98   /** optional name argument - for referencing SR tunnel/policy by name */
99   u8 *name;
100
101   /** optional policy name */
102   u8 *policy_name;
103
104   /** segment list, when inserting an ip6 SR header */
105   ip6_address_t *segments;
106
107   /**
108    * "Tag" list, aka segments inserted at the end of the list,
109    * past last_seg
110    */
111   ip6_address_t *tags;
112
113   /** Shared secret => generate SHA-256 HMAC security fields */
114   u8 *shared_secret;
115
116   /** Flags, e.g. cleanup, policy-list flags */
117   u16 flags_net_byte_order;
118
119   /** Delete the tunnnel? */
120   u8 is_del;
121 } ip6_sr_add_del_tunnel_args_t;
122
123 /**
124  * @brief Args for creating a policy.
125  *
126  * Typically used for multicast replication.
127  * ie a multicast address can be associated with a policy,
128  * then replicated across a number of unicast SR tunnels.
129  */
130 typedef struct
131 {
132   /** policy name */
133   u8 *name;
134
135   /** tunnel names */
136   u8 **tunnel_names;
137
138   /** Delete the policy? */
139   u8 is_del;
140 } ip6_sr_add_del_policy_args_t;
141
142 /**
143  * @brief Segment Routing policy.
144  *
145  * Typically used for multicast replication.
146  * ie a multicast address can be associated with a policy,
147  * then replicated across a number of unicast SR tunnels.
148  */
149 typedef struct
150 {
151   /** name of policy */
152   u8 *name;
153
154   /** vector to SR tunnel index */
155   u32 *tunnel_indices;
156
157 } ip6_sr_policy_t;
158
159 /**
160  * @brief Args for mapping of multicast address to policy name.
161  *
162  * Typically used for multicast replication.
163  * ie a multicast address can be associated with a policy,
164  * then replicated across a number of unicast SR tunnels.
165  */
166 typedef struct
167 {
168   /** multicast IP6 address */
169   ip6_address_t *multicast_address;
170
171   /** name of policy to map to */
172   u8 *policy_name;
173
174   /** Delete the mapping */
175   u8 is_del;
176
177 } ip6_sr_add_del_multicastmap_args_t;
178
179 /**
180  * @brief Segment Routing state.
181  */
182 typedef struct
183 {
184   /** pool of tunnel instances, sr entry only */
185   ip6_sr_tunnel_t *tunnels;
186
187   /** find an sr "tunnel" by its outer-IP src/dst */
188   uword *tunnel_index_by_key;
189
190   /** find an sr "tunnel" by its name */
191   uword *tunnel_index_by_name;
192
193   /** policy pool */
194   ip6_sr_policy_t *policies;
195
196   /** find a policy by name */
197   uword *policy_index_by_policy_name;
198
199   /** multicast address to policy mapping */
200   uword *policy_index_by_multicast_address;
201
202   /** hmac key id by shared secret */
203   uword *hmac_key_by_shared_secret;
204
205   /** ip6-rewrite next index for reinstalling the original dst address */
206   u32 ip6_rewrite_sr_next_index;
207
208   /** ip6-replicate next index for multicast tunnel */
209   u32 ip6_lookup_sr_replicate_index;
210
211   /** application API callback */
212   void *sr_local_cb;
213
214   /** validate hmac keys */
215   u8 validate_hmac;
216
217   /** pool of hmac keys */
218   ip6_sr_hmac_key_t *hmac_keys;
219
220   /** Openssl var */
221   EVP_MD *md;
222   /** Openssl var */
223   HMAC_CTX *hmac_ctx;
224
225   /** enable debug spew */
226   u8 is_debug;
227
228   /** convenience */
229   vlib_main_t *vlib_main;
230   /** convenience */
231   vnet_main_t *vnet_main;
232 } ip6_sr_main_t;
233
234 ip6_sr_main_t sr_main;
235
236 format_function_t format_ip6_sr_header;
237 format_function_t format_ip6_sr_header_with_length;
238
239 vlib_node_registration_t ip6_sr_input_node;
240
241 #if DPDK > 0
242 extern vlib_node_registration_t sr_replicate_node;
243 #endif /* DPDK */
244
245 int ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a);
246 int ip6_sr_add_del_policy (ip6_sr_add_del_policy_args_t * a);
247 int ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a);
248
249 void vnet_register_sr_app_callback (void *cb);
250
251 void sr_fix_hmac (ip6_sr_main_t * sm, ip6_header_t * ip,
252                   ip6_sr_header_t * sr);
253
254 #endif /* included_vnet_sr_h */
255
256 /*
257  * fd.io coding-style-patch-verification: ON
258  *
259  * Local Variables:
260  * eval: (c-set-style "gnu")
261  * End:
262  */