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