FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
nat_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 NAT plugin API implementation
19  */
20 
21 #include <nat/nat.h>
22 #include <nat/nat_det.h>
23 #include <nat/nat64.h>
24 #include <nat/nat66.h>
25 #include <nat/dslite.h>
26 #include <nat/nat_reass.h>
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
29 
30 #include <nat/nat_msg_enum.h>
31 #include <vnet/fib/fib_table.h>
32 
33 #define vl_api_nat44_lb_addr_port_t_endian vl_noop_handler
34 #define vl_api_nat44_add_del_lb_static_mapping_t_endian vl_noop_handler
35 #define vl_api_nat44_nat44_lb_static_mapping_details_t_endian vl_noop_handler
36 
37 /* define message structures */
38 #define vl_typedefs
39 #include <nat/nat_all_api_h.h>
40 #undef vl_typedefs
41 
42 /* define generated endian-swappers */
43 #define vl_endianfun
44 #include <nat/nat_all_api_h.h>
45 #undef vl_endianfun
46 
47 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
48 
49 #define REPLY_MSG_ID_BASE sm->msg_id_base
51 
52 /* Get the API version number */
53 #define vl_api_version(n,v) static u32 api_version=(v);
54 #include <nat/nat_all_api_h.h>
55 #undef vl_api_version
56 
57 /* Macro to finish up custom dump fns */
58 #define FINISH \
59  vec_add1 (s, 0); \
60  vl_print (handle, (char *)s); \
61  vec_free (s); \
62  return handle;
63 
64 
65 /******************************/
66 /*** Common NAT plugin APIs ***/
67 /******************************/
68 
69 static void
71 {
73  snat_main_t *sm = &snat_main;
74  int rv = 0;
75 
76  /* *INDENT-OFF* */
77  REPLY_MACRO2 (VL_API_NAT_CONTROL_PING_REPLY,
78  ({
79  rmp->vpe_pid = ntohl (getpid ());
80  }));
81  /* *INDENT-ON* */
82 }
83 
84 static void *
86 {
87  u8 *s;
88 
89  s = format (0, "SCRIPT: nat_control_ping ");
90 
91  FINISH;
92 }
93 
94 static void
96 {
98  snat_main_t *sm = &snat_main;
99  int rv = 0;
100 
101  /* *INDENT-OFF* */
102  REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_REPLY,
103  ({
104  rmp->translation_buckets = htonl (sm->translation_buckets);
106  rmp->user_buckets = htonl (sm->user_buckets);
107  rmp->user_memory_size = htonl (sm->user_memory_size);
109  rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
110  rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
114  rmp->deterministic = sm->deterministic;
115  }));
116  /* *INDENT-ON* */
117 }
118 
119 static void *
121 {
122  u8 *s;
123 
124  s = format (0, "SCRIPT: nat_show_config ");
125 
126  FINISH;
127 }
128 
129 static void
131 {
132  snat_main_t *sm = &snat_main;
133  vl_api_nat_set_workers_reply_t *rmp;
134  int rv = 0;
135  uword *bitmap = 0;
136  u64 mask = clib_net_to_host_u64 (mp->worker_mask);
137 
138  if (sm->num_workers < 2)
139  {
140  rv = VNET_API_ERROR_FEATURE_DISABLED;
141  goto send_reply;
142  }
143 
144  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
145  rv = snat_set_workers (bitmap);
146  clib_bitmap_free (bitmap);
147 
148 send_reply:
149  REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
150 }
151 
152 static void *
154 {
155  u8 *s;
156  uword *bitmap = 0;
157  u8 first = 1;
158  int i;
159  u64 mask = clib_net_to_host_u64 (mp->worker_mask);
160 
161  s = format (0, "SCRIPT: nat_set_workers ");
162  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
163  /* *INDENT-OFF* */
164  clib_bitmap_foreach (i, bitmap,
165  ({
166  if (first)
167  s = format (s, "%d", i);
168  else
169  s = format (s, ",%d", i);
170  first = 0;
171  }));
172  /* *INDENT-ON* */
173  clib_bitmap_free (bitmap);
174  FINISH;
175 }
176 
177 static void
179  u32 context)
180 {
182  snat_main_t *sm = &snat_main;
184  vlib_worker_threads + worker_index + sm->first_worker_index;
185 
186  rmp = vl_msg_api_alloc (sizeof (*rmp));
187  memset (rmp, 0, sizeof (*rmp));
188  rmp->_vl_msg_id = ntohs (VL_API_NAT_WORKER_DETAILS + sm->msg_id_base);
189  rmp->context = context;
190  rmp->worker_index = htonl (worker_index);
191  rmp->lcore_id = htonl (w->lcore_id);
192  strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1);
193 
194  vl_api_send_msg (reg, (u8 *) rmp);
195 }
196 
197 static void
199 {
201  snat_main_t *sm = &snat_main;
202  u32 *worker_index;
203 
205  if (!reg)
206  return;
207 
208  /* *INDENT-OFF* */
209  vec_foreach (worker_index, sm->workers)
210  send_nat_worker_details(*worker_index, reg, mp->context);
211  /* *INDENT-ON* */
212 }
213 
214 static void *
216 {
217  u8 *s;
218 
219  s = format (0, "SCRIPT: nat_worker_dump ");
220 
221  FINISH;
222 }
223 
224 static void
226  mp)
227 {
228  snat_main_t *sm = &snat_main;
229  vl_api_nat_ipfix_enable_disable_reply_t *rmp;
230  int rv = 0;
231 
233  clib_host_to_net_u32
234  (mp->domain_id),
235  clib_host_to_net_u16
236  (mp->src_port));
237 
238  REPLY_MACRO (VL_API_NAT_IPFIX_ENABLE_DISABLE_REPLY);
239 }
240 
241 static void *
243  mp, void *handle)
244 {
245  u8 *s;
246 
247  s = format (0, "SCRIPT: nat_ipfix_enable_disable ");
248  if (mp->domain_id)
249  s = format (s, "domain %d ", clib_net_to_host_u32 (mp->domain_id));
250  if (mp->src_port)
251  s = format (s, "src_port %d ", clib_net_to_host_u16 (mp->src_port));
252  if (!mp->enable)
253  s = format (s, "disable ");
254 
255  FINISH;
256 }
257 
258 static void
260 {
261  snat_main_t *sm = &snat_main;
262  vl_api_nat_set_reass_reply_t *rmp;
263  int rv = 0;
264 
265  rv =
266  nat_reass_set (ntohl (mp->timeout), ntohs (mp->max_reass), mp->max_frag,
267  mp->drop_frag, mp->is_ip6);
268 
269  REPLY_MACRO (VL_API_NAT_SET_REASS_REPLY);
270 }
271 
272 static void *
274 {
275  u8 *s;
276 
277  s = format (0, "SCRIPT: nat_set_reass ");
278  s = format (s, "timeout %d max_reass %d max_frag %d drop_frag %d is_ip6 %d",
279  clib_host_to_net_u32 (mp->timeout),
280  clib_host_to_net_u16 (mp->max_reass),
281  mp->max_frag, mp->drop_frag, mp->is_ip6);
282 
283  FINISH;
284 }
285 
286 static void
288 {
289  snat_main_t *sm = &snat_main;
291  int rv = 0;
292 
293  /* *INDENT-OFF* */
294  REPLY_MACRO2 (VL_API_NAT_GET_REASS_REPLY,
295  ({
296  rmp->ip4_timeout = htonl (nat_reass_get_timeout(0));
297  rmp->ip4_max_reass = htons (nat_reass_get_max_reass(0));
300  rmp->ip6_timeout = htonl (nat_reass_get_timeout(1));
301  rmp->ip6_max_reass = htons (nat_reass_get_max_reass(1));
304  }))
305  /* *INDENT-ON* */
306 }
307 
308 static void *
310 {
311  u8 *s;
312 
313  s = format (0, "SCRIPT: nat_get_reass");
314 
315  FINISH;
316 }
317 
318 typedef struct nat_api_walk_ctx_t_
319 {
323 
324 static int
325 nat_ip4_reass_walk_api (nat_reass_ip4_t * reass, void *arg)
326 {
328  snat_main_t *sm = &snat_main;
329  nat_api_walk_ctx_t *ctx = arg;
330 
331  rmp = vl_msg_api_alloc (sizeof (*rmp));
332  memset (rmp, 0, sizeof (*rmp));
333  rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base);
334  rmp->context = ctx->context;
335  clib_memcpy (rmp->src_addr, &(reass->key.src), 4);
336  clib_memcpy (rmp->dst_addr, &(reass->key.dst), 4);
337  rmp->proto = reass->key.proto;
338  rmp->frag_id = ntohl (reass->key.frag_id);
339  rmp->frag_n = reass->frag_n;
340  rmp->is_ip4 = 1;
341 
342  vl_api_send_msg (ctx->reg, (u8 *) rmp);
343 
344  return 0;
345 }
346 
347 static int
348 nat_ip6_reass_walk_api (nat_reass_ip6_t * reass, void *arg)
349 {
351  snat_main_t *sm = &snat_main;
352  nat_api_walk_ctx_t *ctx = arg;
353 
354  rmp = vl_msg_api_alloc (sizeof (*rmp));
355  memset (rmp, 0, sizeof (*rmp));
356  rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base);
357  rmp->context = ctx->context;
358  clib_memcpy (rmp->src_addr, &(reass->key.src), 16);
359  clib_memcpy (rmp->dst_addr, &(reass->key.dst), 16);
360  rmp->proto = reass->key.proto;
361  rmp->frag_id = ntohl (reass->key.frag_id);
362  rmp->frag_n = reass->frag_n;
363  rmp->is_ip4 = 0;
364 
365  vl_api_send_msg (ctx->reg, (u8 *) rmp);
366 
367  return 0;
368 }
369 
370 static void
372 {
374 
376  if (!reg)
377  return;
378 
380  .reg = reg,
381  .context = mp->context,
382  };
383 
386 }
387 
388 static void *
390 {
391  u8 *s;
392 
393  s = format (0, "SCRIPT: nat_reass_dump");
394 
395  FINISH;
396 }
397 
398 /*************/
399 /*** NAT44 ***/
400 /*************/
401 static void
404 {
405  snat_main_t *sm = &snat_main;
406  vl_api_nat44_add_del_address_range_reply_t *rmp;
407  ip4_address_t this_addr;
408  u32 start_host_order, end_host_order;
409  u32 vrf_id;
410  int i, count;
411  int rv = 0;
412  u32 *tmp;
413 
414  if (sm->static_mapping_only)
415  {
416  rv = VNET_API_ERROR_FEATURE_DISABLED;
417  goto send_reply;
418  }
419 
420  tmp = (u32 *) mp->first_ip_address;
421  start_host_order = clib_host_to_net_u32 (tmp[0]);
422  tmp = (u32 *) mp->last_ip_address;
423  end_host_order = clib_host_to_net_u32 (tmp[0]);
424 
425  count = (end_host_order - start_host_order) + 1;
426 
427  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
428 
429  if (count > 1024)
430  clib_warning ("%U - %U, %d addresses...",
432  format_ip4_address, mp->last_ip_address, count);
433 
434  memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
435 
436  for (i = 0; i < count; i++)
437  {
438  if (mp->is_add)
439  snat_add_address (sm, &this_addr, vrf_id, mp->twice_nat);
440  else
441  rv = snat_del_address (sm, this_addr, 0, mp->twice_nat);
442 
443  if (rv)
444  goto send_reply;
445 
446  if (sm->out2in_dpo)
447  nat44_add_del_address_dpo (this_addr, mp->is_add);
448 
449  increment_v4_address (&this_addr);
450  }
451 
452 send_reply:
453  REPLY_MACRO (VL_API_NAT44_ADD_DEL_ADDRESS_RANGE_REPLY);
454 }
455 
458 {
459  u8 *s;
460 
461  s = format (0, "SCRIPT: nat44_add_address_range ");
462  s = format (s, "%U ", format_ip4_address, mp->first_ip_address);
463  if (memcmp (mp->first_ip_address, mp->last_ip_address, 4))
464  {
465  s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
466  }
467  s = format (s, "twice_nat %d ", mp->twice_nat);
468  FINISH;
469 }
470 
471 static void
474  u8 twice_nat)
475 {
477  snat_main_t *sm = &snat_main;
478 
479  rmp = vl_msg_api_alloc (sizeof (*rmp));
480  memset (rmp, 0, sizeof (*rmp));
481  rmp->_vl_msg_id = ntohs (VL_API_NAT44_ADDRESS_DETAILS + sm->msg_id_base);
482  clib_memcpy (rmp->ip_address, &(a->addr), 4);
483  if (a->fib_index != ~0)
484  {
486  rmp->vrf_id = ntohl (fib->ft_table_id);
487  }
488  else
489  rmp->vrf_id = ~0;
490  rmp->twice_nat = twice_nat;
491  rmp->context = context;
492 
493  vl_api_send_msg (reg, (u8 *) rmp);
494 }
495 
496 static void
498 {
500  snat_main_t *sm = &snat_main;
501  snat_address_t *a;
502 
504  if (!reg)
505  return;
506 
507  /* *INDENT-OFF* */
508  vec_foreach (a, sm->addresses)
509  send_nat44_address_details (a, reg, mp->context, 0);
511  send_nat44_address_details (a, reg, mp->context, 1);
512  /* *INDENT-ON* */
513 }
514 
515 static void *
517  void *handle)
518 {
519  u8 *s;
520 
521  s = format (0, "SCRIPT: nat44_address_dump ");
522 
523  FINISH;
524 }
525 
526 static void
529 {
530  snat_main_t *sm = &snat_main;
531  vl_api_nat44_interface_add_del_feature_reply_t *rmp;
532  u8 is_del = mp->is_add == 0;
533  u32 sw_if_index = ntohl (mp->sw_if_index);
534  int rv = 0;
535 
537 
538  rv = snat_interface_add_del (sw_if_index, mp->is_inside, is_del);
539 
541 
542  REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_FEATURE_REPLY);
543 }
544 
547 {
548  u8 *s;
549 
550  s = format (0, "SCRIPT: nat44_interface_add_del_feature ");
551  s = format (s, "sw_if_index %d %s %s",
552  clib_host_to_net_u32 (mp->sw_if_index),
553  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
554 
555  FINISH;
556 }
557 
558 static void
561 {
563  snat_main_t *sm = &snat_main;
564 
565  rmp = vl_msg_api_alloc (sizeof (*rmp));
566  memset (rmp, 0, sizeof (*rmp));
567  rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_DETAILS + sm->msg_id_base);
568  rmp->sw_if_index = ntohl (i->sw_if_index);
570  && nat_interface_is_outside (i)) ? 2 :
572  rmp->context = context;
573 
574  vl_api_send_msg (reg, (u8 *) rmp);
575 }
576 
577 static void
579 {
581  snat_main_t *sm = &snat_main;
583 
585  if (!reg)
586  return;
587 
588  /* *INDENT-OFF* */
589  pool_foreach (i, sm->interfaces,
590  ({
591  send_nat44_interface_details(i, reg, mp->context);
592  }));
593  /* *INDENT-ON* */
594 }
595 
596 static void *
598  void *handle)
599 {
600  u8 *s;
601 
602  s = format (0, "SCRIPT: nat44_interface_dump ");
603 
604  FINISH;
605 }
606 
607 static void
610 {
611  snat_main_t *sm = &snat_main;
612  vl_api_nat44_interface_add_del_output_feature_reply_t *rmp;
613  u8 is_del = mp->is_add == 0;
614  u32 sw_if_index = ntohl (mp->sw_if_index);
615  int rv = 0;
616 
618 
619  rv = snat_interface_add_del_output_feature (sw_if_index, mp->is_inside,
620  is_del);
621 
623 
624  REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY);
625 }
626 
629 {
630  u8 *s;
631 
632  s = format (0, "SCRIPT: nat44_interface_add_del_output_feature ");
633  s = format (s, "sw_if_index %d %s %s",
634  clib_host_to_net_u32 (mp->sw_if_index),
635  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
636 
637  FINISH;
638 }
639 
640 static void
643  u32 context)
644 {
646  snat_main_t *sm = &snat_main;
647 
648  rmp = vl_msg_api_alloc (sizeof (*rmp));
649  memset (rmp, 0, sizeof (*rmp));
650  rmp->_vl_msg_id =
651  ntohs (VL_API_NAT44_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base);
652  rmp->sw_if_index = ntohl (i->sw_if_index);
653  rmp->context = context;
655 
656  vl_api_send_msg (reg, (u8 *) rmp);
657 }
658 
659 static void
662 {
664  snat_main_t *sm = &snat_main;
666 
668  if (!reg)
669  return;
670 
671  /* *INDENT-OFF* */
673  ({
674  send_nat44_interface_output_feature_details(i, reg, mp->context);
675  }));
676  /* *INDENT-ON* */
677 }
678 
681 {
682  u8 *s;
683 
684  s = format (0, "SCRIPT: nat44_interface_output_feature_dump ");
685 
686  FINISH;
687 }
688 
689 static void
692 {
693  snat_main_t *sm = &snat_main;
694  vl_api_nat44_add_del_static_mapping_reply_t *rmp;
695  ip4_address_t local_addr, external_addr;
696  u16 local_port = 0, external_port = 0;
697  u32 vrf_id, external_sw_if_index;
698  int rv = 0;
699  snat_protocol_t proto;
700  u8 *tag = 0;
701 
702  memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
703  memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
704  if (mp->addr_only == 0)
705  {
706  local_port = clib_net_to_host_u16 (mp->local_port);
707  external_port = clib_net_to_host_u16 (mp->external_port);
708  }
709  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
710  external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
711  proto = ip_proto_to_snat_proto (mp->protocol);
712  mp->tag[sizeof (mp->tag) - 1] = 0;
713  tag = format (0, "%s", mp->tag);
715 
716  rv = snat_add_static_mapping (local_addr, external_addr, local_port,
717  external_port, vrf_id, mp->addr_only,
718  external_sw_if_index, proto, mp->is_add,
719  mp->twice_nat, mp->out2in_only, tag);
720 
721  vec_free (tag);
722 
723  REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY);
724 }
725 
728 {
729  u8 *s;
730 
731  s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
732  s = format (s, "protocol %d local_addr %U external_addr %U ",
733  mp->protocol,
736 
737  if (mp->addr_only == 0)
738  s = format (s, "local_port %d external_port %d ",
739  clib_net_to_host_u16 (mp->local_port),
740  clib_net_to_host_u16 (mp->external_port));
741 
742  s = format (s, "twice_nat %d out2in_only %d ",
743  mp->twice_nat, mp->out2in_only);
744 
745  if (mp->vrf_id != ~0)
746  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
747 
748  if (mp->external_sw_if_index != ~0)
749  s = format (s, "external_sw_if_index %d",
750  clib_net_to_host_u32 (mp->external_sw_if_index));
751  FINISH;
752 }
753 
754 static void
757 {
759  snat_main_t *sm = &snat_main;
760 
761  rmp = vl_msg_api_alloc (sizeof (*rmp));
762  memset (rmp, 0, sizeof (*rmp));
763  rmp->_vl_msg_id =
764  ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
765  rmp->addr_only = m->addr_only;
766  clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
768  rmp->external_sw_if_index = ~0;
769  rmp->vrf_id = htonl (m->vrf_id);
770  rmp->context = context;
771  rmp->twice_nat = m->twice_nat;
772  rmp->out2in_only = m->out2in_only;
773  if (m->addr_only == 0)
774  {
776  rmp->external_port = htons (m->external_port);
777  rmp->local_port = htons (m->local_port);
778  }
779  if (m->tag)
780  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
781 
782  vl_api_send_msg (reg, (u8 *) rmp);
783 }
784 
785 static void
788  u32 context)
789 {
791  snat_main_t *sm = &snat_main;
792 
793  rmp = vl_msg_api_alloc (sizeof (*rmp));
794  memset (rmp, 0, sizeof (*rmp));
795  rmp->_vl_msg_id =
796  ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
797  rmp->addr_only = m->addr_only;
798  clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
799  rmp->external_sw_if_index = htonl (m->sw_if_index);
800  rmp->vrf_id = htonl (m->vrf_id);
801  rmp->context = context;
802  rmp->twice_nat = m->twice_nat;
803  if (m->addr_only == 0)
804  {
806  rmp->external_port = htons (m->e_port);
807  rmp->local_port = htons (m->l_port);
808  }
809  if (m->tag)
810  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
811 
812  vl_api_send_msg (reg, (u8 *) rmp);
813 }
814 
815 static void
817  * mp)
818 {
820  snat_main_t *sm = &snat_main;
823  int j;
824 
826  if (!reg)
827  return;
828 
829  /* *INDENT-OFF* */
831  ({
832  if (!vec_len(m->locals) && (m->local_addr.as_u32 != m->external_addr.as_u32))
833  send_nat44_static_mapping_details (m, reg, mp->context);
834  }));
835  /* *INDENT-ON* */
836 
837  for (j = 0; j < vec_len (sm->to_resolve); j++)
838  {
839  rp = sm->to_resolve + j;
840  if (rp->l_addr.as_u32 != 0)
842  }
843 }
844 
845 static void *
847  mp, void *handle)
848 {
849  u8 *s;
850 
851  s = format (0, "SCRIPT: nat44_static_mapping_dump ");
852 
853  FINISH;
854 }
855 
856 static void
859 {
860  snat_main_t *sm = &snat_main;
861  vl_api_nat44_add_del_identity_mapping_reply_t *rmp;
863  u16 port = 0;
864  u32 vrf_id, sw_if_index;
865  int rv = 0;
866  snat_protocol_t proto = ~0;
867  u8 *tag = 0;
868 
869  if (mp->addr_only == 0)
870  {
871  port = clib_net_to_host_u16 (mp->port);
872  proto = ip_proto_to_snat_proto (mp->protocol);
873  }
874  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
875  sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
876  if (sw_if_index != ~0)
877  addr.as_u32 = 0;
878  else
879  memcpy (&addr.as_u8, mp->ip_address, 4);
880  mp->tag[sizeof (mp->tag) - 1] = 0;
881  tag = format (0, "%s", mp->tag);
883 
884  rv =
885  snat_add_static_mapping (addr, addr, port, port, vrf_id, mp->addr_only,
886  sw_if_index, proto, mp->is_add, 0, 0, tag);
887 
888  vec_free (tag);
889 
890  REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY);
891 }
892 
895 {
896  u8 *s;
897 
898  s = format (0, "SCRIPT: nat44_add_del_identity_mapping ");
899  if (mp->sw_if_index != ~0)
900  s = format (s, "sw_if_index %d", clib_net_to_host_u32 (mp->sw_if_index));
901  else
902  s = format (s, "addr %U", format_ip4_address, mp->ip_address);
903 
904  if (mp->addr_only == 0)
905  s =
906  format (s, "protocol %d port %d", mp->protocol,
907  clib_net_to_host_u16 (mp->port));
908 
909  if (mp->vrf_id != ~0)
910  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
911 
912  FINISH;
913 }
914 
915 static void
918 {
920  snat_main_t *sm = &snat_main;
921 
922  rmp = vl_msg_api_alloc (sizeof (*rmp));
923  memset (rmp, 0, sizeof (*rmp));
924  rmp->_vl_msg_id =
925  ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
926  rmp->addr_only = m->addr_only;
927  clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
928  rmp->port = htons (m->local_port);
929  rmp->sw_if_index = ~0;
930  rmp->vrf_id = htonl (m->vrf_id);
932  rmp->context = context;
933  if (m->tag)
934  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
935 
936  vl_api_send_msg (reg, (u8 *) rmp);
937 }
938 
939 static void
942  u32 context)
943 {
945  snat_main_t *sm = &snat_main;
946 
947  rmp = vl_msg_api_alloc (sizeof (*rmp));
948  memset (rmp, 0, sizeof (*rmp));
949  rmp->_vl_msg_id =
950  ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
951  rmp->addr_only = m->addr_only;
952  rmp->port = htons (m->l_port);
953  rmp->sw_if_index = htonl (m->sw_if_index);
954  rmp->vrf_id = htonl (m->vrf_id);
956  rmp->context = context;
957  if (m->tag)
958  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
959 
960  vl_api_send_msg (reg, (u8 *) rmp);
961 }
962 
963 static void
966 {
968  snat_main_t *sm = &snat_main;
971  int j;
972 
974  if (!reg)
975  return;
976 
977  /* *INDENT-OFF* */
979  ({
980  if (!vec_len(m->locals) && (m->local_addr.as_u32 == m->external_addr.as_u32))
981  send_nat44_identity_mapping_details (m, reg, mp->context);
982  }));
983  /* *INDENT-ON* */
984 
985  for (j = 0; j < vec_len (sm->to_resolve); j++)
986  {
987  rp = sm->to_resolve + j;
988  if (rp->l_addr.as_u32 == 0)
990  }
991 }
992 
995 {
996  u8 *s;
997 
998  s = format (0, "SCRIPT: nat44_identity_mapping_dump ");
999 
1000  FINISH;
1001 }
1002 
1003 static void
1006 {
1007  snat_main_t *sm = &snat_main;
1008  vl_api_nat44_add_del_interface_addr_reply_t *rmp;
1009  u8 is_del = mp->is_add == 0;
1010  u32 sw_if_index = ntohl (mp->sw_if_index);
1011  int rv = 0;
1012 
1013  VALIDATE_SW_IF_INDEX (mp);
1014 
1015  rv = snat_add_interface_address (sm, sw_if_index, is_del, mp->twice_nat);
1016 
1018 
1019  REPLY_MACRO (VL_API_NAT44_ADD_DEL_INTERFACE_ADDR_REPLY);
1020 }
1021 
1024 {
1025  u8 *s;
1026 
1027  s = format (0, "SCRIPT: nat44_add_del_interface_addr ");
1028  s = format (s, "sw_if_index %d twice_nat %d %s",
1029  clib_host_to_net_u32 (mp->sw_if_index),
1030  mp->twice_nat, mp->is_add ? "" : "del");
1031 
1032  FINISH;
1033 }
1034 
1035 static void
1038  u8 twice_nat)
1039 {
1041  snat_main_t *sm = &snat_main;
1042 
1043  rmp = vl_msg_api_alloc (sizeof (*rmp));
1044  memset (rmp, 0, sizeof (*rmp));
1045  rmp->_vl_msg_id =
1046  ntohs (VL_API_NAT44_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
1047  rmp->sw_if_index = ntohl (sw_if_index);
1048  rmp->twice_nat = twice_nat;
1049  rmp->context = context;
1050 
1051  vl_api_send_msg (reg, (u8 *) rmp);
1052 }
1053 
1054 static void
1056  * mp)
1057 {
1059  snat_main_t *sm = &snat_main;
1060  u32 *i;
1061 
1063  if (!reg)
1064  return;
1065 
1066  /* *INDENT-OFF* */
1068  send_nat44_interface_addr_details(*i, reg, mp->context, 0);
1070  send_nat44_interface_addr_details(*i, reg, mp->context, 1);
1071  /* *INDENT-ON* */
1072 }
1073 
1074 static void *
1076  mp, void *handle)
1077 {
1078  u8 *s;
1079 
1080  s = format (0, "SCRIPT: nat44_interface_addr_dump ");
1081 
1082  FINISH;
1083 }
1084 
1085 static void
1087  u32 context)
1088 {
1090  snat_main_t *sm = &snat_main;
1092 
1093  rmp = vl_msg_api_alloc (sizeof (*rmp));
1094  memset (rmp, 0, sizeof (*rmp));
1095  rmp->_vl_msg_id = ntohs (VL_API_NAT44_USER_DETAILS + sm->msg_id_base);
1096 
1097  rmp->vrf_id = ntohl (fib->ft_table_id);
1098 
1099  clib_memcpy (rmp->ip_address, &(u->addr), 4);
1100  rmp->nsessions = ntohl (u->nsessions);
1101  rmp->nstaticsessions = ntohl (u->nstaticsessions);
1102  rmp->context = context;
1103 
1104  vl_api_send_msg (reg, (u8 *) rmp);
1105 }
1106 
1107 static void
1109 {
1111  snat_main_t *sm = &snat_main;
1113  snat_user_t *u;
1114 
1116  if (!reg)
1117  return;
1118 
1119  /* *INDENT-OFF* */
1120  vec_foreach (tsm, sm->per_thread_data)
1121  vec_foreach (u, tsm->users)
1122  send_nat44_user_details (u, reg, mp->context);
1123  /* *INDENT-ON* */
1124 }
1125 
1126 static void *
1128 {
1129  u8 *s;
1130 
1131  s = format (0, "SCRIPT: nat44_user_dump ");
1132 
1133  FINISH;
1134 }
1135 
1136 static void
1139 {
1141  snat_main_t *sm = &snat_main;
1142 
1143  rmp = vl_msg_api_alloc (sizeof (*rmp));
1144  memset (rmp, 0, sizeof (*rmp));
1145  rmp->_vl_msg_id =
1146  ntohs (VL_API_NAT44_USER_SESSION_DETAILS + sm->msg_id_base);
1147  clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
1148  clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
1149  rmp->is_static = s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING ? 1 : 0;
1150  rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
1151  rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
1152  rmp->total_pkts = ntohl (s->total_pkts);
1153  rmp->context = context;
1154  if (snat_is_unk_proto_session (s))
1155  {
1156  rmp->outside_port = 0;
1157  rmp->inside_port = 0;
1158  rmp->protocol = ntohs (s->in2out.port);
1159  }
1160  else
1161  {
1162  rmp->outside_port = s->out2in.port;
1163  rmp->inside_port = s->in2out.port;
1164  rmp->protocol = ntohs (snat_proto_to_ip_proto (s->in2out.protocol));
1165  }
1166 
1167  vl_api_send_msg (reg, (u8 *) rmp);
1168 }
1169 
1170 static void
1172  mp)
1173 {
1175  snat_main_t *sm = &snat_main;
1177  snat_session_t *s;
1178  clib_bihash_kv_8_8_t key, value;
1179  snat_user_key_t ukey;
1180  snat_user_t *u;
1181  u32 session_index, head_index, elt_index;
1182  dlist_elt_t *head, *elt;
1183  ip4_header_t ip;
1184 
1186  if (!reg)
1187  return;
1188 
1189  clib_memcpy (&ukey.addr, mp->ip_address, 4);
1190  ip.src_address.as_u32 = ukey.addr.as_u32;
1191  ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
1192  key.key = ukey.as_u64;
1193  if (sm->num_workers > 1)
1194  tsm =
1196  sm->worker_in2out_cb (&ip, ukey.fib_index));
1197  else
1198  tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
1199  if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
1200  return;
1201  u = pool_elt_at_index (tsm->users, value.value);
1202  if (!u->nsessions && !u->nstaticsessions)
1203  return;
1204 
1205  head_index = u->sessions_per_user_list_head_index;
1206  head = pool_elt_at_index (tsm->list_pool, head_index);
1207  elt_index = head->next;
1208  elt = pool_elt_at_index (tsm->list_pool, elt_index);
1209  session_index = elt->value;
1210  while (session_index != ~0)
1211  {
1212  s = pool_elt_at_index (tsm->sessions, session_index);
1213 
1215 
1216  elt_index = elt->next;
1217  elt = pool_elt_at_index (tsm->list_pool, elt_index);
1218  session_index = elt->value;
1219  }
1220 }
1221 
1222 static void *
1224  void *handle)
1225 {
1226  u8 *s;
1227 
1228  s = format (0, "SCRIPT: nat44_user_session_dump ");
1229  s = format (s, "ip_address %U vrf_id %d\n",
1231  clib_net_to_host_u32 (mp->vrf_id));
1232 
1233  FINISH;
1234 }
1235 
1236 static nat44_lb_addr_port_t *
1238  u8 addr_port_pair_num)
1239 {
1240  u8 i;
1241  nat44_lb_addr_port_t *lb_addr_port_pairs = 0, lb_addr_port;
1243 
1244  for (i = 0; i < addr_port_pair_num; i++)
1245  {
1246  ap = &addr_port_pairs[i];
1247  memset (&lb_addr_port, 0, sizeof (lb_addr_port));
1248  clib_memcpy (&lb_addr_port.addr, ap->addr, 4);
1249  lb_addr_port.port = clib_net_to_host_u16 (ap->port);
1250  lb_addr_port.probability = ap->probability;
1251  vec_add1 (lb_addr_port_pairs, lb_addr_port);
1252  }
1253 
1254  return lb_addr_port_pairs;
1255 }
1256 
1257 static void
1260 {
1261  snat_main_t *sm = &snat_main;
1262  vl_api_nat44_add_del_lb_static_mapping_reply_t *rmp;
1263  int rv = 0;
1264  nat44_lb_addr_port_t *locals = 0;
1265  ip4_address_t e_addr;
1266  snat_protocol_t proto;
1267  u8 *tag = 0;
1268 
1269  locals = unformat_nat44_lb_addr_port (mp->locals, mp->local_num);
1270  clib_memcpy (&e_addr, mp->external_addr, 4);
1271  proto = ip_proto_to_snat_proto (mp->protocol);
1272  mp->tag[sizeof (mp->tag) - 1] = 0;
1273  tag = format (0, "%s", mp->tag);
1274  vec_terminate_c_string (tag);
1275 
1276  rv =
1278  clib_net_to_host_u16 (mp->external_port),
1279  proto, clib_net_to_host_u32 (mp->vrf_id),
1280  locals, mp->is_add, mp->twice_nat,
1281  mp->out2in_only, tag);
1282 
1283  vec_free (locals);
1284  vec_free (tag);
1285 
1286  REPLY_MACRO (VL_API_NAT44_ADD_DEL_LB_STATIC_MAPPING_REPLY);
1287 }
1288 
1291 {
1292  u8 *s;
1293 
1294  s = format (0, "SCRIPT: nat44_add_del_lb_static_mapping ");
1295  s = format (s, "is_add %d twice_nat %d out2in_only %d ",
1296  mp->is_add, mp->twice_nat, mp->out2in_only);
1297 
1298  FINISH;
1299 }
1300 
1301 static void
1304  u32 context)
1305 {
1307  snat_main_t *sm = &snat_main;
1310 
1311  rmp =
1312  vl_msg_api_alloc (sizeof (*rmp) +
1313  (vec_len (m->locals) * sizeof (nat44_lb_addr_port_t)));
1314  memset (rmp, 0, sizeof (*rmp));
1315  rmp->_vl_msg_id =
1316  ntohs (VL_API_NAT44_LB_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1317 
1318  clib_memcpy (rmp->external_addr, &(m->external_addr), 4);
1319  rmp->external_port = ntohs (m->external_port);
1321  rmp->vrf_id = ntohl (m->vrf_id);
1322  rmp->context = context;
1323  rmp->twice_nat = m->twice_nat;
1324  rmp->out2in_only = m->out2in_only;
1325  if (m->tag)
1326  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1327 
1328  locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
1329  vec_foreach (ap, m->locals)
1330  {
1331  clib_memcpy (locals->addr, &(ap->addr), 4);
1332  locals->port = htons (ap->port);
1333  locals->probability = ap->probability;
1334  locals++;
1335  rmp->local_num++;
1336  }
1337 
1338  vl_api_send_msg (reg, (u8 *) rmp);
1339 }
1340 
1341 static void
1344 {
1346  snat_main_t *sm = &snat_main;
1348 
1350  if (!reg)
1351  return;
1352 
1353  /* *INDENT-OFF* */
1354  pool_foreach (m, sm->static_mappings,
1355  ({
1356  if (vec_len(m->locals))
1357  send_nat44_lb_static_mapping_details (m, reg, mp->context);
1358  }));
1359  /* *INDENT-ON* */
1360 }
1361 
1364 {
1365  u8 *s;
1366 
1367  s = format (0, "SCRIPT: nat44_lb_static_mapping_dump ");
1368 
1369  FINISH;
1370 }
1371 
1372 static void
1374 {
1375  snat_main_t *sm = &snat_main;
1376  vl_api_nat44_del_session_reply_t *rmp;
1378  u16 port;
1379  u32 vrf_id;
1380  int rv = 0;
1381  snat_protocol_t proto;
1382 
1383  memcpy (&addr.as_u8, mp->address, 4);
1384  port = clib_net_to_host_u16 (mp->port);
1385  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1386  proto = ip_proto_to_snat_proto (mp->protocol);
1387 
1388  rv = nat44_del_session (sm, &addr, port, proto, vrf_id, mp->is_in);
1389 
1390  REPLY_MACRO (VL_API_NAT44_DEL_SESSION_REPLY);
1391 }
1392 
1393 static void *
1395  void *handle)
1396 {
1397  u8 *s;
1398 
1399  s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
1400  s = format (s, "addr %U port %d protocol %d vrf_id %d is_in %d",
1402  clib_net_to_host_u16 (mp->port),
1403  mp->protocol, clib_net_to_host_u32 (mp->vrf_id), mp->is_in);
1404 
1405  FINISH;
1406 }
1407 
1408 static void
1411 {
1412  snat_main_t *sm = &snat_main;
1413  vl_api_nat44_forwarding_enable_disable_reply_t *rmp;
1414  int rv = 0;
1415 
1416  sm->forwarding_enabled = mp->enable != 0;
1417 
1418  REPLY_MACRO (VL_API_NAT44_FORWARDING_ENABLE_DISABLE_REPLY);
1419 }
1420 
1423 {
1424  u8 *s;
1425 
1426  s = format (0, "SCRIPT: nat44_forwarding_enable_disable ");
1427  s = format (s, "enable %d", mp->enable != 0);
1428 
1429  FINISH;
1430 }
1431 
1432 static void
1435 {
1437  snat_main_t *sm = &snat_main;
1439 
1441  if (!reg)
1442  return;
1443 
1444  rmp = vl_msg_api_alloc (sizeof (*rmp));
1445  memset (rmp, 0, sizeof (*rmp));
1446  rmp->_vl_msg_id =
1447  ntohs (VL_API_NAT44_FORWARDING_IS_ENABLED_REPLY + sm->msg_id_base);
1448  rmp->context = mp->context;
1449 
1450  rmp->enabled = sm->forwarding_enabled;
1451 
1452  vl_api_send_msg (reg, (u8 *) rmp);
1453 }
1454 
1457 {
1458  u8 *s;
1459 
1460  s = format (0, "SCRIPT: nat44_forwarding_is_enabled ");
1461 
1462  FINISH;
1463 }
1464 
1465 /*******************************/
1466 /*** Deterministic NAT (CGN) ***/
1467 /*******************************/
1468 
1469 static void
1471 {
1472  snat_main_t *sm = &snat_main;
1473  vl_api_nat_det_add_del_map_reply_t *rmp;
1474  int rv = 0;
1475  ip4_address_t in_addr, out_addr;
1476 
1477  if (!mp->is_nat44)
1478  {
1479  rv = VNET_API_ERROR_UNIMPLEMENTED;
1480  goto send_reply;
1481  }
1482 
1483  clib_memcpy (&in_addr, mp->in_addr, 4);
1484  clib_memcpy (&out_addr, mp->out_addr, 4);
1485  rv = snat_det_add_map (sm, &in_addr, mp->in_plen, &out_addr,
1486  mp->out_plen, mp->is_add);
1487 
1488 send_reply:
1489  REPLY_MACRO (VL_API_NAT_DET_ADD_DEL_MAP_REPLY);
1490 }
1491 
1492 static void *
1494  void *handle)
1495 {
1496  u8 *s;
1497 
1498  s = format (0, "SCRIPT: nat_det_add_del_map ");
1499  s = format (s, "inside address %U/%d outside address %U/%d\n",
1502 
1503  FINISH;
1504 }
1505 
1506 static void
1508 {
1509  snat_main_t *sm = &snat_main;
1511  int rv = 0;
1512  u16 lo_port = 0, hi_port = 0;
1513  snat_det_map_t *dm;
1514  ip4_address_t in_addr, out_addr;
1515 
1516  if (!mp->is_nat44)
1517  {
1518  out_addr.as_u32 = 0;
1519  rv = VNET_API_ERROR_UNIMPLEMENTED;
1520  goto send_reply;
1521  }
1522 
1523  out_addr.as_u32 = 0;
1524  clib_memcpy (&in_addr, mp->in_addr, 4);
1525  dm = snat_det_map_by_user (sm, &in_addr);
1526  if (!dm)
1527  {
1528  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1529  goto send_reply;
1530  }
1531 
1532  snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1533  hi_port = lo_port + dm->ports_per_host - 1;
1534 
1535 send_reply:
1536  /* *INDENT-OFF* */
1537  REPLY_MACRO2 (VL_API_NAT_DET_FORWARD_REPLY,
1538  ({
1539  rmp->out_port_lo = ntohs (lo_port);
1540  rmp->out_port_hi = ntohs (hi_port);
1541  clib_memcpy (rmp->out_addr, &out_addr, 4);
1542  }))
1543  /* *INDENT-ON* */
1544 }
1545 
1546 static void *
1548 {
1549  u8 *s;
1550 
1551  s = format (0, "SCRIPT: nat_det_forward");
1552  s = format (s, "inside ip address %U\n", format_ip4_address, mp->in_addr);
1553 
1554  FINISH;
1555 }
1556 
1557 static void
1559 {
1560  snat_main_t *sm = &snat_main;
1562  int rv = 0;
1563  ip4_address_t out_addr, in_addr;
1564  snat_det_map_t *dm;
1565 
1566  in_addr.as_u32 = 0;
1567  clib_memcpy (&out_addr, mp->out_addr, 4);
1568  dm = snat_det_map_by_out (sm, &out_addr);
1569  if (!dm)
1570  {
1571  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1572  goto send_reply;
1573  }
1574 
1575  snat_det_reverse (dm, &out_addr, htons (mp->out_port), &in_addr);
1576 
1577 send_reply:
1578  /* *INDENT-OFF* */
1579  REPLY_MACRO2 (VL_API_NAT_DET_REVERSE_REPLY,
1580  ({
1581  rmp->is_nat44 = 1;
1582  memset (rmp->in_addr, 0, 16);
1583  clib_memcpy (rmp->in_addr, &in_addr, 4);
1584  }))
1585  /* *INDENT-ON* */
1586 }
1587 
1588 static void *
1590 {
1591  u8 *s;
1592 
1593  s = format (0, "SCRIPT: nat_det_reverse");
1594  s = format (s, "outside ip address %U outside port %d",
1595  format_ip4_address, mp->out_addr, ntohs (mp->out_port));
1596 
1597  FINISH;
1598 }
1599 
1600 static void
1602  u32 context)
1603 {
1605  snat_main_t *sm = &snat_main;
1606 
1607  rmp = vl_msg_api_alloc (sizeof (*rmp));
1608  memset (rmp, 0, sizeof (*rmp));
1609  rmp->_vl_msg_id = ntohs (VL_API_NAT_DET_MAP_DETAILS + sm->msg_id_base);
1610  rmp->is_nat44 = 1;
1611  clib_memcpy (rmp->in_addr, &m->in_addr, 4);
1612  rmp->in_plen = m->in_plen;
1613  clib_memcpy (rmp->out_addr, &m->out_addr, 4);
1614  rmp->out_plen = m->out_plen;
1615  rmp->sharing_ratio = htonl (m->sharing_ratio);
1616  rmp->ports_per_host = htons (m->ports_per_host);
1617  rmp->ses_num = htonl (m->ses_num);
1618  rmp->context = context;
1619 
1620  vl_api_send_msg (reg, (u8 *) rmp);
1621 }
1622 
1623 static void
1625 {
1627  snat_main_t *sm = &snat_main;
1628  snat_det_map_t *m;
1629 
1631  if (!reg)
1632  return;
1633 
1634  /* *INDENT-OFF* */
1635  vec_foreach(m, sm->det_maps)
1636  sent_nat_det_map_details(m, reg, mp->context);
1637  /* *INDENT-ON* */
1638 }
1639 
1640 static void *
1642 {
1643  u8 *s;
1644 
1645  s = format (0, "SCRIPT: nat_det_map_dump ");
1646 
1647  FINISH;
1648 }
1649 
1650 static void
1652 {
1653  snat_main_t *sm = &snat_main;
1654  vl_api_nat_det_set_timeouts_reply_t *rmp;
1655  int rv = 0;
1656 
1657  sm->udp_timeout = ntohl (mp->udp);
1658  sm->tcp_established_timeout = ntohl (mp->tcp_established);
1659  sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
1660  sm->icmp_timeout = ntohl (mp->icmp);
1661 
1662  REPLY_MACRO (VL_API_NAT_DET_SET_TIMEOUTS_REPLY);
1663 }
1664 
1665 static void *
1667  void *handle)
1668 {
1669  u8 *s;
1670 
1671  s = format (0, "SCRIPT: nat_det_set_timeouts ");
1672  s = format (s, "udp %d tcp_established %d tcp_transitory %d icmp %d\n",
1673  ntohl (mp->udp),
1674  ntohl (mp->tcp_established),
1675  ntohl (mp->tcp_transitory), ntohl (mp->icmp));
1676 
1677  FINISH;
1678 }
1679 
1680 static void
1682 {
1683  snat_main_t *sm = &snat_main;
1685  int rv = 0;
1686 
1687  /* *INDENT-OFF* */
1688  REPLY_MACRO2 (VL_API_NAT_DET_GET_TIMEOUTS_REPLY,
1689  ({
1690  rmp->udp = htonl (sm->udp_timeout);
1691  rmp->tcp_established = htonl (sm->tcp_established_timeout);
1692  rmp->tcp_transitory = htonl (sm->tcp_transitory_timeout);
1693  rmp->icmp = htonl (sm->icmp_timeout);
1694  }))
1695  /* *INDENT-ON* */
1696 }
1697 
1698 static void *
1700  void *handle)
1701 {
1702  u8 *s;
1703 
1704  s = format (0, "SCRIPT: nat_det_get_timeouts");
1705 
1706  FINISH;
1707 }
1708 
1709 static void
1711  * mp)
1712 {
1713  snat_main_t *sm = &snat_main;
1714  vl_api_nat_det_close_session_out_reply_t *rmp;
1715  ip4_address_t out_addr, ext_addr, in_addr;
1716  snat_det_out_key_t key;
1717  snat_det_map_t *dm;
1718  snat_det_session_t *ses;
1719  int rv = 0;
1720 
1721  clib_memcpy (&out_addr, mp->out_addr, 4);
1722  clib_memcpy (&ext_addr, mp->ext_addr, 4);
1723 
1724  dm = snat_det_map_by_out (sm, &out_addr);
1725  if (!dm)
1726  {
1727  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1728  goto send_reply;
1729  }
1730  snat_det_reverse (dm, &ext_addr, ntohs (mp->out_port), &in_addr);
1731  key.ext_host_addr = ext_addr;
1732  key.ext_host_port = mp->ext_port;
1733  key.out_port = mp->out_port;
1734  ses = snat_det_get_ses_by_out (dm, &in_addr, key.as_u64);
1735  if (!ses)
1736  {
1737  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1738  goto send_reply;
1739  }
1740  snat_det_ses_close (dm, ses);
1741 
1742 send_reply:
1743  REPLY_MACRO (VL_API_NAT_DET_CLOSE_SESSION_OUT_REPLY);
1744 }
1745 
1746 static void *
1748  mp, void *handle)
1749 {
1750  u8 *s;
1751 
1752  s = format (0, "SCRIPT: nat_det_close_session_out ");
1753  s = format (s, "out_addr %U out_port %d "
1754  "ext_addr %U ext_port %d\n",
1755  format_ip4_address, mp->out_addr, ntohs (mp->out_port),
1756  format_ip4_address, mp->ext_addr, ntohs (mp->ext_port));
1757 
1758  FINISH;
1759 }
1760 
1761 static void
1763  mp)
1764 {
1765  snat_main_t *sm = &snat_main;
1766  vl_api_nat_det_close_session_in_reply_t *rmp;
1767  ip4_address_t in_addr, ext_addr;
1768  snat_det_out_key_t key;
1769  snat_det_map_t *dm;
1770  snat_det_session_t *ses;
1771  int rv = 0;
1772 
1773  if (!mp->is_nat44)
1774  {
1775  rv = VNET_API_ERROR_UNIMPLEMENTED;
1776  goto send_reply;
1777  }
1778 
1779  clib_memcpy (&in_addr, mp->in_addr, 4);
1780  clib_memcpy (&ext_addr, mp->ext_addr, 4);
1781 
1782  dm = snat_det_map_by_user (sm, &in_addr);
1783  if (!dm)
1784  {
1785  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1786  goto send_reply;
1787  }
1788  key.ext_host_addr = ext_addr;
1789  key.ext_host_port = mp->ext_port;
1790  ses = snat_det_find_ses_by_in (dm, &in_addr, mp->in_port, key);
1791  if (!ses)
1792  {
1793  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1794  goto send_reply;
1795  }
1796  snat_det_ses_close (dm, ses);
1797 
1798 send_reply:
1799  REPLY_MACRO (VL_API_NAT_DET_CLOSE_SESSION_OUT_REPLY);
1800 }
1801 
1802 static void *
1804  mp, void *handle)
1805 {
1806  u8 *s;
1807  s = format (0, "SCRIPT: nat_det_close_session_in ");
1808  s = format (s, "in_addr %U in_port %d ext_addr %U ext_port %d\n",
1809  format_ip4_address, mp->in_addr, ntohs (mp->in_port),
1810  format_ip4_address, mp->ext_addr, ntohs (mp->ext_port));
1811 
1812  FINISH;
1813 }
1814 
1815 static void
1818 {
1820  snat_main_t *sm = &snat_main;
1821 
1822  rmp = vl_msg_api_alloc (sizeof (*rmp));
1823  memset (rmp, 0, sizeof (*rmp));
1824  rmp->_vl_msg_id = ntohs (VL_API_NAT_DET_SESSION_DETAILS + sm->msg_id_base);
1825  rmp->in_port = s->in_port;
1826  clib_memcpy (rmp->ext_addr, &s->out.ext_host_addr, 4);
1827  rmp->ext_port = s->out.ext_host_port;
1828  rmp->out_port = s->out.out_port;
1829  rmp->state = s->state;
1830  rmp->expire = ntohl (s->expire);
1831  rmp->context = context;
1832 
1833  vl_api_send_msg (reg, (u8 *) rmp);
1834 }
1835 
1836 static void
1838 {
1840  snat_main_t *sm = &snat_main;
1841  ip4_address_t user_addr;
1842  snat_det_map_t *dm;
1843  snat_det_session_t *s, empty_ses;
1844  u16 i;
1845 
1847  if (!reg)
1848  return;
1849  if (!mp->is_nat44)
1850  return;
1851 
1852  memset (&empty_ses, 0, sizeof (empty_ses));
1853  clib_memcpy (&user_addr, mp->user_addr, 4);
1854  dm = snat_det_map_by_user (sm, &user_addr);
1855  if (!dm)
1856  return;
1857 
1858  s = dm->sessions + snat_det_user_ses_offset (&user_addr, dm->in_plen);
1859  for (i = 0; i < SNAT_DET_SES_PER_USER; i++)
1860  {
1861  if (s->out.as_u64)
1862  send_nat_det_session_details (s, reg, mp->context);
1863  s++;
1864  }
1865 }
1866 
1867 static void *
1869  void *handle)
1870 {
1871  u8 *s;
1872 
1873  s = format (0, "SCRIPT: nat_det_session_dump ");
1874  s = format (s, "user_addr %U\n", format_ip4_address, mp->user_addr);
1875 
1876  FINISH;
1877 }
1878 
1879 /*************/
1880 /*** NAT64 ***/
1881 /*************/
1882 
1883 static void
1886 {
1887  vl_api_nat64_add_del_pool_addr_range_reply_t *rmp;
1888  snat_main_t *sm = &snat_main;
1889  int rv = 0;
1890  ip4_address_t this_addr;
1891  u32 start_host_order, end_host_order;
1892  u32 vrf_id;
1893  int i, count;
1894  u32 *tmp;
1895 
1896  tmp = (u32 *) mp->start_addr;
1897  start_host_order = clib_host_to_net_u32 (tmp[0]);
1898  tmp = (u32 *) mp->end_addr;
1899  end_host_order = clib_host_to_net_u32 (tmp[0]);
1900 
1901  count = (end_host_order - start_host_order) + 1;
1902 
1903  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
1904 
1905  memcpy (&this_addr.as_u8, mp->start_addr, 4);
1906 
1907  for (i = 0; i < count; i++)
1908  {
1909  if ((rv = nat64_add_del_pool_addr (&this_addr, vrf_id, mp->is_add)))
1910  goto send_reply;
1911 
1912  increment_v4_address (&this_addr);
1913  }
1914 
1915 send_reply:
1916  REPLY_MACRO (VL_API_NAT64_ADD_DEL_POOL_ADDR_RANGE_REPLY);
1917 }
1918 
1921 {
1922  u8 *s;
1923 
1924  s = format (0, "SCRIPT: nat64_add_del_pool_addr_range ");
1925  s = format (s, "%U - %U vrf_id %u %s\n",
1928  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
1929 
1930  FINISH;
1931 }
1932 
1934 {
1939 
1940 static int
1942 {
1944  snat_main_t *sm = &snat_main;
1945  nat64_api_walk_ctx_t *ctx = arg;
1946 
1947  rmp = vl_msg_api_alloc (sizeof (*rmp));
1948  memset (rmp, 0, sizeof (*rmp));
1949  rmp->_vl_msg_id = ntohs (VL_API_NAT64_POOL_ADDR_DETAILS + sm->msg_id_base);
1950  clib_memcpy (rmp->address, &(a->addr), 4);
1951  if (a->fib_index != ~0)
1952  {
1954  if (!fib)
1955  return -1;
1956  rmp->vrf_id = ntohl (fib->ft_table_id);
1957  }
1958  else
1959  rmp->vrf_id = ~0;
1960  rmp->context = ctx->context;
1961 
1962  vl_api_send_msg (ctx->reg, (u8 *) rmp);
1963 
1964  return 0;
1965 }
1966 
1967 static void
1969 {
1971 
1973  if (!reg)
1974  return;
1975 
1977  .reg = reg,
1978  .context = mp->context,
1979  };
1980 
1982 }
1983 
1984 static void *
1986  void *handle)
1987 {
1988  u8 *s;
1989 
1990  s = format (0, "SCRIPT: nat64_pool_addr_dump\n");
1991 
1992  FINISH;
1993 }
1994 
1995 static void
1997  mp)
1998 {
1999  snat_main_t *sm = &snat_main;
2000  vl_api_nat64_add_del_interface_reply_t *rmp;
2001  int rv = 0;
2002 
2003  VALIDATE_SW_IF_INDEX (mp);
2004 
2005  rv =
2006  nat64_add_del_interface (ntohl (mp->sw_if_index), mp->is_inside,
2007  mp->is_add);
2008 
2010 
2011  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_REPLY);
2012 }
2013 
2014 static void *
2016  void *handle)
2017 {
2018  u8 *s;
2019 
2020  s = format (0, "SCRIPT: nat64_add_del_interface ");
2021  s = format (s, "sw_if_index %d %s %s",
2022  clib_host_to_net_u32 (mp->sw_if_index),
2023  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
2024 
2025  FINISH;
2026 }
2027 
2028 static int
2030 {
2032  snat_main_t *sm = &snat_main;
2033  nat64_api_walk_ctx_t *ctx = arg;
2034 
2035  rmp = vl_msg_api_alloc (sizeof (*rmp));
2036  memset (rmp, 0, sizeof (*rmp));
2037  rmp->_vl_msg_id = ntohs (VL_API_NAT64_INTERFACE_DETAILS + sm->msg_id_base);
2038  rmp->sw_if_index = ntohl (i->sw_if_index);
2040  && nat_interface_is_outside (i)) ? 2 :
2042  rmp->context = ctx->context;
2043 
2044  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2045 
2046  return 0;
2047 }
2048 
2049 static void
2051 {
2053 
2055  if (!reg)
2056  return;
2057 
2059  .reg = reg,
2060  .context = mp->context,
2061  };
2062 
2064 }
2065 
2066 static void *
2068  void *handle)
2069 {
2070  u8 *s;
2071 
2072  s = format (0, "SCRIPT: snat_interface_dump ");
2073 
2074  FINISH;
2075 }
2076 
2077 static void
2080 {
2081  snat_main_t *sm = &snat_main;
2082  vl_api_nat64_add_del_static_bib_reply_t *rmp;
2083  ip6_address_t in_addr;
2084  ip4_address_t out_addr;
2085  int rv = 0;
2086 
2087  memcpy (&in_addr.as_u8, mp->i_addr, 16);
2088  memcpy (&out_addr.as_u8, mp->o_addr, 4);
2089 
2090  rv =
2091  nat64_add_del_static_bib_entry (&in_addr, &out_addr,
2092  clib_net_to_host_u16 (mp->i_port),
2093  clib_net_to_host_u16 (mp->o_port),
2094  mp->proto,
2095  clib_net_to_host_u32 (mp->vrf_id),
2096  mp->is_add);
2097 
2098  REPLY_MACRO (VL_API_NAT64_ADD_DEL_STATIC_BIB_REPLY);
2099 }
2100 
2103 {
2104  u8 *s;
2105 
2106  s = format (0, "SCRIPT: nat64_add_del_static_bib ");
2107  s = format (s, "protocol %d i_addr %U o_addr %U ",
2108  mp->proto,
2110 
2111  if (mp->vrf_id != ~0)
2112  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
2113 
2114  FINISH;
2115 }
2116 
2117 static int
2118 nat64_api_bib_walk (nat64_db_bib_entry_t * bibe, void *arg)
2119 {
2121  snat_main_t *sm = &snat_main;
2122  nat64_api_walk_ctx_t *ctx = arg;
2123  fib_table_t *fib;
2124 
2125  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
2126  if (!fib)
2127  return -1;
2128 
2129  rmp = vl_msg_api_alloc (sizeof (*rmp));
2130  memset (rmp, 0, sizeof (*rmp));
2131  rmp->_vl_msg_id = ntohs (VL_API_NAT64_BIB_DETAILS + sm->msg_id_base);
2132  rmp->context = ctx->context;
2133  clib_memcpy (rmp->i_addr, &(bibe->in_addr), 16);
2134  clib_memcpy (rmp->o_addr, &(bibe->out_addr), 4);
2135  rmp->i_port = bibe->in_port;
2136  rmp->o_port = bibe->out_port;
2137  rmp->vrf_id = ntohl (fib->ft_table_id);
2138  rmp->proto = bibe->proto;
2139  rmp->is_static = bibe->is_static;
2140  rmp->ses_num = ntohl (bibe->ses_num);
2141 
2142  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2143 
2144  return 0;
2145 }
2146 
2147 static void
2149 {
2151  nat64_main_t *nm = &nat64_main;
2152  nat64_db_t *db;
2153 
2155  if (!reg)
2156  return;
2157 
2159  .reg = reg,
2160  .context = mp->context,
2161  };
2162 
2163  /* *INDENT-OFF* */
2164  vec_foreach (db, nm->db)
2165  nat64_db_bib_walk (db, mp->proto, nat64_api_bib_walk, &ctx);
2166  /* *INDENT-ON* */
2167 }
2168 
2169 static void *
2171 {
2172  u8 *s;
2173 
2174  s = format (0, "SCRIPT: snat_bib_dump protocol %d", mp->proto);
2175 
2176  FINISH;
2177 }
2178 
2179 static void
2181 {
2182  snat_main_t *sm = &snat_main;
2183  vl_api_nat64_set_timeouts_reply_t *rmp;
2184  int rv = 0;
2185 
2186  rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
2187  if (rv)
2188  goto send_reply;
2189  rv = nat64_set_udp_timeout (ntohl (mp->udp));
2190  if (rv)
2191  goto send_reply;
2192  rv =
2193  nat64_set_tcp_timeouts (ntohl (mp->tcp_trans), ntohl (mp->tcp_est),
2194  ntohl (mp->tcp_incoming_syn));
2195 
2196 send_reply:
2197  REPLY_MACRO (VL_API_NAT64_SET_TIMEOUTS_REPLY);
2198 }
2199 
2201  (vl_api_nat64_set_timeouts_t * mp, void *handle)
2202 {
2203  u8 *s;
2204 
2205  s = format (0, "SCRIPT: nat64_set_timeouts ");
2206  s =
2207  format (s,
2208  "udp %d icmp %d, tcp_trans %d, tcp_est %d, tcp_incoming_syn %d\n",
2209  ntohl (mp->udp), ntohl (mp->icmp), ntohl (mp->tcp_trans),
2210  ntohl (mp->tcp_est), ntohl (mp->tcp_incoming_syn));
2211 
2212  FINISH;
2213 }
2214 
2215 static void
2217 {
2218  snat_main_t *sm = &snat_main;
2220  int rv = 0;
2221 
2222  /* *INDENT-OFF* */
2223  REPLY_MACRO2 (VL_API_NAT64_GET_TIMEOUTS_REPLY,
2224  ({
2225  rmp->udp = htonl (nat64_get_udp_timeout());
2226  rmp->icmp = htonl (nat64_get_icmp_timeout());
2227  rmp->tcp_trans = htonl (nat64_get_tcp_trans_timeout());
2228  rmp->tcp_est = htonl (nat64_get_tcp_est_timeout());
2230  }))
2231  /* *INDENT-ON* */
2232 }
2233 
2235  (vl_api_nat64_get_timeouts_t * mp, void *handle)
2236 {
2237  u8 *s;
2238 
2239  s = format (0, "SCRIPT: nat64_get_timeouts");
2240 
2241  FINISH;
2242 }
2243 
2244 static int
2245 nat64_api_st_walk (nat64_db_st_entry_t * ste, void *arg)
2246 {
2248  snat_main_t *sm = &snat_main;
2249  nat64_api_walk_ctx_t *ctx = arg;
2250  nat64_db_bib_entry_t *bibe;
2251  fib_table_t *fib;
2252 
2253  bibe = nat64_db_bib_entry_by_index (ctx->db, ste->proto, ste->bibe_index);
2254  if (!bibe)
2255  return -1;
2256 
2257  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
2258  if (!fib)
2259  return -1;
2260 
2261  rmp = vl_msg_api_alloc (sizeof (*rmp));
2262  memset (rmp, 0, sizeof (*rmp));
2263  rmp->_vl_msg_id = ntohs (VL_API_NAT64_ST_DETAILS + sm->msg_id_base);
2264  rmp->context = ctx->context;
2265  clib_memcpy (rmp->il_addr, &(bibe->in_addr), 16);
2266  clib_memcpy (rmp->ol_addr, &(bibe->out_addr), 4);
2267  rmp->il_port = bibe->in_port;
2268  rmp->ol_port = bibe->out_port;
2269  clib_memcpy (rmp->ir_addr, &(ste->in_r_addr), 16);
2270  clib_memcpy (rmp->or_addr, &(ste->out_r_addr), 4);
2271  rmp->il_port = ste->r_port;
2272  rmp->vrf_id = ntohl (fib->ft_table_id);
2273  rmp->proto = ste->proto;
2274 
2275  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2276 
2277  return 0;
2278 }
2279 
2280 static void
2282 {
2284  nat64_main_t *nm = &nat64_main;
2285  nat64_db_t *db;
2286 
2288  if (!reg)
2289  return;
2290 
2292  .reg = reg,
2293  .context = mp->context,
2294  };
2295 
2296  /* *INDENT-OFF* */
2297  vec_foreach (db, nm->db)
2298  {
2299  ctx.db = db;
2300  nat64_db_st_walk (db, mp->proto, nat64_api_st_walk, &ctx);
2301  }
2302  /* *INDENT-ON* */
2303 }
2304 
2305 static void *
2307 {
2308  u8 *s;
2309 
2310  s = format (0, "SCRIPT: snat_st_dump protocol %d", mp->proto);
2311 
2312  FINISH;
2313 }
2314 
2315 static void
2317 {
2318  vl_api_nat64_add_del_prefix_reply_t *rmp;
2319  snat_main_t *sm = &snat_main;
2320  ip6_address_t prefix;
2321  int rv = 0;
2322 
2323  memcpy (&prefix.as_u8, mp->prefix, 16);
2324 
2325  rv =
2326  nat64_add_del_prefix (&prefix, mp->prefix_len,
2327  clib_net_to_host_u32 (mp->vrf_id), mp->is_add);
2328  REPLY_MACRO (VL_API_NAT64_ADD_DEL_PREFIX_REPLY);
2329 }
2330 
2331 static void *
2333  void *handle)
2334 {
2335  u8 *s;
2336 
2337  s = format (0, "SCRIPT: nat64_add_del_prefix %U/%u vrf_id %u %s\n",
2339  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
2340 
2341  FINISH;
2342 }
2343 
2344 static int
2346 {
2348  snat_main_t *sm = &snat_main;
2349  nat64_api_walk_ctx_t *ctx = arg;
2350 
2351  rmp = vl_msg_api_alloc (sizeof (*rmp));
2352  memset (rmp, 0, sizeof (*rmp));
2353  rmp->_vl_msg_id = ntohs (VL_API_NAT64_PREFIX_DETAILS + sm->msg_id_base);
2354  clib_memcpy (rmp->prefix, &(p->prefix), 16);
2355  rmp->prefix_len = p->plen;
2356  rmp->vrf_id = ntohl (p->vrf_id);
2357  rmp->context = ctx->context;
2358 
2359  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2360 
2361  return 0;
2362 }
2363 
2364 static void
2366 {
2368 
2370  if (!reg)
2371  return;
2372 
2374  .reg = reg,
2375  .context = mp->context,
2376  };
2377 
2379 }
2380 
2381 static void *
2383  void *handle)
2384 {
2385  u8 *s;
2386 
2387  s = format (0, "SCRIPT: nat64_prefix_dump\n");
2388 
2389  FINISH;
2390 }
2391 
2392 static void
2395 {
2396  snat_main_t *sm = &snat_main;
2397  vl_api_nat64_add_del_interface_addr_reply_t *rmp;
2398  u32 sw_if_index = ntohl (mp->sw_if_index);
2399  int rv = 0;
2400 
2401  VALIDATE_SW_IF_INDEX (mp);
2402 
2403  rv = nat64_add_interface_address (sw_if_index, mp->is_add);
2404 
2406 
2407  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_ADDR_REPLY);
2408 }
2409 
2412 {
2413  u8 *s;
2414 
2415  s = format (0, "SCRIPT: nat64_add_del_interface_addr ");
2416  s = format (s, "sw_if_index %d %s",
2417  clib_host_to_net_u32 (mp->sw_if_index),
2418  mp->is_add ? "" : "del");
2419 
2420  FINISH;
2421 }
2422 
2423 /***************/
2424 /*** DS-Lite ***/
2425 /***************/
2426 
2427 static void
2429 {
2430  vl_api_dslite_set_aftr_addr_reply_t *rmp;
2431  snat_main_t *sm = &snat_main;
2432  dslite_main_t *dm = &dslite_main;
2433  int rv = 0;
2434  ip6_address_t ip6_addr;
2435  ip4_address_t ip4_addr;
2436 
2437  memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
2438  memcpy (&ip4_addr.as_u8, mp->ip4_addr, 4);
2439 
2440  rv = dslite_set_aftr_ip6_addr (dm, &ip6_addr);
2441  if (rv == 0)
2442  rv = dslite_set_aftr_ip4_addr (dm, &ip4_addr);
2443 
2444  REPLY_MACRO (VL_API_DSLITE_SET_AFTR_ADDR_REPLY);
2445 }
2446 
2447 static void *
2449  void *handle)
2450 {
2451  u8 *s;
2452 
2453  s = format (0, "SCRIPT: dslite_set_aftr_addr ");
2454  s = format (s, "ip6_addr %U ip4_addr %U\n",
2457 
2458  FINISH;
2459 }
2460 
2461 static void
2463 {
2464  snat_main_t *sm = &snat_main;
2466  dslite_main_t *dm = &dslite_main;
2467  int rv = 0;
2468 
2469  /* *INDENT-OFF* */
2470  REPLY_MACRO2 (VL_API_DSLITE_GET_AFTR_ADDR_REPLY,
2471  ({
2472  memcpy (rmp->ip4_addr, &dm->aftr_ip4_addr.as_u8, 4);
2473  memcpy (rmp->ip6_addr, &dm->aftr_ip6_addr.as_u8, 16);
2474  }))
2475  /* *INDENT-ON* */
2476 }
2477 
2478 static void *
2480  void *handle)
2481 {
2482  u8 *s;
2483 
2484  s = format (0, "SCRIPT: dslite_get_aftr_addr");
2485 
2486  FINISH;
2487 }
2488 
2489 static void
2491 {
2492  vl_api_dslite_set_b4_addr_reply_t *rmp;
2493  snat_main_t *sm = &snat_main;
2494  dslite_main_t *dm = &dslite_main;
2495  int rv = 0;
2496  ip6_address_t ip6_addr;
2497  ip4_address_t ip4_addr;
2498 
2499  memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
2500  memcpy (&ip4_addr.as_u8, mp->ip4_addr, 4);
2501 
2502  rv = dslite_set_b4_ip6_addr (dm, &ip6_addr);
2503  if (rv == 0)
2504  rv = dslite_set_b4_ip4_addr (dm, &ip4_addr);
2505 
2506  REPLY_MACRO (VL_API_DSLITE_SET_B4_ADDR_REPLY);
2507 }
2508 
2509 static void *
2511  void *handle)
2512 {
2513  u8 *s;
2514 
2515  s = format (0, "SCRIPT: dslite_set_b4_addr ");
2516  s = format (s, "ip6_addr %U ip4_addr %U\n",
2519 
2520  FINISH;
2521 }
2522 
2523 static void
2525 {
2526  snat_main_t *sm = &snat_main;
2528  dslite_main_t *dm = &dslite_main;
2529  int rv = 0;
2530 
2531  /* *INDENT-OFF* */
2532  REPLY_MACRO2 (VL_API_DSLITE_GET_AFTR_ADDR_REPLY,
2533  ({
2534  memcpy (rmp->ip4_addr, &dm->b4_ip4_addr.as_u8, 4);
2535  memcpy (rmp->ip6_addr, &dm->b4_ip6_addr.as_u8, 16);
2536  }))
2537  /* *INDENT-ON* */
2538 }
2539 
2540 static void *
2542  void *handle)
2543 {
2544  u8 *s;
2545 
2546  s = format (0, "SCRIPT: dslite_get_b4_addr");
2547 
2548  FINISH;
2549 }
2550 
2551 static void
2554 {
2555  vl_api_dslite_add_del_pool_addr_range_reply_t *rmp;
2556  snat_main_t *sm = &snat_main;
2557  dslite_main_t *dm = &dslite_main;
2558  int rv = 0;
2559  ip4_address_t this_addr;
2560  u32 start_host_order, end_host_order;
2561  int i, count;
2562  u32 *tmp;
2563 
2564  tmp = (u32 *) mp->start_addr;
2565  start_host_order = clib_host_to_net_u32 (tmp[0]);
2566  tmp = (u32 *) mp->end_addr;
2567  end_host_order = clib_host_to_net_u32 (tmp[0]);
2568 
2569  count = (end_host_order - start_host_order) + 1;
2570  memcpy (&this_addr.as_u8, mp->start_addr, 4);
2571 
2572  for (i = 0; i < count; i++)
2573  {
2574  if ((rv = dslite_add_del_pool_addr (dm, &this_addr, mp->is_add)))
2575  goto send_reply;
2576 
2577  increment_v4_address (&this_addr);
2578  }
2579 
2580 send_reply:
2581  REPLY_MACRO (VL_API_DSLITE_ADD_DEL_POOL_ADDR_RANGE_REPLY);
2582 }
2583 
2586 {
2587  u8 *s;
2588 
2589  s = format (0, "SCRIPT: dslite_add_del_pool_addr_range ");
2590  s = format (s, "%U - %U\n",
2593 
2594  FINISH;
2595 }
2596 
2597 
2598 /*************/
2599 /*** NAT66 ***/
2600 /*************/
2601 
2602 static void
2604  mp)
2605 {
2606  snat_main_t *sm = &snat_main;
2607  vl_api_nat66_add_del_interface_reply_t *rmp;
2608  int rv = 0;
2609 
2610  VALIDATE_SW_IF_INDEX (mp);
2611 
2612  rv =
2613  nat66_interface_add_del (ntohl (mp->sw_if_index), mp->is_inside,
2614  mp->is_add);
2615 
2617 
2618  REPLY_MACRO (VL_API_NAT66_ADD_DEL_INTERFACE_REPLY);
2619 }
2620 
2621 static void *
2623  void *handle)
2624 {
2625  u8 *s;
2626 
2627  s = format (0, "SCRIPT: nat66_add_del_interface ");
2628  s = format (s, "sw_if_index %d %s %s",
2629  clib_host_to_net_u32 (mp->sw_if_index),
2630  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
2631 
2632  FINISH;
2633 }
2634 
2635 static void
2638 {
2639  snat_main_t *sm = &snat_main;
2640  vl_api_nat66_add_del_static_mapping_reply_t *rmp;
2641  ip6_address_t l_addr, e_addr;
2642  int rv = 0;
2643 
2644  memcpy (&l_addr.as_u8, mp->local_ip_address, 16);
2645  memcpy (&e_addr.as_u8, mp->external_ip_address, 16);
2646 
2647  rv =
2648  nat66_static_mapping_add_del (&l_addr, &e_addr,
2649  clib_net_to_host_u32 (mp->vrf_id),
2650  mp->is_add);
2651 
2652  REPLY_MACRO (VL_API_NAT66_ADD_DEL_STATIC_MAPPING_REPLY);
2653 }
2654 
2657 {
2658  u8 *s;
2659 
2660  s = format (0, "SCRIPT: nat66_add_del_static_mapping ");
2661  s = format (s, "local_ip_address %U external_ip_address %U vrf_id %d %s",
2664  clib_net_to_host_u32 (mp->vrf_id), mp->is_add ? "" : "del");
2665 
2666  FINISH;
2667 }
2668 
2670 {
2674 
2675 static int
2677 {
2679  snat_main_t *sm = &snat_main;
2680  nat66_api_walk_ctx_t *ctx = arg;
2681 
2682  rmp = vl_msg_api_alloc (sizeof (*rmp));
2683  memset (rmp, 0, sizeof (*rmp));
2684  rmp->_vl_msg_id = ntohs (VL_API_NAT66_INTERFACE_DETAILS + sm->msg_id_base);
2685  rmp->sw_if_index = ntohl (i->sw_if_index);
2687  rmp->context = ctx->context;
2688 
2689  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
2690 
2691  return 0;
2692 }
2693 
2694 static void
2696 {
2697  svm_queue_t *q;
2698 
2700  if (q == 0)
2701  return;
2702 
2704  .q = q,
2705  .context = mp->context,
2706  };
2707 
2709 }
2710 
2711 static void *
2713  void *handle)
2714 {
2715  u8 *s;
2716 
2717  s = format (0, "SCRIPT: nat66_interface_dump ");
2718 
2719  FINISH;
2720 }
2721 
2722 static int
2724 {
2726  nat66_main_t *nm = &nat66_main;
2727  snat_main_t *sm = &snat_main;
2728  nat66_api_walk_ctx_t *ctx = arg;
2729  fib_table_t *fib;
2730  vlib_counter_t vc;
2731 
2733  if (!fib)
2734  return -1;
2735 
2736  vlib_get_combined_counter (&nm->session_counters, m - nm->sm, &vc);
2737 
2738  rmp = vl_msg_api_alloc (sizeof (*rmp));
2739  memset (rmp, 0, sizeof (*rmp));
2740  rmp->_vl_msg_id =
2741  ntohs (VL_API_NAT66_STATIC_MAPPING_DETAILS + sm->msg_id_base);
2742  clib_memcpy (rmp->local_ip_address, &m->l_addr, 16);
2743  clib_memcpy (rmp->external_ip_address, &m->e_addr, 16);
2744  rmp->vrf_id = ntohl (fib->ft_table_id);
2745  rmp->total_bytes = clib_host_to_net_u64 (vc.bytes);
2746  rmp->total_pkts = clib_host_to_net_u64 (vc.packets);
2747  rmp->context = ctx->context;
2748 
2749  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
2750 
2751  return 0;
2752 }
2753 
2754 static void
2756  * mp)
2757 {
2758  svm_queue_t *q;
2759 
2761  if (q == 0)
2762  return;
2763 
2765  .q = q,
2766  .context = mp->context,
2767  };
2768 
2770 }
2771 
2772 static void *
2774  mp, void *handle)
2775 {
2776  u8 *s;
2777 
2778  s = format (0, "SCRIPT: nat66_static_mapping_dump ");
2779 
2780  FINISH;
2781 }
2782 
2783 
2784 /* List of message types that this plugin understands */
2785 #define foreach_snat_plugin_api_msg \
2786 _(NAT_CONTROL_PING, nat_control_ping) \
2787 _(NAT_SHOW_CONFIG, nat_show_config) \
2788 _(NAT_SET_WORKERS, nat_set_workers) \
2789 _(NAT_WORKER_DUMP, nat_worker_dump) \
2790 _(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \
2791 _(NAT_SET_REASS, nat_set_reass) \
2792 _(NAT_GET_REASS, nat_get_reass) \
2793 _(NAT_REASS_DUMP, nat_reass_dump) \
2794 _(NAT44_ADD_DEL_ADDRESS_RANGE, nat44_add_del_address_range) \
2795 _(NAT44_INTERFACE_ADD_DEL_FEATURE, nat44_interface_add_del_feature) \
2796 _(NAT44_ADD_DEL_STATIC_MAPPING, nat44_add_del_static_mapping) \
2797 _(NAT44_ADD_DEL_IDENTITY_MAPPING, nat44_add_del_identity_mapping) \
2798 _(NAT44_STATIC_MAPPING_DUMP, nat44_static_mapping_dump) \
2799 _(NAT44_IDENTITY_MAPPING_DUMP, nat44_identity_mapping_dump) \
2800 _(NAT44_ADDRESS_DUMP, nat44_address_dump) \
2801 _(NAT44_INTERFACE_DUMP, nat44_interface_dump) \
2802 _(NAT44_ADD_DEL_INTERFACE_ADDR, nat44_add_del_interface_addr) \
2803 _(NAT44_INTERFACE_ADDR_DUMP, nat44_interface_addr_dump) \
2804 _(NAT44_USER_DUMP, nat44_user_dump) \
2805 _(NAT44_USER_SESSION_DUMP, nat44_user_session_dump) \
2806 _(NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE, \
2807  nat44_interface_add_del_output_feature) \
2808 _(NAT44_INTERFACE_OUTPUT_FEATURE_DUMP, \
2809  nat44_interface_output_feature_dump) \
2810 _(NAT44_ADD_DEL_LB_STATIC_MAPPING, nat44_add_del_lb_static_mapping) \
2811 _(NAT44_LB_STATIC_MAPPING_DUMP, nat44_lb_static_mapping_dump) \
2812 _(NAT44_DEL_SESSION, nat44_del_session) \
2813 _(NAT44_FORWARDING_ENABLE_DISABLE, nat44_forwarding_enable_disable) \
2814 _(NAT44_FORWARDING_IS_ENABLED, nat44_forwarding_is_enabled) \
2815 _(NAT_DET_ADD_DEL_MAP, nat_det_add_del_map) \
2816 _(NAT_DET_FORWARD, nat_det_forward) \
2817 _(NAT_DET_REVERSE, nat_det_reverse) \
2818 _(NAT_DET_MAP_DUMP, nat_det_map_dump) \
2819 _(NAT_DET_SET_TIMEOUTS, nat_det_set_timeouts) \
2820 _(NAT_DET_GET_TIMEOUTS, nat_det_get_timeouts) \
2821 _(NAT_DET_CLOSE_SESSION_OUT, nat_det_close_session_out) \
2822 _(NAT_DET_CLOSE_SESSION_IN, nat_det_close_session_in) \
2823 _(NAT_DET_SESSION_DUMP, nat_det_session_dump) \
2824 _(NAT64_ADD_DEL_POOL_ADDR_RANGE, nat64_add_del_pool_addr_range) \
2825 _(NAT64_POOL_ADDR_DUMP, nat64_pool_addr_dump) \
2826 _(NAT64_ADD_DEL_INTERFACE, nat64_add_del_interface) \
2827 _(NAT64_INTERFACE_DUMP, nat64_interface_dump) \
2828 _(NAT64_ADD_DEL_STATIC_BIB, nat64_add_del_static_bib) \
2829 _(NAT64_BIB_DUMP, nat64_bib_dump) \
2830 _(NAT64_SET_TIMEOUTS, nat64_set_timeouts) \
2831 _(NAT64_GET_TIMEOUTS, nat64_get_timeouts) \
2832 _(NAT64_ST_DUMP, nat64_st_dump) \
2833 _(NAT64_ADD_DEL_PREFIX, nat64_add_del_prefix) \
2834 _(NAT64_PREFIX_DUMP, nat64_prefix_dump) \
2835 _(NAT64_ADD_DEL_INTERFACE_ADDR, nat64_add_del_interface_addr) \
2836 _(DSLITE_ADD_DEL_POOL_ADDR_RANGE, dslite_add_del_pool_addr_range) \
2837 _(DSLITE_SET_AFTR_ADDR, dslite_set_aftr_addr) \
2838 _(DSLITE_GET_AFTR_ADDR, dslite_get_aftr_addr) \
2839 _(DSLITE_SET_B4_ADDR, dslite_set_b4_addr) \
2840 _(DSLITE_GET_B4_ADDR, dslite_get_b4_addr) \
2841 _(NAT66_ADD_DEL_INTERFACE, nat66_add_del_interface) \
2842 _(NAT66_INTERFACE_DUMP, nat66_interface_dump) \
2843 _(NAT66_ADD_DEL_STATIC_MAPPING, nat66_add_del_static_mapping) \
2844 _(NAT66_STATIC_MAPPING_DUMP, nat66_static_mapping_dump)
2845 
2846 /* Set up the API message handling tables */
2847 static clib_error_t *
2849 {
2850  snat_main_t *sm __attribute__ ((unused)) = &snat_main;
2851 #define _(N,n) \
2852  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
2853  #n, \
2854  vl_api_##n##_t_handler, \
2855  vl_noop_handler, \
2856  vl_api_##n##_t_endian, \
2857  vl_api_##n##_t_print, \
2858  sizeof(vl_api_##n##_t), 1);
2860 #undef _
2861 
2862  return 0;
2863 }
2864 
2865 #define vl_msg_name_crc_list
2866 #include <nat/nat_all_api_h.h>
2867 #undef vl_msg_name_crc_list
2868 
2869 static void
2871 {
2872 #define _(id,n,crc) \
2873  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
2874  foreach_vl_msg_name_crc_nat;
2875 #undef _
2876 }
2877 
2878 static void
2880 {
2881 #define _(n,f) sm->api_main->msg_print_handlers \
2882  [VL_API_##n + sm->msg_id_base] \
2883  = (void *) vl_api_##f##_t_print;
2885 #undef _
2886 }
2887 
2888 clib_error_t *
2890 {
2891  u8 *name;
2892  clib_error_t *error = 0;
2893 
2894  name = format (0, "nat_%08x%c", api_version, 0);
2895 
2896  /* Ask for a correctly-sized block of API message decode slots */
2897  sm->msg_id_base =
2899 
2900  error = snat_plugin_api_hookup (vm);
2901 
2902  /* Add our API messages to the global name_crc hash table */
2903  setup_message_id_table (sm, sm->api_main);
2904 
2906 
2907  vec_free (name);
2908 
2909  return error;
2910 }
2911 
2912 /*
2913  * fd.io coding-style-patch-verification: ON
2914  *
2915  * Local Variables:
2916  * eval: (c-set-style "gnu")
2917  * End:
2918  */
ip4_address_t external_addr
Definition: nat.h:215
u32 nat64_get_icmp_timeout(void)
Get ICMP session timeout.
Definition: nat64.c:789
u32 user_memory_size
Definition: nat.h:368
Dump NAT64 prefix.
Definition: nat.api:1162
u32 next
Definition: dlist.h:30
NAT64 interface details response.
Definition: nat.api:987
nat64_db_t * db
BIB and session DB per thread.
Definition: nat64.h:83
u32 nat_reass_get_timeout(u8 is_ip6)
Get reassembly timeout.
Definition: nat_reass.c:135
NAT virtual fragmentation reassemblies response.
Definition: nat.api:213
u32 sessions_per_user_list_head_index
Definition: nat.h:171
NAT44 load-balancing static mapping rule details response.
Definition: nat.api:629
static void vl_api_nat66_add_del_interface_t_handler(vl_api_nat66_add_del_interface_t *mp)
Definition: nat_api.c:2603
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Definition: nat.c:1414
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
Definition: nat64.c:753
static void send_nat44_identity_map_resolve_details(snat_static_map_resolve_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:940
static void vl_api_nat_worker_dump_t_handler(vl_api_nat_worker_dump_t *mp)
Definition: nat_api.c:198
u16 ext_host_port
Definition: nat.h:79
static int nat64_api_pool_walk(snat_address_t *a, void *arg)
Definition: nat_api.c:1941
u16 out_port
Definition: nat.h:80
NAT64 BIB details response.
Definition: nat.api:1042
Dump NAT virtual fragmentation reassemblies.
Definition: nat.api:199
a
Definition: bitmap.h:516
static void * vl_api_nat44_user_dump_t_print(vl_api_nat44_user_dump_t *mp, void *handle)
Definition: nat_api.c:1127
u32 icmp_timeout
Definition: nat.h:379
static void * vl_api_nat_ipfix_enable_disable_t_print(vl_api_nat_ipfix_enable_disable_t *mp, void *handle)
Definition: nat_api.c:242
static void * vl_api_nat_det_close_session_in_t_print(vl_api_nat_det_close_session_in_t *mp, void *handle)
Definition: nat_api.c:1803
NAT workers details response.
Definition: nat.api:120
ip4_address_t src_address
Definition: ip4_packet.h:164
ip6_address_t prefix
Definition: nat64.h:49
Set AFTR IPv6 and IPv4 addresses.
Definition: nat.api:1220
static void * vl_api_nat64_interface_dump_t_print(vl_api_nat64_interface_dump_t *mp, void *handle)
Definition: nat_api.c:2067
static void send_nat44_user_session_details(snat_session_t *s, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1137
NAT44 interface with output feature details response.
Definition: nat.api:333
Dump NAT44 pool addresses interfaces.
Definition: nat.api:488
u32 nsessions
Definition: nat.h:172
static void vl_api_nat44_user_session_dump_t_handler(vl_api_nat44_user_session_dump_t *mp)
Definition: nat_api.c:1171
u8 as_u8[16]
Definition: ip6_packet.h:48
static void * vl_api_nat44_del_session_t_print(vl_api_nat44_del_session_t *mp, void *handle)
Definition: nat_api.c:1394
ip4_address_t aftr_ip4_addr
Definition: dslite.h:82
NAT44 identity mapping details response.
Definition: nat.api:458
ip4_address_t addr
Definition: nat.h:207
Add/delete NAT44 identity mapping.
Definition: nat.api:426
vl_api_nat44_lb_addr_port_t locals[local_num]
Definition: nat.api:604
#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:403
snat_protocol_t proto
Definition: nat.h:223
static void vl_api_nat44_lb_static_mapping_dump_t_handler(vl_api_nat44_lb_static_mapping_dump_t *mp)
Definition: nat_api.c:1343
static void vl_api_nat_reass_dump_t_handler(vl_api_nat_reass_dump_t *mp)
Definition: nat_api.c:371
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
static int nat64_api_interface_walk(snat_interface_t *i, void *arg)
Definition: nat_api.c:2029
NAT users response.
Definition: nat.api:793
Add/delete address range to DS-Lite pool.
Definition: nat.api:1206
static void vl_api_nat64_bib_dump_t_handler(vl_api_nat64_bib_dump_t *mp)
Definition: nat_api.c:2148
static int nat_ip6_reass_walk_api(nat_reass_ip6_t *reass, void *arg)
Definition: nat_api.c:348
svm_queue_t * q
Definition: nat_api.c:2671
static clib_error_t * snat_plugin_api_hookup(vlib_main_t *vm)
Definition: nat_api.c:2848
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:273
Set NAT virtual fragmentation reassembly.
Definition: nat.api:151
static void * vl_api_nat64_bib_dump_t_print(vl_api_nat64_bib_dump_t *mp, void *handle)
Definition: nat_api.c:2170
static void * vl_api_nat66_add_del_static_mapping_t_print(vl_api_nat66_add_del_static_mapping_t *mp, void *handle)
Definition: nat_api.c:2656
Control ping from client to api server request.
Definition: nat.api:34
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:992
Get outside address and port range from inside address.
Definition: nat.api:725
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:520
u32 nstaticsessions
Definition: nat.h:173
static void vl_api_nat64_add_del_pool_addr_range_t_handler(vl_api_nat64_add_del_pool_addr_range_t *mp)
Definition: nat_api.c:1885
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
Definition: nat_det.h:180
Get inside address from outside address and port reply.
Definition: nat.api:766
Combined counter to hold both packets and byte differences.
Definition: counter.h:139
NAT44 interface details response.
Definition: nat.api:297
static nat44_lb_addr_port_t * unformat_nat44_lb_addr_port(vl_api_nat44_lb_addr_port_t *addr_port_pairs, u8 addr_port_pair_num)
Definition: nat_api.c:1237
int i
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: nat_det.h:129
static void send_nat44_interface_addr_details(u32 sw_if_index, vl_api_registration_t *reg, u32 context, u8 twice_nat)
Definition: nat_api.c:1036
Dump NAT66 static mappings.
Definition: nat.api:1343
static void snat_det_forward(snat_det_map_t *dm, ip4_address_t *in_addr, ip4_address_t *out_addr, u16 *lo_port)
Definition: nat_det.h:75
NAT44 static mapping details response.
Definition: nat.api:398
static void * vl_api_dslite_add_del_pool_addr_range_t_print(vl_api_dslite_add_del_pool_addr_range_t *mp, void *handle)
Definition: nat_api.c:2585
static void * vl_api_nat64_add_del_static_bib_t_print(vl_api_nat64_add_del_static_bib_t *mp, void *handle)
Definition: nat_api.c:2102
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static void * vl_api_nat64_pool_addr_dump_t_print(vl_api_nat64_pool_addr_dump_t *mp, void *handle)
Definition: nat_api.c:1985
u32 fib_index
Definition: nat.h:170
Response to check if forwarding is enabled or disabled.
Definition: nat.api:687
snat_det_map_t * det_maps
Definition: nat.h:354
Get values of timeouts for deterministic NAT (seconds)
Definition: nat.api:826
static void vl_api_nat_control_ping_t_handler(vl_api_nat_control_ping_t *mp)
Definition: nat_api.c:70
Get NAT virtual fragmentation reassembly configuration reply.
Definition: nat.api:182
int nat64_add_interface_address(u32 sw_if_index, int is_add)
NAT64 pool address from specific (DHCP addressed) interface.
Definition: nat64.c:362
Add/delete NAT64 pool address from specific interfce.
Definition: nat.api:1186
u8 in_plen
Definition: nat.h:196
static void snat_det_reverse(snat_det_map_t *dm, ip4_address_t *out_addr, u16 out_port, ip4_address_t *in_addr)
Definition: nat_det.h:90
void * vl_msg_api_alloc(int nbytes)
#define snat_is_unk_proto_session(s)
Check if SNAT session for unknown protocol.
Definition: nat.h:451
int nat64_set_tcp_timeouts(u32 trans, u32 est, u32 incoming_syn)
Set TCP session timeouts.
Definition: nat64.c:797
static void vl_api_nat44_add_del_interface_addr_t_handler(vl_api_nat44_add_del_interface_addr_t *mp)
Definition: nat_api.c:1005
static void vl_api_nat_set_workers_t_handler(vl_api_nat_set_workers_t *mp)
Definition: nat_api.c:130
u8 deterministic
Definition: nat.h:362
Enable/disable NAT64 feature on the interface.
Definition: nat.api:965
void nat_ip4_reass_walk(nat_ip4_reass_walk_fn_t fn, void *ctx)
Walk IPv4 reassemblies.
Definition: nat_reass.c:370
static void * vl_api_nat_get_reass_t_print(vl_api_nat_get_reass_t *mp, void *handle)
Definition: nat_api.c:309
static int nat64_api_prefix_walk(nat64_prefix_t *p, void *arg)
Definition: nat_api.c:2345
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat.c:1527
nat44_lb_addr_port_t * locals
Definition: nat.h:226
static void * vl_api_nat_det_reverse_t_print(vl_api_nat_det_reverse_t *mp, void *handle)
Definition: nat_api.c:1589
static void * vl_api_nat_show_config_t_print(vl_api_nat_show_config_t *mp, void *handle)
Definition: nat_api.c:120
static void * vl_api_nat44_forwarding_is_enabled_t_print(vl_api_nat44_forwarding_is_enabled_t *mp, void *handle)
Definition: nat_api.c:1456
u32 user_buckets
Definition: nat.h:367
#define nat_interface_is_outside(i)
Definition: nat.h:472
u32 max_translations_per_user
Definition: nat.h:369
static void * vl_api_nat44_interface_addr_dump_t_print(vl_api_nat44_interface_addr_dump_t *mp, void *handle)
Definition: nat_api.c:1075
static void * vl_api_nat44_identity_mapping_dump_t_print(vl_api_nat44_identity_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:994
nat66_main_t nat66_main
Definition: nat66.c:23
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, snat_protocol_t proto, u32 vrf_id, nat44_lb_addr_port_t *locals, u8 is_add, u8 twice_nat, u8 out2in_only, u8 *tag)
Definition: nat.c:1141
format_function_t format_ip4_address
Definition: format.h:79
static void * vl_api_nat_det_add_del_map_t_print(vl_api_nat_det_add_del_map_t *mp, void *handle)
Definition: nat_api.c:1493
static void vl_api_nat44_user_dump_t_handler(vl_api_nat44_user_dump_t *mp)
Definition: nat_api.c:1108
Check if forwarding is enabled or disabled.
Definition: nat.api:678
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
Dump NAT64 session table.
Definition: nat.api:1110
static void * vl_api_nat44_lb_static_mapping_dump_t_print(vl_api_nat44_lb_static_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:1363
ip4_address_t ext_host_addr
Definition: nat.h:78
NAT66 interface details response.
Definition: nat.api:1316
static int nat64_api_st_walk(nat64_db_st_entry_t *ste, void *arg)
Definition: nat_api.c:2245
Response to get AFTR IPv6 and IPv4 addresses.
Definition: nat.api:1242
Enable/disbale NAT44 as an interface output feature (postrouting in2out translation) ...
Definition: nat.api:311
static void sent_nat_det_map_details(snat_det_map_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1601
u32 translation_buckets
Definition: nat.h:364
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
Definition: nat64.c:776
struct nat64_api_walk_ctx_t_ nat64_api_walk_ctx_t
ip4_address_t addr
Definition: nat.h:169
ip6_address_t b4_ip6_addr
Definition: dslite.h:83
#define SNAT_DET_SES_PER_USER
Definition: nat_det.h:30
NAT44 load-balancing address and port pair.
Definition: nat.api:572
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define foreach_snat_plugin_api_msg
Definition: nat_api.c:2785
static void vl_api_nat44_interface_add_del_output_feature_t_handler(vl_api_nat44_interface_add_del_output_feature_t *mp)
Definition: nat_api.c:609
int snat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable NAT plugin IPFIX logging.
unsigned long u64
Definition: types.h:89
static void vl_api_nat64_get_timeouts_t_handler(vl_api_nat64_get_timeouts_t *mp)
Definition: nat_api.c:2216
static void send_nat44_user_details(snat_user_t *u, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1086
Dump interfaces with NAT44 output feature.
Definition: nat.api:323
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:1037
static void vl_api_nat44_add_del_address_range_t_handler(vl_api_nat44_add_del_address_range_t *mp)
Definition: nat_api.c:403
static void vl_api_nat44_forwarding_enable_disable_t_handler(vl_api_nat44_forwarding_enable_disable_t *mp)
Definition: nat_api.c:1410
static void vl_api_nat_det_map_dump_t_handler(vl_api_nat_det_map_dump_t *mp)
Definition: nat_api.c:1624
ip4_address_t local_addr
Definition: nat.h:214
Get B4 IPv6 and IPv4 addresses.
Definition: nat.api:1266
static void * vl_api_nat66_add_del_interface_t_print(vl_api_nat66_add_del_interface_t *mp, void *handle)
Definition: nat_api.c:2622
snat_protocol_t proto
Definition: nat.h:240
static void * vl_api_nat44_forwarding_enable_disable_t_print(vl_api_nat44_forwarding_enable_disable_t *mp, void *handle)
Definition: nat_api.c:1422
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:2889
Get values of timeouts for NAT64 (seconds)
Definition: nat.api:1077
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
u8 nat_reass_get_max_frag(u8 is_ip6)
Get maximum number of fragmets per reassembly.
Definition: nat_reass.c:157
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:335
static void * vl_api_dslite_get_b4_addr_t_print(vl_api_dslite_get_b4_addr_t *mp, void *handle)
Definition: nat_api.c:2541
static u32 snat_det_user_ses_offset(ip4_address_t *addr, u8 plen)
Definition: nat_det.h:105
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
static void send_nat44_address_details(snat_address_t *a, vl_api_registration_t *reg, u32 context, u8 twice_nat)
Definition: nat_api.c:472
#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:461
Control ping from the client to the server response.
Definition: nat.api:46
void nat66_static_mappings_walk(nat66_static_mapping_walk_fn_t fn, void *ctx)
Definition: nat66.c:219
static void * vl_api_nat64_st_dump_t_print(vl_api_nat64_st_dump_t *mp, void *handle)
Definition: nat_api.c:2306
static void * vl_api_nat_control_ping_t_print(vl_api_nat_control_ping_t *mp, void *handle)
Definition: nat_api.c:85
counter_t packets
packet counter
Definition: counter.h:141
static void vl_api_nat44_forwarding_is_enabled_t_handler(vl_api_nat44_forwarding_is_enabled_t *mp)
Definition: nat_api.c:1434
Add/delete address range to NAT64 pool.
Definition: nat.api:929
snat_det_session_t * sessions
Definition: nat.h:203
u64 key
the key
Definition: bihash_8_8.h:35
Close deterministic NAT session by outside address and port.
Definition: nat.api:856
static void vl_api_nat_det_set_timeouts_t_handler(vl_api_nat_det_set_timeouts_t *mp)
Definition: nat_api.c:1651
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
Definition: nat_det.h:60
static void * vl_api_dslite_get_aftr_addr_t_print(vl_api_dslite_get_aftr_addr_t *mp, void *handle)
Definition: nat_api.c:2479
static void send_nat44_interface_output_feature_details(snat_interface_t *i, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:641
u32 nat64_get_udp_timeout(void)
Get UDP session timeout.
Definition: nat64.c:768
Enable/disable forwarding for NAT44 Forward packets which don&#39;t match existing translation or static ...
Definition: nat.api:668
Dump NAT64 pool addresses.
Definition: nat.api:942
static void * vl_api_nat_set_workers_t_print(vl_api_nat_set_workers_t *mp, void *handle)
Definition: nat_api.c:153
u8 out2in_dpo
Definition: nat.h:363
snat_static_mapping_t * static_mappings
Definition: nat.h:317
Add/del NAT64 prefix.
Definition: nat.api:1149
u32 udp_timeout
Definition: nat.h:376
u8 static_mapping_only
Definition: nat.h:360
vl_api_registration_t * reg
Definition: nat_api.c:320
static void vl_api_nat64_set_timeouts_t_handler(vl_api_nat64_set_timeouts_t *mp)
Definition: nat_api.c:2180
static void * vl_api_dslite_set_aftr_addr_t_print(vl_api_dslite_set_aftr_addr_t *mp, void *handle)
Definition: nat_api.c:2448
static int nat66_api_interface_walk(snat_interface_t *i, void *arg)
Definition: nat_api.c:2676
#define REPLY_MACRO(t)
static void vl_api_nat64_pool_addr_dump_t_handler(vl_api_nat64_pool_addr_dump_t *mp)
Definition: nat_api.c:1968
#define nat_interface_is_inside(i)
Definition: nat.h:471
static void * vl_api_nat44_interface_output_feature_dump_t_print(vl_api_nat44_interface_output_feature_dump_t *mp, void *handle)
Definition: nat_api.c:680
static void vl_api_nat_det_reverse_t_handler(vl_api_nat_det_reverse_t *mp)
Definition: nat_api.c:1558
Dump NAT44 identity mappings.
Definition: nat.api:443
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, u8 twice_nat, u8 out2in_only, u8 *tag)
Add static mapping.
Definition: nat.c:663
int dslite_add_del_pool_addr(dslite_main_t *dm, ip4_address_t *addr, u8 is_add)
Definition: dslite.c:168
int dslite_set_b4_ip4_addr(dslite_main_t *dm, ip4_address_t *addr)
Definition: dslite.c:153
static void vl_api_nat44_add_del_identity_mapping_t_handler(vl_api_nat44_add_del_identity_mapping_t *mp)
Definition: nat_api.c:858
static void send_nat_det_session_details(snat_det_session_t *s, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1816
static void * vl_api_nat66_static_mapping_dump_t_print(vl_api_nat66_static_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:2773
api_main_t * api_main
Definition: nat.h:389
Add/delete NAT44 pool address from specific interfce.
Definition: nat.api:476
u8 out_plen
Definition: nat.h:198
static void * vl_api_nat_worker_dump_t_print(vl_api_nat_worker_dump_t *mp, void *handle)
Definition: nat_api.c:215
static void * vl_api_nat44_address_dump_t_print(vl_api_nat44_address_dump_t *mp, void *handle)
Definition: nat_api.c:516
static void vl_api_dslite_set_aftr_addr_t_handler(vl_api_dslite_set_aftr_addr_t *mp)
Definition: nat_api.c:2428
u32 inside_vrf_id
Definition: nat.h:372
static void vl_api_nat44_del_session_t_handler(vl_api_nat44_del_session_t *mp)
Definition: nat_api.c:1373
static void * vl_api_nat_det_session_dump_t_print(vl_api_nat_det_session_dump_t *mp, void *handle)
Definition: nat_api.c:1868
Add/delete NAT64 static BIB entry.
Definition: nat.api:1004
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:199
static void vl_api_nat44_add_del_static_mapping_t_handler(vl_api_nat44_add_del_static_mapping_t *mp)
Definition: nat_api.c:691
Enable/disable NAT66 feature on the interface.
Definition: nat.api:1294
static void send_nat44_interface_details(snat_interface_t *i, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:559
snat_interface_t * output_feature_interfaces
Definition: nat.h:321
snat_main_t snat_main
Definition: nat.c:35
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
u16 nat_reass_get_max_reass(u8 is_ip6)
Get maximum number of concurrent reassemblies.
Definition: nat_reass.c:146
u64 value
the value
Definition: bihash_8_8.h:36
#define BAD_SW_IF_INDEX_LABEL
Add/delete NAT deterministic mapping.
Definition: nat.api:707
u32 nat64_get_tcp_est_timeout(void)
Get TCP established timeout.
Definition: nat64.c:828
snat_user_t * users
Definition: nat.h:256
ip6_address_t aftr_ip6_addr
Definition: dslite.h:81
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
static int nat66_api_static_mapping_walk(nat66_static_mapping_t *m, void *arg)
Definition: nat_api.c:2723
static void * vl_api_nat66_interface_dump_t_print(vl_api_nat66_interface_dump_t *mp, void *handle)
Definition: nat_api.c:2712
static void vl_api_nat66_add_del_static_mapping_t_handler(vl_api_nat66_add_del_static_mapping_t *mp)
Definition: nat_api.c:2637
static void * vl_api_nat64_add_del_prefix_t_print(vl_api_nat64_add_del_prefix_t *mp, void *handle)
Definition: nat_api.c:2332
static void vl_api_nat64_add_del_interface_addr_t_handler(vl_api_nat64_add_del_interface_addr_t *mp)
Definition: nat_api.c:2394
Dump interfaces with NAT44 feature.
Definition: nat.api:287
int nat66_interface_add_del(u32 sw_if_index, u8 is_inside, u8 is_add)
Definition: nat66.c:58
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
Definition: nat64.c:347
int nat_reass_set(u32 timeout, u16 max_reass, u8 max_frag, u8 drop_frag, u8 is_ip6)
Set NAT virtual fragmentation reassembly configuration.
Definition: nat_reass.c:85
ip6_address_t e_addr
Definition: nat66.h:28
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:89
format_function_t format_ip6_address
Definition: format.h:95
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
Definition: nat_reass.c:168
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:250
vlib_main_t * vm
Definition: buffer.c:294
static void vl_api_nat44_identity_mapping_dump_t_handler(vl_api_nat44_identity_mapping_dump_t *mp)
Definition: nat_api.c:965
static void vl_api_nat_det_forward_t_handler(vl_api_nat_det_forward_t *mp)
Definition: nat_api.c:1507
u32 outside_vrf_id
Definition: nat.h:370
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: nat_api.c:1920
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Definition: nat.c:2218
svm_queue_t * vl_api_client_index_to_input_queue(u32 index)
Definition: memory_api.c:739
static void vl_api_nat_show_config_t_handler(vl_api_nat_show_config_t *mp)
Definition: nat_api.c:95
static void vl_api_nat44_add_del_lb_static_mapping_t_handler(vl_api_nat44_add_del_lb_static_mapping_t *mp)
Definition: nat_api.c:1259
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:302
u8 static_mapping_connection_tracking
Definition: nat.h:361
Dump NAT44 load-balancing static mapping rules.
Definition: nat.api:611
Dump NAT44 addresses.
Definition: nat.api:250
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
ip4_address_t b4_ip4_addr
Definition: dslite.h:84
deterministic NAT definitions
NAT44 user&#39;s sessions response.
Definition: nat.api:554
static void * vl_api_nat44_interface_dump_t_print(vl_api_nat44_interface_dump_t *mp, void *handle)
Definition: nat_api.c:597
static void * vl_api_nat_det_map_dump_t_print(vl_api_nat_det_map_dump_t *mp, void *handle)
Definition: nat_api.c:1641
Set NAT workers.
Definition: nat.api:99
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
Definition: nat64.c:950
static void vl_api_nat44_interface_addr_dump_t_handler(vl_api_nat44_interface_addr_dump_t *mp)
Definition: nat_api.c:1055
#define clib_warning(format, args...)
Definition: error.h:59
NAT66 static mapping details response.
Definition: nat.api:1356
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat.c:1683
#define clib_memcpy(a, b, c)
Definition: string.h:75
u32 sharing_ratio
Definition: nat.h:199
ip4_address_t out_addr
Definition: nat.h:197
static void vl_api_nat64_add_del_prefix_t_handler(vl_api_nat64_add_del_prefix_t *mp)
Definition: nat_api.c:2316
dslite_main_t dslite_main
Definition: dslite.c:19
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
static void vl_api_nat64_prefix_dump_t_handler(vl_api_nat64_prefix_dump_t *mp)
Definition: nat_api.c:2365
static void * vl_api_nat44_add_del_lb_static_mapping_t_print(vl_api_nat44_add_del_lb_static_mapping_t *mp, void *handle)
Definition: nat_api.c:1290
static void vl_api_nat_det_get_timeouts_t_handler(vl_api_nat_det_get_timeouts_t *mp)
Definition: nat_api.c:1681
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:33
#define ARRAY_LEN(x)
Definition: clib.h:59
static void send_nat44_identity_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:916
u32 sw_if_index
Definition: nat.h:230
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
nat64_main_t nat64_main
Definition: nat64.c:27
static void vl_api_dslite_set_b4_addr_t_handler(vl_api_dslite_set_b4_addr_t *mp)
Definition: nat_api.c:2490
static void send_nat44_lb_static_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1302
u32 tcp_transitory_timeout
Definition: nat.h:378
static void vl_api_nat_det_close_session_out_t_handler(vl_api_nat_det_close_session_out_t *mp)
Definition: nat_api.c:1710
static void send_nat44_static_map_resolve_details(snat_static_map_resolve_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:786
static void vl_api_nat_det_add_del_map_t_handler(vl_api_nat_det_add_del_map_t *mp)
Definition: nat_api.c:1470
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: nat_det.c:40
u32 vrf_id
Definition: nat64.h:51
u32 * auto_add_sw_if_indices
Definition: nat.h:334
static int nat64_api_bib_walk(nat64_db_bib_entry_t *bibe, void *arg)
Definition: nat_api.c:2118
static void vl_api_nat66_static_mapping_dump_t_handler(vl_api_nat66_static_mapping_dump_t *mp)
Definition: nat_api.c:2755
static void vl_api_dslite_get_aftr_addr_t_handler(vl_api_dslite_get_aftr_addr_t *mp)
Definition: nat_api.c:2462
Get NAT virtual fragmentation reassembly configuration.
Definition: nat.api:165
static void vl_api_nat_get_reass_t_handler(vl_api_nat_get_reass_t *mp)
Definition: nat_api.c:287
static void * vl_api_nat44_add_del_static_mapping_t_print(vl_api_nat44_add_del_static_mapping_t *mp, void *handle)
Definition: nat_api.c:727
static void vl_api_nat_det_close_session_in_t_handler(vl_api_nat_det_close_session_in_t *mp)
Definition: nat_api.c:1762
static snat_det_map_t * snat_det_map_by_user(snat_main_t *sm, ip4_address_t *user_addr)
Definition: nat_det.h:45
static void * vl_api_nat64_add_del_interface_addr_t_print(vl_api_nat64_add_del_interface_addr_t *mp, void *handle)
Definition: nat_api.c:2411
vl_api_nat44_lb_addr_port_t locals[local_num]
Definition: nat.api:639
u32 num_workers
Definition: nat.h:298
unsigned int u32
Definition: types.h:88
static int nat_ip4_reass_walk_api(nat_reass_ip4_t *reass, void *arg)
Definition: nat_api.c:325
static void vl_api_dslite_add_del_pool_addr_range_t_handler(vl_api_dslite_add_del_pool_addr_range_t *mp)
Definition: nat_api.c:2553
NAT44 users response.
Definition: nat.api:520
Get values of timeouts for NAT64 reply.
Definition: nat.api:1091
u32 first_worker_index
Definition: nat.h:299
void nat64_db_st_walk(nat64_db_t *db, u8 proto, nat64_db_st_walk_fn_t fn, void *ctx)
Walk NAT64 session table.
Definition: nat64_db.c:320
u32 nat64_get_tcp_incoming_syn_timeout(void)
Get TCP incoming SYN timeout.
Definition: nat64.c:836
static void * vl_api_nat44_interface_add_del_output_feature_t_print(vl_api_nat44_interface_add_del_output_feature_t *mp, void *handle)
Definition: nat_api.c:628
static void send_nat44_static_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:755
long ctx[MAX_CONNS]
Definition: main.c:126
vl_api_registration_t * reg
Definition: nat_api.c:1935
ip4_address_t l_addr
Definition: nat.h:235
NAT64 pool address details response.
Definition: nat.api:952
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: nat.h:486
static void * vl_api_nat_set_reass_t_print(vl_api_nat_set_reass_t *mp, void *handle)
Definition: nat_api.c:273
Dump NAT workers.
Definition: nat.api:109
static void vl_api_nat_ipfix_enable_disable_t_handler(vl_api_nat_ipfix_enable_disable_t *mp)
Definition: nat_api.c:225
Dump NAT64 prefix details response.
Definition: nat.api:1173
Set B4 IPv6 and IPv4 addresses.
Definition: nat.api:1255
static void send_nat_worker_details(u32 worker_index, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:178
static void * vl_api_nat64_get_timeouts_t_print(vl_api_nat64_get_timeouts_t *mp, void *handle)
Definition: nat_api.c:2235
static void vl_api_nat_det_session_dump_t_handler(vl_api_nat_det_session_dump_t *mp)
Definition: nat_api.c:1837
u64 as_u64
Definition: nat.h:94
static void * vl_api_nat44_add_del_identity_mapping_t_print(vl_api_nat44_add_del_identity_mapping_t *mp, void *handle)
Definition: nat_api.c:894
Add/del NAT44 address range.
Definition: nat.api:236
nat64_db_bib_entry_t * nat64_db_bib_entry_by_index(nat64_db_t *db, u8 proto, u32 bibe_index)
Get BIB entry by index and protocol.
Definition: nat64_db.c:297
Close deterministic NAT session by inside address and port.
Definition: nat.api:874
static void vl_api_nat64_interface_dump_t_handler(vl_api_nat64_interface_dump_t *mp)
Definition: nat_api.c:2050
ip4_address_t addr
Definition: nat.h:91
ip4_address_t in_addr
Definition: nat.h:195
static void * vl_api_nat44_static_mapping_dump_t_print(vl_api_nat44_static_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:846
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
size_t count
Definition: vapi.c:42
Dump determinstic NAT sessions.
Definition: nat.api:890
static void * vl_api_nat_det_forward_t_print(vl_api_nat_det_forward_t *mp, void *handle)
Definition: nat_api.c:1547
ip4_address_t addr
Definition: nat.h:177
static void vl_api_nat66_interface_dump_t_handler(vl_api_nat66_interface_dump_t *mp)
Definition: nat_api.c:2695
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, snat_protocol_t proto, u32 vrf_id, int is_in)
Definition: nat.c:3014
snat_address_t * twice_nat_addresses
Definition: nat.h:331
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
Definition: nat64.c:998
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:487
static void * vl_api_nat_det_get_timeouts_t_print(vl_api_nat_det_get_timeouts_t *mp, void *handle)
Definition: nat_api.c:1699
int dslite_set_aftr_ip4_addr(dslite_main_t *dm, ip4_address_t *addr)
Definition: dslite.c:116
NAT64 global declarations.
counter_t bytes
byte counter
Definition: counter.h:142
ip6_address_t l_addr
Definition: nat66.h:27
void increment_v4_address(ip4_address_t *a)
Definition: nat.c:610
vlib_combined_counter_main_t session_counters
Session counters.
Definition: nat66.h:57
Dump NAT64 BIB.
Definition: nat.api:1025
unsigned short u16
Definition: types.h:57
static void * vl_api_nat44_add_del_address_range_t_print(vl_api_nat44_add_del_address_range_t *mp, void *handle)
Definition: nat_api.c:457
void nat66_interfaces_walk(nat66_interface_walk_fn_t fn, void *ctx)
Definition: nat66.c:100
Add/delete NAT44 load-balancing static mapping rule.
Definition: nat.api:592
Dump NAT deterministic mappings.
Definition: nat.api:777
Show NAT plugin startup config reply.
Definition: nat.api:78
void snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Definition: nat.c:542
Get outside address and port range from inside address.
Definition: nat.api:739
static void vl_api_dslite_get_b4_addr_t_handler(vl_api_dslite_get_b4_addr_t *mp)
Definition: nat_api.c:2524
static void vl_api_nat44_interface_dump_t_handler(vl_api_nat44_interface_dump_t *mp)
Definition: nat_api.c:578
Dump interfaces with NAT66 feature.
Definition: nat.api:1306
Add/delete NAT44 static mapping.
Definition: nat.api:358
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
int dslite_set_b4_ip6_addr(dslite_main_t *dm, ip6_address_t *addr)
Definition: dslite.c:123
unsigned char u8
Definition: types.h:56
static void * vl_api_nat44_add_del_interface_addr_t_print(vl_api_nat44_add_del_interface_addr_t *mp, void *handle)
Definition: nat_api.c:1023
static void * vl_api_nat44_user_session_dump_t_print(vl_api_nat44_user_session_dump_t *mp, void *handle)
Definition: nat_api.c:1223
u16 msg_id_base
Definition: nat.h:382
Add/delete 1:1 NAT66.
Definition: nat.api:1330
Dump NAT44 static mappings.
Definition: nat.api:379
u16 ports_per_host
Definition: nat.h:200
Deterministic NAT sessions reply.
Definition: nat.api:906
static void vl_api_nat64_add_del_static_bib_t_handler(vl_api_nat64_add_del_static_bib_t *mp)
Definition: nat_api.c:2079
Dump interfaces with NAT64 feature.
Definition: nat.api:977
u32 * workers
Definition: nat.h:301
NAT44 pool addresses interfaces details response.
Definition: nat.api:498
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:308
snat_protocol_t
Definition: nat.h:104
snat_det_out_key_t out
Definition: nat.h:189
void nat_ip6_reass_walk(nat_ip6_reass_walk_fn_t fn, void *ctx)
Walk IPv6 reassemblies.
Definition: nat_reass.c:566
static void * vl_api_nat_det_set_timeouts_t_print(vl_api_nat_det_set_timeouts_t *mp, void *handle)
Definition: nat_api.c:1666
u32 fib_index
Definition: nat.h:92
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
int nat66_static_mapping_add_del(ip6_address_t *l_addr, ip6_address_t *e_addr, u32 vrf_id, u8 is_add)
Definition: nat66.c:139
Enable/disable NAT IPFIX logging.
Definition: nat.api:134
snat_address_t * addresses
Definition: nat.h:324
NAT44 user&#39;s sessions.
Definition: nat.api:535
nat64_db_t * db
Definition: nat_api.c:1937
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Definition: nat.c:2947
static void * vl_api_nat64_add_del_interface_t_print(vl_api_nat64_add_del_interface_t *mp, void *handle)
Definition: nat_api.c:2015
struct _svm_queue svm_queue_t
static void * vl_api_nat64_set_timeouts_t_print(vl_api_nat64_set_timeouts_t *mp, void *handle)
Definition: nat_api.c:2201
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: nat_det.h:112
snat_static_map_resolve_t * to_resolve
Definition: nat.h:338
#define SNAT_SESSION_FLAG_STATIC_MAPPING
Definition: nat.h:128
Set values of timeouts for deterministic NAT (seconds, 0 = default)
Definition: nat.api:813
static void vl_api_nat44_address_dump_t_handler(vl_api_nat44_address_dump_t *mp)
Definition: nat_api.c:497
u8 forwarding_enabled
Definition: nat.h:357
u32 translation_memory_size
Definition: nat.h:365
#define vec_foreach(var, vec)
Vector iterator.
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:2870
static void plugin_custom_dump_configure(snat_main_t *sm)
Definition: nat_api.c:2879
static void vl_api_nat44_interface_add_del_feature_t_handler(vl_api_nat44_interface_add_del_feature_t *mp)
Definition: nat_api.c:528
u32 ses_num
Definition: nat.h:201
#define FINISH
Definition: nat_api.c:58
nat66_static_mapping_t * sm
Static mapping pool.
Definition: nat66.h:51
static void vl_api_nat64_st_dump_t_handler(vl_api_nat64_st_dump_t *mp)
Definition: nat_api.c:2281
int snat_set_workers(uword *bitmap)
Definition: nat.c:1778
Set values of timeouts for NAT64 (seconds, 0 = default)
Definition: nat.api:1063
struct nat66_api_walk_ctx_t_ nat66_api_walk_ctx_t
Response to get B4 IPv6 and IPv4 addresses.
Definition: nat.api:1277
vhost_vring_addr_t addr
Definition: vhost-user.h:83
static void * vl_api_nat_det_close_session_out_t_print(vl_api_nat_det_close_session_out_t *mp, void *handle)
Definition: nat_api.c:1747
static void * vl_api_nat44_interface_add_del_feature_t_print(vl_api_nat44_interface_add_del_feature_t *mp, void *handle)
Definition: nat_api.c:546
static void * vl_api_nat64_prefix_dump_t_print(vl_api_nat64_prefix_dump_t *mp, void *handle)
Definition: nat_api.c:2382
NAT plugin virtual fragmentation reassembly.
Get inside address from outside address and port.
Definition: nat.api:753
NAT66 global declarations.
Get values of timeouts for deterministic NAT reply.
Definition: nat.api:839
static void * vl_api_dslite_set_b4_addr_t_print(vl_api_dslite_set_b4_addr_t *mp, void *handle)
Definition: nat_api.c:2510
Get AFTR IPv6 and IPv4 addresses.
Definition: nat.api:1231
static void * vl_api_nat_reass_dump_t_print(vl_api_nat_reass_dump_t *mp, void *handle)
Definition: nat_api.c:389
Dump NAT44 users.
Definition: nat.api:508
#define BITS(x)
Definition: clib.h:58
Enable/disable NAT44 feature on the interface.
Definition: nat.api:275
void nat64_db_bib_walk(nat64_db_t *db, u8 proto, nat64_db_bib_walk_fn_t fn, void *ctx)
Walk NAT64 BIB.
Definition: nat64_db.c:246
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:624
int dslite_set_aftr_ip6_addr(dslite_main_t *dm, ip6_address_t *addr)
Definition: dslite.c:80
static void vl_api_nat44_static_mapping_dump_t_handler(vl_api_nat44_static_mapping_dump_t *mp)
Definition: nat_api.c:816
static void vl_api_nat_set_reass_t_handler(vl_api_nat_set_reass_t *mp)
Definition: nat_api.c:259
u32 fib_index
Definition: nat.h:178
snat_interface_t * interfaces
Definition: nat.h:320
Delete NAT44 session.
Definition: nat.api:651
u32 nat64_get_tcp_trans_timeout(void)
Get TCP transitory timeout.
Definition: nat64.c:820
#define VALIDATE_SW_IF_INDEX(mp)
A protocol Independent FIB table.
Definition: fib_table.h:69
static void vl_api_nat44_interface_output_feature_dump_t_handler(vl_api_nat44_interface_output_feature_dump_t *mp)
Definition: nat_api.c:661
Show NAT plugin startup config.
Definition: nat.api:58
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
Definition: nat.h:499
NAT44 address details response.
Definition: nat.api:261
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:872
NAT64 session table details response.
Definition: nat.api:1128
static void vl_api_nat64_add_del_interface_t_handler(vl_api_nat64_add_del_interface_t *mp)
Definition: nat_api.c:1996
u32 tcp_established_timeout
Definition: nat.h:377
struct nat_api_walk_ctx_t_ nat_api_walk_ctx_t