nat: refactor and split fo EI/ED features p.2
[vpp.git] / src / plugins / nat / nat.h
index 710c86f..58883d4 100644 (file)
@@ -88,6 +88,7 @@ typedef enum
   NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH,
   NAT_NEXT_OUT2IN_ED_FAST_PATH,
   NAT_NEXT_OUT2IN_ED_SLOW_PATH,
+  NAT_NEXT_OUT2IN_ED_HANDOFF,
   NAT_NEXT_IN2OUT_CLASSIFY,
   NAT_NEXT_OUT2IN_CLASSIFY,
   NAT_N_NEXT,
@@ -162,6 +163,19 @@ typedef enum
     NAT_IN2OUT_ED_N_ERROR,
 } nat_in2out_ed_error_t;
 
+#define foreach_nat44_handoff_error                       \
+_(CONGESTION_DROP, "congestion drop")                     \
+_(SAME_WORKER, "same worker")                             \
+_(DO_HANDOFF, "do handoff")
+
+typedef enum
+{
+#define _(sym,str) NAT44_HANDOFF_ERROR_##sym,
+  foreach_nat44_handoff_error
+#undef _
+    NAT44_HANDOFF_N_ERROR,
+} nat44_handoff_error_t;
+
 #define foreach_nat_out2in_ed_error                     \
 _(UNSUPPORTED_PROTOCOL, "unsupported protocol")         \
 _(OUT_OF_PORTS, "out of ports")                         \
@@ -199,8 +213,7 @@ typedef enum
 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT   16
 #define SNAT_SESSION_FLAG_FWD_BYPASS           32
 #define SNAT_SESSION_FLAG_AFFINITY             64
-#define SNAT_SESSION_FLAG_OUTPUT_FEATURE       128
-#define SNAT_SESSION_FLAG_EXACT_ADDRESS        256
+#define SNAT_SESSION_FLAG_EXACT_ADDRESS        128
 
 /* NAT interface flags */
 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
@@ -414,7 +427,6 @@ typedef struct
   u32 flags;
   int addr_only;
   int twice_nat;
-  int is_add;
   int out2in_only;
   int identity_nat;
   int exact;
@@ -716,6 +728,9 @@ typedef struct snat_main_s
   fib_source_t fib_src_hi;
   fib_source_t fib_src_low;
 
+  /* pat - dynamic mapping enabled or conneciton tracking */
+  u8 pat;
+
   /* nat44 plugin enabled */
   u8 enabled;
 
@@ -1284,20 +1299,6 @@ int snat_interface_add_del_output_feature (u32 sw_if_index, u8 is_inside,
 int snat_add_interface_address (snat_main_t * sm, u32 sw_if_index, int is_del,
                                u8 twice_nat);
 
-/**
- * @brief Delete NAT44 session
- *
- * @param addr   IPv4 address
- * @param port   L4 port number
- * @param proto  L4 protocol
- * @param vrf_id VRF ID
- * @param is_in  1 = inside network address and port pair, 0 = outside
- *
- * @return 0 on success, non-zero value otherwise
- */
-int nat44_del_session (snat_main_t * sm, ip4_address_t * addr, u16 port,
-                      nat_protocol_t proto, u32 vrf_id, int is_in);
-
 /**
  * @brief Delete NAT44 endpoint-dependent session
  *
@@ -1343,28 +1344,6 @@ int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
  */
 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
 
-/**
- * @brief Initialize NAT44 data
- *
- * @param tsm          per thread data
- */
-void nat44_db_init (snat_main_per_thread_data_t * tsm);
-
-/**
- * @brief Free NAT44 data
- *
- * @param tsm          per thread data
- */
-void nat44_db_free (snat_main_per_thread_data_t * tsm);
-
-/**
- * @brief Delete specific NAT44 EI user and his sessions
- *
- * @param addr         IPv4 address
- * @param fib_index    FIB table index
- */
-int nat44_ei_user_del (ip4_address_t * addr, u32 fib_index);
-
 /**
  * @brief Free all NAT44 sessions
  */
@@ -1398,29 +1377,6 @@ snat_session_t *nat_session_alloc_or_recycle (snat_main_t * sm,
                                              snat_user_t * u,
                                              u32 thread_index, f64 now);
 
-/**
- * @brief Set address and port assignment algorithm for MAP-E CE
- *
- * @param psid        Port Set Identifier value
- * @param psid_offset number of offset bits
- * @param psid_length length of PSID
- */
-void nat_set_alloc_addr_and_port_mape (u16 psid, u16 psid_offset,
-                                      u16 psid_length);
-
-/**
- * @brief Set address and port assignment algorithm for port range
- *
- * @param start_port beginning of the port range
- * @param end_port   end of the port range
- */
-void nat_set_alloc_addr_and_port_range (u16 start_port, u16 end_port);
-
-/**
- * @brief Set address and port assignment algorithm to default/standard
- */
-void nat_set_alloc_addr_and_port_default (void);
-
 /**
  * @brief Free outside address and port pair
  *
@@ -1434,26 +1390,6 @@ snat_free_outside_address_and_port (snat_address_t * addresses,
                                    ip4_address_t * addr,
                                    u16 port, nat_protocol_t protocol);
 
-/**
- * @brief Alloc outside address and port
- *
- * @param addresses         vector of outside addresses
- * @param fib_index         FIB table index
- * @param thread_index      thread index
- * @param port_per_thread   number of ports per thread
- * @param snat_thread_index NAT thread index
- *
- * @return 0 on success, non-zero value otherwise
- */
-int snat_alloc_outside_address_and_port (snat_address_t * addresses,
-                                        u32 fib_index,
-                                        u32 thread_index,
-                                        nat_protocol_t proto,
-                                        ip4_address_t * addr,
-                                        u16 * port,
-                                        u16 port_per_thread,
-                                        u32 snat_thread_index);
-
 void expire_per_vrf_sessions (u32 fib_index);
 
 /**
@@ -1505,23 +1441,7 @@ int snat_static_mapping_match (snat_main_t * sm,
 void snat_add_del_addr_to_fib (ip4_address_t * addr,
                               u8 p_len, u32 sw_if_index, int is_add);
 
-void
-nat_ha_sadd_cb (ip4_address_t * in_addr, u16 in_port,
-               ip4_address_t * out_addr, u16 out_port,
-               ip4_address_t * eh_addr, u16 eh_port,
-               ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
-               u32 fib_index, u16 flags, u32 thread_index);
-
-void
-nat_ha_sdel_cb (ip4_address_t * out_addr, u16 out_port,
-               ip4_address_t * eh_addr, u16 eh_port, u8 proto, u32 fib_index,
-               u32 ti);
-
-void
-nat_ha_sref_cb (ip4_address_t * out_addr, u16 out_port,
-               ip4_address_t * eh_addr, u16 eh_port, u8 proto, u32 fib_index,
-               u32 total_pkts, u64 total_bytes, u32 thread_index);
-
+#if 0
 void
 nat_ha_sadd_ed_cb (ip4_address_t * in_addr, u16 in_port,
                   ip4_address_t * out_addr, u16 out_port,
@@ -1534,16 +1454,16 @@ nat_ha_sdel_ed_cb (ip4_address_t * out_addr, u16 out_port,
                   ip4_address_t * eh_addr, u16 eh_port, u8 proto,
                   u32 fib_index, u32 ti);
 
-void
-nat_ha_sdel_ed_cb (ip4_address_t * out_addr, u16 out_port,
-                  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
-                  u32 fib_index, u32 ti);
-
 void
 nat_ha_sref_ed_cb (ip4_address_t * out_addr, u16 out_port,
                   ip4_address_t * eh_addr, u16 eh_port, u8 proto,
                   u32 fib_index, u32 total_pkts, u64 total_bytes,
                   u32 thread_index);
+#endif
+
+int nat_set_outside_address_and_port (snat_address_t *addresses,
+                                     u32 thread_index, ip4_address_t addr,
+                                     u16 port, nat_protocol_t protocol);
 
 /*
  * Why is this here? Because we don't need to touch this layer to
@@ -1564,6 +1484,18 @@ typedef struct
 
 u8 *format_user_kvp (u8 * s, va_list * args);
 
+u32 get_thread_idx_by_port (u16 e_port);
+
+u8 *format_static_mapping_kvp (u8 *s, va_list *args);
+
+u8 *format_session_kvp (u8 *s, va_list *args);
+
+u8 *format_user_kvp (u8 *s, va_list *args);
+
+u32 nat_calc_bihash_buckets (u32 n_elts);
+
+void nat44_addresses_free (snat_address_t **addresses);
+
 #endif /* __included_nat_h__ */
 /*
  * fd.io coding-style-patch-verification: ON