pespin submitted this change.

View Change

Approvals: pespin: Looks good to me, but someone else must approve osmith: Looks good to me, approved Jenkins Builder: Verified
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(-)

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 change 41922. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ibcd00f15131b0291f0b10eca51401c518b77cc39
Gerrit-Change-Number: 41922
Gerrit-PatchSet: 4
Gerrit-Owner: Timur Davydov <dtv.comp@gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>