From e3621518046ad7f37ccf77c549a93375ab89da19 Mon Sep 17 00:00:00 2001 From: Klement Sekera Date: Tue, 19 May 2020 17:47:23 +0000 Subject: nat: more long read after short write optimization Replace whitespread (mis)use of snat_session_key_t by proper function arguments where applicable and inline functions to calculate hash keys instead of using structs for that. Make all hash tables use same network byte order port so that there is no longer a discrepancy between static mappings using host byte order while in2out/out2in tables using network byte order. Type: improvement Signed-off-by: Klement Sekera Change-Id: I80786d2f947c67824c101a13bb608f1fe1080f34 --- src/plugins/nat/nat44_cli.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/plugins/nat/nat44_cli.c') diff --git a/src/plugins/nat/nat44_cli.c b/src/plugins/nat/nat44_cli.c index 68ed0cb7207..ffc5fd43618 100644 --- a/src/plugins/nat/nat44_cli.c +++ b/src/plugins/nat/nat44_cli.c @@ -674,7 +674,7 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input, if (now >= sess_timeout_time) timed_out++; - switch (s->in2out.protocol) + switch (s->nat_proto) { case NAT_PROTOCOL_ICMP: icmp_sessions++; @@ -720,7 +720,7 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input, if (now >= sess_timeout_time) timed_out++; - switch (s->in2out.protocol) + switch (s->nat_proto) { case NAT_PROTOCOL_ICMP: icmp_sessions++; @@ -1071,7 +1071,8 @@ add_static_mapping_command_fn (vlib_main_t * vm, goto done; } - rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port, + rv = snat_add_static_mapping (l_addr, e_addr, clib_host_to_net_u16 (l_port), + clib_host_to_net_u16 (e_port), vrf_id, addr_only, sw_if_index, proto, is_add, twice_nat, out2in_only, 0, 0); @@ -1155,9 +1156,10 @@ add_identity_mapping_command_fn (vlib_main_t * vm, } } - rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port, - vrf_id, addr_only, sw_if_index, proto, is_add, - 0, 0, 0, 1); + rv = + snat_add_static_mapping (addr, addr, clib_host_to_net_u16 (port), + clib_host_to_net_u16 (port), vrf_id, addr_only, + sw_if_index, proto, is_add, 0, 0, 0, 1); switch (rv) { @@ -1730,10 +1732,13 @@ nat44_del_session_command_fn (vlib_main_t * vm, if (is_ed) rv = - nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port, + nat44_del_ed_session (sm, &addr, clib_host_to_net_u16 (port), &eh_addr, + clib_host_to_net_u16 (eh_port), nat_proto_to_ip_proto (proto), vrf_id, is_in); else - rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in); + rv = + nat44_del_session (sm, &addr, clib_host_to_net_u16 (port), proto, + vrf_id, is_in); switch (rv) { -- cgit 1.2.3-korg