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