31 #include <vpp/app/version.h> 48 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 50 #define REPLY_MSG_ID_BASE sm->msg_id_base 54 #define vl_api_version(n,v) static u32 api_version=(v); 61 vl_print (handle, (char *)s); \ 67 .arc_name =
"ip4-unicast",
68 .node_name =
"snat-in2out",
72 .arc_name =
"ip4-unicast",
73 .node_name =
"snat-out2in",
77 .arc_name =
"ip4-unicast",
78 .node_name =
"snat-det-in2out",
82 .arc_name =
"ip4-unicast",
83 .node_name =
"snat-det-out2in",
87 .arc_name =
"ip4-unicast",
88 .node_name =
"snat-in2out-worker-handoff",
92 .arc_name =
"ip4-unicast",
93 .node_name =
"snat-out2in-worker-handoff",
97 .arc_name =
"ip4-unicast",
98 .node_name =
"snat-in2out-fast",
102 .arc_name =
"ip4-unicast",
103 .node_name =
"snat-out2in-fast",
109 .version = VPP_BUILD_VER,
110 .description =
"Network Address Translation",
134 .ip4.as_u32 = addr->
as_u32,
177 #define _(N, i, n, s) \ 178 clib_bitmap_alloc (ap->busy_##n##_port_bitmap, 65535); 188 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
199 if (m->external_addr.as_u32 == addr.as_u32)
210 v = clib_net_to_host_u32(a->
as_u32) + 1;
211 a->
as_u32 = clib_host_to_net_u32(v);
255 u16 l_port,
u16 e_port,
u32 vrf_id,
int addr_only,
269 if (sw_if_index != ~0)
275 (sm->ip4_main, sw_if_index, 0 );
278 if (first_int_addr == 0)
281 (sm, l_addr, l_port, sw_if_index, e_port, vrf_id, proto,
290 m_key.
port = addr_only ? 0 : e_port;
291 m_key.
protocol = addr_only ? 0 : proto;
294 if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv, &value))
302 return VNET_API_ERROR_VALUE_EXIST;
307 p =
hash_get (sm->ip4_main->fib_index_by_table_id, vrf_id);
309 return VNET_API_ERROR_NO_SUCH_FIB;
315 fib_index = sm->inside_fib_index;
316 vrf_id = sm->inside_vrf_id;
321 if (!addr_only && !(sm->static_mapping_only))
323 for (i = 0; i <
vec_len (sm->addresses); i++)
325 if (sm->addresses[i].addr.as_u32 == e_addr.
as_u32)
327 a = sm->addresses +
i;
331 #define _(N, j, n, s) \ 332 case SNAT_PROTOCOL_##N: \ 333 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, e_port)) \ 334 return VNET_API_ERROR_INVALID_VALUE; \ 335 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \ 337 a->busy_##n##_ports++; \ 343 return VNET_API_ERROR_INVALID_VALUE_2;
350 return VNET_API_ERROR_NO_SUCH_ENTRY;
354 memset (m, 0,
sizeof (*m));
372 kv.
value = m - sm->static_mappings;
373 clib_bihash_add_del_8_8(&sm->static_mapping_by_local, &kv, 1);
379 kv.
value = m - sm->static_mappings;
380 clib_bihash_add_del_8_8(&sm->static_mapping_by_external, &kv, 1);
392 if (clib_bihash_search_8_8 (&sm->worker_by_in, &kv, &value))
394 kv.
value = sm->first_worker_index +
395 sm->workers[sm->next_worker++ %
vec_len (sm->workers)];
397 clib_bihash_add_del_8_8 (&sm->worker_by_in, &kv, 1);
406 w_key1.
fib_index = sm->outside_fib_index;
408 clib_bihash_add_del_8_8 (&sm->worker_by_out, &kv, 1);
414 return VNET_API_ERROR_NO_SUCH_ENTRY;
417 if (!addr_only && !(sm->static_mapping_only))
419 for (i = 0; i <
vec_len (sm->addresses); i++)
421 if (sm->addresses[i].addr.as_u32 == e_addr.
as_u32)
423 a = sm->addresses +
i;
426 #define _(N, j, n, s) \ 427 case SNAT_PROTOCOL_##N: \ 428 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \ 430 a->busy_##n##_ports--; \ 436 return VNET_API_ERROR_INVALID_VALUE_2;
448 clib_bihash_add_del_8_8(&sm->static_mapping_by_local, &kv, 0);
454 clib_bihash_add_del_8_8(&sm->static_mapping_by_external, &kv, 0);
457 if (!(sm->static_mapping_only) ||
458 (sm->static_mapping_only && sm->static_mapping_connection_tracking))
463 u32 elt_index, head_index, del_elt_index;
472 if (!clib_bihash_search_8_8 (&sm->user_hash, &kv, &value))
474 user_index = value.
value;
475 if (!clib_bihash_search_8_8 (&sm->worker_by_in, &kv, &value))
484 elt_index = head->
next;
486 ses_index = elt->
value;
487 while (ses_index != ~0)
490 del_elt_index = elt_index;
491 elt_index = elt->
next;
493 ses_index = elt->
value;
497 if ((s->out2in.addr.as_u32 != e_addr.
as_u32) &&
498 (clib_net_to_host_u16 (s->out2in.port) != e_port))
504 s->out2in.addr.as_u32,
508 s->in2out.fib_index);
510 value.
key = s->in2out.as_u64;
511 clib_bihash_add_del_8_8 (&sm->in2out, &value, 0);
512 value.
key = s->out2in.as_u64;
513 clib_bihash_add_del_8_8 (&sm->out2in, &value, 0);
526 clib_bihash_add_del_8_8 (&sm->user_hash, &kv, 0);
542 if (interface->is_inside)
545 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
556 u32 *ses_to_be_removed = 0, *ses_index;
566 for (i=0; i <
vec_len (sm->addresses); i++)
568 if (sm->addresses[i].addr.as_u32 == addr.
as_u32)
570 a = sm->addresses +
i;
575 return VNET_API_ERROR_NO_SUCH_ENTRY;
581 if (m->external_addr.as_u32 == addr.as_u32)
582 (void) snat_add_static_mapping (m->local_addr, m->external_addr,
583 m->local_port, m->external_port,
584 m->vrf_id, m->addr_only, ~0,
594 return VNET_API_ERROR_UNSPECIFIED;
599 if (a->busy_tcp_ports || a->busy_udp_ports || a->busy_icmp_ports)
604 if (ses->out2in.addr.as_u32 == addr.as_u32)
607 snat_ipfix_logging_nat44_ses_delete(ses->in2out.addr.as_u32,
608 ses->out2in.addr.as_u32,
609 ses->in2out.protocol,
612 ses->in2out.fib_index);
613 vec_add1 (ses_to_be_removed, ses - tsm->sessions);
614 kv.key = ses->in2out.as_u64;
615 clib_bihash_add_del_8_8 (&sm->in2out, &kv, 0);
616 kv.key = ses->out2in.as_u64;
617 clib_bihash_add_del_8_8 (&sm->out2in, &kv, 0);
618 clib_dlist_remove (tsm->list_pool, ses->per_user_index);
619 user_key.addr = ses->in2out.addr;
620 user_key.fib_index = ses->in2out.fib_index;
621 kv.key = user_key.as_u64;
622 if (!clib_bihash_search_8_8 (&sm->user_hash, &kv, &value))
624 u = pool_elt_at_index (tsm->users, value.value);
642 if (interface->is_inside)
645 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
656 const char * feature_name;
661 if (sm->static_mapping_only && !(sm->static_mapping_connection_tracking))
662 feature_name = is_inside ?
"snat-in2out-fast" :
"snat-out2in-fast";
665 if (sm->num_workers > 1 && !sm->deterministic)
666 feature_name = is_inside ?
"snat-in2out-worker-handoff" :
"snat-out2in-worker-handoff";
667 else if (sm->deterministic)
668 feature_name = is_inside ?
"snat-det-in2out" :
"snat-det-out2in";
670 feature_name = is_inside ?
"snat-in2out" :
"snat-out2in";
676 if (sm->fq_in2out_index == ~0 && !sm->deterministic && sm->num_workers > 1)
679 if (sm->fq_out2in_index == ~0 && !sm->deterministic && sm->num_workers > 1)
684 if (i->sw_if_index == sw_if_index)
687 pool_put (sm->interfaces, i);
689 return VNET_API_ERROR_VALUE_EXIST;
696 return VNET_API_ERROR_NO_SUCH_ENTRY;
715 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
720 snat_add_del_addr_to_fib(&dm->out_addr, dm->out_plen, sw_if_index, !is_del);
731 if (sm->num_workers < 2)
732 return VNET_API_ERROR_FEATURE_DISABLED;
735 return VNET_API_ERROR_INVALID_WORKER;
753 u32 start_host_order, end_host_order;
761 rv = VNET_API_ERROR_UNIMPLEMENTED;
765 if (sm->static_mapping_only)
767 rv = VNET_API_ERROR_FEATURE_DISABLED;
772 start_host_order = clib_host_to_net_u32 (tmp[0]);
774 end_host_order = clib_host_to_net_u32 (tmp[0]);
776 count = (end_host_order - start_host_order) + 1;
778 vrf_id = clib_host_to_net_u32 (mp->
vrf_id);
788 for (i = 0; i < count; i++)
810 s =
format (0,
"SCRIPT: snat_add_address_range ");
827 memset (rmp, 0,
sizeof (*rmp));
828 rmp->_vl_msg_id = ntohs (VL_API_SNAT_ADDRESS_DETAILS+sm->msg_id_base);
861 s =
format (0,
"SCRIPT: snat_address_dump ");
882 REPLY_MACRO(VL_API_SNAT_INTERFACE_ADD_DEL_FEATURE_REPLY);
890 s =
format (0,
"SCRIPT: snat_interface_add_del_feature ");
891 s =
format (s,
"sw_if_index %d %s %s",
907 memset (rmp, 0,
sizeof (*rmp));
908 rmp->_vl_msg_id = ntohs (VL_API_SNAT_INTERFACE_DETAILS+sm->msg_id_base);
930 send_snat_interface_details(i, q, mp->context);
939 s =
format (0,
"SCRIPT: snat_interface_dump ");
950 u16 local_port = 0, external_port = 0;
951 u32 vrf_id, external_sw_if_index;
957 rv = VNET_API_ERROR_UNIMPLEMENTED;
965 local_port = clib_net_to_host_u16 (mp->
local_port);
968 vrf_id = clib_net_to_host_u32 (mp->
vrf_id);
974 external_sw_if_index, proto, mp->
is_add);
985 s =
format (0,
"SCRIPT: snat_add_static_mapping ");
986 s =
format (s,
"protocol %d local_addr %U external_addr %U ",
992 s =
format (s,
"local_port %d external_port %d ",
997 s =
format (s,
"vrf %d", clib_net_to_host_u32 (mp->
vrf_id));
1000 s =
format (s,
"external_sw_if_index %d",
1013 memset (rmp, 0,
sizeof (*rmp));
1014 rmp->_vl_msg_id = ntohs (VL_API_SNAT_STATIC_MAPPING_DETAILS+sm->msg_id_base);
1037 memset (rmp, 0,
sizeof (*rmp));
1038 rmp->_vl_msg_id = ntohs (VL_API_SNAT_STATIC_MAPPING_DETAILS+sm->msg_id_base);
1068 send_snat_static_mapping_details (m, q, mp->context);
1071 for (j = 0; j <
vec_len (sm->to_resolve); j++)
1073 rp = sm->to_resolve + j;
1083 s =
format (0,
"SCRIPT: snat_static_mapping_dump ");
1098 rmp->
vpe_pid = ntohl (getpid());
1107 s =
format (0,
"SCRIPT: snat_control_ping ");
1131 sm->static_mapping_connection_tracking;
1141 s =
format (0,
"SCRIPT: snat_show_config ");
1156 if (sm->num_workers < 2)
1158 rv = VNET_API_ERROR_FEATURE_DISABLED;
1179 s =
format (0,
"SCRIPT: snat_set_workers ");
1186 s =
format (s,
",%d", i);
1203 memset (rmp, 0,
sizeof (*rmp));
1204 rmp->_vl_msg_id = ntohs (VL_API_SNAT_WORKER_DETAILS+sm->msg_id_base);
1236 s =
format (0,
"SCRIPT: snat_worker_dump ");
1261 REPLY_MACRO(VL_API_SNAT_ADD_DEL_INTERFACE_ADDR_REPLY);
1269 s =
format (0,
"SCRIPT: snat_add_del_interface_addr ");
1270 s =
format (s,
"sw_if_index %d %s",
1272 mp->
is_add ?
"" :
"del");
1285 memset (rmp, 0,
sizeof (*rmp));
1286 rmp->_vl_msg_id = ntohs (VL_API_SNAT_INTERFACE_ADDR_DETAILS+sm->msg_id_base);
1314 s =
format (0,
"SCRIPT: snat_interface_addr_dump ");
1329 clib_host_to_net_u16 (mp->
src_port));
1331 REPLY_MACRO (VL_API_SNAT_IPFIX_ENABLE_DISABLE_REPLY);
1339 s =
format (0,
"SCRIPT: snat_ipfix_enable_disable ");
1343 s =
format (s,
"src_port %d ", clib_net_to_host_u16 (mp->
src_port));
1345 s =
format (s,
"disable ");
1359 memset (rmp, 0,
sizeof (*rmp));
1360 rmp->_vl_msg_id = ntohs (VL_API_SNAT_USER_DETAILS+sm->msg_id_base);
1397 s =
format (0,
"SCRIPT: snat_user_dump ");
1410 memset (rmp, 0,
sizeof (*rmp));
1411 rmp->_vl_msg_id = ntohs (VL_API_SNAT_USER_SESSION_DETAILS+sm->msg_id_base);
1420 rmp->
total_bytes = clib_host_to_net_u64(s->total_bytes);
1438 u32 session_index, head_index, elt_index;
1450 if (!clib_bihash_search_8_8 (&sm->worker_by_in, &key, &value))
1454 if (clib_bihash_search_8_8 (&sm->user_hash, &key, &value))
1462 elt_index = head->
next;
1464 session_index = elt->
value;
1465 while (session_index != ~0)
1471 elt_index = elt->
next;
1473 session_index = elt->
value;
1482 s =
format (0,
"SCRIPT: snat_user_session_dump ");
1483 s =
format (s,
"ip_address %U vrf_id %d\n",
1485 clib_net_to_host_u32 (mp->
vrf_id));
1512 s =
format (0,
"SCRIPT: snat_add_det_map ");
1513 s =
format (s,
"inside address %U/%d outside address %U/%d\n",
1527 u16 lo_port = 0, hi_port = 0;
1536 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1559 s =
format (0,
"SCRIPT: smat_det_forward_t");
1560 s =
format (s,
"inside ip address %U\n",
1581 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1601 s =
format(0,
"SCRIPT: smat_det_reverse_t");
1602 s =
format(s,
"outside ip address %U outside port %d",
1616 memset (rmp, 0,
sizeof (*rmp));
1617 rmp->_vl_msg_id = ntohs (VL_API_SNAT_DET_MAP_DETAILS+sm->msg_id_base);
1652 s =
format (0,
"SCRIPT: snat_det_map_dump ");
1658 #define foreach_snat_plugin_api_msg \ 1659 _(SNAT_ADD_ADDRESS_RANGE, snat_add_address_range) \ 1660 _(SNAT_INTERFACE_ADD_DEL_FEATURE, snat_interface_add_del_feature) \ 1661 _(SNAT_ADD_STATIC_MAPPING, snat_add_static_mapping) \ 1662 _(SNAT_CONTROL_PING, snat_control_ping) \ 1663 _(SNAT_STATIC_MAPPING_DUMP, snat_static_mapping_dump) \ 1664 _(SNAT_SHOW_CONFIG, snat_show_config) \ 1665 _(SNAT_ADDRESS_DUMP, snat_address_dump) \ 1666 _(SNAT_INTERFACE_DUMP, snat_interface_dump) \ 1667 _(SNAT_SET_WORKERS, snat_set_workers) \ 1668 _(SNAT_WORKER_DUMP, snat_worker_dump) \ 1669 _(SNAT_ADD_DEL_INTERFACE_ADDR, snat_add_del_interface_addr) \ 1670 _(SNAT_INTERFACE_ADDR_DUMP, snat_interface_addr_dump) \ 1671 _(SNAT_IPFIX_ENABLE_DISABLE, snat_ipfix_enable_disable) \ 1672 _(SNAT_USER_DUMP, snat_user_dump) \ 1673 _(SNAT_USER_SESSION_DUMP, snat_user_session_dump) \ 1674 _(SNAT_ADD_DET_MAP, snat_add_det_map) \ 1675 _(SNAT_DET_FORWARD, snat_det_forward) \ 1676 _(SNAT_DET_REVERSE, snat_det_reverse) \ 1677 _(SNAT_DET_MAP_DUMP, snat_det_map_dump) 1685 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ 1687 vl_api_##n##_t_handler, \ 1689 vl_api_##n##_t_endian, \ 1690 vl_api_##n##_t_print, \ 1691 sizeof(vl_api_##n##_t), 1); 1698 #define vl_msg_name_crc_list 1700 #undef vl_msg_name_crc_list 1705 #define _(id,n,crc) \ 1706 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); 1707 foreach_vl_msg_name_crc_snat;
1713 #define _(n,f) sm->api_main->msg_print_handlers \ 1714 [VL_API_##n + sm->msg_id_base] \ 1715 = (void *) vl_api_##f##_t_print; 1727 u32 if_address_index,
1744 name =
format (0,
"snat_%08x%c", api_version, 0);
1753 sm->ip4_lookup_main = lm;
1755 sm->first_worker_index = 0;
1756 sm->next_worker = 0;
1757 sm->num_workers = 0;
1759 sm->fq_in2out_index = ~0;
1760 sm->fq_out2in_index = ~0;
1768 sm->num_workers = tr->
count;
1774 if (sm->num_workers > 1)
1776 for (i=0; i < sm->num_workers; i++)
1809 u16 port_host_byte_order = clib_net_to_host_u16 (k->
port);
1813 a = sm->addresses + address_index;
1817 #define _(N, i, n, s) \ 1818 case SNAT_PROTOCOL_##N: \ 1819 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 1820 port_host_byte_order) == 1); \ 1821 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 1822 port_host_byte_order, 0); \ 1823 a->busy_##n##_ports--; \ 1854 clib_bihash_8_8_t *mapping_hash = &sm->static_mapping_by_local;
1857 mapping_hash = &sm->static_mapping_by_external;
1860 m_key.
port = clib_net_to_host_u16 (match.
port);
1866 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
1872 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
1892 mapping->
fib_index = sm->outside_fib_index;
1904 u32 * address_indexp)
1910 for (i = 0; i <
vec_len (sm->addresses); i++)
1912 a = sm->addresses +
i;
1917 #define _(N, j, n, s) \ 1918 case SNAT_PROTOCOL_##N: \ 1919 if (a->busy_##n##_ports < (65535-1024)) \ 1923 portnum = random_u32 (&sm->random_seed); \ 1924 portnum &= 0xFFFF; \ 1925 if (portnum < 1024) \ 1927 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 1929 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 1930 a->busy_##n##_ports++; \ 1931 k->addr = a->addr; \ 1932 k->port = clib_host_to_net_u16(portnum); \ 1933 *address_indexp = i; \ 1960 u32 start_host_order, end_host_order;
1973 if (
unformat (line_input,
"%U - %U",
1977 else if (
unformat (line_input,
"tenant-vrf %u", &vrf_id))
1980 end_addr = start_addr;
1981 else if (
unformat (line_input,
"del"))
1991 if (sm->static_mapping_only)
1997 start_host_order = clib_host_to_net_u32 (start_addr.
as_u32);
1998 end_host_order = clib_host_to_net_u32 (end_addr.
as_u32);
2000 if (end_host_order < start_host_order)
2006 count = (end_host_order - start_host_order) + 1;
2014 this_addr = start_addr;
2016 for (i = 0; i < count; i++)
2025 case VNET_API_ERROR_NO_SUCH_ENTRY:
2028 case VNET_API_ERROR_UNSPECIFIED:
2045 .path =
"snat add address",
2046 .short_help =
"snat add addresses <ip4-range-start> [- <ip4-range-end>] " 2047 "[tenant-vrf <vrf-id>] [del]",
2060 u32 * inside_sw_if_indices = 0;
2061 u32 * outside_sw_if_indices = 0;
2075 vec_add1 (inside_sw_if_indices, sw_if_index);
2078 vec_add1 (outside_sw_if_indices, sw_if_index);
2079 else if (
unformat (line_input,
"del"))
2089 if (
vec_len (inside_sw_if_indices))
2091 for (i = 0; i <
vec_len(inside_sw_if_indices); i++)
2093 sw_if_index = inside_sw_if_indices[
i];
2098 if (
vec_len (outside_sw_if_indices))
2100 for (i = 0; i <
vec_len(outside_sw_if_indices); i++)
2102 sw_if_index = outside_sw_if_indices[
i];
2116 .path =
"set interface snat",
2118 .short_help =
"set interface snat in <intfc> out <intfc> [del]",
2124 u32 *r = va_arg (*args,
u32 *);
2127 #define _(N, i, n, s) else if (unformat (input, s)) *r = SNAT_PROTOCOL_##N; 2138 u32 i = va_arg (*args,
u32);
2143 #define _(N, j, n, str) case SNAT_PROTOCOL_##N: t = (u8 *) str; break; 2147 s =
format (s,
"unknown");
2161 u32 l_port = 0, e_port = 0, vrf_id = ~0;
2164 u32 sw_if_index = ~0;
2187 else if (
unformat (line_input,
"external %U %u",
2192 else if (
unformat (line_input,
"external %U",
2195 else if (
unformat (line_input,
"vrf %u", &vrf_id))
2199 else if (
unformat (line_input,
"del"))
2209 if (!addr_only && !proto_set)
2216 vrf_id, addr_only, sw_if_index, proto, is_add);
2220 case VNET_API_ERROR_INVALID_VALUE:
2223 case VNET_API_ERROR_NO_SUCH_ENTRY:
2229 case VNET_API_ERROR_NO_SUCH_FIB:
2232 case VNET_API_ERROR_VALUE_EXIST:
2260 .path =
"snat add static mapping",
2263 "snat add static mapping local tcp|udp|icmp <addr> [<port>] external <addr> [<port>] [vrf <table-id>] [del]",
2304 case VNET_API_ERROR_INVALID_WORKER:
2307 case VNET_API_ERROR_FEATURE_DISABLED:
2309 "Supported only if 2 or more workes available.");
2329 .path =
"set snat workers",
2332 "set snat workers <workers-list>",
2353 if (
unformat (line_input,
"domain %d", &domain_id))
2355 else if (
unformat (line_input,
"src-port %d", &src_port))
2357 else if (
unformat (line_input,
"disable"))
2391 .path =
"snat ipfix logging",
2393 .short_help =
"snat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2402 u32 next_worker_index = 0;
2410 if (clib_bihash_search_8_8 (&sm->worker_by_in, &kv0, &value0))
2413 next_worker_index = sm->first_worker_index;
2416 next_worker_index +=
2417 sm->workers[sm->next_worker++ % _vec_len (sm->workers)];
2421 kv0.
value = next_worker_index;
2422 clib_bihash_add_del_8_8 (&sm->worker_by_in, &kv0, 1);
2425 next_worker_index = value0.
value;
2427 return next_worker_index;
2437 u32 next_worker_index = 0;
2447 icmp46_header_t * icmp0 = (icmp46_header_t *) udp0;
2455 if (clib_bihash_search_8_8 (&sm->worker_by_out, &kv0, &value0))
2460 if (clib_bihash_search_8_8 (&sm->worker_by_out, &kv0, &value0))
2463 next_worker_index = sm->first_worker_index;
2466 next_worker_index +=
2467 sm->workers[sm->next_worker++ % _vec_len (sm->workers)];
2473 next_worker_index = value0.
value;
2477 kv0.
value = next_worker_index;
2478 clib_bihash_add_del_8_8 (&sm->worker_by_out, &kv0, 1);
2481 next_worker_index = value0.
value;
2483 return next_worker_index;
2490 u32 translation_buckets = 1024;
2491 u32 translation_memory_size = 128<<20;
2492 u32 user_buckets = 128;
2493 u32 user_memory_size = 64<<20;
2494 u32 max_translations_per_user = 100;
2495 u32 outside_vrf_id = 0;
2496 u32 inside_vrf_id = 0;
2497 u32 static_mapping_buckets = 1024;
2498 u32 static_mapping_memory_size = 64<<20;
2499 u8 static_mapping_only = 0;
2500 u8 static_mapping_connection_tracking = 0;
2503 sm->deterministic = 0;
2507 if (
unformat (input,
"translation hash buckets %d", &translation_buckets))
2509 else if (
unformat (input,
"translation hash memory %d",
2510 &translation_memory_size));
2511 else if (
unformat (input,
"user hash buckets %d", &user_buckets))
2513 else if (
unformat (input,
"user hash memory %d",
2516 else if (
unformat (input,
"max translations per user %d",
2517 &max_translations_per_user))
2519 else if (
unformat (input,
"outside VRF id %d",
2522 else if (
unformat (input,
"inside VRF id %d",
2525 else if (
unformat (input,
"static mapping only"))
2527 static_mapping_only = 1;
2528 if (
unformat (input,
"connection tracking"))
2529 static_mapping_connection_tracking = 1;
2531 else if (
unformat (input,
"deterministic"))
2532 sm->deterministic = 1;
2539 sm->translation_buckets = translation_buckets;
2540 sm->translation_memory_size = translation_memory_size;
2541 sm->user_buckets = user_buckets;
2542 sm->user_memory_size = user_memory_size;
2543 sm->max_translations_per_user = max_translations_per_user;
2544 sm->outside_vrf_id = outside_vrf_id;
2547 sm->inside_vrf_id = inside_vrf_id;
2550 sm->static_mapping_only = static_mapping_only;
2551 sm->static_mapping_connection_tracking = static_mapping_connection_tracking;
2553 if (sm->deterministic)
2564 if (!static_mapping_only ||
2565 (static_mapping_only && static_mapping_connection_tracking))
2570 clib_bihash_init_8_8 (&sm->worker_by_in,
"worker-by-in", user_buckets,
2573 clib_bihash_init_8_8 (&sm->worker_by_out,
"worker-by-out", user_buckets,
2578 clib_bihash_init_8_8 (&sm->in2out,
"in2out", translation_buckets,
2579 translation_memory_size);
2581 clib_bihash_init_8_8 (&sm->out2in,
"out2in", translation_buckets,
2582 translation_memory_size);
2584 clib_bihash_init_8_8 (&sm->user_hash,
"users", user_buckets,
2592 clib_bihash_init_8_8 (&sm->static_mapping_by_local,
2593 "static_mapping_by_local", static_mapping_buckets,
2594 static_mapping_memory_size);
2596 clib_bihash_init_8_8 (&sm->static_mapping_by_external,
2597 "static_mapping_by_external", static_mapping_buckets,
2598 static_mapping_memory_size);
2608 u32 i = va_arg (*args,
u32);
2613 #define _(v, N, str) case SNAT_SESSION_##N: t = (u8 *) str; break; 2617 t =
format (t,
"unknown");
2626 char * protocol_string =
"unknown";
2627 static char *protocol_strings[] = {
2634 protocol_string = protocol_strings[key->
protocol];
2636 s =
format (s,
"%U proto %s port %d fib %d",
2645 snat_session_t * sess = va_arg (*args, snat_session_t *);
2649 s =
format (s,
" last heard %.2f\n", sess->last_heard);
2650 s =
format (s,
" total pkts %d, total bytes %lld\n",
2651 sess->total_pkts, sess->total_bytes);
2653 s =
format (s,
" static translation\n");
2655 s =
format (s,
" dynamic translation\n");
2664 int verbose = va_arg (*args,
int);
2666 u32 elt_index, head_index;
2668 snat_session_t * sess;
2670 s =
format (s,
"%U: %d dynamic translations, %d static translations\n",
2681 elt_index = head->
next;
2683 session_index = elt->
value;
2685 while (session_index != ~0)
2691 elt_index = elt->
next;
2693 session_index = elt->
value;
2705 s =
format (s,
"local %U external %U vrf %d",
2710 s =
format (s,
"%U local %U:%d external %U:%d vrf %d",
2725 s =
format (s,
"local %U external %U vrf %d",
2731 s =
format (s,
"%U local %U:%d external %U:%d vrf %d",
2745 u32 in_offset, out_offset;
2747 u32 * i = va_arg (*args,
u32 *);
2750 in_addr.
as_u32 = clib_host_to_net_u32 (
2751 clib_net_to_host_u32(det_map->
in_addr.
as_u32) + user_index);
2752 in_offset = clib_net_to_host_u32(in_addr.
as_u32) -
2755 out_addr.
as_u32 = clib_host_to_net_u32(
2757 s =
format (s,
"in %U:%d out %U:%d external host %U:%d state: %U expire: %d\n",
2759 clib_net_to_host_u16 (ses->
in_port),
2783 u32 users_num = 0, sessions_num = 0, *worker, *sw_if_index;
2791 else if (
unformat (input,
"verbose"))
2794 if (sm->static_mapping_only)
2796 if (sm->static_mapping_connection_tracking)
2802 else if (sm->deterministic)
2815 vlib_cli_output (vm,
"%U %s", format_vnet_sw_interface_name, vnm,
2816 vnet_get_sw_interface (vnm, i->sw_if_index),
2817 i->is_inside ?
"in" :
"out");
2820 if (
vec_len (sm->auto_add_sw_if_indices))
2823 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
2838 #define _(N, i, n, s) \ 2839 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s); 2845 if (sm->num_workers > 1)
2859 if (sm->deterministic)
2867 vlib_cli_output (vm,
"in %U/%d out %U/%d\n",
2868 format_ip4_address, &dm->in_addr, dm->in_plen,
2869 format_ip4_address, &dm->out_addr, dm->out_plen);
2870 vlib_cli_output (vm,
" outside address sharing ratio: %d\n",
2872 vlib_cli_output (vm,
" number of ports per inside host: %d\n",
2873 dm->ports_per_host);
2874 vlib_cli_output (vm,
" sessions number: %d\n", dm->ses_num);
2877 vec_foreach_index (j, dm->sessions)
2879 ses = vec_elt_at_index (dm->sessions, j);
2881 vlib_cli_output (vm,
" %U", format_det_map_ses, dm, ses,
2890 if (sm->static_mapping_only && !(sm->static_mapping_connection_tracking))
2899 vlib_cli_output (vm,
"%U", format_snat_static_mapping, m);
2908 sessions_num +=
pool_elts (tsm->sessions);
2912 " %d static mappings",
2943 vlib_cli_output (vm,
" %U", format_snat_user, tsm, u,
2953 vlib_cli_output (vm,
"%U", format_snat_static_mapping, m);
2955 for (j = 0; j <
vec_len (sm->to_resolve); j++)
2957 rp = sm->to_resolve + j;
2969 .path =
"show snat",
2970 .short_help =
"show snat",
2981 u32 if_address_index,
2986 u32 *indices_to_delete = 0;
2990 for (i = 0; i <
vec_len(sm->auto_add_sw_if_indices); i++)
2992 if (sw_if_index == sm->auto_add_sw_if_indices[i])
2997 for (j = 0; j <
vec_len(sm->addresses); j++)
2998 if (sm->addresses[j].addr.as_u32 == address->
as_u32)
3003 for (j = 0; j <
vec_len (sm->to_resolve); j++)
3005 rp = sm->to_resolve + j;
3026 if (
vec_len(indices_to_delete))
3029 for (j =
vec_len(indices_to_delete)-1; j >= 0; j--)
3052 u32 *indices_to_delete = 0;
3058 for (i = 0; i <
vec_len(sm->auto_add_sw_if_indices); i++)
3060 if (sm->auto_add_sw_if_indices[i] == sw_if_index)
3069 for (j = 0; j <
vec_len (sm->to_resolve); j++)
3071 rp = sm->to_resolve + j;
3075 if (
vec_len(indices_to_delete))
3077 for (j =
vec_len(indices_to_delete)-1; j >= 0; j--)
3082 vec_del1(sm->auto_add_sw_if_indices, i);
3085 return VNET_API_ERROR_VALUE_EXIST;
3092 return VNET_API_ERROR_NO_SUCH_ENTRY;
3095 vec_add1(sm->auto_add_sw_if_indices, sw_if_index);
3123 sm->vnet_main, &sw_if_index))
3125 else if (
unformat (line_input,
"del"))
3155 .path =
"snat add interface address",
3156 .short_help =
"snat add interface address <interface> [del]",
3168 u32 in_plen, out_plen;
3182 else if (
unformat (line_input,
"del"))
3221 .path =
"snat deterministic add",
3222 .short_help =
"snat deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
3283 .path =
"snat deterministic forward",
3284 .short_help =
"snat deterministic forward <addr>",
3317 if (out_port < 1024 || out_port > 65535)
3348 .path =
"snat deterministic reverse",
3349 .short_help =
"snat deterministic reverse <addr>:<port>",
ip4_address_t external_addr
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
fib_node_index_t fib_table_entry_update_one_path(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_protocol_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Update the entry to have just one path.
static void vl_api_snat_add_det_map_t_handler(vl_api_snat_add_det_map_t *mp)
u8 external_ip_address[16]
static void vl_api_snat_add_del_interface_addr_t_handler(vl_api_snat_add_del_interface_addr_t *mp)
static void send_snat_user_session_details(snat_session_t *s, unix_shared_memory_queue_t *q, u32 context)
static void * vl_api_snat_worker_dump_t_print(vl_api_snat_worker_dump_t *mp, void *handle)
Add/del S-NAT address range.
static vlib_cli_command_t set_interface_snat_command
(constructor) VLIB_CLI_COMMAND (set_interface_snat_command)
#define vec_foreach_index(var, v)
Iterate over vector indices.
u32 sessions_per_user_list_head_index
static void vl_api_snat_interface_add_del_feature_t_handler(vl_api_snat_interface_add_del_feature_t *mp)
void snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id)
static void * vl_api_snat_add_det_map_t_print(vl_api_snat_add_det_map_t *mp, void *handle)
sll srl srl sll sra u16x4 i
static void * vl_api_snat_add_static_mapping_t_print(vl_api_snat_add_static_mapping_t *mp, void *handle)
static void sent_snat_det_map_details(snat_det_map_t *m, unix_shared_memory_queue_t *q, u32 context)
Add/delete S-NAT pool address from specific interfce.
ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Functions to call when interface address changes.
u8 * format_snat_session_state(u8 *s, va_list *args)
static void * vl_api_snat_interface_add_del_feature_t_print(vl_api_snat_interface_add_del_feature_t *mp, void *handle)
static void vl_api_snat_user_dump_t_handler(vl_api_snat_user_dump_t *mp)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
vnet_main_t * vnet_get_main(void)
int snat_alloc_outside_address_and_port(snat_main_t *sm, u32 fib_index, snat_session_key_t *k, u32 *address_indexp)
static void vl_api_snat_add_address_range_t_handler(vl_api_snat_add_address_range_t *mp)
#define REPLY_MACRO2(t, body)
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
static void snat_det_reverse(snat_det_map_t *dm, ip4_address_t *out_addr, u16 out_port, ip4_address_t *in_addr)
Add/delete S-NAT deterministic mapping.
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Dump S-NAT deterministic mappings.
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static void send_snat_worker_details(u32 worker_index, unix_shared_memory_queue_t *q, u32 context)
static void send_snat_user_details(snat_user_t *u, unix_shared_memory_queue_t *q, u32 context)
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
u8 * format_snat_static_map_to_resolve(u8 *s, va_list *args)
Enable/disable S-NAT IPFIX logging.
ip_lookup_main_t lookup_main
static void snat_det_forward(snat_det_map_t *dm, ip4_address_t *in_addr, ip4_address_t *out_addr, u16 *lo_port)
void snat_ipfix_logging_init(vlib_main_t *vm)
Initialize SNAT IPFIX logging.
static vlib_cli_command_t snat_add_interface_address_command
(constructor) VLIB_CLI_COMMAND (snat_add_interface_address_command)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
int snat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable SNAT IPFIX logging.
static void vl_api_snat_det_forward_t_handler(vl_api_snat_det_forward_t *mp)
unformat_function_t unformat_vnet_sw_interface
static u32 snat_get_worker_in2out_cb(ip4_header_t *ip0, u32 rx_fib_index0)
void snat_ipfix_logging_nat44_ses_delete(u32 src_ip, u32 nat_src_ip, snat_protocol_t snat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session delete event.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static clib_error_t * snat_init(vlib_main_t *vm)
static clib_error_t * add_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void vl_api_snat_add_static_mapping_t_handler(vl_api_snat_add_static_mapping_t *mp)
static void * vl_api_snat_det_reverse_t_print(vl_api_snat_det_reverse_t *mp, void *handle)
static void vl_api_snat_control_ping_t_handler(vl_api_snat_control_ping_t *mp)
static int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
S-NAT user's sessions response.
u8 * format_snat_key(u8 *s, va_list *args)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static void snat_add_static_mapping_when_resolved(snat_main_t *sm, ip4_address_t l_addr, u16 l_port, u32 sw_if_index, u16 e_port, u32 vrf_id, snat_protocol_t proto, int addr_only, int is_add)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
static void * vl_api_snat_control_ping_t_print(vl_api_snat_control_ping_t *mp, void *handle)
#define VLIB_INIT_FUNCTION(x)
ip4_address_t ext_host_addr
Get outside address and port range from inside address.
u8 * format_snat_user(u8 *s, va_list *args)
static void snat_ip4_add_del_interface_address_cb(ip4_main_t *im, uword opaque, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
A high priority source a plugin can use.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Aggregrate type for a prefix.
#define foreach_snat_plugin_api_msg
#define clib_error_return(e, args...)
static void * ip4_next_header(ip4_header_t *i)
static clib_error_t * snat_det_forward_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * snat_ipfix_logging_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * snat_plugin_api_hookup(vlib_main_t *vm)
S-NAT user's sessions.
static void * vl_api_snat_ipfix_enable_disable_t_print(vl_api_snat_ipfix_enable_disable_t *mp, void *handle)
u16 fp_len
The mask length.
Control ping from the client to the server response.
Add/delete S-NAT deterministic mapping reply.
static void * vl_api_snat_user_session_dump_t_print(vl_api_snat_user_session_dump_t *mp, void *handle)
uword unformat_snat_protocol(unformat_input_t *input, va_list *args)
static void vl_api_snat_interface_addr_dump_t_handler(vl_api_snat_interface_addr_dump_t *mp)
u32 translation_memory_size
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation.
static heap_elt_t * first(heap_header_t *h)
static vlib_cli_command_t snat_ipfix_logging_enable_disable_command
(constructor) VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command)
S-NAT static mapping details response.
vlib_worker_thread_t * vlib_worker_threads
format_function_t format_vnet_sw_interface_name
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
deterministic NAT definitions
static uword clib_bitmap_last_set(uword *ai)
Return the higest numbered set bit in a bitmap.
static u32 snat_get_worker_out2in_cb(ip4_header_t *ip0, u32 rx_fib_index0)
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation and create session if needed...
static void send_snat_static_mapping_details(snat_static_mapping_t *m, unix_shared_memory_queue_t *q, u32 context)
static int is_snat_address_used_in_static_mapping(snat_main_t *sm, ip4_address_t addr)
#define pool_put(P, E)
Free an object E in pool P.
S-NAT pool addresses interfaces details response.
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation and create session if needed...
u8 outside_ip_address[16]
Enable/disable S-NAT feature on the interface reply.
#define VLIB_CONFIG_FUNCTION(x, n,...)
#define vec_del1(v, i)
Delete the element at index I.
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm)
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
static void * vl_api_snat_address_dump_t_print(vl_api_snat_address_dump_t *mp, void *handle)
static void vl_api_snat_det_map_dump_t_handler(vl_api_snat_det_map_dump_t *mp)
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only)
Match SNAT static mapping.
static void increment_v4_address(ip4_address_t *a)
static void * vl_api_snat_det_map_dump_t_print(vl_api_snat_det_map_dump_t *mp, void *handle)
static clib_error_t * snat_add_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 * format_snat_session(u8 *s, va_list *args)
#define SNAT_DET_SES_PER_USER
Dump S-NAT static mappings.
VNET_FEATURE_INIT(ip4_snat_in2out, static)
u8 external_ip_address[16]
static void * vl_api_snat_set_workers_t_print(vl_api_snat_set_workers_t *mp, void *handle)
#define BAD_SW_IF_INDEX_LABEL
void * vl_msg_api_alloc(int nbytes)
static void send_snat_static_map_resolve_details(snat_static_map_resolve_t *m, unix_shared_memory_queue_t *q, u32 context)
static void send_snat_interface_addr_details(u32 sw_if_index, unix_shared_memory_queue_t *q, u32 context)
static clib_error_t * show_snat_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void * vl_api_snat_static_mapping_dump_t_print(vl_api_snat_static_mapping_dump_t *mp, void *handle)
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * add_static_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void fib_table_entry_delete(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Delete a FIB entry.
ip4_add_del_interface_address_function_t * function
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
Get outside address and port range from inside address.
Dump interfaces with S-NAT feature.
u8 * format_snat_protocol(u8 *s, va_list *args)
#define clib_warning(format, args...)
u32 max_translations_per_user
#define clib_memcpy(a, b, c)
static void send_snat_interface_details(snat_interface_t *i, unix_shared_memory_queue_t *q, u32 context)
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)
Add static mapping.
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
static clib_error_t * snat_config(vlib_main_t *vm, unformat_input_t *input)
static u32 ip4_fib_index_from_table_id(u32 table_id)
8 octet key, 8 octet key value pair
Enable/disable S-NAT IPFIX logging reply.
static void vl_api_snat_user_session_dump_t_handler(vl_api_snat_user_session_dump_t *mp)
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
S-NAT address details response.
Add S-NAT address range reply.
Add/delete S-NAT static mapping.
Enable/disable S-NAT feature on the interface.
#define VLIB_CLI_COMMAND(x,...)
void snat_ipfix_logging_addresses_exhausted(u32 pool_id)
Generate NAT addresses exhausted event.
static void vl_api_snat_ipfix_enable_disable_t_handler(vl_api_snat_ipfix_enable_disable_t *mp)
#define pool_put_index(p, i)
Free pool element with given index.
static clib_error_t * snat_det_map_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
static void vl_api_snat_set_workers_t_handler(vl_api_snat_set_workers_t *mp)
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
static snat_protocol_t ip_proto_to_snat_proto(u8 ip_proto)
u8 * format_snat_static_mapping(u8 *s, va_list *args)
static vlib_cli_command_t snat_det_map_command
(constructor) VLIB_CLI_COMMAND (snat_det_map_command)
static void vl_api_snat_show_config_t_handler(vl_api_snat_show_config_t *mp)
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
#define clib_bitmap_free(v)
Free a bitmap.
static void vl_api_snat_det_reverse_t_handler(vl_api_snat_det_reverse_t *mp)
static void * vl_api_snat_user_dump_t_print(vl_api_snat_user_dump_t *mp, void *handle)
uword * thread_registrations_by_name
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
u8 * format_det_map_ses(u8 *s, va_list *args)
#define VNET_FEATURES(...)
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.
static vlib_cli_command_t show_snat_command
(constructor) VLIB_CLI_COMMAND (show_snat_command)
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
static void vl_api_snat_static_mapping_dump_t_handler(vl_api_snat_static_mapping_dump_t *mp)
static void * vl_api_snat_add_del_interface_addr_t_print(vl_api_snat_add_del_interface_addr_t *mp, void *handle)
S-NAT workers details response.
static void vl_api_snat_interface_dump_t_handler(vl_api_snat_interface_dump_t *mp)
static vlib_cli_command_t snat_det_reverse_command
(constructor) VLIB_CLI_COMMAND (snat_det_reverse_command)
static void * vl_api_snat_det_forward_t_print(vl_api_snat_det_forward_t *mp, void *handle)
static void * vl_api_snat_add_address_range_t_print(vl_api_snat_add_address_range_t *mp, void *handle)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static snat_det_map_t * snat_det_map_by_user(snat_main_t *sm, ip4_address_t *user_addr)
static int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del)
static uword unformat_bitmap_list(unformat_input_t *input, va_list *va)
unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
static vlib_cli_command_t add_address_command
(constructor) VLIB_CLI_COMMAND (add_address_command)
static void * vl_api_snat_show_config_t_print(vl_api_snat_show_config_t *mp, void *handle)
void snat_free_outside_address_and_port(snat_main_t *sm, snat_session_key_t *k, u32 address_index)
static vlib_cli_command_t add_static_mapping_command
(constructor) VLIB_CLI_COMMAND (add_static_mapping_command)
S-NAT interface details response.
#define hash_get_mem(h, key)
Dump S-NAT pool addresses interfaces.
static void send_snat_address_details(snat_address_t *a, unix_shared_memory_queue_t *q, u32 context)
Show S-NAT plugin startup config reply.
ip4_main_t ip4_main
Global ip4 main structure.
static vlib_thread_main_t * vlib_get_thread_main()
Control ping from client to api server request.
static void vl_api_snat_worker_dump_t_handler(vl_api_snat_worker_dump_t *mp)
Get inside address from outside address and port reply.
#define vec_foreach(var, vec)
Vector iterator.
static void vl_api_snat_address_dump_t_handler(vl_api_snat_address_dump_t *mp)
static vlib_cli_command_t snat_det_forward_command
(constructor) VLIB_CLI_COMMAND (snat_det_forward_command)
static void plugin_custom_dump_configure(snat_main_t *sm)
u16 vl_msg_api_get_msg_ids(char *name, int n)
u8 static_mapping_connection_tracking
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation.
#define SNAT_SESSION_FLAG_STATIC_MAPPING
Add/delete S-NAT static mapping reply.
static vlib_cli_command_t set_workers_command
(constructor) VLIB_CLI_COMMAND (set_workers_command)
static void * vl_api_snat_interface_dump_t_print(vl_api_snat_interface_dump_t *mp, void *handle)
Show S-NAT plugin startup config.
static clib_error_t * snat_det_reverse_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
snat_session_t * sessions
static clib_error_t * snat_feature_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
static clib_error_t * set_workers_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Get inside address from outside address and port.
Add/delete S-NAT pool address from specific interfce reply.
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
static void * vl_api_snat_interface_addr_dump_t_print(vl_api_snat_interface_addr_dump_t *mp, void *handle)
#define VALIDATE_SW_IF_INDEX(mp)
static int snat_set_workers(uword *bitmap)
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static uword pool_elts(void *v)
Number of active elements in a pool.