summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_api.c
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-05-19 17:47:23 +0000
committerOle Trøan <otroan@employees.org>2020-06-08 13:46:35 +0000
commite3621518046ad7f37ccf77c549a93375ab89da19 (patch)
treeaab4446172fe661f3a2eaa58c1fc4cc1d209219b /src/plugins/nat/nat_api.c
parentc1f0d9c105c25c67d9ef86a53c10d43d40b61fe0 (diff)
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 <ksekera@cisco.com> Change-Id: I80786d2f947c67824c101a13bb608f1fe1080f34
Diffstat (limited to 'src/plugins/nat/nat_api.c')
-rw-r--r--src/plugins/nat/nat_api.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c
index abd1d867c47..9d1ed1bd9a9 100644
--- a/src/plugins/nat/nat_api.c
+++ b/src/plugins/nat/nat_api.c
@@ -1110,8 +1110,8 @@ static void
if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
{
- local_port = clib_net_to_host_u16 (mp->local_port);
- external_port = clib_net_to_host_u16 (mp->external_port);
+ local_port = mp->local_port;
+ external_port = mp->external_port;
}
vrf_id = clib_net_to_host_u32 (mp->vrf_id);
@@ -1201,8 +1201,8 @@ send_nat44_static_mapping_details (snat_static_mapping_t * m,
else
{
rmp->protocol = nat_proto_to_ip_proto (m->proto);
- rmp->external_port = htons (m->external_port);
- rmp->local_port = htons (m->local_port);
+ rmp->external_port = m->external_port;
+ rmp->local_port = m->local_port;
}
if (m->tag)
@@ -1238,8 +1238,8 @@ send_nat44_static_map_resolve_details (snat_static_map_resolve_t * m,
else
{
rmp->protocol = nat_proto_to_ip_proto (m->proto);
- rmp->external_port = htons (m->e_port);
- rmp->local_port = htons (m->l_port);
+ rmp->external_port = m->e_port;
+ rmp->local_port = m->l_port;
}
if (m->tag)
strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
@@ -1312,7 +1312,7 @@ static void
if (!(mp->flags & NAT_API_IS_ADDR_ONLY))
{
- port = clib_net_to_host_u16 (mp->port);
+ port = mp->port;
proto = ip_proto_to_nat_proto (mp->protocol);
}
vrf_id = clib_net_to_host_u32 (mp->vrf_id);
@@ -1374,7 +1374,7 @@ send_nat44_identity_mapping_details (snat_static_mapping_t * m, int index,
rmp->flags |= NAT_API_IS_ADDR_ONLY;
clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
- rmp->port = htons (m->local_port);
+ rmp->port = m->local_port;
rmp->sw_if_index = ~0;
rmp->vrf_id = htonl (local->vrf_id);
rmp->protocol = nat_proto_to_ip_proto (m->proto);
@@ -1401,7 +1401,7 @@ send_nat44_identity_map_resolve_details (snat_static_map_resolve_t * m,
if (m->addr_only)
rmp->flags = (vl_api_nat_config_flags_t) NAT_API_IS_ADDR_ONLY;
- rmp->port = htons (m->l_port);
+ rmp->port = m->l_port;
rmp->sw_if_index = htonl (m->sw_if_index);
rmp->vrf_id = htonl (m->vrf_id);
rmp->protocol = nat_proto_to_ip_proto (m->proto);
@@ -1719,7 +1719,7 @@ send_nat44_user_session_details (snat_session_t * s,
{
rmp->outside_port = s->out2in.port;
rmp->inside_port = s->in2out.port;
- rmp->protocol = ntohs (nat_proto_to_ip_proto (s->in2out.protocol));
+ rmp->protocol = ntohs (nat_proto_to_ip_proto (s->nat_proto));
}
if (is_ed_session (s) || is_fwd_bypass_session (s))
{
@@ -1831,7 +1831,7 @@ unformat_nat44_lb_addr_port (vl_api_nat44_lb_addr_port_t * addr_port_pairs,
ap = &addr_port_pairs[i];
clib_memset (&lb_addr_port, 0, sizeof (lb_addr_port));
clib_memcpy (&lb_addr_port.addr, ap->addr, 4);
- lb_addr_port.port = clib_net_to_host_u16 (ap->port);
+ lb_addr_port.port = ap->port;
lb_addr_port.probability = ap->probability;
lb_addr_port.vrf_id = clib_net_to_host_u32 (ap->vrf_id);
vec_add1 (lb_addr_port_pairs, lb_addr_port);
@@ -1875,7 +1875,7 @@ static void
rv =
nat44_add_del_lb_static_mapping (e_addr,
- clib_net_to_host_u16 (mp->external_port),
+ mp->external_port,
proto, locals, mp->is_add,
twice_nat,
mp->flags & NAT_API_IS_OUT2IN_ONLY, tag,
@@ -1968,7 +1968,7 @@ send_nat44_lb_static_mapping_details (snat_static_mapping_t * m,
ntohs (VL_API_NAT44_LB_STATIC_MAPPING_DETAILS + sm->msg_id_base);
clib_memcpy (rmp->external_addr, &(m->external_addr), 4);
- rmp->external_port = ntohs (m->external_port);
+ rmp->external_port = m->external_port;
rmp->protocol = nat_proto_to_ip_proto (m->proto);
rmp->context = context;
@@ -1986,7 +1986,7 @@ send_nat44_lb_static_mapping_details (snat_static_mapping_t * m,
pool_foreach (ap, m->locals,
({
clib_memcpy (locals->addr, &(ap->addr), 4);
- locals->port = htons (ap->port);
+ locals->port = ap->port;
locals->probability = ap->probability;
locals->vrf_id = ntohl (ap->vrf_id);
locals++;
@@ -2051,11 +2051,11 @@ vl_api_nat44_del_session_t_handler (vl_api_nat44_del_session_t * mp)
}
memcpy (&addr.as_u8, mp->address, 4);
- port = clib_net_to_host_u16 (mp->port);
+ port = mp->port;
vrf_id = clib_net_to_host_u32 (mp->vrf_id);
proto = ip_proto_to_nat_proto (mp->protocol);
memcpy (&eh_addr.as_u8, mp->ext_host_address, 4);
- eh_port = clib_net_to_host_u16 (mp->ext_host_port);
+ eh_port = mp->ext_host_port;
is_in = mp->flags & NAT_API_IS_INSIDE;