From 37f611005d2d8104852fad508c01fdb5181933f9 Mon Sep 17 00:00:00 2001 From: Laurent Coustet Date: Mon, 28 Dec 2015 12:19:51 +0100 Subject: [PATCH] filters: Fix build when --disable-filters, fixes configure.ac libpcap detect --- README.md | 1 + configure.ac | 17 +++++++++-------- src/Makefile.am | 6 +++--- src/config.c | 6 +++--- src/mlvpn.c | 4 +++- src/mlvpn.h | 6 +++--- src/tuntap_generic.c | 4 ++-- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 32d5d2a..53915fd 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Dependencies ============ - libev - libsodium + - libpcap (optional) Security ======== diff --git a/configure.ac b/configure.ac index 8903277..294eab1 100644 --- a/configure.ac +++ b/configure.ac @@ -163,20 +163,21 @@ mlvpn_ARG_WITH([systemdtmpfilesdir], [Directory for systemd tmpfiles], [test -n "$with_systemdtmpfilesdir" -a "x$with_systemdtmpfilesdir" != xno ]) dnl checks for libpcap -# Default values -AC_DEFINE([HAVE_LIBPCAP], [0], []) -AM_CONDITIONAL([HAVE_LIBPCAP], [false]) -if test x"$ENABLE_FILTERS" = x"yes"; then +# Default values +AM_CONDITIONAL([HAVE_FILTERS], [false]) +AS_IF([test x"$enable_filters" = x"yes"], [ + AM_CONDITIONAL([HAVE_FILTERS], [true]) + AC_DEFINE([HAVE_FILTERS], [], [filters enabled]) dnl checks for libpcap PKG_CHECK_MODULES([libpcap], [libpcap], [], [ AC_CHECK_HEADERS([pcap.h], [], [AC_MSG_ERROR("pcap.h not found")]) AC_CHECK_LIB([pcap], [pcap_open_dead], [ libpcap_LIBS="-lpcap" - AC_DEFINE([HAVE_LIBPCAP], [1], [pcap_open_dead in -lpcap]) - AM_CONDITIONAL([HAVE_LIBPCAP], [true]) - ], [AC_MSG_ERROR("libpcap not found")]) + ], [ + AC_MSG_ERROR("libpcap not found") + ]) ]) -fi +]) AC_CHECK_PROGS([RONN], [ronn], []) AM_CONDITIONAL(HAVE_RONN, [test x"$RONN" != "x"]) diff --git a/src/Makefile.am b/src/Makefile.am index a142d0e..ac6f687 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,8 +67,8 @@ EXTRA_DIST = \ mlvpn_LDADD=-lm $(libsodium_LIBS) $(libev_LIBS) mlvpn_CFLAGS=$(CFLAGS) $(libsodium_CFLAGS) $(libev_CFLAGS) -if ENABLE_FILTERS +if HAVE_FILTERS mlvpn_SOURCES += filters.c -mlvpn_LDADD += -lpcap +mlvpn_LDADD += $(libpcap_LIBS) mlvpn_CFLAGS += $(libpcap_CFLAGS) -endif \ No newline at end of file +endif diff --git a/src/config.c b/src/config.c index 013fe9f..4125b3c 100644 --- a/src/config.c +++ b/src/config.c @@ -62,7 +62,7 @@ mlvpn_config(int config_file_fd, int first_time) mlvpn_options.fallback_available = 0; /* reset all bpf filters on every interface */ -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS struct bpf_program filter; pcap_t *pcap_dead_p = pcap_open_dead(DLT_RAW, DEFAULT_MTU); memset(&mlvpn_filters, 0, sizeof(mlvpn_filters)); @@ -425,7 +425,7 @@ mlvpn_config(int config_file_fd, int first_time) } } -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS work = config; int found_in_config = 0; while (work) @@ -463,7 +463,7 @@ mlvpn_config(int config_file_fd, int first_time) //_conf_printConfig(config); _conf_freeConfig(config); -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS pcap_close(pcap_dead_p); #endif diff --git a/src/mlvpn.c b/src/mlvpn.c index 7b76190..e3a9433 100644 --- a/src/mlvpn.c +++ b/src/mlvpn.c @@ -106,9 +106,11 @@ struct mlvpn_options_s mlvpn_options = { .root_allowed = 0, .reorder_buffer_size = 0 }; +#ifdef HAVE_FILTERS struct mlvpn_filters_s mlvpn_filters = { .count = 0 }; +#endif struct mlvpn_reorder_buffer *reorder_buffer; freebuffer_t *freebuf; @@ -1507,4 +1509,4 @@ main(int argc, char **argv) free(_progname); return 0; -} \ No newline at end of file +} diff --git a/src/mlvpn.h b/src/mlvpn.h index ef33022..9163073 100644 --- a/src/mlvpn.h +++ b/src/mlvpn.h @@ -37,7 +37,7 @@ #include #endif -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS #include #endif @@ -177,7 +177,7 @@ typedef struct mlvpn_tunnel_s ev_timer io_timeout; } mlvpn_tunnel_t; -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS struct mlvpn_filters_s { uint8_t count; struct bpf_program filter[255]; @@ -200,7 +200,7 @@ mlvpn_tunnel_t *mlvpn_rtun_new(const char *name, uint32_t loss_tolerence); void mlvpn_rtun_drop(mlvpn_tunnel_t *t); void mlvpn_rtun_status_down(mlvpn_tunnel_t *t); -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS int mlvpn_filters_add(const struct bpf_program *filter, mlvpn_tunnel_t *tun); mlvpn_tunnel_t *mlvpn_filters_choose(uint32_t pktlen, const u_char *pktdata); #endif diff --git a/src/tuntap_generic.c b/src/tuntap_generic.c index 344cbdb..1141c35 100644 --- a/src/tuntap_generic.c +++ b/src/tuntap_generic.c @@ -7,7 +7,7 @@ mlvpn_tuntap_generic_read(u_char *data, uint32_t len) mlvpn_tunnel_t *rtun = NULL; mlvpn_pkt_t *pkt; -#ifdef ENABLE_FILTERS +#ifdef HAVE_FILTERS rtun = mlvpn_filters_choose((uint32_t)len, data); if (rtun) { /* High priority buffer, not reorderd when a filter applies */ @@ -33,4 +33,4 @@ mlvpn_tuntap_generic_read(u_char *data, uint32_t len) ev_io_start(EV_DEFAULT_UC, &rtun->io_write); } return pkt->len; -} \ No newline at end of file +}