FD.io VPP  v20.09-64-g4f7b92f0a
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/nat64.h>
23 #include <nat/nat_inlines.h>
24 #include <nat/nat44/inlines.h>
25 #include <nat/nat_ha.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
28 
29 #include <nat/nat_msg_enum.h>
30 #include <vnet/fib/fib_table.h>
31 #include <vnet/ip/ip_types_api.h>
32 #include <nat/nat44/ed_inlines.h>
33 #include <nat/nat_ipfix_logging.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;
99  //dslite_main_t *dm = &dslite_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);
107  rmp->translation_memory_size = clib_host_to_net_u32 (
108  sm->translation_memory_size > 0xffffffffULL
109  ? 0xffffffffUL
111  rmp->user_buckets = htonl (sm->user_buckets);
112  rmp->user_memory_size = clib_host_to_net_u64 (sm->user_memory_size);
114  rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
115  rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
119  rmp->deterministic = 0;
121  rmp->out2in_dpo = sm->out2in_dpo;
122  //rmp->dslite_ce = dm->is_ce;
123  rmp->nat64_bib_buckets = clib_net_to_host_u32(n64m->bib_buckets);
124  rmp->nat64_bib_memory_size = clib_net_to_host_u64(n64m->bib_memory_size);
125  rmp->nat64_st_buckets = clib_net_to_host_u32(n64m->st_buckets);
126  rmp->nat64_st_memory_size = clib_net_to_host_u64(n64m->st_memory_size);
127  }));
128  /* *INDENT-ON* */
129 }
130 
131 static void *
133 {
134  u8 *s;
135 
136  s = format (0, "SCRIPT: nat_show_config ");
137 
138  FINISH;
139 }
140 
141 static void
143 {
145  snat_main_t *sm = &snat_main;
146  //dslite_main_t *dm = &dslite_main;
147  nat64_main_t *n64m = &nat64_main;
148  int rv = 0;
149 
150  /* *INDENT-OFF* */
151  REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_2_REPLY,
152  ({
153  rmp->translation_buckets = htonl (sm->translation_buckets);
154  rmp->translation_memory_size = clib_host_to_net_u64 (sm->translation_memory_size);
155  rmp->user_buckets = htonl (sm->user_buckets);
156  rmp->user_memory_size = clib_host_to_net_u64 (sm->user_memory_size);
158  rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
159  rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
163  rmp->deterministic = 0;
165  rmp->out2in_dpo = sm->out2in_dpo;
166  //rmp->dslite_ce = dm->is_ce;
167  rmp->nat64_bib_buckets = clib_net_to_host_u32(n64m->bib_buckets);
168  rmp->nat64_bib_memory_size = clib_net_to_host_u64(n64m->bib_memory_size);
169  rmp->nat64_st_buckets = clib_net_to_host_u32(n64m->st_buckets);
170  rmp->nat64_st_memory_size = clib_net_to_host_u64(n64m->st_memory_size);
171  rmp->max_translations_per_thread = clib_net_to_host_u32(sm->max_translations_per_thread);
172  rmp->max_users_per_thread = clib_net_to_host_u32(sm->max_users_per_thread);
173  }));
174  /* *INDENT-ON* */
175 }
176 
177 static void *
179 {
180  u8 *s;
181 
182  s = format (0, "SCRIPT: nat_show_config_2 ");
183 
184  FINISH;
185 }
186 
187 static void
189 {
190  snat_main_t *sm = &snat_main;
191  vl_api_nat_set_workers_reply_t *rmp;
192  int rv = 0;
193  uword *bitmap = 0;
194  u64 mask;
195 
196  mask = clib_net_to_host_u64 (mp->worker_mask);
197 
198  if (sm->num_workers < 2)
199  {
200  rv = VNET_API_ERROR_FEATURE_DISABLED;
201  goto send_reply;
202  }
203 
204  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
205  rv = snat_set_workers (bitmap);
206  clib_bitmap_free (bitmap);
207 
208 send_reply:
209  REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
210 }
211 
212 static void *
214 {
215  u8 *s;
216  uword *bitmap = 0;
217  u8 first = 1;
218  int i;
219  u64 mask = clib_net_to_host_u64 (mp->worker_mask);
220 
221  s = format (0, "SCRIPT: nat_set_workers ");
222  bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
223  /* *INDENT-OFF* */
224  clib_bitmap_foreach (i, bitmap,
225  ({
226  if (first)
227  s = format (s, "%d", i);
228  else
229  s = format (s, ",%d", i);
230  first = 0;
231  }));
232  /* *INDENT-ON* */
233  clib_bitmap_free (bitmap);
234  FINISH;
235 }
236 
237 static void
239  u32 context)
240 {
242  snat_main_t *sm = &snat_main;
244  vlib_worker_threads + worker_index + sm->first_worker_index;
245 
246  rmp = vl_msg_api_alloc (sizeof (*rmp));
247  clib_memset (rmp, 0, sizeof (*rmp));
248  rmp->_vl_msg_id = ntohs (VL_API_NAT_WORKER_DETAILS + sm->msg_id_base);
249  rmp->context = context;
250  rmp->worker_index = htonl (worker_index);
251  rmp->lcore_id = htonl (w->cpu_id);
252  strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1);
253 
254  vl_api_send_msg (reg, (u8 *) rmp);
255 }
256 
257 static void
259 {
261  snat_main_t *sm = &snat_main;
262  u32 *worker_index;
263 
265  if (!reg)
266  return;
267 
268  /* *INDENT-OFF* */
269  vec_foreach (worker_index, sm->workers)
270  send_nat_worker_details(*worker_index, reg, mp->context);
271  /* *INDENT-ON* */
272 }
273 
274 static void *
276 {
277  u8 *s;
278 
279  s = format (0, "SCRIPT: nat_worker_dump ");
280 
281  FINISH;
282 }
283 
284 static void
286  mp)
287 {
288  snat_main_t *sm = &snat_main;
289  vl_api_nat44_set_session_limit_reply_t *rmp;
290  int rv = 0;
291 
293  (ntohl (mp->session_limit), ntohl (mp->vrf_id));
294 
295  REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
296 }
297 
298 static void *
300  mp, void *handle)
301 {
302  u8 *s;
303 
304  s = format (0, "SCRIPT: nat44_set_session_limit ");
305  s = format (s, "session_limit %d", ntohl (mp->session_limit));
306  s = format (s, "vrf_id %d", ntohl (mp->vrf_id));
307 
308  FINISH;
309 }
310 
311 static void
313 {
314  snat_main_t *sm = &snat_main;
315  vl_api_nat_set_log_level_reply_t *rmp;
316  int rv = 0;
317 
318  if (sm->log_level > NAT_LOG_DEBUG)
319  rv = VNET_API_ERROR_UNSUPPORTED;
320  else
321  sm->log_level = mp->log_level;
322 
323  REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
324 }
325 
326 static void *
328  mp, void *handle)
329 {
330  u8 *s;
331 
332  s = format (0, "SCRIPT: nat_set_log_level ");
333  s = format (s, "log_level %d", mp->log_level);
334 
335  FINISH;
336 }
337 
338 static void
340  mp)
341 {
342  snat_main_t *sm = &snat_main;
343  vl_api_nat_ipfix_enable_disable_reply_t *rmp;
344  int rv = 0;
345 
347  clib_host_to_net_u32
348  (mp->domain_id),
349  clib_host_to_net_u16
350  (mp->src_port));
351 
352  REPLY_MACRO (VL_API_NAT_IPFIX_ENABLE_DISABLE_REPLY);
353 }
354 
355 static void *
357  mp, void *handle)
358 {
359  u8 *s;
360 
361  s = format (0, "SCRIPT: nat_ipfix_enable_disable ");
362  if (mp->domain_id)
363  s = format (s, "domain %d ", clib_net_to_host_u32 (mp->domain_id));
364  if (mp->src_port)
365  s = format (s, "src_port %d ", clib_net_to_host_u16 (mp->src_port));
366  if (!mp->enable)
367  s = format (s, "disable ");
368 
369  FINISH;
370 }
371 
372 static void
374 {
375  snat_main_t *sm = &snat_main;
376  vl_api_nat_set_timeouts_reply_t *rmp;
377  int rv = 0;
378 
379  sm->udp_timeout = ntohl (mp->udp);
380  sm->tcp_established_timeout = ntohl (mp->tcp_established);
381  sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
382  sm->icmp_timeout = ntohl (mp->icmp);
383 
384  rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
385  if (rv)
386  goto send_reply;
387  rv = nat64_set_udp_timeout (ntohl (mp->udp));
388  if (rv)
389  goto send_reply;
390  rv =
392  ntohl (mp->tcp_established));
393 
394 send_reply:
395  REPLY_MACRO (VL_API_NAT_SET_TIMEOUTS_REPLY);
396 }
397 
398 static void *
400 {
401  u8 *s;
402 
403  s = format (0, "SCRIPT: nat_set_timeouts ");
404  s = format (s, "udp %d tcp_established %d tcp_transitory %d icmp %d\n",
405  ntohl (mp->udp),
406  ntohl (mp->tcp_established),
407  ntohl (mp->tcp_transitory), ntohl (mp->icmp));
408 
409  FINISH;
410 }
411 
412 static void
414 {
415  snat_main_t *sm = &snat_main;
417  int rv = 0;
418 
419  /* *INDENT-OFF* */
420  REPLY_MACRO2 (VL_API_NAT_GET_TIMEOUTS_REPLY,
421  ({
422  rmp->udp = htonl (sm->udp_timeout);
423  rmp->tcp_established = htonl (sm->tcp_established_timeout);
424  rmp->tcp_transitory = htonl (sm->tcp_transitory_timeout);
425  rmp->icmp = htonl (sm->icmp_timeout);
426  }))
427  /* *INDENT-ON* */
428 }
429 
430 static void *
432 {
433  u8 *s;
434 
435  s = format (0, "SCRIPT: nat_get_timeouts");
436 
437  FINISH;
438 }
439 
440 static void
443 {
444  snat_main_t *sm = &snat_main;
445  vl_api_nat_set_addr_and_port_alloc_alg_reply_t *rmp;
446  int rv = 0;
447  u16 port_start, port_end;
448 
449  switch (mp->alg)
450  {
451  case NAT_ADDR_AND_PORT_ALLOC_ALG_DEFAULT:
453  break;
454  case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
456  mp->psid_length);
457  break;
458  case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
459  port_start = ntohs (mp->start_port);
460  port_end = ntohs (mp->end_port);
461  if (port_end <= port_start)
462  {
463  rv = VNET_API_ERROR_INVALID_VALUE;
464  goto send_reply;
465  }
466  nat_set_alloc_addr_and_port_range (port_start, port_end);
467  break;
468  default:
469  rv = VNET_API_ERROR_INVALID_VALUE;
470  break;
471  }
472 
473 send_reply:
474  REPLY_MACRO (VL_API_NAT_SET_ADDR_AND_PORT_ALLOC_ALG_REPLY);
475 }
476 
479 {
480  u8 *s;
481 
482  s = format (0, "SCRIPT: nat_set_addr_and_port_alloc_alg ");
483  s = format (s, "alg %d psid_offset %d psid_length %d psid %d start_port %d "
484  "end_port %d\n",
485  ntohl (mp->alg), ntohl (mp->psid_offset),
486  ntohl (mp->psid_length), ntohs (mp->psid),
487  ntohs (mp->start_port), ntohs (mp->end_port));
488 
489  FINISH;
490 }
491 
492 static void
495 {
496  snat_main_t *sm = &snat_main;
498  int rv = 0;
499 
500  /* *INDENT-OFF* */
501  REPLY_MACRO2 (VL_API_NAT_GET_ADDR_AND_PORT_ALLOC_ALG_REPLY,
502  ({
503  rmp->alg = sm->addr_and_port_alloc_alg;
504  rmp->psid_offset = sm->psid_offset;
505  rmp->psid_length = sm->psid_length;
506  rmp->psid = htons (sm->psid);
507  rmp->start_port = htons (sm->start_port);
508  rmp->end_port = htons (sm->end_port);
509  }))
510  /* *INDENT-ON* */
511 }
512 
515 {
516  u8 *s;
517 
518  s = format (0, "SCRIPT: nat_get_addr_and_port_alloc_alg");
519 
520  FINISH;
521 }
522 
523 static void
525 {
526  snat_main_t *sm = &snat_main;
527  vl_api_nat_set_mss_clamping_reply_t *rmp;
528  int rv = 0;
529 
530  if (mp->enable)
531  sm->mss_clamping = ntohs (mp->mss_value);
532  else
533  sm->mss_clamping = 0;
534 
535  REPLY_MACRO (VL_API_NAT_SET_MSS_CLAMPING_REPLY);
536 }
537 
538 static void *
540  void *handle)
541 {
542  u8 *s;
543 
544  s = format (0, "SCRIPT: nat_set_mss_clamping enable %d mss_value %d\n",
545  mp->enable, ntohs (mp->mss_value));
546 
547  FINISH;
548 }
549 
550 static void
552 {
553  snat_main_t *sm = &snat_main;
555  int rv = 0;
556 
557  /* *INDENT-OFF* */
558  REPLY_MACRO2 (VL_API_NAT_GET_MSS_CLAMPING_REPLY,
559  ({
560  rmp->enable = sm->mss_clamping ? 1 : 0;
561  rmp->mss_value = htons (sm->mss_clamping);
562  }))
563  /* *INDENT-ON* */
564 }
565 
566 static void *
568  void *handle)
569 {
570  u8 *s;
571 
572  s = format (0, "SCRIPT: nat_get_mss_clamping");
573 
574  FINISH;
575 }
576 
577 static void
579 {
580  snat_main_t *sm = &snat_main;
581  vl_api_nat_ha_set_listener_reply_t *rmp;
583  int rv;
584 
585  memcpy (&addr, &mp->ip_address, sizeof (addr));
586  rv =
587  nat_ha_set_listener (&addr, clib_net_to_host_u16 (mp->port),
588  clib_net_to_host_u32 (mp->path_mtu));
589 
590  REPLY_MACRO (VL_API_NAT_HA_SET_LISTENER_REPLY);
591 }
592 
593 static void *
595  void *handle)
596 {
597  u8 *s;
598 
599  s = format (0, "SCRIPT: nat_ha_set_listener ");
600  s = format (s, "ip_address %U ", format_ip4_address, mp->ip_address);
601  s = format (s, "port %d ", clib_net_to_host_u16 (mp->port));
602  s = format (s, "path_mtu %d", clib_net_to_host_u32 (mp->path_mtu));
603 
604  FINISH;
605 }
606 
607 static void
609 {
610  snat_main_t *sm = &snat_main;
612  int rv = 0;
614  u16 port;
615  u32 path_mtu;
616 
617  nat_ha_get_listener (&addr, &port, &path_mtu);
618 
619  /* *INDENT-OFF* */
620  REPLY_MACRO2 (VL_API_NAT_HA_GET_LISTENER_REPLY,
621  ({
622  clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
623  rmp->port = clib_host_to_net_u16 (port);
624  rmp->path_mtu = clib_host_to_net_u32 (path_mtu);
625  }))
626  /* *INDENT-ON* */
627 }
628 
629 static void *
631  void *handle)
632 {
633  u8 *s;
634 
635  s = format (0, "SCRIPT: nat_ha_get_listener");
636 
637  FINISH;
638 }
639 
640 static void
642 {
643  snat_main_t *sm = &snat_main;
644  vl_api_nat_ha_set_failover_reply_t *rmp;
646  int rv;
647 
648  memcpy (&addr, &mp->ip_address, sizeof (addr));
649  rv =
650  nat_ha_set_failover (&addr, clib_net_to_host_u16 (mp->port),
651  clib_net_to_host_u32 (mp->session_refresh_interval));
652 
653  REPLY_MACRO (VL_API_NAT_HA_SET_FAILOVER_REPLY);
654 }
655 
656 static void *
658  void *handle)
659 {
660  u8 *s;
661 
662  s = format (0, "SCRIPT: nat_ha_set_failover ");
663  s = format (s, "ip_address %U ", format_ip4_address, mp->ip_address);
664  s = format (s, "port %d ", clib_net_to_host_u16 (mp->port));
665 
666  FINISH;
667 }
668 
669 static void
671 {
672  snat_main_t *sm = &snat_main;
674  int rv = 0;
676  u16 port;
677  u32 session_refresh_interval;
678 
679  nat_ha_get_failover (&addr, &port, &session_refresh_interval);
680 
681  /* *INDENT-OFF* */
682  REPLY_MACRO2 (VL_API_NAT_HA_GET_FAILOVER_REPLY,
683  ({
684  clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
685  rmp->port = clib_host_to_net_u16 (port);
686  rmp->session_refresh_interval = clib_host_to_net_u32 (session_refresh_interval);
687  }))
688  /* *INDENT-ON* */
689 }
690 
691 static void *
693  void *handle)
694 {
695  u8 *s;
696 
697  s = format (0, "SCRIPT: nat_ha_get_failover");
698 
699  FINISH;
700 }
701 
702 static void
704 {
705  snat_main_t *sm = &snat_main;
706  vl_api_nat_ha_flush_reply_t *rmp;
707  int rv = 0;
708 
709  nat_ha_flush (0);
710 
711  REPLY_MACRO (VL_API_NAT_HA_FLUSH_REPLY);
712 }
713 
714 static void *
716 {
717  u8 *s;
718 
719  s = format (0, "SCRIPT: nat_ha_flush ");
720 
721  FINISH;
722 }
723 
724 static void
725 nat_ha_resync_completed_event_cb (u32 client_index, u32 pid, u32 missed_count)
726 {
727  snat_main_t *sm = &snat_main;
730 
731  reg = vl_api_client_index_to_registration (client_index);
732  if (!reg)
733  return;
734 
735  mp = vl_msg_api_alloc (sizeof (*mp));
736  clib_memset (mp, 0, sizeof (*mp));
737  mp->client_index = client_index;
738  mp->pid = pid;
739  mp->missed_count = clib_host_to_net_u32 (missed_count);
740  mp->_vl_msg_id =
741  ntohs (VL_API_NAT_HA_RESYNC_COMPLETED_EVENT + sm->msg_id_base);
742 
743  vl_api_send_msg (reg, (u8 *) mp);
744 }
745 
746 static void
748 {
749  snat_main_t *sm = &snat_main;
750  vl_api_nat_ha_resync_reply_t *rmp;
751  int rv;
752 
753  rv =
754  nat_ha_resync (mp->client_index, mp->pid,
756  NULL);
757 
758  REPLY_MACRO (VL_API_NAT_HA_RESYNC_REPLY);
759 }
760 
761 static void *
763 {
764  u8 *s;
765 
766  s = format (0, "SCRIPT: nat_ha_resync ");
767  s =
768  format (s, "want_resync_event %d pid %d", mp->want_resync_event,
769  clib_host_to_net_u32 (mp->pid));
770 
771  FINISH;
772 }
773 
774 /*************/
775 /*** NAT44 ***/
776 /*************/
777 static void
779 {
780  snat_main_t *sm = &snat_main;
781  vl_api_nat44_del_user_reply_t *rmp;
783  int rv;
784  memcpy (&addr.as_u8, mp->ip_address, 4);
785  rv = nat44_user_del (&addr, ntohl (mp->fib_index));
786  REPLY_MACRO (VL_API_NAT44_DEL_USER_REPLY);
787 }
788 
790  (vl_api_nat44_del_user_t * mp, void *handle)
791 {
792  u8 *s;
793  s = format (0, "SCRIPT: nat44_del_user ");
794  s = format (s, "ip_address %U fib_index %U ",
795  format_ip4_address, mp->ip_address, ntohl (mp->fib_index));
796  FINISH;
797 }
798 
799 static void
802 {
803  snat_main_t *sm = &snat_main;
804  vl_api_nat44_add_del_address_range_reply_t *rmp;
805  ip4_address_t this_addr;
806  u8 is_add, twice_nat;
807  u32 start_host_order, end_host_order;
808  u32 vrf_id;
809  int i, count;
810  int rv = 0;
811  u32 *tmp;
812 
813  if (sm->static_mapping_only)
814  {
815  rv = VNET_API_ERROR_FEATURE_DISABLED;
816  goto send_reply;
817  }
818 
819  is_add = mp->is_add;
820  twice_nat = mp->flags & NAT_API_IS_TWICE_NAT;
821 
822  tmp = (u32 *) mp->first_ip_address;
823  start_host_order = clib_host_to_net_u32 (tmp[0]);
824  tmp = (u32 *) mp->last_ip_address;
825  end_host_order = clib_host_to_net_u32 (tmp[0]);
826 
827  count = (end_host_order - start_host_order) + 1;
828 
829  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
830 
831  if (count > 1024)
832  nat_log_info ("%U - %U, %d addresses...",
834  format_ip4_address, mp->last_ip_address, count);
835 
836  memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
837 
838  for (i = 0; i < count; i++)
839  {
840  if (is_add)
841  rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
842  else
843  rv = snat_del_address (sm, this_addr, 0, twice_nat);
844 
845  if (rv)
846  goto send_reply;
847 
848  if (sm->out2in_dpo)
849  nat44_add_del_address_dpo (this_addr, is_add);
850 
851  increment_v4_address (&this_addr);
852  }
853 
854 send_reply:
855  REPLY_MACRO (VL_API_NAT44_ADD_DEL_ADDRESS_RANGE_REPLY);
856 }
857 
860 {
861  u8 *s;
862 
863  s = format (0, "SCRIPT: nat44_add_address_range ");
864  s = format (s, "%U ", format_ip4_address, mp->first_ip_address);
865  if (memcmp (mp->first_ip_address, mp->last_ip_address, 4))
866  {
867  s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
868  }
869  s = format (s, "twice_nat %d ", mp->flags & NAT_API_IS_TWICE_NAT);
870  FINISH;
871 }
872 
873 static void
875  vl_api_registration_t * reg, u32 context,
876  u8 twice_nat)
877 {
879  snat_main_t *sm = &snat_main;
880 
881  rmp = vl_msg_api_alloc (sizeof (*rmp));
882  clib_memset (rmp, 0, sizeof (*rmp));
883  rmp->_vl_msg_id = ntohs (VL_API_NAT44_ADDRESS_DETAILS + sm->msg_id_base);
884  clib_memcpy (rmp->ip_address, &(a->addr), 4);
885  if (a->fib_index != ~0)
886  {
888  rmp->vrf_id = ntohl (fib->ft_table_id);
889  }
890  else
891  rmp->vrf_id = ~0;
892  if (twice_nat)
893  rmp->flags |= NAT_API_IS_TWICE_NAT;
894  rmp->context = context;
895 
896  vl_api_send_msg (reg, (u8 *) rmp);
897 }
898 
899 static void
901 {
903  snat_main_t *sm = &snat_main;
904  snat_address_t *a;
905 
907  if (!reg)
908  return;
909 
910  /* *INDENT-OFF* */
911  vec_foreach (a, sm->addresses)
912  send_nat44_address_details (a, reg, mp->context, 0);
914  send_nat44_address_details (a, reg, mp->context, 1);
915  /* *INDENT-ON* */
916 }
917 
918 static void *
920  void *handle)
921 {
922  u8 *s;
923 
924  s = format (0, "SCRIPT: nat44_address_dump ");
925 
926  FINISH;
927 }
928 
929 static void
932 {
933  snat_main_t *sm = &snat_main;
934  vl_api_nat44_interface_add_del_feature_reply_t *rmp;
935  u32 sw_if_index = ntohl (mp->sw_if_index);
936  u8 is_del;
937  int rv = 0;
938 
939  is_del = !mp->is_add;
940 
942 
943  rv =
944  snat_interface_add_del (sw_if_index, mp->flags & NAT_API_IS_INSIDE,
945  is_del);
946 
948 
949  REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_FEATURE_REPLY);
950 }
951 
954 {
955  u8 *s;
956 
957  s = format (0, "SCRIPT: nat44_interface_add_del_feature ");
958  s = format (s, "sw_if_index %d %s %s",
959  clib_host_to_net_u32 (mp->sw_if_index),
960  mp->flags & NAT_API_IS_INSIDE ? "in" : "out",
961  mp->is_add ? "" : "del");
962 
963  FINISH;
964 }
965 
966 static void
968  vl_api_registration_t * reg, u32 context)
969 {
971  snat_main_t *sm = &snat_main;
972 
973  rmp = vl_msg_api_alloc (sizeof (*rmp));
974  clib_memset (rmp, 0, sizeof (*rmp));
975  rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_DETAILS + sm->msg_id_base);
976  rmp->sw_if_index = ntohl (i->sw_if_index);
977 
978  if (nat_interface_is_inside (i))
979  rmp->flags |= NAT_API_IS_INSIDE;
980  if (nat_interface_is_outside (i))
981  rmp->flags |= NAT_API_IS_OUTSIDE;
982 
983  rmp->context = context;
984 
985  vl_api_send_msg (reg, (u8 *) rmp);
986 }
987 
988 static void
990 {
992  snat_main_t *sm = &snat_main;
994 
996  if (!reg)
997  return;
998 
999  /* *INDENT-OFF* */
1000  pool_foreach (i, sm->interfaces,
1001  ({
1002  send_nat44_interface_details(i, reg, mp->context);
1003  }));
1004  /* *INDENT-ON* */
1005 }
1006 
1007 static void *
1009  void *handle)
1010 {
1011  u8 *s;
1012 
1013  s = format (0, "SCRIPT: nat44_interface_dump ");
1014 
1015  FINISH;
1016 }
1017 
1018 static void
1021 {
1022  snat_main_t *sm = &snat_main;
1023  vl_api_nat44_interface_add_del_output_feature_reply_t *rmp;
1024  u32 sw_if_index = ntohl (mp->sw_if_index);
1025  int rv = 0;
1026 
1027  VALIDATE_SW_IF_INDEX (mp);
1028 
1029  rv = snat_interface_add_del_output_feature (sw_if_index,
1030  mp->flags & NAT_API_IS_INSIDE,
1031  !mp->is_add);
1032 
1034  REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY);
1035 }
1036 
1039 {
1040  u8 *s;
1041 
1042  s = format (0, "SCRIPT: nat44_interface_add_del_output_feature ");
1043  s = format (s, "sw_if_index %d %s %s",
1044  clib_host_to_net_u32 (mp->sw_if_index),
1045  mp->flags & NAT_API_IS_INSIDE ? "in" : "out",
1046  mp->is_add ? "" : "del");
1047 
1048  FINISH;
1049 }
1050 
1051 static void
1053  vl_api_registration_t * reg,
1054  u32 context)
1055 {
1057  snat_main_t *sm = &snat_main;
1058 
1059  rmp = vl_msg_api_alloc (sizeof (*rmp));
1060  clib_memset (rmp, 0, sizeof (*rmp));
1061  rmp->_vl_msg_id =
1062  ntohs (VL_API_NAT44_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base);
1063  rmp->sw_if_index = ntohl (i->sw_if_index);
1064  rmp->context = context;
1065 
1066  if (nat_interface_is_inside (i))
1067  rmp->flags |= NAT_API_IS_INSIDE;
1068 
1069  vl_api_send_msg (reg, (u8 *) rmp);
1070 }
1071 
1072 static void
1075 {
1076  vl_api_registration_t *reg;
1077  snat_main_t *sm = &snat_main;
1079 
1081  if (!reg)
1082  return;
1083 
1084  /* *INDENT-OFF* */
1086  ({
1087  send_nat44_interface_output_feature_details(i, reg, mp->context);
1088  }));
1089  /* *INDENT-ON* */
1090 }
1091 
1094 {
1095  u8 *s;
1096 
1097  s = format (0, "SCRIPT: nat44_interface_output_feature_dump ");
1098 
1099  FINISH;
1100 }
1101 
1102 static void
1105 {
1106  snat_main_t *sm = &snat_main;
1107  vl_api_nat44_add_del_static_mapping_reply_t *rmp;
1108  ip4_address_t local_addr, external_addr, pool_addr = { 0 };
1109  u16 local_port = 0, external_port = 0;
1110  u32 vrf_id, external_sw_if_index;
1112  int rv = 0;
1114  u8 *tag = 0;
1115 
1116  memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
1117  memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
1118 
1119  if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1120  {
1121  local_port = mp->local_port;
1122  external_port = mp->external_port;
1123  }
1124 
1125  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1126  external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
1127  proto = ip_proto_to_nat_proto (mp->protocol);
1128 
1129  if (mp->flags & NAT_API_IS_TWICE_NAT)
1130  twice_nat = TWICE_NAT;
1131  else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
1132  twice_nat = TWICE_NAT_SELF;
1133  mp->tag[sizeof (mp->tag) - 1] = 0;
1134  tag = format (0, "%s", mp->tag);
1135  vec_terminate_c_string (tag);
1136 
1137  rv = snat_add_static_mapping (local_addr, external_addr, local_port,
1138  external_port, vrf_id,
1139  mp->flags & NAT_API_IS_ADDR_ONLY,
1140  external_sw_if_index, proto,
1141  mp->is_add, twice_nat,
1142  mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, 0,
1143  pool_addr, 0);
1144  vec_free (tag);
1145 
1146  REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY);
1147 }
1148 
1149 static void
1152 {
1153  snat_main_t *sm = &snat_main;
1154  vl_api_nat44_add_del_static_mapping_v2_reply_t *rmp;
1155  ip4_address_t local_addr, external_addr, pool_addr;
1156  u16 local_port = 0, external_port = 0;
1157  u32 vrf_id, external_sw_if_index;
1159  int rv = 0;
1161  u8 *tag = 0;
1162 
1163  memcpy (&pool_addr.as_u8, mp->pool_ip_address, 4);
1164  memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
1165  memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
1166 
1167  if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1168  {
1169  local_port = mp->local_port;
1170  external_port = mp->external_port;
1171  }
1172 
1173  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1174  external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
1175  proto = ip_proto_to_nat_proto (mp->protocol);
1176 
1177  if (mp->flags & NAT_API_IS_TWICE_NAT)
1178  twice_nat = TWICE_NAT;
1179  else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
1180  twice_nat = TWICE_NAT_SELF;
1181  mp->tag[sizeof (mp->tag) - 1] = 0;
1182  tag = format (0, "%s", mp->tag);
1183  vec_terminate_c_string (tag);
1184 
1185  rv = snat_add_static_mapping (local_addr, external_addr, local_port,
1186  external_port, vrf_id,
1187  mp->flags & NAT_API_IS_ADDR_ONLY,
1188  external_sw_if_index, proto,
1189  mp->is_add, twice_nat,
1190  mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, 0,
1191  pool_addr, mp->match_pool);
1192  vec_free (tag);
1193 
1194  REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_V2_REPLY);
1195 }
1196 
1199 {
1200  u8 *s;
1201 
1202  s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
1203  s = format (s, "protocol %d local_addr %U external_addr %U ",
1204  mp->protocol,
1207 
1208  if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1209  s = format (s, "local_port %d external_port %d ",
1210  clib_net_to_host_u16 (mp->local_port),
1211  clib_net_to_host_u16 (mp->external_port));
1212 
1213  s = format (s, "twice_nat %d out2in_only %d ",
1214  mp->flags & NAT_API_IS_TWICE_NAT,
1215  mp->flags & NAT_API_IS_OUT2IN_ONLY);
1216 
1217  if (mp->vrf_id != ~0)
1218  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1219 
1220  if (mp->external_sw_if_index != ~0)
1221  s = format (s, "external_sw_if_index %d",
1222  clib_net_to_host_u32 (mp->external_sw_if_index));
1223  FINISH;
1224 }
1225 
1228 {
1229  u8 *s;
1230 
1231  s = format (0, "SCRIPT: nat44_add_del_static_mapping_v2 ");
1232  s = format (s, "protocol %d local_addr %U external_addr %U ",
1233  mp->protocol,
1236 
1237  if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1238  s = format (s, "local_port %d external_port %d ",
1239  clib_net_to_host_u16 (mp->local_port),
1240  clib_net_to_host_u16 (mp->external_port));
1241 
1242  s = format (s, "twice_nat %d out2in_only %d ",
1243  mp->flags & NAT_API_IS_TWICE_NAT,
1244  mp->flags & NAT_API_IS_OUT2IN_ONLY);
1245 
1246  if (mp->vrf_id != ~0)
1247  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1248 
1249  if (mp->external_sw_if_index != ~0)
1250  s = format (s, "external_sw_if_index %d",
1251  clib_net_to_host_u32 (mp->external_sw_if_index));
1252  if (mp->match_pool)
1253  s = format (s, "match pool address %U",
1255 
1256  FINISH;
1257 }
1258 
1259 static void
1261  vl_api_registration_t * reg, u32 context)
1262 {
1264  snat_main_t *sm = &snat_main;
1265  u32 len = sizeof (*rmp);
1266 
1267  rmp = vl_msg_api_alloc (len);
1268  clib_memset (rmp, 0, len);
1269  rmp->_vl_msg_id =
1270  ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1271 
1272  clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
1274  rmp->external_sw_if_index = ~0;
1275  rmp->vrf_id = htonl (m->vrf_id);
1276  rmp->context = context;
1277 
1278  if (m->twice_nat == TWICE_NAT)
1279  rmp->flags |= NAT_API_IS_TWICE_NAT;
1280  else if (m->twice_nat == TWICE_NAT_SELF)
1281  rmp->flags |= NAT_API_IS_SELF_TWICE_NAT;
1282 
1284  rmp->flags |= NAT_API_IS_OUT2IN_ONLY;
1285 
1287  {
1288  rmp->flags |= NAT_API_IS_ADDR_ONLY;
1289  }
1290  else
1291  {
1292  rmp->protocol = nat_proto_to_ip_proto (m->proto);
1293  rmp->external_port = m->external_port;
1294  rmp->local_port = m->local_port;
1295  }
1296 
1297  if (m->tag)
1298  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1299 
1300  vl_api_send_msg (reg, (u8 *) rmp);
1301 }
1302 
1303 static void
1305  vl_api_registration_t * reg,
1306  u32 context)
1307 {
1309  snat_main_t *sm = &snat_main;
1310 
1311  rmp = vl_msg_api_alloc (sizeof (*rmp));
1312  clib_memset (rmp, 0, sizeof (*rmp));
1313  rmp->_vl_msg_id =
1314  ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1315  clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
1316  rmp->external_sw_if_index = htonl (m->sw_if_index);
1317  rmp->vrf_id = htonl (m->vrf_id);
1318  rmp->context = context;
1319 
1320  if (m->twice_nat)
1321  rmp->flags |= NAT_API_IS_TWICE_NAT;
1322 
1323  if (m->addr_only)
1324  {
1325  rmp->flags |= NAT_API_IS_ADDR_ONLY;
1326  }
1327  else
1328  {
1329  rmp->protocol = nat_proto_to_ip_proto (m->proto);
1330  rmp->external_port = m->e_port;
1331  rmp->local_port = m->l_port;
1332  }
1333  if (m->tag)
1334  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1335 
1336  vl_api_send_msg (reg, (u8 *) rmp);
1337 }
1338 
1339 static void
1341  * mp)
1342 {
1343  vl_api_registration_t *reg;
1344  snat_main_t *sm = &snat_main;
1347  int j;
1348 
1350  if (!reg)
1351  return;
1352 
1353  /* *INDENT-OFF* */
1354  pool_foreach (m, sm->static_mappings,
1355  ({
1356  if (!is_identity_static_mapping(m) && !is_lb_static_mapping (m))
1357  send_nat44_static_mapping_details (m, reg, mp->context);
1358  }));
1359  /* *INDENT-ON* */
1360 
1361  for (j = 0; j < vec_len (sm->to_resolve); j++)
1362  {
1363  rp = sm->to_resolve + j;
1364  if (!rp->identity_nat)
1366  }
1367 }
1368 
1369 static void *
1371  mp, void *handle)
1372 {
1373  u8 *s;
1374 
1375  s = format (0, "SCRIPT: nat44_static_mapping_dump ");
1376 
1377  FINISH;
1378 }
1379 
1380 static void
1383 {
1384  snat_main_t *sm = &snat_main;
1385  vl_api_nat44_add_del_identity_mapping_reply_t *rmp;
1386  ip4_address_t addr, pool_addr = { 0 };
1387  u16 port = 0;
1389  int rv = 0;
1390  nat_protocol_t proto = NAT_PROTOCOL_OTHER;
1391  u8 *tag = 0;
1392 
1393  if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1394  {
1395  port = mp->port;
1396  proto = ip_proto_to_nat_proto (mp->protocol);
1397  }
1398  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1399  sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1400  if (sw_if_index != ~0)
1401  addr.as_u32 = 0;
1402  else
1403  memcpy (&addr.as_u8, mp->ip_address, 4);
1404  mp->tag[sizeof (mp->tag) - 1] = 0;
1405  tag = format (0, "%s", mp->tag);
1406  vec_terminate_c_string (tag);
1407 
1408  rv =
1409  snat_add_static_mapping (addr, addr, port, port, vrf_id,
1410  mp->flags & NAT_API_IS_ADDR_ONLY, sw_if_index,
1411  proto, mp->is_add, 0, 0, tag, 1, pool_addr, 0);
1412  vec_free (tag);
1413 
1414  REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY);
1415 }
1416 
1419 {
1420  u8 *s;
1421 
1422  s = format (0, "SCRIPT: nat44_add_del_identity_mapping ");
1423  if (mp->sw_if_index != ~0)
1424  s = format (s, "sw_if_index %d", clib_net_to_host_u32 (mp->sw_if_index));
1425  else
1426  s = format (s, "addr %U", format_ip4_address, mp->ip_address);
1427 
1428  if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1429  s =
1430  format (s, " protocol %d port %d", mp->protocol,
1431  clib_net_to_host_u16 (mp->port));
1432 
1433  if (mp->vrf_id != ~0)
1434  s = format (s, " vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1435 
1436  FINISH;
1437 }
1438 
1439 static void
1441  vl_api_registration_t * reg, u32 context)
1442 {
1444  snat_main_t *sm = &snat_main;
1445  nat44_lb_addr_port_t *local = pool_elt_at_index (m->locals, index);
1446 
1447  rmp = vl_msg_api_alloc (sizeof (*rmp));
1448  clib_memset (rmp, 0, sizeof (*rmp));
1449  rmp->_vl_msg_id =
1450  ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
1451 
1453  rmp->flags |= NAT_API_IS_ADDR_ONLY;
1454 
1455  clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
1456  rmp->port = m->local_port;
1457  rmp->sw_if_index = ~0;
1458  rmp->vrf_id = htonl (local->vrf_id);
1459  rmp->protocol = nat_proto_to_ip_proto (m->proto);
1460  rmp->context = context;
1461  if (m->tag)
1462  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1463 
1464  vl_api_send_msg (reg, (u8 *) rmp);
1465 }
1466 
1467 static void
1469  vl_api_registration_t * reg,
1470  u32 context)
1471 {
1473  snat_main_t *sm = &snat_main;
1474 
1475  rmp = vl_msg_api_alloc (sizeof (*rmp));
1476  clib_memset (rmp, 0, sizeof (*rmp));
1477  rmp->_vl_msg_id =
1478  ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
1479 
1480  if (m->addr_only)
1481  rmp->flags = (vl_api_nat_config_flags_t) NAT_API_IS_ADDR_ONLY;
1482 
1483  rmp->port = m->l_port;
1484  rmp->sw_if_index = htonl (m->sw_if_index);
1485  rmp->vrf_id = htonl (m->vrf_id);
1486  rmp->protocol = nat_proto_to_ip_proto (m->proto);
1487  rmp->context = context;
1488  if (m->tag)
1489  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1490 
1491  vl_api_send_msg (reg, (u8 *) rmp);
1492 }
1493 
1494 static void
1497 {
1498  vl_api_registration_t *reg;
1499  snat_main_t *sm = &snat_main;
1502  int j;
1503 
1505  if (!reg)
1506  return;
1507 
1508  /* *INDENT-OFF* */
1509  pool_foreach (m, sm->static_mappings,
1510  ({
1511  if (is_identity_static_mapping(m) && !is_lb_static_mapping (m))
1512  {
1513  pool_foreach_index (j, m->locals,
1514  ({
1515  send_nat44_identity_mapping_details (m, j, reg, mp->context);
1516  }));
1517  }
1518  }));
1519  /* *INDENT-ON* */
1520 
1521  for (j = 0; j < vec_len (sm->to_resolve); j++)
1522  {
1523  rp = sm->to_resolve + j;
1524  if (rp->identity_nat)
1526  }
1527 }
1528 
1531 {
1532  u8 *s;
1533 
1534  s = format (0, "SCRIPT: nat44_identity_mapping_dump ");
1535 
1536  FINISH;
1537 }
1538 
1539 static void
1542 {
1543  snat_main_t *sm = &snat_main;
1544  vl_api_nat44_add_del_interface_addr_reply_t *rmp;
1545  u32 sw_if_index = ntohl (mp->sw_if_index);
1546  int rv = 0;
1547  u8 is_del;
1548 
1549  is_del = !mp->is_add;
1550 
1551  VALIDATE_SW_IF_INDEX (mp);
1552 
1553  rv = snat_add_interface_address (sm, sw_if_index, is_del,
1554  mp->flags & NAT_API_IS_TWICE_NAT);
1555 
1557  REPLY_MACRO (VL_API_NAT44_ADD_DEL_INTERFACE_ADDR_REPLY);
1558 }
1559 
1562 {
1563  u8 *s;
1564 
1565  s = format (0, "SCRIPT: nat44_add_del_interface_addr ");
1566  s = format (s, "sw_if_index %d twice_nat %d %s",
1567  clib_host_to_net_u32 (mp->sw_if_index),
1568  mp->flags & NAT_API_IS_TWICE_NAT, mp->is_add ? "" : "del");
1569 
1570  FINISH;
1571 }
1572 
1573 static void
1575  vl_api_registration_t * reg, u32 context,
1576  u8 twice_nat)
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_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
1585  rmp->sw_if_index = ntohl (sw_if_index);
1586 
1587  if (twice_nat)
1588  rmp->flags = (vl_api_nat_config_flags_t) NAT_API_IS_TWICE_NAT;
1589  rmp->context = context;
1590 
1591  vl_api_send_msg (reg, (u8 *) rmp);
1592 }
1593 
1594 static void
1596  * mp)
1597 {
1598  vl_api_registration_t *reg;
1599  snat_main_t *sm = &snat_main;
1600  u32 *i;
1601 
1603  if (!reg)
1604  return;
1605 
1606  /* *INDENT-OFF* */
1608  send_nat44_interface_addr_details(*i, reg, mp->context, 0);
1610  send_nat44_interface_addr_details(*i, reg, mp->context, 1);
1611  /* *INDENT-ON* */
1612 }
1613 
1614 static void *
1616  mp, void *handle)
1617 {
1618  u8 *s;
1619 
1620  s = format (0, "SCRIPT: nat44_interface_addr_dump ");
1621 
1622  FINISH;
1623 }
1624 
1625 static void
1627  u32 context)
1628 {
1630  snat_main_t *sm = &snat_main;
1631  ip4_main_t *im = &ip4_main;
1632 
1633  rmp = vl_msg_api_alloc (sizeof (*rmp));
1634  clib_memset (rmp, 0, sizeof (*rmp));
1635  rmp->_vl_msg_id = ntohs (VL_API_NAT44_USER_DETAILS + sm->msg_id_base);
1636 
1637  if (!pool_is_free_index (im->fibs, u->fib_index))
1638  {
1640  rmp->vrf_id = ntohl (fib->ft_table_id);
1641  }
1642 
1643  clib_memcpy (rmp->ip_address, &(u->addr), 4);
1644  rmp->nsessions = ntohl (u->nsessions);
1645  rmp->nstaticsessions = ntohl (u->nstaticsessions);
1646  rmp->context = context;
1647 
1648  vl_api_send_msg (reg, (u8 *) rmp);
1649 }
1650 
1651 static void
1653  snat_session_t * s)
1654 {
1655  snat_user_key_t k;
1656  k.addr = s->in2out.addr;
1657  k.fib_index = s->in2out.fib_index;
1659  key.key = k.as_u64;
1660  snat_user_t *u;
1661  if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
1662  {
1663  pool_get (tsm->users, u);
1664  u->addr = k.addr;
1665  u->fib_index = k.fib_index;
1666  u->nsessions = 0;
1667  u->nstaticsessions = 0;
1668  key.value = u - tsm->users;
1669  clib_bihash_add_del_8_8 (&tsm->user_hash, &key, 1);
1670  }
1671  else
1672  {
1673  u = pool_elt_at_index (tsm->users, value.value);
1674  }
1675  if (snat_is_session_static (s))
1676  {
1677  ++u->nstaticsessions;
1678  }
1679  else
1680  {
1681  ++u->nsessions;
1682  }
1683 }
1684 
1685 static void
1687 {
1688  snat_session_t *s;
1689  /* *INDENT-OFF* */
1690  pool_foreach (s, tsm->sessions, { nat_ed_user_create_helper (tsm, s); });
1691  /* *INDENT-ON* */
1692 }
1693 
1694 static void
1696 {
1697  snat_user_t *u;
1698  /* *INDENT-OFF* */
1699  pool_flush (u, tsm->users, { });
1700  /* *INDENT-ON* */
1701  clib_bihash_free_8_8 (&tsm->user_hash);
1702  clib_bihash_init_8_8 (&tsm->user_hash, "users", snat_main.user_buckets,
1704  clib_bihash_set_kvp_format_fn_8_8 (&tsm->user_hash, format_user_kvp);
1705 }
1706 
1707 static void
1709 {
1710  vl_api_registration_t *reg;
1711  snat_main_t *sm = &snat_main;
1713  snat_user_t *u;
1714 
1716  if (!reg)
1717  return;
1718 
1719  /* *INDENT-OFF* */
1720  vec_foreach (tsm, sm->per_thread_data)
1721  {
1722  if (sm->endpoint_dependent)
1723  {
1724  nat_ed_users_create (tsm);
1725  }
1726  pool_foreach (u, tsm->users,
1727  ({
1728  send_nat44_user_details (u, reg, mp->context);
1729  }));
1730  if (sm->endpoint_dependent)
1731  {
1732  nat_ed_users_destroy (tsm);
1733  }
1734  }
1735  /* *INDENT-ON* */
1736 }
1737 
1738 static void *
1740 {
1741  u8 *s;
1742 
1743  s = format (0, "SCRIPT: nat44_user_dump ");
1744 
1745  FINISH;
1746 }
1747 
1748 static void
1750  vl_api_registration_t * reg, u32 context)
1751 {
1753  snat_main_t *sm = &snat_main;
1754 
1755  rmp = vl_msg_api_alloc (sizeof (*rmp));
1756  clib_memset (rmp, 0, sizeof (*rmp));
1757  rmp->_vl_msg_id =
1758  ntohs (VL_API_NAT44_USER_SESSION_DETAILS + sm->msg_id_base);
1759  clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
1760  clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
1761 
1762  if (snat_is_session_static (s))
1763  rmp->flags |= NAT_API_IS_STATIC;
1764 
1765  if (is_twice_nat_session (s))
1766  rmp->flags |= NAT_API_IS_TWICE_NAT;
1767 
1768  if (is_ed_session (s) || is_fwd_bypass_session (s))
1769  rmp->flags |= NAT_API_IS_EXT_HOST_VALID;
1770 
1771  rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
1772  rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
1773  rmp->total_pkts = ntohl (s->total_pkts);
1774  rmp->context = context;
1775  if (snat_is_unk_proto_session (s))
1776  {
1777  rmp->outside_port = 0;
1778  rmp->inside_port = 0;
1779  rmp->protocol = ntohs (s->in2out.port);
1780  }
1781  else
1782  {
1783  rmp->outside_port = s->out2in.port;
1784  rmp->inside_port = s->in2out.port;
1785  rmp->protocol = ntohs (nat_proto_to_ip_proto (s->nat_proto));
1786  }
1787  if (is_ed_session (s) || is_fwd_bypass_session (s))
1788  {
1789  clib_memcpy (rmp->ext_host_address, &s->ext_host_addr, 4);
1790  rmp->ext_host_port = s->ext_host_port;
1791  if (is_twice_nat_session (s))
1792  {
1793  clib_memcpy (rmp->ext_host_nat_address, &s->ext_host_nat_addr, 4);
1794  rmp->ext_host_nat_port = s->ext_host_nat_port;
1795  }
1796  }
1797 
1798  vl_api_send_msg (reg, (u8 *) rmp);
1799 }
1800 
1801 static void
1803  mp)
1804 {
1805  vl_api_registration_t *reg;
1806  snat_main_t *sm = &snat_main;
1808  snat_session_t *s;
1810  snat_user_key_t ukey;
1811  snat_user_t *u;
1812  u32 session_index, head_index, elt_index;
1813  dlist_elt_t *head, *elt;
1814  ip4_header_t ip;
1815 
1817  if (!reg)
1818  return;
1819 
1820  clib_memcpy (&ukey.addr, mp->ip_address, 4);
1821  ip.src_address.as_u32 = ukey.addr.as_u32;
1822  ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
1823  key.key = ukey.as_u64;
1824  if (sm->num_workers > 1)
1825  tsm =
1827  sm->worker_in2out_cb (&ip, ukey.fib_index, 0));
1828  else
1829  tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
1830  if (!sm->endpoint_dependent)
1831  {
1832  if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
1833  return;
1834  u = pool_elt_at_index (tsm->users, value.value);
1835  if (!u->nsessions && !u->nstaticsessions)
1836  return;
1837 
1838  head_index = u->sessions_per_user_list_head_index;
1839  head = pool_elt_at_index (tsm->list_pool, head_index);
1840  elt_index = head->next;
1841  elt = pool_elt_at_index (tsm->list_pool, elt_index);
1842  session_index = elt->value;
1843  while (session_index != ~0)
1844  {
1845  s = pool_elt_at_index (tsm->sessions, session_index);
1846 
1848 
1849  elt_index = elt->next;
1850  elt = pool_elt_at_index (tsm->list_pool, elt_index);
1851  session_index = elt->value;
1852  }
1853  }
1854  else
1855  {
1856  /* *INDENT-OFF* */
1857  pool_foreach (s, tsm->sessions, {
1858  if (s->in2out.addr.as_u32 == ukey.addr.as_u32)
1859  {
1860  send_nat44_user_session_details (s, reg, mp->context);
1861  }
1862  });
1863  /* *INDENT-ON* */
1864  }
1865 }
1866 
1867 static void *
1869  void *handle)
1870 {
1871  u8 *s;
1872 
1873  s = format (0, "SCRIPT: nat44_user_session_dump ");
1874  s = format (s, "ip_address %U vrf_id %d\n",
1876  clib_net_to_host_u32 (mp->vrf_id));
1877 
1878  FINISH;
1879 }
1880 
1881 static nat44_lb_addr_port_t *
1882 unformat_nat44_lb_addr_port (vl_api_nat44_lb_addr_port_t * addr_port_pairs,
1883  u32 addr_port_pair_num)
1884 {
1885  u8 i;
1886  nat44_lb_addr_port_t *lb_addr_port_pairs = 0, lb_addr_port;
1887  vl_api_nat44_lb_addr_port_t *ap;
1888 
1889  for (i = 0; i < addr_port_pair_num; i++)
1890  {
1891  ap = &addr_port_pairs[i];
1892  clib_memset (&lb_addr_port, 0, sizeof (lb_addr_port));
1893  clib_memcpy (&lb_addr_port.addr, ap->addr, 4);
1894  lb_addr_port.port = ap->port;
1895  lb_addr_port.probability = ap->probability;
1896  lb_addr_port.vrf_id = clib_net_to_host_u32 (ap->vrf_id);
1897  vec_add1 (lb_addr_port_pairs, lb_addr_port);
1898  }
1899 
1900  return lb_addr_port_pairs;
1901 }
1902 
1903 static void
1906 {
1907  snat_main_t *sm = &snat_main;
1908  vl_api_nat44_add_del_lb_static_mapping_reply_t *rmp;
1910  int rv = 0;
1911  nat44_lb_addr_port_t *locals = 0;
1912  ip4_address_t e_addr;
1914  u8 *tag = 0;
1915 
1916  if (!sm->endpoint_dependent)
1917  {
1918  rv = VNET_API_ERROR_UNSUPPORTED;
1919  goto send_reply;
1920  }
1921 
1922  locals =
1924  clib_net_to_host_u32 (mp->local_num));
1925  clib_memcpy (&e_addr, mp->external_addr, 4);
1926  proto = ip_proto_to_nat_proto (mp->protocol);
1927 
1928  if (mp->flags & NAT_API_IS_TWICE_NAT)
1929  twice_nat = TWICE_NAT;
1930  else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
1931  twice_nat = TWICE_NAT_SELF;
1932  mp->tag[sizeof (mp->tag) - 1] = 0;
1933  tag = format (0, "%s", mp->tag);
1934  vec_terminate_c_string (tag);
1935 
1936  rv =
1938  mp->external_port,
1939  proto, locals, mp->is_add,
1940  twice_nat,
1941  mp->flags & NAT_API_IS_OUT2IN_ONLY, tag,
1942  clib_net_to_host_u32 (mp->affinity));
1943 
1944  vec_free (locals);
1945  vec_free (tag);
1946 
1947 send_reply:
1948  REPLY_MACRO (VL_API_NAT44_ADD_DEL_LB_STATIC_MAPPING_REPLY);
1949 }
1950 
1953 {
1954  u8 *s;
1955 
1956  s = format (0, "SCRIPT: nat44_add_del_lb_static_mapping ");
1957  s = format (s, "is_add %d twice_nat %d out2in_only %d ",
1958  mp->is_add,
1959  mp->flags & NAT_API_IS_TWICE_NAT,
1960  mp->flags & NAT_API_IS_OUT2IN_ONLY);
1961 
1962  FINISH;
1963 }
1964 
1965 static void
1968 {
1969  snat_main_t *sm = &snat_main;
1970  vl_api_nat44_lb_static_mapping_add_del_local_reply_t *rmp;
1971  int rv = 0;
1972  ip4_address_t e_addr, l_addr;
1974 
1975  if (!sm->endpoint_dependent)
1976  {
1977  rv = VNET_API_ERROR_UNSUPPORTED;
1978  goto send_reply;
1979  }
1980 
1981  clib_memcpy (&e_addr, mp->external_addr, 4);
1982  clib_memcpy (&l_addr, mp->local.addr, 4);
1983  proto = ip_proto_to_nat_proto (mp->protocol);
1984 
1985  rv =
1987  clib_net_to_host_u16
1988  (mp->external_port), l_addr,
1989  clib_net_to_host_u16 (mp->
1990  local.port),
1991  proto,
1992  clib_net_to_host_u32 (mp->
1993  local.vrf_id),
1994  mp->local.probability, mp->is_add);
1995 
1996 send_reply:
1997  REPLY_MACRO (VL_API_NAT44_LB_STATIC_MAPPING_ADD_DEL_LOCAL_REPLY);
1998 }
1999 
2002 {
2003  u8 *s;
2004 
2005  s = format (0, "SCRIPT: nat44_lb_static_mapping_add_del_local ");
2006  s = format (s, "is_add %d", mp->is_add);
2007 
2008  FINISH;
2009 }
2010 
2011 static void
2013  vl_api_registration_t * reg,
2014  u32 context)
2015 {
2017  snat_main_t *sm = &snat_main;
2019  vl_api_nat44_lb_addr_port_t *locals;
2020  u32 local_num = 0;
2021 
2022  rmp =
2023  vl_msg_api_alloc (sizeof (*rmp) +
2024  (pool_elts (m->locals) *
2025  sizeof (nat44_lb_addr_port_t)));
2026  clib_memset (rmp, 0, sizeof (*rmp));
2027  rmp->_vl_msg_id =
2028  ntohs (VL_API_NAT44_LB_STATIC_MAPPING_DETAILS + sm->msg_id_base);
2029 
2030  clib_memcpy (rmp->external_addr, &(m->external_addr), 4);
2031  rmp->external_port = m->external_port;
2032  rmp->protocol = nat_proto_to_ip_proto (m->proto);
2033  rmp->context = context;
2034 
2035  if (m->twice_nat == TWICE_NAT)
2036  rmp->flags |= NAT_API_IS_TWICE_NAT;
2037  else if (m->twice_nat == TWICE_NAT_SELF)
2038  rmp->flags |= NAT_API_IS_SELF_TWICE_NAT;
2040  rmp->flags |= NAT_API_IS_OUT2IN_ONLY;
2041  if (m->tag)
2042  strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
2043 
2044  locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
2045  /* *INDENT-OFF* */
2046  pool_foreach (ap, m->locals,
2047  ({
2048  clib_memcpy (locals->addr, &(ap->addr), 4);
2049  locals->port = ap->port;
2050  locals->probability = ap->probability;
2051  locals->vrf_id = ntohl (ap->vrf_id);
2052  locals++;
2053  local_num++;
2054  }));
2055  /* *INDENT-ON* */
2056  rmp->local_num = ntohl (local_num);
2057 
2058  vl_api_send_msg (reg, (u8 *) rmp);
2059 }
2060 
2061 static void
2064 {
2065  vl_api_registration_t *reg;
2066  snat_main_t *sm = &snat_main;
2068 
2069  if (!sm->endpoint_dependent)
2070  return;
2071 
2073  if (!reg)
2074  return;
2075 
2076  /* *INDENT-OFF* */
2077  pool_foreach (m, sm->static_mappings,
2078  ({
2079  if (is_lb_static_mapping(m))
2080  send_nat44_lb_static_mapping_details (m, reg, mp->context);
2081  }));
2082  /* *INDENT-ON* */
2083 }
2084 
2087 {
2088  u8 *s;
2089 
2090  s = format (0, "SCRIPT: nat44_lb_static_mapping_dump ");
2091 
2092  FINISH;
2093 }
2094 
2095 static void
2097 {
2098  snat_main_t *sm = &snat_main;
2099  vl_api_nat44_del_session_reply_t *rmp;
2100  ip4_address_t addr, eh_addr;
2101  u16 port, eh_port;
2102  u32 vrf_id;
2103  int rv = 0;
2104  u8 is_in;
2106 
2107  memcpy (&addr.as_u8, mp->address, 4);
2108  port = mp->port;
2109  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
2110  proto = ip_proto_to_nat_proto (mp->protocol);
2111  memcpy (&eh_addr.as_u8, mp->ext_host_address, 4);
2112  eh_port = mp->ext_host_port;
2113 
2114  is_in = mp->flags & NAT_API_IS_INSIDE;
2115 
2116  if (mp->flags & NAT_API_IS_EXT_HOST_VALID)
2117  rv =
2118  nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port, mp->protocol,
2119  vrf_id, is_in);
2120  else
2121  rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
2122 
2123  REPLY_MACRO (VL_API_NAT44_DEL_SESSION_REPLY);
2124 }
2125 
2126 static void *
2128  void *handle)
2129 {
2130  u8 *s;
2131 
2132  s = format (0, "SCRIPT: nat44_add_del_session ");
2133  s = format (s, "addr %U port %d protocol %d vrf_id %d is_in %d",
2135  clib_net_to_host_u16 (mp->port),
2136  mp->protocol, clib_net_to_host_u32 (mp->vrf_id),
2137  mp->flags & NAT_API_IS_INSIDE);
2138  if (mp->flags & NAT_API_IS_EXT_HOST_VALID)
2139  s = format (s, "ext_host_address %U ext_host_port %d",
2141  clib_net_to_host_u16 (mp->ext_host_port));
2142 
2143  FINISH;
2144 }
2145 
2146 static void
2149 {
2150  snat_main_t *sm = &snat_main;
2151  vl_api_nat44_forwarding_enable_disable_reply_t *rmp;
2152  int rv = 0;
2153  u32 *ses_to_be_removed = 0, *ses_index;
2155  snat_session_t *s;
2156 
2157  sm->forwarding_enabled = mp->enable != 0;
2158 
2159  if (mp->enable == 0)
2160  {
2161  /* *INDENT-OFF* */
2162  vec_foreach (tsm, sm->per_thread_data)
2163  {
2164  pool_foreach (s, tsm->sessions,
2165  ({
2166  if (is_fwd_bypass_session(s))
2167  {
2168  vec_add1 (ses_to_be_removed, s - tsm->sessions);
2169  }
2170  }));
2171  if(sm->endpoint_dependent){
2172  vec_foreach (ses_index, ses_to_be_removed)
2173  {
2174  s = pool_elt_at_index(tsm->sessions, ses_index[0]);
2175  nat_free_session_data (sm, s, tsm - sm->per_thread_data, 0);
2176  nat_ed_session_delete (sm, s, tsm - sm->per_thread_data, 1);
2177  }
2178  }else{
2179  vec_foreach (ses_index, ses_to_be_removed)
2180  {
2181  s = pool_elt_at_index(tsm->sessions, ses_index[0]);
2182  nat_free_session_data (sm, s, tsm - sm->per_thread_data, 0);
2183  nat44_delete_session (sm, s, tsm - sm->per_thread_data);
2184  }
2185  }
2186  vec_free (ses_to_be_removed);
2187  }
2188  /* *INDENT-ON* */
2189  }
2190 
2191  REPLY_MACRO (VL_API_NAT44_FORWARDING_ENABLE_DISABLE_REPLY);
2192 }
2193 
2196 {
2197  u8 *s;
2198 
2199  s = format (0, "SCRIPT: nat44_forwarding_enable_disable ");
2200  s = format (s, "enable %d", mp->enable != 0);
2201 
2202  FINISH;
2203 }
2204 
2205 static void
2208 {
2209  vl_api_registration_t *reg;
2210  snat_main_t *sm = &snat_main;
2212 
2214  if (!reg)
2215  return;
2216 
2217  rmp = vl_msg_api_alloc (sizeof (*rmp));
2218  clib_memset (rmp, 0, sizeof (*rmp));
2219  rmp->_vl_msg_id =
2220  ntohs (VL_API_NAT44_FORWARDING_IS_ENABLED_REPLY + sm->msg_id_base);
2221  rmp->context = mp->context;
2222 
2223  rmp->enabled = sm->forwarding_enabled;
2224 
2225  vl_api_send_msg (reg, (u8 *) rmp);
2226 }
2227 
2230 {
2231  u8 *s;
2232 
2233  s = format (0, "SCRIPT: nat44_forwarding_is_enabled ");
2234 
2235  FINISH;
2236 }
2237 
2238 /*************/
2239 /*** NAT64 ***/
2240 /*************/
2241 
2242 static void
2245 {
2246  vl_api_nat64_add_del_pool_addr_range_reply_t *rmp;
2247  snat_main_t *sm = &snat_main;
2248  int rv = 0;
2249  ip4_address_t this_addr;
2250  u32 start_host_order, end_host_order;
2251  u32 vrf_id;
2252  int i, count;
2253  u32 *tmp;
2254 
2255  tmp = (u32 *) mp->start_addr;
2256  start_host_order = clib_host_to_net_u32 (tmp[0]);
2257  tmp = (u32 *) mp->end_addr;
2258  end_host_order = clib_host_to_net_u32 (tmp[0]);
2259 
2260  count = (end_host_order - start_host_order) + 1;
2261 
2262  vrf_id = clib_host_to_net_u32 (mp->vrf_id);
2263 
2264  memcpy (&this_addr.as_u8, mp->start_addr, 4);
2265 
2266  for (i = 0; i < count; i++)
2267  {
2268  if ((rv = nat64_add_del_pool_addr (0, &this_addr, vrf_id, mp->is_add)))
2269  goto send_reply;
2270 
2271  increment_v4_address (&this_addr);
2272  }
2273 
2274 send_reply:
2275  REPLY_MACRO (VL_API_NAT64_ADD_DEL_POOL_ADDR_RANGE_REPLY);
2276 }
2277 
2280 {
2281  u8 *s;
2282 
2283  s = format (0, "SCRIPT: nat64_add_del_pool_addr_range ");
2284  s = format (s, "%U - %U vrf_id %u %s\n",
2287  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
2288 
2289  FINISH;
2290 }
2291 
2293 {
2298 
2299 static int
2301 {
2303  snat_main_t *sm = &snat_main;
2304  nat64_api_walk_ctx_t *ctx = arg;
2305 
2306  rmp = vl_msg_api_alloc (sizeof (*rmp));
2307  clib_memset (rmp, 0, sizeof (*rmp));
2308  rmp->_vl_msg_id = ntohs (VL_API_NAT64_POOL_ADDR_DETAILS + sm->msg_id_base);
2309  clib_memcpy (rmp->address, &(a->addr), 4);
2310  if (a->fib_index != ~0)
2311  {
2313  if (!fib)
2314  return -1;
2315  rmp->vrf_id = ntohl (fib->ft_table_id);
2316  }
2317  else
2318  rmp->vrf_id = ~0;
2319  rmp->context = ctx->context;
2320 
2321  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2322 
2323  return 0;
2324 }
2325 
2326 static void
2328 {
2330 
2332  if (!reg)
2333  return;
2334 
2336  .reg = reg,
2337  .context = mp->context,
2338  };
2339 
2341 }
2342 
2343 static void *
2345  void *handle)
2346 {
2347  u8 *s;
2348 
2349  s = format (0, "SCRIPT: nat64_pool_addr_dump\n");
2350 
2351  FINISH;
2352 }
2353 
2354 static void
2356  mp)
2357 {
2358  snat_main_t *sm = &snat_main;
2359  vl_api_nat64_add_del_interface_reply_t *rmp;
2360  int rv = 0;
2361 
2362  VALIDATE_SW_IF_INDEX (mp);
2363 
2364  rv =
2365  nat64_add_del_interface (ntohl (mp->sw_if_index),
2366  mp->flags & NAT_API_IS_INSIDE, mp->is_add);
2367 
2369 
2370  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_REPLY);
2371 }
2372 
2373 static void *
2375  void *handle)
2376 {
2377  u8 *s;
2378 
2379  s = format (0, "SCRIPT: nat64_add_del_interface ");
2380  s = format (s, "sw_if_index %d %s %s",
2381  clib_host_to_net_u32 (mp->sw_if_index),
2382  mp->flags & NAT_API_IS_INSIDE ? "in" : "out",
2383  mp->is_add ? "" : "del");
2384 
2385  FINISH;
2386 }
2387 
2388 static int
2390 {
2392  snat_main_t *sm = &snat_main;
2393  nat64_api_walk_ctx_t *ctx = arg;
2394 
2395  rmp = vl_msg_api_alloc (sizeof (*rmp));
2396  clib_memset (rmp, 0, sizeof (*rmp));
2397  rmp->_vl_msg_id = ntohs (VL_API_NAT64_INTERFACE_DETAILS + sm->msg_id_base);
2398  rmp->sw_if_index = ntohl (i->sw_if_index);
2399 
2400  if (nat_interface_is_inside (i))
2401  rmp->flags |= NAT_API_IS_INSIDE;
2402  if (nat_interface_is_outside (i))
2403  rmp->flags |= NAT_API_IS_OUTSIDE;
2404 
2405  rmp->context = ctx->context;
2406 
2407  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2408 
2409  return 0;
2410 }
2411 
2412 static void
2414 {
2416 
2418  if (!reg)
2419  return;
2420 
2422  .reg = reg,
2423  .context = mp->context,
2424  };
2425 
2427 }
2428 
2429 static void *
2431  void *handle)
2432 {
2433  u8 *s;
2434 
2435  s = format (0, "SCRIPT: snat_interface_dump ");
2436 
2437  FINISH;
2438 }
2439 
2440 static void
2443 {
2444  snat_main_t *sm = &snat_main;
2445  vl_api_nat64_add_del_static_bib_reply_t *rmp;
2446  ip6_address_t in_addr;
2447  ip4_address_t out_addr;
2448  int rv = 0;
2449 
2450  memcpy (&in_addr.as_u8, mp->i_addr, 16);
2451  memcpy (&out_addr.as_u8, mp->o_addr, 4);
2452 
2453  rv =
2454  nat64_add_del_static_bib_entry (&in_addr, &out_addr,
2455  clib_net_to_host_u16 (mp->i_port),
2456  clib_net_to_host_u16 (mp->o_port),
2457  mp->proto,
2458  clib_net_to_host_u32 (mp->vrf_id),
2459  mp->is_add);
2460 
2461  REPLY_MACRO (VL_API_NAT64_ADD_DEL_STATIC_BIB_REPLY);
2462 }
2463 
2466 {
2467  u8 *s;
2468 
2469  s = format (0, "SCRIPT: nat64_add_del_static_bib ");
2470  s = format (s, "protocol %d i_addr %U o_addr %U ",
2471  mp->proto,
2473 
2474  if (mp->vrf_id != ~0)
2475  s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
2476 
2477  FINISH;
2478 }
2479 
2480 static int
2481 nat64_api_bib_walk (nat64_db_bib_entry_t * bibe, void *arg)
2482 {
2484  snat_main_t *sm = &snat_main;
2485  nat64_api_walk_ctx_t *ctx = arg;
2486  fib_table_t *fib;
2487 
2488  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
2489  if (!fib)
2490  return -1;
2491 
2492  rmp = vl_msg_api_alloc (sizeof (*rmp));
2493  clib_memset (rmp, 0, sizeof (*rmp));
2494  rmp->_vl_msg_id = ntohs (VL_API_NAT64_BIB_DETAILS + sm->msg_id_base);
2495  rmp->context = ctx->context;
2496  clib_memcpy (rmp->i_addr, &(bibe->in_addr), 16);
2497  clib_memcpy (rmp->o_addr, &(bibe->out_addr), 4);
2498  rmp->i_port = bibe->in_port;
2499  rmp->o_port = bibe->out_port;
2500  rmp->vrf_id = ntohl (fib->ft_table_id);
2501  rmp->proto = bibe->proto;
2502  if (bibe->is_static)
2503  rmp->flags |= NAT_API_IS_STATIC;
2504  rmp->ses_num = ntohl (bibe->ses_num);
2505 
2506  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2507 
2508  return 0;
2509 }
2510 
2511 static void
2513 {
2515  nat64_main_t *nm = &nat64_main;
2516  nat64_db_t *db;
2517 
2519  if (!reg)
2520  return;
2521 
2523  .reg = reg,
2524  .context = mp->context,
2525  };
2526 
2527  /* *INDENT-OFF* */
2528  vec_foreach (db, nm->db)
2529  nat64_db_bib_walk (db, mp->proto, nat64_api_bib_walk, &ctx);
2530  /* *INDENT-ON* */
2531 }
2532 
2533 static void *
2535 {
2536  u8 *s;
2537 
2538  s = format (0, "SCRIPT: snat_bib_dump protocol %d", mp->proto);
2539 
2540  FINISH;
2541 }
2542 
2543 static int
2544 nat64_api_st_walk (nat64_db_st_entry_t * ste, void *arg)
2545 {
2547  snat_main_t *sm = &snat_main;
2548  nat64_api_walk_ctx_t *ctx = arg;
2549  nat64_db_bib_entry_t *bibe;
2550  fib_table_t *fib;
2551 
2552  bibe = nat64_db_bib_entry_by_index (ctx->db, ste->proto, ste->bibe_index);
2553  if (!bibe)
2554  return -1;
2555 
2556  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
2557  if (!fib)
2558  return -1;
2559 
2560  rmp = vl_msg_api_alloc (sizeof (*rmp));
2561  clib_memset (rmp, 0, sizeof (*rmp));
2562  rmp->_vl_msg_id = ntohs (VL_API_NAT64_ST_DETAILS + sm->msg_id_base);
2563  rmp->context = ctx->context;
2564  clib_memcpy (rmp->il_addr, &(bibe->in_addr), 16);
2565  clib_memcpy (rmp->ol_addr, &(bibe->out_addr), 4);
2566  rmp->il_port = bibe->in_port;
2567  rmp->ol_port = bibe->out_port;
2568  clib_memcpy (rmp->ir_addr, &(ste->in_r_addr), 16);
2569  clib_memcpy (rmp->or_addr, &(ste->out_r_addr), 4);
2570  rmp->il_port = ste->r_port;
2571  rmp->vrf_id = ntohl (fib->ft_table_id);
2572  rmp->proto = ste->proto;
2573 
2574  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2575 
2576  return 0;
2577 }
2578 
2579 static void
2581 {
2583  nat64_main_t *nm = &nat64_main;
2584  nat64_db_t *db;
2585 
2587  if (!reg)
2588  return;
2589 
2591  .reg = reg,
2592  .context = mp->context,
2593  };
2594 
2595  /* *INDENT-OFF* */
2596  vec_foreach (db, nm->db)
2597  {
2598  ctx.db = db;
2599  nat64_db_st_walk (db, mp->proto, nat64_api_st_walk, &ctx);
2600  }
2601  /* *INDENT-ON* */
2602 }
2603 
2604 static void *
2606 {
2607  u8 *s;
2608 
2609  s = format (0, "SCRIPT: snat_st_dump protocol %d", mp->proto);
2610 
2611  FINISH;
2612 }
2613 
2614 static void
2616 {
2617  vl_api_nat64_add_del_prefix_reply_t *rmp;
2618  snat_main_t *sm = &snat_main;
2619  ip6_address_t prefix;
2620  int rv = 0;
2621 
2622  memcpy (&prefix.as_u8, mp->prefix.address, 16);
2623 
2624  rv =
2625  nat64_add_del_prefix (&prefix, mp->prefix.len,
2626  clib_net_to_host_u32 (mp->vrf_id), mp->is_add);
2627  REPLY_MACRO (VL_API_NAT64_ADD_DEL_PREFIX_REPLY);
2628 }
2629 
2630 static void *
2632  void *handle)
2633 {
2634  u8 *s;
2635 
2636  s = format (0, "SCRIPT: nat64_add_del_prefix %U/%u vrf_id %u %s\n",
2637  format_ip6_address, mp->prefix.address, mp->prefix.len,
2638  ntohl (mp->vrf_id), mp->is_add ? "" : "del");
2639 
2640  FINISH;
2641 }
2642 
2643 static int
2645 {
2647  snat_main_t *sm = &snat_main;
2648  nat64_api_walk_ctx_t *ctx = arg;
2649 
2650  rmp = vl_msg_api_alloc (sizeof (*rmp));
2651  clib_memset (rmp, 0, sizeof (*rmp));
2652  rmp->_vl_msg_id = ntohs (VL_API_NAT64_PREFIX_DETAILS + sm->msg_id_base);
2653  clib_memcpy (rmp->prefix.address, &(p->prefix), 16);
2654  rmp->prefix.len = p->plen;
2655  rmp->vrf_id = ntohl (p->vrf_id);
2656  rmp->context = ctx->context;
2657 
2658  vl_api_send_msg (ctx->reg, (u8 *) rmp);
2659 
2660  return 0;
2661 }
2662 
2663 static void
2665 {
2667 
2669  if (!reg)
2670  return;
2671 
2673  .reg = reg,
2674  .context = mp->context,
2675  };
2676 
2678 }
2679 
2680 static void *
2682  void *handle)
2683 {
2684  u8 *s;
2685 
2686  s = format (0, "SCRIPT: nat64_prefix_dump\n");
2687 
2688  FINISH;
2689 }
2690 
2691 static void
2694 {
2695  snat_main_t *sm = &snat_main;
2696  vl_api_nat64_add_del_interface_addr_reply_t *rmp;
2697  u32 sw_if_index = ntohl (mp->sw_if_index);
2698  int rv = 0;
2699 
2700  VALIDATE_SW_IF_INDEX (mp);
2701 
2702  rv = nat64_add_interface_address (sw_if_index, mp->is_add);
2703 
2705 
2706  REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_ADDR_REPLY);
2707 }
2708 
2711 {
2712  u8 *s;
2713 
2714  s = format (0, "SCRIPT: nat64_add_del_interface_addr ");
2715  s = format (s, "sw_if_index %d %s",
2716  clib_host_to_net_u32 (mp->sw_if_index),
2717  mp->is_add ? "" : "del");
2718 
2719  FINISH;
2720 }
2721 
2722 /* List of message types that this plugin understands */
2723 #define foreach_snat_plugin_api_msg \
2724 _(NAT_CONTROL_PING, nat_control_ping) \
2725 _(NAT_SHOW_CONFIG, nat_show_config) \
2726 _(NAT_SHOW_CONFIG_2, nat_show_config_2) \
2727 _(NAT_SET_WORKERS, nat_set_workers) \
2728 _(NAT_WORKER_DUMP, nat_worker_dump) \
2729 _(NAT44_DEL_USER, nat44_del_user) \
2730 _(NAT44_SET_SESSION_LIMIT, nat44_set_session_limit) \
2731 _(NAT_SET_LOG_LEVEL, nat_set_log_level) \
2732 _(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \
2733 _(NAT_SET_TIMEOUTS, nat_set_timeouts) \
2734 _(NAT_GET_TIMEOUTS, nat_get_timeouts) \
2735 _(NAT_SET_ADDR_AND_PORT_ALLOC_ALG, nat_set_addr_and_port_alloc_alg) \
2736 _(NAT_GET_ADDR_AND_PORT_ALLOC_ALG, nat_get_addr_and_port_alloc_alg) \
2737 _(NAT_SET_MSS_CLAMPING, nat_set_mss_clamping) \
2738 _(NAT_GET_MSS_CLAMPING, nat_get_mss_clamping) \
2739 _(NAT_HA_SET_LISTENER, nat_ha_set_listener) \
2740 _(NAT_HA_SET_FAILOVER, nat_ha_set_failover) \
2741 _(NAT_HA_GET_LISTENER, nat_ha_get_listener) \
2742 _(NAT_HA_GET_FAILOVER, nat_ha_get_failover) \
2743 _(NAT_HA_FLUSH, nat_ha_flush) \
2744 _(NAT_HA_RESYNC, nat_ha_resync) \
2745 _(NAT44_ADD_DEL_ADDRESS_RANGE, nat44_add_del_address_range) \
2746 _(NAT44_INTERFACE_ADD_DEL_FEATURE, nat44_interface_add_del_feature) \
2747 _(NAT44_ADD_DEL_STATIC_MAPPING, nat44_add_del_static_mapping) \
2748 _(NAT44_ADD_DEL_STATIC_MAPPING_V2, nat44_add_del_static_mapping_v2) \
2749 _(NAT44_ADD_DEL_IDENTITY_MAPPING, nat44_add_del_identity_mapping) \
2750 _(NAT44_STATIC_MAPPING_DUMP, nat44_static_mapping_dump) \
2751 _(NAT44_IDENTITY_MAPPING_DUMP, nat44_identity_mapping_dump) \
2752 _(NAT44_ADDRESS_DUMP, nat44_address_dump) \
2753 _(NAT44_INTERFACE_DUMP, nat44_interface_dump) \
2754 _(NAT44_ADD_DEL_INTERFACE_ADDR, nat44_add_del_interface_addr) \
2755 _(NAT44_INTERFACE_ADDR_DUMP, nat44_interface_addr_dump) \
2756 _(NAT44_USER_DUMP, nat44_user_dump) \
2757 _(NAT44_USER_SESSION_DUMP, nat44_user_session_dump) \
2758 _(NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE, \
2759  nat44_interface_add_del_output_feature) \
2760 _(NAT44_INTERFACE_OUTPUT_FEATURE_DUMP, \
2761  nat44_interface_output_feature_dump) \
2762 _(NAT44_ADD_DEL_LB_STATIC_MAPPING, nat44_add_del_lb_static_mapping) \
2763 _(NAT44_LB_STATIC_MAPPING_ADD_DEL_LOCAL, \
2764  nat44_lb_static_mapping_add_del_local) \
2765 _(NAT44_LB_STATIC_MAPPING_DUMP, nat44_lb_static_mapping_dump) \
2766 _(NAT44_DEL_SESSION, nat44_del_session) \
2767 _(NAT44_FORWARDING_ENABLE_DISABLE, nat44_forwarding_enable_disable) \
2768 _(NAT44_FORWARDING_IS_ENABLED, nat44_forwarding_is_enabled) \
2769 _(NAT64_ADD_DEL_POOL_ADDR_RANGE, nat64_add_del_pool_addr_range) \
2770 _(NAT64_POOL_ADDR_DUMP, nat64_pool_addr_dump) \
2771 _(NAT64_ADD_DEL_INTERFACE, nat64_add_del_interface) \
2772 _(NAT64_INTERFACE_DUMP, nat64_interface_dump) \
2773 _(NAT64_ADD_DEL_STATIC_BIB, nat64_add_del_static_bib) \
2774 _(NAT64_BIB_DUMP, nat64_bib_dump) \
2775 _(NAT64_ST_DUMP, nat64_st_dump) \
2776 _(NAT64_ADD_DEL_PREFIX, nat64_add_del_prefix) \
2777 _(NAT64_PREFIX_DUMP, nat64_prefix_dump) \
2778 _(NAT64_ADD_DEL_INTERFACE_ADDR, nat64_add_del_interface_addr)
2779 
2780 /* Set up the API message handling tables */
2781 static clib_error_t *
2783 {
2784  snat_main_t *sm __attribute__ ((unused)) = &snat_main;
2785 #define _(N,n) \
2786  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
2787  #n, \
2788  vl_api_##n##_t_handler, \
2789  vl_noop_handler, \
2790  vl_api_##n##_t_endian, \
2791  vl_api_##n##_t_print, \
2792  sizeof(vl_api_##n##_t), 1);
2794 #undef _
2795 
2796  return 0;
2797 }
2798 
2799 #define vl_msg_name_crc_list
2800 #include <nat/nat_all_api_h.h>
2801 #undef vl_msg_name_crc_list
2802 
2803 static void
2805 {
2806 #define _(id,n,crc) \
2807  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
2808  foreach_vl_msg_name_crc_nat;
2809 #undef _
2810 }
2811 
2812 static void
2814 {
2815 #define _(n,f) sm->api_main->msg_print_handlers \
2816  [VL_API_##n + sm->msg_id_base] \
2817  = (void *) vl_api_##f##_t_print;
2819 #undef _
2820 }
2821 
2822 clib_error_t *
2824 {
2825  u8 *name;
2826  clib_error_t *error = 0;
2827 
2828  name = format (0, "nat_%08x%c", api_version, 0);
2829 
2830  /* Ask for a correctly-sized block of API message decode slots */
2831  sm->msg_id_base =
2833 
2834  error = snat_plugin_api_hookup (vm);
2835 
2836  /* Add our API messages to the global name_crc hash table */
2837  setup_message_id_table (sm, sm->api_main);
2838 
2840 
2841  vec_free (name);
2842 
2843  return error;
2844 }
2845 
2846 /*
2847  * fd.io coding-style-patch-verification: ON
2848  *
2849  * Local Variables:
2850  * eval: (c-set-style "gnu")
2851  * End:
2852  */
ip4_address_t external_addr
Definition: nat.h:361
Dump NAT64 prefix.
Definition: nat.api:1293
u32 next
Definition: dlist.h:30
u8 count
Definition: dhcp.api:208
vl_api_ip4_address_t ext_host_address
Definition: nat.api:928
NAT64 interface details response.
Definition: nat.api:1166
vl_api_interface_index_t external_sw_if_index
Definition: nat.api:723
uword translation_memory_size
Definition: nat.h:604
nat64_db_t * db
BIB and session DB per thread.
Definition: nat64.h:83
#define nat_log_info(...)
Definition: nat.h:857
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
Definition: nat.h:748
u32 sessions_per_user_list_head_index
Definition: nat.h:289
NAT44 load-balancing static mapping rule details response.
Definition: nat.api:1023
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:1666
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
Definition: nat64.c:804
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:1468
static void vl_api_nat_worker_dump_t_handler(vl_api_nat_worker_dump_t *mp)
Definition: nat_api.c:258
vl_api_interface_index_t sw_if_index
Definition: nat.api:834
Get address and port assignment algorithm reply.
Definition: nat.api:348
static int nat64_api_pool_walk(snat_address_t *a, void *arg)
Definition: nat_api.c:2300
NAT64 BIB details response.
Definition: nat.api:1222
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:1739
static void * vl_api_nat_ha_set_listener_t_print(vl_api_nat_ha_set_listener_t *mp, void *handle)
Definition: nat_api.c:594
u32 icmp_timeout
Definition: nat.h:622
static void * vl_api_nat_ipfix_enable_disable_t_print(vl_api_nat_ipfix_enable_disable_t *mp, void *handle)
Definition: nat_api.c:356
vl_api_ip4_address_t external_addr
Definition: nat.api:1025
static void vl_api_nat_ha_set_listener_t_handler(vl_api_nat_ha_set_listener_t *mp)
Definition: nat_api.c:578
Get values of timeouts for NAT sessions (seconds)
Definition: nat.api:282
NAT workers details response.
Definition: nat.api:239
ip4_address_t src_address
Definition: ip4_packet.h:125
#define ntohs(x)
Definition: af_xdp.bpf.c:29
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, nat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44 session.
Definition: nat.c:4544
ip6_address_t prefix
Definition: nat64.h:49
vl_api_interface_index_t external_sw_if_index
Definition: nat.api:682
Get values of timeouts for NAT sessions reply.
Definition: nat.api:295
static void * vl_api_nat64_interface_dump_t_print(vl_api_nat64_interface_dump_t *mp, void *handle)
Definition: nat_api.c:2430
vl_api_interface_index_t sw_if_index
Definition: nat.api:587
static void send_nat44_user_session_details(snat_session_t *s, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1749
vl_api_ip4_address_t external_addr
Definition: nat.api:970
NAT44 interface with output feature details response.
Definition: nat.api:645
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:478
u16 start_port
Definition: nat.h:533
Dump NAT44 pool addresses interfaces.
Definition: nat.api:842
u32 nsessions
Definition: nat.h:290
static void vl_api_nat44_user_session_dump_t_handler(vl_api_nat44_user_session_dump_t *mp)
Definition: nat_api.c:1802
#define is_ed_session(s)
Check if NAT session is endpoint dependent.
Definition: nat.h:778
static void * vl_api_nat44_del_session_t_print(vl_api_nat44_del_session_t *mp, void *handle)
Definition: nat_api.c:2127
NAT44 identity mapping details response.
Definition: nat.api:812
unsigned long u64
Definition: types.h:89
u32 st_buckets
Definition: nat64.h:95
Add/delete NAT44 identity mapping.
Definition: nat.api:780
vl_api_nat44_lb_addr_port_t locals[local_num]
Definition: nat.api:976
#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:433
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vl_api_nat_config_flags_t flags
Definition: nat.api:784
vl_api_nat_config_flags_t flags
Definition: nat.api:1230
static void vl_api_nat44_lb_static_mapping_dump_t_handler(vl_api_nat44_lb_static_mapping_dump_t *mp)
Definition: nat_api.c:2063
vl_api_nat_config_flags_t flags
Definition: nat.api:609
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:2389
static void vl_api_nat64_bib_dump_t_handler(vl_api_nat64_bib_dump_t *mp)
Definition: nat_api.c:2512
static clib_error_t * snat_plugin_api_hookup(vlib_main_t *vm)
Definition: nat_api.c:2782
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 address port)
Definition: nat.c:186
static void * vl_api_nat64_bib_dump_t_print(vl_api_nat64_bib_dump_t *mp, void *handle)
Definition: nat_api.c:2534
Control ping from client to api server request.
Definition: nat.api:37
static void vl_api_nat44_add_del_static_mapping_v2_t_handler(vl_api_nat44_add_del_static_mapping_v2_t *mp)
Definition: nat_api.c:1151
Set values of timeouts for NAT sessions (seconds)
Definition: nat.api:269
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1090
vl_api_ip4_address_t local_ip_address
Definition: nat.api:677
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
vl_api_ip4_address_t ip_address
Definition: nat.api:469
u32 nstaticsessions
Definition: nat.h:291
static void vl_api_nat44_del_user_t_handler(vl_api_nat44_del_user_t *mp)
Definition: nat_api.c:778
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:2244
Add/delete NAT44 load-balancing static mapping rule backend.
Definition: nat.api:988
NAT44 interface details response.
Definition: nat.api:607
vl_api_ip6_prefix_t prefix
Definition: nat.api:1305
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:1574
u8 * format_user_kvp(u8 *s, va_list *args)
Definition: nat.c:3221
nat_protocol_t proto
Definition: nat.h:372
NAT44 static mapping details response.
Definition: nat.api:754
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:494
vlib_main_t * vm
Definition: in2out_ed.c:1582
vl_api_nat_config_flags_t flags
Definition: nat.api:586
vl_api_ip4_address_t first_ip_address
Definition: nat.api:545
bool static_mapping_connection_tracking
Definition: nat.api:94
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:2465
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:4582
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vl_api_ip4_address_t or_addr
Definition: nat.api:1268
static void * vl_api_nat64_pool_addr_dump_t_print(vl_api_nat64_pool_addr_dump_t *mp, void *handle)
Definition: nat_api.c:2344
u32 fib_index
Definition: nat.h:288
vl_api_ip4_address_t ip_address
Definition: nat.api:815
Response to check if forwarding is enabled or disabled.
Definition: nat.api:1087
nat_protocol_t
Definition: lib.h:41
static void nat_ed_session_delete(snat_main_t *sm, snat_session_t *ses, u32 thread_index, int lru_delete)
Definition: ed_inlines.h:55
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:379
static void vl_api_nat_show_config_2_t_handler(vl_api_nat_show_config_2_t *mp)
Definition: nat_api.c:142
u16 mask
Definition: flow_types.api:52
Get HA failover/remote settings reply.
Definition: nat.api:466
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:252
Add/delete NAT64 pool address from specific interfce.
Definition: nat.api:1315
void * vl_msg_api_alloc(int nbytes)
#define snat_is_unk_proto_session(s)
Check if SNAT session for unknown protocol.
Definition: nat.h:754
u32 max_translations_per_thread
Definition: nat.h:605
vhost_vring_addr_t addr
Definition: vhost_user.h:111
Set HA failover (remote settings)
Definition: nat.api:417
vl_api_nat_config_flags_t flags
Definition: nat.api:856
static void vl_api_nat44_add_del_interface_addr_t_handler(vl_api_nat44_add_del_interface_addr_t *mp)
Definition: nat_api.c:1541
static void vl_api_nat_set_workers_t_handler(vl_api_nat_set_workers_t *mp)
Definition: nat_api.c:188
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:2001
unsigned char u8
Definition: types.h:56
Enable/disable NAT64 feature on the interface.
Definition: nat.api:1141
static int nat64_api_prefix_walk(nat64_prefix_t *p, void *arg)
Definition: nat_api.c:2644
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:1886
nat44_lb_addr_port_t * locals
Definition: nat.h:380
static void vl_api_nat_get_timeouts_t_handler(vl_api_nat_get_timeouts_t *mp)
Definition: nat_api.c:413
static void * vl_api_nat_show_config_t_print(vl_api_nat_show_config_t *mp, void *handle)
Definition: nat_api.c:132
static void * vl_api_nat44_forwarding_is_enabled_t_print(vl_api_nat44_forwarding_is_enabled_t *mp, void *handle)
Definition: nat_api.c:2229
u32 user_buckets
Definition: nat.h:608
clib_bihash_8_8_t user_hash
Definition: nat.h:422
#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:802
u32 max_translations_per_user
Definition: nat.h:610
static void * vl_api_nat44_interface_addr_dump_t_print(vl_api_nat44_interface_addr_dump_t *mp, void *handle)
Definition: nat_api.c:1615
static void * vl_api_nat44_identity_mapping_dump_t_print(vl_api_nat44_identity_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:1530
vl_api_nat_config_flags_t flags
Definition: nat.api:716
vl_api_interface_index_t sw_if_index
Definition: nat.api:1319
format_function_t format_ip4_address
Definition: format.h:73
vl_api_nat_config_flags_t flags
Definition: nat.api:1145
static void vl_api_nat44_user_dump_t_handler(vl_api_nat44_user_dump_t *mp)
Definition: nat_api.c:1708
vl_api_ip6_address_t ir_addr
Definition: nat.api:1267
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:1078
vl_api_ip4_address_t o_addr
Definition: nat.api:1187
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
Definition: inlines.h:22
Dump NAT64 session table.
Definition: nat.api:1243
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:2086
static void vl_api_nat_ha_get_listener_t_handler(vl_api_nat_ha_get_listener_t *mp)
Definition: nat_api.c:608
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:442
vl_api_nat_config_flags_t flags
Definition: nat.api:814
static int nat64_api_st_walk(nat64_db_st_entry_t *ste, void *arg)
Definition: nat_api.c:2544
Enable/disbale NAT44 as an interface output feature (postrouting in2out translation) ...
Definition: nat.api:622
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:608
static void vl_api_nat_ha_resync_t_handler(vl_api_nat_ha_resync_t *mp)
Definition: nat_api.c:747
u32 translation_buckets
Definition: nat.h:603
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
Definition: nat64.c:825
static void * vl_api_nat_ha_set_failover_t_print(vl_api_nat_ha_set_failover_t *mp, void *handle)
Definition: nat_api.c:657
struct nat64_api_walk_ctx_t_ nat64_api_walk_ctx_t
ip4_address_t addr
Definition: nat.h:287
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void nat_ed_user_create_helper(snat_main_per_thread_data_t *tsm, snat_session_t *s)
Definition: nat_api.c:1652
static void nat_ed_users_create(snat_main_per_thread_data_t *tsm)
Definition: nat_api.c:1686
#define is_fwd_bypass_session(s)
Check if NAT session is forwarding bypass.
Definition: nat.h:772
#define foreach_snat_plugin_api_msg
Definition: nat_api.c:2723
vl_api_ip6_address_t i_addr
Definition: nat.api:1186
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:1020
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:1626
unsigned int u32
Definition: types.h:88
Dump interfaces with NAT44 output feature.
Definition: nat.api:634
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:801
vl_api_ip4_address_t ip_address
Definition: nat.api:892
static void vl_api_nat44_forwarding_enable_disable_t_handler(vl_api_nat44_forwarding_enable_disable_t *mp)
Definition: nat_api.c:2148
ip4_address_t local_addr
Definition: nat.h:359
static void * vl_api_nat_set_log_level_t_print(vl_api_nat_set_log_level_t *mp, void *handle)
Definition: nat_api.c:327
vl_api_nat_config_flags_t flags
Definition: nat.api:1056
Flush the current HA data (for testing)
Definition: nat.api:478
vl_api_ip4_address_t external_ip_address
Definition: nat.api:719
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:1440
vl_api_nat_config_flags_t flags
Definition: nat.api:924
static void * vl_api_nat44_forwarding_enable_disable_t_print(vl_api_nat44_forwarding_enable_disable_t *mp, void *handle)
Definition: nat_api.c:2195
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:2823
static void nat44_delete_session(snat_main_t *sm, snat_session_t *ses, u32 thread_index)
Definition: nat_inlines.h:275
static void nat_ha_resync_completed_event_cb(u32 client_index, u32 pid, u32 missed_count)
Definition: nat_api.c:725
static void * vl_api_nat_ha_resync_t_print(vl_api_nat_ha_resync_t *mp, void *handle)
Definition: nat_api.c:762
static void * vl_api_nat_ha_get_listener_t_print(vl_api_nat_ha_get_listener_t *mp, void *handle)
Definition: nat_api.c:630
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
int nat44_set_session_limit(u32 session_limit, u32 vrf_id)
Set NAT44 session limit (session limit, vrf id)
Definition: nat.c:3933
twice_nat_type_t twice_nat
Definition: nat.h:367
#define pool_flush(VAR, POOL, BODY)
Remove all elements from a pool in a safe way.
Definition: pool.h:573
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:547
static void * vl_api_nat_get_timeouts_t_print(vl_api_nat_get_timeouts_t *mp, void *handle)
Definition: nat_api.c:431
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:34
static void send_nat44_address_details(snat_address_t *a, vl_api_registration_t *reg, u32 context, u8 twice_nat)
Definition: nat_api.c:874
Get TCP MSS rewriting configuration.
Definition: nat.api:376
uword user_memory_size
Definition: nat.h:609
#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:549
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
Control ping from the client to the server response.
Definition: nat.api:49
static_always_inline int nat44_user_del(ip4_address_t *addr, u32 fib_index)
Definition: inlines.h:93
static void * vl_api_nat64_st_dump_t_print(vl_api_nat64_st_dump_t *mp, void *handle)
Definition: nat_api.c:2605
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:715
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat.h:527
static void vl_api_nat44_forwarding_is_enabled_t_handler(vl_api_nat44_forwarding_is_enabled_t *mp)
Definition: nat_api.c:2207
Add/delete address range to NAT64 pool.
Definition: nat.api:1104
static void * vl_api_nat44_del_user_t_print(vl_api_nat44_del_user_t *mp, void *handle)
Definition: nat_api.c:790
vl_api_ip_proto_t proto
Definition: acl_types.api:50
u64 key
the key
Definition: bihash_8_8.h:41
vl_api_nat_config_flags_t flags
Definition: nat.api:969
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:514
vl_api_nat_config_flags_t flags
Definition: nat.api:756
long ctx[MAX_CONNS]
Definition: main.c:144
u16 mss_clamping
Definition: nat.h:625
static void vl_api_nat_ha_get_failover_t_handler(vl_api_nat_ha_get_failover_t *mp)
Definition: nat_api.c:670
static void send_nat44_interface_output_feature_details(snat_interface_t *i, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1052
vl_api_nat_config_flags_t flags
Definition: nat.api:1028
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:1068
Dump NAT64 pool addresses.
Definition: nat.api:1117
static void * vl_api_nat_set_workers_t_print(vl_api_nat_set_workers_t *mp, void *handle)
Definition: nat_api.c:213
u8 out2in_dpo
Definition: nat.h:597
static void vl_api_nat_set_timeouts_t_handler(vl_api_nat_set_timeouts_t *mp)
Definition: nat_api.c:373
Tell client about a HA resync completion event.
Definition: nat.api:504
snat_static_mapping_t * static_mappings
Definition: nat.h:513
Add/del NAT64 prefix.
Definition: nat.api:1281
u32 udp_timeout
Definition: nat.h:619
u8 static_mapping_only
Definition: nat.h:595
vl_api_ip4_address_t external_ip_address
Definition: nat.api:758
void nat_ha_get_listener(ip4_address_t *addr, u16 *port, u32 *path_mtu)
Get HA listener/local configuration.
Definition: nat_ha.c:385
uword st_memory_size
Definition: nat64.h:96
Set HA listener (local settings)
Definition: nat.api:401
static void vl_api_nat_ha_set_failover_t_handler(vl_api_nat_ha_set_failover_t *mp)
Definition: nat_api.c:641
void nat_ha_flush(u8 is_resync)
Flush the current HA data (for testing)
Definition: nat_ha.c:682
#define REPLY_MACRO(t)
vl_api_ip6_address_t i_addr
Definition: nat.api:1224
static void vl_api_nat64_pool_addr_dump_t_handler(vl_api_nat64_pool_addr_dump_t *mp)
Definition: nat_api.c:2327
#define nat_interface_is_inside(i)
Check if NAT interface is inside.
Definition: nat.h:796
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:1093
u8 psid_offset
Definition: nat.h:529
Dump NAT44 identity mappings.
Definition: nat.api:797
vl_api_ip4_address_t ext_host_nat_address
Definition: nat.api:930
vl_api_ip4_address_t outside_ip_address
Definition: nat.api:919
vl_api_ip4_address_t address
Definition: nat.api:1052
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
Definition: nat.c:4643
static void vl_api_nat44_add_del_identity_mapping_t_handler(vl_api_nat44_add_del_identity_mapping_t *mp)
Definition: nat_api.c:1382
api_main_t * api_main
Definition: nat.h:697
static void vl_api_nat_get_mss_clamping_t_handler(vl_api_nat_get_mss_clamping_t *mp)
Definition: nat_api.c:551
Add/delete NAT44 pool address from specific interfce.
Definition: nat.api:830
vl_api_ip4_address_t ip_address
Definition: nat.api:528
static void * vl_api_nat_worker_dump_t_print(vl_api_nat_worker_dump_t *mp, void *handle)
Definition: nat_api.c:275
u8 psid_length
Definition: nat.h:530
static void * vl_api_nat44_address_dump_t_print(vl_api_nat44_address_dump_t *mp, void *handle)
Definition: nat_api.c:919
vl_api_ip6_address_t il_addr
Definition: nat.api:1263
u32 inside_vrf_id
Definition: nat.h:614
Get address and port assignment algorithm.
Definition: nat.api:331
vl_api_ip4_address_t pool_ip_address
Definition: nat.api:717
static void vl_api_nat44_del_session_t_handler(vl_api_nat44_del_session_t *mp)
Definition: nat_api.c:2096
u8 log_level
Definition: nat.h:691
Add/delete NAT64 static BIB entry.
Definition: nat.api:1183
u8 len
Definition: ip_types.api:92
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:227
Add/delete NAT44 static mapping.
Definition: nat.api:710
static void * vl_api_nat_show_config_2_t_print(vl_api_nat_show_config_t *mp, void *handle)
Definition: nat_api.c:178
static void vl_api_nat44_add_del_static_mapping_t_handler(vl_api_nat44_add_del_static_mapping_t *mp)
Definition: nat_api.c:1104
static void send_nat44_interface_details(snat_interface_t *i, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:967
snat_interface_t * output_feature_interfaces
Definition: nat.h:520
snat_main_t snat_main
Definition: nat.c:39
vl_api_ip4_address_t last_ip_address
Definition: nat.api:546
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
vl_api_interface_index_t sw_if_index
Definition: nat.api:1169
vl_api_ip4_address_t ip_address
Definition: nat.api:569
u64 value
the value
Definition: bihash_8_8.h:42
#define BAD_SW_IF_INDEX_LABEL
snat_user_t * users
Definition: nat.h:425
static void vl_api_nat_ha_flush_t_handler(vl_api_nat_ha_flush_t *mp)
Definition: nat_api.c:703
static void * vl_api_nat_set_timeouts_t_print(vl_api_nat_set_timeouts_t *mp, void *handle)
Definition: nat_api.c:399
u32 max_users_per_thread
Definition: nat.h:607
static void * vl_api_nat64_add_del_prefix_t_print(vl_api_nat64_add_del_prefix_t *mp, void *handle)
Definition: nat_api.c:2631
static void vl_api_nat64_add_del_interface_addr_t_handler(vl_api_nat64_add_del_interface_addr_t *mp)
Definition: nat_api.c:2693
Get HA failover/remote settings.
Definition: nat.api:453
Dump interfaces with NAT44 feature.
Definition: nat.api:594
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
Definition: nat64.c:364
Show NAT plugin startup config reply.
Definition: nat.api:145
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 vl_api_nat44_identity_mapping_dump_t_handler(vl_api_nat44_identity_mapping_dump_t *mp)
Definition: nat_api.c:1496
vl_api_ip4_address_t ip_address
Definition: nat.api:404
u32 outside_vrf_id
Definition: nat.h:612
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:2279
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:3177
static void vl_api_nat_show_config_t_handler(vl_api_nat_show_config_t *mp)
Definition: nat_api.c:95
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
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:1905
u8 static_mapping_connection_tracking
Definition: nat.h:596
u16 end_port
Definition: nat.h:534
Dump NAT44 load-balancing static mapping rules.
Definition: nat.api:1002
Dump NAT44 addresses.
Definition: nat.api:556
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
NAT44 user&#39;s sessions response.
Definition: nat.api:917
static void * vl_api_nat44_interface_dump_t_print(vl_api_nat44_interface_dump_t *mp, void *handle)
Definition: nat_api.c:1008
Set NAT workers.
Definition: nat.api:218
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
Definition: nat64.c:986
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:1595
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:2137
vl_api_ip4_address_t ol_addr
Definition: nat.api:1264
vl_api_nat_config_flags_t flags
Definition: nat.api:835
u16 psid
Definition: nat.h:531
static void vl_api_nat64_add_del_prefix_t_handler(vl_api_nat64_add_del_prefix_t *mp)
Definition: nat_api.c:2615
static uword * clib_bitmap_set_multiple(uword *bitmap, uword i, uword value, uword n_bits)
sets the ith through ith + n_bits bits in a bitmap
Definition: bitmap.h:275
static void vl_api_nat64_prefix_dump_t_handler(vl_api_nat64_prefix_dump_t *mp)
Definition: nat_api.c:2664
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:299
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:1952
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:39
#define ARRAY_LEN(x)
Definition: clib.h:67
u32 sw_if_index
Definition: nat.h:389
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
vl_api_ip4_address_t ext_host_address
Definition: nat.api:1057
string name[64]
Definition: ip.api:44
nat64_main_t nat64_main
Definition: nat64.c:29
static void send_nat44_lb_static_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:2012
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:1967
u32 tcp_transitory_timeout
Definition: nat.h:620
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 send_nat44_static_map_resolve_details(snat_static_map_resolve_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1304
u32 vrf_id
Definition: nat64.h:51
u32 * auto_add_sw_if_indices
Definition: nat.h:546
static int nat64_api_bib_walk(nat64_db_bib_entry_t *bibe, void *arg)
Definition: nat_api.c:2481
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:1198
Get HA listener/local configuration reply.
Definition: nat.api:441
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:2710
vl_api_nat44_lb_addr_port_t locals[local_num]
Definition: nat.api:1032
#define is_addr_only_static_mapping(sm)
Check if NAT static mapping is address only (1:1NAT).
Definition: nat.h:814
u32 num_workers
Definition: nat.h:496
Definition: nat.h:339
NAT44 users response.
Definition: nat.api:875
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:497
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:1038
static void send_nat44_static_mapping_details(snat_static_mapping_t *m, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:1260
vl_api_registration_t * reg
Definition: nat_api.c:2294
uword bib_memory_size
Definition: nat64.h:94
ip4_address_t l_addr
Definition: nat.h:395
static void * vl_api_nat_ha_get_failover_t_print(vl_api_nat_ha_get_failover_t *mp, void *handle)
Definition: nat_api.c:692
NAT64 pool address details response.
Definition: nat.api:1127
Dump NAT workers.
Definition: nat.api:228
static void vl_api_nat_ipfix_enable_disable_t_handler(vl_api_nat_ipfix_enable_disable_t *mp)
Definition: nat_api.c:339
Dump NAT64 prefix details response.
Definition: nat.api:1303
IPv4 main type.
Definition: ip4.h:106
static void send_nat_worker_details(u32 worker_index, vl_api_registration_t *reg, u32 context)
Definition: nat_api.c:238
static void vl_api_nat44_set_session_limit_t_handler(vl_api_nat44_set_session_limit_t *mp)
Definition: nat_api.c:285
Set address and port assignment algorithm.
Definition: nat.api:316
u64 as_u64
Definition: nat.h:82
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:1418
Add/del NAT44 address range.
Definition: nat.api:542
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:4632
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:567
static void vl_api_nat64_interface_dump_t_handler(vl_api_nat64_interface_dump_t *mp)
Definition: nat_api.c:2413
ip4_address_t addr
Definition: nat.h:79
static void * vl_api_nat44_static_mapping_dump_t_print(vl_api_nat44_static_mapping_dump_t *mp, void *handle)
Definition: nat_api.c:1370
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
NAT44 set session limit.
Definition: nat.api:195
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:288
ip4_address_t addr
Definition: nat.h:296
static void * vl_api_nat_set_mss_clamping_t_print(vl_api_nat_set_mss_clamping_t *mp, void *handle)
Definition: nat_api.c:539
snat_address_t * twice_nat_addresses
Definition: nat.h:543
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
Definition: nat64.c:1034
Set TCP MSS rewriting configuration.
Definition: nat.api:365
vl_api_ip4_address_t o_addr
Definition: nat.api:1225
u32 value
Definition: dlist.h:32
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
Definition: nat64.c:532
vl_api_nat_config_flags_t flags
Definition: nat.api:676
typedef key
Definition: ipsec_types.api:85
NAT64 global declarations.
int nat64_set_tcp_timeouts(u32 trans, u32 est)
Set TCP session timeouts.
Definition: nat64.c:846
Dump NAT64 BIB.
Definition: nat.api:1204
static void * vl_api_nat44_add_del_static_mapping_v2_t_print(vl_api_nat44_add_del_static_mapping_v2_t *mp, void *handle)
Definition: nat_api.c:1227
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:859
vl_api_ip4_address_t local_ip_address
Definition: nat.api:718
vl_api_interface_index_t sw_if_index
Definition: nat.api:818
Add/delete NAT44 load-balancing static mapping rule.
Definition: nat.api:965
vl_api_address_t ip
Definition: l2.api:501
Get TCP MSS rewriting configuration reply.
Definition: nat.api:387
DEPRECATED: Show NAT plugin startup config reply.
Definition: nat.api:89
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, nat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
Definition: nat.c:1515
static void vl_api_nat44_interface_dump_t_handler(vl_api_nat44_interface_dump_t *mp)
Definition: nat_api.c:989
twice_nat_type_t
Definition: nat.h:334
Add/delete NAT44 static mapping.
Definition: nat.api:672
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
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:1561
static void vl_api_nat_set_log_level_t_handler(vl_api_nat_set_log_level_t *mp)
Definition: nat_api.c:312
static void * vl_api_nat44_user_session_dump_t_print(vl_api_nat44_user_session_dump_t *mp, void *handle)
Definition: nat_api.c:1868
u16 msg_id_base
Definition: nat.h:686
vl_api_ip4_address_t start_addr
Definition: nat.api:1107
#define is_out2in_only_static_mapping(sm)
Check if NAT static mapping match only out2in direction.
Definition: nat.h:820
static_always_inline u8 nat_proto_to_ip_proto(nat_protocol_t nat_proto)
Definition: inlines.h:35
Dump NAT44 static mappings.
Definition: nat.api:732
vl_api_interface_index_t external_sw_if_index
Definition: nat.api:762
vl_api_interface_index_t sw_if_index
Definition: nat.api:610
static void * vl_api_nat44_set_session_limit_t_print(vl_api_nat44_set_session_limit_t *mp, void *handle)
Definition: nat_api.c:299
static void vl_api_nat64_add_del_static_bib_t_handler(vl_api_nat64_add_del_static_bib_t *mp)
Definition: nat_api.c:2442
Dump interfaces with NAT64 feature.
Definition: nat.api:1153
u32 * workers
Definition: nat.h:498
NAT44 pool addresses interfaces details response.
Definition: nat.api:853
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:504
vl_api_interface_index_t sw_if_index
Definition: nat.api:1146
u32 pid
Definition: dhcp.api:164
vl_api_ip4_address_t ip_address
Definition: nat.api:785
u32 index
Definition: flow_types.api:221
Del NAT44 user.
Definition: nat.api:525
static void vl_api_nat_set_mss_clamping_t_handler(vl_api_nat_set_mss_clamping_t *mp)
Definition: nat_api.c:524
u32 fib_index
Definition: nat.h:80
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:1882
vl_api_interface_index_t sw_if_index
Definition: nat.api:855
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:878
Enable/disable NAT IPFIX logging.
Definition: nat.api:253
vl_api_ip4_address_t end_addr
Definition: nat.api:1108
snat_address_t * addresses
Definition: nat.h:523
NAT44 user&#39;s sessions.
Definition: nat.api:889
u16 port
Definition: lb_types.api:72
nat64_db_t * db
Definition: nat_api.c:2296
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 interface.
Definition: nat.c:4476
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:2374
vl_api_ip4_address_t ip_address
Definition: nat.api:420
vl_api_interface_index_t sw_if_index
Definition: nat.api:788
snat_get_worker_in2out_function_t * worker_in2out_cb
Definition: nat.h:499
snat_static_map_resolve_t * to_resolve
Definition: nat.h:550
static void increment_v4_address(ip4_address_t *a)
Definition: nat_inlines.h:757
vl_api_ip4_address_t external_ip_address
Definition: nat.api:678
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1144
Set NAT logging level.
Definition: nat.api:207
static void vl_api_nat44_address_dump_t_handler(vl_api_nat44_address_dump_t *mp)
Definition: nat_api.c:900
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:111
u8 forwarding_enabled
Definition: nat.h:592
vl_api_ip4_address_t inside_ip_address
Definition: nat.api:921
vl_api_ip6_prefix_t prefix
Definition: nat.api:1284
#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:2804
nat_protocol_t proto
Definition: nat.h:401
vl_api_ip4_address_t address
Definition: nat.api:1129
static void nat_ed_users_destroy(snat_main_per_thread_data_t *tsm)
Definition: nat_api.c:1695
static void plugin_custom_dump_configure(snat_main_t *sm)
Definition: nat_api.c:2813
static void vl_api_nat44_interface_add_del_feature_t_handler(vl_api_nat44_interface_add_del_feature_t *mp)
Definition: nat_api.c:931
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, nat_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:1281
#define FINISH
Definition: nat_api.c:59
static void vl_api_nat64_st_dump_t_handler(vl_api_nat64_st_dump_t *mp)
Definition: nat_api.c:2580
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
Definition: nat.c:2337
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, nat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat, ip4_address_t pool_addr, int exact)
Add/delete NAT44 static mapping.
Definition: nat.c:837
#define is_twice_nat_session(s)
Check if NAT session is twice NAT.
Definition: nat.h:760
vl_api_nat_config_flags_t flags
Definition: nat.api:570
u32 vrf_id
Definition: nat.api:944
u8 endpoint_dependent
Definition: nat.h:598
vl_api_ip4_address_t local_ip_address
Definition: nat.api:757
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:953
Resync HA (resend existing sessions to new failover)
Definition: nat.api:491
static void * vl_api_nat64_prefix_dump_t_print(vl_api_nat64_prefix_dump_t *mp, void *handle)
Definition: nat_api.c:2681
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:4620
Dump NAT44 users.
Definition: nat.api:863
vl_api_nat_log_level_t log_level
Definition: nat.api:210
#define BITS(x)
Definition: clib.h:66
Enable/disable NAT44 feature on the interface.
Definition: nat.api:582
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:670
vl_api_interface_index_t sw_if_index
Definition: nat.api:648
snat_session_t * sessions
Definition: nat.h:428
vl_api_interface_index_t sw_if_index
Definition: nat.api:627
static void vl_api_nat44_static_mapping_dump_t_handler(vl_api_nat44_static_mapping_dump_t *mp)
Definition: nat_api.c:1340
vl_api_nat44_lb_addr_port_t local
Definition: nat.api:995
u32 fib_index
Definition: nat.h:297
Get HA listener/local configuration.
Definition: nat.api:429
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
snat_interface_t * interfaces
Definition: nat.h:519
Delete NAT44 session.
Definition: nat.api:1049
NAT active-passive HA.
vl_api_nat_config_flags_t flags
Definition: nat.api:1168
vl_api_ip4_address_t ip_address
Definition: nat.api:444
#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:1074
Show NAT plugin startup config.
Definition: nat.api:61
Show NAT plugin startup config.
Definition: nat.api:116
NAT44 address details response.
Definition: nat.api:567
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:1033
NAT64 session table details response.
Definition: nat.api:1261
static void vl_api_nat64_add_del_interface_t_handler(vl_api_nat64_add_del_interface_t *mp)
Definition: nat_api.c:2355
u32 tcp_established_timeout
Definition: nat.h:621
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128