vcl: add option to build vcl wihout bapi support 19/43819/3
authorFlorin Coras <[email protected]>
Wed, 1 Oct 2025 03:01:29 +0000 (23:01 -0400)
committerDave Wallace <[email protected]>
Wed, 1 Oct 2025 23:19:58 +0000 (23:19 +0000)
Add compile time option to disable building vcl bapi infrastructure. For
now, the build is still enabled and the code is tested, but BAPI support
is deprecated and will be removed in time.

Type: improvement

Change-Id: I8d04b0496b53025637e3339cac600d2637f282a8
Signed-off-by: Florin Coras <[email protected]>
src/vcl/CMakeLists.txt
src/vcl/vcl_cfg.c
src/vcl/vcl_private.c
src/vcl/vcl_private.h
src/vcl/vppcom.c

index 2787ce6..473e403 100644 (file)
@@ -20,21 +20,38 @@ if(NOT VPP_BUILD_VCL)
   return()
 endif(NOT VPP_BUILD_VCL)
 
-add_vpp_library(vppcom
-  SOURCES
-  vppcom.c
-  vcl_bapi.c
-  vcl_cfg.c
-  vcl_private.c
-  vcl_locked.c
-  vcl_sapi.c
+option(VPP_BUILD_VCL_BAPI "Build VCL BAPI" ON)
 
-  LINK_LIBRARIES
-  vppinfra svm vlibmemoryclient rt pthread
+if (NOT VPP_BUILD_VCL_BAPI)
+  add_vpp_library(vppcom
+    SOURCES
+    vppcom.c
+    vcl_cfg.c
+    vcl_private.c
+    vcl_locked.c
+    vcl_sapi.c
 
-  DEPENDS
-  api_headers
-)
+    LINK_LIBRARIES
+    vppinfra svm rt pthread
+  )
+else()
+  add_definitions(-DVCL_BAPI_ENABLED)
+  add_vpp_library(vppcom
+    SOURCES
+    vppcom.c
+    vcl_bapi.c
+    vcl_cfg.c
+    vcl_private.c
+    vcl_locked.c
+    vcl_sapi.c
+
+    LINK_LIBRARIES
+    vppinfra svm vlibmemoryclient rt pthread
+
+    DEPENDS
+    api_headers
+  )
+endif()
 
 option(LDP_HAS_GNU_SOURCE "LDP configured to use _GNU_SOURCE" ON)
 if (LDP_HAS_GNU_SOURCE)
index edea60d..48be5a7 100644 (file)
@@ -225,7 +225,9 @@ vppcom_cfg_read_file (char *conf_fname)
   unformat_input_t _line_input, *line_input = &_line_input;
   u8 vc_cfg_input = 0;
   struct stat s;
+#if VCL_BAPI_ENABLED
   u32 uid, gid;
+#endif
 
   fd = open (conf_fname, O_RDONLY);
   if (fd < 0)
@@ -279,13 +281,6 @@ vppcom_cfg_read_file (char *conf_fname)
              VCFG_DBG (0, "VCL<%d>: configured max-workers %u", getpid (),
                        vcl_cfg->max_workers);
            }
-         else if (unformat (line_input, "api-socket-name %s",
-                            &vcl_cfg->vpp_bapi_socket_name))
-           {
-             vec_terminate_c_string (vcl_cfg->vpp_bapi_socket_name);
-             VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)",
-                       getpid (), vcl_cfg->vpp_bapi_socket_name);
-           }
          else if (unformat (line_input, "app-socket-api %s",
                             &vcl_cfg->vpp_app_socket_api))
            {
@@ -293,16 +288,6 @@ vppcom_cfg_read_file (char *conf_fname)
              VCFG_DBG (0, "VCL<%d>: configured app-socket-api (%s)",
                        getpid (), vcl_cfg->vpp_app_socket_api);
            }
-         else if (unformat (line_input, "uid %d", &uid))
-           {
-             vl_set_memory_uid (uid);
-             VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid);
-           }
-         else if (unformat (line_input, "gid %d", &gid))
-           {
-             vl_set_memory_gid (gid);
-             VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid);
-           }
          else if (unformat (line_input, "segment-size 0x%lx",
                             &vcl_cfg->segment_size))
            {
@@ -422,11 +407,37 @@ vppcom_cfg_read_file (char *conf_fname)
              VCFG_DBG (0, "VCL<%d>: configured huge_page (%d)", getpid (),
                        vcl_cfg->huge_page);
            }
+         else if (unformat (line_input, "use-mq-eventfd"))
+           {
+             vcl_cfg->use_mq_eventfd = 1;
+             VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd",
+                       getpid ());
+           }
+         else if (unformat (line_input, "tls-engine %u",
+                            &vcl_cfg->tls_engine))
+           {
+             VCFG_DBG (0, "VCL<%d>: configured tls-engine %u (0x%x)",
+                       getpid (), vcl_cfg->tls_engine, vcl_cfg->tls_engine);
+           }
+         else if (unformat (line_input, "multi-thread-workers"))
+           {
+             vcl_cfg->mt_wrk_supported = 1;
+             VCFG_DBG (0, "VCL<%d>: configured with multithread workers",
+                       getpid ());
+           }
+         else if (unformat (line_input, "app_original_dst"))
+           {
+             vcl_cfg->app_original_dst = 1;
+             VCFG_DBG (0, "VCL<%d>: support original destination", getpid ());
+           }
+#if VCL_BAPI_ENABLED
          else if (unformat (line_input, "namespace-secret %lu",
                             &vcl_cfg->namespace_secret))
            {
-             VCFG_DBG (0, "VCL<%d>: configured namespace_secret %llu "
-                       "(0x%llx)", getpid (),
+             VCFG_DBG (0,
+                       "VCL<%d>: configured namespace_secret %llu "
+                       "(0x%llx)",
+                       getpid (),
                        (unsigned long long) vcl_cfg->namespace_secret,
                        (unsigned long long) vcl_cfg->namespace_secret);
            }
@@ -438,37 +449,33 @@ vppcom_cfg_read_file (char *conf_fname)
              if (nsid_vec_len > max_nsid_vec_len)
                {
                  vec_set_len (vcl_cfg->namespace_id, max_nsid_vec_len);
-                 VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long,"
+                 VCFG_DBG (0,
+                           "VCL<%d>: configured namespace_id is too long,"
                            " truncated to %d characters!",
                            getpid (), max_nsid_vec_len);
                }
 
-             VCFG_DBG (0, "VCL<%d>: configured namespace_id %s",
-                       getpid (), (char *) vcl_cfg->namespace_id);
+             VCFG_DBG (0, "VCL<%d>: configured namespace_id %s", getpid (),
+                       (char *) vcl_cfg->namespace_id);
            }
-         else if (unformat (line_input, "use-mq-eventfd"))
-           {
-             vcl_cfg->use_mq_eventfd = 1;
-             VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd",
-                       getpid ());
-           }
-         else if (unformat (line_input, "tls-engine %u",
-                            &vcl_cfg->tls_engine))
+         else if (unformat (line_input, "api-socket-name %s",
+                            &vcl_cfg->vpp_bapi_socket_name))
            {
-             VCFG_DBG (0, "VCL<%d>: configured tls-engine %u (0x%x)",
-                       getpid (), vcl_cfg->tls_engine, vcl_cfg->tls_engine);
+             vec_terminate_c_string (vcl_cfg->vpp_bapi_socket_name);
+             VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)",
+                       getpid (), vcl_cfg->vpp_bapi_socket_name);
            }
-         else if (unformat (line_input, "multi-thread-workers"))
+         else if (unformat (line_input, "uid %d", &uid))
            {
-             vcl_cfg->mt_wrk_supported = 1;
-             VCFG_DBG (0, "VCL<%d>: configured with multithread workers",
-                       getpid ());
+             vl_set_memory_uid (uid);
+             VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid);
            }
-         else if (unformat (line_input, "app_original_dst"))
+         else if (unformat (line_input, "gid %d", &gid))
            {
-             vcl_cfg->app_original_dst = 1;
-             VCFG_DBG (0, "VCL<%d>: support original destination", getpid ());
+             vl_set_memory_gid (gid);
+             VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid);
            }
+#endif
          else if (unformat (line_input, "}"))
            {
              vc_cfg_input = 0;
index 714ecda..1822e2d 100644 (file)
@@ -126,27 +126,6 @@ vcl_worker_free (vcl_worker_t * wrk)
   pool_put (vcm->workers, wrk);
 }
 
-int
-vcl_api_app_worker_add (void)
-{
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_app_worker_add ();
-
-  return vcl_bapi_app_worker_add ();
-}
-
-void
-vcl_api_app_worker_del (vcl_worker_t * wrk)
-{
-  if (wrk->api_client_handle == ~0)
-    return;
-
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_app_worker_del (wrk);
-
-  vcl_bapi_app_worker_del (wrk);
-}
-
 void
 vcl_worker_cleanup (vcl_worker_t * wrk, u8 notify_vpp)
 {
index cc51946..de21422 100644 (file)
@@ -820,6 +820,7 @@ void vcl_init_epoll_fns (void);
 /*
  * VCL Binary API
  */
+#if defined(VCL_BAPI_ENABLED)
 int vcl_bapi_attach (void);
 int vcl_bapi_app_worker_add (void);
 void vcl_bapi_app_worker_del (vcl_worker_t * wrk);
@@ -829,6 +830,7 @@ int vcl_bapi_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair);
 int vcl_bapi_del_cert_key_pair (u32 ckpair_index);
 u32 vcl_bapi_max_nsid_len (void);
 int vcl_bapi_worker_set (void);
+#endif
 
 /*
  * VCL Socket API
@@ -841,6 +843,95 @@ int vcl_sapi_recv_fds (vcl_worker_t * wrk, int *fds, int n_fds);
 int vcl_sapi_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair);
 int vcl_sapi_del_cert_key_pair (u32 ckpair_index);
 
+static inline int
+vcl_api_attach (void)
+{
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_attach ();
+#if VCL_BAPI_ENABLED
+  return vcl_bapi_attach ();
+#else
+  return -1;
+#endif
+}
+
+static inline int
+vcl_api_recv_fd (vcl_worker_t *wrk, int *fds, int n_fds)
+{
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_recv_fds (wrk, fds, n_fds);
+
+#if VCL_BAPI_ENABLED
+  return vcl_bapi_recv_fds (wrk, fds, n_fds);
+#else
+  return -1;
+#endif
+}
+
+static inline void
+vcl_api_detach (vcl_worker_t *wrk)
+{
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_detach (wrk);
+
+#if VCL_BAPI_ENABLED
+  vcl_bapi_disconnect_from_vpp ();
+#endif
+}
+
+static inline int
+vcl_api_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair)
+{
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_add_cert_key_pair (ckpair);
+
+#if VCL_BAPI_ENABLED
+  return vcl_bapi_add_cert_key_pair (ckpair);
+#else
+  return -1;
+#endif
+}
+
+static inline int
+vcl_api_app_worker_add (void)
+{
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_app_worker_add ();
+
+#if VCL_BAPI_ENABLED
+  return vcl_bapi_app_worker_add ();
+#else
+  return -1;
+#endif
+}
+
+static inline void
+vcl_api_app_worker_del (vcl_worker_t *wrk)
+{
+  if (wrk->api_client_handle == ~0)
+    return;
+
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_app_worker_del (wrk);
+
+#if VCL_BAPI_ENABLED
+  vcl_bapi_app_worker_del (wrk);
+#endif
+}
+
+static inline int
+vcl_api_del_cert_key_pair (uint32_t ckpair_index)
+{
+  if (vcm->cfg.vpp_app_socket_api)
+    return vcl_sapi_del_cert_key_pair (ckpair_index);
+
+#if VCL_BAPI_ENABLED
+  return vcl_bapi_del_cert_key_pair (ckpair_index);
+#else
+  return -1;
+#endif
+}
+
 /*
  * Utility functions
  */
index 7b1a5f1..6364693 100644 (file)
@@ -933,16 +933,6 @@ vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data)
        s->vpp_handle, wrk->wrk_index);
 }
 
-static int
-vcl_api_recv_fd (vcl_worker_t * wrk, int *fds, int n_fds)
-{
-
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_recv_fds (wrk, fds, n_fds);
-
-  return vcl_bapi_recv_fds (wrk, fds, n_fds);
-}
-
 static void
 vcl_session_app_add_segment_handler (vcl_worker_t * wrk, void *data)
 {
@@ -1370,15 +1360,6 @@ vppcom_app_exit (void)
   vcl_elog_stop (vcm);
 }
 
-static int
-vcl_api_attach (void)
-{
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_attach ();
-
-  return vcl_bapi_attach ();
-}
-
 int
 vcl_is_first_reattach_to_execute ()
 {
@@ -1454,20 +1435,6 @@ vcl_api_handle_disconnect (vcl_worker_t *wrk)
   vcl_worker_detach_sessions (wrk);
 }
 
-static void
-vcl_api_detach (vcl_worker_t * wrk)
-{
-  if (wrk->api_client_handle == ~0)
-    return;
-
-  vcl_send_app_detach (wrk);
-
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_detach (wrk);
-
-  return vcl_bapi_disconnect_from_vpp ();
-}
-
 /*
  * VPPCOM Public API functions
  */
@@ -1534,7 +1501,12 @@ vppcom_app_destroy (void)
       vcl_worker_cleanup (wrk, 0 /* notify vpp */ );
   }
 
-  vcl_api_detach (current_wrk);
+  if (current_wrk->api_client_handle != ~0)
+  {
+    vcl_send_app_detach (current_wrk);
+    vcl_api_detach (current_wrk);
+  }
+
   vcl_worker_cleanup (current_wrk, 0 /* notify vpp */ );
   vcl_set_worker_index (~0);
 
@@ -4952,19 +4924,13 @@ vppcom_retval_str (int retval)
 int
 vppcom_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair)
 {
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_add_cert_key_pair (ckpair);
-  else
-    return vcl_bapi_add_cert_key_pair (ckpair);
+  return vcl_api_add_cert_key_pair (ckpair);
 }
 
 int
 vppcom_del_cert_key_pair (uint32_t ckpair_index)
 {
-  if (vcm->cfg.vpp_app_socket_api)
-    return vcl_sapi_del_cert_key_pair (ckpair_index);
-  else
-    return vcl_bapi_del_cert_key_pair (ckpair_index);
+  return vcl_api_del_cert_key_pair (ckpair_index);
 }
 
 int