cnat: Prepare extended snat policies
[vpp.git] / src / plugins / cnat / cnat_types.h
index 16d985f..47e34e1 100644 (file)
@@ -21,6 +21,7 @@
 #include <vnet/fib/fib_source.h>
 #include <vnet/ip/ip_types.h>
 #include <vnet/ip/ip.h>
+#include <vnet/util/throttle.h>
 
 /* only in the default table for v4 and v6 */
 #define CNAT_FIB_TABLE 0
 #define CNAT_DEFAULT_SESSION_BUCKETS     1024
 #define CNAT_DEFAULT_TRANSLATION_BUCKETS 1024
 #define CNAT_DEFAULT_SNAT_BUCKETS        1024
+#define CNAT_DEFAULT_SNAT_IF_MAP_LEN    4096
 
 #define CNAT_DEFAULT_SESSION_MEMORY      (1 << 20)
 #define CNAT_DEFAULT_TRANSLATION_MEMORY  (256 << 10)
 #define CNAT_DEFAULT_SNAT_MEMORY         (64 << 20)
 
+/* Should be prime >~ 100 * numBackends */
+#define CNAT_DEFAULT_MAGLEV_LEN 1009
+
 /* This should be strictly lower than FIB_SOURCE_INTERFACE
  * from fib_source.h */
 #define CNAT_FIB_SOURCE_PRIORITY  0x02
@@ -53,7 +58,7 @@
 typedef enum
 {
   /* Endpoint addr has been resolved */
-  CNAT_EP_FLAG_RESOLVED = 1,
+  CNAT_EP_FLAG_RESOLVED = (1 << 0),
 } cnat_ep_flag_t;
 
 typedef struct cnat_endpoint_t_
@@ -68,6 +73,7 @@ typedef struct cnat_endpoint_tuple_t_
 {
   cnat_endpoint_t dst_ep;
   cnat_endpoint_t src_ep;
+  u8 ep_flags; /* cnat_trk_flag_t */
 } cnat_endpoint_tuple_t;
 
 typedef struct
@@ -76,23 +82,6 @@ typedef struct
   u16 sequence;
 } cnat_echo_header_t;
 
-typedef struct
-{
-  u32 dst_address_length_refcounts[129];
-  u16 *prefix_lengths_in_search_order;
-  uword *non_empty_dst_address_length_bitmap;
-} cnat_snat_pfx_table_meta_t;
-
-typedef struct
-{
-  /* Stores (ip family, prefix & mask) */
-  clib_bihash_24_8_t ip_hash;
-  /* family dependant cache */
-  cnat_snat_pfx_table_meta_t meta[2];
-  /* Precomputed ip masks (ip4 & ip6) */
-  ip6_address_t ip_masks[129];
-} cnat_snat_pfx_table_t;
-
 typedef struct cnat_main_
 {
   /* Memory size of the session bihash */
@@ -113,6 +102,10 @@ typedef struct cnat_main_
   /* Number of buckets of the  source NAT prefix bihash */
   u32 snat_hash_buckets;
 
+  /* Bit map for include / exclude sw_if_index
+   * so max number of expected interfaces */
+  u32 snat_if_map_length;
+
   /* Timeout after which to clear sessions (in seconds) */
   u32 session_max_age;
 
@@ -126,15 +119,6 @@ typedef struct cnat_main_
   /* Lock for the timestamp pool */
   clib_rwlock_t ts_lock;
 
-  /* Ip4 Address to use for source NATing */
-  cnat_endpoint_t snat_ip4;
-
-  /* Ip6 Address to use for source NATing */
-  cnat_endpoint_t snat_ip6;
-
-  /* Longest prefix Match table for source NATing */
-  cnat_snat_pfx_table_t snat_pfx_table;
-
   /* Index of the scanner process node */
   uword scanner_node_index;
 
@@ -143,6 +127,10 @@ typedef struct cnat_main_
 
   /* Enable or Disable the scanner on startup */
   u8 default_scanner_state;
+
+  /* Number of buckets for maglev, should be a
+   * prime >= 100 * max num bakends */
+  u32 maglev_len;
 } cnat_main_t;
 
 typedef struct cnat_timestamp_t_
@@ -158,7 +146,6 @@ typedef struct cnat_timestamp_t_
 typedef struct cnat_node_ctx_
 {
   f64 now;
-  u64 seed;
   u32 thread_index;
   ip_address_family_t af;
   u8 do_trace;
@@ -172,7 +159,6 @@ extern uword unformat_cnat_ep (unformat_input_t * input, va_list * args);
 extern cnat_timestamp_t *cnat_timestamps;
 extern fib_source_t cnat_fib_source;
 extern cnat_main_t cnat_main;
-extern throttle_t cnat_throttle;
 
 extern char *cnat_error_strings[];