FD.io VPP  v21.01.1
Vector Packet Processing
ipsec_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 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/ip/ip.h>
26 #include <vnet/ip/ip_types_api.h>
29 #include <vnet/fib/fib.h>
30 #include <vnet/ipip/ipip.h>
32 
33 #include <vnet/vnet_msg_enum.h>
34 
35 #if WITH_LIBSSL > 0
36 #include <vnet/ipsec/ipsec.h>
37 #include <vnet/ipsec/ipsec_tun.h>
38 #include <vnet/ipsec/ipsec_itf.h>
39 #endif /* IPSEC */
40 
41 #define vl_typedefs /* define message structures */
42 #include <vnet/vnet_all_api_h.h>
43 #undef vl_typedefs
44 
45 #define vl_endianfun /* define message structures */
46 #include <vnet/vnet_all_api_h.h>
47 #undef vl_endianfun
48 
49 /* instantiate all the print functions we know about */
50 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51 #define vl_printfun
52 #include <vnet/vnet_all_api_h.h>
53 #undef vl_printfun
54 
56 
57 #define foreach_vpe_api_msg \
58 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
59 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
60 _(IPSEC_SPD_ENTRY_ADD_DEL, ipsec_spd_entry_add_del) \
61 _(IPSEC_SAD_ENTRY_ADD_DEL, ipsec_sad_entry_add_del) \
62 _(IPSEC_SAD_ENTRY_ADD_DEL_V2, ipsec_sad_entry_add_del_v2) \
63 _(IPSEC_SA_DUMP, ipsec_sa_dump) \
64 _(IPSEC_SA_V2_DUMP, ipsec_sa_v2_dump) \
65 _(IPSEC_SPDS_DUMP, ipsec_spds_dump) \
66 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
67 _(IPSEC_SPD_INTERFACE_DUMP, ipsec_spd_interface_dump) \
68 _(IPSEC_ITF_CREATE, ipsec_itf_create) \
69 _(IPSEC_ITF_DELETE, ipsec_itf_delete) \
70 _(IPSEC_ITF_DUMP, ipsec_itf_dump) \
71 _(IPSEC_TUNNEL_IF_ADD_DEL, ipsec_tunnel_if_add_del) \
72 _(IPSEC_TUNNEL_IF_SET_SA, ipsec_tunnel_if_set_sa) \
73 _(IPSEC_SELECT_BACKEND, ipsec_select_backend) \
74 _(IPSEC_BACKEND_DUMP, ipsec_backend_dump) \
75 _(IPSEC_TUNNEL_PROTECT_UPDATE, ipsec_tunnel_protect_update) \
76 _(IPSEC_TUNNEL_PROTECT_DEL, ipsec_tunnel_protect_del) \
77 _(IPSEC_TUNNEL_PROTECT_DUMP, ipsec_tunnel_protect_dump) \
78 _(IPSEC_SET_ASYNC_MODE, ipsec_set_async_mode)
79 
80 static void
82 {
83 #if WITH_LIBSSL == 0
84  clib_warning ("unimplemented");
85 #else
86 
87  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
88  vl_api_ipsec_spd_add_del_reply_t *rmp;
89  int rv;
90 
91  rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
92 
93  REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
94 #endif
95 }
96 
99 {
100  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
101  vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
102  int rv;
103  u32 sw_if_index __attribute__ ((unused));
104  u32 spd_id __attribute__ ((unused));
105 
106  sw_if_index = ntohl (mp->sw_if_index);
107  spd_id = ntohl (mp->spd_id);
108 
110 
111 #if WITH_LIBSSL > 0
112  rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
113 #else
114  rv = VNET_API_ERROR_UNIMPLEMENTED;
115 #endif
116 
118 
119  REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
120 }
121 
124 {
125  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
126  vl_api_ipsec_tunnel_protect_update_reply_t *rmp;
127  u32 sw_if_index, ii, *sa_ins = NULL;
129  int rv;
130 
131  sw_if_index = ntohl (mp->tunnel.sw_if_index);
132 
133  VALIDATE_SW_IF_INDEX (&(mp->tunnel));
134 
135 #if WITH_LIBSSL > 0
136 
137  for (ii = 0; ii < mp->tunnel.n_sa_in; ii++)
138  vec_add1 (sa_ins, ntohl (mp->tunnel.sa_in[ii]));
139 
140  ip_address_decode2 (&mp->tunnel.nh, &nh);
141 
142  rv = ipsec_tun_protect_update (sw_if_index, &nh,
143  ntohl (mp->tunnel.sa_out), sa_ins);
144 #else
145  rv = VNET_API_ERROR_UNIMPLEMENTED;
146 #endif
147 
149 
150  REPLY_MACRO (VL_API_IPSEC_TUNNEL_PROTECT_UPDATE_REPLY);
151 }
152 
155 {
156  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
157  vl_api_ipsec_tunnel_protect_del_reply_t *rmp;
160  int rv;
161 
162  sw_if_index = ntohl (mp->sw_if_index);
163 
165 
166 #if WITH_LIBSSL > 0
167  ip_address_decode2 (&mp->nh, &nh);
168  rv = ipsec_tun_protect_del (sw_if_index, &nh);
169 #else
170  rv = VNET_API_ERROR_UNIMPLEMENTED;
171 #endif
172 
174 
175  REPLY_MACRO (VL_API_IPSEC_TUNNEL_PROTECT_DEL_REPLY);
176 }
177 
179 {
183 
184 static walk_rc_t
186 {
187  ipsec_dump_walk_ctx_t *ctx = arg;
189  ipsec_tun_protect_t *itp;
190  u32 ii = 0;
191  ipsec_sa_t *sa;
192 
193  itp = ipsec_tun_protect_get (itpi);
194 
195  mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (u32) * itp->itp_n_sa_in));
196  clib_memset (mp, 0, sizeof (*mp));
197  mp->_vl_msg_id = ntohs (VL_API_IPSEC_TUNNEL_PROTECT_DETAILS);
198  mp->context = ctx->context;
199 
200  mp->tun.sw_if_index = htonl (itp->itp_sw_if_index);
201  ip_address_encode2 (itp->itp_key, &mp->tun.nh);
202 
203  sa = ipsec_sa_get (itp->itp_out_sa);
204  mp->tun.sa_out = htonl (sa->id);
205  mp->tun.n_sa_in = itp->itp_n_sa_in;
206  /* *INDENT-OFF* */
208  ({
209  mp->tun.sa_in[ii++] = htonl (sa->id);
210  }));
211  /* *INDENT-ON* */
212 
213  vl_api_send_msg (ctx->reg, (u8 *) mp);
214 
215  return (WALK_CONTINUE);
216 }
217 
218 static void
220  * mp)
221 {
224 
225 #if WITH_LIBSSL > 0
227  if (!reg)
228  return;
229 
231  .reg = reg,
232  .context = mp->context,
233  };
234 
235  sw_if_index = ntohl (mp->sw_if_index);
236 
237  if (~0 == sw_if_index)
238  {
240  }
241  else
242  {
243  ipsec_tun_protect_walk_itf (sw_if_index,
245  }
246 #else
247  clib_warning ("unimplemented");
248 #endif
249 }
250 
251 static int
252 ipsec_spd_action_decode (vl_api_ipsec_spd_action_t in,
253  ipsec_policy_action_t * out)
254 {
255  in = clib_net_to_host_u32 (in);
256 
257  switch (in)
258  {
259 #define _(v,f,s) case IPSEC_API_SPD_ACTION_##f: \
260  *out = IPSEC_POLICY_ACTION_##f; \
261  return (0);
263 #undef _
264  }
265  return (VNET_API_ERROR_UNIMPLEMENTED);
266 }
267 
270 {
271  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
273  ip46_type_t itype;
274  u32 stat_index;
275  int rv;
276 
277  stat_index = ~0;
278 
279 #if WITH_LIBSSL > 0
280  ipsec_policy_t p;
281 
282  clib_memset (&p, 0, sizeof (p));
283 
284  p.id = ntohl (mp->entry.spd_id);
285  p.priority = ntohl (mp->entry.priority);
286 
287  itype = ip_address_decode (&mp->entry.remote_address_start, &p.raddr.start);
288  ip_address_decode (&mp->entry.remote_address_stop, &p.raddr.stop);
289  ip_address_decode (&mp->entry.local_address_start, &p.laddr.start);
290  ip_address_decode (&mp->entry.local_address_stop, &p.laddr.stop);
291 
292  p.is_ipv6 = (itype == IP46_TYPE_IP6);
293 
294  p.protocol = mp->entry.protocol;
295  p.rport.start = ntohs (mp->entry.remote_port_start);
296  p.rport.stop = ntohs (mp->entry.remote_port_stop);
297  p.lport.start = ntohs (mp->entry.local_port_start);
298  p.lport.stop = ntohs (mp->entry.local_port_stop);
299 
300  rv = ipsec_spd_action_decode (mp->entry.policy, &p.policy);
301 
302  if (rv)
303  goto out;
304 
305  /* policy action resolve unsupported */
306  if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
307  {
308  clib_warning ("unsupported action: 'resolve'");
309  rv = VNET_API_ERROR_UNIMPLEMENTED;
310  goto out;
311  }
312  p.sa_id = ntohl (mp->entry.sa_id);
313  rv =
314  ipsec_policy_mk_type (mp->entry.is_outbound, p.is_ipv6, p.policy,
315  &p.type);
316  if (rv)
317  goto out;
318 
319  rv = ipsec_add_del_policy (vm, &p, mp->is_add, &stat_index);
320  if (rv)
321  goto out;
322 
323 #else
324  rv = VNET_API_ERROR_UNIMPLEMENTED;
325  goto out;
326 #endif
327 
328 out:
329  /* *INDENT-OFF* */
330  REPLY_MACRO2 (VL_API_IPSEC_SPD_ENTRY_ADD_DEL_REPLY,
331  ({
332  rmp->stat_index = ntohl(stat_index);
333  }));
334  /* *INDENT-ON* */
335 }
336 
339 {
340  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
342  ip46_address_t tun_src = { }, tun_dst =
343  {
344  };
345  ipsec_key_t crypto_key, integ_key;
346  ipsec_crypto_alg_t crypto_alg;
347  ipsec_integ_alg_t integ_alg;
348  ipsec_protocol_t proto;
350  u32 id, spi, sa_index = ~0;
351  int rv;
352 
353 #if WITH_LIBSSL > 0
354 
355  id = ntohl (mp->entry.sad_id);
356  spi = ntohl (mp->entry.spi);
357 
358  rv = ipsec_proto_decode (mp->entry.protocol, &proto);
359 
360  if (rv)
361  goto out;
362 
363  rv = ipsec_crypto_algo_decode (mp->entry.crypto_algorithm, &crypto_alg);
364 
365  if (rv)
366  goto out;
367 
368  rv = ipsec_integ_algo_decode (mp->entry.integrity_algorithm, &integ_alg);
369 
370  if (rv)
371  goto out;
372 
373  ipsec_key_decode (&mp->entry.crypto_key, &crypto_key);
374  ipsec_key_decode (&mp->entry.integrity_key, &integ_key);
375 
376  flags = ipsec_sa_flags_decode (mp->entry.flags);
377 
378  ip_address_decode (&mp->entry.tunnel_src, &tun_src);
379  ip_address_decode (&mp->entry.tunnel_dst, &tun_dst);
380 
381  if (mp->is_add)
382  rv = ipsec_sa_add_and_lock (id, spi, proto,
383  crypto_alg, &crypto_key,
384  integ_alg, &integ_key, flags,
385  0, mp->entry.salt, &tun_src, &tun_dst,
386  TUNNEL_ENCAP_DECAP_FLAG_NONE,
387  IP_DSCP_CS0,
388  &sa_index,
389  htons (mp->entry.udp_src_port),
390  htons (mp->entry.udp_dst_port));
391  else
392  rv = ipsec_sa_unlock_id (id);
393 
394 #else
395  rv = VNET_API_ERROR_UNIMPLEMENTED;
396 #endif
397 
398 out:
399  /* *INDENT-OFF* */
400  REPLY_MACRO2 (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_REPLY,
401  {
402  rmp->stat_index = htonl (sa_index);
403  });
404  /* *INDENT-ON* */
405 }
406 
409 {
410  vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
412  ip46_address_t tun_src = { }, tun_dst =
413  {
414  };
416  ipsec_key_t crypto_key, integ_key;
417  ipsec_crypto_alg_t crypto_alg;
418  ipsec_integ_alg_t integ_alg;
419  ipsec_protocol_t proto;
421  u32 id, spi, sa_index = ~0;
422  int rv;
423 
424 #if WITH_LIBSSL > 0
425 
426  id = ntohl (mp->entry.sad_id);
427  spi = ntohl (mp->entry.spi);
428 
429  rv = ipsec_proto_decode (mp->entry.protocol, &proto);
430 
431  if (rv)
432  goto out;
433 
434  rv = ipsec_crypto_algo_decode (mp->entry.crypto_algorithm, &crypto_alg);
435 
436  if (rv)
437  goto out;
438 
439  rv = ipsec_integ_algo_decode (mp->entry.integrity_algorithm, &integ_alg);
440 
441  if (rv)
442  goto out;
443 
444  rv =
445  tunnel_encap_decap_flags_decode (mp->entry.tunnel_flags, &tunnel_flags);
446 
447  if (rv)
448  goto out;
449 
450  ipsec_key_decode (&mp->entry.crypto_key, &crypto_key);
451  ipsec_key_decode (&mp->entry.integrity_key, &integ_key);
452 
453  flags = ipsec_sa_flags_decode (mp->entry.flags);
454 
455  ip_address_decode (&mp->entry.tunnel_src, &tun_src);
456  ip_address_decode (&mp->entry.tunnel_dst, &tun_dst);
457 
458  if (mp->is_add)
459  rv = ipsec_sa_add_and_lock (id, spi, proto,
460  crypto_alg, &crypto_key,
461  integ_alg, &integ_key, flags,
462  0, mp->entry.salt, &tun_src, &tun_dst,
463  tunnel_flags,
464  ip_dscp_decode (mp->entry.dscp),
465  &sa_index,
466  htons (mp->entry.udp_src_port),
467  htons (mp->entry.udp_dst_port));
468  else
469  rv = ipsec_sa_unlock_id (id);
470 
471 #else
472  rv = VNET_API_ERROR_UNIMPLEMENTED;
473 #endif
474 
475 out:
476  /* *INDENT-OFF* */
477  REPLY_MACRO2 (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_V2_REPLY,
478  {
479  rmp->stat_index = htonl (sa_index);
480  });
481  /* *INDENT-ON* */
482 }
483 
484 static void
486  u32 context)
487 {
489  u32 n_policies = 0;
490 
491  mp = vl_msg_api_alloc (sizeof (*mp));
492  clib_memset (mp, 0, sizeof (*mp));
493  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPDS_DETAILS);
494  mp->context = context;
495 
496  mp->spd_id = htonl (spd->id);
497 #define _(s, n) n_policies += vec_len (spd->policies[IPSEC_SPD_POLICY_##s]);
499 #undef _
500  mp->npolicies = htonl (n_policies);
501 
502  vl_api_send_msg (reg, (u8 *) mp);
503 }
504 
505 static void
507 {
509  ipsec_main_t *im = &ipsec_main;
510  ipsec_spd_t *spd;
511 #if WITH_LIBSSL > 0
513  if (!reg)
514  return;
515 
516  /* *INDENT-OFF* */
517  pool_foreach (spd, im->spds) {
518  send_ipsec_spds_details (spd, reg, mp->context);
519  }
520  /* *INDENT-ON* */
521 #else
522  clib_warning ("unimplemented");
523 #endif
524 }
525 
526 vl_api_ipsec_spd_action_t
528 {
529  vl_api_ipsec_spd_action_t out = IPSEC_API_SPD_ACTION_BYPASS;
530 
531  switch (in)
532  {
533 #define _(v,f,s) case IPSEC_POLICY_ACTION_##f: \
534  out = IPSEC_API_SPD_ACTION_##f; \
535  break;
537 #undef _
538  }
539  return (clib_host_to_net_u32 (out));
540 }
541 
542 static void
544  u32 context)
545 {
547 
548  mp = vl_msg_api_alloc (sizeof (*mp));
549  clib_memset (mp, 0, sizeof (*mp));
550  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
551  mp->context = context;
552 
553  mp->entry.spd_id = htonl (p->id);
554  mp->entry.priority = htonl (p->priority);
555  mp->entry.is_outbound = ((p->type == IPSEC_SPD_POLICY_IP6_OUTBOUND) ||
556  (p->type == IPSEC_SPD_POLICY_IP4_OUTBOUND));
557 
559  &mp->entry.local_address_start);
561  &mp->entry.local_address_stop);
563  &mp->entry.remote_address_start);
565  &mp->entry.remote_address_stop);
566  mp->entry.local_port_start = htons (p->lport.start);
567  mp->entry.local_port_stop = htons (p->lport.stop);
568  mp->entry.remote_port_start = htons (p->rport.start);
569  mp->entry.remote_port_stop = htons (p->rport.stop);
570  mp->entry.protocol = p->protocol;
571  mp->entry.policy = ipsec_spd_action_encode (p->policy);
572  mp->entry.sa_id = htonl (p->sa_id);
573 
574  vl_api_send_msg (reg, (u8 *) mp);
575 }
576 
577 static void
579 {
581  ipsec_main_t *im = &ipsec_main;
584  ipsec_spd_t *spd;
585  uword *p;
586  u32 spd_index, *ii;
587 #if WITH_LIBSSL > 0
589  if (!reg)
590  return;
591 
592  p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
593  if (!p)
594  return;
595 
596  spd_index = p[0];
597  spd = pool_elt_at_index (im->spds, spd_index);
598 
599  /* *INDENT-OFF* */
601  vec_foreach(ii, spd->policies[ptype])
602  {
603  policy = pool_elt_at_index(im->policies, *ii);
604 
605  if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
606  send_ipsec_spd_details (policy, reg, mp->context);
607  }
608  }
609  /* *INDENT-ON* */
610 #else
611  clib_warning ("unimplemented");
612 #endif
613 }
614 
615 static void
618 {
620 
621  mp = vl_msg_api_alloc (sizeof (*mp));
622  clib_memset (mp, 0, sizeof (*mp));
623  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_INTERFACE_DETAILS);
624  mp->context = context;
625 
626  mp->spd_index = htonl (spd_index);
627  mp->sw_if_index = htonl (sw_if_index);
628 
629  vl_api_send_msg (reg, (u8 *) mp);
630 }
631 
632 static void
634  mp)
635 {
636  ipsec_main_t *im = &ipsec_main;
638  u32 k, v, spd_index;
639 
640 #if WITH_LIBSSL > 0
642  if (!reg)
643  return;
644 
645  if (mp->spd_index_valid)
646  {
647  spd_index = ntohl (mp->spd_index);
648  /* *INDENT-OFF* */
650  if (v == spd_index)
651  send_ipsec_spd_interface_details(reg, v, k, mp->context);
652  }));
653  /* *INDENT-ON* */
654  }
655  else
656  {
657  /* *INDENT-OFF* */
659  send_ipsec_spd_interface_details(reg, v, k, mp->context);
660  }));
661  /* *INDENT-ON* */
662  }
663 
664 #else
665  clib_warning ("unimplemented");
666 #endif
667 }
668 
669 static u32
671 {
672  return (0x80000000 | ti);
673 }
674 
675 static u32
677 {
678  return (0xc0000000 | ti);
679 }
680 
681 static void
683  mp)
684 {
686  u32 sw_if_index = ~0;
687  int rv;
688 
689 #if WITH_LIBSSL > 0
690  ip46_address_t local_ip = ip46_address_initializer;
691  ip46_address_t remote_ip = ip46_address_initializer;
692  ipsec_key_t crypto_key, integ_key;
694  ip46_type_t local_ip_type, remote_ip_type;
695  ipip_transport_t transport;
696  u32 fib_index;
697 
698  local_ip_type = ip_address_decode (&mp->local_ip, &local_ip);
699  remote_ip_type = ip_address_decode (&mp->remote_ip, &remote_ip);
700  transport = (IP46_TYPE_IP6 == local_ip_type ?
702 
703  if (local_ip_type != remote_ip_type)
704  {
705  rv = VNET_API_ERROR_INVALID_VALUE;
706  goto done;
707  }
708 
709  flags = IPSEC_SA_FLAG_NONE;
710 
711  if (mp->udp_encap)
712  flags |= IPSEC_SA_FLAG_UDP_ENCAP;
713  if (mp->esn)
714  flags |= IPSEC_SA_FLAG_USE_ESN;
715  if (mp->anti_replay)
716  flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
717 
718  ipsec_mk_key (&crypto_key, mp->remote_crypto_key,
720  ipsec_mk_key (&integ_key, mp->remote_integ_key, mp->remote_integ_key_len);
721  ipsec_mk_key (&crypto_key, mp->local_crypto_key, mp->local_crypto_key_len);
722  ipsec_mk_key (&integ_key, mp->local_integ_key, mp->local_integ_key_len);
723 
724  fib_index =
725  fib_table_find (fib_proto_from_ip46 (local_ip_type),
726  ntohl (mp->tx_table_id));
727 
728  if (~0 == fib_index)
729  {
730  rv = VNET_API_ERROR_NO_SUCH_FIB;
731  goto done;
732  }
733 
734  if (mp->is_add)
735  {
736  // remote = input, local = output
737  /* create an ip-ip tunnel, then the two SA, then bind them */
738  rv = ipip_add_tunnel (transport,
739  (mp->renumber ? ntohl (mp->show_instance) : ~0),
740  &local_ip,
741  &remote_ip, fib_index,
742  TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0,
743  TUNNEL_MODE_P2P, &sw_if_index);
744 
745  if (rv)
746  goto done;
747 
749  ntohl (mp->remote_spi),
751  mp->crypto_alg,
752  &crypto_key,
753  mp->integ_alg,
754  &integ_key,
755  (flags | IPSEC_SA_FLAG_IS_INBOUND),
756  ntohl (mp->tx_table_id),
757  mp->salt, &remote_ip, &local_ip,
758  TUNNEL_ENCAP_DECAP_FLAG_NONE,
759  IP_DSCP_CS0, NULL,
761 
762  if (rv)
763  goto done;
764 
766  ntohl (mp->local_spi),
768  mp->crypto_alg,
769  &crypto_key,
770  mp->integ_alg,
771  &integ_key,
772  flags,
773  ntohl (mp->tx_table_id),
774  mp->salt, &local_ip, &remote_ip,
775  TUNNEL_ENCAP_DECAP_FLAG_NONE,
776  IP_DSCP_CS0, NULL,
778 
779  if (rv)
780  goto done;
781 
782  rv = ipsec_tun_protect_update_one (sw_if_index, NULL,
784  (sw_if_index),
786  (sw_if_index));
787  if (rv)
788  goto done;
789 
790  /* the SAs are locked as a result of being used for proection,
791  * they cannot be removed from the API, since they cannot be refered
792  * to by the API. unlock them now, so that if the tunnel is rekeyed
793  * they-ll disapper
794  */
797  }
798  else
799  {
800  /* *INDENT-OFF* */
801  ipip_tunnel_key_t key = {
802  .transport = transport,
803  .fib_index = fib_index,
804  .src = local_ip,
805  .dst = remote_ip
806  };
807  /* *INDENT-ON* */
808 
810 
811  if (NULL != t)
812  {
813  rv = ipsec_tun_protect_del (t->sw_if_index, NULL);
815  }
816  else
817  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
818  }
819 
820 #else
821  rv = VNET_API_ERROR_UNIMPLEMENTED;
822 #endif
823 done:
824  /* *INDENT-OFF* */
825  REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY,
826  ({
827  rmp->sw_if_index = htonl (sw_if_index);
828  }));
829  /* *INDENT-ON* */
830 }
831 
832 static void
834 {
837  u32 sw_if_index = ~0;
838  int rv;
839 
840  rv = tunnel_mode_decode (mp->itf.mode, &mode);
841 
842  if (!rv)
843  rv = ipsec_itf_create (ntohl (mp->itf.user_instance), mode, &sw_if_index);
844 
845  /* *INDENT-OFF* */
846  REPLY_MACRO2 (VL_API_IPSEC_ITF_CREATE_REPLY,
847  ({
848  rmp->sw_if_index = htonl (sw_if_index);
849  }));
850  /* *INDENT-ON* */
851 }
852 
853 static void
855 {
856  vl_api_ipsec_itf_delete_reply_t *rmp;
857  int rv;
858 
859  rv = ipsec_itf_delete (ntohl (mp->sw_if_index));
860 
861  REPLY_MACRO (VL_API_IPSEC_ITF_DELETE_REPLY);
862 }
863 
864 static void
866 {
867 }
868 
870 {
874 
875 static walk_rc_t
877 {
879  ipsec_tun_protect_t *itp;
880  index_t sai;
881 
882  itp = ipsec_tun_protect_get (itpi);
883 
884  if (itp->itp_out_sa == ctx->sai)
885  {
886  ctx->sw_if_index = itp->itp_sw_if_index;
887  return (WALK_STOP);
888  }
889  /* *INDENT-OFF* */
891  ({
892  if (sai == ctx->sai)
893  {
894  ctx->sw_if_index = itp->itp_sw_if_index;
895  return (WALK_STOP);
896  }
897  }));
898  /* *INDENT-OFF* */
899 
900  return (WALK_CONTINUE);
901 }
902 
903 static walk_rc_t
905 {
906  ipsec_dump_walk_ctx_t *ctx = arg;
908  ipsec_main_t *im = &ipsec_main;
909 
910  mp = vl_msg_api_alloc (sizeof (*mp));
911  clib_memset (mp, 0, sizeof (*mp));
912  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS);
913  mp->context = ctx->context;
914 
915  mp->entry.sad_id = htonl (sa->id);
916  mp->entry.spi = htonl (sa->spi);
917  mp->entry.protocol = ipsec_proto_encode (sa->protocol);
918  mp->entry.tx_table_id =
920 
921  mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
922  ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
923 
924  mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
925  ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
926 
927  mp->entry.flags = ipsec_sad_flags_encode (sa);
928  mp->entry.salt = clib_host_to_net_u32 (sa->salt);
929 
930  if (ipsec_sa_is_set_IS_PROTECT (sa))
931  {
933  .sai = sa - im->sad,
934  .sw_if_index = ~0,
935  };
937 
938  mp->sw_if_index = htonl (ctx.sw_if_index);
939  }
940  else
941  mp->sw_if_index = ~0;
942 
943  if (ipsec_sa_is_set_IS_TUNNEL (sa))
944  {
946  &mp->entry.tunnel_src);
948  &mp->entry.tunnel_dst);
949  }
950  if (ipsec_sa_is_set_UDP_ENCAP (sa))
951  {
952  mp->entry.udp_src_port = sa->udp_hdr.src_port;
953  mp->entry.udp_dst_port = sa->udp_hdr.dst_port;
954  }
955 
956  mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq));
957  mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq));
958  if (ipsec_sa_is_set_USE_ESN (sa))
959  {
960  mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi));
961  mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi));
962  }
963  if (ipsec_sa_is_set_USE_ANTI_REPLAY (sa))
964  mp->replay_window = clib_host_to_net_u64 (sa->replay_window);
965 
966  mp->stat_index = clib_host_to_net_u32 (sa->stat_index);
967 
968  vl_api_send_msg (ctx->reg, (u8 *) mp);
969 
970  return (WALK_CONTINUE);
971 }
972 
973 static void
975 {
977 
978 #if WITH_LIBSSL > 0
980  if (!reg)
981  return;
982 
984  .reg = reg,
985  .context = mp->context,
986  };
987 
989 
990 #else
991  clib_warning ("unimplemented");
992 #endif
993 }
994 
995 static walk_rc_t
997 {
998  ipsec_dump_walk_ctx_t *ctx = arg;
1000  ipsec_main_t *im = &ipsec_main;
1001 
1002  mp = vl_msg_api_alloc (sizeof (*mp));
1003  clib_memset (mp, 0, sizeof (*mp));
1004  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_V2_DETAILS);
1005  mp->context = ctx->context;
1006 
1007  mp->entry.sad_id = htonl (sa->id);
1008  mp->entry.spi = htonl (sa->spi);
1009  mp->entry.protocol = ipsec_proto_encode (sa->protocol);
1010  mp->entry.tx_table_id =
1012 
1013  mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
1014  ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
1015 
1016  mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
1017  ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
1018 
1019  mp->entry.flags = ipsec_sad_flags_encode (sa);
1020  mp->entry.salt = clib_host_to_net_u32 (sa->salt);
1021 
1022  if (ipsec_sa_is_set_IS_PROTECT (sa))
1023  {
1025  .sai = sa - im->sad,
1026  .sw_if_index = ~0,
1027  };
1029 
1030  mp->sw_if_index = htonl (ctx.sw_if_index);
1031  }
1032  else
1033  mp->sw_if_index = ~0;
1034 
1035  if (ipsec_sa_is_set_IS_TUNNEL (sa))
1036  {
1038  &mp->entry.tunnel_src);
1040  &mp->entry.tunnel_dst);
1041  }
1042  if (ipsec_sa_is_set_UDP_ENCAP (sa))
1043  {
1044  mp->entry.udp_src_port = sa->udp_hdr.src_port;
1045  mp->entry.udp_dst_port = sa->udp_hdr.dst_port;
1046  }
1047 
1048  mp->entry.tunnel_flags = tunnel_encap_decap_flags_encode (sa->tunnel_flags);
1049  mp->entry.dscp = ip_dscp_encode (sa->dscp);
1050 
1051  mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq));
1052  mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq));
1053  if (ipsec_sa_is_set_USE_ESN (sa))
1054  {
1055  mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi));
1056  mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi));
1057  }
1058  if (ipsec_sa_is_set_USE_ANTI_REPLAY (sa))
1059  mp->replay_window = clib_host_to_net_u64 (sa->replay_window);
1060 
1061  mp->stat_index = clib_host_to_net_u32 (sa->stat_index);
1062 
1063  vl_api_send_msg (ctx->reg, (u8 *) mp);
1064 
1065  return (WALK_CONTINUE);
1066 }
1067 
1068 static void
1070 {
1072 
1073 #if WITH_LIBSSL > 0
1075  if (!reg)
1076  return;
1077 
1079  .reg = reg,
1080  .context = mp->context,
1081  };
1082 
1084 
1085 #else
1086  clib_warning ("unimplemented");
1087 #endif
1088 }
1089 
1090 static void
1092 {
1093  vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp;
1094  int rv;
1095 
1096 #if WITH_LIBSSL > 0
1098 
1099  if (mp->is_outbound)
1100  rv = ipsec_tun_protect_update_out (ntohl (mp->sw_if_index), NULL,
1101  ntohl (mp->sa_id));
1102  else
1103  rv = ipsec_tun_protect_update_in (ntohl (mp->sw_if_index), NULL,
1104  ntohl (mp->sa_id));
1105 
1106 #else
1107  clib_warning ("unimplemented");
1108 #endif
1109 
1111 
1112  REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY);
1113 }
1114 
1115 static void
1117 {
1119  ipsec_main_t *im = &ipsec_main;
1120  u32 context = mp->context;
1121 
1123 
1124  if (rp == 0)
1125  {
1126  clib_warning ("Client %d AWOL", mp->client_index);
1127  return;
1128  }
1129 
1130  ipsec_ah_backend_t *ab;
1131  ipsec_esp_backend_t *eb;
1132  /* *INDENT-OFF* */
1133  pool_foreach (ab, im->ah_backends) {
1134  vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
1135  clib_memset (mp, 0, sizeof (*mp));
1136  mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
1137  mp->context = context;
1138  snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (ab->name),
1139  ab->name);
1140  mp->protocol = ntohl (IPSEC_API_PROTO_AH);
1141  mp->index = ab - im->ah_backends;
1142  mp->active = mp->index == im->ah_current_backend ? 1 : 0;
1143  vl_api_send_msg (rp, (u8 *)mp);
1144  }
1145  pool_foreach (eb, im->esp_backends) {
1146  vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
1147  clib_memset (mp, 0, sizeof (*mp));
1148  mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
1149  mp->context = context;
1150  snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (eb->name),
1151  eb->name);
1152  mp->protocol = ntohl (IPSEC_API_PROTO_ESP);
1153  mp->index = eb - im->esp_backends;
1154  mp->active = mp->index == im->esp_current_backend ? 1 : 0;
1155  vl_api_send_msg (rp, (u8 *)mp);
1156  }
1157  /* *INDENT-ON* */
1158 }
1159 
1160 static void
1162 {
1163  ipsec_main_t *im = &ipsec_main;
1164  vl_api_ipsec_select_backend_reply_t *rmp;
1165  ipsec_protocol_t protocol;
1166  int rv = 0;
1167  if (pool_elts (im->sad) > 0)
1168  {
1169  rv = VNET_API_ERROR_INSTANCE_IN_USE;
1170  goto done;
1171  }
1172 
1173  rv = ipsec_proto_decode (mp->protocol, &protocol);
1174 
1175  if (rv)
1176  goto done;
1177 
1178 #if WITH_LIBSSL > 0
1179  switch (protocol)
1180  {
1181  case IPSEC_PROTOCOL_ESP:
1182  rv = ipsec_select_esp_backend (im, mp->index);
1183  break;
1184  case IPSEC_PROTOCOL_AH:
1185  rv = ipsec_select_ah_backend (im, mp->index);
1186  break;
1187  default:
1188  rv = VNET_API_ERROR_INVALID_PROTOCOL;
1189  break;
1190  }
1191 #else
1192  clib_warning ("unimplemented"); /* FIXME */
1193 #endif
1194 done:
1195  REPLY_MACRO (VL_API_IPSEC_SELECT_BACKEND_REPLY);
1196 }
1197 
1198 static void
1200 {
1201  vl_api_ipsec_set_async_mode_reply_t *rmp;
1202  int rv = 0;
1203 
1206 
1207  REPLY_MACRO (VL_API_IPSEC_SET_ASYNC_MODE_REPLY);
1208 }
1209 
1210 /*
1211  * ipsec_api_hookup
1212  * Add vpe's API message handlers to the table.
1213  * vlib has already mapped shared memory and
1214  * added the client registration handlers.
1215  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1216  */
1217 #define vl_msg_name_crc_list
1218 #include <vnet/vnet_all_api_h.h>
1219 #undef vl_msg_name_crc_list
1220 
1221 static void
1223 {
1224 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1225  foreach_vl_msg_name_crc_ipsec;
1226 #undef _
1227 }
1228 
1229 static clib_error_t *
1231 {
1232  api_main_t *am = vlibapi_get_main ();
1233 
1234 #define _(N,n) \
1235  vl_msg_api_set_handlers(VL_API_##N, #n, \
1236  vl_api_##n##_t_handler, \
1237  vl_noop_handler, \
1238  vl_api_##n##_t_endian, \
1239  vl_api_##n##_t_print, \
1240  sizeof(vl_api_##n##_t), 1);
1242 #undef _
1243 
1244  /*
1245  * Set up the (msg_name, crc, message-id) table
1246  */
1248 
1249  return 0;
1250 }
1251 
1253 
1254 /*
1255  * fd.io coding-style-patch-verification: ON
1256  *
1257  * Local Variables:
1258  * eval: (c-set-style "gnu")
1259  * End:
1260  */
ipip_tunnel_t * ipip_tunnel_db_find(const ipip_tunnel_key_t *key)
Definition: ipip.c:493
ipsec_spd_t * spds
Definition: ipsec.h:109
static void vl_api_ipsec_sa_v2_dump_t_handler(vl_api_ipsec_sa_dump_t *mp)
Definition: ipsec_api.c:1069
IPsec: Add/delete Security Policy Database entry.
Definition: ipsec.api:122
vl_api_ipsec_spd_action_t ipsec_spd_action_encode(ipsec_policy_action_t in)
Definition: ipsec_api.c:527
int ipsec_sa_add_and_lock(u32 id, u32 spi, ipsec_protocol_t proto, ipsec_crypto_alg_t crypto_alg, const ipsec_key_t *ck, ipsec_integ_alg_t integ_alg, const ipsec_key_t *ik, ipsec_sa_flags_t flags, u32 tx_table_id, u32 salt, const ip46_address_t *tun_src, const ip46_address_t *tun_dst, tunnel_encap_decap_flags_t tunnel_flags, ip_dscp_t dscp, u32 *sa_out_index, u16 src_port, u16 dst_port)
Definition: ipsec_sa.c:170
vl_api_tunnel_encap_decap_flags_t tunnel_flags
static void vl_api_ipsec_sad_entry_add_del_v2_t_handler(vl_api_ipsec_sad_entry_add_del_v2_t *mp)
Definition: ipsec_api.c:408
void ipsec_key_decode(const vl_api_key_t *key, ipsec_key_t *out)
ip46_address_t tunnel_src_addr
Definition: ipsec_sa.h:197
bool is_add
Definition: ipsec.api:126
void ip_address_encode2(const ip_address_t *in, vl_api_address_t *out)
Definition: ip_types_api.c:242
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
enum ipsec_spd_policy_t_ ipsec_spd_policy_type_t
static void vl_api_ipsec_itf_create_t_handler(vl_api_ipsec_itf_create_t *mp)
Definition: ipsec_api.c:833
#define ntohs(x)
Definition: af_xdp.bpf.c:29
IPsec: SPD interface response.
Definition: ipsec.api:321
A representation of a IPIP tunnel.
Definition: ipip.h:75
Dump IPsec backends.
Definition: ipsec.api:522
Add IPsec interface interface response.
Definition: ipsec.api:417
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:527
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
ip_dscp_t dscp
Definition: ipsec_sa.h:168
VLIB_API_INIT_FUNCTION(ipsec_api_hookup)
unsigned long u64
Definition: types.h:89
ip46_address_range_t laddr
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
#define REPLY_MACRO2(t, body)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define FOR_EACH_IPSEC_SPD_POLICY_TYPE(_t)
Definition: ipsec_spd.h:38
vl_api_ipsec_proto_t protocol
Definition: ipsec.api:536
int ipsec_policy_mk_type(bool is_outbound, bool is_ipv6, ipsec_policy_action_t action, ipsec_spd_policy_type_t *type)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
ipsec_key_t crypto_key
Definition: ipsec_sa.h:217
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:513
vl_api_ipsec_sad_entry_v2_t entry
Definition: ipsec.api:204
ipsec_integ_alg_t integ_alg
Definition: ipsec_sa.h:214
void vnet_crypto_request_async_mode(int is_enable)
Definition: crypto.c:559
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
void ipsec_tun_protect_walk_itf(u32 sw_if_index, ipsec_tun_protect_walk_cb_t fn, void *ctx)
Definition: ipsec_tun.c:849
static void setup_message_id_table(api_main_t *am)
Definition: ipsec_api.c:1222
static walk_rc_t send_ipsec_sa_v2_details(ipsec_sa_t *sa, void *arg)
Definition: ipsec_api.c:996
int ipsec_integ_algo_decode(vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t *out)
vl_api_ipsec_itf_t itf
Definition: ipsec.api:409
vl_api_ipsec_spd_action_t policy
Definition: ipsec.api:99
static void vl_api_ipsec_sa_dump_t_handler(vl_api_ipsec_sa_dump_t *mp)
Definition: ipsec_api.c:974
vlib_main_t * vm
Definition: in2out_ed.c:1580
int ipsec_select_ah_backend(ipsec_main_t *im, u32 backend_idx)
Definition: ipsec.c:270
u32 ah_current_backend
Definition: ipsec.h:175
#define FOR_EACH_IPSEC_PROTECT_INPUT_SA(_itp, _sa, body)
Definition: ipsec_tun.h:137
vl_api_tunnel_encap_decap_flags_t tunnel_encap_decap_flags_encode(tunnel_encap_decap_flags_t f)
A Secruity Policy Database.
Definition: ipsec_spd.h:46
u32 esp_current_backend
Definition: ipsec.h:177
int ipip_add_tunnel(ipip_transport_t transport, u32 instance, ip46_address_t *src, ip46_address_t *dst, u32 fib_index, tunnel_encap_decap_flags_t flags, ip_dscp_t dscp, tunnel_mode_t tmode, u32 *sw_if_indexp)
Definition: ipip.c:664
void * vl_msg_api_alloc(int nbytes)
void ipsec_tun_protect_walk(ipsec_tun_protect_walk_cb_t fn, void *ctx)
Definition: ipsec_tun.c:836
void ipsec_mk_key(ipsec_key_t *key, const u8 *data, u8 len)
Definition: ipsec_sa.c:56
unsigned char u8
Definition: types.h:56
#define foreach_vpe_api_msg
Definition: ipsec_api.c:57
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:293
vl_api_address_t remote_ip
Definition: ipsec.api:366
ip_dscp_t ip_dscp_decode(vl_api_ip_dscp_t in)
Definition: ip_types_api.c:99
u8 id[64]
Definition: dhcp.api:160
struct ipsec_sa_dump_match_ctx_t_ ipsec_sa_dump_match_ctx_t
u32 seq_hi
Definition: ipsec_sa.h:123
uword * spd_index_by_sw_if_index
Definition: ipsec.h:126
static void vl_api_ipsec_interface_add_del_spd_t_handler(vl_api_ipsec_interface_add_del_spd_t *mp)
Definition: ipsec_api.c:98
enum walk_rc_t_ walk_rc_t
Walk return code.
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:282
u64 replay_window
Definition: ipsec_sa.h:126
void ipsec_sa_walk(ipsec_sa_walk_cb_t cb, void *ctx)
Definition: ipsec_sa.c:457
Select IPsec backend.
Definition: ipsec.api:547
ipsec_main_t ipsec_main
Definition: ipsec.c:28
Definition: ipsec.api:206
int ipsec_tun_protect_del(u32 sw_if_index, const ip_address_t *nh)
Definition: ipsec_tun.c:804
static void vl_api_ipsec_tunnel_if_add_del_t_handler(vl_api_ipsec_tunnel_if_add_del_t *mp)
Definition: ipsec_api.c:682
static void vl_api_ipsec_backend_dump_t_handler(vl_api_ipsec_backend_dump_t *mp)
Definition: ipsec_api.c:1116
int ipsec_select_esp_backend(ipsec_main_t *im, u32 backend_idx)
Definition: ipsec.c:293
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
tunnel_encap_decap_flags_t tunnel_flags
Definition: ipsec_sa.h:167
static void vl_api_ipsec_spd_dump_t_handler(vl_api_ipsec_spd_dump_t *mp)
Definition: ipsec_api.c:578
static void vl_api_ipsec_spd_interface_dump_t_handler(vl_api_ipsec_spd_interface_dump_t *mp)
Definition: ipsec_api.c:633
vl_api_address_t local_ip
Definition: ipsec.api:365
int ipsec_sa_unlock_id(u32 id)
Definition: ipsec_sa.c:435
port_range_t rport
Dump all tunnel protections.
Definition: ipsec.api:289
unsigned int u32
Definition: types.h:88
vl_api_ipsec_crypto_alg_t ipsec_crypto_algo_encode(ipsec_crypto_alg_t c)
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1106
IPsec: Reply Add/delete Security Policy Database entry.
Definition: ipsec.api:136
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Decode/Encode for struct/union types.
Definition: ip_types_api.c:186
u32 stat_index
Definition: ipsec_sa.h:204
static void vl_api_ipsec_spd_add_del_t_handler(vl_api_ipsec_spd_add_del_t *mp)
Definition: ipsec_api.c:81
fib_protocol_t fib_proto_from_ip46(ip46_type_t iproto)
Convert from ip46_type to fib_protocol.
Definition: fib_types.c:409
u32 last_seq
Definition: ipsec_sa.h:124
#define hash_get(h, key)
Definition: hash.h:249
IPsec: Add/delete Security Association Database entry.
Definition: ipsec.api:192
u32 tx_fib_index
Definition: ipsec_sa.h:210
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
u32 stat_index
Definition: ipsec.api:216
u8 integ_alg
Definition: ikev2_types.api:59
Dump IPsec all SPD IDs response.
Definition: ipsec.api:157
Add/delete IPsec tunnel interface response.
Definition: ipsec.api:391
vl_api_ip_proto_t proto
Definition: acl_types.api:51
long ctx[MAX_CONNS]
Definition: main.c:144
IPsec: Add/delete Security Policy Database.
Definition: ipsec.api:32
u32 salt
Definition: ipsec_sa.h:164
vl_api_ipsec_tunnel_protect_t tun
Definition: ipsec.api:299
vl_api_ipsec_proto_t ipsec_proto_encode(ipsec_protocol_t p)
int ipsec_add_del_policy(vlib_main_t *vm, ipsec_policy_t *policy, int is_add, u32 *stat_index)
Add/Delete a SPD.
u32 last_seq_hi
Definition: ipsec_sa.h:125
static int ipsec_spd_action_decode(vl_api_ipsec_spd_action_t in, ipsec_policy_action_t *out)
Definition: ipsec_api.c:252
Definition: ipsec.api:212
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:421
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:490
#define REPLY_MACRO(t)
vl_api_ipsec_tunnel_protect_t tunnel
Definition: ipsec.api:274
ipsec_spd_policy_type_t type
int tunnel_mode_decode(vl_api_tunnel_mode_t in, tunnel_mode_t *out)
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:56
static ipsec_sa_t * ipsec_sa_get(u32 sa_index)
Definition: ipsec.h:290
vl_api_tunnel_mode_t mode
Definition: gre.api:48
ipsec_policy_action_t
uword * spd_index_by_spd_id
Definition: ipsec.h:125
static void vl_api_ipsec_tunnel_if_set_sa_t_handler(vl_api_ipsec_tunnel_if_set_sa_t *mp)
Definition: ipsec_api.c:1091
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:227
ip46_address_t tunnel_dst_addr
Definition: ipsec_sa.h:198
void ip_address_decode2(const vl_api_address_t *in, ip_address_t *out)
Definition: ip_types_api.c:192
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
static void vl_api_ipsec_set_async_mode_t_handler(vl_api_ipsec_set_async_mode_t *mp)
Definition: ipsec_api.c:1199
int ipsec_tun_protect_update_one(u32 sw_if_index, const ip_address_t *nh, u32 sa_out, u32 sa_in)
Definition: ipsec_tun.c:533
#define BAD_SW_IF_INDEX_LABEL
IPsec: Add/delete SPD from interface.
Definition: ipsec.api:50
static walk_rc_t ipsec_sa_dump_match_sa(index_t itpi, void *arg)
Definition: ipsec_api.c:876
ipsec_ah_backend_t * ah_backends
Definition: ipsec.h:171
vl_api_ipsec_sad_flags_t ipsec_sad_flags_encode(const ipsec_sa_t *sa)
Dump IPsec all SPD IDs.
Definition: ipsec.api:147
vl_api_ipsec_sad_entry_t entry
Definition: ipsec.api:197
ipsec_policy_action_t policy
ip46_address_t start
#define clib_warning(format, args...)
Definition: error.h:59
vl_api_key_t crypto_key
udp_header_t udp_hdr
Definition: ipsec_sa.h:161
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
vl_api_ipsec_proto_t protocol
Definition: ipsec.api:550
int ipsec_tun_protect_update_out(u32 sw_if_index, const ip_address_t *nh, u32 sa_out)
Definition: ipsec_tun.c:546
u32 spi
Definition: flow_types.api:140
#define FOR_EACH_IPSEC_PROTECT_INPUT_SAI(_itp, _sai, body)
Definition: ipsec_tun.h:129
bool is_add
Definition: ipsec.api:196
static u32 ipsec_tun_mk_input_sa_id(u32 ti)
Definition: ipsec_api.c:670
Set new SA on IPsec interface.
Definition: ipsec.api:509
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
A Secruity Policy.
static void vl_api_ipsec_spds_dump_t_handler(vl_api_ipsec_spds_dump_t *mp)
Definition: ipsec_api.c:506
static void vl_api_ipsec_tunnel_protect_dump_t_handler(vl_api_ipsec_tunnel_protect_dump_t *mp)
Definition: ipsec_api.c:219
static void send_ipsec_spd_interface_details(vl_api_registration_t *reg, u32 spd_index, u32 sw_if_index, u32 context)
Definition: ipsec_api.c:616
vl_api_ipsec_sad_entry_t entry
Definition: ipsec.api:476
static void send_ipsec_spd_details(ipsec_policy_t *p, vl_api_registration_t *reg, u32 context)
Definition: ipsec_api.c:543
static void vl_api_ipsec_itf_dump_t_handler(vl_api_ipsec_itf_dump_t *mp)
Definition: ipsec_api.c:865
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:478
void ipsec_set_async_mode(u32 is_enabled)
Definition: ipsec.c:339
static void vl_api_ipsec_spd_entry_add_del_t_handler(vl_api_ipsec_spd_entry_add_del_t *mp)
Definition: ipsec_api.c:269
ipsec_policy_t * policies
Definition: ipsec.h:113
vl_api_ip_dscp_t ip_dscp_encode(ip_dscp_t dscp)
Definition: ip_types_api.c:105
Dump IPsec security association.
Definition: ipsec.api:449
ipsec_sa_t * sad
Definition: ipsec.h:111
static void vl_api_ipsec_itf_delete_t_handler(vl_api_ipsec_itf_delete_t *mp)
Definition: ipsec_api.c:854
u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
Definition: fib_table.c:1095
static ipsec_tun_protect_t * ipsec_tun_protect_get(u32 index)
Definition: ipsec_tun.h:185
int ipsec_tun_protect_update_in(u32 sw_if_index, const ip_address_t *nh, u32 sa_in)
Definition: ipsec_tun.c:595
vl_api_ipsec_integ_alg_t ipsec_integ_algo_encode(ipsec_integ_alg_t i)
u32 * policies[IPSEC_SPD_POLICY_N_TYPES]
vectors for each of the policy types
Definition: ipsec_spd.h:51
ipsec_sa_flags_t ipsec_sa_flags_decode(vl_api_ipsec_sad_flags_t in)
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:394
Dump ipsec policy database data.
Definition: ipsec.api:169
u32 stat_index
Definition: ipsec.api:140
ipsec_protocol_t protocol
Definition: ipsec_sa.h:166
static void vl_api_ipsec_tunnel_protect_update_t_handler(vl_api_ipsec_tunnel_protect_update_t *mp)
Definition: ipsec_api.c:123
int ipsec_itf_delete(u32 sw_if_index)
Definition: ipsec_itf.c:328
static void send_ipsec_spds_details(ipsec_spd_t *spd, vl_api_registration_t *reg, u32 context)
Definition: ipsec_api.c:485
IPsec Set Async mode.
Definition: ipsec.api:560
u32 sw_if_index
Definition: ipip.h:86
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
IPsec policy database response.
Definition: ipsec.api:182
IPsec: Get SPD interfaces.
Definition: ipsec.api:309
vl_api_ipsec_spd_entry_t entry
Definition: ipsec.api:184
typedef key
Definition: ipsec_types.api:86
vl_api_ipsec_spd_entry_t entry
Definition: ipsec.api:127
struct ipsec_dump_walk_ctx_t_ ipsec_dump_walk_ctx_t
static walk_rc_t send_ipsec_sa_details(ipsec_sa_t *sa, void *arg)
Definition: ipsec_api.c:904
static u32 ipsec_tun_mk_output_sa_id(u32 ti)
Definition: ipsec_api.c:676
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
ip46_address_range_t raddr
u64 uword
Definition: types.h:112
int ipip_del_tunnel(u32 sw_if_index)
Definition: ipip.c:772
IPsec backend details.
Definition: ipsec.api:533
Create an IPSec interface.
Definition: ipsec.api:406
int ipsec_set_interface_spd(vlib_main_t *vm, u32 sw_if_index, u32 spd_id, int is_add)
Bind/attach a SPD to an interface.
Definition: ipsec_spd.c:63
void ip_address_encode(const ip46_address_t *in, ip46_type_t type, vl_api_address_t *out)
Definition: ip_types_api.c:220
u32 id
the User&#39;s ID for this policy
Definition: ipsec_spd.h:49
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:389
int ipsec_itf_create(u32 user_instance, tunnel_mode_t mode, u32 *sw_if_indexp)
Definition: ipsec_itf.c:281
vl_api_registration_t * reg
Definition: ipsec_api.c:180
vl_api_ipsec_sad_entry_v2_t entry
Definition: ipsec.api:488
ipsec_crypto_alg_t crypto_alg
Definition: ipsec_sa.h:213
port_range_t lport
int ipsec_add_del_spd(vlib_main_t *vm, u32 spd_id, int is_add)
Add/Delete a SPD.
Definition: ipsec_spd.c:20
static clib_error_t * ipsec_api_hookup(vlib_main_t *vm)
Definition: ipsec_api.c:1230
#define foreach_ipsec_spd_policy_type
Definition: ipsec_spd.h:20
Definition: ipsec.api:199
static void vl_api_ipsec_tunnel_protect_del_t_handler(vl_api_ipsec_tunnel_protect_del_t *mp)
Definition: ipsec_api.c:154
#define vec_foreach(var, vec)
Vector iterator.
bool is_add
Definition: ipsec.api:203
ip_address_t * itp_key
Definition: ipsec_tun.h:125
int tunnel_encap_decap_flags_decode(vl_api_tunnel_encap_decap_flags_t f, tunnel_encap_decap_flags_t *o)
Conversion functions to/from (decode/encode) API types to VPP internal types.
static walk_rc_t send_ipsec_tunnel_protect_details(index_t itpi, void *arg)
Definition: ipsec_api.c:185
static void vl_api_ipsec_select_backend_t_handler(vl_api_ipsec_select_backend_t *mp)
Definition: ipsec_api.c:1161
IPsec security association database response.
Definition: ipsec.api:474
ipsec_esp_backend_t * esp_backends
Definition: ipsec.h:173
int ipsec_crypto_algo_decode(vl_api_ipsec_crypto_alg_t in, ipsec_crypto_alg_t *out)
ipsec_key_t integ_key
Definition: ipsec_sa.h:216
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:428
enum tunnel_mode_t_ tunnel_mode_t
#define IPSEC_UDP_PORT_NONE
Definition: ipsec_sa.h:290
Add or delete IPsec tunnel interface.
Definition: ipsec.api:358
#define ip46_address_initializer
Definition: ip46_address.h:52
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
int ipsec_proto_decode(vl_api_ipsec_proto_t in, ipsec_protocol_t *out)
Encode/decode function from/to API to internal types.
#define VALIDATE_SW_IF_INDEX(mp)
ip46_type_t
Definition: ip46_address.h:22
vl_api_interface_index_t sw_if_index
Definition: ipsec.api:324
u32 stat_index
Definition: ipsec.api:210
int ipsec_tun_protect_update(u32 sw_if_index, const ip_address_t *nh, u32 sa_out, u32 *sas_in)
Definition: ipsec_tun.c:654
static void vl_api_ipsec_sad_entry_add_del_t_handler(vl_api_ipsec_sad_entry_add_del_t *mp)
Definition: ipsec_api.c:338
void ipsec_key_encode(const ipsec_key_t *in, vl_api_key_t *out)
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127