From c0f3283ad42a1d8e70ee699271b91168b14ec357 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Tue, 30 Aug 2022 21:32:07 -0700 Subject: [PATCH] Divert: use PF_DIVERT socket on FreeBSD 14 and beyond --- configure.ac | 5 ++++- modules/divert/daq_divert.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7ab1b1a..c563af9 100644 --- a/configure.ac +++ b/configure.ac @@ -161,7 +161,10 @@ AC_ARG_ENABLE(divert-module, AS_HELP_STRING([--disable-divert-module],[do not build the bundled Divert module]), [enable_divert_module="$enableval"], [enable_divert_module="$DEFAULT_ENABLE"]) if test "$enable_divert_module" = yes; then - AC_CHECK_DECLS([IPPROTO_DIVERT], [], [enable_divert_module=no], [[#include ]]) + AC_CHECK_DECLS([PF_DIVERT], [], + AC_CHECK_DECLS([IPPROTO_DIVERT], [], [enable_divert_module=no], + [[#include ]]), + [[#include ]]) fi AM_CONDITIONAL([BUILD_DIVERT_MODULE], [test "$enable_divert_module" = yes]) AM_COND_IF([BUILD_DIVERT_MODULE], [AC_CONFIG_FILES([modules/divert/libdaq_static_divert.pc])]) diff --git a/modules/divert/daq_divert.c b/modules/divert/daq_divert.c index 79eddcc..bd8456b 100644 --- a/modules/divert/daq_divert.c +++ b/modules/divert/daq_divert.c @@ -183,7 +183,11 @@ static int divert_daq_instantiate(const DAQ_ModuleConfig_h modcfg, DAQ_ModuleIns dc->passive = (daq_base_api.config_get_mode(modcfg) == DAQ_MODE_PASSIVE); /* Open the divert socket. Traffic will not start going to it until we bind it in start(). */ +#ifdef PF_DIVERT + if ((dc->sock = socket(PF_DIVERT, SOCK_RAW, 0)) == -1) +#else if ((dc->sock = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) == -1) +#endif { SET_ERROR(modinst, "%s: Couldn't open the DIVERT socket: %s", __func__, strerror(errno)); divert_daq_destroy(dc);