X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat_format.c;h=3dfe6046969f1da5f7025af368d9937db31b9dce;hb=6c25154e9544810afc1179ce8b0977a9786a8027;hp=17f64b9b222a0c98e3c28dfefccc9ef2a443ec75;hpb=f126e746fc01c75bc99329d10ce9127b26b23814;p=vpp.git diff --git a/src/plugins/nat/nat_format.c b/src/plugins/nat/nat_format.c index 17f64b9b222..3dfe6046969 100644 --- a/src/plugins/nat/nat_format.c +++ b/src/plugins/nat/nat_format.c @@ -18,16 +18,16 @@ */ #include -#include +#include uword -unformat_snat_protocol (unformat_input_t * input, va_list * args) +unformat_nat_protocol (unformat_input_t * input, va_list * args) { u32 *r = va_arg (*args, u32 *); if (0); -#define _(N, i, n, s) else if (unformat (input, s)) *r = SNAT_PROTOCOL_##N; - foreach_snat_protocol +#define _(N, i, n, s) else if (unformat (input, s)) *r = NAT_PROTOCOL_##N; + foreach_nat_protocol #undef _ else return 0; @@ -35,15 +35,15 @@ unformat_snat_protocol (unformat_input_t * input, va_list * args) } u8 * -format_snat_protocol (u8 * s, va_list * args) +format_nat_protocol (u8 * s, va_list * args) { u32 i = va_arg (*args, u32); u8 *t = 0; switch (i) { -#define _(N, j, n, str) case SNAT_PROTOCOL_##N: t = (u8 *) str; break; - foreach_snat_protocol +#define _(N, j, n, str) case NAT_PROTOCOL_##N: t = (u8 *) str; break; + foreach_nat_protocol #undef _ default: s = format (s, "unknown"); @@ -75,23 +75,19 @@ format_nat_addr_and_port_alloc_alg (u8 * s, va_list * args) u8 * format_snat_key (u8 * s, va_list * args) { - snat_session_key_t *key = va_arg (*args, snat_session_key_t *); + u64 key = va_arg (*args, u64); - s = format (s, "%U proto %U port %d fib %d", - format_ip4_address, &key->addr, - format_snat_protocol, key->protocol, - clib_net_to_host_u16 (key->port), key->fib_index); - return s; -} + ip4_address_t addr; + u16 port; + nat_protocol_t protocol; + u32 fib_index; -u8 * -format_static_mapping_key (u8 * s, va_list * args) -{ - snat_session_key_t *key = va_arg (*args, snat_session_key_t *); + split_nat_key (key, &addr, &port, &fib_index, &protocol); s = format (s, "%U proto %U port %d fib %d", - format_ip4_address, &key->addr, - format_snat_protocol, key->protocol, key->port, key->fib_index); + format_ip4_address, &addr, + format_nat_protocol, protocol, + clib_net_to_host_u16 (port), fib_index); return s; } @@ -116,7 +112,7 @@ format_snat_session_state (u8 * s, va_list * args) u8 * format_snat_session (u8 * s, va_list * args) { - snat_main_per_thread_data_t *sm = + snat_main_per_thread_data_t *tsm = va_arg (*args, snat_main_per_thread_data_t *); snat_session_t *sess = va_arg (*args, snat_session_t *); @@ -125,14 +121,22 @@ format_snat_session (u8 * s, va_list * args) s = format (s, " i2o %U proto %u fib %u\n", format_ip4_address, &sess->in2out.addr, sess->in2out.port, sess->in2out.fib_index); - s = format (s, " o2i %U proto %u fib %u\n", + s = format (s, " o2i %U proto %u fib %u\n", format_ip4_address, &sess->out2in.addr, sess->out2in.port, sess->out2in.fib_index); } else { - s = format (s, " i2o %U\n", format_snat_key, &sess->in2out); - s = format (s, " o2i %U\n", format_snat_key, &sess->out2in); + s = format (s, " i2o %U proto %U port %d fib %d\n", + format_ip4_address, &sess->in2out.addr, + format_nat_protocol, sess->nat_proto, + clib_net_to_host_u16 (sess->in2out.port), + sess->in2out.fib_index); + s = format (s, " o2i %U proto %U port %d fib %d\n", + format_ip4_address, &sess->out2in.addr, + format_nat_protocol, sess->nat_proto, + clib_net_to_host_u16 (sess->out2in.port), + sess->out2in.fib_index); } if (is_ed_session (sess) || is_fwd_bypass_session (sess)) { @@ -152,7 +156,7 @@ format_snat_session (u8 * s, va_list * args) clib_net_to_host_u16 (sess->ext_host_port)); } } - s = format (s, " index %llu\n", sess - sm->sessions); + s = format (s, " index %llu\n", sess - tsm->sessions); s = format (s, " last heard %.2f\n", sess->last_heard); s = format (s, " total pkts %d, total bytes %lld\n", sess->total_pkts, sess->total_bytes); @@ -173,7 +177,7 @@ 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_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); @@ -191,20 +195,20 @@ 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); + s = format (s, " %U\n", format_snat_session, tsm, 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; } } @@ -225,7 +229,7 @@ format_snat_static_mapping (u8 * s, va_list * args) format_ip4_address, &m->local_addr); else s = format (s, "identity mapping %U %U:%d", - format_snat_protocol, m->proto, + format_nat_protocol, m->proto, format_ip4_address, &m->local_addr, m->local_port); /* *INDENT-OFF* */ @@ -251,7 +255,7 @@ format_snat_static_mapping (u8 * s, va_list * args) if (is_lb_static_mapping (m)) { s = format (s, "%U external %U:%d %s %s", - format_snat_protocol, m->proto, + format_nat_protocol, m->proto, format_ip4_address, &m->external_addr, m->external_port, m->twice_nat == TWICE_NAT ? "twice-nat" : m->twice_nat == TWICE_NAT_SELF ? "self-twice-nat" : "", @@ -269,7 +273,7 @@ format_snat_static_mapping (u8 * s, va_list * args) } else s = format (s, "%U local %U:%d external %U:%d vrf %d %s %s", - format_snat_protocol, m->proto, + format_nat_protocol, m->proto, format_ip4_address, &m->local_addr, m->local_port, format_ip4_address, &m->external_addr, m->external_port, m->vrf_id, @@ -292,7 +296,7 @@ format_snat_static_map_to_resolve (u8 * s, va_list * args) format_vnet_sw_if_index_name, vnm, m->sw_if_index, m->vrf_id); else s = format (s, "%U local %U:%d external %U:%d vrf %d", - format_snat_protocol, m->proto, + format_nat_protocol, m->proto, format_ip4_address, &m->l_addr, m->l_port, format_vnet_sw_if_index_name, vnm, m->sw_if_index, m->e_port, m->vrf_id); @@ -300,39 +304,6 @@ format_snat_static_map_to_resolve (u8 * s, va_list * args) return s; } -u8 * -format_det_map_ses (u8 * s, va_list * args) -{ - snat_det_map_t *det_map = va_arg (*args, snat_det_map_t *); - ip4_address_t in_addr, out_addr; - u32 in_offset, out_offset; - snat_det_session_t *ses = va_arg (*args, snat_det_session_t *); - u32 *i = va_arg (*args, u32 *); - - u32 user_index = *i / SNAT_DET_SES_PER_USER; - in_addr.as_u32 = - clib_host_to_net_u32 (clib_net_to_host_u32 (det_map->in_addr.as_u32) + - user_index); - in_offset = - clib_net_to_host_u32 (in_addr.as_u32) - - clib_net_to_host_u32 (det_map->in_addr.as_u32); - out_offset = in_offset / det_map->sharing_ratio; - out_addr.as_u32 = - clib_host_to_net_u32 (clib_net_to_host_u32 (det_map->out_addr.as_u32) + - out_offset); - s = - format (s, - "in %U:%d out %U:%d external host %U:%d state: %U expire: %d\n", - format_ip4_address, &in_addr, clib_net_to_host_u16 (ses->in_port), - format_ip4_address, &out_addr, - clib_net_to_host_u16 (ses->out.out_port), format_ip4_address, - &ses->out.ext_host_addr, - clib_net_to_host_u16 (ses->out.ext_host_port), - format_snat_session_state, ses->state, ses->expire); - - return s; -} - /* * fd.io coding-style-patch-verification: ON *