vcl: new vcl api to get detailed session errors 00/36700/4
authorRadha krishna Saragadam <krishna_srk2003@yahoo.com>
Mon, 18 Jul 2022 14:11:05 +0000 (19:41 +0530)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 20 Jul 2022 14:47:09 +0000 (14:47 +0000)
Sometimes VPP rejects application connection requests
due to various reasons. Some errors application can
retry to get a successful connection.
In a non-blocking session, VCL sends EPOLLHUP.
An application can call a new API
vppcom_session_get_error to find the details and retry
depending on the error.

Type: fix

Signed-off-by: Radha krishna Saragadam <krishna_srk2003@yahoo.com>
Change-Id: If0e21a8e25701f66a190a2799b2209e0c31f897c

src/vcl/vcl_private.h
src/vcl/vppcom.c
src/vcl/vppcom.h

index 9c90533..624a2da 100644 (file)
@@ -172,6 +172,8 @@ typedef struct vcl_session_
   transport_endpt_ext_cfg_t *ext_config;
   u8 dscp;
 
+  i32 vpp_error;
+
 #if VCL_ELOG
   elog_track_t elog_track;
 #endif
index 8476ea4..05b84d4 100644 (file)
@@ -411,6 +411,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
            format_session_error, mp->retval);
       session->session_state = VCL_STATE_DETACHED;
       session->vpp_handle = VCL_INVALID_SESSION_HANDLE;
+      session->vpp_error = mp->retval;
       return session_index;
     }
 
@@ -1398,6 +1399,7 @@ vppcom_session_create (u8 proto, u8 is_nonblocking)
   session->session_state = VCL_STATE_CLOSED;
   session->vpp_handle = ~0;
   session->is_dgram = vcl_proto_is_dgram (proto);
+  session->vpp_error = SESSION_E_NONE;
 
   if (is_nonblocking)
     vcl_session_set_attr (session, VCL_SESS_ATTR_NONBLOCK);
@@ -4420,6 +4422,10 @@ vppcom_retval_str (int retval)
       st = "VPPCOM_ETIMEDOUT";
       break;
 
+    case VPPCOM_EADDRINUSE:
+      st = "VPPCOM_EADDRINUSE";
+      break;
+
     default:
       st = "UNKNOWN_STATE";
       break;
@@ -4446,6 +4452,32 @@ vppcom_del_cert_key_pair (uint32_t ckpair_index)
     return vcl_bapi_del_cert_key_pair (ckpair_index);
 }
 
+int
+vppcom_session_get_error (uint32_t session_handle)
+{
+  vcl_worker_t *wrk = vcl_worker_get_current ();
+  vcl_session_t *session = 0;
+
+  session = vcl_session_get_w_handle (wrk, session_handle);
+  if (!session)
+    return VPPCOM_EBADFD;
+
+  if (PREDICT_FALSE (session->flags & VCL_SESSION_F_IS_VEP))
+    {
+      VWRN ("epoll session %u! will not have connect", session->session_index);
+      return VPPCOM_EBADFD;
+    }
+
+  if (session->vpp_error == SESSION_E_PORTINUSE)
+    return VPPCOM_EADDRINUSE;
+  else if (session->vpp_error == SESSION_E_REFUSED)
+    return VPPCOM_ECONNREFUSED;
+  else if (session->vpp_error != SESSION_E_NONE)
+    return VPPCOM_EFAULT;
+  else
+    return VPPCOM_OK;
+}
+
 /*
  * fd.io coding-style-patch-verification: ON
  *
index c50850c..6e15cd1 100644 (file)
@@ -102,6 +102,7 @@ typedef enum
   VPPCOM_ENOPROTOOPT = -ENOPROTOOPT,
   VPPCOM_EPIPE = -EPIPE,
   VPPCOM_ENOENT = -ENOENT,
+  VPPCOM_EADDRINUSE = -EADDRINUSE
 } vppcom_error_t;
 
 typedef enum
@@ -264,6 +265,13 @@ extern void vppcom_worker_index_set (int);
  */
 extern int vppcom_worker_mqs_epfd (void);
 
+/**
+ * Returns Session error
+ *
+ * Application can use this API to find the detailed session error
+ */
+extern int vppcom_session_get_error (uint32_t session_handle);
+
 /* *INDENT-OFF* */
 #ifdef __cplusplus
 }