Timur Davydov has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/41922?usp=email )
Change subject: core: guard TCP stats on availability of linux/tcp.h and struct
tcp_info
......................................................................
core: guard TCP stats on availability of linux/tcp.h and struct tcp_info
Detect availability of linux/tcp.h and struct tcp_info 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 TCP stats code is compiled out,
while keeping the public API intact.
No functional changes on systems where linux/tcp.h and struct tcp_info
are available.
Change-Id: Ibcd00f15131b0291f0b10eca51401c518b77cc39
---
M configure.ac
M src/core/stats_tcp.c
2 files changed, 13 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/22/41922/1
diff --git a/configure.ac b/configure.ac
index 5d1bdec..1ef513d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -627,6 +627,13 @@
CHECK_BUILTIN_SUPPORT([__builtin_cpu_supports],
[Runtime SIMD detection will be disabled])
+dnl Check header linux/tcp.h
+AC_CHECK_HEADERS([linux/tcp.h])
+AC_CHECK_TYPES([struct tcp_info],
+ [AC_DEFINE([HAVE_TCP_INFO], 1, [Define if struct tcp_info
exists])],
+ [],
+ [[#include <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..f79fc6a 100644
--- a/src/core/stats_tcp.c
+++ b/src/core/stats_tcp.c
@@ -29,7 +29,9 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
+#ifdef HAVE_LINUX_TCP_H
#include <linux/tcp.h>
+#endif
#include <errno.h>
#include <pthread.h>
@@ -74,6 +76,7 @@
STATS_TCP_REORD_SEEN,
};
+#if HAVE_TCP_INFO
static struct osmo_stat_item_desc stats_tcp_item_desc[] = {
[STATS_TCP_UNACKED] = { "tcp:unacked", "unacknowledged packets", "",
60, 0 },
[STATS_TCP_LOST] = { "tcp:lost", "lost packets", "", 60, 0 },
@@ -93,9 +96,11 @@
.num_items = ARRAY_SIZE(stats_tcp_item_desc),
.item_desc = stats_tcp_item_desc,
};
+#endif /* HAVE_TCP_INFO */
static void fill_stats(struct stats_tcp_entry *stats_tcp_entry)
{
+#if HAVE_TCP_INFO
int rc;
struct tcp_info tcp_info;
socklen_t tcp_info_len = sizeof(tcp_info);
@@ -161,6 +166,7 @@
osmo_stat_item_set(osmo_stat_item_group_get_item(stats_tcp_entry->stats_tcp,
STATS_TCP_REORD_SEEN), -1);
#endif
+#endif /* HAVE_TCP_INFO */
}
static bool is_tcp(const struct osmo_fd *fd)
--
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: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ibcd00f15131b0291f0b10eca51401c518b77cc39
Gerrit-Change-Number: 41922
Gerrit-PatchSet: 1
Gerrit-Owner: Timur Davydov <[email protected]>