X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fmap%2Fip4_map.c;h=6a3bdd51f4426fe1804b5e086f43181940b45319;hb=1c7104514cd40d2377caca36cf40c13b791bc5aa;hp=2be9ad37e7219f4762866698e21d797a5681437a;hpb=8082380922c65702251d5242058f7b5f35011574;p=vpp.git diff --git a/src/vnet/map/ip4_map.c b/src/vnet/map/ip4_map.c index 2be9ad37e72..6a3bdd51f44 100644 --- a/src/vnet/map/ip4_map.c +++ b/src/vnet/map/ip4_map.c @@ -19,6 +19,7 @@ #include "map.h" #include "../ip/ip_frag.h" +#include vlib_node_registration_t ip4_map_reass_node; @@ -62,52 +63,6 @@ format_ip4_map_reass_trace (u8 * s, va_list * args) t->cached ? "cached" : "forwarded"); } -/* - * ip4_map_get_port - */ -u16 -ip4_map_get_port (ip4_header_t * ip, map_dir_e dir) -{ - /* Find port information */ - if (PREDICT_TRUE ((ip->protocol == IP_PROTOCOL_TCP) || - (ip->protocol == IP_PROTOCOL_UDP))) - { - udp_header_t *udp = (void *) (ip + 1); - return (dir == MAP_SENDER ? udp->src_port : udp->dst_port); - } - else if (ip->protocol == IP_PROTOCOL_ICMP) - { - /* - * 1) ICMP Echo request or Echo reply - * 2) ICMP Error with inner packet being UDP or TCP - * 3) ICMP Error with inner packet being ICMP Echo request or Echo reply - */ - icmp46_header_t *icmp = (void *) (ip + 1); - if (icmp->type == ICMP4_echo_request || icmp->type == ICMP4_echo_reply) - { - return *((u16 *) (icmp + 1)); - } - else if (clib_net_to_host_u16 (ip->length) >= 56) - { // IP + ICMP + IP + L4 header - ip4_header_t *icmp_ip = (ip4_header_t *) (icmp + 2); - if (PREDICT_TRUE ((icmp_ip->protocol == IP_PROTOCOL_TCP) || - (icmp_ip->protocol == IP_PROTOCOL_UDP))) - { - udp_header_t *udp = (void *) (icmp_ip + 1); - return (dir == MAP_SENDER ? udp->dst_port : udp->src_port); - } - else if (icmp_ip->protocol == IP_PROTOCOL_ICMP) - { - icmp46_header_t *inner_icmp = (void *) (icmp_ip + 1); - if (inner_icmp->type == ICMP4_echo_request - || inner_icmp->type == ICMP4_echo_reply) - return (*((u16 *) (inner_icmp + 1))); - } - } - } - return (0); -} - static_always_inline u16 ip4_map_port_and_security_check (map_domain_t * d, ip4_header_t * ip, u32 * next, u8 * error) @@ -124,7 +79,7 @@ ip4_map_port_and_security_check (map_domain_t * d, ip4_header_t * ip, { return 0; } - port = ip4_map_get_port (ip, MAP_RECEIVER); + port = ip4_get_port (ip, 0); if (port) { /* Verify that port is not among the well-known ports */ @@ -248,7 +203,7 @@ ip4_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) next_index = node->cached_next_index; map_main_t *mm = &map_main; vlib_combined_counter_main_t *cm = mm->domain_counters; - u32 cpu_index = os_get_cpu_number (); + u32 thread_index = vlib_get_thread_index (); while (n_left_from > 0) { @@ -293,12 +248,10 @@ ip4_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) p1 = vlib_get_buffer (vm, pi1); ip40 = vlib_buffer_get_current (p0); ip41 = vlib_buffer_get_current (p1); - d0 = - ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX], - &map_domain_index0); - d1 = - ip4_map_get_domain (vnet_buffer (p1)->ip.adj_index[VLIB_TX], - &map_domain_index1); + map_domain_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; + d0 = ip4_map_get_domain (map_domain_index0); + map_domain_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX]; + d1 = ip4_map_get_domain (map_domain_index1); ASSERT (d0); ASSERT (d1); @@ -379,7 +332,7 @@ ip4_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) ip40) ? IP4_MAP_NEXT_IP6_REWRITE : next0; vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_TX, - cpu_index, + thread_index, map_domain_index0, 1, clib_net_to_host_u16 (ip6h0->payload_length) + @@ -411,7 +364,7 @@ ip4_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) ip41) ? IP4_MAP_NEXT_IP6_REWRITE : next1; vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_TX, - cpu_index, + thread_index, map_domain_index1, 1, clib_net_to_host_u16 (ip6h1->payload_length) + @@ -464,9 +417,8 @@ ip4_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) p0 = vlib_get_buffer (vm, pi0); ip40 = vlib_buffer_get_current (p0); - d0 = - ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX], - &map_domain_index0); + map_domain_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; + d0 = ip4_map_get_domain (map_domain_index0); ASSERT (d0); /* @@ -523,7 +475,7 @@ ip4_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) ip40) ? IP4_MAP_NEXT_IP6_REWRITE : next0; vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_TX, - cpu_index, + thread_index, map_domain_index0, 1, clib_net_to_host_u16 (ip6h0->payload_length) + @@ -567,7 +519,7 @@ ip4_map_reass (vlib_main_t * vm, next_index = node->cached_next_index; map_main_t *mm = &map_main; vlib_combined_counter_main_t *cm = mm->domain_counters; - u32 cpu_index = os_get_cpu_number (); + u32 thread_index = vlib_get_thread_index (); u32 *fragments_to_drop = NULL; u32 *fragments_to_loopback = NULL; @@ -597,9 +549,8 @@ ip4_map_reass (vlib_main_t * vm, p0 = vlib_get_buffer (vm, pi0); ip60 = vlib_buffer_get_current (p0); ip40 = (ip4_header_t *) (ip60 + 1); - d0 = - ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX], - &map_domain_index0); + map_domain_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; + d0 = ip4_map_get_domain (map_domain_index0); map_ip4_reass_lock (); map_ip4_reass_t *r = map_ip4_reass_get (ip40->src_address.as_u32, @@ -630,9 +581,7 @@ ip4_map_reass (vlib_main_t * vm, cached = 1; } } - else - if ((port0 = - ip4_get_port (ip40, MAP_RECEIVER, p0->current_length)) < 0) + else if ((port0 = ip4_get_port (ip40, 0)) == 0) { // Could not find port. We'll free the reassembly. error0 = MAP_ERROR_BAD_PROTOCOL; @@ -698,8 +647,8 @@ ip4_map_reass (vlib_main_t * vm, { if (error0 == MAP_ERROR_NONE) vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_TX, - cpu_index, map_domain_index0, - 1, + thread_index, + map_domain_index0, 1, clib_net_to_host_u16 (ip60->payload_length) + 40); next0 =