nat: ICMP handling fixes
[vpp.git] / src / plugins / nat / nat44-ed / nat44_ed.h
index 902e5e3..420f84c 100644 (file)
@@ -28,6 +28,7 @@
 #include <vppinfra/elog.h>
 #include <vppinfra/bihash_8_8.h>
 #include <vppinfra/bihash_16_8.h>
+#include <vppinfra/hash.h>
 #include <vppinfra/dlist.h>
 #include <vppinfra/error.h>
 #include <vlibapi/api.h>
@@ -190,7 +191,6 @@ typedef enum
 #define NAT_STATIC_MAPPING_FLAG_LB             8
 #define NAT_STATIC_MAPPING_FLAG_EXACT_ADDRESS  16
 
-/* *INDENT-OFF* */
 typedef CLIB_PACKED(struct
 {
   // number of sessions in this vrf
@@ -202,7 +202,6 @@ typedef CLIB_PACKED(struct
   // is this vrf expired
   u8 expired;
 }) per_vrf_sessions_t;
-/* *INDENT-ON* */
 
 typedef union
 {
@@ -287,7 +286,6 @@ nat_6t_flow_icmp_id_rewrite_set (nat_6t_flow_t *f, u16 id)
   f->rewrite.icmp_id = id;
 }
 
-/* *INDENT-OFF* */
 typedef CLIB_PACKED(struct
 {
   /* Outside network tuple */
@@ -347,21 +345,19 @@ typedef CLIB_PACKED(struct
   /* per vrf sessions index */
   u32 per_vrf_sessions_index;
 
+  u32 thread_index;
 }) snat_session_t;
-/* *INDENT-ON* */
 
 typedef struct
 {
   ip4_address_t addr;
   u32 fib_index;
-/* *INDENT-OFF* */
 #define _(N, i, n, s) \
   u32 busy_##n##_ports; \
   u32 * busy_##n##_ports_per_thread; \
   u32 busy_##n##_port_refcounts[65535];
   foreach_nat_protocol
 #undef _
-/* *INDENT-ON* */
 } snat_address_t;
 
 typedef struct
@@ -495,16 +491,12 @@ typedef struct
 
 struct snat_main_s;
 
-/* Return worker thread index for given packet */
-typedef u32 (snat_get_worker_in2out_function_t) (ip4_header_t * ip,
-                                                u32 rx_fib_index,
-                                                u8 is_output);
-
-typedef u32 (snat_get_worker_out2in_function_t) (vlib_buffer_t * b,
-                                                ip4_header_t * ip,
-                                                u32 rx_fib_index,
-                                                u8 is_output);
+u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
+                                     u32 rx_fib_index, u8 is_output);
+u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
+                                     u32 rx_fib_index, u8 is_output);
 
+/* Return worker thread index for given packet */
 /* NAT address and port allocation function */
 typedef int (nat_alloc_out_addr_and_port_function_t) (snat_address_t *
                                                      addresses,
@@ -522,8 +514,6 @@ typedef struct snat_main_s
   u32 num_workers;
   u32 first_worker_index;
   u32 *workers;
-  snat_get_worker_in2out_function_t *worker_in2out_cb;
-  snat_get_worker_out2in_function_t *worker_out2in_cb;
   u16 port_per_thread;
 
   /* Per thread data */
@@ -620,6 +610,8 @@ typedef struct snat_main_s
 
   /* counters */
   vlib_simple_counter_main_t total_sessions;
+  u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
+                                stats */
 
 #define _(x) vlib_simple_counter_main_t x;
   struct
@@ -692,7 +684,7 @@ typedef struct
 typedef struct
 {
   u32 cached_sw_if_index;
-  u32 cached_ip4_address;
+  uword *cached_presence_by_ip4_address;
 } snat_runtime_t;
 
 extern snat_main_t snat_main;
@@ -962,15 +954,6 @@ clib_error_t *nat44_api_hookup (vlib_main_t * vm);
  */
 int snat_set_workers (uword * bitmap);
 
-/**
- * @brief Set NAT plugin number of frame queue elements
- *
- * @param frame_queue_nelts number of worker handoff frame queue elements
- *
- * @return 0 on success, non-zero value otherwise
- */
-int snat_set_frame_queue_nelts (u32 frame_queue_nelts);
-
 /**
  * @brief Enable/disable NAT44 feature on the interface
  *
@@ -1084,21 +1067,13 @@ void expire_per_vrf_sessions (u32 fib_index);
  *
  * @returns 0 if match found otherwise 1.
  */
-int snat_static_mapping_match (snat_main_t * sm,
-                              ip4_address_t match_addr,
-                              u16 match_port,
-                              u32 match_fib_index,
-                              nat_protocol_t match_protocol,
-                              ip4_address_t * mapping_addr,
-                              u16 * mapping_port,
-                              u32 * mapping_fib_index,
-                              u8 by_external,
-                              u8 * is_addr_only,
-                              twice_nat_type_t * twice_nat,
-                              lb_nat_type_t * lb,
-                              ip4_address_t * ext_host_addr,
-                              u8 * is_identity_nat,
-                              snat_static_mapping_t ** out);
+int snat_static_mapping_match (
+  vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port,
+  u32 match_fib_index, nat_protocol_t match_protocol,
+  ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index,
+  u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat,
+  lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat,
+  snat_static_mapping_t **out);
 
 /**
  * @brief Add/del NAT address to FIB.
@@ -1178,9 +1153,14 @@ typedef enum
 } nat_translation_error_e;
 
 nat_translation_error_e
-nat_6t_flow_buf_translate (snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
-                          nat_6t_flow_t *f, nat_protocol_t proto,
-                          int is_output_feature);
+nat_6t_flow_buf_translate_i2o (snat_main_t *sm, vlib_buffer_t *b,
+                              ip4_header_t *ip, nat_6t_flow_t *f,
+                              nat_protocol_t proto, int is_output_feature);
+
+nat_translation_error_e
+nat_6t_flow_buf_translate_o2i (snat_main_t *sm, vlib_buffer_t *b,
+                              ip4_header_t *ip, nat_6t_flow_t *f,
+                              nat_protocol_t proto, int is_output_feature);
 
 void nat_6t_l3_l4_csum_calc (nat_6t_flow_t *f);