vcl: refactor vcl session
[vpp.git] / src / vnet / session / application_interface.h
index 5fd2185..cc63671 100644 (file)
@@ -136,7 +136,7 @@ typedef enum
   _(ACCEPT_REDIRECT, "Use FIFO with redirects")                        \
   _(ADD_SEGMENT, "Add segment and signal app if needed")       \
   _(IS_BUILTIN, "Application is builtin")                      \
-  _(IS_PROXY, "Application is proxying")                               \
+  _(IS_PROXY, "Application is proxying")                       \
   _(USE_GLOBAL_SCOPE, "App can use global session scope")      \
   _(USE_LOCAL_SCOPE, "App can use local session scope")
 
@@ -177,21 +177,26 @@ typedef struct app_session_transport_
 {
   ip46_address_t rmt_ip;       /**< remote ip */
   ip46_address_t lcl_ip;       /**< local ip */
-  u16 rmt_port;                        /**< remote port */
-  u16 lcl_port;                        /**< local port */
+  u16 rmt_port;                        /**< remote port (network order) */
+  u16 lcl_port;                        /**< local port (network order) */
   u8 is_ip4;                   /**< set if uses ip4 networking */
 } app_session_transport_t;
 
-typedef struct app_session_
+#define foreach_app_session_field                                      \
+  _(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 */    \
+  _(app_session_transport_t, transport)        /**< transport info */          \
+  _(svm_queue_t, *vpp_evt_q)           /**< vpp event queue  */        \
+  _(u8, is_dgram)                      /**< flag for dgram mode */     \
+
+typedef struct
 {
-  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 */
-  app_session_transport_t transport;   /**< transport info */
-  svm_queue_t *vpp_evt_q;              /**< vpp event queue for session */
-  u8 is_dgram;                         /**< set if it works in dgram mode */
+#define _(type, name) type name;
+  foreach_app_session_field
+#undef _
 } app_session_t;
 
 always_inline int
@@ -204,7 +209,7 @@ app_send_dgram_raw (svm_fifo_t * f, app_session_transport_t * at,
   int rv;
 
   max_enqueue = svm_fifo_max_enqueue (f);
-  if (svm_fifo_max_enqueue (f) <= sizeof (session_dgram_hdr_t))
+  if (max_enqueue <= sizeof (session_dgram_hdr_t))
     return 0;
 
   max_enqueue -= sizeof (session_dgram_hdr_t);
@@ -217,9 +222,6 @@ app_send_dgram_raw (svm_fifo_t * f, app_session_transport_t * at,
   clib_memcpy (&hdr.lcl_ip, &at->lcl_ip, sizeof (ip46_address_t));
   hdr.lcl_port = at->lcl_port;
   rv = svm_fifo_enqueue_nowait (f, sizeof (hdr), (u8 *) & hdr);
-  if (rv <= 0)
-    return 0;
-
   ASSERT (rv == sizeof (hdr));
 
   if ((rv = svm_fifo_enqueue_nowait (f, actual_write, data)) > 0)
@@ -231,6 +233,7 @@ app_send_dgram_raw (svm_fifo_t * f, app_session_transport_t * at,
          svm_queue_add (vpp_evt_q, (u8 *) & evt, noblock);
        }
     }
+  ASSERT (rv);
   return rv;
 }