37 #include <vpp/app/version.h> 45 .arc_name =
"ip4-unicast",
46 .node_name =
"nat44-in2out",
50 .arc_name =
"ip4-unicast",
51 .node_name =
"nat44-out2in",
53 "ip4-dhcp-client-detect"),
56 .arc_name =
"ip4-unicast",
57 .node_name =
"nat44-classify",
61 .arc_name =
"ip4-unicast",
62 .node_name =
"nat44-det-in2out",
66 .arc_name =
"ip4-unicast",
67 .node_name =
"nat44-det-out2in",
69 "ip4-dhcp-client-detect"),
72 .arc_name =
"ip4-unicast",
73 .node_name =
"nat44-det-classify",
77 .arc_name =
"ip4-unicast",
78 .node_name =
"nat44-ed-in2out",
82 .arc_name =
"ip4-unicast",
83 .node_name =
"nat44-ed-out2in",
85 "ip4-dhcp-client-detect"),
88 .arc_name =
"ip4-unicast",
89 .node_name =
"nat44-ed-classify",
93 .arc_name =
"ip4-unicast",
94 .node_name =
"nat44-in2out-worker-handoff",
98 .arc_name =
"ip4-unicast",
99 .node_name =
"nat44-out2in-worker-handoff",
101 "ip4-dhcp-client-detect"),
104 .arc_name =
"ip4-unicast",
105 .node_name =
"nat44-handoff-classify",
109 .arc_name =
"ip4-unicast",
110 .node_name =
"nat44-in2out-fast",
114 .arc_name =
"ip4-unicast",
115 .node_name =
"nat44-out2in-fast",
117 "ip4-dhcp-client-detect"),
120 .arc_name =
"ip4-unicast",
121 .node_name =
"nat44-hairpin-dst",
125 .arc_name =
"ip4-unicast",
126 .node_name =
"nat44-ed-hairpin-dst",
132 .arc_name =
"ip4-output",
133 .node_name =
"nat44-in2out-output",
137 .arc_name =
"ip4-output",
138 .node_name =
"nat44-in2out-output-worker-handoff",
142 .arc_name =
"ip4-output",
143 .node_name =
"nat44-hairpin-src",
147 .arc_name =
"ip4-output",
148 .node_name =
"nat44-ed-in2out-output",
152 .arc_name =
"ip4-output",
153 .node_name =
"nat44-ed-hairpin-src",
160 .arc_name =
"ip4-local",
161 .node_name =
"nat44-hairpinning",
166 .arc_name =
"ip4-local",
167 .node_name =
"nat44-ed-hairpinning",
173 .version = VPP_BUILD_VER,
174 .description =
"Network Address Translation (NAT)",
191 ed_key.
l_addr = s->in2out.addr;
192 ed_key.
r_addr = s->ext_host_addr;
193 ed_key.
l_port = s->in2out.port;
194 ed_key.
r_port = s->ext_host_port;
199 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0))
209 s->in2out.protocol, s->out2in.port);
210 ed_key.
l_addr = s->out2in.addr;
211 ed_key.
r_addr = s->ext_host_addr;
215 ed_key.
proto = s->in2out.port;
222 ed_key.
l_port = s->out2in.port;
223 ed_key.
r_port = s->ext_host_port;
227 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &ed_kv, 0))
229 ed_key.
l_addr = s->in2out.addr;
232 ed_key.
l_port = s->in2out.port;
235 ed_key.
r_addr = s->ext_host_nat_addr;
236 ed_key.
r_port = s->ext_host_nat_port;
240 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0))
245 &s->in2out.addr, s->in2out.port,
246 &s->ext_host_nat_addr, s->ext_host_nat_port,
247 &s->out2in.addr, s->out2in.port,
248 &s->ext_host_addr, s->ext_host_port,
253 kv.
key = s->in2out.as_u64;
254 if (clib_bihash_add_del_8_8 (&tsm->
in2out, &kv, 0))
256 kv.
key = s->out2in.as_u64;
257 if (clib_bihash_add_del_8_8 (&tsm->
out2in, &kv, 0))
262 &s->in2out.addr, s->in2out.port,
263 &s->out2in.addr, s->out2in.port,
274 s->in2out.addr.as_u32,
275 s->out2in.addr.as_u32,
279 s->in2out.fib_index);
281 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
282 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
290 key.
port = s->ext_host_nat_port;
291 key.
addr.
as_u32 = s->ext_host_nat_addr.as_u32;
318 if (clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
336 if (clib_bihash_add_del_8_8 (&tsm->
user_hash, &kv, 1))
352 u32 thread_index,
f64 now)
356 u32 oldest_per_user_translation_list_index, session_index;
363 oldest_per_user_translation_list_index =
367 ASSERT (oldest_per_user_translation_list_index != ~0);
372 oldest_per_user_translation_list_index);
374 oldest_per_user_translation_list_elt =
376 oldest_per_user_translation_list_index);
379 session_index = oldest_per_user_translation_list_elt->
value;
392 s->ext_host_addr.as_u32 = 0;
393 s->ext_host_port = 0;
394 s->ext_host_nat_addr.as_u32 = 0;
395 s->ext_host_nat_port = 0;
405 per_user_translation_list_elt - tsm->
list_pool);
408 s->per_user_index = per_user_translation_list_elt - tsm->
list_pool;
412 s->per_user_list_head_index,
413 per_user_translation_list_elt - tsm->
list_pool);
415 s->user_index = u - tsm->
users;
420 s->ha_last_refreshed = now;
431 dlist_elt_t *per_user_translation_list_elt, *oldest_elt;
433 u64 sess_timeout_time;
444 if (now >= sess_timeout_time)
457 s->ext_host_addr.as_u32 = 0;
458 s->ext_host_port = 0;
459 s->ext_host_nat_addr.as_u32 = 0;
460 s->ext_host_nat_port = 0;
484 per_user_translation_list_elt - tsm->
list_pool);
487 s->per_user_index = per_user_translation_list_elt - tsm->
list_pool;
491 s->per_user_list_head_index,
492 per_user_translation_list_elt - tsm->
list_pool);
499 s->ha_last_refreshed = now;
512 .ip4.as_u32 = addr->
as_u32,
541 return VNET_API_ERROR_FEATURE_DISABLED;
548 return VNET_API_ERROR_VALUE_EXIST;
564 #define _(N, i, n, s) \ 565 clib_bitmap_alloc (ap->busy_##n##_port_bitmap, 65535); \ 566 ap->busy_##n##_ports = 0; \ 567 ap->busy_##n##_ports_per_thread = 0;\ 568 vec_validate_init_empty (ap->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0); 578 if (nat_interface_is_inside(i) || sm->out2in_dpo)
581 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
586 if (nat_interface_is_inside(i) || sm->out2in_dpo)
589 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
604 if (is_addr_only_static_mapping (m) ||
605 is_out2in_only_static_mapping (m) ||
606 is_identity_static_mapping (m))
608 if (m->external_addr.as_u32 == addr.as_u32)
621 v = clib_net_to_host_u32 (a->
as_u32) + 1;
622 a->
as_u32 = clib_host_to_net_u32 (v);
633 int addr_only,
int is_add,
u8 * tag,
634 int twice_nat,
int out2in_only,
670 u16 l_port,
u16 e_port,
u32 vrf_id,
int addr_only,
687 u32 elt_index, head_index;
697 if (twice_nat || out2in_only)
698 return VNET_API_ERROR_FEATURE_DISABLED;
702 if (sw_if_index != ~0)
717 || rp->
proto != proto)
732 return VNET_API_ERROR_VALUE_EXIST;
735 (sm, l_addr, l_port, sw_if_index, e_port, vrf_id, proto,
736 addr_only, is_add, tag, twice_nat, out2in_only, identity_nat);
739 if (first_int_addr == 0)
754 return VNET_API_ERROR_NO_SUCH_ENTRY;
771 m_key.
port = addr_only ? 0 : e_port;
772 m_key.
protocol = addr_only ? 0 : proto;
789 if (local->vrf_id == vrf_id)
790 return VNET_API_ERROR_VALUE_EXIST;
808 return VNET_API_ERROR_VALUE_EXIST;
811 if (twice_nat && addr_only)
812 return VNET_API_ERROR_UNSUPPORTED;
826 if (!(out2in_only || identity_nat))
829 m_key.
port = addr_only ? 0 : l_port;
830 m_key.
protocol = addr_only ? 0 : proto;
833 if (!clib_bihash_search_8_8
835 return VNET_API_ERROR_VALUE_EXIST;
850 #define _(N, j, n, s) \ 851 case SNAT_PROTOCOL_##N: \ 852 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, e_port)) \ 853 return VNET_API_ERROR_INVALID_VALUE; \ 854 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \ 857 a->busy_##n##_ports++; \ 858 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ 865 return VNET_API_ERROR_INVALID_VALUE_2;
873 if (sw_if_index != ~0)
890 return VNET_API_ERROR_NO_SUCH_ENTRY;
956 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
958 user_index = value.
value;
964 elt_index = head->
next;
966 ses_index = elt->
value;
967 while (ses_index != ~0)
971 ses_index = elt->
value;
977 && (clib_net_to_host_u16 (s->in2out.port) !=
996 if (sw_if_index != ~0)
999 return VNET_API_ERROR_NO_SUCH_ENTRY;
1010 if (local->vrf_id == vrf_id)
1011 find = local - m->locals;
1015 return VNET_API_ERROR_NO_SUCH_ENTRY;
1034 #define _(N, j, n, s) \ 1035 case SNAT_PROTOCOL_##N: \ 1036 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \ 1037 if (e_port > 1024) \ 1039 a->busy_##n##_ports--; \ 1040 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ 1047 return VNET_API_ERROR_INVALID_VALUE_2;
1074 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
1076 user_index = value.
value;
1082 elt_index = head->
next;
1084 ses_index = elt->
value;
1085 while (ses_index != ~0)
1089 ses_index = elt->
value;
1093 if ((s->out2in.addr.as_u32 != e_addr.
as_u32) ||
1094 (clib_net_to_host_u16 (s->out2in.port) !=
1139 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1142 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
1147 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1150 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
1163 u8 * tag,
u32 affinity)
1172 u32 elt_index, head_index, ses_index;
1181 return VNET_API_ERROR_FEATURE_DISABLED;
1183 m_key.
addr = e_addr;
1184 m_key.
port = e_port;
1196 return VNET_API_ERROR_VALUE_EXIST;
1199 return VNET_API_ERROR_INVALID_VALUE;
1213 #define _(N, j, n, s) \ 1214 case SNAT_PROTOCOL_##N: \ 1215 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, e_port)) \ 1216 return VNET_API_ERROR_INVALID_VALUE; \ 1217 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \ 1218 if (e_port > 1024) \ 1220 a->busy_##n##_ports++; \ 1221 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ 1228 return VNET_API_ERROR_INVALID_VALUE_2;
1235 return VNET_API_ERROR_NO_SUCH_ENTRY;
1264 nat_log_err (
"static_mapping_by_external key add failed");
1265 return VNET_API_ERROR_UNSPECIFIED;
1269 for (i = 0; i <
vec_len (locals); i++)
1284 locals[
i].
prefix = (i == 0) ? locals[i].probability :
1285 (locals[i - 1].
prefix + locals[i].probability);
1313 return VNET_API_ERROR_NO_SUCH_ENTRY;
1316 return VNET_API_ERROR_INVALID_VALUE;
1328 #define _(N, j, n, s) \ 1329 case SNAT_PROTOCOL_##N: \ 1330 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \ 1331 if (e_port > 1024) \ 1333 a->busy_##n##_ports--; \ 1334 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ 1341 return VNET_API_ERROR_INVALID_VALUE_2;
1355 nat_log_err (
"static_mapping_by_external key del failed");
1356 return VNET_API_ERROR_UNSPECIFIED;
1362 fib_table_unlock (local->fib_index, FIB_PROTOCOL_IP4,
1363 FIB_SOURCE_PLUGIN_LOW);
1364 m_key.addr = local->addr;
1367 m_key.port = local->port;
1368 m_key.fib_index = local->fib_index;
1369 kv.key = m_key.as_u64;
1370 if (clib_bihash_add_del_8_8(&sm->static_mapping_by_local, &kv, 0))
1372 nat_log_err (
"static_mapping_by_local key del failed");
1373 return VNET_API_ERROR_UNSPECIFIED;
1380 .src_address = local->addr,
1392 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
1399 elt_index = head->
next;
1401 ses_index = elt->
value;
1402 while (ses_index != ~0)
1406 ses_index = elt->
value;
1411 if ((s->in2out.addr.as_u32 != local->
addr.
as_u32) ||
1412 (clib_net_to_host_u16 (s->in2out.port) != local->
port))
1450 u32 elt_index, head_index, ses_index, *locals = 0;
1455 return VNET_API_ERROR_FEATURE_DISABLED;
1457 m_key.
addr = e_addr;
1458 m_key.
port = e_port;
1466 return VNET_API_ERROR_NO_SUCH_ENTRY;
1469 return VNET_API_ERROR_INVALID_VALUE;
1474 if ((local->addr.as_u32 == l_addr.as_u32) && (local->port == l_port) &&
1475 (local->vrf_id == vrf_id))
1477 match_local = local;
1486 return VNET_API_ERROR_VALUE_EXIST;
1490 local->addr.as_u32 = l_addr.as_u32;
1491 local->port = l_port;
1492 local->probability = probability;
1493 local->vrf_id = vrf_id;
1500 m_key.addr = l_addr;
1501 m_key.port = l_port;
1502 m_key.fib_index = local->fib_index;
1503 kv.key = m_key.as_u64;
1504 kv.value = m - sm->static_mappings;
1505 if (clib_bihash_add_del_8_8 (&sm->static_mapping_by_local, &kv, 1))
1506 nat_log_err (
"static_mapping_by_local key add failed");
1512 return VNET_API_ERROR_NO_SUCH_ENTRY;
1515 return VNET_API_ERROR_UNSPECIFIED;
1522 m_key.addr = l_addr;
1523 m_key.port = l_port;
1524 m_key.fib_index = match_local->fib_index;
1525 kv.key = m_key.as_u64;
1526 if (clib_bihash_add_del_8_8 (&sm->static_mapping_by_local, &kv, 0))
1527 nat_log_err (
"static_mapping_by_local key del failed");
1530 if (sm->num_workers > 1)
1536 sm->worker_in2out_cb (&ip, m->fib_index));
1542 u_key.addr = match_local->addr;
1543 u_key.fib_index = match_local->fib_index;
1544 kv.key = u_key.as_u64;
1545 if (!clib_bihash_search_8_8 (&tsm->user_hash, &kv, &value))
1548 if (u->nstaticsessions)
1550 head_index = u->sessions_per_user_list_head_index;
1552 elt_index = head->next;
1554 ses_index = elt->value;
1555 while (ses_index != ~0)
1559 ses_index = elt->value;
1564 if ((s->in2out.addr.as_u32 != match_local->addr.as_u32) ||
1565 (clib_net_to_host_u16 (s->in2out.port) !=
1583 vec_add1 (locals, local - m->locals);
1584 if (sm->num_workers > 1)
1587 ip.src_address.as_u32 = local->addr.as_u32,
1588 bitmap = clib_bitmap_set (bitmap,
1589 sm->worker_in2out_cb (&ip, local->fib_index),
1598 local->prefix = local->probability;
1603 local->prefix = local->probability + prev_local->prefix;
1607 if (sm->num_workers > 1)
1622 snat_session_t *ses;
1623 u32 *ses_to_be_removed = 0, *ses_index;
1632 for (i = 0; i <
vec_len (addresses); i++)
1641 return VNET_API_ERROR_NO_SUCH_ENTRY;
1648 if (m->external_addr.as_u32 == addr.as_u32)
1649 (void) snat_add_static_mapping (m->local_addr, m->external_addr,
1650 m->local_port, m->external_port,
1651 m->vrf_id, is_addr_only_static_mapping(m), ~0,
1652 m->proto, 0, m->twice_nat,
1653 is_out2in_only_static_mapping(m), m->tag, is_identity_static_mapping(m));
1663 return VNET_API_ERROR_UNSPECIFIED;
1671 if (a->busy_tcp_ports || a->busy_udp_ports || a->busy_icmp_ports)
1677 if (ses->out2in.addr.as_u32 == addr.as_u32)
1679 nat_free_session_data (sm, ses, tsm - sm->per_thread_data, 0);
1680 vec_add1 (ses_to_be_removed, ses - tsm->sessions);
1695 #define _(N, i, n, s) \ 1696 clib_bitmap_free (a->busy_##n##_port_bitmap); \ 1697 vec_free (a->busy_##n##_ports_per_thread); 1712 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1715 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
1718 pool_foreach (interface, sm->output_feature_interfaces,
1720 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1723 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
1736 const char *feature_name, *del_feature_name;
1745 return VNET_API_ERROR_UNSUPPORTED;
1750 if (i->sw_if_index == sw_if_index)
1751 return VNET_API_ERROR_VALUE_EXIST;
1756 feature_name = is_inside ?
"nat44-in2out-fast" :
"nat44-out2in-fast";
1761 is_inside ?
"nat44-in2out-worker-handoff" :
1762 "nat44-out2in-worker-handoff";
1764 feature_name = is_inside ?
"nat44-det-in2out" :
"nat44-det-out2in";
1766 feature_name = is_inside ?
"nat44-ed-in2out" :
"nat44-ed-out2in";
1768 feature_name = is_inside ?
"nat44-in2out" :
"nat44-out2in";
1784 if (outside_fib->
fib_index == fib_index)
1809 if (i->sw_if_index == sw_if_index)
1813 if (nat_interface_is_inside(i) && nat_interface_is_outside(i))
1816 i->flags &= ~NAT_INTERFACE_FLAG_IS_INSIDE;
1818 i->flags &= ~NAT_INTERFACE_FLAG_IS_OUTSIDE;
1820 if (sm->num_workers > 1 && !sm->deterministic)
1822 del_feature_name =
"nat44-handoff-classify";
1823 feature_name = !is_inside ?
"nat44-in2out-worker-handoff" :
1824 "nat44-out2in-worker-handoff";
1826 else if (sm->deterministic)
1828 del_feature_name =
"nat44-det-classify";
1829 feature_name = !is_inside ?
"nat44-det-in2out" :
1832 else if (sm->endpoint_dependent)
1834 del_feature_name =
"nat44-ed-classify";
1835 feature_name = !is_inside ?
"nat44-ed-in2out" :
1840 del_feature_name =
"nat44-classify";
1841 feature_name = !is_inside ?
"nat44-in2out" :
"nat44-out2in";
1844 vnet_feature_enable_disable (
"ip4-unicast", del_feature_name,
1845 sw_if_index, 0, 0, 0);
1846 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1847 sw_if_index, 1, 0, 0);
1850 if (sm->endpoint_dependent)
1851 vnet_feature_enable_disable (
"ip4-local",
1852 "nat44-ed-hairpinning",
1853 sw_if_index, 1, 0, 0);
1854 else if (!sm->deterministic)
1855 vnet_feature_enable_disable (
"ip4-local",
1856 "nat44-hairpinning",
1857 sw_if_index, 1, 0, 0);
1862 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1863 sw_if_index, 0, 0, 0);
1864 pool_put (sm->interfaces, i);
1867 if (sm->endpoint_dependent)
1868 vnet_feature_enable_disable (
"ip4-local",
1869 "nat44-ed-hairpinning",
1870 sw_if_index, 0, 0, 0);
1871 else if (!sm->deterministic)
1872 vnet_feature_enable_disable (
"ip4-local",
1873 "nat44-hairpinning",
1874 sw_if_index, 0, 0, 0);
1880 if ((nat_interface_is_inside(i) && is_inside) ||
1881 (nat_interface_is_outside(i) && !is_inside))
1884 if (sm->num_workers > 1 && !sm->deterministic)
1886 del_feature_name = !is_inside ?
"nat44-in2out-worker-handoff" :
1887 "nat44-out2in-worker-handoff";
1888 feature_name =
"nat44-handoff-classify";
1890 else if (sm->deterministic)
1892 del_feature_name = !is_inside ?
"nat44-det-in2out" :
1894 feature_name =
"nat44-det-classify";
1896 else if (sm->endpoint_dependent)
1898 del_feature_name = !is_inside ?
"nat44-ed-in2out" :
1900 feature_name =
"nat44-ed-classify";
1904 del_feature_name = !is_inside ?
"nat44-in2out" :
"nat44-out2in";
1905 feature_name =
"nat44-classify";
1908 vnet_feature_enable_disable (
"ip4-unicast", del_feature_name,
1909 sw_if_index, 0, 0, 0);
1910 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1911 sw_if_index, 1, 0, 0);
1914 if (sm->endpoint_dependent)
1915 vnet_feature_enable_disable (
"ip4-local",
"nat44-ed-hairpinning",
1916 sw_if_index, 0, 0, 0);
1917 else if (!sm->deterministic)
1918 vnet_feature_enable_disable (
"ip4-local",
"nat44-hairpinning",
1919 sw_if_index, 0, 0, 0);
1930 return VNET_API_ERROR_NO_SUCH_ENTRY;
1938 if (is_inside && !sm->out2in_dpo)
1940 if (sm->endpoint_dependent)
1943 else if (!sm->deterministic)
1965 if (!(is_addr_only_static_mapping(m)) || (m->local_addr.as_u32 == m->external_addr.as_u32))
1968 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
1973 snat_add_del_addr_to_fib(&dm->out_addr, dm->out_plen, sw_if_index, !is_del);
1982 u8 is_inside,
int is_del)
1995 return VNET_API_ERROR_UNSUPPORTED;
2000 if (i->sw_if_index == sw_if_index)
2001 return VNET_API_ERROR_VALUE_EXIST;
2010 if (outside_fib->
fib_index == fib_index)
2038 sw_if_index, !is_del, 0, 0);
2040 sw_if_index, !is_del, 0, 0);
2045 sw_if_index, !is_del, 0, 0);
2047 sw_if_index, !is_del, 0, 0);
2055 "nat44-out2in-worker-handoff",
2056 sw_if_index, !is_del, 0, 0);
2058 "nat44-in2out-output-worker-handoff",
2059 sw_if_index, !is_del, 0, 0);
2066 sw_if_index, !is_del, 0, 0);
2068 sw_if_index, !is_del, 0, 0);
2073 sw_if_index, !is_del, 0, 0);
2075 sw_if_index, !is_del, 0, 0);
2091 if (i->sw_if_index == sw_if_index)
2094 pool_put (sm->output_feature_interfaces, i);
2096 return VNET_API_ERROR_VALUE_EXIST;
2104 return VNET_API_ERROR_NO_SUCH_ENTRY;
2106 pool_get (sm->output_feature_interfaces,
i);
2125 if (!((is_addr_only_static_mapping(m))) || (m->local_addr.as_u32 == m->external_addr.as_u32))
2128 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
2142 return VNET_API_ERROR_FEATURE_DISABLED;
2145 return VNET_API_ERROR_INVALID_WORKER;
2173 if (new_fib_index == old_fib_index)
2182 if (i->sw_if_index == sw_if_index)
2184 if (!(nat_interface_is_outside (i)))
2196 if (outside_fib->fib_index == old_fib_index)
2198 outside_fib->refcount--;
2199 if (!outside_fib->refcount)
2200 vec_del1 (sm->outside_fibs, outside_fib - sm->outside_fibs);
2207 if (outside_fib->fib_index == new_fib_index)
2209 outside_fib->refcount++;
2217 vec_add2 (sm->outside_fibs, outside_fib, 1);
2218 outside_fib->refcount = 1;
2219 outside_fib->fib_index = new_fib_index;
2237 u32 if_address_index,
u32 is_delete);
2245 u32 if_address_index,
u32 is_delete);
2252 u16 port_per_thread,
u32 snat_thread_index);
2429 u16 port_host_byte_order = clib_net_to_host_u16 (k->
port);
2431 for (address_index = 0; address_index <
vec_len (addresses);
2438 ASSERT (address_index < vec_len (addresses));
2440 a = addresses + address_index;
2444 #define _(N, i, n, s) \ 2445 case SNAT_PROTOCOL_##N: \ 2446 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 2447 port_host_byte_order) == 1); \ 2448 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 2449 port_host_byte_order, 0); \ 2450 a->busy_##n##_ports--; \ 2451 a->busy_##n##_ports_per_thread[thread_index]--; \ 2467 u16 port_host_byte_order = clib_net_to_host_u16 (k->
port);
2469 for (address_index = 0; address_index <
vec_len (addresses);
2475 a = addresses + address_index;
2478 #define _(N, j, n, s) \ 2479 case SNAT_PROTOCOL_##N: \ 2480 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, port_host_byte_order)) \ 2481 return VNET_API_ERROR_INSTANCE_IN_USE; \ 2482 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, port_host_byte_order, 1); \ 2483 a->busy_##n##_ports_per_thread[thread_index]++; \ 2484 a->busy_##n##_ports++; \ 2494 return VNET_API_ERROR_NO_SUCH_ENTRY;
2505 u8 * is_identity_nat)
2511 u32 rand,
lo = 0,
hi, mid, *tmp = 0,
i;
2523 m_key.
port = clib_net_to_host_u16 (match.
port);
2528 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
2534 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
2555 mapping->
port = clib_host_to_net_u16 (local->
port);
2571 mid = ((hi -
lo) >> 1) +
lo;
2573 (rand > local->
prefix) ? (lo = mid + 1) : (hi = mid);
2576 if (!(local->
prefix >= rand))
2588 mapping->
port = clib_host_to_net_u16 (local->
port);
2647 u16 port_per_thread,
2648 u32 snat_thread_index)
2653 port_per_thread, snat_thread_index);
2661 u16 port_per_thread,
u32 snat_thread_index)
2667 for (i = 0; i <
vec_len (addresses); i++)
2672 #define _(N, j, n, s) \ 2673 case SNAT_PROTOCOL_##N: \ 2674 if (a->busy_##n##_ports_per_thread[thread_index] < port_per_thread) \ 2676 if (a->fib_index == fib_index) \ 2680 portnum = (port_per_thread * \ 2681 snat_thread_index) + \ 2682 snat_random_port(1, port_per_thread) + 1024; \ 2683 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2685 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2686 a->busy_##n##_ports_per_thread[thread_index]++; \ 2687 a->busy_##n##_ports++; \ 2688 k->addr = a->addr; \ 2689 k->port = clib_host_to_net_u16(portnum); \ 2693 else if (a->fib_index == ~0) \ 2713 #define _(N, j, n, s) \ 2714 case SNAT_PROTOCOL_##N: \ 2717 portnum = (port_per_thread * \ 2718 snat_thread_index) + \ 2719 snat_random_port(1, port_per_thread) + 1024; \ 2720 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2722 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2723 a->busy_##n##_ports_per_thread[thread_index]++; \ 2724 a->busy_##n##_ports++; \ 2725 k->addr = a->addr; \ 2726 k->port = clib_host_to_net_u16(portnum); \ 2748 u16 port_per_thread,
u32 snat_thread_index)
2752 u16 m, ports, portnum,
A, j;
2761 #define _(N, i, n, s) \ 2762 case SNAT_PROTOCOL_##N: \ 2763 if (a->busy_##n##_ports < ports) \ 2767 A = snat_random_port(1, pow2_mask(sm->psid_offset)); \ 2768 j = snat_random_port(0, pow2_mask(m)); \ 2769 portnum = A | (sm->psid << sm->psid_offset) | (j << (16 - m)); \ 2770 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2772 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2773 a->busy_##n##_ports++; \ 2774 k->addr = a->addr; \ 2775 k->port = clib_host_to_net_u16 (portnum); \ 2798 u16 port_per_thread,
u32 snat_thread_index)
2811 #define _(N, i, n, s) \ 2812 case SNAT_PROTOCOL_##N: \ 2813 if (a->busy_##n##_ports < ports) \ 2817 portnum = snat_random_port(sm->start_port, sm->end_port); \ 2818 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2820 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2821 a->busy_##n##_ports++; \ 2822 k->addr = a->addr; \ 2823 k->port = clib_host_to_net_u16 (portnum); \ 2848 .fp_addr.ip4.as_u32 = addr.
as_u32,
2885 s =
format (s,
"%U static-mapping-index %llu",
2915 format (s,
"local %U:%d remote %U:%d proto %U fib %d session-index %llu",
2927 u32 next_worker_index = 0;
2935 next_worker_index += sm->
workers[hash & (_vec_len (sm->
workers) - 1)];
2939 return next_worker_index;
2952 u32 next_worker_index = 0;
2962 if (!clib_bihash_search_8_8
2979 nat_reass_ip4_t *reass;
2983 if (reass && (reass->thread_index != (
u32) ~ 0))
2984 return reass->thread_index;
2997 m_key.
port = clib_net_to_host_u16 (port);
3001 if (!clib_bihash_search_8_8
3005 reass->thread_index = m->
workers[0];
3006 return reass->thread_index;
3010 reass->thread_index +=
3011 sm->
workers[(clib_net_to_host_u16 (port) - 1024) /
3013 return reass->thread_index;
3029 icmp46_header_t *icmp = (icmp46_header_t *) udp;
3040 case SNAT_PROTOCOL_ICMP:
3041 icmp = (icmp46_header_t *) l4_header;
3045 case SNAT_PROTOCOL_UDP:
3046 case SNAT_PROTOCOL_TCP:
3058 m_key.addr = ip0->dst_address;
3059 m_key.port = clib_net_to_host_u16 (port);
3060 m_key.protocol = proto;
3061 m_key.fib_index = rx_fib_index0;
3062 kv.key = m_key.as_u64;
3063 if (!clib_bihash_search_8_8
3064 (&sm->static_mapping_by_external, &kv, &value))
3067 return m->workers[0];
3072 next_worker_index = sm->first_worker_index;
3073 next_worker_index +=
3074 sm->workers[(clib_net_to_host_u16 (port) - 1024) / sm->port_per_thread];
3075 return next_worker_index;
3083 u32 proto, next_worker_index = 0;
3093 if (!clib_bihash_search_8_8
3115 icmp46_header_t *icmp = (icmp46_header_t *) udp;
3126 case SNAT_PROTOCOL_ICMP:
3127 icmp = (icmp46_header_t *) l4_header;
3131 case SNAT_PROTOCOL_UDP:
3132 case SNAT_PROTOCOL_TCP:
3145 clib_net_to_host_u16 (port));
3146 if (!clib_bihash_search_8_8
3147 (&sm->static_mapping_by_external, &kv, &value))
3151 return m->workers[0];
3157 return m->workers[hash & (_vec_len (m->workers) - 1)];
3159 return m->workers[hash % _vec_len (m->workers)];
3164 next_worker_index = sm->first_worker_index;
3165 next_worker_index +=
3166 sm->workers[(clib_net_to_host_u16 (port) - 1024) / sm->port_per_thread];
3168 return next_worker_index;
3191 .ip4.as_u32 = eh_addr->
as_u32,
3198 key.
port = out_port;
3216 s->last_heard = now;
3218 s->ext_host_addr.as_u32 = eh_addr->
as_u32;
3219 s->ext_host_port = eh_port;
3249 if (clib_bihash_add_del_8_8 (&tsm->
out2in, &kv, 1))
3257 if (clib_bihash_add_del_8_8 (&tsm->
in2out, &kv, 1))
3276 (sm->
workers[(clib_net_to_host_u16 (out_port) -
3283 key.
port = out_port;
3287 if (clib_bihash_search_8_8 (&tsm->
out2in, &kv, &value))
3298 u32 total_pkts,
u64 total_bytes,
u32 thread_index)
3309 key.
port = out_port;
3313 if (clib_bihash_search_8_8 (&tsm->
out2in, &kv, &value))
3317 s->total_pkts = total_pkts;
3318 s->total_bytes = total_bytes;
3341 .ip4.as_u32 = eh_addr->
as_u32,
3348 key.
port = out_port;
3359 key.
port = ehn_port;
3375 s->last_heard = now;
3377 s->ext_host_nat_addr.as_u32 = s->ext_host_addr.as_u32 = eh_addr->
as_u32;
3378 s->ext_host_nat_port = s->ext_host_port = eh_port;
3381 s->ext_host_nat_addr.as_u32 = ehn_addr->
as_u32;
3382 s->ext_host_nat_port = ehn_port;
3411 key.
port = out_port;
3420 make_ed_kv (&kv, in_addr, &s->ext_host_nat_addr,
3422 s->ext_host_nat_port);
3423 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &kv, 1))
3427 s->out2in.fib_index, out_port, eh_port);
3428 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &kv, 1))
3447 (sm->
workers[(clib_net_to_host_u16 (out_port) -
3461 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
3472 u32 fib_index,
u32 total_pkts,
u64 total_bytes,
3491 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
3495 s->total_pkts = total_pkts;
3496 s->total_bytes = total_bytes;
3504 u32 translation_buckets = 1024;
3505 u32 translation_memory_size = 128 << 20;
3506 u32 user_buckets = 128;
3507 u32 user_memory_size = 64 << 20;
3508 u32 max_translations_per_user = 100;
3509 u32 outside_vrf_id = 0;
3510 u32 outside_ip6_vrf_id = 0;
3511 u32 inside_vrf_id = 0;
3512 u32 static_mapping_buckets = 1024;
3513 u32 static_mapping_memory_size = 64 << 20;
3514 u32 nat64_bib_buckets = 1024;
3515 u32 nat64_bib_memory_size = 128 << 20;
3516 u32 nat64_st_buckets = 2048;
3517 u32 nat64_st_memory_size = 256 << 20;
3518 u8 static_mapping_only = 0;
3519 u8 static_mapping_connection_tracking = 0;
3530 (input,
"translation hash buckets %d", &translation_buckets))
3532 else if (
unformat (input,
"translation hash memory %d",
3533 &translation_memory_size));
3534 else if (
unformat (input,
"user hash buckets %d", &user_buckets))
3536 else if (
unformat (input,
"user hash memory %d", &user_memory_size))
3538 else if (
unformat (input,
"max translations per user %d",
3539 &max_translations_per_user))
3541 else if (
unformat (input,
"outside VRF id %d", &outside_vrf_id))
3543 else if (
unformat (input,
"outside ip6 VRF id %d", &outside_ip6_vrf_id))
3545 else if (
unformat (input,
"inside VRF id %d", &inside_vrf_id))
3547 else if (
unformat (input,
"static mapping only"))
3549 static_mapping_only = 1;
3550 if (
unformat (input,
"connection tracking"))
3551 static_mapping_connection_tracking = 1;
3553 else if (
unformat (input,
"deterministic"))
3555 else if (
unformat (input,
"nat64 bib hash buckets %d",
3556 &nat64_bib_buckets))
3558 else if (
unformat (input,
"nat64 bib hash memory %d",
3559 &nat64_bib_memory_size))
3562 if (
unformat (input,
"nat64 st hash buckets %d", &nat64_st_buckets))
3564 else if (
unformat (input,
"nat64 st hash memory %d",
3565 &nat64_st_memory_size))
3567 else if (
unformat (input,
"out2in dpo"))
3569 else if (
unformat (input,
"dslite ce"))
3571 else if (
unformat (input,
"endpoint-dependent"))
3580 "deterministic and endpoint-dependent modes are mutually exclusive");
3584 "static mapping only mode available only for simple nat");
3588 "out2in dpo mode available only for simple nat");
3613 nat64_set_hash (nat64_bib_buckets, nat64_bib_memory_size, nat64_st_buckets,
3614 nat64_st_memory_size);
3650 if (!static_mapping_only ||
3651 (static_mapping_only && static_mapping_connection_tracking))
3658 clib_bihash_init_16_8 (&tsm->
in2out_ed,
"in2out-ed",
3659 translation_buckets,
3660 translation_memory_size);
3661 clib_bihash_set_kvp_format_fn_16_8 (&tsm->
in2out_ed,
3664 clib_bihash_init_16_8 (&tsm->
out2in_ed,
"out2in-ed",
3665 translation_buckets,
3666 translation_memory_size);
3667 clib_bihash_set_kvp_format_fn_16_8 (&tsm->
out2in_ed,
3672 clib_bihash_init_8_8 (&tsm->
in2out,
"in2out",
3673 translation_buckets,
3674 translation_memory_size);
3675 clib_bihash_set_kvp_format_fn_8_8 (&tsm->
in2out,
3678 clib_bihash_init_8_8 (&tsm->
out2in,
"out2in",
3679 translation_buckets,
3680 translation_memory_size);
3681 clib_bihash_set_kvp_format_fn_8_8 (&tsm->
out2in,
3685 clib_bihash_init_8_8 (&tsm->
user_hash,
"users", user_buckets,
3687 clib_bihash_set_kvp_format_fn_8_8 (&tsm->
user_hash,
3699 "static_mapping_by_local", static_mapping_buckets,
3700 static_mapping_memory_size);
3705 "static_mapping_by_external",
3706 static_mapping_buckets,
3707 static_mapping_memory_size);
3723 u32 if_address_index,
u32 is_delete)
3791 u32 if_address_index,
u32 is_delete)
3821 for (j = 0; j <
vec_len (addresses); j++)
3822 if (addresses[j].
addr.as_u32 == address->
as_u32)
3873 u32 *indices_to_delete = 0;
3875 u32 *auto_add_sw_if_indices =
3882 for (i = 0; i <
vec_len (auto_add_sw_if_indices); i++)
3884 if (auto_add_sw_if_indices[i] == sw_if_index)
3899 if (vec_len (indices_to_delete))
3901 for (j = vec_len (indices_to_delete) - 1; j >= 0; j--)
3912 return VNET_API_ERROR_VALUE_EXIST;
3919 return VNET_API_ERROR_NO_SUCH_ENTRY;
3944 clib_bihash_8_8_t *t;
3947 return VNET_API_ERROR_UNSUPPORTED;
3958 key.
port = clib_host_to_net_u16 (port);
3962 t = is_in ? &tsm->in2out : &tsm->out2in;
3963 if (!clib_bihash_search_8_8 (t, &kv, &value))
3966 return VNET_API_ERROR_UNSPECIFIED;
3974 return VNET_API_ERROR_NO_SUCH_ENTRY;
3980 u32 vrf_id,
int is_in)
3983 clib_bihash_16_8_t *t;
3991 return VNET_API_ERROR_FEATURE_DISABLED;
4001 t = is_in ? &tsm->in2out_ed : &tsm->out2in_ed;
4004 key.
l_port = clib_host_to_net_u16 (port);
4005 key.
r_port = clib_host_to_net_u16 (eh_port);
4010 if (clib_bihash_search_16_8 (t, &kv, &value))
4011 return VNET_API_ERROR_NO_SUCH_ENTRY;
4014 return VNET_API_ERROR_UNSPECIFIED;
ip4_address_t external_addr
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
void dslite_set_ce(dslite_main_t *dm, u8 set)
fib_protocol_t fp_proto
protocol type
static void snat_update_outside_fib(u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
nat_outside_fib_t * outside_fibs
void snat_ipfix_logging_max_entries_per_user(u32 thread_index, u32 limit, u32 src_ip)
Generate maximum entries per user exceeded event.
#define nat_log_info(...)
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
u32 sessions_per_user_list_head_index
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
ip4_table_bind_function_t * function
int nat_affinity_create_and_lock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port, u8 backend_index, u32 sticky_time, u32 affinity_per_service_list_head_index)
Create affinity record and take reference counting lock.
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Delete external address from NAT44 pool.
u32 hairpin_dst_node_index
void dslite_init(vlib_main_t *vm)
ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Functions to call when interface address changes.
u32 ed_hairpinning_node_index
static void clib_dlist_init(dlist_elt_t *pool, u32 index)
vnet_main_t * vnet_get_main(void)
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, u8 *tag, int twice_nat, int out2in_only, int identity_nat)
static u32 nat44_session_get_timeout(snat_main_t *sm, snat_session_t *s)
u32 fq_in2out_output_index
u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
clib_error_t * nat_reass_init(vlib_main_t *vm)
Initialize NAT virtual fragmentation reassembly.
static int nat_alloc_addr_and_port_range(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
#define SNAT_TCP_ESTABLISHED_TIMEOUT
#define is_ed_session(s)
Check if NAT session is endpoint dependent.
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
static f64 vlib_time_now(vlib_main_t *vm)
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
static void make_sm_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t *addr, u8 proto, u32 fib_index, u16 port)
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
nat_reass_ip4_t * nat_ip4_reass_find(ip4_address_t src, ip4_address_t dst, u16 frag_id, u8 proto)
Find reassembly.
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external addrres port)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
u32 ed_in2out_reass_node_index
#define nat_log_warn(...)
void nat_ha_sref_ed_cb(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts, u64 total_bytes, u32 thread_index)
u32 ed_out2in_slowpath_node_index
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define NAT_INTERFACE_FLAG_IS_OUTSIDE
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_user_kvp(u8 *s, va_list *args)
void nat_syslog_nat44_sdel(u32 ssubix, u32 sfibix, ip4_address_t *isaddr, u16 isport, ip4_address_t *idaddr, u16 idport, ip4_address_t *xsaddr, u16 xsport, ip4_address_t *xdaddr, u16 xdport, snat_protocol_t proto, u8 is_twicenat)
ip_lookup_main_t lookup_main
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
void nat64_set_hash(u32 bib_buckets, u32 bib_memory_size, u32 st_buckets, u32 st_memory_size)
Set NAT64 hash tables configuration.
int nat44_del_ed_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Delete NAT44 endpoint-dependent session.
format_function_t format_snat_key
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.
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
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)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define snat_is_unk_proto_session(s)
Check if SNAT session for unknown protocol.
static int nat_alloc_addr_and_port_mape(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
static int nat_alloc_addr_and_port_default(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 feature on the interface.
u32 icmp_match_out2in_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
nat44_lb_addr_port_t * locals
clib_bihash_8_8_t user_hash
static int ip4_is_fragment(const ip4_header_t *i)
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, snat_protocol_t proto, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u32 affinity)
Add/delete static mapping with load-balancing (multiple backends)
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
Allocate new NAT session or recycle last used.
#define NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY
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, dpo_proto_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, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Update the entry to have just one path.
u32 max_translations_per_user
u32 in2out_reass_node_index
void nat_ha_sadd_cb(ip4_address_t *in_addr, u16 in_port, ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, ip4_address_t *ehn_addr, u16 ehn_port, u8 proto, u32 fib_index, u16 flags, u32 thread_index)
u32 in2out_output_node_index
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a 'special' entry from the FIB.
u8 * format_static_mapping_kvp(u8 *s, va_list *args)
void nat_ha_sadd_ed_cb(ip4_address_t *in_addr, u16 in_port, ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, ip4_address_t *ehn_addr, u16 ehn_port, u8 proto, u32 fib_index, u16 flags, u32 thread_index)
u32 det_in2out_node_index
static u32 snat_get_worker_in2out_cb(ip4_header_t *ip0, u32 rx_fib_index0)
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Add external address to NAT44 pool.
u8 * format_ed_session_kvp(u8 *s, va_list *args)
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 clib_error_return(e, args...)
#define is_fwd_bypass_session(s)
Check if NAT session is forwarding bypass.
void snat_ipfix_logging_init(vlib_main_t *vm)
Initialize NAT plugin IPFIX logging.
static void * ip4_next_header(ip4_header_t *i)
void snat_ipfix_logging_addresses_exhausted(u32 thread_index, u32 pool_id)
Generate NAT addresses exhausted event.
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
void nat_ha_sdel_ed_cb(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 ti)
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
static void nat_ip4_add_del_addr_only_sm_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)
void nat_affinity_unlock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port)
Release a reference counting lock for affinity.
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, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat)
Match NAT44 static mapping.
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k)
Free outside address and port pair.
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
static void nat44_delete_session(snat_main_t *sm, snat_session_t *ses, u32 thread_index)
char * name
The counter collection's name.
twice_nat_type_t twice_nat
VNET_FEATURE_INIT(ip4_snat_in2out, static)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
u32 * auto_add_sw_if_indices_twice_nat
void nat66_init(vlib_main_t *vm)
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
int snat_alloc_outside_address_and_port(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
Alloc outside address and port.
snat_user_t * nat_user_get_or_create(snat_main_t *sm, ip4_address_t *addr, u32 fib_index, u32 thread_index)
Find or create NAT user.
#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.
void nat_dpo_module_init(void)
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
clib_bihash_16_8_t out2in_ed
static uword clib_bitmap_last_set(uword *ai)
Return the higest numbered set bit in a bitmap.
void nat_ha_sdel_cb(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 ti)
void nat_ha_sref_cb(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts, u64 total_bytes, u32 thread_index)
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
snat_session_t * nat_ed_session_alloc(snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
Allocate NAT endpoint-dependent session.
snat_static_mapping_t * static_mappings
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
#define VLIB_CONFIG_FUNCTION(x, n,...)
#define vec_del1(v, i)
Delete the element at index I.
u32 hairpin_src_node_index
clib_bihash_8_8_t static_mapping_by_external
u32 in2out_slowpath_output_node_index
static void vlib_set_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 value)
Set a simple counter.
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
#define nat_log_notice(...)
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
#define is_lb_session(s)
Check if NAT session is load-balancing.
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
snat_interface_t * output_feature_interfaces
u32 ed_hairpin_src_node_index
#define pool_free(p)
Free a pool.
void snat_ipfix_logging_nat44_ses_delete(u32 thread_index, 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.
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
#define is_affinity_sessions(s)
Check if NAT session has affinity record.
u32 ed_out2in_reass_node_index
static u32 nat44_ed_get_worker_out2in_cb(ip4_header_t *ip, u32 rx_fib_index)
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
#define NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT
u32 nat_affinity_get_per_service_list_head_index(void)
Get new affinity per service list head index.
static void clib_dlist_addhead(dlist_elt_t *pool, u32 head_index, u32 new_index)
static u32 random_u32_max(void)
Maximum value returned by random_u32()
static_always_inline uword vlib_get_thread_index(void)
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
u8 static_mapping_connection_tracking
snat_get_worker_function_t * worker_in2out_cb
#define vec_free(V)
Free vector's memory (no header).
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
deterministic NAT definitions
int nat_affinity_find_and_lock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port, u8 *backend_index)
Find service backend index for client-IP and take a reference counting lock.
u32 ed_in2out_slowpath_node_index
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 output feature on the interface (postrouting NAT)
dslite_main_t dslite_main
static void snat_ip4_table_bind(ip4_main_t *im, uword opaque, u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
u8 * format_session_kvp(u8 *s, va_list *args)
u32 fib_node_index_t
A typedef of a node index.
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
8 octet key, 8 octet key value pair
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
u32 ed_hairpin_dst_node_index
static void make_ed_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port)
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
u32 tcp_transitory_timeout
int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, snat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat)
Add/delete NAT44 static mapping.
u32 * auto_add_sw_if_indices
u32 in2out_fast_node_index
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a 'special' entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
void vlib_validate_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
validate a simple counter
static_always_inline u16 snat_random_port(u16 min, u16 max)
#define NAT_INTERFACE_FLAG_IS_INSIDE
#define is_addr_only_static_mapping(sm)
Check if NAT static mapping is address only (1:1NAT).
#define is_identity_static_mapping(sm)
Check if NAT static mapping is identity NAT.
u32 det_out2in_node_index
snat_get_worker_function_t * worker_out2in_cb
clib_error_t * nat_affinity_init(vlib_main_t *vm)
Initialize NAT client-IP based affinity.
u32 in2out_slowpath_node_index
snat_icmp_match_function_t * icmp_match_out2in_cb
vlib_log_class_t log_class
#define SNAT_SESSION_FLAG_TWICE_NAT
void nat_set_alloc_addr_and_port_range(u16 start_port, u16 end_port)
Set address and port assignment algorithm for port range.
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
#define clib_bitmap_free(v)
Free a bitmap.
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
uword * thread_registrations_by_name
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, snat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44 session.
snat_address_t * twice_nat_addresses
#define VNET_FEATURES(...)
void nat_syslog_nat44_apmdel(u32 ssubix, u32 sfibix, ip4_address_t *isaddr, u16 isport, ip4_address_t *xsaddr, u16 xsport, snat_protocol_t proto)
static clib_error_t * snat_init(vlib_main_t *vm)
void nat_ha_sdel(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 thread_index)
Create session delete HA event.
static uword is_pow2(uword x)
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
ip4_table_bind_callback_t * table_bind_callbacks
Functions to call when interface to table biding changes.
clib_error_t * nat64_init(vlib_main_t *vm)
Initialize NAT64.
u32 out2in_reass_node_index
NAT64 global declarations.
#define is_lb_static_mapping(sm)
Check if NAT static mapping is load-balancing.
void increment_v4_address(ip4_address_t *a)
Increment IPv4 address.
char * stat_segment_name
Name in stat segment directory.
vlib_simple_counter_main_t total_users
static int ip4_is_first_fragment(const ip4_header_t *i)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
#define FIB_NODE_INDEX_INVALID
format_function_t format_static_mapping_key
static void user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 hairpinning_node_index
#define is_out2in_only_static_mapping(sm)
Check if NAT static mapping match only out2in direction.
snat_main_per_thread_data_t * per_thread_data
void nat_affinity_flush_service(u32 affinity_per_service_list_head_index)
Flush all service affinity data.
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
u32 affinity_per_service_list_head_index
snat_address_t * addresses
void nat_dpo_create(dpo_proto_t dproto, u32 aftr_index, dpo_id_t *dpo)
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Add/delete NAT44 pool address from specific interfce.
u32 out2in_fast_node_index
#define hash_get_mem(h, key)
#define SNAT_ICMP_TIMEOUT
snat_static_map_resolve_t * to_resolve
static u32 random_u32(u32 *seed)
32-bit random number generator
#define SNAT_SESSION_FLAG_STATIC_MAPPING
ip4_main_t ip4_main
Global ip4 main structure.
static vlib_thread_main_t * vlib_get_thread_main()
static u32 get_thread_idx_by_port(u16 e_port)
u32 translation_memory_size
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
#define vec_foreach(var, vec)
Vector iterator.
vlib_node_registration_t snat_in2out_output_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_node)
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
u32 icmp_match_in2out_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b, ip4_header_t *ip, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
#define is_twice_nat_session(s)
Check if NAT session is twice NAT.
clib_bihash_16_8_t in2out_ed
static clib_error_t * snat_config(vlib_main_t *vm, unformat_input_t *input)
#define pool_foreach_index(i, v, body)
Iterate pool by index.
NAT plugin virtual fragmentation reassembly.
void nat_set_alloc_addr_and_port_mape(u16 psid, u16 psid_offset, u16 psid_length)
Set address and port assignment algorithm for MAP-E CE.
NAT66 global declarations.
NAT plugin client-IP based session affinity for load-balancing.
vlib_simple_counter_main_t total_sessions
#define SNAT_TCP_TRANSITORY_TIMEOUT
ip_lookup_main_t * ip4_lookup_main
#define NAT_STATIC_MAPPING_FLAG_LB
static int is_snat_address_used_in_static_mapping(snat_main_t *sm, ip4_address_t addr)
#define NAT_STATIC_MAPPING_FLAG_ADDR_ONLY
snat_session_t * sessions
A low (below routing) priority source a plugin can use.
snat_icmp_match_function_t * icmp_match_in2out_cb
clib_bihash_8_8_t static_mapping_by_local
static u32 snat_get_worker_out2in_cb(ip4_header_t *ip0, u32 rx_fib_index0)
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, snat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
snat_interface_t * interfaces
void nat_ha_init(vlib_main_t *vm, nat_ha_sadd_cb_t sadd_cb, nat_ha_sdel_cb_t sdel_cb, nat_ha_sref_cb_t sref_cb)
Initialize NAT HA.
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)
nat_reass_ip4_t * nat_ip4_reass_create(ip4_address_t src, ip4_address_t dst, u16 frag_id, u8 proto)
Create reassembly.
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)
static int nat_set_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k)
u32 tcp_established_timeout
static uword pool_elts(void *v)
Number of active elements in a pool.