X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat_format.c;h=71bdaa6662c8ada665b57199a181a3ad64107216;hb=e5d34919b;hp=a4b62b6e97736b015bad694afaa3963b73e16a23;hpb=e2f4e2f175beb6d6490d275049199db7dd61c783;p=vpp.git diff --git a/src/plugins/nat/nat_format.c b/src/plugins/nat/nat_format.c index a4b62b6e977..71bdaa6662c 100644 --- a/src/plugins/nat/nat_format.c +++ b/src/plugins/nat/nat_format.c @@ -18,6 +18,7 @@ */ #include +#include #include uword @@ -124,12 +125,10 @@ format_snat_session (u8 * s, va_list * args) { s = format (s, " i2o %U proto %u fib %u\n", format_ip4_address, &sess->in2out.addr, - clib_net_to_host_u16 (sess->in2out.port), - sess->in2out.fib_index); + sess->in2out.port, sess->in2out.fib_index); s = format (s, " o2i %U proto %u fib %u\n", format_ip4_address, &sess->out2in.addr, - clib_net_to_host_u16 (sess->out2in.port), - sess->out2in.fib_index); + sess->out2in.port, sess->out2in.fib_index); } else { @@ -175,7 +174,9 @@ format_snat_session (u8 * s, va_list * args) u8 * format_snat_user (u8 * s, va_list * args) { - snat_main_per_thread_data_t *sm = + + snat_main_t *sm = &snat_main; + snat_main_per_thread_data_t *tsm = va_arg (*args, snat_main_per_thread_data_t *); snat_user_t *u = va_arg (*args, snat_user_t *); int verbose = va_arg (*args, int); @@ -193,24 +194,102 @@ format_snat_user (u8 * s, va_list * args) if (u->nsessions || u->nstaticsessions) { head_index = u->sessions_per_user_list_head_index; - head = pool_elt_at_index (sm->list_pool, head_index); + head = pool_elt_at_index (tsm->list_pool, head_index); elt_index = head->next; - elt = pool_elt_at_index (sm->list_pool, elt_index); + elt = pool_elt_at_index (tsm->list_pool, elt_index); session_index = elt->value; while (session_index != ~0) { - sess = pool_elt_at_index (sm->sessions, session_index); + sess = pool_elt_at_index (tsm->sessions, session_index); s = format (s, " %U\n", format_snat_session, sm, sess); elt_index = elt->next; - elt = pool_elt_at_index (sm->list_pool, elt_index); + elt = pool_elt_at_index (tsm->list_pool, elt_index); + session_index = elt->value; + } + } + + return s; +} + +u8 * +format_snat_user_v2 (u8 * s, va_list * args) +{ + + snat_main_t *sm = &snat_main; + snat_main_per_thread_data_t *tsm = + va_arg (*args, snat_main_per_thread_data_t *); + snat_user_t *u = va_arg (*args, snat_user_t *); + u64 now = va_arg (*args, u64); + + dlist_elt_t *head, *elt; + u32 elt_index, head_index; + u32 session_index; + snat_session_t *sess; + + u32 udp_sessions = 0; + u32 tcp_sessions = 0; + u32 icmp_sessions = 0; + + u32 timed_out = 0; + u32 transitory = 0; + u32 established = 0; + + u64 sess_timeout_time; + + if (u->nsessions || u->nstaticsessions) + { + head_index = u->sessions_per_user_list_head_index; + head = pool_elt_at_index (tsm->list_pool, head_index); + + elt_index = head->next; + elt = pool_elt_at_index (tsm->list_pool, elt_index); + session_index = elt->value; + + while (session_index != ~0) + { + sess = pool_elt_at_index (tsm->sessions, session_index); + + sess_timeout_time = sess->last_heard + + (f64) nat44_session_get_timeout (sm, sess); + if (now >= sess_timeout_time) + timed_out++; + + switch (sess->in2out.protocol) + { + case SNAT_PROTOCOL_ICMP: + icmp_sessions++; + break; + case SNAT_PROTOCOL_TCP: + tcp_sessions++; + if (sess->state) + transitory++; + else + established++; + break; + case SNAT_PROTOCOL_UDP: + default: + udp_sessions++; + break; + + } + + elt_index = elt->next; + elt = pool_elt_at_index (tsm->list_pool, elt_index); session_index = elt->value; } } + s = format (s, "%U: %d dynamic translations, %d static translations\n", + format_ip4_address, &u->addr, u->nsessions, u->nstaticsessions); + s = format (s, "\t%u timed out, %u transitory, %u established\n", + timed_out, transitory, established); + s = format (s, "\t%u tcp sessions, %u udp sessions, %u icmp sessions\n", + tcp_sessions, udp_sessions, icmp_sessions); + return s; } @@ -220,6 +299,26 @@ format_snat_static_mapping (u8 * s, va_list * args) snat_static_mapping_t *m = va_arg (*args, snat_static_mapping_t *); nat44_lb_addr_port_t *local; + if (is_identity_static_mapping (m)) + { + if (is_addr_only_static_mapping (m)) + s = format (s, "identity mapping %U", + format_ip4_address, &m->local_addr); + else + s = format (s, "identity mapping %U %U:%d", + format_snat_protocol, m->proto, + format_ip4_address, &m->local_addr, m->local_port); + + /* *INDENT-OFF* */ + pool_foreach (local, m->locals, + ({ + s = format (s, " vrf %d", local->vrf_id); + })); + /* *INDENT-ON* */ + + return s; + } + if (is_addr_only_static_mapping (m)) s = format (s, "local %U external %U vrf %d %s %s", format_ip4_address, &m->local_addr, @@ -230,7 +329,7 @@ format_snat_static_mapping (u8 * s, va_list * args) is_out2in_only_static_mapping (m) ? "out2in-only" : ""); else { - if (vec_len (m->locals)) + if (is_lb_static_mapping (m)) { s = format (s, "%U external %U:%d %s %s", format_snat_protocol, m->proto, @@ -238,10 +337,16 @@ format_snat_static_mapping (u8 * s, va_list * args) m->twice_nat == TWICE_NAT ? "twice-nat" : m->twice_nat == TWICE_NAT_SELF ? "self-twice-nat" : "", is_out2in_only_static_mapping (m) ? "out2in-only" : ""); - vec_foreach (local, m->locals) + + /* *INDENT-OFF* */ + pool_foreach (local, m->locals, + ({ s = format (s, "\n local %U:%d vrf %d probability %d\%", format_ip4_address, &local->addr, local->port, local->vrf_id, local->probability); + })); + /* *INDENT-ON* */ + } else s = format (s, "%U local %U:%d external %U:%d vrf %d %s %s", @@ -309,20 +414,6 @@ format_det_map_ses (u8 * s, va_list * args) return s; } -u8 * -format_nat44_reass_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - nat44_reass_trace_t *t = va_arg (*args, nat44_reass_trace_t *); - - s = format (s, "NAT44_REASS: sw_if_index %d, next index %d, status %s", - t->sw_if_index, t->next_index, - t->cached ? "cached" : "translated"); - - return s; -} - /* * fd.io coding-style-patch-verification: ON *