FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
snat_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /**
17  * @file
18  * @brief SNAT plugin API implementation
19  */
20 
21 #include <snat/snat.h>
22 #include <snat/snat_det.h>
23 #include <snat/nat64.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 #include <vlibsocket/api.h>
27 #include <snat/snat_msg_enum.h>
28 #include <vnet/fib/fib_table.h>
29 
30 /* define message structures */
31 #define vl_typedefs
32 #include <snat/snat_all_api_h.h>
33 #undef vl_typedefs
34 
35 /* define generated endian-swappers */
36 #define vl_endianfun
37 #include <snat/snat_all_api_h.h>
38 #undef vl_endianfun
39 
40 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
41 
42 #define REPLY_MSG_ID_BASE sm->msg_id_base
44 
45 /* Get the API version number */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <snat/snat_all_api_h.h>
48 #undef vl_api_version
49 
50 /* Macro to finish up custom dump fns */
51 #define FINISH \
52  vec_add1 (s, 0); \
53  vl_print (handle, (char *)s); \
54  vec_free (s); \
55  return handle;
56 
57 static void
60 {
61  snat_main_t *sm = &snat_main;
62  vl_api_snat_add_address_range_reply_t *rmp;
63  ip4_address_t this_addr;
64  u32 start_host_order, end_host_order;
65  u32 vrf_id;
66  int i, count;
67  int rv = 0;
68  u32 *tmp;
69 
70  if (mp->is_ip4 != 1)
71  {
72  rv = VNET_API_ERROR_UNIMPLEMENTED;
73  goto send_reply;
74  }
75 
76  if (sm->static_mapping_only)
77  {
78  rv = VNET_API_ERROR_FEATURE_DISABLED;
79  goto send_reply;
80  }
81 
82  tmp = (u32 *) mp->first_ip_address;
83  start_host_order = clib_host_to_net_u32 (tmp[0]);
84  tmp = (u32 *) mp->last_ip_address;
85  end_host_order = clib_host_to_net_u32 (tmp[0]);
86 
87  count = (end_host_order - start_host_order) + 1;
88 
89  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
90 
91  if (count > 1024)
92  clib_warning ("%U - %U, %d addresses...",
95 
96  memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
97 
98  for (i = 0; i < count; i++)
99  {
100  if (mp->is_add)
101  snat_add_address (sm, &this_addr, vrf_id);
102  else
103  rv = snat_del_address (sm, this_addr, 0);
104 
105  if (rv)
106  goto send_reply;
107 
108  increment_v4_address (&this_addr);
109  }
110 
111 send_reply:
112  REPLY_MACRO (VL_API_SNAT_ADD_ADDRESS_RANGE_REPLY);
113 }
114 
116  (vl_api_snat_add_address_range_t * mp, void *handle)
117 {
118  u8 *s;
119 
120  s = format (0, "SCRIPT: snat_add_address_range ");
121  s = format (s, "%U ", format_ip4_address, mp->first_ip_address);
122  if (memcmp (mp->first_ip_address, mp->last_ip_address, 4))
123  {
124  s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
125  }
126  FINISH;
127 }
128 
129 static void
132 {
134  snat_main_t *sm = &snat_main;
135 
136  rmp = vl_msg_api_alloc (sizeof (*rmp));
137  memset (rmp, 0, sizeof (*rmp));
138  rmp->_vl_msg_id = ntohs (VL_API_SNAT_ADDRESS_DETAILS + sm->msg_id_base);
139  rmp->is_ip4 = 1;
140  clib_memcpy (rmp->ip_address, &(a->addr), 4);
141  if (a->fib_index != ~0)
142  {
144  rmp->vrf_id = ntohl (fib->ft_table_id);
145  }
146  else
147  rmp->vrf_id = ~0;
148  rmp->context = context;
149 
150  vl_msg_api_send_shmem (q, (u8 *) & rmp);
151 }
152 
153 static void
155 {
157  snat_main_t *sm = &snat_main;
158  snat_address_t *a;
159 
161  if (q == 0)
162  return;
163 
164  /* *INDENT-OFF* */
165  vec_foreach (a, sm->addresses)
167  /* *INDENT-ON* */
168 }
169 
171  (vl_api_snat_address_dump_t * mp, void *handle)
172 {
173  u8 *s;
174 
175  s = format (0, "SCRIPT: snat_address_dump ");
176 
177  FINISH;
178 }
179 
180 static void
183 {
184  snat_main_t *sm = &snat_main;
185  vl_api_snat_interface_add_del_feature_reply_t *rmp;
186  u8 is_del = mp->is_add == 0;
187  u32 sw_if_index = ntohl (mp->sw_if_index);
188  int rv = 0;
189 
191 
192  rv = snat_interface_add_del (sw_if_index, mp->is_inside, is_del);
193 
195 
196  REPLY_MACRO (VL_API_SNAT_INTERFACE_ADD_DEL_FEATURE_REPLY);
197 }
198 
201 {
202  u8 *s;
203 
204  s = format (0, "SCRIPT: snat_interface_add_del_feature ");
205  s = format (s, "sw_if_index %d %s %s",
206  clib_host_to_net_u32 (mp->sw_if_index),
207  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
208 
209  FINISH;
210 }
211 
212 static void
215 {
217  snat_main_t *sm = &snat_main;
218 
219  rmp = vl_msg_api_alloc (sizeof (*rmp));
220  memset (rmp, 0, sizeof (*rmp));
221  rmp->_vl_msg_id = ntohs (VL_API_SNAT_INTERFACE_DETAILS + sm->msg_id_base);
222  rmp->sw_if_index = ntohl (i->sw_if_index);
223  rmp->is_inside = i->is_inside;
224  rmp->context = context;
225 
226  vl_msg_api_send_shmem (q, (u8 *) & rmp);
227 }
228 
229 static void
231 {
233  snat_main_t *sm = &snat_main;
235 
237  if (q == 0)
238  return;
239 
240  /* *INDENT-OFF* */
241  pool_foreach (i, sm->interfaces,
242  ({
243  send_snat_interface_details(i, q, mp->context);
244  }));
245  /* *INDENT-ON* */
246 }
247 
249  (vl_api_snat_interface_dump_t * mp, void *handle)
250 {
251  u8 *s;
252 
253  s = format (0, "SCRIPT: snat_interface_dump ");
254 
255  FINISH;
256 } static void
259 {
260  snat_main_t *sm = &snat_main;
261  vl_api_snat_add_static_mapping_reply_t *rmp;
262  ip4_address_t local_addr, external_addr;
263  u16 local_port = 0, external_port = 0;
264  u32 vrf_id, external_sw_if_index;
265  int rv = 0;
266  snat_protocol_t proto;
267 
268  if (mp->is_ip4 != 1)
269  {
270  rv = VNET_API_ERROR_UNIMPLEMENTED;
271  goto send_reply;
272  }
273 
274  memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
275  memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
276  if (mp->addr_only == 0)
277  {
278  local_port = clib_net_to_host_u16 (mp->local_port);
279  external_port = clib_net_to_host_u16 (mp->external_port);
280  }
281  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
282  external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
283  proto = ip_proto_to_snat_proto (mp->protocol);
284 
285  rv = snat_add_static_mapping (local_addr, external_addr, local_port,
286  external_port, vrf_id, mp->addr_only,
287  external_sw_if_index, proto, mp->is_add);
288 
289 send_reply:
290  REPLY_MACRO (VL_API_SNAT_ADD_ADDRESS_RANGE_REPLY);
291 }
292 
294  (vl_api_snat_add_static_mapping_t * mp, void *handle)
295 {
296  u8 *s;
297 
298  s = format (0, "SCRIPT: snat_add_static_mapping ");
299  s = format (s, "protocol %d local_addr %U external_addr %U ",
300  mp->protocol,
303 
304  if (mp->addr_only == 0)
305  s = format (s, "local_port %d external_port %d ",
306  clib_net_to_host_u16 (mp->local_port),
307  clib_net_to_host_u16 (mp->external_port));
308 
309  if (mp->vrf_id != ~0)
310  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
311 
312  if (mp->external_sw_if_index != ~0)
313  s = format (s, "external_sw_if_index %d",
314  clib_net_to_host_u32 (mp->external_sw_if_index));
315  FINISH;
316 }
317 
318 static void
321 {
323  snat_main_t *sm = &snat_main;
324 
325  rmp = vl_msg_api_alloc (sizeof (*rmp));
326  memset (rmp, 0, sizeof (*rmp));
327  rmp->_vl_msg_id =
328  ntohs (VL_API_SNAT_STATIC_MAPPING_DETAILS + sm->msg_id_base);
329  rmp->is_ip4 = 1;
330  rmp->addr_only = m->addr_only;
331  clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
333  rmp->local_port = htons (m->local_port);
334  rmp->external_port = htons (m->external_port);
335  rmp->external_sw_if_index = ~0;
336  rmp->vrf_id = htonl (m->vrf_id);
338  rmp->context = context;
339 
340  vl_msg_api_send_shmem (q, (u8 *) & rmp);
341 }
342 
343 static void
346 {
348  snat_main_t *sm = &snat_main;
349 
350  rmp = vl_msg_api_alloc (sizeof (*rmp));
351  memset (rmp, 0, sizeof (*rmp));
352  rmp->_vl_msg_id =
353  ntohs (VL_API_SNAT_STATIC_MAPPING_DETAILS + sm->msg_id_base);
354  rmp->is_ip4 = 1;
355  rmp->addr_only = m->addr_only;
356  clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
357  rmp->local_port = htons (m->l_port);
358  rmp->external_port = htons (m->e_port);
359  rmp->external_sw_if_index = htonl (m->sw_if_index);
360  rmp->vrf_id = htonl (m->vrf_id);
362  rmp->context = context;
363 
364  vl_msg_api_send_shmem (q, (u8 *) & rmp);
365 }
366 
367 static void
370 {
372  snat_main_t *sm = &snat_main;
375  int j;
376 
378  if (q == 0)
379  return;
380 
381  /* *INDENT-OFF* */
382  pool_foreach (m, sm->static_mappings,
383  ({
384  send_snat_static_mapping_details (m, q, mp->context);
385  }));
386  /* *INDENT-ON* */
387 
388  for (j = 0; j < vec_len (sm->to_resolve); j++)
389  {
390  rp = sm->to_resolve + j;
392  }
393 }
394 
397 {
398  u8 *s;
399 
400  s = format (0, "SCRIPT: snat_static_mapping_dump ");
401 
402  FINISH;
403 }
404 
405 static void
407 {
409  snat_main_t *sm = &snat_main;
410  int rv = 0;
411 
412  /* *INDENT-OFF* */
413  REPLY_MACRO2 (VL_API_SNAT_CONTROL_PING_REPLY,
414  ({
415  rmp->vpe_pid = ntohl (getpid ());
416  }));
417  /* *INDENT-ON* */
418 }
419 
421  (vl_api_snat_control_ping_t * mp, void *handle)
422 {
423  u8 *s;
424 
425  s = format (0, "SCRIPT: snat_control_ping ");
426 
427  FINISH;
428 }
429 
430 static void
432 {
434  snat_main_t *sm = &snat_main;
435  int rv = 0;
436 
437  /* *INDENT-OFF* */
438  REPLY_MACRO2 (VL_API_SNAT_SHOW_CONFIG_REPLY,
439  ({
440  rmp->translation_buckets = htonl (sm->translation_buckets);
441  rmp->translation_memory_size = htonl (sm->translation_memory_size);
442  rmp->user_buckets = htonl (sm->user_buckets);
443  rmp->user_memory_size = htonl (sm->user_memory_size);
444  rmp->max_translations_per_user = htonl (sm->max_translations_per_user);
445  rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
446  rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
447  rmp->static_mapping_only = sm->static_mapping_only;
449  sm->static_mapping_connection_tracking;
450  rmp->deterministic = sm->deterministic;
451  }));
452  /* *INDENT-ON* */
453 }
454 
456  (vl_api_snat_show_config_t * mp, void *handle)
457 {
458  u8 *s;
459 
460  s = format (0, "SCRIPT: snat_show_config ");
461 
462  FINISH;
463 }
464 
465 static void
467 {
468  snat_main_t *sm = &snat_main;
469  vl_api_snat_set_workers_reply_t *rmp;
470  int rv = 0;
471  uword *bitmap = 0;
472  u64 mask = clib_net_to_host_u64 (mp->worker_mask);
473 
474  if (sm->num_workers < 2)
475  {
476  rv = VNET_API_ERROR_FEATURE_DISABLED;
477  goto send_reply;
478  }
479 
480  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
481  rv = snat_set_workers (bitmap);
482  clib_bitmap_free (bitmap);
483 
484 send_reply:
485  REPLY_MACRO (VL_API_SNAT_SET_WORKERS_REPLY);
486 }
487 
489  (vl_api_snat_set_workers_t * mp, void *handle)
490 {
491  u8 *s;
492  uword *bitmap = 0;
493  u8 first = 1;
494  int i;
495  u64 mask = clib_net_to_host_u64 (mp->worker_mask);
496 
497  s = format (0, "SCRIPT: snat_set_workers ");
498  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
499  /* *INDENT-OFF* */
500  clib_bitmap_foreach (i, bitmap,
501  ({
502  if (first)
503  s = format (s, "%d", i);
504  else
505  s = format (s, ",%d", i);
506  first = 0;
507  }));
508  /* *INDENT-ON* */
509  clib_bitmap_free (bitmap);
510  FINISH;
511 }
512 
513 static void
515  (u32 worker_index, unix_shared_memory_queue_t * q, u32 context)
516 {
518  snat_main_t *sm = &snat_main;
520  vlib_worker_threads + worker_index + sm->first_worker_index;
521 
522  rmp = vl_msg_api_alloc (sizeof (*rmp));
523  memset (rmp, 0, sizeof (*rmp));
524  rmp->_vl_msg_id = ntohs (VL_API_SNAT_WORKER_DETAILS + sm->msg_id_base);
525  rmp->context = context;
526  rmp->worker_index = htonl (worker_index);
527  rmp->lcore_id = htonl (w->lcore_id);
528  strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1);
529 
530  vl_msg_api_send_shmem (q, (u8 *) & rmp);
531 }
532 
533 static void
535 {
537  snat_main_t *sm = &snat_main;
538  u32 *worker_index;
539 
541  if (q == 0)
542  return;
543 
544  /* *INDENT-OFF* */
545  vec_foreach (worker_index, sm->workers)
546  send_snat_worker_details(*worker_index, q, mp->context);
547  /* *INDENT-ON* */
548 }
549 
551  (vl_api_snat_worker_dump_t * mp, void *handle)
552 {
553  u8 *s;
554 
555  s = format (0, "SCRIPT: snat_worker_dump ");
556 
557  FINISH;
558 }
559 
560 static void
563 {
564  snat_main_t *sm = &snat_main;
565  vl_api_snat_add_del_interface_addr_reply_t *rmp;
566  u8 is_del = mp->is_add == 0;
567  u32 sw_if_index = ntohl (mp->sw_if_index);
568  int rv = 0;
569 
571 
572  rv = snat_add_interface_address (sm, sw_if_index, is_del);
573 
575 
576  REPLY_MACRO (VL_API_SNAT_ADD_DEL_INTERFACE_ADDR_REPLY);
577 }
578 
581 {
582  u8 *s;
583 
584  s = format (0, "SCRIPT: snat_add_del_interface_addr ");
585  s = format (s, "sw_if_index %d %s",
586  clib_host_to_net_u32 (mp->sw_if_index),
587  mp->is_add ? "" : "del");
588 
589  FINISH;
590 }
591 
592 static void
594  (u32 sw_if_index, unix_shared_memory_queue_t * q, u32 context)
595 {
597  snat_main_t *sm = &snat_main;
598 
599  rmp = vl_msg_api_alloc (sizeof (*rmp));
600  memset (rmp, 0, sizeof (*rmp));
601  rmp->_vl_msg_id =
602  ntohs (VL_API_SNAT_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
603  rmp->sw_if_index = ntohl (sw_if_index);
604  rmp->context = context;
605 
606  vl_msg_api_send_shmem (q, (u8 *) & rmp);
607 }
608 
609 static void
612 {
614  snat_main_t *sm = &snat_main;
615  u32 *i;
616 
618  if (q == 0)
619  return;
620 
621  /* *INDENT-OFF* */
622  vec_foreach (i, sm->auto_add_sw_if_indices)
624  /* *INDENT-ON* */
625 }
626 
629 {
630  u8 *s;
631 
632  s = format (0, "SCRIPT: snat_interface_addr_dump ");
633 
634  FINISH;
635 }
636 
637 static void
640 {
641  snat_main_t *sm = &snat_main;
642  vl_api_snat_ipfix_enable_disable_reply_t *rmp;
643  int rv = 0;
644 
646  clib_host_to_net_u32
647  (mp->domain_id),
648  clib_host_to_net_u16
649  (mp->src_port));
650 
651  REPLY_MACRO (VL_API_SNAT_IPFIX_ENABLE_DISABLE_REPLY);
652 }
653 
656 {
657  u8 *s;
658 
659  s = format (0, "SCRIPT: snat_ipfix_enable_disable ");
660  if (mp->domain_id)
661  s = format (s, "domain %d ", clib_net_to_host_u32 (mp->domain_id));
662  if (mp->src_port)
663  s = format (s, "src_port %d ", clib_net_to_host_u16 (mp->src_port));
664  if (!mp->enable)
665  s = format (s, "disable ");
666 
667  FINISH;
668 }
669 
670 static void
673 {
675  snat_main_t *sm = &snat_main;
677 
678  rmp = vl_msg_api_alloc (sizeof (*rmp));
679  memset (rmp, 0, sizeof (*rmp));
680  rmp->_vl_msg_id = ntohs (VL_API_SNAT_USER_DETAILS + sm->msg_id_base);
681 
682  rmp->vrf_id = ntohl (fib->ft_table_id);
683 
684  rmp->is_ip4 = 1;
685  clib_memcpy (rmp->ip_address, &(u->addr), 4);
686  rmp->nsessions = ntohl (u->nsessions);
687  rmp->nstaticsessions = ntohl (u->nstaticsessions);
688  rmp->context = context;
689 
690  vl_msg_api_send_shmem (q, (u8 *) & rmp);
691 }
692 
693 static void
695 {
697  snat_main_t *sm = &snat_main;
699  snat_user_t *u;
700 
702  if (q == 0)
703  return;
704 
705  /* *INDENT-OFF* */
706  vec_foreach (tsm, sm->per_thread_data)
707  vec_foreach (u, tsm->users)
708  send_snat_user_details (u, q, mp->context);
709  /* *INDENT-ON* */
710 }
711 
713  (vl_api_snat_user_dump_t * mp, void *handle)
714 {
715  u8 *s;
716 
717  s = format (0, "SCRIPT: snat_user_dump ");
718 
719  FINISH;
720 }
721 
722 static void
724  (snat_session_t * s, unix_shared_memory_queue_t * q, u32 context)
725 {
727  snat_main_t *sm = &snat_main;
728 
729  rmp = vl_msg_api_alloc (sizeof (*rmp));
730  memset (rmp, 0, sizeof (*rmp));
731  rmp->_vl_msg_id =
732  ntohs (VL_API_SNAT_USER_SESSION_DETAILS + sm->msg_id_base);
733  rmp->is_ip4 = 1;
734  clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
735  rmp->outside_port = s->out2in.port;
736  clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
737  rmp->inside_port = s->in2out.port;
738  rmp->protocol = ntohs (snat_proto_to_ip_proto (s->in2out.protocol));
739  rmp->is_static = s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING ? 1 : 0;
740  rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
741  rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
742  rmp->total_pkts = ntohl (s->total_pkts);
743  rmp->context = context;
744 
745  vl_msg_api_send_shmem (q, (u8 *) & rmp);
746 }
747 
748 static void
751 {
753  snat_main_t *sm = &snat_main;
755  snat_session_t *s;
756  clib_bihash_kv_8_8_t key, value;
757  snat_user_key_t ukey;
758  snat_user_t *u;
759  u32 session_index, head_index, elt_index;
760  dlist_elt_t *head, *elt;
761 
763  if (q == 0)
764  return;
765  if (!mp->is_ip4)
766  return;
767 
768  clib_memcpy (&ukey.addr, mp->ip_address, 4);
769  ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
770  key.key = ukey.as_u64;
771  if (!clib_bihash_search_8_8 (&sm->worker_by_in, &key, &value))
772  tsm = vec_elt_at_index (sm->per_thread_data, value.value);
773  else
774  tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
775  if (clib_bihash_search_8_8 (&sm->user_hash, &key, &value))
776  return;
777  u = pool_elt_at_index (tsm->users, value.value);
778  if (!u->nsessions && !u->nstaticsessions)
779  return;
780 
781  head_index = u->sessions_per_user_list_head_index;
782  head = pool_elt_at_index (tsm->list_pool, head_index);
783  elt_index = head->next;
784  elt = pool_elt_at_index (tsm->list_pool, elt_index);
785  session_index = elt->value;
786  while (session_index != ~0)
787  {
788  s = pool_elt_at_index (tsm->sessions, session_index);
789 
791 
792  elt_index = elt->next;
793  elt = pool_elt_at_index (tsm->list_pool, elt_index);
794  session_index = elt->value;
795  }
796 }
797 
799  (vl_api_snat_user_session_dump_t * mp, void *handle)
800 {
801  u8 *s;
802 
803  s = format (0, "SCRIPT: snat_user_session_dump ");
804  s = format (s, "ip_address %U vrf_id %d\n",
806  clib_net_to_host_u32 (mp->vrf_id));
807 
808  FINISH;
809 }
810 
811 /****************************/
812 /*** detrministic NAT/CGN ***/
813 /****************************/
814 
815 static void
817 {
818  snat_main_t *sm = &snat_main;
819  vl_api_snat_add_det_map_reply_t *rmp;
820  int rv = 0;
821  ip4_address_t in_addr, out_addr;
822 
823  clib_memcpy (&in_addr, mp->in_addr, 4);
824  clib_memcpy (&out_addr, mp->out_addr, 4);
825  rv = snat_det_add_map (sm, &in_addr, mp->in_plen, &out_addr,
826  mp->out_plen, mp->is_add);
827 
828  REPLY_MACRO (VL_API_SNAT_ADD_DET_MAP_REPLY);
829 }
830 
832  (vl_api_snat_add_det_map_t * mp, void *handle)
833 {
834  u8 *s;
835 
836  s = format (0, "SCRIPT: snat_add_det_map ");
837  s = format (s, "inside address %U/%d outside address %U/%d\n",
840 
841  FINISH;
842 }
843 
844 static void
846 {
847  snat_main_t *sm = &snat_main;
849  int rv = 0;
850  u16 lo_port = 0, hi_port = 0;
851  snat_det_map_t *dm;
852  ip4_address_t in_addr, out_addr;
853 
854  out_addr.as_u32 = 0;
855  clib_memcpy (&in_addr, mp->in_addr, 4);
856  dm = snat_det_map_by_user (sm, &in_addr);
857  if (!dm)
858  {
859  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
860  goto send_reply;
861  }
862 
863  snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
864  hi_port = lo_port + dm->ports_per_host - 1;
865 
866 send_reply:
867  /* *INDENT-OFF* */
868  REPLY_MACRO2 (VL_API_SNAT_DET_FORWARD_REPLY,
869  ({
870  rmp->out_port_lo = ntohs (lo_port);
871  rmp->out_port_hi = ntohs (hi_port);
872  rmp->is_ip4 = 1;
873  memset (rmp->out_addr, 0, 16);
874  clib_memcpy (rmp->out_addr, &out_addr, 4);
875  }))
876  /* *INDENT-ON* */
877 }
878 
880  (vl_api_snat_det_forward_t * mp, void *handle)
881 {
882  u8 *s;
883 
884  s = format (0, "SCRIPT: smat_det_forward_t");
885  s = format (s, "inside ip address %U\n", format_ip4_address, mp->in_addr);
886 
887  FINISH;
888 }
889 
890 static void
892 {
893  snat_main_t *sm = &snat_main;
895  int rv = 0;
896  ip4_address_t out_addr, in_addr;
897  snat_det_map_t *dm;
898 
899  in_addr.as_u32 = 0;
900  clib_memcpy (&out_addr, mp->out_addr, 4);
901  dm = snat_det_map_by_out (sm, &out_addr);
902  if (!dm)
903  {
904  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
905  goto send_reply;
906  }
907 
908  snat_det_reverse (dm, &out_addr, htons (mp->out_port), &in_addr);
909 
910 send_reply:
911  /* *INDENT-OFF* */
912  REPLY_MACRO2 (VL_API_SNAT_DET_REVERSE_REPLY,
913  ({
914  rmp->is_ip4 = 1;
915  memset (rmp->in_addr, 0, 16);
916  clib_memcpy (rmp->in_addr, &in_addr, 4);
917  }))
918  /* *INDENT-ON* */
919 }
920 
922  (vl_api_snat_det_reverse_t * mp, void *handle)
923 {
924  u8 *s;
925 
926  s = format (0, "SCRIPT: smat_det_reverse_t");
927  s = format (s, "outside ip address %U outside port %d",
928  format_ip4_address, mp->out_addr, ntohs (mp->out_port));
929 
930  FINISH;
931 }
932 
933 static void
936 {
938  snat_main_t *sm = &snat_main;
939 
940  rmp = vl_msg_api_alloc (sizeof (*rmp));
941  memset (rmp, 0, sizeof (*rmp));
942  rmp->_vl_msg_id = ntohs (VL_API_SNAT_DET_MAP_DETAILS + sm->msg_id_base);
943  rmp->is_ip4 = 1;
944  clib_memcpy (rmp->in_addr, &m->in_addr, 4);
945  rmp->in_plen = m->in_plen;
946  clib_memcpy (rmp->out_addr, &m->out_addr, 4);
947  rmp->out_plen = m->out_plen;
948  rmp->sharing_ratio = htonl (m->sharing_ratio);
949  rmp->ports_per_host = htons (m->ports_per_host);
950  rmp->ses_num = htonl (m->ses_num);
951  rmp->context = context;
952 
953  vl_msg_api_send_shmem (q, (u8 *) & rmp);
954 }
955 
956 static void
958 {
960  snat_main_t *sm = &snat_main;
961  snat_det_map_t *m;
962 
964  if (q == 0)
965  return;
966 
967  /* *INDENT-OFF* */
968  vec_foreach(m, sm->det_maps)
970  /* *INDENT-ON* */
971 }
972 
974  (vl_api_snat_det_map_dump_t * mp, void *handle)
975 {
976  u8 *s;
977 
978  s = format (0, "SCRIPT: snat_det_map_dump ");
979 
980  FINISH;
981 }
982 
983 static void
985 {
986  snat_main_t *sm = &snat_main;
987  vl_api_snat_det_set_timeouts_reply_t *rmp;
988  int rv = 0;
989 
990  sm->udp_timeout = ntohl (mp->udp);
991  sm->tcp_established_timeout = ntohl (mp->tcp_established);
992  sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
993  sm->icmp_timeout = ntohl (mp->icmp);
994 
995  REPLY_MACRO (VL_API_SNAT_DET_SET_TIMEOUTS_REPLY);
996 }
997 
999  (vl_api_snat_det_set_timeouts_t * mp, void *handle)
1000 {
1001  u8 *s;
1002 
1003  s = format (0, "SCRIPT: snat_det_set_timeouts ");
1004  s = format (s, "udp %d tcp_established %d tcp_transitory %d icmp %d\n",
1005  ntohl (mp->udp),
1006  ntohl (mp->tcp_established),
1007  ntohl (mp->tcp_transitory), ntohl (mp->icmp));
1008 
1009  FINISH;
1010 }
1011 
1012 static void
1014 {
1015  snat_main_t *sm = &snat_main;
1017  int rv = 0;
1018 
1019  /* *INDENT-OFF* */
1020  REPLY_MACRO2 (VL_API_SNAT_DET_GET_TIMEOUTS_REPLY,
1021  ({
1022  rmp->udp = htonl (sm->udp_timeout);
1023  rmp->tcp_established = htonl (sm->tcp_established_timeout);
1024  rmp->tcp_transitory = htonl (sm->tcp_transitory_timeout);
1025  rmp->icmp = htonl (sm->icmp_timeout);
1026  }))
1027  /* *INDENT-ON* */
1028 }
1029 
1031  (vl_api_snat_det_get_timeouts_t * mp, void *handle)
1032 {
1033  u8 *s;
1034 
1035  s = format (0, "SCRIPT: snat_det_get_timeouts");
1036 
1037  FINISH;
1038 }
1039 
1040 static void
1043 {
1044  snat_main_t *sm = &snat_main;
1045  vl_api_snat_det_close_session_out_reply_t *rmp;
1046  ip4_address_t out_addr, ext_addr, in_addr;
1047  snat_det_out_key_t key;
1048  snat_det_map_t *dm;
1049  snat_det_session_t *ses;
1050  int rv = 0;
1051 
1052  clib_memcpy (&out_addr, mp->out_addr, 4);
1053  clib_memcpy (&ext_addr, mp->ext_addr, 4);
1054 
1055  dm = snat_det_map_by_out (sm, &out_addr);
1056  if (!dm)
1057  {
1058  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1059  goto send_reply;
1060  }
1061  snat_det_reverse (dm, &ext_addr, ntohs (mp->out_port), &in_addr);
1062  key.ext_host_addr = ext_addr;
1063  key.ext_host_port = mp->ext_port;
1064  key.out_port = mp->out_port;
1065  ses = snat_det_get_ses_by_out (dm, &in_addr, key.as_u64);
1066  if (!ses)
1067  {
1068  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1069  goto send_reply;
1070  }
1071  snat_det_ses_close (dm, ses);
1072 
1073 send_reply:
1074  REPLY_MACRO (VL_API_SNAT_DET_CLOSE_SESSION_OUT_REPLY);
1075 }
1076 
1079 {
1080  u8 *s;
1081 
1082  s = format (0, "SCRIPT: snat_det_close_session_out ");
1083  s = format (s, "out_addr %U out_port %d "
1084  "ext_addr %U ext_port %d\n",
1085  format_ip4_address, mp->out_addr, ntohs (mp->out_port),
1086  format_ip4_address, mp->ext_addr, ntohs (mp->ext_port));
1087 
1088  FINISH;
1089 }
1090 
1091 static void
1094 {
1095  snat_main_t *sm = &snat_main;
1096  vl_api_snat_det_close_session_in_reply_t *rmp;
1097  ip4_address_t in_addr, ext_addr;
1098  snat_det_out_key_t key;
1099  snat_det_map_t *dm;
1100  snat_det_session_t *ses;
1101  int rv = 0;
1102 
1103  clib_memcpy (&in_addr, mp->in_addr, 4);
1104  clib_memcpy (&ext_addr, mp->ext_addr, 4);
1105 
1106  dm = snat_det_map_by_user (sm, &in_addr);
1107  if (!dm)
1108  {
1109  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1110  goto send_reply;
1111  }
1112  key.ext_host_addr = ext_addr;
1113  key.ext_host_port = mp->ext_port;
1114  ses = snat_det_find_ses_by_in (dm, &in_addr, mp->in_port, key);
1115  if (!ses)
1116  {
1117  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1118  goto send_reply;
1119  }
1120  snat_det_ses_close (dm, ses);
1121 
1122 send_reply:
1123  REPLY_MACRO (VL_API_SNAT_DET_CLOSE_SESSION_OUT_REPLY);
1124 }
1125 
1128 {
1129  u8 *s;
1130  s = format (0, "SCRIPT: snat_det_close_session_in ");
1131  s = format (s, "in_addr %U in_port %d "
1132  "ext_addr %U ext_port %d\n",
1133  format_ip4_address, mp->in_addr, ntohs (mp->in_port),
1134  format_ip4_address, mp->ext_addr, ntohs (mp->ext_port));
1135 
1136  FINISH;
1137 }
1138 
1139 static void
1142 {
1144  snat_main_t *sm = &snat_main;
1145 
1146  rmp = vl_msg_api_alloc (sizeof (*rmp));
1147  memset (rmp, 0, sizeof (*rmp));
1148  rmp->_vl_msg_id = ntohs (VL_API_SNAT_DET_SESSION_DETAILS + sm->msg_id_base);
1149  rmp->is_ip4 = 1;
1150  rmp->in_port = s->in_port;
1151  clib_memcpy (rmp->ext_addr, &s->out.ext_host_addr, 4);
1152  rmp->ext_port = s->out.ext_host_port;
1153  rmp->out_port = s->out.out_port;
1154  rmp->state = s->state;
1155  rmp->expire = ntohl (s->expire);
1156  rmp->context = context;
1157 
1158  vl_msg_api_send_shmem (q, (u8 *) & rmp);
1159 }
1160 
1161 static void
1163 {
1165  snat_main_t *sm = &snat_main;
1166  ip4_address_t user_addr;
1167  snat_det_map_t *dm;
1168  snat_det_session_t *s, empty_ses;
1169  u16 i;
1170 
1172  if (q == 0)
1173  return;
1174  if (!mp->is_ip4)
1175  return;
1176 
1177  memset (&empty_ses, 0, sizeof (empty_ses));
1178  clib_memcpy (&user_addr, mp->user_addr, 4);
1179  dm = snat_det_map_by_user (sm, &user_addr);
1180  if (!dm)
1181  return;
1182 
1183  s = dm->sessions + snat_det_user_ses_offset (&user_addr, dm->in_plen);
1184  for (i = 0; i < SNAT_DET_SES_PER_USER; i++)
1185  {
1186  if (s->out.as_u64)
1188  s++;
1189  }
1190 }
1191 
1193  (vl_api_snat_det_session_dump_t * mp, void *handle)
1194 {
1195  u8 *s;
1196 
1197  s = format (0, "SCRIPT: snat_det_session_dump ");
1198  s = format (s, "user_addr %U\n", format_ip4_address, mp->user_addr);
1199 
1200  FINISH;
1201 }
1202 
1203 /*************/
1204 /*** NAT64 ***/
1205 /*************/
1206 
1207 static void
1210 {
1211  vl_api_nat64_add_del_pool_addr_range_reply_t *rmp;
1212  snat_main_t *sm = &snat_main;
1213  nat64_main_t *nm = &nat64_main;
1214  int rv = 0;
1215  ip4_address_t this_addr;
1216  u32 start_host_order, end_host_order;
1217  u32 vrf_id;
1218  int i, count;
1219  u32 *tmp;
1220 
1221  if (nm->is_disabled)
1222  {
1223  rv = VNET_API_ERROR_FEATURE_DISABLED;
1224  goto send_reply;
1225  }
1226 
1227  tmp = (u32 *) mp->start_addr;
1228  start_host_order = clib_host_to_net_u32 (tmp[0]);
1229  tmp = (u32 *) mp->end_addr;
1230  end_host_order = clib_host_to_net_u32 (tmp[0]);
1231 
1232  count = (end_host_order - start_host_order) + 1;
1233 
1234  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
1235 
1236  memcpy (&this_addr.as_u8, mp->start_addr, 4);
1237 
1238  for (i = 0; i < count; i++)
1239  {
1240  if ((rv = nat64_add_del_pool_addr (&this_addr, vrf_id, mp->is_add)))
1241  goto send_reply;
1242 
1243  increment_v4_address (&this_addr);
1244  }
1245 
1246 send_reply:
1247  REPLY_MACRO (VL_API_NAT64_ADD_DEL_POOL_ADDR_RANGE_REPLY);
1248 }
1249 
1252 {
1253  u8 *s;
1254 
1255  s = format (0, "SCRIPT: nat64_add_del_pool_addr_range ");
1256  s = format (s, "%U - %U vrf_id %u %s\n",
1259  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
1260 
1261  FINISH;
1262 }
1263 
1265 {
1269 
1270 static int
1272 {
1274  snat_main_t *sm = &snat_main;
1275  nat64_api_walk_ctx_t *ctx = arg;
1276 
1277  rmp = vl_msg_api_alloc (sizeof (*rmp));
1278  memset (rmp, 0, sizeof (*rmp));
1279  rmp->_vl_msg_id = ntohs (VL_API_NAT64_POOL_ADDR_DETAILS + sm->msg_id_base);
1280  clib_memcpy (rmp->address, &(a->addr), 4);
1281  if (a->fib_index != ~0)
1282  {
1284  if (!fib)
1285  return -1;
1286  rmp->vrf_id = ntohl (fib->ft_table_id);
1287  }
1288  else
1289  rmp->vrf_id = ~0;
1290  rmp->context = ctx->context;
1291 
1292  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
1293 
1294  return 0;
1295 }
1296 
1297 static void
1299 {
1301  nat64_main_t *nm = &nat64_main;
1302 
1303  if (nm->is_disabled)
1304  return;
1305 
1307  if (q == 0)
1308  return;
1309 
1310  nat64_api_walk_ctx_t ctx = {
1311  .q = q,
1312  .context = mp->context,
1313  };
1314 
1316 }
1317 
1318 static void *
1320  void *handle)
1321 {
1322  u8 *s;
1323 
1324  s = format (0, "SCRIPT: nat64_pool_addr_dump\n");
1325 
1326  FINISH;
1327 }
1328 
1329 static void
1331  mp)
1332 {
1333  snat_main_t *sm = &snat_main;
1334  nat64_main_t *nm = &nat64_main;
1335  vl_api_nat64_add_del_interface_reply_t *rmp;
1336  int rv = 0;
1337 
1338  if (nm->is_disabled)
1339  {
1340  rv = VNET_API_ERROR_FEATURE_DISABLED;
1341  goto send_reply;
1342  }
1343 
1344  VALIDATE_SW_IF_INDEX (mp);
1345 
1346  rv =
1347  nat64_add_del_interface (ntohl (mp->sw_if_index), mp->is_inside,
1348  mp->is_add);
1349 
1351 
1352 send_reply:
1353  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_REPLY);
1354 }
1355 
1356 static void *
1358  void *handle)
1359 {
1360  u8 *s;
1361 
1362  s = format (0, "SCRIPT: nat64_add_del_interface ");
1363  s = format (s, "sw_if_index %d %s %s",
1364  clib_host_to_net_u32 (mp->sw_if_index),
1365  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
1366 
1367  FINISH;
1368 }
1369 
1370 static int
1372 {
1374  snat_main_t *sm = &snat_main;
1375  nat64_api_walk_ctx_t *ctx = arg;
1376 
1377  rmp = vl_msg_api_alloc (sizeof (*rmp));
1378  memset (rmp, 0, sizeof (*rmp));
1379  rmp->_vl_msg_id = ntohs (VL_API_NAT64_INTERFACE_DETAILS + sm->msg_id_base);
1380  rmp->sw_if_index = ntohl (i->sw_if_index);
1381  rmp->is_inside = i->is_inside;
1382  rmp->context = ctx->context;
1383 
1384  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
1385 
1386  return 0;
1387 }
1388 
1389 static void
1391 {
1393  nat64_main_t *nm = &nat64_main;
1394 
1395  if (nm->is_disabled)
1396  return;
1397 
1399  if (q == 0)
1400  return;
1401 
1402  nat64_api_walk_ctx_t ctx = {
1403  .q = q,
1404  .context = mp->context,
1405  };
1406 
1408 }
1409 
1410 static void *
1412  void *handle)
1413 {
1414  u8 *s;
1415 
1416  s = format (0, "SCRIPT: snat_interface_dump ");
1417 
1418  FINISH;
1419 }
1420 
1421 static void
1424 {
1425  snat_main_t *sm = &snat_main;
1426  nat64_main_t *nm = &nat64_main;
1427  vl_api_nat64_add_del_static_bib_reply_t *rmp;
1428  ip6_address_t in_addr;
1429  ip4_address_t out_addr;
1430  int rv = 0;
1431 
1432  if (nm->is_disabled)
1433  {
1434  rv = VNET_API_ERROR_FEATURE_DISABLED;
1435  goto send_reply;
1436  }
1437 
1438  memcpy (&in_addr.as_u8, mp->i_addr, 16);
1439  memcpy (&out_addr.as_u8, mp->o_addr, 4);
1440 
1441  rv =
1442  nat64_add_del_static_bib_entry (&in_addr, &out_addr,
1443  clib_net_to_host_u16 (mp->i_port),
1444  clib_net_to_host_u16 (mp->o_port),
1445  mp->proto,
1446  clib_net_to_host_u32 (mp->vrf_id),
1447  mp->is_add);
1448 
1449 send_reply:
1450  REPLY_MACRO (VL_API_NAT64_ADD_DEL_STATIC_BIB_REPLY);
1451 }
1452 
1455 {
1456  u8 *s;
1457 
1458  s = format (0, "SCRIPT: nat64_add_del_static_bib ");
1459  s = format (s, "protocol %d i_addr %U o_addr %U ",
1460  mp->proto,
1462 
1463  if (mp->vrf_id != ~0)
1464  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1465 
1466  FINISH;
1467 }
1468 
1469 static int
1470 nat64_api_bib_walk (nat64_db_bib_entry_t * bibe, void *arg)
1471 {
1473  snat_main_t *sm = &snat_main;
1474  nat64_api_walk_ctx_t *ctx = arg;
1475  fib_table_t *fib;
1476 
1477  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
1478  if (!fib)
1479  return -1;
1480 
1481  rmp = vl_msg_api_alloc (sizeof (*rmp));
1482  memset (rmp, 0, sizeof (*rmp));
1483  rmp->_vl_msg_id = ntohs (VL_API_NAT64_BIB_DETAILS + sm->msg_id_base);
1484  rmp->context = ctx->context;
1485  clib_memcpy (rmp->i_addr, &(bibe->in_addr), 16);
1486  clib_memcpy (rmp->o_addr, &(bibe->out_addr), 4);
1487  rmp->i_port = bibe->in_port;
1488  rmp->o_port = bibe->out_port;
1489  rmp->vrf_id = ntohl (fib->ft_table_id);
1490  rmp->proto = snat_proto_to_ip_proto (bibe->proto);
1491  rmp->is_static = bibe->is_static;
1492  rmp->ses_num = ntohl (bibe->ses_num);
1493 
1494  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
1495 
1496  return 0;
1497 }
1498 
1499 static void
1501 {
1503  nat64_main_t *nm = &nat64_main;
1504  snat_protocol_t proto;
1505 
1506  if (nm->is_disabled)
1507  return;
1508 
1510  if (q == 0)
1511  return;
1512 
1513  nat64_api_walk_ctx_t ctx = {
1514  .q = q,
1515  .context = mp->context,
1516  };
1517 
1518  proto = ip_proto_to_snat_proto (mp->proto);
1519 
1520  nat64_db_bib_walk (&nm->db, proto, nat64_api_bib_walk, &ctx);
1521 }
1522 
1523 static void *
1525 {
1526  u8 *s;
1527 
1528  s = format (0, "SCRIPT: snat_bib_dump protocol %d", mp->proto);
1529 
1530  FINISH;
1531 }
1532 
1533 static void
1535 {
1536  snat_main_t *sm = &snat_main;
1537  nat64_main_t *nm = &nat64_main;
1538  vl_api_nat64_set_timeouts_reply_t *rmp;
1539  int rv = 0;
1540 
1541  if (nm->is_disabled)
1542  {
1543  rv = VNET_API_ERROR_FEATURE_DISABLED;
1544  goto send_reply;
1545  }
1546 
1547  rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
1548  if (rv)
1549  goto send_reply;
1550  rv = nat64_set_udp_timeout (ntohl (mp->udp));
1551  if (rv)
1552  goto send_reply;
1553  rv =
1554  nat64_set_tcp_timeouts (ntohl (mp->tcp_trans), ntohl (mp->tcp_est),
1555  ntohl (mp->tcp_incoming_syn));
1556 
1557 send_reply:
1558  REPLY_MACRO (VL_API_NAT64_SET_TIMEOUTS_REPLY);
1559 }
1560 
1562  (vl_api_nat64_set_timeouts_t * mp, void *handle)
1563 {
1564  u8 *s;
1565 
1566  s = format (0, "SCRIPT: nat64_set_timeouts ");
1567  s =
1568  format (s,
1569  "udp %d icmp %d, tcp_trans %d, tcp_est %d, tcp_incoming_syn %d\n",
1570  ntohl (mp->udp), ntohl (mp->icmp), ntohl (mp->tcp_trans),
1571  ntohl (mp->tcp_est), ntohl (mp->tcp_incoming_syn));
1572 
1573  FINISH;
1574 }
1575 
1576 static void
1578 {
1579  snat_main_t *sm = &snat_main;
1580  nat64_main_t *nm = &nat64_main;
1582  int rv = 0;
1583 
1584  if (nm->is_disabled)
1585  return;
1586 
1587  /* *INDENT-OFF* */
1588  REPLY_MACRO2 (VL_API_NAT64_GET_TIMEOUTS_REPLY,
1589  ({
1590  rmp->udp = htonl (nat64_get_udp_timeout());
1591  rmp->icmp = htonl (nat64_get_icmp_timeout());
1592  rmp->tcp_trans = htonl (nat64_get_tcp_trans_timeout());
1593  rmp->tcp_est = htonl (nat64_get_tcp_est_timeout());
1595  }))
1596  /* *INDENT-ON* */
1597 }
1598 
1600  (vl_api_nat64_get_timeouts_t * mp, void *handle)
1601 {
1602  u8 *s;
1603 
1604  s = format (0, "SCRIPT: nat64_get_timeouts");
1605 
1606  FINISH;
1607 }
1608 
1609 static int
1610 nat64_api_st_walk (nat64_db_st_entry_t * ste, void *arg)
1611 {
1613  snat_main_t *sm = &snat_main;
1614  nat64_api_walk_ctx_t *ctx = arg;
1615  nat64_main_t *nm = &nat64_main;
1616  nat64_db_bib_entry_t *bibe;
1617  fib_table_t *fib;
1618 
1619  bibe = nat64_db_bib_entry_by_index (&nm->db, ste->proto, ste->bibe_index);
1620  if (!bibe)
1621  return -1;
1622 
1623  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
1624  if (!fib)
1625  return -1;
1626 
1627  rmp = vl_msg_api_alloc (sizeof (*rmp));
1628  memset (rmp, 0, sizeof (*rmp));
1629  rmp->_vl_msg_id = ntohs (VL_API_NAT64_ST_DETAILS + sm->msg_id_base);
1630  rmp->context = ctx->context;
1631  clib_memcpy (rmp->il_addr, &(bibe->in_addr), 16);
1632  clib_memcpy (rmp->ol_addr, &(bibe->out_addr), 4);
1633  rmp->il_port = bibe->in_port;
1634  rmp->ol_port = bibe->out_port;
1635  clib_memcpy (rmp->ir_addr, &(ste->in_r_addr), 16);
1636  clib_memcpy (rmp->or_addr, &(ste->out_r_addr), 4);
1637  rmp->il_port = ste->r_port;
1638  rmp->vrf_id = ntohl (fib->ft_table_id);
1639  rmp->proto = snat_proto_to_ip_proto (ste->proto);
1640 
1641  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
1642 
1643  return 0;
1644 }
1645 
1646 static void
1648 {
1650  nat64_main_t *nm = &nat64_main;
1651  snat_protocol_t proto;
1652 
1653  if (nm->is_disabled)
1654  return;
1655 
1657  if (q == 0)
1658  return;
1659 
1660  nat64_api_walk_ctx_t ctx = {
1661  .q = q,
1662  .context = mp->context,
1663  };
1664 
1665  proto = ip_proto_to_snat_proto (mp->proto);
1666 
1667  nat64_db_st_walk (&nm->db, proto, nat64_api_st_walk, &ctx);
1668 }
1669 
1670 static void *
1672 {
1673  u8 *s;
1674 
1675  s = format (0, "SCRIPT: snat_st_dump protocol %d", mp->proto);
1676 
1677  FINISH;
1678 }
1679 
1680 static void
1682 {
1683  vl_api_nat64_add_del_prefix_reply_t *rmp;
1684  snat_main_t *sm = &snat_main;
1685  nat64_main_t *nm = &nat64_main;
1686  ip6_address_t prefix;
1687  int rv = 0;
1688 
1689  if (nm->is_disabled)
1690  {
1691  rv = VNET_API_ERROR_FEATURE_DISABLED;
1692  goto send_reply;
1693  }
1694 
1695  memcpy (&prefix.as_u8, mp->prefix, 16);
1696 
1697  rv =
1698  nat64_add_del_prefix (&prefix, mp->prefix_len,
1699  clib_net_to_host_u32 (mp->vrf_id), mp->is_add);
1700 send_reply:
1701  REPLY_MACRO (VL_API_NAT64_ADD_DEL_PREFIX_REPLY);
1702 }
1703 
1704 static void *
1706  void *handle)
1707 {
1708  u8 *s;
1709 
1710  s = format (0, "SCRIPT: nat64_add_del_prefix %U/%u vrf_id %u %s\n",
1712  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
1713 
1714  FINISH;
1715 }
1716 
1717 static int
1719 {
1721  snat_main_t *sm = &snat_main;
1722  nat64_api_walk_ctx_t *ctx = arg;
1723 
1724  rmp = vl_msg_api_alloc (sizeof (*rmp));
1725  memset (rmp, 0, sizeof (*rmp));
1726  rmp->_vl_msg_id = ntohs (VL_API_NAT64_PREFIX_DETAILS + sm->msg_id_base);
1727  clib_memcpy (rmp->prefix, &(p->prefix), 16);
1728  rmp->prefix_len = p->plen;
1729  rmp->vrf_id = ntohl (p->vrf_id);
1730  rmp->context = ctx->context;
1731 
1732  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
1733 
1734  return 0;
1735 }
1736 
1737 static void
1739 {
1741  nat64_main_t *nm = &nat64_main;
1742 
1743  if (nm->is_disabled)
1744  return;
1745 
1747  if (q == 0)
1748  return;
1749 
1750  nat64_api_walk_ctx_t ctx = {
1751  .q = q,
1752  .context = mp->context,
1753  };
1754 
1756 }
1757 
1758 static void *
1760  void *handle)
1761 {
1762  u8 *s;
1763 
1764  s = format (0, "SCRIPT: nat64_prefix_dump\n");
1765 
1766  FINISH;
1767 }
1768 
1769 /* List of message types that this plugin understands */
1770 #define foreach_snat_plugin_api_msg \
1771 _(SNAT_ADD_ADDRESS_RANGE, snat_add_address_range) \
1772 _(SNAT_INTERFACE_ADD_DEL_FEATURE, snat_interface_add_del_feature) \
1773 _(SNAT_ADD_STATIC_MAPPING, snat_add_static_mapping) \
1774 _(SNAT_CONTROL_PING, snat_control_ping) \
1775 _(SNAT_STATIC_MAPPING_DUMP, snat_static_mapping_dump) \
1776 _(SNAT_SHOW_CONFIG, snat_show_config) \
1777 _(SNAT_ADDRESS_DUMP, snat_address_dump) \
1778 _(SNAT_INTERFACE_DUMP, snat_interface_dump) \
1779 _(SNAT_SET_WORKERS, snat_set_workers) \
1780 _(SNAT_WORKER_DUMP, snat_worker_dump) \
1781 _(SNAT_ADD_DEL_INTERFACE_ADDR, snat_add_del_interface_addr) \
1782 _(SNAT_INTERFACE_ADDR_DUMP, snat_interface_addr_dump) \
1783 _(SNAT_IPFIX_ENABLE_DISABLE, snat_ipfix_enable_disable) \
1784 _(SNAT_USER_DUMP, snat_user_dump) \
1785 _(SNAT_USER_SESSION_DUMP, snat_user_session_dump) \
1786 _(SNAT_ADD_DET_MAP, snat_add_det_map) \
1787 _(SNAT_DET_FORWARD, snat_det_forward) \
1788 _(SNAT_DET_REVERSE, snat_det_reverse) \
1789 _(SNAT_DET_MAP_DUMP, snat_det_map_dump) \
1790 _(SNAT_DET_SET_TIMEOUTS, snat_det_set_timeouts) \
1791 _(SNAT_DET_GET_TIMEOUTS, snat_det_get_timeouts) \
1792 _(SNAT_DET_CLOSE_SESSION_OUT, snat_det_close_session_out) \
1793 _(SNAT_DET_CLOSE_SESSION_IN, snat_det_close_session_in) \
1794 _(SNAT_DET_SESSION_DUMP, snat_det_session_dump) \
1795 _(NAT64_ADD_DEL_POOL_ADDR_RANGE, nat64_add_del_pool_addr_range) \
1796 _(NAT64_POOL_ADDR_DUMP, nat64_pool_addr_dump) \
1797 _(NAT64_ADD_DEL_INTERFACE, nat64_add_del_interface) \
1798 _(NAT64_INTERFACE_DUMP, nat64_interface_dump) \
1799 _(NAT64_ADD_DEL_STATIC_BIB, nat64_add_del_static_bib) \
1800 _(NAT64_BIB_DUMP, nat64_bib_dump) \
1801 _(NAT64_SET_TIMEOUTS, nat64_set_timeouts) \
1802 _(NAT64_GET_TIMEOUTS, nat64_get_timeouts) \
1803 _(NAT64_ST_DUMP, nat64_st_dump) \
1804 _(NAT64_ADD_DEL_PREFIX, nat64_add_del_prefix) \
1805 _(NAT64_PREFIX_DUMP, nat64_prefix_dump)
1806 
1807 /* Set up the API message handling tables */
1808 static clib_error_t *
1810 {
1811  snat_main_t *sm __attribute__ ((unused)) = &snat_main;
1812 #define _(N,n) \
1813  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
1814  #n, \
1815  vl_api_##n##_t_handler, \
1816  vl_noop_handler, \
1817  vl_api_##n##_t_endian, \
1818  vl_api_##n##_t_print, \
1819  sizeof(vl_api_##n##_t), 1);
1821 #undef _
1822 
1823  return 0;
1824 }
1825 
1826 #define vl_msg_name_crc_list
1827 #include <snat/snat_all_api_h.h>
1828 #undef vl_msg_name_crc_list
1829 
1830 static void
1832 {
1833 #define _(id,n,crc) \
1834  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
1835  foreach_vl_msg_name_crc_snat;
1836 #undef _
1837 }
1838 
1839 static void
1841 {
1842 #define _(n,f) sm->api_main->msg_print_handlers \
1843  [VL_API_##n + sm->msg_id_base] \
1844  = (void *) vl_api_##f##_t_print;
1846 #undef _
1847 }
1848 
1849 clib_error_t *
1851 {
1852  u8 *name;
1853  clib_error_t *error = 0;
1854 
1855  name = format (0, "snat_%08x%c", api_version, 0);
1856 
1857  /* Ask for a correctly-sized block of API message decode slots */
1858  sm->msg_id_base =
1860 
1861  error = snat_plugin_api_hookup (vm);
1862 
1863  /* Add our API messages to the global name_crc hash table */
1864  setup_message_id_table (sm, sm->api_main);
1865 
1867 
1868  vec_free (name);
1869 
1870  return error;
1871 }
1872 
1873 /*
1874  * fd.io coding-style-patch-verification: ON
1875  *
1876  * Local Variables:
1877  * eval: (c-set-style "gnu")
1878  * End:
1879  */
ip4_address_t external_addr
Definition: snat.h:188
u32 nat64_get_icmp_timeout(void)
Get ICMP session timeout.
Definition: nat64.c:451
static void vl_api_snat_det_close_session_in_t_handler(vl_api_snat_det_close_session_in_t *mp)
Definition: snat_api.c:1093
static void vl_api_snat_det_forward_t_handler(vl_api_snat_det_forward_t *mp)
Definition: snat_api.c:845
static void vl_api_nat64_st_dump_t_handler(vl_api_nat64_st_dump_t *mp)
Definition: snat_api.c:1647
Dump NAT64 prefix.
Definition: snat.api:837
u32 next
Definition: dlist.h:30
static int nat64_api_bib_walk(nat64_db_bib_entry_t *bibe, void *arg)
Definition: snat_api.c:1470
NAT64 interface details response.
Definition: snat.api:670
Add/del S-NAT address range.
Definition: snat.api:32
static void * vl_api_snat_add_static_mapping_t_print(vl_api_snat_add_static_mapping_t *mp, void *handle)
Definition: snat_api.c:294
u32 sessions_per_user_list_head_index
Definition: snat.h:152
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:837
void snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id)
Definition: snat.c:128
static void * vl_api_snat_show_config_t_print(vl_api_snat_show_config_t *mp, void *handle)
Definition: snat_api.c:456
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
Definition: nat64.c:415
static void vl_api_snat_add_address_range_t_handler(vl_api_snat_add_address_range_t *mp)
Definition: snat_api.c:59
u16 ext_host_port
Definition: snat.h:60
Add/delete S-NAT pool address from specific interfce.
Definition: snat.api:267
NAT64 BIB details response.
Definition: snat.api:721
a
Definition: bitmap.h:516
static void * vl_api_nat64_pool_addr_dump_t_print(vl_api_nat64_pool_addr_dump_t *mp, void *handle)
Definition: snat_api.c:1319
ip6_address_t prefix
Definition: nat64.h:44
static void * vl_api_snat_det_session_dump_t_print(vl_api_snat_det_session_dump_t *mp, void *handle)
Definition: snat_api.c:1193
static void * vl_api_snat_add_del_interface_addr_t_print(vl_api_snat_add_del_interface_addr_t *mp, void *handle)
Definition: snat_api.c:580
static void * vl_api_snat_address_dump_t_print(vl_api_snat_address_dump_t *mp, void *handle)
Definition: snat_api.c:171
void nat64_db_st_walk(nat64_db_t *db, snat_protocol_t proto, nat64_db_st_walk_fn_t fn, void *ctx)
Walk NAT64 session table.
Definition: nat64_db.c:267
u32 nsessions
Definition: snat.h:153
u8 as_u8[16]
Definition: ip6_packet.h:48
static void vl_api_snat_ipfix_enable_disable_t_handler(vl_api_snat_ipfix_enable_disable_t *mp)
Definition: snat_api.c:639
static void * vl_api_nat64_add_del_prefix_t_print(vl_api_nat64_add_del_prefix_t *mp, void *handle)
Definition: snat_api.c:1705
#define REPLY_MACRO2(t, body)
int nat64_add_del_interface(u32 sw_if_index, u8 is_inside, u8 is_add)
Enable/disable NAT64 feature on the interface.
Definition: nat64.c:159
snat_protocol_t proto
Definition: snat.h:194
u8 is_disabled
Definition: nat64.h:71
static void snat_det_reverse(snat_det_map_t *dm, ip4_address_t *out_addr, u16 out_port, ip4_address_t *in_addr)
Definition: snat_det.h:90
static void * vl_api_nat64_interface_dump_t_print(vl_api_nat64_interface_dump_t *mp, void *handle)
Definition: snat_api.c:1411
Add/delete S-NAT deterministic mapping.
Definition: snat.api:386
static void send_snat_static_mapping_details(snat_static_mapping_t *m, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:320
static void vl_api_snat_user_dump_t_handler(vl_api_snat_user_dump_t *mp)
Definition: snat_api.c:694
int nat64_add_del_pool_addr(ip4_address_t *addr, u32 vrf_id, u8 is_add)
Add/delete address to NAT64 pool.
Definition: nat64.c:83
static void * vl_api_snat_det_close_session_out_t_print(vl_api_snat_det_close_session_out_t *mp, void *handle)
Definition: snat_api.c:1078
static int nat64_api_prefix_walk(nat64_prefix_t *p, void *arg)
Definition: snat_api.c:1718
static void vl_api_snat_control_ping_t_handler(vl_api_snat_control_ping_t *mp)
Definition: snat_api.c:406
Dump S-NAT deterministic mappings.
Definition: snat.api:460
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
Definition: snat_det.h:60
u32 nstaticsessions
Definition: snat.h:154
static void vl_api_snat_det_set_timeouts_t_handler(vl_api_snat_det_set_timeouts_t *mp)
Definition: snat_api.c:984
static void * vl_api_snat_ipfix_enable_disable_t_print(vl_api_snat_ipfix_enable_disable_t *mp, void *handle)
Definition: snat_api.c:655
Enable/disable S-NAT IPFIX logging.
Definition: snat.api:300
static void snat_det_forward(snat_det_map_t *dm, ip4_address_t *in_addr, ip4_address_t *out_addr, u16 *lo_port)
Definition: snat_det.h:75
int snat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable SNAT IPFIX logging.
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u32 fib_index
Definition: snat.h:151
static void vl_api_snat_det_map_dump_t_handler(vl_api_snat_det_map_dump_t *mp)
Definition: snat_api.c:957
static void vl_api_snat_det_close_session_out_t_handler(vl_api_snat_det_close_session_out_t *mp)
Definition: snat_api.c:1042
static int nat64_api_pool_walk(snat_address_t *a, void *arg)
Definition: snat_api.c:1271
static void * vl_api_snat_static_mapping_dump_t_print(vl_api_snat_static_mapping_dump_t *mp, void *handle)
Definition: snat_api.c:396
u8 in_plen
Definition: snat.h:176
dlist_elt_t * list_pool
Definition: snat.h:221
static void vl_api_nat64_interface_dump_t_handler(vl_api_nat64_interface_dump_t *mp)
Definition: snat_api.c:1390
int nat64_set_tcp_timeouts(u32 trans, u32 est, u32 incoming_syn)
Set TCP session timeouts.
Definition: nat64.c:459
Enable/disable NAT64 feature on the interface.
Definition: snat.api:648
static void vl_api_nat64_add_del_static_bib_t_handler(vl_api_nat64_add_del_static_bib_t *mp)
Definition: snat_api.c:1423
static void * vl_api_nat64_bib_dump_t_print(vl_api_nat64_bib_dump_t *mp, void *handle)
Definition: snat_api.c:1524
static void * vl_api_snat_add_address_range_t_print(vl_api_snat_add_address_range_t *mp, void *handle)
Definition: snat_api.c:116
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: snat_api.c:1850
S-NAT deterministic sessions reply.
Definition: snat.api:592
S-NAT user&#39;s sessions response.
Definition: snat.api:362
static void vl_api_snat_interface_add_del_feature_t_handler(vl_api_snat_interface_add_del_feature_t *mp)
Definition: snat_api.c:182
format_function_t format_ip4_address
Definition: format.h:79
void increment_v4_address(ip4_address_t *a)
Definition: snat.c:175
static void vl_api_snat_set_workers_t_handler(vl_api_snat_set_workers_t *mp)
Definition: snat_api.c:466
static void send_snat_interface_addr_details(u32 sw_if_index, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:594
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:376
Get values of timeouts for deterministic NAT reply.
Definition: snat.api:522
Dump NAT64 session table.
Definition: snat.api:785
ip4_address_t ext_host_addr
Definition: snat.h:59
Get outside address and port range from inside address.
Definition: snat.api:419
static void * vl_api_nat64_st_dump_t_print(vl_api_nat64_st_dump_t *mp, void *handle)
Definition: snat_api.c:1671
static clib_error_t * snat_plugin_api_hookup(vlib_main_t *vm)
Definition: snat_api.c:1809
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
Definition: nat64.c:438
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del)
Definition: snat.c:2043
ip4_address_t addr
Definition: snat.h:150
static void vl_api_snat_interface_dump_t_handler(vl_api_snat_interface_dump_t *mp)
Definition: snat_api.c:230
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void vl_api_snat_static_mapping_dump_t_handler(vl_api_snat_static_mapping_dump_t *mp)
Definition: snat_api.c:369
unsigned long u64
Definition: types.h:89
Set values of timeouts for deterministic NAT (seconds, 0 = default)
Definition: snat.api:496
S-NAT user&#39;s sessions.
Definition: snat.api:341
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1025
ip4_address_t local_addr
Definition: snat.h:187
Control ping from the client to the server response.
Definition: snat.api:180
Close CGNAT session by outside address and port.
Definition: snat.api:540
void * vl_msg_api_alloc(int nbytes)
nat64_db_t db
BIB and session DB.
Definition: nat64.h:62
snat_protocol_t proto
Definition: snat.h:208
Get values of timeouts for NAT64 (seconds)
Definition: snat.api:756
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
struct nat64_api_walk_ctx_t_ nat64_api_walk_ctx_t
S-NAT static mapping details response.
Definition: snat.api:151
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
Dump S-NAT workers.
Definition: snat.api:243
deterministic NAT definitions
Add/delete address range to NAT64 pool.
Definition: snat.api:612
snat_det_session_t * sessions
Definition: snat.h:183
u64 key
the key
Definition: bihash_8_8.h:32
u32 nat64_get_udp_timeout(void)
Get UDP session timeout.
Definition: nat64.c:430
Dump NAT64 pool addresses.
Definition: snat.api:625
static void * vl_api_snat_set_workers_t_print(vl_api_snat_set_workers_t *mp, void *handle)
Definition: snat_api.c:489
void nat64_db_bib_walk(nat64_db_t *db, snat_protocol_t proto, nat64_db_bib_walk_fn_t fn, void *ctx)
Walk NAT64 BIB.
Definition: nat64_db.c:213
Add/del NAT64 prefix.
Definition: snat.api:824
static void vl_api_snat_worker_dump_t_handler(vl_api_snat_worker_dump_t *mp)
Definition: snat_api.c:534
snat_main_t snat_main
Definition: jvpp_snat.h:39
S-NAT pool addresses interfaces details response.
Definition: snat.api:288
Set S-NAT workers.
Definition: snat.api:233
#define REPLY_MACRO(t)
S-NAT users response.
Definition: snat.api:476
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm)
Definition: snat.c:521
static void send_snat_static_map_resolve_details(snat_static_map_resolve_t *m, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:345
static void * vl_api_snat_det_close_session_in_t_print(vl_api_snat_det_close_session_in_t *mp, void *handle)
Definition: snat_api.c:1127
static void vl_api_snat_show_config_t_handler(vl_api_snat_show_config_t *mp)
Definition: snat_api.c:431
static void * vl_api_snat_interface_dump_t_print(vl_api_snat_interface_dump_t *mp, void *handle)
Definition: snat_api.c:249
u8 out_plen
Definition: snat.h:178
static void vl_api_nat64_bib_dump_t_handler(vl_api_nat64_bib_dump_t *mp)
Definition: snat_api.c:1500
#define SNAT_DET_SES_PER_USER
Definition: snat_det.h:30
Add/delete NAT64 static BIB entry.
Definition: snat.api:687
Dump S-NAT static mappings.
Definition: snat.api:134
Dump S-NAT deterministic sessions.
Definition: snat.api:575
u64 value
the value
Definition: bihash_8_8.h:33
#define BAD_SW_IF_INDEX_LABEL
u32 nat64_get_tcp_est_timeout(void)
Get TCP established timeout.
Definition: nat64.c:490
snat_user_t * users
Definition: snat.h:215
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
Definition: nat64.c:144
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:44
format_function_t format_ip6_address
Definition: format.h:95
nat64_db_bib_entry_t * nat64_db_bib_entry_by_index(nat64_db_t *db, snat_protocol_t proto, u32 bibe_index)
Get BIB entry by index and protocol.
Definition: nat64_db.c:243
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
Get outside address and port range from inside address.
Definition: snat.api:404
Dump interfaces with S-NAT feature.
Definition: snat.api:83
static void vl_api_nat64_pool_addr_dump_t_handler(vl_api_nat64_pool_addr_dump_t *mp)
Definition: snat_api.c:1298
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
Definition: nat64.c:611
#define clib_warning(format, args...)
Definition: error.h:59
static void * vl_api_snat_det_get_timeouts_t_print(vl_api_snat_det_get_timeouts_t *mp, void *handle)
Definition: snat_api.c:1031
int snat_set_workers(uword *bitmap)
Definition: snat.c:695
#define clib_memcpy(a, b, c)
Definition: string.h:69
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
u32 sharing_ratio
Definition: snat.h:179
static void * vl_api_nat64_add_del_pool_addr_range_t_print(vl_api_nat64_add_del_pool_addr_range_t *mp, void *handle)
Definition: snat_api.c:1251
ip4_address_t out_addr
Definition: snat.h:177
static void vl_api_nat64_add_del_pool_addr_range_t_handler(vl_api_nat64_add_del_pool_addr_range_t *mp)
Definition: snat_api.c:1209
int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, snat_protocol_t proto, int is_add)
Add static mapping.
Definition: snat.c:223
static void * vl_api_snat_control_ping_t_print(vl_api_snat_control_ping_t *mp, void *handle)
Definition: snat_api.c:421
static void * vl_api_snat_worker_dump_t_print(vl_api_snat_worker_dump_t *mp, void *handle)
Definition: snat_api.c:551
static uword * clib_bitmap_set_multiple(uword *bitmap, uword i, uword value, uword n_bits)
sets the ith through ith + n_bits bits in a bitmap
Definition: bitmap.h:275
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:30
#define ARRAY_LEN(x)
Definition: clib.h:59
u32 sw_if_index
Definition: snat.h:198
static void * vl_api_snat_det_set_timeouts_t_print(vl_api_snat_det_set_timeouts_t *mp, void *handle)
Definition: snat_api.c:999
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
Definition: snat.h:402
nat64_main_t nat64_main
Definition: nat64.c:25
static void * vl_api_snat_interface_add_del_feature_t_print(vl_api_snat_interface_add_del_feature_t *mp, void *handle)
Definition: snat_api.c:200
S-NAT address details response.
Definition: snat.api:57
static void sent_snat_det_map_details(snat_det_map_t *m, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:935
static void * vl_api_snat_interface_addr_dump_t_print(vl_api_snat_interface_addr_dump_t *mp, void *handle)
Definition: snat_api.c:628
Add/delete S-NAT static mapping.
Definition: snat.api:115
Enable/disable S-NAT feature on the interface.
Definition: snat.api:71
u32 vrf_id
Definition: nat64.h:46
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: snat_api.c:1831
snat_protocol_t
Definition: snat.h:98
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
static void * vl_api_snat_user_session_dump_t_print(vl_api_snat_user_session_dump_t *mp, void *handle)
Definition: snat_api.c:799
Dump S-NAT addresses.
Definition: snat.api:46
static void send_snat_interface_details(snat_interface_t *i, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:214
unsigned int u32
Definition: types.h:88
Get values of timeouts for NAT64 reply.
Definition: snat.api:770
u32 nat64_get_tcp_incoming_syn_timeout(void)
Get TCP incoming SYN timeout.
Definition: nat64.c:498
ip4_address_t l_addr
Definition: snat.h:203
static void * vl_api_snat_det_forward_t_print(vl_api_snat_det_forward_t *mp, void *handle)
Definition: snat_api.c:880
NAT64 pool address details response.
Definition: snat.api:635
Dump NAT64 prefix details response.
Definition: snat.api:848
Close CGNAT session by inside address and port.
Definition: snat.api:559
u64 as_u64
Definition: snat.h:75
static void vl_api_snat_det_get_timeouts_t_handler(vl_api_snat_det_get_timeouts_t *mp)
Definition: snat_api.c:1013
ip4_address_t addr
Definition: snat.h:72
static void vl_api_snat_det_session_dump_t_handler(vl_api_snat_det_session_dump_t *mp)
Definition: snat_api.c:1162
static u32 snat_det_user_ses_offset(ip4_address_t *addr, u8 plen)
Definition: snat_det.h:105
ip4_address_t in_addr
Definition: snat.h:175
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
static void vl_api_nat64_get_timeouts_t_handler(vl_api_nat64_get_timeouts_t *mp)
Definition: snat_api.c:1577
ip4_address_t addr
Definition: snat.h:158
static snat_det_session_t * snat_det_find_ses_by_in(snat_det_map_t *dm, ip4_address_t *in_addr, u16 in_port, snat_det_out_key_t out_key)
Definition: snat_det.h:129
#define FINISH
Definition: snat_api.c:51
static snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
Definition: snat_det.h:112
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
Definition: nat64.c:658
int snat_det_add_map(snat_main_t *sm, ip4_address_t *in_addr, u8 in_plen, ip4_address_t *out_addr, u8 out_plen, int is_add)
Add/delete deterministic NAT mapping.
Definition: snat_det.c:40
u32 value
Definition: dlist.h:32
u64 uword
Definition: types.h:112
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
Definition: nat64.c:212
static void * vl_api_snat_user_dump_t_print(vl_api_snat_user_dump_t *mp, void *handle)
Definition: snat_api.c:713
NAT64 global declarations.
S-NAT workers details response.
Definition: snat.api:254
static void * vl_api_snat_det_map_dump_t_print(vl_api_snat_det_map_dump_t *mp, void *handle)
Definition: snat_api.c:974
static void vl_api_snat_user_session_dump_t_handler(vl_api_snat_user_session_dump_t *mp)
Definition: snat_api.c:750
Dump NAT64 BIB.
Definition: snat.api:704
unsigned short u16
Definition: types.h:57
S-NAT users response.
Definition: snat.api:325
static void vl_api_snat_add_static_mapping_t_handler(vl_api_snat_add_static_mapping_t *mp)
Definition: snat_api.c:258
unix_shared_memory_queue_t * q
Definition: snat_api.c:1266
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * vl_api_nat64_set_timeouts_t_print(vl_api_nat64_set_timeouts_t *mp, void *handle)
Definition: snat_api.c:1562
unsigned char u8
Definition: types.h:56
static void send_snat_worker_details(u32 worker_index, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:515
static snat_det_map_t * snat_det_map_by_user(snat_main_t *sm, ip4_address_t *user_addr)
Definition: snat_det.h:45
u16 ports_per_host
Definition: snat.h:180
static void vl_api_snat_add_del_interface_addr_t_handler(vl_api_snat_add_del_interface_addr_t *mp)
Definition: snat_api.c:562
static void vl_api_nat64_add_del_interface_t_handler(vl_api_nat64_add_del_interface_t *mp)
Definition: snat_api.c:1330
Dump interfaces with NAT64 feature.
Definition: snat.api:660
static void * vl_api_nat64_add_del_interface_t_print(vl_api_nat64_add_del_interface_t *mp, void *handle)
Definition: snat_api.c:1357
static void vl_api_snat_add_det_map_t_handler(vl_api_snat_add_det_map_t *mp)
Definition: snat_api.c:816
static void * vl_api_nat64_prefix_dump_t_print(vl_api_nat64_prefix_dump_t *mp, void *handle)
Definition: snat_api.c:1759
snat_det_out_key_t out
Definition: snat.h:169
static void * vl_api_nat64_get_timeouts_t_print(vl_api_nat64_get_timeouts_t *mp, void *handle)
Definition: snat_api.c:1600
static void * vl_api_snat_add_det_map_t_print(vl_api_snat_add_det_map_t *mp, void *handle)
Definition: snat_api.c:832
#define foreach_snat_plugin_api_msg
Definition: snat_api.c:1770
u32 fib_index
Definition: snat.h:73
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: fib_table.c:27
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: snat.h:389
S-NAT interface details response.
Definition: snat.api:93
static int nat64_api_interface_walk(snat_interface_t *i, void *arg)
Definition: snat_api.c:1371
Dump S-NAT pool addresses interfaces.
Definition: snat.api:279
static void send_snat_address_details(snat_address_t *a, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:131
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
Definition: snat_det.h:179
Get values of timeouts for deterministic NAT (seconds)
Definition: snat.api:509
Show S-NAT plugin startup config reply.
Definition: snat.api:212
static int nat64_api_st_walk(nat64_db_st_entry_t *ste, void *arg)
Definition: snat_api.c:1610
static void send_snat_user_session_details(snat_session_t *s, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:724
Control ping from client to api server request.
Definition: snat.api:168
Get inside address from outside address and port reply.
Definition: snat.api:449
#define vec_foreach(var, vec)
Vector iterator.
u32 ses_num
Definition: snat.h:181
static void send_snat_user_details(snat_user_t *u, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:672
static void * vl_api_snat_det_reverse_t_print(vl_api_snat_det_reverse_t *mp, void *handle)
Definition: snat_api.c:922
Set values of timeouts for NAT64 (seconds, 0 = default)
Definition: snat.api:742
#define SNAT_SESSION_FLAG_STATIC_MAPPING
Definition: snat.h:122
static void * vl_api_nat64_add_del_static_bib_t_print(vl_api_nat64_add_del_static_bib_t *mp, void *handle)
Definition: snat_api.c:1454
static void vl_api_nat64_set_timeouts_t_handler(vl_api_nat64_set_timeouts_t *mp)
Definition: snat_api.c:1534
#define BITS(x)
Definition: clib.h:58
static void vl_api_snat_det_reverse_t_handler(vl_api_snat_det_reverse_t *mp)
Definition: snat_api.c:891
Show S-NAT plugin startup config.
Definition: snat.api:192
int nat64_add_del_static_bib_entry(ip6_address_t *in_addr, ip4_address_t *out_addr, u16 in_port, u16 out_port, u8 proto, u32 vrf_id, u8 is_add)
Add/delete static NAT64 BIB entry.
Definition: nat64.c:345
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Definition: snat.c:621
static void plugin_custom_dump_configure(snat_main_t *sm)
Definition: snat_api.c:1840
snat_session_t * sessions
Definition: snat.h:218
static void vl_api_snat_interface_addr_dump_t_handler(vl_api_snat_interface_addr_dump_t *mp)
Definition: snat_api.c:611
u32 fib_index
Definition: snat.h:159
static void vl_api_nat64_add_del_prefix_t_handler(vl_api_nat64_add_del_prefix_t *mp)
Definition: snat_api.c:1681
Get inside address from outside address and port.
Definition: snat.api:435
Dump S-NAT users.
Definition: snat.api:312
u32 nat64_get_tcp_trans_timeout(void)
Get TCP transitory timeout.
Definition: nat64.c:482
static void vl_api_nat64_prefix_dump_t_handler(vl_api_nat64_prefix_dump_t *mp)
Definition: snat_api.c:1738
static void vl_api_snat_address_dump_t_handler(vl_api_snat_address_dump_t *mp)
Definition: snat_api.c:154
#define VALIDATE_SW_IF_INDEX(mp)
A protocol Independent FIB table.
Definition: fib_table.h:29
struct _unix_shared_memory_queue unix_shared_memory_queue_t
NAT64 session table details response.
Definition: snat.api:803
static void send_snat_det_session_details(snat_det_session_t *s, unix_shared_memory_queue_t *q, u32 context)
Definition: snat_api.c:1141