ipsec: Revert "IPSEC: remove byte swap operations in DP during SPD classify"
[vpp.git] / src / vnet / session / session_types.h
index ec5841f..3564ee7 100644 (file)
 #define SRC_VNET_SESSION_SESSION_TYPES_H_
 
 #include <svm/svm_fifo.h>
-#include <vnet/session/transport.h>
+#include <vnet/session/transport_types.h>
+
+#define foreach_session_endpoint_fields                                \
+  foreach_transport_endpoint_cfg_fields                                \
+  _(u8, transport_proto)                                       \
+
+typedef struct _session_endpoint
+{
+#define _(type, name) type name;
+  foreach_session_endpoint_fields
+#undef _
+} session_endpoint_t;
+
+typedef struct _session_endpoint_cfg
+{
+#define _(type, name) type name;
+  foreach_session_endpoint_fields
+#undef _
+  u32 app_wrk_index;
+  u32 opaque;
+  u32 ns_index;
+  u8 original_tp;
+  u8 *hostname;
+  u64 transport_opts;
+} session_endpoint_cfg_t;
+
+#define SESSION_IP46_ZERO                      \
+{                                              \
+    .ip6 = {                                   \
+       { 0, 0, },                              \
+    },                                         \
+}
+
+#define TRANSPORT_ENDPOINT_NULL                        \
+{                                              \
+  .sw_if_index = ENDPOINT_INVALID_INDEX,       \
+  .ip = SESSION_IP46_ZERO,                     \
+  .fib_index = ENDPOINT_INVALID_INDEX,         \
+  .is_ip4 = 0,                                 \
+  .port = 0,                                   \
+}
+#define SESSION_ENDPOINT_NULL                  \
+{                                              \
+  .sw_if_index = ENDPOINT_INVALID_INDEX,       \
+  .ip = SESSION_IP46_ZERO,                     \
+  .fib_index = ENDPOINT_INVALID_INDEX,         \
+  .is_ip4 = 0,                                 \
+  .port = 0,                                   \
+  .peer = TRANSPORT_ENDPOINT_NULL,             \
+  .transport_proto = 0,                                \
+}
+#define SESSION_ENDPOINT_CFG_NULL              \
+{                                              \
+  .sw_if_index = ENDPOINT_INVALID_INDEX,       \
+  .ip = SESSION_IP46_ZERO,                     \
+  .fib_index = ENDPOINT_INVALID_INDEX,         \
+  .is_ip4 = 0,                                 \
+  .port = 0,                                   \
+  .peer = TRANSPORT_ENDPOINT_NULL,             \
+  .transport_proto = 0,                                \
+  .app_wrk_index = ENDPOINT_INVALID_INDEX,     \
+  .opaque = ENDPOINT_INVALID_INDEX,            \
+  .hostname = 0,                               \
+}
+
+#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
+#define session_endpoint_to_transport_cfg(_sep)                \
+  ((transport_endpoint_cfg_t *)_sep)
+
+always_inline u8
+session_endpoint_fib_proto (session_endpoint_t * sep)
+{
+  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
+}
+
+static inline u8
+session_endpoint_is_local (session_endpoint_t * sep)
+{
+  return (ip_is_zero (&sep->ip, sep->is_ip4)
+         || ip_is_local_host (&sep->ip, sep->is_ip4));
+}
+
+static inline u8
+session_endpoint_is_zero (session_endpoint_t * sep)
+{
+  return ip_is_zero (&sep->ip, sep->is_ip4);
+}
 
 typedef u8 session_type_t;
+typedef u64 session_handle_t;
+
+typedef enum
+{
+  SESSION_CLEANUP_TRANSPORT,
+  SESSION_CLEANUP_SESSION,
+} session_cleanup_ntf_t;
 
 /*
- * Application session state
+ * Session states
  */
 typedef enum
 {
+  SESSION_STATE_CREATED,
   SESSION_STATE_LISTENING,
   SESSION_STATE_CONNECTING,
   SESSION_STATE_ACCEPTING,
@@ -39,191 +133,226 @@ typedef enum
   SESSION_STATE_N_STATES,
 } session_state_t;
 
-typedef struct generic_session_
+typedef enum session_flags_
 {
-  svm_fifo_t *rx_fifo;         /**< rx fifo */
-  svm_fifo_t *tx_fifo;         /**< tx fifo */
-  session_type_t session_type; /**< session type */
-  volatile u8 session_state;   /**< session state */
-  u32 session_index;           /**< index in owning pool */
-} generic_session_t;
+  SESSION_F_RX_EVT = 1,
+  SESSION_F_PROXY = (1 << 1),
+} session_flags_t;
 
 typedef struct session_
 {
-  /** fifo pointers. Once allocated, these do not move */
+  /** Pointers to rx/tx buffers. Once allocated, these do not move */
   svm_fifo_t *rx_fifo;
   svm_fifo_t *tx_fifo;
 
-  /** Type */
+  /** Type built from transport and network protocol types */
   session_type_t session_type;
 
-  /** State */
+  /** State in session layer state machine. See @ref session_state_t */
   volatile u8 session_state;
 
-  /** Session index in per_thread pool */
+  /** Index in thread pool where session was allocated */
   u32 session_index;
 
-  /** App worker pool index */
+  /** Index of the app worker that owns the session */
   u32 app_wrk_index;
 
+  /** Index of the thread that allocated the session */
   u8 thread_index;
 
-  /** To avoid n**2 "one event per frame" check */
-  u64 enqueue_epoch;
-
-  /** svm segment index where fifos were allocated */
-  u32 svm_segment_index;
+  /** Session flags. See @ref session_flags_t */
+  u32 flags;
 
-  /** Transport specific */
+  /** Index of the transport connection associated to the session */
   u32 connection_index;
 
-  union
-  {
-    /** Parent listener session if the result of an accept */
-    u32 listener_index;
-
-    /** Application index if a listener */
-    u32 app_index;
-  };
+  /** Index of application that owns the listener. Set only if a listener */
+  u32 app_index;
 
   union
   {
-    /** Transport app index for apps acting as transports */
-    u32 t_app_index;
-
-    /** Index in listener app's listener db */
-    u32 listener_db_index;
+    /** Parent listener session index if the result of an accept */
+    session_handle_t listener_handle;
 
-    /** Opaque, for general use */
-    u32 opaque;
+    /** App listener index in app's listener pool if a listener */
+    u32 al_index;
   };
 
+  /** Opaque, for general use */
+  u32 opaque;
+
     CLIB_CACHE_LINE_ALIGN_MARK (pad);
 } session_t;
 
-typedef struct local_session_
+always_inline session_type_t
+session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
 {
-  /** fifo pointers. Once allocated, these do not move */
-  svm_fifo_t *rx_fifo;
-  svm_fifo_t *tx_fifo;
-
-  /** Type */
-  session_type_t session_type;
-
-  /** State */
-  volatile u8 session_state;
-
-  /** Session index */
-  u32 session_index;
+  return (proto << 1 | is_ip4);
+}
 
-  /** Server index */
-  u32 app_wrk_index;
+always_inline transport_proto_t
+session_type_transport_proto (session_type_t st)
+{
+  return (st >> 1);
+}
 
-  /** Port for connection. Overlaps thread_index/enqueue_epoch */
-  u16 port;
+always_inline u8
+session_type_is_ip4 (session_type_t st)
+{
+  return (st & 1);
+}
 
-  /** Partly overlaps enqueue_epoch */
-  u8 pad_epoch[7];
+always_inline transport_proto_t
+session_get_transport_proto (session_t * s)
+{
+  return (s->session_type >> 1);
+}
 
-  /** Segment index where fifos were allocated */
-  u32 svm_segment_index;
+always_inline fib_protocol_t
+session_get_fib_proto (session_t * s)
+{
+  u8 is_ip4 = s->session_type & 1;
+  return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+}
 
-  /** Transport listener index. Overlaps connection index */
-  u32 transport_listener_index;
+always_inline u8
+session_has_transport (session_t * s)
+{
+  return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
+}
 
-  union
-  {
-    u32 listener_index;
-    u32 app_index;
-  };
+static inline transport_service_type_t
+session_transport_service_type (session_t * s)
+{
+  transport_proto_t tp;
+  tp = session_get_transport_proto (s);
+  return transport_protocol_service_type (tp);
+}
 
-  u32 listener_db_index;
+static inline transport_tx_fn_type_t
+session_transport_tx_fn_type (session_t * s)
+{
+  transport_proto_t tp;
+  tp = session_get_transport_proto (s);
+  return transport_protocol_tx_fn_type (tp);
+}
 
-  /** Has transport embedded when listener not purely local */
-  session_type_t listener_session_type;
+static inline u8
+session_tx_is_dgram (session_t * s)
+{
+  return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
+}
 
-  /**
-   * Client data
-   */
-  u32 client_wrk_index;
-  u32 client_opaque;
+always_inline session_handle_t
+session_handle (session_t * s)
+{
+  return ((u64) s->thread_index << 32) | (u64) s->session_index;
+}
 
-  u64 server_evt_q;
-  u64 client_evt_q;
+always_inline u32
+session_index_from_handle (session_handle_t handle)
+{
+  return handle & 0xFFFFFFFF;
+}
 
-    CLIB_CACHE_LINE_ALIGN_MARK (pad);
-} local_session_t;
+always_inline u32
+session_thread_from_handle (session_handle_t handle)
+{
+  return handle >> 32;
+}
 
-#define foreach_session_endpoint_fields                                \
-  foreach_transport_endpoint_cfg_fields                                \
-  _(u8, transport_proto)                                       \
+always_inline void
+session_parse_handle (session_handle_t handle, u32 * index,
+                     u32 * thread_index)
+{
+  *index = session_index_from_handle (handle);
+  *thread_index = session_thread_from_handle (handle);
+}
 
-typedef struct _session_endpoint
+typedef enum
 {
-#define _(type, name) type name;
-  foreach_session_endpoint_fields
-#undef _
-} session_endpoint_t;
+  SESSION_IO_EVT_RX,
+  SESSION_IO_EVT_TX,
+  SESSION_IO_EVT_TX_FLUSH,
+  SESSION_IO_EVT_BUILTIN_RX,
+  SESSION_IO_EVT_BUILTIN_TX,
+  SESSION_CTRL_EVT_RPC,
+  SESSION_CTRL_EVT_CLOSE,
+  SESSION_CTRL_EVT_BOUND,
+  SESSION_CTRL_EVT_UNLISTEN_REPLY,
+  SESSION_CTRL_EVT_ACCEPTED,
+  SESSION_CTRL_EVT_ACCEPTED_REPLY,
+  SESSION_CTRL_EVT_CONNECTED,
+  SESSION_CTRL_EVT_CONNECTED_REPLY,
+  SESSION_CTRL_EVT_DISCONNECTED,
+  SESSION_CTRL_EVT_DISCONNECTED_REPLY,
+  SESSION_CTRL_EVT_RESET,
+  SESSION_CTRL_EVT_RESET_REPLY,
+  SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
+  SESSION_CTRL_EVT_WORKER_UPDATE,
+  SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
+} session_evt_type_t;
+
+/* Deprecated and will be removed. Use types above */
+#define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
+#define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
+#define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
+#define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
+#define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
 
-typedef struct _session_endpoint_cfg
+typedef enum
 {
-#define _(type, name) type name;
-  foreach_session_endpoint_fields
-#undef _
-  u32 app_wrk_index;
-  u32 opaque;
-  u8 *hostname;
-} session_endpoint_cfg_t;
+  SESSION_MQ_IO_EVT_RING,
+  SESSION_MQ_CTRL_EVT_RING,
+  SESSION_MQ_N_RINGS
+} session_mq_rings_e;
 
-#define SESSION_IP46_ZERO                      \
-{                                              \
-    .ip6 = {                                   \
-       { 0, 0, },                              \
-    },                                         \
-}
+typedef struct
+{
+  void *fp;
+  void *arg;
+} session_rpc_args_t;
 
-#define TRANSPORT_ENDPOINT_NULL                        \
-{                                              \
-  .sw_if_index = ENDPOINT_INVALID_INDEX,       \
-  .ip = SESSION_IP46_ZERO,                     \
-  .fib_index = ENDPOINT_INVALID_INDEX,         \
-  .is_ip4 = 0,                                 \
-  .port = 0,                                   \
-}
-#define SESSION_ENDPOINT_NULL                  \
-{                                              \
-  .sw_if_index = ENDPOINT_INVALID_INDEX,       \
-  .ip = SESSION_IP46_ZERO,                     \
-  .fib_index = ENDPOINT_INVALID_INDEX,         \
-  .is_ip4 = 0,                                 \
-  .port = 0,                                   \
-  .peer = TRANSPORT_ENDPOINT_NULL,             \
-  .transport_proto = 0,                                \
-}
-#define SESSION_ENDPOINT_CFG_NULL              \
-{                                              \
-  .sw_if_index = ENDPOINT_INVALID_INDEX,       \
-  .ip = SESSION_IP46_ZERO,                     \
-  .fib_index = ENDPOINT_INVALID_INDEX,         \
-  .is_ip4 = 0,                                 \
-  .port = 0,                                   \
-  .peer = TRANSPORT_ENDPOINT_NULL,             \
-  .transport_proto = 0,                                \
-  .app_wrk_index = ENDPOINT_INVALID_INDEX,     \
-  .opaque = ENDPOINT_INVALID_INDEX,            \
-  .hostname = 0,                               \
-}
+typedef struct
+{
+  u8 event_type;
+  u8 postponed;
+  union
+  {
+    u32 session_index;
+    session_handle_t session_handle;
+    session_rpc_args_t rpc_args;
+    struct
+    {
+      u8 data[0];
+    };
+  };
+} __clib_packed session_event_t;
 
-#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
-#define session_endpoint_to_transport_cfg(_sep)                \
-  ((transport_endpoint_cfg_t *)_sep)
+#define SESSION_MSG_NULL { }
 
-always_inline u8
-session_endpoint_fib_proto (session_endpoint_t * sep)
+typedef struct session_dgram_pre_hdr_
 {
-  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
-}
+  u32 data_length;
+  u32 data_offset;
+} session_dgram_pre_hdr_t;
 
+typedef struct session_dgram_header_
+{
+  u32 data_length;
+  u32 data_offset;
+  ip46_address_t rmt_ip;
+  ip46_address_t lcl_ip;
+  u16 rmt_port;
+  u16 lcl_port;
+  u8 is_ip4;
+} __clib_packed session_dgram_hdr_t;
+
+#define SESSION_CONN_ID_LEN 37
+#define SESSION_CONN_HDR_LEN 45
+
+STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
+              "session conn id wrong length");
 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
 
 /*