pespin has submitted this change. (
https://gerrit.osmocom.org/c/libosmocore/+/41922?usp=email )
Change subject: core: guard TCP stats on availability of linux/tcp.h
......................................................................
core: guard TCP stats on availability of linux/tcp.h
Detect availability of linux/tcp.h at configure time
and build TCP statistics code conditionally based on that.
This replaces platform-specific conditionals with proper feature checks
and avoids build failures on systems lacking Linux TCP headers or types
(e.g. non-Linux or cross-build environments).
When TCP_INFO support is unavailable, the public API remains unchanged,
but all related functions return -ENOTSUP.
No functional changes on systems where linux/tcp.h are available.
Change-Id: Ibcd00f15131b0291f0b10eca51401c518b77cc39
---
M configure.ac
M src/core/stats_tcp.c
2 files changed, 35 insertions(+), 4 deletions(-)
Approvals:
pespin: Looks good to me, but someone else must approve
osmith: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/configure.ac b/configure.ac
index ee779ea..5c10f12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -628,6 +628,9 @@
CHECK_BUILTIN_SUPPORT([__builtin_cpu_supports],
[Runtime SIMD detection will be disabled])
+dnl Check header linux/tcp.h
+AC_CHECK_HEADERS([linux/tcp.h])
+
dnl There are some members in struct tcp_info that might not exist on all
linux versions
AC_CHECK_MEMBER([struct tcp_info.tcpi_notsent_bytes],
AC_DEFINE([HAVE_TCP_INFO_TCPI_NOTSENT_BYTES],
diff --git a/src/core/stats_tcp.c b/src/core/stats_tcp.c
index c6459fe..282f306 100644
--- a/src/core/stats_tcp.c
+++ b/src/core/stats_tcp.c
@@ -24,16 +24,21 @@
#include "config.h"
#if !defined(EMBEDDED)
+#include <errno.h>
+
+#include <osmocom/core/select.h>
+#include <osmocom/core/stats_tcp.h>
+
+#ifdef HAVE_LINUX_TCP_H
+
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <linux/tcp.h>
-#include <errno.h>
#include <pthread.h>
-#include <osmocom/core/select.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
@@ -41,7 +46,8 @@
#include <osmocom/core/stat_item.h>
#include <osmocom/core/stats.h>
#include <osmocom/core/socket.h>
-#include <osmocom/core/stats_tcp.h>
+
+#endif /* HAVE_LINUX_TCP_H */
static struct osmo_tcp_stats_config s_tcp_stats_config = {
.interval = TCP_STATS_DEFAULT_INTERVAL,
@@ -49,6 +55,8 @@
struct osmo_tcp_stats_config *osmo_tcp_stats_config = &s_tcp_stats_config;
+#ifdef HAVE_LINUX_TCP_H
+
static struct osmo_timer_list stats_tcp_poll_timer;
static LLIST_HEAD(stats_tcp);
@@ -160,7 +168,6 @@
#else
osmo_stat_item_set(osmo_stat_item_group_get_item(stats_tcp_entry->stats_tcp,
STATS_TCP_REORD_SEEN), -1);
#endif
-
}
static bool is_tcp(const struct osmo_fd *fd)
@@ -322,6 +329,27 @@
osmo_timer_setup(&stats_tcp_poll_timer, stats_tcp_poll_timer_cb, NULL);
}
+#else
+
+/* Stubs for systems that do not have header <linux/tcp.h> and TCP_INFO struct
*/
+
+int osmo_stats_tcp_osmo_fd_register(const struct osmo_fd *fd, const char *name)
+{
+ return -ENOTSUP;
+}
+
+int osmo_stats_tcp_osmo_fd_unregister(const struct osmo_fd *fd)
+{
+ return -ENOTSUP;
+}
+
+int osmo_stats_tcp_set_interval(int interval)
+{
+ return -ENOTSUP;
+}
+
+#endif /* HAVE_LINUX_TCP_H */
+
#endif /* !EMBEDDED */
/* @} */
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41922?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ibcd00f15131b0291f0b10eca51401c518b77cc39
Gerrit-Change-Number: 41922
Gerrit-PatchSet: 4
Gerrit-Owner: Timur Davydov <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>