2 * Copyright (c) 2017 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @brief NAT plugin API implementation
22 #include <nat/nat_inlines.h>
23 #include <nat/nat44/inlines.h>
24 #include <nat/lib/nat_inlines.h>
25 #include <nat/nat_ha.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
29 #include <nat/nat_msg_enum.h>
30 #include <vnet/fib/fib_table.h>
31 #include <vnet/ip/ip_types_api.h>
32 #include <nat/nat44/ed_inlines.h>
33 #include <nat/lib/ipfix_logging.h>
35 #define vl_api_nat44_add_del_lb_static_mapping_t_endian vl_noop_handler
36 #define vl_api_nat44_nat44_lb_static_mapping_details_t_endian vl_noop_handler
38 /* define message structures */
40 #include <nat/nat_all_api_h.h>
43 /* define generated endian-swappers */
45 #include <nat/nat_all_api_h.h>
48 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
50 #define REPLY_MSG_ID_BASE sm->msg_id_base
51 #include <vlibapi/api_helper_macros.h>
53 /* Get the API version number */
54 #define vl_api_version(n,v) static u32 api_version=(v);
55 #include <nat/nat_all_api_h.h>
58 /* Macro to finish up custom dump fns */
61 vl_print (handle, (char *)s); \
65 /******************************/
66 /*** Common NAT plugin APIs ***/
67 /******************************/
70 vl_api_nat_control_ping_t_handler (vl_api_nat_control_ping_t * mp)
72 vl_api_nat_control_ping_reply_t *rmp;
73 snat_main_t *sm = &snat_main;
77 REPLY_MACRO2 (VL_API_NAT_CONTROL_PING_REPLY,
79 rmp->vpe_pid = ntohl (getpid ());
85 vl_api_nat_control_ping_t_print (vl_api_nat_control_ping_t * mp, void *handle)
89 s = format (0, "SCRIPT: nat_control_ping ");
95 vl_api_nat_show_config_t_handler (vl_api_nat_show_config_t * mp)
97 vl_api_nat_show_config_reply_t *rmp;
98 snat_main_t *sm = &snat_main;
102 REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_REPLY,
104 rmp->translation_buckets = htonl (sm->translation_buckets);
105 rmp->translation_memory_size = clib_host_to_net_u32 (
106 sm->translation_memory_size > 0xffffffffULL
108 : (u32)sm->translation_memory_size);
109 rmp->user_buckets = htonl (sm->user_buckets);
110 rmp->user_memory_size = clib_host_to_net_u64 (sm->user_memory_size);
111 rmp->max_translations_per_user = htonl (sm->max_translations_per_user);
112 rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
113 rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
114 rmp->static_mapping_only = sm->static_mapping_only;
115 rmp->static_mapping_connection_tracking =
116 sm->static_mapping_connection_tracking;
117 rmp->endpoint_dependent = sm->endpoint_dependent;
118 rmp->out2in_dpo = sm->out2in_dpo;
119 // these are obsolete
121 rmp->deterministic = 0;
122 rmp->nat64_bib_buckets = 0;
123 rmp->nat64_bib_memory_size = 0;
124 rmp->nat64_st_buckets = 0;
125 rmp->nat64_st_memory_size = 0;
131 vl_api_nat_show_config_t_print (vl_api_nat_show_config_t * mp, void *handle)
135 s = format (0, "SCRIPT: nat_show_config ");
141 vl_api_nat_show_config_2_t_handler (vl_api_nat_show_config_2_t * mp)
143 vl_api_nat_show_config_2_reply_t *rmp;
144 snat_main_t *sm = &snat_main;
148 REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_2_REPLY,
150 rmp->translation_buckets = htonl (sm->translation_buckets);
151 rmp->translation_memory_size = clib_host_to_net_u64 (sm->translation_memory_size);
152 rmp->user_buckets = htonl (sm->user_buckets);
153 rmp->user_memory_size = clib_host_to_net_u64 (sm->user_memory_size);
154 rmp->max_translations_per_user = htonl (sm->max_translations_per_user);
155 rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
156 rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
157 rmp->static_mapping_only = sm->static_mapping_only;
158 rmp->static_mapping_connection_tracking =
159 sm->static_mapping_connection_tracking;
160 rmp->endpoint_dependent = sm->endpoint_dependent;
161 rmp->out2in_dpo = sm->out2in_dpo;
162 rmp->max_translations_per_thread = clib_net_to_host_u32(sm->max_translations_per_thread);
163 rmp->max_users_per_thread = clib_net_to_host_u32(sm->max_users_per_thread);
164 // these are obsolete
166 rmp->deterministic = 0;
167 rmp->nat64_bib_buckets = 0;
168 rmp->nat64_bib_memory_size = 0;
169 rmp->nat64_st_buckets = 0;
170 rmp->nat64_st_memory_size = 0;
176 vl_api_nat_show_config_2_t_print (vl_api_nat_show_config_t * mp, void *handle)
180 s = format (0, "SCRIPT: nat_show_config_2 ");
186 vl_api_nat_set_workers_t_handler (vl_api_nat_set_workers_t * mp)
188 snat_main_t *sm = &snat_main;
189 vl_api_nat_set_workers_reply_t *rmp;
194 mask = clib_net_to_host_u64 (mp->worker_mask);
196 if (sm->num_workers < 2)
198 rv = VNET_API_ERROR_FEATURE_DISABLED;
202 bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
203 rv = snat_set_workers (bitmap);
204 clib_bitmap_free (bitmap);
207 REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
211 vl_api_nat_set_workers_t_print (vl_api_nat_set_workers_t * mp, void *handle)
217 u64 mask = clib_net_to_host_u64 (mp->worker_mask);
219 s = format (0, "SCRIPT: nat_set_workers ");
220 bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
222 clib_bitmap_foreach (i, bitmap,
225 s = format (s, "%d", i);
227 s = format (s, ",%d", i);
231 clib_bitmap_free (bitmap);
236 send_nat_worker_details (u32 worker_index, vl_api_registration_t * reg,
239 vl_api_nat_worker_details_t *rmp;
240 snat_main_t *sm = &snat_main;
241 vlib_worker_thread_t *w =
242 vlib_worker_threads + worker_index + sm->first_worker_index;
244 rmp = vl_msg_api_alloc (sizeof (*rmp));
245 clib_memset (rmp, 0, sizeof (*rmp));
246 rmp->_vl_msg_id = ntohs (VL_API_NAT_WORKER_DETAILS + sm->msg_id_base);
247 rmp->context = context;
248 rmp->worker_index = htonl (worker_index);
249 rmp->lcore_id = htonl (w->cpu_id);
250 strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1);
252 vl_api_send_msg (reg, (u8 *) rmp);
256 vl_api_nat_worker_dump_t_handler (vl_api_nat_worker_dump_t * mp)
258 vl_api_registration_t *reg;
259 snat_main_t *sm = &snat_main;
262 reg = vl_api_client_index_to_registration (mp->client_index);
267 vec_foreach (worker_index, sm->workers)
268 send_nat_worker_details(*worker_index, reg, mp->context);
273 vl_api_nat_worker_dump_t_print (vl_api_nat_worker_dump_t * mp, void *handle)
277 s = format (0, "SCRIPT: nat_worker_dump ");
283 vl_api_nat44_set_session_limit_t_handler (vl_api_nat44_set_session_limit_t *
286 snat_main_t *sm = &snat_main;
287 vl_api_nat44_set_session_limit_reply_t *rmp;
290 rv = nat44_set_session_limit
291 (ntohl (mp->session_limit), ntohl (mp->vrf_id));
293 REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
297 vl_api_nat44_set_session_limit_t_print (vl_api_nat44_set_session_limit_t *
302 s = format (0, "SCRIPT: nat44_set_session_limit ");
303 s = format (s, "session_limit %d", ntohl (mp->session_limit));
304 s = format (s, "vrf_id %d", ntohl (mp->vrf_id));
310 vl_api_nat_set_log_level_t_handler (vl_api_nat_set_log_level_t * mp)
312 snat_main_t *sm = &snat_main;
313 vl_api_nat_set_log_level_reply_t *rmp;
316 if (sm->log_level > NAT_LOG_DEBUG)
317 rv = VNET_API_ERROR_UNSUPPORTED;
319 sm->log_level = mp->log_level;
321 REPLY_MACRO (VL_API_NAT_SET_WORKERS_REPLY);
325 vl_api_nat_set_log_level_t_print (vl_api_nat_set_log_level_t *
330 s = format (0, "SCRIPT: nat_set_log_level ");
331 s = format (s, "log_level %d", mp->log_level);
337 vl_api_nat_ipfix_enable_disable_t_handler (vl_api_nat_ipfix_enable_disable_t *
340 snat_main_t *sm = &snat_main;
341 vl_api_nat_ipfix_enable_disable_reply_t *rmp;
344 rv = nat_ipfix_logging_enable_disable (mp->enable,
347 clib_host_to_net_u16 (mp->src_port));
349 REPLY_MACRO (VL_API_NAT_IPFIX_ENABLE_DISABLE_REPLY);
353 vl_api_nat_ipfix_enable_disable_t_print (vl_api_nat_ipfix_enable_disable_t *
358 s = format (0, "SCRIPT: nat_ipfix_enable_disable ");
360 s = format (s, "domain %d ", clib_net_to_host_u32 (mp->domain_id));
362 s = format (s, "src_port %d ", clib_net_to_host_u16 (mp->src_port));
364 s = format (s, "disable ");
370 vl_api_nat_set_timeouts_t_handler (vl_api_nat_set_timeouts_t * mp)
372 snat_main_t *sm = &snat_main;
373 vl_api_nat_set_timeouts_reply_t *rmp;
376 sm->udp_timeout = ntohl (mp->udp);
377 sm->tcp_established_timeout = ntohl (mp->tcp_established);
378 sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
379 sm->icmp_timeout = ntohl (mp->icmp);
381 REPLY_MACRO (VL_API_NAT_SET_TIMEOUTS_REPLY);
385 vl_api_nat_set_timeouts_t_print (vl_api_nat_set_timeouts_t * mp, void *handle)
389 s = format (0, "SCRIPT: nat_set_timeouts ");
390 s = format (s, "udp %d tcp_established %d tcp_transitory %d icmp %d\n",
392 ntohl (mp->tcp_established),
393 ntohl (mp->tcp_transitory), ntohl (mp->icmp));
399 vl_api_nat_get_timeouts_t_handler (vl_api_nat_get_timeouts_t * mp)
401 snat_main_t *sm = &snat_main;
402 vl_api_nat_get_timeouts_reply_t *rmp;
406 REPLY_MACRO2 (VL_API_NAT_GET_TIMEOUTS_REPLY,
408 rmp->udp = htonl (sm->udp_timeout);
409 rmp->tcp_established = htonl (sm->tcp_established_timeout);
410 rmp->tcp_transitory = htonl (sm->tcp_transitory_timeout);
411 rmp->icmp = htonl (sm->icmp_timeout);
417 vl_api_nat_get_timeouts_t_print (vl_api_nat_get_timeouts_t * mp, void *handle)
421 s = format (0, "SCRIPT: nat_get_timeouts");
427 vl_api_nat_set_addr_and_port_alloc_alg_t_handler
428 (vl_api_nat_set_addr_and_port_alloc_alg_t * mp)
430 snat_main_t *sm = &snat_main;
431 vl_api_nat_set_addr_and_port_alloc_alg_reply_t *rmp;
433 u16 port_start, port_end;
437 case NAT_ADDR_AND_PORT_ALLOC_ALG_DEFAULT:
438 nat_set_alloc_addr_and_port_default ();
440 case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
441 nat_set_alloc_addr_and_port_mape (ntohs (mp->psid), mp->psid_offset,
444 case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
445 port_start = ntohs (mp->start_port);
446 port_end = ntohs (mp->end_port);
447 if (port_end <= port_start)
449 rv = VNET_API_ERROR_INVALID_VALUE;
452 nat_set_alloc_addr_and_port_range (port_start, port_end);
455 rv = VNET_API_ERROR_INVALID_VALUE;
460 REPLY_MACRO (VL_API_NAT_SET_ADDR_AND_PORT_ALLOC_ALG_REPLY);
463 static void *vl_api_nat_set_addr_and_port_alloc_alg_t_print
464 (vl_api_nat_set_addr_and_port_alloc_alg_t * mp, void *handle)
468 s = format (0, "SCRIPT: nat_set_addr_and_port_alloc_alg ");
469 s = format (s, "alg %d psid_offset %d psid_length %d psid %d start_port %d "
471 ntohl (mp->alg), ntohl (mp->psid_offset),
472 ntohl (mp->psid_length), ntohs (mp->psid),
473 ntohs (mp->start_port), ntohs (mp->end_port));
479 vl_api_nat_get_addr_and_port_alloc_alg_t_handler
480 (vl_api_nat_get_addr_and_port_alloc_alg_t * mp)
482 snat_main_t *sm = &snat_main;
483 vl_api_nat_get_addr_and_port_alloc_alg_reply_t *rmp;
487 REPLY_MACRO2 (VL_API_NAT_GET_ADDR_AND_PORT_ALLOC_ALG_REPLY,
489 rmp->alg = sm->addr_and_port_alloc_alg;
490 rmp->psid_offset = sm->psid_offset;
491 rmp->psid_length = sm->psid_length;
492 rmp->psid = htons (sm->psid);
493 rmp->start_port = htons (sm->start_port);
494 rmp->end_port = htons (sm->end_port);
499 static void *vl_api_nat_get_addr_and_port_alloc_alg_t_print
500 (vl_api_nat_get_addr_and_port_alloc_alg_t * mp, void *handle)
504 s = format (0, "SCRIPT: nat_get_addr_and_port_alloc_alg");
510 vl_api_nat_set_mss_clamping_t_handler (vl_api_nat_set_mss_clamping_t * mp)
512 snat_main_t *sm = &snat_main;
513 vl_api_nat_set_mss_clamping_reply_t *rmp;
517 sm->mss_clamping = ntohs (mp->mss_value);
519 sm->mss_clamping = 0;
521 REPLY_MACRO (VL_API_NAT_SET_MSS_CLAMPING_REPLY);
525 vl_api_nat_set_mss_clamping_t_print (vl_api_nat_set_mss_clamping_t * mp,
530 s = format (0, "SCRIPT: nat_set_mss_clamping enable %d mss_value %d\n",
531 mp->enable, ntohs (mp->mss_value));
537 vl_api_nat_get_mss_clamping_t_handler (vl_api_nat_get_mss_clamping_t * mp)
539 snat_main_t *sm = &snat_main;
540 vl_api_nat_get_mss_clamping_reply_t *rmp;
544 REPLY_MACRO2 (VL_API_NAT_GET_MSS_CLAMPING_REPLY,
546 rmp->enable = sm->mss_clamping ? 1 : 0;
547 rmp->mss_value = htons (sm->mss_clamping);
553 vl_api_nat_get_mss_clamping_t_print (vl_api_nat_get_mss_clamping_t * mp,
558 s = format (0, "SCRIPT: nat_get_mss_clamping");
564 vl_api_nat_ha_set_listener_t_handler (vl_api_nat_ha_set_listener_t * mp)
566 snat_main_t *sm = &snat_main;
567 vl_api_nat_ha_set_listener_reply_t *rmp;
571 memcpy (&addr, &mp->ip_address, sizeof (addr));
573 nat_ha_set_listener (&addr, clib_net_to_host_u16 (mp->port),
574 clib_net_to_host_u32 (mp->path_mtu));
576 REPLY_MACRO (VL_API_NAT_HA_SET_LISTENER_REPLY);
580 vl_api_nat_ha_set_listener_t_print (vl_api_nat_ha_set_listener_t * mp,
585 s = format (0, "SCRIPT: nat_ha_set_listener ");
586 s = format (s, "ip_address %U ", format_ip4_address, mp->ip_address);
587 s = format (s, "port %d ", clib_net_to_host_u16 (mp->port));
588 s = format (s, "path_mtu %d", clib_net_to_host_u32 (mp->path_mtu));
594 vl_api_nat_ha_get_listener_t_handler (vl_api_nat_ha_get_listener_t * mp)
596 snat_main_t *sm = &snat_main;
597 vl_api_nat_ha_get_listener_reply_t *rmp;
603 nat_ha_get_listener (&addr, &port, &path_mtu);
606 REPLY_MACRO2 (VL_API_NAT_HA_GET_LISTENER_REPLY,
608 clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
609 rmp->port = clib_host_to_net_u16 (port);
610 rmp->path_mtu = clib_host_to_net_u32 (path_mtu);
616 vl_api_nat_ha_get_listener_t_print (vl_api_nat_ha_get_listener_t * mp,
621 s = format (0, "SCRIPT: nat_ha_get_listener");
627 vl_api_nat_ha_set_failover_t_handler (vl_api_nat_ha_set_failover_t * mp)
629 snat_main_t *sm = &snat_main;
630 vl_api_nat_ha_set_failover_reply_t *rmp;
634 memcpy (&addr, &mp->ip_address, sizeof (addr));
636 nat_ha_set_failover (&addr, clib_net_to_host_u16 (mp->port),
637 clib_net_to_host_u32 (mp->session_refresh_interval));
639 REPLY_MACRO (VL_API_NAT_HA_SET_FAILOVER_REPLY);
643 vl_api_nat_ha_set_failover_t_print (vl_api_nat_ha_set_failover_t * mp,
648 s = format (0, "SCRIPT: nat_ha_set_failover ");
649 s = format (s, "ip_address %U ", format_ip4_address, mp->ip_address);
650 s = format (s, "port %d ", clib_net_to_host_u16 (mp->port));
656 vl_api_nat_ha_get_failover_t_handler (vl_api_nat_ha_get_failover_t * mp)
658 snat_main_t *sm = &snat_main;
659 vl_api_nat_ha_get_failover_reply_t *rmp;
663 u32 session_refresh_interval;
665 nat_ha_get_failover (&addr, &port, &session_refresh_interval);
668 REPLY_MACRO2 (VL_API_NAT_HA_GET_FAILOVER_REPLY,
670 clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
671 rmp->port = clib_host_to_net_u16 (port);
672 rmp->session_refresh_interval = clib_host_to_net_u32 (session_refresh_interval);
678 vl_api_nat_ha_get_failover_t_print (vl_api_nat_ha_get_failover_t * mp,
683 s = format (0, "SCRIPT: nat_ha_get_failover");
689 vl_api_nat_ha_flush_t_handler (vl_api_nat_ha_flush_t * mp)
691 snat_main_t *sm = &snat_main;
692 vl_api_nat_ha_flush_reply_t *rmp;
697 REPLY_MACRO (VL_API_NAT_HA_FLUSH_REPLY);
701 vl_api_nat_ha_flush_t_print (vl_api_nat_ha_flush_t * mp, void *handle)
705 s = format (0, "SCRIPT: nat_ha_flush ");
711 nat_ha_resync_completed_event_cb (u32 client_index, u32 pid, u32 missed_count)
713 snat_main_t *sm = &snat_main;
714 vl_api_registration_t *reg;
715 vl_api_nat_ha_resync_completed_event_t *mp;
717 reg = vl_api_client_index_to_registration (client_index);
721 mp = vl_msg_api_alloc (sizeof (*mp));
722 clib_memset (mp, 0, sizeof (*mp));
723 mp->client_index = client_index;
725 mp->missed_count = clib_host_to_net_u32 (missed_count);
727 ntohs (VL_API_NAT_HA_RESYNC_COMPLETED_EVENT + sm->msg_id_base);
729 vl_api_send_msg (reg, (u8 *) mp);
733 vl_api_nat_ha_resync_t_handler (vl_api_nat_ha_resync_t * mp)
735 snat_main_t *sm = &snat_main;
736 vl_api_nat_ha_resync_reply_t *rmp;
740 nat_ha_resync (mp->client_index, mp->pid,
741 mp->want_resync_event ? nat_ha_resync_completed_event_cb :
744 REPLY_MACRO (VL_API_NAT_HA_RESYNC_REPLY);
748 vl_api_nat_ha_resync_t_print (vl_api_nat_ha_resync_t * mp, void *handle)
752 s = format (0, "SCRIPT: nat_ha_resync ");
754 format (s, "want_resync_event %d pid %d", mp->want_resync_event,
755 clib_host_to_net_u32 (mp->pid));
764 vl_api_nat44_del_user_t_handler (vl_api_nat44_del_user_t * mp)
766 snat_main_t *sm = &snat_main;
767 vl_api_nat44_del_user_reply_t *rmp;
770 memcpy (&addr.as_u8, mp->ip_address, 4);
771 rv = nat44_user_del (&addr, ntohl (mp->fib_index));
772 REPLY_MACRO (VL_API_NAT44_DEL_USER_REPLY);
775 static void *vl_api_nat44_del_user_t_print
776 (vl_api_nat44_del_user_t * mp, void *handle)
779 s = format (0, "SCRIPT: nat44_del_user ");
780 s = format (s, "ip_address %U fib_index %U ",
781 format_ip4_address, mp->ip_address, ntohl (mp->fib_index));
786 vl_api_nat44_add_del_address_range_t_handler
787 (vl_api_nat44_add_del_address_range_t * mp)
789 snat_main_t *sm = &snat_main;
790 vl_api_nat44_add_del_address_range_reply_t *rmp;
791 ip4_address_t this_addr;
792 u8 is_add, twice_nat;
793 u32 start_host_order, end_host_order;
799 if (sm->static_mapping_only)
801 rv = VNET_API_ERROR_FEATURE_DISABLED;
806 twice_nat = mp->flags & NAT_API_IS_TWICE_NAT;
808 tmp = (u32 *) mp->first_ip_address;
809 start_host_order = clib_host_to_net_u32 (tmp[0]);
810 tmp = (u32 *) mp->last_ip_address;
811 end_host_order = clib_host_to_net_u32 (tmp[0]);
813 count = (end_host_order - start_host_order) + 1;
815 vrf_id = clib_host_to_net_u32 (mp->vrf_id);
818 nat_log_info ("%U - %U, %d addresses...",
819 format_ip4_address, mp->first_ip_address,
820 format_ip4_address, mp->last_ip_address, count);
822 memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
824 for (i = 0; i < count; i++)
827 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
829 rv = snat_del_address (sm, this_addr, 0, twice_nat);
835 nat44_add_del_address_dpo (this_addr, is_add);
837 increment_v4_address (&this_addr);
841 REPLY_MACRO (VL_API_NAT44_ADD_DEL_ADDRESS_RANGE_REPLY);
844 static void *vl_api_nat44_add_del_address_range_t_print
845 (vl_api_nat44_add_del_address_range_t * mp, void *handle)
849 s = format (0, "SCRIPT: nat44_add_address_range ");
850 s = format (s, "%U ", format_ip4_address, mp->first_ip_address);
851 if (memcmp (mp->first_ip_address, mp->last_ip_address, 4))
853 s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
855 s = format (s, "twice_nat %d ", mp->flags & NAT_API_IS_TWICE_NAT);
860 send_nat44_address_details (snat_address_t * a,
861 vl_api_registration_t * reg, u32 context,
864 vl_api_nat44_address_details_t *rmp;
865 snat_main_t *sm = &snat_main;
867 rmp = vl_msg_api_alloc (sizeof (*rmp));
868 clib_memset (rmp, 0, sizeof (*rmp));
869 rmp->_vl_msg_id = ntohs (VL_API_NAT44_ADDRESS_DETAILS + sm->msg_id_base);
870 clib_memcpy (rmp->ip_address, &(a->addr), 4);
871 if (a->fib_index != ~0)
873 fib_table_t *fib = fib_table_get (a->fib_index, FIB_PROTOCOL_IP4);
874 rmp->vrf_id = ntohl (fib->ft_table_id);
879 rmp->flags |= NAT_API_IS_TWICE_NAT;
880 rmp->context = context;
882 vl_api_send_msg (reg, (u8 *) rmp);
886 vl_api_nat44_address_dump_t_handler (vl_api_nat44_address_dump_t * mp)
888 vl_api_registration_t *reg;
889 snat_main_t *sm = &snat_main;
892 reg = vl_api_client_index_to_registration (mp->client_index);
897 vec_foreach (a, sm->addresses)
898 send_nat44_address_details (a, reg, mp->context, 0);
899 vec_foreach (a, sm->twice_nat_addresses)
900 send_nat44_address_details (a, reg, mp->context, 1);
905 vl_api_nat44_address_dump_t_print (vl_api_nat44_address_dump_t * mp,
910 s = format (0, "SCRIPT: nat44_address_dump ");
916 vl_api_nat44_interface_add_del_feature_t_handler
917 (vl_api_nat44_interface_add_del_feature_t * mp)
919 snat_main_t *sm = &snat_main;
920 vl_api_nat44_interface_add_del_feature_reply_t *rmp;
921 u32 sw_if_index = ntohl (mp->sw_if_index);
925 is_del = !mp->is_add;
927 VALIDATE_SW_IF_INDEX (mp);
930 snat_interface_add_del (sw_if_index, mp->flags & NAT_API_IS_INSIDE,
933 BAD_SW_IF_INDEX_LABEL;
935 REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_FEATURE_REPLY);
938 static void *vl_api_nat44_interface_add_del_feature_t_print
939 (vl_api_nat44_interface_add_del_feature_t * mp, void *handle)
943 s = format (0, "SCRIPT: nat44_interface_add_del_feature ");
944 s = format (s, "sw_if_index %d %s %s",
945 clib_host_to_net_u32 (mp->sw_if_index),
946 mp->flags & NAT_API_IS_INSIDE ? "in" : "out",
947 mp->is_add ? "" : "del");
953 send_nat44_interface_details (snat_interface_t * i,
954 vl_api_registration_t * reg, u32 context)
956 vl_api_nat44_interface_details_t *rmp;
957 snat_main_t *sm = &snat_main;
959 rmp = vl_msg_api_alloc (sizeof (*rmp));
960 clib_memset (rmp, 0, sizeof (*rmp));
961 rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_DETAILS + sm->msg_id_base);
962 rmp->sw_if_index = ntohl (i->sw_if_index);
964 if (nat_interface_is_inside (i))
965 rmp->flags |= NAT_API_IS_INSIDE;
966 if (nat_interface_is_outside (i))
967 rmp->flags |= NAT_API_IS_OUTSIDE;
969 rmp->context = context;
971 vl_api_send_msg (reg, (u8 *) rmp);
975 vl_api_nat44_interface_dump_t_handler (vl_api_nat44_interface_dump_t * mp)
977 vl_api_registration_t *reg;
978 snat_main_t *sm = &snat_main;
981 reg = vl_api_client_index_to_registration (mp->client_index);
986 pool_foreach (i, sm->interfaces,
988 send_nat44_interface_details(i, reg, mp->context);
994 vl_api_nat44_interface_dump_t_print (vl_api_nat44_interface_dump_t * mp,
999 s = format (0, "SCRIPT: nat44_interface_dump ");
1005 vl_api_nat44_interface_add_del_output_feature_t_handler
1006 (vl_api_nat44_interface_add_del_output_feature_t * mp)
1008 snat_main_t *sm = &snat_main;
1009 vl_api_nat44_interface_add_del_output_feature_reply_t *rmp;
1010 u32 sw_if_index = ntohl (mp->sw_if_index);
1013 VALIDATE_SW_IF_INDEX (mp);
1015 rv = snat_interface_add_del_output_feature (sw_if_index,
1016 mp->flags & NAT_API_IS_INSIDE,
1019 BAD_SW_IF_INDEX_LABEL;
1020 REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY);
1023 static void *vl_api_nat44_interface_add_del_output_feature_t_print
1024 (vl_api_nat44_interface_add_del_output_feature_t * mp, void *handle)
1028 s = format (0, "SCRIPT: nat44_interface_add_del_output_feature ");
1029 s = format (s, "sw_if_index %d %s %s",
1030 clib_host_to_net_u32 (mp->sw_if_index),
1031 mp->flags & NAT_API_IS_INSIDE ? "in" : "out",
1032 mp->is_add ? "" : "del");
1038 send_nat44_interface_output_feature_details (snat_interface_t * i,
1039 vl_api_registration_t * reg,
1042 vl_api_nat44_interface_output_feature_details_t *rmp;
1043 snat_main_t *sm = &snat_main;
1045 rmp = vl_msg_api_alloc (sizeof (*rmp));
1046 clib_memset (rmp, 0, sizeof (*rmp));
1048 ntohs (VL_API_NAT44_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base);
1049 rmp->sw_if_index = ntohl (i->sw_if_index);
1050 rmp->context = context;
1052 if (nat_interface_is_inside (i))
1053 rmp->flags |= NAT_API_IS_INSIDE;
1055 vl_api_send_msg (reg, (u8 *) rmp);
1059 vl_api_nat44_interface_output_feature_dump_t_handler
1060 (vl_api_nat44_interface_output_feature_dump_t * mp)
1062 vl_api_registration_t *reg;
1063 snat_main_t *sm = &snat_main;
1064 snat_interface_t *i;
1066 reg = vl_api_client_index_to_registration (mp->client_index);
1071 pool_foreach (i, sm->output_feature_interfaces,
1073 send_nat44_interface_output_feature_details(i, reg, mp->context);
1078 static void *vl_api_nat44_interface_output_feature_dump_t_print
1079 (vl_api_nat44_interface_output_feature_dump_t * mp, void *handle)
1083 s = format (0, "SCRIPT: nat44_interface_output_feature_dump ");
1089 vl_api_nat44_add_del_static_mapping_t_handler
1090 (vl_api_nat44_add_del_static_mapping_t * mp)
1092 snat_main_t *sm = &snat_main;
1093 vl_api_nat44_add_del_static_mapping_reply_t *rmp;
1094 ip4_address_t local_addr, external_addr, pool_addr = { 0 };
1095 u16 local_port = 0, external_port = 0;
1096 u32 vrf_id, external_sw_if_index;
1097 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1099 nat_protocol_t proto;
1102 memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
1103 memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
1105 if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1107 local_port = mp->local_port;
1108 external_port = mp->external_port;
1111 vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1112 external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
1113 proto = ip_proto_to_nat_proto (mp->protocol);
1115 if (mp->flags & NAT_API_IS_TWICE_NAT)
1116 twice_nat = TWICE_NAT;
1117 else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
1118 twice_nat = TWICE_NAT_SELF;
1119 mp->tag[sizeof (mp->tag) - 1] = 0;
1120 tag = format (0, "%s", mp->tag);
1121 vec_terminate_c_string (tag);
1123 rv = snat_add_static_mapping (local_addr, external_addr, local_port,
1124 external_port, vrf_id,
1125 mp->flags & NAT_API_IS_ADDR_ONLY,
1126 external_sw_if_index, proto,
1127 mp->is_add, twice_nat,
1128 mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, 0,
1132 REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY);
1136 vl_api_nat44_add_del_static_mapping_v2_t_handler
1137 (vl_api_nat44_add_del_static_mapping_v2_t * mp)
1139 snat_main_t *sm = &snat_main;
1140 vl_api_nat44_add_del_static_mapping_v2_reply_t *rmp;
1141 ip4_address_t local_addr, external_addr, pool_addr;
1142 u16 local_port = 0, external_port = 0;
1143 u32 vrf_id, external_sw_if_index;
1144 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1146 nat_protocol_t proto;
1149 memcpy (&pool_addr.as_u8, mp->pool_ip_address, 4);
1150 memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
1151 memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
1153 if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1155 local_port = mp->local_port;
1156 external_port = mp->external_port;
1159 vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1160 external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
1161 proto = ip_proto_to_nat_proto (mp->protocol);
1163 if (mp->flags & NAT_API_IS_TWICE_NAT)
1164 twice_nat = TWICE_NAT;
1165 else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
1166 twice_nat = TWICE_NAT_SELF;
1167 mp->tag[sizeof (mp->tag) - 1] = 0;
1168 tag = format (0, "%s", mp->tag);
1169 vec_terminate_c_string (tag);
1171 rv = snat_add_static_mapping (local_addr, external_addr, local_port,
1172 external_port, vrf_id,
1173 mp->flags & NAT_API_IS_ADDR_ONLY,
1174 external_sw_if_index, proto,
1175 mp->is_add, twice_nat,
1176 mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, 0,
1177 pool_addr, mp->match_pool);
1180 REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_V2_REPLY);
1183 static void *vl_api_nat44_add_del_static_mapping_t_print
1184 (vl_api_nat44_add_del_static_mapping_t * mp, void *handle)
1188 s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
1189 s = format (s, "protocol %d local_addr %U external_addr %U ",
1191 format_ip4_address, mp->local_ip_address,
1192 format_ip4_address, mp->external_ip_address);
1194 if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1195 s = format (s, "local_port %d external_port %d ",
1196 clib_net_to_host_u16 (mp->local_port),
1197 clib_net_to_host_u16 (mp->external_port));
1199 s = format (s, "twice_nat %d out2in_only %d ",
1200 mp->flags & NAT_API_IS_TWICE_NAT,
1201 mp->flags & NAT_API_IS_OUT2IN_ONLY);
1203 if (mp->vrf_id != ~0)
1204 s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1206 if (mp->external_sw_if_index != ~0)
1207 s = format (s, "external_sw_if_index %d",
1208 clib_net_to_host_u32 (mp->external_sw_if_index));
1212 static void *vl_api_nat44_add_del_static_mapping_v2_t_print
1213 (vl_api_nat44_add_del_static_mapping_v2_t * mp, void *handle)
1217 s = format (0, "SCRIPT: nat44_add_del_static_mapping_v2 ");
1218 s = format (s, "protocol %d local_addr %U external_addr %U ",
1220 format_ip4_address, mp->local_ip_address,
1221 format_ip4_address, mp->external_ip_address);
1223 if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1224 s = format (s, "local_port %d external_port %d ",
1225 clib_net_to_host_u16 (mp->local_port),
1226 clib_net_to_host_u16 (mp->external_port));
1228 s = format (s, "twice_nat %d out2in_only %d ",
1229 mp->flags & NAT_API_IS_TWICE_NAT,
1230 mp->flags & NAT_API_IS_OUT2IN_ONLY);
1232 if (mp->vrf_id != ~0)
1233 s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1235 if (mp->external_sw_if_index != ~0)
1236 s = format (s, "external_sw_if_index %d",
1237 clib_net_to_host_u32 (mp->external_sw_if_index));
1239 s = format (s, "match pool address %U",
1240 format_ip4_address, mp->pool_ip_address);
1246 send_nat44_static_mapping_details (snat_static_mapping_t * m,
1247 vl_api_registration_t * reg, u32 context)
1249 vl_api_nat44_static_mapping_details_t *rmp;
1250 snat_main_t *sm = &snat_main;
1251 u32 len = sizeof (*rmp);
1253 rmp = vl_msg_api_alloc (len);
1254 clib_memset (rmp, 0, len);
1256 ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1258 clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
1259 clib_memcpy (rmp->external_ip_address, &(m->external_addr), 4);
1260 rmp->external_sw_if_index = ~0;
1261 rmp->vrf_id = htonl (m->vrf_id);
1262 rmp->context = context;
1264 if (m->twice_nat == TWICE_NAT)
1265 rmp->flags |= NAT_API_IS_TWICE_NAT;
1266 else if (m->twice_nat == TWICE_NAT_SELF)
1267 rmp->flags |= NAT_API_IS_SELF_TWICE_NAT;
1269 if (is_out2in_only_static_mapping (m))
1270 rmp->flags |= NAT_API_IS_OUT2IN_ONLY;
1272 if (is_addr_only_static_mapping (m))
1274 rmp->flags |= NAT_API_IS_ADDR_ONLY;
1278 rmp->protocol = nat_proto_to_ip_proto (m->proto);
1279 rmp->external_port = m->external_port;
1280 rmp->local_port = m->local_port;
1284 strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1286 vl_api_send_msg (reg, (u8 *) rmp);
1290 send_nat44_static_map_resolve_details (snat_static_map_resolve_t * m,
1291 vl_api_registration_t * reg,
1294 vl_api_nat44_static_mapping_details_t *rmp;
1295 snat_main_t *sm = &snat_main;
1297 rmp = vl_msg_api_alloc (sizeof (*rmp));
1298 clib_memset (rmp, 0, sizeof (*rmp));
1300 ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base);
1301 clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
1302 rmp->external_sw_if_index = htonl (m->sw_if_index);
1303 rmp->vrf_id = htonl (m->vrf_id);
1304 rmp->context = context;
1307 rmp->flags |= NAT_API_IS_TWICE_NAT;
1311 rmp->flags |= NAT_API_IS_ADDR_ONLY;
1315 rmp->protocol = nat_proto_to_ip_proto (m->proto);
1316 rmp->external_port = m->e_port;
1317 rmp->local_port = m->l_port;
1320 strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1322 vl_api_send_msg (reg, (u8 *) rmp);
1326 vl_api_nat44_static_mapping_dump_t_handler (vl_api_nat44_static_mapping_dump_t
1329 vl_api_registration_t *reg;
1330 snat_main_t *sm = &snat_main;
1331 snat_static_mapping_t *m;
1332 snat_static_map_resolve_t *rp;
1335 reg = vl_api_client_index_to_registration (mp->client_index);
1340 pool_foreach (m, sm->static_mappings,
1342 if (!is_identity_static_mapping(m) && !is_lb_static_mapping (m))
1343 send_nat44_static_mapping_details (m, reg, mp->context);
1347 for (j = 0; j < vec_len (sm->to_resolve); j++)
1349 rp = sm->to_resolve + j;
1350 if (!rp->identity_nat)
1351 send_nat44_static_map_resolve_details (rp, reg, mp->context);
1356 vl_api_nat44_static_mapping_dump_t_print (vl_api_nat44_static_mapping_dump_t *
1361 s = format (0, "SCRIPT: nat44_static_mapping_dump ");
1367 vl_api_nat44_add_del_identity_mapping_t_handler
1368 (vl_api_nat44_add_del_identity_mapping_t * mp)
1370 snat_main_t *sm = &snat_main;
1371 vl_api_nat44_add_del_identity_mapping_reply_t *rmp;
1372 ip4_address_t addr, pool_addr = { 0 };
1374 u32 vrf_id, sw_if_index;
1376 nat_protocol_t proto = NAT_PROTOCOL_OTHER;
1379 if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1382 proto = ip_proto_to_nat_proto (mp->protocol);
1384 vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1385 sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1386 if (sw_if_index != ~0)
1389 memcpy (&addr.as_u8, mp->ip_address, 4);
1390 mp->tag[sizeof (mp->tag) - 1] = 0;
1391 tag = format (0, "%s", mp->tag);
1392 vec_terminate_c_string (tag);
1395 snat_add_static_mapping (addr, addr, port, port, vrf_id,
1396 mp->flags & NAT_API_IS_ADDR_ONLY, sw_if_index,
1397 proto, mp->is_add, 0, 0, tag, 1, pool_addr, 0);
1400 REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY);
1403 static void *vl_api_nat44_add_del_identity_mapping_t_print
1404 (vl_api_nat44_add_del_identity_mapping_t * mp, void *handle)
1408 s = format (0, "SCRIPT: nat44_add_del_identity_mapping ");
1409 if (mp->sw_if_index != ~0)
1410 s = format (s, "sw_if_index %d", clib_net_to_host_u32 (mp->sw_if_index));
1412 s = format (s, "addr %U", format_ip4_address, mp->ip_address);
1414 if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
1416 format (s, " protocol %d port %d", mp->protocol,
1417 clib_net_to_host_u16 (mp->port));
1419 if (mp->vrf_id != ~0)
1420 s = format (s, " vrf %d", clib_net_to_host_u32 (mp->vrf_id));
1426 send_nat44_identity_mapping_details (snat_static_mapping_t * m, int index,
1427 vl_api_registration_t * reg, u32 context)
1429 vl_api_nat44_identity_mapping_details_t *rmp;
1430 snat_main_t *sm = &snat_main;
1431 nat44_lb_addr_port_t *local = pool_elt_at_index (m->locals, index);
1433 rmp = vl_msg_api_alloc (sizeof (*rmp));
1434 clib_memset (rmp, 0, sizeof (*rmp));
1436 ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
1438 if (is_addr_only_static_mapping (m))
1439 rmp->flags |= NAT_API_IS_ADDR_ONLY;
1441 clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
1442 rmp->port = m->local_port;
1443 rmp->sw_if_index = ~0;
1444 rmp->vrf_id = htonl (local->vrf_id);
1445 rmp->protocol = nat_proto_to_ip_proto (m->proto);
1446 rmp->context = context;
1448 strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1450 vl_api_send_msg (reg, (u8 *) rmp);
1454 send_nat44_identity_map_resolve_details (snat_static_map_resolve_t * m,
1455 vl_api_registration_t * reg,
1458 vl_api_nat44_identity_mapping_details_t *rmp;
1459 snat_main_t *sm = &snat_main;
1461 rmp = vl_msg_api_alloc (sizeof (*rmp));
1462 clib_memset (rmp, 0, sizeof (*rmp));
1464 ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
1467 rmp->flags = (vl_api_nat_config_flags_t) NAT_API_IS_ADDR_ONLY;
1469 rmp->port = m->l_port;
1470 rmp->sw_if_index = htonl (m->sw_if_index);
1471 rmp->vrf_id = htonl (m->vrf_id);
1472 rmp->protocol = nat_proto_to_ip_proto (m->proto);
1473 rmp->context = context;
1475 strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
1477 vl_api_send_msg (reg, (u8 *) rmp);
1481 vl_api_nat44_identity_mapping_dump_t_handler
1482 (vl_api_nat44_identity_mapping_dump_t * mp)
1484 vl_api_registration_t *reg;
1485 snat_main_t *sm = &snat_main;
1486 snat_static_mapping_t *m;
1487 snat_static_map_resolve_t *rp;
1490 reg = vl_api_client_index_to_registration (mp->client_index);
1495 pool_foreach (m, sm->static_mappings,
1497 if (is_identity_static_mapping(m) && !is_lb_static_mapping (m))
1499 pool_foreach_index (j, m->locals,
1501 send_nat44_identity_mapping_details (m, j, reg, mp->context);
1507 for (j = 0; j < vec_len (sm->to_resolve); j++)
1509 rp = sm->to_resolve + j;
1510 if (rp->identity_nat)
1511 send_nat44_identity_map_resolve_details (rp, reg, mp->context);
1515 static void *vl_api_nat44_identity_mapping_dump_t_print
1516 (vl_api_nat44_identity_mapping_dump_t * mp, void *handle)
1520 s = format (0, "SCRIPT: nat44_identity_mapping_dump ");
1526 vl_api_nat44_add_del_interface_addr_t_handler
1527 (vl_api_nat44_add_del_interface_addr_t * mp)
1529 snat_main_t *sm = &snat_main;
1530 vl_api_nat44_add_del_interface_addr_reply_t *rmp;
1531 u32 sw_if_index = ntohl (mp->sw_if_index);
1535 is_del = !mp->is_add;
1537 VALIDATE_SW_IF_INDEX (mp);
1539 rv = snat_add_interface_address (sm, sw_if_index, is_del,
1540 mp->flags & NAT_API_IS_TWICE_NAT);
1542 BAD_SW_IF_INDEX_LABEL;
1543 REPLY_MACRO (VL_API_NAT44_ADD_DEL_INTERFACE_ADDR_REPLY);
1546 static void *vl_api_nat44_add_del_interface_addr_t_print
1547 (vl_api_nat44_add_del_interface_addr_t * mp, void *handle)
1551 s = format (0, "SCRIPT: nat44_add_del_interface_addr ");
1552 s = format (s, "sw_if_index %d twice_nat %d %s",
1553 clib_host_to_net_u32 (mp->sw_if_index),
1554 mp->flags & NAT_API_IS_TWICE_NAT, mp->is_add ? "" : "del");
1560 send_nat44_interface_addr_details (u32 sw_if_index,
1561 vl_api_registration_t * reg, u32 context,
1564 vl_api_nat44_interface_addr_details_t *rmp;
1565 snat_main_t *sm = &snat_main;
1567 rmp = vl_msg_api_alloc (sizeof (*rmp));
1568 clib_memset (rmp, 0, sizeof (*rmp));
1570 ntohs (VL_API_NAT44_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
1571 rmp->sw_if_index = ntohl (sw_if_index);
1574 rmp->flags = (vl_api_nat_config_flags_t) NAT_API_IS_TWICE_NAT;
1575 rmp->context = context;
1577 vl_api_send_msg (reg, (u8 *) rmp);
1581 vl_api_nat44_interface_addr_dump_t_handler (vl_api_nat44_interface_addr_dump_t
1584 vl_api_registration_t *reg;
1585 snat_main_t *sm = &snat_main;
1588 reg = vl_api_client_index_to_registration (mp->client_index);
1593 vec_foreach (i, sm->auto_add_sw_if_indices)
1594 send_nat44_interface_addr_details(*i, reg, mp->context, 0);
1595 vec_foreach (i, sm->auto_add_sw_if_indices_twice_nat)
1596 send_nat44_interface_addr_details(*i, reg, mp->context, 1);
1601 vl_api_nat44_interface_addr_dump_t_print (vl_api_nat44_interface_addr_dump_t *
1606 s = format (0, "SCRIPT: nat44_interface_addr_dump ");
1612 send_nat44_user_details (snat_user_t * u, vl_api_registration_t * reg,
1615 vl_api_nat44_user_details_t *rmp;
1616 snat_main_t *sm = &snat_main;
1617 ip4_main_t *im = &ip4_main;
1619 rmp = vl_msg_api_alloc (sizeof (*rmp));
1620 clib_memset (rmp, 0, sizeof (*rmp));
1621 rmp->_vl_msg_id = ntohs (VL_API_NAT44_USER_DETAILS + sm->msg_id_base);
1623 if (!pool_is_free_index (im->fibs, u->fib_index))
1625 fib_table_t *fib = fib_table_get (u->fib_index, FIB_PROTOCOL_IP4);
1626 rmp->vrf_id = ntohl (fib->ft_table_id);
1629 clib_memcpy (rmp->ip_address, &(u->addr), 4);
1630 rmp->nsessions = ntohl (u->nsessions);
1631 rmp->nstaticsessions = ntohl (u->nstaticsessions);
1632 rmp->context = context;
1634 vl_api_send_msg (reg, (u8 *) rmp);
1638 nat_ed_user_create_helper (snat_main_per_thread_data_t * tsm,
1642 k.addr = s->in2out.addr;
1643 k.fib_index = s->in2out.fib_index;
1644 clib_bihash_kv_8_8_t key, value;
1647 if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
1649 pool_get (tsm->users, u);
1651 u->fib_index = k.fib_index;
1653 u->nstaticsessions = 0;
1654 key.value = u - tsm->users;
1655 clib_bihash_add_del_8_8 (&tsm->user_hash, &key, 1);
1659 u = pool_elt_at_index (tsm->users, value.value);
1661 if (snat_is_session_static (s))
1663 ++u->nstaticsessions;
1672 nat_ed_users_create (snat_main_per_thread_data_t * tsm)
1676 pool_foreach (s, tsm->sessions, { nat_ed_user_create_helper (tsm, s); });
1681 nat_ed_users_destroy (snat_main_per_thread_data_t * tsm)
1685 pool_flush (u, tsm->users, { });
1687 clib_bihash_free_8_8 (&tsm->user_hash);
1688 clib_bihash_init_8_8 (&tsm->user_hash, "users", snat_main.user_buckets,
1689 snat_main.user_memory_size);
1690 clib_bihash_set_kvp_format_fn_8_8 (&tsm->user_hash, format_user_kvp);
1694 vl_api_nat44_user_dump_t_handler (vl_api_nat44_user_dump_t * mp)
1696 vl_api_registration_t *reg;
1697 snat_main_t *sm = &snat_main;
1698 snat_main_per_thread_data_t *tsm;
1701 reg = vl_api_client_index_to_registration (mp->client_index);
1706 vec_foreach (tsm, sm->per_thread_data)
1708 if (sm->endpoint_dependent)
1710 nat_ed_users_create (tsm);
1712 pool_foreach (u, tsm->users,
1714 send_nat44_user_details (u, reg, mp->context);
1716 if (sm->endpoint_dependent)
1718 nat_ed_users_destroy (tsm);
1725 vl_api_nat44_user_dump_t_print (vl_api_nat44_user_dump_t * mp, void *handle)
1729 s = format (0, "SCRIPT: nat44_user_dump ");
1735 send_nat44_user_session_details (snat_session_t * s,
1736 vl_api_registration_t * reg, u32 context)
1738 vl_api_nat44_user_session_details_t *rmp;
1739 snat_main_t *sm = &snat_main;
1741 rmp = vl_msg_api_alloc (sizeof (*rmp));
1742 clib_memset (rmp, 0, sizeof (*rmp));
1744 ntohs (VL_API_NAT44_USER_SESSION_DETAILS + sm->msg_id_base);
1745 clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
1746 clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
1748 if (snat_is_session_static (s))
1749 rmp->flags |= NAT_API_IS_STATIC;
1751 if (is_twice_nat_session (s))
1752 rmp->flags |= NAT_API_IS_TWICE_NAT;
1754 if (is_ed_session (s) || is_fwd_bypass_session (s))
1755 rmp->flags |= NAT_API_IS_EXT_HOST_VALID;
1757 rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
1758 rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
1759 rmp->total_pkts = ntohl (s->total_pkts);
1760 rmp->context = context;
1761 if (snat_is_unk_proto_session (s))
1763 rmp->outside_port = 0;
1764 rmp->inside_port = 0;
1765 rmp->protocol = ntohs (s->in2out.port);
1769 rmp->outside_port = s->out2in.port;
1770 rmp->inside_port = s->in2out.port;
1771 rmp->protocol = ntohs (nat_proto_to_ip_proto (s->nat_proto));
1773 if (is_ed_session (s) || is_fwd_bypass_session (s))
1775 clib_memcpy (rmp->ext_host_address, &s->ext_host_addr, 4);
1776 rmp->ext_host_port = s->ext_host_port;
1777 if (is_twice_nat_session (s))
1779 clib_memcpy (rmp->ext_host_nat_address, &s->ext_host_nat_addr, 4);
1780 rmp->ext_host_nat_port = s->ext_host_nat_port;
1784 vl_api_send_msg (reg, (u8 *) rmp);
1788 vl_api_nat44_user_session_dump_t_handler (vl_api_nat44_user_session_dump_t *
1791 vl_api_registration_t *reg;
1792 snat_main_t *sm = &snat_main;
1793 snat_main_per_thread_data_t *tsm;
1795 clib_bihash_kv_8_8_t key, value;
1796 snat_user_key_t ukey;
1798 u32 session_index, head_index, elt_index;
1799 dlist_elt_t *head, *elt;
1802 reg = vl_api_client_index_to_registration (mp->client_index);
1806 clib_memcpy (&ukey.addr, mp->ip_address, 4);
1807 ip.src_address.as_u32 = ukey.addr.as_u32;
1808 ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
1809 key.key = ukey.as_u64;
1810 if (sm->num_workers > 1)
1812 vec_elt_at_index (sm->per_thread_data,
1813 sm->worker_in2out_cb (&ip, ukey.fib_index, 0));
1815 tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
1816 if (!sm->endpoint_dependent)
1818 if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
1820 u = pool_elt_at_index (tsm->users, value.value);
1821 if (!u->nsessions && !u->nstaticsessions)
1824 head_index = u->sessions_per_user_list_head_index;
1825 head = pool_elt_at_index (tsm->list_pool, head_index);
1826 elt_index = head->next;
1827 elt = pool_elt_at_index (tsm->list_pool, elt_index);
1828 session_index = elt->value;
1829 while (session_index != ~0)
1831 s = pool_elt_at_index (tsm->sessions, session_index);
1833 send_nat44_user_session_details (s, reg, mp->context);
1835 elt_index = elt->next;
1836 elt = pool_elt_at_index (tsm->list_pool, elt_index);
1837 session_index = elt->value;
1843 pool_foreach (s, tsm->sessions, {
1844 if (s->in2out.addr.as_u32 == ukey.addr.as_u32)
1846 send_nat44_user_session_details (s, reg, mp->context);
1854 vl_api_nat44_user_session_dump_t_print (vl_api_nat44_user_session_dump_t * mp,
1859 s = format (0, "SCRIPT: nat44_user_session_dump ");
1860 s = format (s, "ip_address %U vrf_id %d\n",
1861 format_ip4_address, mp->ip_address,
1862 clib_net_to_host_u32 (mp->vrf_id));
1867 static nat44_lb_addr_port_t *
1868 unformat_nat44_lb_addr_port (vl_api_nat44_lb_addr_port_t * addr_port_pairs,
1869 u32 addr_port_pair_num)
1872 nat44_lb_addr_port_t *lb_addr_port_pairs = 0, lb_addr_port;
1873 vl_api_nat44_lb_addr_port_t *ap;
1875 for (i = 0; i < addr_port_pair_num; i++)
1877 ap = &addr_port_pairs[i];
1878 clib_memset (&lb_addr_port, 0, sizeof (lb_addr_port));
1879 clib_memcpy (&lb_addr_port.addr, ap->addr, 4);
1880 lb_addr_port.port = ap->port;
1881 lb_addr_port.probability = ap->probability;
1882 lb_addr_port.vrf_id = clib_net_to_host_u32 (ap->vrf_id);
1883 vec_add1 (lb_addr_port_pairs, lb_addr_port);
1886 return lb_addr_port_pairs;
1890 vl_api_nat44_add_del_lb_static_mapping_t_handler
1891 (vl_api_nat44_add_del_lb_static_mapping_t * mp)
1893 snat_main_t *sm = &snat_main;
1894 vl_api_nat44_add_del_lb_static_mapping_reply_t *rmp;
1895 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1897 nat44_lb_addr_port_t *locals = 0;
1898 ip4_address_t e_addr;
1899 nat_protocol_t proto;
1902 if (!sm->endpoint_dependent)
1904 rv = VNET_API_ERROR_UNSUPPORTED;
1909 unformat_nat44_lb_addr_port (mp->locals,
1910 clib_net_to_host_u32 (mp->local_num));
1911 clib_memcpy (&e_addr, mp->external_addr, 4);
1912 proto = ip_proto_to_nat_proto (mp->protocol);
1914 if (mp->flags & NAT_API_IS_TWICE_NAT)
1915 twice_nat = TWICE_NAT;
1916 else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
1917 twice_nat = TWICE_NAT_SELF;
1918 mp->tag[sizeof (mp->tag) - 1] = 0;
1919 tag = format (0, "%s", mp->tag);
1920 vec_terminate_c_string (tag);
1923 nat44_add_del_lb_static_mapping (e_addr,
1925 proto, locals, mp->is_add,
1927 mp->flags & NAT_API_IS_OUT2IN_ONLY, tag,
1928 clib_net_to_host_u32 (mp->affinity));
1934 REPLY_MACRO (VL_API_NAT44_ADD_DEL_LB_STATIC_MAPPING_REPLY);
1937 static void *vl_api_nat44_add_del_lb_static_mapping_t_print
1938 (vl_api_nat44_add_del_lb_static_mapping_t * mp, void *handle)
1942 s = format (0, "SCRIPT: nat44_add_del_lb_static_mapping ");
1943 s = format (s, "is_add %d twice_nat %d out2in_only %d ",
1945 mp->flags & NAT_API_IS_TWICE_NAT,
1946 mp->flags & NAT_API_IS_OUT2IN_ONLY);
1952 vl_api_nat44_lb_static_mapping_add_del_local_t_handler
1953 (vl_api_nat44_lb_static_mapping_add_del_local_t * mp)
1955 snat_main_t *sm = &snat_main;
1956 vl_api_nat44_lb_static_mapping_add_del_local_reply_t *rmp;
1958 ip4_address_t e_addr, l_addr;
1959 nat_protocol_t proto;
1961 if (!sm->endpoint_dependent)
1963 rv = VNET_API_ERROR_UNSUPPORTED;
1967 clib_memcpy (&e_addr, mp->external_addr, 4);
1968 clib_memcpy (&l_addr, mp->local.addr, 4);
1969 proto = ip_proto_to_nat_proto (mp->protocol);
1972 nat44_lb_static_mapping_add_del_local (e_addr,
1973 clib_net_to_host_u16
1974 (mp->external_port), l_addr,
1975 clib_net_to_host_u16 (mp->
1978 clib_net_to_host_u32 (mp->
1980 mp->local.probability, mp->is_add);
1983 REPLY_MACRO (VL_API_NAT44_LB_STATIC_MAPPING_ADD_DEL_LOCAL_REPLY);
1986 static void *vl_api_nat44_lb_static_mapping_add_del_local_t_print
1987 (vl_api_nat44_lb_static_mapping_add_del_local_t * mp, void *handle)
1991 s = format (0, "SCRIPT: nat44_lb_static_mapping_add_del_local ");
1992 s = format (s, "is_add %d", mp->is_add);
1998 send_nat44_lb_static_mapping_details (snat_static_mapping_t * m,
1999 vl_api_registration_t * reg,
2002 vl_api_nat44_lb_static_mapping_details_t *rmp;
2003 snat_main_t *sm = &snat_main;
2004 nat44_lb_addr_port_t *ap;
2005 vl_api_nat44_lb_addr_port_t *locals;
2009 vl_msg_api_alloc (sizeof (*rmp) +
2010 (pool_elts (m->locals) *
2011 sizeof (nat44_lb_addr_port_t)));
2012 clib_memset (rmp, 0, sizeof (*rmp));
2014 ntohs (VL_API_NAT44_LB_STATIC_MAPPING_DETAILS + sm->msg_id_base);
2016 clib_memcpy (rmp->external_addr, &(m->external_addr), 4);
2017 rmp->external_port = m->external_port;
2018 rmp->protocol = nat_proto_to_ip_proto (m->proto);
2019 rmp->context = context;
2021 if (m->twice_nat == TWICE_NAT)
2022 rmp->flags |= NAT_API_IS_TWICE_NAT;
2023 else if (m->twice_nat == TWICE_NAT_SELF)
2024 rmp->flags |= NAT_API_IS_SELF_TWICE_NAT;
2025 if (is_out2in_only_static_mapping (m))
2026 rmp->flags |= NAT_API_IS_OUT2IN_ONLY;
2028 strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
2030 locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
2032 pool_foreach (ap, m->locals,
2034 clib_memcpy (locals->addr, &(ap->addr), 4);
2035 locals->port = ap->port;
2036 locals->probability = ap->probability;
2037 locals->vrf_id = ntohl (ap->vrf_id);
2042 rmp->local_num = ntohl (local_num);
2044 vl_api_send_msg (reg, (u8 *) rmp);
2048 vl_api_nat44_lb_static_mapping_dump_t_handler
2049 (vl_api_nat44_lb_static_mapping_dump_t * mp)
2051 vl_api_registration_t *reg;
2052 snat_main_t *sm = &snat_main;
2053 snat_static_mapping_t *m;
2055 if (!sm->endpoint_dependent)
2058 reg = vl_api_client_index_to_registration (mp->client_index);
2063 pool_foreach (m, sm->static_mappings,
2065 if (is_lb_static_mapping(m))
2066 send_nat44_lb_static_mapping_details (m, reg, mp->context);
2071 static void *vl_api_nat44_lb_static_mapping_dump_t_print
2072 (vl_api_nat44_lb_static_mapping_dump_t * mp, void *handle)
2076 s = format (0, "SCRIPT: nat44_lb_static_mapping_dump ");
2082 vl_api_nat44_del_session_t_handler (vl_api_nat44_del_session_t * mp)
2084 snat_main_t *sm = &snat_main;
2085 vl_api_nat44_del_session_reply_t *rmp;
2086 ip4_address_t addr, eh_addr;
2091 nat_protocol_t proto;
2093 memcpy (&addr.as_u8, mp->address, 4);
2095 vrf_id = clib_net_to_host_u32 (mp->vrf_id);
2096 proto = ip_proto_to_nat_proto (mp->protocol);
2097 memcpy (&eh_addr.as_u8, mp->ext_host_address, 4);
2098 eh_port = mp->ext_host_port;
2100 is_in = mp->flags & NAT_API_IS_INSIDE;
2102 if (mp->flags & NAT_API_IS_EXT_HOST_VALID)
2104 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port, mp->protocol,
2107 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
2109 REPLY_MACRO (VL_API_NAT44_DEL_SESSION_REPLY);
2113 vl_api_nat44_del_session_t_print (vl_api_nat44_del_session_t * mp,
2118 s = format (0, "SCRIPT: nat44_add_del_session ");
2119 s = format (s, "addr %U port %d protocol %d vrf_id %d is_in %d",
2120 format_ip4_address, mp->address,
2121 clib_net_to_host_u16 (mp->port),
2122 mp->protocol, clib_net_to_host_u32 (mp->vrf_id),
2123 mp->flags & NAT_API_IS_INSIDE);
2124 if (mp->flags & NAT_API_IS_EXT_HOST_VALID)
2125 s = format (s, "ext_host_address %U ext_host_port %d",
2126 format_ip4_address, mp->ext_host_address,
2127 clib_net_to_host_u16 (mp->ext_host_port));
2133 vl_api_nat44_forwarding_enable_disable_t_handler
2134 (vl_api_nat44_forwarding_enable_disable_t * mp)
2136 snat_main_t *sm = &snat_main;
2137 vl_api_nat44_forwarding_enable_disable_reply_t *rmp;
2139 u32 *ses_to_be_removed = 0, *ses_index;
2140 snat_main_per_thread_data_t *tsm;
2143 sm->forwarding_enabled = mp->enable != 0;
2145 if (mp->enable == 0)
2148 vec_foreach (tsm, sm->per_thread_data)
2150 pool_foreach (s, tsm->sessions,
2152 if (is_fwd_bypass_session(s))
2154 vec_add1 (ses_to_be_removed, s - tsm->sessions);
2157 if(sm->endpoint_dependent){
2158 vec_foreach (ses_index, ses_to_be_removed)
2160 s = pool_elt_at_index(tsm->sessions, ses_index[0]);
2161 nat_free_session_data (sm, s, tsm - sm->per_thread_data, 0);
2162 nat_ed_session_delete (sm, s, tsm - sm->per_thread_data, 1);
2165 vec_foreach (ses_index, ses_to_be_removed)
2167 s = pool_elt_at_index(tsm->sessions, ses_index[0]);
2168 nat_free_session_data (sm, s, tsm - sm->per_thread_data, 0);
2169 nat44_delete_session (sm, s, tsm - sm->per_thread_data);
2172 vec_free (ses_to_be_removed);
2177 REPLY_MACRO (VL_API_NAT44_FORWARDING_ENABLE_DISABLE_REPLY);
2180 static void *vl_api_nat44_forwarding_enable_disable_t_print
2181 (vl_api_nat44_forwarding_enable_disable_t * mp, void *handle)
2185 s = format (0, "SCRIPT: nat44_forwarding_enable_disable ");
2186 s = format (s, "enable %d", mp->enable != 0);
2192 vl_api_nat44_forwarding_is_enabled_t_handler
2193 (vl_api_nat44_forwarding_is_enabled_t * mp)
2195 vl_api_registration_t *reg;
2196 snat_main_t *sm = &snat_main;
2197 vl_api_nat44_forwarding_is_enabled_reply_t *rmp;
2199 reg = vl_api_client_index_to_registration (mp->client_index);
2203 rmp = vl_msg_api_alloc (sizeof (*rmp));
2204 clib_memset (rmp, 0, sizeof (*rmp));
2206 ntohs (VL_API_NAT44_FORWARDING_IS_ENABLED_REPLY + sm->msg_id_base);
2207 rmp->context = mp->context;
2209 rmp->enabled = sm->forwarding_enabled;
2211 vl_api_send_msg (reg, (u8 *) rmp);
2214 static void *vl_api_nat44_forwarding_is_enabled_t_print
2215 (vl_api_nat44_forwarding_is_enabled_t * mp, void *handle)
2219 s = format (0, "SCRIPT: nat44_forwarding_is_enabled ");
2224 /* List of message types that this plugin understands */
2225 #define foreach_snat_plugin_api_msg \
2226 _(NAT_CONTROL_PING, nat_control_ping) \
2227 _(NAT_SHOW_CONFIG, nat_show_config) \
2228 _(NAT_SHOW_CONFIG_2, nat_show_config_2) \
2229 _(NAT_SET_WORKERS, nat_set_workers) \
2230 _(NAT_WORKER_DUMP, nat_worker_dump) \
2231 _(NAT44_DEL_USER, nat44_del_user) \
2232 _(NAT44_SET_SESSION_LIMIT, nat44_set_session_limit) \
2233 _(NAT_SET_LOG_LEVEL, nat_set_log_level) \
2234 _(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \
2235 _(NAT_SET_TIMEOUTS, nat_set_timeouts) \
2236 _(NAT_GET_TIMEOUTS, nat_get_timeouts) \
2237 _(NAT_SET_ADDR_AND_PORT_ALLOC_ALG, nat_set_addr_and_port_alloc_alg) \
2238 _(NAT_GET_ADDR_AND_PORT_ALLOC_ALG, nat_get_addr_and_port_alloc_alg) \
2239 _(NAT_SET_MSS_CLAMPING, nat_set_mss_clamping) \
2240 _(NAT_GET_MSS_CLAMPING, nat_get_mss_clamping) \
2241 _(NAT_HA_SET_LISTENER, nat_ha_set_listener) \
2242 _(NAT_HA_SET_FAILOVER, nat_ha_set_failover) \
2243 _(NAT_HA_GET_LISTENER, nat_ha_get_listener) \
2244 _(NAT_HA_GET_FAILOVER, nat_ha_get_failover) \
2245 _(NAT_HA_FLUSH, nat_ha_flush) \
2246 _(NAT_HA_RESYNC, nat_ha_resync) \
2247 _(NAT44_ADD_DEL_ADDRESS_RANGE, nat44_add_del_address_range) \
2248 _(NAT44_INTERFACE_ADD_DEL_FEATURE, nat44_interface_add_del_feature) \
2249 _(NAT44_ADD_DEL_STATIC_MAPPING, nat44_add_del_static_mapping) \
2250 _(NAT44_ADD_DEL_STATIC_MAPPING_V2, nat44_add_del_static_mapping_v2) \
2251 _(NAT44_ADD_DEL_IDENTITY_MAPPING, nat44_add_del_identity_mapping) \
2252 _(NAT44_STATIC_MAPPING_DUMP, nat44_static_mapping_dump) \
2253 _(NAT44_IDENTITY_MAPPING_DUMP, nat44_identity_mapping_dump) \
2254 _(NAT44_ADDRESS_DUMP, nat44_address_dump) \
2255 _(NAT44_INTERFACE_DUMP, nat44_interface_dump) \
2256 _(NAT44_ADD_DEL_INTERFACE_ADDR, nat44_add_del_interface_addr) \
2257 _(NAT44_INTERFACE_ADDR_DUMP, nat44_interface_addr_dump) \
2258 _(NAT44_USER_DUMP, nat44_user_dump) \
2259 _(NAT44_USER_SESSION_DUMP, nat44_user_session_dump) \
2260 _(NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE, \
2261 nat44_interface_add_del_output_feature) \
2262 _(NAT44_INTERFACE_OUTPUT_FEATURE_DUMP, \
2263 nat44_interface_output_feature_dump) \
2264 _(NAT44_ADD_DEL_LB_STATIC_MAPPING, nat44_add_del_lb_static_mapping) \
2265 _(NAT44_LB_STATIC_MAPPING_ADD_DEL_LOCAL, \
2266 nat44_lb_static_mapping_add_del_local) \
2267 _(NAT44_LB_STATIC_MAPPING_DUMP, nat44_lb_static_mapping_dump) \
2268 _(NAT44_DEL_SESSION, nat44_del_session) \
2269 _(NAT44_FORWARDING_ENABLE_DISABLE, nat44_forwarding_enable_disable) \
2270 _(NAT44_FORWARDING_IS_ENABLED, nat44_forwarding_is_enabled)
2272 /* Set up the API message handling tables */
2273 static clib_error_t *
2274 snat_plugin_api_hookup (vlib_main_t * vm)
2276 snat_main_t *sm __attribute__ ((unused)) = &snat_main;
2278 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
2280 vl_api_##n##_t_handler, \
2282 vl_api_##n##_t_endian, \
2283 vl_api_##n##_t_print, \
2284 sizeof(vl_api_##n##_t), 1);
2285 foreach_snat_plugin_api_msg;
2291 #define vl_msg_name_crc_list
2292 #include <nat/nat_all_api_h.h>
2293 #undef vl_msg_name_crc_list
2296 setup_message_id_table (snat_main_t * sm, api_main_t * am)
2298 #define _(id,n,crc) \
2299 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
2300 foreach_vl_msg_name_crc_nat;
2305 plugin_custom_dump_configure (snat_main_t * sm)
2307 #define _(n,f) sm->api_main->msg_print_handlers \
2308 [VL_API_##n + sm->msg_id_base] \
2309 = (void *) vl_api_##f##_t_print;
2310 foreach_snat_plugin_api_msg;
2315 snat_api_init (vlib_main_t * vm, snat_main_t * sm)
2318 clib_error_t *error = 0;
2320 name = format (0, "nat_%08x%c", api_version, 0);
2322 /* Ask for a correctly-sized block of API message decode slots */
2324 vl_msg_api_get_msg_ids ((char *) name, VL_MSG_FIRST_AVAILABLE);
2326 error = snat_plugin_api_hookup (vm);
2328 /* Add our API messages to the global name_crc hash table */
2329 setup_message_id_table (sm, sm->api_main);
2331 plugin_custom_dump_configure (sm);
2339 * fd.io coding-style-patch-verification: ON
2342 * eval: (c-set-style "gnu")