FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
ikev2_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * ipsec_api.c - ipsec api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 #include <vnet/api_errno.h>
23 #include <vpp/app/version.h>
24 
25 #include <ikev2/ikev2.h>
26 #include <ikev2/ikev2_priv.h>
27 
28 /* define message IDs */
29 #include <vnet/format_fns.h>
30 #include <plugins/ikev2/ikev2.api_enum.h>
31 #include <plugins/ikev2/ikev2.api_types.h>
32 
34 
35 #define IKEV2_PLUGIN_VERSION_MAJOR 1
36 #define IKEV2_PLUGIN_VERSION_MINOR 0
37 #define REPLY_MSG_ID_BASE ikev2_main.msg_id_base
39 
40 static void
42  mp)
43 {
44  ikev2_main_t *im = &ikev2_main;
46  int msg_size = sizeof (*rmp);
48 
50  if (!reg)
51  return;
52 
53  rmp = vl_msg_api_alloc (msg_size);
54  clib_memset (rmp, 0, msg_size);
55  rmp->_vl_msg_id =
56  ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION_REPLY + im->msg_id_base);
57  rmp->context = mp->context;
58  rmp->major = htonl (IKEV2_PLUGIN_VERSION_MAJOR);
59  rmp->minor = htonl (IKEV2_PLUGIN_VERSION_MINOR);
60 
61  vl_api_send_msg (reg, (u8 *) rmp);
62 }
63 
64 static void
66 {
67  vl_api_ikev2_profile_add_del_reply_t *rmp;
68  int rv = 0;
69 
70 #if WITH_LIBSSL > 0
72  clib_error_t *error;
73  u8 *tmp = format (0, "%s", mp->name);
74  error = ikev2_add_del_profile (vm, tmp, mp->is_add);
75  vec_free (tmp);
76  if (error)
77  rv = VNET_API_ERROR_UNSPECIFIED;
78 #else
79  rv = VNET_API_ERROR_UNIMPLEMENTED;
80 #endif
81 
82  REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
83 }
84 
85 static void
88 {
89  vl_api_ikev2_profile_set_auth_reply_t *rmp;
90  int rv = 0;
91 
92 #if WITH_LIBSSL > 0
94  clib_error_t *error;
95  int data_len = ntohl (mp->data_len);
96  u8 *tmp = format (0, "%s", mp->name);
97  u8 *data = vec_new (u8, data_len);
98  clib_memcpy (data, mp->data, data_len);
99  error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
100  vec_free (tmp);
101  vec_free (data);
102  if (error)
103  rv = VNET_API_ERROR_UNSPECIFIED;
104 #else
105  rv = VNET_API_ERROR_UNIMPLEMENTED;
106 #endif
107 
108  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
109 }
110 
111 static void
113 {
114  vl_api_ikev2_profile_add_del_reply_t *rmp;
115  int rv = 0;
116 
117 #if WITH_LIBSSL > 0
119  clib_error_t *error;
120  u8 *tmp = format (0, "%s", mp->name);
121  int data_len = ntohl (mp->data_len);
122  u8 *data = vec_new (u8, data_len);
123  clib_memcpy (data, mp->data, data_len);
124  error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
125  vec_free (tmp);
126  vec_free (data);
127  if (error)
128  rv = VNET_API_ERROR_UNSPECIFIED;
129 #else
130  rv = VNET_API_ERROR_UNIMPLEMENTED;
131 #endif
132 
133  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
134 }
135 
136 static void
138 {
139  vl_api_ikev2_profile_set_ts_reply_t *rmp;
140  int rv = 0;
141 
142 #if WITH_LIBSSL > 0
144  clib_error_t *error;
145  u8 *tmp = format (0, "%s", mp->name);
146  error =
147  ikev2_set_profile_ts (vm, tmp, mp->proto,
148  clib_net_to_host_u16 (mp->start_port),
149  clib_net_to_host_u16 (mp->end_port),
151  (ip4_address_t) mp->end_addr, mp->is_local);
152  vec_free (tmp);
153  if (error)
154  rv = VNET_API_ERROR_UNSPECIFIED;
155 #else
156  rv = VNET_API_ERROR_UNIMPLEMENTED;
157 #endif
158 
159  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
160 }
161 
162 static void
164 {
165  vl_api_ikev2_profile_set_ts_reply_t *rmp;
166  int rv = 0;
167 
168 #if WITH_LIBSSL > 0
170  clib_error_t *error;
171 
172  error = ikev2_set_local_key (vm, mp->key_file);
173  if (error)
174  rv = VNET_API_ERROR_UNSPECIFIED;
175 #else
176  rv = VNET_API_ERROR_UNIMPLEMENTED;
177 #endif
178 
179  REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
180 }
181 
182 static void
184 {
185  vl_api_ikev2_set_responder_reply_t *rmp;
186  int rv = 0;
187 
188 #if WITH_LIBSSL > 0
190  clib_error_t *error;
191 
192  u8 *tmp = format (0, "%s", mp->name);
194  clib_memcpy (&ip4, mp->address, sizeof (ip4));
195 
196  error = ikev2_set_profile_responder (vm, tmp, ntohl (mp->sw_if_index), ip4);
197  vec_free (tmp);
198  if (error)
199  rv = VNET_API_ERROR_UNSPECIFIED;
200 #else
201  rv = VNET_API_ERROR_UNIMPLEMENTED;
202 #endif
203 
204  REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
205 }
206 
207 static void
209  mp)
210 {
211  vl_api_ikev2_set_ike_transforms_reply_t *rmp;
212  int rv = 0;
213 
214 #if WITH_LIBSSL > 0
216  clib_error_t *error;
217 
218  u8 *tmp = format (0, "%s", mp->name);
219 
220  error =
221  ikev2_set_profile_ike_transforms (vm, tmp, ntohl (mp->crypto_alg),
222  ntohl (mp->integ_alg),
223  ntohl (mp->dh_group),
224  ntohl (mp->crypto_key_size));
225  vec_free (tmp);
226  if (error)
227  rv = VNET_API_ERROR_UNSPECIFIED;
228 #else
229  rv = VNET_API_ERROR_UNIMPLEMENTED;
230 #endif
231 
232  REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
233 }
234 
235 static void
237  mp)
238 {
239  vl_api_ikev2_set_esp_transforms_reply_t *rmp;
240  int rv = 0;
241 
242 #if WITH_LIBSSL > 0
244  clib_error_t *error;
245 
246  u8 *tmp = format (0, "%s", mp->name);
247 
248  error =
249  ikev2_set_profile_esp_transforms (vm, tmp, ntohl (mp->crypto_alg),
250  ntohl (mp->integ_alg),
251  ntohl (mp->dh_group),
252  ntohl (mp->crypto_key_size));
253  vec_free (tmp);
254  if (error)
255  rv = VNET_API_ERROR_UNSPECIFIED;
256 #else
257  rv = VNET_API_ERROR_UNIMPLEMENTED;
258 #endif
259 
260  REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
261 }
262 
263 static void
265 {
266  vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
267  int rv = 0;
268 
269 #if WITH_LIBSSL > 0
271  clib_error_t *error;
272 
273  u8 *tmp = format (0, "%s", mp->name);
274 
275  error =
277  clib_net_to_host_u64 (mp->lifetime),
278  ntohl (mp->lifetime_jitter),
279  ntohl (mp->handover),
280  clib_net_to_host_u64
281  (mp->lifetime_maxdata));
282  vec_free (tmp);
283  if (error)
284  rv = VNET_API_ERROR_UNSPECIFIED;
285 #else
286  rv = VNET_API_ERROR_UNIMPLEMENTED;
287 #endif
288 
289  REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
290 }
291 
292 static void
294 {
295  vl_api_ikev2_initiate_sa_init_reply_t *rmp;
296  int rv = 0;
297 
298 #if WITH_LIBSSL > 0
300  clib_error_t *error;
301 
302  u8 *tmp = format (0, "%s", mp->name);
303 
304  error = ikev2_initiate_sa_init (vm, tmp);
305  vec_free (tmp);
306  if (error)
307  rv = VNET_API_ERROR_UNSPECIFIED;
308 #else
309  rv = VNET_API_ERROR_UNIMPLEMENTED;
310 #endif
311 
312  REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
313 }
314 
315 static void
317  * mp)
318 {
319  vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
320  int rv = 0;
321 
322 #if WITH_LIBSSL > 0
324  clib_error_t *error;
325 
326  error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
327  if (error)
328  rv = VNET_API_ERROR_UNSPECIFIED;
329 #else
330  rv = VNET_API_ERROR_UNIMPLEMENTED;
331 #endif
332 
333  REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
334 }
335 
336 static void
339 {
340  vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
341  int rv = 0;
342 
343 #if WITH_LIBSSL > 0
345  clib_error_t *error;
346 
347  error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
348  if (error)
349  rv = VNET_API_ERROR_UNSPECIFIED;
350 #else
351  rv = VNET_API_ERROR_UNIMPLEMENTED;
352 #endif
353 
354  REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
355 }
356 
357 static void
360 {
361  vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
362  int rv = 0;
363 
364 #if WITH_LIBSSL > 0
366  clib_error_t *error;
367 
368  error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
369  if (error)
370  rv = VNET_API_ERROR_UNSPECIFIED;
371 #else
372  rv = VNET_API_ERROR_UNIMPLEMENTED;
373 #endif
374 
375  REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
376 }
377 
378 #include <ikev2/ikev2.api.c>
379 static clib_error_t *
381 {
382  ikev2_main_t *im = &ikev2_main;
383 
384  /* Ask for a correctly-sized block of API message decode slots */
386 
387  return 0;
388 }
389 
391 
392 /*
393  * fd.io coding-style-patch-verification: ON
394  *
395  * Local Variables:
396  * eval: (c-set-style "gnu")
397  * End:
398  */
clib_error_t * ikev2_set_profile_responder(vlib_main_t *vm, u8 *name, u32 sw_if_index, ip4_address_t ip4)
Definition: ikev2.c:3018
static void vl_api_ikev2_initiate_rekey_child_sa_t_handler(vl_api_ikev2_initiate_rekey_child_sa_t *mp)
Definition: ikev2_api.c:359
IKEv2: Set Child SA lifetime, limited by time and/or data.
Definition: ikev2.api:227
clib_error_t * ikev2_add_del_profile(vlib_main_t *vm, u8 *name, int is_add)
Definition: ikev2.c:2877
IKEv2: Add/delete profile.
Definition: ikev2.api:51
clib_error_t * ikev2_initiate_delete_ike_sa(vlib_main_t *vm, u64 ispi)
Definition: ikev2.c:3334
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
clib_error_t * ikev2_set_profile_sa_lifetime(vlib_main_t *vm, u8 *name, u64 lifetime, u32 jitter, u32 handover, u64 maxdata)
Definition: ikev2.c:3089
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void vl_api_ikev2_initiate_sa_init_t_handler(vl_api_ikev2_initiate_sa_init_t *mp)
Definition: ikev2_api.c:293
static void vl_api_ikev2_set_sa_lifetime_t_handler(vl_api_ikev2_set_sa_lifetime_t *mp)
Definition: ikev2_api.c:264
void * vl_msg_api_alloc(int nbytes)
static void vl_api_ikev2_initiate_del_ike_sa_t_handler(vl_api_ikev2_initiate_del_ike_sa_t *mp)
Definition: ikev2_api.c:316
unsigned char u8
Definition: types.h:56
#define clib_memcpy(d, s, n)
Definition: string.h:180
IKEv2: Set IKEv2 IKE transforms in SA_INIT proposal (RFC 7296)
Definition: ikev2.api:179
static void vl_api_ikev2_plugin_get_version_t_handler(vl_api_ikev2_plugin_get_version_t *mp)
Definition: ikev2_api.c:41
static void vl_api_ikev2_set_local_key_t_handler(vl_api_ikev2_set_local_key_t *mp)
Definition: ikev2_api.c:163
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
clib_error_t * ikev2_initiate_sa_init(vlib_main_t *vm, u8 *name)
Definition: ikev2.c:3112
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:312
clib_error_t * ikev2_set_profile_auth(vlib_main_t *vm, u8 *name, u8 auth_method, u8 *auth_data, u8 data_hex_format)
Definition: ikev2.c:2908
IKEv2: Initiate the delete Child SA exchange.
Definition: ikev2.api:279
clib_error_t * ikev2_set_profile_esp_transforms(vlib_main_t *vm, u8 *name, ikev2_transform_encr_type_t crypto_alg, ikev2_transform_integ_type_t integ_alg, ikev2_transform_dh_type_t dh_type, u32 crypto_key_size)
Definition: ikev2.c:3064
IKEv2: Set IKEv2 profile local/remote identification.
Definition: ikev2.api:94
static void vl_api_ikev2_profile_set_ts_t_handler(vl_api_ikev2_profile_set_ts_t *mp)
Definition: ikev2_api.c:137
IKEv2: Set IKEv2 profile traffic selector parameters.
Definition: ikev2.api:119
static void vl_api_ikev2_set_ike_transforms_t_handler(vl_api_ikev2_set_ike_transforms_t *mp)
Definition: ikev2_api.c:208
clib_error_t * ikev2_set_profile_id(vlib_main_t *vm, u8 *name, u8 id_type, u8 *data, int is_local)
Definition: ikev2.c:2940
IKEv2: Initiate the rekey Child SA exchange.
Definition: ikev2.api:295
clib_error_t * ikev2_initiate_delete_child_sa(vlib_main_t *vm, u32 ispi)
Definition: ikev2.c:3294
#define REPLY_MACRO(t)
vlib_main_t * vm
Definition: in2out_ed.c:1810
static void vl_api_ikev2_set_responder_t_handler(vl_api_ikev2_set_responder_t *mp)
Definition: ikev2_api.c:183
clib_error_t * ikev2_set_local_key(vlib_main_t *vm, u8 *file)
Definition: ikev2.c:2865
clib_error_t * ikev2_set_profile_ts(vlib_main_t *vm, u8 *name, u8 protocol_id, u16 start_port, u16 end_port, ip4_address_t start_addr, ip4_address_t end_addr, int is_local)
Definition: ikev2.c:2979
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
clib_error_t * ikev2_initiate_rekey_child_sa(vlib_main_t *vm, u32 ispi)
Definition: ikev2.c:3444
static void vl_api_ikev2_initiate_del_child_sa_t_handler(vl_api_ikev2_initiate_del_child_sa_t *mp)
Definition: ikev2_api.c:338
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
vl_api_ip4_address_t address
Definition: ikev2.api:164
IKEv2: Initiate the SA_INIT exchange.
Definition: ikev2.api:247
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
u8 data[128]
Definition: ipsec_types.api:87
IKEv2: Set IKEv2 responder interface and IP address.
Definition: ikev2.api:157
IKEv2: Initiate the delete IKE SA exchange.
Definition: ikev2.api:263
IKEv2: Set IKEv2 profile authentication method.
Definition: ikev2.api:71
static void vl_api_ikev2_profile_set_auth_t_handler(vl_api_ikev2_profile_set_auth_t *mp)
Definition: ikev2_api.c:87
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
ikev2_main_t ikev2_main
Definition: ikev2.c:32
#define IKEV2_PLUGIN_VERSION_MINOR
Definition: ikev2_api.c:36
#define IKEV2_PLUGIN_VERSION_MAJOR
Definition: ikev2_api.c:35
IKEv2: Set IKEv2 local RSA private key.
Definition: ikev2.api:140
static void vl_api_ikev2_profile_set_id_t_handler(vl_api_ikev2_profile_set_id_t *mp)
Definition: ikev2_api.c:112
clib_error_t * ikev2_set_profile_ike_transforms(vlib_main_t *vm, u8 *name, ikev2_transform_encr_type_t crypto_alg, ikev2_transform_integ_type_t integ_alg, ikev2_transform_dh_type_t dh_type, u32 crypto_key_size)
Definition: ikev2.c:3039
Get the plugin version.
Definition: ikev2.api:26
IKEv2: Set IKEv2 ESP transforms in SA_INIT proposal (RFC 7296)
Definition: ikev2.api:203
static void vl_api_ikev2_set_esp_transforms_t_handler(vl_api_ikev2_set_esp_transforms_t *mp)
Definition: ikev2_api.c:236
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3410
static void vl_api_ikev2_profile_add_del_t_handler(vl_api_ikev2_profile_add_del_t *mp)
Definition: ikev2_api.c:65
Reply to get the plugin version.
Definition: ikev2.api:37
vl_api_interface_index_t sw_if_index
Definition: ikev2.api:163
u32 ip4
Definition: one.api:440
static clib_error_t * ikev2_api_init(vlib_main_t *vm)
Definition: ikev2_api.c:380