sflow: Update build rules 42/42242/4
authorPim van Pelt <[email protected]>
Thu, 23 Jan 2025 10:04:19 +0000 (11:04 +0100)
committerPim van Pelt <[email protected]>
Thu, 23 Jan 2025 10:16:08 +0000 (11:16 +0100)
1) we rely on Netlink PSAMPLE and USERSOCK make sure we have headers
2) sflow plugin is not available on FreeBSD, due to Netlink features
3) preprocessor flag SFLOW_USE_VAPI controls whether the sflow plugin
will attempt to contact the linux-cp plugin using the binary VAPI. It
has to be a preprocessor flag so it can suppress the "#include"
statements that define that linux-cp api, because those include files
will be missing if linux-cp is excluded from the build.

The "excluded_plugins" list can be used with:
make VPP_EXCLUDED_PLUGINS=linux-cp build build-release

Type: fix
Fixes: e40f8a90bb0c39986c198fca8ad9b0b3c1658401
Change-Id: If44929d285d27db7862910ecb4ec11ddd4591fd2
Signed-off-by: [email protected]
src/plugins/sflow/CMakeLists.txt
src/plugins/sflow/sflow.c
src/plugins/sflow/sflow.h
src/plugins/sflow/sflow_common.h
src/plugins/sflow/sflow_vapi.c
src/plugins/sflow/sflow_vapi.h

index fc20f0f..35433bd 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+vpp_find_path(NETLINK_INCLUDE_DIR NAMES linux/netlink.h)
+if (NOT NETLINK_INCLUDE_DIR)
+  message(WARNING "netlink headers not found - sflow plugin disabled")
+  return()
+endif()
+
+if ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
+  message(WARNING "sflow is not supported on FreeBSD - sflow plugin disabled")
+  return()
+endif()
+
+LIST(FIND excluded_plugins linux-cp exc_index)
+if(${exc_index} EQUAL "-1")
+  message(WARNING "sflow plugin - linux-cp plugin included: compiling VAPI calls")
+  add_compile_definitions(SFLOW_USE_VAPI)
+else()
+  message(WARNING "sflow plugin - linux-cp plugin excluded: not compiling VAPI calls")
+endif()
+
 include_directories(${CMAKE_SOURCE_DIR}/vpp-api ${CMAKE_CURRENT_BINARY_DIR}/../../vpp-api)
 add_vpp_plugin(sflow
   SOURCES
index ad8cf7c..5aa6506 100644 (file)
@@ -539,8 +539,10 @@ sflow_sampling_start (sflow_main_t *smp)
   smp->psample_seq_egress = 0;
   smp->psample_send_drops = 0;
 
+#ifdef SFLOW_USE_VAPI
   // reset vapi request count so that we make a request the first time
   smp->vapi_requests = 0;
+#endif
 
   /* open PSAMPLE netlink channel for writing packet samples */
   SFLOWPS_open (&smp->sflow_psample);
index 18e2dab..609ff72 100644 (file)
@@ -33,7 +33,6 @@
 #define SFLOW_MIN_HEADER_BYTES    64
 #define SFLOW_HEADER_BYTES_STEP           32
 
-#define SFLOW_USE_VAPI
 #define SFLOW_FIFO_DEPTH  2048 // must be power of 2
 #define SFLOW_POLL_WAIT_S 0.001
 #define SFLOW_READ_BATCH  100
@@ -165,12 +164,12 @@ typedef struct
   u32 csample_send;
   u32 csample_send_drops;
   u32 unixsock_seq;
-
+#ifdef SFLOW_USE_VAPI
   /* vapi query helper thread (transient) */
   CLIB_CACHE_LINE_ALIGN_MARK (_vapi);
   sflow_vapi_client_t vac;
   int vapi_requests;
-
+#endif
 } sflow_main_t;
 
 extern sflow_main_t sflow_main;
index 1d5b908..2978463 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef __included_sflow_common_h__
 #define __included_sflow_common_h__
 
-#define SFLOW_USE_VAPI
+// #define SFLOW_USE_VAPI (set by CMakeLists.txt)
 
 extern vlib_log_class_t sflow_logger;
 #define SFLOW_DBG(...)   vlib_log_debug (sflow_logger, __VA_ARGS__);
index 66e9eba..cdc89a5 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <sflow/sflow_vapi.h>
 
+#ifdef SFLOW_USE_VAPI
+
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 #include <vpp/app/version.h>
@@ -212,6 +214,9 @@ sflow_vapi_check_for_linux_if_index_results (sflow_vapi_client_t *vac,
     }
   return false;
 }
+
+#endif /* SFLOW_USE_VAPI */
+
 /*
  * fd.io coding-style-patch-verification: ON
  *
index baf4304..640fe99 100644 (file)
@@ -18,6 +18,8 @@
 #include <vnet/vnet.h>
 #include <sflow/sflow_common.h>
 
+#ifdef SFLOW_USE_VAPI
+
 #define SFLOW_VAPI_POLL_INTERVAL  5
 #define SFLOW_VAPI_MAX_REQUEST_Q  8
 #define SFLOW_VAPI_MAX_RESPONSE_Q 16
@@ -41,6 +43,7 @@ int
 sflow_vapi_check_for_linux_if_index_results (sflow_vapi_client_t *vac,
                                             sflow_per_interface_data_t *itfs);
 
+#endif /* SFLOW_USE_VAPI */
 #endif /* __included_sflow_vapi_h__ */
 
 /*