macOS: Assume that net/if_utun.h is always present

Has been present in all releases since 10.7,
i.e. about 13 years ago. At this point the check
just makes the code uglier for no actual benefit.

Change-Id: I41eeae35ab23d9fb2512f33086f20f54c2d4f6df
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Message-Id: <20241128142708.14665-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29963.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Frank Lichtenheld 2024-11-28 15:27:08 +01:00 committed by Gert Doering
parent f626b661db
commit cb87888238
4 changed files with 14 additions and 25 deletions

View File

@ -145,7 +145,6 @@ elseif (WIN32)
set(ENABLE_DCO YES) set(ENABLE_DCO YES)
elseif (APPLE) elseif (APPLE)
set(TARGET_DARWIN YES) set(TARGET_DARWIN YES)
set(HAVE_NET_IF_UTUN_H YES)
else() else()
message(FATAL_ERROR "Unknown system name: \"${CMAKE_SYSTEM_NAME}\"") message(FATAL_ERROR "Unknown system name: \"${CMAKE_SYSTEM_NAME}\"")
endif () endif ()
@ -223,7 +222,6 @@ check_include_files(libgen.h HAVE_LIBGEN_H)
check_include_files(net/if.h HAVE_NET_IF_H) check_include_files(net/if.h HAVE_NET_IF_H)
check_include_files("${NETEXTRA};netinet/ip.h" HAVE_NETINET_IP_H) check_include_files("${NETEXTRA};netinet/ip.h" HAVE_NETINET_IP_H)
check_include_files(arpa/inet.h HAVE_ARPA_INET_H) check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
check_include_files(net/if_utun.h HAVE_NET_UTUN_H)
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H) check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
check_include_files("${NETEXTRA};sys/uio.h" HAVE_SYS_UIO_H) check_include_files("${NETEXTRA};sys/uio.h" HAVE_SYS_UIO_H)

View File

@ -202,9 +202,6 @@ don't. */
/* Define to 1 if you have the <net/if_tun.h> header file. */ /* Define to 1 if you have the <net/if_tun.h> header file. */
#cmakedefine HAVE_NET_IF_TUN_H #cmakedefine HAVE_NET_IF_TUN_H
/* Define to 1 if you have the <net/if_utun.h> header file. */
#cmakedefine01 HAVE_NET_IF_UTUN_H
/* Define to 1 if you have the <net/tun/if_tun.h> header file. */ /* Define to 1 if you have the <net/tun/if_tun.h> header file. */
#cmakedefine HAVE_NET_TUN_IF_TUN_H #cmakedefine HAVE_NET_TUN_IF_TUN_H

View File

@ -502,7 +502,7 @@ SOCKET_INCLUDES="
" "
AC_CHECK_HEADERS( AC_CHECK_HEADERS(
[net/if.h netinet/ip.h resolv.h sys/un.h net/if_utun.h sys/kern_control.h], [net/if.h netinet/ip.h resolv.h sys/un.h sys/kern_control.h],
, ,
, ,
[[${SOCKET_INCLUDES}]] [[${SOCKET_INCLUDES}]]

View File

@ -437,7 +437,7 @@ static void solaris_error_close(struct tuntap *tt, const struct env_set *es, con
#include <stropts.h> #include <stropts.h>
#endif #endif
#if defined(TARGET_DARWIN) && HAVE_NET_IF_UTUN_H #if defined(TARGET_DARWIN)
#include <sys/kern_control.h> #include <sys/kern_control.h>
#include <net/if_utun.h> #include <net/if_utun.h>
#include <sys/sys_domain.h> #include <sys/sys_domain.h>
@ -1782,7 +1782,7 @@ clear_tuntap(struct tuntap *tuntap)
#endif #endif
} }
#if defined (TARGET_OPENBSD) || (defined(TARGET_DARWIN) && HAVE_NET_IF_UTUN_H) #if defined(TARGET_OPENBSD) || defined(TARGET_DARWIN)
/* /*
* OpenBSD and Mac OS X when using utun * OpenBSD and Mac OS X when using utun
@ -1871,7 +1871,7 @@ read_tun_header(struct tuntap *tt, uint8_t *buf, int len)
return read(tt->fd, buf, len); return read(tt->fd, buf, len);
} }
} }
#endif /* if defined (TARGET_OPENBSD) || (defined(TARGET_DARWIN) && HAVE_NET_IF_UTUN_H) */ #endif /* if defined (TARGET_OPENBSD) || defined(TARGET_DARWIN) */
bool bool
tun_name_is_fixed(const char *dev) tun_name_is_fixed(const char *dev)
@ -3215,14 +3215,12 @@ read_tun(struct tuntap *tt, uint8_t *buf, int len)
* (http://newosxbook.com/src.jl?tree=listings&file=17-15-utun.c) * (http://newosxbook.com/src.jl?tree=listings&file=17-15-utun.c)
*/ */
#ifdef HAVE_NET_IF_UTUN_H
/* Helper functions that tries to open utun device /* Helper functions that tries to open utun device
* return -2 on early initialization failures (utun not supported * return -2 on early initialization failures (utun not supported
* at all (old OS X) and -1 on initlization failure of utun * at all) and -1 on initlization failure of utun
* device (utun works but utunX is already used */ * device (utun works but utunX is already used)
static */
int static int
utun_open_helper(struct ctl_info ctlInfo, int utunnum) utun_open_helper(struct ctl_info ctlInfo, int utunnum)
{ {
struct sockaddr_ctl sc; struct sockaddr_ctl sc;
@ -3346,13 +3344,10 @@ open_darwin_utun(const char *dev, const char *dev_type, const char *dev_node, st
tt->backend_driver = DRIVER_UTUN; tt->backend_driver = DRIVER_UTUN;
} }
#endif /* ifdef HAVE_NET_IF_UTUN_H */
void void
open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt,
openvpn_net_ctx_t *ctx) openvpn_net_ctx_t *ctx)
{ {
#ifdef HAVE_NET_IF_UTUN_H
/* If dev_node does not start start with utun assume regular tun/tap */ /* If dev_node does not start start with utun assume regular tun/tap */
if ((!dev_node && tt->type==DEV_TYPE_TUN) if ((!dev_node && tt->type==DEV_TYPE_TUN)
|| (dev_node && !strncmp(dev_node, "utun", 4))) || (dev_node && !strncmp(dev_node, "utun", 4)))
@ -3387,7 +3382,6 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
} }
} }
else else
#endif /* ifdef HAVE_NET_IF_UTUN_H */
{ {
/* Use plain dev-node tun to select /dev/tun style /* Use plain dev-node tun to select /dev/tun style
@ -3431,27 +3425,27 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
int int
write_tun(struct tuntap *tt, uint8_t *buf, int len) write_tun(struct tuntap *tt, uint8_t *buf, int len)
{ {
#ifdef HAVE_NET_IF_UTUN_H
if (tt->backend_driver == DRIVER_UTUN) if (tt->backend_driver == DRIVER_UTUN)
{ {
return write_tun_header(tt, buf, len); return write_tun_header(tt, buf, len);
} }
else else
#endif {
return write(tt->fd, buf, len); return write(tt->fd, buf, len);
}
} }
int int
read_tun(struct tuntap *tt, uint8_t *buf, int len) read_tun(struct tuntap *tt, uint8_t *buf, int len)
{ {
#ifdef HAVE_NET_IF_UTUN_H
if (tt->backend_driver == DRIVER_UTUN) if (tt->backend_driver == DRIVER_UTUN)
{ {
return read_tun_header(tt, buf, len); return read_tun_header(tt, buf, len);
} }
else else
#endif {
return read(tt->fd, buf, len); return read(tt->fd, buf, len);
}
} }
#elif defined(TARGET_AIX) #elif defined(TARGET_AIX)