Timur Davydov has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/41878?usp=email ) Change subject: build: move netns/tun conditionals to configure.ac Move Linux-/embedded-specific conditional compilation out of the sources and into configure.ac. ...................................................................... build: move netns/tun conditionals to configure.ac Move Linux-/embedded-specific conditional compilation out of the sources and into configure.ac. - Define USE_NETNS based on host_os and disable it for --enable-embedded. - Detect struct in6_addr.s6_addr32 via AC_CHECK_MEMBER and use HAVE_IN6_ADDR_S6_ADDR32 instead of __linux__. - Do not build tun.c for embedded targets (previously it was compiled but effectively empty due to #if (!EMBEDDED)). No functional changes intended, this is a preparatory refactor to keep follow-up patches focused and easier to review. Change-Id: I2322eb2936bea35596f1fd6b6a713ea5f997b1ea --- M configure.ac M include/osmocom/core/netns.h M src/core/Makefile.am M src/core/socket.c M src/core/tun.c 5 files changed, 23 insertions(+), 12 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/78/41878/1 diff --git a/configure.ac b/configure.ac index 64690f9..bc060b6 100644 --- a/configure.ac +++ b/configure.ac @@ -25,6 +25,13 @@ AC_PROG_INSTALL LT_INIT([pic-only disable-static]) +dnl Define USE_NETNS when building for Linux +case "${host_os}" in +*linux*) + AC_DEFINE([USE_NETNS], [1], [Define to 1 if network namespace support is available]) + ;; +esac + AC_CONFIG_MACRO_DIR([m4]) dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang @@ -86,6 +93,13 @@ AC_CHECK_LIB(execinfo, backtrace, BACKTRACE_LIB=-lexecinfo, BACKTRACE_LIB=) AC_SUBST(BACKTRACE_LIB) +# check for struct in6_addr has s6_addr32 field +AC_CHECK_MEMBER([struct in6_addr.s6_addr32], + [AC_DEFINE([HAVE_IN6_ADDR_S6_ADDR32], [1], + [Define if struct in6_addr has s6_addr32 field])], + [], + [[#include <netinet/in.h>]]) + # check for pthread (PTHREAD_CFLAGS, PTHREAD_LIBS) AX_PTHREAD @@ -225,6 +239,7 @@ [embedded=$enableval], [embedded=$ENABLE_EMBEDDED_DEFAULT]) AM_CONDITIONAL(EMBEDDED, test x"$embedded" = x"yes") AM_CONDITIONAL(ENABLE_SERCOM_STUB, test x"$embedded" = x"yes") +AM_CONDITIONAL(ENABLE_TUN, test "x$embedded" != "xyes") if test x"$embedded" = x"yes" then @@ -246,6 +261,7 @@ ENABLE_SYSLOG_LOGGING_DEFAULT="no" ENABLE_PANIC_INFLOOP_DEFAULT="yes" ENABLE_GNUTLS_DEFAULT="no" + AC_DEFINE([USE_NETNS],[0]) fi AC_ARG_ENABLE([uring], [AS_HELP_STRING([--disable-uring], [Build without io_uring support])], diff --git a/include/osmocom/core/netns.h b/include/osmocom/core/netns.h index 5bbf224..45ae614 100644 --- a/include/osmocom/core/netns.h +++ b/include/osmocom/core/netns.h @@ -2,9 +2,7 @@ * Network namespace convenience functions. */ #pragma once -#if (!EMBEDDED) - -#if defined(__linux__) +#if (USE_NETNS) #include <signal.h> @@ -18,7 +16,5 @@ int osmo_netns_switch_exit(struct osmo_netns_switch_state *state); -#endif /* defined(__linux__) */ - -#endif /* (!EMBEDDED) */ +#endif /* (USE_NETNS) */ /*! @} */ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index f2cf138..6fdf893 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -74,13 +74,16 @@ timer.c \ timer_gettimeofday.c \ timer_clockgettime.c \ - tun.c \ use_count.c \ utils.c \ write_queue.c \ probes.d \ $(NULL) +if ENABLE_TUN +libosmocore_la_SOURCES += tun.c +endif + if HAVE_SSSE3 libosmocore_la_SOURCES += conv_acc_sse.c if HAVE_SSE4_1 diff --git a/src/core/socket.c b/src/core/socket.c index bb32185..2de4bb3 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1695,7 +1695,7 @@ static unsigned int in6_addr_netmask_to_prefixlen(const struct in6_addr *netmask) { - #if defined(__linux__) + #if (HAVE_IN6_ADDR_S6_ADDR32) #define ADDRFIELD(i) s6_addr32[i] #else #define ADDRFIELD(i) __u6_addr.__u6_addr32[i] diff --git a/src/core/tun.c b/src/core/tun.c index 09a3f81..8234e4b 100644 --- a/src/core/tun.c +++ b/src/core/tun.c @@ -67,8 +67,6 @@ * osmo_tundev_free(tundev); */ -#if (!EMBEDDED) - #include <stdio.h> #include <stdlib.h> #include <stdio.h> @@ -584,6 +582,4 @@ } -#endif /* (!EMBEDDED) */ - /*! @} */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41878?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: I2322eb2936bea35596f1fd6b6a713ea5f997b1ea Gerrit-Change-Number: 41878 Gerrit-PatchSet: 1 Gerrit-Owner: Timur Davydov <dtv.comp@gmail.com>