nat: fix per thread data vlib_main_t usage
[vpp.git] / src / plugins / nat / in2out.c
index 8d6f124..d5bd9f5 100755 (executable)
@@ -264,9 +264,6 @@ slow_path (snat_main_t * sm, vlib_buffer_t * b0,
   };
   nat44_is_idle_session_ctx_t ctx0;
 
-  nat44_session_try_cleanup (&ip0->src_address, rx_fib_index0, thread_index,
-                            now);
-
   if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
     {
       b0->error = node->errors[SNAT_IN2OUT_ERROR_MAX_SESSIONS_EXCEEDED];
@@ -449,6 +446,7 @@ static_always_inline
  * @param[in,out] node           NAT node runtime
  * @param[in] thread_index       thread index
  * @param[in,out] b0             buffer containing packet to be translated
+ * @param[in,out] ip0            ip header
  * @param[out] p_proto           protocol used for matching
  * @param[out] p_value           address and port after NAT translation
  * @param[out] p_dont_translate  if packet should not be translated
@@ -462,6 +460,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
                        snat_session_key_t * p_value,
                        u8 * p_dont_translate, void *d, void *e)
 {
+  snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
   u32 sw_if_index0;
   u32 rx_fib_index0;
   snat_session_key_t key0;
@@ -485,8 +484,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
 
   kv0.key = key0.as_u64;
 
-  if (clib_bihash_search_8_8 (&sm->per_thread_data[thread_index].in2out, &kv0,
-                             &value0))
+  if (clib_bihash_search_8_8 (&tsm->in2out, &kv0, &value0))
     {
       if (vnet_buffer (b0)->sw_if_index[VLIB_TX] != ~0)
        {
@@ -523,7 +521,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
        }
 
       next0 = slow_path (sm, b0, ip0, rx_fib_index0, &key0, &s0, node, next0,
-                        thread_index, vlib_time_now (sm->vlib_main));
+                        thread_index, vlib_time_now (tsm->vlib_main));
 
       if (PREDICT_FALSE (next0 == SNAT_IN2OUT_NEXT_DROP))
        goto out;
@@ -549,8 +547,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
          goto out;
        }
 
-      s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
-                             value0.value);
+      s0 = pool_elt_at_index (tsm->sessions, value0.value);
     }
 
 out:
@@ -572,6 +569,7 @@ out:
  * @param[in,out] node           NAT node runtime
  * @param[in] thread_index       thread index
  * @param[in,out] b0             buffer containing packet to be translated
+ * @param[in,out] ip0            ip header
  * @param[out] p_proto           protocol used for matching
  * @param[out] p_value           address and port after NAT translation
  * @param[out] p_dont_translate  if packet should not be translated
@@ -661,6 +659,7 @@ icmp_in2out (snat_main_t * sm,
             vlib_node_runtime_t * node,
             u32 next0, u32 thread_index, void *d, void *e)
 {
+  snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
   snat_session_key_t sm0;
   u8 protocol;
   icmp_echo_header_t *echo0, *inner_echo0 = 0;
@@ -687,11 +686,12 @@ icmp_in2out (snat_main_t * sm,
 
   if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
     {
-      sum0 = ip_incremental_checksum_buffer (sm->vlib_main, b0, (u8 *) icmp0 -
-                                            (u8 *)
-                                            vlib_buffer_get_current (b0),
-                                            ntohs (ip0->length) -
-                                            ip4_header_bytes (ip0), 0);
+      sum0 =
+       ip_incremental_checksum_buffer (tsm->vlib_main, b0,
+                                       (u8 *) icmp0 -
+                                       (u8 *) vlib_buffer_get_current (b0),
+                                       ntohs (ip0->length) -
+                                       ip4_header_bytes (ip0), 0);
       checksum0 = ~ip_csum_fold (sum0);
       if (PREDICT_FALSE (checksum0 != 0 && checksum0 != 0xffff))
        {
@@ -819,6 +819,7 @@ icmp_in2out_slow_path (snat_main_t * sm,
                       u32 next0,
                       f64 now, u32 thread_index, snat_session_t ** p_s0)
 {
+  snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
   next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
                       next0, thread_index, p_s0, 0);
   snat_session_t *s0 = *p_s0;
@@ -827,7 +828,7 @@ icmp_in2out_slow_path (snat_main_t * sm,
       /* Accounting */
       nat44_session_update_counters (s0, now,
                                     vlib_buffer_length_in_chain
-                                    (sm->vlib_main, b0), thread_index);
+                                    (tsm->vlib_main, b0), thread_index);
       /* Per-user LRU list maintenance */
       nat44_session_update_lru (sm, s0, thread_index);
     }
@@ -1043,11 +1044,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                       * be able to use dhcp client on the outside interface
                       */
                      if (PREDICT_FALSE
-                         ((b0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)
-                          && proto0 == SNAT_PROTOCOL_UDP
+                         (proto0 == SNAT_PROTOCOL_UDP
                           && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
                               clib_host_to_net_u16
-                              (UDP_DST_PORT_dhcp_to_server))))
+                              (UDP_DST_PORT_dhcp_to_server))
+                          && ip0->dst_address.as_u32 == 0xffffffff))
                        goto trace00;
                    }
                  else
@@ -1251,11 +1252,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                       * be able to use dhcp client on the outside interface
                       */
                      if (PREDICT_FALSE
-                         ((b1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)
-                          && proto1 == SNAT_PROTOCOL_UDP
+                         (proto1 == SNAT_PROTOCOL_UDP
                           && (vnet_buffer (b1)->ip.reass.l4_dst_port ==
                               clib_host_to_net_u16
-                              (UDP_DST_PORT_dhcp_to_server))))
+                              (UDP_DST_PORT_dhcp_to_server))
+                          && ip1->dst_address.as_u32 == 0xffffffff))
                        goto trace01;
                    }
                  else
@@ -1492,11 +1493,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                       * be able to use dhcp client on the outside interface
                       */
                      if (PREDICT_FALSE
-                         ((b0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)
-                          && proto0 == SNAT_PROTOCOL_UDP
+                         (proto0 == SNAT_PROTOCOL_UDP
                           && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
                               clib_host_to_net_u16
-                              (UDP_DST_PORT_dhcp_to_server))))
+                              (UDP_DST_PORT_dhcp_to_server))
+                          && ip0->dst_address.as_u32 == 0xffffffff))
                        goto trace0;
                    }
                  else