FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ikev2.c
Go to the documentation of this file.
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 #include <vlib/vlib.h>
17 #include <vlib/unix/plugin.h>
18 #include <vlibmemory/api.h>
19 #include <vpp/app/version.h>
20 #include <vnet/vnet.h>
21 #include <vppinfra/error.h>
22 #include <vppinfra/random.h>
23 #include <vnet/udp/udp.h>
24 #include <vnet/ipsec/ipsec.h>
25 #include <vnet/ipsec/ipsec_tun.h>
26 #include <vnet/ipip/ipip.h>
27 #include <plugins/ikev2/ikev2.h>
29 #include <plugins/dns/dns.h>
30 #include <openssl/sha.h>
31 #include <vnet/ipsec/ipsec_punt.h>
32 #include <plugins/ikev2/ikev2.api_enum.h>
33 
34 #define IKEV2_LIVENESS_RETRIES 3
35 #define IKEV2_LIVENESS_PERIOD_CHECK 30
36 
38 
40  ikev2_sa_t * sa,
41  ikev2_child_sa_t * child);
42 
43 #define ikev2_set_state(sa, v, ...) do { \
44  (sa)->state = v; \
45  ikev2_elog_sa_state("ispi %lx SA state changed to " #v __VA_ARGS__, sa->ispi); \
46  } while(0);
47 
48 typedef struct
49 {
53 
54 static u8 *
55 format_ikev2_trace (u8 * s, va_list * args)
56 {
57  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
58  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
59  ikev2_trace_t *t = va_arg (*args, ikev2_trace_t *);
60 
61  s = format (s, "ikev2: sw_if_index %d, next index %d",
62  t->sw_if_index, t->next_index);
63  return s;
64 }
65 
66 #define IKEV2_GENERATE_SA_INIT_OK_str ""
67 #define IKEV2_GENERATE_SA_INIT_OK_ERR_NO_DH_STR \
68  "no DH group configured for IKE proposals!"
69 #define IKEV2_GENERATE_SA_INIT_OK_ERR_UNSUPP_STR \
70  "DH group not supported!"
71 
72 typedef enum
73 {
78 
79 static u8 *
80 format_ikev2_gen_sa_error (u8 * s, va_list * args)
81 {
83  switch (e)
84  {
86  break;
89  break;
92  break;
93  }
94  return s;
95 }
96 
97 typedef enum
98 {
103 
104 typedef enum
105 {
110 
112 
115 {
117 }
118 
120 ikev2_insert_non_esp_marker (ike_header_t * ike, int len)
121 {
122  memmove ((u8 *) ike + sizeof (ikev2_non_esp_marker), ike, len);
123  clib_memset (ike, 0, sizeof (ikev2_non_esp_marker));
124  return len + sizeof (ikev2_non_esp_marker);
125 }
126 
127 static ikev2_sa_transform_t *
129 {
130  ikev2_main_t *km = &ikev2_main;
132 
134  {
135  if (td->type != t->type)
136  continue;
137 
138  if (td->transform_id != t->transform_id)
139  continue;
140 
141  if (td->type == IKEV2_TRANSFORM_TYPE_ENCR)
142  {
143  if (vec_len (t->attrs) != 4 || t->attrs[0] != 0x80
144  || t->attrs[1] != 14)
145  continue;
146 
147  if (((t->attrs[2] << 8 | t->attrs[3]) / 8) != td->key_len)
148  continue;
149  }
150  return td;
151  }
152  return 0;
153 }
154 
155 static ikev2_sa_proposal_t *
157  ikev2_protocol_id_t prot_id)
158 {
159  ikev2_sa_proposal_t *rv = 0;
160  ikev2_sa_proposal_t *proposal;
161  ikev2_sa_transform_t *transform, *new_t;
162  u8 mandatory_bitmap, optional_bitmap;
163 
164  if (prot_id == IKEV2_PROTOCOL_IKE)
165  {
166  mandatory_bitmap = (1 << IKEV2_TRANSFORM_TYPE_ENCR) |
167  (1 << IKEV2_TRANSFORM_TYPE_PRF) | (1 << IKEV2_TRANSFORM_TYPE_DH);
168  optional_bitmap = mandatory_bitmap | (1 << IKEV2_TRANSFORM_TYPE_INTEG);
169  }
170  else if (prot_id == IKEV2_PROTOCOL_ESP)
171  {
172  mandatory_bitmap = (1 << IKEV2_TRANSFORM_TYPE_ENCR) |
173  (1 << IKEV2_TRANSFORM_TYPE_ESN);
174  optional_bitmap = mandatory_bitmap |
175  (1 << IKEV2_TRANSFORM_TYPE_INTEG) | (1 << IKEV2_TRANSFORM_TYPE_DH);
176  }
177  else if (prot_id == IKEV2_PROTOCOL_AH)
178  {
179  mandatory_bitmap = (1 << IKEV2_TRANSFORM_TYPE_INTEG) |
180  (1 << IKEV2_TRANSFORM_TYPE_ESN);
181  optional_bitmap = mandatory_bitmap | (1 << IKEV2_TRANSFORM_TYPE_DH);
182  }
183  else
184  return 0;
185 
186  vec_add2 (rv, proposal, 1);
187 
188  vec_foreach (proposal, proposals)
189  {
190  u8 bitmap = 0;
191  if (proposal->protocol_id != prot_id)
192  continue;
193 
194  vec_foreach (transform, proposal->transforms)
195  {
196  if ((1 << transform->type) & bitmap)
197  continue;
198 
199  if (ikev2_find_transform_data (transform))
200  {
201  bitmap |= 1 << transform->type;
202  vec_add2 (rv->transforms, new_t, 1);
203  clib_memcpy_fast (new_t, transform, sizeof (*new_t));
204  new_t->attrs = vec_dup (transform->attrs);
205  }
206  }
207 
208  if ((bitmap & mandatory_bitmap) == mandatory_bitmap &&
209  (bitmap & ~optional_bitmap) == 0)
210  {
211  rv->proposal_num = proposal->proposal_num;
212  rv->protocol_id = proposal->protocol_id;
213  RAND_bytes ((u8 *) & rv->spi, sizeof (rv->spi));
214  goto done;
215  }
216  else
217  {
218  vec_free (rv->transforms);
219  }
220  }
221 
222  vec_free (rv);
223 done:
224  return rv;
225 }
226 
230 {
232 
233  if (!p)
234  return 0;
235 
236  vec_foreach (t, p->transforms)
237  {
238  if (t->type == type)
239  return ikev2_find_transform_data (t);
240  }
241  return 0;
242 }
243 
246  int by_initiator)
247 {
249  vec_foreach (c, sa->childs)
250  {
251  ikev2_sa_proposal_t *proposal =
252  by_initiator ? &c->i_proposals[0] : &c->r_proposals[0];
253  if (proposal && proposal->spi == spi && proposal->protocol_id == prot_id)
254  return c;
255  }
256 
257  return 0;
258 }
259 
260 void
262 {
265 
266  if (!*v)
267  return;
268 
269  vec_foreach (p, *v)
270  {
271  vec_foreach (t, p->transforms)
272  {
273  vec_free (t->attrs);
274  }
275  vec_free (p->transforms);
276  }
277  vec_free (*v);
278 }
279 
280 static void
282 {
283  ikev2_sa_free_proposal_vector (&c->r_proposals);
284  ikev2_sa_free_proposal_vector (&c->i_proposals);
285  vec_free (c->sk_ai);
286  vec_free (c->sk_ar);
287  vec_free (c->sk_ei);
288  vec_free (c->sk_er);
289  vec_free (c->tsi);
290  vec_free (c->tsr);
291 }
292 
293 static void
295 {
297  vec_foreach (c, *childs) ikev2_sa_free_child_sa (c);
298 
299  vec_free (*childs);
300 }
301 
302 static void
304 {
305  ikev2_sa_free_child_sa (child);
306  vec_del1 (sa->childs, child - sa->childs);
307 }
308 
309 static void
311 {
312  vec_free (sa->i_nonce);
313  vec_free (sa->r_nonce);
314 
315  vec_free (sa->dh_shared_key);
316  vec_free (sa->dh_private_key);
317  vec_free (sa->i_dh_data);
318  vec_free (sa->r_dh_data);
319 
322 
323  vec_free (sa->sk_d);
324  vec_free (sa->sk_ai);
325  vec_free (sa->sk_ar);
326  vec_free (sa->sk_ei);
327  vec_free (sa->sk_er);
328  vec_free (sa->sk_pi);
329  vec_free (sa->sk_pr);
330 
331  vec_free (sa->i_id.data);
332  vec_free (sa->r_id.data);
333 
334  vec_free (sa->i_auth.data);
335  if (sa->i_auth.key)
336  EVP_PKEY_free (sa->i_auth.key);
337  vec_free (sa->r_auth.data);
338  if (sa->r_auth.key)
339  EVP_PKEY_free (sa->r_auth.key);
340 
341  vec_free (sa->del);
342 
343  vec_free (sa->rekey);
344 
347 
349 
351 }
352 
353 static void
355 {
356  uword *p;
357 
359 
360  p = hash_get (ptd->sa_by_rspi, sa->rspi);
361  if (p)
362  {
363  hash_unset (ptd->sa_by_rspi, sa->rspi);
364  pool_put (ptd->sas, sa);
365  }
366 }
367 
370 {
371  ikev2_sa_transform_t *t = 0, *t2;
372  ikev2_main_t *km = &ikev2_main;
373 
374  if (sa->dh_group == IKEV2_TRANSFORM_DH_TYPE_NONE)
376 
377  /* check if received DH group is on our list of supported groups */
379  {
380  if (t2->type == IKEV2_TRANSFORM_TYPE_DH && sa->dh_group == t2->dh_type)
381  {
382  t = t2;
383  break;
384  }
385  }
386 
387  if (!t)
388  {
389  sa->dh_group = IKEV2_TRANSFORM_DH_TYPE_NONE;
391  }
392 
393  if (sa->is_initiator)
394  {
395  /* generate rspi */
396  RAND_bytes ((u8 *) & sa->ispi, 8);
397 
398  /* generate nonce */
400  RAND_bytes ((u8 *) sa->i_nonce, IKEV2_NONCE_SIZE);
401  }
402  else
403  {
404  /* generate rspi */
405  RAND_bytes ((u8 *) & sa->rspi, 8);
406 
407  /* generate nonce */
409  RAND_bytes ((u8 *) sa->r_nonce, IKEV2_NONCE_SIZE);
410  }
411 
412  /* generate dh keys */
413  ikev2_generate_dh (sa, t);
414 
416 }
417 
418 static void
420 {
421  ikev2_sa_transform_t *t = 0, *t2;
422  ikev2_main_t *km = &ikev2_main;
423 
424  /*move some data to the new SA */
425 #define _(A) ({void* __tmp__ = (A); (A) = 0; __tmp__;})
426  sa->i_nonce = _(sai->i_nonce);
427  sa->i_dh_data = _(sai->i_dh_data);
428  sa->dh_private_key = _(sai->dh_private_key);
429  ip_address_copy (&sa->iaddr, &sai->iaddr);
430  ip_address_copy (&sa->raddr, &sai->raddr);
431  sa->is_initiator = sai->is_initiator;
432  sa->i_id.type = sai->i_id.type;
433  sa->r_id.type = sai->r_id.type;
434  sa->profile_index = sai->profile_index;
435  sa->tun_itf = sai->tun_itf;
436  sa->is_tun_itf_set = sai->is_tun_itf_set;
437  if (sai->natt_state == IKEV2_NATT_DISABLED)
439  sa->i_id.data = _(sai->i_id.data);
440  sa->r_id.data = _(sai->r_id.data);
441  sa->i_auth.method = sai->i_auth.method;
442  sa->i_auth.hex = sai->i_auth.hex;
443  sa->i_auth.data = _(sai->i_auth.data);
444  sa->i_auth.key = _(sai->i_auth.key);
447  sa->childs = _(sai->childs);
448  sa->udp_encap = sai->udp_encap;
450  sa->dst_port = sai->dst_port;
451  sa->sw_if_index = sai->sw_if_index;
452 #undef _
453 
454 
455  if (sa->dh_group == IKEV2_TRANSFORM_DH_TYPE_NONE)
456  {
457  return;
458  }
459 
460  /* check if received DH group is on our list of supported groups */
462  {
463  if (t2->type == IKEV2_TRANSFORM_TYPE_DH && sa->dh_group == t2->dh_type)
464  {
465  t = t2;
466  break;
467  }
468  }
469 
470  if (!t)
471  {
472  sa->dh_group = IKEV2_TRANSFORM_DH_TYPE_NONE;
473  return;
474  }
475 
476 
477  /* generate dh keys */
478  ikev2_complete_dh (sa, t);
479 
480 }
481 
482 static void
484 {
485  u8 *tmp;
486  /* calculate SKEYSEED = prf(Ni | Nr, g^ir) */
487  u8 *skeyseed = 0;
488  u8 *s = 0;
489  u16 integ_key_len = 0, salt_len = 0;
490  ikev2_sa_transform_t *tr_encr, *tr_prf, *tr_integ;
491  tr_encr =
492  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
493  tr_prf =
494  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
495  tr_integ =
496  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
497 
498  if (tr_integ)
499  integ_key_len = tr_integ->key_len;
500  else
501  salt_len = sizeof (u32);
502 
503  vec_append (s, sa->i_nonce);
504  vec_append (s, sa->r_nonce);
505  skeyseed = ikev2_calc_prf (tr_prf, s, sa->dh_shared_key);
506 
507  /* Calculate S = Ni | Nr | SPIi | SPIr */
508  u64 *spi;
509  vec_add2 (s, tmp, 2 * sizeof (*spi));
510  spi = (u64 *) tmp;
511  spi[0] = clib_host_to_net_u64 (sa->ispi);
512  spi[1] = clib_host_to_net_u64 (sa->rspi);
513 
514  /* calculate PRFplus */
515  u8 *keymat;
516  int len = tr_prf->key_trunc + /* SK_d */
517  integ_key_len * 2 + /* SK_ai, SK_ar */
518  tr_encr->key_len * 2 + /* SK_ei, SK_er */
519  tr_prf->key_len * 2 + /* SK_pi, SK_pr */
520  salt_len * 2;
521 
522  keymat = ikev2_calc_prfplus (tr_prf, skeyseed, s, len);
523  vec_free (skeyseed);
524  vec_free (s);
525 
526  int pos = 0;
527 
528  /* SK_d */
529  sa->sk_d = vec_new (u8, tr_prf->key_trunc);
530  clib_memcpy_fast (sa->sk_d, keymat + pos, tr_prf->key_trunc);
531  pos += tr_prf->key_trunc;
532 
533  if (integ_key_len)
534  {
535  /* SK_ai */
536  sa->sk_ai = vec_new (u8, integ_key_len);
537  clib_memcpy_fast (sa->sk_ai, keymat + pos, integ_key_len);
538  pos += integ_key_len;
539 
540  /* SK_ar */
541  sa->sk_ar = vec_new (u8, integ_key_len);
542  clib_memcpy_fast (sa->sk_ar, keymat + pos, integ_key_len);
543  pos += integ_key_len;
544  }
545 
546  /* SK_ei */
547  sa->sk_ei = vec_new (u8, tr_encr->key_len + salt_len);
548  clib_memcpy_fast (sa->sk_ei, keymat + pos, tr_encr->key_len + salt_len);
549  pos += tr_encr->key_len + salt_len;
550 
551  /* SK_er */
552  sa->sk_er = vec_new (u8, tr_encr->key_len + salt_len);
553  clib_memcpy_fast (sa->sk_er, keymat + pos, tr_encr->key_len + salt_len);
554  pos += tr_encr->key_len + salt_len;
555 
556  /* SK_pi */
557  sa->sk_pi = vec_new (u8, tr_prf->key_len);
558  clib_memcpy_fast (sa->sk_pi, keymat + pos, tr_prf->key_len);
559  pos += tr_prf->key_len;
560 
561  /* SK_pr */
562  sa->sk_pr = vec_new (u8, tr_prf->key_len);
563  clib_memcpy_fast (sa->sk_pr, keymat + pos, tr_prf->key_len);
564  pos += tr_prf->key_len;
565 
566  vec_free (keymat);
567  sa->keys_generated = 1;
568 }
569 
570 static void
572 {
573  u8 *s = 0;
574  u16 integ_key_len = 0;
575  u8 salt_len = 0;
576 
577  ikev2_sa_transform_t *tr_prf, *ctr_encr, *ctr_integ;
578  tr_prf =
579  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
580  ctr_encr =
581  ikev2_sa_get_td_for_type (child->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
582  ctr_integ =
583  ikev2_sa_get_td_for_type (child->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
584 
585  if (ctr_integ)
586  integ_key_len = ctr_integ->key_len;
587  else
588  salt_len = sizeof (u32);
589 
590  vec_append (s, sa->i_nonce);
591  vec_append (s, sa->r_nonce);
592  /* calculate PRFplus */
593  u8 *keymat;
594  int len = ctr_encr->key_len * 2 + integ_key_len * 2 + salt_len * 2;
595 
596  keymat = ikev2_calc_prfplus (tr_prf, sa->sk_d, s, len);
597 
598  int pos = 0;
599 
600  /* SK_ei */
601  child->sk_ei = vec_new (u8, ctr_encr->key_len);
602  clib_memcpy_fast (child->sk_ei, keymat + pos, ctr_encr->key_len);
603  pos += ctr_encr->key_len;
604 
605  if (ctr_integ)
606  {
607  /* SK_ai */
608  child->sk_ai = vec_new (u8, ctr_integ->key_len);
609  clib_memcpy_fast (child->sk_ai, keymat + pos, ctr_integ->key_len);
610  pos += ctr_integ->key_len;
611  }
612  else
613  {
614  clib_memcpy (&child->salt_ei, keymat + pos, salt_len);
615  pos += salt_len;
616  }
617 
618  /* SK_er */
619  child->sk_er = vec_new (u8, ctr_encr->key_len);
620  clib_memcpy_fast (child->sk_er, keymat + pos, ctr_encr->key_len);
621  pos += ctr_encr->key_len;
622 
623  if (ctr_integ)
624  {
625  /* SK_ar */
626  child->sk_ar = vec_new (u8, integ_key_len);
627  clib_memcpy_fast (child->sk_ar, keymat + pos, integ_key_len);
628  pos += integ_key_len;
629  }
630  else
631  {
632  clib_memcpy (&child->salt_er, keymat + pos, salt_len);
633  pos += salt_len;
634  }
635 
636  ASSERT (pos == len);
637 
638  vec_free (keymat);
639 }
640 
643 {
644  const u32 max_buf_size =
645  sizeof (ispi) + sizeof (rspi) + sizeof (ip6_address_t) + sizeof (u16);
646  u8 buf[max_buf_size];
647  u8 *res = vec_new (u8, 20);
648 
649  clib_memcpy_fast (&buf[0], &ispi, sizeof (ispi));
650  clib_memcpy_fast (&buf[8], &rspi, sizeof (rspi));
651  clib_memcpy_fast (&buf[8 + 8], ip_addr_bytes (ia), ip_address_size (ia));
652  clib_memcpy_fast (&buf[8 + 8 + ip_address_size (ia)], &port, sizeof (port));
653  SHA1 (buf, 2 * sizeof (ispi) + sizeof (port) + ip_address_size (ia), res);
654  return res;
655 }
656 
657 static int
658 ikev2_parse_ke_payload (const void *p, u32 rlen, ikev2_sa_t * sa,
659  u8 ** ke_data)
660 {
661  const ike_ke_payload_header_t *ke = p;
662  u16 plen = clib_net_to_host_u16 (ke->length);
663  ASSERT (plen >= sizeof (*ke) && plen <= rlen);
664  if (sizeof (*ke) > rlen)
665  return 0;
666 
667  sa->dh_group = clib_net_to_host_u16 (ke->dh_group);
668  vec_reset_length (ke_data[0]);
669  vec_add (ke_data[0], ke->payload, plen - sizeof (*ke));
670  return 1;
671 }
672 
673 static int
674 ikev2_parse_nonce_payload (const void *p, u32 rlen, u8 * nonce)
675 {
676  const ike_payload_header_t *ikep = p;
677  u16 plen = clib_net_to_host_u16 (ikep->length);
678  ASSERT (plen >= sizeof (*ikep) && plen <= rlen);
679  clib_memcpy_fast (nonce, ikep->payload, plen - sizeof (*ikep));
680  return 1;
681 }
682 
683 static int
684 ikev2_check_payload_length (const ike_payload_header_t * ikep, int rlen,
685  u16 * plen)
686 {
687  if (sizeof (*ikep) > rlen)
688  return 0;
689  *plen = clib_net_to_host_u16 (ikep->length);
690  if (*plen < sizeof (*ikep) || *plen > rlen)
691  return 0;
692  return 1;
693 }
694 
695 static int
698 {
699  u8 nonce[IKEV2_NONCE_SIZE];
700  int p = 0;
701  u8 payload = ike->nextpayload;
702  ike_payload_header_t *ikep;
703  u16 plen;
704 
705  ikev2_elog_exchange ("ispi %lx rspi %lx IKE_INIT request received "
706  "from ", clib_net_to_host_u64 (ike->ispi),
707  clib_net_to_host_u64 (ike->rspi),
708  ip_addr_v4 (&sa->iaddr).as_u32,
709  ip_addr_version (&sa->iaddr) == AF_IP4);
710 
711  sa->ispi = clib_net_to_host_u64 (ike->ispi);
712  sa->sw_if_index = sw_if_index;
713 
714  /* store whole IKE payload - needed for PSK auth */
717 
718  if (len < sizeof (*ike))
719  return 0;
720 
721  len -= sizeof (*ike);
722  while (p < len && payload != IKEV2_PAYLOAD_NONE)
723  {
724  ikep = (ike_payload_header_t *) & ike->payload[p];
725  int current_length = len - p;
726  if (!ikev2_check_payload_length (ikep, current_length, &plen))
727  return 0;
728 
729  if (payload == IKEV2_PAYLOAD_SA)
730  {
732  sa->i_proposals = ikev2_parse_sa_payload (ikep, current_length);
733  }
734  else if (payload == IKEV2_PAYLOAD_KE)
735  {
736  if (!ikev2_parse_ke_payload (ikep, current_length, sa,
737  &sa->i_dh_data))
738  return 0;
739  }
740  else if (payload == IKEV2_PAYLOAD_NONCE)
741  {
743  if (ikev2_parse_nonce_payload (ikep, current_length, nonce))
744  vec_add (sa->i_nonce, nonce, plen - sizeof (*ikep));
745  }
746  else if (payload == IKEV2_PAYLOAD_NOTIFY)
747  {
748  ikev2_notify_t *n =
749  ikev2_parse_notify_payload (ikep, current_length);
750  if (n->msg_type == IKEV2_NOTIFY_MSG_NAT_DETECTION_SOURCE_IP)
751  {
752  u8 *src_sha = ikev2_compute_nat_sha1 (ike->ispi, 0, &sa->iaddr,
753  udp->src_port);
754  if (clib_memcmp (src_sha, n->data, vec_len (src_sha)))
755  {
756  if (sa->natt_state == IKEV2_NATT_ENABLED)
758  ikev2_elog_uint (IKEV2_LOG_DEBUG, "ispi %lx initiator"
759  " behind NAT", sa->ispi);
760  }
761  vec_free (src_sha);
762  }
763  else if (n->msg_type ==
764  IKEV2_NOTIFY_MSG_NAT_DETECTION_DESTINATION_IP)
765  {
766  u8 *dst_sha = ikev2_compute_nat_sha1 (ike->ispi, 0, &sa->raddr,
767  udp->dst_port);
768  if (clib_memcmp (dst_sha, n->data, vec_len (dst_sha)))
769  {
770  if (sa->natt_state == IKEV2_NATT_ENABLED)
772  ikev2_elog_uint (IKEV2_LOG_DEBUG, "ispi %lx responder"
773  " (self) behind NAT", sa->ispi);
774  }
775  vec_free (dst_sha);
776  }
777  vec_free (n);
778  }
779  else if (payload == IKEV2_PAYLOAD_VENDOR)
780  {
782  }
783  else
784  {
785  ikev2_elog_uint (IKEV2_LOG_ERROR, "Unknown payload! type=%d",
786  payload);
787  if (ikep->flags & IKEV2_PAYLOAD_FLAG_CRITICAL)
788  {
790  sa->unsupported_cp = payload;
791  return 0;
792  }
793  }
794 
795  payload = ikep->nextpayload;
796  p += plen;
797  }
798 
800  return 1;
801 }
802 
803 static void
805  ikev2_sa_t * sa, ike_header_t * ike,
806  udp_header_t * udp, u32 len)
807 {
808  u8 nonce[IKEV2_NONCE_SIZE];
809  int p = 0;
810  u8 payload = ike->nextpayload;
811  ike_payload_header_t *ikep;
812  u16 plen;
813 
814  sa->ispi = clib_net_to_host_u64 (ike->ispi);
815  sa->rspi = clib_net_to_host_u64 (ike->rspi);
816 
817  ikev2_elog_exchange ("ispi %lx rspi %lx IKE_INIT response received "
818  "from ", sa->ispi, sa->rspi,
819  ip_addr_v4 (&sa->raddr).as_u32,
820  ip_addr_version (&sa->raddr) == AF_IP4);
821 
822  /* store whole IKE payload - needed for PSK auth */
825 
826  if (sizeof (*ike) > len)
827  return;
828 
829  len -= sizeof (*ike);
830  while (p < len && payload != IKEV2_PAYLOAD_NONE)
831  {
832  int current_length = len - p;
833  ikep = (ike_payload_header_t *) & ike->payload[p];
834  if (!ikev2_check_payload_length (ikep, current_length, &plen))
835  return;
836 
837  if (payload == IKEV2_PAYLOAD_SA)
838  {
840  sa->r_proposals = ikev2_parse_sa_payload (ikep, current_length);
841  if (sa->r_proposals)
842  {
844  ike->msgid =
845  clib_host_to_net_u32 (clib_net_to_host_u32 (ike->msgid) + 1);
846  }
847  }
848  else if (payload == IKEV2_PAYLOAD_KE)
849  {
850  if (!ikev2_parse_ke_payload (ikep, current_length, sa,
851  &sa->r_dh_data))
852  return;
853  }
854  else if (payload == IKEV2_PAYLOAD_NONCE)
855  {
857  if (ikev2_parse_nonce_payload (ikep, current_length, nonce))
858  vec_add (sa->r_nonce, nonce, plen - sizeof (*ikep));
859  }
860  else if (payload == IKEV2_PAYLOAD_NOTIFY)
861  {
862  ikev2_notify_t *n =
863  ikev2_parse_notify_payload (ikep, current_length);
864  if (n->msg_type == IKEV2_NOTIFY_MSG_NAT_DETECTION_SOURCE_IP)
865  {
866  u8 *src_sha = ikev2_compute_nat_sha1 (ike->ispi, ike->rspi,
867  &sa->raddr,
868  udp->src_port);
869  if (clib_memcmp (src_sha, n->data, vec_len (src_sha)))
870  {
871  ikev2_elog_uint (IKEV2_LOG_DEBUG, "ispi %lx responder"
872  " behind NAT, unsupported", sa->ispi);
873  }
874  vec_free (src_sha);
875  }
876  else if (n->msg_type ==
877  IKEV2_NOTIFY_MSG_NAT_DETECTION_DESTINATION_IP)
878  {
879  u8 *dst_sha = ikev2_compute_nat_sha1 (ike->ispi, ike->rspi,
880  &sa->iaddr,
881  udp->dst_port);
882  if (clib_memcmp (dst_sha, n->data, vec_len (dst_sha)))
883  {
884  if (sa->natt_state == IKEV2_NATT_ENABLED)
886  ikev2_elog_uint (IKEV2_LOG_DEBUG, "ispi %lx initiator"
887  " (self) behind NAT", sa->ispi);
888  }
889  vec_free (dst_sha);
890  }
891  vec_free (n);
892  }
893  else if (payload == IKEV2_PAYLOAD_VENDOR)
894  {
896  }
897  else
898  {
899  ikev2_elog_uint (IKEV2_LOG_ERROR, "Unknown payload! type=%d",
900  payload);
901  if (ikep->flags & IKEV2_PAYLOAD_FLAG_CRITICAL)
902  {
904  sa->unsupported_cp = payload;
905  return;
906  }
907  }
908 
909  payload = ikep->nextpayload;
910  p += plen;
911  }
912 }
913 
914 static u8 *
916  u8 * payload, u32 rlen, u32 * out_len)
917 {
919  int p = 0;
920  u8 last_payload = 0, *hmac = 0, *plaintext = 0;
921  ike_payload_header_t *ikep = 0;
922  u16 plen = 0;
923  u32 dlen = 0;
924  ikev2_sa_transform_t *tr_integ;
925  ikev2_sa_transform_t *tr_encr;
926  tr_integ =
927  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
928  tr_encr =
929  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
930  int is_aead = tr_encr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_GCM_16;
931 
932  if (((!sa->sk_ar || !sa->sk_ai) && !is_aead) || (!sa->sk_ei || !sa->sk_er))
933  return 0;
934 
935  if (rlen <= sizeof (*ike))
936  return 0;
937 
938  int len = rlen - sizeof (*ike);
939  while (p < len &&
940  *payload != IKEV2_PAYLOAD_NONE && last_payload != IKEV2_PAYLOAD_SK)
941  {
942  ikep = (ike_payload_header_t *) & ike->payload[p];
943  int current_length = len - p;
944  if (!ikev2_check_payload_length (ikep, current_length, &plen))
945  return 0;
946 
947  if (*payload == IKEV2_PAYLOAD_SK)
948  {
949  last_payload = *payload;
950  }
951  else
952  {
953  ikev2_elog_uint (IKEV2_LOG_ERROR, "Unknown payload! type=%d",
954  *payload);
955  if (ikep->flags & IKEV2_PAYLOAD_FLAG_CRITICAL)
956  {
957  sa->unsupported_cp = *payload;
958  return 0;
959  }
960  }
961 
962  *payload = ikep->nextpayload;
963  p += plen;
964  }
965 
966  if (last_payload != IKEV2_PAYLOAD_SK)
967  {
968  ikev2_elog_error ("Last payload must be SK");
969  return 0;
970  }
971 
972  if (is_aead)
973  {
974  if (plen < sizeof (*ikep) + IKEV2_GCM_ICV_SIZE)
975  return 0;
976 
977  plen -= sizeof (*ikep) + IKEV2_GCM_ICV_SIZE;
978  u8 *aad = (u8 *) ike;
979  u32 aad_len = ikep->payload - aad;
980  u8 *tag = ikep->payload + plen;
981 
982  int rc = ikev2_decrypt_aead_data (ptd, sa, tr_encr, ikep->payload,
983  plen, aad, aad_len, tag, &dlen);
984  if (rc)
985  {
986  *out_len = dlen;
987  plaintext = ikep->payload + IKEV2_GCM_IV_SIZE;
988  }
989  }
990  else
991  {
992  if (rlen < tr_integ->key_trunc)
993  return 0;
994 
995  hmac =
996  ikev2_calc_integr (tr_integ, sa->is_initiator ? sa->sk_ar : sa->sk_ai,
997  (u8 *) ike, rlen - tr_integ->key_trunc);
998 
999  if (plen < sizeof (*ikep) + tr_integ->key_trunc)
1000  return 0;
1001 
1002  plen = plen - sizeof (*ikep) - tr_integ->key_trunc;
1003 
1004  if (clib_memcmp (hmac, &ikep->payload[plen], tr_integ->key_trunc))
1005  {
1006  ikev2_elog_error ("message integrity check failed");
1007  vec_free (hmac);
1008  return 0;
1009  }
1010  vec_free (hmac);
1011 
1012  int rc = ikev2_decrypt_data (ptd, sa, tr_encr, ikep->payload, plen,
1013  &dlen);
1014  if (rc)
1015  {
1016  *out_len = dlen;
1017  plaintext = ikep->payload + tr_encr->block_size;
1018  }
1019  }
1020 
1021  return plaintext;
1022 }
1023 
1026 {
1027  if (i1->type != i2->type)
1028  return 0;
1029 
1030  if (vec_len (i1->data) != vec_len (i2->data))
1031  return 0;
1032 
1033  if (clib_memcmp (i1->data, i2->data, vec_len (i1->data)))
1034  return 0;
1035 
1036  return 1;
1037 }
1038 
1039 static void
1041  ikev2_sa_t * sa)
1042 {
1043  ikev2_main_t *km = &ikev2_main;
1044  ikev2_sa_t *tmp;
1045  u32 i, *delete = 0;
1047 
1048  /* find old IKE SAs with the same authenticated identity */
1049  /* *INDENT-OFF* */
1050  pool_foreach (tmp, ptd->sas) {
1051  if (!ikev2_is_id_equal (&tmp->i_id, &sa->i_id)
1052  || !ikev2_is_id_equal(&tmp->r_id, &sa->r_id))
1053  continue;
1054 
1055  if (sa->rspi != tmp->rspi)
1056  vec_add1(delete, tmp - ptd->sas);
1057  }
1058  /* *INDENT-ON* */
1059 
1060  for (i = 0; i < vec_len (delete); i++)
1061  {
1062  tmp = pool_elt_at_index (ptd->sas, delete[i]);
1063  vec_foreach (c, tmp->childs)
1064  {
1066  }
1067  ikev2_delete_sa (ptd, tmp);
1068  }
1069 
1070  vec_free (delete);
1071  sa->initial_contact = 0;
1072 }
1073 
1074 static void
1076  ikev2_sa_t * sa)
1077 {
1078  ikev2_main_t *km = &ikev2_main;
1079 
1080  if (!sa->initial_contact)
1081  return;
1082 
1083  if (ptd)
1084  {
1086  }
1087  else
1088  {
1089  vec_foreach (ptd, km->per_thread_data)
1091  }
1092  sa->initial_contact = 0;
1093 }
1094 
1095 static int
1096 ikev2_parse_id_payload (const void *p, u16 rlen, ikev2_id_t * sa_id)
1097 {
1098  const ike_id_payload_header_t *id = p;
1099  u16 plen = clib_net_to_host_u16 (id->length);
1100  if (plen < sizeof (*id) || plen > rlen)
1101  return 0;
1102 
1103  sa_id->type = id->id_type;
1104  vec_reset_length (sa_id->data);
1105  vec_add (sa_id->data, id->payload, plen - sizeof (*id));
1106 
1107  return 1;
1108 }
1109 
1110 static int
1111 ikev2_parse_auth_payload (const void *p, u32 rlen, ikev2_auth_t * a)
1112 {
1113  const ike_auth_payload_header_t *ah = p;
1114  u16 plen = clib_net_to_host_u16 (ah->length);
1115 
1116  a->method = ah->auth_method;
1117  vec_reset_length (a->data);
1118  vec_add (a->data, ah->payload, plen - sizeof (*ah));
1119  return 1;
1120 }
1121 
1122 static int
1124  ike_header_t * ike, u32 len)
1125 {
1126  int p = 0;
1127  ikev2_child_sa_t *first_child_sa;
1128  u8 payload = ike->nextpayload;
1129  u8 *plaintext = 0;
1130  ike_payload_header_t *ikep;
1131  u16 plen;
1132  u32 dlen = 0;
1133 
1134  ikev2_elog_exchange ("ispi %lx rspi %lx EXCHANGE_IKE_AUTH received "
1135  "from ", clib_host_to_net_u64 (ike->ispi),
1136  clib_host_to_net_u64 (ike->rspi),
1137  sa->is_initiator ?
1138  ip_addr_v4 (&sa->raddr).as_u32 :
1139  ip_addr_v4 (&sa->iaddr).as_u32,
1140  ip_addr_version (&sa->raddr) == AF_IP4);
1141 
1142  ikev2_calc_keys (sa);
1143 
1144  plaintext = ikev2_decrypt_sk_payload (sa, ike, &payload, len, &dlen);
1145 
1146  if (!plaintext)
1147  {
1148  if (sa->unsupported_cp)
1149  {
1151  return 0;
1152  }
1153  goto malformed;
1154  }
1155 
1156  /* select or create 1st child SA */
1157  if (sa->is_initiator)
1158  {
1159  first_child_sa = &sa->childs[0];
1160  }
1161  else
1162  {
1164  vec_add2 (sa->childs, first_child_sa, 1);
1165  }
1166 
1167 
1168  /* process encrypted payload */
1169  while (p < dlen && payload != IKEV2_PAYLOAD_NONE)
1170  {
1171  ikep = (ike_payload_header_t *) & plaintext[p];
1172  int current_length = dlen - p;
1173  if (!ikev2_check_payload_length (ikep, current_length, &plen))
1174  goto malformed;
1175 
1176  if (payload == IKEV2_PAYLOAD_SA) /* 33 */
1177  {
1178  if (sa->is_initiator)
1179  {
1180  ikev2_sa_free_proposal_vector (&first_child_sa->r_proposals);
1181  first_child_sa->r_proposals = ikev2_parse_sa_payload (ikep,
1182  current_length);
1183  }
1184  else
1185  {
1186  ikev2_sa_free_proposal_vector (&first_child_sa->i_proposals);
1187  first_child_sa->i_proposals = ikev2_parse_sa_payload (ikep,
1188  current_length);
1189  }
1190  }
1191  else if (payload == IKEV2_PAYLOAD_IDI) /* 35 */
1192  {
1193  if (!ikev2_parse_id_payload (ikep, current_length, &sa->i_id))
1194  goto malformed;
1195  }
1196  else if (payload == IKEV2_PAYLOAD_IDR) /* 36 */
1197  {
1198  if (!ikev2_parse_id_payload (ikep, current_length, &sa->r_id))
1199  goto malformed;
1200  }
1201  else if (payload == IKEV2_PAYLOAD_AUTH) /* 39 */
1202  {
1203  if (sa->is_initiator)
1204  {
1205  if (!ikev2_parse_auth_payload (ikep, current_length,
1206  &sa->r_auth))
1207  goto malformed;
1208  }
1209  else
1210  {
1211  if (!ikev2_parse_auth_payload (ikep, current_length,
1212  &sa->i_auth))
1213  goto malformed;
1214  }
1215  }
1216  else if (payload == IKEV2_PAYLOAD_NOTIFY) /* 41 */
1217  {
1218  ikev2_notify_t *n =
1219  ikev2_parse_notify_payload (ikep, current_length);
1220  if (n->msg_type == IKEV2_NOTIFY_MSG_INITIAL_CONTACT)
1221  {
1222  sa->initial_contact = 1;
1223  }
1224  vec_free (n);
1225  }
1226  else if (payload == IKEV2_PAYLOAD_VENDOR) /* 43 */
1227  {
1229  }
1230  else if (payload == IKEV2_PAYLOAD_TSI) /* 44 */
1231  {
1232  vec_free (first_child_sa->tsi);
1233  first_child_sa->tsi = ikev2_parse_ts_payload (ikep, current_length);
1234  }
1235  else if (payload == IKEV2_PAYLOAD_TSR) /* 45 */
1236  {
1237  vec_free (first_child_sa->tsr);
1238  first_child_sa->tsr = ikev2_parse_ts_payload (ikep, current_length);
1239  }
1240  else
1241  {
1242  ikev2_elog_uint (IKEV2_LOG_ERROR, "Unknown payload! type=%d",
1243  payload);
1244 
1245  if (ikep->flags & IKEV2_PAYLOAD_FLAG_CRITICAL)
1246  {
1248  sa->unsupported_cp = payload;
1249  return 0;
1250  }
1251  }
1252 
1253  payload = ikep->nextpayload;
1254  p += plen;
1255  }
1256 
1257  return 1;
1258 
1259 malformed:
1260  ikev2_set_state (sa, IKEV2_STATE_DELETED, ": malformed IKE_AUTH");
1261  return 0;
1262 }
1263 
1264 static int
1266  ikev2_sa_t * sa, ike_header_t * ike, u32 len)
1267 {
1268  int p = 0;
1269  u8 payload = ike->nextpayload;
1270  u8 *plaintext = 0;
1271  ike_payload_header_t *ikep;
1272  u32 dlen = 0;
1273  ikev2_notify_t *n = 0;
1274 
1275  sa->liveness_retries = 0;
1276  ikev2_elog_exchange ("ispi %lx rspi %lx INFORMATIONAL received "
1277  "from ", clib_host_to_net_u64 (ike->ispi),
1278  clib_host_to_net_u64 (ike->rspi),
1279  ip_addr_v4 (&sa->iaddr).as_u32,
1280  ip_addr_version (&sa->iaddr) == AF_IP4);
1281 
1282  plaintext = ikev2_decrypt_sk_payload (sa, ike, &payload, len, &dlen);
1283 
1284  if (!plaintext)
1285  return 0;
1286 
1287  /* process encrypted payload */
1288  p = 0;
1289  while (p < dlen && payload != IKEV2_PAYLOAD_NONE)
1290  {
1291  u32 current_length = dlen - p;
1292  if (p + sizeof (*ikep) > dlen)
1293  return 0;
1294 
1295  ikep = (ike_payload_header_t *) & plaintext[p];
1296  u16 plen = clib_net_to_host_u16 (ikep->length);
1297 
1298  if (plen < sizeof (*ikep) || plen > current_length)
1299  return 0;
1300 
1301  if (payload == IKEV2_PAYLOAD_NOTIFY) /* 41 */
1302  {
1303  n = ikev2_parse_notify_payload (ikep, current_length);
1304  if (!n)
1305  return 0;
1306  if (n->msg_type == IKEV2_NOTIFY_MSG_AUTHENTICATION_FAILED)
1308  vec_free (n);
1309  }
1310  else if (payload == IKEV2_PAYLOAD_DELETE) /* 42 */
1311  {
1312  sa->del = ikev2_parse_delete_payload (ikep, current_length);
1313  }
1314  else if (payload == IKEV2_PAYLOAD_VENDOR) /* 43 */
1315  {
1317  }
1318  else
1319  {
1320  ikev2_elog_uint (IKEV2_LOG_ERROR, "Unknown payload! type=%d",
1321  payload);
1322  if (ikep->flags & IKEV2_PAYLOAD_FLAG_CRITICAL)
1323  {
1324  sa->unsupported_cp = payload;
1325  return 0;
1326  }
1327  }
1328  payload = ikep->nextpayload;
1329  p += plen;
1330  }
1331  return 1;
1332 }
1333 
1334 static int
1336  ikev2_sa_t * sa, ike_header_t * ike,
1337  u32 len)
1338 {
1339  int p = 0;
1340  u8 payload = ike->nextpayload;
1341  u8 *plaintext = 0;
1342  u8 rekeying = 0;
1343  u8 nonce[IKEV2_NONCE_SIZE];
1344  ikev2_rekey_t *rekey;
1345  ike_payload_header_t *ikep;
1346  ikev2_notify_t *n = 0;
1347  ikev2_ts_t *tsi = 0;
1348  ikev2_ts_t *tsr = 0;
1349  ikev2_sa_proposal_t *proposal = 0;
1350  ikev2_child_sa_t *child_sa;
1351  u32 dlen = 0, src;
1352  u16 plen;
1353 
1354  if (sa->is_initiator)
1355  src = ip_addr_v4 (&sa->raddr).as_u32;
1356  else
1357  src = ip_addr_v4 (&sa->iaddr).as_u32;
1358 
1359  ikev2_elog_exchange ("ispi %lx rspi %lx CREATE_CHILD_SA received from",
1360  clib_host_to_net_u64 (ike->ispi),
1361  clib_host_to_net_u64 (ike->rspi), src,
1362  ip_addr_version (&sa->raddr) == AF_IP4);
1363 
1364  plaintext = ikev2_decrypt_sk_payload (sa, ike, &payload, len, &dlen);
1365 
1366  if (!plaintext)
1367  goto cleanup_and_exit;
1368 
1369  /* process encrypted payload */
1370  p = 0;
1371  while (payload != IKEV2_PAYLOAD_NONE)
1372  {
1373  ikep = (ike_payload_header_t *) & plaintext[p];
1374  int current_length = dlen - p;
1375  if (!ikev2_check_payload_length (ikep, current_length, &plen))
1376  goto cleanup_and_exit;
1377 
1378  if (payload == IKEV2_PAYLOAD_SA)
1379  {
1380  proposal = ikev2_parse_sa_payload (ikep, current_length);
1381  }
1382  else if (payload == IKEV2_PAYLOAD_NOTIFY)
1383  {
1384  n = ikev2_parse_notify_payload (ikep, current_length);
1385  if (n->msg_type == IKEV2_NOTIFY_MSG_REKEY_SA)
1386  {
1387  rekeying = 1;
1388  }
1389  }
1390  else if (payload == IKEV2_PAYLOAD_DELETE)
1391  {
1392  sa->del = ikev2_parse_delete_payload (ikep, current_length);
1393  }
1394  else if (payload == IKEV2_PAYLOAD_VENDOR)
1395  {
1397  }
1398  else if (payload == IKEV2_PAYLOAD_NONCE)
1399  {
1400  ikev2_parse_nonce_payload (ikep, current_length, nonce);
1401  }
1402  else if (payload == IKEV2_PAYLOAD_TSI)
1403  {
1404  tsi = ikev2_parse_ts_payload (ikep, current_length);
1405  }
1406  else if (payload == IKEV2_PAYLOAD_TSR)
1407  {
1408  tsr = ikev2_parse_ts_payload (ikep, current_length);
1409  }
1410  else
1411  {
1412  ikev2_elog_uint (IKEV2_LOG_ERROR, "Unknown payload! type=%d",
1413  payload);
1414  if (ikep->flags & IKEV2_PAYLOAD_FLAG_CRITICAL)
1415  {
1416  sa->unsupported_cp = payload;
1417  goto cleanup_and_exit;
1418  }
1419  }
1420  payload = ikep->nextpayload;
1421  p += plen;
1422  }
1423 
1424  if (!proposal || proposal->protocol_id != IKEV2_PROTOCOL_ESP)
1425  goto cleanup_and_exit;
1426 
1427  if (sa->is_initiator)
1428  {
1429  rekey = sa->rekey;
1430  if (vec_len (rekey) == 0)
1431  goto cleanup_and_exit;
1432  rekey->protocol_id = proposal->protocol_id;
1433  rekey->i_proposal =
1435  rekey->i_proposal->spi = rekey->spi;
1436  rekey->r_proposal = proposal;
1437  rekey->tsi = tsi;
1438  rekey->tsr = tsr;
1439  /* update Nr */
1440  vec_reset_length (sa->r_nonce);
1441  vec_add (sa->r_nonce, nonce, IKEV2_NONCE_SIZE);
1442  child_sa = ikev2_sa_get_child (sa, rekey->ispi, IKEV2_PROTOCOL_ESP, 1);
1443  if (child_sa)
1444  {
1445  child_sa->rekey_retries = 0;
1446  }
1447  }
1448  else
1449  {
1450  if (rekeying)
1451  {
1452  child_sa = ikev2_sa_get_child (sa, n->spi, n->protocol_id, 1);
1453  if (!child_sa)
1454  {
1455  ikev2_elog_uint (IKEV2_LOG_ERROR, "child SA spi %lx not found",
1456  n->spi);
1457  goto cleanup_and_exit;
1458  }
1459  vec_add2 (sa->rekey, rekey, 1);
1460  rekey->protocol_id = n->protocol_id;
1461  rekey->spi = n->spi;
1462  rekey->i_proposal = proposal;
1463  rekey->r_proposal =
1465  /* update Ni */
1466  vec_reset_length (sa->i_nonce);
1467  vec_add (sa->i_nonce, nonce, IKEV2_NONCE_SIZE);
1468  /* generate new Nr */
1470  RAND_bytes ((u8 *) sa->r_nonce, IKEV2_NONCE_SIZE);
1471  }
1472  else
1473  {
1474  /* create new child SA */
1475  vec_add2 (sa->new_child, rekey, 1);
1476  rekey->i_proposal = proposal;
1477  rekey->r_proposal =
1479  /* update Ni */
1480  vec_reset_length (sa->i_nonce);
1481  vec_add (sa->i_nonce, nonce, IKEV2_NONCE_SIZE);
1482  /* generate new Nr */
1484  RAND_bytes ((u8 *) sa->r_nonce, IKEV2_NONCE_SIZE);
1485  }
1486  rekey->tsi = tsi;
1487  rekey->tsr = tsr;
1488  }
1489  vec_free (n);
1490  return 1;
1491 
1492 cleanup_and_exit:
1493  vec_free (n);
1494  vec_free (proposal);
1495  vec_free (tsr);
1496  vec_free (tsi);
1497  return 0;
1498 }
1499 
1500 static u8 *
1501 ikev2_sa_generate_authmsg (ikev2_sa_t * sa, int is_responder)
1502 {
1503  u8 *authmsg = 0;
1504  u8 *data;
1505  u8 *nonce;
1506  ikev2_id_t *id;
1507  u8 *key;
1508  u8 *packet_data;
1509  ikev2_sa_transform_t *tr_prf;
1510 
1511  tr_prf =
1512  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
1513 
1514  if (is_responder)
1515  {
1516  id = &sa->r_id;
1517  key = sa->sk_pr;
1518  nonce = sa->i_nonce;
1519  packet_data = sa->last_sa_init_res_packet_data;
1520  }
1521  else
1522  {
1523  id = &sa->i_id;
1524  key = sa->sk_pi;
1525  nonce = sa->r_nonce;
1526  packet_data = sa->last_sa_init_req_packet_data;
1527  }
1528 
1529  data = vec_new (u8, 4);
1530  data[0] = id->type;
1531  vec_append (data, id->data);
1532 
1533  u8 *id_hash = ikev2_calc_prf (tr_prf, key, data);
1534  vec_append (authmsg, packet_data);
1535  vec_append (authmsg, nonce);
1536  vec_append (authmsg, id_hash);
1537  vec_free (id_hash);
1538  vec_free (data);
1539 
1540  return authmsg;
1541 }
1542 
1543 static int
1545 {
1546  if (ts1->ts_type == ts2->ts_type && ts1->protocol_id == ts2->protocol_id &&
1547  ts1->start_port == ts2->start_port && ts1->end_port == ts2->end_port &&
1548  !ip_address_cmp (&ts1->start_addr, &ts2->start_addr) &&
1549  !ip_address_cmp (&ts1->end_addr, &ts2->end_addr))
1550  return 1;
1551 
1552  return 0;
1553 }
1554 
1555 static void
1557 {
1558  ikev2_main_t *km = &ikev2_main;
1559  ikev2_profile_t *p;
1560  ikev2_ts_t *ts, *p_tsi, *p_tsr, *tsi = 0, *tsr = 0;
1561  ikev2_id_t *id_rem, *id_loc;
1562 
1563  /* *INDENT-OFF* */
1564  pool_foreach (p, km->profiles) {
1565 
1566  if (sa->is_initiator)
1567  {
1568  p_tsi = &p->loc_ts;
1569  p_tsr = &p->rem_ts;
1570  id_rem = &sa->r_id;
1571  id_loc = &sa->i_id;
1572  }
1573  else
1574  {
1575  p_tsi = &p->rem_ts;
1576  p_tsr = &p->loc_ts;
1577  id_rem = &sa->i_id;
1578  id_loc = &sa->r_id;
1579  }
1580 
1581  /* check id */
1582  if (!ikev2_is_id_equal (&p->rem_id, id_rem)
1583  || !ikev2_is_id_equal (&p->loc_id, id_loc))
1584  continue;
1585 
1586  sa->profile_index = p - km->profiles;
1587 
1588  vec_foreach(ts, sa->childs[0].tsi)
1589  {
1590  if (ikev2_ts_cmp(p_tsi, ts))
1591  {
1592  vec_add1 (tsi, ts[0]);
1593  break;
1594  }
1595  }
1596 
1597  vec_foreach(ts, sa->childs[0].tsr)
1598  {
1599  if (ikev2_ts_cmp(p_tsr, ts))
1600  {
1601  vec_add1 (tsr, ts[0]);
1602  break;
1603  }
1604  }
1605 
1606  break;
1607  }
1608  /* *INDENT-ON* */
1609 
1610  if (tsi && tsr)
1611  {
1612  vec_free (sa->childs[0].tsi);
1613  vec_free (sa->childs[0].tsr);
1614  sa->childs[0].tsi = tsi;
1615  sa->childs[0].tsr = tsr;
1616  }
1617  else
1618  {
1619  vec_free (tsi);
1620  vec_free (tsr);
1622  }
1623 }
1624 
1625 static ikev2_profile_t *
1627  ikev2_sa_transform_t *tr_prf, u8 *key_pad)
1628 {
1629  ikev2_profile_t *ret = 0, *p;
1630  ikev2_id_t *id_rem, *id_loc;
1631  ikev2_auth_t *sa_auth;
1632  u8 *authmsg, *psk = 0, *auth = 0;
1633 
1634  authmsg = ikev2_sa_generate_authmsg (sa, sa->is_initiator);
1635 
1636  if (sa->is_initiator)
1637  {
1638  id_rem = &sa->r_id;
1639  id_loc = &sa->i_id;
1640  sa_auth = &sa->r_auth;
1641  }
1642  else
1643  {
1644  id_rem = &sa->i_id;
1645  id_loc = &sa->r_id;
1646  sa_auth = &sa->i_auth;
1647  }
1648 
1649  pool_foreach (p, km->profiles)
1650  {
1651  /* check id */
1652  if (!ikev2_is_id_equal (&p->rem_id, id_rem) ||
1653  !ikev2_is_id_equal (&p->loc_id, id_loc))
1654  continue;
1655 
1656  if (sa_auth->method == IKEV2_AUTH_METHOD_SHARED_KEY_MIC)
1657  {
1658  if (!p->auth.data ||
1659  p->auth.method != IKEV2_AUTH_METHOD_SHARED_KEY_MIC)
1660  continue;
1661 
1662  psk = ikev2_calc_prf (tr_prf, p->auth.data, key_pad);
1663  auth = ikev2_calc_prf (tr_prf, psk, authmsg);
1664 
1665  if (!clib_memcmp (auth, sa_auth->data, vec_len (sa_auth->data)))
1666  {
1668  vec_free (auth);
1669  ret = p;
1670  break;
1671  }
1672  else
1673  {
1674  ikev2_elog_uint (IKEV2_LOG_ERROR,
1675  "shared key mismatch! ispi %lx", sa->ispi);
1676  }
1677  }
1678  else if (sa_auth->method == IKEV2_AUTH_METHOD_RSA_SIG)
1679  {
1680  if (p->auth.method != IKEV2_AUTH_METHOD_RSA_SIG)
1681  continue;
1682 
1683  if (ikev2_verify_sign (p->auth.key, sa_auth->data, authmsg) == 1)
1684  {
1686  ret = p;
1687  break;
1688  }
1689  else
1690  {
1691  ikev2_elog_uint (IKEV2_LOG_ERROR,
1692  "cert verification failed! ispi %lx", sa->ispi);
1693  }
1694  }
1695  }
1696  vec_free (authmsg);
1697  return ret;
1698 }
1699 
1700 static void
1702 {
1703  ikev2_main_t *km = &ikev2_main;
1704  ikev2_profile_t *sel_p = 0;
1705  ikev2_sa_transform_t *tr_prf;
1706  u8 *psk, *authmsg, *key_pad;
1707 
1708  tr_prf =
1709  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
1710 
1711  /* only shared key and rsa signature */
1712  if (!(sa->i_auth.method == IKEV2_AUTH_METHOD_SHARED_KEY_MIC ||
1713  sa->i_auth.method == IKEV2_AUTH_METHOD_RSA_SIG))
1714  {
1715  ikev2_elog_uint (IKEV2_LOG_ERROR, "unsupported authentication method %u",
1716  sa->i_auth.method);
1718  return;
1719  }
1720 
1721  key_pad = format (0, "%s", IKEV2_KEY_PAD);
1722  sel_p = ikev2_select_profile (km, sa, tr_prf, key_pad);
1723 
1724  if (sel_p)
1725  {
1727  sa->udp_encap = sel_p->udp_encap;
1729 
1730  if (!sa->is_initiator)
1731  {
1732  vec_free (sa->r_id.data);
1733  sa->r_id.data = vec_dup (sel_p->loc_id.data);
1734  sa->r_id.type = sel_p->loc_id.type;
1735  sa->i_id.data = vec_dup (sel_p->rem_id.data);
1736  sa->i_id.type = sel_p->rem_id.type;
1737 
1738  /* generate our auth data */
1739  authmsg = ikev2_sa_generate_authmsg (sa, 1);
1740  if (sel_p->auth.method == IKEV2_AUTH_METHOD_SHARED_KEY_MIC)
1741  {
1742  vec_free (sa->r_auth.data);
1743  psk = ikev2_calc_prf (tr_prf, sel_p->auth.data, key_pad);
1744  sa->r_auth.data = ikev2_calc_prf (tr_prf, psk, authmsg);
1745  sa->r_auth.method = IKEV2_AUTH_METHOD_SHARED_KEY_MIC;
1746  vec_free (psk);
1747  }
1748  else if (sel_p->auth.method == IKEV2_AUTH_METHOD_RSA_SIG)
1749  {
1750  vec_free (sa->r_auth.data);
1751  sa->r_auth.data = ikev2_calc_sign (km->pkey, authmsg);
1752  sa->r_auth.method = IKEV2_AUTH_METHOD_RSA_SIG;
1753  }
1754  vec_free (authmsg);
1755 
1756  /* select transforms for 1st child sa */
1758  sa->childs[0].r_proposals =
1761 
1762  if (~0 != sel_p->tun_itf)
1763  {
1764  sa->is_tun_itf_set = 1;
1765  sa->tun_itf = sel_p->tun_itf;
1766  }
1767  }
1768  }
1769  else
1770  {
1771  ikev2_elog_uint (IKEV2_LOG_ERROR, "authentication failed, no matching "
1772  "profile found! ispi %lx", sa->ispi);
1774  }
1775  vec_free (key_pad);
1776 }
1777 
1778 static void
1780 {
1781  ikev2_main_t *km = &ikev2_main;
1782  u8 *authmsg, *key_pad, *psk = 0;
1783  ikev2_sa_transform_t *tr_prf;
1784 
1785  tr_prf =
1786  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
1787 
1788  /* only shared key and rsa signature */
1789  if (!(sa->i_auth.method == IKEV2_AUTH_METHOD_SHARED_KEY_MIC ||
1790  sa->i_auth.method == IKEV2_AUTH_METHOD_RSA_SIG))
1791  {
1792  ikev2_elog_uint (IKEV2_LOG_ERROR,
1793  "unsupported authentication method %u",
1794  sa->i_auth.method);
1796  return;
1797  }
1798 
1799  authmsg = ikev2_sa_generate_authmsg (sa, 0);
1800 
1801  if (sa->i_auth.method == IKEV2_AUTH_METHOD_SHARED_KEY_MIC)
1802  {
1803  key_pad = format (0, "%s", IKEV2_KEY_PAD);
1804  psk = ikev2_calc_prf (tr_prf, sa->i_auth.data, key_pad);
1805  vec_free (sa->i_auth.data);
1806  sa->i_auth.data = ikev2_calc_prf (tr_prf, psk, authmsg);
1807  sa->i_auth.method = IKEV2_AUTH_METHOD_SHARED_KEY_MIC;
1808  vec_free (psk);
1809  vec_free (key_pad);
1810  }
1811  else if (sa->i_auth.method == IKEV2_AUTH_METHOD_RSA_SIG)
1812  {
1813  vec_free (sa->i_auth.data);
1814  sa->i_auth.data = ikev2_calc_sign (km->pkey, authmsg);
1815  sa->i_auth.method = IKEV2_AUTH_METHOD_RSA_SIG;
1816  }
1817  vec_free (authmsg);
1818 }
1819 
1820 static u32
1822 {
1823  return (0x80000000 | (ti << 24) | (sai << 12) | ci);
1824 }
1825 
1826 static u32
1828 {
1829  return (0xc0000000 | (ti << 24) | (sai << 12) | ci);
1830 }
1831 
1832 typedef struct
1833 {
1842  ipsec_crypto_alg_t encr_type;
1843  ipsec_integ_alg_t integ_type;
1846  ipsec_key_t loc_ckey, rem_ckey, loc_ikey, rem_ikey;
1853 
1854 static void
1856 {
1857  ikev2_main_t *km = &ikev2_main;
1858  u32 sw_if_index;
1859  int rv = 0;
1860  tunnel_t tun_in = {
1862  .t_encap_decap_flags = TUNNEL_ENCAP_DECAP_FLAG_NONE,
1863  .t_dscp = 0,
1864  .t_mode = TUNNEL_MODE_P2P,
1865  .t_table_id = 0,
1866  .t_hop_limit = 255,
1867  .t_src = a->local_ip,
1868  .t_dst = a->remote_ip,
1869  };
1870  tunnel_t tun_out = {
1872  .t_encap_decap_flags = TUNNEL_ENCAP_DECAP_FLAG_NONE,
1873  .t_dscp = 0,
1874  .t_mode = TUNNEL_MODE_P2P,
1875  .t_table_id = 0,
1876  .t_hop_limit = 255,
1877  .t_src = a->remote_ip,
1878  .t_dst = a->local_ip,
1879  };
1880 
1881  if (~0 == a->sw_if_index)
1882  {
1883  /* no tunnel associated with the SA/profile - create a new one */
1884  rv = ipip_add_tunnel (IPIP_TRANSPORT_IP4, ~0, &ip_addr_46 (&a->local_ip),
1885  &ip_addr_46 (&a->remote_ip), 0,
1886  TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0,
1887  TUNNEL_MODE_P2P, &sw_if_index);
1888 
1889  if (rv == VNET_API_ERROR_IF_ALREADY_EXISTS)
1890  {
1891  if (hash_get (km->sw_if_indices, sw_if_index))
1892  /* interface is managed by IKE; proceed with updating SAs */
1893  rv = 0;
1894  }
1896  }
1897  else
1898  {
1899  sw_if_index = a->sw_if_index;
1901  }
1902 
1903  if (rv)
1904  {
1905  ikev2_elog_uint (IKEV2_LOG_ERROR,
1906  "installing ipip tunnel failed! local spi: %x",
1907  a->local_spi);
1908  return;
1909  }
1910 
1911  u32 *sas_in = NULL;
1912  vec_add1 (sas_in, a->remote_sa_id);
1913  if (a->is_rekey)
1914  {
1916 
1917  /* replace local SA immediately */
1918  ipsec_sa_unlock_id (a->local_sa_id);
1919 
1920  /* keep the old sa */
1921  vec_add1 (sas_in, a->old_remote_sa_id);
1922  }
1923 
1924  rv = ipsec_sa_add_and_lock (a->local_sa_id, a->local_spi, IPSEC_PROTOCOL_ESP,
1925  a->encr_type, &a->loc_ckey, a->integ_type,
1926  &a->loc_ikey, a->flags, a->salt_local,
1927  a->src_port, a->dst_port, &tun_out, NULL);
1928  if (rv)
1929  goto err0;
1930 
1932  a->remote_sa_id, a->remote_spi, IPSEC_PROTOCOL_ESP, a->encr_type,
1933  &a->rem_ckey, a->integ_type, &a->rem_ikey,
1934  (a->flags | IPSEC_SA_FLAG_IS_INBOUND), a->salt_remote,
1935  a->ipsec_over_udp_port, a->ipsec_over_udp_port, &tun_in, NULL);
1936  if (rv)
1937  goto err1;
1938 
1939  rv = ipsec_tun_protect_update (sw_if_index, NULL, a->local_sa_id, sas_in);
1940  if (rv)
1941  goto err2;
1942 
1943  return;
1944 
1945 err2:
1946  ipsec_sa_unlock_id (a->remote_sa_id);
1947 err1:
1948  ipsec_sa_unlock_id (a->local_sa_id);
1949 err0:
1950  vec_free (sas_in);
1951 }
1952 
1953 static int
1955  ikev2_sa_t * sa,
1956  ikev2_child_sa_t * child, u32 sa_index,
1957  u32 child_index, u8 is_rekey)
1958 {
1960  ikev2_main_t *km = &ikev2_main;
1961  ipsec_crypto_alg_t encr_type;
1962  ipsec_integ_alg_t integ_type;
1963  ikev2_profile_t *p = 0;
1965  ikev2_sa_proposal_t *proposals;
1966  u8 is_aead = 0;
1968 
1969  clib_memset (&a, 0, sizeof (a));
1970 
1971  if (!child->r_proposals)
1972  {
1974  return 1;
1975  }
1976 
1977  if (sa->is_initiator)
1978  {
1979  ip_address_copy (&a.local_ip, &sa->iaddr);
1980  ip_address_copy (&a.remote_ip, &sa->raddr);
1981  proposals = child->r_proposals;
1982  a.local_spi = child->r_proposals[0].spi;
1983  a.remote_spi = child->i_proposals[0].spi;
1984  }
1985  else
1986  {
1987  ip_address_copy (&a.local_ip, &sa->raddr);
1988  ip_address_copy (&a.remote_ip, &sa->iaddr);
1989  proposals = child->i_proposals;
1990  a.local_spi = child->i_proposals[0].spi;
1991  a.remote_spi = child->r_proposals[0].spi;
1992  }
1993 
1994  a.flags = IPSEC_SA_FLAG_USE_ANTI_REPLAY;
1995  if (sa->udp_encap)
1996  {
1997  a.flags |= IPSEC_SA_FLAG_IS_TUNNEL;
1998  a.flags |= IPSEC_SA_FLAG_UDP_ENCAP;
1999  }
2000  if (ikev2_natt_active (sa))
2001  a.flags |= IPSEC_SA_FLAG_UDP_ENCAP;
2002  a.is_rekey = is_rekey;
2003 
2004  tr = ikev2_sa_get_td_for_type (proposals, IKEV2_TRANSFORM_TYPE_ESN);
2005  if (tr && tr->esn_type)
2006  a.flags |= IPSEC_SA_FLAG_USE_ESN;
2007 
2008  tr = ikev2_sa_get_td_for_type (proposals, IKEV2_TRANSFORM_TYPE_ENCR);
2009  if (tr)
2010  {
2011  if (tr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_CBC && tr->key_len)
2012  {
2013  switch (tr->key_len)
2014  {
2015  case 16:
2016  encr_type = IPSEC_CRYPTO_ALG_AES_CBC_128;
2017  break;
2018  case 24:
2019  encr_type = IPSEC_CRYPTO_ALG_AES_CBC_192;
2020  break;
2021  case 32:
2022  encr_type = IPSEC_CRYPTO_ALG_AES_CBC_256;
2023  break;
2024  default:
2026  return 1;
2027  break;
2028  }
2029  }
2030  else if (tr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_GCM_16
2031  && tr->key_len)
2032  {
2033  switch (tr->key_len)
2034  {
2035  case 16:
2036  encr_type = IPSEC_CRYPTO_ALG_AES_GCM_128;
2037  break;
2038  case 24:
2039  encr_type = IPSEC_CRYPTO_ALG_AES_GCM_192;
2040  break;
2041  case 32:
2042  encr_type = IPSEC_CRYPTO_ALG_AES_GCM_256;
2043  break;
2044  default:
2046  return 1;
2047  break;
2048  }
2049  is_aead = 1;
2050  }
2051  else
2052  {
2054  return 1;
2055  }
2056  }
2057  else
2058  {
2060  return 1;
2061  }
2062  a.encr_type = encr_type;
2063 
2064  if (!is_aead)
2065  {
2066  tr = ikev2_sa_get_td_for_type (proposals, IKEV2_TRANSFORM_TYPE_INTEG);
2067  if (tr)
2068  {
2069  switch (tr->integ_type)
2070  {
2071  case IKEV2_TRANSFORM_INTEG_TYPE_AUTH_HMAC_SHA2_256_128:
2072  integ_type = IPSEC_INTEG_ALG_SHA_256_128;
2073  break;
2074  case IKEV2_TRANSFORM_INTEG_TYPE_AUTH_HMAC_SHA2_384_192:
2075  integ_type = IPSEC_INTEG_ALG_SHA_384_192;
2076  break;
2077  case IKEV2_TRANSFORM_INTEG_TYPE_AUTH_HMAC_SHA2_512_256:
2078  integ_type = IPSEC_INTEG_ALG_SHA_512_256;
2079  break;
2080  case IKEV2_TRANSFORM_INTEG_TYPE_AUTH_HMAC_SHA1_96:
2081  integ_type = IPSEC_INTEG_ALG_SHA1_96;
2082  break;
2083  default:
2085  return 1;
2086  }
2087  }
2088  else
2089  {
2091  return 1;
2092  }
2093  }
2094  else
2095  {
2096  integ_type = IPSEC_INTEG_ALG_NONE;
2097  }
2098 
2099  a.integ_type = integ_type;
2100  ikev2_calc_child_keys (sa, child);
2101 
2102  if (sa->is_initiator)
2103  {
2104  ipsec_mk_key (&a.loc_ikey, child->sk_ai, vec_len (child->sk_ai));
2105  ipsec_mk_key (&a.rem_ikey, child->sk_ar, vec_len (child->sk_ar));
2106  ipsec_mk_key (&a.loc_ckey, child->sk_ei, vec_len (child->sk_ei));
2107  ipsec_mk_key (&a.rem_ckey, child->sk_er, vec_len (child->sk_er));
2108  if (is_aead)
2109  {
2110  a.salt_remote = child->salt_er;
2111  a.salt_local = child->salt_ei;
2112  }
2113  a.dst_port = a.src_port = sa->ipsec_over_udp_port;
2114  }
2115  else
2116  {
2117  ipsec_mk_key (&a.loc_ikey, child->sk_ar, vec_len (child->sk_ar));
2118  ipsec_mk_key (&a.rem_ikey, child->sk_ai, vec_len (child->sk_ai));
2119  ipsec_mk_key (&a.loc_ckey, child->sk_er, vec_len (child->sk_er));
2120  ipsec_mk_key (&a.rem_ckey, child->sk_ei, vec_len (child->sk_ei));
2121  if (is_aead)
2122  {
2123  a.salt_remote = child->salt_ei;
2124  a.salt_local = child->salt_er;
2125  }
2126  a.dst_port =
2128  a.src_port = sa->ipsec_over_udp_port;
2129  }
2130 
2131  if (sa->is_initiator && sa->profile_index != ~0)
2132  p = pool_elt_at_index (km->profiles, sa->profile_index);
2133 
2134  if (p && p->lifetime)
2135  {
2136  child->time_to_expiration = vlib_time_now (vm) + p->lifetime;
2137  if (p->lifetime_jitter)
2138  {
2139  // This is not much better than rand(3), which Coverity warns
2140  // is unsuitable for security applications; random_u32 is
2141  // however fast. If this perturbance to the expiration time
2142  // needs to use a better RNG then we may need to use something
2143  // like /dev/urandom which has significant overhead.
2144  u32 rnd = (u32) (vlib_time_now (vm) * 1e6);
2145  rnd = random_u32 (&rnd);
2146 
2147  child->time_to_expiration += 1 + (rnd % p->lifetime_jitter);
2148  }
2149  }
2150 
2151  if (thread_index & 0xffffffc0)
2152  ikev2_elog_error ("error: thread index exceeds max range 0x3f!");
2153 
2154  if (child_index & 0xfffff000 || sa_index & 0xfffff000)
2155  ikev2_elog_error ("error: sa/child index exceeds max range 0xfff!");
2156 
2157  child->local_sa_id =
2158  a.local_sa_id =
2159  ikev2_mk_local_sa_id (sa_index, child_index, thread_index);
2160 
2161  u32 remote_sa_id = ikev2_mk_remote_sa_id (sa_index, child_index,
2162  thread_index);
2163 
2164  if (is_rekey)
2165  {
2166  /* create a new remote SA ID to keep the old SA for a bit longer
2167  * so the peer has some time to swap their SAs */
2168 
2169  /* use most significat bit of child index part in id */
2170  u32 mask = 0x800;
2171  if (sa->current_remote_id_mask)
2172  {
2173  sa->old_remote_id = a.old_remote_sa_id = remote_sa_id | mask;
2174  sa->current_remote_id_mask = 0;
2175  }
2176  else
2177  {
2178  sa->old_remote_id = a.old_remote_sa_id = remote_sa_id;
2180  remote_sa_id |= mask;
2181  }
2182  sa->old_id_expiration = 3.0;
2183  sa->old_remote_id_present = 1;
2184  }
2185 
2186  child->remote_sa_id = a.remote_sa_id = remote_sa_id;
2187 
2188  a.sw_if_index = (sa->is_tun_itf_set ? sa->tun_itf : ~0);
2189  a.ipsec_over_udp_port = sa->ipsec_over_udp_port;
2190 
2192  (u8 *) & a, sizeof (a));
2193  return 0;
2194 }
2195 
2196 typedef struct
2197 {
2198  ip46_address_t local_ip;
2199  ip46_address_t remote_ip;
2204 
2207 {
2208  u32 mask = 0x800;
2209  if (mask & id)
2210  return id & ~mask;
2211  return id | mask;
2212 }
2213 
2214 static void
2216 {
2217  ikev2_main_t *km = &ikev2_main;
2218  ipip_tunnel_t *ipip = NULL;
2219  u32 sw_if_index;
2220 
2221  if (~0 == a->sw_if_index)
2222  {
2223  /* *INDENT-OFF* */
2224  ipip_tunnel_key_t key = {
2225  .src = a->local_ip,
2226  .dst = a->remote_ip,
2227  .transport = IPIP_TRANSPORT_IP4,
2228  .fib_index = 0,
2229  };
2230  /* *INDENT-ON* */
2231 
2232  ipip = ipip_tunnel_db_find (&key);
2233 
2234  if (ipip)
2235  {
2236  sw_if_index = ipip->sw_if_index;
2237  hash_unset (km->sw_if_indices, ipip->sw_if_index);
2238  }
2239  else
2240  sw_if_index = ~0;
2241  }
2242  else
2243  {
2244  sw_if_index = a->sw_if_index;
2246  }
2247 
2248  if (~0 != sw_if_index)
2250 
2251  ipsec_sa_unlock_id (a->remote_sa_id);
2252  ipsec_sa_unlock_id (a->local_sa_id);
2254 
2255  if (ipip)
2256  ipip_del_tunnel (ipip->sw_if_index);
2257 }
2258 
2259 static int
2261  ikev2_child_sa_t * child)
2262 {
2264 
2265  clib_memset (&a, 0, sizeof (a));
2266 
2267  if (sa->is_initiator)
2268  {
2269  ip_address_to_46 (&sa->iaddr, &a.local_ip);
2270  ip_address_to_46 (&sa->raddr, &a.remote_ip);
2271  }
2272  else
2273  {
2274  ip_address_to_46 (&sa->raddr, &a.local_ip);
2275  ip_address_to_46 (&sa->iaddr, &a.remote_ip);
2276  }
2277 
2278  a.remote_sa_id = child->remote_sa_id;
2279  a.local_sa_id = child->local_sa_id;
2280  a.sw_if_index = (sa->is_tun_itf_set ? sa->tun_itf : ~0);
2281 
2283  sizeof (a));
2284  return 0;
2285 }
2286 
2287 static u32
2289  void *user, udp_header_t *udp, ikev2_stats_t *stats)
2290 {
2291  ikev2_main_t *km = &ikev2_main;
2292  u16 buffer_data_size = vlib_buffer_get_default_data_size (km->vlib_main);
2293  v8 *integ = 0;
2294  ike_payload_header_t *ph;
2295  u16 plen;
2296  u32 tlen = 0;
2297 
2298  ikev2_sa_transform_t *tr_encr, *tr_integ;
2299  tr_encr =
2300  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
2301  tr_integ =
2302  ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
2303 
2304  ikev2_payload_chain_t *chain = 0;
2305  ikev2_payload_new_chain (chain);
2306 
2307  if (ike->exchange == IKEV2_EXCHANGE_SA_INIT)
2308  {
2309  if (sa->r_proposals == 0)
2310  {
2311  ikev2_payload_add_notify (chain,
2312  IKEV2_NOTIFY_MSG_NO_PROPOSAL_CHOSEN, 0);
2314  }
2315  else if (sa->dh_group == IKEV2_TRANSFORM_DH_TYPE_NONE)
2316  {
2317  u8 *data = vec_new (u8, 2);
2318  ikev2_sa_transform_t *tr_dh;
2319  tr_dh =
2321  IKEV2_TRANSFORM_TYPE_DH);
2322  ASSERT (tr_dh && tr_dh->dh_type);
2323 
2324  data[0] = (tr_dh->dh_type >> 8) & 0xff;
2325  data[1] = (tr_dh->dh_type) & 0xff;
2326 
2327  ikev2_payload_add_notify (chain,
2328  IKEV2_NOTIFY_MSG_INVALID_KE_PAYLOAD,
2329  data);
2330  vec_free (data);
2332  }
2333  else if (sa->state == IKEV2_STATE_NOTIFY_AND_DELETE)
2334  {
2335  u8 *data = vec_new (u8, 1);
2336 
2337  data[0] = sa->unsupported_cp;
2338  ikev2_payload_add_notify (chain,
2339  IKEV2_NOTIFY_MSG_UNSUPPORTED_CRITICAL_PAYLOAD,
2340  data);
2341  vec_free (data);
2342  }
2343  else
2344  {
2345  ASSERT (udp);
2346 
2347  ike->rspi = clib_host_to_net_u64 (sa->rspi);
2348  ikev2_payload_add_sa (chain, sa->r_proposals);
2349  ikev2_payload_add_ke (chain, sa->dh_group, sa->r_dh_data);
2350  ikev2_payload_add_nonce (chain, sa->r_nonce);
2351 
2352  u8 *nat_detection_sha1 =
2353  ikev2_compute_nat_sha1 (clib_host_to_net_u64 (sa->ispi),
2354  clib_host_to_net_u64 (sa->rspi),
2355  &sa->raddr, udp->dst_port);
2356  ikev2_payload_add_notify (chain,
2357  IKEV2_NOTIFY_MSG_NAT_DETECTION_SOURCE_IP,
2358  nat_detection_sha1);
2359  vec_free (nat_detection_sha1);
2360  nat_detection_sha1 =
2361  ikev2_compute_nat_sha1 (clib_host_to_net_u64 (sa->ispi),
2362  clib_host_to_net_u64 (sa->rspi),
2363  &sa->iaddr, udp->src_port);
2364  ikev2_payload_add_notify (chain,
2365  IKEV2_NOTIFY_MSG_NAT_DETECTION_DESTINATION_IP,
2366  nat_detection_sha1);
2367  vec_free (nat_detection_sha1);
2368  }
2369  }
2370  else if (ike->exchange == IKEV2_EXCHANGE_IKE_AUTH)
2371  {
2372  if (sa->state == IKEV2_STATE_AUTHENTICATED)
2373  {
2376  ikev2_payload_add_auth (chain, &sa->r_auth);
2377  ikev2_payload_add_sa (chain, sa->childs[0].r_proposals);
2380  }
2381  else if (sa->state == IKEV2_STATE_AUTH_FAILED)
2382  {
2383  ikev2_payload_add_notify (chain,
2384  IKEV2_NOTIFY_MSG_AUTHENTICATION_FAILED,
2385  0);
2387  }
2388  else if (sa->state == IKEV2_STATE_TS_UNACCEPTABLE)
2389  {
2390  ikev2_payload_add_notify (chain, IKEV2_NOTIFY_MSG_TS_UNACCEPTABLE,
2391  0);
2393  ikev2_payload_add_auth (chain, &sa->r_auth);
2394  }
2395  else if (sa->state == IKEV2_STATE_NO_PROPOSAL_CHOSEN)
2396  {
2397  ikev2_payload_add_notify (chain,
2398  IKEV2_NOTIFY_MSG_NO_PROPOSAL_CHOSEN, 0);
2400  ikev2_payload_add_auth (chain, &sa->r_auth);
2403  }
2404  else if (sa->state == IKEV2_STATE_NOTIFY_AND_DELETE)
2405  {
2406  u8 *data = vec_new (u8, 1);
2407 
2408  data[0] = sa->unsupported_cp;
2409  ikev2_payload_add_notify (chain,
2410  IKEV2_NOTIFY_MSG_UNSUPPORTED_CRITICAL_PAYLOAD,
2411  data);
2412  vec_free (data);
2413  }
2414  else if (sa->state == IKEV2_STATE_SA_INIT)
2415  {
2418  ikev2_payload_add_auth (chain, &sa->i_auth);
2419  ikev2_payload_add_sa (chain, sa->childs[0].i_proposals);
2422  ikev2_payload_add_notify (chain, IKEV2_NOTIFY_MSG_INITIAL_CONTACT,
2423  0);
2424  }
2425  else
2426  {
2427  ikev2_set_state (sa, IKEV2_STATE_DELETED, ": unexpected IKE_AUTH");
2428  goto done;
2429  }
2430  }
2431  else if (ike->exchange == IKEV2_EXCHANGE_INFORMATIONAL)
2432  {
2433  /* if pending delete */
2434  if (sa->del)
2435  {
2436  if (sa->del[0].protocol_id == IKEV2_PROTOCOL_IKE)
2437  {
2438  if (ike_hdr_is_request (ike))
2439  ikev2_payload_add_delete (chain, sa->del);
2440 
2441  /* The response to a request that deletes the IKE SA is an empty
2442  INFORMATIONAL response. */
2444  }
2445  /* The response to a request that deletes ESP or AH SAs will contain
2446  delete payloads for the paired SAs going in the other direction. */
2447  else
2448  {
2449  ikev2_payload_add_delete (chain, sa->del);
2450  }
2451  vec_free (sa->del);
2452  sa->del = 0;
2453  }
2454  /* received N(AUTHENTICATION_FAILED) */
2455  else if (sa->state == IKEV2_STATE_AUTH_FAILED)
2456  {
2457  ikev2_set_state (sa, IKEV2_STATE_DELETED, ": auth failed");
2458  goto done;
2459  }
2460  /* received unsupported critical payload */
2461  else if (sa->unsupported_cp)
2462  {
2463  u8 *data = vec_new (u8, 1);
2464 
2465  data[0] = sa->unsupported_cp;
2466  ikev2_payload_add_notify (chain,
2467  IKEV2_NOTIFY_MSG_UNSUPPORTED_CRITICAL_PAYLOAD,
2468  data);
2469  vec_free (data);
2470  sa->unsupported_cp = 0;
2471  }
2472  else
2473  /* else send empty response */
2474  {
2475  if (ike_hdr_is_response (ike))
2476  {
2477  ASSERT (stats != 0);
2478  stats->n_keepalives++;
2479  sa->stats.n_keepalives++;
2480  }
2481  }
2482  }
2483  else if (ike->exchange == IKEV2_EXCHANGE_CREATE_CHILD_SA)
2484  {
2485  if (sa->is_initiator)
2486  {
2487 
2488  ikev2_sa_proposal_t *proposals = (ikev2_sa_proposal_t *) user;
2489  ikev2_notify_t notify;
2490  u8 *data = vec_new (u8, 4);
2491  clib_memset (&notify, 0, sizeof (notify));
2493  notify.spi = sa->childs[0].i_proposals->spi;
2494  *(u32 *) data = clib_host_to_net_u32 (notify.spi);
2495 
2496  ikev2_payload_add_sa (chain, proposals);
2497  ikev2_payload_add_nonce (chain, sa->i_nonce);
2500  ikev2_payload_add_notify_2 (chain, IKEV2_NOTIFY_MSG_REKEY_SA, data,
2501  &notify);
2502 
2503  vec_free (data);
2504  }
2505  else if (vec_len (sa->rekey) > 0)
2506  {
2507  ikev2_payload_add_sa (chain, sa->rekey[0].r_proposal);
2508  ikev2_payload_add_nonce (chain, sa->r_nonce);
2511  vec_del1 (sa->rekey, 0);
2512  }
2513  else if (vec_len (sa->new_child) > 0)
2514  {
2515  ikev2_payload_add_sa (chain, sa->new_child[0].r_proposal);
2516  ikev2_payload_add_nonce (chain, sa->r_nonce);
2517  ikev2_payload_add_ts (chain, sa->new_child[0].tsi,
2519  ikev2_payload_add_ts (chain, sa->new_child[0].tsr,
2521  vec_del1 (sa->new_child, 0);
2522  }
2523  else if (sa->unsupported_cp)
2524  {
2525  u8 *data = vec_new (u8, 1);
2526 
2527  data[0] = sa->unsupported_cp;
2529  chain, IKEV2_NOTIFY_MSG_UNSUPPORTED_CRITICAL_PAYLOAD, data);
2530  vec_free (data);
2531  sa->unsupported_cp = 0;
2532  }
2533  else
2534  {
2535  ikev2_payload_add_notify (chain, IKEV2_NOTIFY_MSG_NO_ADDITIONAL_SAS,
2536  0);
2537  }
2538  }
2539 
2540  /* IKEv2 header */
2541  ike->version = IKE_VERSION_2;
2542  ike->nextpayload = IKEV2_PAYLOAD_SK;
2543  tlen = sizeof (*ike);
2544 
2545  if (sa->is_initiator)
2546  ike->flags |= IKEV2_HDR_FLAG_INITIATOR;
2547 
2548  if (ike->exchange == IKEV2_EXCHANGE_SA_INIT)
2549  {
2550  tlen += vec_len (chain->data);
2551  ike->nextpayload = chain->first_payload_type;
2552  ike->length = clib_host_to_net_u32 (tlen);
2553 
2554  if (tlen + b->current_length + b->current_data > buffer_data_size)
2555  {
2556  tlen = ~0;
2557  goto done;
2558  }
2559 
2560  clib_memcpy_fast (ike->payload, chain->data, vec_len (chain->data));
2561 
2562  /* store whole IKE payload - needed for PSK auth */
2565  }
2566  else
2567  {
2569  ikev2_payload_chain_add_padding (chain, tr_encr->block_size);
2570 
2571  /* SK payload */
2572  plen = sizeof (*ph);
2573  ph = (ike_payload_header_t *) & ike->payload[0];
2574  ph->nextpayload = chain->first_payload_type;
2575  ph->flags = 0;
2576  int is_aead =
2577  tr_encr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_GCM_16;
2578  int iv_len = is_aead ? IKEV2_GCM_IV_SIZE : tr_encr->block_size;
2579  plen += vec_len (chain->data) + iv_len;
2580 
2581  /* add space for hmac/tag */
2582  if (tr_integ)
2583  plen += tr_integ->key_trunc;
2584  else
2585  plen += IKEV2_GCM_ICV_SIZE;
2586  tlen += plen;
2587 
2588  if (tlen + b->current_length + b->current_data > buffer_data_size)
2589  {
2590  tlen = ~0;
2591  goto done;
2592  }
2593 
2594  /* payload and total length */
2595  ph->length = clib_host_to_net_u16 (plen);
2596  ike->length = clib_host_to_net_u32 (tlen);
2597 
2598  if (is_aead)
2599  {
2600  if (!ikev2_encrypt_aead_data (ptd, sa, tr_encr, chain->data,
2601  ph->payload, (u8 *) ike,
2602  sizeof (*ike) + sizeof (*ph),
2603  ph->payload + plen - sizeof (*ph) -
2605  {
2606  tlen = ~0;
2607  goto done;
2608  }
2609  }
2610  else
2611  {
2612  if (!ikev2_encrypt_data
2613  (ptd, sa, tr_encr, chain->data, ph->payload))
2614  {
2615  tlen = ~0;
2616  goto done;
2617  }
2618  integ =
2619  ikev2_calc_integr (tr_integ,
2620  sa->is_initiator ? sa->sk_ai : sa->sk_ar,
2621  (u8 *) ike, tlen - tr_integ->key_trunc);
2622  clib_memcpy_fast (ike->payload + tlen - tr_integ->key_trunc -
2623  sizeof (*ike), integ, tr_integ->key_trunc);
2624  }
2625 
2626  /* store whole IKE payload - needed for retransmit */
2628  vec_add (sa->last_res_packet_data, ike, tlen);
2629  }
2630 
2631 done:
2633  vec_free (integ);
2634  return tlen;
2635 }
2636 
2637 static u32
2640  u32 rlen)
2641 {
2642  int p = 0;
2643  ike_header_t *tmp;
2644  u8 payload = ike->nextpayload;
2645 
2646  if (sa->ispi != clib_net_to_host_u64 (ike->ispi) ||
2647  ip_address_cmp (&sa->iaddr, &iaddr) ||
2648  ip_address_cmp (&sa->raddr, &raddr))
2649  {
2650  return 0;
2651  }
2652 
2653  while (p < rlen && payload != IKEV2_PAYLOAD_NONE)
2654  {
2655  ike_payload_header_t *ikep = (ike_payload_header_t *) & ike->payload[p];
2656  u32 plen = clib_net_to_host_u16 (ikep->length);
2657 
2658  if (plen < sizeof (ike_payload_header_t))
2659  return ~0;
2660 
2661  if (payload == IKEV2_PAYLOAD_NONCE &&
2662  !clib_memcmp (sa->i_nonce, ikep->payload, plen - sizeof (*ikep)))
2663  {
2664  /* req is retransmit */
2665  if (sa->state == IKEV2_STATE_SA_INIT)
2666  {
2667  sa->stats.n_init_retransmit++;
2668  tmp = (ike_header_t *) sa->last_sa_init_res_packet_data;
2669  u32 slen = clib_net_to_host_u32 (tmp->length);
2670  ike->ispi = tmp->ispi;
2671  ike->rspi = tmp->rspi;
2672  ike->nextpayload = tmp->nextpayload;
2673  ike->version = tmp->version;
2674  ike->exchange = tmp->exchange;
2675  ike->flags = tmp->flags;
2676  ike->msgid = tmp->msgid;
2677  ike->length = tmp->length;
2678  clib_memcpy_fast (ike->payload, tmp->payload,
2679  slen - sizeof (*ike));
2680  ikev2_elog_uint_peers (IKEV2_LOG_DEBUG,
2681  "ispi %lx IKE_SA_INIT retransmit "
2682  "from %d.%d.%d.%d to %d.%d.%d.%d",
2683  ike->ispi,
2684  ip_addr_v4 (&raddr).as_u32,
2685  ip_addr_v4 (&iaddr).as_u32);
2686  return slen;
2687  }
2688  /* else ignore req */
2689  else
2690  {
2691  ikev2_elog_uint_peers (IKEV2_LOG_DEBUG,
2692  "ispi %lx IKE_SA_INIT ignore "
2693  "from %d.%d.%d.%d to %d.%d.%d.%d",
2694  ike->ispi,
2695  ip_addr_v4 (&raddr).as_u32,
2696  ip_addr_v4 (&iaddr).as_u32);
2697  return ~0;
2698  }
2699  }
2700  payload = ikep->nextpayload;
2701  p += plen;
2702  }
2703 
2704  return 0;
2705 }
2706 
2707 static u32
2709  ip_address_t raddr, u32 rlen)
2710 {
2711  ikev2_sa_t *sa;
2712  u32 res;
2714 
2715  /* *INDENT-OFF* */
2716  pool_foreach (sa, ptd->sas) {
2717  res = ikev2_retransmit_sa_init_one (sa, ike, iaddr, raddr, rlen);
2718  if (res)
2719  return res;
2720  }
2721  /* *INDENT-ON* */
2722 
2723  /* req is not retransmit */
2724  return 0;
2725 }
2726 
2727 static u32
2728 ikev2_retransmit_resp (ikev2_sa_t * sa, ike_header_t * ike)
2729 {
2730  if (ike_hdr_is_response (ike))
2731  return 0;
2732 
2733  u32 msg_id = clib_net_to_host_u32 (ike->msgid);
2734 
2735  /* new req */
2736  if (msg_id > sa->last_msg_id || sa->last_msg_id == ~0)
2737  {
2738  sa->last_msg_id = msg_id;
2739  return 0;
2740  }
2741 
2742  /* retransmitted req */
2743  if (msg_id == sa->last_msg_id)
2744  {
2745  sa->stats.n_retransmit++;
2746  ike_header_t *tmp = (ike_header_t *) sa->last_res_packet_data;
2747  u32 slen = clib_net_to_host_u32 (tmp->length);
2748  ike->ispi = tmp->ispi;
2749  ike->rspi = tmp->rspi;
2750  ike->nextpayload = tmp->nextpayload;
2751  ike->version = tmp->version;
2752  ike->exchange = tmp->exchange;
2753  ike->flags = tmp->flags;
2754  ike->msgid = tmp->msgid;
2755  ike->length = tmp->length;
2756  clib_memcpy_fast (ike->payload, tmp->payload, slen - sizeof (*ike));
2757  ikev2_elog_uint_peers (IKEV2_LOG_DEBUG, "IKE retransmit msgid %d",
2758  msg_id, ip_addr_v4 (&sa->raddr).as_u32,
2759  ip_addr_v4 (&sa->iaddr).as_u32);
2760  return slen;
2761  }
2762 
2763  /* old req ignore */
2764  ikev2_elog_uint_peers (IKEV2_LOG_DEBUG, "IKE req ignore msgid %d",
2765  msg_id, ip_addr_v4 (&sa->raddr).as_u32,
2766  ip_addr_v4 (&sa->iaddr).as_u32);
2767  return ~0;
2768 }
2769 
2770 static void
2772 {
2773  ikev2_main_t *km = &ikev2_main;
2775  sa->profile_index = ~0;
2776 }
2777 
2778 static void
2780 {
2781  ikev2_main_t *km = &ikev2_main;
2782  uword *p = hash_get (km->sa_by_ispi, *ispi);
2783  if (p)
2784  {
2785  ikev2_sa_t *sai = pool_elt_at_index (km->sais, p[0]);
2786  hash_unset (km->sa_by_ispi, sai->ispi);
2787  ikev2_sa_free_all_vec (sai);
2788  pool_put (km->sais, sai);
2789  }
2790 }
2791 
2792 static void
2794 {
2796  sizeof (ispi));
2797 }
2798 
2801 {
2802  if (sa->is_initiator)
2803  {
2804  ip_address_copy_addr (&ih->dst_address, &sa->raddr);
2805  ip_address_copy_addr (&ih->src_address, &sa->iaddr);
2806  }
2807  else
2808  {
2809  ip_address_copy_addr (&ih->dst_address, &sa->iaddr);
2810  ip_address_copy_addr (&ih->src_address, &sa->raddr);
2811  }
2812 }
2813 
2816 {
2817  if (sa->is_initiator)
2818  {
2819  ip_address_copy_addr (&ih->dst_address, &sa->raddr);
2820  ip_address_copy_addr (&ih->src_address, &sa->iaddr);
2821  }
2822  else
2823  {
2824  ip_address_copy_addr (&ih->dst_address, &sa->iaddr);
2825  ip_address_copy_addr (&ih->src_address, &sa->raddr);
2826  }
2827 }
2828 
2830 ikev2_set_ip_address (ikev2_sa_t *sa, const void *iaddr, const void *raddr,
2831  const ip_address_family_t af)
2832 {
2833  ip_address_set (&sa->raddr, raddr, af);
2834  ip_address_set (&sa->iaddr, iaddr, af);
2835 }
2836 
2837 static void
2839  ip6_header_t * ip6, u8 is_ip4)
2840 {
2841  u32 src, dst;
2842  if (is_ip4)
2843  {
2844  src = ip4->src_address.as_u32;
2845  dst = ip4->dst_address.as_u32;
2846  }
2847  else
2848  {
2849  src = ip6->src_address.as_u32[3];
2850  dst = ip6->dst_address.as_u32[3];
2851  }
2852  ikev2_elog_uint_peers (IKEV2_LOG_WARNING, "IKEv2 exchange %d "
2853  "received from %d.%d.%d.%d to %d.%d.%d.%d",
2854  exchange, src, dst);
2855 }
2856 
2857 static void
2859 {
2861 
2863  return;
2864 
2869 }
2870 
2871 static void
2873 {
2874  vlib_node_increment_counter (vm, node_index, IKEV2_ERROR_KEEPALIVE,
2875  s->n_keepalives);
2876  vlib_node_increment_counter (vm, node_index, IKEV2_ERROR_REKEY_REQ,
2877  s->n_rekey_req);
2878  vlib_node_increment_counter (vm, node_index, IKEV2_ERROR_INIT_SA_REQ,
2879  s->n_sa_init_req);
2880  vlib_node_increment_counter (vm, node_index, IKEV2_ERROR_IKE_AUTH_REQ,
2881  s->n_sa_auth_req);
2882 }
2883 
2886  vlib_frame_t *frame, u8 is_ip4, u8 natt)
2887 {
2888  u32 n_left = frame->n_vectors, *from;
2889  ikev2_main_t *km = &ikev2_main;
2893  ikev2_stats_t _stats, *stats = &_stats;
2894  int res;
2895 
2896  /* no NAT traversal for ip6 */
2897  ASSERT (!natt || is_ip4);
2898 
2899  clib_memset_u16 (stats, 0, sizeof (stats[0]) / sizeof (u16));
2902  b = bufs;
2903 
2904  while (n_left > 0)
2905  {
2906  vlib_buffer_t *b0 = b[0];
2907  next[0] = is_ip4 ? IKEV2_NEXT_IP4_ERROR_DROP
2909  ip4_header_t *ip40 = 0;
2910  ip6_header_t *ip60 = 0;
2911  udp_header_t *udp0;
2912  ike_header_t *ike0;
2913  ikev2_sa_t *sa0 = 0;
2914  ikev2_sa_t sa; /* temporary store for SA */
2915  u32 rlen, slen = 0;
2916  int ip_hdr_sz = 0;
2917  int is_req = 0;
2918 
2919  if (natt)
2920  {
2921  u8 *ptr = vlib_buffer_get_current (b0);
2922  ip40 = (ip4_header_t *) ptr;
2923  ptr += sizeof (*ip40);
2924  udp0 = (udp_header_t *) ptr;
2925  ptr += sizeof (*udp0);
2926  ike0 = (ike_header_t *) ptr;
2927  ip_hdr_sz = sizeof (*ip40);
2928  }
2929  else
2930  {
2931  u8 *ipx_hdr = b0->data + vnet_buffer (b0)->l3_hdr_offset;
2932  ike0 = vlib_buffer_get_current (b0);
2933  vlib_buffer_advance (b0, -sizeof (*udp0));
2934  udp0 = vlib_buffer_get_current (b0);
2935 
2936  if (is_ip4)
2937  {
2938  ip40 = (ip4_header_t *) ipx_hdr;
2939  ip_hdr_sz = sizeof (*ip40);
2940  }
2941  else
2942  {
2943  ip60 = (ip6_header_t *) ipx_hdr;
2944  ip_hdr_sz = sizeof (*ip60);
2945  }
2946  vlib_buffer_advance (b0, -ip_hdr_sz);
2947  }
2948 
2949  rlen = b0->current_length - ip_hdr_sz - sizeof (*udp0);
2950 
2951  /* check for non-esp marker */
2952  if (natt)
2953  {
2954  ASSERT (*((u32 *) ike0) == 0);
2955  ike0 =
2956  (ike_header_t *) ((u8 *) ike0 + sizeof (ikev2_non_esp_marker));
2957  rlen -= sizeof (ikev2_non_esp_marker);
2958  }
2959 
2960  if (clib_net_to_host_u32 (ike0->length) != rlen)
2961  {
2962  vlib_node_increment_counter (vm, node->node_index,
2963  IKEV2_ERROR_BAD_LENGTH, 1);
2964  goto dispatch0;
2965  }
2966 
2967  if (ike0->version != IKE_VERSION_2)
2968  {
2969  vlib_node_increment_counter (vm, node->node_index,
2970  IKEV2_ERROR_NOT_IKEV2, 1);
2971  goto dispatch0;
2972  }
2973 
2974  if (ike0->exchange == IKEV2_EXCHANGE_SA_INIT)
2975  {
2976  sa0 = &sa;
2977  clib_memset (sa0, 0, sizeof (*sa0));
2978 
2979  if (ike_hdr_is_initiator (ike0))
2980  {
2981  sa0->stats.n_sa_init_req++;
2982  stats->n_sa_init_req++;
2983  if (ike0->rspi == 0)
2984  {
2985  if (is_ip4)
2986  ikev2_set_ip_address (sa0, &ip40->src_address,
2987  &ip40->dst_address, AF_IP4);
2988  else
2989  ikev2_set_ip_address (sa0, &ip60->src_address,
2990  &ip60->dst_address, AF_IP6);
2991 
2992  sa0->dst_port = clib_net_to_host_u16 (udp0->src_port);
2993 
2994  slen =
2995  ikev2_retransmit_sa_init (ike0, sa0->iaddr,
2996  sa0->raddr, rlen);
2997  if (slen)
2998  {
2999  vlib_node_increment_counter (vm, node->node_index,
3000  ~0 ==
3001  slen ?
3002  IKEV2_ERROR_IKE_SA_INIT_IGNORE
3003  :
3004  IKEV2_ERROR_IKE_SA_INIT_RETRANSMIT,
3005  1);
3006  goto dispatch0;
3007  }
3008 
3010  vm, sa0, ike0, udp0, rlen,
3012  if (!res)
3013  vlib_node_increment_counter (vm, node->node_index,
3014  IKEV2_ERROR_MALFORMED_PACKET,
3015  1);
3016 
3017  if (sa0->state == IKEV2_STATE_SA_INIT)
3018  {
3020  sa0->r_proposals =
3024  }
3025 
3026  if (sa0->state == IKEV2_STATE_SA_INIT
3028  {
3029  ike0->flags = IKEV2_HDR_FLAG_RESPONSE;
3030  slen =
3031  ikev2_generate_message (b0, sa0, ike0, 0, udp0, stats);
3032  if (~0 == slen)
3033  vlib_node_increment_counter (vm, node->node_index,
3034  IKEV2_ERROR_NO_BUFF_SPACE,
3035  1);
3036  }
3037 
3038  if (sa0->state == IKEV2_STATE_SA_INIT)
3039  {
3040  /* add SA to the pool */
3041  pool_get (ptd->sas, sa0);
3042  clib_memcpy_fast (sa0, &sa, sizeof (*sa0));
3043  ikev2_init_sa (vm, sa0);
3044  hash_set (ptd->sa_by_rspi, sa0->rspi, sa0 - ptd->sas);
3045  }
3046  else
3047  {
3048  ikev2_sa_free_all_vec (sa0);
3049  }
3050  }
3051  }
3052  else //received sa_init without initiator flag
3053  {
3054  if (is_ip4)
3055  ikev2_set_ip_address (sa0, &ip40->dst_address,
3056  &ip40->src_address, AF_IP4);
3057  else
3058  ikev2_set_ip_address (sa0, &ip60->dst_address,
3059  &ip60->src_address, AF_IP6);
3060 
3061  ikev2_process_sa_init_resp (vm, sa0, ike0, udp0, rlen);
3062 
3063  if (sa0->state == IKEV2_STATE_SA_INIT)
3064  {
3065  is_req = 1;
3066  ike0->exchange = IKEV2_EXCHANGE_IKE_AUTH;
3067  uword *p = hash_get (km->sa_by_ispi, sa0->ispi);
3068  if (p)
3069  {
3070  ikev2_sa_t *sai = pool_elt_at_index (km->sais, p[0]);
3071 
3073  (&sai->init_response_received, 0, 1))
3074  {
3075  ikev2_complete_sa_data (sa0, sai);
3076  ikev2_calc_keys (sa0);
3077  ikev2_sa_auth_init (sa0);
3078  ike0->flags = IKEV2_HDR_FLAG_INITIATOR;
3079  ike0->msgid =
3080  clib_net_to_host_u32 (sai->last_init_msg_id);
3081  sa0->last_init_msg_id = sai->last_init_msg_id + 1;
3082  slen = ikev2_generate_message (b0, sa0, ike0, 0,
3083  udp0, stats);
3084  if (~0 == slen)
3086  node->node_index,
3087  IKEV2_ERROR_NO_BUFF_SPACE,
3088  1);
3089  }
3090  else
3091  {
3092  /* we've already processed sa-init response */
3093  sa0->state = IKEV2_STATE_UNKNOWN;
3094  }
3095  }
3096  }
3097 
3098  if (sa0->state == IKEV2_STATE_SA_INIT)
3099  {
3100  /* add SA to the pool */
3101  pool_get (ptd->sas, sa0);
3102  clib_memcpy_fast (sa0, &sa, sizeof (*sa0));
3103  hash_set (ptd->sa_by_rspi, sa0->rspi, sa0 - ptd->sas);
3104  }
3105  else
3106  {
3107  ikev2_sa_free_all_vec (sa0);
3108  }
3109  }
3110  }
3111  else if (ike0->exchange == IKEV2_EXCHANGE_IKE_AUTH)
3112  {
3113  uword *p;
3114  p = hash_get (ptd->sa_by_rspi, clib_net_to_host_u64 (ike0->rspi));
3115  if (p)
3116  {
3117  sa0 = pool_elt_at_index (ptd->sas, p[0]);
3118  slen = ikev2_retransmit_resp (sa0, ike0);
3119  if (slen)
3120  {
3121  vlib_node_increment_counter (vm, node->node_index,
3122  ~0 ==
3123  slen ?
3124  IKEV2_ERROR_IKE_REQ_IGNORE
3125  :
3126  IKEV2_ERROR_IKE_REQ_RETRANSMIT,
3127  1);
3128  goto dispatch0;
3129  }
3130 
3131  sa0->dst_port = clib_net_to_host_u16 (udp0->src_port);
3132  res = ikev2_process_auth_req (vm, sa0, ike0, rlen);
3133  if (res)
3134  ikev2_sa_auth (sa0);
3135  else
3136  vlib_node_increment_counter (vm, node->node_index,
3137  IKEV2_ERROR_MALFORMED_PACKET, 1);
3138  if (sa0->state == IKEV2_STATE_AUTHENTICATED)
3139  {
3140  ikev2_initial_contact_cleanup (ptd, sa0);
3141  ikev2_sa_match_ts (sa0);
3142  if (sa0->state != IKEV2_STATE_TS_UNACCEPTABLE)
3144  &sa0->childs[0],
3145  p[0], 0, 0);
3146  }
3147 
3148  if (sa0->is_initiator)
3149  {
3150  sa0->last_msg_id = ~0;
3151  ikev2_del_sa_init (sa0->ispi);
3152  }
3153  else
3154  {
3155  sa0->stats.n_sa_auth_req++;
3156  stats->n_sa_auth_req++;
3157  ike0->flags = IKEV2_HDR_FLAG_RESPONSE;
3158  slen =
3159  ikev2_generate_message (b0, sa0, ike0, 0, udp0, stats);
3160  if (~0 == slen)
3161  vlib_node_increment_counter (vm, node->node_index,
3162  IKEV2_ERROR_NO_BUFF_SPACE,
3163  1);
3164  }
3165  }
3166  }
3167  else if (ike0->exchange == IKEV2_EXCHANGE_INFORMATIONAL)
3168  {
3169  uword *p;
3170  p = hash_get (ptd->sa_by_rspi, clib_net_to_host_u64 (ike0->rspi));
3171  if (p)
3172  {
3173  sa0 = pool_elt_at_index (ptd->sas, p[0]);
3174  slen = ikev2_retransmit_resp (sa0, ike0);
3175  if (slen)
3176  {
3177  vlib_node_increment_counter (vm, node->node_index,
3178  ~0 ==
3179  slen ?
3180  IKEV2_ERROR_IKE_REQ_IGNORE
3181  :
3182  IKEV2_ERROR_IKE_REQ_RETRANSMIT,
3183  1);
3184  goto dispatch0;
3185  }
3186 
3187  res = ikev2_process_informational_req (vm, sa0, ike0, rlen);
3188  if (!res)
3189  {
3190  vlib_node_increment_counter (vm, node->node_index,
3191  IKEV2_ERROR_MALFORMED_PACKET,
3192  1);
3193  slen = ~0;
3194  goto dispatch0;
3195  }
3196 
3197  if (sa0->del)
3198  {
3199  if (sa0->del[0].protocol_id != IKEV2_PROTOCOL_IKE)
3200  {
3201  ikev2_delete_t *d, *tmp, *resp = 0;
3202  vec_foreach (d, sa0->del)
3203  {
3204  ikev2_child_sa_t *ch_sa;
3205  ch_sa = ikev2_sa_get_child (sa0, d->spi,
3206  d->protocol_id,
3207  !sa0->is_initiator);
3208  if (ch_sa)
3209  {
3211  sa0, ch_sa);
3212  if (!sa0->is_initiator)
3213  {
3214  vec_add2 (resp, tmp, 1);
3215  tmp->protocol_id = d->protocol_id;
3216  tmp->spi = ch_sa->r_proposals[0].spi;
3217  }
3218  ikev2_sa_del_child_sa (sa0, ch_sa);
3219  }
3220  }
3221  if (!sa0->is_initiator)
3222  {
3223  vec_free (sa0->del);
3224  sa0->del = resp;
3225  }
3226  }
3227  }
3228  if (ike_hdr_is_request (ike0))
3229  {
3230  ike0->flags = IKEV2_HDR_FLAG_RESPONSE;
3231  slen =
3232  ikev2_generate_message (b0, sa0, ike0, 0, udp0, stats);
3233  if (~0 == slen)
3234  vlib_node_increment_counter (vm, node->node_index,
3235  IKEV2_ERROR_NO_BUFF_SPACE,
3236  1);
3237  }
3238  }
3239  }
3240  else if (ike0->exchange == IKEV2_EXCHANGE_CREATE_CHILD_SA)
3241  {
3242  uword *p;
3243  p = hash_get (ptd->sa_by_rspi, clib_net_to_host_u64 (ike0->rspi));
3244  if (p)
3245  {
3246  sa0 = pool_elt_at_index (ptd->sas, p[0]);
3247  slen = ikev2_retransmit_resp (sa0, ike0);
3248  if (slen)
3249  {
3250  vlib_node_increment_counter (vm, node->node_index,
3251  ~0 ==
3252  slen ?
3253  IKEV2_ERROR_IKE_REQ_IGNORE
3254  :
3255  IKEV2_ERROR_IKE_REQ_RETRANSMIT,
3256  1);
3257  goto dispatch0;
3258  }
3259 
3260  res = ikev2_process_create_child_sa_req (vm, sa0, ike0, rlen);
3261  if (!res)
3262  {
3263  vlib_node_increment_counter (vm, node->node_index,
3264  IKEV2_ERROR_MALFORMED_PACKET,
3265  1);
3266  slen = ~0;
3267  goto dispatch0;
3268  }
3269 
3270  if (sa0->rekey)
3271  {
3272  if (sa0->rekey[0].protocol_id != IKEV2_PROTOCOL_IKE)
3273  {
3274  if (sa0->childs)
3276  ikev2_child_sa_t *child;
3277  vec_add2 (sa0->childs, child, 1);
3278  clib_memset (child, 0, sizeof (*child));
3279  child->r_proposals = sa0->rekey[0].r_proposal;
3280  child->i_proposals = sa0->rekey[0].i_proposal;
3281  child->tsi = sa0->rekey[0].tsi;
3282  child->tsr = sa0->rekey[0].tsr;
3283  ikev2_create_tunnel_interface (vm, sa0, child, p[0],
3284  child - sa0->childs, 1);
3285  }
3286  if (ike_hdr_is_response (ike0))
3287  {
3288  vec_free (sa0->rekey);
3289  }
3290  else
3291  {
3292  stats->n_rekey_req++;
3293  sa0->stats.n_rekey_req++;
3294  ike0->flags = IKEV2_HDR_FLAG_RESPONSE;
3295  slen =
3296  ikev2_generate_message (b0, sa0, ike0, 0, udp0, stats);
3297  if (~0 == slen)
3298  vlib_node_increment_counter (vm, node->node_index,
3299  IKEV2_ERROR_NO_BUFF_SPACE,
3300  1);
3301  }
3302  }
3303  else if (sa0->new_child)
3304  {
3306  vec_add2 (sa0->childs, c, 1);
3307  memset (c, 0, sizeof (*c));
3308  c->r_proposals = sa0->new_child[0].r_proposal;
3309  c->i_proposals = sa0->new_child[0].i_proposal;
3310  c->tsi = sa0->new_child[0].tsi;
3311  c->tsr = sa0->new_child[0].tsr;
3312  ikev2_create_tunnel_interface (vm, sa0, c, p[0],
3313  c - sa0->childs, 0);
3314  if (ike_hdr_is_request (ike0))
3315  {
3316  ike0->flags = IKEV2_HDR_FLAG_RESPONSE;
3317  slen =
3318  ikev2_generate_message (b0, sa0, ike0, 0, udp0, 0);
3319  if (~0 == slen)
3321  vm, node->node_index, IKEV2_ERROR_NO_BUFF_SPACE, 1);
3322  }
3323  }
3324  }
3325  }
3326  else
3327  {
3328  ikev2_elog_uint_peers_addr (ike0->exchange, ip40, ip60, is_ip4);
3329  }
3330 
3331  dispatch0:
3332  /* if we are sending packet back, rewrite headers */
3333  if (slen && ~0 != slen)
3334  {
3335  if (is_ip4)
3336  {
3338  ikev2_rewrite_v4_addrs (sa0, ip40);
3339  }
3340  else
3341  {
3343  ikev2_rewrite_v6_addrs (sa0, ip60);
3344  }
3345 
3346  if (is_req)
3347  {
3348  udp0->dst_port = udp0->src_port =
3349  clib_net_to_host_u16 (ikev2_get_port (sa0));
3350 
3351  if (udp0->dst_port == clib_net_to_host_u16 (IKEV2_PORT_NATT)
3352  && ikev2_natt_active (sa0))
3353  {
3354  if (!natt)
3355  slen = ikev2_insert_non_esp_marker (ike0, slen);
3356  }
3357  }
3358  else
3359  {
3360  if (natt)
3361  slen += sizeof (ikev2_non_esp_marker);
3362 
3363  u16 tp = udp0->dst_port;
3364  udp0->dst_port = udp0->src_port;
3365  udp0->src_port = tp;
3366  }
3367 
3368  udp0->length = clib_host_to_net_u16 (slen + sizeof (udp_header_t));
3369  udp0->checksum = 0;
3370  b0->current_length = slen + ip_hdr_sz + sizeof (udp_header_t);
3371  if (is_ip4)
3372  {
3373  ip40->length = clib_host_to_net_u16 (b0->current_length);
3374  ip40->checksum = ip4_header_checksum (ip40);
3375  }
3376  else
3377  {
3378  ip60->payload_length =
3379  clib_host_to_net_u16 (b0->current_length - sizeof (*ip60));
3380  }
3381  }
3382  /* delete sa */
3383  if (sa0 && (sa0->state == IKEV2_STATE_DELETED ||
3385  {
3387 
3388  vec_foreach (c, sa0->childs)
3390 
3391  ikev2_delete_sa (ptd, sa0);
3392  }
3393  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
3394  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
3395  {
3396 
3397  ikev2_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
3398  t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
3399  t->next_index = next[0];
3400  }
3401  n_left -= 1;
3402  next += 1;
3403  b += 1;
3404  }
3405 
3406  ikev2_update_stats (vm, node->node_index, stats);
3407  vlib_node_increment_counter (vm, node->node_index,
3408  IKEV2_ERROR_PROCESSED, frame->n_vectors);
3410  return frame->n_vectors;
3411 }
3412 
3413 static uword
3415 {
3416  return ikev2_node_internal (vm, node, frame, 1 /* is_ip4 */, 0);
3417 }
3418 
3419 static uword
3422 {
3423  return ikev2_node_internal (vm, node, frame, 1 /* is_ip4 */, 1 /* natt */);
3424 }
3425 
3426 static uword
3428 {
3429  return ikev2_node_internal (vm, node, frame, 0 /* is_ip4 */, 0);
3430 }
3431 
3432 /* *INDENT-OFF* */
3434  .function = ikev2_ip4,
3435  .name = "ikev2-ip4",
3436  .vector_size = sizeof (u32),
3437  .format_trace = format_ikev2_trace,
3439 
3440  .n_errors = IKEV2_N_ERROR,
3441  .error_counters = ikev2_error_counters,
3442 
3443  .n_next_nodes = IKEV2_IP4_N_NEXT,
3444  .next_nodes = {
3445  [IKEV2_NEXT_IP4_LOOKUP] = "ip4-lookup",
3446  [IKEV2_NEXT_IP4_ERROR_DROP] = "error-drop",
3447  },
3448 };
3449 
3451  .function = ikev2_ip4_natt,
3452  .name = "ikev2-ip4-natt",
3453  .vector_size = sizeof (u32),
3454  .format_trace = format_ikev2_trace,
3456 
3457  .n_errors = IKEV2_N_ERROR,
3458  .error_counters = ikev2_error_counters,
3459 
3460  .n_next_nodes = IKEV2_IP4_N_NEXT,
3461  .next_nodes = {
3462  [IKEV2_NEXT_IP4_LOOKUP] = "ip4-lookup",
3463  [IKEV2_NEXT_IP4_ERROR_DROP] = "error-drop",
3464  },
3465 };
3466 
3468  .function = ikev2_ip6,
3469  .name = "ikev2-ip6",
3470  .vector_size = sizeof (u32),
3471  .format_trace = format_ikev2_trace,
3473 
3474  .n_errors = IKEV2_N_ERROR,
3475  .error_counters = ikev2_error_counters,
3476 
3477  .n_next_nodes = IKEV2_IP6_N_NEXT,
3478  .next_nodes = {
3479  [IKEV2_NEXT_IP6_LOOKUP] = "ip6-lookup",
3480  [IKEV2_NEXT_IP6_ERROR_DROP] = "error-drop",
3481  },
3482 };
3483 /* *INDENT-ON* */
3484 
3485 // set ikev2 proposals when vpp is used as initiator
3486 static clib_error_t *
3488  ikev2_transforms_set * ts,
3489  ikev2_sa_proposal_t ** proposals, int is_ike)
3490 {
3491  clib_error_t *r;
3492  ikev2_main_t *km = &ikev2_main;
3493  ikev2_sa_proposal_t *proposal;
3494  vec_add2 (*proposals, proposal, 1);
3496  int error;
3497 
3498  /* Encryption */
3499  error = 1;
3501  {
3502  if (td->type == IKEV2_TRANSFORM_TYPE_ENCR
3503  && td->encr_type == ts->crypto_alg
3504  && td->key_len == ts->crypto_key_size / 8)
3505  {
3506  u16 attr[2];
3507  attr[0] = clib_host_to_net_u16 (14 | (1 << 15));
3508  attr[1] = clib_host_to_net_u16 (td->key_len << 3);
3509  vec_add (td->attrs, (u8 *) attr, 4);
3510  vec_add1 (proposal->transforms, *td);
3511  td->attrs = 0;
3512 
3513  error = 0;
3514  break;
3515  }
3516  }
3517  if (error)
3518  {
3519  r = clib_error_return (0, "Unsupported algorithm");
3520  return r;
3521  }
3522 
3523  if (IKEV2_TRANSFORM_INTEG_TYPE_NONE != ts->integ_alg)
3524  {
3525  /* Integrity */
3526  error = 1;
3528  {
3529  if (td->type == IKEV2_TRANSFORM_TYPE_INTEG
3530  && td->integ_type == ts->integ_alg)
3531  {
3532  vec_add1 (proposal->transforms, *td);
3533  error = 0;
3534  break;
3535  }
3536  }
3537  if (error)
3538  {
3540  ("Didn't find any supported algorithm for IKEV2_TRANSFORM_TYPE_INTEG");
3541  r = clib_error_return (0, "Unsupported algorithm");
3542  return r;
3543  }
3544  }
3545 
3546  /* PRF */
3547  if (is_ike)
3548  {
3549  error = 1;
3551  {
3552  if (td->type == IKEV2_TRANSFORM_TYPE_PRF
3553  && td->prf_type == IKEV2_TRANSFORM_PRF_TYPE_PRF_HMAC_SHA2_256)
3554  {
3555  vec_add1 (proposal->transforms, *td);
3556  error = 0;
3557  break;
3558  }
3559  }
3560  if (error)
3561  {
3562  r = clib_error_return (0, "Unsupported algorithm");
3563  return r;
3564  }
3565  }
3566 
3567  /* DH */
3568  if (is_ike)
3569  {
3570  error = 1;
3572  {
3573  if (td->type == IKEV2_TRANSFORM_TYPE_DH && td->dh_type == ts->dh_type)
3574  {
3575  vec_add1 (proposal->transforms, *td);
3576  if (is_ike)
3577  {
3578  sa->dh_group = td->dh_type;
3579  }
3580  error = 0;
3581  break;
3582  }
3583  }
3584  if (error)
3585  {
3586  r = clib_error_return (0, "Unsupported algorithm");
3587  return r;
3588  }
3589  }
3590 
3591  if (!is_ike)
3592  {
3593  error = 1;
3595  {
3596  if (td->type == IKEV2_TRANSFORM_TYPE_ESN)
3597  {
3598  vec_add1 (proposal->transforms, *td);
3599  error = 0;
3600  }
3601  }
3602  if (error)
3603  {
3604  r = clib_error_return (0, "Unsupported algorithm");
3605  return r;
3606  }
3607  }
3608 
3609 
3610  return 0;
3611 }
3612 
3613 static ikev2_profile_t *
3615 {
3616  ikev2_main_t *km = &ikev2_main;
3617  uword *p;
3618 
3619  p = mhash_get (&km->profile_index_by_name, name);
3620  if (!p)
3621  return 0;
3622 
3623  return pool_elt_at_index (km->profiles, p[0]);
3624 }
3625 
3626 
3627 static void
3630 {
3631  ip4_header_t *ip40;
3632  ip6_header_t *ip60;
3633  udp_header_t *udp0;
3634  vlib_buffer_t *b0;
3635  vlib_frame_t *f;
3636  u32 *to_next;
3637 
3638  b0 = vlib_get_buffer (vm, bi0);
3639  vlib_buffer_advance (b0, -sizeof (udp_header_t));
3640  udp0 = vlib_buffer_get_current (b0);
3641  udp0->dst_port = clib_host_to_net_u16 (dst_port);
3642  udp0->src_port = clib_host_to_net_u16 (src_port);
3643  udp0->length = clib_host_to_net_u16 (len + sizeof (udp_header_t));
3644  udp0->checksum = 0;
3645 
3646  if (ip_addr_version (dst) == AF_IP4)
3647  {
3648  vlib_buffer_advance (b0, -sizeof (ip4_header_t));
3649  ip40 = vlib_buffer_get_current (b0);
3650  ip40->ip_version_and_header_length = 0x45;
3651  ip40->tos = 0;
3652  ip40->fragment_id = 0;
3653  ip40->flags_and_fragment_offset = 0;
3654  ip40->ttl = 0xff;
3655  ip40->protocol = IP_PROTOCOL_UDP;
3656  ip40->dst_address.as_u32 = ip_addr_v4 (dst).as_u32;
3657  ip40->src_address.as_u32 = ip_addr_v4 (src).as_u32;
3658  b0->current_length =
3659  len + sizeof (ip4_header_t) + sizeof (udp_header_t);
3660  ip40->length = clib_host_to_net_u16 (b0->current_length);
3661  ip40->checksum = ip4_header_checksum (ip40);
3662  }
3663  else
3664  {
3665  vlib_buffer_advance (b0, -sizeof (ip6_header_t));
3666  ip60 = vlib_buffer_get_current (b0);
3667 
3668  b0->current_length = len + sizeof (*ip60) + sizeof (udp_header_t);
3670  clib_host_to_net_u32 (0x6 << 28);
3671  ip60->payload_length =
3672  clib_host_to_net_u16 (b0->current_length - sizeof (*ip60));
3673  ip60->protocol = IP_PROTOCOL_UDP;
3674  ip60->hop_limit = 0xff;
3675  clib_memcpy_fast (ip60->src_address.as_u8, ip_addr_v6 (src).as_u8,
3676  sizeof (ip60->src_address));
3677  clib_memcpy_fast (ip60->dst_address.as_u8, ip_addr_v6 (dst).as_u8,
3678  sizeof (ip60->src_address));
3679  }
3680 
3681  b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
3682  vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index;
3683  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
3684 
3686  ip4_lookup_node.index : ip6_lookup_node.index;
3687 
3688  /* send the request */
3690  to_next = vlib_frame_vector_args (f);
3691  to_next[0] = bi0;
3692  f->n_vectors = 1;
3694 
3695 }
3696 
3697 static u32
3699 {
3700  u32 bi0;
3701  if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
3702  {
3703  *b = 0;
3704  return 0;
3705  }
3706  *b = vlib_get_buffer (vm, bi0);
3707  return bi0;
3708 }
3709 
3710 clib_error_t *
3712 {
3713  ikev2_main_t *km = &ikev2_main;
3714 
3715  if (km->pkey)
3716  EVP_PKEY_free (km->pkey);
3717  km->pkey = ikev2_load_key_file (file);
3718  if (km->pkey == NULL)
3719  return clib_error_return (0, "load key '%s' failed", file);
3720 
3721  return 0;
3722 }
3723 
3726 {
3729  return 0;
3730 }
3731 
3734 {
3736  return;
3737 
3740 }
3741 
3742 static void
3745  ikev2_sa_t * sa, u8 send_notification)
3746 {
3747  ikev2_main_t *km = &ikev2_main;
3748  ip_address_t *src, *dst;
3749  vlib_buffer_t *b0;
3751 
3752  /* Create the Initiator notification for IKE SA removal */
3753  ike_header_t *ike0;
3754  u32 bi0 = 0;
3755  int len;
3756 
3757  vec_resize (sa->del, 1);
3759  sa->del->spi = sa->ispi;
3760 
3761  if (send_notification)
3762  {
3763  bi0 = ikev2_get_new_ike_header_buff (vm, &b0);
3764  if (!bi0)
3765  {
3766  ikev2_log_error ("buffer alloc failure");
3767  goto delete_sa;
3768  }
3769 
3770  ike0 = vlib_buffer_get_current (b0);
3771  ike0->exchange = IKEV2_EXCHANGE_INFORMATIONAL;
3772  ike0->ispi = clib_host_to_net_u64 (sa->ispi);
3773  ike0->rspi = clib_host_to_net_u64 (sa->rspi);
3774  ike0->flags = 0;
3775  ike0->msgid = clib_host_to_net_u32 (sa->last_init_msg_id);
3776  sa->last_init_msg_id += 1;
3777  len = ikev2_generate_message (b0, sa, ike0, 0, 0, 0);
3778  if (~0 == len)
3779  return;
3780 
3781  if (ikev2_natt_active (sa))
3783 
3784  if (sa->is_initiator)
3785  {
3786  src = &sa->iaddr;
3787  dst = &sa->raddr;
3788  }
3789  else
3790  {
3791  dst = &sa->iaddr;
3792  src = &sa->raddr;
3793  }
3794 
3795  ikev2_send_ike (vm, src, dst, bi0, len,
3796  ikev2_get_port (sa), sa->dst_port, 0);
3797  }
3798 
3799 delete_sa:
3800  /* delete local SA */
3801  vec_foreach (c, sa->childs)
3803 
3804  u64 rspi = sa->rspi;
3805  ikev2_sa_free_all_vec (sa);
3806  uword *p = hash_get (tkm->sa_by_rspi, rspi);
3807  if (p)
3808  {
3809  hash_unset (tkm->sa_by_rspi, rspi);
3810  pool_put (tkm->sas, sa);
3811  }
3812 }
3813 
3814 static void
3816 {
3818  ikev2_sa_t *sa;
3819  u32 pi = p - km->profiles;
3820  u32 *sai;
3821  u32 *del_sai = 0;
3822 
3823  /* *INDENT-OFF* */
3824  pool_foreach (sa, km->sais) {
3825  if (pi == sa->profile_index)
3826  vec_add1 (del_sai, sa - km->sais);
3827  }
3828  /* *INDENT-ON* */
3829 
3830  vec_foreach (sai, del_sai)
3831  {
3832  sa = pool_elt_at_index (km->sais, sai[0]);
3833  ikev2_sa_free_all_vec (sa);
3834  hash_unset (km->sa_by_ispi, sa->ispi);
3835  pool_put (km->sais, sa);
3836  }
3837  vec_reset_length (del_sai);
3838 
3839  vec_foreach (tkm, km->per_thread_data)
3840  {
3841  /* *INDENT-OFF* */
3842  pool_foreach (sa, tkm->sas) {
3843  if (sa->profile_index != ~0 && pi == sa->profile_index)
3844  vec_add1 (del_sai, sa - tkm->sas);
3845  }
3846  /* *INDENT-ON* */
3847 
3848  vec_foreach (sai, del_sai)
3849  {
3850  sa = pool_elt_at_index (tkm->sas, sai[0]);
3852  }
3853 
3854  vec_reset_length (del_sai);
3855  }
3856 
3857  vec_free (del_sai);
3858 }
3859 
3860 static void
3862 {
3863  vec_free (r->hostname);
3864 }
3865 
3866 static void
3868 {
3869  vec_free (p->name);
3870 
3871  vec_free (p->auth.data);
3872  if (p->auth.key)
3873  EVP_PKEY_free (p->auth.key);
3874 
3876 
3877  vec_free (p->loc_id.data);
3878  vec_free (p->rem_id.data);
3879 }
3880 
3881 clib_error_t *
3883 {
3884  ikev2_main_t *km = &ikev2_main;
3885  ikev2_profile_t *p;
3886 
3887  if (is_add)
3888  {
3890  return clib_error_return (0, "policy %v already exists", name);
3891 
3892  pool_get (km->profiles, p);
3893  clib_memset (p, 0, sizeof (*p));
3894  p->name = vec_dup (name);
3896  p->responder.sw_if_index = ~0;
3897  p->tun_itf = ~0;
3898  uword index = p - km->profiles;
3900  }
3901  else
3902  {
3904  if (!p)
3905  return clib_error_return (0, "policy %v does not exists", name);
3906 
3909 
3910  ikev2_profile_free (p);
3911  pool_put (km->profiles, p);
3913  }
3914  return 0;
3915 }
3916 
3917 clib_error_t *
3919  u8 * auth_data, u8 data_hex_format)
3920 {
3921  ikev2_profile_t *p;
3922  clib_error_t *r;
3923 
3925 
3926  if (!p)
3927  {
3928  r = clib_error_return (0, "unknown profile %v", name);
3929  return r;
3930  }
3931 
3932  if (p->auth.key)
3933  EVP_PKEY_free (p->auth.key);
3934  vec_free (p->auth.data);
3935 
3936  p->auth.method = auth_method;
3937  p->auth.data = vec_dup (auth_data);
3938  p->auth.hex = data_hex_format;
3939 
3940  if (auth_method == IKEV2_AUTH_METHOD_RSA_SIG)
3941  {
3942  vec_add1 (p->auth.data, 0);
3944  if (p->auth.key == NULL)
3945  return clib_error_return (0, "load cert '%s' failed", p->auth.data);
3946  }
3947 
3948  return 0;
3949 }
3950 
3951 static int
3953 {
3954  return (id_type == IKEV2_ID_TYPE_ID_IPV4_ADDR ||
3955  id_type == IKEV2_ID_TYPE_ID_IPV6_ADDR ||
3956  id_type == IKEV2_ID_TYPE_ID_RFC822_ADDR ||
3957  id_type == IKEV2_ID_TYPE_ID_FQDN);
3958 }
3959 
3960 clib_error_t *
3962  int is_local)
3963 {
3964  ikev2_profile_t *p;
3965  clib_error_t *r;
3966 
3967  if (!ikev2_is_id_supported (id_type))
3968  {
3969  r = clib_error_return (0, "unsupported identity type %U",
3970  format_ikev2_id_type, id_type);
3971  return r;
3972  }
3973 
3975 
3976  if (!p)
3977  {
3978  r = clib_error_return (0, "unknown profile %v", name);
3979  return r;
3980  }
3981 
3982  if (is_local)
3983  {
3984  vec_free (p->loc_id.data);
3985  p->loc_id.type = id_type;
3986  p->loc_id.data = vec_dup (data);
3987  }
3988  else
3989  {
3990  vec_free (p->rem_id.data);
3991  p->rem_id.type = id_type;
3992  p->rem_id.data = vec_dup (data);
3993  }
3994 
3995  return 0;
3996 }
3997 
4000 {
4001  if (ip_addr_version (addr) == AF_IP4)
4003  else
4005 }
4006 
4009  const ip_address_t * end)
4010 {
4011  ip_address_copy (&ts->start_addr, start);
4012  ip_address_copy (&ts->end_addr, end);
4013 }
4014 
4015 clib_error_t *
4019 {
4020  ikev2_profile_t *p;
4021  clib_error_t *r;
4022 
4024 
4025  if (!p)
4026  {
4027  r = clib_error_return (0, "unknown profile %v", name);
4028  return r;
4029  }
4030 
4032  return clib_error_return (0, "IP address version mismatch!");
4033 
4034  if (is_local)
4035  {
4038  p->loc_ts.end_port = end_port;
4041  }
4042  else
4043  {
4046  p->rem_ts.end_port = end_port;
4049  }
4050 
4051  return 0;
4052 }
4053 
4054 clib_error_t *
4056  u32 sw_if_index)
4057 {
4058  ikev2_profile_t *p;
4059  clib_error_t *r;
4060 
4062 
4063  if (!p)
4064  {
4065  r = clib_error_return (0, "unknown profile %v", name);
4066  return r;
4067  }
4068 
4069  p->responder.is_resolved = 0;
4072 
4073  return 0;
4074 }
4075 
4076 clib_error_t *
4079 {
4080  ikev2_profile_t *p;
4081  clib_error_t *r;
4082 
4084 
4085  if (!p)
4086  {
4087  r = clib_error_return (0, "unknown profile %v", name);
4088  return r;
4089  }
4090 
4091  p->responder.is_resolved = 1;
4094 
4095  return 0;
4096 }
4097 
4098 clib_error_t *
4100  ikev2_transform_encr_type_t crypto_alg,
4102  ikev2_transform_dh_type_t dh_type,
4104 {
4105  ikev2_profile_t *p;
4106  clib_error_t *r;
4107 
4109 
4110  if (!p)
4111  {
4112  r = clib_error_return (0, "unknown profile %v", name);
4113  return r;
4114  }
4115 
4116  p->ike_ts.crypto_alg = crypto_alg;
4117  p->ike_ts.integ_alg = integ_alg;
4118  p->ike_ts.dh_type = dh_type;
4120  return 0;
4121 }
4122 
4123 clib_error_t *
4125  ikev2_transform_encr_type_t crypto_alg,
4128 {
4129  ikev2_profile_t *p;
4130  clib_error_t *r;
4131 
4133 
4134  if (!p)
4135  {
4136  r = clib_error_return (0, "unknown profile %v", name);
4137  return r;
4138  }
4139 
4140  p->esp_ts.crypto_alg = crypto_alg;
4141  p->esp_ts.integ_alg = integ_alg;
4143  return 0;
4144 }
4145 
4146 clib_error_t *
4148  u8 * name, u32 sw_if_index)
4149 {
4150  ikev2_profile_t *p;
4151  clib_error_t *r;
4152 
4154 
4155  if (!p)
4156  {
4157  r = clib_error_return (0, "unknown profile %v", name);
4158  return r;
4159  }
4160 
4161  p->tun_itf = sw_if_index;
4162 
4163  return 0;
4164 }
4165 
4168  u8 is_set)
4169 {
4171  vnet_api_error_t rv = 0;
4172 
4173  if (!p)
4174  return VNET_API_ERROR_INVALID_VALUE;
4175 
4176  if (is_set)
4177  {
4179  return VNET_API_ERROR_VALUE_EXIST;
4180 
4182  }
4183  else
4184  {
4186  return VNET_API_ERROR_INVALID_VALUE;
4187 
4189  }
4190  return rv;
4191 }
4192 
4193 clib_error_t *
4195 {
4197  clib_error_t *r;
4198 
4199  if (!p)
4200  {
4201  r = clib_error_return (0, "unknown profile %v", name);
4202  return r;
4203  }
4204 
4205  p->udp_encap = 1;
4206  return 0;
4207 }
4208 
4209 clib_error_t *
4211  u64 lifetime, u32 jitter, u32 handover,
4212  u64 maxdata)
4213 {
4214  ikev2_profile_t *p;
4215  clib_error_t *r;
4216 
4218 
4219  if (!p)
4220  {
4221  r = clib_error_return (0, "unknown profile %v", name);
4222  return r;
4223  }
4224 
4225  p->lifetime = lifetime;
4226  p->lifetime_jitter = jitter;
4227  p->handover = handover;
4228  p->lifetime_maxdata = maxdata;
4229  return 0;
4230 }
4231 
4232 static int
4234  ip_address_t * out_addr)
4235 {
4236  ip4_address_t *if_ip4;
4237  ip6_address_t *if_ip6;
4238 
4239  if (af == AF_IP4)
4240  {
4242  if (if_ip4)
4243  {
4244  ip_address_set (out_addr, if_ip4, AF_IP4);
4245  return 1;
4246  }
4247  }
4248  else
4249  {
4251  if (if_ip6)
4252  {
4253  ip_address_set (out_addr, if_ip6, AF_IP6);
4254  return 1;
4255  }
4256  }
4257  return 0;
4258 }
4259 
4260 static clib_error_t *
4262 {
4263  ikev2_main_t *km = &ikev2_main;
4264  dns_cache_entry_t *ep = 0;
4265  dns_pending_request_t _t0, *t0 = &_t0;
4266  dns_resolve_name_t _rn, *rn = &_rn;
4267  int rv;
4268 
4269  if (!km->dns_resolve_name)
4270  return clib_error_return (0, "cannot load symbols from dns plugin");
4271 
4273  rv = km->dns_resolve_name (r->hostname, &ep, t0, rn);
4274  if (rv < 0)
4275  return clib_error_return (0, "dns lookup failure");
4276 
4277  if (ep == 0)
4278  return 0;
4279 
4280  ip_address_copy (&r->addr, &rn->address);
4281  r->is_resolved = 1;
4282  return 0;
4283 }
4284 
4285 clib_error_t *
4287 {
4288  ikev2_profile_t *p;
4289  clib_error_t *r;
4290  ikev2_main_t *km = &ikev2_main;
4291  vlib_buffer_t *b0;
4292  ike_header_t *ike0;
4293  u32 bi0 = 0;
4294  int len = sizeof (ike_header_t), valid_ip = 0;
4296 
4298 
4299  if (!p)
4300  {
4301  r = clib_error_return (0, "unknown profile %v", name);
4302  return r;
4303  }
4304 
4305  if (p->responder.sw_if_index == ~0 ||
4307  vec_len (p->responder.hostname) == 0))
4308  {
4309  r = clib_error_return (0, "responder not set for profile %v", name);
4310  return r;
4311  }
4312 
4313  if (!p->responder.is_resolved)
4314  {
4315  /* try to resolve using dns plugin
4316  * success does not mean we have resolved the name */
4318  if (r)
4319  return r;
4320  }
4321 
4322  if (p->responder.is_resolved &&
4324  ip_addr_version (&p->responder.addr), &src_if_ip))
4325  {
4326  valid_ip = 1;
4327  }
4328 
4329  /* Prepare the SA and the IKE payload */
4330  ikev2_sa_t sa;
4331  clib_memset (&sa, 0, sizeof (ikev2_sa_t));
4332  ikev2_payload_chain_t *chain = 0;
4333  ikev2_payload_new_chain (chain);
4334 
4335  /* Build the IKE proposal payload */
4336  ikev2_sa_proposal_t *proposals = 0;
4337  ikev2_set_initiator_proposals (vm, &sa, &p->ike_ts, &proposals, 1);
4338  proposals[0].proposal_num = 1;
4339  proposals[0].protocol_id = IKEV2_PROTOCOL_IKE;
4340 
4341  /* Add and then cleanup proposal data */
4342  ikev2_payload_add_sa (chain, proposals);
4343  ikev2_sa_free_proposal_vector (&proposals);
4344 
4345  sa.is_initiator = 1;
4346  sa.profile_index = p - km->profiles;
4348  sa.tun_itf = p->tun_itf;
4349  sa.udp_encap = p->udp_encap;
4350  if (p->natt_disabled)
4353  sa.is_tun_itf_set = 1;
4354  sa.initial_contact = 1;
4355  sa.dst_port = IKEV2_PORT;
4356 
4358  if (rc != IKEV2_GENERATE_SA_INIT_OK)
4359  {
4360  ikev2_sa_free_all_vec (&sa);
4362  return clib_error_return (0, "%U", format_ikev2_gen_sa_error, rc);
4363  }
4364 
4365  ikev2_payload_add_ke (chain, sa.dh_group, sa.i_dh_data);
4366  ikev2_payload_add_nonce (chain, sa.i_nonce);
4367 
4368  /* Build the child SA proposal */
4369  vec_resize (sa.childs, 1);
4371  &sa.childs[0].i_proposals, 0);
4372  sa.childs[0].i_proposals[0].proposal_num = 1;
4374  RAND_bytes ((u8 *) & sa.childs[0].i_proposals[0].spi,
4375  sizeof (sa.childs[0].i_proposals[0].spi));
4376 
4377  /* Add NAT detection notification messages (mandatory) */
4378  u8 *nat_detection_sha1 = ikev2_compute_nat_sha1 (
4379  clib_host_to_net_u64 (sa.ispi), clib_host_to_net_u64 (sa.rspi), &src_if_ip,
4380  clib_host_to_net_u16 (IKEV2_PORT));
4381 
4382  ikev2_payload_add_notify (chain, IKEV2_NOTIFY_MSG_NAT_DETECTION_SOURCE_IP,
4383  nat_detection_sha1);
4384  vec_free (nat_detection_sha1);
4385  nat_detection_sha1 =
4386  ikev2_compute_nat_sha1 (clib_host_to_net_u64 (sa.ispi),
4387  clib_host_to_net_u64 (sa.rspi),
4388  &p->responder.addr,
4389  clib_host_to_net_u16 (sa.dst_port));
4390  ikev2_payload_add_notify (chain,
4391  IKEV2_NOTIFY_MSG_NAT_DETECTION_DESTINATION_IP,
4392  nat_detection_sha1);
4393  vec_free (nat_detection_sha1);
4394 
4395  u8 *sig_hash_algo = vec_new (u8, 8);
4396  u64 tmpsig = clib_host_to_net_u64 (0x0001000200030004);
4397  clib_memcpy_fast (sig_hash_algo, &tmpsig, sizeof (tmpsig));
4398  ikev2_payload_add_notify (chain,
4399  IKEV2_NOTIFY_MSG_SIGNATURE_HASH_ALGORITHMS,
4400  sig_hash_algo);
4401  vec_free (sig_hash_algo);
4402 
4403  bi0 = ikev2_get_new_ike_header_buff (vm, &b0);
4404  if (!bi0)
4405  {
4406  ikev2_sa_free_all_vec (&sa);
4408  char *errmsg = "buffer alloc failure";
4409  ikev2_log_error (errmsg);
4410  return clib_error_return (0, errmsg);
4411  }
4412  ike0 = vlib_buffer_get_current (b0);
4413 
4414  /* Buffer update and boilerplate */
4415  len += vec_len (chain->data);
4416  ike0->nextpayload = chain->first_payload_type;
4417  ike0->length = clib_host_to_net_u32 (len);
4418  clib_memcpy_fast (ike0->payload, chain->data, vec_len (chain->data));
4420 
4421  ike0->version = IKE_VERSION_2;
4422  ike0->flags = IKEV2_HDR_FLAG_INITIATOR;
4423  ike0->exchange = IKEV2_EXCHANGE_SA_INIT;
4424  ike0->ispi = clib_host_to_net_u64 (sa.ispi);
4425  ike0->rspi = 0;
4426  ike0->msgid = 0;
4427  sa.last_init_msg_id += 1;
4428 
4429  /* store whole IKE payload - needed for PSK auth */
4432 
4433  /* add data to the SA then add it to the pool */
4434  ip_address_copy (&sa.iaddr, &src_if_ip);
4435  ip_address_copy (&sa.raddr, &p->responder.addr);
4436  sa.i_id.type = p->loc_id.type;
4437  sa.i_id.data = vec_dup (p->loc_id.data);
4438  sa.r_id.type = p->rem_id.type;
4439  sa.r_id.data = vec_dup (p->rem_id.data);
4440  sa.i_auth.method = p->auth.method;
4441  sa.i_auth.hex = p->auth.hex;
4442  sa.i_auth.data = vec_dup (p->auth.data);
4444  vec_add (sa.childs[0].tsi, &p->loc_ts, 1);
4445  vec_add (sa.childs[0].tsr, &p->rem_ts, 1);
4446 
4448 
4449  /* add SA to the pool */
4450  ikev2_sa_t *sa0 = 0;
4451  pool_get (km->sais, sa0);
4452  clib_memcpy_fast (sa0, &sa, sizeof (*sa0));
4453  hash_set (km->sa_by_ispi, sa0->ispi, sa0 - km->sais);
4454 
4455  if (valid_ip)
4456  {
4457  ikev2_send_ike (vm, &src_if_ip, &p->responder.addr, bi0, len, IKEV2_PORT,
4458  sa.dst_port, sa.sw_if_index);
4459 
4461  ("ispi %lx rspi %lx IKEV2_EXCHANGE_SA_INIT sent to ",
4462  clib_host_to_net_u64 (sa0->ispi), 0,
4463  ip_addr_v4 (&p->responder.addr).as_u32,
4465  }
4466 
4467  return 0;
4468 }
4469 
4470 static void
4472  ikev2_child_sa_t * csa)
4473 {
4474  /* Create the Initiator notification for child SA removal */
4475  ikev2_main_t *km = &ikev2_main;
4476  ike_header_t *ike0;
4477  u32 bi0 = 0;
4478  vlib_buffer_t *b0;
4479  int len;
4480 
4481  bi0 = ikev2_get_new_ike_header_buff (vm, &b0);
4482  if (!bi0)
4483  {
4484  ikev2_log_error ("buffer alloc failure");
4485  return;
4486  }
4487 
4488  ike0 = vlib_buffer_get_current (b0);
4489  ike0->exchange = IKEV2_EXCHANGE_INFORMATIONAL;
4490  ike0->ispi = clib_host_to_net_u64 (sa->ispi);
4491  ike0->rspi = clib_host_to_net_u64 (sa->rspi);
4492  ike0->flags = 0;
4493  vec_resize (sa->del, 1);
4495  sa->del->spi = csa->i_proposals->spi;
4496  ike0->msgid = clib_host_to_net_u32 (sa->last_init_msg_id);
4497  sa->last_init_msg_id += 1;
4498  len = ikev2_generate_message (b0, sa, ike0, 0, 0, 0);
4499  if (~0 == len)
4500  return;
4501 
4502  if (ikev2_natt_active (sa))
4504  ikev2_send_ike (vm, &sa->iaddr, &sa->raddr, bi0, len,
4505  ikev2_get_port (sa), sa->dst_port, sa->sw_if_index);
4506 
4507  /* delete local child SA */
4509  ikev2_sa_del_child_sa (sa, csa);
4510 }
4511 
4512 clib_error_t *
4514 {
4515  clib_error_t *r;
4516  ikev2_main_t *km = &ikev2_main;
4518  ikev2_sa_t *fsa = 0;
4519  ikev2_child_sa_t *fchild = 0;
4520 
4521  /* Search for the child SA */
4522  vec_foreach (tkm, km->per_thread_data)
4523  {
4524  ikev2_sa_t *sa;
4525  if (fchild)
4526  break;
4527  /* *INDENT-OFF* */
4528  pool_foreach (sa, tkm->sas) {
4529  fchild = ikev2_sa_get_child(sa, ispi, IKEV2_PROTOCOL_ESP, 1);
4530  if (fchild)
4531  {
4532  fsa = sa;
4533  break;
4534  }
4535  }
4536  /* *INDENT-ON* */
4537  }
4538 
4539  if (!fchild || !fsa)
4540  {
4541  r = clib_error_return (0, "Child SA not found");
4542  return r;
4543  }
4544  else
4545  {
4546  ikev2_delete_child_sa_internal (vm, fsa, fchild);
4547  }
4548 
4549  return 0;
4550 }
4551 
4552 clib_error_t *
4554 {
4555  clib_error_t *r;
4556  ikev2_main_t *km = &ikev2_main;
4558  ikev2_sa_t *fsa = 0;
4559  ikev2_main_per_thread_data_t *ftkm = 0;
4560 
4561  /* Search for the IKE SA */
4562  vec_foreach (tkm, km->per_thread_data)
4563  {
4564  ikev2_sa_t *sa;
4565  if (fsa)
4566  break;
4567  /* *INDENT-OFF* */
4568  pool_foreach (sa, tkm->sas) {
4569  if (sa->ispi == ispi)
4570  {
4571  fsa = sa;
4572  ftkm = tkm;
4573  break;
4574  }
4575  }
4576  /* *INDENT-ON* */
4577  }
4578 
4579  if (!fsa)
4580  {
4581  r = clib_error_return (0, "IKE SA not found");
4582  return r;
4583  }
4584 
4585  ikev2_initiate_delete_ike_sa_internal (vm, ftkm, fsa, 1);
4586  return 0;
4587 }
4588 
4589 static void
4591  ikev2_child_sa_t * csa)
4592 {
4593  /* Create the Initiator request for create child SA */
4594  ike_header_t *ike0;
4595  vlib_buffer_t *b0;
4596  u32 bi0 = 0;
4597  int len;
4598 
4599  bi0 = ikev2_get_new_ike_header_buff (vm, &b0);
4600  if (!bi0)
4601  {
4602  ikev2_log_error ("buffer alloc failure");
4603  return;
4604  }
4605 
4606  ike0 = vlib_buffer_get_current (b0);
4607  ike0->version = IKE_VERSION_2;
4608  ike0->flags = IKEV2_HDR_FLAG_INITIATOR;
4609  ike0->exchange = IKEV2_EXCHANGE_CREATE_CHILD_SA;
4610  ike0->ispi = clib_host_to_net_u64 (sa->ispi);
4611  ike0->rspi = clib_host_to_net_u64 (sa->rspi);
4612  ike0->msgid = clib_host_to_net_u32 (sa->last_init_msg_id);
4613  sa->last_init_msg_id += 1;
4614 
4615  ikev2_rekey_t *rekey;
4616  vec_reset_length (sa->rekey);
4617  vec_add2 (sa->rekey, rekey, 1);
4618  ikev2_sa_proposal_t *proposals = vec_dup (csa->i_proposals);
4619 
4620  /*need new ispi */
4621  RAND_bytes ((u8 *) & proposals[0].spi, sizeof (proposals[0].spi));
4622  rekey->spi = proposals[0].spi;
4623  rekey->ispi = csa->i_proposals->spi;
4624  len = ikev2_generate_message (b0, sa, ike0, proposals, 0, 0);
4625  if (~0 == len)
4626  return;
4627 
4628  if (ikev2_natt_active (sa))
4630  ikev2_send_ike (vm, &sa->iaddr, &sa->raddr, bi0, len,
4631  ikev2_get_port (sa), ikev2_get_port (sa), sa->sw_if_index);
4632  vec_free (proposals);
4633 }
4634 
4635 clib_error_t *
4637 {
4638  clib_error_t *r;
4639  ikev2_main_t *km = &ikev2_main;
4641  ikev2_sa_t *fsa = 0;
4642  ikev2_child_sa_t *fchild = 0;
4643 
4644  /* Search for the child SA */
4645  vec_foreach (tkm, km->per_thread_data)
4646  {
4647  ikev2_sa_t *sa;
4648  if (fchild)
4649  break;
4650  /* *INDENT-OFF* */
4651  pool_foreach (sa, tkm->sas) {
4652  fchild = ikev2_sa_get_child(sa, ispi, IKEV2_PROTOCOL_ESP, 1);
4653  if (fchild)
4654  {
4655  fsa = sa;
4656  break;
4657  }
4658  }
4659  /* *INDENT-ON* */
4660  }
4661 
4662  if (!fchild || !fsa)
4663  {
4664  r = clib_error_return (0, "Child SA not found");
4665  return r;
4666  }
4667  else
4668  {
4669  ikev2_rekey_child_sa_internal (vm, fsa, fchild);
4670  }
4671 
4672  return 0;
4673 }
4674 
4675 static int
4677 {
4678  return (sa->sw_if_index == sw_if_index) && sa->is_initiator;
4679 }
4680 
4681 static void
4683 {
4684  u64 *ispi, *ispi_vec = 0;
4685  ikev2_sa_t *sa, **sap, **sa_vec = 0;
4686  ikev2_main_t *km = &ikev2_main;
4688  p->responder.sw_if_index = ~0;
4689 
4690  vec_foreach (tkm, km->per_thread_data)
4691  {
4692  /* *INDENT-OFF* */
4693  pool_foreach (sa, tkm->sas) {
4695  vec_add1 (sa_vec, sa);
4696  }
4697  /* *INDENT-ON* */
4698 
4699  vec_foreach (sap, sa_vec)
4700  {
4702  }
4703  vec_reset_length (sa_vec);
4704  }
4705  vec_free (sa_vec);
4706 
4707  /* *INDENT-OFF* */
4708  pool_foreach (sa, km->sais) {
4710  vec_add1 (ispi_vec, sa->ispi);
4711  }
4712  /* *INDENT-ON* */
4713 
4714  vec_foreach (ispi, ispi_vec)
4715  {
4717  }
4718 
4719  vec_free (ispi_vec);
4720 }
4721 
4722 static clib_error_t *
4724 {
4725  ikev2_main_t *km = &ikev2_main;
4726  ikev2_profile_t *p;
4727 
4728  if (is_add)
4729  return 0;
4730 
4731  /* *INDENT-OFF* */
4732  pool_foreach (p, km->profiles) {
4733  if (p->responder.sw_if_index == sw_if_index)
4735  }
4736  /* *INDENT-ON* */
4737 
4738  return 0;
4739 }
4740 
4742 
4743 clib_error_t *
4745 {
4746  ikev2_main_t *km = &ikev2_main;
4748  int thread_id;
4749 
4750  clib_memset (km, 0, sizeof (ikev2_main_t));
4751  km->vnet_main = vnet_get_main ();
4752  km->vlib_main = vm;
4753 
4756  ikev2_crypto_init (km);
4757 
4759 
4762  for (thread_id = 0; thread_id < tm->n_vlib_mains; thread_id++)
4763  {
4765  vec_elt_at_index (km->per_thread_data, thread_id);
4766 
4767  ptd->sa_by_rspi = hash_create (0, sizeof (uword));
4768 
4769 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
4770  ptd->evp_ctx = EVP_CIPHER_CTX_new ();
4771  ptd->hmac_ctx = HMAC_CTX_new ();
4772 #else
4773  EVP_CIPHER_CTX_init (&ptd->_evp_ctx);
4774  ptd->evp_ctx = &ptd->_evp_ctx;
4775  HMAC_CTX_init (&(ptd->_hmac_ctx));
4776  ptd->hmac_ctx = &ptd->_hmac_ctx;
4777 #endif
4778  }
4779 
4780  km->sa_by_ispi = hash_create (0, sizeof (uword));
4781  km->sw_if_indices = hash_create (0, 0);
4782 
4787 
4788  vlib_punt_hdl_t punt_hdl = vlib_punt_client_register ("ikev2-ip4-natt");
4789  vlib_punt_register (punt_hdl, ipsec_punt_reason[IPSEC_PUNT_IP4_SPI_UDP_0],
4790  "ikev2-ip4-natt");
4792 
4793  km->dns_resolve_name =
4794  vlib_get_plugin_symbol ("dns_plugin.so", "dns_resolve_name");
4795  if (!km->dns_resolve_name)
4796  ikev2_log_error ("cannot load symbols from dns plugin");
4797 
4798  km->log_level = IKEV2_LOG_ERROR;
4799  km->log_class = vlib_log_register_class ("ikev2", 0);
4800  return 0;
4801 }
4802 
4803 /* *INDENT-OFF* */
4805  .runs_after = VLIB_INITS ("ipsec_init", "ipsec_punt_init", "dns_init"),
4806 };
4807 /* *INDENT-ON* */
4808 
4809 static u8
4811  u8 del_old_ids)
4812 {
4813  ikev2_main_t *km = &ikev2_main;
4814  ikev2_profile_t *p = 0;
4815  vlib_main_t *vm = km->vlib_main;
4816  f64 now = vlib_time_now (vm);
4817  u8 res = 0;
4818 
4819  if (sa->profile_index != ~0)
4820  p = pool_elt_at_index (km->profiles, sa->profile_index);
4821 
4822  if (sa->is_initiator && p && csa->time_to_expiration
4823  && now > csa->time_to_expiration)
4824  {
4825  if (!csa->is_expired || csa->rekey_retries > 0)
4826  {
4827  ikev2_rekey_child_sa_internal (vm, sa, csa);
4828  csa->time_to_expiration = now + p->handover;
4829  csa->is_expired = 1;
4830  if (csa->rekey_retries == 0)
4831  {
4832  csa->rekey_retries = 5;
4833  }
4834  else if (csa->rekey_retries > 0)
4835  {
4836  csa->rekey_retries--;
4837  ikev2_log_debug ("Rekeying Child SA 0x%x, retries left %d",
4838  csa->i_proposals->spi, csa->rekey_retries);
4839  if (csa->rekey_retries == 0)
4840  {
4841  csa->rekey_retries = -1;
4842  }
4843  }
4844  res |= 1;
4845  }
4846  else
4847  {
4848  csa->time_to_expiration = 0;
4850  res |= 1;
4851  return res;
4852  }
4853  }
4854 
4855  if (del_old_ids)
4856  {
4857  ipip_tunnel_t *ipip = NULL;
4858  u32 sw_if_index = sa->is_tun_itf_set ? sa->tun_itf : ~0;
4859  if (~0 == sw_if_index)
4860  {
4861  ip46_address_t local_ip;
4862  ip46_address_t remote_ip;
4863  if (sa->is_initiator)
4864  {
4865  local_ip = to_ip46 (ip_addr_version (&sa->iaddr),
4866  ip_addr_bytes (&sa->iaddr));
4867  remote_ip = to_ip46 (ip_addr_version (&sa->raddr),
4868  ip_addr_bytes (&sa->raddr));
4869  }
4870  else
4871  {
4872  local_ip = to_ip46 (ip_addr_version (&sa->raddr),
4873  ip_addr_bytes (&sa->raddr));
4874  remote_ip = to_ip46 (ip_addr_version (&sa->iaddr),
4875  ip_addr_bytes (&sa->iaddr));
4876  }
4877 
4878  /* *INDENT-OFF* */
4879  ipip_tunnel_key_t key = {
4880  .src = local_ip,
4881  .dst = remote_ip,
4882  .transport = IPIP_TRANSPORT_IP4,
4883  .fib_index = 0,
4884  };
4885  /* *INDENT-ON* */
4886 
4887  ipip = ipip_tunnel_db_find (&key);
4888 
4889  if (ipip)
4890  sw_if_index = ipip->sw_if_index;
4891  else
4892  return res;
4893  }
4894 
4895  u32 *sas_in = NULL;
4896  vec_add1 (sas_in, csa->remote_sa_id);
4899  csa->local_sa_id, sas_in);
4900  if (rv)
4901  vec_free (sas_in);
4904  }
4905 
4906  return res;
4907 }
4908 
4909 int
4911 {
4912  ikev2_main_t *km = &ikev2_main;
4913 
4914  if (log_level >= IKEV2_LOG_MAX)
4915  {
4916  ikev2_log_error ("unknown logging level %d", log_level);
4917  return -1;
4918  }
4919 
4920  km->log_level = log_level;
4921  return 0;
4922 }
4923 
4924 clib_error_t *
4925 ikev2_set_liveness_params (u32 period, u32 max_retries)
4926 {
4927  ikev2_main_t *km = &ikev2_main;
4928 
4929  if (period == 0 || max_retries == 0)
4930  return clib_error_return (0, "invalid args");
4931 
4932  km->liveness_period = period;
4933  km->liveness_max_retries = max_retries;
4934  return 0;
4935 }
4936 
4937 clib_error_t *
4939 {
4941  if (!p)
4942  return clib_error_return (0, "unknown profile %v", name);
4943 
4944  p->natt_disabled = 1;
4945  return 0;
4946 }
4947 
4948 static void
4950 {
4951  ikev2_main_t *km = &ikev2_main;
4952  vlib_main_t *vm = km->vlib_main;
4954  ikev2_sa_t *fsa = 0;
4955  ikev2_profile_t *p = 0;
4956  ikev2_child_sa_t *fchild = 0;
4957  f64 now = vlib_time_now (vm);
4958  vlib_counter_t counts;
4959 
4960  /* Search for the SA and child SA */
4961  vec_foreach (tkm, km->per_thread_data)
4962  {
4963  ikev2_sa_t *sa;
4964  if (fchild)
4965  break;
4966  /* *INDENT-OFF* */
4967  pool_foreach (sa, tkm->sas) {
4968  fchild = ikev2_sa_get_child(sa, ipsec_sa->spi, IKEV2_PROTOCOL_ESP, 1);
4969  if (fchild)
4970  {
4971  fsa = sa;
4972  break;
4973  }
4974  }
4975  /* *INDENT-ON* */
4976  }
4978  ipsec_sa->stat_index, &counts);
4979 
4980  if (fsa && fsa->profile_index != ~0 && fsa->is_initiator)
4981  p = pool_elt_at_index (km->profiles, fsa->profile_index);
4982 
4983  if (fchild && p && p->lifetime_maxdata)
4984  {
4985  if (!fchild->is_expired && counts.bytes > p->lifetime_maxdata)
4986  {
4987  fchild->time_to_expiration = now;
4988  }
4989  }
4990 }
4991 
4992 static void
4994  ikev2_sa_t *sa)
4995 {
4996  ikev2_profile_t *p;
4997  u32 bi0;
4998  u8 *nat_sha, *np;
4999  p = pool_elt_at_index (km->profiles, sa->profile_index);
5000 
5001  if (!p->responder.is_resolved)
5002  {
5004  if (r)
5005  {
5006  clib_error_free (r);
5007  return;
5008  }
5009 
5010  if (!p->responder.is_resolved)
5011  return;
5012 
5013  ip_address_copy (&sa->raddr, &p->responder.addr);
5014 
5015  /* update nat detection destination hash */
5017  (ike_header_t *) sa->last_sa_init_req_packet_data,
5018  IKEV2_NOTIFY_MSG_NAT_DETECTION_DESTINATION_IP);
5019  if (np)
5020  {
5021  nat_sha = ikev2_compute_nat_sha1 (
5022  clib_host_to_net_u64 (sa->ispi), clib_host_to_net_u64 (sa->rspi),
5023  &sa->raddr, clib_host_to_net_u16 (sa->dst_port));
5024  clib_memcpy_fast (np, nat_sha, vec_len (nat_sha));
5025  vec_free (nat_sha);
5026  }
5027  }
5028 
5029  if (ip_address_is_zero (&sa->iaddr))
5030  {
5033  &sa->iaddr))
5034  return;
5035 
5036  /* update NAT detection payload */
5037  np =
5039  ((ike_header_t *) sa->last_sa_init_req_packet_data,
5040  IKEV2_NOTIFY_MSG_NAT_DETECTION_SOURCE_IP);
5041  if (np)
5042  {
5043  nat_sha =
5044  ikev2_compute_nat_sha1 (clib_host_to_net_u64 (sa->ispi),
5045  clib_host_to_net_u64 (sa->rspi),
5046  &sa->iaddr,
5047  clib_host_to_net_u16 (IKEV2_PORT));
5048  clib_memcpy_fast (np, nat_sha, vec_len (nat_sha));
5049  vec_free (nat_sha);
5050  }
5051  }
5052 
5053  if (vlib_buffer_alloc (km->vlib_main, &bi0, 1) != 1)
5054  return;
5055 
5056  vlib_buffer_t *b = vlib_get_buffer (km->vlib_main, bi0);
5060 
5061  ikev2_send_ike (km->vlib_main, &sa->iaddr, &sa->raddr, bi0,
5064 }
5065 
5066 static void
5068 {
5069  u32 sai;
5070  u64 ispi;
5071  ikev2_sa_t *sa;
5072 
5073  /* *INDENT-OFF* */
5074  hash_foreach (ispi, sai, km->sa_by_ispi,
5075  ({
5076  sa = pool_elt_at_index (km->sais, sai);
5077  if (sa->init_response_received)
5078  continue;
5079 
5080  ikev2_process_pending_sa_init_one (vm, km, sa);
5081  }));
5082  /* *INDENT-ON* */
5083 }
5084 
5085 static void
5087 {
5088  ikev2_main_t *km = &ikev2_main;
5089  ip_address_t *src, *dst;
5090  ike_header_t *ike0;
5091  vlib_buffer_t *b0;
5092  u32 bi0 = 0;
5093  u16 dp;
5094  int len;
5095 
5096  bi0 = ikev2_get_new_ike_header_buff (km->vlib_main, &b0);
5097  if (!bi0)
5098  {
5099  ikev2_log_error ("buffer alloc failure");
5100  return;
5101  }
5102 
5103  ike0 = vlib_buffer_get_current (b0);
5104  ike0->exchange = IKEV2_EXCHANGE_INFORMATIONAL;
5105  ike0->ispi = clib_host_to_net_u64 (sa->ispi);
5106  ike0->rspi = clib_host_to_net_u64 (sa->rspi);
5107  ike0->msgid = clib_host_to_net_u32 (sa->last_init_msg_id);
5108  ike0->flags = 0;
5109  sa->last_init_msg_id += 1;
5110  len = ikev2_generate_message (b0, sa, ike0, 0, 0, 0);
5111  if (~0 == len)
5112  return;
5113 
5114  if (ikev2_natt_active (sa))
5116 
5117  if (sa->is_initiator)
5118  {
5119  src = &sa->iaddr;
5120  dst = &sa->raddr;
5121  }
5122  else
5123  {
5124  dst = &sa->iaddr;
5125  src = &sa->raddr;
5126  }
5127 
5128  dp = sa->dst_port ? sa->dst_port : ikev2_get_port (sa);
5129  ikev2_send_ike (km->vlib_main, src, dst, bi0, len, ikev2_get_port (sa), dp,
5130  sa->sw_if_index);
5131 }
5132 
5133 void
5135 {
5136  ikev2_main_t *km = &ikev2_main;
5137  km->dpd_disabled = 1;
5138 }
5139 
5142 {
5143  ikev2_main_t *km = &ikev2_main;
5144  vlib_main_t *vm = km->vlib_main;
5145 
5146  if (!sa->keys_generated)
5147  return 0;
5148 
5149  if (sa->liveness_retries >= km->liveness_max_retries)
5150  return 1;
5151 
5152  f64 now = vlib_time_now (vm);
5153 
5154  if (sa->liveness_period_check < now)
5155  {
5156  sa->liveness_retries++;
5159  }
5160  return 0;
5161 }
5162 
5163 static uword
5165  vlib_frame_t * f)
5166 {
5167  ikev2_main_t *km = &ikev2_main;
5168  ikev2_profile_t *p;
5170  u32 *sai;
5171 
5172  while (1)
5173  {
5175  vlib_process_get_events (vm, NULL);
5176 
5177  /* process ike child sas */
5179  vec_foreach (tkm, km->per_thread_data)
5180  {
5181  ikev2_sa_t *sa;
5182  u32 *to_be_deleted = 0;
5183 
5184  /* *INDENT-OFF* */
5185  pool_foreach (sa, tkm->sas) {
5187  u8 del_old_ids = 0;
5188 
5189  if (sa->state != IKEV2_STATE_AUTHENTICATED)
5190  continue;
5191 
5192  if (sa->old_remote_id_present && 0 > sa->old_id_expiration)
5193  {
5194  sa->old_remote_id_present = 0;
5195  del_old_ids = 1;
5196  }
5197  else
5198  sa->old_id_expiration -= 1;
5199 
5200  vec_foreach (c, sa->childs)
5201  ikev2_mngr_process_child_sa(sa, c, del_old_ids);
5202 
5204  vec_add1 (to_be_deleted, sa - tkm->sas);
5205  }
5206  /* *INDENT-ON* */
5207 
5208  vec_foreach (sai, to_be_deleted)
5209  {
5210  sa = pool_elt_at_index (tkm->sas, sai[0]);
5211  u8 reinitiate = (sa->is_initiator && sa->profile_index != ~0);
5212  vec_foreach (c, sa->childs)
5213  {
5215  ikev2_sa_del_child_sa (sa, c);
5216  }
5217  ikev2_sa_free_all_vec (sa);
5218  hash_unset (tkm->sa_by_rspi, sa->rspi);
5219  pool_put (tkm->sas, sa);
5220 
5221  if (reinitiate)
5222  {
5223  p = pool_elt_at_index (km->profiles, sa->profile_index);
5224  if (p)
5225  {
5227  if (e)
5228  {
5230  clib_error_free (e);
5231  }
5232  }
5233  }
5234  }
5235  vec_free (to_be_deleted);
5236  }
5237 
5238  /* process ipsec sas */
5239  ipsec_sa_t *sa;
5240  /* *INDENT-OFF* */
5242  {
5244  }
5245  /* *INDENT-ON* */
5246 
5248  }
5249  return 0;
5250 }
5251 
5252 /* *INDENT-OFF* */
5254  .function = ikev2_mngr_process_fn,
5255  .type = VLIB_NODE_TYPE_PROCESS,
5256  .name =
5257  "ikev2-manager-process",
5258 };
5259 
5260 VLIB_PLUGIN_REGISTER () = {
5261  .version = VPP_BUILD_VER,
5262  .description = "Internet Key Exchange (IKEv2) Protocol",
5263 };
5264 /* *INDENT-ON* */
5265 
5266 /*
5267  * fd.io coding-style-patch-verification: ON
5268  *
5269  * Local Variables:
5270  * eval: (c-set-style "gnu")
5271  * End:
5272  */
ikev2_del_tunnel_from_main
static void ikev2_del_tunnel_from_main(ikev2_del_ipsec_tunnel_args_t *a)
Definition: ikev2.c:2215
ikev2_protocol_id_t
ikev2_protocol_id_t
Definition: ikev2.h:121
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
vlib.h
ikev2_profile_t::tun_itf
u32 tun_itf
Definition: ikev2_priv.h:350
ipsec.h
ip_address
Definition: ip_types.h:79
tmp
u32 * tmp
Definition: interface_output.c:1078
IKEV2_STATE_AUTHENTICATED
@ IKEV2_STATE_AUTHENTICATED
Definition: ikev2_priv.h:193
IKEV2_PORT_NATT
#define IKEV2_PORT_NATT
Definition: ikev2.h:25
ikev2_sa_sw_if_match
static int ikev2_sa_sw_if_match(ikev2_sa_t *sa, u32 sw_if_index)
Definition: ikev2.c:4676
ikev2_sa_t::i_dh_data
u8 * i_dh_data
Definition: ikev2_priv.h:396
ip4_lookup_node
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
Definition: ip4_forward.c:104
vlib_frame_t::n_vectors
u16 n_vectors
Definition: node.h:387
ikev2_main_t
Definition: ikev2_priv.h:486
ikev2_payload_add_nonce
void ikev2_payload_add_nonce(ikev2_payload_chain_t *c, u8 *nonce)
Definition: ikev2_payload.c:235
ikev2_child_sa_t::i_proposals
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:282
ip_addr_46
#define ip_addr_46(_a)
Definition: ip_types.h:90
ikev2_log_error
#define ikev2_log_error(...)
Definition: ikev2_priv.h:180
ikev2_add_ipsec_tunnel_args_t::rem_ikey
ipsec_key_t rem_ikey
Definition: ikev2.c:1846
ikev2_send_informational_request
static void ikev2_send_informational_request(ikev2_sa_t *sa)
Definition: ikev2.c:5086
udp_header_t::src_port
u16 src_port
Definition: udp_packet.h:48
ikev2_ts_cmp
static int ikev2_ts_cmp(ikev2_ts_t *ts1, ikev2_ts_t *ts2)
Definition: ikev2.c:1544
auth
vl_api_ikev2_auth_t auth
Definition: ikev2_types.api:88
ikev2_set_profile_sa_lifetime
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:4210
ikev2_sa_transform_t::encr_type
ikev2_transform_encr_type_t encr_type
Definition: ikev2_priv.h:219
ikev2_mngr_process_node
static vlib_node_registration_t ikev2_mngr_process_node
(constructor) VLIB_REGISTER_NODE (ikev2_mngr_process_node)
Definition: ikev2.c:5253
ispi
u64 ispi
Definition: ikev2_types.api:146
ipsec_tun.h
udp_header_t::length
u16 length
Definition: udp_packet.h:51
api.h
ikev2_process_pending_sa_init_one
static void ikev2_process_pending_sa_init_one(vlib_main_t *vm, ikev2_main_t *km, ikev2_sa_t *sa)
Definition: ikev2.c:4993
vlib_worker_thread_barrier_release
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1386
vec_add
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:688
ikev2_stats_t::n_init_retransmit
u16 n_init_retransmit
Definition: ikev2_priv.h:376
ikev2_add_ipsec_tunnel_args_t
Definition: ikev2.c:1832
ikev2_sa_t::ispi
u64 ispi
Definition: ikev2_priv.h:387
ikev2_initiate_delete_ike_sa_internal
static void ikev2_initiate_delete_ike_sa_internal(vlib_main_t *vm, ikev2_main_per_thread_data_t *tkm, ikev2_sa_t *sa, u8 send_notification)
Definition: ikev2.c:3743
ikev2_child_sa_t::sk_er
u8 * sk_er
Definition: ikev2_priv.h:293
IKEV2_PAYLOAD_NONE
#define IKEV2_PAYLOAD_NONE
Definition: ikev2.h:105
ikev2_set_state
#define ikev2_set_state(sa, v,...)
Definition: ikev2.c:43
ikev2_sa_transform_t::dh_type
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:222
ikev2_set_profile_tunnel_interface
clib_error_t * ikev2_set_profile_tunnel_interface(vlib_main_t *vm, u8 *name, u32 sw_if_index)
Definition: ikev2.c:4147
ikev2_main_t::profiles
ikev2_profile_t * profiles
Definition: ikev2_priv.h:489
ikev2_mngr_process_fn
static uword ikev2_mngr_process_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: ikev2.c:5164
ikev2_initiate_rekey_child_sa
clib_error_t * ikev2_initiate_rekey_child_sa(vlib_main_t *vm, u32 ispi)
Definition: ikev2.c:4636
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
end_addr
vl_api_address_t end_addr
Definition: ikev2_types.api:38
ikev2_init_sa
static void ikev2_init_sa(vlib_main_t *vm, ikev2_sa_t *sa)
Definition: ikev2.c:2771
bufs
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:717
ikev2_sa_transform_t::transform_id
u16 transform_id
Definition: ikev2_priv.h:218
ikev2_profile_t::name
u8 * name
Definition: ikev2_priv.h:334
ikev2_sa_proposal_t
Definition: ikev2_priv.h:237
ikev2_profile_t::handover
u32 handover
Definition: ikev2_priv.h:347
ikev2_profile_t::loc_id
ikev2_id_t loc_id
Definition: ikev2_priv.h:337
dst_port
vl_api_ip_port_and_mask_t dst_port
Definition: flow_types.api:92
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
ikev2_del_sa_init_from_main
static void ikev2_del_sa_init_from_main(u64 *ispi)
Definition: ikev2.c:2779
IKEV2_NEXT_IP6_ERROR_DROP
@ IKEV2_NEXT_IP6_ERROR_DROP
Definition: ikev2.c:107
ikev2_get_if_address
static int ikev2_get_if_address(u32 sw_if_index, ip_address_family_t af, ip_address_t *out_addr)
Definition: ikev2.c:4233
ikev2_generate_sa_error_t
ikev2_generate_sa_error_t
Definition: ikev2.c:72
IKEV2_PAYLOAD_TSR
#define IKEV2_PAYLOAD_TSR
Definition: ikev2.h:118
dns_cache_entry_t
Definition: dns.h:55
ikev2_sa_transform_t::integ_type
ikev2_transform_integ_type_t integ_type
Definition: ikev2_priv.h:221
ikev2_delete_child_sa_internal
static void ikev2_delete_child_sa_internal(vlib_main_t *vm, ikev2_sa_t *sa, ikev2_child_sa_t *csa)
Definition: ikev2.c:4471
vec_new
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:365
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
ikev2_update_stats
static void ikev2_update_stats(vlib_main_t *vm, u32 node_index, ikev2_stats_t *s)
Definition: ikev2.c:2872
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
ikev2_profile_t::lifetime_jitter
u32 lifetime_jitter
Definition: ikev2_priv.h:346
ikev2_main_t::vnet_main
vnet_main_t * vnet_main
Definition: ikev2_priv.h:502
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
ip4_main
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1105
ikev2_parse_ts_payload
ikev2_ts_t * ikev2_parse_ts_payload(ike_payload_header_t *ikep, u32 rlen)
Definition: ikev2_payload.c:447
ikev2_sa_proposal_t::spi
u32 spi
Definition: ikev2_priv.h:241
ikev2_ts_t::end_addr
ip_address_t end_addr
Definition: ikev2_priv.h:253
ikev2_ts_t::ts_type
ikev2_traffic_selector_type_t ts_type
Definition: ikev2_priv.h:247
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
ikev2_child_sa_t::is_expired
u8 is_expired
Definition: ikev2_priv.h:303
f
vlib_frame_t * f
Definition: interface_output.c:1080
ikev2_sa_free_all_vec
static void ikev2_sa_free_all_vec(ikev2_sa_t *sa)
Definition: ikev2.c:310
ikev2_sa_t::raddr
ip_address_t raddr
Definition: ikev2_priv.h:386
ikev2_transforms_set::crypto_key_size
u32 crypto_key_size
Definition: ikev2_priv.h:269
IKEV2_GCM_ICV_SIZE
#define IKEV2_GCM_ICV_SIZE
Definition: ikev2.h:28
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
clib_memcmp
#define clib_memcmp(s1, s2, m1)
Definition: string.h:734
tunnel_t_
A representation of an IP tunnel config.
Definition: tunnel.h:85
ikev2_calc_sign
u8 * ikev2_calc_sign(EVP_PKEY *pkey, u8 *data)
Definition: ikev2_crypto.c:782
ikev2_sa_t::state
ikev2_state_t state
Definition: ikev2_priv.h:382
name
string name[64]
Definition: fib.api:25
clib_memset_u16
static_always_inline void clib_memset_u16(void *p, u16 val, uword count)
Definition: string.h:395
ikev2_main_t::liveness_period
u32 liveness_period
Definition: ikev2_priv.h:524
ike_hdr_is_initiator
#define ike_hdr_is_initiator(_h)
Definition: ikev2.h:49
ip6_header_t::protocol
u8 protocol
Definition: ip6_packet.h:304
ikev2_generate_dh
void ikev2_generate_dh(ikev2_sa_t *sa, ikev2_sa_transform_t *t)
Definition: ikev2_crypto.c:498
format_ikev2_id_type
u8 * format_ikev2_id_type(u8 *s, va_list *args)
ike_hdr_is_response
#define ike_hdr_is_response(_h)
Definition: ikev2.h:47
ikev2_add_ipsec_tunnel_args_t::dst_port
u16 dst_port
Definition: ikev2.c:1851
ikev2_main_t::sais
ikev2_sa_t * sais
Definition: ikev2_priv.h:505
ikev2_child_sa_t::salt_er
u32 salt_er
Definition: ikev2_priv.h:295
ikev2_sa_t::liveness_retries
u8 liveness_retries
Definition: ikev2_priv.h:454
vlib_get_buffers
vlib_get_buffers(vm, from, b, n_left_from)
next
u16 * next
Definition: nat44_ei_out2in.c:718
ikev2_del_sa_init
static void ikev2_del_sa_init(u64 ispi)
Definition: ikev2.c:2793
ikev2_rekey_t
Definition: ikev2_priv.h:313
ikev2_add_ipsec_tunnel_args_t::encr_type
ipsec_crypto_alg_t encr_type
Definition: ikev2.c:1842
iaddr
vl_api_address_t iaddr
Definition: ikev2_types.api:148
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
vlib_log_register_class
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:339
IKEV2_GCM_IV_SIZE
#define IKEV2_GCM_IV_SIZE
Definition: ikev2.h:31
ikev2_add_ipsec_tunnel_args_t::sw_if_index
u32 sw_if_index
Definition: ikev2.c:1834
ikev2_payload_chain_t::data
u8 * data
Definition: ikev2_priv.h:574
handover
u32 handover
Definition: ikev2_types.api:83
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
ikev2_load_cert_file
EVP_PKEY * ikev2_load_cert_file(u8 *file)
Definition: ikev2_crypto.c:816
ikev2_payload_add_ke
void ikev2_payload_add_ke(ikev2_payload_chain_t *c, u16 dh_group, u8 *dh_data)
Definition: ikev2_payload.c:224
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip6_header_t::hop_limit
u8 hop_limit
Definition: ip6_packet.h:307
ikev2_sa_t::current_remote_id_mask
u32 current_remote_id_mask
Definition: ikev2_priv.h:447
IKEV2_GENERATE_SA_INIT_OK
@ IKEV2_GENERATE_SA_INIT_OK
Definition: ikev2.c:74
ikev2_load_key_file
EVP_PKEY * ikev2_load_key_file(u8 *file)
Definition: ikev2_crypto.c:847
ikev2_calc_keys
static void ikev2_calc_keys(ikev2_sa_t *sa)
Definition: ikev2.c:483
ikev2_rekey_t::r_proposal
ikev2_sa_proposal_t * r_proposal
Definition: ikev2_priv.h:319
ikev2_process_sa_init_req
static int ikev2_process_sa_init_req(vlib_main_t *vm, ikev2_sa_t *sa, ike_header_t *ike, udp_header_t *udp, u32 len, u32 sw_if_index)
Definition: ikev2.c:696
punt_hdl
static vlib_punt_hdl_t punt_hdl
Definition: ipsec_punt.c:23
ikev2_stats_t
Definition: ikev2_priv.h:370
ikev2_calc_prfplus
u8 * ikev2_calc_prfplus(ikev2_sa_transform_t *tr, u8 *key, u8 *seed, int len)
Definition: ikev2_crypto.c:272
ikev2_insert_non_esp_marker
static_always_inline int ikev2_insert_non_esp_marker(ike_header_t *ike, int len)
Definition: ikev2.c:120
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
IKEV2_PAYLOAD_NONCE
#define IKEV2_PAYLOAD_NONCE
Definition: ikev2.h:113
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
ikev2_compute_nat_sha1
static_always_inline u8 * ikev2_compute_nat_sha1(u64 ispi, u64 rspi, ip_address_t *ia, u16 port)
Definition: ikev2.c:642
DNS_API_PENDING_NAME_TO_IP
@ DNS_API_PENDING_NAME_TO_IP
Definition: dns.h:49
IKEV2_STATE_DELETED
@ IKEV2_STATE_DELETED
Definition: ikev2_priv.h:191
vec_append
#define vec_append(v1, v2)
Append v2 after v1.
Definition: vec.h:911
ikev2_sa_t::i_proposals
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:400
ikev2_sa_transform_t
Definition: ikev2_priv.h:213
ikev2_select_profile
static ikev2_profile_t * ikev2_select_profile(ikev2_main_t *km, ikev2_sa_t *sa, ikev2_sa_transform_t *tr_prf, u8 *key_pad)
Definition: ikev2.c:1626
TS_IPV4_ADDR_RANGE
@ TS_IPV4_ADDR_RANGE
Definition: ikev2.h:379
IKEV2_NEXT_IP4_LOOKUP
@ IKEV2_NEXT_IP4_LOOKUP
Definition: ikev2.c:99
ikev2_transforms_set::integ_alg
ikev2_transform_integ_type_t integ_alg
Definition: ikev2_priv.h:267
ipip_tunnel_t::sw_if_index
u32 sw_if_index
Definition: ipip.h:86
u16
unsigned short u16
Definition: types.h:57
ikev2_sa_t::last_res_packet_data
u8 * last_res_packet_data
Definition: ikev2_priv.h:435
ikev2_rekey_t::i_proposal
ikev2_sa_proposal_t * i_proposal
Definition: ikev2_priv.h:318
ikev2_sa_t::new_child
ikev2_rekey_t * new_child
Definition: ikev2_priv.h:426
ikev2_child_sa_t::time_to_expiration
f64 time_to_expiration
Definition: ikev2_priv.h:302
ikev2_main_t::profile_index_by_name
mhash_t profile_index_by_name
Definition: ikev2_priv.h:495
IKEV2_STATE_NO_PROPOSAL_CHOSEN
@ IKEV2_STATE_NO_PROPOSAL_CHOSEN
Definition: ikev2_priv.h:196
ikev2_auth_t::method
ikev2_auth_method_t method
Definition: ikev2_priv.h:201
ikev2_sa_t::init_response_received
u8 init_response_received
Definition: ikev2_priv.h:450
ikev2_profile_t::ike_ts
ikev2_transforms_set ike_ts
Definition: ikev2_priv.h:342
ikev2_complete_sa_data
static void ikev2_complete_sa_data(ikev2_sa_t *sa, ikev2_sa_t *sai)
Definition: ikev2.c:419
ikev2_auth_t::hex
u8 hex
Definition: ikev2_priv.h:203
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
mhash_get
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
IKE_VERSION_2
#define IKE_VERSION_2
Definition: ikev2.h:92
IKEV2_EXCHANGE_SA_INIT
#define IKEV2_EXCHANGE_SA_INIT
Definition: ikev2.h:94
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
IKEV2_STATE_AUTH_FAILED
@ IKEV2_STATE_AUTH_FAILED
Definition: ikev2_priv.h:192
ikev2_transforms_set::crypto_alg
ikev2_transform_encr_type_t crypto_alg
Definition: ikev2_priv.h:266
IKEV2_PROTOCOL_ESP
@ IKEV2_PROTOCOL_ESP
Definition: ikev2.h:125
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
ikev2_set_ts_type
static_always_inline void ikev2_set_ts_type(ikev2_ts_t *ts, const ip_address_t *addr)
Definition: ikev2.c:3999
ikev2_delete_tunnel_interface
static int ikev2_delete_tunnel_interface(vnet_main_t *vnm, ikev2_sa_t *sa, ikev2_child_sa_t *child)
Definition: ikev2.c:2260
ikev2_sa_auth
static void ikev2_sa_auth(ikev2_sa_t *sa)
Definition: ikev2.c:1701
ikev2_sa_t::i_id
ikev2_id_t i_id
Definition: ikev2_priv.h:417
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
node_index
node node_index
Definition: interface_output.c:420
ikev2_sa_t::r_dh_data
u8 * r_dh_data
Definition: ikev2_priv.h:397
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
port
u16 port
Definition: lb_types.api:73
plugin.h
ikev2_profile_index_by_name
static ikev2_profile_t * ikev2_profile_index_by_name(u8 *name)
Definition: ikev2.c:3614
ikev2_encrypt_data
int ikev2_encrypt_data(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa, ikev2_sa_transform_t *tr_encr, v8 *src, u8 *dst)
Definition: ikev2_crypto.c:453
ikev2_sa_t::childs
ikev2_child_sa_t * childs
Definition: ikev2_priv.h:452
ikev2_main_t::dns_resolve_name
int(* dns_resolve_name)()
Definition: ikev2_priv.h:533
stats
vl_api_ikev2_sa_stats_t stats
Definition: ikev2_types.api:162
ikev2_mk_local_sa_id
static u32 ikev2_mk_local_sa_id(u32 sai, u32 ci, u32 ti)
Definition: ikev2.c:1821
ikev2_set_profile_esp_transforms
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, u32 crypto_key_size)
Definition: ikev2.c:4124
ikev2_sa_t::last_init_msg_id
u32 last_init_msg_id
Definition: ikev2_priv.h:439
vlib_buffer_enqueue_to_next
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
ikev2_set_ip_address
static_always_inline void ikev2_set_ip_address(ikev2_sa_t *sa, const void *iaddr, const void *raddr, const ip_address_family_t af)
Definition: ikev2.c:2830
TUNNEL_FLAG_NONE
@ TUNNEL_FLAG_NONE
Definition: tunnel.h:71
IKEV2_NATT_ACTIVE
@ IKEV2_NATT_ACTIVE
Definition: ikev2_priv.h:365
IPSEC_PROTOCOL_ESP
@ IPSEC_PROTOCOL_ESP
Definition: ipsec_sa.h:76
ikev2_main_t::sa_by_ispi
uword * sa_by_ispi
Definition: ikev2_priv.h:507
IKEV2_PAYLOAD_TSI
#define IKEV2_PAYLOAD_TSI
Definition: ikev2.h:117
vlib_punt_register
int vlib_punt_register(vlib_punt_hdl_t client, vlib_punt_reason_t reason, const char *node_name)
Register a node to receive particular punted buffers.
Definition: punt.c:283
start_addr
vl_api_address_t start_addr
Definition: ikev2_types.api:37
ikev2_set_local_key
clib_error_t * ikev2_set_local_key(vlib_main_t *vm, u8 *file)
Definition: ikev2.c:3711
ikev2_transforms_set::dh_type
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:268
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
ikev2_add_ipsec_tunnel_args_t::src_port
u16 src_port
Definition: ikev2.c:1850
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1071
ikev2_select_proposal
static ikev2_sa_proposal_t * ikev2_select_proposal(ikev2_sa_proposal_t *proposals, ikev2_protocol_id_t prot_id)
Definition: ikev2.c:156
ikev2_add_ipsec_tunnel_args_t::local_ip
ip_address_t local_ip
Definition: ikev2.c:1844
vlib_frame_t
Definition: node.h:372
ikev2_node_internal
static_always_inline uword ikev2_node_internal(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u8 is_ip4, u8 natt)
Definition: ikev2.c:2885
hash_create
#define hash_create(elts, value_bytes)
Definition: hash.h:695
vlib_get_frame_to_node
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:184
plaintext
static u8 plaintext[]
Definition: aes_cbc.c:29
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
ip6_lookup_node
vlib_node_registration_t ip6_lookup_node
(constructor) VLIB_REGISTER_NODE (ip6_lookup_node)
Definition: ip6_forward.c:741
ikev2_delete_t::protocol_id
u8 protocol_id
Definition: ikev2_priv.h:309
IKEV2_PAYLOAD_NOTIFY
#define IKEV2_PAYLOAD_NOTIFY
Definition: ikev2.h:114
ikev2_rekey_t::spi
u32 spi
Definition: ikev2_priv.h:316
ikev2_stats_t::n_sa_auth_req
u16 n_sa_auth_req
Definition: ikev2_priv.h:374
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
ikev2_set_profile_id
clib_error_t * ikev2_set_profile_id(vlib_main_t *vm, u8 *name, u8 id_type, u8 *data, int is_local)
Definition: ikev2.c:3961
ikev2_elog_uint_peers
#define ikev2_elog_uint_peers(_level, _format, _val, _ip1, _ip2)
Definition: ikev2_priv.h:143
ipip_tunnel_t
A representation of a IPIP tunnel.
Definition: ipip.h:75
ikev2_sa_t
Definition: ikev2_priv.h:380
ikev2_main_t::log_class
vlib_log_class_t log_class
Definition: ikev2_priv.h:518
ip4_header_t::tos
ip_dscp_t tos
Definition: ip4_packet.h:96
ikev2_stats_t::n_sa_init_req
u16 n_sa_init_req
Definition: ikev2_priv.h:375
raddr
vl_api_address_t raddr
Definition: ikev2_types.api:149
error
Definition: cJSON.c:88
ikev2_priv.h
ikev2_main_t::log_level
ikev2_log_level_t log_level
Definition: ikev2_priv.h:521
ip4_header_t::length
u16 length
Definition: ip4_packet.h:99
dns_resolve_name_t
Definition: dns.h:42
ikev2_child_sa_t::sk_ei
u8 * sk_ei
Definition: ikev2_priv.h:292
log_level
log_level
Definition: vpe_types.api:33
ikev2_set_profile_ipsec_udp_port
vnet_api_error_t ikev2_set_profile_ipsec_udp_port(vlib_main_t *vm, u8 *name, u16 port, u8 is_set)
Definition: ikev2.c:4167
ikev2_sa_t::rspi
u64 rspi
Definition: ikev2_priv.h:388
ph
pool_header_t * ph(void *p)
GDB callable function: ph - call pool_header - get pool header.
Definition: gdb_funcs.c:78
key
typedef key
Definition: ipsec_types.api:88
ikev2_child_sa_t::sk_ar
u8 * sk_ar
Definition: ikev2_priv.h:291
format_clib_error
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
ip_address_size
u16 ip_address_size(const ip_address_t *a)
Definition: ip_types.c:87
ikev2_profile_t::loc_ts
ikev2_ts_t loc_ts
Definition: ikev2_priv.h:339
ikev2_payload_new_chain
#define ikev2_payload_new_chain(V)
Definition: ikev2_priv.h:577
ikev2_payload_add_delete
void ikev2_payload_add_delete(ikev2_payload_chain_t *c, ikev2_delete_t *d)
Definition: ikev2_payload.c:255
ikev2_responder_t::sw_if_index
u32 sw_if_index
Definition: ikev2_priv.h:258
ipsec_unregister_udp_port
void ipsec_unregister_udp_port(u16 port)
Definition: ipsec.c:128
ikev2_add_ipsec_tunnel_args_t::local_spi
u32 local_spi
Definition: ikev2.c:1840
ikev2_main_t::per_thread_data
ikev2_main_per_thread_data_t * per_thread_data
Definition: ikev2_priv.h:509
ikev2_sa_t::sw_if_index
u32 sw_if_index
Definition: ikev2_priv.h:458
ikev2_delete_sa
static void ikev2_delete_sa(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa)
Definition: ikev2.c:354
random_u32
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
IKEV2_PAYLOAD_IDI
#define IKEV2_PAYLOAD_IDI
Definition: ikev2.h:110
ikev2_sa_proposal_t::proposal_num
u8 proposal_num
Definition: ikev2_priv.h:239
ikev2_sa_t::i_auth
ikev2_auth_t i_auth
Definition: ikev2_priv.h:413
ikev2_verify_sign
int ikev2_verify_sign(EVP_PKEY *pkey, u8 *sigbuf, u8 *data)
Definition: ikev2_crypto.c:753
ikev2_responder_t::addr
ip_address_t addr
Definition: ikev2_priv.h:259
ikev2_parse_delete_payload
ikev2_delete_t * ikev2_parse_delete_payload(ike_payload_header_t *ikep, u32 rlen)
Definition: ikev2_payload.c:560
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
ikev2_payload_add_notify
void ikev2_payload_add_notify(ikev2_payload_chain_t *c, u16 msg_type, u8 *data)
Definition: ikev2_payload.c:142
ikev2_elog_uint
#define ikev2_elog_uint(_level, _format, _val)
Definition: ikev2_priv.h:124
ikev2_main_t::pkey
EVP_PKEY * pkey
Definition: ikev2_priv.h:498
ikev2_decrypt_data
int ikev2_decrypt_data(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa, ikev2_sa_transform_t *tr_encr, u8 *data, int len, u32 *out_len)
Definition: ikev2_crypto.c:389
ikev2_profile_t::rem_ts
ikev2_ts_t rem_ts
Definition: ikev2_priv.h:340
ikev2_node_ip6
static vlib_node_registration_t ikev2_node_ip6
(constructor) VLIB_REGISTER_NODE (ikev2_node_ip6)
Definition: ikev2.c:3467
ikev2_del_ipsec_tunnel_args_t
Definition: ikev2.c:2196
ikev2_generate_sa_init_data_and_log
static void ikev2_generate_sa_init_data_and_log(ikev2_sa_t *sa)
Definition: ikev2.c:2858
vlib_process_get_events
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
Definition: node_funcs.h:583
ikev2_set_initiator_proposals
static clib_error_t * ikev2_set_initiator_proposals(vlib_main_t *vm, ikev2_sa_t *sa, ikev2_transforms_set *ts, ikev2_sa_proposal_t **proposals, int is_ike)
Definition: ikev2.c:3487
vlib_buffer_t::current_data
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
vlib_put_frame_to_node
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:218
vlib_thread_main_t::n_vlib_mains
u32 n_vlib_mains
Definition: threads.h:283
IPSEC_UDP_PORT_NONE
#define IPSEC_UDP_PORT_NONE
Definition: ipsec_sa.h:299
ti
u32 ti
Definition: interface_output.c:405
ip_addr_version
#define ip_addr_version(_a)
Definition: ip_types.h:93
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
ip_address_copy_addr
void ip_address_copy_addr(void *dst, const ip_address_t *src)
Definition: ip_types.c:164
ikev2_payload_chain_t::first_payload_type
u8 first_payload_type
Definition: ikev2_priv.h:572
start_port
u16 start_port
Definition: ikev2_types.api:35
ipsec_sa_flags_t
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
ikev2_flip_alternate_sa_bit
static_always_inline u32 ikev2_flip_alternate_sa_bit(u32 id)
Definition: ikev2.c:2206
ikev2_unregister_udp_port
static_always_inline void ikev2_unregister_udp_port(ikev2_profile_t *p)
Definition: ikev2.c:3733
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
ikev2_child_sa_t::local_sa_id
u32 local_sa_id
Definition: ikev2_priv.h:298
IPIP_TRANSPORT_IP4
@ IPIP_TRANSPORT_IP4
Definition: ipip.h:49
ikev2_add_ipsec_tunnel_args_t::ipsec_over_udp_port
u16 ipsec_over_udp_port
Definition: ikev2.c:1849
IKEV2_PAYLOAD_IDR
#define IKEV2_PAYLOAD_IDR
Definition: ikev2.h:111
hostname
string hostname[64]
Definition: dhcp.api:159
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
ikev2_init
clib_error_t * ikev2_init(vlib_main_t *vm)
Definition: ikev2.c:4744
ikev2_delete_t
Definition: ikev2_priv.h:307
ikev2_set_ts_addrs
static_always_inline void ikev2_set_ts_addrs(ikev2_ts_t *ts, const ip_address_t *start, const ip_address_t *end)
Definition: ikev2.c:4008
vnet_sw_interface_admin_up
void vnet_sw_interface_admin_up(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface.c:533
ikev2_del_ipsec_tunnel_args_t::local_sa_id
u32 local_sa_id
Definition: ikev2.c:2201
len
u8 len
Definition: ip_types.api:103
error.h
IKEV2_KEY_PAD
#define IKEV2_KEY_PAD
Definition: ikev2.h:26
random.h
ikev2_sa_transform_t::block_size
u16 block_size
Definition: ikev2_priv.h:228
vec_add2
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:644
v8
u8 v8
Definition: ikev2.h:33
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
ikev2_profile_t
Definition: ikev2_priv.h:332
ikev2_sa_t::sk_pi
u8 * sk_pi
Definition: ikev2_priv.h:409
ikev2_auth_t::key
EVP_PKEY * key
Definition: ikev2_priv.h:204
IKEV2_PROTOCOL_AH
@ IKEV2_PROTOCOL_AH
Definition: ikev2.h:124
ikev2_add_ipsec_tunnel_args_t::flags
ipsec_sa_flags_t flags
Definition: ikev2.c:1839
ikev2_parse_auth_payload
static int ikev2_parse_auth_payload(const void *p, u32 rlen, ikev2_auth_t *a)
Definition: ikev2.c:1111
ikev2_add_ipsec_tunnel_args_t::remote_spi
u32 remote_spi
Definition: ikev2.c:1841
dns_resolve_name_t::address
ip_address_t address
Definition: dns.h:44
ikev2_ip4_natt
static uword ikev2_ip4_natt(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ikev2.c:3420
ikev2_profile_free
static void ikev2_profile_free(ikev2_profile_t *p)
Definition: ikev2.c:3867
ikev2_id_t::data
u8 * data
Definition: ikev2_priv.h:276
vlib_buffer_alloc
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:708
ikev2_initiate_delete_child_sa
clib_error_t * ikev2_initiate_delete_child_sa(vlib_main_t *vm, u32 ispi)
Definition: ikev2.c:4513
key_trunc
u16 key_trunc
Definition: ikev2_types.api:96
ikev2_calc_prf
v8 * ikev2_calc_prf(ikev2_sa_transform_t *tr, v8 *key, v8 *data)
Definition: ikev2_crypto.c:255
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
vec_dup
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:444
ikev2_profile_t::ipsec_over_udp_port
u16 ipsec_over_udp_port
Definition: ikev2_priv.h:348
ikev2_rekey_t::ispi
u32 ispi
Definition: ikev2_priv.h:317
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
ip_addr_v6
#define ip_addr_v6(_a)
Definition: ip_types.h:92
IKEV2_GENERATE_SA_INIT_OK_ERR_NO_DH_STR
#define IKEV2_GENERATE_SA_INIT_OK_ERR_NO_DH_STR
Definition: ikev2.c:67
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
ipsec_sa_counters
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
Definition: ipsec_sa.c:27
ikev2_sa_t::sk_ar
u8 * sk_ar
Definition: ikev2_priv.h:406
ikev2_ts_t::protocol_id
u8 protocol_id
Definition: ikev2_priv.h:248
IKEV2_HDR_FLAG_INITIATOR
#define IKEV2_HDR_FLAG_INITIATOR
Definition: ikev2.h:99
vlib_worker_thread_barrier_sync
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:194
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ikev2_ip6_next_t
ikev2_ip6_next_t
Definition: ikev2.c:104
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:208
ikev2_ts_t::end_port
u16 end_port
Definition: ikev2_priv.h:251
ikev2_mngr_process_ipsec_sa
static void ikev2_mngr_process_ipsec_sa(ipsec_sa_t *ipsec_sa)
Definition: ikev2.c:4949
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
ikev2_sa_proposal_t::transforms
ikev2_sa_transform_t * transforms
Definition: ikev2_priv.h:242
end
f64 end
end of the time range
Definition: mactime.api:44
ikev2_child_sa_t::rekey_retries
i8 rekey_retries
Definition: ikev2_priv.h:304
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
ikev2_stats_t::n_rekey_req
u16 n_rekey_req
Definition: ikev2_priv.h:373
ikev2_main_t::supported_transforms
ikev2_sa_transform_t * supported_transforms
Definition: ikev2_priv.h:492
ikev2_sa_t::dh_private_key
u8 * dh_private_key
Definition: ikev2_priv.h:395
ikev2_get_port
static_always_inline u16 ikev2_get_port(ikev2_sa_t *sa)
Definition: ikev2.c:114
ikev2_transforms_set
Definition: ikev2_priv.h:264
ipsec_punt.h
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
ikev2_trace_t::next_index
u32 next_index
Definition: ikev2.c:50
ikev2_elog_uint_peers_addr
static void ikev2_elog_uint_peers_addr(u32 exchange, ip4_header_t *ip4, ip6_header_t *ip6, u8 is_ip4)
Definition: ikev2.c:2838
static_always_inline
#define static_always_inline
Definition: clib.h:112
ikev2_parse_notify_payload
ikev2_notify_t * ikev2_parse_notify_payload(ike_payload_header_t *ikep, u32 rlen)
Definition: ikev2_payload.c:505
ikev2_node_ip4
static vlib_node_registration_t ikev2_node_ip4
(constructor) VLIB_REGISTER_NODE (ikev2_node_ip4)
Definition: ikev2.c:3433
ikev2_rewrite_v6_addrs
static_always_inline void ikev2_rewrite_v6_addrs(ikev2_sa_t *sa, ip6_header_t *ih)
Definition: ikev2.c:2800
IKEV2_NEXT_IP4_ERROR_DROP
@ IKEV2_NEXT_IP4_ERROR_DROP
Definition: ikev2.c:100
ikev2_elog_exchange
#define ikev2_elog_exchange(_fmt, _ispi, _rspi, _addr, _v4)
Definition: ikev2_priv.h:116
ikev2_sa_t::old_remote_id
u32 old_remote_id
Definition: ikev2_priv.h:448
ikev2_is_id_supported
static int ikev2_is_id_supported(u8 id_type)
Definition: ikev2.c:3952
mhash_init_vec_string
static void mhash_init_vec_string(mhash_t *h, uword n_value_bytes)
Definition: mhash.h:84
IKEV2_STATE_NOTIFY_AND_DELETE
@ IKEV2_STATE_NOTIFY_AND_DELETE
Definition: ikev2_priv.h:194
ipsec_tun_protect_update
int ipsec_tun_protect_update(u32 sw_if_index, const ip_address_t *nh, u32 sa_out, u32 *sas_in)
Definition: ipsec_tun.c:564
ikev2_sa_t::r_id
ikev2_id_t r_id
Definition: ikev2_priv.h:418
uword
u64 uword
Definition: types.h:112
ikev2_sa_t::last_sa_init_res_packet_data
u8 * last_sa_init_res_packet_data
Definition: ikev2_priv.h:430
ikev2_sa_transform_t::attrs
u8 * attrs
Definition: ikev2_priv.h:225
lifetime
u64 lifetime
Definition: ikev2_types.api:80
if
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
hash_get
#define hash_get(h, key)
Definition: hash.h:249
ikev2_add_ipsec_tunnel_args_t::local_sa_id
u32 local_sa_id
Definition: ikev2.c:1837
ikev2_sa_t::dst_port
u16 dst_port
Definition: ikev2_priv.h:457
ikev2_encrypt_aead_data
int ikev2_encrypt_aead_data(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa, ikev2_sa_transform_t *tr_encr, v8 *src, u8 *dst, u8 *aad, u32 aad_len, u8 *tag)
Definition: ikev2_crypto.c:422
ip_addr_v4
#define ip_addr_v4(_a)
Definition: ip_types.h:91
ikev2_send_ike
static void ikev2_send_ike(vlib_main_t *vm, ip_address_t *src, ip_address_t *dst, u32 bi0, u32 len, u16 src_port, u16 dst_port, u32 sw_if_index)
Definition: ikev2.c:3628
IKEV2_PROTOCOL_IKE
@ IKEV2_PROTOCOL_IKE
Definition: ikev2.h:123
hash_foreach
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:441
format_ikev2_gen_sa_error
static u8 * format_ikev2_gen_sa_error(u8 *s, va_list *args)
Definition: ikev2.c:80
ikev2_process_auth_req
static int ikev2_process_auth_req(vlib_main_t *vm, ikev2_sa_t *sa, ike_header_t *ike, u32 len)
Definition: ikev2.c:1123
ikev2_add_tunnel_from_main
static void ikev2_add_tunnel_from_main(ikev2_add_ipsec_tunnel_args_t *a)
Definition: ikev2.c:1855
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
udp_register_dst_port
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
ikev2_main_t::dpd_disabled
u8 dpd_disabled
Definition: ikev2_priv.h:530
src_port
vl_api_ip_port_and_mask_t src_port
Definition: flow_types.api:91
ikev2_set_profile_responder
clib_error_t * ikev2_set_profile_responder(vlib_main_t *vm, u8 *name, u32 sw_if_index, ip_address_t addr)
Definition: ikev2.c:4077
crypto_key_size
u32 crypto_key_size
Definition: ikev2_types.api:58
ikev2_child_sa_t::tsi
ikev2_ts_t * tsi
Definition: ikev2_priv.h:286
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
ikev2_child_sa_t::remote_sa_id
u32 remote_sa_id
Definition: ikev2_priv.h:299
ikev2_node_ip4_natt
static vlib_node_registration_t ikev2_node_ip4_natt
(constructor) VLIB_REGISTER_NODE (ikev2_node_ip4_natt)
Definition: ikev2.c:3450
f64
double f64
Definition: types.h:142
ikev2.h
ip_address_initializer
#define ip_address_initializer
Definition: ip_types.h:88
ikev2_add_ipsec_tunnel_args_t::is_rekey
u8 is_rekey
Definition: ikev2.c:1847
ip6_header_t::dst_address
ip6_address_t dst_address
Definition: ip6_packet.h:310
ikev2_sa_t::udp_encap
u8 udp_encap
Definition: ikev2_priv.h:443
ikev2_del_ipsec_tunnel_args_t::local_ip
ip46_address_t local_ip
Definition: ikev2.c:2198
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
ikev2_child_sa_t::r_proposals
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:283
ikev2_main_per_thread_data_t
Definition: ikev2_priv.h:468
ikev2_sa_match_ts
static void ikev2_sa_match_ts(ikev2_sa_t *sa)
Definition: ikev2.c:1556
ikev2_profile_t::natt_disabled
u8 natt_disabled
Definition: ikev2_priv.h:352
ipsec_key_t_
Definition: ipsec_sa.h:80
ikev2_main_t::sw_if_indices
uword * sw_if_indices
Definition: ikev2_priv.h:512
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
ikev2_find_ike_notify_payload
u8 * ikev2_find_ike_notify_payload(ike_header_t *ike, u32 msg_type)
Definition: ikev2_payload.c:592
ikev2_sa_t::last_msg_id
u32 last_msg_id
Definition: ikev2_priv.h:434
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
ikev2_add_ipsec_tunnel_args_t::integ_type
ipsec_integ_alg_t integ_type
Definition: ikev2.c:1843
ipsec_register_udp_port
void ipsec_register_udp_port(u16 port)
Definition: ipsec.c:153
ip4_header_t::checksum
u16 checksum
Definition: ip4_packet.h:118
src
vl_api_address_t src
Definition: gre.api:54
IKEV2_IP6_N_NEXT
@ IKEV2_IP6_N_NEXT
Definition: ikev2.c:108
ikev2_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ikev2_priv.h:501
ikev2_generate_message
static u32 ikev2_generate_message(vlib_buffer_t *b, ikev2_sa_t *sa, ike_header_t *ike, void *user, udp_header_t *udp, ikev2_stats_t *stats)
Definition: ikev2.c:2288
ikev2_decrypt_sk_payload
static u8 * ikev2_decrypt_sk_payload(ikev2_sa_t *sa, ike_header_t *ike, u8 *payload, u32 rlen, u32 *out_len)
Definition: ikev2.c:915
IKEV2_HDR_FLAG_RESPONSE
#define IKEV2_HDR_FLAG_RESPONSE
Definition: ikev2.h:101
ip_address_to_46
fib_protocol_t ip_address_to_46(const ip_address_t *addr, ip46_address_t *a)
Definition: ip_types.c:252
IKEV2_EXCHANGE_IKE_AUTH
#define IKEV2_EXCHANGE_IKE_AUTH
Definition: ikev2.h:95
ip_address_set
void ip_address_set(ip_address_t *dst, const void *src, ip_address_family_t af)
Definition: ip_types.c:207
ip4_address_t
Definition: ip4_packet.h:50
ikev2_payload_destroy_chain
#define ikev2_payload_destroy_chain(V)
Definition: ikev2_priv.h:578
dns_pending_request_t::request_type
u32 request_type
Definition: dns.h:31
ikev2_payload_add_notify_2
void ikev2_payload_add_notify_2(ikev2_payload_chain_t *c, u16 msg_type, u8 *data, ikev2_notify_t *notify)
Definition: ikev2_payload.c:148
ipip_del_tunnel
int ipip_del_tunnel(u32 sw_if_index)
Definition: ipip.c:832
ikev2_payload_chain_t
Definition: ikev2_priv.h:570
IKEV2_PAYLOAD_KE
#define IKEV2_PAYLOAD_KE
Definition: ikev2.h:109
ikev2_ts_t::start_port
u16 start_port
Definition: ikev2_priv.h:250
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
sa_id
u32 sa_id
Definition: ipsec.api:98
IKEV2_NONCE_SIZE
#define IKEV2_NONCE_SIZE
Definition: ikev2.h:23
ikev2_stats_t::n_retransmit
u16 n_retransmit
Definition: ikev2_priv.h:377
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
ikev2_main_t::liveness_max_retries
u32 liveness_max_retries
Definition: ikev2_priv.h:527
ikev2_initiate_sa_init
clib_error_t * ikev2_initiate_sa_init(vlib_main_t *vm, u8 *name)
Definition: ikev2.c:4286
IKEV2_LIVENESS_PERIOD_CHECK
#define IKEV2_LIVENESS_PERIOD_CHECK
Definition: ikev2.c:35
ip4_header_t::dst_address
ip4_address_t dst_address
Definition: ip4_packet.h:125
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
ikev2_notify_t::data
u8 * data
Definition: ikev2_priv.h:329
IKEV2_LOG_MAX
@ IKEV2_LOG_MAX
Definition: ikev2_priv.h:47
ikev2_set_profile_auth
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:3918
ikev2_add_ipsec_tunnel_args_t::remote_sa_id
u32 remote_sa_id
Definition: ikev2.c:1838
ikev2_log_level_t
enum ikev2_log_level_t_ ikev2_log_level_t
ip4_header_t::fragment_id
u16 fragment_id
Definition: ip4_packet.h:102
ikev2_add_ipsec_tunnel_args_t::salt_local
u32 salt_local
Definition: ikev2.c:1835
udp_header_t::checksum
u16 checksum
Definition: udp_packet.h:55
ikev2_add_ipsec_tunnel_args_t::salt_remote
u32 salt_remote
Definition: ikev2.c:1836
ikev2_is_id_equal
static_always_inline int ikev2_is_id_equal(ikev2_id_t *i1, ikev2_id_t *i2)
Definition: ikev2.c:1025
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2787
VNET_SW_INTERFACE_ADD_DEL_FUNCTION
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(ikev2_sw_interface_add_del)
data
u8 data[128]
Definition: ipsec_types.api:92
IKEV2_STATE_UNKNOWN
@ IKEV2_STATE_UNKNOWN
Definition: ikev2_priv.h:189
ikev2_rewrite_v4_addrs
static_always_inline void ikev2_rewrite_v4_addrs(ikev2_sa_t *sa, ip4_header_t *ih)
Definition: ikev2.c:2815
ikev2_payload_add_ts
void ikev2_payload_add_ts(ikev2_payload_chain_t *c, ikev2_ts_t *ts, u8 type)
Definition: ikev2_payload.c:333
ikev2_sa_proposal_t::protocol_id
ikev2_protocol_id_t protocol_id
Definition: ikev2_priv.h:240
ikev2_profile_t::lifetime_maxdata
u64 lifetime_maxdata
Definition: ikev2_priv.h:345
ipsec_sa_t
Definition: ipsec_sa.h:116
ip_address_is_zero
bool ip_address_is_zero(const ip_address_t *ip)
Definition: ip_types.c:102
id
u8 id[64]
Definition: dhcp.api:160
IKEV2_GENERATE_SA_INIT_ERR_UNSUPPORTED_DH
@ IKEV2_GENERATE_SA_INIT_ERR_UNSUPPORTED_DH
Definition: ikev2.c:76
ikev2_mk_remote_sa_id
static u32 ikev2_mk_remote_sa_id(u32 sai, u32 ci, u32 ti)
Definition: ikev2.c:1827
ike_hdr_is_request
#define ike_hdr_is_request(_h)
Definition: ikev2.h:48
vlib_get_combined_counter
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:272
IKEV2_NATT_DISABLED
@ IKEV2_NATT_DISABLED
Definition: ikev2_priv.h:362
ikev2_profile_t::auth
ikev2_auth_t auth
Definition: ikev2_priv.h:336
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
index
u32 index
Definition: flow_types.api:221
ipsec_mk_key
void ipsec_mk_key(ipsec_key_t *key, const u8 *data, u8 len)
Definition: ipsec_sa.c:57
ikev2_rekey_child_sa_internal
static void ikev2_rekey_child_sa_internal(vlib_main_t *vm, ikev2_sa_t *sa, ikev2_child_sa_t *csa)
Definition: ikev2.c:4590
ikev2_sa_transform_t::esn_type
ikev2_transform_esn_type_t esn_type
Definition: ikev2_priv.h:223
ip4_header_t::src_address
ip4_address_t src_address
Definition: ip4_packet.h:125
ikev2_ts_t::start_addr
ip_address_t start_addr
Definition: ikev2_priv.h:252
ikev2_sa_del
static void ikev2_sa_del(ikev2_profile_t *p, u32 sw_if_index)
Definition: ikev2.c:4682
ikev2_sa_t::r_auth
ikev2_auth_t r_auth
Definition: ikev2_priv.h:414
ikev2_sa_t::is_initiator
u8 is_initiator
Definition: ikev2_priv.h:437
ikev2_sa_t::ipsec_over_udp_port
u16 ipsec_over_udp_port
Definition: ikev2_priv.h:444
ikev2_profile_natt_disable
clib_error_t * ikev2_profile_natt_disable(u8 *name)
Definition: ikev2.c:4938
ikev2_set_profile_ike_transforms
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:4099
IKEV2_PAYLOAD_FLAG_CRITICAL
#define IKEV2_PAYLOAD_FLAG_CRITICAL
Definition: ikev2.h:103
ikev2_register_udp_port
static_always_inline vnet_api_error_t ikev2_register_udp_port(ikev2_profile_t *p, u16 port)
Definition: ikev2.c:3725
ikev2_get_new_ike_header_buff
static u32 ikev2_get_new_ike_header_buff(vlib_main_t *vm, vlib_buffer_t **b)
Definition: ikev2.c:3698
ikev2_natt_active
#define ikev2_natt_active(_sa)
Definition: ikev2_priv.h:368
format_ikev2_trace
static u8 * format_ikev2_trace(u8 *s, va_list *args)
Definition: ikev2.c:55
ikev2_parse_nonce_payload
static int ikev2_parse_nonce_payload(const void *p, u32 rlen, u8 *nonce)
Definition: ikev2.c:674
ikev2_child_sa_t::tsr
ikev2_ts_t * tsr
Definition: ikev2_priv.h:287
spi
u32 spi
Definition: flow_types.api:140
IKEV2_PAYLOAD_VENDOR
#define IKEV2_PAYLOAD_VENDOR
Definition: ikev2.h:116
ip6_interface_first_address
ip6_address_t * ip6_interface_first_address(ip6_main_t *im, u32 sw_if_index)
get first IPv6 interface address
Definition: ip6_forward.c:278
ikev2_log_debug
#define ikev2_log_debug(...)
Definition: ikev2_priv.h:184
u64
unsigned long u64
Definition: types.h:89
ikev2_ip4_next_t
ikev2_ip4_next_t
Definition: ikev2.c:97
ikev2_sa_t::i_nonce
u8 * i_nonce
Definition: ikev2_priv.h:389
vlib_process_wait_for_event_or_clock
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:755
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
ikev2_sa_t::natt_state
ikev2_natt_state_t natt_state
Definition: ikev2_priv.h:461
ikev2_find_transform_data
static ikev2_sa_transform_t * ikev2_find_transform_data(ikev2_sa_transform_t *t)
Definition: ikev2.c:128
IKEV2_PORT
#define IKEV2_PORT
Definition: ikev2.h:24
ikev2_add_ipsec_tunnel_args_t::remote_ip
ip_address_t remote_ip
Definition: ikev2.c:1845
end_port
u16 end_port
Definition: ikev2_types.api:36
ikev2_profile_t::responder
ikev2_responder_t responder
Definition: ikev2_priv.h:341
ikev2_main_per_thread_data_t::hmac_ctx
HMAC_CTX * hmac_ctx
Definition: ikev2_priv.h:479
malformed
malformed
Definition: map.api:441
IKEV2_IP4_N_NEXT
@ IKEV2_IP4_N_NEXT
Definition: ikev2.c:101
ikev2_sa_t::r_proposals
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:401
ikev2_parse_vendor_payload
void ikev2_parse_vendor_payload(ike_payload_header_t *ikep)
Definition: ikev2_payload.c:553
IKEV2_STATE_SA_INIT
@ IKEV2_STATE_SA_INIT
Definition: ikev2_priv.h:190
ikev2_sw_interface_add_del
static clib_error_t * ikev2_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: ikev2.c:4723
IKEV2_GENERATE_SA_INIT_ERR_NO_DH
@ IKEV2_GENERATE_SA_INIT_ERR_NO_DH
Definition: ikev2.c:75
ikev2_cli_reference
void ikev2_cli_reference(void)
Definition: ikev2_cli.c:809
ikev2_child_sa_t::salt_ei
u32 salt_ei
Definition: ikev2_priv.h:294
ikev2_rekey_t::protocol_id
u8 protocol_id
Definition: ikev2_priv.h:315
ikev2_sa_transform_t::key_len
u16 key_len
Definition: ikev2_priv.h:226
vlib_buffer_get_default_data_size
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:122
ikev2_notify_t::protocol_id
u8 protocol_id
Definition: ikev2_priv.h:327
ikev2_process_informational_req
static int ikev2_process_informational_req(vlib_main_t *vm, ikev2_sa_t *sa, ike_header_t *ike, u32 len)
Definition: ikev2.c:1265
buf
u64 buf
Definition: application.c:493
ikev2_sa_t::sk_ei
u8 * sk_ei
Definition: ikev2_priv.h:407
ike
err ikev2 ip6 ike
Definition: ikev2.api:592
u32
unsigned int u32
Definition: types.h:88
ikev2_sa_t::r_nonce
u8 * r_nonce
Definition: ikev2_priv.h:390
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ikev2_responder_t::hostname
u8 * hostname
Definition: ikev2_priv.h:260
ikev2_create_tunnel_interface
static int ikev2_create_tunnel_interface(vlib_main_t *vm, ikev2_sa_t *sa, ikev2_child_sa_t *child, u32 sa_index, u32 child_index, u8 is_rekey)
Definition: ikev2.c:1954
IKEV2_PAYLOAD_SA
#define IKEV2_PAYLOAD_SA
Definition: ikev2.h:108
ikev2_sa_t::profile_index
u32 profile_index
Definition: ikev2_priv.h:440
udp_header_t::dst_port
u16 dst_port
Definition: udp_packet.h:48
integ_alg
u8 integ_alg
Definition: ikev2_types.api:59
ip4_header_t::ttl
u8 ttl
Definition: ip4_packet.h:112
ipip_tunnel_db_find
ipip_tunnel_t * ipip_tunnel_db_find(const ipip_tunnel_key_t *key)
Definition: ipip.c:551
ikev2_rekey_t::tsr
ikev2_ts_t * tsr
Definition: ikev2_priv.h:321
vlib_thread_main_t
Definition: threads.h:264
vlib_counter_t::bytes
counter_t bytes
byte counter
Definition: counter_types.h:29
ip6
vl_api_ip6_address_t ip6
Definition: one.api:424
ipsec_tun_protect_del
int ipsec_tun_protect_del(u32 sw_if_index, const ip_address_t *nh)
Definition: ipsec_tun.c:714
protocol_id
u8 protocol_id
Definition: ikev2_types.api:34
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
ikev2_sa_transform_t::type
ikev2_transform_type_t type
Definition: ikev2_priv.h:215
ikev2_process_create_child_sa_req
static int ikev2_process_create_child_sa_req(vlib_main_t *vm, ikev2_sa_t *sa, ike_header_t *ike, u32 len)
Definition: ikev2.c:1335
IKEV2_LIVENESS_RETRIES
#define IKEV2_LIVENESS_RETRIES
Definition: ikev2.c:34
ikev2_notify_t
Definition: ikev2_priv.h:324
ikev2_mngr_process_responder_sas
static_always_inline int ikev2_mngr_process_responder_sas(ikev2_sa_t *sa)
Definition: ikev2.c:5141
ikev2_sa_t::stats
ikev2_stats_t stats
Definition: ikev2_priv.h:464
ikev2_payload_add_sa
void ikev2_payload_add_sa(ikev2_payload_chain_t *c, ikev2_sa_proposal_t *proposals)
Definition: ikev2_payload.c:170
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
ikev2_set_profile_udp_encap
clib_error_t * ikev2_set_profile_udp_encap(vlib_main_t *vm, u8 *name)
Definition: ikev2.c:4194
ikev2_sa_free_all_child_sa
static void ikev2_sa_free_all_child_sa(ikev2_child_sa_t **childs)
Definition: ikev2.c:294
vl_api_rpc_call_main_thread
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:620
n_left
u32 n_left
Definition: interface_output.c:1078
VLIB_NODE_TYPE_PROCESS
@ VLIB_NODE_TYPE_PROCESS
Definition: node.h:84
ikev2_sa_transform_t::prf_type
ikev2_transform_prf_type_t prf_type
Definition: ikev2_priv.h:220
ikev2_profile_t::rem_id
ikev2_id_t rem_id
Definition: ikev2_priv.h:338
AF_IP6
@ AF_IP6
Definition: ip_types.h:24
to_ip46
static ip46_address_t to_ip46(u32 is_ipv6, u8 *buf)
Definition: ip46_address.h:137
udp.h
vlib_punt_hdl_t
int vlib_punt_hdl_t
Typedef for a client handle.
Definition: punt.h:52
ikev2_parse_ke_payload
static int ikev2_parse_ke_payload(const void *p, u32 rlen, ikev2_sa_t *sa, u8 **ke_data)
Definition: ikev2.c:658
ikev2_rekey_t::tsi
ikev2_ts_t * tsi
Definition: ikev2_priv.h:320
ikev2_resolve_responder_hostname
static clib_error_t * ikev2_resolve_responder_hostname(vlib_main_t *vm, ikev2_responder_t *r)
Definition: ikev2.c:4261
ikev2_payload_add_auth
void ikev2_payload_add_auth(ikev2_payload_chain_t *c, ikev2_auth_t *auth)
Definition: ikev2_payload.c:286
vec_resize
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V,...
Definition: vec.h:296
ikev2_ip4
static uword ikev2_ip4(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ikev2.c:3414
ikev2_sa_t::sk_ai
u8 * sk_ai
Definition: ikev2_priv.h:405
ip6_header_t
Definition: ip6_packet.h:294
ikev2_profile_t::udp_encap
u8 udp_encap
Definition: ikev2_priv.h:351
ip4_header_t::flags_and_fragment_offset
u16 flags_and_fragment_offset
Definition: ip4_packet.h:106
ikev2_sa_t::sk_er
u8 * sk_er
Definition: ikev2_priv.h:408
ikev2_profile_t::esp_ts
ikev2_transforms_set esp_ts
Definition: ikev2_priv.h:343
ikev2_retransmit_sa_init
static u32 ikev2_retransmit_sa_init(ike_header_t *ike, ip_address_t iaddr, ip_address_t raddr, u32 rlen)
Definition: ikev2.c:2708
ikev2_initial_contact_cleanup
static void ikev2_initial_contact_cleanup(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa)
Definition: ikev2.c:1075
ikev2_crypto_init
void ikev2_crypto_init(ikev2_main_t *km)
Definition: ikev2_crypto.c:869
ikev2_ip6
static uword ikev2_ip6(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ikev2.c:3427
ikev2_sa_free_child_sa
static void ikev2_sa_free_child_sa(ikev2_child_sa_t *c)
Definition: ikev2.c:281
ikev2_transform_dh_type_t
ikev2_transform_dh_type_t
Definition: ikev2.h:332
now
f64 now
Definition: nat44_ei_out2in.c:710
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
ikev2_sa_generate_authmsg
static u8 * ikev2_sa_generate_authmsg(ikev2_sa_t *sa, int is_responder)
Definition: ikev2.c:1501
IKEV2_PAYLOAD_SK
#define IKEV2_PAYLOAD_SK
Definition: ikev2.h:119
ikev2_add_ipsec_tunnel_args_t::old_remote_sa_id
u32 old_remote_sa_id
Definition: ikev2.c:1848
ikev2_main
ikev2_main_t ikev2_main
Definition: ikev2.c:37
ikev2_calc_child_keys
static void ikev2_calc_child_keys(ikev2_sa_t *sa, ikev2_child_sa_t *child)
Definition: ikev2.c:571
ikev2_del_ipsec_tunnel_args_t::remote_ip
ip46_address_t remote_ip
Definition: ikev2.c:2199
ip6_header_t::src_address
ip6_address_t src_address
Definition: ip6_packet.h:310
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
ikev2_sa_get_child
ikev2_child_sa_t * ikev2_sa_get_child(ikev2_sa_t *sa, u32 spi, ikev2_protocol_id_t prot_id, int by_initiator)
Definition: ikev2.c:245
vlib_main_t
Definition: main.h:102
IKEV2_NEXT_IP6_LOOKUP
@ IKEV2_NEXT_IP6_LOOKUP
Definition: ikev2.c:106
ikev2_sa_t::sk_pr
u8 * sk_pr
Definition: ikev2_priv.h:410
ikev2_sa_t::dh_group
u16 dh_group
Definition: ikev2_priv.h:393
ikev2_process_sa_init_resp
static void ikev2_process_sa_init_resp(vlib_main_t *vm, ikev2_sa_t *sa, ike_header_t *ike, udp_header_t *udp, u32 len)
Definition: ikev2.c:804
ip4_header_t::ip_version_and_header_length
u8 ip_version_and_header_length
Definition: ip4_packet.h:93
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
VLIB_INITS
#define VLIB_INITS(...)
Definition: init.h:352
ikev2_delete_t::spi
u32 spi
Definition: ikev2_priv.h:310
ikev2_id_t::type
ikev2_id_type_t type
Definition: ikev2_priv.h:275
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
ikev2_sa_t::initial_contact
u8 initial_contact
Definition: ikev2_priv.h:384
u8
unsigned char u8
Definition: types.h:56
ikev2_payload_chain_add_padding
void ikev2_payload_chain_add_padding(ikev2_payload_chain_t *c, int bs)
Definition: ikev2_payload.c:356
clib_error_t
Definition: clib_error.h:21
TS_IPV6_ADDR_RANGE
@ TS_IPV6_ADDR_RANGE
Definition: ikev2.h:380
a
a
Definition: bitmap.h:544
ikev2_main_per_thread_data_t::sas
ikev2_sa_t * sas
Definition: ikev2_priv.h:473
ikev2_sa_t::keys_generated
u8 keys_generated
Definition: ikev2_priv.h:462
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
rt
vnet_interface_output_runtime_t * rt
Definition: interface_output.c:399
ikev2_sa_t::del
ikev2_delete_t * del
Definition: ikev2_priv.h:421
ikev2_calc_integr
v8 * ikev2_calc_integr(ikev2_sa_transform_t *tr, v8 *key, u8 *data, int len)
Definition: ikev2_crypto.c:314
ip4_header_checksum
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:314
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
ikev2_sa_t::last_sa_init_req_packet_data
u8 * last_sa_init_req_packet_data
Definition: ikev2_priv.h:429
ikev2_initiate_delete_ike_sa
clib_error_t * ikev2_initiate_delete_ike_sa(vlib_main_t *vm, u64 ispi)
Definition: ikev2.c:4553
ikev2_add_del_profile
clib_error_t * ikev2_add_del_profile(vlib_main_t *vm, u8 *name, int is_add)
Definition: ikev2.c:3882
ikev2_set_profile_ts
clib_error_t * ikev2_set_profile_ts(vlib_main_t *vm, u8 *name, u8 protocol_id, u16 start_port, u16 end_port, ip_address_t start_addr, ip_address_t end_addr, int is_local)
Definition: ikev2.c:4016
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
ikev2_child_sa_t::sk_ai
u8 * sk_ai
Definition: ikev2_priv.h:290
IKEV2_PAYLOAD_AUTH
#define IKEV2_PAYLOAD_AUTH
Definition: ikev2.h:112
IKEV2_NATT_ENABLED
@ IKEV2_NATT_ENABLED
Definition: ikev2_priv.h:359
ikev2_sa_transform_t::key_trunc
u16 key_trunc
Definition: ikev2_priv.h:227
ikev2_decrypt_aead_data
int ikev2_decrypt_aead_data(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa, ikev2_sa_transform_t *tr_encr, u8 *data, int data_len, u8 *aad, u32 aad_len, u8 *tag, u32 *out_len)
Definition: ikev2_crypto.c:351
ikev2_sa_t::sk_d
u8 * sk_d
Definition: ikev2_priv.h:404
ikev2_profile_responder_free
static void ikev2_profile_responder_free(ikev2_responder_t *r)
Definition: ikev2.c:3861
ikev2_sa_t::liveness_period_check
f64 liveness_period_check
Definition: ikev2_priv.h:455
ikev2_id_t
Definition: ikev2_priv.h:273
ikev2_sa_t::tun_itf
u32 tun_itf
Definition: ikev2_priv.h:442
ikev2_transform_encr_type_t
ikev2_transform_encr_type_t
Definition: ikev2.h:241
ikev2_retransmit_sa_init_one
static u32 ikev2_retransmit_sa_init_one(ikev2_sa_t *sa, ike_header_t *ike, ip_address_t iaddr, ip_address_t raddr, u32 rlen)
Definition: ikev2.c:2638
ikev2_auth_t
Definition: ikev2_priv.h:199
ipip.h
ikev2_disable_dpd
void ikev2_disable_dpd(void)
Definition: ikev2.c:5134
ikev2_sa_auth_init
static void ikev2_sa_auth_init(ikev2_sa_t *sa)
Definition: ikev2.c:1779
ikev2_responder_t
Definition: ikev2_priv.h:256
ikev2_parse_id_payload
static int ikev2_parse_id_payload(const void *p, u16 rlen, ikev2_id_t *sa_id)
Definition: ikev2.c:1096
ikev2_ts_t
Definition: ikev2_priv.h:245
ikev2_parse_sa_payload
ikev2_sa_proposal_t * ikev2_parse_sa_payload(ike_payload_header_t *ikep, u32 rlen)
Definition: ikev2_payload.c:365
ikev2_stats_t::n_keepalives
u16 n_keepalives
Definition: ikev2_priv.h:372
clib_error_free
#define clib_error_free(e)
Definition: error.h:86
nexts
u16 nexts[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:718
ikev2_sa_t::old_id_expiration
f64 old_id_expiration
Definition: ikev2_priv.h:446
ikev2_sa_free_proposal_vector
void ikev2_sa_free_proposal_vector(ikev2_sa_proposal_t **v)
Definition: ikev2.c:261
rv
int __clib_unused rv
Definition: application.c:491
ikev2_elog_error
#define ikev2_elog_error(_msg)
Definition: ikev2_priv.h:170
ikev2_sa_t::rekey
ikev2_rekey_t * rekey
Definition: ikev2_priv.h:424
ip_address_cmp
int ip_address_cmp(const ip_address_t *ip1, const ip_address_t *ip2)
Definition: ip_types.c:117
ikev2_sa_t::unsupported_cp
u8 unsupported_cp
Definition: ikev2_priv.h:383
ikev2_responder_t::is_resolved
u8 is_resolved
Definition: ikev2_priv.h:261
ipsec_sa_t::stat_index
u32 stat_index
Definition: ipsec_sa.h:212
dns_pending_request_t
Definition: dns.h:29
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:325
ipsec_sa_add_and_lock
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 salt, u16 src_port, u16 dst_port, const tunnel_t *tun, u32 *sa_out_index)
Definition: ipsec_sa.c:170
ip4_interface_first_address
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4_forward.c:281
ikev2_complete_dh
void ikev2_complete_dh(ikev2_sa_t *sa, ikev2_sa_transform_t *t)
Definition: ikev2_crypto.c:646
vnet.h
IKEV2_EXCHANGE_CREATE_CHILD_SA
#define IKEV2_EXCHANGE_CREATE_CHILD_SA
Definition: ikev2.h:96
ip6_header_t::payload_length
u16 payload_length
Definition: ip6_packet.h:301
dns.h
vlib_node_runtime_t
Definition: node.h:454
ikev2_check_payload_length
static int ikev2_check_payload_length(const ike_payload_header_t *ikep, int rlen, u16 *plen)
Definition: ikev2.c:684
IKEV2_EXCHANGE_INFORMATIONAL
#define IKEV2_EXCHANGE_INFORMATIONAL
Definition: ikev2.h:97
ikev2_set_log_level
int ikev2_set_log_level(ikev2_log_level_t log_level)
Definition: ikev2.c:4910
ikev2_sa_t::is_tun_itf_set
u8 is_tun_itf_set
Definition: ikev2_priv.h:441
ikev2_set_liveness_params
clib_error_t * ikev2_set_liveness_params(u32 period, u32 max_retries)
Definition: ikev2.c:4925
IKEV2_GENERATE_SA_INIT_OK_ERR_UNSUPP_STR
#define IKEV2_GENERATE_SA_INIT_OK_ERR_UNSUPP_STR
Definition: ikev2.c:69
is_local
bool is_local
Definition: ikev2_types.api:33
ikev2_del_ipsec_tunnel_args_t::sw_if_index
u32 sw_if_index
Definition: ikev2.c:2202
vlib_punt_client_register
vlib_punt_hdl_t vlib_punt_client_register(const char *who)
Register a new clinet.
Definition: punt.c:171
hash_set1
#define hash_set1(h, key)
Definition: hash.h:258
ikev2_initial_contact_cleanup_internal
static void ikev2_initial_contact_cleanup_internal(ikev2_main_per_thread_data_t *ptd, ikev2_sa_t *sa)
Definition: ikev2.c:1040
from
from
Definition: nat44_ei_hairpinning.c:415
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
ikev2_trace_t::sw_if_index
u32 sw_if_index
Definition: ikev2.c:51
ip_address_copy
void ip_address_copy(ip_address_t *dst, const ip_address_t *src)
Definition: ip_types.c:133
rspi
u64 rspi
Definition: ikev2_types.api:147
ikev2_process_pending_sa_init
static void ikev2_process_pending_sa_init(vlib_main_t *vm, ikev2_main_t *km)
Definition: ikev2.c:5067
ikev2_set_profile_responder_hostname
clib_error_t * ikev2_set_profile_responder_hostname(vlib_main_t *vm, u8 *name, u8 *hostname, u32 sw_if_index)
Definition: ikev2.c:4055
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ikev2_main_per_thread_data_t::evp_ctx
EVP_CIPHER_CTX * evp_ctx
Definition: ikev2_priv.h:478
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
ikev2_sa_del_child_sa
static void ikev2_sa_del_child_sa(ikev2_sa_t *sa, ikev2_child_sa_t *child)
Definition: ikev2.c:303
ikev2_get_per_thread_data
static_always_inline ikev2_main_per_thread_data_t * ikev2_get_per_thread_data()
Definition: ikev2_priv.h:613
ikev2_child_sa_t
Definition: ikev2_priv.h:279
clib_atomic_bool_cmp_and_swap
#define clib_atomic_bool_cmp_and_swap(addr, old, new)
Definition: atomics.h:38
IKEV2_PAYLOAD_DELETE
#define IKEV2_PAYLOAD_DELETE
Definition: ikev2.h:115
ikev2_mngr_process_child_sa
static u8 ikev2_mngr_process_child_sa(ikev2_sa_t *sa, ikev2_child_sa_t *csa, u8 del_old_ids)
Definition: ikev2.c:4810
ikev2_transform_integ_type_t
ikev2_transform_integ_type_t
Definition: ikev2.h:282
mhash_set_mem
__clib_export uword mhash_set_mem(mhash_t *h, void *key, uword *new_value, uword *old_value)
Definition: mhash.c:264
ipsec_sa_unlock_id
int ipsec_sa_unlock_id(u32 id)
Definition: ipsec_sa.c:402
ipsec_sa_t::spi
u32 spi
Definition: ipsec_sa.h:131
ikev2_cleanup_profile_sessions
static void ikev2_cleanup_profile_sessions(ikev2_main_t *km, ikev2_profile_t *p)
Definition: ikev2.c:3815
ikev2_sa_get_td_for_type
ikev2_sa_transform_t * ikev2_sa_get_td_for_type(ikev2_sa_proposal_t *p, ikev2_transform_type_t type)
Definition: ikev2.c:228
ikev2_auth_t::data
u8 * data
Definition: ikev2_priv.h:202
mhash_unset
__clib_export uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:346
vnet_sw_interface_admin_down
void vnet_sw_interface_admin_down(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface.c:546
ip6_header_t::ip_version_traffic_class_and_flow_label
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:297
ipsec_punt_reason
vlib_punt_reason_t ipsec_punt_reason[IPSEC_PUNT_N_REASONS]
Definition: ipsec_punt.c:25
ipsec_sa_pool
ipsec_sa_t * ipsec_sa_pool
Pool of IPSec SAs.
Definition: ipsec_sa.c:32
ikev2_generate_sa_init_data
static ikev2_generate_sa_error_t ikev2_generate_sa_init_data(ikev2_sa_t *sa)
Definition: ikev2.c:369
ikev2_main_per_thread_data_t::sa_by_rspi
uword * sa_by_rspi
Definition: ikev2_priv.h:476
IKEV2_STATE_TS_UNACCEPTABLE
@ IKEV2_STATE_TS_UNACCEPTABLE
Definition: ikev2_priv.h:195
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ikev2_sa_t::iaddr
ip_address_t iaddr
Definition: ikev2_priv.h:385
ipip_add_tunnel
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:722
ip4_header_t::protocol
u8 protocol
Definition: ip4_packet.h:115
ikev2_non_esp_marker
u32 ikev2_non_esp_marker
Definition: ikev2.c:111
vec_del1
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:896
ikev2_sa_t::old_remote_id_present
u8 old_remote_id_present
Definition: ikev2_priv.h:449
ikev2_notify_t::msg_type
u16 msg_type
Definition: ikev2_priv.h:326
tunnel_t_::t_flags
tunnel_flags_t t_flags
Definition: tunnel.h:90
ip_addr_bytes
u8 * ip_addr_bytes(ip_address_t *ip)
Definition: ip_types.c:149
ikev2_sa_t::dh_shared_key
u8 * dh_shared_key
Definition: ikev2_priv.h:394
vnet_api_error_t
vnet_api_error_t
Definition: api_errno.h:162
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
ikev2_notify_t::spi
u32 spi
Definition: ikev2_priv.h:328
ikev2_retransmit_resp
static u32 ikev2_retransmit_resp(ikev2_sa_t *sa, ike_header_t *ike)
Definition: ikev2.c:2728
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t
ikev2_payload_add_id
void ikev2_payload_add_id(ikev2_payload_chain_t *c, ikev2_id_t *id, u8 type)
Definition: ikev2_payload.c:243
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
ikev2_trace_t
Definition: ikev2.c:48
vlib_get_plugin_symbol
void * vlib_get_plugin_symbol(char *plugin_name, char *symbol_name)
Definition: plugin.c:38
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
ikev2_del_ipsec_tunnel_args_t::remote_sa_id
u32 remote_sa_id
Definition: ikev2.c:2200
ikev2_profile_t::lifetime
u64 lifetime
Definition: ikev2_priv.h:344
ikev2_transform_type_t
ikev2_transform_type_t
Definition: ikev2.h:217