diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 9b890f25a..8bc6c9bb3 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -58,12 +58,11 @@ // If you want mDNS support, then you can't use Apple utun. I use the non-Apple driver // pretty much exclusively, because mDNS is a requirement. -#define USE_APPLE_UTUN 0 -#define USE_TUN 1 - -#if USE_TUN && USE_APPLE_UTUN -#error "You may not use both tun and utun." -#endif // USE_TUN && USE_APPLE_UTUN +#if !(defined(OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION) && \ + ((OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_UTUN) || \ + (OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_TUN))) +#error "Unexpected tunnel driver selection" +#endif #endif // defined(__APPLE__) @@ -118,16 +117,16 @@ extern int #include // ND6_INFINITE_LIFETIME #ifdef __APPLE__ -#if USE_APPLE_UTUN +#if OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_UTUN #include -#endif // USE_APPLE_UTUN +#endif -#if USE_TUN +#if OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_TUN #include // FIX ME: include the tun_ioctl.h file (challenging, as it's location depends on where the developer puts it) #define TUNSIFHEAD _IOW('t', 96, int) #define TUNGIFHEAD _IOR('t', 97, int) -#endif // USE_TUN +#endif #include #endif // defined(__APPLE__) @@ -156,9 +155,9 @@ extern int #elif defined(__NetBSD__) || defined(__FreeBSD__) #define OPENTHREAD_POSIX_TUN_DEVICE "/dev/tun0" #elif defined(__APPLE__) -#if USE_APPLE_UTUN +#if OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_UTUN #define OPENTHREAD_POSIX_TUN_DEVICE // not used - calculated dynamically -#elif USE_TUN +#elif OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_TUN #define OPENTHREAD_POSIX_TUN_DEVICE "/dev/tun0" #endif #else @@ -1207,7 +1206,7 @@ static void platformConfigureTunDevice(otInstance *aInstance, } #endif -#if defined(__APPLE__) && USE_APPLE_UTUN +#if defined(__APPLE__) && (OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_UTUN) static void platformConfigureTunDevice(otInstance *aInstance, const char *aInterfaceName, char * deviceName, @@ -1262,7 +1261,9 @@ exit: } #endif -#if defined(__NetBSD__) || (defined(__APPLE__) && USE_TUN) || defined(__FreeBSD__) +#if defined(__NetBSD__) || \ + (defined(__APPLE__) && (OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION == OT_POSIX_CONFIG_MACOS_TUN)) || \ + defined(__FreeBSD__) static void platformConfigureTunDevice(otInstance *aInstance, const char *aInterfaceName, char * deviceName, diff --git a/src/posix/platform/openthread-posix-config.h b/src/posix/platform/openthread-posix-config.h index fd4b8a028..223e8e26d 100644 --- a/src/posix/platform/openthread-posix-config.h +++ b/src/posix/platform/openthread-posix-config.h @@ -101,4 +101,28 @@ #define OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 0 #endif +#ifdef __APPLE__ + +/** + * Use built-in utun driver on mac OS + */ +#define OT_POSIX_CONFIG_MACOS_UTUN 1 + +/** + * Use open-source tun driver on mac OS + */ +#define OT_POSIX_CONFIG_MACOS_TUN 2 + +/** + * @def OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION + * + * This setting configures which tunnel driver to use. + * + */ +#ifndef OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION +#define OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION OT_POSIX_CONFIG_MACOS_UTUN +#endif + +#endif // __APPLE__ + #endif // OPENTHREAD_PLATFORM_CONFIG_H_