#include <vnet/fib/fib_table.h>
#include <nat/nat_ha.h>
+
+#define UNSUPPORTED_IN_DET_OR_ED_MODE_STR \
+ "This command is unsupported in deterministic or endpoint dependent mode"
+#define UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR \
+ "This command is unsupported in deterministic or non endpoint dependent mode"
#define UNSUPPORTED_IN_DET_MODE_STR \
"This command is unsupported in deterministic mode"
+#define SUPPORTED_ONLY_IN_ED_MODE_STR \
+ "This command is supported only in endpoint dependent mode"
#define SUPPORTED_ONLY_IN_DET_MODE_STR \
"This command is supported only in deterministic mode"
vlib_cli_output (vm, "%U",
format_bihash_8_8, &sm->static_mapping_by_external,
verbose);
+ vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->out2in_ed, verbose);
vec_foreach_index (i, sm->per_thread_data)
{
tsm = vec_elt_at_index (sm->per_thread_data, i);
{
vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
verbose);
- vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
- verbose);
}
else
{
{
vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
verbose);
- vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->ed_ext_ports, 0);
}
return 0;
}
if (unformat (line_input, "disable"))
sm->mss_clamping = 0;
else if (unformat (line_input, "%d", &mss))
- {
- sm->mss_clamping = (u16) mss;
- sm->mss_value_net = clib_host_to_net_u16 (sm->mss_clamping);
- }
+ sm->mss_clamping = (u16) mss;
else
{
error = clib_error_return (0, "unknown input '%U'",
snat_session_t *s;
if (sm->deterministic || !sm->endpoint_dependent)
- return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+ return clib_error_return (0, UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR);
- // print session configuration values
vlib_cli_output (vm, "max translations: %u", sm->max_translations);
vlib_cli_output (vm, "max translations per user: %u",
sm->max_translations_per_user);
u32 count = 0;
- u64 now = vlib_time_now (sm->vlib_main);
+ u64 now = vlib_time_now (vm);
u64 sess_timeout_time;
u32 udp_sessions = 0;
switch (s->in2out.protocol)
{
- case SNAT_PROTOCOL_ICMP:
+ case NAT_PROTOCOL_ICMP:
icmp_sessions++;
break;
- case SNAT_PROTOCOL_TCP:
+ case NAT_PROTOCOL_TCP:
tcp_sessions++;
if (s->state)
{
- if (s->tcp_close_timestamp)
+ if (s->tcp_closed_timestamp)
{
- if (now >= s->tcp_close_timestamp)
+ if (now >= s->tcp_closed_timestamp)
{
++transitory_closed;
}
else
established++;
break;
- case SNAT_PROTOCOL_UDP:
+ case NAT_PROTOCOL_UDP:
default:
udp_sessions++;
break;
switch (s->in2out.protocol)
{
- case SNAT_PROTOCOL_ICMP:
+ case NAT_PROTOCOL_ICMP:
icmp_sessions++;
break;
- case SNAT_PROTOCOL_TCP:
+ case NAT_PROTOCOL_TCP:
tcp_sessions++;
if (s->state)
{
- if (s->tcp_close_timestamp)
+ if (s->tcp_closed_timestamp)
{
- if (now >= s->tcp_close_timestamp)
+ if (now >= s->tcp_closed_timestamp)
{
++transitory_closed;
}
else
established++;
break;
- case SNAT_PROTOCOL_UDP:
+ case NAT_PROTOCOL_UDP:
default:
udp_sessions++;
break;
}));
/* *INDENT-ON* */
count = pool_elts (tsm->sessions);
+ if (sm->endpoint_dependent)
+ {
+ dlist_elt_t *oldest_elt;
+ u32 oldest_index;
+#define _(n, d) \
+ oldest_index = \
+ clib_dlist_remove_head (tsm->lru_pool, tsm->n##_lru_head_index); \
+ if (~0 != oldest_index) \
+ { \
+ oldest_elt = pool_elt_at_index (tsm->lru_pool, oldest_index); \
+ s = pool_elt_at_index (tsm->sessions, oldest_elt->value); \
+ sess_timeout_time = \
+ s->last_heard + (f64)nat44_session_get_timeout (sm, s); \
+ vlib_cli_output (vm, d " LRU min session timeout %llu (now %llu)", \
+ sess_timeout_time, now); \
+ clib_dlist_addhead (tsm->lru_pool, tsm->n##_lru_head_index, \
+ oldest_index); \
+ }
+ _(tcp_estab, "established tcp");
+ _(tcp_trans, "transitory tcp");
+ _(udp, "udp");
+ _(unk_proto, "unknown protocol");
+ _(icmp, "icmp");
+#undef _
+ }
}
vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
vlib_cli_output (vm, " tenant VRF independent");
#define _(N, i, n, s) \
vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
}
vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
vlib_cli_output (vm, " tenant VRF independent");
#define _(N, i, n, s) \
vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
}
/* *INDENT-ON* */
u32 sw_if_index = ~0;
vnet_main_t *vnm = vnet_get_main ();
int rv;
- snat_protocol_t proto = ~0;
+ nat_protocol_t proto = NAT_PROTOCOL_OTHER;
u8 proto_set = 0;
twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
u8 out2in_only = 0;
;
else if (unformat (line_input, "vrf %u", &vrf_id))
;
- else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
+ else if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
proto_set = 1;
else if (unformat (line_input, "twice-nat"))
twice_nat = TWICE_NAT;
goto done;
}
- if (!addr_only && !proto_set)
+ if (addr_only)
{
- error = clib_error_return (0, "missing protocol");
+ if (proto_set)
+ {
+ error =
+ clib_error_return (0,
+ "address only mapping doesn't support protocol");
+ goto done;
+ }
+ }
+ else if (!proto_set)
+ {
+ error = clib_error_return (0, "protocol is required");
goto done;
}
u32 sw_if_index = ~0;
vnet_main_t *vnm = vnet_get_main ();
int rv;
- snat_protocol_t proto;
+ nat_protocol_t proto;
if (sm->deterministic)
return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
;
else if (unformat (line_input, "vrf %u", &vrf_id))
;
- else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
+ else if (unformat (line_input, "%U %u", unformat_nat_protocol, &proto,
&port))
addr_only = 0;
else if (unformat (line_input, "del"))
u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
int is_add = 1;
int rv;
- snat_protocol_t proto;
+ nat_protocol_t proto;
u8 proto_set = 0;
nat44_lb_addr_port_t *locals = 0, local;
twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
&e_addr, &e_port))
;
- else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
+ else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
&proto))
proto_set = 1;
else if (unformat (line_input, "twice-nat"))
u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
int is_add = 1;
int rv;
- snat_protocol_t proto;
+ nat_protocol_t proto;
u8 proto_set = 0;
if (sm->deterministic)
else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
&e_addr, &e_port))
;
- else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
+ else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
&proto))
proto_set = 1;
else if (unformat (line_input, "del"))
{
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = 0;
- snat_main_t *sm = &snat_main;
+
snat_main_per_thread_data_t *tsm;
+ snat_main_t *sm = &snat_main;
- int detail = 0, metrics = 0;
- snat_user_t *u;
+ int detail = 0;
int i = 0;
if (sm->deterministic)
{
if (unformat (line_input, "detail"))
detail = 1;
- else if (unformat (line_input, "metrics"))
- metrics = 1;
else
{
error = clib_error_return (0, "unknown input '%U'",
unformat_free (line_input);
print:
- vlib_cli_output (vm, "NAT44 sessions:");
+ if (!sm->endpoint_dependent)
+ vlib_cli_output (vm, "NAT44 sessions:");
+ else
+ vlib_cli_output (vm, "NAT44 ED sessions:");
+
/* *INDENT-OFF* */
vec_foreach_index (i, sm->per_thread_data)
{
vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
i, vlib_worker_threads[i].name,
pool_elts (tsm->sessions));
- if (metrics)
+
+ if (!sm->endpoint_dependent)
{
- u64 now = vlib_time_now (sm->vlib_main);
+ snat_user_t *u;
pool_foreach (u, tsm->users,
({
- vlib_cli_output (vm, " %U", format_snat_user_v2, tsm, u, now);
+ vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
}));
}
else
{
- pool_foreach (u, tsm->users,
+ snat_session_t *s;
+ pool_foreach (s, tsm->sessions,
({
- vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
+ vlib_cli_output (vm, " %U\n", format_snat_session, tsm, s);
}));
}
}
return error;
}
+static clib_error_t *
+nat44_set_session_limit_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ snat_main_t *sm = &snat_main;
+ unformat_input_t _line_input, *line_input = &_line_input;
+ clib_error_t *error = 0;
+
+ u32 session_limit = 0, vrf_id = 0;
+
+ if (sm->deterministic)
+ return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "%u", &session_limit))
+ ;
+ else if (unformat (line_input, "vrf %u", &vrf_id))
+ ;
+ else
+ {
+ error = clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
+ }
+
+ if (!session_limit)
+ error = clib_error_return (0, "missing value of session limit");
+ else if (nat44_set_session_limit (session_limit, vrf_id))
+ error = clib_error_return (0, "nat44_set_session_limit failed");
+
+done:
+ unformat_free (line_input);
+
+ return error;
+}
+
static clib_error_t *
nat44_del_user_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
u32 fib_index = 0;
int rv;
- if (sm->deterministic)
- return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+ if (sm->deterministic || sm->endpoint_dependent)
+ return clib_error_return (0, UNSUPPORTED_IN_DET_OR_ED_MODE_STR);
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
return error;
}
+static clib_error_t *
+nat44_clear_sessions_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ snat_main_t *sm = &snat_main;
+ clib_error_t *error = 0;
+
+ if (sm->deterministic)
+ return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+
+ nat44_sessions_clear ();
+ return error;
+}
+
static clib_error_t *
nat44_del_session_command_fn (vlib_main_t * vm,
unformat_input_t * input,
clib_error_t *error = 0;
ip4_address_t addr, eh_addr;
u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
- snat_protocol_t proto;
+ nat_protocol_t proto;
int rv;
if (sm->deterministic)
{
if (unformat
(line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
- unformat_snat_protocol, &proto))
+ unformat_nat_protocol, &proto))
;
else if (unformat (line_input, "in"))
{
if (is_ed)
rv =
nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
- snat_proto_to_ip_proto (proto), vrf_id, is_in);
+ nat_proto_to_ip_proto (proto), vrf_id, is_in);
else
rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
* vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
* If not runnig "static mapping only" NAT plugin mode use before:
* vpp# nat44 add address 4.4.4.4
- * To create static mapping between local and external address use:
+ * To create address only static mapping between local and external address use:
* vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
+ * To create ICMP static mapping between local and external with ICMP echo
+ * identifier 10 use:
+ * vpp# nat44 add static mapping icmp local 10.0.0.3 10 external 4.4.4.4 10
* @cliexend
?*/
VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
.path = "nat44 add static mapping",
.function = add_static_mapping_command_fn,
.short_help =
- "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
- "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
+ "nat44 add static mapping tcp|udp|icmp local <addr> [<port|icmp-echo-id>] "
+ "external <addr> [<port|icmp-echo-id>] [vrf <table-id>] [twice-nat|self-twice-nat] "
"[out2in-only] [del]",
};
.function = nat44_show_sessions_command_fn,
};
+/*?
+ * @cliexpar
+ * @cliexstart{set nat44 session limit}
+ * Set NAT44 session limit.
+ * @cliexend
+?*/
+VLIB_CLI_COMMAND (nat44_set_session_limit_command, static) = {
+ .path = "set nat44 session limit",
+ .short_help = "set nat44 session limit <limit> [vrf <table-id>]",
+ .function = nat44_set_session_limit_command_fn,
+};
+
/*?
* @cliexpar
* @cliexstart{nat44 del user}
.function = nat44_del_user_command_fn,
};
+/*?
+ * @cliexpar
+ * @cliexstart{clear nat44 sessions}
+ * To clear all NAT44 sessions
+ * vpp# clear nat44 sessions
+ * @cliexend
+?*/
+VLIB_CLI_COMMAND (nat44_clear_sessions_command, static) = {
+ .path = "clear nat44 sessions",
+ .short_help = "clear nat44 sessions",
+ .function = nat44_clear_sessions_command_fn,
+};
+
/*?
* @cliexpar
* @cliexstart{nat44 del session}