pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/41939?usp=email )
(
1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: core: always build tun.c and gate TUN support by headers ......................................................................
core: always build tun.c and gate TUN support by headers
Always build tun.c and move platform-specific checks into the implementation.
Guard the TUN-specific code paths based on the availability of linux/if_tun.h detected at configure time. If TUN support is not available, osmo_tundev_open() returns -ENOTSUP.
This keeps the public TUN API available while disabling unsupported functionality in a capability-based way.
Change-Id: I6d1ea1644d12ef59a54cf2f73b9155def58b17a9 --- M configure.ac M src/core/tun.c 2 files changed, 10 insertions(+), 3 deletions(-)
Approvals: fixeria: Looks good to me, approved pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/configure.ac b/configure.ac index 5c10f12..18807f8 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/if_tun.h +AC_CHECK_HEADERS([linux/if_tun.h]) + dnl Check header linux/tcp.h AC_CHECK_HEADERS([linux/tcp.h])
diff --git a/src/core/tun.c b/src/core/tun.c index 09a3f81..537caf9 100644 --- a/src/core/tun.c +++ b/src/core/tun.c @@ -84,10 +84,8 @@ #include <sys/time.h> #include <net/if.h>
-#if defined(__linux__) +#ifdef HAVE_LINUX_IF_TUN_H #include <linux/if_tun.h> -#else -#error "Unknown platform!" #endif
#include <osmocom/core/utils.h> @@ -265,6 +263,7 @@ talloc_free(tundev); }
+#ifdef HAVE_LINUX_IF_TUN_H /*! Open and configure fd of the tunnel device. * \param[in] tundev The tundev object whose tunnel interface to open * \param[in] flags internal linux flags to pass when creating the device (not used yet) @@ -337,6 +336,7 @@ close(fd); return rc; } +#endif /* HAVE_LINUX_IF_TUN_H */
/*! Open the tunnel device owned by the tundev object. * \param[in] tundev The tundev object to open @@ -344,6 +344,7 @@ */ int osmo_tundev_open(struct osmo_tundev *tundev) { +#ifdef HAVE_LINUX_IF_TUN_H struct osmo_netns_switch_state switch_state; int rc; int netns_fd = -1; @@ -418,6 +419,9 @@ if (netns_fd >= 0) close(netns_fd); return rc; +#else + return -ENOTSUP; +#endif /* HAVE_LINUX_IF_TUN_H */ }
/*! Close the tunnel device owned by the tundev object.