Skip to content

Commit

Permalink
filters: Fix build when --disable-filters, fixes configure.ac libpcap…
Browse files Browse the repository at this point in the history
… detect
  • Loading branch information
Laurent Coustet committed Dec 28, 2015
1 parent 8752cef commit 37f6110
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Dependencies
============
- libev
- libsodium
- libpcap (optional)

Security
========
Expand Down
17 changes: 9 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
endif
6 changes: 3 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/mlvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1507,4 +1509,4 @@ main(int argc, char **argv)

free(_progname);
return 0;
}
}
6 changes: 3 additions & 3 deletions src/mlvpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <resolv.h>
#endif

#ifdef ENABLE_FILTERS
#ifdef HAVE_FILTERS
#include <pcap/pcap.h>
#endif

Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/tuntap_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
}

0 comments on commit 37f6110

Please sign in to comment.