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