Timur Davydov has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/41939?usp=email ) 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(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/39/41939/1 diff --git a/configure.ac b/configure.ac index 2fd6fca..d0cdb32 100644 --- a/configure.ac +++ b/configure.ac @@ -627,6 +627,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. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41939?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: I6d1ea1644d12ef59a54cf2f73b9155def58b17a9 Gerrit-Change-Number: 41939 Gerrit-PatchSet: 1 Gerrit-Owner: Timur Davydov <dtv.comp@gmail.com>