diff options
author | Klement Sekera <ksekera@cisco.com> | 2020-05-11 08:58:05 +0000 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2020-05-13 11:36:42 +0000 |
commit | bc752e432ff3e252f6e1a3f0372c9532f14909cd (patch) | |
tree | 5399347c1e469d21529a0bc20ffd2d0783434e40 /src/plugins/nat/nat_format.c | |
parent | 1d61c2194d21df2003ff07ff5feae4130de6277e (diff) |
nat: perf improvement - replace branchy code
Use a lookup table instead.
Type: improvement
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: Ia8461099828bb8824bf016201f135e6b69c444d1
Diffstat (limited to 'src/plugins/nat/nat_format.c')
-rw-r--r-- | src/plugins/nat/nat_format.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/plugins/nat/nat_format.c b/src/plugins/nat/nat_format.c index b9241545096..33e9655dc4e 100644 --- a/src/plugins/nat/nat_format.c +++ b/src/plugins/nat/nat_format.c @@ -22,13 +22,13 @@ #include <nat/nat_det.h> 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; @@ -36,15 +36,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"); @@ -80,7 +80,7 @@ format_snat_key (u8 * s, va_list * args) s = format (s, "%U proto %U port %d fib %d", format_ip4_address, &key->addr, - format_snat_protocol, key->protocol, + format_nat_protocol, key->protocol, clib_net_to_host_u16 (key->port), key->fib_index); return s; } @@ -92,7 +92,7 @@ format_static_mapping_key (u8 * s, va_list * args) 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_nat_protocol, key->protocol, key->port, key->fib_index); return s; } @@ -226,7 +226,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* */ @@ -252,7 +252,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" : "", @@ -270,7 +270,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, @@ -293,7 +293,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); |