39 #include <vpp/app/version.h> 49 .arc_name =
"ip4-unicast",
50 .node_name =
"nat-pre-in2out",
52 "ip4-sv-reassembly-feature"),
55 .arc_name =
"ip4-unicast",
56 .node_name =
"nat-pre-out2in",
58 "ip4-dhcp-client-detect",
59 "ip4-sv-reassembly-feature"),
62 .arc_name =
"ip4-unicast",
63 .node_name =
"nat44-in2out-worker-handoff",
67 .arc_name =
"ip4-unicast",
68 .node_name =
"nat44-out2in-worker-handoff",
70 "ip4-dhcp-client-detect"),
73 .arc_name =
"ip4-unicast",
74 .node_name =
"nat44-in2out",
75 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
78 .arc_name =
"ip4-unicast",
79 .node_name =
"nat44-out2in",
80 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature",
81 "ip4-dhcp-client-detect"),
84 .arc_name =
"ip4-unicast",
85 .node_name =
"nat44-classify",
86 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
89 .arc_name =
"ip4-unicast",
90 .node_name =
"nat44-det-in2out",
91 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
94 .arc_name =
"ip4-unicast",
95 .node_name =
"nat44-det-out2in",
96 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature",
97 "ip4-dhcp-client-detect"),
100 .arc_name =
"ip4-unicast",
101 .node_name =
"nat44-det-classify",
102 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
105 .arc_name =
"ip4-unicast",
106 .node_name =
"nat44-ed-in2out",
107 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
110 .arc_name =
"ip4-unicast",
111 .node_name =
"nat44-ed-out2in",
112 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature",
113 "ip4-dhcp-client-detect"),
116 .arc_name =
"ip4-unicast",
117 .node_name =
"nat44-ed-classify",
118 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
121 .arc_name =
"ip4-unicast",
122 .node_name =
"nat44-handoff-classify",
123 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
126 .arc_name =
"ip4-unicast",
127 .node_name =
"nat44-in2out-fast",
128 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
131 .arc_name =
"ip4-unicast",
132 .node_name =
"nat44-out2in-fast",
133 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature",
134 "ip4-dhcp-client-detect"),
137 .arc_name =
"ip4-unicast",
138 .node_name =
"nat44-hairpin-dst",
139 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
142 .arc_name =
"ip4-unicast",
143 .node_name =
"nat44-ed-hairpin-dst",
144 .runs_after =
VNET_FEATURES (
"acl-plugin-in-ip4-fa",
"ip4-sv-reassembly-feature"),
149 .arc_name =
"ip4-output",
150 .node_name =
"nat44-in2out-output",
151 .runs_after =
VNET_FEATURES (
"acl-plugin-out-ip4-fa",
"ip4-sv-reassembly-output-feature"),
154 .arc_name =
"ip4-output",
155 .node_name =
"nat44-in2out-output-worker-handoff",
156 .runs_after =
VNET_FEATURES (
"acl-plugin-out-ip4-fa",
"ip4-sv-reassembly-output-feature"),
159 .arc_name =
"ip4-output",
160 .node_name =
"nat44-hairpin-src",
161 .runs_after =
VNET_FEATURES (
"acl-plugin-out-ip4-fa",
"ip4-sv-reassembly-output-feature"),
164 .arc_name =
"ip4-output",
165 .node_name =
"nat44-ed-in2out-output",
166 .runs_after =
VNET_FEATURES (
"ip4-sv-reassembly-output-feature"),
170 .arc_name =
"ip4-output",
171 .node_name =
"nat44-ed-hairpin-src",
172 .runs_after =
VNET_FEATURES (
"ip4-sv-reassembly-output-feature"),
179 .arc_name =
"ip4-local",
180 .node_name =
"nat44-hairpinning",
185 .arc_name =
"ip4-local",
186 .node_name =
"nat44-ed-hairpinning",
192 .version = VPP_BUILD_VER,
193 .description =
"Network Address Translation (NAT)",
215 make_ed_kv (&s->in2out.addr, &s->ext_host_addr, s->in2out.port, 0,
216 0, 0, ~0ULL, &ed_kv);
220 l_port = s->in2out.port;
221 r_port = s->ext_host_port;
222 l_addr = &s->in2out.addr;
223 r_addr = &s->ext_host_addr;
225 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
228 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0))
238 s->in2out.protocol, s->out2in.port);
239 l_addr = &s->out2in.addr;
240 r_addr = &s->ext_host_addr;
241 fib_index = s->out2in.fib_index;
244 proto = s->in2out.port;
251 l_port = s->out2in.port;
252 r_port = s->ext_host_port;
254 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
256 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &ed_kv, 0))
258 l_addr = &s->in2out.addr;
259 fib_index = s->in2out.fib_index;
261 l_port = s->in2out.port;
264 r_addr = &s->ext_host_nat_addr;
265 r_port = s->ext_host_nat_port;
267 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
269 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0))
274 &s->in2out.addr, s->in2out.port,
275 &s->ext_host_nat_addr, s->ext_host_nat_port,
276 &s->out2in.addr, s->out2in.port,
277 &s->ext_host_addr, s->ext_host_port,
282 kv.
key = s->in2out.as_u64;
283 if (clib_bihash_add_del_8_8 (&tsm->
in2out, &kv, 0))
285 kv.
key = s->out2in.as_u64;
286 if (clib_bihash_add_del_8_8 (&tsm->
out2in, &kv, 0))
291 &s->in2out.addr, s->in2out.port,
292 &s->out2in.addr, s->out2in.port,
303 s->in2out.addr.as_u32,
304 s->out2in.addr.as_u32,
308 s->in2out.fib_index);
310 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
311 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
319 key.
port = s->ext_host_nat_port;
320 key.
addr.
as_u32 = s->ext_host_nat_addr.as_u32;
339 if (len <= fib_index)
353 u32 thread_index,
u8 is_ha)
368 proto = s->in2out.port;
375 l_port = s->in2out.port;
376 r_port = s->ext_host_port;
379 l_addr = &s->in2out.addr;
380 r_addr = &s->ext_host_addr;
382 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
386 (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &ed_kv, 0)))
394 s->in2out.protocol, s->out2in.port);
395 l_addr = &s->out2in.addr;
396 r_addr = &s->ext_host_addr;
397 fib_index = s->out2in.fib_index;
400 proto = s->in2out.port;
407 l_port = s->out2in.port;
408 r_port = s->ext_host_port;
410 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
416 l_addr = &s->in2out.addr;
417 fib_index = s->in2out.fib_index;
420 l_port = s->in2out.port;
424 r_addr = &s->ext_host_nat_addr;
425 r_port = s->ext_host_nat_port;
427 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
436 &s->in2out.addr, s->in2out.port,
437 &s->ext_host_nat_addr, s->ext_host_nat_port,
438 &s->out2in.addr, s->out2in.port,
439 &s->ext_host_addr, s->ext_host_port,
450 s->in2out.addr.as_u32,
451 s->out2in.addr.as_u32,
455 s->in2out.fib_index);
456 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
457 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
465 key.
port = s->ext_host_nat_port;
466 key.
addr.
as_u32 = s->ext_host_nat_addr.as_u32;
495 if (clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
514 if (clib_bihash_add_del_8_8 (&tsm->
user_hash, &kv, 1))
534 u32 thread_index,
f64 now)
538 u32 oldest_per_user_translation_list_index, session_index;
545 oldest_per_user_translation_list_index =
549 ASSERT (oldest_per_user_translation_list_index != ~0);
554 oldest_per_user_translation_list_index);
556 oldest_per_user_translation_list_elt =
558 oldest_per_user_translation_list_index);
561 session_index = oldest_per_user_translation_list_elt->
value;
574 s->ext_host_addr.as_u32 = 0;
575 s->ext_host_port = 0;
576 s->ext_host_nat_addr.as_u32 = 0;
577 s->ext_host_nat_port = 0;
587 per_user_translation_list_elt - tsm->
list_pool);
590 s->per_user_index = per_user_translation_list_elt - tsm->
list_pool;
594 s->per_user_list_head_index,
595 per_user_translation_list_elt - tsm->
list_pool);
597 s->user_index = u - tsm->
users;
602 s->ha_last_refreshed = now;
615 .ip4.as_u32 = addr->
as_u32,
644 return VNET_API_ERROR_FEATURE_DISABLED;
651 return VNET_API_ERROR_VALUE_EXIST;
667 #define _(N, i, n, s) \ 668 clib_memset(ap->busy_##n##_port_refcounts, 0, sizeof(ap->busy_##n##_port_refcounts));\ 669 ap->busy_##n##_ports = 0; \ 670 ap->busy_##n##_ports_per_thread = 0;\ 671 vec_validate_init_empty (ap->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0); 681 if (nat_interface_is_inside(i) || sm->out2in_dpo)
684 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
689 if (nat_interface_is_inside(i) || sm->out2in_dpo)
692 snat_add_del_addr_to_fib(addr, 32, i->sw_if_index, 1);
707 if (is_addr_only_static_mapping (m) ||
708 is_out2in_only_static_mapping (m) ||
709 is_identity_static_mapping (m))
711 if (m->external_addr.as_u32 == addr.as_u32)
727 int addr_only,
int is_add,
u8 * tag,
728 int twice_nat,
int out2in_only,
774 u32 elt_index, head_index, ses_index;
775 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
777 user_index = value.
value;
783 elt_index = head->
next;
785 ses_index = elt->
value;
786 while (ses_index != ~0)
790 ses_index = elt->
value;
794 if ((s->out2in.addr.as_u32 != e_addr.
as_u32) ||
795 (clib_net_to_host_u16 (s->out2in.port) != e_port))
821 u32 fib_index,
int addr_only,
825 u32 *indexes_to_free = NULL;
828 if (s->in2out.fib_index != fib_index ||
829 s->in2out.addr.as_u32 != l_addr.as_u32)
835 if ((s->out2in.addr.as_u32 != e_addr.
as_u32) ||
836 (clib_net_to_host_u16 (s->out2in.port) != e_port) ||
837 clib_net_to_host_u16 (s->in2out.port) != l_port ||
838 s->in2out.protocol != protocol)
880 u32 elt_index, head_index;
890 if (twice_nat || out2in_only)
891 return VNET_API_ERROR_FEATURE_DISABLED;
895 if (sw_if_index != ~0)
925 return VNET_API_ERROR_VALUE_EXIST;
928 (sm, l_addr, l_port, sw_if_index, e_port, vrf_id, proto,
929 addr_only, is_add, tag, twice_nat, out2in_only, identity_nat);
932 if (first_int_addr == 0)
947 return VNET_API_ERROR_NO_SUCH_ENTRY;
964 m_key.
port = addr_only ? 0 : e_port;
982 if (local->vrf_id == vrf_id)
983 return VNET_API_ERROR_VALUE_EXIST;
1001 return VNET_API_ERROR_VALUE_EXIST;
1004 if (twice_nat && addr_only)
1005 return VNET_API_ERROR_UNSUPPORTED;
1020 if (!(out2in_only || identity_nat))
1022 m_key.
addr = l_addr;
1023 m_key.
port = addr_only ? 0 : l_port;
1027 if (!clib_bihash_search_8_8
1029 return VNET_API_ERROR_VALUE_EXIST;
1044 #define _(N, j, n, s) \ 1045 case NAT_PROTOCOL_##N: \ 1046 if (a->busy_##n##_port_refcounts[e_port]) \ 1047 return VNET_API_ERROR_INVALID_VALUE; \ 1048 ++a->busy_##n##_port_refcounts[e_port]; \ 1049 if (e_port > 1024) \ 1051 a->busy_##n##_ports++; \ 1052 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ 1059 return VNET_API_ERROR_INVALID_VALUE_2;
1067 if (sw_if_index != ~0)
1084 return VNET_API_ERROR_NO_SUCH_ENTRY;
1150 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
1152 user_index = value.
value;
1158 elt_index = head->
next;
1160 ses_index = elt->
value;
1161 while (ses_index != ~0)
1165 ses_index = elt->
value;
1171 && (clib_net_to_host_u16 (s->in2out.port) !=
1190 if (sw_if_index != ~0)
1193 return VNET_API_ERROR_NO_SUCH_ENTRY;
1204 if (local->vrf_id == vrf_id)
1205 find = local - m->locals;
1209 return VNET_API_ERROR_NO_SUCH_ENTRY;
1228 #define _(N, j, n, s) \ 1229 case NAT_PROTOCOL_##N: \ 1230 --a->busy_##n##_port_refcounts[e_port]; \ 1231 if (e_port > 1024) \ 1233 a->busy_##n##_ports--; \ 1234 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ 1241 return VNET_API_ERROR_INVALID_VALUE_2;
1269 fib_index, addr_only,
1305 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1308 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
1313 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1316 snat_add_del_addr_to_fib(&e_addr, 32, interface->sw_if_index, is_add);
1329 u8 * tag,
u32 affinity)
1343 return VNET_API_ERROR_FEATURE_DISABLED;
1345 m_key.
addr = e_addr;
1346 m_key.
port = e_port;
1358 return VNET_API_ERROR_VALUE_EXIST;
1361 return VNET_API_ERROR_INVALID_VALUE;
1375 #define _(N, j, n, s) \ 1376 case NAT_PROTOCOL_##N: \ 1377 if (a->busy_##n##_port_refcounts[e_port]) \ 1378 return VNET_API_ERROR_INVALID_VALUE; \ 1379 ++a->busy_##n##_port_refcounts[e_port]; \ 1380 if (e_port > 1024) \ 1382 a->busy_##n##_ports++; \ 1383 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ 1390 return VNET_API_ERROR_INVALID_VALUE_2;
1397 return VNET_API_ERROR_NO_SUCH_ENTRY;
1426 nat_elog_err (
"static_mapping_by_external key add failed");
1427 return VNET_API_ERROR_UNSPECIFIED;
1431 for (i = 0; i <
vec_len (locals); i++)
1453 .src_address = locals[
i].
addr,
1476 return VNET_API_ERROR_NO_SUCH_ENTRY;
1479 return VNET_API_ERROR_INVALID_VALUE;
1491 #define _(N, j, n, s) \ 1492 case NAT_PROTOCOL_##N: \ 1493 --a->busy_##n##_port_refcounts[e_port]; \ 1494 if (e_port > 1024) \ 1496 a->busy_##n##_ports--; \ 1497 a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ 1504 return VNET_API_ERROR_INVALID_VALUE_2;
1518 nat_elog_err (
"static_mapping_by_external key del failed");
1519 return VNET_API_ERROR_UNSPECIFIED;
1525 fib_table_unlock (local->fib_index, FIB_PROTOCOL_IP4,
1527 m_key.addr = local->addr;
1530 m_key.port = local->port;
1531 m_key.fib_index = local->fib_index;
1532 kv.key = m_key.as_u64;
1533 if (clib_bihash_add_del_8_8(&sm->static_mapping_by_local, &kv, 0))
1535 nat_elog_err (
"static_mapping_by_local key del failed");
1536 return VNET_API_ERROR_UNSPECIFIED;
1543 .src_address = local->addr,
1553 if (!(is_lb_session (s)))
1556 if ((s->in2out.addr.as_u32 != local->addr.as_u32) ||
1557 (clib_net_to_host_u16 (s->in2out.port) != local->port))
1560 nat_free_session_data (sm, s, tsm - sm->per_thread_data, 0);
1561 nat_ed_session_delete (sm, s, tsm - sm->per_thread_data, 1);
1595 return VNET_API_ERROR_FEATURE_DISABLED;
1597 m_key.
addr = e_addr;
1598 m_key.
port = e_port;
1606 return VNET_API_ERROR_NO_SUCH_ENTRY;
1609 return VNET_API_ERROR_INVALID_VALUE;
1614 if ((local->addr.as_u32 == l_addr.as_u32) && (local->port == l_port) &&
1615 (local->vrf_id == vrf_id))
1617 match_local = local;
1626 return VNET_API_ERROR_VALUE_EXIST;
1630 local->addr.as_u32 = l_addr.as_u32;
1631 local->port = l_port;
1640 m_key.addr = l_addr;
1641 m_key.port = l_port;
1642 m_key.fib_index = local->fib_index;
1643 kv.key = m_key.as_u64;
1644 kv.value = m - sm->static_mappings;
1645 if (clib_bihash_add_del_8_8 (&sm->static_mapping_by_local, &kv, 1))
1646 nat_elog_err (
"static_mapping_by_local key add failed");
1652 return VNET_API_ERROR_NO_SUCH_ENTRY;
1655 return VNET_API_ERROR_UNSPECIFIED;
1662 m_key.addr = l_addr;
1663 m_key.port = l_port;
1664 m_key.fib_index = match_local->fib_index;
1665 kv.key = m_key.as_u64;
1666 if (clib_bihash_add_del_8_8 (&sm->static_mapping_by_local, &kv, 0))
1667 nat_elog_err (
"static_mapping_by_local key del failed");
1670 if (sm->num_workers > 1)
1673 .src_address = local->addr,
1676 sm->worker_in2out_cb (&ip, m->fib_index,
1685 if (!(is_lb_session (s)))
1688 if ((s->in2out.addr.as_u32 != match_local->addr.as_u32) ||
1689 (clib_net_to_host_u16 (s->in2out.port) != match_local->port))
1692 nat_free_session_data (sm, s, tsm - sm->per_thread_data, 0);
1693 nat_ed_session_delete (sm, s, tsm - sm->per_thread_data, 1);
1705 vec_add1 (locals, local - m->locals);
1706 if (sm->num_workers > 1)
1709 ip.src_address.as_u32 = local->addr.as_u32,
1710 bitmap = clib_bitmap_set (bitmap,
1711 sm->worker_in2out_cb (&ip, local->fib_index, 0),
1720 local->prefix = local->probability;
1725 local->prefix = local->probability + prev_local->prefix;
1729 if (sm->num_workers > 1)
1744 snat_session_t *ses;
1745 u32 *ses_to_be_removed = 0, *ses_index;
1754 for (i = 0; i <
vec_len (addresses); i++)
1763 return VNET_API_ERROR_NO_SUCH_ENTRY;
1770 if (m->external_addr.as_u32 == addr.as_u32)
1771 (void) snat_add_static_mapping (m->local_addr, m->external_addr,
1772 m->local_port, m->external_port,
1773 m->vrf_id, is_addr_only_static_mapping(m), ~0,
1774 m->proto, 0, m->twice_nat,
1775 is_out2in_only_static_mapping(m), m->tag, is_identity_static_mapping(m));
1785 return VNET_API_ERROR_UNSPECIFIED;
1793 if (a->busy_tcp_ports || a->busy_udp_ports || a->busy_icmp_ports)
1799 if (ses->out2in.addr.as_u32 == addr.as_u32)
1801 nat_free_session_data (sm, ses, tsm - sm->per_thread_data, 0);
1802 vec_add1 (ses_to_be_removed, ses - tsm->sessions);
1825 #define _(N, i, n, s) \ 1826 vec_free (a->busy_##n##_ports_per_thread); 1841 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1844 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
1847 pool_foreach (interface, sm->output_feature_interfaces,
1849 if (nat_interface_is_inside(interface) || sm->out2in_dpo)
1852 snat_add_del_addr_to_fib(&addr, 32, interface->sw_if_index, 0);
1865 const char *feature_name, *del_feature_name;
1874 return VNET_API_ERROR_UNSUPPORTED;
1879 if (i->sw_if_index == sw_if_index)
1880 return VNET_API_ERROR_VALUE_EXIST;
1885 feature_name = is_inside ?
"nat44-in2out-fast" :
"nat44-out2in-fast";
1890 is_inside ?
"nat44-in2out-worker-handoff" :
1891 "nat44-out2in-worker-handoff";
1893 feature_name = is_inside ?
"nat44-det-in2out" :
"nat44-det-out2in";
1896 feature_name = is_inside ?
"nat-pre-in2out" :
"nat-pre-out2in";
1899 feature_name = is_inside ?
"nat44-in2out" :
"nat44-out2in";
1915 if (outside_fib->
fib_index == fib_index)
1940 if (i->sw_if_index == sw_if_index)
1944 if (nat_interface_is_inside(i) && nat_interface_is_outside(i))
1947 i->flags &= ~NAT_INTERFACE_FLAG_IS_INSIDE;
1949 i->flags &= ~NAT_INTERFACE_FLAG_IS_OUTSIDE;
1951 if (sm->num_workers > 1 && !sm->deterministic)
1953 del_feature_name =
"nat44-handoff-classify";
1954 feature_name = !is_inside ?
"nat44-in2out-worker-handoff" :
1955 "nat44-out2in-worker-handoff";
1957 else if (sm->deterministic)
1959 del_feature_name =
"nat44-det-classify";
1960 feature_name = !is_inside ?
"nat44-det-in2out" :
1963 else if (sm->endpoint_dependent)
1965 del_feature_name =
"nat44-ed-classify";
1966 feature_name = !is_inside ?
"nat-pre-in2out" :
1971 del_feature_name =
"nat44-classify";
1972 feature_name = !is_inside ?
"nat44-in2out" :
"nat44-out2in";
1975 int rv = ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, 0);
1978 vnet_feature_enable_disable (
"ip4-unicast", del_feature_name,
1979 sw_if_index, 0, 0, 0);
1980 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
1981 sw_if_index, 1, 0, 0);
1984 if (sm->endpoint_dependent)
1985 vnet_feature_enable_disable (
"ip4-local",
1986 "nat44-ed-hairpinning",
1987 sw_if_index, 1, 0, 0);
1988 else if (!sm->deterministic)
1989 vnet_feature_enable_disable (
"ip4-local",
1990 "nat44-hairpinning",
1991 sw_if_index, 1, 0, 0);
1996 int rv = ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, 0);
1999 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
2000 sw_if_index, 0, 0, 0);
2001 pool_put (sm->interfaces, i);
2004 if (sm->endpoint_dependent)
2005 vnet_feature_enable_disable (
"ip4-local",
2006 "nat44-ed-hairpinning",
2007 sw_if_index, 0, 0, 0);
2008 else if (!sm->deterministic)
2009 vnet_feature_enable_disable (
"ip4-local",
2010 "nat44-hairpinning",
2011 sw_if_index, 0, 0, 0);
2017 if ((nat_interface_is_inside(i) && is_inside) ||
2018 (nat_interface_is_outside(i) && !is_inside))
2021 if (sm->num_workers > 1 && !sm->deterministic)
2023 del_feature_name = !is_inside ?
"nat44-in2out-worker-handoff" :
2024 "nat44-out2in-worker-handoff";
2025 feature_name =
"nat44-handoff-classify";
2027 else if (sm->deterministic)
2029 del_feature_name = !is_inside ?
"nat44-det-in2out" :
2031 feature_name =
"nat44-det-classify";
2033 else if (sm->endpoint_dependent)
2035 del_feature_name = !is_inside ?
"nat-pre-in2out" :
2038 feature_name =
"nat44-ed-classify";
2042 del_feature_name = !is_inside ?
"nat44-in2out" :
"nat44-out2in";
2043 feature_name =
"nat44-classify";
2046 int rv = ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, 1);
2049 vnet_feature_enable_disable (
"ip4-unicast", del_feature_name,
2050 sw_if_index, 0, 0, 0);
2051 vnet_feature_enable_disable (
"ip4-unicast", feature_name,
2052 sw_if_index, 1, 0, 0);
2055 if (sm->endpoint_dependent)
2056 vnet_feature_enable_disable (
"ip4-local",
"nat44-ed-hairpinning",
2057 sw_if_index, 0, 0, 0);
2058 else if (!sm->deterministic)
2059 vnet_feature_enable_disable (
"ip4-local",
"nat44-hairpinning",
2060 sw_if_index, 0, 0, 0);
2071 return VNET_API_ERROR_NO_SUCH_ENTRY;
2083 if (is_inside && !sm->out2in_dpo)
2085 if (sm->endpoint_dependent)
2088 else if (!sm->deterministic)
2110 if (!(is_addr_only_static_mapping(m)) || (m->local_addr.as_u32 == m->external_addr.as_u32))
2113 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
2118 snat_add_del_addr_to_fib(&dm->out_addr, dm->out_plen, sw_if_index, !is_del);
2127 u8 is_inside,
int is_del)
2140 return VNET_API_ERROR_UNSUPPORTED;
2145 if (i->sw_if_index == sw_if_index)
2146 return VNET_API_ERROR_VALUE_EXIST;
2155 if (outside_fib->
fib_index == fib_index)
2192 sw_if_index, !is_del, 0, 0);
2194 sw_if_index, !is_del, 0, 0);
2208 sw_if_index, !is_del, 0, 0);
2210 sw_if_index, !is_del, 0, 0);
2225 "nat44-out2in-worker-handoff",
2226 sw_if_index, !is_del, 0, 0);
2228 "nat44-in2out-output-worker-handoff",
2229 sw_if_index, !is_del, 0, 0);
2245 sw_if_index, !is_del, 0, 0);
2247 sw_if_index, !is_del, 0, 0);
2261 sw_if_index, !is_del, 0, 0);
2263 sw_if_index, !is_del, 0, 0);
2279 if (i->sw_if_index == sw_if_index)
2282 pool_put (sm->output_feature_interfaces, i);
2284 return VNET_API_ERROR_VALUE_EXIST;
2292 return VNET_API_ERROR_NO_SUCH_ENTRY;
2294 pool_get (sm->output_feature_interfaces,
i);
2313 if (!((is_addr_only_static_mapping(m))) || (m->local_addr.as_u32 == m->external_addr.as_u32))
2316 snat_add_del_addr_to_fib(&m->external_addr, 32, sw_if_index, !is_del);
2330 return VNET_API_ERROR_FEATURE_DISABLED;
2333 return VNET_API_ERROR_INVALID_WORKER;
2362 if (new_fib_index == old_fib_index)
2371 if (i->sw_if_index == sw_if_index)
2373 if (!(nat_interface_is_outside (i)))
2381 if (i->sw_if_index == sw_if_index)
2383 if (!(nat_interface_is_outside (i)))
2395 if (outside_fib->fib_index == old_fib_index)
2397 outside_fib->refcount--;
2398 if (!outside_fib->refcount)
2399 vec_del1 (sm->outside_fibs, outside_fib - sm->outside_fibs);
2406 if (outside_fib->fib_index == new_fib_index)
2408 outside_fib->refcount++;
2416 vec_add2 (sm->outside_fibs, outside_fib, 1);
2417 outside_fib->refcount = 1;
2418 outside_fib->fib_index = new_fib_index;
2436 u32 if_address_index,
u32 is_delete);
2444 u32 if_address_index,
u32 is_delete);
2451 u16 port_per_thread,
u32 snat_thread_index);
2457 l_addr.
as_u8[0] = 1;
2458 l_addr.
as_u8[1] = 1;
2459 l_addr.
as_u8[2] = 1;
2460 l_addr.
as_u8[3] = 1;
2462 r_addr.
as_u8[0] = 2;
2463 r_addr.
as_u8[1] = 2;
2464 r_addr.
as_u8[2] = 2;
2465 r_addr.
as_u8[3] = 2;
2469 u32 fib_index = 9000001;
2472 make_ed_kv (&l_addr, &r_addr, proto, fib_index, l_port, r_port, value, &kv);
2481 split_ed_kv (&kv, &l_addr2, &r_addr2, &proto2, &fib_index2, &l_port2,
2486 ASSERT (l_port == l_port2);
2487 ASSERT (r_port == r_port2);
2488 ASSERT (proto == proto2);
2489 ASSERT (fib_index == fib_index2);
2490 ASSERT (value == value2);
2674 u16 port_host_byte_order = clib_net_to_host_u16 (k->
port);
2676 for (address_index = 0; address_index <
vec_len (addresses);
2683 ASSERT (address_index < vec_len (addresses));
2685 a = addresses + address_index;
2689 #define _(N, i, n, s) \ 2690 case NAT_PROTOCOL_##N: \ 2691 ASSERT (a->busy_##n##_port_refcounts[port_host_byte_order] >= 1); \ 2692 --a->busy_##n##_port_refcounts[port_host_byte_order]; \ 2693 a->busy_##n##_ports--; \ 2694 a->busy_##n##_ports_per_thread[thread_index]--; \ 2710 u16 port_host_byte_order = clib_net_to_host_u16 (k->
port);
2712 for (address_index = 0; address_index <
vec_len (addresses);
2718 a = addresses + address_index;
2721 #define _(N, j, n, s) \ 2722 case NAT_PROTOCOL_##N: \ 2723 if (a->busy_##n##_port_refcounts[port_host_byte_order]) \ 2724 return VNET_API_ERROR_INSTANCE_IN_USE; \ 2725 ++a->busy_##n##_port_refcounts[port_host_byte_order]; \ 2726 a->busy_##n##_ports_per_thread[thread_index]++; \ 2727 a->busy_##n##_ports++; \ 2737 return VNET_API_ERROR_NO_SUCH_ENTRY;
2748 u8 * is_identity_nat)
2754 u32 rand,
lo = 0,
hi, mid, *tmp = 0,
i;
2766 m_key.
port = clib_net_to_host_u16 (match.
port);
2771 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
2777 if (clib_bihash_search_8_8 (mapping_hash, &kv, &value))
2797 mapping->
port = clib_host_to_net_u16 (local->
port);
2808 local = pool_elt_at_index (m->locals, i);
2811 .src_address = local->addr,
2837 mid = ((hi -
lo) >> 1) +
lo;
2839 (rand > local->
prefix) ? (lo = mid + 1) : (hi = mid);
2842 if (!(local->
prefix >= rand))
2845 mapping->
port = clib_host_to_net_u16 (local->
port);
2871 mapping->addr = m->external_addr;
2874 : clib_host_to_net_u16 (m->external_port);
2875 mapping->fib_index = sm->outside_fib_index;
2883 *twice_nat = m->twice_nat;
2904 u16 port_per_thread,
2905 u32 snat_thread_index)
2910 port_per_thread, snat_thread_index);
2918 u16 port_per_thread,
u32 snat_thread_index)
2924 for (i = 0; i <
vec_len (addresses); i++)
2929 #define _(N, j, n, s) \ 2930 case NAT_PROTOCOL_##N: \ 2931 if (a->busy_##n##_ports_per_thread[thread_index] < port_per_thread) \ 2933 if (a->fib_index == fib_index) \ 2937 portnum = (port_per_thread * \ 2938 snat_thread_index) + \ 2939 snat_random_port(1, port_per_thread) + 1024; \ 2940 if (a->busy_##n##_port_refcounts[portnum]) \ 2942 --a->busy_##n##_port_refcounts[portnum]; \ 2943 a->busy_##n##_ports_per_thread[thread_index]++; \ 2944 a->busy_##n##_ports++; \ 2945 k->addr = a->addr; \ 2946 k->port = clib_host_to_net_u16(portnum); \ 2950 else if (a->fib_index == ~0) \ 2970 #define _(N, j, n, s) \ 2971 case NAT_PROTOCOL_##N: \ 2974 portnum = (port_per_thread * \ 2975 snat_thread_index) + \ 2976 snat_random_port(1, port_per_thread) + 1024; \ 2977 if (a->busy_##n##_port_refcounts[portnum]) \ 2979 ++a->busy_##n##_port_refcounts[portnum]; \ 2980 a->busy_##n##_ports_per_thread[thread_index]++; \ 2981 a->busy_##n##_ports++; \ 2982 k->addr = a->addr; \ 2983 k->port = clib_host_to_net_u16(portnum); \ 3005 u16 port_per_thread,
u32 snat_thread_index)
3009 u16 m, ports, portnum,
A, j;
3018 #define _(N, i, n, s) \ 3019 case NAT_PROTOCOL_##N: \ 3020 if (a->busy_##n##_ports < ports) \ 3024 A = snat_random_port(1, pow2_mask(sm->psid_offset)); \ 3025 j = snat_random_port(0, pow2_mask(m)); \ 3026 portnum = A | (sm->psid << sm->psid_offset) | (j << (16 - m)); \ 3027 if (a->busy_##n##_port_refcounts[portnum]) \ 3029 ++a->busy_##n##_port_refcounts[portnum]; \ 3030 a->busy_##n##_ports++; \ 3031 k->addr = a->addr; \ 3032 k->port = clib_host_to_net_u16 (portnum); \ 3055 u16 port_per_thread,
u32 snat_thread_index)
3068 #define _(N, i, n, s) \ 3069 case NAT_PROTOCOL_##N: \ 3070 if (a->busy_##n##_ports < ports) \ 3074 portnum = snat_random_port(sm->start_port, sm->end_port); \ 3075 if (a->busy_##n##_port_refcounts[portnum]) \ 3077 ++a->busy_##n##_port_refcounts[portnum]; \ 3078 a->busy_##n##_ports++; \ 3079 k->addr = a->addr; \ 3080 k->port = clib_host_to_net_u16 (portnum); \ 3105 .fp_addr.ip4.as_u32 = addr.
as_u32,
3142 s =
format (s,
"%U static-mapping-index %llu",
3172 split_ed_kv (v, &l_addr, &r_addr, &proto, &fib_index, &l_port, &r_port);
3174 format (s,
"local %U:%d remote %U:%d proto %U fib %d session-index %llu",
3187 u32 next_worker_index = 0;
3195 next_worker_index += sm->
workers[hash & (_vec_len (sm->
workers) - 1)];
3199 return next_worker_index;
3204 u32 rx_fib_index0,
u8 is_output)
3213 u32 next_worker_index = 0;
3223 if (!clib_bihash_search_8_8
3244 icmp46_header_t *icmp = (icmp46_header_t *) udp;
3247 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
3257 case NAT_PROTOCOL_ICMP:
3258 icmp = (icmp46_header_t *) l4_header;
3262 case NAT_PROTOCOL_UDP:
3263 case NAT_PROTOCOL_TCP:
3276 m_key.
port = clib_net_to_host_u16 (port);
3280 if (!clib_bihash_search_8_8
3290 next_worker_index +=
3292 return next_worker_index;
3362 "HANDOFF IN2OUT-OUTPUT-FEATURE (session)",
3363 next_worker_index, fib_index,
3367 return next_worker_index;
3377 next_worker_index += sm->
workers[hash & (_vec_len (sm->
workers) - 1)];
3384 next_worker_index, rx_fib_index,
3391 next_worker_index, rx_fib_index,
3396 return next_worker_index;
3401 u32 rx_fib_index,
u8 is_output)
3416 if (
PREDICT_TRUE (proto == NAT_PROTOCOL_UDP || proto == NAT_PROTOCOL_TCP))
3432 next_worker_index, rx_fib_index,
3435 return next_worker_index;
3440 else if (proto == NAT_PROTOCOL_ICMP)
3453 next_worker_index, rx_fib_index,
3456 return next_worker_index;
3467 if (!clib_bihash_search_8_8
3471 next_worker_index = m->
workers[0];
3489 icmp46_header_t *icmp = (icmp46_header_t *) udp;
3492 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
3502 case NAT_PROTOCOL_ICMP:
3503 icmp = (icmp46_header_t *) l4_header;
3507 case NAT_PROTOCOL_UDP:
3508 case NAT_PROTOCOL_TCP:
3522 clib_net_to_host_u16 (port));
3523 if (!clib_bihash_search_8_8
3529 next_worker_index = m->
workers[0];
3547 next_worker_index +=
3554 return next_worker_index;
3578 .ip4.as_u32 = eh_addr->
as_u32,
3583 key.
port = out_port;
3606 s->last_heard = now;
3608 s->ext_host_addr.as_u32 = eh_addr->
as_u32;
3609 s->ext_host_port = eh_port;
3639 if (clib_bihash_add_del_8_8 (&tsm->
out2in, &kv, 1))
3647 if (clib_bihash_add_del_8_8 (&tsm->
in2out, &kv, 1))
3666 (sm->
workers[(clib_net_to_host_u16 (out_port) -
3673 key.
port = out_port;
3677 if (clib_bihash_search_8_8 (&tsm->
out2in, &kv, &value))
3688 u32 total_pkts,
u64 total_bytes,
u32 thread_index)
3699 key.
port = out_port;
3703 if (clib_bihash_search_8_8 (&tsm->
out2in, &kv, &value))
3707 s->total_pkts = total_pkts;
3708 s->total_bytes = total_bytes;
3731 .ip4.as_u32 = eh_addr->
as_u32,
3736 key.
port = out_port;
3747 key.
port = ehn_port;
3759 s->last_heard = now;
3761 s->ext_host_nat_addr.as_u32 = s->ext_host_addr.as_u32 = eh_addr->
as_u32;
3762 s->ext_host_nat_port = s->ext_host_port = eh_port;
3765 s->ext_host_nat_addr.as_u32 = ehn_addr->
as_u32;
3766 s->ext_host_nat_port = ehn_port;
3794 key.
port = out_port;
3805 s->ext_host_nat_port, s - tsm->
sessions, &kv);
3806 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &kv, 1))
3810 s->out2in.fib_index, out_port, eh_port, s - tsm->
sessions, &kv);
3811 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &kv, 1))
3829 (sm->
workers[(clib_net_to_host_u16 (out_port) -
3835 make_ed_kv (out_addr, eh_addr, proto, fib_index, out_port, eh_port, ~0ULL,
3837 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
3848 u32 fib_index,
u32 total_pkts,
u64 total_bytes,
3858 make_ed_kv (out_addr, eh_addr, proto, fib_index, out_port, eh_port, ~0ULL,
3860 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
3864 s->total_pkts = total_pkts;
3865 s->total_bytes = total_bytes;
3900 clib_bihash_init_16_8 (&tsm->
in2out_ed,
"in2out-ed",
3903 clib_bihash_set_kvp_format_fn_16_8 (&tsm->
in2out_ed,
3905 clib_bihash_init_16_8 (&tsm->
out2in_ed,
"out2in-ed",
3908 clib_bihash_set_kvp_format_fn_16_8 (&tsm->
out2in_ed,
3913 clib_bihash_init_8_8 (&tsm->
in2out,
"in2out",
3917 clib_bihash_init_8_8 (&tsm->
out2in,
"out2in",
3940 clib_bihash_free_16_8 (&tsm->
in2out_ed);
3941 clib_bihash_free_16_8 (&tsm->
out2in_ed);
3945 clib_bihash_free_8_8 (&tsm->
in2out);
3946 clib_bihash_free_8_8 (&tsm->
out2in);
3962 u32 static_mapping_buckets = 1024;
3963 uword static_mapping_memory_size = 64 << 20;
3965 u32 nat64_bib_buckets = 1024;
3966 u32 nat64_bib_memory_size = 128 << 20;
3968 u32 nat64_st_buckets = 2048;
3969 uword nat64_st_memory_size = 256 << 20;
3971 u32 user_buckets = 128;
3972 uword user_memory_size = 64 << 20;
3973 u32 translation_buckets = 1024;
3974 uword translation_memory_size = 128 << 20;
3976 u32 max_translations_per_user = ~0;
3978 u32 outside_vrf_id = 0;
3979 u32 outside_ip6_vrf_id = 0;
3980 u32 inside_vrf_id = 0;
3981 u8 static_mapping_only = 0;
3982 u8 static_mapping_connection_tracking = 0;
3997 (input,
"translation hash buckets %d", &translation_buckets))
3999 else if (
unformat (input,
"udp timeout %d", &udp_timeout))
4001 else if (
unformat (input,
"icmp timeout %d", &icmp_timeout))
4003 else if (
unformat (input,
"tcp transitory timeout %d",
4004 &tcp_transitory_timeout));
4005 else if (
unformat (input,
"tcp established timeout %d",
4006 &tcp_established_timeout));
4007 else if (
unformat (input,
"translation hash memory %d",
4008 &translation_memory_size));
4009 else if (
unformat (input,
"user hash buckets %d", &user_buckets))
4011 else if (
unformat (input,
"user hash memory %d", &user_memory_size))
4013 else if (
unformat (input,
"max translations per user %d",
4014 &max_translations_per_user))
4016 else if (
unformat (input,
"outside VRF id %d", &outside_vrf_id))
4018 else if (
unformat (input,
"outside ip6 VRF id %d", &outside_ip6_vrf_id))
4020 else if (
unformat (input,
"inside VRF id %d", &inside_vrf_id))
4022 else if (
unformat (input,
"static mapping only"))
4024 static_mapping_only = 1;
4025 if (
unformat (input,
"connection tracking"))
4026 static_mapping_connection_tracking = 1;
4028 else if (
unformat (input,
"deterministic"))
4030 else if (
unformat (input,
"nat64 bib hash buckets %d",
4031 &nat64_bib_buckets))
4033 else if (
unformat (input,
"nat64 bib hash memory %d",
4034 &nat64_bib_memory_size))
4037 if (
unformat (input,
"nat64 st hash buckets %d", &nat64_st_buckets))
4039 else if (
unformat (input,
"nat64 st hash memory %d",
4040 &nat64_st_memory_size))
4042 else if (
unformat (input,
"out2in dpo"))
4046 else if (
unformat (input,
"endpoint-dependent"))
4055 "deterministic and endpoint-dependent modes are mutually exclusive");
4059 "static mapping only mode available only for simple nat");
4063 "out2in dpo mode available only for simple nat");
4098 nat64_set_hash (nat64_bib_buckets, nat64_bib_memory_size, nat64_st_buckets,
4099 nat64_st_memory_size);
4139 if (!static_mapping_only ||
4140 (static_mapping_only && static_mapping_connection_tracking))
4155 "static_mapping_by_local", static_mapping_buckets,
4156 static_mapping_memory_size);
4161 "static_mapping_by_external",
4162 static_mapping_buckets,
4163 static_mapping_memory_size);
4179 u32 if_address_index,
u32 is_delete)
4247 u32 if_address_index,
u32 is_delete)
4277 for (j = 0; j <
vec_len (addresses); j++)
4278 if (addresses[j].
addr.as_u32 == address->
as_u32)
4330 u32 *indices_to_delete = 0;
4332 u32 *auto_add_sw_if_indices =
4339 for (i = 0; i <
vec_len (auto_add_sw_if_indices); i++)
4341 if (auto_add_sw_if_indices[i] == sw_if_index)
4356 if (vec_len (indices_to_delete))
4358 for (j = vec_len (indices_to_delete) - 1; j >= 0; j--)
4369 return VNET_API_ERROR_VALUE_EXIST;
4376 return VNET_API_ERROR_NO_SUCH_ENTRY;
4401 clib_bihash_8_8_t *t;
4404 return VNET_API_ERROR_UNSUPPORTED;
4415 key.
port = clib_host_to_net_u16 (port);
4419 t = is_in ? &tsm->in2out : &tsm->out2in;
4420 if (!clib_bihash_search_8_8 (t, &kv, &value))
4423 return VNET_API_ERROR_UNSPECIFIED;
4431 return VNET_API_ERROR_NO_SUCH_ENTRY;
4440 clib_bihash_16_8_t *t;
4447 return VNET_API_ERROR_FEATURE_DISABLED;
4457 t = is_in ? &tsm->in2out_ed : &tsm->out2in_ed;
4458 make_ed_kv (addr, eh_addr, proto, fib_index, clib_host_to_net_u16 (port),
4459 clib_host_to_net_u16 (eh_port), ~0ULL, &kv);
4460 if (clib_bihash_search_16_8 (t, &kv, &value))
4462 return VNET_API_ERROR_NO_SUCH_ENTRY;
4466 return VNET_API_ERROR_UNSPECIFIED;
4514 .name =
"nat-default",
4515 .vector_size =
sizeof (
u32),
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)
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
enum fib_source_t_ fib_source_t
The different sources that can create a route.
uword translation_memory_size
u32 * max_translations_per_fib
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
u32 sessions_per_user_list_head_index
void nat44_db_init(snat_main_per_thread_data_t *tsm)
Initialize NAT44 data.
vlib_node_registration_t nat_default_node
(constructor) VLIB_REGISTER_NODE (nat_default_node)
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
#define nat_elog_debug_handoff(_str, _tid, _fib, _src, _dst)
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 test_ed_make_split()
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)
int ip4_sv_reass_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, nat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44 session.
vnet_main_t * vnet_get_main(void)
#define nat_elog_info(nat_elog_str)
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...
#define nat_elog_notice(nat_elog_str)
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
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 u32 nat44_ed_get_worker_out2in_cb(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
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)
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 address port)
add paths without path extensions
int ip4_sv_reass_output_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
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)
ip_lookup_main_t lookup_main
void snat_static_mapping_del_sessions(snat_main_t *sm, snat_main_per_thread_data_t *tsm, snat_user_key_t u_key, int addr_only, ip4_address_t e_addr, u16 e_port)
#define nat_elog_warn(nat_elog_str)
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
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.
#define VLIB_NODE_FN(node)
static void nat_ed_session_delete(snat_main_t *sm, snat_session_t *ses, u32 thread_index, int lru_delete)
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.
void nat44_db_free(snat_main_per_thread_data_t *tsm)
Free NAT44 data.
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)
VNET_FEATURE_INIT(nat_pre_in2out, static)
nat44_lb_addr_port_t * locals
clib_bihash_8_8_t user_hash
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
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
vl_api_ip_proto_t protocol
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
snat_get_worker_out2in_function_t * worker_out2in_cb
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
vl_api_interface_index_t sw_if_index
#define VLIB_INIT_FUNCTION(x)
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
void nat_syslog_nat44_apmdel(u32 ssubix, u32 sfibix, ip4_address_t *isaddr, u16 isport, ip4_address_t *xsaddr, u16 xsport, nat_protocol_t proto)
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
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)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Aggregate type for a prefix.
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
#define clib_error_return(e, args...)
#define is_fwd_bypass_session(s)
Check if NAT session is forwarding bypass.
static u32 snat_get_worker_in2out_cb(ip4_header_t *ip0, u32 rx_fib_index0, u8 is_output)
static void split_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)
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.
fib_source_t fib_source_allocate(const char *name, fib_source_priority_t prio, fib_source_behaviour_t bh)
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.
vl_api_fib_path_type_t type
int nat44_set_session_limit(u32 session_limit, u32 vrf_id)
Set NAT44 session limit (session limit, vrf id)
twice_nat_type_t twice_nat
static u32 snat_get_worker_out2in_cb(vlib_buffer_t *b, ip4_header_t *ip0, u32 rx_fib_index0, u8 is_output)
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)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
#define FIB_SOURCE_PRIORITY_HI
Some priority values that plugins might use when they are not to concerned where in the list they'll ...
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)
IPv4 shallow virtual reassembly.
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)
u32 pre_in2out_node_index
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.
static_always_inline int nat_ed_lru_insert(snat_main_per_thread_data_t *tsm, snat_session_t *s, f64 now, u8 proto)
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
static_always_inline snat_session_t * nat_ed_session_alloc(snat_main_t *sm, u32 thread_index, f64 now, u8 proto)
#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
void snat_ed_static_mapping_del_sessions(snat_main_t *sm, snat_main_per_thread_data_t *tsm, ip4_address_t l_addr, u16 l_port, u8 protocol, u32 fib_index, int addr_only, ip4_address_t e_addr, u16 e_port)
u32 pre_out2in_node_index
u32 ed_hairpin_src_node_index
#define pool_free(p)
Free a pool.
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
void nat64_set_hash(u32 bib_buckets, uword bib_memory_size, u32 st_buckets, uword st_memory_size)
Set NAT64 hash tables configuration.
static void nat44_delete_user_with_no_session(snat_main_t *sm, snat_user_t *u, u32 thread_index)
#define is_affinity_sessions(s)
Check if NAT session has affinity record.
#define VLIB_REGISTER_NODE(x,...)
#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 u32 random_u32_max(void)
Maximum value returned by random_u32()
static_always_inline uword vlib_get_thread_index(void)
fib_source_t nat_fib_src_low
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)
sll srl srl sll sra u16x4 i
u8 static_mapping_connection_tracking
#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)
#define nat_elog_notice_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
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
u32 ed_hairpin_dst_node_index
fib_source_t nat_fib_src_hi
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...
vlib_main_t vlib_node_runtime_t * node
u32 tcp_transitory_timeout
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
u32 * auto_add_sw_if_indices
u32 in2out_fast_node_index
void nat44_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 ED session data (lookup keys, external address port)
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)
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, nat_protocol_t proto, u8 is_twicenat)
#define NAT_INTERFACE_FLAG_IS_INSIDE
#define is_addr_only_static_mapping(sm)
Check if NAT static mapping is address only (1:1NAT).
manual_print typedef address
#define is_identity_static_mapping(sm)
Check if NAT static mapping is identity NAT.
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, nat_protocol_t proto, int addr_only, int is_add, u8 *tag, int twice_nat, int out2in_only, int identity_nat)
u32 det_out2in_node_index
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
void snat_ipfix_logging_nat44_ses_delete(u32 thread_index, u32 src_ip, u32 nat_src_ip, nat_protocol_t nat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session delete event.
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
#define FIB_SOURCE_PRIORITY_LOW
snat_address_t * twice_nat_addresses
#define VNET_FEATURES(...)
static vlib_main_t * vlib_get_main(void)
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.
NAT64 global declarations.
#define is_lb_static_mapping(sm)
Check if NAT static mapping is load-balancing.
u32 unk_proto_lru_head_index
char * stat_segment_name
Name in stat segment directory.
vlib_simple_counter_main_t total_users
#define nat_elog_err(nat_elog_str)
#define FIB_NODE_INDEX_INVALID
format_function_t format_static_mapping_key
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, nat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
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
u32 tcp_trans_lru_head_index
#define is_out2in_only_static_mapping(sm)
Check if NAT static mapping match only out2in direction.
static_always_inline u8 nat_proto_to_ip_proto(nat_protocol_t nat_proto)
VLIB buffer representation.
u32 tcp_estab_lru_head_index
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 interface.
u32 out2in_fast_node_index
static_always_inline int get_icmp_o2i_ed_key(vlib_buffer_t *b, ip4_header_t *ip0, u32 rx_fib_index, u64 value, u8 *nat_proto, u16 *l_port, u16 *r_port, clib_bihash_kv_16_8_t *kv)
#define hash_get_mem(h, key)
#define SNAT_ICMP_TIMEOUT
snat_get_worker_in2out_function_t * worker_in2out_cb
snat_static_map_resolve_t * to_resolve
static api_main_t * vlibapi_get_main(void)
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()
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, nat_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.
static u32 get_thread_idx_by_port(u16 e_port)
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)
f64 end
end of the time range
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, nat_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)
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)
static u32 nat44_ed_get_worker_in2out_cb(ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
#define pool_foreach_index(i, v, body)
Iterate pool by index.
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
snat_icmp_match_function_t * icmp_match_in2out_cb
static void make_ed_kv(ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port, u64 value, clib_bihash_kv_16_8_t *kv)
clib_bihash_8_8_t static_mapping_by_local
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)
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.