35 #include <vpp/app/version.h> 43 .arc_name =
"ip4-unicast",
44 .node_name =
"nat44-in2out",
48 .arc_name =
"ip4-unicast",
49 .node_name =
"nat44-out2in",
51 "ip4-dhcp-client-detect"),
54 .arc_name =
"ip4-unicast",
55 .node_name =
"nat44-classify",
59 .arc_name =
"ip4-unicast",
60 .node_name =
"nat44-det-in2out",
64 .arc_name =
"ip4-unicast",
65 .node_name =
"nat44-det-out2in",
67 "ip4-dhcp-client-detect"),
70 .arc_name =
"ip4-unicast",
71 .node_name =
"nat44-det-classify",
75 .arc_name =
"ip4-unicast",
76 .node_name =
"nat44-ed-in2out",
80 .arc_name =
"ip4-unicast",
81 .node_name =
"nat44-ed-out2in",
83 "ip4-dhcp-client-detect"),
86 .arc_name =
"ip4-unicast",
87 .node_name =
"nat44-ed-classify",
91 .arc_name =
"ip4-unicast",
92 .node_name =
"nat44-in2out-worker-handoff",
96 .arc_name =
"ip4-unicast",
97 .node_name =
"nat44-out2in-worker-handoff",
99 "ip4-dhcp-client-detect"),
102 .arc_name =
"ip4-unicast",
103 .node_name =
"nat44-handoff-classify",
107 .arc_name =
"ip4-unicast",
108 .node_name =
"nat44-in2out-fast",
112 .arc_name =
"ip4-unicast",
113 .node_name =
"nat44-out2in-fast",
115 "ip4-dhcp-client-detect"),
118 .arc_name =
"ip4-unicast",
119 .node_name =
"nat44-hairpin-dst",
123 .arc_name =
"ip4-unicast",
124 .node_name =
"nat44-ed-hairpin-dst",
130 .arc_name =
"ip4-output",
131 .node_name =
"nat44-in2out-output",
135 .arc_name =
"ip4-output",
136 .node_name =
"nat44-in2out-output-worker-handoff",
140 .arc_name =
"ip4-output",
141 .node_name =
"nat44-hairpin-src",
145 .arc_name =
"ip4-output",
146 .node_name =
"nat44-ed-in2out-output",
150 .arc_name =
"ip4-output",
151 .node_name =
"nat44-ed-hairpin-src",
158 .arc_name =
"ip4-local",
159 .node_name =
"nat44-hairpinning",
164 .arc_name =
"ip4-local",
165 .node_name =
"nat44-ed-hairpinning",
171 .version = VPP_BUILD_VER,
172 .description =
"Network Address Translation",
188 ed_key.
l_addr = s->in2out.addr;
189 ed_key.
r_addr = s->ext_host_addr;
190 ed_key.
l_port = s->in2out.port;
191 ed_key.
r_port = s->ext_host_port;
196 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0))
206 s->in2out.protocol, s->out2in.port);
207 ed_key.
l_addr = s->out2in.addr;
208 ed_key.
r_addr = s->ext_host_addr;
212 ed_key.
proto = s->in2out.port;
219 ed_key.
l_port = s->out2in.port;
220 ed_key.
r_port = s->ext_host_port;
224 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &ed_kv, 0))
226 ed_key.
l_addr = s->in2out.addr;
229 ed_key.
l_port = s->in2out.port;
232 ed_key.
r_addr = s->ext_host_nat_addr;
233 ed_key.
r_port = s->ext_host_nat_port;
237 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0))
242 kv.
key = s->in2out.as_u64;
243 if (clib_bihash_add_del_8_8 (&tsm->
in2out, &kv, 0))
245 kv.
key = s->out2in.as_u64;
246 if (clib_bihash_add_del_8_8 (&tsm->
out2in, &kv, 0))
255 s->out2in.addr.as_u32,
258 s->out2in.port, s->in2out.fib_index);
264 key.
port = s->ext_host_nat_port;
265 key.
addr.
as_u32 = s->ext_host_nat_addr.as_u32;
292 if (clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
296 memset (u, 0,
sizeof (*u));
310 if (clib_bihash_add_del_8_8 (&tsm->
user_hash, &kv, 1))
327 u32 oldest_per_user_translation_list_index, session_index;
334 oldest_per_user_translation_list_index =
338 ASSERT (oldest_per_user_translation_list_index != ~0);
343 oldest_per_user_translation_list_index);
345 oldest_per_user_translation_list_elt =
347 oldest_per_user_translation_list_index);
350 session_index = oldest_per_user_translation_list_elt->
value;
363 s->ext_host_addr.as_u32 = 0;
364 s->ext_host_port = 0;
365 s->ext_host_nat_addr.as_u32 = 0;
366 s->ext_host_nat_port = 0;
371 memset (s, 0,
sizeof (*s));
376 per_user_translation_list_elt - tsm->
list_pool);
379 s->per_user_index = per_user_translation_list_elt - tsm->
list_pool;
383 s->per_user_list_head_index,
384 per_user_translation_list_elt - tsm->
list_pool);
396 dlist_elt_t *per_user_translation_list_elt, *oldest_elt;
398 u64 sess_timeout_time;
409 if (now >= sess_timeout_time)
422 s->ext_host_addr.as_u32 = 0;
423 s->ext_host_port = 0;
424 s->ext_host_nat_addr.as_u32 = 0;
425 s->ext_host_nat_port = 0;
444 memset (s, 0,
sizeof (*s));
449 per_user_translation_list_elt - tsm->
list_pool);
452 s->per_user_index = per_user_translation_list_elt - tsm->
list_pool;
456 s->per_user_list_head_index,
457 per_user_translation_list_elt - tsm->
list_pool);
472 .ip4.as_u32 = addr->
as_u32,
501 return VNET_API_ERROR_FEATURE_DISABLED;
508 return VNET_API_ERROR_VALUE_EXIST;
524 #define _(N, i, n, s) \ 525 clib_bitmap_alloc (ap->busy_##n##_port_bitmap, 65535); \ 526 ap->busy_##n##_ports = 0; \ 527 ap->busy_##n##_ports_per_thread = 0;\ 528 vec_validate_init_empty (ap->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0); 538 if (nat_interface_is_inside(i) || sm->out2in_dpo)
541 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
546 if (nat_interface_is_inside(i) || sm->out2in_dpo)
549 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
564 if (is_addr_only_static_mapping (m) ||
565 is_out2in_only_static_mapping (m) ||
566 is_identity_static_mapping (m))
568 if (m->external_addr.as_u32 == addr.as_u32)
581 v = clib_net_to_host_u32 (a->
as_u32) + 1;
582 a->
as_u32 = clib_host_to_net_u32 (v);
593 int addr_only,
int is_add,
u8 * tag,
594 int twice_nat,
int out2in_only,
630 u16 l_port,
u16 e_port,
u32 vrf_id,
int addr_only,
647 u32 elt_index, head_index;
657 if (twice_nat || out2in_only)
658 return VNET_API_ERROR_FEATURE_DISABLED;
662 if (sw_if_index != ~0)
677 || rp->
proto != proto)
692 return VNET_API_ERROR_VALUE_EXIST;
695 (sm, l_addr, l_port, sw_if_index, e_port, vrf_id, proto,
696 addr_only, is_add, tag, twice_nat, out2in_only, identity_nat);
699 if (first_int_addr == 0)
714 return VNET_API_ERROR_NO_SUCH_ENTRY;
731 m_key.
port = addr_only ? 0 : e_port;
732 m_key.
protocol = addr_only ? 0 : proto;
749 if (local->
vrf_id == vrf_id)
750 return VNET_API_ERROR_VALUE_EXIST;
768 return VNET_API_ERROR_VALUE_EXIST;
771 if (twice_nat && addr_only)
772 return VNET_API_ERROR_UNSUPPORTED;
786 if (!(out2in_only || identity_nat))
789 m_key.
port = addr_only ? 0 : l_port;
790 m_key.
protocol = addr_only ? 0 : proto;
793 if (!clib_bihash_search_8_8
795 return VNET_API_ERROR_VALUE_EXIST;
810 #define _(N, j, n, s) \ 811 case SNAT_PROTOCOL_##N: \ 812 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, e_port)) \ 813 return VNET_API_ERROR_INVALID_VALUE; \ 814 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \ 817 a->busy_##n##_ports++; \ 818 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ 825 return VNET_API_ERROR_INVALID_VALUE_2;
833 if (sw_if_index != ~0)
850 return VNET_API_ERROR_NO_SUCH_ENTRY;
855 memset (m, 0,
sizeof (*m));
916 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
918 user_index = value.
value;
924 elt_index = head->
next;
926 ses_index = elt->
value;
927 while (ses_index != ~0)
931 ses_index = elt->
value;
937 && (clib_net_to_host_u16 (s->in2out.port) !=
956 if (sw_if_index != ~0)
959 return VNET_API_ERROR_NO_SUCH_ENTRY;
976 return VNET_API_ERROR_NO_SUCH_ENTRY;
994 #define _(N, j, n, s) \ 995 case SNAT_PROTOCOL_##N: \ 996 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \ 999 a->busy_##n##_ports--; \ 1000 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ 1007 return VNET_API_ERROR_INVALID_VALUE_2;
1034 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
1036 user_index = value.
value;
1042 elt_index = head->
next;
1044 ses_index = elt->
value;
1045 while (ses_index != ~0)
1049 ses_index = elt->
value;
1053 if ((s->out2in.addr.as_u32 != e_addr.
as_u32) ||
1054 (clib_net_to_host_u16 (s->out2in.port) !=
1099 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1102 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
1107 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1110 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
1123 u8 * tag,
u32 affinity)
1132 u32 elt_index, head_index, ses_index;
1141 return VNET_API_ERROR_FEATURE_DISABLED;
1143 m_key.
addr = e_addr;
1144 m_key.
port = e_port;
1156 return VNET_API_ERROR_VALUE_EXIST;
1159 return VNET_API_ERROR_INVALID_VALUE;
1173 #define _(N, j, n, s) \ 1174 case SNAT_PROTOCOL_##N: \ 1175 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, e_port)) \ 1176 return VNET_API_ERROR_INVALID_VALUE; \ 1177 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \ 1178 if (e_port > 1024) \ 1180 a->busy_##n##_ports++; \ 1181 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ 1188 return VNET_API_ERROR_INVALID_VALUE_2;
1195 return VNET_API_ERROR_NO_SUCH_ENTRY;
1199 memset (m, 0,
sizeof (*m));
1224 nat_log_err (
"static_mapping_by_external key add failed");
1225 return VNET_API_ERROR_UNSPECIFIED;
1229 for (i = 0; i <
vec_len (locals); i++)
1244 locals[
i].
prefix = (i == 0) ? locals[i].probability :
1245 (locals[i - 1].
prefix + locals[i].probability);
1272 return VNET_API_ERROR_NO_SUCH_ENTRY;
1275 return VNET_API_ERROR_INVALID_VALUE;
1287 #define _(N, j, n, s) \ 1288 case SNAT_PROTOCOL_##N: \ 1289 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \ 1290 if (e_port > 1024) \ 1292 a->busy_##n##_ports--; \ 1293 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ 1300 return VNET_API_ERROR_INVALID_VALUE_2;
1314 nat_log_err (
"static_mapping_by_external key del failed");
1315 return VNET_API_ERROR_UNSPECIFIED;
1331 nat_log_err (
"static_mapping_by_local key del failed");
1332 return VNET_API_ERROR_UNSPECIFIED;
1351 if (!clib_bihash_search_8_8 (&tsm->user_hash, &kv, &value))
1358 elt_index = head->
next;
1360 ses_index = elt->
value;
1361 while (ses_index != ~0)
1365 ses_index = elt->
value;
1370 if ((s->in2out.addr.as_u32 != local->
addr.
as_u32) ||
1371 (clib_net_to_host_u16 (s->in2out.port) != local->
port))
1398 snat_session_t *ses;
1399 u32 *ses_to_be_removed = 0, *ses_index;
1408 for (i = 0; i <
vec_len (addresses); i++)
1417 return VNET_API_ERROR_NO_SUCH_ENTRY;
1424 if (m->external_addr.as_u32 == addr.as_u32)
1425 (void) snat_add_static_mapping (m->local_addr, m->external_addr,
1426 m->local_port, m->external_port,
1427 m->vrf_id, is_addr_only_static_mapping(m), ~0,
1428 m->proto, 0, m->twice_nat,
1429 is_out2in_only_static_mapping(m), m->tag, is_identity_static_mapping(m));
1439 return VNET_API_ERROR_UNSPECIFIED;
1447 if (a->busy_tcp_ports || a->busy_udp_ports || a->busy_icmp_ports)
1453 if (ses->out2in.addr.as_u32 == addr.as_u32)
1455 nat_free_session_data (sm, ses, tsm - sm->per_thread_data);
1456 vec_add1 (ses_to_be_removed, ses - tsm->sessions);
1471 #define _(N, i, n, s) \ 1472 clib_bitmap_free (a->busy_##n##_port_bitmap); \ 1473 vec_free (a->busy_##n##_ports_per_thread); 1488 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1491 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
1494 pool_foreach (interface, sm->output_feature_interfaces,
1496 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1499 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
1512 const char *feature_name, *del_feature_name;
1521 return VNET_API_ERROR_UNSUPPORTED;
1526 if (i->sw_if_index == sw_if_index)
1527 return VNET_API_ERROR_VALUE_EXIST;
1532 feature_name = is_inside ?
"nat44-in2out-fast" :
"nat44-out2in-fast";
1537 is_inside ?
"nat44-in2out-worker-handoff" :
1538 "nat44-out2in-worker-handoff";
1540 feature_name = is_inside ?
"nat44-det-in2out" :
"nat44-det-out2in";
1542 feature_name = is_inside ?
"nat44-ed-in2out" :
"nat44-ed-out2in";
1544 feature_name = is_inside ?
"nat44-in2out" :
"nat44-out2in";
1560 if (outside_fib->
fib_index == fib_index)
1585 if (i->sw_if_index == sw_if_index)
1589 if (nat_interface_is_inside(i) && nat_interface_is_outside(i))
1592 i->flags &= ~NAT_INTERFACE_FLAG_IS_INSIDE;
1594 i->flags &= ~NAT_INTERFACE_FLAG_IS_OUTSIDE;
1596 if (sm->num_workers > 1 && !sm->deterministic)
1598 del_feature_name =
"nat44-handoff-classify";
1599 feature_name = !is_inside ?
"nat44-in2out-worker-handoff" :
1600 "nat44-out2in-worker-handoff";
1602 else if (sm->deterministic)
1604 del_feature_name =
"nat44-det-classify";
1605 feature_name = !is_inside ?
"nat44-det-in2out" :
1608 else if (sm->endpoint_dependent)
1610 del_feature_name =
"nat44-ed-classify";
1611 feature_name = !is_inside ?
"nat44-ed-in2out" :
1616 del_feature_name =
"nat44-classify";
1617 feature_name = !is_inside ?
"nat44-in2out" :
"nat44-out2in";
1620 vnet_feature_enable_disable (
"ip4-unicast", del_feature_name,
1621 sw_if_index, 0, 0, 0);
1622 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1623 sw_if_index, 1, 0, 0);
1626 if (sm->endpoint_dependent)
1627 vnet_feature_enable_disable (
"ip4-local",
1628 "nat44-ed-hairpinning",
1629 sw_if_index, 1, 0, 0);
1630 else if (!sm->deterministic)
1631 vnet_feature_enable_disable (
"ip4-local",
1632 "nat44-hairpinning",
1633 sw_if_index, 1, 0, 0);
1638 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1639 sw_if_index, 0, 0, 0);
1640 pool_put (sm->interfaces, i);
1643 if (sm->endpoint_dependent)
1644 vnet_feature_enable_disable (
"ip4-local",
1645 "nat44-ed-hairpinning",
1646 sw_if_index, 0, 0, 0);
1647 else if (!sm->deterministic)
1648 vnet_feature_enable_disable (
"ip4-local",
1649 "nat44-hairpinning",
1650 sw_if_index, 0, 0, 0);
1656 if ((nat_interface_is_inside(i) && is_inside) ||
1657 (nat_interface_is_outside(i) && !is_inside))
1660 if (sm->num_workers > 1 && !sm->deterministic)
1662 del_feature_name = !is_inside ?
"nat44-in2out-worker-handoff" :
1663 "nat44-out2in-worker-handoff";
1664 feature_name =
"nat44-handoff-classify";
1666 else if (sm->deterministic)
1668 del_feature_name = !is_inside ?
"nat44-det-in2out" :
1670 feature_name =
"nat44-det-classify";
1672 else if (sm->endpoint_dependent)
1674 del_feature_name = !is_inside ?
"nat44-ed-in2out" :
1676 feature_name =
"nat44-ed-classify";
1680 del_feature_name = !is_inside ?
"nat44-in2out" :
"nat44-out2in";
1681 feature_name =
"nat44-classify";
1684 vnet_feature_enable_disable (
"ip4-unicast", del_feature_name,
1685 sw_if_index, 0, 0, 0);
1686 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1687 sw_if_index, 1, 0, 0);
1690 if (sm->endpoint_dependent)
1691 vnet_feature_enable_disable (
"ip4-local",
"nat44-ed-hairpinning",
1692 sw_if_index, 0, 0, 0);
1693 else if (!sm->deterministic)
1694 vnet_feature_enable_disable (
"ip4-local",
"nat44-hairpinning",
1695 sw_if_index, 0, 0, 0);
1706 return VNET_API_ERROR_NO_SUCH_ENTRY;
1714 if (is_inside && !sm->out2in_dpo)
1716 if (sm->endpoint_dependent)
1719 else if (!sm->deterministic)
1741 if (!(is_addr_only_static_mapping(m)) || (m->local_addr.as_u32 == m->external_addr.as_u32))
1744 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
1749 snat_add_del_addr_to_fib(&dm->out_addr, dm->out_plen, sw_if_index, !is_del);
1758 u8 is_inside,
int is_del)
1767 return VNET_API_ERROR_UNSUPPORTED;
1772 if (i->sw_if_index == sw_if_index)
1773 return VNET_API_ERROR_VALUE_EXIST;
1782 sw_if_index, !is_del, 0, 0);
1784 sw_if_index, !is_del, 0, 0);
1789 sw_if_index, !is_del, 0, 0);
1791 sw_if_index, !is_del, 0, 0);
1799 "nat44-out2in-worker-handoff",
1800 sw_if_index, !is_del, 0, 0);
1802 "nat44-in2out-output-worker-handoff",
1803 sw_if_index, !is_del, 0, 0);
1810 sw_if_index, !is_del, 0, 0);
1812 sw_if_index, !is_del, 0, 0);
1817 sw_if_index, !is_del, 0, 0);
1819 sw_if_index, !is_del, 0, 0);
1835 if (i->sw_if_index == sw_if_index)
1838 pool_put (sm->output_feature_interfaces, i);
1840 return VNET_API_ERROR_VALUE_EXIST;
1848 return VNET_API_ERROR_NO_SUCH_ENTRY;
1850 pool_get (sm->output_feature_interfaces,
i);
1869 if (!((is_addr_only_static_mapping(m))) || (m->local_addr.as_u32 == m->external_addr.as_u32))
1872 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
1886 return VNET_API_ERROR_FEATURE_DISABLED;
1889 return VNET_API_ERROR_INVALID_WORKER;
1914 u32 if_address_index,
u32 is_delete);
1922 u32 if_address_index,
u32 is_delete);
1929 u16 port_per_thread,
u32 snat_thread_index);
2037 u16 port_host_byte_order = clib_net_to_host_u16 (k->
port);
2039 for (address_index = 0; address_index <
vec_len (addresses);
2046 ASSERT (address_index < vec_len (addresses));
2048 a = addresses + address_index;
2052 #define _(N, i, n, s) \ 2053 case SNAT_PROTOCOL_##N: \ 2054 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 2055 port_host_byte_order) == 1); \ 2056 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 2057 port_host_byte_order, 0); \ 2058 a->busy_##n##_ports--; \ 2059 a->busy_##n##_ports_per_thread[thread_index]--; \ 2077 u8 * is_identity_nat)
2094 m_key.
port = clib_net_to_host_u16 (match.
port);
2099 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
2105 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
2126 clib_host_to_net_u16 (m->
locals[backend_index].
port);
2135 mid = ((
hi -
lo) >> 1) +
lo;
2208 u16 port_per_thread,
2209 u32 snat_thread_index)
2214 port_per_thread, snat_thread_index);
2222 u16 port_per_thread,
u32 snat_thread_index)
2228 for (i = 0; i <
vec_len (addresses); i++)
2233 #define _(N, j, n, s) \ 2234 case SNAT_PROTOCOL_##N: \ 2235 if (a->busy_##n##_ports_per_thread[thread_index] < port_per_thread) \ 2237 if (a->fib_index == fib_index) \ 2241 portnum = (port_per_thread * \ 2242 snat_thread_index) + \ 2243 snat_random_port(1, port_per_thread) + 1024; \ 2244 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2246 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2247 a->busy_##n##_ports_per_thread[thread_index]++; \ 2248 a->busy_##n##_ports++; \ 2249 k->addr = a->addr; \ 2250 k->port = clib_host_to_net_u16(portnum); \ 2254 else if (a->fib_index == ~0) \ 2274 #define _(N, j, n, s) \ 2275 case SNAT_PROTOCOL_##N: \ 2278 portnum = (port_per_thread * \ 2279 snat_thread_index) + \ 2280 snat_random_port(1, port_per_thread) + 1024; \ 2281 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2283 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2284 a->busy_##n##_ports_per_thread[thread_index]++; \ 2285 a->busy_##n##_ports++; \ 2286 k->addr = a->addr; \ 2287 k->port = clib_host_to_net_u16(portnum); \ 2309 u16 port_per_thread,
u32 snat_thread_index)
2313 u16 m, ports, portnum, A, j;
2322 #define _(N, i, n, s) \ 2323 case SNAT_PROTOCOL_##N: \ 2324 if (a->busy_##n##_ports < ports) \ 2328 A = snat_random_port(1, pow2_mask(sm->psid_offset)); \ 2329 j = snat_random_port(0, pow2_mask(m)); \ 2330 portnum = A | (sm->psid << sm->psid_offset) | (j << (16 - m)); \ 2331 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2333 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2334 a->busy_##n##_ports++; \ 2335 k->addr = a->addr; \ 2336 k->port = clib_host_to_net_u16 (portnum); \ 2359 u16 port_per_thread,
u32 snat_thread_index)
2372 #define _(N, i, n, s) \ 2373 case SNAT_PROTOCOL_##N: \ 2374 if (a->busy_##n##_ports < ports) \ 2378 portnum = snat_random_port(sm->start_port, sm->end_port); \ 2379 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 2381 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 2382 a->busy_##n##_ports++; \ 2383 k->addr = a->addr; \ 2384 k->port = clib_host_to_net_u16 (portnum); \ 2409 .fp_addr.ip4.as_u32 = addr.
as_u32,
2446 s =
format (s,
"%U static-mapping-index %llu",
2476 format (s,
"local %U:%d remote %U:%d proto %U fib %d session-index %llu",
2488 u32 next_worker_index = 0;
2496 next_worker_index += sm->
workers[hash & (_vec_len (sm->
workers) - 1)];
2500 return next_worker_index;
2513 u32 next_worker_index = 0;
2523 if (!clib_bihash_search_8_8
2542 nat_reass_ip4_t *reass;
2547 if (reass && (reass->thread_index != (
u32) ~ 0))
2548 return reass->thread_index;
2563 icmp46_header_t *icmp = (icmp46_header_t *) udp;
2574 case SNAT_PROTOCOL_ICMP:
2575 icmp = (icmp46_header_t *) l4_header;
2579 case SNAT_PROTOCOL_UDP:
2580 case SNAT_PROTOCOL_TCP:
2592 m_key.addr = ip0->dst_address;
2593 m_key.port = clib_net_to_host_u16 (port);
2594 m_key.protocol = proto;
2595 m_key.fib_index = rx_fib_index0;
2596 kv.key = m_key.as_u64;
2597 if (!clib_bihash_search_8_8
2598 (&sm->static_mapping_by_external, &kv, &value))
2601 return m->workers[0];
2606 next_worker_index = sm->first_worker_index;
2607 next_worker_index +=
2608 sm->workers[(clib_net_to_host_u16 (port) - 1024) / sm->port_per_thread];
2609 return next_worker_index;
2617 u32 proto, next_worker_index = 0;
2627 if (!clib_bihash_search_8_8
2649 icmp46_header_t *icmp = (icmp46_header_t *) udp;
2660 case SNAT_PROTOCOL_ICMP:
2661 icmp = (icmp46_header_t *) l4_header;
2665 case SNAT_PROTOCOL_UDP:
2666 case SNAT_PROTOCOL_TCP:
2678 make_sm_kv (&kv, &ip->dst_address, proto, rx_fib_index,
2679 clib_net_to_host_u16 (port));
2680 if (!clib_bihash_search_8_8
2681 (&sm->static_mapping_by_external, &kv, &value))
2685 return m->workers[0];
2687 hash = ip->src_address.as_u32 + (ip->src_address.as_u32 >> 8) +
2688 (ip->src_address.as_u32 >> 16) + (ip->src_address.as_u32 >> 24);
2691 return m->workers[hash & (_vec_len (m->workers) - 1)];
2693 return m->workers[hash % _vec_len (m->workers)];
2698 next_worker_index = sm->first_worker_index;
2699 next_worker_index +=
2700 sm->workers[(clib_net_to_host_u16 (port) - 1024) / sm->port_per_thread];
2702 return next_worker_index;
2710 u32 translation_buckets = 1024;
2711 u32 translation_memory_size = 128 << 20;
2712 u32 user_buckets = 128;
2713 u32 user_memory_size = 64 << 20;
2714 u32 max_translations_per_user = 100;
2715 u32 outside_vrf_id = 0;
2716 u32 outside_ip6_vrf_id = 0;
2717 u32 inside_vrf_id = 0;
2718 u32 static_mapping_buckets = 1024;
2719 u32 static_mapping_memory_size = 64 << 20;
2720 u32 nat64_bib_buckets = 1024;
2721 u32 nat64_bib_memory_size = 128 << 20;
2722 u32 nat64_st_buckets = 2048;
2723 u32 nat64_st_memory_size = 256 << 20;
2724 u8 static_mapping_only = 0;
2725 u8 static_mapping_connection_tracking = 0;
2736 (input,
"translation hash buckets %d", &translation_buckets))
2738 else if (
unformat (input,
"translation hash memory %d",
2739 &translation_memory_size));
2740 else if (
unformat (input,
"user hash buckets %d", &user_buckets))
2742 else if (
unformat (input,
"user hash memory %d", &user_memory_size))
2744 else if (
unformat (input,
"max translations per user %d",
2745 &max_translations_per_user))
2747 else if (
unformat (input,
"outside VRF id %d", &outside_vrf_id))
2749 else if (
unformat (input,
"outside ip6 VRF id %d", &outside_ip6_vrf_id))
2751 else if (
unformat (input,
"inside VRF id %d", &inside_vrf_id))
2753 else if (
unformat (input,
"static mapping only"))
2755 static_mapping_only = 1;
2756 if (
unformat (input,
"connection tracking"))
2757 static_mapping_connection_tracking = 1;
2759 else if (
unformat (input,
"deterministic"))
2761 else if (
unformat (input,
"nat64 bib hash buckets %d",
2762 &nat64_bib_buckets))
2764 else if (
unformat (input,
"nat64 bib hash memory %d",
2765 &nat64_bib_memory_size))
2768 if (
unformat (input,
"nat64 st hash buckets %d", &nat64_st_buckets))
2770 else if (
unformat (input,
"nat64 st hash memory %d",
2771 &nat64_st_memory_size))
2773 else if (
unformat (input,
"out2in dpo"))
2775 else if (
unformat (input,
"dslite ce"))
2777 else if (
unformat (input,
"endpoint-dependent"))
2786 "deterministic and endpoint-dependent modes are mutually exclusive");
2790 "static mapping only mode available only for simple nat");
2794 "out2in dpo mode available only for simple nat");
2819 nat64_set_hash (nat64_bib_buckets, nat64_bib_memory_size, nat64_st_buckets,
2820 nat64_st_memory_size);
2853 if (!static_mapping_only ||
2854 (static_mapping_only && static_mapping_connection_tracking))
2861 clib_bihash_init_16_8 (&tsm->
in2out_ed,
"in2out-ed",
2862 translation_buckets,
2863 translation_memory_size);
2864 clib_bihash_set_kvp_format_fn_16_8 (&tsm->
in2out_ed,
2867 clib_bihash_init_16_8 (&tsm->
out2in_ed,
"out2in-ed",
2868 translation_buckets,
2869 translation_memory_size);
2870 clib_bihash_set_kvp_format_fn_16_8 (&tsm->
out2in_ed,
2875 clib_bihash_init_8_8 (&tsm->
in2out,
"in2out",
2876 translation_buckets,
2877 translation_memory_size);
2878 clib_bihash_set_kvp_format_fn_8_8 (&tsm->
in2out,
2881 clib_bihash_init_8_8 (&tsm->
out2in,
"out2in",
2882 translation_buckets,
2883 translation_memory_size);
2884 clib_bihash_set_kvp_format_fn_8_8 (&tsm->
out2in,
2888 clib_bihash_init_8_8 (&tsm->
user_hash,
"users", user_buckets,
2890 clib_bihash_set_kvp_format_fn_8_8 (&tsm->
user_hash,
2902 "static_mapping_by_local", static_mapping_buckets,
2903 static_mapping_memory_size);
2908 "static_mapping_by_external",
2909 static_mapping_buckets,
2910 static_mapping_memory_size);
2926 u32 if_address_index,
u32 is_delete)
2994 u32 if_address_index,
u32 is_delete)
3024 for (j = 0; j <
vec_len (addresses); j++)
3025 if (addresses[j].
addr.as_u32 == address->
as_u32)
3076 u32 *indices_to_delete = 0;
3078 u32 *auto_add_sw_if_indices =
3085 for (i = 0; i <
vec_len (auto_add_sw_if_indices); i++)
3087 if (auto_add_sw_if_indices[i] == sw_if_index)
3102 if (vec_len (indices_to_delete))
3104 for (j = vec_len (indices_to_delete) - 1; j >= 0; j--)
3115 return VNET_API_ERROR_VALUE_EXIST;
3122 return VNET_API_ERROR_NO_SUCH_ENTRY;
3147 clib_bihash_8_8_t *t;
3150 return VNET_API_ERROR_UNSUPPORTED;
3161 key.
port = clib_host_to_net_u16 (port);
3165 t = is_in ? &tsm->in2out : &tsm->out2in;
3166 if (!clib_bihash_search_8_8 (t, &kv, &value))
3169 return VNET_API_ERROR_UNSPECIFIED;
3177 return VNET_API_ERROR_NO_SUCH_ENTRY;
3183 u32 vrf_id,
int is_in)
3186 clib_bihash_16_8_t *t;
3194 return VNET_API_ERROR_FEATURE_DISABLED;
3204 t = is_in ? &tsm->in2out_ed : &tsm->out2in_ed;
3207 key.
l_port = clib_host_to_net_u16 (port);
3208 key.
r_port = clib_host_to_net_u16 (eh_port);
3213 if (clib_bihash_search_16_8 (t, &kv, &value))
3214 return VNET_API_ERROR_NO_SUCH_ENTRY;
3217 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
nat_outside_fib_t * outside_fibs
#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)
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.
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.
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)
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
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.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define nat_log_warn(...)
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)
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)
#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_output_node_index
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#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)
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)
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
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)
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
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_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Free NAT44 session data (lookup keys, external addrres port)
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.
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
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_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.
clib_bihash_8_8_t static_mapping_by_external
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.
snat_interface_t * output_feature_interfaces
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.
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.
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
u8 * format_session_kvp(u8 *s, va_list *args)
#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 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
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...
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.
snat_get_worker_function_t * worker_out2in_cb
clib_error_t * nat_affinity_init(vlib_main_t *vm)
Initialize NAT client-IP based affinity.
snat_icmp_match_function_t * icmp_match_out2in_cb
vlib_log_class_t log_class
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.
void snat_ipfix_logging_max_entries_per_user(u32 limit, u32 src_ip)
Generate maximum entries per user exceeded event.
#define clib_bitmap_free(v)
Free a bitmap.
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(...)
static clib_error_t * snat_init(vlib_main_t *vm)
static uword is_pow2(uword x)
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index)
Allocate new NAT session or recycle last used.
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.
clib_error_t * nat64_init(vlib_main_t *vm)
Initialize NAT64.
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.
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.
format_function_t format_static_mapping_key
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void snat_ipfix_logging_addresses_exhausted(u32 pool_id)
Generate NAT addresses exhausted event.
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.
#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
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)
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.
#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)
snat_interface_t * interfaces
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 u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)
u32 tcp_established_timeout
static uword pool_elts(void *v)
Number of active elements in a pool.