FD.io VPP  v19.01.3-6-g70449b9b9
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 <nat/nat_inlines.h>
28 #include <vlibapi/api.h>
29 #include <vlibmemory/api.h>
30 
31 #include <nat/nat_msg_enum.h>
32 #include <vnet/fib/fib_table.h>
33 
34 #define vl_api_nat44_lb_addr_port_t_endian vl_noop_handler
35 #define vl_api_nat44_add_del_lb_static_mapping_t_endian vl_noop_handler
36 #define vl_api_nat44_nat44_lb_static_mapping_details_t_endian vl_noop_handler
37 
38 /* define message structures */
39 #define vl_typedefs
40 #include <nat/nat_all_api_h.h>
41 #undef vl_typedefs
42 
43 /* define generated endian-swappers */
44 #define vl_endianfun
45 #include <nat/nat_all_api_h.h>
46 #undef vl_endianfun
47 
48 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
49 
50 #define REPLY_MSG_ID_BASE sm->msg_id_base
52 
53 /* Get the API version number */
54 #define vl_api_version(n,v) static u32 api_version=(v);
55 #include <nat/nat_all_api_h.h>
56 #undef vl_api_version
57 
58 /* Macro to finish up custom dump fns */
59 #define FINISH \
60  vec_add1 (s, 0); \
61  vl_print (handle, (char *)s); \
62  vec_free (s); \
63  return handle;
64 
65 
66 /******************************/
67 /*** Common NAT plugin APIs ***/
68 /******************************/
69 
70 static void
72 {
74  snat_main_t *sm = &snat_main;
75  int rv = 0;
76 
77  /* *INDENT-OFF* */
78  REPLY_MACRO2 (VL_API_NAT_CONTROL_PING_REPLY,
79  ({
80  rmp->vpe_pid = ntohl (getpid ());
81  }));
82  /* *INDENT-ON* */
83 }
84 
85 static void *
87 {
88  u8 *s;
89 
90  s = format (0, "SCRIPT: nat_control_ping ");
91 
92  FINISH;
93 }
94 
95 static void
97 {
99  snat_main_t *sm = &snat_main;
100  dslite_main_t *dm = &dslite_main;
101  nat64_main_t *n64m = &nat64_main;
102  int rv = 0;
103 
104  /* *INDENT-OFF* */
105  REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_REPLY,
106  ({
107  rmp->translation_buckets = htonl (sm->translation_buckets);
109  rmp->user_buckets = htonl (sm->user_buckets);
110  rmp->user_memory_size = htonl (sm->user_memory_size);
112  rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
113  rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
117  rmp->deterministic = sm->deterministic;
119  rmp->out2in_dpo = sm->out2in_dpo;
120  rmp->dslite_ce = dm->is_ce;
121  rmp->nat64_bib_buckets = n64m->bib_buckets;
123  rmp->nat64_st_buckets = n64m->st_buckets;
125  }));
126  /* *INDENT-ON* */
127 }
128 
129 static void *
131 {
132  u8 *s;
133 
134  s = format (0, "SCRIPT: nat_show_config ");
135 
136  FINISH;
137 }
138 
139 static void
141 {
142  snat_main_t *sm = &snat_main;
143  vl_api_nat_set_workers_reply_t *rmp;
144  int rv = 0;
145  uword *bitmap = 0;
146  u64 mask;
147 
148  if (sm->deterministic)
149  {
150  rv = VNET_API_ERROR_UNSUPPORTED;
151  goto send_reply;
152  }
153 
154  mask = clib_net_to_host_u64 (mp->worker_mask);
155 
156  if (sm->num_workers < 2)
157  {
158  rv = VNET_API_ERROR_FEATURE_DISABLED;
159  goto send_reply;
160  }
161 
162  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
163  rv = snat_set_workers (bitmap);
164  clib_bitmap_free (bitmap);
165 
166 send_reply:
167  REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
168 }
169 
170 static void *
172 {
173  u8 *s;
174  uword *bitmap = 0;
175  u8 first = 1;
176  int i;
177  u64 mask = clib_net_to_host_u64 (mp->worker_mask);
178 
179  s = format (0, "SCRIPT: nat_set_workers ");
180  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
181  /* *INDENT-OFF* */
182  clib_bitmap_foreach (i, bitmap,
183  ({
184  if (first)
185  s = format (s, "%d", i);
186  else
187  s = format (s, ",%d", i);
188  first = 0;
189  }));
190  /* *INDENT-ON* */
191  clib_bitmap_free (bitmap);
192  FINISH;
193 }
194 
195 static void
197  u32 context)
198 {
200  snat_main_t *sm = &snat_main;
202  vlib_worker_threads + worker_index + sm->first_worker_index;
203 
204  rmp = vl_msg_api_alloc (sizeof (*rmp));
205  clib_memset (rmp, 0, sizeof (*rmp));
206  rmp->_vl_msg_id = ntohs (VL_API_NAT_WORKER_DETAILS + sm->msg_id_base);
207  rmp->context = context;
208  rmp->worker_index = htonl (worker_index);
209  rmp->lcore_id = htonl (w->cpu_id);
210  strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1);
211 
212  vl_api_send_msg (reg, (u8 *) rmp);
213 }
214 
215 static void
217 {
219  snat_main_t *sm = &snat_main;
220  u32 *worker_index;
221 
222  if (sm->deterministic)
223  return;
224 
226  if (!reg)
227  return;
228 
229  /* *INDENT-OFF* */
230  vec_foreach (worker_index, sm->workers)
231  send_nat_worker_details(*worker_index, reg, mp->context);
232  /* *INDENT-ON* */
233 }
234 
235 static void *
237 {
238  u8 *s;
239 
240  s = format (0, "SCRIPT: nat_worker_dump ");
241 
242  FINISH;
243 }
244 
245 static void
247  mp)
248 {
249  snat_main_t *sm = &snat_main;
250  vl_api_nat_ipfix_enable_disable_reply_t *rmp;
251  int rv = 0;
252 
254  clib_host_to_net_u32
255  (mp->domain_id),
256  clib_host_to_net_u16
257  (mp->src_port));
258 
259  REPLY_MACRO (VL_API_NAT_IPFIX_ENABLE_DISABLE_REPLY);
260 }
261 
262 static void *
264  mp, void *handle)
265 {
266  u8 *s;
267 
268  s = format (0, "SCRIPT: nat_ipfix_enable_disable ");
269  if (mp->domain_id)
270  s = format (s, "domain %d ", clib_net_to_host_u32 (mp->domain_id));
271  if (mp->src_port)
272  s = format (s, "src_port %d ", clib_net_to_host_u16 (mp->src_port));
273  if (!mp->enable)
274  s = format (s, "disable ");
275 
276  FINISH;
277 }
278 
279 static void
281 {
282  snat_main_t *sm = &snat_main;
283  vl_api_nat_set_reass_reply_t *rmp;
284  int rv = 0;
285 
286  rv =
287  nat_reass_set (ntohl (mp->timeout), ntohs (mp->max_reass), mp->max_frag,
288  mp->drop_frag, mp->is_ip6);
289 
290  REPLY_MACRO (VL_API_NAT_SET_REASS_REPLY);
291 }
292 
293 static void *
295 {
296  u8 *s;
297 
298  s = format (0, "SCRIPT: nat_set_reass ");
299  s = format (s, "timeout %d max_reass %d max_frag %d drop_frag %d is_ip6 %d",
300  clib_host_to_net_u32 (mp->timeout),
301  clib_host_to_net_u16 (mp->max_reass),
302  mp->max_frag, mp->drop_frag, mp->is_ip6);
303 
304  FINISH;
305 }
306 
307 static void
309 {
310  snat_main_t *sm = &snat_main;
312  int rv = 0;
313 
314  /* *INDENT-OFF* */
315  REPLY_MACRO2 (VL_API_NAT_GET_REASS_REPLY,
316  ({
317  rmp->ip4_timeout = htonl (nat_reass_get_timeout(0));
318  rmp->ip4_max_reass = htons (nat_reass_get_max_reass(0));
321  rmp->ip6_timeout = htonl (nat_reass_get_timeout(1));
322  rmp->ip6_max_reass = htons (nat_reass_get_max_reass(1));
325  }))
326  /* *INDENT-ON* */
327 }
328 
329 static void *
331 {
332  u8 *s;
333 
334  s = format (0, "SCRIPT: nat_get_reass");
335 
336  FINISH;
337 }
338 
339 typedef struct nat_api_walk_ctx_t_
340 {
344 
345 static int
346 nat_ip4_reass_walk_api (nat_reass_ip4_t * reass, void *arg)
347 {
349  snat_main_t *sm = &snat_main;
350  nat_api_walk_ctx_t *ctx = arg;
351 
352  rmp = vl_msg_api_alloc (sizeof (*rmp));
353  clib_memset (rmp, 0, sizeof (*rmp));
354  rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base);
355  rmp->context = ctx->context;
356  clib_memcpy (rmp->src_addr, &(reass->key.src), 4);
357  clib_memcpy (rmp->dst_addr, &(reass->key.dst), 4);
358  rmp->proto = reass->key.proto;
359  rmp->frag_id = ntohl (reass->key.frag_id);
360  rmp->frag_n = reass->frag_n;
361  rmp->is_ip4 = 1;
362 
363  vl_api_send_msg (ctx->reg, (u8 *) rmp);
364 
365  return 0;
366 }
367 
368 static int
369 nat_ip6_reass_walk_api (nat_reass_ip6_t * reass, void *arg)
370 {
372  snat_main_t *sm = &snat_main;
373  nat_api_walk_ctx_t *ctx = arg;
374 
375  rmp = vl_msg_api_alloc (sizeof (*rmp));
376  clib_memset (rmp, 0, sizeof (*rmp));
377  rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base);
378  rmp->context = ctx->context;
379  clib_memcpy (rmp->src_addr, &(reass->key.src), 16);
380  clib_memcpy (rmp->dst_addr, &(reass->key.dst), 16);
381  rmp->proto = reass->key.proto;
382  rmp->frag_id = ntohl (reass->key.frag_id);
383  rmp->frag_n = reass->frag_n;
384  rmp->is_ip4 = 0;
385 
386  vl_api_send_msg (ctx->reg, (u8 *) rmp);
387 
388  return 0;
389 }
390 
391 static void
393 {
395 
397  if (!reg)
398  return;
399 
401  .reg = reg,
402  .context = mp->context,
403  };
404 
407 }
408 
409 static void *
411 {
412  u8 *s;
413 
414  s = format (0, "SCRIPT: nat_reass_dump");
415 
416  FINISH;
417 }
418 
419 static void
421 {
422  snat_main_t *sm = &snat_main;
423  vl_api_nat_set_timeouts_reply_t *rmp;
424  int rv = 0;
425 
426  sm->udp_timeout = ntohl (mp->udp);
427  sm->tcp_established_timeout = ntohl (mp->tcp_established);
428  sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
429  sm->icmp_timeout = ntohl (mp->icmp);
430 
431  rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
432  if (rv)
433  goto send_reply;
434  rv = nat64_set_udp_timeout (ntohl (mp->udp));
435  if (rv)
436  goto send_reply;
437  rv =
439  ntohl (mp->tcp_established));
440 
441 send_reply:
442  REPLY_MACRO (VL_API_NAT_SET_TIMEOUTS_REPLY);
443 }
444 
445 static void *
447 {
448  u8 *s;
449 
450  s = format (0, "SCRIPT: nat_set_timeouts ");
451  s = format (s, "udp %d tcp_established %d tcp_transitory %d icmp %d\n",
452  ntohl (mp->udp),
453  ntohl (mp->tcp_established),
454  ntohl (mp->tcp_transitory), ntohl (mp->icmp));
455 
456  FINISH;
457 }
458 
459 static void
461 {
462  snat_main_t *sm = &snat_main;
464  int rv = 0;
465 
466  /* *INDENT-OFF* */
467  REPLY_MACRO2 (VL_API_NAT_GET_TIMEOUTS_REPLY,
468  ({
469  rmp->udp = htonl (sm->udp_timeout);
470  rmp->tcp_established = htonl (sm->tcp_established_timeout);
471  rmp->tcp_transitory = htonl (sm->tcp_transitory_timeout);
472  rmp->icmp = htonl (sm->icmp_timeout);
473  }))
474  /* *INDENT-ON* */
475 }
476 
477 static void *
479 {
480  u8 *s;
481 
482  s = format (0, "SCRIPT: nat_get_timeouts");
483 
484  FINISH;
485 }
486 
487 static void
490 {
491  snat_main_t *sm = &snat_main;
492  vl_api_nat_set_addr_and_port_alloc_alg_reply_t *rmp;
493  int rv = 0;
494  u16 port_start, port_end;
495 
496  if (sm->deterministic)
497  {
498  rv = VNET_API_ERROR_UNSUPPORTED;
499  goto send_reply;
500  }
501 
502  switch (mp->alg)
503  {
504  case NAT_ADDR_AND_PORT_ALLOC_ALG_DEFAULT:
506  break;
507  case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
509  mp->psid_length);
510  break;
511  case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
512  port_start = ntohs (mp->start_port);
513  port_end = ntohs (mp->end_port);
514  if (port_end <= port_start)
515  {
516  rv = VNET_API_ERROR_INVALID_VALUE;
517  goto send_reply;
518  }
519  nat_set_alloc_addr_and_port_range (port_start, port_end);
520  break;
521  default:
522  rv = VNET_API_ERROR_INVALID_VALUE;
523  break;
524  }
525 
526 send_reply:
527  REPLY_MACRO (VL_API_NAT_SET_ADDR_AND_PORT_ALLOC_ALG_REPLY);
528 }
529 
532 {
533  u8 *s;
534 
535  s = format (0, "SCRIPT: nat_set_addr_and_port_alloc_alg ");
536  s = format (s, "alg %d psid_offset %d psid_length %d psid %d start_port %d "
537  "end_port %d\n",
538  ntohl (mp->alg), ntohl (mp->psid_offset),
539  ntohl (mp->psid_length), ntohs (mp->psid),
540  ntohs (mp->start_port), ntohs (mp->end_port));
541 
542  FINISH;
543 }
544 
545 static void
548 {
549  snat_main_t *sm = &snat_main;
551  int rv = 0;
552 
553  /* *INDENT-OFF* */
554  REPLY_MACRO2 (VL_API_NAT_GET_ADDR_AND_PORT_ALLOC_ALG_REPLY,
555  ({
556  rmp->alg = sm->addr_and_port_alloc_alg;
557  rmp->psid_offset = sm->psid_offset;
558  rmp->psid_length = sm->psid_length;
559  rmp->psid = htons (sm->psid);
560  rmp->start_port = htons (sm->start_port);
561  rmp->end_port = htons (sm->end_port);
562  }))
563  /* *INDENT-ON* */
564 }
565 
568 {
569  u8 *s;
570 
571  s = format (0, "SCRIPT: nat_get_addr_and_port_alloc_alg");
572 
573  FINISH;
574 }
575 
576 static void
578 {
579  snat_main_t *sm = &snat_main;
580  vl_api_nat_set_mss_clamping_reply_t *rmp;
581  int rv = 0;
582 
583  if (mp->enable)
584  {
585  sm->mss_clamping = ntohs (mp->mss_value);
586  sm->mss_value_net = mp->mss_value;
587  }
588  else
589  sm->mss_clamping = 0;
590 
591  REPLY_MACRO (VL_API_NAT_SET_MSS_CLAMPING_REPLY);
592 }
593 
594 static void *
596  void *handle)
597 {
598  u8 *s;
599 
600  s = format (0, "SCRIPT: nat_set_mss_clamping enable %d mss_value %d\n",
601  mp->enable, ntohs (mp->mss_value));
602 
603  FINISH;
604 }
605 
606 static void
608 {
609  snat_main_t *sm = &snat_main;
611  int rv = 0;
612 
613  /* *INDENT-OFF* */
614  REPLY_MACRO2 (VL_API_NAT_GET_MSS_CLAMPING_REPLY,
615  ({
616  rmp->enable = sm->mss_clamping ? 1 : 0;
617  rmp->mss_value = htons (sm->mss_clamping);
618  }))
619  /* *INDENT-ON* */
620 }
621 
622 static void *
624  void *handle)
625 {
626  u8 *s;
627 
628  s = format (0, "SCRIPT: nat_get_mss_clamping");
629 
630  FINISH;
631 }
632 
633 /*************/
634 /*** NAT44 ***/
635 /*************/
636 static void
639 {
640  snat_main_t *sm = &snat_main;
641  vl_api_nat44_add_del_address_range_reply_t *rmp;
642  ip4_address_t this_addr;
643  u32 start_host_order, end_host_order;
644  u32 vrf_id;
645  int i, count;
646  int rv = 0;
647  u32 *tmp;
648 
649  if (sm->deterministic)
650  {
651  rv = VNET_API_ERROR_UNSUPPORTED;
652  goto send_reply;
653  }
654 
655  if (sm->static_mapping_only)
656  {
657  rv = VNET_API_ERROR_FEATURE_DISABLED;
658  goto send_reply;
659  }
660 
661  tmp = (u32 *) mp->first_ip_address;
662  start_host_order = clib_host_to_net_u32 (tmp[0]);
663  tmp = (u32 *) mp->last_ip_address;
664  end_host_order = clib_host_to_net_u32 (tmp[0]);
665 
666  count = (end_host_order - start_host_order) + 1;
667 
668  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
669 
670  if (count > 1024)
671  nat_log_info ("%U - %U, %d addresses...",
673  format_ip4_address, mp->last_ip_address, count);
674 
675  memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
676 
677  for (i = 0; i < count; i++)
678  {
679  if (mp->is_add)
680  rv = snat_add_address (sm, &this_addr, vrf_id, mp->twice_nat);
681  else
682  rv = snat_del_address (sm, this_addr, 0, mp->twice_nat);
683 
684  if (rv)
685  goto send_reply;
686 
687  if (sm->out2in_dpo)
688  nat44_add_del_address_dpo (this_addr, mp->is_add);
689 
690  increment_v4_address (&this_addr);
691  }
692 
693 send_reply:
694  REPLY_MACRO (VL_API_NAT44_ADD_DEL_ADDRESS_RANGE_REPLY);
695 }
696 
699 {
700  u8 *s;
701 
702  s = format (0, "SCRIPT: nat44_add_address_range ");
703  s = format (s, "%U ", format_ip4_address, mp->first_ip_address);
704  if (memcmp (mp->first_ip_address, mp->last_ip_address, 4))
705  {
706  s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
707  }
708  s = format (s, "twice_nat %d ", mp->twice_nat);
709  FINISH;
710 }
711 
712 static void
715  u8 twice_nat)
716 {
718  snat_main_t *sm = &snat_main;
719 
720  rmp = vl_msg_api_alloc (sizeof (*rmp));
721  clib_memset (rmp, 0, sizeof (*rmp));
722  rmp->_vl_msg_id = ntohs (VL_API_NAT44_ADDRESS_DETAILS + sm->msg_id_base);
723  clib_memcpy (rmp->ip_address, &(a->addr), 4);
724  if (a->fib_index != ~0)
725  {
727  rmp->vrf_id = ntohl (fib->ft_table_id);
728  }
729  else
730  rmp->vrf_id = ~0;
731  rmp->twice_nat = twice_nat;
732  rmp->context = context;
733 
734  vl_api_send_msg (reg, (u8 *) rmp);
735 }
736 
737 static void
739 {
741  snat_main_t *sm = &snat_main;
742  snat_address_t *a;
743 
744  if (sm->deterministic)
745  return;
746 
748  if (!reg)
749  return;
750 
751  /* *INDENT-OFF* */
752  vec_foreach (a, sm->addresses)
753  send_nat44_address_details (a, reg, mp->context, 0);
755  send_nat44_address_details (a, reg, mp->context, 1);
756  /* *INDENT-ON* */
757 }
758 
759 static void *
761  void *handle)
762 {
763  u8 *s;
764 
765  s = format (0, "SCRIPT: nat44_address_dump ");
766 
767  FINISH;
768 }
769 
770 static void
773 {
774  snat_main_t *sm = &snat_main;
775  vl_api_nat44_interface_add_del_feature_reply_t *rmp;
776  u8 is_del = mp->is_add == 0;
777  u32 sw_if_index = ntohl (mp->sw_if_index);
778  int rv = 0;
779 
781 
782  rv = snat_interface_add_del (sw_if_index, mp->is_inside, is_del);
783 
785 
786  REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_FEATURE_REPLY);
787 }
788 
791 {
792  u8 *s;
793 
794  s = format (0, "SCRIPT: nat44_interface_add_del_feature ");
795  s = format (s, "sw_if_index %d %s %s",
796  clib_host_to_net_u32 (mp->sw_if_index),
797  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
798 
799  FINISH;
800 }
801 
802 static void
805 {
807  snat_main_t *sm = &snat_main;
808 
809  rmp = vl_msg_api_alloc (sizeof (*rmp));
810  clib_memset (rmp, 0, sizeof (*rmp));
811  rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_DETAILS + sm->msg_id_base);
812  rmp->sw_if_index = ntohl (i->sw_if_index);
814  && nat_interface_is_outside (i)) ? 2 :
816  rmp->context = context;
817 
818  vl_api_send_msg (reg, (u8 *) rmp);
819 }
820 
821 static void
823 {
825  snat_main_t *sm = &snat_main;
827 
829  if (!reg)
830  return;
831 
832  /* *INDENT-OFF* */
833  pool_foreach (i, sm->interfaces,
834  ({
835  send_nat44_interface_details(i, reg, mp->context);
836  }));
837  /* *INDENT-ON* */
838 }
839 
840 static void *
842  void *handle)
843 {
844  u8 *s;
845 
846  s = format (0, "SCRIPT: nat44_interface_dump ");
847 
848  FINISH;
849 }
850 
851 static void
854 {
855  snat_main_t *sm = &snat_main;
856  vl_api_nat44_interface_add_del_output_feature_reply_t *rmp;
857  u8 is_del = mp->is_add == 0;
858  u32 sw_if_index = ntohl (mp->sw_if_index);
859  int rv = 0;
860 
861  if (sm->deterministic)
862  {
863  rv = VNET_API_ERROR_UNSUPPORTED;
864  goto send_reply;
865  }
866 
868 
869  rv = snat_interface_add_del_output_feature (sw_if_index, mp->is_inside,
870  is_del);
871 
873 send_reply:
874  REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY);
875 }
876 
879 {
880  u8 *s;
881 
882  s = format (0, "SCRIPT: nat44_interface_add_del_output_feature ");
883  s = format (s, "sw_if_index %d %s %s",
884  clib_host_to_net_u32 (mp->sw_if_index),
885  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
886 
887  FINISH;
888 }
889 
890 static void
893  u32 context)
894 {
896  snat_main_t *sm = &snat_main;
897 
898  rmp = vl_msg_api_alloc (sizeof (*rmp));
899  clib_memset (rmp, 0, sizeof (*rmp));
900  rmp->_vl_msg_id =
901  ntohs (VL_API_NAT44_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base);
902  rmp->sw_if_index = ntohl (i->sw_if_index);
903  rmp->context = context;
905 
906  vl_api_send_msg (reg, (u8 *) rmp);
907 }
908 
909 static void
912 {
914  snat_main_t *sm = &snat_main;
916 
917  if (sm->deterministic)
918  return;
919 
921  if (!reg)
922  return;
923 
924  /* *INDENT-OFF* */
926  ({
927  send_nat44_interface_output_feature_details(i, reg, mp->context);
928  }));
929  /* *INDENT-ON* */
930 }
931 
934 {
935  u8 *s;
936 
937  s = format (0, "SCRIPT: nat44_interface_output_feature_dump ");
938 
939  FINISH;
940 }
941 
942 static void
945 {
946  snat_main_t *sm = &snat_main;
947  vl_api_nat44_add_del_static_mapping_reply_t *rmp;
948  ip4_address_t local_addr, external_addr;
949  u16 local_port = 0, external_port = 0;
950  u32 vrf_id, external_sw_if_index;
952  int rv = 0;
953  snat_protocol_t proto;
954  u8 *tag = 0;
955 
956  if (sm->deterministic)
957  {
958  rv = VNET_API_ERROR_UNSUPPORTED;
959  goto send_reply;
960  }
961 
962  memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
963  memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
964  if (mp->addr_only == 0)
965  {
966  local_port = clib_net_to_host_u16 (mp->local_port);
967  external_port = clib_net_to_host_u16 (mp->external_port);
968  }
969  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
970  external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
971  proto = ip_proto_to_snat_proto (mp->protocol);
972  if (mp->twice_nat)
973  twice_nat = TWICE_NAT;
974  else if (mp->self_twice_nat)
975  twice_nat = TWICE_NAT_SELF;
976  mp->tag[sizeof (mp->tag) - 1] = 0;
977  tag = format (0, "%s", mp->tag);
979 
980  rv = snat_add_static_mapping (local_addr, external_addr, local_port,
981  external_port, vrf_id, mp->addr_only,
982  external_sw_if_index, proto, mp->is_add,
983  twice_nat, mp->out2in_only, tag, 0);
984 
985  vec_free (tag);
986 
987 send_reply:
988  REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY);
989 }
990 
993 {
994  u8 *s;
995 
996  s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
997  s = format (s, "protocol %d local_addr %U external_addr %U ",
998  mp->protocol,
1001 
1002  if (mp->addr_only == 0)
1003  s = format (s, "local_port %d external_port %d ",
1004  clib_net_to_host_u16 (mp->local_port),
1005  clib_net_to_host_u16 (mp->external_port));
1006 
1007  s = format (s, "twice_nat %d out2in_only %d ",
1008  mp->twice_nat, mp->out2in_only);
1009 
1010  if (mp->vrf_id != ~0)
1011  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1012 
1013  if (mp->external_sw_if_index != ~0)
1014  s = format (s, "external_sw_if_index %d",
1015  clib_net_to_host_u32 (mp->external_sw_if_index));
1016  FINISH;
1017 }
1018 
1019 static void
1022 {
1024  snat_main_t *sm = &snat_main;
1025 
1026  rmp = vl_msg_api_alloc (sizeof (*rmp));
1027  clib_memset (rmp, 0, sizeof (*rmp));
1028  rmp->_vl_msg_id =
1029  ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1031  clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
1033  rmp->external_sw_if_index = ~0;
1034  rmp->vrf_id = htonl (m->vrf_id);
1035  rmp->context = context;
1036  if (m->twice_nat == TWICE_NAT)
1037  rmp->twice_nat = 1;
1038  else if (m->twice_nat == TWICE_NAT_SELF)
1039  rmp->self_twice_nat = 1;
1041  if (rmp->addr_only == 0)
1042  {
1044  rmp->external_port = htons (m->external_port);
1045  rmp->local_port = htons (m->local_port);
1046  }
1047  if (m->tag)
1048  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1049 
1050  vl_api_send_msg (reg, (u8 *) rmp);
1051 }
1052 
1053 static void
1056  u32 context)
1057 {
1059  snat_main_t *sm = &snat_main;
1060 
1061  rmp = vl_msg_api_alloc (sizeof (*rmp));
1062  clib_memset (rmp, 0, sizeof (*rmp));
1063  rmp->_vl_msg_id =
1064  ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1065  rmp->addr_only = m->addr_only;
1066  clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
1067  rmp->external_sw_if_index = htonl (m->sw_if_index);
1068  rmp->vrf_id = htonl (m->vrf_id);
1069  rmp->context = context;
1070  rmp->twice_nat = m->twice_nat;
1071  if (m->addr_only == 0)
1072  {
1074  rmp->external_port = htons (m->e_port);
1075  rmp->local_port = htons (m->l_port);
1076  }
1077  if (m->tag)
1078  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1079 
1080  vl_api_send_msg (reg, (u8 *) rmp);
1081 }
1082 
1083 static void
1085  * mp)
1086 {
1088  snat_main_t *sm = &snat_main;
1091  int j;
1092 
1093  if (sm->deterministic)
1094  return;
1095 
1097  if (!reg)
1098  return;
1099 
1100  /* *INDENT-OFF* */
1101  pool_foreach (m, sm->static_mappings,
1102  ({
1103  if (!is_identity_static_mapping(m) && !is_lb_static_mapping (m))
1104  send_nat44_static_mapping_details (m, reg, mp->context);
1105  }));
1106  /* *INDENT-ON* */
1107 
1108  for (j = 0; j < vec_len (sm->to_resolve); j++)
1109  {
1110  rp = sm->to_resolve + j;
1111  if (!rp->identity_nat)
1113  }
1114 }
1115 
1116 static void *
1118  mp, void *handle)
1119 {
1120  u8 *s;
1121 
1122  s = format (0, "SCRIPT: nat44_static_mapping_dump ");
1123 
1124  FINISH;
1125 }
1126 
1127 static void
1130 {
1131  snat_main_t *sm = &snat_main;
1132  vl_api_nat44_add_del_identity_mapping_reply_t *rmp;
1134  u16 port = 0;
1135  u32 vrf_id, sw_if_index;
1136  int rv = 0;
1137  snat_protocol_t proto = ~0;
1138  u8 *tag = 0;
1139 
1140  if (sm->deterministic)
1141  {
1142  rv = VNET_API_ERROR_UNSUPPORTED;
1143  goto send_reply;
1144  }
1145 
1146  if (mp->addr_only == 0)
1147  {
1148  port = clib_net_to_host_u16 (mp->port);
1149  proto = ip_proto_to_snat_proto (mp->protocol);
1150  }
1151  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1152  sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1153  if (sw_if_index != ~0)
1154  addr.as_u32 = 0;
1155  else
1156  memcpy (&addr.as_u8, mp->ip_address, 4);
1157  mp->tag[sizeof (mp->tag) - 1] = 0;
1158  tag = format (0, "%s", mp->tag);
1159  vec_terminate_c_string (tag);
1160 
1161  rv =
1162  snat_add_static_mapping (addr, addr, port, port, vrf_id, mp->addr_only,
1163  sw_if_index, proto, mp->is_add, 0, 0, tag, 1);
1164 
1165  vec_free (tag);
1166 
1167 send_reply:
1168  REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY);
1169 }
1170 
1173 {
1174  u8 *s;
1175 
1176  s = format (0, "SCRIPT: nat44_add_del_identity_mapping ");
1177  if (mp->sw_if_index != ~0)
1178  s = format (s, "sw_if_index %d", clib_net_to_host_u32 (mp->sw_if_index));
1179  else
1180  s = format (s, "addr %U", format_ip4_address, mp->ip_address);
1181 
1182  if (mp->addr_only == 0)
1183  s =
1184  format (s, " protocol %d port %d", mp->protocol,
1185  clib_net_to_host_u16 (mp->port));
1186 
1187  if (mp->vrf_id != ~0)
1188  s = format (s, " vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1189 
1190  FINISH;
1191 }
1192 
1193 static void
1196 {
1198  snat_main_t *sm = &snat_main;
1199  nat44_lb_addr_port_t *local = pool_elt_at_index (m->locals, index);
1200 
1201  rmp = vl_msg_api_alloc (sizeof (*rmp));
1202  clib_memset (rmp, 0, sizeof (*rmp));
1203  rmp->_vl_msg_id =
1204  ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
1206  clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
1207  rmp->port = htons (m->local_port);
1208  rmp->sw_if_index = ~0;
1209  rmp->vrf_id = htonl (local->vrf_id);
1211  rmp->context = context;
1212  if (m->tag)
1213  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1214 
1215  vl_api_send_msg (reg, (u8 *) rmp);
1216 }
1217 
1218 static void
1221  u32 context)
1222 {
1224  snat_main_t *sm = &snat_main;
1225 
1226  rmp = vl_msg_api_alloc (sizeof (*rmp));
1227  clib_memset (rmp, 0, sizeof (*rmp));
1228  rmp->_vl_msg_id =
1229  ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
1230  rmp->addr_only = m->addr_only;
1231  rmp->port = htons (m->l_port);
1232  rmp->sw_if_index = htonl (m->sw_if_index);
1233  rmp->vrf_id = htonl (m->vrf_id);
1235  rmp->context = context;
1236  if (m->tag)
1237  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1238 
1239  vl_api_send_msg (reg, (u8 *) rmp);
1240 }
1241 
1242 static void
1245 {
1247  snat_main_t *sm = &snat_main;
1250  int j;
1251 
1252  if (sm->deterministic)
1253  return;
1254 
1256  if (!reg)
1257  return;
1258 
1259  /* *INDENT-OFF* */
1260  pool_foreach (m, sm->static_mappings,
1261  ({
1262  if (is_identity_static_mapping(m) && !is_lb_static_mapping (m))
1263  {
1264  pool_foreach_index (j, m->locals,
1265  ({
1266  send_nat44_identity_mapping_details (m, j, reg, mp->context);
1267  }));
1268  }
1269  }));
1270  /* *INDENT-ON* */
1271 
1272  for (j = 0; j < vec_len (sm->to_resolve); j++)
1273  {
1274  rp = sm->to_resolve + j;
1275  if (rp->identity_nat)
1277  }
1278 }
1279 
1282 {
1283  u8 *s;
1284 
1285  s = format (0, "SCRIPT: nat44_identity_mapping_dump ");
1286 
1287  FINISH;
1288 }
1289 
1290 static void
1293 {
1294  snat_main_t *sm = &snat_main;
1295  vl_api_nat44_add_del_interface_addr_reply_t *rmp;
1296  u8 is_del = mp->is_add == 0;
1297  u32 sw_if_index = ntohl (mp->sw_if_index);
1298  int rv = 0;
1299 
1300  if (sm->deterministic)
1301  {
1302  rv = VNET_API_ERROR_UNSUPPORTED;
1303  goto send_reply;
1304  }
1305 
1306  VALIDATE_SW_IF_INDEX (mp);
1307 
1308  rv = snat_add_interface_address (sm, sw_if_index, is_del, mp->twice_nat);
1309 
1311 send_reply:
1312  REPLY_MACRO (VL_API_NAT44_ADD_DEL_INTERFACE_ADDR_REPLY);
1313 }
1314 
1317 {
1318  u8 *s;
1319 
1320  s = format (0, "SCRIPT: nat44_add_del_interface_addr ");
1321  s = format (s, "sw_if_index %d twice_nat %d %s",
1322  clib_host_to_net_u32 (mp->sw_if_index),
1323  mp->twice_nat, mp->is_add ? "" : "del");
1324 
1325  FINISH;
1326 }
1327 
1328 static void
1331  u8 twice_nat)
1332 {
1334  snat_main_t *sm = &snat_main;
1335 
1336  rmp = vl_msg_api_alloc (sizeof (*rmp));
1337  clib_memset (rmp, 0, sizeof (*rmp));
1338  rmp->_vl_msg_id =
1339  ntohs (VL_API_NAT44_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
1340  rmp->sw_if_index = ntohl (sw_if_index);
1341  rmp->twice_nat = twice_nat;
1342  rmp->context = context;
1343 
1344  vl_api_send_msg (reg, (u8 *) rmp);
1345 }
1346 
1347 static void
1349  * mp)
1350 {
1352  snat_main_t *sm = &snat_main;
1353  u32 *i;
1354 
1355  if (sm->deterministic)
1356  return;
1357 
1359  if (!reg)
1360  return;
1361 
1362  /* *INDENT-OFF* */
1364  send_nat44_interface_addr_details(*i, reg, mp->context, 0);
1366  send_nat44_interface_addr_details(*i, reg, mp->context, 1);
1367  /* *INDENT-ON* */
1368 }
1369 
1370 static void *
1372  mp, void *handle)
1373 {
1374  u8 *s;
1375 
1376  s = format (0, "SCRIPT: nat44_interface_addr_dump ");
1377 
1378  FINISH;
1379 }
1380 
1381 static void
1383  u32 context)
1384 {
1386  snat_main_t *sm = &snat_main;
1387  ip4_main_t *im = &ip4_main;
1388 
1389  rmp = vl_msg_api_alloc (sizeof (*rmp));
1390  clib_memset (rmp, 0, sizeof (*rmp));
1391  rmp->_vl_msg_id = ntohs (VL_API_NAT44_USER_DETAILS + sm->msg_id_base);
1392 
1393  if (!pool_is_free_index (im->fibs, u->fib_index))
1394  {
1396  rmp->vrf_id = ntohl (fib->ft_table_id);
1397  }
1398 
1399  clib_memcpy (rmp->ip_address, &(u->addr), 4);
1400  rmp->nsessions = ntohl (u->nsessions);
1401  rmp->nstaticsessions = ntohl (u->nstaticsessions);
1402  rmp->context = context;
1403 
1404  vl_api_send_msg (reg, (u8 *) rmp);
1405 }
1406 
1407 static void
1409 {
1411  snat_main_t *sm = &snat_main;
1413  snat_user_t *u;
1414 
1415  if (sm->deterministic)
1416  return;
1417 
1419  if (!reg)
1420  return;
1421 
1422  /* *INDENT-OFF* */
1423  vec_foreach (tsm, sm->per_thread_data)
1424  {
1425  pool_foreach (u, tsm->users,
1426  ({
1427  send_nat44_user_details (u, reg, mp->context);
1428  }));
1429  }
1430  /* *INDENT-ON* */
1431 }
1432 
1433 static void *
1435 {
1436  u8 *s;
1437 
1438  s = format (0, "SCRIPT: nat44_user_dump ");
1439 
1440  FINISH;
1441 }
1442 
1443 static void
1446 {
1448  snat_main_t *sm = &snat_main;
1449 
1450  rmp = vl_msg_api_alloc (sizeof (*rmp));
1451  clib_memset (rmp, 0, sizeof (*rmp));
1452  rmp->_vl_msg_id =
1453  ntohs (VL_API_NAT44_USER_SESSION_DETAILS + sm->msg_id_base);
1454  clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
1455  clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
1456  rmp->is_static = snat_is_session_static (s) ? 1 : 0;
1457  rmp->is_twicenat = is_twice_nat_session (s) ? 1 : 0;
1458  rmp->ext_host_valid = is_ed_session (s)
1459  || is_fwd_bypass_session (s) ? 1 : 0;
1460  rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
1461  rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
1462  rmp->total_pkts = ntohl (s->total_pkts);
1463  rmp->context = context;
1464  if (snat_is_unk_proto_session (s))
1465  {
1466  rmp->outside_port = 0;
1467  rmp->inside_port = 0;
1468  rmp->protocol = ntohs (s->in2out.port);
1469  }
1470  else
1471  {
1472  rmp->outside_port = s->out2in.port;
1473  rmp->inside_port = s->in2out.port;
1474  rmp->protocol = ntohs (snat_proto_to_ip_proto (s->in2out.protocol));
1475  }
1476  if (is_ed_session (s) || is_fwd_bypass_session (s))
1477  {
1478  clib_memcpy (rmp->ext_host_address, &s->ext_host_addr, 4);
1479  rmp->ext_host_port = s->ext_host_port;
1480  if (is_twice_nat_session (s))
1481  {
1482  clib_memcpy (rmp->ext_host_nat_address, &s->ext_host_nat_addr, 4);
1483  rmp->ext_host_nat_port = s->ext_host_nat_port;
1484  }
1485  }
1486 
1487  vl_api_send_msg (reg, (u8 *) rmp);
1488 }
1489 
1490 static void
1492  mp)
1493 {
1495  snat_main_t *sm = &snat_main;
1497  snat_session_t *s;
1498  clib_bihash_kv_8_8_t key, value;
1499  snat_user_key_t ukey;
1500  snat_user_t *u;
1501  u32 session_index, head_index, elt_index;
1502  dlist_elt_t *head, *elt;
1503  ip4_header_t ip;
1504 
1505  if (sm->deterministic)
1506  return;
1507 
1509  if (!reg)
1510  return;
1511 
1512  clib_memcpy (&ukey.addr, mp->ip_address, 4);
1513  ip.src_address.as_u32 = ukey.addr.as_u32;
1514  ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
1515  key.key = ukey.as_u64;
1516  if (sm->num_workers > 1)
1517  tsm =
1519  sm->worker_in2out_cb (&ip, ukey.fib_index));
1520  else
1521  tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
1522  if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
1523  return;
1524  u = pool_elt_at_index (tsm->users, value.value);
1525  if (!u->nsessions && !u->nstaticsessions)
1526  return;
1527 
1528  head_index = u->sessions_per_user_list_head_index;
1529  head = pool_elt_at_index (tsm->list_pool, head_index);
1530  elt_index = head->next;
1531  elt = pool_elt_at_index (tsm->list_pool, elt_index);
1532  session_index = elt->value;
1533  while (session_index != ~0)
1534  {
1535  s = pool_elt_at_index (tsm->sessions, session_index);
1536 
1538 
1539  elt_index = elt->next;
1540  elt = pool_elt_at_index (tsm->list_pool, elt_index);
1541  session_index = elt->value;
1542  }
1543 }
1544 
1545 static void *
1547  void *handle)
1548 {
1549  u8 *s;
1550 
1551  s = format (0, "SCRIPT: nat44_user_session_dump ");
1552  s = format (s, "ip_address %U vrf_id %d\n",
1554  clib_net_to_host_u32 (mp->vrf_id));
1555 
1556  FINISH;
1557 }
1558 
1559 static nat44_lb_addr_port_t *
1561  u32 addr_port_pair_num)
1562 {
1563  u8 i;
1564  nat44_lb_addr_port_t *lb_addr_port_pairs = 0, lb_addr_port;
1566 
1567  for (i = 0; i < addr_port_pair_num; i++)
1568  {
1569  ap = &addr_port_pairs[i];
1570  clib_memset (&lb_addr_port, 0, sizeof (lb_addr_port));
1571  clib_memcpy (&lb_addr_port.addr, ap->addr, 4);
1572  lb_addr_port.port = clib_net_to_host_u16 (ap->port);
1573  lb_addr_port.probability = ap->probability;
1574  lb_addr_port.vrf_id = clib_net_to_host_u32 (ap->vrf_id);
1575  vec_add1 (lb_addr_port_pairs, lb_addr_port);
1576  }
1577 
1578  return lb_addr_port_pairs;
1579 }
1580 
1581 static void
1584 {
1585  snat_main_t *sm = &snat_main;
1586  vl_api_nat44_add_del_lb_static_mapping_reply_t *rmp;
1588  int rv = 0;
1589  nat44_lb_addr_port_t *locals = 0;
1590  ip4_address_t e_addr;
1591  snat_protocol_t proto;
1592  u8 *tag = 0;
1593 
1594  if (!sm->endpoint_dependent)
1595  {
1596  rv = VNET_API_ERROR_UNSUPPORTED;
1597  goto send_reply;
1598  }
1599 
1600  locals =
1602  clib_net_to_host_u32 (mp->local_num));
1603  clib_memcpy (&e_addr, mp->external_addr, 4);
1604  proto = ip_proto_to_snat_proto (mp->protocol);
1605  if (mp->twice_nat)
1606  twice_nat = TWICE_NAT;
1607  else if (mp->self_twice_nat)
1608  twice_nat = TWICE_NAT_SELF;
1609  mp->tag[sizeof (mp->tag) - 1] = 0;
1610  tag = format (0, "%s", mp->tag);
1611  vec_terminate_c_string (tag);
1612 
1613  rv =
1615  clib_net_to_host_u16 (mp->external_port),
1616  proto, locals, mp->is_add, twice_nat,
1617  mp->out2in_only, tag,
1618  clib_net_to_host_u32 (mp->affinity));
1619 
1620  vec_free (locals);
1621  vec_free (tag);
1622 
1623 send_reply:
1624  REPLY_MACRO (VL_API_NAT44_ADD_DEL_LB_STATIC_MAPPING_REPLY);
1625 }
1626 
1629 {
1630  u8 *s;
1631 
1632  s = format (0, "SCRIPT: nat44_add_del_lb_static_mapping ");
1633  s = format (s, "is_add %d twice_nat %d out2in_only %d ",
1634  mp->is_add, mp->twice_nat, mp->out2in_only);
1635 
1636  FINISH;
1637 }
1638 
1639 static void
1642 {
1643  snat_main_t *sm = &snat_main;
1644  vl_api_nat44_lb_static_mapping_add_del_local_reply_t *rmp;
1645  int rv = 0;
1646  ip4_address_t e_addr, l_addr;
1647  snat_protocol_t proto;
1648 
1649  if (!sm->endpoint_dependent)
1650  {
1651  rv = VNET_API_ERROR_UNSUPPORTED;
1652  goto send_reply;
1653  }
1654 
1655  clib_memcpy (&e_addr, mp->external_addr, 4);
1656  clib_memcpy (&l_addr, mp->local.addr, 4);
1657  proto = ip_proto_to_snat_proto (mp->protocol);
1658 
1659  rv =
1661  clib_net_to_host_u16
1662  (mp->external_port), l_addr,
1663  clib_net_to_host_u16 (mp->
1664  local.port),
1665  proto,
1666  clib_net_to_host_u32 (mp->
1667  local.vrf_id),
1668  mp->local.probability, mp->is_add);
1669 
1670 send_reply:
1671  REPLY_MACRO (VL_API_NAT44_LB_STATIC_MAPPING_ADD_DEL_LOCAL_REPLY);
1672 }
1673 
1676 {
1677  u8 *s;
1678 
1679  s = format (0, "SCRIPT: nat44_lb_static_mapping_add_del_local ");
1680  s = format (s, "is_add %d", mp->is_add);
1681 
1682  FINISH;
1683 }
1684 
1685 static void
1688  u32 context)
1689 {
1691  snat_main_t *sm = &snat_main;
1694  u32 local_num = 0;
1695 
1696  rmp =
1697  vl_msg_api_alloc (sizeof (*rmp) +
1698  (pool_elts (m->locals) *
1699  sizeof (nat44_lb_addr_port_t)));
1700  clib_memset (rmp, 0, sizeof (*rmp));
1701  rmp->_vl_msg_id =
1702  ntohs (VL_API_NAT44_LB_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1703 
1704  clib_memcpy (rmp->external_addr, &(m->external_addr), 4);
1705  rmp->external_port = ntohs (m->external_port);
1707  rmp->context = context;
1708  if (m->twice_nat == TWICE_NAT)
1709  rmp->twice_nat = 1;
1710  else if (m->twice_nat == TWICE_NAT_SELF)
1711  rmp->self_twice_nat = 1;
1713  if (m->tag)
1714  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1715 
1716  locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
1717  /* *INDENT-OFF* */
1718  pool_foreach (ap, m->locals,
1719  ({
1720  clib_memcpy (locals->addr, &(ap->addr), 4);
1721  locals->port = htons (ap->port);
1722  locals->probability = ap->probability;
1723  locals->vrf_id = ntohl (ap->vrf_id);
1724  locals++;
1725  local_num++;
1726  }));
1727  /* *INDENT-ON* */
1728  rmp->local_num = ntohl (local_num);
1729 
1730  vl_api_send_msg (reg, (u8 *) rmp);
1731 }
1732 
1733 static void
1736 {
1738  snat_main_t *sm = &snat_main;
1740 
1741  if (!sm->endpoint_dependent)
1742  return;
1743 
1745  if (!reg)
1746  return;
1747 
1748  /* *INDENT-OFF* */
1749  pool_foreach (m, sm->static_mappings,
1750  ({
1751  if (is_lb_static_mapping(m))
1752  send_nat44_lb_static_mapping_details (m, reg, mp->context);
1753  }));
1754  /* *INDENT-ON* */
1755 }
1756 
1759 {
1760  u8 *s;
1761 
1762  s = format (0, "SCRIPT: nat44_lb_static_mapping_dump ");
1763 
1764  FINISH;
1765 }
1766 
1767 static void
1769 {
1770  snat_main_t *sm = &snat_main;
1771  vl_api_nat44_del_session_reply_t *rmp;
1772  ip4_address_t addr, eh_addr;
1773  u16 port, eh_port;
1774  u32 vrf_id;
1775  int rv = 0;
1776  snat_protocol_t proto;
1777 
1778  if (sm->deterministic)
1779  {
1780  rv = VNET_API_ERROR_UNSUPPORTED;
1781  goto send_reply;
1782  }
1783 
1784  memcpy (&addr.as_u8, mp->address, 4);
1785  port = clib_net_to_host_u16 (mp->port);
1786  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1787  proto = ip_proto_to_snat_proto (mp->protocol);
1788  memcpy (&eh_addr.as_u8, mp->ext_host_address, 4);
1789  eh_port = clib_net_to_host_u16 (mp->ext_host_port);
1790 
1791  if (mp->ext_host_valid)
1792  rv =
1793  nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port, mp->protocol,
1794  vrf_id, mp->is_in);
1795  else
1796  rv = nat44_del_session (sm, &addr, port, proto, vrf_id, mp->is_in);
1797 
1798 send_reply:
1799  REPLY_MACRO (VL_API_NAT44_DEL_SESSION_REPLY);
1800 }
1801 
1802 static void *
1804  void *handle)
1805 {
1806  u8 *s;
1807 
1808  s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
1809  s = format (s, "addr %U port %d protocol %d vrf_id %d is_in %d",
1811  clib_net_to_host_u16 (mp->port),
1812  mp->protocol, clib_net_to_host_u32 (mp->vrf_id), mp->is_in);
1813  if (mp->ext_host_valid)
1814  s = format (s, "ext_host_address %U ext_host_port %d",
1816  clib_net_to_host_u16 (mp->ext_host_port));
1817 
1818  FINISH;
1819 }
1820 
1821 static void
1824 {
1825  snat_main_t *sm = &snat_main;
1826  vl_api_nat44_forwarding_enable_disable_reply_t *rmp;
1827  int rv = 0;
1828  u32 *ses_to_be_removed = 0, *ses_index;
1830  snat_session_t *s;
1831 
1832  sm->forwarding_enabled = mp->enable != 0;
1833 
1834  if (mp->enable == 0)
1835  {
1836  /* *INDENT-OFF* */
1837  vec_foreach (tsm, sm->per_thread_data)
1838  {
1839  pool_foreach (s, tsm->sessions,
1840  ({
1841  if (is_fwd_bypass_session(s))
1842  {
1843  vec_add1 (ses_to_be_removed, s - tsm->sessions);
1844  }
1845  }));
1846  vec_foreach (ses_index, ses_to_be_removed)
1847  {
1848  s = pool_elt_at_index(tsm->sessions, ses_index[0]);
1849  nat_free_session_data (sm, s, tsm - sm->per_thread_data);
1850  nat44_delete_session (sm, s, tsm - sm->per_thread_data);
1851  }
1852  vec_free (ses_to_be_removed);
1853  }
1854  /* *INDENT-ON* */
1855  }
1856 
1857  REPLY_MACRO (VL_API_NAT44_FORWARDING_ENABLE_DISABLE_REPLY);
1858 }
1859 
1862 {
1863  u8 *s;
1864 
1865  s = format (0, "SCRIPT: nat44_forwarding_enable_disable ");
1866  s = format (s, "enable %d", mp->enable != 0);
1867 
1868  FINISH;
1869 }
1870 
1871 static void
1874 {
1876  snat_main_t *sm = &snat_main;
1878 
1880  if (!reg)
1881  return;
1882 
1883  rmp = vl_msg_api_alloc (sizeof (*rmp));
1884  clib_memset (rmp, 0, sizeof (*rmp));
1885  rmp->_vl_msg_id =
1886  ntohs (VL_API_NAT44_FORWARDING_IS_ENABLED_REPLY + sm->msg_id_base);
1887  rmp->context = mp->context;
1888 
1889  rmp->enabled = sm->forwarding_enabled;
1890 
1891  vl_api_send_msg (reg, (u8 *) rmp);
1892 }
1893 
1896 {
1897  u8 *s;
1898 
1899  s = format (0, "SCRIPT: nat44_forwarding_is_enabled ");
1900 
1901  FINISH;
1902 }
1903 
1904 /*******************************/
1905 /*** Deterministic NAT (CGN) ***/
1906 /*******************************/
1907 
1908 static void
1910 {
1911  snat_main_t *sm = &snat_main;
1912  vl_api_nat_det_add_del_map_reply_t *rmp;
1913  int rv = 0;
1914  ip4_address_t in_addr, out_addr;
1915 
1916  if (!sm->deterministic)
1917  {
1918  rv = VNET_API_ERROR_UNSUPPORTED;
1919  goto send_reply;
1920  }
1921 
1922  if (!mp->is_nat44)
1923  {
1924  rv = VNET_API_ERROR_UNIMPLEMENTED;
1925  goto send_reply;
1926  }
1927 
1928  clib_memcpy (&in_addr, mp->in_addr, 4);
1929  clib_memcpy (&out_addr, mp->out_addr, 4);
1930  rv = snat_det_add_map (sm, &in_addr, mp->in_plen, &out_addr,
1931  mp->out_plen, mp->is_add);
1932 
1933 send_reply:
1934  REPLY_MACRO (VL_API_NAT_DET_ADD_DEL_MAP_REPLY);
1935 }
1936 
1937 static void *
1939  void *handle)
1940 {
1941  u8 *s;
1942 
1943  s = format (0, "SCRIPT: nat_det_add_del_map ");
1944  s = format (s, "inside address %U/%d outside address %U/%d\n",
1947 
1948  FINISH;
1949 }
1950 
1951 static void
1953 {
1954  snat_main_t *sm = &snat_main;
1956  int rv = 0;
1957  u16 lo_port = 0, hi_port = 0;
1958  snat_det_map_t *dm;
1959  ip4_address_t in_addr, out_addr;
1960 
1961  if (!sm->deterministic)
1962  {
1963  rv = VNET_API_ERROR_UNSUPPORTED;
1964  REPLY_MACRO (VL_API_NAT_DET_FORWARD_REPLY);
1965  return;
1966  }
1967 
1968  if (!mp->is_nat44)
1969  {
1970  out_addr.as_u32 = 0;
1971  rv = VNET_API_ERROR_UNIMPLEMENTED;
1972  goto send_reply;
1973  }
1974 
1975  out_addr.as_u32 = 0;
1976  clib_memcpy (&in_addr, mp->in_addr, 4);
1977  dm = snat_det_map_by_user (sm, &in_addr);
1978  if (!dm)
1979  {
1980  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1981  goto send_reply;
1982  }
1983 
1984  snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1985  hi_port = lo_port + dm->ports_per_host - 1;
1986 
1987 send_reply:
1988  /* *INDENT-OFF* */
1989  REPLY_MACRO2 (VL_API_NAT_DET_FORWARD_REPLY,
1990  ({
1991  rmp->out_port_lo = ntohs (lo_port);
1992  rmp->out_port_hi = ntohs (hi_port);
1993  clib_memcpy (rmp->out_addr, &out_addr, 4);
1994  }))
1995  /* *INDENT-ON* */
1996 }
1997 
1998 static void *
2000 {
2001  u8 *s;
2002 
2003  s = format (0, "SCRIPT: nat_det_forward");
2004  s = format (s, "inside ip address %U\n", format_ip4_address, mp->in_addr);
2005 
2006  FINISH;
2007 }
2008 
2009 static void
2011 {
2012  snat_main_t *sm = &snat_main;
2014  int rv = 0;
2015  ip4_address_t out_addr, in_addr;
2016  snat_det_map_t *dm;
2017 
2018  if (!sm->deterministic)
2019  {
2020  rv = VNET_API_ERROR_UNSUPPORTED;
2021  REPLY_MACRO (VL_API_NAT_DET_REVERSE_REPLY);
2022  return;
2023  }
2024 
2025  in_addr.as_u32 = 0;
2026  clib_memcpy (&out_addr, mp->out_addr, 4);
2027  dm = snat_det_map_by_out (sm, &out_addr);
2028  if (!dm)
2029  {
2030  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2031  goto send_reply;
2032  }
2033 
2034  snat_det_reverse (dm, &out_addr, htons (mp->out_port), &in_addr);
2035 
2036 send_reply:
2037  /* *INDENT-OFF* */
2038  REPLY_MACRO2 (VL_API_NAT_DET_REVERSE_REPLY,
2039  ({
2040  rmp->is_nat44 = 1;
2041  clib_memset (rmp->in_addr, 0, 16);
2042  clib_memcpy (rmp->in_addr, &in_addr, 4);
2043  }))
2044  /* *INDENT-ON* */
2045 }
2046 
2047 static void *
2049 {
2050  u8 *s;
2051 
2052  s = format (0, "SCRIPT: nat_det_reverse");
2053  s = format (s, "outside ip address %U outside port %d",
2054  format_ip4_address, mp->out_addr, ntohs (mp->out_port));
2055 
2056  FINISH;
2057 }
2058 
2059 static void
2061  u32 context)
2062 {
2064  snat_main_t *sm = &snat_main;
2065 
2066  rmp = vl_msg_api_alloc (sizeof (*rmp));
2067  clib_memset (rmp, 0, sizeof (*rmp));
2068  rmp->_vl_msg_id = ntohs (VL_API_NAT_DET_MAP_DETAILS + sm->msg_id_base);
2069  rmp->is_nat44 = 1;
2070  clib_memcpy (rmp->in_addr, &m->in_addr, 4);
2071  rmp->in_plen = m->in_plen;
2072  clib_memcpy (rmp->out_addr, &m->out_addr, 4);
2073  rmp->out_plen = m->out_plen;
2074  rmp->sharing_ratio = htonl (m->sharing_ratio);
2075  rmp->ports_per_host = htons (m->ports_per_host);
2076  rmp->ses_num = htonl (m->ses_num);
2077  rmp->context = context;
2078 
2079  vl_api_send_msg (reg, (u8 *) rmp);
2080 }
2081 
2082 static void
2084 {
2086  snat_main_t *sm = &snat_main;
2087  snat_det_map_t *m;
2088 
2089  if (!sm->deterministic)
2090  return;
2091 
2093  if (!reg)
2094  return;
2095 
2096  /* *INDENT-OFF* */
2097  vec_foreach(m, sm->det_maps)
2098  sent_nat_det_map_details(m, reg, mp->context);
2099  /* *INDENT-ON* */
2100 }
2101 
2102 static void *
2104 {
2105  u8 *s;
2106 
2107  s = format (0, "SCRIPT: nat_det_map_dump ");
2108 
2109  FINISH;
2110 }
2111 
2112 static void
2114  * mp)
2115 {
2116  snat_main_t *sm = &snat_main;
2117  vl_api_nat_det_close_session_out_reply_t *rmp;
2118  ip4_address_t out_addr, ext_addr, in_addr;
2119  snat_det_out_key_t key;
2120  snat_det_map_t *dm;
2121  snat_det_session_t *ses;
2122  int rv = 0;
2123 
2124  if (!sm->deterministic)
2125  {
2126  rv = VNET_API_ERROR_UNSUPPORTED;
2127  goto send_reply;
2128  }
2129 
2130  clib_memcpy (&out_addr, mp->out_addr, 4);
2131  clib_memcpy (&ext_addr, mp->ext_addr, 4);
2132 
2133  dm = snat_det_map_by_out (sm, &out_addr);
2134  if (!dm)
2135  {
2136  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2137  goto send_reply;
2138  }
2139  snat_det_reverse (dm, &ext_addr, ntohs (mp->out_port), &in_addr);
2140  key.ext_host_addr = ext_addr;
2141  key.ext_host_port = mp->ext_port;
2142  key.out_port = mp->out_port;
2143  ses = snat_det_get_ses_by_out (dm, &in_addr, key.as_u64);
2144  if (!ses)
2145  {
2146  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2147  goto send_reply;
2148  }
2149  snat_det_ses_close (dm, ses);
2150 
2151 send_reply:
2152  REPLY_MACRO (VL_API_NAT_DET_CLOSE_SESSION_OUT_REPLY);
2153 }
2154 
2155 static void *
2157  mp, void *handle)
2158 {
2159  u8 *s;
2160 
2161  s = format (0, "SCRIPT: nat_det_close_session_out ");
2162  s = format (s, "out_addr %U out_port %d "
2163  "ext_addr %U ext_port %d\n",
2164  format_ip4_address, mp->out_addr, ntohs (mp->out_port),
2165  format_ip4_address, mp->ext_addr, ntohs (mp->ext_port));
2166 
2167  FINISH;
2168 }
2169 
2170 static void
2172  mp)
2173 {
2174  snat_main_t *sm = &snat_main;
2175  vl_api_nat_det_close_session_in_reply_t *rmp;
2176  ip4_address_t in_addr, ext_addr;
2177  snat_det_out_key_t key;
2178  snat_det_map_t *dm;
2179  snat_det_session_t *ses;
2180  int rv = 0;
2181 
2182  if (!sm->deterministic)
2183  {
2184  rv = VNET_API_ERROR_UNSUPPORTED;
2185  goto send_reply;
2186  }
2187 
2188  if (!mp->is_nat44)
2189  {
2190  rv = VNET_API_ERROR_UNIMPLEMENTED;
2191  goto send_reply;
2192  }
2193 
2194  clib_memcpy (&in_addr, mp->in_addr, 4);
2195  clib_memcpy (&ext_addr, mp->ext_addr, 4);
2196 
2197  dm = snat_det_map_by_user (sm, &in_addr);
2198  if (!dm)
2199  {
2200  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2201  goto send_reply;
2202  }
2203  key.ext_host_addr = ext_addr;
2204  key.ext_host_port = mp->ext_port;
2205  ses = snat_det_find_ses_by_in (dm, &in_addr, mp->in_port, key);
2206  if (!ses)
2207  {
2208  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2209  goto send_reply;
2210  }
2211  snat_det_ses_close (dm, ses);
2212 
2213 send_reply:
2214  REPLY_MACRO (VL_API_NAT_DET_CLOSE_SESSION_OUT_REPLY);
2215 }
2216 
2217 static void *
2219  mp, void *handle)
2220 {
2221  u8 *s;
2222  s = format (0, "SCRIPT: nat_det_close_session_in ");
2223  s = format (s, "in_addr %U in_port %d ext_addr %U ext_port %d\n",
2224  format_ip4_address, mp->in_addr, ntohs (mp->in_port),
2225  format_ip4_address, mp->ext_addr, ntohs (mp->ext_port));
2226 
2227  FINISH;
2228 }
2229 
2230 static void
2233 {
2235  snat_main_t *sm = &snat_main;
2236 
2237  rmp = vl_msg_api_alloc (sizeof (*rmp));
2238  clib_memset (rmp, 0, sizeof (*rmp));
2239  rmp->_vl_msg_id = ntohs (VL_API_NAT_DET_SESSION_DETAILS + sm->msg_id_base);
2240  rmp->in_port = s->in_port;
2241  clib_memcpy (rmp->ext_addr, &s->out.ext_host_addr, 4);
2242  rmp->ext_port = s->out.ext_host_port;
2243  rmp->out_port = s->out.out_port;
2244  rmp->state = s->state;
2245  rmp->expire = ntohl (s->expire);
2246  rmp->context = context;
2247 
2248  vl_api_send_msg (reg, (u8 *) rmp);
2249 }
2250 
2251 static void
2253 {
2255  snat_main_t *sm = &snat_main;
2256  ip4_address_t user_addr;
2257  snat_det_map_t *dm;
2258  snat_det_session_t *s, empty_ses;
2259  u16 i;
2260 
2261  if (!sm->deterministic)
2262  return;
2263 
2265  if (!reg)
2266  return;
2267  if (!mp->is_nat44)
2268  return;
2269 
2270  clib_memset (&empty_ses, 0, sizeof (empty_ses));
2271  clib_memcpy (&user_addr, mp->user_addr, 4);
2272  dm = snat_det_map_by_user (sm, &user_addr);
2273  if (!dm)
2274  return;
2275 
2276  s = dm->sessions + snat_det_user_ses_offset (&user_addr, dm->in_plen);
2277  for (i = 0; i < SNAT_DET_SES_PER_USER; i++)
2278  {
2279  if (s->out.as_u64)
2280  send_nat_det_session_details (s, reg, mp->context);
2281  s++;
2282  }
2283 }
2284 
2285 static void *
2287  void *handle)
2288 {
2289  u8 *s;
2290 
2291  s = format (0, "SCRIPT: nat_det_session_dump ");
2292  s = format (s, "user_addr %U\n", format_ip4_address, mp->user_addr);
2293 
2294  FINISH;
2295 }
2296 
2297 /*************/
2298 /*** NAT64 ***/
2299 /*************/
2300 
2301 static void
2304 {
2305  vl_api_nat64_add_del_pool_addr_range_reply_t *rmp;
2306  snat_main_t *sm = &snat_main;
2307  int rv = 0;
2308  ip4_address_t this_addr;
2309  u32 start_host_order, end_host_order;
2310  u32 vrf_id;
2311  int i, count;
2312  u32 *tmp;
2313 
2314  tmp = (u32 *) mp->start_addr;
2315  start_host_order = clib_host_to_net_u32 (tmp[0]);
2316  tmp = (u32 *) mp->end_addr;
2317  end_host_order = clib_host_to_net_u32 (tmp[0]);
2318 
2319  count = (end_host_order - start_host_order) + 1;
2320 
2321  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
2322 
2323  memcpy (&this_addr.as_u8, mp->start_addr, 4);
2324 
2325  for (i = 0; i < count; i++)
2326  {
2327  if ((rv = nat64_add_del_pool_addr (&this_addr, vrf_id, mp->is_add)))
2328  goto send_reply;
2329 
2330  increment_v4_address (&this_addr);
2331  }
2332 
2333 send_reply:
2334  REPLY_MACRO (VL_API_NAT64_ADD_DEL_POOL_ADDR_RANGE_REPLY);
2335 }
2336 
2339 {
2340  u8 *s;
2341 
2342  s = format (0, "SCRIPT: nat64_add_del_pool_addr_range ");
2343  s = format (s, "%U - %U vrf_id %u %s\n",
2346  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
2347 
2348  FINISH;
2349 }
2350 
2352 {
2357 
2358 static int
2360 {
2362  snat_main_t *sm = &snat_main;
2363  nat64_api_walk_ctx_t *ctx = arg;
2364 
2365  rmp = vl_msg_api_alloc (sizeof (*rmp));
2366  clib_memset (rmp, 0, sizeof (*rmp));
2367  rmp->_vl_msg_id = ntohs (VL_API_NAT64_POOL_ADDR_DETAILS + sm->msg_id_base);
2368  clib_memcpy (rmp->address, &(a->addr), 4);
2369  if (a->fib_index != ~0)
2370  {
2372  if (!fib)
2373  return -1;
2374  rmp->vrf_id = ntohl (fib->ft_table_id);
2375  }
2376  else
2377  rmp->vrf_id = ~0;
2378  rmp->context = ctx->context;
2379 
2380  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2381 
2382  return 0;
2383 }
2384 
2385 static void
2387 {
2389 
2391  if (!reg)
2392  return;
2393 
2395  .reg = reg,
2396  .context = mp->context,
2397  };
2398 
2400 }
2401 
2402 static void *
2404  void *handle)
2405 {
2406  u8 *s;
2407 
2408  s = format (0, "SCRIPT: nat64_pool_addr_dump\n");
2409 
2410  FINISH;
2411 }
2412 
2413 static void
2415  mp)
2416 {
2417  snat_main_t *sm = &snat_main;
2418  vl_api_nat64_add_del_interface_reply_t *rmp;
2419  int rv = 0;
2420 
2421  VALIDATE_SW_IF_INDEX (mp);
2422 
2423  rv =
2424  nat64_add_del_interface (ntohl (mp->sw_if_index), mp->is_inside,
2425  mp->is_add);
2426 
2428 
2429  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_REPLY);
2430 }
2431 
2432 static void *
2434  void *handle)
2435 {
2436  u8 *s;
2437 
2438  s = format (0, "SCRIPT: nat64_add_del_interface ");
2439  s = format (s, "sw_if_index %d %s %s",
2440  clib_host_to_net_u32 (mp->sw_if_index),
2441  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
2442 
2443  FINISH;
2444 }
2445 
2446 static int
2448 {
2450  snat_main_t *sm = &snat_main;
2451  nat64_api_walk_ctx_t *ctx = arg;
2452 
2453  rmp = vl_msg_api_alloc (sizeof (*rmp));
2454  clib_memset (rmp, 0, sizeof (*rmp));
2455  rmp->_vl_msg_id = ntohs (VL_API_NAT64_INTERFACE_DETAILS + sm->msg_id_base);
2456  rmp->sw_if_index = ntohl (i->sw_if_index);
2458  && nat_interface_is_outside (i)) ? 2 :
2460  rmp->context = ctx->context;
2461 
2462  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2463 
2464  return 0;
2465 }
2466 
2467 static void
2469 {
2471 
2473  if (!reg)
2474  return;
2475 
2477  .reg = reg,
2478  .context = mp->context,
2479  };
2480 
2482 }
2483 
2484 static void *
2486  void *handle)
2487 {
2488  u8 *s;
2489 
2490  s = format (0, "SCRIPT: snat_interface_dump ");
2491 
2492  FINISH;
2493 }
2494 
2495 static void
2498 {
2499  snat_main_t *sm = &snat_main;
2500  vl_api_nat64_add_del_static_bib_reply_t *rmp;
2501  ip6_address_t in_addr;
2502  ip4_address_t out_addr;
2503  int rv = 0;
2504 
2505  memcpy (&in_addr.as_u8, mp->i_addr, 16);
2506  memcpy (&out_addr.as_u8, mp->o_addr, 4);
2507 
2508  rv =
2509  nat64_add_del_static_bib_entry (&in_addr, &out_addr,
2510  clib_net_to_host_u16 (mp->i_port),
2511  clib_net_to_host_u16 (mp->o_port),
2512  mp->proto,
2513  clib_net_to_host_u32 (mp->vrf_id),
2514  mp->is_add);
2515 
2516  REPLY_MACRO (VL_API_NAT64_ADD_DEL_STATIC_BIB_REPLY);
2517 }
2518 
2521 {
2522  u8 *s;
2523 
2524  s = format (0, "SCRIPT: nat64_add_del_static_bib ");
2525  s = format (s, "protocol %d i_addr %U o_addr %U ",
2526  mp->proto,
2528 
2529  if (mp->vrf_id != ~0)
2530  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
2531 
2532  FINISH;
2533 }
2534 
2535 static int
2536 nat64_api_bib_walk (nat64_db_bib_entry_t * bibe, void *arg)
2537 {
2539  snat_main_t *sm = &snat_main;
2540  nat64_api_walk_ctx_t *ctx = arg;
2541  fib_table_t *fib;
2542 
2543  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
2544  if (!fib)
2545  return -1;
2546 
2547  rmp = vl_msg_api_alloc (sizeof (*rmp));
2548  clib_memset (rmp, 0, sizeof (*rmp));
2549  rmp->_vl_msg_id = ntohs (VL_API_NAT64_BIB_DETAILS + sm->msg_id_base);
2550  rmp->context = ctx->context;
2551  clib_memcpy (rmp->i_addr, &(bibe->in_addr), 16);
2552  clib_memcpy (rmp->o_addr, &(bibe->out_addr), 4);
2553  rmp->i_port = bibe->in_port;
2554  rmp->o_port = bibe->out_port;
2555  rmp->vrf_id = ntohl (fib->ft_table_id);
2556  rmp->proto = bibe->proto;
2557  rmp->is_static = bibe->is_static;
2558  rmp->ses_num = ntohl (bibe->ses_num);
2559 
2560  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2561 
2562  return 0;
2563 }
2564 
2565 static void
2567 {
2569  nat64_main_t *nm = &nat64_main;
2570  nat64_db_t *db;
2571 
2573  if (!reg)
2574  return;
2575 
2577  .reg = reg,
2578  .context = mp->context,
2579  };
2580 
2581  /* *INDENT-OFF* */
2582  vec_foreach (db, nm->db)
2583  nat64_db_bib_walk (db, mp->proto, nat64_api_bib_walk, &ctx);
2584  /* *INDENT-ON* */
2585 }
2586 
2587 static void *
2589 {
2590  u8 *s;
2591 
2592  s = format (0, "SCRIPT: snat_bib_dump protocol %d", mp->proto);
2593 
2594  FINISH;
2595 }
2596 
2597 static int
2598 nat64_api_st_walk (nat64_db_st_entry_t * ste, void *arg)
2599 {
2601  snat_main_t *sm = &snat_main;
2602  nat64_api_walk_ctx_t *ctx = arg;
2603  nat64_db_bib_entry_t *bibe;
2604  fib_table_t *fib;
2605 
2606  bibe = nat64_db_bib_entry_by_index (ctx->db, ste->proto, ste->bibe_index);
2607  if (!bibe)
2608  return -1;
2609 
2610  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
2611  if (!fib)
2612  return -1;
2613 
2614  rmp = vl_msg_api_alloc (sizeof (*rmp));
2615  clib_memset (rmp, 0, sizeof (*rmp));
2616  rmp->_vl_msg_id = ntohs (VL_API_NAT64_ST_DETAILS + sm->msg_id_base);
2617  rmp->context = ctx->context;
2618  clib_memcpy (rmp->il_addr, &(bibe->in_addr), 16);
2619  clib_memcpy (rmp->ol_addr, &(bibe->out_addr), 4);
2620  rmp->il_port = bibe->in_port;
2621  rmp->ol_port = bibe->out_port;
2622  clib_memcpy (rmp->ir_addr, &(ste->in_r_addr), 16);
2623  clib_memcpy (rmp->or_addr, &(ste->out_r_addr), 4);
2624  rmp->il_port = ste->r_port;
2625  rmp->vrf_id = ntohl (fib->ft_table_id);
2626  rmp->proto = ste->proto;
2627 
2628  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2629 
2630  return 0;
2631 }
2632 
2633 static void
2635 {
2637  nat64_main_t *nm = &nat64_main;
2638  nat64_db_t *db;
2639 
2641  if (!reg)
2642  return;
2643 
2645  .reg = reg,
2646  .context = mp->context,
2647  };
2648 
2649  /* *INDENT-OFF* */
2650  vec_foreach (db, nm->db)
2651  {
2652  ctx.db = db;
2653  nat64_db_st_walk (db, mp->proto, nat64_api_st_walk, &ctx);
2654  }
2655  /* *INDENT-ON* */
2656 }
2657 
2658 static void *
2660 {
2661  u8 *s;
2662 
2663  s = format (0, "SCRIPT: snat_st_dump protocol %d", mp->proto);
2664 
2665  FINISH;
2666 }
2667 
2668 static void
2670 {
2671  vl_api_nat64_add_del_prefix_reply_t *rmp;
2672  snat_main_t *sm = &snat_main;
2674  int rv = 0;
2675 
2676  memcpy (&prefix.as_u8, mp->prefix, 16);
2677 
2678  rv =
2679  nat64_add_del_prefix (&prefix, mp->prefix_len,
2680  clib_net_to_host_u32 (mp->vrf_id), mp->is_add);
2681  REPLY_MACRO (VL_API_NAT64_ADD_DEL_PREFIX_REPLY);
2682 }
2683 
2684 static void *
2686  void *handle)
2687 {
2688  u8 *s;
2689 
2690  s = format (0, "SCRIPT: nat64_add_del_prefix %U/%u vrf_id %u %s\n",
2692  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
2693 
2694  FINISH;
2695 }
2696 
2697 static int
2699 {
2701  snat_main_t *sm = &snat_main;
2702  nat64_api_walk_ctx_t *ctx = arg;
2703 
2704  rmp = vl_msg_api_alloc (sizeof (*rmp));
2705  clib_memset (rmp, 0, sizeof (*rmp));
2706  rmp->_vl_msg_id = ntohs (VL_API_NAT64_PREFIX_DETAILS + sm->msg_id_base);
2707  clib_memcpy (rmp->prefix, &(p->prefix), 16);
2708  rmp->prefix_len = p->plen;
2709  rmp->vrf_id = ntohl (p->vrf_id);
2710  rmp->context = ctx->context;
2711 
2712  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2713 
2714  return 0;
2715 }
2716 
2717 static void
2719 {
2721 
2723  if (!reg)
2724  return;
2725 
2727  .reg = reg,
2728  .context = mp->context,
2729  };
2730 
2732 }
2733 
2734 static void *
2736  void *handle)
2737 {
2738  u8 *s;
2739 
2740  s = format (0, "SCRIPT: nat64_prefix_dump\n");
2741 
2742  FINISH;
2743 }
2744 
2745 static void
2748 {
2749  snat_main_t *sm = &snat_main;
2750  vl_api_nat64_add_del_interface_addr_reply_t *rmp;
2751  u32 sw_if_index = ntohl (mp->sw_if_index);
2752  int rv = 0;
2753 
2754  VALIDATE_SW_IF_INDEX (mp);
2755 
2756  rv = nat64_add_interface_address (sw_if_index, mp->is_add);
2757 
2759 
2760  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_ADDR_REPLY);
2761 }
2762 
2765 {
2766  u8 *s;
2767 
2768  s = format (0, "SCRIPT: nat64_add_del_interface_addr ");
2769  s = format (s, "sw_if_index %d %s",
2770  clib_host_to_net_u32 (mp->sw_if_index),
2771  mp->is_add ? "" : "del");
2772 
2773  FINISH;
2774 }
2775 
2776 /***************/
2777 /*** DS-Lite ***/
2778 /***************/
2779 
2780 static void
2782 {
2783  vl_api_dslite_set_aftr_addr_reply_t *rmp;
2784  snat_main_t *sm = &snat_main;
2785  dslite_main_t *dm = &dslite_main;
2786  int rv = 0;
2787  ip6_address_t ip6_addr;
2788  ip4_address_t ip4_addr;
2789 
2790  memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
2791  memcpy (&ip4_addr.as_u8, mp->ip4_addr, 4);
2792 
2793  rv = dslite_set_aftr_ip6_addr (dm, &ip6_addr);
2794  if (rv == 0)
2795  rv = dslite_set_aftr_ip4_addr (dm, &ip4_addr);
2796 
2797  REPLY_MACRO (VL_API_DSLITE_SET_AFTR_ADDR_REPLY);
2798 }
2799 
2800 static void *
2802  void *handle)
2803 {
2804  u8 *s;
2805 
2806  s = format (0, "SCRIPT: dslite_set_aftr_addr ");
2807  s = format (s, "ip6_addr %U ip4_addr %U\n",
2810 
2811  FINISH;
2812 }
2813 
2814 static void
2816 {
2817  snat_main_t *sm = &snat_main;
2819  dslite_main_t *dm = &dslite_main;
2820  int rv = 0;
2821 
2822  /* *INDENT-OFF* */
2823  REPLY_MACRO2 (VL_API_DSLITE_GET_AFTR_ADDR_REPLY,
2824  ({
2825  memcpy (rmp->ip4_addr, &dm->aftr_ip4_addr.as_u8, 4);
2826  memcpy (rmp->ip6_addr, &dm->aftr_ip6_addr.as_u8, 16);
2827  }))
2828  /* *INDENT-ON* */
2829 }
2830 
2831 static void *
2833  void *handle)
2834 {
2835  u8 *s;
2836 
2837  s = format (0, "SCRIPT: dslite_get_aftr_addr");
2838 
2839  FINISH;
2840 }
2841 
2842 static void
2844 {
2845  vl_api_dslite_set_b4_addr_reply_t *rmp;
2846  snat_main_t *sm = &snat_main;
2847  dslite_main_t *dm = &dslite_main;
2848  int rv = 0;
2849  ip6_address_t ip6_addr;
2850  ip4_address_t ip4_addr;
2851 
2852  memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
2853  memcpy (&ip4_addr.as_u8, mp->ip4_addr, 4);
2854 
2855  rv = dslite_set_b4_ip6_addr (dm, &ip6_addr);
2856  if (rv == 0)
2857  rv = dslite_set_b4_ip4_addr (dm, &ip4_addr);
2858 
2859  REPLY_MACRO (VL_API_DSLITE_SET_B4_ADDR_REPLY);
2860 }
2861 
2862 static void *
2864  void *handle)
2865 {
2866  u8 *s;
2867 
2868  s = format (0, "SCRIPT: dslite_set_b4_addr ");
2869  s = format (s, "ip6_addr %U ip4_addr %U\n",
2872 
2873  FINISH;
2874 }
2875 
2876 static void
2878 {
2879  snat_main_t *sm = &snat_main;
2881  dslite_main_t *dm = &dslite_main;
2882  int rv = 0;
2883 
2884  /* *INDENT-OFF* */
2885  REPLY_MACRO2 (VL_API_DSLITE_GET_AFTR_ADDR_REPLY,
2886  ({
2887  memcpy (rmp->ip4_addr, &dm->b4_ip4_addr.as_u8, 4);
2888  memcpy (rmp->ip6_addr, &dm->b4_ip6_addr.as_u8, 16);
2889  }))
2890  /* *INDENT-ON* */
2891 }
2892 
2893 static void *
2895  void *handle)
2896 {
2897  u8 *s;
2898 
2899  s = format (0, "SCRIPT: dslite_get_b4_addr");
2900 
2901  FINISH;
2902 }
2903 
2904 static void
2907 {
2908  vl_api_dslite_add_del_pool_addr_range_reply_t *rmp;
2909  snat_main_t *sm = &snat_main;
2910  dslite_main_t *dm = &dslite_main;
2911  int rv = 0;
2912  ip4_address_t this_addr;
2913  u32 start_host_order, end_host_order;
2914  int i, count;
2915  u32 *tmp;
2916 
2917  tmp = (u32 *) mp->start_addr;
2918  start_host_order = clib_host_to_net_u32 (tmp[0]);
2919  tmp = (u32 *) mp->end_addr;
2920  end_host_order = clib_host_to_net_u32 (tmp[0]);
2921 
2922  count = (end_host_order - start_host_order) + 1;
2923  memcpy (&this_addr.as_u8, mp->start_addr, 4);
2924 
2925  for (i = 0; i < count; i++)
2926  {
2927  if ((rv = dslite_add_del_pool_addr (dm, &this_addr, mp->is_add)))
2928  goto send_reply;
2929 
2930  increment_v4_address (&this_addr);
2931  }
2932 
2933 send_reply:
2934  REPLY_MACRO (VL_API_DSLITE_ADD_DEL_POOL_ADDR_RANGE_REPLY);
2935 }
2936 
2937 static void
2940 {
2942  snat_main_t *sm = &snat_main;
2943 
2944  rmp = vl_msg_api_alloc (sizeof (*rmp));
2945 
2946  clib_memset (rmp, 0, sizeof (*rmp));
2947 
2948  rmp->_vl_msg_id = ntohs (VL_API_DSLITE_ADDRESS_DETAILS + sm->msg_id_base);
2949  clib_memcpy (rmp->ip_address, &(ap->addr), 4);
2950  rmp->context = context;
2951 
2952  vl_api_send_msg (reg, (u8 *) rmp);
2953 }
2954 
2955 static void
2957 {
2959  dslite_main_t *dm = &dslite_main;
2960  snat_address_t *ap;
2961 
2963  if (!reg)
2964  return;
2965 
2966  /* *INDENT-OFF* */
2967  vec_foreach (ap, dm->addr_pool)
2968  {
2969  send_dslite_address_details (ap, reg, mp->context);
2970  }
2971  /* *INDENT-ON* */
2972 }
2973 
2974 static void *
2976  void *handle)
2977 {
2978  u8 *s;
2979 
2980  s = format (0, "SCRIPT: dslite_address_dump ");
2981 
2982  FINISH;
2983 }
2984 
2987 {
2988  u8 *s;
2989 
2990  s = format (0, "SCRIPT: dslite_add_del_pool_addr_range ");
2991  s = format (s, "%U - %U\n",
2994 
2995  FINISH;
2996 }
2997 
2998 
2999 /*************/
3000 /*** NAT66 ***/
3001 /*************/
3002 
3003 static void
3005  mp)
3006 {
3007  snat_main_t *sm = &snat_main;
3008  vl_api_nat66_add_del_interface_reply_t *rmp;
3009  int rv = 0;
3010 
3011  VALIDATE_SW_IF_INDEX (mp);
3012 
3013  rv =
3014  nat66_interface_add_del (ntohl (mp->sw_if_index), mp->is_inside,
3015  mp->is_add);
3016 
3018 
3019  REPLY_MACRO (VL_API_NAT66_ADD_DEL_INTERFACE_REPLY);
3020 }
3021 
3022 static void *
3024  void *handle)
3025 {
3026  u8 *s;
3027 
3028  s = format (0, "SCRIPT: nat66_add_del_interface ");
3029  s = format (s, "sw_if_index %d %s %s",
3030  clib_host_to_net_u32 (mp->sw_if_index),
3031  mp->is_inside ? "in" : "out", mp->is_add ? "" : "del");
3032 
3033  FINISH;
3034 }
3035 
3036 static void
3039 {
3040  snat_main_t *sm = &snat_main;
3041  vl_api_nat66_add_del_static_mapping_reply_t *rmp;
3042  ip6_address_t l_addr, e_addr;
3043  int rv = 0;
3044 
3045  memcpy (&l_addr.as_u8, mp->local_ip_address, 16);
3046  memcpy (&e_addr.as_u8, mp->external_ip_address, 16);
3047 
3048  rv =
3049  nat66_static_mapping_add_del (&l_addr, &e_addr,
3050  clib_net_to_host_u32 (mp->vrf_id),
3051  mp->is_add);
3052 
3053  REPLY_MACRO (VL_API_NAT66_ADD_DEL_STATIC_MAPPING_REPLY);
3054 }
3055 
3058 {
3059  u8 *s;
3060 
3061  s = format (0, "SCRIPT: nat66_add_del_static_mapping ");
3062  s = format (s, "local_ip_address %U external_ip_address %U vrf_id %d %s",
3065  clib_net_to_host_u32 (mp->vrf_id), mp->is_add ? "" : "del");
3066 
3067  FINISH;
3068 }
3069 
3071 {
3075 
3076 static int
3078 {
3080  snat_main_t *sm = &snat_main;
3081  nat66_api_walk_ctx_t *ctx = arg;
3082 
3083  rmp = vl_msg_api_alloc (sizeof (*rmp));
3084  clib_memset (rmp, 0, sizeof (*rmp));
3085  rmp->_vl_msg_id = ntohs (VL_API_NAT66_INTERFACE_DETAILS + sm->msg_id_base);
3086  rmp->sw_if_index = ntohl (i->sw_if_index);
3088  rmp->context = ctx->context;
3089 
3090  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
3091 
3092  return 0;
3093 }
3094 
3095 static void
3097 {
3098  svm_queue_t *q;
3099 
3101  if (q == 0)
3102  return;
3103 
3105  .q = q,
3106  .context = mp->context,
3107  };
3108 
3110 }
3111 
3112 static void *
3114  void *handle)
3115 {
3116  u8 *s;
3117 
3118  s = format (0, "SCRIPT: nat66_interface_dump ");
3119 
3120  FINISH;
3121 }
3122 
3123 static int
3125 {
3127  nat66_main_t *nm = &nat66_main;
3128  snat_main_t *sm = &snat_main;
3129  nat66_api_walk_ctx_t *ctx = arg;
3130  fib_table_t *fib;
3131  vlib_counter_t vc;
3132 
3134  if (!fib)
3135  return -1;
3136 
3137  vlib_get_combined_counter (&nm->session_counters, m - nm->sm, &vc);
3138 
3139  rmp = vl_msg_api_alloc (sizeof (*rmp));
3140  clib_memset (rmp, 0, sizeof (*rmp));
3141  rmp->_vl_msg_id =
3142  ntohs (VL_API_NAT66_STATIC_MAPPING_DETAILS + sm->msg_id_base);
3143  clib_memcpy (rmp->local_ip_address, &m->l_addr, 16);
3144  clib_memcpy (rmp->external_ip_address, &m->e_addr, 16);
3145  rmp->vrf_id = ntohl (fib->ft_table_id);
3146  rmp->total_bytes = clib_host_to_net_u64 (vc.bytes);
3147  rmp->total_pkts = clib_host_to_net_u64 (vc.packets);
3148  rmp->context = ctx->context;
3149 
3150  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
3151 
3152  return 0;
3153 }
3154 
3155 static void
3157  * mp)
3158 {
3159  svm_queue_t *q;
3160 
3162  if (q == 0)
3163  return;
3164 
3166  .q = q,
3167  .context = mp->context,
3168  };
3169 
3171 }
3172 
3173 static void *
3175  mp, void *handle)
3176 {
3177  u8 *s;
3178 
3179  s = format (0, "SCRIPT: nat66_static_mapping_dump ");
3180 
3181  FINISH;
3182 }
3183 
3184 
3185 /* List of message types that this plugin understands */
3186 #define foreach_snat_plugin_api_msg \
3187 _(NAT_CONTROL_PING, nat_control_ping) \
3188 _(NAT_SHOW_CONFIG, nat_show_config) \
3189 _(NAT_SET_WORKERS, nat_set_workers) \
3190 _(NAT_WORKER_DUMP, nat_worker_dump) \
3191 _(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \
3192 _(NAT_SET_REASS, nat_set_reass) \
3193 _(NAT_GET_REASS, nat_get_reass) \
3194 _(NAT_REASS_DUMP, nat_reass_dump) \
3195 _(NAT_SET_TIMEOUTS, nat_set_timeouts) \
3196 _(NAT_GET_TIMEOUTS, nat_get_timeouts) \
3197 _(NAT_SET_ADDR_AND_PORT_ALLOC_ALG, nat_set_addr_and_port_alloc_alg) \
3198 _(NAT_GET_ADDR_AND_PORT_ALLOC_ALG, nat_get_addr_and_port_alloc_alg) \
3199 _(NAT_SET_MSS_CLAMPING, nat_set_mss_clamping) \
3200 _(NAT_GET_MSS_CLAMPING, nat_get_mss_clamping) \
3201 _(NAT44_ADD_DEL_ADDRESS_RANGE, nat44_add_del_address_range) \
3202 _(NAT44_INTERFACE_ADD_DEL_FEATURE, nat44_interface_add_del_feature) \
3203 _(NAT44_ADD_DEL_STATIC_MAPPING, nat44_add_del_static_mapping) \
3204 _(NAT44_ADD_DEL_IDENTITY_MAPPING, nat44_add_del_identity_mapping) \
3205 _(NAT44_STATIC_MAPPING_DUMP, nat44_static_mapping_dump) \
3206 _(NAT44_IDENTITY_MAPPING_DUMP, nat44_identity_mapping_dump) \
3207 _(NAT44_ADDRESS_DUMP, nat44_address_dump) \
3208 _(NAT44_INTERFACE_DUMP, nat44_interface_dump) \
3209 _(NAT44_ADD_DEL_INTERFACE_ADDR, nat44_add_del_interface_addr) \
3210 _(NAT44_INTERFACE_ADDR_DUMP, nat44_interface_addr_dump) \
3211 _(NAT44_USER_DUMP, nat44_user_dump) \
3212 _(NAT44_USER_SESSION_DUMP, nat44_user_session_dump) \
3213 _(NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE, \
3214  nat44_interface_add_del_output_feature) \
3215 _(NAT44_INTERFACE_OUTPUT_FEATURE_DUMP, \
3216  nat44_interface_output_feature_dump) \
3217 _(NAT44_ADD_DEL_LB_STATIC_MAPPING, nat44_add_del_lb_static_mapping) \
3218 _(NAT44_LB_STATIC_MAPPING_ADD_DEL_LOCAL, \
3219  nat44_lb_static_mapping_add_del_local) \
3220 _(NAT44_LB_STATIC_MAPPING_DUMP, nat44_lb_static_mapping_dump) \
3221 _(NAT44_DEL_SESSION, nat44_del_session) \
3222 _(NAT44_FORWARDING_ENABLE_DISABLE, nat44_forwarding_enable_disable) \
3223 _(NAT44_FORWARDING_IS_ENABLED, nat44_forwarding_is_enabled) \
3224 _(NAT_DET_ADD_DEL_MAP, nat_det_add_del_map) \
3225 _(NAT_DET_FORWARD, nat_det_forward) \
3226 _(NAT_DET_REVERSE, nat_det_reverse) \
3227 _(NAT_DET_MAP_DUMP, nat_det_map_dump) \
3228 _(NAT_DET_CLOSE_SESSION_OUT, nat_det_close_session_out) \
3229 _(NAT_DET_CLOSE_SESSION_IN, nat_det_close_session_in) \
3230 _(NAT_DET_SESSION_DUMP, nat_det_session_dump) \
3231 _(NAT64_ADD_DEL_POOL_ADDR_RANGE, nat64_add_del_pool_addr_range) \
3232 _(NAT64_POOL_ADDR_DUMP, nat64_pool_addr_dump) \
3233 _(NAT64_ADD_DEL_INTERFACE, nat64_add_del_interface) \
3234 _(NAT64_INTERFACE_DUMP, nat64_interface_dump) \
3235 _(NAT64_ADD_DEL_STATIC_BIB, nat64_add_del_static_bib) \
3236 _(NAT64_BIB_DUMP, nat64_bib_dump) \
3237 _(NAT64_ST_DUMP, nat64_st_dump) \
3238 _(NAT64_ADD_DEL_PREFIX, nat64_add_del_prefix) \
3239 _(NAT64_PREFIX_DUMP, nat64_prefix_dump) \
3240 _(NAT64_ADD_DEL_INTERFACE_ADDR, nat64_add_del_interface_addr) \
3241 _(DSLITE_ADD_DEL_POOL_ADDR_RANGE, dslite_add_del_pool_addr_range) \
3242 _(DSLITE_ADDRESS_DUMP, dslite_address_dump) \
3243 _(DSLITE_SET_AFTR_ADDR, dslite_set_aftr_addr) \
3244 _(DSLITE_GET_AFTR_ADDR, dslite_get_aftr_addr) \
3245 _(DSLITE_SET_B4_ADDR, dslite_set_b4_addr) \
3246 _(DSLITE_GET_B4_ADDR, dslite_get_b4_addr) \
3247 _(NAT66_ADD_DEL_INTERFACE, nat66_add_del_interface) \
3248 _(NAT66_INTERFACE_DUMP, nat66_interface_dump) \
3249 _(NAT66_ADD_DEL_STATIC_MAPPING, nat66_add_del_static_mapping) \
3250 _(NAT66_STATIC_MAPPING_DUMP, nat66_static_mapping_dump)
3251 
3252 /* Set up the API message handling tables */
3253 static clib_error_t *
3255 {
3256  snat_main_t *sm __attribute__ ((unused)) = &snat_main;
3257 #define _(N,n) \
3258  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
3259  #n, \
3260  vl_api_##n##_t_handler, \
3261  vl_noop_handler, \
3262  vl_api_##n##_t_endian, \
3263  vl_api_##n##_t_print, \
3264  sizeof(vl_api_##n##_t), 1);
3266 #undef _
3267 
3268  return 0;
3269 }
3270 
3271 #define vl_msg_name_crc_list
3272 #include <nat/nat_all_api_h.h>
3273 #undef vl_msg_name_crc_list
3274 
3275 static void
3277 {
3278 #define _(id,n,crc) \
3279  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
3280  foreach_vl_msg_name_crc_nat;
3281 #undef _
3282 }
3283 
3284 static void
3286 {
3287 #define _(n,f) sm->api_main->msg_print_handlers \
3288  [VL_API_##n + sm->msg_id_base] \
3289  = (void *) vl_api_##f##_t_print;
3291 #undef _
3292 }
3293 
3294 clib_error_t *
3296 {
3297  u8 *name;
3298  clib_error_t *error = 0;
3299 
3300  name = format (0, "nat_%08x%c", api_version, 0);
3301 
3302  /* Ask for a correctly-sized block of API message decode slots */
3303  sm->msg_id_base =
3305 
3306  error = snat_plugin_api_hookup (vm);
3307 
3308  /* Add our API messages to the global name_crc hash table */
3309  setup_message_id_table (sm, sm->api_main);
3310 
3312 
3313  vec_free (name);
3314 
3315  return error;
3316 }
3317 
3318 /*
3319  * fd.io coding-style-patch-verification: ON
3320  *
3321  * Local Variables:
3322  * eval: (c-set-style "gnu")
3323  * End:
3324  */
ip4_address_t external_addr
Definition: nat.h:330
u32 user_memory_size
Definition: nat.h:518
Dump NAT64 prefix.
Definition: nat.api:1276
u32 next
Definition: dlist.h:30
NAT64 interface details response.
Definition: nat.api:1148
nat64_db_t * db
BIB and session DB per thread.
Definition: nat64.h:83
#define nat_log_info(...)
Definition: nat.h:698
u32 nat_reass_get_timeout(u8 is_ip6)
Get reassembly timeout.
Definition: nat_reass.c:135
NAT virtual fragmentation reassemblies response.
Definition: nat.api:227
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
Definition: nat.h:605
u32 sessions_per_user_list_head_index
Definition: nat.h:236
NAT44 load-balancing static mapping rule details response.
Definition: nat.api:827
static void vl_api_nat66_add_del_interface_t_handler(vl_api_nat66_add_del_interface_t *mp)
Definition: nat_api.c:3004
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Delete external address from NAT44 pool.
Definition: nat.c:1601
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
Definition: nat64.c:785
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:1219
static void vl_api_nat_worker_dump_t_handler(vl_api_nat_worker_dump_t *mp)
Definition: nat_api.c:216
u16 ext_host_port
Definition: nat.h:85
Get address and port assignment algorithm reply.
Definition: nat.api:324
static int nat64_api_pool_walk(snat_address_t *a, void *arg)
Definition: nat_api.c:2359
u16 out_port
Definition: nat.h:86
NAT64 BIB details response.
Definition: nat.api:1203
Dump NAT virtual fragmentation reassemblies.
Definition: nat.api:213
a
Definition: bitmap.h:538
static void * vl_api_nat44_user_dump_t_print(vl_api_nat44_user_dump_t *mp, void *handle)
Definition: nat_api.c:1434
u32 icmp_timeout
Definition: nat.h:529
static void * vl_api_nat_ipfix_enable_disable_t_print(vl_api_nat_ipfix_enable_disable_t *mp, void *handle)
Definition: nat_api.c:263
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:2218
Get values of timeouts for NAT sessions (seconds)
Definition: nat.api:258
NAT workers details response.
Definition: nat.api:134
ip4_address_t src_address
Definition: ip4_packet.h:170
ip6_address_t prefix
Definition: nat64.h:49
Get values of timeouts for NAT sessions reply.
Definition: nat.api:271
Set AFTR IPv6 and IPv4 addresses.
Definition: nat.api:1352
static void * vl_api_nat64_interface_dump_t_print(vl_api_nat64_interface_dump_t *mp, void *handle)
Definition: nat_api.c:2485
static void send_nat44_user_session_details(snat_session_t *s, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1444
NAT44 interface with output feature details response.
Definition: nat.api:480
static void * vl_api_nat_set_addr_and_port_alloc_alg_t_print(vl_api_nat_set_addr_and_port_alloc_alg_t *mp, void *handle)
Definition: nat_api.c:531
u16 start_port
Definition: nat.h:472
Dump NAT44 pool addresses interfaces.
Definition: nat.api:643
u32 nsessions
Definition: nat.h:237
static void vl_api_nat44_user_session_dump_t_handler(vl_api_nat44_user_session_dump_t *mp)
Definition: nat_api.c:1491
u8 as_u8[16]
Definition: ip6_packet.h:48
#define is_ed_session(s)
Check if NAT session is endpoint dependent.
Definition: nat.h:635
static void * vl_api_nat44_del_session_t_print(vl_api_nat44_del_session_t *mp, void *handle)
Definition: nat_api.c:1803
ip4_address_t aftr_ip4_addr
Definition: dslite.h:81
NAT44 identity mapping details response.
Definition: nat.api:613
unsigned long u64
Definition: types.h:89
u32 st_buckets
Definition: nat64.h:97
Add/delete NAT44 identity mapping.
Definition: nat.api:581
vl_api_nat44_lb_addr_port_t locals[local_num]
Definition: nat.api:779
#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:419
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
snat_protocol_t proto
Definition: nat.h:341
static void vl_api_nat44_lb_static_mapping_dump_t_handler(vl_api_nat44_lb_static_mapping_dump_t *mp)
Definition: nat_api.c:1735
static void send_dslite_address_details(snat_address_t *ap, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:2938
static void vl_api_nat_reass_dump_t_handler(vl_api_nat_reass_dump_t *mp)
Definition: nat_api.c:392
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:2447
NAT users response.
Definition: nat.api:998
Add/delete address range to DS-Lite pool.
Definition: nat.api:1320
static void vl_api_nat64_bib_dump_t_handler(vl_api_nat64_bib_dump_t *mp)
Definition: nat_api.c:2566
static int nat_ip6_reass_walk_api(nat_reass_ip6_t *reass, void *arg)
Definition: nat_api.c:369
svm_queue_t * q
Definition: nat_api.c:3072
static clib_error_t * snat_plugin_api_hookup(vlib_main_t *vm)
Definition: nat_api.c:3254
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:283
Set NAT virtual fragmentation reassembly.
Definition: nat.api:165
static void * vl_api_nat64_bib_dump_t_print(vl_api_nat64_bib_dump_t *mp, void *handle)
Definition: nat_api.c:2588
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:3057
Control ping from client to api server request.
Definition: nat.api:34
Set values of timeouts for NAT sessions (seconds)
Definition: nat.api:245
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1018
Get outside address and port range from inside address.
Definition: nat.api:930
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
u32 nstaticsessions
Definition: nat.h:238
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:2303
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:971
u32 bib_memory_size
Definition: nat64.h:96
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
Add/delete NAT44 load-balancing static mapping rule backend.
Definition: nat.api:791
NAT44 interface details response.
Definition: nat.api:444
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:1329
Dump NAT66 static mappings.
Definition: nat.api:1475
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:552
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:2986
static void vl_api_nat_get_addr_and_port_alloc_alg_t_handler(vl_api_nat_get_addr_and_port_alloc_alg_t *mp)
Definition: nat_api.c:547
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:2520
int nat44_del_ed_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Delete NAT44 endpoint-dependent session.
Definition: nat.c:3409
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:2403
u32 fib_index
Definition: nat.h:235
Response to check if forwarding is enabled or disabled.
Definition: nat.api:892
snat_det_map_t * det_maps
Definition: nat.h:503
static void vl_api_nat_control_ping_t_handler(vl_api_nat_control_ping_t *mp)
Definition: nat_api.c:71
Get NAT virtual fragmentation reassembly configuration reply.
Definition: nat.api:196
int nat64_add_interface_address(u32 sw_if_index, int is_add)
NAT64 pool address from specific (DHCP addressed) interface.
Definition: nat64.c:378
Add/delete NAT64 pool address from specific interfce.
Definition: nat.api:1300
u8 in_plen
Definition: nat.h:277
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:611
vhost_vring_addr_t addr
Definition: vhost_user.h:121
static void vl_api_nat44_add_del_interface_addr_t_handler(vl_api_nat44_add_del_interface_addr_t *mp)
Definition: nat_api.c:1292
static void vl_api_nat_set_workers_t_handler(vl_api_nat_set_workers_t *mp)
Definition: nat_api.c:140
static void * vl_api_nat44_lb_static_mapping_add_del_local_t_print(vl_api_nat44_lb_static_mapping_add_del_local_t *mp, void *handle)
Definition: nat_api.c:1675
unsigned char u8
Definition: types.h:56
u8 deterministic
Definition: nat.h:511
Enable/disable NAT64 feature on the interface.
Definition: nat.api:1126
void nat_ip4_reass_walk(nat_ip4_reass_walk_fn_t fn, void *ctx)
Walk IPv4 reassemblies.
Definition: nat_reass.c:382
static void * vl_api_nat_get_reass_t_print(vl_api_nat_get_reass_t *mp, void *handle)
Definition: nat_api.c:330
static int nat64_api_prefix_walk(nat64_prefix_t *p, void *arg)
Definition: nat_api.c:2698
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 feature on the interface.
Definition: nat.c:1715
nat44_lb_addr_port_t * locals
Definition: nat.h:349
static void vl_api_nat_get_timeouts_t_handler(vl_api_nat_get_timeouts_t *mp)
Definition: nat_api.c:460
static void * vl_api_nat_det_reverse_t_print(vl_api_nat_det_reverse_t *mp, void *handle)
Definition: nat_api.c:2048
static void * vl_api_nat_show_config_t_print(vl_api_nat_show_config_t *mp, void *handle)
Definition: nat_api.c:130
static void * vl_api_nat44_forwarding_is_enabled_t_print(vl_api_nat44_forwarding_is_enabled_t *mp, void *handle)
Definition: nat_api.c:1895
u32 user_buckets
Definition: nat.h:517
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, snat_protocol_t proto, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u32 affinity)
Add/delete static mapping with load-balancing (multiple backends)
Definition: nat.c:1142
#define clib_memcpy(d, s, n)
Definition: string.h:180
#define nat_interface_is_outside(i)
Check if NAT interface is outside.
Definition: nat.h:653
u32 max_translations_per_user
Definition: nat.h:519
static void * vl_api_nat44_interface_addr_dump_t_print(vl_api_nat44_interface_addr_dump_t *mp, void *handle)
Definition: nat_api.c:1371
static void * vl_api_nat44_identity_mapping_dump_t_print(vl_api_nat44_identity_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:1281
nat66_main_t nat66_main
Definition: nat66.c:23
static void * vl_api_dslite_address_dump_t_print(vl_api_dslite_address_dump_t *mp, void *handle)
Definition: nat_api.c:2975
format_function_t format_ip4_address
Definition: format.h:75
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:1938
static void vl_api_nat44_user_dump_t_handler(vl_api_nat44_user_dump_t *mp)
Definition: nat_api.c:1408
Check if forwarding is enabled or disabled.
Definition: nat.api:883
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
Dump NAT64 session table.
Definition: nat.api:1224
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:1758
static void vl_api_nat_set_addr_and_port_alloc_alg_t_handler(vl_api_nat_set_addr_and_port_alloc_alg_t *mp)
Definition: nat_api.c:489
ip4_address_t ext_host_addr
Definition: nat.h:84
NAT66 interface details response.
Definition: nat.api:1448
u32 sw_if_index
Definition: vxlan_gbp.api:37
static int nat64_api_st_walk(nat64_db_st_entry_t *ste, void *arg)
Definition: nat_api.c:2598
Response to get AFTR IPv6 and IPv4 addresses.
Definition: nat.api:1374
Enable/disbale NAT44 as an interface output feature (postrouting in2out translation) ...
Definition: nat.api:458
static void sent_nat_det_map_details(snat_det_map_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:2060
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Add external address to NAT44 pool.
Definition: nat.c:516
u32 translation_buckets
Definition: nat.h:514
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
Definition: nat64.c:806
struct nat64_api_walk_ctx_t_ nat64_api_walk_ctx_t
ip4_address_t addr
Definition: nat.h:234
Dump DS-Lite addresses.
Definition: nat.api:1332
ip6_address_t b4_ip6_addr
Definition: dslite.h:82
#define SNAT_DET_SES_PER_USER
Definition: nat_det.h:30
NAT44 load-balancing address and port pair.
Definition: nat.api:741
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define is_fwd_bypass_session(s)
Check if NAT session is forwarding bypass.
Definition: nat.h:629
#define foreach_snat_plugin_api_msg
Definition: nat_api.c:3186
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:853
int snat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable NAT plugin IPFIX logging.
static void send_nat44_user_details(snat_user_t *u, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1382
unsigned int u32
Definition: types.h:88
Dump interfaces with NAT44 output feature.
Definition: nat.api:470
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:1064
static void vl_api_nat44_add_del_address_range_t_handler(vl_api_nat44_add_del_address_range_t *mp)
Definition: nat_api.c:638
static void vl_api_nat44_forwarding_enable_disable_t_handler(vl_api_nat44_forwarding_enable_disable_t *mp)
Definition: nat_api.c:1823
static void vl_api_nat_det_map_dump_t_handler(vl_api_nat_det_map_dump_t *mp)
Definition: nat_api.c:2083
ip4_address_t local_addr
Definition: nat.h:328
Get B4 IPv6 and IPv4 addresses.
Definition: nat.api:1398
static void send_nat44_identity_mapping_details(snat_static_mapping_t *m, int index, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1194
static void * vl_api_nat66_add_del_interface_t_print(vl_api_nat66_add_del_interface_t *mp, void *handle)
Definition: nat_api.c:3023
snat_protocol_t proto
Definition: nat.h:369
static void * vl_api_nat44_forwarding_enable_disable_t_print(vl_api_nat44_forwarding_enable_disable_t *mp, void *handle)
Definition: nat_api.c:1861
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:3295
static void nat44_delete_session(snat_main_t *sm, snat_session_t *ses, u32 thread_index)
Definition: nat_inlines.h:168
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
twice_nat_type_t twice_nat
Definition: nat.h:336
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:483
static void * vl_api_dslite_get_b4_addr_t_print(vl_api_dslite_get_b4_addr_t *mp, void *handle)
Definition: nat_api.c:2894
static u32 snat_det_user_ses_offset(ip4_address_t *addr, u8 plen)
Definition: nat_det.h:105
static void * vl_api_nat_get_timeouts_t_print(vl_api_nat_get_timeouts_t *mp, void *handle)
Definition: nat_api.c:478
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:36
static void send_nat44_address_details(snat_address_t *a, vl_api_registration_t *reg, u32 context, u8 twice_nat)
Definition: nat_api.c:713
Get TCP MSS rewriting configuration.
Definition: nat.api:352
#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:511
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
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Free NAT44 session data (lookup keys, external addrres port)
Definition: nat.c:178
static void * vl_api_nat64_st_dump_t_print(vl_api_nat64_st_dump_t *mp, void *handle)
Definition: nat_api.c:2659
u16 mss_value_net
Definition: nat.h:533
static void * vl_api_nat_control_ping_t_print(vl_api_nat_control_ping_t *mp, void *handle)
Definition: nat_api.c:86
u32 st_memory_size
Definition: nat64.h:98
counter_t packets
packet counter
Definition: counter_types.h:28
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat.h:466
static void vl_api_nat44_forwarding_is_enabled_t_handler(vl_api_nat44_forwarding_is_enabled_t *mp)
Definition: nat_api.c:1873
Add/delete address range to NAT64 pool.
Definition: nat.api:1090
snat_det_session_t * sessions
Definition: nat.h:288
u64 key
the key
Definition: bihash_8_8.h:33
Close deterministic NAT session by outside address and port.
Definition: nat.api:1018
static void * vl_api_nat_get_addr_and_port_alloc_alg_t_print(vl_api_nat_get_addr_and_port_alloc_alg_t *mp, void *handle)
Definition: nat_api.c:567
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
Definition: nat_det.h:60
long ctx[MAX_CONNS]
Definition: main.c:144
u16 mss_clamping
Definition: nat.h:532
static void * vl_api_dslite_get_aftr_addr_t_print(vl_api_dslite_get_aftr_addr_t *mp, void *handle)
Definition: nat_api.c:2832
static void send_nat44_interface_output_feature_details(snat_interface_t *i, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:891
unsigned short u16
Definition: types.h:57
Enable/disable forwarding for NAT44 Forward packets which don&#39;t match existing translation or static ...
Definition: nat.api:873
Dump NAT64 pool addresses.
Definition: nat.api:1103
static void * vl_api_nat_set_workers_t_print(vl_api_nat_set_workers_t *mp, void *handle)
Definition: nat_api.c:171
u8 out2in_dpo
Definition: nat.h:512
static void vl_api_nat_set_timeouts_t_handler(vl_api_nat_set_timeouts_t *mp)
Definition: nat_api.c:420
snat_static_mapping_t * static_mappings
Definition: nat.h:455
Add/del NAT64 prefix.
Definition: nat.api:1263
u32 udp_timeout
Definition: nat.h:526
u8 static_mapping_only
Definition: nat.h:509
vl_api_registration_t * reg
Definition: nat_api.c:341
static void * vl_api_dslite_set_aftr_addr_t_print(vl_api_dslite_set_aftr_addr_t *mp, void *handle)
Definition: nat_api.c:2801
static int nat66_api_interface_walk(snat_interface_t *i, void *arg)
Definition: nat_api.c:3077
#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:2386
#define nat_interface_is_inside(i)
Check if NAT interface is inside.
Definition: nat.h:647
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:933
u8 psid_offset
Definition: nat.h:468
static void vl_api_nat_det_reverse_t_handler(vl_api_nat_det_reverse_t *mp)
Definition: nat_api.c:2010
snat_address_t * addr_pool
Definition: dslite.h:85
Dump NAT44 identity mappings.
Definition: nat.api:598
int dslite_add_del_pool_addr(dslite_main_t *dm, ip4_address_t *addr, u8 is_add)
Definition: dslite.c:178
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
Definition: nat.c:3476
int dslite_set_b4_ip4_addr(dslite_main_t *dm, ip4_address_t *addr)
Definition: dslite.c:163
static void vl_api_nat44_add_del_identity_mapping_t_handler(vl_api_nat44_add_del_identity_mapping_t *mp)
Definition: nat_api.c:1129
static void send_nat_det_session_details(snat_det_session_t *s, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:2231
static void * vl_api_nat66_static_mapping_dump_t_print(vl_api_nat66_static_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:3174
api_main_t * api_main
Definition: nat.h:550
u8 name[64]
Definition: memclnt.api:152
static void vl_api_nat_get_mss_clamping_t_handler(vl_api_nat_get_mss_clamping_t *mp)
Definition: nat_api.c:607
Add/delete NAT44 pool address from specific interfce.
Definition: nat.api:631
u8 out_plen
Definition: nat.h:280
static void * vl_api_nat_worker_dump_t_print(vl_api_nat_worker_dump_t *mp, void *handle)
Definition: nat_api.c:236
u8 psid_length
Definition: nat.h:469
static void * vl_api_nat44_address_dump_t_print(vl_api_nat44_address_dump_t *mp, void *handle)
Definition: nat_api.c:760
static void vl_api_dslite_set_aftr_addr_t_handler(vl_api_dslite_set_aftr_addr_t *mp)
Definition: nat_api.c:2781
u32 inside_vrf_id
Definition: nat.h:522
Get address and port assignment algorithm.
Definition: nat.api:307
static void vl_api_nat44_del_session_t_handler(vl_api_nat44_del_session_t *mp)
Definition: nat_api.c:1768
static void * vl_api_nat_det_session_dump_t_print(vl_api_nat_det_session_dump_t *mp, void *handle)
Definition: nat_api.c:2286
Add/delete NAT64 static BIB entry.
Definition: nat.api:1165
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
static void vl_api_nat44_add_del_static_mapping_t_handler(vl_api_nat44_add_del_static_mapping_t *mp)
Definition: nat_api.c:944
Enable/disable NAT66 feature on the interface.
Definition: nat.api:1426
static void send_nat44_interface_details(snat_interface_t *i, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:803
snat_interface_t * output_feature_interfaces
Definition: nat.h:459
snat_main_t snat_main
Definition: nat.c:38
An API client registration, only in vpp/vlib.
Definition: api_common.h:45
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:34
#define BAD_SW_IF_INDEX_LABEL
Add/delete NAT deterministic mapping.
Definition: nat.api:912
snat_user_t * users
Definition: nat.h:393
static void * vl_api_nat_set_timeouts_t_print(vl_api_nat_set_timeouts_t *mp, void *handle)
Definition: nat_api.c:446
ip6_address_t aftr_ip6_addr
Definition: dslite.h:80
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:3124
static void * vl_api_nat66_interface_dump_t_print(vl_api_nat66_interface_dump_t *mp, void *handle)
Definition: nat_api.c:3113
static void vl_api_nat66_add_del_static_mapping_t_handler(vl_api_nat66_add_del_static_mapping_t *mp)
Definition: nat_api.c:3038
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
Definition: nat_inlines.h:41
static void * vl_api_nat64_add_del_prefix_t_print(vl_api_nat64_add_del_prefix_t *mp, void *handle)
Definition: nat_api.c:2685
static void vl_api_nat64_add_del_interface_addr_t_handler(vl_api_nat64_add_del_interface_addr_t *mp)
Definition: nat_api.c:2747
Dump interfaces with NAT44 feature.
Definition: nat.api:434
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:363
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:93
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:259
vlib_main_t * vm
Definition: buffer.c:301
static void vl_api_nat44_identity_mapping_dump_t_handler(vl_api_nat44_identity_mapping_dump_t *mp)
Definition: nat_api.c:1244
static void vl_api_nat_det_forward_t_handler(vl_api_nat_det_forward_t *mp)
Definition: nat_api.c:1952
u32 outside_vrf_id
Definition: nat.h:520
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:2338
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
Definition: nat.c:2631
svm_queue_t * vl_api_client_index_to_input_queue(u32 index)
Definition: memory_api.c:799
static void vl_api_nat_show_config_t_handler(vl_api_nat_show_config_t *mp)
Definition: nat_api.c:96
static void vl_api_dslite_address_dump_t_handler(vl_api_dslite_address_dump_t *mp)
Definition: nat_api.c:2956
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:1583
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:440
u8 static_mapping_connection_tracking
Definition: nat.h:510
u16 end_port
Definition: nat.h:473
Dump NAT44 load-balancing static mapping rules.
Definition: nat.api:805
Dump NAT44 addresses.
Definition: nat.api:397
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
ip4_address_t b4_ip4_addr
Definition: dslite.h:83
deterministic NAT definitions
NAT44 user&#39;s sessions response.
Definition: nat.api:717
static void * vl_api_nat44_interface_dump_t_print(vl_api_nat44_interface_dump_t *mp, void *handle)
Definition: nat_api.c:841
static void * vl_api_nat_det_map_dump_t_print(vl_api_nat_det_map_dump_t *mp, void *handle)
Definition: nat_api.c:2103
Set NAT workers.
Definition: nat.api:113
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
Definition: nat64.c:967
u32 bib_buckets
config parameters
Definition: nat64.h:95
static void vl_api_nat44_interface_addr_dump_t_handler(vl_api_nat44_interface_addr_dump_t *mp)
Definition: nat_api.c:1348
NAT66 static mapping details response.
Definition: nat.api:1488
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 output feature on the interface (postrouting NAT)
Definition: nat.c:1964
u32 sharing_ratio
Definition: nat.h:282
ip4_address_t out_addr
Definition: nat.h:279
u16 psid
Definition: nat.h:470
static void vl_api_nat64_add_del_prefix_t_handler(vl_api_nat64_add_del_prefix_t *mp)
Definition: nat_api.c:2669
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:2718
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
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:1628
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:31
#define ARRAY_LEN(x)
Definition: clib.h:62
u32 sw_if_index
Definition: nat.h:358
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:28
static void vl_api_dslite_set_b4_addr_t_handler(vl_api_dslite_set_b4_addr_t *mp)
Definition: nat_api.c:2843
static void send_nat44_lb_static_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1686
static void vl_api_nat44_lb_static_mapping_add_del_local_t_handler(vl_api_nat44_lb_static_mapping_add_del_local_t *mp)
Definition: nat_api.c:1641
u32 tcp_transitory_timeout
Definition: nat.h:528
static void vl_api_nat_det_close_session_out_t_handler(vl_api_nat_det_close_session_out_t *mp)
Definition: nat_api.c:2113
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, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat)
Add/delete NAT44 static mapping.
Definition: nat.c:652
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:1054
static void vl_api_nat_det_add_del_map_t_handler(vl_api_nat_det_add_del_map_t *mp)
Definition: nat_api.c:1909
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:482
static int nat64_api_bib_walk(nat64_db_bib_entry_t *bibe, void *arg)
Definition: nat_api.c:2536
static void vl_api_nat66_static_mapping_dump_t_handler(vl_api_nat66_static_mapping_dump_t *mp)
Definition: nat_api.c:3156
static void vl_api_dslite_get_aftr_addr_t_handler(vl_api_dslite_get_aftr_addr_t *mp)
Definition: nat_api.c:2815
Get NAT virtual fragmentation reassembly configuration.
Definition: nat.api:179
static void vl_api_nat_get_reass_t_handler(vl_api_nat_get_reass_t *mp)
Definition: nat_api.c:308
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:992
static void vl_api_nat_det_close_session_in_t_handler(vl_api_nat_det_close_session_in_t *mp)
Definition: nat_api.c:2171
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:2764
vl_api_nat44_lb_addr_port_t locals[local_num]
Definition: nat.api:838
#define is_addr_only_static_mapping(sm)
Check if NAT static mapping is address only (1:1NAT).
Definition: nat.h:665
u32 num_workers
Definition: nat.h:437
static int nat_ip4_reass_walk_api(nat_reass_ip4_t *reass, void *arg)
Definition: nat_api.c:346
Definition: nat.h:310
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:2906
DS-Lite address details response.
Definition: nat.api:1341
NAT44 users response.
Definition: nat.api:675
u32 first_worker_index
Definition: nat.h:438
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:322
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:878
static void send_nat44_static_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1020
vl_api_registration_t * reg
Definition: nat_api.c:2353
ip4_address_t l_addr
Definition: nat.h:364
NAT64 pool address details response.
Definition: nat.api:1113
static void * vl_api_nat_set_reass_t_print(vl_api_nat_set_reass_t *mp, void *handle)
Definition: nat_api.c:294
Dump NAT workers.
Definition: nat.api:123
static void vl_api_nat_ipfix_enable_disable_t_handler(vl_api_nat_ipfix_enable_disable_t *mp)
Definition: nat_api.c:246
Dump NAT64 prefix details response.
Definition: nat.api:1287
Set B4 IPv6 and IPv4 addresses.
Definition: nat.api:1387
IPv4 main type.
Definition: ip4.h:96
static void send_nat_worker_details(u32 worker_index, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:196
Set address and port assignment algorithm.
Definition: nat.api:292
static void vl_api_nat_det_session_dump_t_handler(vl_api_nat_det_session_dump_t *mp)
Definition: nat_api.c:2252
u64 as_u64
Definition: nat.h:102
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:1172
Add/del NAT44 address range.
Definition: nat.api:383
void nat_set_alloc_addr_and_port_range(u16 start_port, u16 end_port)
Set address and port assignment algorithm for port range.
Definition: nat.c:3465
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:299
static void * vl_api_nat_get_mss_clamping_t_print(vl_api_nat_get_mss_clamping_t *mp, void *handle)
Definition: nat_api.c:623
Close deterministic NAT session by inside address and port.
Definition: nat.api:1036
static void vl_api_nat64_interface_dump_t_handler(vl_api_nat64_interface_dump_t *mp)
Definition: nat_api.c:2468
ip4_address_t addr
Definition: nat.h:99
ip4_address_t in_addr
Definition: nat.h:276
static void * vl_api_nat44_static_mapping_dump_t_print(vl_api_nat44_static_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:1117
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
size_t count
Definition: vapi.c:47
Dump determinstic NAT sessions.
Definition: nat.api:1052
static void * vl_api_nat_det_forward_t_print(vl_api_nat_det_forward_t *mp, void *handle)
Definition: nat_api.c:1999
ip4_address_t addr
Definition: nat.h:243
static void vl_api_nat66_interface_dump_t_handler(vl_api_nat66_interface_dump_t *mp)
Definition: nat_api.c:3096
static void * vl_api_nat_set_mss_clamping_t_print(vl_api_nat_set_mss_clamping_t *mp, void *handle)
Definition: nat_api.c:595
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, snat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44 session.
Definition: nat.c:3366
snat_address_t * twice_nat_addresses
Definition: nat.h:479
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
Definition: nat64.c:1015
Set TCP MSS rewriting configuration.
Definition: nat.api:341
u32 value
Definition: dlist.h:32
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
Definition: nat64.c:503
int dslite_set_aftr_ip4_addr(dslite_main_t *dm, ip4_address_t *addr)
Definition: dslite.c:126
NAT64 global declarations.
counter_t bytes
byte counter
Definition: counter_types.h:29
int nat64_set_tcp_timeouts(u32 trans, u32 est)
Set TCP session timeouts.
Definition: nat64.c:827
ip6_address_t l_addr
Definition: nat66.h:27
void increment_v4_address(ip4_address_t *a)
Increment IPv4 address.
Definition: nat.c:600
vlib_combined_counter_main_t session_counters
Session counters.
Definition: nat66.h:57
Dump NAT64 BIB.
Definition: nat.api:1186
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:698
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:766
Dump NAT deterministic mappings.
Definition: nat.api:982
Get TCP MSS rewriting configuration reply.
Definition: nat.api:363
Show NAT plugin startup config reply.
Definition: nat.api:85
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
Definition: nat_inlines.h:26
Get outside address and port range from inside address.
Definition: nat.api:944
static void vl_api_dslite_get_b4_addr_t_handler(vl_api_dslite_get_b4_addr_t *mp)
Definition: nat_api.c:2877
static void vl_api_nat44_interface_dump_t_handler(vl_api_nat44_interface_dump_t *mp)
Definition: nat_api.c:822
Dump interfaces with NAT66 feature.
Definition: nat.api:1438
twice_nat_type_t
Definition: nat.h:305
Add/delete NAT44 static mapping.
Definition: nat.api:508
#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:133
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:1316
static void * vl_api_nat44_user_session_dump_t_print(vl_api_nat44_user_session_dump_t *mp, void *handle)
Definition: nat_api.c:1546
u16 msg_id_base
Definition: nat.h:540
#define is_out2in_only_static_mapping(sm)
Check if NAT static mapping match only out2in direction.
Definition: nat.h:671
Add/delete 1:1 NAT66.
Definition: nat.api:1462
Dump NAT44 static mappings.
Definition: nat.api:530
u16 ports_per_host
Definition: nat.h:284
Deterministic NAT sessions reply.
Definition: nat.api:1068
static void vl_api_nat64_add_del_static_bib_t_handler(vl_api_nat64_add_del_static_bib_t *mp)
Definition: nat_api.c:2497
Dump interfaces with NAT64 feature.
Definition: nat.api:1138
u32 * workers
Definition: nat.h:439
NAT44 pool addresses interfaces details response.
Definition: nat.api:653
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:446
snat_protocol_t
Definition: nat.h:133
snat_det_out_key_t out
Definition: nat.h:266
void nat_ip6_reass_walk(nat_ip6_reass_walk_fn_t fn, void *ctx)
Walk IPv6 reassemblies.
Definition: nat_reass.c:588
static void vl_api_nat_set_mss_clamping_t_handler(vl_api_nat_set_mss_clamping_t *mp)
Definition: nat_api.c:577
u32 fib_index
Definition: nat.h:100
static nat44_lb_addr_port_t * unformat_nat44_lb_addr_port(vl_api_nat44_lb_addr_port_t *addr_port_pairs, u32 addr_port_pair_num)
Definition: nat_api.c:1560
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:148
snat_address_t * addresses
Definition: nat.h:462
NAT44 user&#39;s sessions.
Definition: nat.api:690
nat64_db_t * db
Definition: nat_api.c:2355
typedef prefix
Definition: ip_types.api:35
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Add/delete NAT44 pool address from specific interfce.
Definition: nat.c:3298
static void * vl_api_nat64_add_del_interface_t_print(vl_api_nat64_add_del_interface_t *mp, void *handle)
Definition: nat_api.c:2433
struct _svm_queue svm_queue_t
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:486
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:903
static void vl_api_nat44_address_dump_t_handler(vl_api_nat44_address_dump_t *mp)
Definition: nat_api.c:738
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:101
u8 forwarding_enabled
Definition: nat.h:506
u32 translation_memory_size
Definition: nat.h:515
#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:3276
static void plugin_custom_dump_configure(snat_main_t *sm)
Definition: nat_api.c:3285
static void vl_api_nat44_interface_add_del_feature_t_handler(vl_api_nat44_interface_add_del_feature_t *mp)
Definition: nat_api.c:772
u32 ses_num
Definition: nat.h:286
#define FINISH
Definition: nat_api.c:59
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:2634
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
Definition: nat.c:2087
#define is_twice_nat_session(s)
Check if NAT session is twice NAT.
Definition: nat.h:617
struct nat66_api_walk_ctx_t_ nat66_api_walk_ctx_t
Response to get B4 IPv6 and IPv4 addresses.
Definition: nat.api:1409
u8 endpoint_dependent
Definition: nat.h:513
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:2156
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:790
static void * vl_api_nat64_prefix_dump_t_print(vl_api_nat64_prefix_dump_t *mp, void *handle)
Definition: nat_api.c:2735
NAT plugin virtual fragmentation reassembly.
Get inside address from outside address and port.
Definition: nat.api:958
void nat_set_alloc_addr_and_port_mape(u16 psid, u16 psid_offset, u16 psid_length)
Set address and port assignment algorithm for MAP-E CE.
Definition: nat.c:3453
NAT66 global declarations.
static void * vl_api_dslite_set_b4_addr_t_print(vl_api_dslite_set_b4_addr_t *mp, void *handle)
Definition: nat_api.c:2863
Get AFTR IPv6 and IPv4 addresses.
Definition: nat.api:1363
static void * vl_api_nat_reass_dump_t_print(vl_api_nat_reass_dump_t *mp, void *handle)
Definition: nat_api.c:410
Dump NAT44 users.
Definition: nat.api:663
#define BITS(x)
Definition: clib.h:61
Enable/disable NAT44 feature on the interface.
Definition: nat.api:422
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:248
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:649
snat_session_t * sessions
Definition: nat.h:396
int dslite_set_aftr_ip6_addr(dslite_main_t *dm, ip6_address_t *addr)
Definition: dslite.c:90
static void vl_api_nat44_static_mapping_dump_t_handler(vl_api_nat44_static_mapping_dump_t *mp)
Definition: nat_api.c:1084
vl_api_nat44_lb_addr_port_t local
Definition: nat.api:798
static void vl_api_nat_set_reass_t_handler(vl_api_nat_set_reass_t *mp)
Definition: nat_api.c:280
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, snat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
Definition: nat.c:1418
u32 fib_index
Definition: nat.h:244
snat_interface_t * interfaces
Definition: nat.h:458
Delete NAT44 session.
Definition: nat.api:853
#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:911
Show NAT plugin startup config.
Definition: nat.api:58
NAT44 address details response.
Definition: nat.api:408
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:865
NAT64 session table details response.
Definition: nat.api:1242
static void vl_api_nat64_add_del_interface_t_handler(vl_api_nat64_add_del_interface_t *mp)
Definition: nat_api.c:2414
u32 tcp_established_timeout
Definition: nat.h:527
struct nat_api_walk_ctx_t_ nat_api_walk_ctx_t
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128